3 * Documentation action.
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/
14 * StatusNet - the distributed open-source microblogging tool
15 * Copyright (C) 2008-2010, StatusNet, Inc.
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.
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.
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/>.
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
36 * Documentation class.
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/
45 class DocAction extends Action
51 function prepare($args)
53 parent::prepare($args);
55 $this->title = $this->trimmed('title');
56 if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
57 $this->title = 'help';
68 * @param array $args array of arguments
72 function handle($args)
74 parent::handle($args);
81 * Gives the page title of the document. Override default for hAtom entry.
85 function showPageTitle()
87 $this->element('h1', array('class' => 'entry-title'), $this->title());
93 * 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.
117 function showContent()
119 $this->raw($this->output);
125 * Uses the title of the document.
131 return ucfirst($this->title);
135 * These pages are read-only.
137 * @param array $args unused.
139 * @return boolean read-only flag (false)
141 function isReadOnly($args)
148 if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
150 $this->filename = $this->getFilename();
152 if (empty($this->filename)) {
153 // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
154 // TRANS: %s is the non-existing document.
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()
171 $site = StatusNet::currentSite();
173 if (!empty($site) && file_exists(INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title)) {
174 $localDef = INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title;
176 $local = glob(INSTALLDIR.'/local/doc-src/'.$site.'/'.$this->title.'.*');
177 if ($local === false) {
178 // Some systems return false, others array(), if dir didn't exist.
182 if (file_exists(INSTALLDIR.'/local/doc-src/'.$this->title)) {
183 $localDef = INSTALLDIR.'/local/doc-src/'.$this->title;
186 $local = glob(INSTALLDIR.'/local/doc-src/'.$this->title.'.*');
187 if ($local === false) {
192 if (count($local) || isset($localDef)) {
193 return $this->negotiateLanguage($local, $localDef);
196 if (file_exists(INSTALLDIR.'/doc-src/'.$this->title)) {
197 $distDef = INSTALLDIR.'/doc-src/'.$this->title;
200 $dist = glob(INSTALLDIR.'/doc-src/'.$this->title.'.*');
201 if ($dist === false) {
205 if (count($dist) || isset($distDef)) {
206 return $this->negotiateLanguage($dist, $distDef);
212 function negotiateLanguage($filenames, $defaultFilename=null)
214 // XXX: do this better
216 $langcode = common_language();
218 foreach ($filenames as $filename) {
219 if (preg_match('/\.'.$langcode.'$/', $filename)) {
224 return $defaultFilename;