Skip to content

Commit

Permalink
#4148 - Build-in API support (cmts+timeline)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Jan 20, 2023
1 parent 13dc8c9 commit d508377
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
2 changes: 0 additions & 2 deletions cmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

bx_import('BxDolLanguages');

bx_api_check_origins();

check_logged();

$sSys = isset($_REQUEST['sys']) ? bx_process_input($_REQUEST['sys']) : '';
Expand Down
7 changes: 7 additions & 0 deletions inc/classes/BxDolCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions inc/classes/BxDolForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions inc/utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/** @} */
8 changes: 4 additions & 4 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
24 changes: 14 additions & 10 deletions template/scripts/BxBaseCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [])
Expand Down

0 comments on commit d508377

Please sign in to comment.