We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

action.php 43.6 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
2
/**
3
 * StatusNet, the distributed open-source microblogging tool
Evan Prodromou's avatar
Evan Prodromou committed
4
 *
5 6 7 8 9
 * Base class for all actions (~views)
 *
 * PHP version 5
 *
 * LICENCE: This program is free software: you can redistribute it and/or modify
Evan Prodromou's avatar
Evan Prodromou committed
10 11 12
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Evan Prodromou's avatar
Evan Prodromou committed
13
 *
Evan Prodromou's avatar
Evan Prodromou committed
14 15 16 17
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
Evan Prodromou's avatar
Evan Prodromou committed
18
 *
Evan Prodromou's avatar
Evan Prodromou committed
19 20
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21 22
 *
 * @category  Action
23
 * @package   StatusNet
24 25
 * @author    Evan Prodromou <evan@status.net>
 * @author    Sarven Capadisli <csarven@status.net>
26
 * @copyright 2008 StatusNet, Inc.
27
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28
 * @link      http://status.net/
Evan Prodromou's avatar
Evan Prodromou committed
29
 */
Evan Prodromou's avatar
Evan Prodromou committed
30

31
if (!defined('STATUSNET') && !defined('LACONICA')) {
32 33 34
    exit(1);
}

Evan Prodromou's avatar
Evan Prodromou committed
35
require_once INSTALLDIR.'/lib/noticeform.php';
Evan Prodromou's avatar
Evan Prodromou committed
36 37
require_once INSTALLDIR.'/lib/htmloutputter.php';

38 39 40 41 42 43 44 45 46 47
/**
 * Base class for all actions
 *
 * This is the base class for all actions in the package. An action is
 * more or less a "view" in an MVC framework.
 *
 * Actions are responsible for extracting and validating parameters; using
 * model classes to read and write to the database; and doing ouput.
 *
 * @category Output
48
 * @package  StatusNet
49 50
 * @author   Evan Prodromou <evan@status.net>
 * @author   Sarven Capadisli <csarven@status.net>
51
 * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
52
 * @link     http://status.net/
53 54 55 56 57
 *
 * @see      HTMLOutputter
 */
