Răsfoiți Sursa

#2304 Wiki: basic functionality

Alex Trofimov 6 ani în urmă
părinte
comite
b559b2f66a

+ 32 - 0
inc/classes/BxDolPage.php

@@ -129,6 +129,24 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         $this->_oQuery = new BxDolPageQuery($this->_aObject);
         $this->_oQuery = new BxDolPageQuery($this->_aObject);
     }
     }
 
 
+    /**
+     * Get page object instance by Module name and page URI
+     * @param $sModule module name
+     * @param $sURI unique page URI
+     * @return object instance or false on error
+     */
+    static public function getObjectInstanceByModuleAndURI($sModule, $sURI = '', $oTemplate = false)
+    {
+    	if(empty($sURI) && bx_get('i') !== false)
+    		$sURI = bx_process_input(bx_get('i'));
+
+    	if(empty($sURI))
+			return false;
+
+        $sObject = BxDolPageQuery::getPageObjectNameByURI($sURI, $sModule);
+        return $sObject ? self::getObjectInstance($sObject, $oTemplate) : false;
+    }
+
     /**
     /**
      * Get page object instance by page URI
      * Get page object instance by page URI
      * @param $sURI unique page URI
      * @param $sURI unique page URI
@@ -215,6 +233,20 @@ class BxDolPage extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
         return true;
         return true;
     }
     }
 
 
+    /**
+     * Display complete page
+     */
+    public function displayPage ($oTemplate = null)
+    {
+        if (!$oTemplate)
+            $oTemplate = BxDolTemplate::getInstance();
+
+        $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
+        $oTemplate->setPageType ($this->getType());
+        $oTemplate->setPageContent ('page_main_code', $this->getCode());
+        $oTemplate->getPageCode();
+    }
+
     public function getType ()
     public function getType ()
     {
     {
     	return (int)$this->_aObject['type_id'];
     	return (int)$this->_aObject['type_id'];

+ 8 - 3
inc/classes/BxDolPageQuery.php

@@ -32,11 +32,16 @@ class BxDolPageQuery extends BxDolDb
         return $aObject;
         return $aObject;
     }
     }
 
 
-    static public function getPageObjectNameByURI($sURI)
+    static public function getPageObjectNameByURI($sURI, $sModule = false)
     {
     {
         $oDb = BxDolDb::getInstance();
         $oDb = BxDolDb::getInstance();
-        $sQuery = $oDb->prepare("SELECT `object` FROM `sys_objects_page` WHERE `uri` = ?", $sURI);
-        return $oDb->getOne($sQuery);
+        $a = array('uri' => $sURI);
+        $sQuery = "SELECT `object` FROM `sys_objects_page` WHERE `uri` = :uri";
+        if ($sModule) {
+            $a['module'] = $sModule;
+            $sQuery .= " AND `module` = :module";
+        }
+        return $oDb->getOne($sQuery, $a);
     }
     }
 
 
 	static public function getPageTriggers($sTriggerName)
 	static public function getPageTriggers($sTriggerName)

+ 145 - 0
inc/classes/BxDolWiki.php

