Przeglądaj źródła

#2304 Wiki functionality: controls

Alex Trofimov 6 lat temu
rodzic
commit
16a939edd8

+ 18 - 19
inc/classes/BxDolWiki.php

@@ -116,28 +116,16 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
     {
         if (!$sLang)
             $sLang = bx_lang_name();
-        $a = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
+        $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
 
         require_once(BX_DIRECTORY_PATH_PLUGINS . "parsedown/Parsedown.php");
         $oParsedown = new Parsedown();
-        $oParsedown->setSafeMode($a['unsafe'] ? false : true);
-        $s = $oParsedown->text($a['content']);
+        $oParsedown->setSafeMode($aWikiVer['unsafe'] ? false : true);
+        $s = $oParsedown->text($aWikiVer['content']);
 
-        $s = $this->addControls($iBlockId, $s);
+        $sControls = BxDolService::call('system', 'wiki_controls', array($this, $aWikiVer, $iBlockId), 'TemplServiceWiki');
 
-        return $s;
-    }
-
-    /**
-     * Add controls for edit, delete, translate, history, etc content
-     * @param $iBlockId block ID
-     * @param $sLang optional language name
-     * @return block content
-     */
-    public function addControls ($iBlockId, $s)
-    {
-        $sControl = "<div>TODO: wiki - controls here. On left - Edit, Delete version, Delete block, Translate, History. 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.</div>";
-        return $s . $sControl;
+        return $s . $sControls;
     }
 
     /**
@@ -151,14 +139,25 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         if (isAdmin())
             return true;
 
+        if ('history' == $sType)
+            return true;
+
         $aTypes = array(
             'add' => 'allow_add_for_levels',
             'edit' => 'allow_edit_for_levels',
-            'delete' => 'allow_delete_for_levels',
+            'delete-version' => 'allow_delete_for_levels',
+            'delete-block' => 'allow_delete_for_levels',
             'translate' => 'allow_translate_for_levels',
+            'history' => true,
             'unsafe' => 'allow_unsafe_for_levels',
         );
-        if (!isset($aTypes[$sType]) || !isset($this->_aObject[$aTypes[$sType]]))
+        if (!isset($aTypes[$sType]))
+            return false;
+
+        if (true === $aTypes[$sType] || false === $aTypes[$sType])
+            return $aTypes[$sType];
+
+        if (!isset($this->_aObject[$aTypes[$sType]]))
             return false;
 
         $oAcl = BxDolAcl::getInstance();

+ 2 - 2
inc/classes/BxDolWikiQuery.php

@@ -52,12 +52,12 @@ class BxDolWikiQuery extends BxDolDb
         }
 
         // get latest revision for specific language
-        $aRow = $this->getRow("SELECT `content`, `unsafe` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `language` = :lang $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
+        $aRow = $this->getRow("SELECT `content`, `unsafe`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `language` = :lang $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
 
         // if translation isn't found for specific language then get latest revision for main language 
         if (!$aRow) {
             unset($aBind['lang']);
-            $aRow = $this->getRow("SELECT `content`, `unsafe` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `main_language` = 1 $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
+            $aRow = $this->getRow("SELECT `content`, `unsafe`, `added` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `main_language` = 1 $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
         }
 
         return $aRow ? $aRow : false;

+ 54 - 0
inc/js/classes/BxDolWiki.js

@@ -0,0 +1,54 @@
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+function BxDolWiki (sObject, eContainer, oOptions) {
+    var oDefault = {};
+    this._oOptions = $.extend({}, oDefault, oOptions);
+    this._sObject = sObject;
+    this._eCont = eContainer;
+    this.bindEvents();
+}
+
+BxDolWiki.prototype.bindEvents = function () {
+    var self = this;
+    var oEvents = {
+        "edit": "onEdit",
+        "delete-version": "onDeleteVersion",
+        "delete-block": "onDeleteBlock",
+        "translate": "onTranslate",
+        "history": "onHistory",
+    }
+    $.each(oEvents, function (sSel, sFunc) {
+        $(self._eCont).find(".bx-wiki-controls-menu a." + sSel).on('click', {wiki_obj:self}, function() {
+            BxDolWiki.prototype[sFunc].apply(self);
+            return false;
+        });
+    });
+};
+
+BxDolWiki.prototype.onEdit = function () {
+    console.log("onEdit2:" + this._sObject);
+};
+
+BxDolWiki.prototype.onDeleteVersion = function () {
+    console.log("onDeleteVersion:" + this._sObject);
+};
+
+BxDolWiki.prototype.onDeleteBlock = function () {
+    console.log("onDeleteBlock:" + this._sObject);
+};
+
+BxDolWiki.prototype.onHistory = function () {
+    console.log("onHistory:" + this._sObject);
+};
+
+BxDolWiki.prototype.onTranslate = function () {
+    console.log("onTranslate:" + this._sObject);
+};
+
+/** @} */

