ソースを参照

#92 - Integrate comments in search engine -> Posts Module.

AntonLV 12 年 前
親
コミット
3539a891d0

+ 14 - 0
inc/classes/BxDolCmts.php

@@ -170,6 +170,8 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
     protected $_sBpSessionKeyFilter = '';
     protected $_aOrder = array();
 
+    protected $_sSnippetLenthLiveSearch = 50;
+
     protected $_iRememberTime = 2592000;
 
     /**
@@ -376,6 +378,18 @@ class BxDolCmts extends BxDol implements iBxDolReplaceable
         return sprintf($this->_sListAnchor, str_replace('_', '-', $this->getSystemName()), $this->getId());
     }
 
+	public function getViewUrl($iCmtId)
+    {
+    	if(empty($this->_aSystem['trigger_field_title']))
+    		return '';
+
+    	return bx_append_url_params($this->_sViewUrl, array(
+			'sys' => $this->_sSystem,
+			'id' => $this->_iId,
+			'cmt_id' => $iCmtId
+		));
+    }
+
     public function getConnectionObject($sType)
     {
         $sResult = '';

+ 13 - 6
inc/classes/BxDolSearch.php

@@ -80,18 +80,25 @@ class BxDolSearch extends BxDol
      */
     public function response ()
     {
-        bx_import('BxDolTemplate');
+    	bx_import('BxTemplSearchResult');		
+
         $sCode = '';
         foreach ($this->aChoice as $sKey => $aValue) {
-            if (!class_exists($aValue['class'])) {
-                $sClassPath = str_replace('{tmpl}', BxDolTemplate::getInstance()->getCode(), $aValue['file']);
-                require_once(BX_DIRECTORY_PATH_ROOT . $sClassPath);
-            }
-            $oEx = new $aValue['class']();
+        	$sClassName = 'BxTemplSearchResult';
+	        if(!empty($aValue['class'])) {
+	            $sClassName = $aValue['class'];
+	            if(!empty($aValue['file']))
+	                require_once(BX_DIRECTORY_PATH_ROOT . $aValue['file']);
+	            else
+	                bx_import($sClassName);
+	        }
+
+            $oEx = new $sClassName();
             $oEx->setId($aValue['id']);
             $oEx->setLiveSearch($this->_bLiveSearch);
             $sCode .= $oEx->processing();
         }
+
         return $sCode;
     }
 

+ 94 - 0
modules/base/general/classes/BxBaseModGeneralCmtsSearchResult.php

@@ -0,0 +1,94 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    BaseGeneral Base classes for modules
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxDolCmts');
+bx_import('BxBaseModGeneralSearchResult');
+
+class BxBaseModGeneralCmtsSearchResult extends BxBaseModGeneralSearchResult
+{
+	protected $sModule;
+	protected $sModuleObjectComments;
+
+    function __construct($sMode = '', $aParams = array())
+    {
+        parent::__construct($sMode, $aParams);
+
+        $this->oModule = $this->getMain();
+        $this->sModuleObjectComments = $this->oModule->_oConfig->CNF['OBJECT_COMMENTS'];
+
+        $this->aCurrent = array(
+        	'name' => $this->oModule->_oConfig->getName() . '_cmts',
+        	'title' => '',
+            'table' => $this->oModule->_oConfig->getDbPrefix() . 'cmts',
+            'ownFields' => array('cmt_id', 'cmt_object_id', 'cmt_author_id', 'cmt_text', 'cmt_time'),
+            'searchFields' => array('cmt_text'),
+            'restriction' => array(
+                'author' => array('value' => '', 'field' => 'cmt_author_id', 'operator' => '='),
+            ),
+            'paginate' => array('start' => 0, 'perPage' => 3),
+            'sorting' => 'last',
+        );
+
+        $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
+    }
+
+    function getMain()
+    {
+        bx_import('BxDolModule');
+        return BxDolModule::getInstance($this->sModule);
+    }
+
+    function displaySearchUnit($aData)
+    {
+		$oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, $aData['object_id']);
+		$oCmts->addCssJs();
+
+		if($this->_bLiveSearch) {
+			$aCnf = &$this->oModule->_oConfig->CNF;
+
+			return $oCmts->getCommentLiveSearch($aData['id'], array(
+				'txt_sample_single' => isset($aCnf['T']['txt_sample_comment_single']) ? $aCnf['T']['txt_sample_comment_single'] : ''
+			));
+		}
+		else
+			return $oCmts->getComment($aData['id'], array(), array('type' => BX_CMT_DISPLAY_FLAT, 'view_only' => true));
+    }
+
+    function displayResultBlock ()
+    {
+        $s = parent::displayResultBlock ();
+        $s = '<ul class="cmts">' . $s . '</ul>';
+        return $s;
+    }
+
+    function getAlterOrder()
+    {
+        if($this->aCurrent['sorting'] == 'last')
+            return array(
+            	'order' => " ORDER BY `" . $this->aCurrent['table'] . "`.`cmt_time` DESC"
+            );
+
+        return array();
+    }
+
+    function _getPseud ()
+    {
+        return array(
+            'id' => 'cmt_id',
+        	'object_id' => 'cmt_object_id',
+            'author' => 'cmt_author_id',
+            'text' => 'cmt_text',
+            'added' => 'cmt_time'
+        );
+    }
+}
+
+/** @} */

