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

action.php 47.1 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
    function prepare($argarray)
    {
        $this->args =& common_copy_args($argarray);
86 87 88 89 90

        if ($this->boolean('ajax')) {
            StatusNet::setAjax(true);
        }

91 92 93
        return true;
    }

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

121 122 123 124 125 126 127 128 129 130 131 132 133
    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
134 135 136 137 138
    /**
     * Show head, a template method.
     *
     * @return nothing
     */
139 140 141
    function showHead()
    {
        // XXX: attributes (profile?)
142
        $this->elementStart('head');
143
        if (Event::handle('StartShowHeadElements', array($this))) {
144 145 146 147
            if (Event::handle('StartShowHeadTitle', array($this))) {
                $this->showTitle();
                Event::handle('EndShowHeadTitle', array($this));
            }
148 149 150 151 152 153 154 155
            $this->showShortcutIcon();
            $this->showStylesheets();
            $this->showOpenSearch();
            $this->showFeeds();
            $this->showDescription();
            $this->extraHead();
            Event::handle('EndShowHeadElements', array($this));
        }
156
        $this->elementEnd('head');
157 158
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
159 160 161 162 163
    /**
     * Show title, a template method.
     *
     * @return nothing
     */
164 165 166
    function showTitle()
    {
        $this->element('title', null,
167
                       // TRANS: Page title. %1$s is the title, %2$s is the site name.
168
                       sprintf(_('%1$s - %2$s'),
169 170 171 172
                               $this->title(),
                               common_config('site', 'name')));
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
173 174 175 176 177 178 179
    /**
     * Returns the page title
     *
     * SHOULD overload
     *
     * @return string page title
     */
180 181 182

    function title()
    {
183
        // TRANS: Page title for a page without a title set.
184
        return _('Untitled page');
185 186
    }

187 188 189 190 191 192 193 194 195
    /**
     * 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',
196
                                         'href' => Theme::path('favicon.ico')));
197
        } else {
198
            // favicon.ico should be HTTPS if the rest of the page is
199
            $this->element('link', array('rel' => 'shortcut icon',
200
                                         'href' => common_path('favicon.ico', StatusNet::isHTTPS())));
201
        }
202 203 204 205

        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',
206
                                             'href' => Theme::path('apple-touch-icon.png')));
207 208 209 210 211
            } else {
                $this->element('link', array('rel' => 'apple-touch-icon',
                                             'href' => common_path('apple-touch-icon.png')));
            }
        }
212 213
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
214 215 216 217 218
    /**
     * Show stylesheets
     *
     * @return nothing
     */
219 220
    function showStylesheets()
    {
221
        if (Event::handle('StartShowStyles', array($this))) {
222

223 224 225 226
            // Use old name for StatusNet for compatibility on events

            if (Event::handle('StartShowStatusNetStyles', array($this)) &&
                Event::handle('StartShowLaconicaStyles', array($this))) {
227
                $this->primaryCssLink(null, 'screen, projection, tv, print');
228
                Event::handle('EndShowStatusNetStyles', array($this));
229
                Event::handle('EndShowLaconicaStyles', array($this));
230
            }
231

232 233
            $this->cssLink(common_path('js/css/smoothness/jquery-ui.css'));

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

            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));
            }
263
            Event::handle('EndShowStyles', array($this));
264

265 266 267 268 269 270 271 272 273
            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));
                }
            }
274 275 276
        }
    }