@@ -0,0 +1,145 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+/**
+ * WIKI object.
+ *
+ * It's possble to create different WIKI object which will different URLs, Menus and permissions.
+ * For example it's possible to create 
+ * http://example.com/wiki/somepageshere and http://example.com/cocs/anotherpageshere
+ *
+ * @section wiki_create Creating the WIKI object:
+ *
+ *
+ * Add record to 'sys_objects_wiki' table:
+ *
+ * - object: name of the WIKI object, this name will be user in URL as well, 
+ *          for example, 'wiki' will have URLs like this: http://example.com/wiki/somepageshere
+ * - title: title of the WIKI, for example, documentation, help, tutorial
+ * - module: module name WIKI object belongs to
+ * - allow_add_for_levels: allow to add pages and blocks for this member levels
+ * - allow_edit_for_levels: allow to edit block for this member levels
+ * - allow_delete_for_levels: allow to delet pages and blocks for this member levels
+ * - allow_translate_for_levels: allow to add translations for this member levels
+ * - override_class_name: user defined class name 
+ * - override_class_file: the location of the user defined class, leave it empty if class is located in system folders.
+ *
+ * Add record to 'sys_rewrite_rules' table:
+ * - preg - regular expression which matches some URL
+ * - service - service method to call if abbe regular expression matches
+ * - active - active flag
+ *
+ * Add record to 'sys_permalinks' table:
+ * - standard - how link should look like when permalinks are off
+ * - permalink - how link should look like when permalinks are on, 
+ *      some special server configuration may be required to make permalink to work, 
+ *      such as 'mod_rewrite' and .htaccess file for Apache
+ * - check - option name which enables/disables permalinks
+ * - compare_by_prefix - compare by prefix
+ */
+class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
+{
+    protected $_sObject;
+    protected $_aObject;
+
+    /**
+     * Constructor
+     * @param $aObject array of WIKI options
+     */
+    protected function __construct($aObject)
+    {
+        parent::__construct();
+
+        $this->_sObject = $aObject['object'];
+        $this->_aObject = $aObject;
+        $this->_oQuery = new BxDolWikiQuery($aObject);
+    }
+
+    /**
+     * Get WIKI object instance by object name
+     * @param $sObject object name
+     * @return object instance or false on error
+     */
+    static public function getObjectInstance($sObject = false, $oTemplate = false)
+    {
+        if (isset($GLOBALS['bxDolClasses']['BxDolWiki!'.$sObject]))
+            return $GLOBALS['bxDolClasses']['BxDolWiki!'.$sObject];
+
+        $aObject = BxDolWikiQuery::getWikiObject($sObject);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        $sClass = empty($aObject['override_class_name']) ? 'BxDolWiki' : $aObject['override_class_name'];
+        if (!empty($aObject['override_class_file']))
+            require_once(BX_DIRECTORY_PATH_ROOT . $aObject['override_class_file']);
+
+        $o = new $sClass($aObject, $oTemplate);
+
+        return ($GLOBALS['bxDolClasses']['BxDolWiki!'.$sObject] = $o);
+    }
+
+    /**
+     * Get object name
+     */
+    public function getObjectName ()
+    {
+        return $this->_sObject;
+    }
+
+    /**
+     * Get WIKI block content
+     * @param $iBlockId block ID
+     * @param $sLang optional language name
+     * @return block content
+     */
+    public function getBlockContent ($iBlockId, $sLang = false)
+    {
+        if (!$sLang)
+            $sLang = bx_lang_name();
+        $s = $this->_oQuery->getBlockContent ($iBlockId, $sLang);
+        // $s = TODO: wiki - process markdown
+        $s = $this->addControls($iBlockId, $s);
+        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, such as edit, delete, translate, history</div>";
+        return $s . $sControl;
+    }
+
+    /**
+     * Check if partucular action is allowed
+     * @param $sType action type: add, edit, delete, translate
+     * @param $sProfileId profile to check, if not provided then current profile is used
+     * @return true if action is allowed, false otherwise
+     */
+    public function isAllowed ($sType, $iProfileId = false)
+    {
+        $aTypes = array(
+            'add' => 'allow_add_for_levels',
+            'edit' => 'allow_edit_for_levels',
+            'delete' => 'allow_delete_for_levels',
+            'translate' => 'allow_translate_for_levels',
+        );
+        if (!isset($aTypes[$sType]) || !isset($this->_aObject[$aTypes[$sType]]))
+            return false;
+
+        $oAcl = BxDolAcl::getInstance();
+        return $oAcl->isMemberLevelInSet($this->_aObject[$aTypes[$sType]], $iProfileId); 
+    }
+}
+
+/** @} */

+ 57 - 0
inc/classes/BxDolWikiQuery.php

@@ -0,0 +1,57 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+/**
+ * Database queries for WIKI objects.
+ * @see BxDolWiki
+ */
+class BxDolWikiQuery extends BxDolDb
+{
+    protected $_aObject;
+
+    public function __construct($aObject)
+    {
+        parent::__construct();
+        $this->_aObject = $aObject;
+    }
+
+    static public function getWikiObject ($sObject)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT * FROM `sys_objects_wiki` WHERE `object` = ?", $sObject);
+        $aObject = $oDb->getRow($sQuery);
+        if (!$aObject || !is_array($aObject))
+            return false;
+
+        return $aObject;
+    }
+
+    public function getBlockContent ($iBlockId, $sLang, $iRevision = false)
+    {
+        $sWhere = '';
+        $aBind = array('block' => $iBlockId, 'lang' => $sLang);
+        if (false !== $iRevision) {
+            $sWhere = " AND `revision` = :rev";
+            $aBind['rev'] = $iRevision;
+        }
+
+        // get latest revision for specific language
+        $aRow = $this->getRow("SELECT `content` 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` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block AND `main_language` = 1 $sWhere ORDER BY `revision` DESC LIMIT 1", $aBind);
+        }
+
+        return $aRow ? $aRow['content'] : false;
+    }
+}
+
+/** @} */

Fișier diff suprimat deoarece este prea mare
+ 0 - 0
install/sql/system.sql


+ 3 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -3017,5 +3017,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_option_per_page_browse_showcase"><![CDATA[Number of items in showcase view]]></string>
 	<string name="_sys_option_per_page_browse_showcase"><![CDATA[Number of items in showcase view]]></string>
 	<string name="_sys_option_per_page_browse_recommended"><![CDATA[Number of items in recommended view]]></string>
 	<string name="_sys_option_per_page_browse_recommended"><![CDATA[Number of items in recommended view]]></string>
 	<string name="_sys_javascript_requred"><![CDATA[This site requires JavaScript! Please, enable it in the browser!]]></string>
 	<string name="_sys_javascript_requred"><![CDATA[This site requires JavaScript! Please, enable it in the browser!]]></string>
