BxTimelineCronHot.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineCronHot extends BxDolCron
  12. {
  13. protected $_sModule;
  14. protected $_oModule;
  15. public function __construct()
  16. {
  17. $this->_sModule = 'bx_timeline';
  18. $this->_oModule = BxDolModule::getInstance($this->_sModule);
  19. parent::__construct();
  20. }
  21. function processing()
  22. {
  23. if(!$this->_oModule->_oConfig->isHot())
  24. return;
  25. $this->_oModule->_oDb->clearHot();
  26. $this->_prepareTrackByDates();
  27. }
  28. protected function _prepareTrackByDates()
  29. {
  30. $iInterval = $this->_oModule->_oConfig->getHotInterval();
  31. $sCommon = $this->_oModule->_oConfig->getPrefix('common_post') . 'post';
  32. $aSystemsComments = BxDolCmts::getSystems();
  33. $aSystemsVotes = BxDolVote::getSystems();
  34. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  35. $aModulesActive = [];
  36. foreach($aModules as $aModule)
  37. $aModulesActive[] = $aModule['name'];
  38. $aTracksByDate = [];
  39. $aTracksByDateComments = [];
  40. $aTracksByDateVotes = [];
  41. if($this->_oModule->_oConfig->isHotSource(BX_TIMELINE_HFS_CONTENT))
  42. $aTracksByDate = $this->_oModule->_oDb->getHotTrackByDate($iInterval);
  43. $bHfsComment = $this->_oModule->_oConfig->isHotSource(BX_TIMELINE_HFS_COMMENT);
  44. $bHfsVote = $this->_oModule->_oConfig->isHotSource(BX_TIMELINE_HFS_VOTE);
  45. $iHftContent = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_CONTENT);
  46. $iHftComments = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_COMMENT);
  47. $iHftVotes = $this->_oModule->_oConfig->getHotThreshold(BX_TIMELINE_HFS_VOTE);
  48. $aHandlers = $this->_oModule->_oConfig->getHandlers();
  49. $aHandlersHidden = $this->_oModule->_oConfig->getHandlersHidden();
  50. foreach($aHandlers as $sKey => $aHandler) {
  51. if($aHandler['type'] != BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT || in_array($aHandler['id'], $aHandlersHidden))
  52. continue;
  53. $bSystem = $this->_oModule->_oConfig->isSystem($aHandler['alert_unit'], $aHandler['alert_action']);
  54. if($bSystem && !in_array($aHandler['alert_unit'], $aModulesActive))
  55. continue;
  56. if($bSystem) {
  57. $sModule = $aHandler['alert_unit'];
  58. $oModule = BxDolModule::getInstance($sModule);
  59. if(!$oModule)
  60. continue;
  61. if($bHfsComment && !empty($oModule->_oConfig->CNF['OBJECT_COMMENTS'])) {
  62. $sSystem = $oModule->_oConfig->CNF['OBJECT_COMMENTS'];
  63. if(isset($aSystemsComments[$sSystem]) && (int)$aSystemsComments[$sSystem]['is_on'] == 1)
  64. $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDateModule($sModule, $aSystemsComments[$sSystem]['table'], $iInterval, $iHftContent, $iHftComments);
  65. }
  66. if($bHfsVote) {
  67. if(!empty($oModule->_oConfig->CNF['OBJECT_VOTES'])) {
  68. $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
  69. if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
  70. $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
  71. }
  72. if(!empty($oModule->_oConfig->CNF['OBJECT_REACTIONS'])) {
  73. $sSystem = $oModule->_oConfig->CNF['OBJECT_REACTIONS'];
  74. if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
  75. $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDateModule($sModule, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
  76. }
  77. }
  78. }
  79. else {
  80. if($bHfsComment) {
  81. $sSystem = $this->_oModule->_oConfig->getObject('comment');
  82. if(isset($aSystemsComments[$sSystem]) && (int)$aSystemsComments[$sSystem]['is_on'] == 1)
  83. $aTracksByDateComments += $this->_oModule->_oDb->getHotTrackByCommentsDate($sCommon, $aSystemsComments[$sSystem]['table'], $iInterval, $iHftContent, $iHftComments);
  84. }
  85. if($bHfsVote) {
  86. $sSystem = $this->_oModule->_oConfig->getObject('vote');
  87. if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
  88. $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
  89. $sSystem = $this->_oModule->_oConfig->getObject('reaction');
  90. if(isset($aSystemsVotes[$sSystem]) && (int)$aSystemsVotes[$sSystem]['is_on'] == 1)
  91. $aTracksByDateVotes += $this->_oModule->_oDb->getHotTrackByVotesDate($sCommon, $aSystemsVotes[$sSystem]['table_track'], $iInterval, $iHftContent, $iHftVotes);
  92. }
  93. }
  94. }
  95. $aTracks = [];
  96. $aTracks = $this->_combineArrays($aTracks, $aTracksByDate);
  97. $aTracks = $this->_combineArrays($aTracks, $aTracksByDateComments);
  98. $aTracks = $this->_combineArrays($aTracks, $aTracksByDateVotes);
  99. /*
  100. * Currently $iValue contains event creation date.
  101. */
  102. foreach($aTracks as $iEventId => $iValue)
  103. $this->_oModule->_oDb->updateHotTrack($iEventId, $iValue);
  104. }
  105. /**
  106. * Hot Track by Sum of Votes during specified Period is currently disabled.
  107. */
  108. protected function _prepareTrackByVotesSum()
  109. {
  110. $iInterval = $this->_oModule->_oConfig->getHotInterval();
  111. $sCommon = $this->_oModule->_oConfig->getPrefix('common_post') . 'post';
  112. $aSystems = BxDolVote::getSystems();
  113. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  114. $aModulesActive = array();
  115. foreach($aModules as $aModule)
  116. $aModulesActive[] = $aModule['name'];
  117. $aHandlers = $this->_oModule->_oConfig->getHandlers();
  118. $aHandlersHidden = $this->_oModule->_oConfig->getHandlersHidden();
  119. foreach($aHandlers as $sKey => $aHandler) {
  120. if($aHandler['type'] != BX_BASE_MOD_NTFS_HANDLER_TYPE_INSERT || in_array($aHandler['id'], $aHandlersHidden))
  121. continue;
  122. $bCommon = $aHandler['alert_unit'] == $sCommon;
  123. if(!$bCommon && !in_array($aHandler['alert_unit'], $aModulesActive))
  124. continue;
  125. if(!$bCommon) {
  126. $oModule = BxDolModule::getInstance($aHandler['alert_unit']);
  127. if(empty($oModule->_oConfig->CNF['OBJECT_VOTES']))
  128. continue;
  129. $sMethod = 'getHotTrackByVotesSumModule';
  130. $sModule = $oModule->getName();
  131. $sSystem = $oModule->_oConfig->CNF['OBJECT_VOTES'];
  132. }
  133. else {
  134. $sMethod = 'getHotTrackByVotesSum';
  135. $sModule = $sCommon;
  136. $sSystem = $this->_oModule->_oConfig->getObject('vote');
  137. }
  138. if(!isset($aSystems[$sSystem]) || (int)$aSystems[$sSystem]['is_on'] != 1)
  139. continue;
  140. $aTracks = $this->_oModule->_oDb->$sMethod($sModule, $aSystems[$sSystem]['table_track'], $iInterval);
  141. if(empty($aTracks) || !is_array($aTracks))
  142. continue;
  143. foreach($aTracks as $aTrack)
  144. $this->_oModule->_oDb->updateHotTrack($aTrack);
  145. }
  146. }
  147. protected function _combineArrays($a1, $a2)
  148. {
  149. foreach($a2 as $iId => $iDate) {
  150. if(!isset($a1[$iId])) {
  151. $a1[$iId] = $iDate;
  152. continue;
  153. }
  154. if((int)$iDate > (int)$a1[$iId])
  155. $a1[$iId] = $iDate;
  156. }
  157. return $a1;
  158. }
  159. }
  160. /** @} */