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

action.php 46.5 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 312 313 314
                    $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');
                } else {
                    $this->script('jquery.js');
                    $this->script('jquery.form.js');
315
                    $this->script('jquery-ui.min.js');
316 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');
                }
Shashi Gowda's avatar
Shashi Gowda committed
320

321 322
                Event::handle('EndShowJQueryScripts', array($this));
            }
323 324
            if (Event::handle('StartShowStatusNetScripts', array($this)) &&
                Event::handle('StartShowLaconicaScripts', array($this))) {
325 326 327 328 329 330 331
                if (common_config('site', 'minify')) {
                    $this->script('util.min.js');
                } else {
                    $this->script('util.js');
                    $this->script('xbImportNode.js');
                    $this->script('geometa.js');
                }
332
                $this->inlineScript('var _peopletagAC = "' .
333
                    common_local_url('peopletagautocomplete') . '";');
334
                $this->showScriptMessages();
335
                // Frame-busting code to avoid clickjacking attacks.
336
                $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }');
337
                Event::handle('EndShowStatusNetScripts', array($this));
338 339 340 341
                Event::handle('EndShowLaconicaScripts', array($this));
            }
            Event::handle('EndShowScripts', array($this));
        }
342 343
    }

344 345 346 347 348 349 350 351 352 353
    /**
     * 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();
354

355 356 357 358 359 360
        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');

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

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

367
            $messages = array_merge($messages, $this->getScriptMessages());
368

369
	    Event::handle('EndScriptMessages', array($this, &$messages));
370
        }
371

372
        if (!empty($messages)) {
373 374
            $this->inlineScript('SN.messages=' . json_encode($messages));
        }
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
        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
402 403 404 405 406
    /**
     * Show OpenSearch headers
     *
     * @return nothing
     */
407 408
    function showOpenSearch()
    {
Robin Millette's avatar
phpdocs  
Robin Millette committed
409 410
        $this->element('link', array('rel' => 'search',
                                     'type' => 'application/opensearchdescription+xml',
411 412
                                     'href' =>  common_local_url('opensearch', array('type' => 'people')),
                                     'title' => common_config('site', 'name').' People Search'));
413
        $this->element('link', array('rel' => 'search', 'type' => 'application/opensearchdescription+xml',
414 415 416 417
                                     'href' =>  common_local_url('opensearch', array('type' => 'notice')),
                                     'title' => common_config('site', 'name').' Notice Search'));
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
418 419 420 421 422 423 424
    /**
     * Show feed headers
     *
     * MAY overload
     *
     * @return nothing
     */
425 426
    function showFeeds()
    {
427 428 429 430 431 432 433 434 435 436
        $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));
            }
        }
437 438
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
439 440 441 442 443 444 445
    /**
     * Show description.
     *
     * SHOULD overload
     *
     * @return nothing
     */
446 447 448 449 450
    function showDescription()
    {
        // does nothing by default
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
451 452 453 454 455 456 457
    /**
     * Show extra stuff in <head>.
     *
     * MAY overload
     *
     * @return nothing
     */
458 459 460 461 462
    function extraHead()
    {
        // does nothing by default
    }

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

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

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

sarven's avatar
sarven committed
511
        $this->elementEnd('div');
512 513
    }

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

535
            $this->elementStart('a', array('class' => 'url home bookmark',
Evan Prodromou's avatar
Evan Prodromou committed
536
                                           'href' => $url));
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560

            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)) {
561
                $this->element('img', array('class' => 'logo photo',
562
                                            'src' => $logoUrl,
563 564
                                            'alt' => common_config('site', 'name')));
            }
565

566
            $this->text(' ');
567 568
            $this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
            $this->elementEnd('a');
569

570
            Event::handle('EndAddressData', array($this));
sarven's avatar
sarven committed
571
        }
572
        $this->elementEnd('address');
573 574
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
575 576 577 578 579
    /**
     * Show primary navigation.
     *
     * @return nothing
     */
580 581
    function showPrimaryNav()
    {
Evan Prodromou's avatar
Evan Prodromou committed
582
        $this->elementStart('div', array('id' => 'site_nav_global_primary'));
583 584
        $pn = new PrimaryNav($this);
        $pn->show();
Evan Prodromou's avatar
Evan Prodromou committed
585
        $this->elementEnd('div');
586
    }
587

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

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

        $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
624 625
                $attrs = array('id' => 'input_form_nav_'.$tag,
                               'class' => 'input_form_nav_tab');
626