class Action extends HTMLOutputter // lawsuit
{
58 59
    var $args;

60 61 62 63 64 65 66 67 68 69 70
    /**
     * Constructor
     *
     * Just wraps the HTMLOutputter constructor.
     *
     * @param string  $output URI to output to, default = stdout
     * @param boolean $indent Whether to indent output, default true
     *
     * @see XMLOutputter::__construct
     * @see HTMLOutputter::__construct
     */
71
    function __construct($output='php://output', $indent=null)
72
    {
73
        parent::__construct($output, $indent);
74 75
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
76 77 78 79 80 81 82
    /**
     * For initializing members of the class.
     *
     * @param array $argarray misc. arguments
     *
     * @return boolean true
     */
83 84 85 86 87 88
    function prepare($argarray)
    {
        $this->args =& common_copy_args($argarray);
        return true;
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
89 90 91 92 93
    /**
     * Show page, a template method.
     *
     * @return nothing
     */
94 95
    function showPage()
    {
96 97 98 99
        if (Event::handle('StartShowHTML', array($this))) {
            $this->startHTML();
            Event::handle('EndShowHTML', array($this));
        }
Brian's avatar
Brian committed
100
        if (Event::handle('StartShowHead', array($this))) {
101
            $this->showHead();
Brian's avatar
Brian committed
102 103 104
            Event::handle('EndShowHead', array($this));
        }
        if (Event::handle('StartShowBody', array($this))) {
105
            $this->showBody();
Brian's avatar
Brian committed
106 107 108
            Event::handle('EndShowBody', array($this));
        }
        if (Event::handle('StartEndHTML', array($this))) {
109
            $this->endHTML();
Brian's avatar
Brian committed
110 111
            Event::handle('EndEndHTML', array($this));
        }
112 113
    }

114 115 116 117 118 119 120 121 122 123 124 125 126
    function endHTML()
    {
        global $_startTime;

        if (isset($_startTime)) {
            $endTime = microtime(true);
            $diff = round(($endTime - $_startTime) * 1000);
            $this->raw("<!-- ${diff}ms -->");
        }

        return parent::endHTML();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
127 128 129 130 131
    /**
     * Show head, a template method.
     *
     * @return nothing
     */
132 133 134
    function showHead()
    {
        // XXX: attributes (profile?)
135
        $this->elementStart('head');
136
        if (Event::handle('StartShowHeadElements', array($this))) {
137 138 139 140
            if (Event::handle('StartShowHeadTitle', array($this))) {
                $this->showTitle();
                Event::handle('EndShowHeadTitle', array($this));
            }
141 142 143 144 145 146 147 148
            $this->showShortcutIcon();
            $this->showStylesheets();
            $this->showOpenSearch();
            $this->showFeeds();
            $this->showDescription();
            $this->extraHead();
            Event::handle('EndShowHeadElements', array($this));
        }
149
        $this->elementEnd('head');
150 151
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
152 153 154 155 156
    /**
     * Show title, a template method.
     *
     * @return nothing
     */
157 158 159
    function showTitle()
    {
        $this->element('title', null,
160
                       // TRANS: Page title. %1$s is the title, %2$s is the site name.
161
                       sprintf(_("%1\$s - %2\$s"),
162 163 164 165
                               $this->title(),
                               common_config('site', 'name')));
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
166 167 168 169 170 171 172
    /**
     * Returns the page title
     *
     * SHOULD overload
     *
     * @return string page title
     */
173 174 175

    function title()
    {
176
        // TRANS: Page title for a page without a title set.
177 178 179
        return _("Untitled page");
    }

180 181 182 183 184 185 186 187 188
    /**
     * Show themed shortcut icon
     *
     * @return nothing
     */
    function showShortcutIcon()
    {
        if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/favicon.ico')) {
            $this->element('link', array('rel' => 'shortcut icon',
189
                                         'href' => Theme::path('favicon.ico')));
190
        } else {
191
            // favicon.ico should be HTTPS if the rest of the page is
192
            $this->element('link', array('rel' => 'shortcut icon',
193
                                         'href' => common_path('favicon.ico', StatusNet::isHTTPS())));
194
        }
195 196 197 198

        if (common_config('site', 'mobile')) {
            if (is_readable(INSTALLDIR . '/theme/' . common_config('site', 'theme') . '/apple-touch-icon.png')) {
                $this->element('link', array('rel' => 'apple-touch-icon',
199
                                             'href' => Theme::path('apple-touch-icon.png')));
200 201 202 203 204
            } else {
                $this->element('link', array('rel' => 'apple-touch-icon',
                                             'href' => common_path('apple-touch-icon.png')));
            }
        }
205 206
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
207 208 209 210 211
    /**
     * Show stylesheets
     *
     * @return nothing
     */
212 213
    function showStylesheets()
    {
214
        if (Event::handle('StartShowStyles', array($this))) {
215

216 217 218 219
            // Use old name for StatusNet for compatibility on events

            if (Event::handle('StartShowStatusNetStyles', array($this)) &&
                Event::handle('StartShowLaconicaStyles', array($this))) {
220
                $this->primaryCssLink(null, 'screen, projection, tv, print');
221
                Event::handle('EndShowStatusNetStyles', array($this));
222
                Event::handle('EndShowLaconicaStyles', array($this));
223
            }
224

225 226
            if (Event::handle('StartShowUAStyles', array($this))) {
                $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
227
                               'href="'.Theme::path('css/ie.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
228
                foreach (array(6,7) as $ver) {
229
                    if (file_exists(Theme::file('css/ie'.$ver.'.css', 'base'))) {
230 231
                        // Yes, IE people should be put in jail.
                        $this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
232
                                       'href="'.Theme::path('css/ie'.$ver.'.css', 'base').'?version='.STATUSNET_VERSION.'" /><![endif]');
233 234 235
                    }
                }
                $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
236
                               'href="'.Theme::path('css/ie.css', null).'?version='.STATUSNET_VERSION.'" /><![endif]');
237 238
                Event::handle('EndShowUAStyles', array($this));
            }
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253

            if (Event::handle('StartShowDesign', array($this))) {

                $user = common_current_user();

                if (empty($user) || $user->viewdesigns) {
                    $design = $this->getDesign();

                    if (!empty($design)) {
                        $design->showCSS($this);
                    }
                }

                Event::handle('EndShowDesign', array($this));
            }
254
            Event::handle('EndShowStyles', array($this));
255

256 257 258 259 260 261 262 263 264
            if (common_config('custom_css', 'enabled')) {
                $css = common_config('custom_css', 'css');
                if (Event::handle('StartShowCustomCss', array($this, &$css))) {
                    if (trim($css) != '') {
                        $this->style($css);
                    }
                    Event::handle('EndShowCustomCss', array($this));
                }
            }
265 266 267
        }
    }

268 269 270 271 272 273 274 275 276 277 278 279
    function primaryCssLink($mainTheme=null, $media=null)
    {
        // If the currently-selected theme has dependencies on other themes,
        // we'll need to load their display.css files as well in order.
        $theme = new Theme($mainTheme);
        $baseThemes = $theme->getDeps();
        foreach ($baseThemes as $baseTheme) {
            $this->cssLink('css/display.css', $baseTheme, $media);
        }
        $this->cssLink('css/display.css', $mainTheme, $media);
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
280 281 282 283 284
    /**
     * Show javascript headers
     *
     * @return nothing
     */
285 286
    function showScripts()
    {
287 288
        if (Event::handle('StartShowScripts', array($this))) {
            if (Event::handle('StartShowJQueryScripts', array($this))) {
289
                $this->script('jquery.min.js');
290
                $this->script('jquery.form.min.js');
291
                $this->script('jquery.cookie.min.js');
292
                $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js').'"); }');
293
                $this->script('jquery.joverlay.min.js');
294 295
                Event::handle('EndShowJQueryScripts', array($this));
            }
296 297
            if (Event::handle('StartShowStatusNetScripts', array($this)) &&
                Event::handle('StartShowLaconicaScripts', array($this))) {
298 299 300 301 302 303 304
                if (common_config('site', 'minify')) {
                    $this->script('util.min.js');
                } else {
                    $this->script('util.js');
                    $this->script('xbImportNode.js');
                    $this->script('geometa.js');
                }
305
                $this->showScriptMessages();
306
                // Frame-busting code to avoid clickjacking attacks.
307
                $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
308
                Event::handle('EndShowStatusNetScripts', array($this));
309 310 311 312
                Event::handle('EndShowLaconicaScripts', array($this));
            }
            Event::handle('EndShowScripts', array($this));
        }
313 314
    }

315 316 317 318 319 320 321
    /**
     * Exports a map of localized text strings to JavaScript code.
     *
     * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages
     * events and appending to the array. Try to avoid adding strings that won't be used, as
     * they'll be added to HTML output.
     */
322

323 324 325
    function showScriptMessages()
    {
        $messages = array();
326

327 328 329 330 331 332
        if (Event::handle('StartScriptMessages', array($this, &$messages))) {
            // Common messages needed for timeline views etc...

            // TRANS: Localized tooltip for '...' expansion button on overlong remote messages.
            $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more');

333
            // TRANS: Inline reply form submit button: submits a reply comment.
334
            $messages['reply_submit'] = _m('BUTTON', 'Reply');
335

336
            // TRANS: Placeholder text for inline reply form. Clicking in this box will turn it into a mini notice form.
337
            $messages['reply_placeholder'] = _m('Write a reply...');
338

339
            $messages = array_merge($messages, $this->getScriptMessages());
340

341
	    Event::handle('EndScriptMessages', array($this, &$messages));
342
        }
343

344
        if (!empty($messages)) {
345 346
            $this->inlineScript('SN.messages=' . json_encode($messages));
        }
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
        return $messages;
    }

    /**
     * If the action will need localizable text strings, export them here like so:
     *
     * return array('pool_deepend' => _('Deep end'),
     *              'pool_shallow' => _('Shallow end'));
     *
     * The exported map will be available via SN.msg() to JS code:
     *
     *   $('#pool').html('<div class="deepend"></div><div class="shallow"></div>');
     *   $('#pool .deepend').text(SN.msg('pool_deepend'));
     *   $('#pool .shallow').text(SN.msg('pool_shallow'));
     *
     * Exports a map of localized text strings to JavaScript code.
     *
     * Plugins can add to what's exported on any action by hooking the StartScriptMessages or
     * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't
     * be used, as they'll be added to HTML output.
     */
    function getScriptMessages()
    {
        return array();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
374 375 376 377 378
    /**
     * Show OpenSearch headers
     *
     * @return nothing
     */
379 380
    function showOpenSearch()
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
381 382
        $this->element('link', array('rel' => 'search',
                                     'type' => 'application/opensearchdescription+xml',
383 384
                                     'href' =>  common_local_url('opensearch', array('type' => 'people')),
                                     'title' => common_config('site', 'name').' People Search'));
385
        $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
386 387 388 389
                                     'href' =>  common_local_url('opensearch', array('type' => 'notice')),
                                     'title' => common_config('site', 'name').' Notice Search'));
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
390 391 392 393 394 395 396
    /**
     * Show feed headers
     *
     * MAY overload
     *
     * @return nothing
     */
397 398
    function showFeeds()
    {
399 400 401 402 403 404 405 406 407 408
        $feeds = $this->getFeeds();

        if ($feeds) {
            foreach ($feeds as $feed) {
                $this->element('link', array('rel' => $feed->rel(),
                                             'href' => $feed->url,
                                             'type' => $feed->mimeType(),
                                             'title' => $feed->title));
            }
        }
409 410
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
411 412 413 414 415 416 417
    /**
     * Show description.
     *
     * SHOULD overload
     *
     * @return nothing
     */
418 419 420 421 422
    function showDescription()
    {
        // does nothing by default
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
423 424 425 426 427 428 429
    /**
     * Show extra stuff in <head>.
     *
     * MAY overload
     *
     * @return nothing
     */
430 431 432 433 434
    function extraHead()
    {
        // does nothing by default
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
435 436 437 438 439 440 441
    /**
     * Show body.
     *
     * Calls template methods
     *
     * @return nothing
     */
442 443
    function showBody()
    {
444
        $this->elementStart('body', (common_current_user()) ? array('id' => strtolower($this->trimmed('action')),
445
                                                                    'class' => 'user_in')
446
                            : array('id' => strtolower($this->trimmed('action'))));
447
        $this->elementStart('div', array('id' => 'wrap'));
448 449 450 451
        if (Event::handle('StartShowHeader', array($this))) {
            $this->showHeader();
            Event::handle('EndShowHeader', array($this));
        }
452
        $this->showCore();
453 454 455 456
        if (Event::handle('StartShowFooter', array($this))) {
            $this->showFooter();
            Event::handle('EndShowFooter', array($this));
        }
sarven's avatar
Minor  
sarven committed
457
        $this->elementEnd('div');
458
        $this->showScripts();
459
        $this->elementEnd('body');
460 461
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
462 463 464 465 466 467 468
    /**
     * Show header of the page.
     *
     * Calls template methods
     *
     * @return nothing
     */
469 470
    function showHeader()
    {
sarven's avatar
sarven committed
471
        $this->elementStart('div', array('id' => 'header'));
472 473
        $this->showLogo();
        $this->showPrimaryNav();
474 475 476 477 478
        if (Event::handle('StartShowSiteNotice', array($this))) {
            $this->showSiteNotice();

            Event::handle('EndShowSiteNotice', array($this));
        }
479

sarven's avatar
sarven committed
480
        $this->elementEnd('div');
481 482
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
483 484 485 486 487
    /**
     * Show configured logo.
     *
     * @return nothing
     */
488 489
    function showLogo()
    {
490
        $this->elementStart('address', array('id' => 'site_contact',
491
                                             'class' => 'vcard'));
492
        if (Event::handle('StartAddressData', array($this))) {
Evan Prodromou's avatar
Evan Prodromou committed
493
            if (common_config('singleuser', 'enabled')) {
494
                $user = User::singleUser();
Evan Prodromou's avatar
Evan Prodromou committed
495
                $url = common_local_url('showstream',
496
                                        array('nickname' => $user->nickname));
497 498 499
            } else if (common_logged_in()) {
                $cur = common_current_user();
                $url = common_local_url('all', array('nickname' => $cur->nickname));
Evan Prodromou's avatar
Evan Prodromou committed
500 501 502
            } else {
                $url = common_local_url('public');
            }
503

504
            $this->elementStart('a', array('class' => 'url home bookmark',
Evan Prodromou's avatar
Evan Prodromou committed
505
                                           'href' => $url));
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529

            if (StatusNet::isHTTPS()) {
                $logoUrl = common_config('site', 'ssllogo');
                if (empty($logoUrl)) {
                    // if logo is an uploaded file, try to fall back to HTTPS file URL
                    $httpUrl = common_config('site', 'logo');
                    if (!empty($httpUrl)) {
                        $f = File::staticGet('url', $httpUrl);
                        if (!empty($f) && !empty($f->filename)) {
                            // this will handle the HTTPS case
                            $logoUrl = File::url($f->filename);
                        }
                    }
                }
            } else {
                $logoUrl = common_config('site', 'logo');
            }

            if (empty($logoUrl) && file_exists(Theme::file('logo.png'))) {
                // This should handle the HTTPS case internally
                $logoUrl = Theme::path('logo.png');
            }

            if (!empty($logoUrl)) {
530
                $this->element('img', array('class' => 'logo photo',
531
                                            'src' => $logoUrl,
532 533
                                            'alt' => common_config('site', 'name')));
            }
534

535
            $this->text(' ');
536 537
            $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
            $this->elementEnd('a');
538

539
            Event::handle('EndAddressData', array($this));
sarven's avatar
sarven committed
540
        }
541
        $this->elementEnd('address');
542 543
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
544 545 546 547 548
    /**
     * Show primary navigation.
     *
     * @return nothing
     */
549 550
    function showPrimaryNav()
    {
Evan Prodromou's avatar
Evan Prodromou committed
551
        $this->elementStart('div', array('id' => 'site_nav_global_primary'));
552 553
        $pn = new PrimaryNav($this);
        $pn->show();
Evan Prodromou's avatar
Evan Prodromou committed
554
        $this->elementEnd('div');
555
    }
556

Robin Millette's avatar
phpdocs  
Robin Millette committed
557 558 559 560 561
    /**
     * Show site notice.
     *
     * @return nothing
     */
562 563
    function showSiteNotice()
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
564
        // Revist. Should probably do an hAtom pattern here
565 566
        $text = common_config('site', 'notice');
        if ($text) {
567
            $this->elementStart('div', array('id' => 'site_notice',
568
                                            'class' => 'system_notice'));
569
            $this->raw($text);
570
            $this->elementEnd('div');
571
        }
572
    }
573

Robin Millette's avatar
phpdocs  
Robin Millette committed
574 575 576 577 578 579 580
    /**
     * Show notice form.
     *
     * MAY overload if no notice form needed... or direct message box????
     *
     * @return nothing
     */
581 582
    function showNoticeForm()
    {
583 584 585 586 587 588 589 590 591 592 593
        $tabs = array('status' => _('Status'));

        $this->elementStart('div', 'input_forms');

        if (Event::handle('StartShowEntryForms', array(&$tabs))) {

            $this->elementStart('ul', array('class' => 'nav',
                                            'id' => 'input_form_nav'));

            foreach ($tabs as $tag => $title) {

Evan Prodromou's avatar
Evan Prodromou committed
594 595
                $attrs = array('id' => 'input_form_nav_'.$tag,
                               'class' => 'input_form_nav_tab');
596 597 598 599 600 601 602 603

                if ($tag == 'status') {
                    $attrs['class'] = 'current';
                }

                $this->elementStart('li', $attrs);

                $this->element('a',
Evan Prodromou's avatar
Evan Prodromou committed
604
                               array('href' => 'javascript:SN.U.switchInputFormTab("'.$tag.'")'),
605 606 607 608 609 610 611 612 613 614 615 616
                               $title);
                $this->elementEnd('li');
            }

            $this->elementEnd('ul');

            foreach ($tabs as $tag => $title) {

                $attrs = array('class' => 'input_form',
                               'id' => 'input_form_'.$tag);

                if ($tag == 'status') {
Evan Prodromou's avatar
Evan Prodromou committed
617
                    $attrs['class'] .= ' current';
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
                }

                $this->elementStart('div', $attrs);

                $form = null;

                if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) {
                    if ($tag == 'status') {
                        $form = new NoticeForm($this);
                    }
                    Event::handle('EndMakeEntryForm', array($tag, $this, $form));
                }

                if (!empty($form)) {
                    $form->show();
                }
Evan Prodromou's avatar
Evan Prodromou committed
634 635

                $this->elementEnd('div');
636 637
            }
        }
Evan Prodromou's avatar
Evan Prodromou committed
638 639

        $this->elementEnd('div');
640
    }
641

Robin Millette's avatar
phpdocs  
Robin Millette committed
642 643 644 645 646 647 648
    /**
     * Show anonymous message.
     *
     * SHOULD overload
     *
     * @return nothing
     */
649 650
    function showAnonymousMessage()
    {
651
        // needs to be defined by the class
652
    }
653

Robin Millette's avatar
phpdocs  
Robin Millette committed
654 655 656 657 658 659 660
    /**
     * Show core.
     *
     * Shows local navigation, content block and aside.
     *
     * @return nothing
     */
661 662
    function showCore()
    {
sarven's avatar
sarven committed
663
        $this->elementStart('div', array('id' => 'core'));
Sarven Capadisli's avatar
Sarven Capadisli committed
664 665 666 667
        if (Event::handle('StartShowLocalNavBlock', array($this))) {
            $this->showLocalNavBlock();
            Event::handle('EndShowLocalNavBlock', array($this));
        }
668 669 670 671
        if (Event::handle('StartShowContentBlock', array($this))) {
            $this->showContentBlock();
            Event::handle('EndShowContentBlock', array($this));
        }
672 673 674 675
        if (Event::handle('StartShowAside', array($this))) {
            $this->showAside();
            Event::handle('EndShowAside', array($this));
        }
676 677 678
        $this->elementEnd('div');
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
679 680 681 682 683
    /**
     * Show local navigation block.
     *
     * @return nothing
     */
684 685
    function showLocalNavBlock()
    {
686 687 688
        // Need to have this ID for CSS; I'm too lazy to add it to
        // all menus
        $this->elementStart('div', array('id' => 'site_nav_local_views'));
689
        $this->showLocalNav();
690
        $this->elementEnd('div');
691 692
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
693 694 695 696 697 698 699
    /**
     * Show local navigation.
     *
     * SHOULD overload
     *
     * @return nothing
     */
700
    function showLocalNav()
701
    {
702 703
        $nav = new DefaultLocalNav($this);
        $nav->show();
704 705
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
706
    /**
707 708 709 710 711 712 713 714
     * Show menu for an object (group, profile)
     *
     * @return nothing
     */
    function showObjectNavBlock()
    {
        // Need to have this ID for CSS; I'm too lazy to add it to
        // all menus
Brion Vibber's avatar
Brion Vibber committed
715 716
        $this->elementStart('div', array('id' => 'site_nav_object',
                                         'class' => 'section'));
717 718 719 720 721 722 723 724 725 726 727 728 729 730
        $this->showObjectNav();
        $this->elementEnd('div');
    }

    /**
     * Show object navigation.
     *
     * If there are things to do with this object, show it here.
     *
     * @return nothing
     */
    function showObjectNav()
    {
        /* Nothing here. */
731 732
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
733 734 735 736 737
    /**
     * Show content block.
     *
     * @return nothing
     */
738 739
    function showContentBlock()
    {
740
        $this->elementStart('div', array('id' => 'content'));
741 742 743 744 745 746
        if (common_logged_in()) {
            if (Event::handle('StartShowNoticeForm', array($this))) {
                $this->showNoticeForm();
                Event::handle('EndShowNoticeForm', array($this));
            }
        }
747 748 749 750
        if (Event::handle('StartShowPageTitle', array($this))) {
            $this->showPageTitle();
            Event::handle('EndShowPageTitle', array($this));
        }
751
        $this->showPageNoticeBlock();
Evan Prodromou's avatar
Evan Prodromou committed
752 753
        $this->elementStart('div', array('id' => 'content_inner'));
        // show the actual content (forms, lists, whatever)
754
        $this->showContent();
sarven's avatar
sarven committed
755
        $this->elementEnd('div');
Evan Prodromou's avatar
Evan Prodromou committed
756
        $this->elementEnd('div');
757 758
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
759 760 761 762 763 764 765 766
    /**
     * Show page title.
     *
     * @return nothing
     */
    function showPageTitle()
    {
        $this->element('h1', null, $this->title());
767 768
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
769 770 771
    /**
     * Show page notice block.
     *
772 773 774 775 776 777
     * Only show the block if a subclassed action has overrided
     * Action::showPageNotice(), or an event handler is registered for
     * the StartShowPageNotice event, in which case we assume the
     * 'page_notice' definition list is desired.  This is to prevent
     * empty 'page_notice' definition lists from being output everywhere.
     *
Robin Millette's avatar
phpdocs  
Robin Millette committed
778 779
     * @return nothing
     */
780 781
    function showPageNoticeBlock()
    {
782 783 784 785 786
        $rmethod = new ReflectionMethod($this, 'showPageNotice');
        $dclass = $rmethod->getDeclaringClass()->getName();

        if ($dclass != 'Action' || Event::hasHandler('StartShowPageNotice')) {

787
            $this->elementStart('div', array('id' => 'page_notice',
788 789 790 791 792
                                            'class' => 'system_notice'));
            if (Event::handle('StartShowPageNotice', array($this))) {
                $this->showPageNotice();
                Event::handle('EndShowPageNotice', array($this));
            }
793
            $this->elementEnd('div');
794
        }
Robin Millette's avatar
phpdocs  
Robin Millette committed
795
    }
796

Robin Millette's avatar
phpdocs  
Robin Millette committed
797 798 799 800 801 802 803
    /**
     * Show page notice.
     *
     * SHOULD overload (unless there's not a notice)
     *
     * @return nothing
     */
804 805 806
    function showPageNotice()
    {
    }
807

Robin Millette's avatar
phpdocs  
Robin Millette committed
808 809 810 811 812 813 814
    /**
     * Show content.
     *
     * MUST overload (unless there's not a notice)
     *
     * @return nothing
     */
815 816 817 818
    function showContent()
    {
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
819 820 821 822 823
    /**
     * Show Aside.
     *
     * @return nothing
     */
824 825
    function showAside()
    {
sarven's avatar
sarven committed
826 827
        $this->elementStart('div', array('id' => 'aside_primary',
                                         'class' => 'aside'));
Brion Vibber's avatar
Brion Vibber committed
828 829 830 831
        if (Event::handle('StartShowObjectNavBlock', array($this))) {
            $this->showObjectNavBlock();
            Event::handle('EndShowObjectNavBlock', array($this));
        }
832 833 834 835
        if (Event::handle('StartShowSections', array($this))) {
            $this->showSections();
            Event::handle('EndShowSections', array($this));
        }
836 837 838 839
        if (Event::handle('StartShowExportData', array($this))) {
            $this->showExportData();
            Event::handle('EndShowExportData', array($this));
        }
sarven's avatar
sarven committed
840
        $this->elementEnd('div');
841 842
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
843 844 845
    /**
     * Show export data feeds.
     *
846
     * @return void
Robin Millette's avatar
phpdocs  
Robin Millette committed
847
     */
848 849
    function showExportData()
    {
850 851 852 853 854
        $feeds = $this->getFeeds();
        if ($feeds) {
            $fl = new FeedList($this);
            $fl->show($feeds);
        }
855 856
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
857 858 859 860 861 862 863 864 865
    /**
     * Show sections.
     *
     * SHOULD overload
     *
     * @return nothing
     */
    function showSections()
    {
866 867 868
        // for each section, show it
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
869 870 871 872 873
    /**
     * Show footer.
     *
     * @return nothing
     */
874 875
    function showFooter()
    {
sarven's avatar
sarven committed
876
        $this->elementStart('div', array('id' => 'footer'));
877 878 879 880 881
        if (Event::handle('StartShowInsideFooter', array($this))) {
            $this->showSecondaryNav();
            $this->showLicenses();
            Event::handle('EndShowInsideFooter', array($this));
        }
sarven's avatar
sarven committed
882
        $this->elementEnd('div');
883 884
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
885 886 887 888 889
    /**
     * Show secondary navigation.
     *
     * @return nothing
     */
890 891
    function showSecondaryNav()
    {
892 893
        $sn = new SecondaryNav($this);
        $sn->show();
894 895
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
896 897 898 899 900
    /**
     * Show licenses.
     *
     * @return nothing
     */
901 902
    function showLicenses()
    {
903
        $this->showStatusNetLicense();
904 905 906
        $this->showContentLicense();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
907
    /**
908
     * Show StatusNet license.
Robin Millette's avatar
phpdocs  
Robin Millette committed
909 910 911
     *
     * @return nothing
     */
912
    function showStatusNetLicense()
913 914
    {
        if (common_config('site', 'broughtby')) {
915
            // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
916 917 918
            // TRANS: Text between [] is a link description, text between () is the link itself.
            // TRANS: Make sure there is no whitespace between "]" and "(".
            // TRANS: "%%site.broughtby%%" is the value of the variable site.broughtby
919
            $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%).');
920
        } else {
921 922
            // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
            $instr = _('**%%site.name%%** is a microblogging service.');
923
        }
924
        $instr .= ' ';
925
        // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
926 927 928
        // TRANS: Make sure there is no whitespace between "]" and "(".
        // TRANS: Text between [] is a link description, text between () is the link itself.
        // TRANS: %s is the version of StatusNet that is being used.
Evan Prodromou's avatar
Evan Prodromou committed
929
        $instr .= sprintf(_('It runs the [StatusNet](http://status.net/) microblogging software, version %s, available under the [GNU Affero General Public License](http://www.fsf.org/licensing/licenses/agpl-3.0.html).'), STATUSNET_VERSION);
930
        $output = common_markup_to_html($instr);
931
        $this->raw($output);
932 933 934
        // do it
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
935 936 937 938 939
    /**
     * Show content license.
     *
     * @return nothing
     */
940 941
    function showContentLicense()
    {
942
        if (Event::handle('StartShowContentLicense', array($this))) {
943 944
            switch (common_config('license', 'type')) {
            case 'private':
945 946
                // TRANS: Content license displayed when license is set to 'private'.
                // TRANS: %1$s is the site name.
947 948 949 950 951
                $this->element('p', null, sprintf(_('Content and data of %1$s are private and confidential.'),
                                                  common_config('site', 'name')));
                // fall through
            case 'allrightsreserved':
                if (common_config('license', 'owner')) {
952 953
                    // TRANS: Content license displayed when license is set to 'allrightsreserved'.
                    // TRANS: %1$s is the copyright owner.
954 955 956
                    $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
                                                      common_config('license', 'owner')));
                } else {
957
                    // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
958 959 960 961 962 963
                    $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
                }
                break;
            case 'cc': // fall through
            default:
                $this->elementStart('p');
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981

                $image    = common_config('license', 'image');
                $sslimage = common_config('license', 'sslimage');

                if (StatusNet::isHTTPS()) {
                    if (!empty($sslimage)) {
                        $url = $sslimage;
                    } else if (preg_match('#^http://i.creativecommons.org/#', $image)) {
                        // CC support HTTPS on their images
                        $url = preg_replace('/^http/', 'https', $image);
                    } else {
                        // Better to show mixed content than no content
                        $url = $image;
                    }
                } else {
                    $url = $image;
                }

982
                $this->element('img', array('id' => 'license_cc',
983
                                            'src' => $url,
984 985 986
                                            'alt' => common_config('license', 'title'),
                                            'width' => '80',
                                            'height' => '15'));
987
                $this->text(' ');
988 989
                // TRANS: license message in footer.
                // TRANS: %1$s is the site name, %2$s is a link to the license URL, with a licence name set in configuration.
990 991 992 993 994 995 996 997 998
                $notice = _('All %1$s content and data are available under the %2$s license.');
                $link = "<a class=\"license\" rel=\"external license\" href=\"" .
                        htmlspecialchars(common_config('license', 'url')) .
                        "\">" .
                        htmlspecialchars(common_config('license', 'title')) .
                        "</a>";
                $this->raw(sprintf(htmlspecialchars($notice),
                                   htmlspecialchars(common_config('site', 'name')),
                                   $link));
999 1000 1001 1002
                $this->elementEnd('p');
                break;
            }

1003 1004
            Event::handle('EndShowContentLicense', array($this));
        }
1005 1006
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1007 1008 1009 1010 1011 1012 1013
    /**
     * Return last modified, if applicable.
     *
     * MAY override
     *
     * @return string last modified http header
     */
1014
    function lastModified()
1015
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
1016 1017
        // For comparison with If-Last-Modified
        // If not applicable, return null
1018 1019 1020
        return null;
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1021 1022 1023 1024 1025 1026 1027
    /**
     * Return etag, if applicable.
     *
     * MAY override
     *
     * @return string etag http header
     */
1028 1029 1030 1031 1032
    function etag()
    {
        return null;
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1033 1034 1035 1036 1037
    /**
     * Return true if read only.
     *
     * MAY override
     *
1038 1039
     * @param array $args other arguments
     *
Robin Millette's avatar
phpdocs  
Robin Millette committed
1040 1041
     * @return boolean is read only action?
     */
Evan Prodromou's avatar
Evan Prodromou committed
1042
    function isReadOnly($args)
1043 1044 1045 1046
    {
        return false;
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1047 1048 1049 1050 1051 1052 1053 1054
    /**
     * Returns query argument or default value if not found
     *
     * @param string $key requested argument
     * @param string $def default value to return if $key is not provided
     *
     * @return boolean is read only action?
     */
1055 1056 1057 1058 1059 1060 1061 1062 1063
    function arg($key, $def=null)
    {
        if (array_key_exists($key, $this->args)) {
            return $this->args[$key];
        } else {
            return $def;
        }
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1064 1065 1066 1067 1068 1069 1070 1071
    /**
     * Returns trimmed query argument or default value if not found
     *
     * @param string $key requested argument
     * @param string $def default value to return if $key is not provided
     *
     * @return boolean is read only action?
     */
1072 1073 1074
    function trimmed($key, $def=null)
    {
        $arg = $this->arg($key, $def);
Robin Millette's avatar
phpdocs  
Robin Millette committed
1075
        return is_string($arg) ? trim($arg) : $arg;
1076 1077
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1078 1079 1080 1081 1082 1083 1084
    /**
     * Handler method
     *
     * @param array $argarray is ignored since it's now passed in in prepare()
     *
     * @return boolean is read only action?
     */
1085 1086
    function handle($argarray=null)
    {
1087
        header('Vary: Accept-Encoding,Cookie');
1088

Robin Millette's avatar
phpdocs  
Robin Millette committed
1089
        $lm   = $this->lastModified();
1090
        $etag = $this->etag();
1091

1092 1093 1094
        if ($etag) {
            header('ETag: ' . $etag);
        }
1095

1096 1097
        if ($lm) {
            header('Last-Modified: ' . date(DATE_RFC1123, $lm));
Evan Prodromou's avatar
Evan Prodromou committed
1098 1099 1100
            if ($this->isCacheable()) {
                header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', 0 ) . ' GMT' );
                header( "Cache-Control: private, must-revalidate, max-age=0" );