Просмотр исходного кода

Ticket #4971 - Build-in API support: Site and Keyword searches.

AntonLV 9 месяцев назад
Родитель
Сommit
fc5d1d5515

+ 7 - 11
inc/classes/BxDolMetatags.php

@@ -525,17 +525,13 @@ class BxDolMetatags extends BxDolFactory implements iBxDolFactoryObject
     }
 	
     public function keywordsGetHashTagUrl($sKeyword, $iId, $mixedSection = false) 
-    {   
-        $sSectionPart = '';
-        if (!empty($mixedSection)) {
-            if (is_array($mixedSection))
-                $sSectionPart = '&section[]=' . implode('&section[]=', $mixedSection);
-            elseif (is_string($mixedSection))
-                $sSectionPart = '&section[]=' . $mixedSection;
-        }
-        
-        $sUrl = BX_DOL_URL_ROOT . 'searchKeyword.php?type=keyword&keyword=' . rawurlencode($sKeyword) . $sSectionPart;
-        
+    {
+        $aUrlParams = ['type' => 'keyword', 'keyword' => rawurlencode($sKeyword)];
+        if(!empty($mixedSection))
+            $aUrlParams['section'] = $mixedSection;
+
+        $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=search-keyword', $aUrlParams);
+
         /**
          * @hooks
          * @hookdef hook-meta_keyword-url 'meta_keyword', 'url' - hook to override meta keyword URL

+ 27 - 1
inc/classes/BxDolSearch.php

@@ -128,7 +128,7 @@ class BxDolSearch extends BxDol
             if($this->_bDataProcessing) {
                 if($this->_bIsApi) {
                     if($bSingle)
-                        $sCode = $oEx->decodeDataAPI($oEx->getSearchData());
+                        $sCode = $oEx->{'decode' . ( $this->_bLiveSearch ? 'Ls' : '') . 'DataAPI'}($oEx->getSearchData());
                     else
                         $sCode[$sKey] = $oEx->getSearchQuery($sKey);
                 }
@@ -620,6 +620,32 @@ class BxDolSearchResult implements iBxDolReplaceable
     {
         return $a;
     }
+    
+    function decodeLsDataAPI ($aItems)
+    {
+        if(empty($aItems) || !is_array($aItems))
+            return $aItems;
+
+        var_dump($this->getModuleName() . ' --- ' . $this->getContentInfoName());
+
+        $aResult = [];
+        foreach($aItems as $aItem) {
+            $iItemId = $aItem['id'] ?? false;
+            if(!$iItemId)
+                continue;
+
+            $aItemData = $this->_getLsItemDataAPI($iItemId);
+            if($aItemData && is_array($aItemData) && ($aIdContent = ($aItemData['content'] ?? false)))
+                $aResult[] = $aIdContent;
+        }
+
+        return $aResult;
+    }
+
+    protected function _getLsItemDataAPI($iItemId)
+    {
+        return [];
+    }
 
     /**
      * Get html output of search result

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

@@ -96,6 +96,15 @@ class BxBaseModGeneralCmtsSearchResult extends BxBaseModGeneralSearchResult
         return $a;
     }
 
+    protected function _getLsItemDataAPI($iItemId)
+    {
+        $oCmts = BxDolCmts::getObjectInstance($this->sModuleObjectComments, 0, false);
+        if(!$oCmts)
+            return [];
+         
+        return bx_srv('system', 'get_timeline_post', [['object_id' => $oCmts->getCommentUniqId($iItemId)]], 'TemplCmtsServices');
+    }
+    
     function _getPseud ()
     {
         return array(

+ 5 - 0
modules/base/general/classes/BxBaseModGeneralSearchResult.php

@@ -297,6 +297,11 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
         return $a;
     }
 
+    protected function _getLsItemDataAPI($iItemId)
+    {
+        return bx_srv($this->getModuleName(), 'get_timeline_post', [['object_id' => $iItemId]]);
+    }
+
     protected function _updateCurrentForFollowedContexts($sMode, $aParams, &$oProfileContext)
     {
         $CNF = &$this->oModule->_oConfig->CNF;

+ 3 - 0
template/scripts/BxBaseCmtsServices.php

@@ -286,6 +286,7 @@ class BxBaseCmtsServices extends BxDol
             return false;
 
         $sCmtUrl = $oCmts->getViewUrl($iCmtId);
+        $sCmtUrlApi = $oCmts->getItemUrlApi($iCmtId);
 
         $sSample = '_cmt_txt_sample_comment_single_with_article';
         $sSampleWoArticle = '_cmt_txt_sample_comment_single';
@@ -351,11 +352,13 @@ class BxBaseCmtsServices extends BxDol
                 'markers' => $aActionCustomMarkers
             ),
             'url' => $sCmtUrl,
+            'url_api' => $sCmtUrlApi,
             'content' => array(
                 'sample' => $sSample,
                 'sample_wo_article' => $sSampleWoArticle,
                 'sample_action' => $sAction,
                 'url' => $sCmtUrl,
+                'url_api' => $sCmtUrlApi,
                 'title' => '',
                 'text' => $oCmts->getViewText($aCmt),
                 'images' => array(),

+ 17 - 17
template/scripts/BxBaseServices.php

@@ -1078,16 +1078,17 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
      */
     public function serviceSearchKeywordResult ()
     {
+        $sType = bx_process_input(bx_get('type'));
         $sKeyword = bx_process_input(bx_get('keyword'));
         $bKeyword = $sKeyword !== false;
 
         if(bx_is_api())
             return $this->serviceGetDataSearchApi(['params' => [
-                    'keyword' => $sKeyword,
-                    'section' => bx_process_input(bx_get('section')),
-                    'cat' => bx_process_input(bx_get('cat'))
-                ]
-            ]);
+                'type' => $sType,
+                'keyword' => $sKeyword,
+                'section' => bx_process_input(bx_get('section')),
+                'cat' => bx_process_input(bx_get('cat'))
+            ]]);
 
         $sCode = '';
         if($bKeyword) {
@@ -1124,9 +1125,11 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             return false;
 
         if(is_string($aParams))
-            $aParams = json_decode($aParams, true);
+            $aParams = bx_api_get_browse_params($aParams);
 
-        $aSections = [];
+        $bForceAll = ($aParams['params']['type'] ?? '') == 'keyword';
+
+        $aSectionsAvail = explode(',', getParam('sys_api_search_sections'));
         $aSectionsAll = BxDolDb::getInstance()->fromCache(
             'sys_global_search_pairs', 
             'getPairs', 
@@ -1134,16 +1137,13 @@ class BxBaseServices extends BxDol implements iBxDolProfileService
             'name', 'title'
         );
 
-        $aSectionNames = explode(',', getParam('sys_api_search_sections'));
-        foreach($aSectionNames as $sSectionName) {
-            if(!isset($aSectionsAll[$sSectionName]))
-                continue;
-
-            $aSections[$sSectionName] = [
-                'name' => $sSectionName,
-                'title' => _t($aSectionsAll[$sSectionName])
-            ];
-        }
+        $aSections = [];
+        foreach($aSectionsAll as $sSectionName => $sSectionTitle)
+            if(in_array($sSectionName, $aSectionsAvail) || $bForceAll)
+                $aSections[$sSectionName] = [
+                    'name' => $sSectionName,
+                    'title' => _t($sSectionTitle)
+                ];
 
         $aParamsBrowse = array_merge([
             'keyword' => '',