doc.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. if (Event::handle('StartDocNav', array($this))) {
  159. $stub = new HomeStubNav($this->action);
  160. $this->submenu(_m('MENU','Home'), $stub);
  161. $docs = new DocListNav($this->action);
  162. $this->submenu(_m('MENU','Docs'), $docs);
  163. Event::handle('EndDocNav', array($this));
  164. }
  165. }
  166. }
  167. class DocListNav extends Menu
  168. {
  169. function getItems()
  170. {
  171. $items = array();
  172. if (Event::handle('StartDocsMenu', array(&$items))) {
  173. $items = array(array('doc',
  174. array('title' => 'help'),
  175. _m('MENU', 'Help'),
  176. _('Getting started'),
  177. 'nav_doc_help'),
  178. array('doc',
  179. array('title' => 'about'),
  180. _m('MENU', 'About'),
  181. _('About this site'),
  182. 'nav_doc_about'),
  183. array('doc',
  184. array('title' => 'faq'),
  185. _m('MENU', 'FAQ'),
  186. _('Frequently asked questions'),
  187. 'nav_doc_faq'),
  188. array('doc',
  189. array('title' => 'contact'),
  190. _m('MENU', 'Contact'),
  191. _('Contact info'),
  192. 'nav_doc_contact'),
  193. array('doc',
  194. array('title' => 'tags'),
  195. _m('MENU', 'Tags'),
  196. _('Using tags'),
  197. 'nav_doc_tags'),
  198. array('doc',
  199. array('title' => 'groups'),
  200. _m('MENU', 'Groups'),
  201. _('Using groups'),
  202. 'nav_doc_groups'),
  203. array('doc',
  204. array('title' => 'api'),
  205. _m('MENU', 'API'),
  206. _('RESTful API'),
  207. 'nav_doc_api'));
  208. Event::handle('EndDocsMenu', array(&$items));
  209. }
  210. return $items;
  211. }
  212. }