1
0

BxBaseServiceWiki.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 $sUri categories object name
  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_page wiki_page
  98. *
  99. * @code bx_srv('system', 'wiki_page', ["index"], 'TemplServiceWiki'); @endcode
  100. * @code {{~system:wiki_page:TemplServiceWiki["index"]~}} @endcode
  101. *
  102. * Add controls for edit, delete, translate, history, etc content
  103. * @param $sUri categories object name
  104. *
  105. * @see BxBaseServiceWiki::serviceWikiPage
  106. * @param $iBlockId block ID
  107. */
  108. /**
  109. * @ref bx_system_general-wiki_page "wiki_page"
  110. */
  111. public function serviceWikiControls ($oWikiObject, $aWikiVer, $sBlockId)
  112. {
  113. $this->_addCssJs ();
  114. if (!($oMenu = BxDolMenu::getObjectInstance('sys_wiki')))
  115. return '';
  116. $oMenu->setMenuObject($oWikiObject);
  117. $o = BxDolTemplate::getInstance();
  118. return $o->parseHtmlByName('wiki_controls.html', array(
  119. 'obj' => $oWikiObject->getObjectName(),
  120. 'block_id' => $sBlockId,
  121. 'menu' => $oMenu->getCode(),
  122. 'info' => bx_time_js($aWikiVer['added']), // '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',
  123. 'options' => json_encode(array(
  124. 'block_id' => $sBlockId,
  125. 'lang' => $aWikiVer['lang'],
  126. 'wiki_action_uri' => $oWikiObject->getWikiUri(),
  127. )),
  128. ));
  129. }
  130. protected function _addCssJs ()
  131. {
  132. if ($this->_bJsCssAdded)
  133. return false;
  134. $o = BxDolTemplate::getInstance();
  135. $o->addCss('wiki.css');
  136. $o->addJs('BxDolWiki.js');
  137. $this->_bJsCssAdded = true;
  138. }
  139. }
  140. /** @} */