doc.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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('GNUSOCIAL')) { exit(1); }
  31. /**
  32. * Documentation class.
  33. *
  34. * @category Action
  35. * @package StatusNet
  36. * @author Evan Prodromou <evan@status.net>
  37. * @author Robin Millette <millette@status.net>
  38. * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
  39. * @link http://status.net/
  40. */
  41. class DocAction extends ManagedAction
  42. {
  43. var $output = null;
  44. var $filename = null;
  45. var $title = null;
  46. protected function doPreparation()
  47. {
  48. $this->title = $this->trimmed('title');
  49. if (!preg_match('/^[a-zA-Z0-9_-]*$/', $this->title)) {
  50. $this->title = 'help';
  51. }
  52. $this->output = null;
  53. $this->loadDoc();
  54. }
  55. public function title()
  56. {
  57. return ucfirst($this->title);
  58. }
  59. /**
  60. * Display content.
  61. *
  62. * Shows the content of the document.
  63. *
  64. * @return void
  65. */
  66. function showContent()
  67. {
  68. $this->raw($this->output);
  69. }
  70. function showNoticeForm()
  71. {
  72. // no notice form
  73. }
  74. /**
  75. * These pages are read-only.
  76. *
  77. * @param array $args unused.
  78. *
  79. * @return boolean read-only flag (false)
  80. */
  81. function isReadOnly($args)
  82. {
  83. return true;
  84. }
  85. function loadDoc()
  86. {
  87. if (Event::handle('StartLoadDoc', array(&$this->title, &$this->output))) {
  88. $paths = DocFile::defaultPaths();
  89. $docfile = DocFile::forTitle($this->title, $paths);
  90. if (empty($docfile)) {
  91. // TRANS: Client exception thrown when requesting a document from the documentation that does not exist.
  92. // TRANS: %s is the non-existing document.
  93. throw new ClientException(sprintf(_('No such document "%s".'), $this->title), 404);
  94. }
  95. $this->output = $docfile->toHTML();
  96. Event::handle('EndLoadDoc', array($this->title, &$this->output));
  97. }
  98. }
  99. function showLocalNav()
  100. {
  101. $menu = new DocNav($this);
  102. $menu->show();
  103. }
  104. }
  105. class DocNav extends Menu
  106. {
  107. function show()
  108. {
  109. if (Event::handle('StartDocNav', array($this))) {
  110. $stub = new HomeStubNav($this->action);
  111. $this->submenu(_m('MENU','Home'), $stub);
  112. $docs = new DocListNav($this->action);
  113. $this->submenu(_m('MENU','Docs'), $docs);
  114. Event::handle('EndDocNav', array($this));
  115. }
  116. }
  117. }
  118. class DocListNav extends Menu
  119. {
  120. function getItems()
  121. {
  122. $items = array();
  123. if (Event::handle('StartDocsMenu', array(&$items))) {
  124. $items = array(array('doc',
  125. array('title' => 'help'),
  126. _m('MENU', 'Help'),
  127. _('Getting started'),
  128. 'nav_doc_help'),
  129. array('doc',
  130. array('title' => 'about'),
  131. _m('MENU', 'About'),
  132. _('About this site'),
  133. 'nav_doc_about'),
  134. array('doc',
  135. array('title' => 'faq'),
  136. _m('MENU', 'FAQ'),
  137. _('Frequently asked questions'),
  138. 'nav_doc_faq'),
  139. array('doc',
  140. array('title' => 'contact'),
  141. _m('MENU', 'Contact'),
  142. _('Contact info'),
  143. 'nav_doc_contact'),
  144. array('doc',
  145. array('title' => 'tags'),
  146. _m('MENU', 'Tags'),
  147. _('Using tags'),
  148. 'nav_doc_tags'),
  149. array('doc',
  150. array('title' => 'groups'),
  151. _m('MENU', 'Groups'),
  152. _('Using groups'),
  153. 'nav_doc_groups'),
  154. array('doc',
  155. array('title' => 'api'),
  156. _m('MENU', 'API'),
  157. _('RESTful API'),
  158. 'nav_doc_api'));
  159. Event::handle('EndDocsMenu', array(&$items));
  160. }
  161. return $items;
  162. }
  163. }