277 278
    function primaryCssLink($mainTheme=null, $media=null)
    {
279 280 281 282 283 284 285 286
        $theme = new Theme($mainTheme);

        // Some themes may have external stylesheets, such as using the
        // Google Font APIs to load webfonts.
        foreach ($theme->getExternals() as $url) {
            $this->cssLink($url, $mainTheme, $media);
        }

287 288 289 290 291 292 293 294 295
        // If the currently-selected theme has dependencies on other themes,
        // we'll need to load their display.css files as well in order.
        $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
296 297 298 299 300
    /**
     * Show javascript headers
     *
     * @return nothing
     */
301 302
    function showScripts()
    {
303 304
        if (Event::handle('StartShowScripts', array($this))) {
            if (Event::handle('StartShowJQueryScripts', array($this))) {
305 306 307
                if (common_config('site', 'minify')) {
                    $this->script('jquery.min.js');
                    $this->script('jquery.form.min.js');
308
                    $this->script('jquery-ui.min.js');
309 310 311
                    $this->script('jquery.cookie.min.js');
                    $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js').'"); }');
                    $this->script('jquery.joverlay.min.js');
312
                    $this->script('jquery.infieldlabel.min.js');
313 314 315
                } else {
                    $this->script('jquery.js');
                    $this->script('jquery.form.js');
316
                    $this->script('jquery-ui.min.js');
317 318 319
                    $this->script('jquery.cookie.js');
                    $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }');
                    $this->script('jquery.joverlay.js');
320
                    $this->script('jquery.infieldlabel.js');
321
                }
Shashi Gowda's avatar
Shashi Gowda committed
322

323 324
                Event::handle('EndShowJQueryScripts', array($this));
            }
325 326
            if (Event::handle('StartShowStatusNetScripts', array($this)) &&
                Event::handle('StartShowLaconicaScripts', array($this))) {
327 328 329 330 331 332 333
                if (common_config('site', 'minify')) {
                    $this->script('util.min.js');
                } else {
                    $this->script('util.js');
                    $this->script('xbImportNode.js');
                    $this->script('geometa.js');
                }
334
                $this->inlineScript('var _peopletagAC = "' .
335
                    common_local_url('peopletagautocomplete') . '";');
336
                $this->showScriptMessages();
337 338 339 340
                // Anti-framing code to avoid clickjacking attacks in older browsers.
                // This will show a blank page if the page is being framed, which is
                // consistent with the behavior of the 'X-Frame-Options: SAMEORIGIN'
                // header, which prevents framing in newer browser.
341
                if (common_config('javascript', 'bustframes')) {
342
                    $this->inlineScript('if (window.top !== window.self) { document.write = ""; window.top.location = window.self.location; setTimeout(function () { document.body.innerHTML = ""; }, 1); window.self.onload = function () { document.body.innerHTML = ""; }; }');
343
                }
344
                Event::handle('EndShowStatusNetScripts', array($this));
345 346 347 348
                Event::handle('EndShowLaconicaScripts', array($this));
            }
            Event::handle('EndShowScripts', array($this));
        }
349 350
    }

351 352 353 354 355 356 357 358 359 360
    /**
     * 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.
     */
    function showScriptMessages()
    {
        $messages = array();
361

362 363 364 365 366 367
        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');

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

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

374
            $messages = array_merge($messages, $this->getScriptMessages());
375

376
	    Event::handle('EndScriptMessages', array($this, &$messages));
377
        }
378

379
        if (!empty($messages)) {
380 381
            $this->inlineScript('SN.messages=' . json_encode($messages));
        }
382

383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
        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
409 410 411 412 413
    /**
     * Show OpenSearch headers
     *
     * @return nothing
     */
414 415
    function showOpenSearch()
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
416 417
        $this->element('link', array('rel' => 'search',
                                     'type' => 'application/opensearchdescription+xml',
418 419
                                     'href' =>  common_local_url('opensearch', array('type' => 'people')),
                                     'title' => common_config('site', 'name').' People Search'));
420
        $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
421 422 423 424
                                     'href' =>  common_local_url('opensearch', array('type' => 'notice')),
                                     'title' => common_config('site', 'name').' Notice Search'));
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
425 426 427 428 429 430 431
    /**
     * Show feed headers
     *
     * MAY overload
     *
     * @return nothing
     */
432 433
    function showFeeds()
    {
434 435 436 437 438 439 440 441 442 443
        $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));
            }
        }
444 445
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
446 447 448 449 450 451 452
    /**
     * Show description.
     *
     * SHOULD overload
     *
     * @return nothing
     */
