Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/controllers/collections_controller.php
blob: da80d85ec68d94f7e895977bfc62fa3e64d551e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?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) 2008
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   Ryan Doherty <rdoherty@mozilla.com>
 *   Frederic Wenzel <fwenzel@mozilla.com>
 *
 * 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 ***** */
class CollectionsController extends AppController
{
    var $name = 'Collections';
    var $beforeFilter = array('checkCSRF', 'getNamedArgs', '_checkSandbox');
    var $uses = array('Addon', 'AddonTag', 'Addontype', 'Application',
        'Feature', 'File', 'Platform', 'Preview', 'Tag', 'Translation', 
        'Review', 'Version', 'Collection');
    var $components = array('Amo', 'Image', 'Pagination', 'Session', 'Userfunc', 'Search');
    var $helpers = array('Html', 'Link', 'Time', 'Localization', 'Ajax', 'Number', 'Pagination');
    var $exceptionCSRF = array("/collections/install");
    var $namedArgs = true;

    var $securityLevel = 'low';

    function beforeFilter() {
        // Disable ACLs because this controller is entirely public.
        $this->SimpleAuth->enabled = false;
        $this->SimpleAcl->enabled = false;
        $this->layout='mozilla';
        $this->publish('collapse_categories', true);
        $this->pageTitle = 'Collections' . " :: " . sprintf(_('addons_home_pagetitle'), APP_PRETTYNAME);
    }
    
    function index() {
          
    }
    
    function display($id = NULL) {
        $this->set('jsAdd', array('jquery-ui/ui.core.min.js', 'jquery-ui/ui.accordion.min.js', 'jquery-ui/jqModal.js'));
        
        $this->Amo->clean($id);
        if (!$id || !is_numeric($id)) {
            $this->flash(sprintf(_('error_missing_argument'), 'collection_id'), '/', 3);
            return;
        }
        
        $_conditions = array(
                               'Collection.id' => $id,
                               'Collection.listed' => 1,
                           );
           
        $this->Collection->unbindFully();
        $collection = $this->Collection->find($_conditions, null, null, 1);
        
        if($collection == null) {
            $this->flash(_('collection_not_found'), '/', 3);
            return;
        }
        
        $addonIds = $this->Addon->getAddonsFromCollection($id);
     
        $addons = $this->Addon->getAddonList($addonIds,array(
            'all_tags', 'authors', 'compatible_apps', 'files', 'latest_version',
            'list_details'));
        
        foreach($addons as &$addon) {
            $addonId = $addon['Addon']['id'];
            $addon['Addon']['dateadded'] = $this->Addon->getDateAddedToCollection($addonId, $id);
        }
        
        $this->publish('addons', $addons);
        $this->publish('collection', $collection);
        $this->pageTitle = $collection['Translation']['name']['string'] . " :: " . sprintf(_('addons_home_pagetitle'), APP_PRETTYNAME);
        
        
        if (isset($_GET['format']) && $_GET['format'] == 'rss') {
            $this->publish('rss_title', $collection['Translation']['name']['string']);
            $this->publish('rss_description', $collection['Translation']['description']['string']);
            $this->render('rss/collection', 'rss');
        }
    }
    
    /**
     * Special "interactive collections" page for first-time users
     */
    function interactive() {
        // this is Firefox only, for now.
        if (APP_ID != APP_FIREFOX) {
            $this->redirect('/');
            exit();
        }
        
        // XXX: for accessibility (bug 462411), we use a hand-bundled accordion
        // + core jquery UI file. Once jquery UI is updated to post-1.6.2rc2,
        // the regular jquery UI accordion should be used (cf. jquery ui bug
        // 3553, http://ui.jquery.com/bugs/ticket/3553)
        $this->set('jsAdd', array('jquery-ui/jq-ui-162rc2-accordion-bundle-a11y.min.js', 'jquery-ui/jqModal.js'));
        $this->set('cssAdd', array('collection-style'));
        
        $addonIds = $this->Addon->getCategorizedAddonsFromCollection(1); // special collection ID
        $addons = array();
        foreach ($addonIds as $catid => $cataddons) {
            $addons[$catid] = $this->Addon->getAddonList($cataddons, array('files', 'latest_version', 'list_details'));
        }
        $this->publish('addons', $addons);
        
        // prepare view, then render
        $this->publish('suppressHeader', true, false);
        $this->publish('suppressLanguageSelector', true, false);
        $this->publish('suppressCredits', true, false);
        $this->pageTitle = 'Fashion Your Firefox';
    }
    
    /**
     * installation dialog for collections
     * @param string $method 'html' (with layout) or 'ajax' (without)
     */
    function install($method = 'html') {
        $addons = array();
        if (!empty($_POST['addon'])) {
            $addons = $this->Addon->getAddonList($_POST['addon'], array(
            'compatible_apps', 'files', 'latest_version', 'list_details'));
            
            // XXX: ugly hack allowing signed add-ons to be installed separately
            // due to bug 462108 and 453545. The DB doesn't know which ones are
            // signed or not so we need to hardcode them here.
            $signed_addons = array(
                5579, // Cooliris
                3615, // Delicious
                8384, // Digg
                5202, // Ebay
                2410, // Foxmarks
                1512 // LinkedIn
            );
            foreach ($addons as &$addon) {
                $addon['Addon']['signed_xpi'] = in_array($addon['Addon']['id'], $signed_addons);
            }
        }
        $this->publish('addons', $addons);
        
        // fetch all platforms
        $this->Platform->unbindFully();
        $platforms_all = $this->Platform->findAll();
        $platforms = array();
        foreach ($platforms_all as $pf) {
            $platforms[$pf['Platform']['id']] = $pf['Translation']['name']['string'];
        }
        $this->publish('platforms', $platforms);
        
        // prepare and display view
        $this->pageTitle = 'Collections' . " :: " . sprintf(_('addons_home_pagetitle'), APP_PRETTYNAME);
        $is_ajax = ($method=='ajax');
        $this->publish('is_ajax', $is_ajax, false);
        $this->publish('suppressHeader', true, false);
        $this->publish('suppressLanguageSelector', true, false);
        if ($is_ajax) {
            $this->layout = null;
            $this->render('install', false);
        } else {
            $this->render();
        }
    }

    /**
     * "Success!" screen
     */
    function success() {
        if (isset($_GET['i'])) {
            $installed = explode(',', $_GET['i']);
            $installed = array_filter($installed, 'is_numeric');
            if (!empty($installed)) {
                $addons = $this->Addon->getAddonList($installed);
            } else {
                $addons = array();
            }
        } else {
            $addons = array();
        }
        $this->publish('addons', $addons);
        
        $this->set('cssAdd', array('collection-style'));
        $this->publish('suppressHeader', true, false);
        $this->publish('suppressLanguageSelector', true, false);
        $this->publish('suppressCredits', true, false);
        $this->pageTitle = 'Fashion Your Firefox';
    }

}