BxCnlModule.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. $aInfo = $oModule->_getContent($iContentId);
  43. if (is_array($aInfo)){
  44. $oDolProfileQuery = BxDolProfileQuery::getInstance();
  45. $iProfileInfo = $oDolProfileQuery->getProfileByContentAndType($mixedCnlId, $this->_aModule['name']);
  46. if(is_array($iProfileInfo)){
  47. bx_alert($this->_aModule['name'], 'hashtag_added', $iId, $iProfileInfo['id'], array('object_author_id' => $iAuthorId, 'privacy_view' => $aInfo[1]['allow_view_to']));
  48. bx_alert($this->_aModule['name'], 'hashtag_added_notif', $mixedCnlId, $iProfileInfo['id'], array('object_author_id' => $iAuthorId, 'privacy_view' => $aInfo[1]['allow_view_to'], 'subobject_id' => $iId));
  49. }
  50. }
  51. }
  52. }
  53. }
  54. function removeContentFromChannel($iContentId, $sModuleName)
  55. {
  56. $oDolProfileQuery = BxDolProfileQuery::getInstance();
  57. $aData = $this->_oDb->getDataByContent($iContentId, $sModuleName);
  58. foreach ($aData as $aRow) {
  59. $iProfileInfo = $oDolProfileQuery->getProfileByContentAndType($aRow['cnl_id'], $this->_aModule['name']);
  60. if(is_array($iProfileInfo)){
  61. bx_alert($this->_aModule['name'], 'hashtag_deleted', $aRow['id'], $iProfileInfo['id']);
  62. bx_alert($this->_aModule['name'], 'hashtag_deleted_notif', $aRow['cnl_id'], $iProfileInfo['id'], array('subobject_id' => $aRow['id']));
  63. }
  64. }
  65. return $this->_oDb->removeContentFromChannel($iContentId, $sModuleName);
  66. }
  67. function serviceSearchResultByHashtag($iContentId = 0)
  68. {
  69. $CNF = &$this->_oConfig->CNF;
  70. $oSearch = new BxTemplSearch();
  71. $oSearch->setLiveSearch(0);
  72. $oSearch->setMetaType('keyword');
  73. $aContentInfo = $this->_oDb->getContentInfoById(bx_get('id'));
  74. $_GET['keyword'] = $aContentInfo[$CNF['FIELD_NAME']];
  75. $sCode = '';
  76. $sCode = $oSearch->response();
  77. if (!$sCode)
  78. $sCode = $oSearch->getEmptyResult();
  79. return $sCode;
  80. }
  81. /**
  82. * Data for Timeline module
  83. */
  84. public function serviceGetTimelineData()
  85. {
  86. $sModule = $this->_aModule['name'];
  87. return array(
  88. 'handlers' => array(
  89. 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' => ''),
  90. array('group' => $sModule . '_hastag', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted')
  91. ),
  92. 'alerts' => array(
  93. array('unit' => $sModule, 'action' => 'hashtag_added'),
  94. array('unit' => $sModule, 'action' => 'hashtag_deleted')
  95. )
  96. );
  97. }
  98. public function serviceGetTimelinePostHashtag($aEvent, $aBrowseParams = array())
  99. {
  100. if(empty($aEvent) || !is_array($aEvent))
  101. return '';
  102. $aContentEvent = $this->_oDb->getContentById($aEvent['object_id']);
  103. if(empty($aContentEvent) || !is_array($aContentEvent))
  104. return '';
  105. $oModule = BxDolModule::getInstance($aContentEvent['module_name']);
  106. if ($oModule){
  107. return $oModule->serviceGetTimelinePost(array('object_id' => $aContentEvent['content_id']));
  108. }
  109. return '';
  110. }
  111. /**
  112. * Data for Notifications module
  113. */
  114. public function serviceGetNotificationsData()
  115. {
  116. $a = parent::serviceGetNotificationsData();
  117. $sModule = $this->_aModule['name'];
  118. $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');
  119. $a['handlers'][] = array('group' => $sModule . '_hastag_notif', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'hashtag_deleted_notif');
  120. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_added_notif');
  121. $a['alerts'][] = array('unit' => $sModule, 'action' => 'hashtag_deleted_notif');
  122. return $a;
  123. }
  124. public function serviceGetNotificationsPostHashtag($aEvent)
  125. {
  126. if(empty($aEvent) || !is_array($aEvent))
  127. return '';
  128. $aContentEvent = $this->_oDb->getContentById($aEvent['subobject_id']);
  129. if(empty($aContentEvent) || !is_array($aContentEvent))
  130. return '';
  131. $oModule = BxDolModule::getInstance($aContentEvent['module_name']);
  132. if ($oModule){
  133. $oPrivacy = BxDolPrivacy::getObjectInstance($oModule->_oConfig->CNF['OBJECT_PRIVACY_VIEW']);
  134. if (!$oPrivacy->check($aContentEvent['content_id']))
  135. return '';
  136. $aRv = $oModule->serviceGetNotificationsPost(array('object_id' => $aContentEvent['content_id']));
  137. $aRv['lang_key'] = '_bx_channels_ntfs_txt_subobject_added';
  138. $aRv['channel_url'] = $this->serviceGetLink($aContentEvent['cnl_id']);
  139. return $aRv;
  140. }
  141. return '';
  142. }
  143. }
  144. /** @} */