| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup UnaBaseView UNA Base Representation Classes
- * @{
- */
- /**
- * Services for Wiki functionality
- */
- class BxBaseServiceWiki extends BxDol
- {
- protected $_bJsCssAdded = false;
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-wiki Wiki
- * @subsubsection bx_system_general-wiki_page wiki_page
- *
- * @code bx_srv('system', 'wiki_page', ["index"], 'TemplServiceWiki'); @endcode
- * @code {{~system:wiki_page:TemplServiceWiki["index"]~}} @endcode
- *
- * Display WIKI page.
- * @param $sUri categories object name
- *
- * @see BxBaseServiceWiki::serviceWikiPage
- */
- /**
- * @ref bx_system_general-wiki_page "wiki_page"
- */
- public function serviceWikiPage ($sWikiObjectUri, $sUri)
- {
- $oWiki = BxDolWiki::getObjectInstanceByUri($sWikiObjectUri);
- if (!$oWiki) {
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->displayPageNotFound();
- return;
- }
- $oPage = BxDolPage::getObjectInstanceByModuleAndURI($oWiki->getObjectName(), $sUri);
- if ($oPage) {
- $oPage->displayPage();
- } else {
- if ($oWiki->isAllowed('add')) {
- $oPage = BxDolPage::getObjectInstanceByURI($sUri);
- if ($oPage) {
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->displayErrorOccured(_t("_sys_wiki_error_page_exists", bx_process_output($sUri)));
- } else {
- 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.";
- }
- }
- else {
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->displayPageNotFound();
- }
- }
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-wiki Wiki
- * @subsubsection bx_system_general-wiki_action wiki_action
- *
- * @code bx_srv('system', 'wiki_action', [...], 'TemplServiceWiki'); @endcode
- *
- * Perform WIKI action.
- * @param $sUri categories object name
- *
- * @see BxBaseServiceWiki::serviceWikiAction
- */
- /**
- * @ref bx_system_general-wiki_action "wiki_action"
- */
- public function serviceWikiAction ($sWikiObjectUri, $sAction)
- {
- $oWiki = BxDolWiki::getObjectInstanceByUri($sWikiObjectUri);
- if (!$oWiki) {
- echoJson(array('code' => 1, 'actions' => 'ShowMsg', 'msg' => _t('_sys_wiki_error_missing_wiki_object', $sWikiObjectUri)));
- return;
- }
- $sMethod = 'action' . bx_gen_method_name($sAction, array('-'));
- if (!method_exists($oWiki, $sMethod) || !$oWiki->isAllowed($sAction)) {
- echoJson(array('code' => 2, 'actions' => 'ShowMsg', 'msg' => _t('_sys_wiki_error_action_not_allowed', $sAction, $sWikiObjectUri)));
- return;
- }
-
- $mixed = $oWiki->$sMethod();
- if (is_array($mixed))
- echoJson($mixed);
- else
- echo $mixed;
- }
- /**
- * @page service Service Calls
- * @section bx_system_general System Services
- * @subsection bx_system_general-wiki Wiki
- * @subsubsection bx_system_general-wiki_page wiki_page
- *
- * @code bx_srv('system', 'wiki_page', ["index"], 'TemplServiceWiki'); @endcode
- * @code {{~system:wiki_page:TemplServiceWiki["index"]~}} @endcode
- *
- * Add controls for edit, delete, translate, history, etc content
- * @param $sUri categories object name
- *
- * @see BxBaseServiceWiki::serviceWikiPage
- * @param $iBlockId block ID
- */
- /**
- * @ref bx_system_general-wiki_page "wiki_page"
- */
- public function serviceWikiControls ($oWikiObject, $aWikiVer, $sBlockId)
- {
- $this->_addCssJs ();
-
- if (!($oMenu = BxDolMenu::getObjectInstance('sys_wiki')))
- return '';
- $oMenu->setMenuObject($oWikiObject);
- $o = BxDolTemplate::getInstance();
- return $o->parseHtmlByName('wiki_controls.html', array(
- 'obj' => $oWikiObject->getObjectName(),
- 'block_id' => $sBlockId,
- 'menu' => $oMenu->getCode(),
- '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',
- 'options' => json_encode(array(
- 'block_id' => $sBlockId,
- 'lang' => $aWikiVer['lang'],
- 'wiki_action_uri' => $oWikiObject->getWikiUri(),
- )),
- ));
- }
- protected function _addCssJs ()
- {
- if ($this->_bJsCssAdded)
- return false;
- $o = BxDolTemplate::getInstance();
- $o->addCss('wiki.css');
- $o->addJs('BxDolWiki.js');
- $this->_bJsCssAdded = true;
- }
- }
- /** @} */
|