BxCnlModule.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 checkAllowedSubscribeAdd (&$aDataEntry, $isPerformAction = false)
  21. {
  22. return parent::_checkAllowedSubscribeAdd ($aDataEntry, $isPerformAction);
  23. }
  24. function processHashtag($sHashtag, $sModuleName, $iContentId, $iAuthorId)
  25. {
  26. $mixedCnlId = $this->_oDb->getChannelIdByName($sHashtag);
  27. if (empty($mixedCnlId)){
  28. $CNF = &$this->_oConfig->CNF;
  29. $oAccountQuery = BxDolAccountQuery::getInstance();
  30. $aOperators = $oAccountQuery->getOperators();
  31. if(count($aOperators) > 0){
  32. $oProfile = BxDolProfile::getInstanceByAccount($aOperators[0]);
  33. $aContent = $this->serviceEntityAdd($oProfile->id(), array($CNF['FIELD_NAME'] => $sHashtag));
  34. if (isset($aContent['content']) && isset($aContent['content']['id']))
  35. $mixedCnlId = $aContent['content']['id'];
  36. }
  37. }
  38. if (!empty($mixedCnlId)){
  39. if (0 == (int) $this->_oDb->checkContentInChannel($iContentId, $mixedCnlId, $sModuleName, $iAuthorId)){
  40. $iId = $this->_oDb->addContentToChannel($iContentId, $mixedCnlId, $sModuleName, $iAuthorId);
  41. $oModule = BxDolModule::getInstance($sModuleName);
  42. if ($oModule){
  43. $aInfo = $oModule->_getContent($iContentId);
  44. if (is_array($aInfo)){
  45. $oDolProfileQuery = BxDolProfileQuery::getInstance();
  46. $iProfileInfo = $oDolProfileQuery->getProfileByContentAndType($mixedCnlId, $this->_aModule['name']);
  47. if(is_array($iProfileInfo)){
  48. $sPrivacyKey = 'allow_view_to';
  49. if ($sModuleName == 'bx_timeline'){
  50. $sPrivacyKey ='object_privacy_view';
  51. }
  52. bx_alert($this->_aModule['name'], 'hashtag_added', $iId, $iProfileInfo['id'], array('object_author_id' => $iAuthorId, 'privacy_view' => $aInfo[1][$sPrivacyKey]));
  53. bx_alert($this->_aModule['name'], 'hashtag_added_notif', $mixedCnlId, $iProfileInfo['id'], array('object_author_id' => $iAuthorId, 'privacy_view' => $aInfo[1][$sPrivacyKey], 'subobject_id' => $iId));
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. function removeContentFromChannel($iContentId, $sModuleName)
  61. {
  62. $oDolProfileQuery = BxDolProfileQuery::getInstance();
  63. $aData = $this->_oDb->getDataByContent($iContentId, $sModuleName);
  64. foreach ($aData as $aRow) {
  65. $iProfileInfo = $oDolProfileQuery->getProfileByContentAndType($aRow['cnl_id'], $this->_aModule['name']);
  66. if(is_array($iProfileInfo)){
  67. bx_alert($this->_aModule['name'], 'hashtag_deleted', $aRow['id'], $iProfileInfo['id']);
  68. bx_alert($this->_aModule['name'], 'hashtag_deleted_notif', $aRow['cnl_id'], $iProfileInfo['id'], array('subobject_id' => $aRow['id']));
  69. }
  70. }
  71. return $this->_oDb->removeContentFromChannel($iContentId, $sModuleName);
  72. }
  73. function serviceSearchResultByHashtag($iContentId = 0)
  74. {
  75. $CNF = &$this->_oConfig->CNF;
  76. $oSearch = new BxTemplSearch();
  77. $oSearch->setLiveSearch(0);
  78. $oSearch->setMetaType('keyword');
  79. $aContentInfo = $this->_oDb->getContentInfoById(bx_get('id'));
  80. $_GET['keyword'] = $aContentInfo[$CNF['FIELD_NAME']];
  81. $sCode = $oSearch->response();
  82. if (!$sCode)
  83. $sCode = $oSearch->getEmptyResult();
  84. return $sCode;
  85. }
  86. /**
  87. * Data for Timeline module
  88. */
  89. public function serviceGetTimelineData()
  90. {
  91. $sModule = $this->_aModule['name'];
  92. return array(
  93. 'handlers' => array(
  94. 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' => ''),
  95. array('group' => $sModule . '_hastag', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted')
  96. ),
  97. 'alerts' => array(
  98. array('unit' => $sModule, 'action' => 'hashtag_added'),
  99. array('unit' => $sModule, 'action' => 'hashtag_deleted')
  100. )
  101. );
  102. }
  103. public function serviceGetTimelinePostHashtag($aEvent, $aBrowseParams = array())
  104. {
  105. if(empty($aEvent) || !is_array($aEvent))
  106. return '';
  107. $aContentEvent = $this->_oDb->getContentById($aEvent['object_id']);
  108. if(empty($aContentEvent) || !is_array($aContentEvent))
  109. return '';
  110. $oModule = BxDolModule::getInstance($aContentEvent['module_name']);
  111. if ($oModule){
  112. $aTmp = $oModule->serviceGetTimelinePost(array('object_id' => $aContentEvent['content_id']));
  113. if ($aContentEvent['module_name'] == 'bx_timeline')
  114. $aTmp['owner_id'] = $aEvent['owner_id'];
  115. return $aTmp;
  116. }
  117. return '';
  118. }
  119. /**
  120. * Data for Notifications module
  121. */
  122. public function serviceGetNotificationsData()
  123. {
  124. $a = parent::serviceGetNotificationsData();
  125. $sModule = $this->_aModule['name'];
  126. $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');
  127. $a['handlers'][] = array('group' => $sModule . '_hastag_notif', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted_notif');
  128. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_added_notif');
  129. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_deleted_notif');
  130. return $a;
  131. }
  132. public function serviceGetNotificationsPostHashtag($aEvent)
  133. {
  134. if(empty($aEvent) || !is_array($aEvent))
  135. return '';
  136. $aContentEvent = $this->_oDb->getContentById($aEvent['subobject_id']);
  137. if(empty($aContentEvent) || !is_array($aContentEvent))
  138. return '';
  139. $oModule = BxDolModule::getInstance($aContentEvent['module_name']);
  140. if ($oModule){
  141. if (isset($oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW'])){
  142. $oPrivacy = BxDolPrivacy::getObjectInstance($oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  143. if (!$oPrivacy->check($aContentEvent['content_id']))
  144. return '';
  145. }
  146. $aRv = $oModule->serviceGetNotificationsPost(array('object_id' => $aContentEvent['content_id']));
  147. $aRv['lang_key'] = '_bx_channels_ntfs_txt_subobject_added';
  148. $aRv['channel_url'] = $this->serviceGetLink($aContentEvent['cnl_id']);
  149. return $aRv;
  150. }
  151. return '';
  152. }
  153. public function serviceBrowseMyChannels()
  154. {
  155. $iMyProfileId = bx_get_logged_profile_id();
  156. if ($iMyProfileId){
  157. $CNF = &$this->_oConfig->CNF;
  158. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  159. $aProfile = $oConnection->getConnectedContent($iMyProfileId);
  160. $aVars = array();
  161. foreach ($aProfile as $iProfileId) {
  162. $oProfile = BxDolProfile::getInstance($iProfileId);
  163. if ($oProfile){
  164. $iContentId = $oProfile->getContentId();
  165. $aContentInfo = $this->_oDb->getContentInfoById($oProfile->getContentId());
  166. if (isset($aContentInfo[$CNF['FIELD_NAME']]))
  167. array_push($aVars, array('title' => $aContentInfo[$CNF['FIELD_NAME']], 'link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $iContentId)));
  168. }
  169. }
  170. if (count($aVars) > 0){
  171. return $this->_oTemplate->parseHtmlByName('followers_list.html',
  172. array('bx_if:show_list' => array(
  173. 'condition' => count($aVars) > 0,
  174. 'content' => array('bx_repeat:items' => $aVars))
  175. ));
  176. }
  177. }
  178. }
  179. public function serviceDeleteProfileFromFansAndAdmins ($iProfileId)
  180. {
  181. return true;
  182. }
  183. public function followLabels($sModule, $iContentId)
  184. {
  185. if (!getParam('bx_channels_labels_autofollow'))
  186. return;
  187. if (!($oModuleProfiles = BxDolModule::getInstance($sModule)))
  188. return;
  189. if (!($aContentInfo = $oModuleProfiles->_oDb->getContentInfoById($iContentId)) || !($oProfile = BxDolProfile::getInstanceByContentAndType($iContentId, $sModule)))
  190. return;
  191. $CNF = &$oModuleProfiles->_oConfig->CNF;
  192. if (!$oModuleProfiles->serviceActAsProfile() || !isset($CNF['FIELD_LABELS']) || empty($aContentInfo[$CNF['FIELD_ID']]))
  193. return;
  194. if (!($oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS'])) || !$oMetatags->keywordsIsEnabled() || !($aLabels = $oMetatags->keywordsGet($aContentInfo[$CNF['FIELD_ID']])))
  195. return;
  196. if (!($oConn = BxDolConnection::getObjectInstance('sys_profiles_subscriptions')))
  197. return;
  198. foreach ($aLabels as $sLabel) {
  199. if (!($iContentIdChannel = $this->_oDb->getChannelIdByName($sLabel)))
  200. continue;
  201. if (!($oProfileChannel = BxDolProfile::getInstanceByContentAndType($iContentIdChannel, 'bx_channels')))
  202. continue;
  203. $oConn->addConnection($oProfile->id(), $oProfileChannel->id());
  204. }
  205. }
  206. }
  207. /** @} */