1
0

BxBaseCmtsServices.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System services related to Comments.
  11. */
  12. class BxBaseCmtsServices extends BxDol
  13. {
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceGetBlockView($sSystem = '', $iObjectId = 0, $iCommentId = 0)
  19. {
  20. if(empty($sSystem) && ($sSystem = bx_get('sys')) !== false)
  21. $sSystem = bx_process_input($sSystem);
  22. if(empty($iObjectId) && ($iObjectId = bx_get('id')) !== false)
  23. $iObjectId = bx_process_input($iObjectId, BX_DATA_INT);
  24. if(empty($iCommentId) && ($iCommentId = bx_get('cmt_id')) !== false)
  25. $iCommentId = bx_process_input($iCommentId, BX_DATA_INT);
  26. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iObjectId, true);
  27. if(!$oCmts)
  28. return '';
  29. return $oCmts->getCommentBlock($iCommentId);
  30. }
  31. public function serviceAlertResponseSysCmtsImagesFileDeleted($oAlert)
  32. {
  33. $iUniqId = (int)$oAlert->aExtras['ghost']['content_id'];
  34. $aCmt = BxDolCmts::getGlobalInfo($iUniqId);
  35. if(empty($aCmt) || !is_array($aCmt))
  36. return;
  37. $oCmts = BxDolCmts::getObjectInstance($aCmt['system_name'], 0, false);
  38. if(!$oCmts)
  39. return;
  40. $oCmts->getQueryObject()->deleteImages($aCmt['system_id'], false, $oAlert->iObject);
  41. }
  42. public function serviceGetMenuItemAddonVote($sSystem, $iId, $iCmtId)
  43. {
  44. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId);
  45. $oVote = $oCmts->getVoteObject($iCmtId);
  46. if($oVote !== false)
  47. return $oVote->getCounter();
  48. return '';
  49. }
  50. public function serviceGetLiveUpdate($sSystem, $iContentId, $iProfileId, $iCount = 0)
  51. {
  52. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  53. if(!$oCmts || !$oCmts->isEnabled())
  54. return false;
  55. $sKey = $oCmts->getNotificationId();
  56. bx_import('BxDolSession');
  57. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  58. return false;
  59. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  60. if($iCountNew == $iCount)
  61. return false;
  62. return array(
  63. 'count' => $iCountNew, // required
  64. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdate(oData)', // required
  65. 'data' => array(
  66. 'code' => $oCmts->getLiveUpdate($iCount, $iCountNew)
  67. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  68. );
  69. }
  70. public function serviceGetLiveUpdates($sSystem, $iContentId, $iProfileId, $iCount = 0)
  71. {
  72. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iContentId);
  73. if(!$oCmts || !$oCmts->isEnabled())
  74. return false;
  75. $sKey = $oCmts->getNotificationId();
  76. bx_import('BxDolSession');
  77. if((int)BxDolSession::getInstance()->getValue($sKey) == 1)
  78. return false;
  79. $iCountNew = $oCmts->getCommentsCount($iContentId, -1, BX_CMT_FILTER_OTHERS);
  80. if($iCountNew == $iCount)
  81. return false;
  82. return array(
  83. 'count' => $iCountNew, // required
  84. 'method' => $oCmts->getJsObjectName() . '.showLiveUpdates(oData)', // required
  85. 'data' => array(
  86. 'code' => $oCmts->getLiveUpdates($iCount, $iCountNew)
  87. ), // optional, may have some additional data to be passed in JS method provided using 'method' param above.
  88. );
  89. }
  90. public function serviceManageTools($sType = 'common')
  91. {
  92. $oGrid = BxDolGrid::getObjectInstance('sys_cmts_administration');
  93. if(!$oGrid)
  94. return '';
  95. $oTemplate = BxDolTemplate::getInstance();
  96. $oTemplate->addJs(array('BxDolCmtsManageTools.js'));
  97. $oTemplate->addCss(array('cmts_manage_tools.css'));
  98. $oTemplate->addJsTranslation(array('_sys_grid_search'));
  99. return array(
  100. 'content' => $oGrid->getCode()
  101. );
  102. }
  103. /**
  104. * Comment vote for Notifications module
  105. */
  106. public function serviceGetNotificationsVote($aEvent)
  107. {
  108. $iCmtIdUnique = (int)$aEvent['object_id'];
  109. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  110. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  111. return array();
  112. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  113. if(!$oCmts || !$oCmts->isEnabled())
  114. return array();
  115. $oVote = $oCmts->getVoteObject($iCmtIdUnique);
  116. if(!$oVote)
  117. return array();
  118. $iCmtId = (int)$aCmtInfo['cmt_id'];
  119. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  120. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  121. return array(
  122. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  123. 'entry_url' => $sCmtUrl,
  124. 'entry_caption' => $sCmtCaption,
  125. 'entry_author' => $aCmtInfo['author_id'],
  126. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_vote_single'),
  127. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  128. );
  129. }
  130. /**
  131. * Comment reaction for Notifications module
  132. */
  133. public function serviceGetNotificationsReaction($aEvent)
  134. {
  135. $iCmtIdUnique = (int)$aEvent['object_id'];
  136. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  137. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  138. return array();
  139. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  140. if(!$oCmts || !$oCmts->isEnabled())
  141. return array();
  142. $oReaction = $oCmts->getReactionObject($iCmtIdUnique);
  143. if(!$oReaction)
  144. return array();
  145. $aSubentry = $oReaction->getTrackBy(array('type' => 'id', 'id' => (int)$aEvent['subobject_id']));
  146. if(empty($aSubentry) || !is_array($aSubentry))
  147. return array();
  148. $aSubentrySampleParams = array();
  149. $aReaction = $oReaction->getReaction($aSubentry['reaction']);
  150. if(!empty($aReaction['title']))
  151. $aSubentrySampleParams[] = $aReaction['title'];
  152. else
  153. $aSubentrySampleParams[] = '_undefined';
  154. $iCmtId = (int)$aCmtInfo['cmt_id'];
  155. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  156. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  157. return array(
  158. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  159. 'entry_url' => $sCmtUrl,
  160. 'entry_caption' => $sCmtCaption,
  161. 'entry_author' => $aCmtInfo['author_id'],
  162. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_reaction_single'),
  163. 'subentry_sample_params' => $aSubentrySampleParams,
  164. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  165. );
  166. }
  167. /**
  168. * Comment score -> vote up for Notifications module
  169. */
  170. public function serviceGetNotificationsScoreUp($aEvent)
  171. {
  172. return $this->_serviceGetNotificationsScore('up', $aEvent);
  173. }
  174. /**
  175. * Comment score -> vote down for Notifications module
  176. */
  177. public function serviceGetNotificationsScoreDown($aEvent)
  178. {
  179. return $this->_serviceGetNotificationsScore('down', $aEvent);
  180. }
  181. protected function _serviceGetNotificationsScore($sType, $aEvent)
  182. {
  183. $iCmtIdUnique = (int)$aEvent['object_id'];
  184. $aCmtInfo = BxDolCmts::getGlobalInfo($iCmtIdUnique);
  185. if(empty($aCmtInfo) || !is_array($aCmtInfo))
  186. return array();
  187. $oCmts = BxDolCmts::getObjectInstance($aCmtInfo['system_name'], 0, false);
  188. if(!$oCmts || !$oCmts->isEnabled())
  189. return array();
  190. $oScore = $oCmts->getScoreObject($iCmtIdUnique);
  191. if(!$oScore)
  192. return array();
  193. $iCmtId = (int)$aCmtInfo['cmt_id'];
  194. $sCmtUrl = $oCmts->serviceGetLink($iCmtId);
  195. $sCmtCaption = strmaxtextlen($oCmts->serviceGetText($iCmtId), 20, '...');
  196. return array(
  197. 'entry_sample' => $oCmts->getLanguageKey('txt_sample_single'),
  198. 'entry_url' => $sCmtUrl,
  199. 'entry_caption' => $sCmtCaption,
  200. 'entry_author' => $aCmtInfo['author_id'],
  201. 'subentry_sample' => $oCmts->getLanguageKey('txt_sample_score_' . $sType . '_single'),
  202. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  203. );
  204. }
  205. }
  206. /** @} */