627 628 629 630 631 632
                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';
                }
633 634 635
                $this->elementStart('li', $attrs);

                $this->element('a',
Evan Prodromou's avatar
Evan Prodromou committed
636
                               array('href' => 'javascript:SN.U.switchInputFormTab("'.$tag.'")'),
637 638 639 640 641 642
                               $title);
                $this->elementEnd('li');
            }

            $this->elementEnd('ul');

643 644 645 646 647 648 649
            $attrs = array('class' => 'input_form current',
                           'id' => 'input_form_placeholder');
            $this->elementStart('div', $attrs);
            $form = new NoticePlaceholderForm($this);
            $form->show();
            $this->elementEnd('div');

650 651 652 653 654 655 656 657 658 659
            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') {
660 661
                        $options = $this->noticeFormOptions();
                        $form = new NoticeForm($this, $options);
662 663 664 665 666 667 668
                    }
                    Event::handle('EndMakeEntryForm', array($tag, $this, $form));
                }

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

                $this->elementEnd('div');
671 672
            }
        }
Evan Prodromou's avatar
Evan Prodromou committed
673 674

        $this->elementEnd('div');
675
    }
676

677 678 679 680 681
    function noticeFormOptions()
    {
        return array();
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
682 683 684 685 686 687 688
    /**
     * Show anonymous message.
     *
     * SHOULD overload
     *
     * @return nothing
     */
689 690
    function showAnonymousMessage()
    {
691
        // needs to be defined by the class
692
    }
693

Robin Millette's avatar
phpdocs  
Robin Millette committed
694 695 696 697 698 699 700
    /**
     * Show core.
     *
     * Shows local navigation, content block and aside.
     *
     * @return nothing
     */
701 702
    function showCore()
    {
sarven's avatar
sarven committed
703
        $this->elementStart('div', array('id' => 'core'));
704 705 706
        $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
707 708
        if (Event::handle('StartShowLocalNavBlock', array($this))) {
            $this->showLocalNavBlock();
Evan Prodromou's avatar
Evan Prodromou committed
709
            $this->flush();
Sarven Capadisli's avatar
Sarven Capadisli committed
710 711
            Event::handle('EndShowLocalNavBlock', array($this));
        }
712 713
        if (Event::handle('StartShowContentBlock', array($this))) {
            $this->showContentBlock();
Evan Prodromou's avatar
Evan Prodromou committed
714
            $this->flush();
715 716
            Event::handle('EndShowContentBlock', array($this));
        }
717 718
        if (Event::handle('StartShowAside', array($this))) {
            $this->showAside();
Evan Prodromou's avatar
Evan Prodromou committed
719
            $this->flush();
720 721
            Event::handle('EndShowAside', array($this));
        }
722
        $this->elementEnd('div');
723 724 725
        $this->elementEnd('div');
        $this->elementEnd('div');
        $this->elementEnd('div');
726 727
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
728 729 730 731 732
    /**
     * Show local navigation block.
     *
     * @return nothing
     */
733 734
    function showLocalNavBlock()
    {
735 736 737
        // 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'));
738
        // Cheat cheat cheat!
739
        $this->showLocalNav();
740
        $this->elementEnd('div');
741 742
    }

743 744 745 746 747 748 749 750 751 752 753 754 755
    /**
     * 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
756 757 758 759 760 761 762
    /**
     * Show local navigation.
     *
     * SHOULD overload
     *
     * @return nothing
     */
763
    function showLocalNav()
764
    {
765 766
        $nav = new DefaultLocalNav($this);
        $nav->show();
767 768
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
769
    /**
770 771
     * Show menu for an object (group, profile)
     *
772 773 774
     * This block will only show if a subclass has overridden
     * the showObjectNav() method.
     *
775 776 777 778
     * @return nothing
     */
    function showObjectNavBlock()
    {
779 780 781 782 783 784 785 786 787 788 789
        $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');
        }
790 791 792 793 794 795 796 797 798 799 800 801
    }

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

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

Robin Millette's avatar
phpdocs  
Robin Millette committed
830 831 832 833 834 835 836 837
    /**
     * Show page title.
     *
     * @return nothing
     */
    function showPageTitle()
    {
        $this->element('h1', null, $this->title());
838 839
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
840 841 842
    /**
     * Show page notice block.
     *
843 844 845 846 847 848
     * 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
849 850
     * @return nothing
     */
851 852
    function showPageNoticeBlock()
    {
853 854 855 856 857
        $rmethod = new ReflectionMethod($this, 'showPageNotice');
        $dclass = $rmethod->getDeclaringClass()->getName();

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

858
            $this->elementStart('div', array('id' => 'page_notice',
859 860 861 862 863
                                            'class' => 'system_notice'));
            if (Event::handle('StartShowPageNotice', array($this))) {
                $this->showPageNotice();
                Event::handle('EndShowPageNotice', array($this));
            }
864
            $this->elementEnd('div');
865
        }
Robin Millette's avatar
phpdocs  
Robin Millette committed
866
    }
867

Robin Millette's avatar
phpdocs  
Robin Millette committed
868 869 870 871 872 873 874
    /**
     * Show page notice.
     *
     * SHOULD overload (unless there's not a notice)
     *
     * @return nothing
     */
875 876 877
    function showPageNotice()
    {
    }
878

Robin Millette's avatar
phpdocs  
Robin Millette committed
879 880 881 882 883 884 885
    /**
     * Show content.
     *
     * MUST overload (unless there's not a notice)
     *
     * @return nothing
     */
886 887 888 889
    function showContent()
    {
    }

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

Robin Millette's avatar
phpdocs  
Robin Millette committed
915 916 917
    /**
     * Show export data feeds.
     *
918
     * @return void
Robin Millette's avatar
phpdocs  
Robin Millette committed
919
     */
920 921
    function showExportData()
    {
922 923 924 925 926
        $feeds = $this->getFeeds();
        if ($feeds) {
            $fl = new FeedList($this);
            $fl->show($feeds);
        }
927 928
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
929 930 931 932 933 934 935 936 937
    /**
     * Show sections.
     *
     * SHOULD overload
     *
     * @return nothing
     */
    function showSections()
    {
938 939 940
        // for each section, show it
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
941 942 943 944 945
    /**
     * Show footer.
     *
     * @return nothing
     */
946 947
    function showFooter()
    {
sarven's avatar
sarven committed
948
        $this->elementStart('div', array('id' => 'footer'));
949 950 951 952 953
        if (Event::handle('StartShowInsideFooter', array($this))) {
            $this->showSecondaryNav();
            $this->showLicenses();
            Event::handle('EndShowInsideFooter', array($this));
        }
sarven's avatar
sarven committed
954
        $this->elementEnd('div');
955 956
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
957 958 959 960 961
    /**
     * Show secondary navigation.
     *
     * @return nothing
     */
962 963
    function showSecondaryNav()
    {
964 965
        $sn = new SecondaryNav($this);
        $sn->show();
966 967
    }

Robin Millette's avatar
phpdocs  
Robin Millette committed
968 969 970 971 972
    /**
     * Show licenses.
     *
     * @return nothing
     */
973 974
    function showLicenses()
    {
975
        $this->showStatusNetLicense();
976 977 978
        $this->showContentLicense();
    }

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

Robin Millette's avatar
phpdocs  
Robin Millette committed
1007 1008 1009 1010 1011
    /**
     * Show content license.
     *
     * @return nothing
     */
1012 1013
    function showContentLicense()
    {
1014
        if (Event::handle('StartShowContentLicense', array($this))) {
1015 1016
            switch (common_config('license', 'type')) {
            case 'private':
1017 1018
                // TRANS: Content license displayed when license is set to 'private'.
                // TRANS: %1$s is the site name.
1019 1020 1021 1022 1023
                $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')) {
1024 1025
                    // TRANS: Content license displayed when license is set to 'allrightsreserved'.
                    // TRANS: %1$s is the copyright owner.
1026 1027 1028
                    $this->element('p', null, sprintf(_('Content and data copyright by %1$s. All rights reserved.'),
                                                      common_config('license', 'owner')));
                } else {
1029
                    // TRANS: Content license displayed when license is set to 'allrightsreserved' and no owner is set.
1030 1031 1032 1033 1034 1035
                    $this->element('p', null, _('Content and data copyright by contributors. All rights reserved.'));
                }
                break;
            case 'cc': // fall through
            default:
                $this->elementStart('p');
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053

                $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;
                }

1054
                $this->element('img', array('id' => 'license_cc',
1055
                                            'src' => $url,
1056 1057 1058
                                            'alt' => common_config('license', 'title'),
                                            'width' => '80',
                                            'height' => '15'));
1059
                $this->text(' ');
1060 1061
                // 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.
1062 1063 1064 1065 1066 1067 1068 1069 1070
                $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));
1071 1072 1073 1074
                $this->elementEnd('p');
                b