doc.php 5.47 KB
Newer Older
Evan Prodromou's avatar
Evan Prodromou committed
1
<?php
Robin Millette's avatar
Robin Millette committed
2 3 4 5 6 7
/**
 * Documentation action.
 *
 * PHP version 5
 *
 * @category Action
8
 * @package  StatusNet
9 10
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
11
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
13
 *
14
 * StatusNet - the distributed open-source microblogging tool
15
 * Copyright (C) 2008-2010, StatusNet, Inc.
Evan Prodromou's avatar
Evan Prodromou committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
 *
 * This program is free software: you can redistribute it and/or modify
 * 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.
 *
 * 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.
 *
 * 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/>.
 */

31
if (!defined('GNUSOCIAL')) { exit(1); }
Robin Millette's avatar
Robin Millette committed
32 33 34 35 36

/**
 * Documentation class.
 *
 * @category Action
37
 * @package  StatusNet
38 39
 * @author   Evan Prodromou <evan@status.net>
 * @author   Robin Millette <millette@status.net>
Robin Millette's avatar
Robin Millette committed
40
 * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41
 * @link     http://status.net/
Robin Millette's avatar
Robin Millette committed
42
 */
43
class DocAction extends ManagedAction
44
{
45 46 47 48
    var $output   = null;
    var $filename = null;
    var $title    = null;

49
    protected function doPreparation()
50 51
    {
        $this->title  = $this->trimmed('title');
52 53 54
        if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
            $this->title = 'help';
        }
55 56 57
        $this->output = null;

        $this->loadDoc();
58
    }
59

mmn's avatar
mmn committed
60 61 62 63 64
    public function title()
    {
        return ucfirst($this->title);
    }

Robin Millette's avatar
Robin Millette committed
65 66
    /**
     * Display content.
67
     *
68 69 70
     * Shows the content of the document.
     *
     * @return void
Robin Millette's avatar
Robin Millette committed
71
     */
Robin Millette's avatar
Robin Millette committed
72 73
    function showContent()
    {
74
        $this->raw($this->output);
Robin Millette's avatar
Robin Millette committed
75 76
    }

77 78
    function showNoticeForm()
    {
mmn's avatar
mmn committed
79
        // no notice form
80
    }
81

82 83 84 85 86 87 88
    /**
     * These pages are read-only.
     *
     * @param array $args unused.
     *
     * @return boolean read-only flag (false)
     */
89
    function isReadOnly($args)
90 91 92
    {
        return true;
    }
93 94 95 96 97

    function loadDoc()
    {
        if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {

98
            $paths = DocFile::defaultPaths();
99

100 101 102
            $docfile = DocFile::forTitle($this->title, $paths);

            if (empty($docfile)) {
103 104 105
                // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
                // TRANS: %s is the non-existing document.
                throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
106 107
            }

108
            $this->output = $docfile->toHTML();
109 110 111 112

            Event::handle('EndLoadDoc', array($this->title, &$this->output));
        }
    }
113 114 115 116 117 118 119 120 121 122 123 124

    function showLocalNav()
    {
        $menu = new DocNav($this);
        $menu->show();
    }
}

class DocNav extends Menu
{
    function show()
    {
buttle's avatar
buttle committed
125 126 127 128 129 130 131 132 133
        if (Event::handle('StartDocNav', array($this))) {
            $stub = new HomeStubNav($this->action);
            $this->submenu(_m('MENU','Home'), $stub);

            $docs = new DocListNav($this->action);
            $this->submenu(_m('MENU','Docs'), $docs);
            
            Event::handle('EndDocNav', array($this));
        }
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    }
}

class DocListNav extends Menu
{
    function getItems()
    {
        $items = array();

        if (Event::handle('StartDocsMenu', array(&$items))) {

            $items = array(array('doc',
                                 array('title' => 'help'),
                                 _m('MENU', 'Help'),
                                 _('Getting started'),
                                 'nav_doc_help'),
                           array('doc',
                                 array('title' => 'about'),
                                 _m('MENU', 'About'),
                                 _('About this site'),
                                 'nav_doc_about'),
                           array('doc',
                                 array('title' => 'faq'),
                                 _m('MENU', 'FAQ'),
                                 _('Frequently asked questions'),
                                 'nav_doc_faq'),
                           array('doc',
                                 array('title' => 'contact'),
                                 _m('MENU', 'Contact'),
                                 _('Contact info'),
                                 'nav_doc_contact'),
                           array('doc',
                                 array('title' => 'tags'),
                                 _m('MENU', 'Tags'),
                                 _('Using tags'),
                                 'nav_doc_tags'),
                           array('doc',
                                 array('title' => 'groups'),
                                 _m('MENU', 'Groups'),
                                 _('Using groups'),
                                 'nav_doc_groups'),
                           array('doc',
                                 array('title' => 'api'),
                                 _m('MENU', 'API'),
                                 _('RESTful API'),
                                 'nav_doc_api'));

            Event::handle('EndDocsMenu', array(&$items));
        }
        return $items;
    }
185
}