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, 2009, 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');
66 * @param array $args array of arguments
70 function handle($args)
72 parent::handle($args);
79 * Gives the page title of the document. Override default for hAtom entry.
84 function showPageTitle()
86 $this->element('h1', array('class' => 'entry-title'), $this->title());
92 * Overrides default from Action to wrap everything in an hAtom entry.
97 function showContentBlock()
99 $this->elementStart('div', array('id' => 'content', 'class' => 'hentry'));
100 $this->showPageTitle();
101 $this->showPageNoticeBlock();
102 $this->elementStart('div', array('id' => 'content_inner',
103 'class' => 'entry-content'));
104 // show the actual content (forms, lists, whatever)
105 $this->showContent();
106 $this->elementEnd('div');
107 $this->elementEnd('div');
113 * Shows the content of the document.
118 function showContent()
120 $this->raw($this->output);
126 * Uses the title of the document.
132 return ucfirst($this->title);
136 * These pages are read-only.
138 * @param array $args unused.
140 * @return boolean read-only flag (false)
143 function isReadOnly($args)
150 if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
152 $this->filename = $this->getFilename();
154 if (empty($this->filename)) {
155 throw new ClientException(sprintf(_('No such document "%s"'), $this->title), 404);
158 $c = file_get_contents($this->filename);
160 $this->output = common_markup_to_html($c);
162 Event::handle('EndLoadDoc', array($this->title, &$this->output));
166 function getFilename()
168 if (file_exists(INSTALLDIR.'/local/doc-src/'.$this->title)) {
169 $localDef = INSTALLDIR.'/local/doc-src/'.$this->title;
172 $local = glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*');
174 if (count($local) || isset($localDef)) {
175 return $this->negotiateLanguage($local, $localDef);
178 if (file_exists(INSTALLDIR.'/doc-src/'.$this->title)) {
179 $distDef = INSTALLDIR.'/doc-src/'.$this->title;
182 $dist = glob(INSTALLDIR.'/doc-src/'.$this->title.'.*');
184 if (count($dist) || isset($distDef)) {
185 return $this->negotiateLanguage($dist, $distDef);
191 function negotiateLanguage($filenames, $defaultFilename=null)
193 // XXX: do this better
195 $langcode = common_language();
197 foreach ($filenames as $filename) {
198 if (preg_match('/\.'.$langcode.'$/', $filename)) {
203 return $defaultFilename;