BxCnlModule.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defdroup Channels Channels
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Channels profiles module.
  13. */
  14. class BxCnlModule extends BxBaseModGroupsModule
  15. {
  16. function __construct(&$aModule)
  17. {
  18. parent::__construct($aModule);
  19. }
  20. public function _modGroupsCheckAllowedSubscribeAdd(&$aDataEntry, $isPerformAction = false)
  21. {
  22. return parent::_modProfileCheckAllowedSubscribeAdd($aDataEntry, $isPerformAction);
  23. }
  24. /**
  25. * Process Hash Tag
  26. *
  27. * @param string $sHashtag - hashtag to be processed.
  28. * @param string $sModuleName - module name.
  29. * @param integer $iContentId - ID of the content which has the hashtag.
  30. * @param integer $iSenderId - action's sender (author) id.
  31. */
  32. function processHashtag($sHashtag, $sModuleName, $iContentId, $iSenderId = 0)
  33. {
  34. $CNF = &$this->_oConfig->CNF;
  35. /*
  36. * Note! For now metatag object name is used here as module name, because usually it's equal to module's name. This should be changed in Ticket #1596
  37. * For now if module cannot be created then a channel for such tag shouldn't be created too.
  38. */
  39. $oModule = BxDolModule::getInstance($sModuleName);
  40. if(empty($oModule) && $sModuleName != 'sys_cmts')
  41. return;
  42. /*
  43. * Ticket #4640
  44. *
  45. * Before:
  46. * Use content's author profile when Author ID wasn't provided.
  47. * Usually it happens when tags were processed with cron.
  48. *
  49. * After:
  50. * Use content's author profile every time when it's possible. Otherwise use sender from alert.
  51. */
  52. $iAuthorId = 0;
  53. if(($sModuleMethod = 'get_author') && bx_is_srv($sModuleName, $sModuleMethod))
  54. $iAuthorId = abs(bx_srv($sModuleName, $sModuleMethod, [$iContentId]));
  55. if(empty($iAuthorId) && !empty($iSenderId))
  56. $iAuthorId = $iSenderId;
  57. $aCheck = checkActionModule($iAuthorId, 'create channel auto', $this->getName(), false);
  58. $mixedCnlId = $this->_oDb->getChannelIdByName($sHashtag);
  59. if(empty($mixedCnlId) && ($aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED)) {
  60. $iProfileId = (int)$this->_oDb->getParam($CNF['PARAM_DEFAULT_AUTHOR']);
  61. if(empty($iProfileId)) {
  62. $aOperators = BxDolAccountQuery::getInstance()->getOperators();
  63. if(count($aOperators) > 0)
  64. $iProfileId = BxDolProfile::getInstanceByAccount(array_shift($aOperators))->id();
  65. }
  66. $aContent = $this->serviceEntityAdd($iProfileId, array($CNF['FIELD_NAME'] => $sHashtag, $CNF['FIELD_CF'] => 1));
  67. checkActionModule($iAuthorId, 'create channel auto', $this->getName(), true);
  68. if(isset($aContent['content']) && isset($aContent['content']['id']))
  69. $mixedCnlId = $aContent['content']['id'];
  70. }
  71. if(empty($mixedCnlId) || (int)$this->_oDb->checkContentInChannel($iContentId, $mixedCnlId, $sModuleName, $iAuthorId) != 0)
  72. return;
  73. $iId = (int)$this->_oDb->addContentToChannel($iContentId, $mixedCnlId, $sModuleName, $iAuthorId);
  74. if($iId == 0)
  75. return;
  76. $oCnlProfile = BxDolProfile::getInstanceByContentAndType($mixedCnlId, $this->_oConfig->getName());
  77. if(!$oCnlProfile)
  78. return;
  79. $iCnlProfileId = $oCnlProfile->id();
  80. /**
  81. * @hooks
  82. * @hookdef hook-bx_channels-hashtag_added 'bx_channels', 'hashtag_added' - hook on found hashtag in content
  83. * - $unit_name - equals `bx_channels`
  84. * - $action - equals `hashtag_added`
  85. * - $object_id - content_id in channel
  86. * - $sender_id - channel profile_id
  87. * - $extra_params - array of additional params with the following array keys:
  88. * - `object_author_id` - [int] profile_id for content's author
  89. * - `privacy_view` - [string] equal - channel_profile_id
  90. * - `subobject_id` - [int] content_id in channel
  91. * - `content_module` - [string] module name for content
  92. * - `content_id` - [int] content_id
  93. * - `content_author_id` - [int] equal with object_author_id
  94. * - `timeline_group` - [array] parameters for group event in timeline ['by' => $sModuleName . '_' . $iAuthorId . '_' . $iContentId, 'field' => 'owner_id']
  95. * @hook @ref hook-bx_channels-hashtag_added
  96. */
  97. bx_alert($this->_aModule['name'], 'hashtag_added', $iId, $iCnlProfileId, array(
  98. 'object_author_id' => $iAuthorId,
  99. 'privacy_view' => -$iCnlProfileId,
  100. 'subobject_id' => $iId,
  101. 'content_module' => $sModuleName,
  102. 'content_id' => $iContentId,
  103. 'content_author_id' => $iAuthorId,
  104. 'timeline_group' => array(
  105. 'by' => $sModuleName . '_' . $iAuthorId . '_' . $iContentId,
  106. 'field' => 'owner_id'
  107. )
  108. ));
  109. $aParams = array(
  110. 'object_author_id' => $iAuthorId,
  111. 'privacy_view' => -$iCnlProfileId,
  112. 'subobject_id' => $iId,
  113. 'content_module' => $sModuleName,
  114. 'content_id' => $iContentId,
  115. 'content_author_id' => $iAuthorId
  116. );
  117. bx_alert('system', 'prepare_alert_params', 0, 0, array('unit'=> $this->_aModule['name'], 'action' => 'hashtag_added_notif', 'object_id' => $mixedCnlId, 'sender_id' => $iCnlProfileId, 'extras' => &$aParams));
  118. /**
  119. * @hooks
  120. * @hookdef hook-bx_channels-hashtag_added_notif 'bx_channels', 'hashtag_added_notif' - hook on after found hashtag in content
  121. * - $unit_name - equals `bx_channels`
  122. * - $action - equals `hashtag_added_notif`
  123. * - $object_id - channel id
  124. * - $sender_id - channel profile_id
  125. * - $extra_params - array of additional params with the following array keys:
  126. * - `object_author_id` - [int] profile_id for content's author
  127. * - `privacy_view` - [string] equal - channel_profile_id
  128. * - `subobject_id` - [int] content_id in channel
  129. * - `content_module` - [string] module name for content
  130. * - `content_id` - [int] content_id
  131. * - `content_author_id` - [int] equal with object_author_id
  132. * @hook @ref hook-bx_channels-hashtag_added_notif
  133. */
  134. bx_alert($this->_aModule['name'], 'hashtag_added_notif', $mixedCnlId, $iCnlProfileId, $aParams);
  135. }
  136. function removeContentFromChannel($iContentId, $sModuleName)
  137. {
  138. $oDolProfileQuery = BxDolProfileQuery::getInstance();
  139. $aData = $this->_oDb->getDataByContent($iContentId, $sModuleName);
  140. foreach ($aData as $aRow) {
  141. $iProfileInfo = $oDolProfileQuery->getProfileByContentAndType($aRow['cnl_id'], $this->_aModule['name']);
  142. if(is_array($iProfileInfo)){
  143. /**
  144. * @hooks
  145. * @hookdef hook-bx_channels-hashtag_deleted 'bx_channels', 'hashtag_deleted' - hook on before delete content from channel
  146. * - $unit_name - equals `bx_channels`
  147. * - $action - equals `hashtag_deleted`
  148. * - $object_id - content id in channel
  149. * - $sender_id - channel profile_id
  150. * @hook @ref hook-bx_channels-hashtag_deleted
  151. */
  152. bx_alert($this->_aModule['name'], 'hashtag_deleted', $aRow['id'], $iProfileInfo['id']);
  153. /**
  154. * @hooks
  155. * @hookdef hook-bx_channels-hashtag_deleted_notif 'bx_channels', 'hashtag_deleted_notif' - hook on before delete content from channel
  156. * - $unit_name - equals `bx_channels`
  157. * - $action - equals `hashtag_deleted_notif`
  158. * - $object_id - channel id
  159. * - $sender_id - channel profile_id
  160. * - $extra_params - array of additional params with the following array keys:
  161. * - `subobject_id` - [int] content id in channel
  162. * @hook @ref hook-bx_channels-hashtag_deleted_notif
  163. */
  164. bx_alert($this->_aModule['name'], 'hashtag_deleted_notif', $aRow['cnl_id'], $iProfileInfo['id'], array('subobject_id' => $aRow['id']));
  165. }
  166. }
  167. return $this->_oDb->removeContentFromChannel($iContentId, $sModuleName);
  168. }
  169. public function serviceGetSafeServices()
  170. {
  171. $a = parent::serviceGetSafeServices();
  172. unset($a['GetCreatePostForm']);
  173. unset($a['EntityCreate']);
  174. return array_merge($a, array (
  175. 'EntityBreadcrumb' => '',
  176. 'EntityParent' => '',
  177. 'EntityChilds' => '',
  178. 'SearchResultByHashtag' => '',
  179. ));
  180. }
  181. public function serviceGetWidgetNotices()
  182. {
  183. $CNF = &$this->_oConfig->CNF;
  184. $iResult = 0;
  185. if(empty($this->_oDb->getParam($CNF['PARAM_DEFAULT_AUTHOR'])))
  186. $iResult += 1;
  187. return $iResult;
  188. }
  189. public function serviceGetOptionsDefaultAuthor()
  190. {
  191. $aResult = array(
  192. array('key' => '', 'value' => _t('_Select_one'))
  193. );
  194. $aAccountsIds = BxDolAccountQuery::getInstance()->getOperators();
  195. foreach($aAccountsIds as $iAccountId) {
  196. $aProfilesIds = BxDolAccount::getInstance($iAccountId)->getProfilesIds();
  197. foreach($aProfilesIds as $iProfileId)
  198. $aResult[] = array(
  199. 'key' => $iProfileId,
  200. 'value' => BxDolProfile::getInstance($iProfileId)->getDisplayName()
  201. );
  202. }
  203. return $aResult;
  204. }
  205. /**
  206. * @page service Service Calls
  207. * @section bx_channels Channels
  208. * @subsection bx_channels-page_blocks Page Blocks
  209. * @subsubsection bx_channels-entity_breadcrumb entity_breadcrumb
  210. *
  211. * @code bx_srv('bx_channels', 'entity_breadcrumb', [...]); @endcode
  212. *
  213. * Display channel breadcrumb
  214. * @param $iContentId channel content ID
  215. *
  216. * @see BxCnlModule::serviceEntityBreadcrumb
  217. */
  218. /**
  219. * @ref bx_channels-entity_breadcrumb "entity_breadcrumb"
  220. */
  221. public function serviceEntityBreadcrumb($iContentId = 0)
  222. {
  223. if(!$iContentId)
  224. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  225. if(!$iContentId)
  226. return false;
  227. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  228. if(!$aContentInfo)
  229. return false;
  230. return $this->_oTemplate->entryBreadcrumb($aContentInfo);
  231. }
  232. /**
  233. * @page service Service Calls
  234. * @section bx_channels Channels
  235. * @subsection bx_channels-page_blocks Page Blocks
  236. * @subsubsection bx_channels-entity_parent entity_parent
  237. *
  238. * @code bx_srv('bx_channels', 'entity_parent', [...]); @endcode
  239. *
  240. * Display block with parent channel
  241. * @param $iContentId channel content ID
  242. *
  243. * @see BxCnlModule::serviceEntityParent
  244. */
  245. /**
  246. * @ref bx_channels-entity_parent "entity_parent"
  247. */
  248. public function serviceEntityParent($iContentId = 0)
  249. {
  250. return $this->_serviceTemplateFunc('entryParent', $iContentId);
  251. }
  252. /**
  253. * @page service Service Calls
  254. * @section bx_channels Channels
  255. * @subsection bx_channels-page_blocks Page Blocks
  256. * @subsubsection bx_channels-entity_childs entity_childs
  257. *
  258. * @code bx_srv('bx_channels', 'entity_childs', [...]); @endcode
  259. *
  260. * Display block with child channels
  261. * @param $iContentId channel content ID
  262. *
  263. * @see BxCnlModule::serviceEntityChilds
  264. */
  265. /**
  266. * @ref bx_channels-entity_childs "entity_childs"
  267. */
  268. public function serviceEntityChilds($iContentId = 0)
  269. {
  270. return $this->_serviceTemplateFunc('entryChilds', $iContentId);
  271. }
  272. /**
  273. * @page service Service Calls
  274. * @section bx_channels Channels
  275. * @subsection bx_channels-page_blocks Page Blocks
  276. * @subsubsection bx_channels-search_result_by_hashtag search_result_by_hashtag
  277. *
  278. * @code bx_srv('bx_channels', 'search_result_by_hashtag', [...]); @endcode
  279. *
  280. * Display search results by hashtag for particular channel
  281. * @param $iContentId channel content ID
  282. *
  283. * @see BxCnlModule::serviceSearchResultByHashtag
  284. */
  285. /**
  286. * @ref bx_channels-search_result_by_hashtag "search_result_by_hashtag"
  287. */
  288. public function serviceSearchResultByHashtag($iContentId = 0)
  289. {
  290. $CNF = &$this->_oConfig->CNF;
  291. $oSearch = new BxTemplSearch();
  292. $oSearch->setLiveSearch(0);
  293. $oSearch->setMetaType('keyword');
  294. $aContentInfo = $this->_oDb->getContentInfoById(bx_get('id'));
  295. $_GET['keyword'] = $aContentInfo[$CNF['FIELD_NAME']];
  296. $sCode = $oSearch->response();
  297. if (!$sCode)
  298. $sCode = $oSearch->getEmptyResult();
  299. return $sCode;
  300. }
  301. /**
  302. * Data for Timeline module
  303. */
  304. public function serviceGetTimelineData()
  305. {
  306. $sModule = $this->_aModule['name'];
  307. return array(
  308. 'handlers' => array(
  309. array('group' => $sModule . '_hastag', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_added', 'module_name' => $sModule, 'module_method' => 'get_timeline_post_hashtag', 'module_class' => 'Module', 'groupable' => 0, 'group_by' => ''),
  310. array('group' => $sModule . '_hastag', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted')
  311. ),
  312. 'alerts' => array(
  313. array('unit' => $sModule, 'action' => 'hashtag_added'),
  314. array('unit' => $sModule, 'action' => 'hashtag_deleted')
  315. )
  316. );
  317. }
  318. public function serviceGetTimelinePostAllowedView ($aEvent)
  319. {
  320. $sError = _t('_sys_txt_access_denied');
  321. if(empty($aEvent) || !is_array($aEvent))
  322. return $sError;
  323. $aEventContent = $this->_oDb->getContentById($aEvent['object_id']);
  324. if ($aEventContent['module_name'] == 'sys_cmts')
  325. return CHECK_ACTION_RESULT_ALLOWED;
  326. if(empty($aEventContent) || !is_array($aEventContent))
  327. return $sError;
  328. if(!BxDolRequest::serviceExists($aEventContent['module_name'], 'get_timeline_post_allowed_view'))
  329. return $sError;
  330. return BxDolService::call($aEventContent['module_name'], 'get_timeline_post_allowed_view', array(array('id' => $aEvent['id'], 'owner_id' => $aEventContent['author_id'], 'object_id' => $aEventContent['content_id'])));
  331. }
  332. public function serviceGetTimelinePostHashtag($aEvent, $aBrowseParams = [])
  333. {
  334. if(empty($aEvent) || !is_array($aEvent))
  335. return false;
  336. $aEventContent = $this->_oDb->getContentById($aEvent['object_id']);
  337. if(empty($aEventContent) || !is_array($aEventContent))
  338. return false;
  339. $sModule = $aEventContent['module_name'];
  340. $sClass = 'Module';
  341. if($sModule == 'sys_cmts') {
  342. $sModule = 'system';
  343. $sClass = 'TemplCmtsServices';
  344. }
  345. if(!BxDolRequest::serviceExists($sModule, 'get_timeline_post', $sClass))
  346. return false;
  347. $iContentId = (int)$aEventContent['content_id'];
  348. $iContentAuthor = 0;
  349. if(bx_is_srv($sModule, 'get_author', $sClass))
  350. $iContentAuthor = bx_srv($sModule, 'get_author', [$iContentId], $sClass);
  351. /**
  352. * Prepare fake event array (only mandatory parameters) to get
  353. * necessary data (related to an 'original' event with hashtag/label)
  354. * from associated content module.
  355. */
  356. $iOwnerId = $aEvent['owner_id'];
  357. $mixedObjectPrivacyView = BX_DOL_PG_ALL;
  358. if($iContentAuthor > 0) {
  359. $iOwnerId = (int)$aEventContent['author_id'];
  360. if(bx_is_srv($sModule, 'get_privacy_view', $sClass)) {
  361. $mixedAllowViewTo = bx_srv($sModule, 'get_privacy_view', [$iContentId]);
  362. if($mixedAllowViewTo !== false)
  363. $mixedObjectPrivacyView = $mixedAllowViewTo;
  364. if(is_numeric($mixedAllowViewTo) && (int)$mixedAllowViewTo < 0)
  365. $iOwnerId = abs($mixedAllowViewTo);
  366. }
  367. }
  368. $aResult = bx_srv($sModule, 'get_timeline_post', [[
  369. 'owner_id' => $iOwnerId,
  370. 'object_id' => $iContentId,
  371. 'object_privacy_view' => $mixedObjectPrivacyView
  372. ], $aBrowseParams], $sClass);
  373. if(empty($aResult) || !is_array($aResult))
  374. return $aResult;
  375. /**
  376. * Note. The context shouldn't be changed therefore
  377. * use input event's context (owner_id) in returned results.
  378. */
  379. return array_merge($aResult, [
  380. 'owner_id' => $aEvent['owner_id']
  381. ]);
  382. }
  383. /**
  384. * Data for Notifications module
  385. */
  386. public function serviceGetNotificationsData()
  387. {
  388. $a = parent::serviceGetNotificationsData();
  389. $sModule = $this->_aModule['name'];
  390. $a['handlers'][] = array('group' => $sModule . '_hastag_notif', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_added_notif', 'module_name' => $sModule, 'module_method' => 'get_notifications_post_hashtag', 'module_class' => 'Module');
  391. $a['handlers'][] = array('group' => $sModule . '_hastag_notif', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted_notif');
  392. $a['settings'][] = array('group' => 'hastag', 'unit' => $sModule, 'action' => 'hashtag_added_notif', 'types' => array('follow_context'));
  393. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_added_notif');
  394. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_deleted_notif');
  395. return $a;
  396. }
  397. public function serviceGetNotificationsPostHashtag($aEvent)
  398. {
  399. if(empty($aEvent) || !is_array($aEvent))
  400. return '';
  401. $aContentEvent = $this->_oDb->getContentById($aEvent['subobject_id']);
  402. if(empty($aContentEvent) || !is_array($aContentEvent))
  403. return '';
  404. $oModule = BxDolModule::getInstance($aContentEvent['module_name']);
  405. if ($oModule) {
  406. if (isset($oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW'])){
  407. $oPrivacy = BxDolPrivacy::getObjectInstance($oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  408. if (!$oPrivacy->check($aContentEvent['content_id']))
  409. return '';
  410. }
  411. $aRv = $oModule->serviceGetNotificationsPost(array(
  412. 'object_id' => $aContentEvent['content_id']
  413. ));
  414. $aRv['lang_key'] = '_bx_channels_ntfs_txt_subobject_added';
  415. if(method_exists($oModule, 'serviceActAsProfile') && $oModule->serviceActAsProfile())
  416. $aRv['lang_key'] = '_bx_channels_ntfs_txt_subobject_added_profile';
  417. $aRv['entry_url'] = bx_absolute_url(str_replace(BX_DOL_URL_ROOT, '', $this->serviceGetLink($aContentEvent['cnl_id'])), '{bx_url_root}');
  418. return $aRv;
  419. }
  420. return '';
  421. }
  422. public function serviceBrowseByLevel ($iLevelId = 0, $bDisplayEmptyMsg = false)
  423. {
  424. return $this->_serviceBrowse ('level', array('level' => $iLevelId), BX_DB_PADDING_DEF, $bDisplayEmptyMsg);
  425. }
  426. public function serviceBrowseFollowed($iProfileId = 0, $aParams = array())
  427. {
  428. return $this->_serviceBrowseWithParam ('followed_entries', 'profile_id', $iProfileId, $aParams);
  429. }
  430. public function serviceBrowseAuthor($iProfileId = 0, $aParams = array())
  431. {
  432. $CNF = &$this->_oConfig->CNF;
  433. if(empty($iProfileId))
  434. $iProfileId = bx_get_logged_profile_id();
  435. $sResult = isset($aParams['empty_message']) && (bool)$aParams['empty_message'] === true ? MsgBox(_t('_Empty')) : '';
  436. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  437. if(!$oConnection)
  438. return $sResult;
  439. $aProfiles = $oConnection->getConnectedContentByType($iProfileId, $this->getName());
  440. $aTmplVars = [];
  441. foreach ($aProfiles as $iProfileId) {
  442. $oProfile = BxDolProfile::getInstance($iProfileId);
  443. if(!$oProfile)
  444. continue;
  445. $aTmplVars[] = [
  446. 'unit' => $oProfile->getUnit(0, ['template' => 'unit_wo_cover'])
  447. ];
  448. }
  449. if(empty($aTmplVars) || !is_array($aTmplVars))
  450. return $sResult;
  451. return $this->_oTemplate->parseHtmlByName('my_channels.html', [
  452. 'bx_repeat:items' => $aTmplVars
  453. ]);
  454. }
  455. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  456. {
  457. return true;
  458. }
  459. public function serviceGetFollowingChannelsNames($iProfileId)
  460. {
  461. if (!($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
  462. return array();
  463. if (!($aIds = $oConn->getConnectedContent($iProfileId)))
  464. return array();
  465. $a = array();
  466. foreach ($aIds as $iId) {
  467. if (!($oProfile = BxDolProfile::getInstance($iId)))
  468. continue;
  469. if ($oProfile->getModule() != $this->getName())
  470. continue;
  471. $a[] = $oProfile->getDisplayName();
  472. }
  473. return $a;
  474. }
  475. public function checkAllowedCompose(&$aDataEntry, $isPerformAction = false)
  476. {
  477. return _t('_sys_txt_access_denied');
  478. }
  479. public function checkAllowedContact($aDataEntry, $isPerformAction = false)
  480. {
  481. return _t('_sys_txt_access_denied');
  482. }
  483. public function followLabels($sModule, $iContentId)
  484. {
  485. if (!getParam('bx_channels_labels_autofollow'))
  486. return;
  487. if (!($oModuleProfiles = BxDolModule::getInstance($sModule)))
  488. return;
  489. if (!($aContentInfo = $oModuleProfiles->_oDb->getContentInfoById($iContentId)) || !($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)))
  490. return;
  491. $CNF = &$oModuleProfiles->_oConfig->CNF;
  492. if (!$oModuleProfiles->serviceActAsProfile() || !isset($CNF['FIELD_LABELS']) || empty($aContentInfo[$CNF['FIELD_ID']]))
  493. return;
  494. if (!($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) || !$oMetatags->keywordsIsEnabled() || !($aLabels = $oMetatags->keywordsGet($aContentInfo[$CNF['FIELD_ID']])))
  495. return;
  496. if (!($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
  497. return;
  498. foreach ($aLabels as $sLabel) {
  499. if (!($iContentIdChannel = $this->_oDb->getChannelIdByName($sLabel)))
  500. continue;
  501. if (!($oProfileChannel = BxDolProfile::getInstanceByContentAndType($iContentIdChannel, 'bx_channels')))
  502. continue;
  503. $oConn->addConnection($oProfile->id(), $oProfileChannel->id());
  504. }
  505. }
  506. /** Returns profile's subscribed channels React Jot
  507. *
  508. * @param int $iProfileId
  509. * @param array $aParams
  510. * @return array
  511. */
  512. public function serviceBrowseAuthorChannels($iProfileId = 0, $aParams = array())
  513. {
  514. $CNF = &$this->_oConfig->CNF;
  515. if(empty($iProfileId))
  516. $iProfileId = bx_get_logged_profile_id();
  517. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  518. $aProfile = $oConnection->getConnectedContent($iProfileId);
  519. $aVars = array();
  520. foreach ($aProfile as $iProfileId) {
  521. $oProfile = BxDolProfile::getInstance($iProfileId);
  522. if (!$oProfile || $oProfile->getModule() != $this->getName())
  523. continue;
  524. $iContentId = $oProfile->getContentId();
  525. $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
  526. if (isset($aContentInfo[$CNF['FIELD_NAME']]))
  527. array_push($aVars, array(
  528. 'title' => $aContentInfo[$CNF['FIELD_NAME']],
  529. 'link' => bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId)),
  530. 'followers' => $oConnection -> getConnectedInitiatorsCount($iProfileId),
  531. 'id' => $iProfileId,
  532. 'icon' => $oProfile -> getThumb()
  533. ));
  534. }
  535. return $aVars;
  536. }
  537. }
  538. /** @} */