BxCnlModule.php 26 KB

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