BxBaseServiceWiki.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Services for Wiki functionality
  11. */
  12. class BxBaseServiceWiki extends BxDol
  13. {
  14. protected $_bJsCssAdded = false;
  15. /**
  16. * @page service Service Calls
  17. * @section bx_system_general System Services
  18. * @subsection bx_system_general-wiki Wiki
  19. * @subsubsection bx_system_general-wiki_page wiki_page
  20. *
  21. * @code bx_srv('system', 'wiki_page', ["index"], 'TemplServiceWiki'); @endcode
  22. * @code {{~system:wiki_page:TemplServiceWiki["index"]~}} @endcode
  23. *
  24. * Display WIKI page.
  25. * @param $sUri categories object name
  26. *
  27. * @see BxBaseServiceWiki::serviceWikiPage
  28. */
  29. /**
  30. * @ref bx_system_general-wiki_page "wiki_page"
  31. */
  32. public function serviceWikiPage ($sWikiObjectUri, $sUri)
  33. {
  34. $oWiki = BxDolWiki::getObjectInstanceByUri($sWikiObjectUri);
  35. if (!$oWiki) {
  36. $oTemplate = BxDolTemplate::getInstance();
  37. $oTemplate->displayPageNotFound();
  38. return;
  39. }
  40. $oPage = BxDolPage::getObjectInstanceByModuleAndURI($oWiki->getObjectName(), $sUri);
  41. if ($oPage) {
  42. $oPage->displayPage();
  43. } else {
  44. if ($oWiki->isAllowed('add')) {
  45. $oPage = BxDolPage::getObjectInstanceByURI($sUri);
  46. if ($oPage) {
  47. $oTemplate = BxDolTemplate::getInstance();
  48. $oTemplate->displayErrorOccured(_t("_sys_wiki_error_page_exists", bx_process_output($sUri)));
  49. } else {
  50. echo "TODO: wiki - suggest to create page with specified URI. Display form where user can enter title(text input), text(plain textrea), languale (selectbox with currect site languages with current one pre-selected), revision comments (text input), title - will be page and first block title, text - will be content for first block. Default layout is page with one column and block without borders and title.";
  51. }
  52. }
  53. else {
  54. $oTemplate = BxDolTemplate::getInstance();
  55. $oTemplate->displayPageNotFound();
  56. }
  57. }
  58. }
  59. /**
  60. * @page service Service Calls
  61. * @section bx_system_general System Services
  62. * @subsection bx_system_general-wiki Wiki
  63. * @subsubsection bx_system_general-wiki_action wiki_action
  64. *
  65. * @code bx_srv('system', 'wiki_action', [...], 'TemplServiceWiki'); @endcode
  66. *
  67. * Perform WIKI action.
  68. * @param $sWikiObjectUri wiki object URI
  69. *
  70. * @see BxBaseServiceWiki::serviceWikiAction
  71. */
  72. /**
  73. * @ref bx_system_general-wiki_action "wiki_action"
  74. */
  75. public function serviceWikiAction ($sWikiObjectUri, $sAction)
  76. {
  77. $oWiki = BxDolWiki::getObjectInstanceByUri($sWikiObjectUri);
  78. if (!$oWiki) {
  79. echoJson(array('code' => 1, 'actions' => 'ShowMsg', 'msg' => _t('_sys_wiki_error_missing_wiki_object', $sWikiObjectUri)));
  80. return;
  81. }
  82. $sMethod = 'action' . bx_gen_method_name($sAction, array('-'));
  83. if (!method_exists($oWiki, $sMethod) || !$oWiki->isAllowed($sAction)) {
  84. echoJson(array('code' => 2, 'actions' => 'ShowMsg', 'msg' => _t('_sys_wiki_error_action_not_allowed', $sAction, $sWikiObjectUri)));
  85. return;
  86. }
  87. $mixed = $oWiki->$sMethod();
  88. if (is_array($mixed))
  89. echoJson($mixed);
  90. else
  91. echo $mixed;
  92. }
  93. /**
  94. * @page service Service Calls
  95. * @section bx_system_general System Services
  96. * @subsection bx_system_general-wiki Wiki
  97. * @subsubsection bx_system_general-wiki_controls wiki_controls
  98. *
  99. * Get wiki block controls panel
  100. *
  101. * @see BxBaseServiceWiki::serviceWikiControls
  102. */
  103. /**
  104. * @ref bx_system_general-wiki_controls "wiki_controls"
  105. */
  106. public function serviceWikiControls ($oWikiObject, $aWikiVer, $aWikiVerLatest, $sBlockId)
  107. {
  108. $this->_addCssJs ();
  109. if (!($oMenu = BxDolMenu::getObjectInstance('sys_wiki')))
  110. return '';
  111. $oMenu->setMenuObject($oWikiObject);
  112. $sInfo = '';
  113. if ($aWikiVer && $aWikiVerLatest['revision'] == $aWikiVer['revision']) {
  114. $sInfo = bx_time_js($aWikiVer['added']);
  115. }
  116. elseif ($aWikiVer) {
  117. $oProfile = BxDolProfile::getInstanceMagic($aWikiVer['profile_id']);
  118. $sInfo = _t('_sys_wiki_view_rev', $aWikiVer['revision'], $oProfile->getUrl(), $oProfile->getDisplayName(), bx_time_js($aWikiVer['added']));
  119. }
  120. $o = BxDolTemplate::getInstance();
  121. return $o->parseHtmlByName('wiki_controls.html', array(
  122. 'obj' => $oWikiObject->getObjectName(),
  123. 'block_id' => $sBlockId,
  124. 'menu' => $oMenu->getCode(),
  125. // 'TODO: On right - Last modified time and List of missing and outdated translations. History and Last modified time should be controlled by regular menu privacy, while other actions should have custom privacy for particular wiki object',
  126. 'info' => $sInfo,
  127. 'options' => json_encode(array(
  128. 'block_id' => $sBlockId,
  129. 'lang' => isset($aWikiVer['lang']) ? $aWikiVer['lang'] : bx_lang_name(),
  130. 'wiki_action_uri' => $oWikiObject->getWikiUri(),
  131. 't_confirm_block_deletion' => _t('_sys_wiki_confirm_block_deletion'),
  132. )),
  133. ));
  134. }
  135. /**
  136. * @page service Service Calls
  137. * @section bx_system_general System Services
  138. * @subsection bx_system_general-wiki Wiki
  139. * @subsubsection bx_system_general-wiki_add_block wiki_add_block
  140. *
  141. * Get "add wiki block" panel
  142. *
  143. * @see BxBaseServiceWiki::serviceWikiAddBlock
  144. */
  145. /**
  146. * @ref bx_system_general-wiki_add_block "wiki_add_block"
  147. */
  148. public function serviceWikiAddBlock ($oWikiObject, $sPageObject, $sCellId)
  149. {
  150. $this->_addCssJs ();
  151. if (!preg_match("/cell_(\d+)/", $sCellId, $aMatches))
  152. return '';
  153. $iCellId = $aMatches[1];
  154. $o = BxDolTemplate::getInstance();
  155. return $o->parseHtmlByName('wiki_add_block.html', array(
  156. 'add_block' => _t('_sys_wiki_add_block'),
  157. 'page' => $sPageObject,
  158. 'cell_id' => $iCellId,
  159. 'action_uri' => $oWikiObject->getWikiUri(),
  160. ));
  161. }
  162. protected function _addCssJs ()
  163. {
  164. if ($this->_bJsCssAdded)
  165. return false;
  166. $o = BxDolTemplate::getInstance();
  167. $o->addCss('wiki.css');
  168. $o->addJs('BxDolWiki.js');
  169. $this->_bJsCssAdded = true;
  170. }
  171. }
  172. /** @} */