BxCnlModule.php 26 KB

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