diff --git a/cmts.php b/cmts.php index c53f20eabc..38758f4f8e 100644 --- a/cmts.php +++ b/cmts.php @@ -12,8 +12,6 @@ bx_import('BxDolLanguages'); -bx_api_check_origins(); - check_logged(); $sSys = isset($_REQUEST['sys']) ? bx_process_input($_REQUEST['sys']) : ''; diff --git a/inc/classes/BxDolCmts.php b/inc/classes/BxDolCmts.php index a93413129d..71a1bcda53 100644 --- a/inc/classes/BxDolCmts.php +++ b/inc/classes/BxDolCmts.php @@ -1793,6 +1793,13 @@ protected function _getFormObject($sAction = BX_CMT_ACTION_POST) return BxDolForm::getObjectInstance($this->_sFormObject, $this->$sDisplayName, false, $this->_sSystem); } + + protected function _unsetFormObject($sAction = BX_CMT_ACTION_POST) + { + $sDisplayName = '_sFormDisplay' . ucfirst($sAction); + + return BxDolForm::unsetObjectInstance($this->_sFormObject, $this->$sDisplayName, false, $this->_sSystem); + } protected function _getParams(&$aBp, &$aDp) { diff --git a/inc/classes/BxDolForm.php b/inc/classes/BxDolForm.php index 3b16e7cc2d..52d23deb61 100644 --- a/inc/classes/BxDolForm.php +++ b/inc/classes/BxDolForm.php @@ -803,6 +803,12 @@ static public function getObjectInstance($sObject, $sDisplayName, $oTemplate = f return ($GLOBALS['bxDolClasses'][$sKey] = $o); } + + static public function unSetObjectInstance($sObject, $sDisplayName, $oTemplate = false, $sParam = '') + { + $sKey = 'BxDolForm!'.$sObject.'!'.$sDisplayName.'!'.$sParam; + unset($GLOBALS['bxDolClasses'][$sKey]); + } /** * Get data items array diff --git a/inc/utils.inc.php b/inc/utils.inc.php index 540c197e59..a731ce3350 100644 --- a/inc/utils.inc.php +++ b/inc/utils.inc.php @@ -2347,13 +2347,10 @@ function bx_api_check_origins() header('Access-Control-Allow-Headers: Accept-Encoding, Authorization, Cache-Control, Connection, Host, Origin, Pragma, Referer, User-Agent, X-Custom-Header, X-Requested-With'); exit; } - - } //TODO: Temporatery for use logged state bx_login(1); check_logged(); - //echoDbgLog($_SERVER); } /** @} */ diff --git a/modules/base/general/classes/BxBaseModGeneralModule.php b/modules/base/general/classes/BxBaseModGeneralModule.php index cea5bb0aff..d0b354e89f 100644 --- a/modules/base/general/classes/BxBaseModGeneralModule.php +++ b/modules/base/general/classes/BxBaseModGeneralModule.php @@ -3456,13 +3456,13 @@ protected function _entityComments ($sObject, $iId = 0) $oCmts = BxDolCmts::getObjectInstance($sObject, $iId); if (!$oCmts || !$oCmts->isEnabled()) return false; - if (bx_is_api()){ - $aData = $oCmts->getFormPost(0); + $aForm = $oCmts->getFormPost(0)->getCodeAPI(); + return [ - ['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI(array(), array('in_designbox' => false, 'show_empty' => false))], - ['id' => 2, 'type' => 'form', 'data' => $aData['frm']->getCodeAPI(), 'request' => ['url' => '/cmts.php?api=1', 'immutable' => true]] + ['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false])], + ['id' => 2, 'type' => 'form', 'data' => $aForm, 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_comments', 'immutable' => true]] ]; } return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false)); diff --git a/template/scripts/BxBaseCmts.php b/template/scripts/BxBaseCmts.php index cf503db84c..f91ce372a5 100644 --- a/template/scripts/BxBaseCmts.php +++ b/template/scripts/BxBaseCmts.php @@ -1135,11 +1135,11 @@ protected function _getFormPost($iCmtParentId = 0, $aDp = []) else $sMsg = $this->msgErrPostAllowed(); - return ['msg' => $sMsg]; + return bx_is_api() ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : ['msg' => $sMsg]; } if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId)) - return ['msg' => $this->msgErrReplyAllowed()]; + return bx_is_api() ? [['id' => 1, 'type' => 'msg', 'data' => $sMsg]] : ['msg' => $this->msgErrReplyAllowed()]; $bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode']; $bQuote = isset($aDp['quote']) && (bool)$aDp['quote']; @@ -1171,8 +1171,7 @@ protected function _getFormPost($iCmtParentId = 0, $aDp = []) if(!$bCmtText && !$bImageIds) { $oForm->aInputs['cmt_text']['error'] = _t('_Please enter characters'); $oForm->setValid(false); - - return ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id]; + return bx_is_api() ? $oForm : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id]; } $aParent = []; @@ -1218,14 +1217,19 @@ protected function _getFormPost($iCmtParentId = 0, $aDp = []) if($this->_sMetatagsObj && ($oMetatags = BxDolMetatags::getObjectInstance($this->_sMetatagsObj)) !== false) $oMetatags->metaAdd($iCmtUniqId, $sCmtText); - if(($mixedResult = $this->onPostAfter($iCmtId, $aDp)) !== false) - return $mixedResult; + if(($mixedResult = $this->onPostAfter($iCmtId, $aDp)) !== false){ + if (bx_is_api()){ + $this->_unsetFormObject(BX_CMT_ACTION_POST); + return $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId); + } + else{ + return $mixedResult; + } + } } - - return ['msg' => _t('_cmt_err_cannot_perform_action')]; + return bx_is_api() ? [['id' => 1, 'type' => 'msg', 'data' => _t('_cmt_err_cannot_perform_action')]] : ['msg' => _t('_cmt_err_cannot_perform_action')]; } - - return ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id, 'frm' => $oForm]; + return bx_is_api() ? $oForm : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id]; } protected function _getFormEdit($iCmtId, $aDp = [])