Quellcode durchsuchen

#2304 Wiki functionality: contents block

Alex Trofimov vor 6 Jahren
Ursprung
Commit
ddfa04ea11

+ 20 - 0
inc/classes/BxDolWiki.php

@@ -152,6 +152,26 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
         return $s . $sControls;
     }
 
+    public function getContents ()
+    {
+        if (!($a = $this->_oQuery->getPages()))
+            return '';
+
+        $aVars = array('bx_repeat:pages' => array());
+        foreach ($a as $r) {
+            $sUrl = BX_DOL_URL_ROOT . 'r.php?_q=' . $this->_aObject['uri'] . '/' . $r['uri'];
+            $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
+            $aVars['bx_repeat:pages'][] = array(
+                'url' => $sUrl,
+                'title' => _t($r['title']),
+            );
+        }
+        usort($aVars['bx_repeat:pages'], function ($r1, $r2) {
+            return strcmp($r1['title'], $r2['title']);
+        });
+        return BxDolTemplate::getInstance()->parseHtmlByName('wiki_contents.html', $aVars);
+    }
+
     /**
      * Check if partucular action is allowed
      * @param $sType action type: add, edit, delete, translate

+ 5 - 0
inc/classes/BxDolWikiQuery.php

@@ -92,6 +92,11 @@ class BxDolWikiQuery extends BxDolDb
         return $i;
     }
 
+    public function getPages ()
+    {
+        return $this->getAll("SELECT `title`, `uri` FROM `sys_objects_page` WHERE `module` = ?", array($this->_aObject['module']));
+    }
+
     public function insertPage ($sUri, $sUrl, $sTitleLangKey, $iType = 1, $iLayoutId = 5, $iVisibleForLevels = 2147483647, $sClass = 'BxTemplPageWiki')
     {
         $b = $this->query('INSERT INTO `sys_objects_page` SET

+ 32 - 0
modules/boonex/wiki/classes/BxWikiModule.php

@@ -15,6 +15,38 @@ class BxWikiModule extends BxDolModule
     {
         parent::__construct($aModule);
     }
+
+    public function serviceGetSafeServices()
+    {
+        return array (
+            'Contents' => '',
+        );
+    }
+
+    /**
+     * @page service Service Calls
+     * @section bx_wiki Wiki
+     * @subsection bx_wiki-browse Browse
+     * @subsubsection bx_wiki-contents contents
+     * 
+     * @code bx_srv('bx_wiki', 'contents'); @endcode
+     * 
+     * Wiki contents - list of pages
+     * @code {{~bx_wiki:contents~}} @endcode
+     *
+     * @see BxWikiModule::serviceContents
+     */
+    /** 
+     * @ref bx_wiki-contents "contents"
+     */
+    public function serviceContents ()
+    {
+        if (!($oWiki = BxDolWiki::getObjectInstance($this->getName())))
+            return '';
+        
+        return $oWiki->getContents();
+    }
+
 }
 
 /** @} */

+ 8 - 2
modules/boonex/wiki/install/sql/install.sql

@@ -2,10 +2,16 @@
 -- Wiki home page
 
 INSERT INTO `sys_objects_page` (`object`, `uri`, `title_system`, `title`, `module`, `cover`, `cover_image`, `type_id`, `layout_id`, `submenu`, `visible_for_levels`, `visible_for_levels_editable`, `url`, `meta_description`, `meta_keywords`, `meta_robots`, `cache_lifetime`, `cache_editable`, `deletable`, `override_class_name`, `override_class_file`) VALUES
-('bx_wiki_home', 'wiki-home', '', '_bx_wiki_page_home', 'bx_wiki', 0, 0, 1, 5, '', 2147483647, 1, 'r.php?_q=wiki/wiki-home', '', '', '', 0, 1, 0, 'BxTemplPageWiki', '');
+('bx_wiki_home', 'wiki-home', '', '_bx_wiki_page_home', 'bx_wiki', 0, 0, 1, 1, '', 2147483647, 1, 'r.php?_q=wiki/wiki-home', '', '', '', 0, 1, 0, 'BxTemplPageWiki', '');
 
 INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
-('bx_wiki_home', 1, 'bx_wiki', '', '_bx_wiki_block_home', 0, 2147483647, '0', 'wiki', '', 0, 1, 1, 1);
+('bx_wiki_home', 1, 'bx_wiki', '', '_bx_wiki_block_contents', 0, 2147483647, '0', 'wiki', '', 0, 1, 1, 1);
+SET @iBlockId = LAST_INSERT_ID();
+INSERT INTO `sys_pages_wiki_blocks` (`block_id`, `revision`, `lang`, `main_lang`, `profile_id`, `content`, `notes`, `added`) VALUES
+(@iBlockId, 1, 'en', 1, 0, '# Contents\r\n\r\n{{~bx_wiki:contents~}}', 'Initial version', UNIX_TIMESTAMP());
+
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `deletable`, `copyable`, `active`, `order`) VALUES
+('bx_wiki_home', 2, 'bx_wiki', '', '_bx_wiki_block_home', 0, 2147483647, '0', 'wiki', '', 0, 1, 1, 1);
 SET @iBlockId = LAST_INSERT_ID();
 INSERT INTO `sys_pages_wiki_blocks` (`block_id`, `revision`, `lang`, `main_lang`, `profile_id`, `content`, `notes`, `added`) VALUES
 (@iBlockId, 1, 'en', 1, 0, '# Wiki Home\r\n\r\nInsert **your content** here', 'Initial version', UNIX_TIMESTAMP());

+ 5 - 0
template/wiki_contents.html

@@ -0,0 +1,5 @@
+<ul class="bx-wiki-contents bx-def-font-large">
+    <bx_repeat:pages>
+        <li><a href="__url__">__title__</a></li>
+    </bx_repeat:pages>
+</ul>