فهرست منبع

#4148 Build-in API support (common changes, entryText)

roman.lesnikov@gmail.com 3 سال پیش
والد
کامیت
dd08d2ee3e

+ 5 - 0
inc/utils.inc.php

@@ -2324,4 +2324,9 @@ function bx_absolute_url($sUrl, $sPrefix = BX_DOL_URL_ROOT)
     return $sUrl;
     return $sUrl;
 }
 }
 
 
+function bx_api_rv($mJson, $mHtml)
+{
+    return defined('BX_API') ? $mJson : $mHtml;
+}
+
 /** @} */
 /** @} */

+ 12 - 6
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -137,14 +137,18 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
     {
     {
         $CNF = &$this->_oModule->_oConfig->CNF;
         $CNF = &$this->_oModule->_oConfig->CNF;
 
 
+        $sMsgCnt = '';
         // get content data and profile info
         // get content data and profile info
         list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
         list ($oProfile, $aContentInfo) = $this->_getProfileAndContentData($iContentId);
         if (!$aContentInfo)
         if (!$aContentInfo)
-            return MsgBox(_t('_sys_txt_error_entry_is_not_defined'));
+            $sMsgCnt = _t('_sys_txt_error_entry_is_not_defined');
 
 
         // check access
         // check access
-        if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
-            return MsgBox($sMsg);
+        if (empty($sMsgCnt) && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->_oModule->checkAllowedView($aContentInfo)))
+            $sMsgCnt = $sMsg;
+        
+        if ($sMsgCnt)
+            return bx_api_rv([['id' => 1, 'type' => 'msg', 'data' => $sMsgCnt]], MsgBox($sMsgCnt));
 
 
         $oForm = $this->getObjectFormView();
         $oForm = $this->getObjectFormView();
         if (!$oForm)
         if (!$oForm)
@@ -153,9 +157,11 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
         $oForm->initChecker($aContentInfo);
         $oForm->initChecker($aContentInfo);
 
 
         if(!empty($CNF['FIELD_TEXT']) &&  !$oForm->isInputVisible($CNF['FIELD_TEXT']))
         if(!empty($CNF['FIELD_TEXT']) &&  !$oForm->isInputVisible($CNF['FIELD_TEXT']))
-            return '';
-
-        return $this->_oModule->_oTemplate->entryText($aContentInfo);
+            $s = '';
+        else
+            $s = $this->_oModule->_oTemplate->entryText($aContentInfo);
+        
+        return bx_api_rv([['id' => 1, 'type' => 'entry', 'data' => $s]], $s);
     }
     }
 
 
     public function addData ($iProfile, $aValues, $sDisplay = false)
     public function addData ($iProfile, $aValues, $sDisplay = false)

+ 3 - 7
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -2761,7 +2761,7 @@ class BxBaseModGeneralModule extends BxDolModule
     public function _serviceBrowse ($sMode, $aParams = false, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true, $sClassSearchResult = 'SearchResult')
     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()))
         if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $this->checkAllowedBrowse()))
-            return defined('BX_API') ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : MsgBox($sMsg);
+            return bx_api_rv([['id' => 1, 'type' => 'msg', 'data' => $sMsg]], MsgBox($sMsg));
 
 
         bx_import($sClassSearchResult, $this->_aModule);
         bx_import($sClassSearchResult, $this->_aModule);
         $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
         $sClass = $this->_aModule['class_prefix'] . $sClassSearchResult;
@@ -2778,7 +2778,7 @@ class BxBaseModGeneralModule extends BxDolModule
             return '';
             return '';
 
 
         if ($s = $o->processing())
         if ($s = $o->processing())
-            return defined('BX_API') ? [['id' => 1, 'type' => 'browse', 'data' => $s]] : $s;
+            return bx_api_rv([['id' => 1, 'type' => 'browse', 'data' => $s]], $s);
         else
         else
             return '';
             return '';
     }
     }
@@ -3457,11 +3457,7 @@ class BxBaseModGeneralModule extends BxDolModule
         if (!$oCmts || !$oCmts->isEnabled())
         if (!$oCmts || !$oCmts->isEnabled())
             return false;
             return false;
 
 
-        
-        if (defined('BX_API'))
-            return [['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI(array(), array('in_designbox' => false, 'show_empty' => false))]];
-
-        return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
+        return bx_api_rv([['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI(array(), array('in_designbox' => false, 'show_empty' => false))]], $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false)));
     }
     }
 
 
     protected function _getFields($iContentId)
     protected function _getFields($iContentId)

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralTemplate.php

@@ -226,7 +226,7 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
         if (empty($aVars['entry_text']))
         if (empty($aVars['entry_text']))
             return false;
             return false;
         
         
-        return $this->parseHtmlByName($sTemplateName, $aVars);
+        return bx_api_rv($aVars, $this->parseHtmlByName($sTemplateName, $aVars));
     }
     }
 
 
     public function entryLocation ($iContentId)
     public function entryLocation ($iContentId)