+ 26 - 0
modules/boonex/posts/classes/BxPostsCmtsSearchResult.php

@@ -0,0 +1,26 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
+ * CC-BY License - http://creativecommons.org/licenses/by/3.0/
+ *
+ * @defgroup    Posts Posts
+ * @ingroup     DolphinModules
+ *
+ * @{
+ */
+
+bx_import('BxBaseModGeneralCmtsSearchResult');
+
+class BxPostsCmtsSearchResult extends BxBaseModGeneralCmtsSearchResult
+{
+    function __construct($sMode = '', $aParams = array())
+    {
+    	$this->sModule = 'bx_posts';
+
+        parent::__construct($sMode, $aParams);
+
+        $this->aCurrent['title'] = _t('_bx_posts_page_block_title_browse_cmts');
+    }
+}
+
+/** @} */

+ 1 - 0
modules/boonex/posts/classes/BxPostsConfig.php

@@ -80,6 +80,7 @@ class BxPostsConfig extends BxBaseModTextConfig
             // some language keys
             'T' => array (
                 'txt_sample_single' => '_bx_posts_txt_sample_single',
+            	'txt_sample_comment_single' => '_bx_posts_txt_sample_comment_single',
             ),
         );
 

+ 3 - 0
modules/boonex/posts/install/langs/en.xml

@@ -2,6 +2,7 @@
 <resources name="en" flag="gb" title="English">
 
 	<string name="_bx_posts"><![CDATA[Posts]]></string>
