Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/views/elements/amo2009/install.thtml
blob: e938571e39de7acb8130117398b57283ca4f36f0 (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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?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) 2006
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *   l.m.orchard <lorchard@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 ***** */

/**
 * Required:
 *   $addon with Translation and File bound
 *   $this->controller->Platform or $platforms
 *   $this->controller->Image
 *
 * Optional:
 *   $flags: defaults to [], could contain 'recommended' or 'experimental'
 *   $buttonSize: defaults to '8x9'
 *   $buttonClass: defaults to ''
 *
 * This element accepts the following as overrides or instead of $addon:
 * - $addonIconPath
 * - $addonName
 * - $addonId
 * - $addonFiles
 * - $is_latest -- link to "download/latest" shortcut (default false)
 * - $addonEULA
 * - $addonStatus
 * - $allPlatforms - There should only be one platform in the list when this is used on the eula view.
 * - $addonType - default ADDON_EXTENSION
 * - $collection_uuid - if this add-on download is collection related, this will set a tracking code in the download ID. default null
 * - $buttonMessage - default 'a_install'
 * - $showInstructions - Show install instructions for Thunderbird or Seamonkey, defaults to true
 */

if (isset($addon)) {
    if (!isset($addonIconPath))
        $addonIconPath = $this->controller->Image->getAddonIconURL($addon['Addon']['id']);
    if (!isset($addonName))
        $addonName = $addon['Translation']['name']['string'];
    if (!isset($addonId))
        $addonId = $addon['Addon']['id'];
    if (!isset($addonFiles))
        $addonFiles = $addon['File'];
    if (!isset($addonEULA))
        $addonEULA = $addon['Translation']['eula']['string'];
    if (!isset($addonStatus))
        $addonStatus = $addon['Addon']['status'];
    if (!isset($is_latest))
        $is_latest = ($addonStatus == STATUS_PUBLIC);
    if (!isset($compatible_apps))
        $compatible_apps = $addon['compatible_apps'];
    if (!isset($addonType))
        $addonType = $addon['Addon']['addontype_id'];
}

$compatible_app_ids = array();
foreach ($compatible_apps as $var => $val) {
    $compatible_app_ids[] = $val['Application']['application_id'];
}

if (!isset($platforms)) {
    $this->controller->Platform->unbindFully();
    $platforms = $this->controller->Platform->findAll();
}

if (!isset($flags)) {
    $flags = array();
}

if (!isset($buttonSize)) {
    $buttonSize = '8x9';
}

if (!isset($buttonClass)) {
    $buttonClass = '';
}

?>
<?php
global $browser_apps, $experimental_status, $valid_status;

/* prepare add-on type */
if (!isset($addonType)) $addonType = ADDON_EXTENSION;

if (!isset($showInstructions)) $showInstructions = true;

/* logged in users can install experimental add-ons */
$loggedin = $this->controller->Session->check('User');

/* use "latest public file" permalink if this is the latest version. Defaults to false. */
if (!isset($is_latest)) $is_latest = false;

/* "Install" for browser apps, "Download" for non-browser apps */
if (!isset($buttonMessage)) {
    if (!in_array(APP_ID, $browser_apps) || !in_array(APP_ID, $compatible_app_ids)) {
        $buttonMessage = _('a_download');
    } else {
        $buttonMessage = sprintf(_('install_button_text'), APP_PRETTYNAME, "%s");
    }
}


/* Prepare addon icons */
if (empty($addonIconPath)) {
    switch ($addonType) {
    case ADDON_THEME:
        $addonIconPath = $html->urlImage(DEFAULT_THEME_ICON);
        break;
    default:
        $addonIconPath = $html->urlImage(DEFAULT_ADDON_ICON);
        break;
    }
}