453 454 455 456 457
    function showDescription()
    {
        // does nothing by default
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
458 459 460 461 462 463 464
    /**
     * Show extra stuff in <head>.
     *
     * MAY overload
     *
     * @return nothing
     */
465 466 467 468 469
    function extraHead()
    {
        // does nothing by default
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
470 471 472 473 474 475 476
    /**
     * Show body.
     *
     * Calls template methods
     *
     * @return nothing
     */
477 478
    function showBody()
    {
479
        $this->elementStart('body', (common_current_user()) ? array('id' => strtolower($this->trimmed('action')),
480
                                                                    'class' => 'user_in')
481
                            : array('id' => strtolower($this->trimmed('action'))));
482
        $this->elementStart('div', array('id' => 'wrap'));
483 484
        if (Event::handle('StartShowHeader', array($this))) {
            $this->showHeader();
Evan Prodromou's avatar
Evan Prodromou committed
485
            $this->flush();
486 487
            Event::handle('EndShowHeader', array($this));
        }
488
        $this->showCore();
Evan Prodromou's avatar
Evan Prodromou committed
489
        $this->flush();
490 491
        if (Event::handle('StartShowFooter', array($this))) {
            $this->showFooter();
Evan Prodromou's avatar
Evan Prodromou committed
492
            $this->flush();
493 494
            Event::handle('EndShowFooter', array($this));
        }
sarven's avatar
Minor  
sarven committed
495
        $this->elementEnd('div');
496
        $this->showScripts();
497
        $this->elementEnd('body');
498 499
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
500 501 502 503 504 505 506
    /**
     * Show header of the page.
     *
     * Calls template methods
     *
     * @return nothing
     */
507 508
    function showHeader()
    {
sarven's avatar
sarven committed
509
        $this->elementStart('div', array('id' => 'header'));
510 511
        $this->showLogo();
        $this->showPrimaryNav();
512 513 514 515 516
        if (Event::handle('StartShowSiteNotice', array($this))) {
            $this->showSiteNotice();

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

sarven's avatar
sarven committed
518
        $this->elementEnd('div');
519 520
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
521 522 523 524 525
    /**
     * Show configured logo.
     *
     * @return nothing
     */
526 527
    function showLogo()
    {
528
        $this->elementStart('address', array('id' => 'site_contact',
529
                                             'class' => 'vcard'));
530
        if (Event::handle('StartAddressData', array($this))) {
Evan Prodromou's avatar
Evan Prodromou committed
531
            if (common_config('singleuser', 'enabled')) {
532
                $user = User::singleUser();
Evan Prodromou's avatar
Evan Prodromou committed
533
                $url = common_local_url('showstream',
534
                                        array('nickname' => $user->nickname));
535 536 537
            } 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
538 539 540
            } else {
                $url = common_local_url('public');
            }
541

542
            $this->elementStart('a', array('class' => 'url home bookmark',
Evan Prodromou's avatar
Evan Prodromou committed
543
                                           'href' => $url));
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567

            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)) {
568
                $this->element('img', array('class' => 'logo photo',
569
                                            'src' => $logoUrl,
570 571
                                            'alt' => common_config('site', 'name')));
            }
572

573
            $this->text(' ');
574 575
            $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
            $this->elementEnd('a');
576

577
            Event::handle('EndAddressData', array($this));
sarven's avatar
sarven committed
578
        }
579
        $this->elementEnd('address');
580 581
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
582 583 584 585 586
    /**
     * Show primary navigation.
     *
     * @return nothing
     */
587 588
    function showPrimaryNav()
    {
Evan Prodromou's avatar
Evan Prodromou committed
589
        $this->elementStart('div', array('id' => 'site_nav_global_primary'));
590 591
        $pn = new PrimaryNav($this);
        $pn->show();
Evan Prodromou's avatar
Evan Prodromou committed
592
        $this->elementEnd('div');
593
    }
594

Robin Millette's avatar
phpdocs  
Robin Millette committed
595 596 597 598 599
    /**
     * Show site notice.
     *
     * @return nothing
     */
600 601
    function showSiteNotice()
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
602
        // Revist. Should probably do an hAtom pattern here
603 604
        $text = common_config('site', 'notice');
        if ($text) {
605
            $this->elementStart('div', array('id' => 'site_notice',
606
                                            'class' => 'system_notice'));
607
            $this->raw($text);
608
            $this->elementEnd('div');
609
        }
610
    }
611

Robin Millette's avatar
phpdocs  
Robin Millette committed
612 613 614 615 616 617 618
    /**
     * Show notice form.
     *
     * MAY overload if no notice form needed... or direct message box????
     *
     * @return nothing
     */
619 620
    function showNoticeForm()
    {
621 622
        // TRANS: Tab on the notice form.
        $tabs = array('status' => _m('TAB','Status'));
623 624 625 626 627 628 629 630

        $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
631 632
                $attrs = array('id' => 'input_form_nav_'.$tag,
                               'class' => 'input_form_nav_tab');
633

634 635 636 637 638 639
                if ($tag == 'status') {
                    // We're actually showing the placeholder form,
                    // but we special-case the 'Status' tab as if
                    // it were a small version of it.
                    $attrs['class'] .= ' current';
                }
640 641 642
                $this->elementStart('li', $attrs);

                $this->element('a',
Evan Prodromou's avatar
Evan Prodromou committed
643
                               array('href' => 'javascript:SN.U.switchInputFormTab("'.$tag.'")'),
644 645 646 647 648 649
                               $title);
                $this->elementEnd('li');
            }

            $this->elementEnd('ul');

650 651 652 653 654 655 656
            $attrs = array('class' => 'input_form current',
                           'id' => 'input_form_placeholder');
            $this->elementStart('div', $attrs);
            $form = new NoticePlaceholderForm($this);
            $form->show();
            $this->elementEnd('div');

657 658 659 660 661 662 663 664 665 666
            foreach ($tabs as $tag => $title) {
                $attrs = array('class' => 'input_form',
                               'id' => 'input_form_'.$tag);

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

                $form = null;

                if (Event::handle('StartMakeEntryForm', array($tag, $this, &$form))) {
                    if ($tag == 'status') {
667 668
                        $options = $this->noticeFormOptions();
                        $form = new NoticeForm($this, $options);
669 670 671 672 673 674 675
                    }
                    Event::handle('EndMakeEntryForm', array($tag, $this, $form));
                }

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

                $this->elementEnd('div');
678 679
            }
        }
Evan Prodromou's avatar
Evan Prodromou committed
680 681

        $this->elementEnd('div');
682
    }