+	<string name="_sys_wiki_system_title"><![CDATA[System WIKI]]></string>
+	<string name="_sys_wiki_error_page_exists"><![CDATA[Page with such name({0}) already exists]]></string>
+	<string name="_sys_wiki_error_missing_wiki_object"><![CDATA[Wiki object ({0}) wasn't found]]></string>
 	
 	
 </resources>
 </resources>

+ 4 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -3000,4 +3000,8 @@
 	<string name="_sys_option_per_page_browse_showcase"><![CDATA[Количество позиций при отображении витриной]]></string>
 	<string name="_sys_option_per_page_browse_showcase"><![CDATA[Количество позиций при отображении витриной]]></string>
   <string name="_sys_option_per_page_browse_recommended"><![CDATA[Количество позиций при отображении рекомендованных]]></string>
   <string name="_sys_option_per_page_browse_recommended"><![CDATA[Количество позиций при отображении рекомендованных]]></string>
   <string name="_sys_javascript_requred"><![CDATA[Для корректной работы нужен включенный JavaScript! Пожалуйста, включите его в барузере!]]></string>
   <string name="_sys_javascript_requred"><![CDATA[Для корректной работы нужен включенный JavaScript! Пожалуйста, включите его в барузере!]]></string>
+	<string name="_sys_wiki_system_title"><![CDATA[Системная Вики]]></string>
+	<string name="_sys_wiki_error_page_exists"><![CDATA[Страница с таким именем ({0}) уже существует]]></string>
+    <string name="_sys_wiki_error_missing_wiki_object"><![CDATA[Вики объект ({0}) не найден]]></string>
+
 </resources>
 </resources>

+ 2 - 6
page.php

@@ -14,18 +14,14 @@ bx_import('BxDolLanguages');
 
 
 check_logged();
 check_logged();
 
 
-$oTemplate = BxDolTemplate::getInstance();
-
 $oPage = BxDolPage::getObjectInstanceByURI();
 $oPage = BxDolPage::getObjectInstanceByURI();
 if ($oPage) {
 if ($oPage) {
 
 
-    $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
-    $oTemplate->setPageType ($oPage->getType());
-    $oTemplate->setPageContent ('page_main_code', $oPage->getCode());
-    $oTemplate->getPageCode();
+    $oPage->displayPage();
 
 
 } else {
 } else {
 
 
+    $oTemplate = BxDolTemplate::getInstance();
     $oTemplate->displayPageNotFound();
     $oTemplate->displayPageNotFound();
 }
 }
 
 

+ 21 - 0
template/scripts/BxBasePage.php

@@ -363,6 +363,27 @@ class BxBasePage extends BxDolPage
         return $s;
         return $s;
     }
     }
 
 
+    /**
+     * Get content for 'wiki' block type.
+     * @return string
+     */
+    protected function _getBlockWiki ($aBlock)
+    {
+        $oWiki = BxDolWiki::getObjectInstance($this->_aObject['module']);
+        if (!$oWiki) {
+            $sContent = _t('_sys_wiki_error_missing_wiki_object', $this->_aObject['module']);
+        } 
+        else {
+            $sContent = $oWiki->getBlockContent($aBlock['id']);
+            $sContent = bx_process_macros($sContent);
+        }
+
+        $s = '<div class="bx-page-wiki-container">' . $sContent . '</div>';
+        $s = $this->_replaceMarkers($s);
+        $s = bx_process_macros($s);
+        return $s;
+    }
+
     /**
     /**
      * Get content for 'lang' block type.
      * Get content for 'lang' block type.
      * @return string
      * @return string

+ 30 - 2
template/scripts/BxBaseServiceWiki.php

@@ -30,9 +30,37 @@ class BxBaseServiceWiki extends BxDol
     /** 
     /** 
      * @ref bx_system_general-wiki_page "wiki_page"
      * @ref bx_system_general-wiki_page "wiki_page"
      */
      */
-    public function serviceWikiPage ($sUri)
+    public function serviceWikiPage ($sWikiObject, $sUri)
     {
     {
-        echo "Show wiki page with '$sUri' uri";
+        $oWiki = BxDolWiki::getObjectInstance($sWikiObject);
+        if (!$oWiki) {
+            $oTemplate = BxDolTemplate::getInstance();
+            $oTemplate->displayPageNotFound();
+            return;
+        }
+
+        $oPage = BxDolPage::getObjectInstanceByModuleAndURI($sWikiObject, $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";
+                }
+            } 
+            else {
+                $oTemplate = BxDolTemplate::getInstance();
+                $oTemplate->displayPageNotFound();
+            }
+        }
+
     }
     }
 }
 }
 
 

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff