4 * Documentation action.
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/
15 * StatusNet - the distributed open-source microblogging tool
16 * Copyright (C) 2008-2010, StatusNet, Inc.
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.
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.
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/>.
32 if (!defined('STATUSNET') && !defined('LACONICA')) {
37 * Documentation class.
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/
46 class DocAction extends Action
52 function prepare($args)
54 parent::prepare($args);
56 $this->title = $this->trimmed('title');
57 if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
58 $this->title = 'help';
69 * @param array $args array of arguments
73 function handle($args)
75 parent::handle($args);
82 * Gives the page title of the document. Override default for hAtom entry.
87 function showPageTitle()
89 $this->element('h1', array('class' => 'entry-title'), $this->title());
95 * Overrides default from Action to wrap everything in an hAtom entry.
100 function showContentBlock()
102 $this->elementStart('div', array('id' => 'content', 'class' => 'hentry'));
103 $this->showPageTitle();
104 $this->showPageNoticeBlock();
105 $this->elementStart('div', array('id' => 'content_inner',
106 'class' => 'entry-content'));
107 // show the actual content (forms, lists, whatever)
108 $this->showContent();
109 $this->elementEnd('div');
110 $this->elementEnd('div');
116 * Shows the content of the document.
121 function showContent()
123 $this->raw($this->output);
129 * Uses the title of the document.
135 return ucfirst($this->title);
139 * These pages are read-only.
141 * @param array $args unused.
143 * @return boolean read-only flag (false)
146 function isReadOnly($args)
153 if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
155 $this->filename = $this->getFilename();
157 if (empty($this->filename)) {
158 throw new ClientException(sprintf(_('No such document "%s"'), $this->title), 404);
161 $c = file_get_contents($this->filename);
163 $this->output = common_markup_to_html($c);
165 Event::handle('EndLoadDoc', array($this->title, &$this->output));
169 function getFilename()
174 $site = StatusNet::currentSite();
176 if (!empty($site) && file_exists(INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title)) {
177 $localDef = INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title;
179 $local = glob(INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title.'.*');
180 if ($local === false) {
181 // Some systems return false, others array(), if dir didn't exist.
185 if (file_exists(INSTALLDIR.'/local/doc-src/'.$this->title)) {
186 $localDef = INSTALLDIR.'/local/doc-src/'.$this->title;
189 $local = glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*');
190 if ($local === false) {
195 if (count($local) || isset($localDef)) {
196 return $this->negotiateLanguage($local, $localDef);
199 if (file_exists(INSTALLDIR.'/doc-src/'.$this->title)) {
200 $distDef = INSTALLDIR.'/doc-src/'.$this->title;
203 $dist = glob(INSTALLDIR.'/doc-src/'.$this->title.'.*');
204 if ($dist === false) {
208 if (count($dist) || isset($distDef)) {
209 return $this->negotiateLanguage($dist, $distDef);
215 function negotiateLanguage($filenames, $defaultFilename=null)
217 // XXX: do this better
219 $langcode = common_language();
221 foreach ($filenames as $filename) {
222 if (preg_match('/\.'.$langcode.'$/', $filename)) {
227 return $defaultFilename;