Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/models/addon.php
diff options
context:
space:
mode:
Diffstat (limited to 'site/app/models/addon.php')
-rw-r--r--site/app/models/addon.php263
1 files changed, 92 insertions, 171 deletions
diff --git a/site/app/models/addon.php b/site/app/models/addon.php
index 6c09124..e651d34 100644
--- a/site/app/models/addon.php
+++ b/site/app/models/addon.php
@@ -119,19 +119,19 @@ class Addon extends AppModel
)
);
-
+
var $translated_fields = array(
- 'description',
+ 'description',
'developercomments',
'eula',
'supportemail',
'supporturl',
'homepage',
- 'name',
+ 'name',
'privacypolicy',
'summary'
- );
-
+ );
+
var $validate = array(
'guid' => VALID_NOT_EMPTY,
'name' => VALID_NOT_EMPTY,
@@ -149,9 +149,9 @@ class Addon extends AppModel
'averagerating', 'weeklydownloads', 'totaldownloads', 'totalreviews',
'developercomments', 'inactive', 'trusted', 'viewsource', 'publicstats',
'prerelease', 'adminreview', 'sitespecific', 'externalsoftware', 'binary',
- 'eula', 'privacypolicy', 'nominationmessage', 'target_locale', 'locale_disambiguation',
+ 'eula', 'privacypolicy', 'nominationmessage', 'target_locale', 'locale_disambiguation',
'created', 'modified');
-
+
/**
* Get a single add-on, along with the desired associations
* (uses the object-invalidation framework)
@@ -163,22 +163,22 @@ class Addon extends AppModel
*/
function getAddon($id, $associations = array()) {
global $valid_status;
-
+
// if this object is cached, grab it from memcache
$identifier = array("addon:$id", $associations);
if (QUERY_CACHE && $cached = $this->Cache->readCacheObject($identifier)) {
if (DEBUG >= 2) debug("addon $id was cached");
return $cached;
}
-
+
// deactivate query caching
$caching_was = $this->caching;
$this->caching = false;
-
+
// start with very basic fields and association list, then add more as desired
$this->unbindFully();
$fields = array('id', 'name', 'status');
-
+
foreach ($associations as $association) {
switch ($association) {
case 'all_tags':
@@ -189,7 +189,7 @@ class Addon extends AppModel
'foreignKey' => 'addon_id'
))));
break;
-
+
case 'authors':
// addon authors
$this->bindModel(array('hasAndBelongsToMany' =>
@@ -202,28 +202,28 @@ class Addon extends AppModel
'order' => 'addons_users.position'
))));
break;
-
+
case 'compatible_apps':
// list of applications this add-on is compatible with
break;
-
+
case 'files':
// list of files for all versions returned (depends on lastversion
// or allversions);
loadModel('File');
break;
-
+
case 'latest_version':
// latest public version for public add-ons, latest valid
// version otherwise
break;
-
+
case 'list_details':
// add-on details needed for a list item
$fields = array_merge($fields, array('summary', 'eula',
'weeklydownloads', 'addontype_id', 'averagerating', 'totalreviews'));
break;
-
+
case 'single_tag':
// the first category this add-on is associated with
$this->bindModel(array('hasMany' =>
@@ -233,16 +233,16 @@ class Addon extends AppModel
'limit' => 1
))));
break;
-
+
default:
debug("Association $association not declared!");
break;
}
}
-
+
// get desired add-on from DB
$addon = $this->findById($id, $fields);
-
+
// add additional data
if (in_array('latest_version', $associations)) {
// pull in last version
@@ -255,23 +255,23 @@ class Addon extends AppModel
array('Version.id', 'Version.version', 'Version.created'));
if (!empty($buf[0]['Version'])) {
$addon['Version'][0] = $buf[0]['Version'];
-
+
if (in_array('compatible_apps', $associations)) {
/* get add-on app compatibility info for that version */
$addon['compatible_apps'] = $this->Version->getCompatibleApps($buf[0]['Version']['id']);
}
}
}
-
+
if (in_array('list_details', $associations)) {
// is the addon recommended?
$addon['Addon']['recommended'] = $this->is_recommended($id);
}
-
+
// files
if (in_array('files', $associations) && in_array('latest_version', $associations)
&& !empty($addon['Version'])) {
-
+
loadModel('File');
$this->File =& new File();
$this->File->unbindfully();
@@ -279,7 +279,7 @@ class Addon extends AppModel
$_files = $this->File->findAll("File.version_id = '{$addon['Version'][0]['id']}'");
foreach ($_files as $_file)
$addon['File'][] = $_file['File'];
-
+
// date of addon status change
if (!empty($addon['File'])) {
if ($addon['Addon']['status'] == STATUS_PUBLIC && $addon['File'][0]['datestatuschanged'] > 0)
@@ -290,11 +290,11 @@ class Addon extends AppModel
$addon['Addon']['datestatuschanged'] = $addon['Version'][0]['created'];
}
}
-
+
// add addon tags
if ((in_array('all_tags', $associations) || in_array('single_tag', $associations))
&& !empty($addon['AddonTag'])) {
-
+
$_tag_ids = array();
foreach ($addon['AddonTag'] as $_tag)
$_tag_ids[] = $_tag['tag_id'];
@@ -303,18 +303,18 @@ class Addon extends AppModel
$tags = $this->Tag->findAll(array('Tag.id' => $_tag_ids, 'Tag.application_id' => APP_ID));
$addon['Tag'] = $tags;
}
-
+
// cache this object...
if (QUERY_CACHE)
$this->Cache->writeCacheObject($identifier, $addon, "addon:$id");
-
+
// re-enable query caching
$this->caching = $caching_was;
-
+
// ... then hand it back to the caller
return $addon;
}
-
+
/**
* Get a list of add-ons by id, each with the given associations
* uses the object invalidation framework
@@ -326,7 +326,7 @@ class Addon extends AppModel
}
return $result;
}
-
+
/**
* Get addons in a category, sorted by name, popularity (weekly downloads)
* or "recently updated" (last file approval timestamp).
@@ -334,18 +334,18 @@ class Addon extends AppModel
* @return array list of matching add-on ids
*/
function getAddonsFromCategory($status = array(STATUS_PUBLIC),
- $addontypes = ADDON_EXTENSION, $category = 'all', $sort_by = 'name',
+ $addontypes = ADDON_ACTIVITY, $category = 'all', $sort_by = 'name',
$direction = 'ASC', $limit = '5', $page = '1', $friends = '') {
-
+
$this->unbindFully();
-
+
$select_field = 'DISTINCT Addon.id';
-
+
// make input data uniform
if (!is_array($addontypes)) $addontypes = array($addontypes);
if (!is_array($status)) $status = array($status);
if ($page <= 0) $page = 1;
-
+
// additional joins for sort order etc.
$add_joins = $orderby = $limitclause = $groupby = $where = '';
if ($category != 'all') {
@@ -354,13 +354,13 @@ class Addon extends AppModel
}
// only select add-ons that have any files to offer
$add_joins .= "INNER JOIN files AS File ON (Version.id = File.version_id AND File.status IN (".implode(',',$status).")) ";
-
+
// Facebook friends
if (!empty($friends)) {
$add_joins .= "INNER JOIN facebook_favorites AS ff ON ff.addon_id = Addon.id ";
$where .= "AND ff.fb_user IN ({$friends}) ";
}
-
+
// additional joins etc per list type
switch ($sort_by) {
case 'name':
@@ -376,7 +376,7 @@ class Addon extends AppModel
$groupby = 'GROUP BY Addon.id';
break;
}
-
+
// translate sort_by into SQL ORDER BY
if (!empty($sort_by)) {
$orderby = 'ORDER BY ';
@@ -401,12 +401,12 @@ class Addon extends AppModel
} else {
$orderby = '';
}
-
+
if (!empty($page) && !empty($limit))
$limitclause = "LIMIT ".(($page-1)*$limit).", {$limit}";
else
$limitclause = '';
-
+
// If the search engine type is the only add-on we're looking for, we remove
// the restriction on applications. If the search engine type is in the list
// with other types, it _won't work_ because there is no application
@@ -429,107 +429,52 @@ class Addon extends AppModel
."AND Addon.inactive = 0 "
."{$where} {$groupby} {$orderby} {$limitclause}";
}
-
+
$addon_list = $this->query($sql,true);
-
+
// if there are no results, we are done.
if (empty($addon_list)) return $addon_list;
-
+
// otherwise return the ids
$addon_ids = array();
foreach($addon_list as $id) $addon_ids[] = $id['Addon']['id'];
return $addon_ids;
}
-
- /**
- * Sort and optionally paginate the addons in $addon_ids.
- */
- function sorted($addon_ids, $field, $limit=null, $page=null, $extra='') {
- // Bail early if there isn't anything to sort.
- if (empty($addon_ids)) {
- return $addon_ids;
- }
-
- $join = $orderby = $direction = $limit_clause = '';
-
- $select = "SELECT DISTINCT Addon.id FROM addons AS Addon";
-
- $ids = implode(',', $addon_ids);
- $where = "WHERE Addon.id IN ({$ids})";
-
- if (strstr($field, ' ')) {
- list($field, $direction) = explode(' ', $field);
- }
-
- if (in_array($field, $this->translated_fields)) {
- $join = "LEFT JOIN translations AS tr_l
- ON (tr_l.id = Addon.{$field} AND tr_l.locale = '".LANG."')
- LEFT JOIN translations AS tr_en
- ON (tr_en.id = Addon.{$field} AND tr_en.locale = `Addon`.`defaultlocale`) ";
- $orderby = "ORDER BY IFNULL(tr_l.localized_string, tr_en.localized_string)";
- } else if (!empty($extra)) {
- $join = $extra;
- $orderby = "ORDER BY {$field}";
- } else {
- $orderby = "ORDER BY Addon.{$field}";
- }
-
- if (isset($limit) && isset($page)) {
- $offset = ($page - 1) * $limit;
- $limit_clause .= "LIMIT {$limit} OFFSET {$offset}";
- }
-
- $sql = implode(' ', array($select, $join, $where, $orderby, $direction, $limit_clause));
-
- foreach($this->query($sql) as $a) $sorted[] = $a['Addon']['id'];
-
- return $sorted;
- }
-
+
/**
* Get a list of addon IDs from a collection
* @param int $collectionId ID of the collection
* @param string $orderBy field name to sort the list by
* @param int $cat_id sub-category ID, null for all
*/
- function getAddonsFromCollection($collectionId = null, $orderBy = null, $cat_id = null, $limit = null) {
- global $valid_status;
-
+ function getAddonsFromCollection($collectionId = null, $orderBy = 'name', $cat_id = null) {
$this->unbindFully();
-
+
$query = "SELECT DISTINCT(Addon.id) FROM addons AS Addon INNER JOIN versions AS Version ON (Addon.id = Version.addon_id) "
- ."INNER JOIN files AS File ON (Version.id = File.version_id AND File.status IN (".join(",",$valid_status).")) "
+ ."INNER JOIN applications_versions AS av ON (av.version_id = Version.id AND av.application_id = ".APP_ID.") "
+ ."INNER JOIN files AS File ON (Version.id = File.version_id AND File.status = ".STATUS_PUBLIC.") "
."INNER JOIN addons_collections AS ac ON (ac.addon_id = Addon.id AND ac.collection_id = $collectionId AND "
.((is_null($cat_id))?'1':"ac.category='{$cat_id}'").") WHERE "
- ."Addon.status IN (".join(",",$valid_status).") AND Addon.inactive = 0";
-
- if (!is_null($orderBy)) {
- $query .= " ORDER BY {$orderBy}";
- }
-
- if (!is_null($limit)) {
- $query .= " LIMIT {$limit}";
- }
-
-
+ ."Addon.status = ".STATUS_PUBLIC." AND Addon.inactive = 0";
+
$addon_list = $this->query($query, true);
- $addons_ids = array();
+ $addon_ids = array();
if(!empty($addon_list)) {
foreach($addon_list as $id) {
$addons_ids[] = $id['Addon']['id'];
}
}
-
+
return $addons_ids;
}
-
+
/**
* Get a list of addon IDs from a category, divided into subcategories
*/
function getCategorizedAddonsFromCollection($collectionId = null) {
$subcatlist = $this->query('SELECT DISTINCT(ac.category) FROM addons_collections AS ac '
."WHERE ac.collection_id='{$collectionId}' ORDER BY ac.category");
-
+
$result = array();
if (empty($subcatlist)) return $result;
foreach ($subcatlist as $cat) {
@@ -538,13 +483,13 @@ class Addon extends AppModel
}
return $result;
}
-
+
/**
* Get the number of addons in a specific category
*/
function countAddonsInCategory($status = array(STATUS_PUBLIC),
- $addontypes = ADDON_EXTENSION, $category = 'all', $friends = '') {
-
+ $addontypes = ADDON_ACTIVITY, $category = 'all', $friends = '') {
+
$rowcount = $this->getAddonsFromCategory($status, $addontypes, $category,
null, null, null, null, $friends);
return count($rowcount);
@@ -555,9 +500,9 @@ class Addon extends AppModel
*/
function countAddonsInAllCategories($status = array(STATUS_PUBLIC), $addontypes = array(ADDON_THEME)) {
- if (!is_array($status))
+ if (!is_array($status))
$status = array($status);
- if (!is_array($addontypes))
+ if (!is_array($addontypes))
$addontypes = array($addontypes);
// Construct the SQL query, stolen from getAddonsByCategory
@@ -582,7 +527,7 @@ class Addon extends AppModel
return $addon_counts;
}
-
+
/**
* Returns the name of the add-on with given id
*/
@@ -593,7 +538,7 @@ class Addon extends AppModel
else
return false;
}
-
+
/**
* Returns the name and ids of all add-ons by the user
*/
@@ -605,9 +550,9 @@ class Addon extends AppModel
$addons[$addon_id['addons_users']['addon_id']] = $this->getAddonName($addon_id['addons_users']['addon_id']);
}
}
-
+
asort($addons);
-
+
return $addons;
}
@@ -628,7 +573,7 @@ class Addon extends AppModel
$_addon_ids = array();
foreach ($featAddons as $_addon)
$_addon_ids[] = $_addon['Feature']['addon_id'];
-
+
return $_addon_ids;
}
@@ -643,12 +588,12 @@ class Addon extends AppModel
."Feature.start < NOW() AND Feature.end > NOW() AND "
."Feature.application_id ='" . APP_ID . "' AND "
."(Feature.locale = '" . LANG . "' OR Feature.locale IS NULL)";
-
+
$_rec = $this->Feature->findCount($criteria);
-
+
return ($_rec >= 1);
}
-
+
/**
* Get the most recent update ping count
* This is temporary until we can store this in addons and update
@@ -656,42 +601,42 @@ class Addon extends AppModel
*/
function getMostRecentUpdatePingCount($addon_id) {
$count = $this->query("SELECT `count` FROM update_counts WHERE addon_id={$addon_id} ORDER BY `date` DESC LIMIT 1");
-
+
return !empty($count) ? $count[0]['update_counts']['count'] : 0;
}
-
+
/**
* Retrieves all details from addons_users for a particular add-on
*/
function getAuthors($addon_id, $onlyListed = true) {
$listedQry = $onlyListed ? 'AND addons_users.listed=1 ' : '';
-
+
$authors = $this->query("SELECT addons_users.*, User.id, User.email, User.firstname, User.lastname, User.nickname FROM addons_users INNER JOIN users AS User ON addons_users.user_id = User.id WHERE addons_users.addon_id={$addon_id} {$listedQry}ORDER BY addons_users.position");
-
+
return $authors;
}
-
+
/**
* Removes all authors from an add-on
*/
function clearAuthors($addon_id) {
return $this->execute("DELETE FROM addons_users WHERE addon_id={$addon_id}");
}
-
+
/**
* Saves an add-on author
*/
function saveAuthor($addon_id, $user_id, $role = AUTHOR_ROLE_OWNER, $listed = 1, $position = 0) {
return $this->execute("INSERT INTO addons_users (addon_id, user_id, role, listed, position) VALUES({$addon_id}, {$user_id}, {$role}, {$listed}, {$position})");
}
-
+
/**
* Gets all applications ever supported by the add-on
*/
function getApplicationsEverSupported($addon_id) {
return $this->query("SELECT DISTINCT Application.* FROM addons AS Addon INNER JOIN versions AS Version on Version.addon_id=Addon.id INNER JOIN applications_versions AS av ON av.version_id=Version.id INNER JOIN applications AS Application ON Application.id=av.application_id WHERE Addon.id={$addon_id}");
}
-
+
/**
* afterSave callback. Mark cached objects for flush.
*/
@@ -699,29 +644,16 @@ class Addon extends AppModel
if (QUERY_CACHE) $this->Cache->markListForFlush("addon:{$this->id}");
return parent::afterSave();
}
-
+
/**
* Get the date the addon was added to a specific collection
*/
- function getCollectionPublishDetails($addon_id, $collectionId) {
+ function getDateAddedToCollection($addon_id, $collectionId) {
$this->unbindFully();
- // comments are en-US only
- $sql = "SELECT addons_collections.added, translations.localized_string as comment, users.id, users.firstname, users.lastname, users.nickname
- FROM addons_collections
- LEFT JOIN translations
- ON translations.id = addons_collections.comments AND translations.locale='en-US'
- INNER JOIN users
- ON users.id = addons_collections.user_id
- WHERE collection_id = {$collectionId} AND addon_id = {$addon_id}";
- $data = $this->query($sql);
-
- $details = array(
- 'dateadded' => $data[0]['addons_collections']['added'],
- 'publisher' => $data[0]['users'],
- 'comment' => $data[0]['translations']['comment']
- );
- return $details;
+ $sql = "SELECT added FROM addons_collections WHERE collection_id = {$collectionId} AND addon_id = {$addon_id}";
+ $date = $this->query($sql);
+ return $date['0']['addons_collections']['added'];
}
/**
@@ -738,17 +670,6 @@ class Addon extends AppModel
return $addon_ids;
}
- /**
- * When an add-on was shared with others by email, increase the counter
- * accordingly.
- * @param int $addonid Add-on ID
- * @param int $number times shared
- * @return boolean success
- */
- function increaseShareCount($addonid, $number) {
- $sql = "UPDATE addons SET sharecount = sharecount + {$number} WHERE id = {$addonid};";
- return $this->execute($sql);
- }
/* * * * * * deprecated functions * * * * * */
/**
@@ -794,7 +715,7 @@ class Addon extends AppModel
);
$this->useDbConfig = 'shadow';
-
+
$_fields = array('id', 'guid', 'name', 'defaultlocale', 'addontype_id', 'status',
'icontype', 'icondata', 'supportemail', 'supporturl', 'homepage', 'description', 'summary',
'averagerating', 'weeklydownloads', 'totaldownloads', 'totalreviews',
@@ -802,16 +723,16 @@ class Addon extends AppModel
'prerelease', 'adminreview', 'sitespecific', 'externalsoftware',
'eula', 'privacypolicy', 'target_locale', 'locale_disambiguation',
'nominationmessage', 'created', 'modified');
-
+
$addons = $this->findAllById($id, $_fields, $order);
-
+
if (!empty($addons) && is_array($addons)) {
// we need to File model to pull in the files if requested
if ($includeFiles) {
loadModel('File');
$this->File =& new File();
}
-
+
foreach ($addons as $key=>$addon) {
/* pull in last version */
$this->Version->unbindFully();
@@ -822,14 +743,14 @@ class Addon extends AppModel
array('Version.id', 'Version.version', 'Version.created'));
if (!empty($buf[0]['Version'])) {
$addons[$key]['Version'][0] = $buf[0]['Version'];
-
+
/* get add-on app compatibility info for that version */
$addons[$key]['compatible_apps'] = $this->Version->getCompatibleApps($buf[0]['Version']['id']);
}
-
+
// is the addon recommended?
$addons[$key]['Addon']['recommended'] = $this->is_recommended($addon['Addon']['id']);
-
+
// add addon tags
if (!empty($addon['AddonTag'])) {
$_tag_ids = array();
@@ -840,7 +761,7 @@ class Addon extends AppModel
$tags = $this->Tag->findAll(array('Tag.id' => $_tag_ids, 'Tag.application_id' => APP_ID));
$addons[$key]['Tag'] = $tags;
}
-
+
/* add files for last version, if requested */
if ($includeFiles && !empty($addons[$key]['Version'])) {
$this->File->unbindfully();
@@ -860,9 +781,9 @@ class Addon extends AppModel
* @deprecated since 4.0.1, use getAddonsFromCategory along with getAddonList instead
*/
function getAddonsByCategory($fields = null, $status = array(STATUS_PUBLIC),
- $addontypes = ADDON_EXTENSION, $category = 'all', $sort_by = 'name',
+ $addontypes = ADDON_ACTIVITY, $category = 'all', $sort_by = 'name',
$direction = 'ASC', $limit = '5', $page = '1', $friends = '', $includeFiles = false) {
-
+
$associations = array('all_tags', 'authors', 'compatible_apps',
'latest_version', 'list_details');
if ($includeFiles) {