]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - actions/doc.php
restructure doc.php for new use
[quix0rs-gnu-social.git] / actions / doc.php
1 <?php
2
3 /**
4  * Documentation action.
5  *
6  * PHP version 5
7  *
8  * @category Action
9  * @package  StatusNet
10  * @author   Evan Prodromou <evan@status.net>
11  * @author   Robin Millette <millette@status.net>
12  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
13  * @link     http://status.net/
14  *
15  * StatusNet - the distributed open-source microblogging tool
16  * Copyright (C) 2008, 2009, StatusNet, Inc.
17  *
18  * This program is free software: you can redistribute it and/or modify
19  * it under the terms of the GNU Affero General Public License as published by
20  * the Free Software Foundation, either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26  * GNU Affero General Public License for more details.
27  *
28  * You should have received a copy of the GNU Affero General Public License
29  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
30  */
31
32 if (!defined('STATUSNET') && !defined('LACONICA')) {
33     exit(1);
34 }
35
36 /**
37  * Documentation class.
38  *
39  * @category Action
40  * @package  StatusNet
41  * @author   Evan Prodromou <evan@status.net>
42  * @author   Robin Millette <millette@status.net>
43  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
44  * @link     http://status.net/
45  */
46 class DocAction extends Action
47 {
48     var $output   = null;
49     var $filename = null;
50     var $title    = null;
51
52     function prepare($args)
53     {
54         $this->title  = $this->trimmed('title');
55         $this->output = null;
56
57         $this->loadDoc();
58         return true;
59     }
60
61     /**
62      * Handle a request
63      *
64      * @param array $args array of arguments
65      *
66      * @return nothing
67      */
68     function handle($args)
69     {
70         parent::handle($args);
71         $this->showPage();
72     }
73
74     /**
75      * Page title
76      *
77      * Gives the page title of the document. Override default for hAtom entry.
78      *
79      * @return void
80      */
81
82     function showPageTitle()
83     {
84         $this->element('h1', array('class' => 'entry-title'), $this->title());
85     }
86
87     /**
88      * Block for content.
89      *
90      * Overrides default from Action to wrap everything in an hAtom entry.
91      *
92      * @return void.
93      */
94
95     function showContentBlock()
96     {
97         $this->elementStart('div', array('id' => 'content', 'class' => 'hentry'));
98         $this->showPageTitle();
99         $this->showPageNoticeBlock();
100         $this->elementStart('div', array('id' => 'content_inner',
101                                          'class' => 'entry-content'));
102         // show the actual content (forms, lists, whatever)
103         $this->showContent();
104         $this->elementEnd('div');
105         $this->elementEnd('div');
106     }
107
108     /**
109      * Display content.
110      *
111      * Shows the content of the document.
112      *
113      * @return void
114      */
115
116     function showContent()
117     {
118         $this->raw($this->output);
119     }
120
121     /**
122      * Page title.
123      *
124      * Uses the title of the document.
125      *
126      * @return page title
127      */
128     function title()
129     {
130         return ucfirst($this->title);
131     }
132
133     /**
134      * These pages are read-only.
135      *
136      * @param array $args unused.
137      *
138      * @return boolean read-only flag (false)
139      */
140
141     function isReadOnly($args)
142     {
143         return true;
144     }
145
146     function loadDoc()
147     {
148         if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
149
150             $this->filename = $this->getFilename();
151
152             if (empty($this->filename)) {
153                 throw new ClientException(sprintf(_('No such document "%s"'), $this->title), 404);
154             }
155
156             $c = file_get_contents($this->filename);
157
158             $this->output = common_markup_to_html($c);
159
160             Event::handle('EndLoadDoc', array($this->title, &$this->output));
161         }
162     }
163
164     function getFilename()
165     {
166         $local = array_merge(glob(INSTALLDIR.'/local/doc-src/'.$this->title),
167                              glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*'));
168
169         if (count($local)) {
170             return $this->negotiateLanguage($local);
171         }
172
173         $dist = array_merge(glob(INSTALLDIR.'/doc-src/'.$this->title),
174                             glob(INSTALLDIR.'/doc-src/'.$this->title.'.*'));
175
176         if (count($dist)) {
177             return $this->negotiateLanguage($dist);
178         }
179
180         return null;
181     }
182
183     function negotiateLanguage($files)
184     {
185         // FIXME: write this
186     }
187 }