Răsfoiți Sursa

Ticket #3399 - Related core changes (Search engine).

AntonLV 5 ani în urmă
părinte
comite
653c8195d1

+ 13 - 4
inc/js/functions.js

@@ -979,7 +979,7 @@ function bx_append_url_params (sUrl, mixedParams) {
     return sUrl + sParams + sHash;
 }
 
-function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen) {
+function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, iMinLen, onComplete) {
     var oForm = $(e.target).parents(sFormSel + ':first');
 
     if ('undefined' != typeof(e) && 13 == e.keyCode) {
@@ -996,13 +996,13 @@ function bx_search_on_type (e, n, sFormSel, sResultsContSel, sLoadingContSel, bS
         clearTimeout(glBxSearchTimeoutHandler);
 
     glBxSearchTimeoutHandler = setTimeout(function () {
-        bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults);
+        bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete);
     }, 500);
 
     return true;
 }
 
-function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults) {
+function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults, onComplete) {
     if ('undefined' == typeof(sLoadingContSel))
         sLoadingContSel = sResultsContSel;
     if ('undefined' == typeof(bSortResults))
@@ -1013,6 +1013,10 @@ function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults)
     bx_loading($(sLoadingContSel), true);
     $.post(sUrlRoot + 'searchKeywordContent.php', sQuery, function(data) {
         bx_loading($(sLoadingContSel), false);
+
+        if(!data)
+            return;
+
         if (bSortResults) {
             var aSortedUnits = $(data).find(".bx-def-unit-live-search").toArray().sort(function (a, b) {
                 return b.getAttribute('data-ts') - a.getAttribute('data-ts');
@@ -1022,7 +1026,12 @@ function bx_search (n, sFormSel, sResultsContSel, sLoadingContSel, bSortResults)
                 data += e.outerHTML;
             });
         } 
-        $(sResultsContSel).html(data).bxProcessHtml();
+
+        var oContainer = $(sResultsContSel);
+        oContainer.html(data).bxProcessHtml();
+
+        if(typeof onComplete === 'function')
+            onComplete(oContainer, data);
     });
 
     return false;

+ 5 - 7
modules/base/notifications/classes/BxBaseModNotificationsTemplate.php

@@ -76,17 +76,15 @@ class BxBaseModNotificationsTemplate extends BxBaseModGeneralTemplate
     	$this->getCssJs();
 
     	if($sTemplateName == 'unit.html')
-    		return $this->getUnit($aData);
+            return $this->getUnit($aData);
 
         $oModule = $this->getModule();
         $CNF = &$this->_oConfig->CNF;
 
-        if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->isAllowedView($aData))) {
-            $aVars = array (
-                'summary' => $sMsg,
-            );
-            return $this->parseHtmlByName('unit_private.html', $aVars);
-        }
+        if ($isCheckPrivateContent && !$oModule->isAllowedView($aData))
+            return $this->parseHtmlByName('unit_private.html', array (
+                'summary' => _t('_sys_access_denied_to_private_content'),
+            ));
 
         list($sAuthorName, $sAuthorUrl, $sAuthorIcon) = $oModule->getUserInfo($aData['object_id']);
         $bAuthorIcon = !empty($sAuthorIcon);

+ 68 - 47
template/scripts/BxBaseSearch.php

@@ -12,10 +12,15 @@ require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 class BxBaseSearch extends BxDolSearch
 {
     protected $_oTemplate;
+
     protected $_sIdForm = 'sys_search_form';
     protected $_sIdResults = 'sys_search_results';
+    protected $_sIdLoading;
     protected $_sSuffixLiveSearch = '_quick';
 
+    protected $_iSearchLenth;
+    protected $_sSearchFunctionParams;
+
     public function __construct($aChoice, $oTemplate)
     {
         if (!is_array($aChoice) && $aChoice != '')
@@ -23,6 +28,22 @@ class BxBaseSearch extends BxDolSearch
         parent::__construct($aChoice);
 
         $this->_oTemplate = $oTemplate ? $oTemplate : BxDolTemplate::getInstance();
+
+        $this->_sIdLoading = $this->_sIdForm;
+
+        $this->_iSearchLenth = 5;
+        $this->_sSearchFunctionParams = "%d, '%s', '%s', '%s', %d, %d";
+    }
+
+    public function setLiveSearch($bLiveSearch)
+    {
+        parent::setLiveSearch($bLiveSearch);
+
+        if($this->_bLiveSearch) {
+            $this->_sIdForm .= $this->_sSuffixLiveSearch;
+            $this->_sIdResults .= $this->_sSuffixLiveSearch;
+            $this->_sIdLoading = $this->_sIdResults;
+        }
     }
 
     public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false, $bOnlyForm = false)
