Sfoglia il codice sorgente

#4148 Build-in API support

Alex Trofimov 3 anni fa
parent
commit
839ccdb760

+ 17 - 0
inc/classes/BxDolSearch.php

@@ -479,6 +479,10 @@ class BxDolSearchResult implements iBxDolReplaceable
      */
     function processing ()
     {
+        if (defined('BX_API')) {
+            return $this->processingAPI ();
+        }
+
         $sCode = $this->displayResultBlock();
         if ($this->aCurrent['paginate']['num'] > 0) {
             $sPaginate = $this->showPagination();
@@ -489,6 +493,19 @@ class BxDolSearchResult implements iBxDolReplaceable
         return $sCode;
     }
 
+    function processingAPI () 
+    {
+        return [
+            'unit' => 'general',
+            'data' => $this->getSearchData(),
+            'paginate' => [
+                'num' => $this->aCurrent['paginate']['num'],
+                'per_page' => $this->aCurrent['paginate']['perPage'],
+                'start' => $this->aCurrent['paginate']['start'],
+            ]
+        ];
+    }
+
     /**
      * Get html output of search result
      * @return html code

+ 1 - 7
inc/classes/BxDolTemplate.php

@@ -1630,11 +1630,6 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
     function parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
     {
         if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginTemplate($sName, $sRand = time().rand());
-        
-        if (defined('BX_API') && constant('BX_API')) {
-            if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sContent, false);
-            return $aVariables;
-        }
 
         if (($sContent = $this->getCached($sName, $aVariables, $mixedKeyWrapperHtml, $sCheckIn)) !== false) {
             if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sContent, true);
@@ -2939,8 +2934,7 @@ class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
         ));
 
         //--- Parse Predefined Keys ---//
-        if (!defined('BX_API') || !constant('BX_API'))
-            $sContent = preg_replace($aKeys, $aValues, $sContent);
+        $sContent = preg_replace($aKeys, $aValues, $sContent);
 
         //--- Parse System Keys ---//
         try {

+ 2 - 2
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -2729,7 +2729,7 @@ class BxBaseModGeneralModule extends BxDolModule
     public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
     {
         if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
-            return MsgBox($sMsg);
+            return defined('BX_API') ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : MsgBox($sMsg);
 
         bx_import($sClassSearchResult, $this->_aModule);
         $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
@@ -2746,7 +2746,7 @@ class BxBaseModGeneralModule extends BxDolModule
             return '';
 
         if ($s = $o->processing())
-            return $s;
+            return defined('BX_API') ? [['id' => 1, 'type' => 'browse', 'data' => $s]] : $s;
         else
             return '';
     }