]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/doc.php
Merge branch 'master' of git.gnu.io:Quix0r/gnu-social
[quix0rs-gnu-social.git] / actions / doc.php
1 <?php
2 /**
3  * Documentation action.
4  *
5  * PHP version 5
6  *
7  * @category Action
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @author   Robin Millette <millette@status.net>
11  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
12  * @link     http://status.net/
13  *
14  * StatusNet - the distributed open-source microblogging tool
15  * Copyright (C) 2008-2010, StatusNet, Inc.
16  *
17  * This program is free software: you can redistribute it and/or modify
18  * it under the terms of the GNU Affero General Public License as published by
19  * the Free Software Foundation, either version 3 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU Affero General Public License for more details.
26  *
27  * You should have received a copy of the GNU Affero General Public License
28  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * Documentation class.
37  *
38  * @category Action
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @author   Robin Millette <millette@status.net>
42  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
43  * @link     http://status.net/
44  */
45 class DocAction extends Action
46 {
47     var $output   = null;
48     var $filename = null;
49     var $title    = null;
50
51     function prepare(array $args=array())
52     {
53         parent::prepare($args);
54
55         $this->title  = $this->trimmed('title');
56         if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
57             $this->title = 'help';
58         }
59         $this->output = null;
60
61         $this->loadDoc();
62         return true;
63     }
64
65     /**
66      * Handle a request
67      *
68      * @param array $args array of arguments
69      *
70      * @return nothing
71      */
72     function handle(array $args=array())
73     {
74         parent::handle($args);
75         $this->showPage();
76     }
77
78     /**
79      * Page title
80      *
81      * Gives the page title of the document. Override default for hAtom entry.
82      *
83      * @return void
84      */
85     function showPageTitle()
86     {
87         $this->element('h1', array('class' => 'entry-title'), $this->title());
88     }
89
90     /**
91      * Block for content.
92      *
93      * Overrides default from Action to wrap everything in an hAtom entry.
94      *
95      * @return void.
96      */
97     function showContentBlock()
98     {
99         $this->elementStart('div', array('id' => 'content', 'class' => 'h-entry'));
100         $this->showPageTitle();
101         $this->showPageNoticeBlock();
102         $this->elementStart('div', array('id' => 'content_inner',
103                                          'class' => 'e-content'));
104         // show the actual content (forms, lists, whatever)
105         $this->showContent();
106         $this->elementEnd('div');
107         $this->elementEnd('div');
108     }
109
110     /**
111      * Display content.
112      *
113      * Shows the content of the document.
114      *
115      * @return void
116      */
117     function showContent()
118     {
119         $this->raw($this->output);
120     }
121
122     /**
123      * Page title.
124      *
125      * Uses the title of the document.
126      *
127      * @return page title
128      */
129     function title()
130     {
131         return ucfirst($this->title);
132     }
133
134     /**
135      * These pages are read-only.
136      *
137      * @param array $args unused.
138      *
139      * @return boolean read-only flag (false)
140      */
141     function isReadOnly(array $args=array())
142     {
143         return true;
144     }
145
146     function loadDoc()
147     {
148         if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
149
150             $paths = DocFile::defaultPaths();
151
152             $docfile = DocFile::forTitle($this->title, $paths);
153
154             if (empty($docfile)) {
155                 // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
156                 // TRANS: %s is the non-existing document.
157                 throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
158             }
159
160             $this->output = $docfile->toHTML();
161
162             Event::handle('EndLoadDoc', array($this->title, &$this->output));
163         }
164     }
165
166     function showLocalNav()
167     {
168         $menu = new DocNav($this);
169         $menu->show();
170     }
171 }
172
173 class DocNav extends Menu
174 {
175     function show()
176     {
177         if (Event::handle('StartDocNav', array($this))) {
178             $stub = new HomeStubNav($this->action);
179             $this->submenu(_m('MENU','Home'), $stub);
180
181             $docs = new DocListNav($this->action);
182             $this->submenu(_m('MENU','Docs'), $docs);
183             
184             Event::handle('EndDocNav', array($this));
185         }
186     }
187 }
188
189 class DocListNav extends Menu
190 {
191     function getItems()
192     {
193         $items = array();
194
195         if (Event::handle('StartDocsMenu', array(&$items))) {
196
197             $items = array(array('doc',
198                                  array('title' => 'help'),
199                                  _m('MENU', 'Help'),
200                                  _('Getting started'),
201                                  'nav_doc_help'),
202                            array('doc',
203                                  array('title' => 'about'),
204                                  _m('MENU', 'About'),
205                                  _('About this site'),
206                                  'nav_doc_about'),
207                            array('doc',
208                                  array('title' => 'faq'),
209                                  _m('MENU', 'FAQ'),
210                                  _('Frequently asked questions'),
211                                  'nav_doc_faq'),
212                            array('doc',
213                                  array('title' => 'contact'),
214                                  _m('MENU', 'Contact'),
215                                  _('Contact info'),
216                                  'nav_doc_contact'),
217                            array('doc',
218                                  array('title' => 'tags'),
219                                  _m('MENU', 'Tags'),
220                                  _('Using tags'),
221                                  'nav_doc_tags'),
222                            array('doc',
223                                  array('title' => 'groups'),
224                                  _m('MENU', 'Groups'),
225                                  _('Using groups'),
226                                  'nav_doc_groups'),
227                            array('doc',
228                                  array('title' => 'api'),
229                                  _m('MENU', 'API'),
230                                  _('RESTful API'),
231                                  'nav_doc_api'));
232
233             Event::handle('EndDocsMenu', array(&$items));
234         }
235         return $items;
236     }
237 }