Skip to content

Commit

Permalink
#4148 - Build-in API support - timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Jan 20, 2023
1 parent c8f3916 commit 13dc8c9
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 48 deletions.
10 changes: 10 additions & 0 deletions inc/classes/BxDolProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ public static function getInstance($mixedProfileId = false, $bClearCache = false
return $GLOBALS['bxDolClasses'][$sClass];
}

public static function getData($mixedProfileId = false)
{
$oProfile = BxDolProfile::getInstanceMagic($mixedProfileId);
return [
'display_name' => $oProfile->getDisplayName(),
'url' => $oProfile->getUrl(),
'url_avatar' => $oProfile->getAvatar(),
];
}

/**
* Get profile id
*/
Expand Down
13 changes: 7 additions & 6 deletions inc/utils.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2326,11 +2326,6 @@ function bx_absolute_url($sUrl, $sPrefix = BX_DOL_URL_ROOT)

function bx_is_api()
{
if (bx_get('api-acc')){
$iCookieTime = true ? time() + 60 * getParam('sys_session_lifetime_in_min') : 0;
bx_setcookie("memberID", 1, $iCookieTime, 'auto');
check_logged();
}
return defined('BX_API') || bx_get('api') ? true : false;
}

Expand All @@ -2351,8 +2346,14 @@ function bx_api_check_origins()
header('Access-Control-Allow-Methods: POST, GET');
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);
}

/** @} */
7 changes: 4 additions & 3 deletions modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3458,12 +3458,13 @@ protected function _entityComments ($sObject, $iId = 0)
return false;


if (bx_is_api())
if (bx_is_api()){
$aData = $oCmts->getFormPost(0);
return [
['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI(array(), array('in_designbox' => false, 'show_empty' => false))],
['id' => 2, 'type' => 'form', 'data' => $oCmts->getFormObject()->getCodeAPI(), 'request' => ['url' => '/cmts.php', 'immutable' => true]]
['id' => 2, 'type' => 'form', 'data' => $aData['frm']->getCodeAPI(), 'request' => ['url' => '/cmts.php?api=1', 'immutable' => true]]
];

}
return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
}

Expand Down
16 changes: 3 additions & 13 deletions modules/base/general/classes/BxBaseModGeneralSearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ function displayResultBlock()
function decodeData ($a)
{
$oContentInfo = $this->getContentInfoObject();

$CNF = $this->oModule->_oConfig->CNF;

foreach ($a as $i => $r) {
if (isset($r['author']))
$a[$i]['author_data'] = $this->decodeDataAuthor($oContentInfo, $r);
$a[$i]['author_data'] = BxDolProfile::getData($r[$CNF['FIELD_AUTHOR']]);

$a[$i]['url'] = $this->decodeDataUrl($oContentInfo, $r);
$a[$i]['url_thumb'] = $oContentInfo->getContentThumb($r['id']);
Expand All @@ -232,17 +233,6 @@ function decodeDataUrl ($oContentInfo, $r)
return bx_ltrim_str($oContentInfo->getContentLink($r['id']), BX_DOL_URL_ROOT);
}

function decodeDataAuthor ($oContentInfo, $r)
{
$CNF = $this->oModule->_oConfig->CNF;
$oProfile = BxDolProfile::getInstanceMagic($r[$CNF['FIELD_AUTHOR']]);
return [
'display_name' => $oProfile->getDisplayName(),
'url' => $oProfile->getUrl(),
'url_avatar' => $oProfile->getAvatar(),
];
}

function decodeDataSummaryPlain ($oContentInfo, $r)
{
$CNF = $this->oModule->_oConfig->CNF;
Expand Down
4 changes: 1 addition & 3 deletions modules/boonex/timeline/classes/BxTimelineModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4901,9 +4901,7 @@ protected function _serviceGetBlockViewByType($aBrowseParams = array())

$this->_iOwnerId = $aParams['owner_id'];

return array(
'content' => $this->_oTemplate->getViewBlock($aParams)
);
return bx_is_api() ? [['id' => 1, 'type' => 'browse', 'data' => ['unit' => 'feed', 'data' => $this->_oTemplate->getViewBlock($aParams)]]] : ['content' => $this->_oTemplate->getViewBlock($aParams)];
}

protected function _getBlockPost($iProfileId, $aParams = array())
Expand Down
9 changes: 9 additions & 0 deletions modules/boonex/timeline/classes/BxTimelineTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,15 @@ public function getViewBlock($aParams)
$oModule = $this->getModule();

list($sContent, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->getPosts($aParams);

if (bx_is_api()){
$aPosts = $this->getPosts(array_merge($aParams, ['return_data_type' => 'array']));
foreach($aPosts as &$aPost) {
$aPost['author_data'] = BxDolProfile::getData($aPost['object_owner_id']);
$aPost['url'] = bx_ltrim_str($aPost['content']['url'], BX_DOL_URL_ROOT);
}
return $aPosts;
}

//--- Add live update
$oModule->actionResumeLiveUpdate($aParams['type'], $aParams['owner_id']);
Expand Down
35 changes: 12 additions & 23 deletions template/scripts/BxBaseCmts.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,12 @@ function decodeData ($a)
{
foreach ($a as $i => $r) {
if (isset($r['cmt_author_id']))
$a[$i]['author_data'] = $this->decodeDataAuthor($r);
$a[$i]['author_data'] = BxDolProfile::getData($r['cmt_author_id']);
}

return $a;
}

function decodeDataAuthor ($r) // TODO: get rid of duplicate code here and in BxBaseModGeneralSearchResult
{
$oProfile = BxDolProfile::getInstanceMagic($r['cmt_author_id']);
return [
'display_name' => $oProfile->getDisplayName(),
'url' => $oProfile->getUrl(),
'url_avatar' => $oProfile->getAvatar(),
];
}

/**
* get full comments block with initializations
*/
Expand Down Expand Up @@ -1135,23 +1125,22 @@ protected function _getFormAdd($aValues)
protected function _getFormPost($iCmtParentId = 0, $aDp = [])
{
$bCmtParentId = !empty($iCmtParentId);
if (!bx_is_api()){
if(!$bCmtParentId && !$this->isPostAllowed()) {
$sMsg = '';
if(!isLogged()) {
$oPermalink = BxDolPermalinks::getInstance();
$sMsg = _t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account'));
}
else
$sMsg = $this->msgErrPostAllowed();

return ['msg' => $sMsg];
if(!$bCmtParentId && !$this->isPostAllowed()) {
$sMsg = '';
if(!isLogged()) {
$oPermalink = BxDolPermalinks::getInstance();
$sMsg = _t('_cmt_msg_login_required', $oPermalink->permalink('page.php?i=login'), $oPermalink->permalink('page.php?i=create-account'));
}
else
$sMsg = $this->msgErrPostAllowed();

if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId))
return ['msg' => $this->msgErrReplyAllowed()];
return ['msg' => $sMsg];
}

if($bCmtParentId && !$this->isReplyAllowed($iCmtParentId))
return ['msg' => $this->msgErrReplyAllowed()];

$bDynamic = isset($aDp['dynamic_mode']) && (bool)$aDp['dynamic_mode'];
$bQuote = isset($aDp['quote']) && (bool)$aDp['quote'];

Expand Down

0 comments on commit 13dc8c9

Please sign in to comment.