Skip to content

Commit

Permalink
#4558 - Build-in API support (any core actions)
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Dec 8, 2023
1 parent 4d5f35e commit 6aa6fff
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 3 deletions.
9 changes: 9 additions & 0 deletions inc/classes/BxDolTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -3460,6 +3460,12 @@ function displayAccessDenied ($sMsg = '', $iPage = BX_PAGE_DEFAULT, $iDesignBox
bx_import('BxDolLanguages');
header('HTTP/1.0 403 Forbidden');
header('Status: 403 Forbidden');

$a = [
'title' => _t('_access_denied_page_title'),
'content' => _t('_access_denied_page_content'),
];

$this->displayMsg($sMsg ? $sMsg : _t('_Access denied'), false, $iPage, $iDesignBox);
}

Expand Down Expand Up @@ -3499,6 +3505,9 @@ function displayMsg ($s, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesign
$sTitle = _t($sTitle);
$sContent = _t($sContent);
}

if (bx_is_api())
return [bx_api_get_msg($sContent)];

$sContent = MsgBox($sContent);
if($iPage == BX_PAGE_DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ public function setContentId($iContentId)
));
}

protected function getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile)
{
return '';
}

protected function _getMenuItemConnectionApi($sConnection, $sAction, &$aItem)
{
if(!isLogged() || $this->_oModule->{$this->_aConnectionToFunctionCheck[$sConnection][$sAction]}($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED)
if(!isLogged() || (isset($this->_aConnectionToFunctionCheck[$sConnection]) && $this->_oModule->{$this->_aConnectionToFunctionCheck[$sConnection][$sAction]}($this->_aContentInfo) !== CHECK_ACTION_RESULT_ALLOWED))
return false;

$iInitiatorProfile = bx_get_logged_profile_id();
$iContentProfile = $this->_oProfile->id();
$sTitle = $this->_oModule->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);

if(empty($sTitle))
$sTitle = $this->getMenuItemTitleByConnection($sConnection, $sAction, $iContentProfile, $iInitiatorProfile);
if(empty($sTitle))
return false;

return [
'id' => $aItem['id'],
'name' => $aItem['name'],
Expand Down
17 changes: 16 additions & 1 deletion modules/base/profile/classes/BxBaseModProfileModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1017,10 +1017,25 @@ public function serviceEntityCover ($iContentId = 0, $aParams = [])
return false;

list($iContentId, $aContentInfo) = $mixedContent;

if(bx_is_api()){
$aContentInfo['cover'] = $this->serviceGetCover($iContentId);
$aContentInfo['image'] = $this->serviceGetThumb($iContentId);

$CNF = $this->_oConfig->CNF;
if(!empty($CNF['OBJECT_MENU_VIEW_ENTRY_META'])){
$oMetaMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_VIEW_ENTRY_META']);
$aContentInfo['meta_menu'] = $oMetaMenu->getCodeAPI();
}
if(!empty($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY'])){
$oActionMenu = BxTemplMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_VIEW_ENTRY_ALL']);
$aContentInfo['actions_menu'] = $oActionMenu->getCodeAPI();
}
$oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $this->MODULE);
$aContentInfo['profile'] = BxDolProfile::getData($this->_aProfileInfo['id'], [
'get_avatar' => 'getAvatarBig',
'with_info' => false
]);

return [bx_api_get_block('entity_cover', $aContentInfo)];
}

Expand Down
2 changes: 2 additions & 0 deletions modules/boonex/english/data/langs/system/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<string name="_ATT_SUSPENDED_E"><![CDATA[Your profile is temporarily out of {0} system services. You can activate it <a target=_blank href="change_status.php">here</a>. If you have any questions, please <a target=_blank href="contact.php">contact the administrators</a>.]]></string>
<string name="_ATT_UNCONFIRMED_E"><![CDATA[You will need to follow the link supplied in the e-mail to get your account submitted for approval. <br />Send me <a target=_blank href="activation_email.php">confirmation e-mail</a>.]]></string>
<string name="_Access denied"><![CDATA[Access denied]]></string>
<string name="_access_denied_page_title"><![CDATA[Page Not Available]]></string>
<string name="_access_denied_page_content"><![CDATA[Sorry, this content is no longer available. It may have been removed or is not accessible due to violation of our terms of service.]]></string>
<string name="_Action"><![CDATA[Action]]></string>
<string name="_all"><![CDATA[All]]></string>
<string name="_Allowed Since"><![CDATA[Allowed Since]]></string>
Expand Down
4 changes: 4 additions & 0 deletions template/scripts/BxBasePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,10 @@ public function getPageAPI ($aBlocks = [])
'blocks' => $aBlocks,
'data' => &$a,
];

if (!$this->_isVisiblePage($this->_aObject))
$a['page_status'] = 403;

bx_alert('system', 'get_page_api', 0, 0, $aExtras);

return $a;
Expand Down

0 comments on commit 6aa6fff

Please sign in to comment.