+ 11 - 1
install/sql/system.sql

@@ -3785,7 +3785,8 @@ INSERT INTO `sys_objects_menu` (`object`, `title`, `set_name`, `module`, `templa
 ('sys_social_sharing', '_sys_menu_title_social_sharing', 'sys_social_sharing', 'system', 23, 0, 1, 'BxTemplMenuSocialSharing', ''),
 ('sys_create_post', '_sys_menu_title_create_post', 'sys_add_content_links', 'system', 15, 0, 1, 'BxTemplMenuCreatePost', ''),
 ('sys_add_relation', '_sys_menu_title_add_relation', '', 'system', 6, 0, 1, 'BxTemplMenuAddRelation', ''),
-('sys_vote_reactions_do', '_sys_menu_title_vote_reactions_do', '', 'system', 3, 0, 1, 'BxTemplVoteReactionsMenuDo', '');
+('sys_vote_reactions_do', '_sys_menu_title_vote_reactions_do', '', 'system', 3, 0, 1, 'BxTemplVoteReactionsMenuDo', ''),
+('sys_wiki', '_sys_menu_title_wiki', 'sys_wiki', 'system', 9, 0, 1, 'BxTemplMenuWiki', '');
 
 CREATE TABLE IF NOT EXISTS `sys_menu_sets` (
   `set_name` varchar(64) NOT NULL,
@@ -3817,6 +3818,7 @@ INSERT INTO `sys_menu_sets` (`set_name`, `module`, `title`, `deletable`) VALUES
 ('sys_switch_language', 'system', '_sys_menu_set_title_switch_language', 0),
 ('sys_switch_template', 'system', '_sys_menu_set_title_switch_template', 0),
 ('sys_social_sharing', 'system', '_sys_menu_set_title_sys_social_sharing', 0);
+('sys_wiki', 'system', '_sys_menu_set_title_sys_wiki', 0);
 
 CREATE TABLE IF NOT EXISTS `sys_menu_items` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
@@ -3941,6 +3943,14 @@ INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `titl
 INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES
 ('sys_profile_stats', 'system', 'profile-stats-profile', '_sys_menu_item_title_system_profile', '_sys_menu_item_title_profile', '{member_url}', '', '', 'user', 'a:4:{s:6:"module";s:6:"system";s:6:"method";s:27:"get_menu_addon_profile_edit";s:6:"params";a:0:{}s:5:"class";s:20:"TemplServiceProfiles";}', '', 2147483646, 1, 0, 0);
 
+-- wiki menu
+INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `addon`, `submenu_object`, `submenu_popup`, `visible_for_levels`, `visibility_custom`, `active`, `copyable`, `editable`, `order`) VALUES 
+('sys_wiki', 'system', 'edit', '', '_sys_menu_item_title_wiki_edit', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 1, 1),
+('sys_wiki', 'system', 'delete-version', '', '_sys_menu_item_title_wiki_delete_version', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 1, 2),
+('sys_wiki', 'system', 'delete-block', '', '_sys_menu_item_title_wiki_delete_block', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 1, 3),
+('sys_wiki', 'system', 'translate', '', '_sys_menu_item_title_wiki_translate', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 1, 4),
+('sys_wiki', 'system', 'history', '', '_sys_menu_item_title_wiki_history', '', '', '', '', '', '', 0, 2147483647, '', 1, 0, 1, 5);
+
 -- --------------------------------------------------------
 
 

