Sfoglia il codice sorgente

#2579 Search in pages blocks including wiki

Alex Trofimov 6 anni fa
parent
commit
a7b1a641f2

+ 15 - 0
inc/classes/BxDolWiki.php

@@ -679,10 +679,25 @@ class BxDolWiki extends BxDolFactory implements iBxDolFactoryObject
                 }
             }
 
+            // update indexing data
+            $this->updateBlockIndexingData($iBlockId);
+
             return array('code' => 0, 'actions' => array('Reload', 'ClosePopup'), 'block_id' => $iBlockId);
         }
     }
 
+    protected function updateBlockIndexingData($iBlockId)
+    {
+        if (!($aLangs = $this->_oQuery->getBlockLangs ($iBlockId)))
+            return false;
+        $sText = '';
+        foreach ($aLangs as $sLang) {
+            $aWikiVer = $this->_oQuery->getBlockContent ($iBlockId, $sLang, false, false);
+            $sText .= trim(strip_tags($aWikiVer['content'])) . ' ';
+        }
+        return $this->_oQuery->updateBlockIndexingData ($iBlockId, $sText);
+    }
+
     protected function getPageUrl ($sPageUri, $bPermalink = true, $bAddRootUrl = true)
     {
         $sUrl = ($bAddRootUrl ? BX_DOL_URL_ROOT : '') . 'r.php?_q=' . $this->_aObject['uri'] . '/' . $sPageUri;

+ 10 - 0
inc/classes/BxDolWikiQuery.php

@@ -75,6 +75,16 @@ class BxDolWikiQuery extends BxDolDb
         return $aRow ? $aRow : false;
     }
 
+    public function getBlockLangs ($iBlockId)
+    {
+        return $this->getColumn("SELECT `language` FROM `sys_pages_wiki_blocks` WHERE `block_id` = :block GROUP BY `language`", array('block' => $iBlockId));
+    }
+
+    public function updateBlockIndexingData ($iBlockId, $sText)
+    {
+        return $this->query("UPDATE `sys_pages_blocks` SET `text` = :text, `text_updated` = :updated WHERE `id` = :id", array('text' => $sText, 'updated' => time(), 'id' => $iBlockId));
+    }
+
     public function getBlockHistory ($iBlockId, $sLang)
     {
         $aBind = array('block' => $iBlockId, 'language' => $sLang);

+ 6 - 6
modules/boonex/wiki/install/sql/install.sql

@@ -4,20 +4,20 @@
 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, 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_contents', 0, 2147483647, '0', 'wiki', '', 0, 1, 1, 1);
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `text`, `text_updated`, `deletable`, `copyable`, `active`, `order`) VALUES
+('bx_wiki_home', 1, 'bx_wiki', '', '_bx_wiki_block_contents', 0, 2147483647, '0', 'wiki', '', '# Contents', UNIX_TIMESTAMP(), 0, 1, 1, 1);
 SET @iBlockId = LAST_INSERT_ID();
 INSERT INTO `sys_pages_wiki_blocks` (`block_id`, `revision`, `language`, `main_lang`, `profile_id`, `content`, `notes`, `added`) VALUES
 (@iBlockId, 1, 'en', 1, 0, '# Contents\r\n\r\n{{~bx_wiki:contents["wiki-missing-translations,wiki-outdated-translations"]~}}', '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', 1, 'bx_wiki', '', '_bx_wiki_block_administration', 0, 192, '0', 'wiki', '', 0, 1, 1, 2);
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `text`, `text_updated`, `deletable`, `copyable`, `active`, `order`) VALUES
+('bx_wiki_home', 1, 'bx_wiki', '', '_bx_wiki_block_administration', 0, 192, '0', 'wiki', '', '# Administration', UNIX_TIMESTAMP(), 0, 1, 1, 2);
 SET @iBlockId = LAST_INSERT_ID();
 INSERT INTO `sys_pages_wiki_blocks` (`block_id`, `revision`, `language`, `main_lang`, `profile_id`, `content`, `notes`, `added`) VALUES
 (@iBlockId, 1, 'en', 1, 0, '# Administration\r\n\r\n{{~bx_wiki:contents["","wiki-missing-translations,wiki-outdated-translations"]~}}', '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);
+INSERT INTO `sys_pages_blocks` (`object`, `cell_id`, `module`, `title_system`, `title`, `designbox_id`, `visible_for_levels`, `hidden_on`, `type`, `content`, `text`, `text_updated`, `deletable`, `copyable`, `active`, `order`) VALUES
+('bx_wiki_home', 2, 'bx_wiki', '', '_bx_wiki_block_home', 0, 2147483647, '0', 'wiki', '', '# Wiki Home\r\n\r\nInsert **your content** here', UNIX_TIMESTAMP(), 0, 1, 1, 1);
 SET @iBlockId = LAST_INSERT_ID();
 INSERT INTO `sys_pages_wiki_blocks` (`block_id`, `revision`, `language`, `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());

+ 20 - 1
studio/template/scripts/BxBaseStudioBuilderPage.php

@@ -575,6 +575,9 @@ class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
                         $aBlock['content'] = implode($this->sParamsDivider, array($iImageId, $sImageAlign));
                 }
 
+                // add indexing data
+                $aBlock = array_merge($aBlock, $this->getIndexingDataForBlock($aBlock['type'], $aBlock['content']));
+
                 if(!$this->oDb->insertBlock($aBlock)) {
                     if($sContentKey != "")
                         $oLanguage->deleteLanguageString($sContentKey);
@@ -786,7 +789,10 @@ class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
         if($oForm->isSubmittedAndValid()) {
             $this->onSaveBlock($oForm, $aBlock);
 
-            if($oForm->update($iId) !== false)
+            // add indexing data
+            $aBlockAddon = $this->getIndexingDataForBlock($aBlock['type'], $oForm->getCleanValue('content'));
+
+            if($oForm->update($iId, $aBlockAddon) !== false)
                 return array('eval' => $sJsObject . '.onEditBlock(oData)');
             else
                 return array('msg' => _t('_adm_bp_err_block_edit'));
@@ -1788,6 +1794,19 @@ class BxBaseStudioBuilderPage extends BxDolStudioBuilderPage
 
         return $aTmplParams;
     }
+
+    protected function getIndexingDataForBlock($sType, $sContent)
+    {
+        $aBlock = array();   
+        switch($sType) {
+            case BX_DOL_STUDIO_BP_BLOCK_HTML:
+            case BX_DOL_STUDIO_BP_BLOCK_RAW:
+                $aBlock['text'] = trim(strip_tags($sContent));
+                $aBlock['text_updated'] = time();
+                break;
+        }
+        return $aBlock;
+    }
 }
 
 /** @} */