doc.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. if (!defined('STATUSNET') && !defined('LACONICA')) {
  31. 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 Action
  44. {
  45. var $output = null;
  46. var $filename = null;
  47. var $title = null;
  48. function prepare($args)
  49. {
  50. parent::prepare($args);
  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. $this->loadDoc();
  57. return true;
  58. }
  59. /**
  60. * Handle a request
  61. *
  62. * @param array $args array of arguments
  63. *
  64. * @return nothing
  65. */
  66. function handle($args)
  67. {
  68. parent::handle($args);
  69. $this->showPage();
  70. }
  71. /**
  72. * Page title
  73. *
  74. * Gives the page title of the document. Override default for hAtom entry.
  75. *
  76. * @return void
  77. */
  78. function showPageTitle()
  79. {
  80. $this->element('h1', array('class' => 'entry-title'), $this->title());
  81. }
  82. /**
  83. * Block for content.
  84. *
  85. * Overrides default from Action to wrap everything in an hAtom entry.
  86. *
  87. * @return void.
  88. */
  89. function showContentBlock()
  90. {
  91. $this->elementStart('div', array('id' => 'content', 'class' => 'h-entry'));
  92. $this->showPageTitle();
  93. $this->showPageNoticeBlock();
  94. $this->elementStart('div', array('id' => 'content_inner',
  95. 'class' => 'e-content'));
  96. // show the actual content (forms, lists, whatever)
  97. $this->showContent();
  98. $this->elementEnd('div');
  99. $this->elementEnd('div');
  100. }
  101. /**
  102. * Display content.
  103. *
  104. * Shows the content of the document.
  105. *
  106. * @return void
  107. */
  108. function showContent()
  109. {
  110. $this->raw($this->output);
  111. }
  112. /**
  113. * Page title.
  114. *
  115. * Uses the title of the document.
  116. *
  117. * @return page title
  118. */
  119. function title()
  120. {
  121. return ucfirst($this->title);
  122. }
  123. /**
  124. * These pages are read-only.
  125. *
  126. * @param array $args unused.
  127. *
  128. * @return boolean read-only flag (false)
  129. */
  130. function isReadOnly($args)
  131. {
  132. return true;
  133. }
  134. function loadDoc()
  135. {
  136. if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
  137. $paths = DocFile::defaultPaths();
  138. $docfile = DocFile::forTitle($this->title, $paths);
  139. if (empty($docfile)) {
  140. // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
  141. // TRANS: %s is the non-existing document.
  142. throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
  143. }
  144. $this->output = $docfile->toHTML();
  145. Event::handle('EndLoadDoc', array($this->title, &$this->output));
  146. }
  147. }
  148. function showLocalNav()
  149. {
  150. $menu = new DocNav($this);
  151. $menu->show();
  152. }
  153. }
  154. class DocNav extends Menu
  155. {
  156. function show()
  157. {
  158. $stub = new HomeStubNav($this->action);
  159. $this->submenu(_m('MENU','Home'), $stub);
  160. $docs = new DocListNav($this->action);
  161. $this->submenu(_m('MENU','Docs'), $docs);
  162. }
  163. }
  164. class DocListNav extends Menu
  165. {
  166. function getItems()
  167. {
  168. $items = array();
  169. if (Event::handle('StartDocsMenu', array(&$items))) {
  170. $items = array(array('doc',
  171. array('title' => 'help'),
  172. _m('MENU', 'Help'),
  173. _('Getting started'),
  174. 'nav_doc_help'),
  175. array('doc',
  176. array('title' => 'about'),
  177. _m('MENU', 'About'),
  178. _('About this site'),
  179. 'nav_doc_about'),
  180. array('doc',
  181. array('title' => 'faq'),
  182. _m('MENU', 'FAQ'),
  183. _('Frequently asked questions'),
  184. 'nav_doc_faq'),
  185. array('doc',
  186. array('title' => 'contact'),
  187. _m('MENU', 'Contact'),
  188. _('Contact info'),
  189. 'nav_doc_contact'),
  190. array('doc',
  191. array('title' => 'tags'),
  192. _m('MENU', 'Tags'),
  193. _('Using tags'),
  194. 'nav_doc_tags'),
  195. array('doc',
  196. array('title' => 'groups'),
  197. _m('MENU', 'Groups'),
  198. _('Using groups'),
  199. 'nav_doc_groups'),
  200. array('doc',
  201. array('title' => 'api'),
  202. _m('MENU', 'API'),
  203. _('RESTful API'),
  204. 'nav_doc_api'));
  205. Event::handle('EndDocsMenu', array(&$items));
  206. }
  207. return $items;
  208. }
  209. }