+ 17 - 0
modules/boonex/decorous/data/template/system/scripts/BxTemplMenuWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolMenu
+ */
+class BxTemplMenuWiki extends BxBaseMenuWiki
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/decorous/data/template/system/scripts/BxTemplServiceWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxBaseServiceWiki
+ */
+class BxTemplServiceWiki extends BxBaseServiceWiki
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/lucid/data/template/system/scripts/BxTemplMenuWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolMenu
+ */
+class BxTemplMenuWiki extends BxBaseMenuWiki
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplMenuWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolMenu
+ */
+class BxTemplMenuWiki extends BxBaseMenuWiki
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplServiceWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxBaseServiceWiki
+ */
+class BxTemplServiceWiki extends BxBaseServiceWiki
+{
+}
+
+/** @} */

+ 17 - 0
modules/boonex/protean/data/template/system/scripts/BxTemplMenuWiki.php

@@ -0,0 +1,17 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolMenu
+ */
+class BxTemplMenuWiki extends BxBaseMenuWiki
+{
+}
+
+/** @} */

+ 6 - 0
template/css/wiki.css

@@ -0,0 +1,6 @@
+.bx-wiki-controls-menu {
+    float:left;
+}
+.bx-wiki-controls-info {
+    float:right;
+}

+ 41 - 0
template/scripts/BxBaseMenuWiki.php

@@ -0,0 +1,41 @@
+<?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
+ * @{
+ */
+
+/**
+ * Wiki block menu
+ */
+class BxBaseMenuWiki extends BxTemplMenu
+{
+    protected $_oWikiObject;
+
+    public function __construct ($aObject, $oTemplate)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+
+    public function setMenuObject($o)
+    {
+        $this->_oWikiObject = $o;
+    }
+
+    /**
+     * Check if menu items is visible with extended checking for friends notifications
+     * @param $a menu item array
+     * @return boolean
+     */
+    protected function _isVisible ($a)
+    {
+        if(!$this->_oWikiObject || !parent::_isVisible($a))
+            return false;
+
+        return $this->_oWikiObject->isAllowed($a['name']);
+    }
+}
+
+/** @} */

+ 1 - 1
template/scripts/BxBasePage.php

@@ -403,7 +403,7 @@ class BxBasePage extends BxDolPage
             $sContent = bx_process_macros($sContent);
         }
 
-        $s = '<div class="bx-page-wiki-container">' . $sContent . '</div>';
+        $s = '<div id="bx-page-wiki-container-' . $aBlock['id'] . '" class="bx-page-wiki-container">' . $sContent . '</div>';
         $s = $this->_replaceMarkers($s);
         $s = bx_process_macros($s);
         return $s;

+ 49 - 0
template/scripts/BxBaseServiceWiki.php

@@ -12,6 +12,7 @@
  */
 class BxBaseServiceWiki extends BxDol
 {
+    protected $_bJsCssAdded = false;
 
     /**
      * @page service Service Calls
@@ -62,6 +63,54 @@ class BxBaseServiceWiki extends BxDol
         }
 
     }
+
+    /**
+     * @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()),
+        ));
+    }
+
+    protected function _addCssJs ()
+    {
+        if ($this->_bJsCssAdded)
+            return false;
+
+        $o = BxDolTemplate::getInstance();
+        $o->addCss('wiki.css');
+        $o->addJs('BxDolWiki.js');
+        $this->_bJsCssAdded = true;
+    }
 }
 
 /** @} */

+ 7 - 0
template/wiki_controls.html

@@ -0,0 +1,7 @@
+<div class="bx-wiki-controls bx-clearfix">
+    <div class="bx-wiki-controls-menu">__menu__</div>
+    <div class="bx-wiki-controls-info bx-def-font-grayed bx-def-font-small">__info__</div>
+</div>
+<script>
+    new BxDolWiki('__obj__', $('#bx-page-wiki-container-__block_id__'), __options__);
+</script>