+	<string name="_bx_posts_cmts"><![CDATA[Posts' Comments]]></string>
 
 	<string name="_bx_posts_option_summary_chars"><![CDATA[Number of characters in auto-cropped post summary]]></string>
 	<string name="_bx_posts_option_plain_summary_chars"><![CDATA[Number of characters in plain post description when post hasn't thumb]]></string>
@@ -68,6 +69,7 @@
     <string name="_bx_posts_page_title_entries_of_author"><![CDATA[Posts of {display_name}]]></string>
     <string name="_bx_posts_page_block_title_entries_of_author"><![CDATA[Posts of author]]></string>   
     <string name="_bx_posts_page_block_title_entries_actions"><![CDATA[Posts actions]]></string>
+    <string name="_bx_posts_page_block_title_browse_cmts"><![CDATA[Posts' Comments]]></string>
 
     <string name="_bx_posts_menu_set_title_view_entry"><![CDATA[View Post]]></string>
     <string name="_bx_posts_menu_title_view_entry"><![CDATA[View Post]]></string>
@@ -97,4 +99,5 @@
     <string name="_bx_posts_menu_set_title_entries_my"><![CDATA[My Posts Menu]]></string>
 
     <string name="_bx_posts_txt_sample_single"><![CDATA[post]]></string>
+    <string name="_bx_posts_txt_sample_comment_single"><![CDATA[post's comment]]></string>
 </resources>

+ 2 - 1
modules/boonex/posts/install/sql/enable.sql

@@ -243,7 +243,8 @@ INSERT INTO `sys_acl_matrix` (`IDLevel`, `IDAction`) VALUES
 
 -- SEARCH
 INSERT INTO `sys_objects_search` (`ObjectName`, `Title`, `ClassName`, `ClassPath`) VALUES
-('bx_posts', '_bx_posts', 'BxPostsSearchResult', 'modules/boonex/posts/classes/BxPostsSearchResult.php');
+('bx_posts', '_bx_posts', 'BxPostsSearchResult', 'modules/boonex/posts/classes/BxPostsSearchResult.php'),
+('bx_posts_cmts', '_bx_posts_cmts', 'BxPostsCmtsSearchResult', 'modules/boonex/posts/classes/BxPostsCmtsSearchResult.php');
 
 -- METATAGS
 INSERT INTO `sys_objects_metatags` (`object`, `table_keywords`, `table_locations`, `table_mentions`, `table_pictures`, `override_class_name`, `override_class_file`) VALUES

+ 13 - 0
template/comment_live_search.html

@@ -0,0 +1,13 @@
+<div class="bx-def-unit bx-def-unit-live-search bx-def-margin-sec-bottom">
+	<bx_if:show_icon>
+		<a href="__view_link__">
+			<img class="bx-def-thumb bx-def-thumb-size" src="__author_icon__" />
+		</a>
+	</bx_if:show_icon>
+	<bx_if:show_icon_empty>
+		<div class="bx-def-thumb-size bx-def-unit-img bx-def-round-corners bx-def-color-bg-sec"></div>
+	</bx_if:show_icon_empty>
+	<div class="bx-def-unit-info bx-def-thumb-size-max-height bx-def-padding-sec-left">
+		<a href="__view_link__">__text__</a><br /><span class="bx-def-fonr-grayed bx-def-font-small">__sample__</span>
+	</div>
+</div>

+ 74 - 34
template/scripts/BxBaseCmts.php

@@ -130,12 +130,16 @@ class BxBaseCmts extends BxDolCmts
     /**
      * get comment view block with initializations
      */
-    function getCommentBlock($iCmtId = 0)
+    function getCommentBlock($iCmtId = 0, $aBp = array(), $aDp = array())
     {
         return BxDolTemplate::getInstance()->parseHtmlByName('comment_block.html', array(
             'system' => $this->_sSystem,
             'id' => $this->getId(),
-            'comment' => $this->getComment($iCmtId, array('type' => $this->_sBrowseType), array('type' => BX_CMT_DISPLAY_THREADED)),
+            'comment' => $this->getComment(
+        		$iCmtId, 
+        		array_merge(array('type' => $this->_sBrowseType), $aBp), 
+        		array_merge(array('type' => BX_CMT_DISPLAY_THREADED), $aDp)
+        	),
         	'view_image_popup' => $this->_getViewImagePopup(), 
             'script' => $this->getJsScript()
         ));
@@ -283,6 +287,39 @@ class BxBaseCmts extends BxDolCmts
         ));
     }
 
+	/**
+     * get one comment for "Live Search"
+     *
+     * @param  int    $iCmtId - comment id
+     * @return string
+     */
+    function getCommentLiveSearch($mixedCmt, $aParams = array())
+    {
+        $aCmt = !is_array($mixedCmt) ? $this->getCommentRow((int)$mixedCmt) : $mixedCmt;
+
+        list($sAuthorName, $sAuthorLink, $sAuthorIcon) = $this->_getAuthorInfo($aCmt['cmt_author_id']);
+        $bAuthorIcon = !empty($sAuthorIcon);
+
+        $sViewLink = $this->getViewUrl($aCmt['cmt_id']);
+
+        return BxDolTemplate::getInstance()->parseHtmlByName('comment_live_search.html', array(
+            'bx_if:show_icon' => array(
+                'condition' => $bAuthorIcon,
+                'content' => array(
+                    'author_icon' => $sAuthorIcon,
+        			'view_link' => $sViewLink
+                )
+            ),
+            'bx_if:show_icon_empty' => array(
+                'condition' => !$bAuthorIcon,
+                'content' => array()
+            ),
+            'view_link' => $sViewLink,
+            'text' => BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($aCmt['cmt_text']), $this->_sSnippetLenthLiveSearch),
+            'sample' => isset($aParams['txt_sample_single']) ? _t($aParams['txt_sample_single']) : ''
+        ));
+    }
+
     function getFormBoxPost($aBp = array(), $aDp = array())
     {
         return $this->_getFormBox(BX_CMT_ACTION_POST, $aBp, $aDp);
@@ -374,33 +411,40 @@ class BxBaseCmts extends BxDolCmts
 
     protected function _getActionsBox(&$aCmt, $aDp = array())
     {
-        $oTemplate = BxDolTemplate::getInstance();
-
-        //--- Actions Menu
-        bx_import('BxDolMenu');
-        $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
-        $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
-        $sMenuActions = $oMenuActions->getCode();
-
-        $oVote = $this->getVoteObject($aCmt['cmt_id']);
-        if($oVote !== false)
-            $sMenuActions .= $oVote->getJsScript();
-
-        //--- Manage Menu
-        $oMenuManage = BxDolMenu::getObjectInstance($this->_sMenuObjManage);
-        $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
-
-        $sMenuManage = $oMenuManage->getCode();
-        $bMenuManage = !empty($sMenuManage);
-        if($bMenuManage) {
-            $sMenuManage = $oTemplate->parseHtmlByName('comment_manage.html', array(
-                'style_prefix' => $this->_sStylePrefix,
-                'content' => $sMenuManage
-            ));
-
-            bx_import('BxTemplFunctions');
-            $sMenuManage = BxTemplFunctions::getInstance()->transBox($this->_sSystem . '-manage-' . $aCmt['cmt_id'], $sMenuManage, true);
-        }
+    	$oTemplate = BxDolTemplate::getInstance();
+
+    	$bViewOnly = isset($aDp['view_only']) && $aDp['view_only'] === true;
+
+        $bMenuManage = false;
+        $sMenuActions = $sMenuManage = '';
+
+		if(!$bViewOnly) {
+	        //--- Actions Menu
+	        bx_import('BxDolMenu');
+	        $oMenuActions = BxDolMenu::getObjectInstance($this->_sMenuObjActions);
+	        $oMenuActions->setCmtsData($this, $aCmt['cmt_id']);
+	        $sMenuActions = $oMenuActions->getCode();
+
+	        $oVote = $this->getVoteObject($aCmt['cmt_id']);
+	        if($oVote !== false)
+	            $sMenuActions .= $oVote->getJsScript();
+	
+	        //--- Manage Menu
+	        $oMenuManage = BxDolMenu::getObjectInstance($this->_sMenuObjManage);
+	        $oMenuManage->setCmtsData($this, $aCmt['cmt_id']);
+	
+	        $sMenuManage = $oMenuManage->getCode();
+	        $bMenuManage = !empty($sMenuManage);
+	        if($bMenuManage) {
+	            $sMenuManage = $oTemplate->parseHtmlByName('comment_manage.html', array(
+	                'style_prefix' => $this->_sStylePrefix,
+	                'content' => $sMenuManage
+	            ));
+	
+	            bx_import('BxTemplFunctions');
+	            $sMenuManage = BxTemplFunctions::getInstance()->transBox($this->_sSystem . '-manage-' . $aCmt['cmt_id'], $sMenuManage, true);
+	        }
+		}
 
         $sAgo = bx_time_js($aCmt['cmt_time']);
         $bObjectTitle = !empty($this->_aSystem['trigger_field_title']);
@@ -412,11 +456,7 @@ class BxBaseCmts extends BxDolCmts
                 'condition' => $bObjectTitle,
                 'content' => array(
                     'style_prefix' => $this->_sStylePrefix,
-                    'view_link' => bx_append_url_params($this->_sViewUrl, array(
-                        'sys' => $this->_sSystem,
-                        'id' => $this->_iId,
-                        'cmt_id' => $aCmt['cmt_id']
-                    )),
+                    'view_link' => $this->getViewUrl($aCmt['cmt_id']),
                     'ago' => $sAgo
                 )
             ),