@@ -33,30 +54,51 @@ class BxBaseSearch extends BxDolSearch
         if (false === $sTitle)
             $sTitle = _t( "_Search");
 
-        $aValues = array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs());
+        $aSection = '';
         if (bx_get('type'))
-            $aValue = bx_process_input(bx_get('type'));
-        elseif (bx_get('section'))
-            $aValue = bx_process_input(bx_get('section'));
-        else
-            $aValue = '';
-
-        
-        $sIdForm = $this->_sIdForm;
-        $sIdResults = $this->_sIdResults;
-        $sIdLoadingContainer = $sIdForm;
-        $iKeywordMinLenth = 0;
-        if($this->_bLiveSearch) {
-            $sIdForm .= $this->_sSuffixLiveSearch;
-            $sIdResults .= $this->_sSuffixLiveSearch;
-            $sIdLoadingContainer = $sIdResults;
-            $iKeywordMinLenth = (int)getParam('sys_search_keyword_min_len');
+            $aSection = bx_process_input(bx_get('type'));
+        else if (bx_get('section'))
+            $aSection = bx_process_input(bx_get('section'));
+
+        $aForm = $this->_getForm([
+            'section' => $aSection,
+            'keyword' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : ''
+        ]);
+
+        $oForm = new BxTemplFormView($aForm);
+        $sForm = $oForm->getCode();
+
+        if (!$this->_bLiveSearch) {
+            $o = new BxTemplPaginate(array());
+            $o->addCssJs();
         }
-        $sJsParams = "5, '#{$sIdForm}', '#{$sIdResults}', '#{$sIdLoadingContainer}', '{$this->_bLiveSearch}', {$iKeywordMinLenth}";
+        if ($bOnlyForm)
+            return $sForm;
 
+        return $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
+            'class_add' => '',
+            'bx_if:show_html_id' => array(
+                'condition' => false,
+                'content' => array(),
+            ),
+            'content' => DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate)
+        ));
+    }
+
+    public function getResultsContainer($sCode = '')
+    {
+        return $this->_oTemplate->parseHtmlByName('search_result.html', [
+            'html_id' => $this->_sIdResults,
+            'class' => str_replace('_', '-', $this->_sIdResults),
+            'content' => $sCode
+        ]);
+    }
+
+    protected function _getForm($aValues = array())
+    {
         $aForm = array(
             'form_attrs' => array(
-               'id' => $sIdForm,
+               'id' => $this->_sIdForm,
                'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
                'method' => 'post',
             ),
@@ -75,14 +117,14 @@ class BxBaseSearch extends BxDolSearch
                     'type' => 'select',
                     'name' => 'section',
                     'caption' => _t('_Section'),
-                    'values' => $aValues,
-                    'value' => $aValue,
+                    'values' => array_merge(array('' => _t('_search_in_all_section')), $this->getKeyTitlesPairs()),
+                    'value' => $aValues['section'],
                 ),
                 'keyword' => array(
                     'type' => 'text',
                     'name' => 'keyword',
                     'caption' => _t('_Keyword'),
-                    'value' => bx_get('keyword') ? bx_process_input(bx_get('keyword')) : '',
+                    'value' => $aValues['keyword'],
                 ),
                 'search' => array(
                     'type' => 'submit',
@@ -93,6 +135,8 @@ class BxBaseSearch extends BxDolSearch
         );
 
         if ($this->_bLiveSearch) {
+            $sJsParams = sprintf($this->_sSearchFunctionParams, $this->_iSearchLenth, '#' . $this->_sIdForm, '#' . $this->_sIdResults, '#' . $this->_sIdLoading, $this->_bLiveSearch, (int)getParam('sys_search_keyword_min_len'));
+
             unset($aForm['inputs']['section']);
             unset($aForm['inputs']['search']);
             unset($aForm['inputs']['keyword']['caption']);
@@ -101,32 +145,9 @@ class BxBaseSearch extends BxDolSearch
             $aForm['inputs']['keyword']['attrs']['onpaste'] = $aForm['inputs']['keyword']['attrs']['onkeydown'];
         }
 
-        $oForm = new BxTemplFormView($aForm);
-        $sForm = $oForm->getCode();
-
-        if (!$this->_bLiveSearch) {
-            $o = new BxTemplPaginate(array());
-            $o->addCssJs();
-        }
-        if ($bOnlyForm)
-            return $sForm;
-
-        return $this->_oTemplate->parseHtmlByName('designbox_container.html', array(
-            'class_add' => '',
-            'bx_if:show_html_id' => array(
-                'condition' => false,
-                'content' => array(),
-            ),
-            'content' => DesignBoxContent($sTitle, $sForm, $iDesignBoxTemplate)
-        ));
-    }
-
-    public function getResultsContainer($sCode = '')
-    {
-        $sIdResults = $this->_sIdResults . ($this->_bLiveSearch ? $this->_sSuffixLiveSearch : '');
-        return '<div id="' . $sIdResults . '">' . $sCode . '</div>';
+        return $aForm;
     }