if (count($addonFiles) < 1) {
    // This should never happen - this would mean the file didn't exist.
    echo '<p class="install-button">'._('install_error_addon_not_found').'</p>';

} else {

    // The same add-on can now appear more than once on the same page.
    // Add a unique id suffix to keep IDs unique.
    $uniqueId = '-' . dechex(mt_rand());

    $versionId = $addonFiles[0]['version_id'] . $uniqueId;

    echo '<div id="install-'.$versionId.'" class="install install-container">';
    foreach ($addonFiles as $file) {
        // never display files with invalid statuses (bug 427176)
        if (!in_array($file['status'], $valid_status)) continue;

        // Used for echoing values in our loop
        $_platform_name           = '';
        $_class_platform_string   = '';
        $_install_platform_string = '';

        // ugh...
        foreach ($platforms as $platform) {
            // We found a matching platform
            if ($platform['Platform']['id'] == $file['platform_id']) {
                $_platform_name = $platform['Translation']['name']['string'];
            }
        }

        if (!empty($_platform_name)) {
            $_class_platform_string   = "platform-{$_platform_name}";
            if ($_platform_name != "ALL") {// special case
                $_install_platform_string = "($_platform_name)";
            }
        }

        // run the right javascript action for the addon type in question
        $installTriggerName = "installTrigger" . $file['id'] . $uniqueId;

        if ($addonType != ADDON_SEARCH) {
            /* install for search  */
            if (in_array(APP_ID, $browser_apps)) {
                // prepare link options for browser apps
                $linkOptions = array(
                    'id' => $installTriggerName,
                    'title'     => sprintf(_('install_button_title'), $addonName, APP_PRETTYNAME),
                    'addonName' => $addonName,
                    'addonIcon' => $addonIconPath,
                    'addonHash' => $file['hash'],
                    'jsInstallMethod' => 'browser_app_addon_install',
                    );
            } else {
                // prepare link options for non-browser apps
                $linkOptions = array('id' => $installTriggerName,
                    'title'=>sprintf(_('install_download'),$addonName));
            }
        } else {
            /* prepare link options for search engines */
            $linkOptions = array(
                'id'        => $installTriggerName,
                'title'     => sprintf(_('install_button_title'), $addonName, APP_PRETTYNAME),
                'engineURL' => FULL_BASE_URL . $html->urlFile($file['id'], $file['filename'], @$collection_uuid),
                // search engines use a special install method
                'jsInstallMethod' => 'search_engine_install',
                );
        }

        $linkOptions['class'] = 'button positive ' . $buttonClass;
        ?>

        <?php
        $install_button_image = '<img src="'.$html->url(
            "/img/amo2009/icons/buttons/plus-green-{$buttonSize}.gif", null, false, false
        ).'" alt="" />';
        $install_button_html = '';
        if (empty($addonEULA)) {
            // wipe disallowed characters off the displayed filename
            $addon_filename = $html->entities(preg_replace(
                INVALID_FILENAME_CHARS, '_', $html->unsanitize($file['filename'])));

            // if this is the latest public version, use perma-URL. Otherwise, link directly to file.
            $linktitle = $install_button_image.'<span class="install-button-text">'.sprintf(_('a_download'),$_install_platform_string).'</span>';
            if ($is_latest && $file['status'] == STATUS_PUBLIC) {
                $latest_permalink = "/downloads/latest/{$addonId}";
                if ($file['platform_id'] != PLATFORM_ALL) $latest_permalink .= "/platform:{$file['platform_id']}";

                $file_id = $this->controller->File->getLatestFileByAddonId($addonId);
                $file_data = $this->controller->File->findById($file_id);
                $path_info = pathinfo($file_data['File']['filename']);

                $latest_permalink .= "/addon-${addonId}-latest.".$path_info['extension'];

                if (!empty($collection_uuid)) $latest_permalink .= "?collection_id={$collection_uuid}";

                $install_button_html .= $html->link($linktitle, $latest_permalink, $linkOptions);
            } else {
                $install_button_html .= $html->linkFile($file['id'], $linktitle, null,
                    $linkOptions, false, $addon_filename, @$collection_uuid);
            }
        } else {
            $eula_attributes = array('id' => $installTriggerName,
                'class' => $linkOptions['class'],
                'addonName' => $addonName,
                'title' => sprintf(_('install_button_title'), $addonName, APP_PRETTYNAME),
                'isEULAPageLink' => 'true');

            $link_url = "/addons/policy/0/{$addonId}/{$file['id']}";

            if (!empty($collection_uuid)) $link_url .= "?collection_id={$collection_uuid}";

            $install_button_html .= $html->link(
                $install_button_image.'<span class="install-button-text">'.sprintf(_('a_download'),$_install_platform_string).'</span>',
                $link_url,
                $eula_attributes, false, false);
        }

        /**
         * For logged-in users or public add-ons, show the standard install button.
         */
        if ($loggedin || !in_array($file['status'], $experimental_status) || (isset($is_eula_page) && isset($_GET['confirmed']))):
        ?>
            <p class="install-button <?=$_class_platform_string?>">
                <?= $install_button_html ?>
            </p>
        <?php
        /**
         * For sandbox add-ons, show a frozen version of the standard install button.
         * Users unfreeze the button client-side by checking a confirmation box.
         * Non-JS users must unfreeze by logging in.
         */
        else:
        ?>
            <div class="exp-loggedout">
                <div class="exp-confirm-install" style="display: none">
                    <div class="exp-desc">
                    <strong class="compatmsg">
                        <input type="checkbox" name="confirm-<?= $addonId ?>" />
                        <?= sprintf(___('install_button_confirm_exp_install'), $html->url('/pages/faq#experimental-addons')) ?>
                    </strong>
                    </div>
                </div>

                <p class="install-button <?=$_class_platform_string?>" style="display: none">
                <?= $install_button_html ?>
                </p>

                <noscript>
                <p class="install-button <?=$_class_platform_string?>">
                <?php
                $login_url = $html->login_url('/'.LANG.'/'.APP_SHORTNAME."/addon/{$addonId}", false);
                $attributes = array('id' => $installTriggerName,
                    'addonName' => $addonName,
                    'title' => sprintf(_('install_button_title'), $addonName, APP_PRETTYNAME));
                echo $html->link('<span><span><span><strong>'
                    .sprintf(_('a_download'),$_install_platform_string)
                    .'</strong></span></span></span>',
                    $login_url, $attributes, false, false);

                $exp_addon_url = "/pages/faq#experimental-addons";
                ?>
                </p>
                <?= sprintf(___('install_a_login_to_install'), $html->url($login_url), $html->url($exp_addon_url)); ?>
                </noscript>
            </div>
        <?php endif; ?>
	<script type="text/javascript">
        installVersusDownloadCheck("<?=$installTriggerName?>", "<?=sprintf($buttonMessage, $_install_platform_string) ?>", "<?=sprintf(_('a_download'), $_install_platform_string)?>");
	</script>
    <?php
    }
    ?>

    <?php if (in_array('recommended', $flags)) { ?>
        <strong><?=___('addon_listitem_flag_recommended')?></strong>
    <?php } else if (in_array('experimental', $flags) && $loggedin) { ?>
        <strong><?=_('addon_listitem_flag_experimental')?></strong>
    <?php }
    
    // If we're looking at thunderbird pages, and there is no EULA, show the TB
    // install instructions.  Bug 401272 fixed the button so it downloads instead of
    // installs, but it doesn't hurt to have these instructions still.
    if (empty($addonEULA) && $showInstructions && (APP_ID == APP_THUNDERBIRD || APP_ID == APP_SUNBIRD)):
        $installPopupName = "install-popup-" . $versionId;
        if (APP_ID == APP_THUNDERBIRD):
            $installTitle = _('addons_install_in_thunderbird_title');
            $installBody = _('addons_install_in_thunderbird');
        elseif (APP_ID == APP_SUNBIRD):
            $installTitle = _('addons_install_in_sunbird_title');
            $installBody = _('addons_install_in_sunbird');
        endif;
    ?>
        <div class="app_install">
            <div id="<?= $installPopupName ?>" class="app_install-popup-container">
                <div class="app_install-popup">
                    <div class="app_install-popup-inner">
                        <h3><?= $installTitle ?></h3>
                        <?= $installBody ?>
    </div>
                </div>
            </div>
        </div>

        <script type="text/javascript">
    <?php
        foreach ($addonFiles as $file):
            $installTriggerName = "installTrigger" . $file['id'] . $uniqueId;
    ?>
            initDownloadPopup("<?=$installTriggerName?>", "<?=$installPopupName?>");
    <?php
        endforeach;
    ?>
        </script>
    <?php
    endif;
    ?>
    </div>

    <?php
    // Show platform-specific install buttons only, except on version history page
    $versionsPage = ($this->name == 'Addons' && $this->action == 'versions');
    echo '<script type="text/javascript">'.
         'setTimeout(function() {';
    echo "initExpConfirm('{$versionId}');";
    if (!$versionsPage) {
        echo "fixPlatformLinks('{$versionId}', document.getElementById('{$installTriggerName}').getAttribute('addonName'));";
    }

    // show add-on compatibility hints for Firefox
    if (APP_ID == APP_FIREFOX && !empty($compatible_apps)) {
        $fromVer = $toVer = null;
        foreach ($compatible_apps as $app) {
            if ($app['Application']['application_id'] == APP_FIREFOX) {
                $fromVer = $app['Min_Version']['version'];
                $toVer = $app['Max_Version']['version'];
            }
        }
        if ($fromVer && $toVer) {
            if (!$versionsPage) {
                // show "ignore" link for logged in users only
                $_loggedin = $this->controller->Session->check('User');
                echo "addCompatibilityHints('{$addonId}', '{$versionId}', "
                    ."'{$fromVer}', '{$toVer}', '{$_loggedin}');";
            } else {
                // allow determining latest compatible version for version history page
                echo "addons_history.addVersion('{$versionId}','{$fromVer}','{$toVer}');";
            }
        }

    }
    echo "},0);".
         '</script>';
    ?>

<?php
}
?>