683

684 685 686 687 688
    function noticeFormOptions()
    {
        return array();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
689 690 691 692 693 694 695
    /**
     * Show anonymous message.
     *
     * SHOULD overload
     *
     * @return nothing
     */
696 697
    function showAnonymousMessage()
    {
698
        // needs to be defined by the class
699
    }
700

Robin Millette's avatar
phpdocs  
Robin Millette committed
701 702 703 704 705 706 707
    /**
     * Show core.
     *
     * Shows local navigation, content block and aside.
     *
     * @return nothing
     */
708 709
    function showCore()
    {
sarven's avatar
sarven committed
710
        $this->elementStart('div', array('id' => 'core'));
711 712 713
        $this->elementStart('div', array('id' => 'aside_primary_wrapper'));
        $this->elementStart('div', array('id' => 'content_wrapper'));
        $this->elementStart('div', array('id' => 'site_nav_local_views_wrapper'));
Sarven Capadisli's avatar
Sarven Capadisli committed
714 715
        if (Event::handle('StartShowLocalNavBlock', array($this))) {
            $this->showLocalNavBlock();
Evan Prodromou's avatar
Evan Prodromou committed
716
            $this->flush();
Sarven Capadisli's avatar
Sarven Capadisli committed
717 718
            Event::handle('EndShowLocalNavBlock', array($this));
        }
719 720
        if (Event::handle('StartShowContentBlock', array($this))) {
            $this->showContentBlock();
Evan Prodromou's avatar
Evan Prodromou committed
721
            $this->flush();
722 723
            Event::handle('EndShowContentBlock', array($this));
        }
724 725
        if (Event::handle('StartShowAside', array($this))) {
            $this->showAside();
Evan Prodromou's avatar
Evan Prodromou committed
726
            $this->flush();
727 728
            Event::handle('EndShowAside', array($this));
        }
729
        $this->elementEnd('div');
730 731 732
        $this->elementEnd('div');
        $this->elementEnd('div');
        $this->elementEnd('div');
733 734
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
735 736 737 738 739
    /**
     * Show local navigation block.
     *
     * @return nothing
     */
740 741
    function showLocalNavBlock()
    {
742 743 744
        // 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'));
745
        // Cheat cheat cheat!
746
        $this->showLocalNav();
747
        $this->elementEnd('div');
748 749
    }

750 751 752 753 754 755 756 757 758 759 760 761 762
    /**
     * If there's a logged-in user, show a bit of login context
     *
     * @return nothing
     */
    function showProfileBlock()
    {
        if (common_logged_in()) {
            $block = new DefaultProfileBlock($this);
            $block->show();
        }
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
763 764 765 766 767 768 769
    /**
     * Show local navigation.
     *
     * SHOULD overload
     *
     * @return nothing
     */
770
    function showLocalNav()
771
    {
772 773
        $nav = new DefaultLocalNav($this);
        $nav->show();
774 775
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
776
    /**
777 778
     * Show menu for an object (group, profile)
     *
779 780 781
     * This block will only show if a subclass has overridden
     * the showObjectNav() method.
     *
782 783 784 785
     * @return nothing
     */
    function showObjectNavBlock()
    {
786 787 788 789 790 791 792 793 794 795 796
        $rmethod = new ReflectionMethod($this, 'showObjectNav');
        $dclass = $rmethod->getDeclaringClass()->getName();

        if ($dclass != 'Action') {
            // Need to have this ID for CSS; I'm too lazy to add it to
            // all menus
            $this->elementStart('div', array('id' => 'site_nav_object',
                                             'class' => 'section'));
            $this->showObjectNav();
            $this->elementEnd('div');
        }
797 798 799 800 801 802 803 804 805 806 807 808
    }

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

Robin Millette's avatar
phpdocs  
Robin Millette committed
811 812 813 814 815
    /**
     * Show content block.
     *
     * @return nothing
     */
816 817
    function showContentBlock()
    {
818
        $this->elementStart('div', array('id' => 'content'));
819 820 821 822 823 824
        if (common_logged_in()) {
            if (Event::handle('StartShowNoticeForm', array($this))) {
                $this->showNoticeForm();
                Event::handle('EndShowNoticeForm', array($this));
            }
        }
825 826 827 828
        if (Event::handle('StartShowPageTitle', array($this))) {
            $this->showPageTitle();
            Event::handle('EndShowPageTitle', array($this));
        }
829
        $this->showPageNoticeBlock();
Evan Prodromou's avatar
Evan Prodromou committed
830 831
        $this->elementStart('div', array('id' => 'content_inner'));
        // show the actual content (forms, lists, whatever)
832
        $this->showContent();
sarven's avatar
sarven committed
833
        $this->elementEnd('div');
Evan Prodromou's avatar
Evan Prodromou committed
834
        $this->elementEnd('div');
835 836
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
837 838 839 840 841 842 843 844
    /**
     * Show page title.
     *
     * @return nothing
     */
    function showPageTitle()
    {
        $this->element('h1', null, $this->title());
845 846
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
847 848 849
    /**
     * Show page notice block.
     *
850 851 852 853 854 855
     * 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
856 857
     * @return nothing
     */
858 859
    function showPageNoticeBlock()
    {
860 861 862 863 864
        $rmethod = new ReflectionMethod($this, 'showPageNotice');
        $dclass = $rmethod->getDeclaringClass()->getName();

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

865
            $this->elementStart('div', array('id' => 'page_notice',
866 867 868 869 870
                                            'class' => 'system_notice'));
            if (Event::handle('StartShowPageNotice', array($this))) {
                $this->showPageNotice();
                Event::handle('EndShowPageNotice', array($this));
            }
871
            $this->elementEnd('div');
872
        }
Robin Millette's avatar
phpdocs  
Robin Millette committed
873
    }
874

Robin Millette's avatar
phpdocs  
Robin Millette committed
875 876 877 878 879 880 881
    /**
     * Show page notice.
     *
     * SHOULD overload (unless there's not a notice)
     *
     * @return nothing
     */
882 883 884
    function showPageNotice()
    {
    }
885

Robin Millette's avatar
phpdocs  
Robin Millette committed
886 887 888 889 890 891 892
    /**
     * Show content.
     *
     * MUST overload (unless there's not a notice)
     *
     * @return nothing
     */
893 894 895 896
    function showContent()
    {
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
897 898 899 900 901
    /**
     * Show Aside.
     *
     * @return nothing
     */
902 903
    function showAside()
    {
sarven's avatar
sarven committed
904 905
        $this->elementStart('div', array('id' => 'aside_primary',
                                         'class' => 'aside'));
906
        $this->showProfileBlock();
Brion Vibber's avatar
Brion Vibber committed
907 908 909 910
        if (Event::handle('StartShowObjectNavBlock', array($this))) {
            $this->showObjectNavBlock();
            Event::handle('EndShowObjectNavBlock', array($this));
        }
911 912 913 914
        if (Event::handle('StartShowSections', array($this))) {
            $this->showSections();
            Event::handle('EndShowSections', array($this));
        }
915 916 917 918
        if (Event::handle('StartShowExportData', array($this))) {
            $this->showExportData();
            Event::handle('EndShowExportData', array($this));
        }
sarven's avatar
sarven committed
919
        $this->elementEnd('div');
920 921
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
922 923 924
    /**
     * Show export data feeds.
     *
925
     * @return void
Robin Millette's avatar
phpdocs  
Robin Millette committed
926
     */
927 928
    function showExportData()
    {
929 930 931 932 933
        $feeds = $this->getFeeds();
        if ($feeds) {
            $fl = new FeedList($this);
            $fl->show($feeds);
        }
934 935
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
936 937 938 939 940 941 942 943 944
    /**
     * Show sections.
     *
     * SHOULD overload
     *
     * @return nothing
     */
    function showSections()
    {
945 946 947
        // for each section, show it
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
948 949 950 951 952
    /**
     * Show footer.
     *
     * @return nothing
     */
953 954
    function showFooter()
    {
sarven's avatar
sarven committed
955
        $this->elementStart('div', array('id' => 'footer'));
956 957 958 959 960
        if (Event::handle('StartShowInsideFooter', array($this))) {
            $this->showSecondaryNav();
            $this->showLicenses();
            Event::handle('EndShowInsideFooter', array($this));
        }
sarven's avatar
sarven committed
961
        $this->elementEnd('div');
962 963
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
964 965 966 967 968
    /**
     * Show secondary navigation.
     *
     * @return nothing
     */
969 970
    function showSecondaryNav()
    {
971 972
        $sn = new SecondaryNav($this);
        $sn->show();
973 974
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
975 976 977 978 979
    /**
     * Show licenses.
     *
     * @return nothing
     */
980 981
    function showLicenses()
    {
982
        $this->showStatusNetLicense();
983 984 985
        $this->showContentLicense();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
986
    /**
987
     * Show StatusNet license.
Robin Millette's avatar
phpdocs  
Robin Millette committed
988 989 990
     *
     * @return nothing
     */
991
    function showStatusNetLicense()
992 993
    {
        if (common_config('site', 'broughtby')) {
994
            // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is set.
995 996 997
            // 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
998
            $instr = _('**%%site.name%%** is a microblogging service brought to you by [%%site.broughtby%%](%%site.broughtbyurl%%).');
999
        } else {
1000 1001
            // TRANS: First sentence of the StatusNet site license. Used if 'broughtby' is not set.
            $instr = _('**%%site.name%%** is a microblogging service.');
1002
        }
1003
        $instr .= ' ';
1004
        // TRANS: Second sentence of the StatusNet site license. Mentions the StatusNet source code license.
1005 1006 1007
        // 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
1008
        $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);
1009
        $output = common_markup_to_html($instr);
1010
        $this->raw($output);
1011 1012 1013
        // do it
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
1014 1015 1016 1017 1018
    /**
     * Show content license.
     *
     * @return nothing
     */
1019 1020
    function showContentLicense()
    {
1021
        if (Event::handle('StartShowContentLicense', array($this))) {