Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenoit Tremblay <bentremblay@benoit-tremblays-macbook-pro.local>2009-10-29 14:32:20 (GMT)
committer Benoit Tremblay <bentremblay@benoit-tremblays-macbook-pro.local>2009-10-29 14:32:20 (GMT)
commitc5b22e5f5d38de5fbdfcd4775c5a247732ab49fd (patch)
tree51c2e901cb3ba49adc48340f36dd581ed7be8e63
parent8fc023b6173d1d5ade39264c59cfbab19b60314a (diff)
extended search capabilities
-rw-r--r--site/app/config/constants.php2
-rw-r--r--site/app/controllers/tutorius_api_controller.php134
-rw-r--r--site/app/views/tutorius_api/tutorial_display.thtml118
-rw-r--r--site/app/views/tutorius_api/tutorials.thtml7
4 files changed, 254 insertions, 7 deletions
diff --git a/site/app/config/constants.php b/site/app/config/constants.php
index 055bde0..b42f9c1 100644
--- a/site/app/config/constants.php
+++ b/site/app/config/constants.php
@@ -43,7 +43,7 @@
* Site URL default
*/
if (!defined('SITE_URL'))
- define('SITE_URL', 'https://addons.mozilla.org');
+ define('SITE_URL', 'http://tutorius.dev');
/**
* Site State default
diff --git a/site/app/controllers/tutorius_api_controller.php b/site/app/controllers/tutorius_api_controller.php
index b988eaf..40acccb 100644
--- a/site/app/controllers/tutorius_api_controller.php
+++ b/site/app/controllers/tutorius_api_controller.php
@@ -37,6 +37,7 @@
*
* ***** END LICENSE BLOCK ***** */
//require_once('Archive/Zip.php');
+vendor('sphinx/addonsSearch');
uses('sanitize');
@@ -161,7 +162,7 @@ class TutoriusApiController extends AppController
* Search addons
*
*/
- function search() {
+ function search($terms, $category='all', $page=1, $limit=20, $sortBy='name') {
$args = func_get_args();
return $this->dispatchHttpMethod(array(
'GET' => 'search_GET'
@@ -173,13 +174,137 @@ class TutoriusApiController extends AppController
* Search for addons
*
*/
- function search_GET() {
+ function search_GET($context, $terms, $category='all', $page=1, $limit=20, $sortBy='name') {
+ extract($context);
+
+ global $valid_status, $app_shortnames;
+
+ $search_options = array();
+
+ $associations = array(
+ 'all_categories', 'all_tags', 'authors', 'compatible_apps',
+ 'contrib_details', 'files', 'latest_version', 'list_details'
+ );
+
+ // collection search is a special case
+ if ($category == 'collections') {
+ // special case for collections
+ return;
+ }
+
+ if ($category == 'all')
+ $category = 0;
+
+ $search_options['category'] = $category;
+
+ $search_options['type'] = ADDON_TUTORIUS;
+
+ //if advanced search sort_order set, use it
+ $sort = "";
+ $sort_orders = array('newest', 'name', 'averagerating', 'weeklydownloads');
+ if (isset($sortBy) &&
+ in_array($sortBy, $sort_orders) ) {
+ $search_options['sort'] = $sortBy;
+ }
+
+ // execute this search
+ $as = new AddonsSearch($this->Addon);
+ $_result_ids = array();
+ $total = 0;
+
+ if ($terms) {
+ try {
+ list($_result_ids, $total) = $as->query($terms, $search_options);
+ }
+ catch (AddonsSearchException $e) {
+ header("HTTP/1.1 503 Service Unavailable", true, 503);
+ $this->publish('error', "Search is temporarily unavailable.");
+ }
+ }
+
+ // cut the appropriate slice out of the results array
+ $offset = ($page-1)*$limit;
+ $_result_ids = array_slice($_result_ids, $offset, $limit);
+
+ if (!empty($_result_ids)) {
+ $results = $this->Addon->getAddonList($_result_ids, $associations);
+ $this->_getTutorials($_result_ids);
+ } else {
+ $results = array();
+ }
+
+ $this->_sendToView('app_names', $this->Application->getIDList());
+ $this->_sendToView('guids', array_flip($this->Application->getGUIDList()));
+
+ $this->render('tutorials');
+ }
+
+ function tutorials($category='all', $page=1, $limit=10, $sort_by='') {
+
+ $args = func_get_args();
+ return $this->dispatchHttpMethod(array(
+ 'GET' => 'tutorials_GET'
+ ), $args);
+
+ }
+
+ function tutorials_GET($context, $category='all', $page=1, $limit=10, $sort_by='') {
+ extract($context);
+
+ $this->forceShadowDb();
+
+ $addontype = ADDON_TUTORIUS;
+
+ $app_names = $this->Application->getIDList();
+ $guids = array_flip($this->Application->getGUIDList());
+
+ // By default, we're getting all categories
+ $this_category = array();
+
+ if ($category != 'all') {
+ $this->Category->unbindFully();
+ $this_category = $this->Category->findById($category);
+ }
+
+ $allowed_sort_by = array('name', 'updated', 'newest', 'popular', 'rated');
+
+ switch ($sort_by) {
+ case 'popular':
+ case 'updated':
+ case 'newest':
+ case 'rated':
+ $sort_dir = 'desc';
+ break;
+ case 'name':
+ default:
+ $sort_dir = 'asc';
+ break;
+ }
+
+ $displaystatuses = array(STATUS_PUBLIC);
+
+ $tutorials = $this->Addon->getAddonsByCategory(null, $displaystatuses,
+ $addontype, $category, $sort_by, $sort_dir, $limit, $page, '', true);
+
+ $ids = array();
+
+ // Build an array with all found ids so we can get
+ // more information about these tutorials
+ foreach($tutorials as $tutorial) {
+ $ids[sizeof($ids)] = $tutorial['Addon']['id'];
+ }
+
+ $this->_getTutorials($ids);
+
+ $this->_sendToView('addons', $tutorials);
+ $this->_sendToView('app_names', $app_names);
+ $this->_sendToView('guids', $guids);
}
/**********************************************
- /*************** AUTHENTIFICATION *************
+ /*************** AUTHENTICATION *************
/*********************************************/
/*
@@ -850,9 +975,6 @@ class TutoriusApiController extends AppController
}
}
- // notify subscribed editors of update (if any)
- //$this->Editors->updateNotify($addon['Addon']['id'], $version_id);
-
// Add Files
$data['File']['db']['version_id'] = $version_id;
$platforms = $data['File']['db']['platform_id'];
diff --git a/site/app/views/tutorius_api/tutorial_display.thtml b/site/app/views/tutorius_api/tutorial_display.thtml
new file mode 100644
index 0000000..433b342
--- /dev/null
+++ b/site/app/views/tutorius_api/tutorial_display.thtml
@@ -0,0 +1,118 @@
+<?php
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is addons.mozilla.org site.
+ *
+ * The Initial Developer of the Original Code is
+ * The Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2007
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ * Laura Thomson <lthomson@mozilla.com> (Original Author)
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+ if (empty($addonIconPath)) {
+ $addonIconPath = ($addon['Addon']['addontype_id'] == ADDON_THEME ? $html->urlImage(DEFAULT_THEME_ICON) : $html->urlImage(DEFAULT_ADDON_ICON));
+ }
+
+ $amo = 'http://tutorius.dev';
+?>
+<tutorial>
+ <?php
+ // Allow some additional content to be injected into the addon element by
+ // the including template.
+ if (isset($addon_pre)) echo $addon_pre;
+ ?>
+ <name><?php echo $addon['Translation']['name']['string']; ?></name>
+ <type id='<?php echo $addon['Addon']['addontype_id']; ?>'><?php echo Addontype::getName($addon['Addon']['addontype_id']); ?></type>
+ <guid><?php if (isset($addon['Addon']['guid'])) echo $addon['Addon']['guid']; ?></guid>
+ <version><?php echo $addon['install_version']['version']; ?></version>
+ <status id='<?php echo $addon['Addon']['status']; ?>'><?php if ($addon['Addon']['status'] == STATUS_PUBLIC) {
+ echo rtrim(___('Public', 'a_header_public'));
+ } else {
+ echo rtrim(___('Sandbox', 'a_header_sandbox'));
+ }
+ ?></status>
+ <authors>
+<?php
+ foreach ($addon['User'] as $author) {
+ $authorName = (!empty($author['nickname'])) ? $author['nickname'] : $author['firstname'].' '.$author['lastname'];
+?>
+ <author><?php echo $authorName; ?></author>
+<?php
+ }
+?> </authors>
+ <summary><?php echo $addon['Translation']['summary']['string']; ?></summary>
+ <description><?php if(isset($addon['Translation']['description']['string'])) echo $addon['Translation']['description']['string']; ?></description>
+ <icon><?php if (isset($addon['Icon'])) {
+ echo $amo.$addon['Icon'];
+ } else {
+ $addonIconPath = ($addon['Addon']['addontype_id'] == ADDON_THEME ? $html->urlImage(DEFAULT_THEME_ICON) : $html->urlImage(DEFAULT_ADDON_ICON));
+ echo $amo.$addonIconPath;
+ } ?></icon>
+ <compatible_applications>
+<?php
+ foreach ($addon['Compatible_apps'] as $app) {
+ $name = $app_names[$app['Application']['application_id']];
+?>
+ <application>
+ <name><?php echo $name; ?></name>
+ <application_id><?php echo $app['Application']['application_id']; ?></application_id>
+ <min_version><?php echo $app['Min_Version']['version']; ?></min_version>
+ <max_version><?php echo $app['Max_Version']['version']; ?></max_version>
+
+ <appID><?php echo $guids[$name]; ?></appID>
+
+ </application>
+ <?php
+ }
+?> </compatible_applications>
+ <eula><?php echo $addon['Translation']['eula']['string'];?></eula>
+ <thumbnail><?php echo $amo.$addon['Thumbnail']; ?></thumbnail>
+ <rating><?php
+ $rating ='';
+ if (isset($addon['Addon']['averagerating'])) {
+ $rating = $addon['Addon']['averagerating'];
+
+ // round rating to match stars in AMO
+ $rating = ceil($rating);
+ }
+ echo $rating;
+ ?></rating>
+ <learnmore><?php echo $amo.'/addon/'.$addon['Addon']['id']; ?>?src=api</learnmore>
+ <?php foreach($addon['fileinfo'] as $file) {?>
+ <install hash='<?php echo $file['File']['hash'];?>'><?php
+ echo $amo.'/downloads/file/'.$file['File']['id'].'/'
+ .$file['File']['filename']; ?></install>
+ <?php } ?>
+
+<?php
+ // Allow some additional content to be injected into the addon element by
+ // the including template.
+ if (isset($addon_post)) echo $addon_post;
+?>
+</tutorial> \ No newline at end of file
diff --git a/site/app/views/tutorius_api/tutorials.thtml b/site/app/views/tutorius_api/tutorials.thtml
new file mode 100644
index 0000000..eb955d9
--- /dev/null
+++ b/site/app/views/tutorius_api/tutorials.thtml
@@ -0,0 +1,7 @@
+<tutorials>
+<?php
+ foreach ($addonsdata as $addon) {
+ include 'tutorial_display.thtml';
+ }
+?>
+</tutorials> \ No newline at end of file