-    
+            
     protected function getKeyTitlesPairs ()
     {
         $a = array();

+ 17 - 13
template/scripts/BxBaseSearchResult.php

@@ -50,10 +50,11 @@ class BxBaseSearchResult extends BxDolSearchResult
     {
         $sCode = '';
         bx_alert('simple_search', 'before_get_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode));
+
         $aData = $this->getSearchData();
         bx_alert('simple_search', 'get_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode, 'search_results' => &$aData));
-        if ($this->aCurrent['paginate']['num'] > 0) {
 
+        if ($this->aCurrent['paginate']['num'] > 0) {
             $sCode .= $this->addCustomParts();
 
             foreach ($aData as $aValue)
@@ -65,18 +66,21 @@ class BxBaseSearchResult extends BxDolSearchResult
             $sAttributes = '';
             if(is_array($this->aContainerAttrs) && !empty($this->aContainerAttrs))
             	foreach ($this->aContainerAttrs as $sName => $sValue)
-            		$sAttributes .= ' ' . $sName . '="' . $sValue . '"';
-
-            $sCode = '<div id="' . $sSearchResultBlockId . '" class="' . $sClasses . '"' . $sAttributes . '>' . $sCode . '</div>';
-
-            if (!$this->_bLiveSearch && $this->sCenterContentUnitSelector) {
-                $sCode .= "
-                    <script>
-                        $(document).ready(function() {
-                            bx_center_content('#{$sSearchResultBlockId}', '{$this->sCenterContentUnitSelector}', true);
-                        });
-                    </script>";
-            }
+                    $sAttributes .= ' ' . $sName . '="' . $sValue . '"';
+
+            $sCode = BxDolTemplate::getInstance()->parseHtmlByName('search_result_block.html', [
+                'html_id' => $sSearchResultBlockId,
+                'class' => $sClasses,
+                'attrs' => $sAttributes,
+                'content' => $sCode,
+                'bx_if:do_center' => [
+                    'condition' => !$this->_bLiveSearch && $this->sCenterContentUnitSelector,
+                    'content' => [
+                        'html_id' => $sSearchResultBlockId,
+                        'selector_content' => $this->sCenterContentUnitSelector
+                    ]
+                ]
+            ]);
         }
 
         bx_alert('simple_search', 'show_data', 0, false, array('object' => &$this->aCurrent, 'mode' => $this->_sMode, 'search_results' => &$sCode));

+ 1 - 0
template/search_result.html

@@ -0,0 +1 @@
+<div id="__html_id__" class="__class__">__content__</div>

+ 8 - 0
template/search_result_block.html

@@ -0,0 +1,8 @@
+<div id="__html_id__" class="__class__" __attrs__>__content__</div>
+<bx_if:do_center>
+    <script>
+        $(document).ready(function() {
+            bx_center_content('#__html_id__', '__selector_content__', true);
+        });
+    </script>
+</bx_if:do_center>