]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/doc.php
Merge remote-tracking branch 'upstream/master' into social-master
[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('GNUSOCIAL')) { exit(1); }
32
33 /**
34  * Documentation class.
35  *
36  * @category Action
37  * @package  StatusNet
38  * @author   Evan Prodromou <evan@status.net>
39  * @author   Robin Millette <millette@status.net>
40  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
41  * @link     http://status.net/
42  */
43 class DocAction extends ManagedAction
44 {
45     var $output   = null;
46     var $filename = null;
47     var $title    = null;
48
49     protected function doPreparation()
50     {
51         $this->title  = $this->trimmed('title');
52         if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
53             $this->title = 'help';
54         }
55         $this->output = null;
56
57         $this->loadDoc();
58     }
59
60     public function title()
61     {
62         return ucfirst($this->title);
63     }
64
65     /**
66      * Display content.
67      *
68      * Shows the content of the document.
69      *
70      * @return void
71      */
72     function showContent()
73     {
74         $this->raw($this->output);
75     }
76
77     function showNoticeForm()
78     {
79         // no notice form
80     }
81
82     /**
83      * These pages are read-only.
84      *
85      * @param array $args unused.
86      *
87      * @return boolean read-only flag (false)
88      */
89     function isReadOnly(array $args=array())
90     {
91         return true;
92     }
93
94     function loadDoc()
95     {
96         if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
97
98             $paths = DocFile::defaultPaths();
99
100             $docfile = DocFile::forTitle($this->title, $paths);
101
102             if (empty($docfile)) {
103                 // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
104                 // TRANS: %s is the non-existing document.
105                 throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
106             }
107
108             $this->output = $docfile->toHTML();
109
110             Event::handle('EndLoadDoc', array($this->title, &$this->output));
111         }
112     }
113
114     function showLocalNav()
115     {
116         $menu = new DocNav($this);
117         $menu->show();
118     }
119 }
120
121 class DocNav extends Menu
122 {
123     function show()
124     {
125         if (Event::handle('StartDocNav', array($this))) {
126             $stub = new HomeStubNav($this->action);
127             $this->submenu(_m('MENU','Home'), $stub);
128
129             $docs = new DocListNav($this->action);
130             $this->submenu(_m('MENU','Docs'), $docs);
131             
132             Event::handle('EndDocNav', array($this));
133         }
134     }
135 }
136
137 class DocListNav extends Menu
138 {
139     function getItems()
140     {
141         $items = array();
142
143         if (Event::handle('StartDocsMenu', array(&$items))) {
144
145             $items = array(array('doc',
146                                  array('title' => 'help'),
147                                  _m('MENU', 'Help'),
148                                  _('Getting started'),
149                                  'nav_doc_help'),
150                            array('doc',
151                                  array('title' => 'about'),
152                                  _m('MENU', 'About'),
153                                  _('About this site'),
154                                  'nav_doc_about'),
155                            array('doc',
156                                  array('title' => 'faq'),
157                                  _m('MENU', 'FAQ'),
158                                  _('Frequently asked questions'),
159                                  'nav_doc_faq'),
160                            array('doc',
161                                  array('title' => 'contact'),
162                                  _m('MENU', 'Contact'),
163                                  _('Contact info'),
164                                  'nav_doc_contact'),
165                            array('doc',
166                                  array('title' => 'tags'),
167                                  _m('MENU', 'Tags'),
168                                  _('Using tags'),
169                                  'nav_doc_tags'),
170                            array('doc',
171                                  array('title' => 'groups'),
172                                  _m('MENU', 'Groups'),
173                                  _('Using groups'),
174                                  'nav_doc_groups'),
175                            array('doc',
176                                  array('title' => 'api'),
177                                  _m('MENU', 'API'),
178                                  _('RESTful API'),
179                                  'nav_doc_api'));
180
181             Event::handle('EndDocsMenu', array(&$items));
182         }
183         return $items;
184     }
185 }