1
0

BxBaseModTextSearchResult.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModTextSearchResult extends BxBaseModGeneralSearchResult
  12. {
  13. protected $sUnitViewParamName = 'unit_view';
  14. function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->aUnitViews = array('extended' => 'unit.html', 'gallery' => 'unit_gallery.html', 'full' => 'unit_full.html', 'showcase' => 'unit_showcase.html');
  18. if (!empty($aParams['unit_views']))
  19. $this->aUnitViews = $aParams['unit_views'];
  20. if (!empty($aParams['unit_view']))
  21. $this->sUnitViewDefault = $aParams['unit_view'];
  22. $this->aGetParams = array($this->sUnitViewParamName);
  23. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  24. if (isset($this->aUnitViews[bx_get($this->sUnitViewParamName)]))
  25. $this->sUnitTemplate = $this->aUnitViews[bx_get($this->sUnitViewParamName)];
  26. $this->addContainerClass ('bx-def-margin-bottom-neg');
  27. if ('unit_gallery.html' == $this->sUnitTemplate){
  28. $this->removeContainerClass ('bx-def-margin-bottom-neg');
  29. $this->addContainerClass (array('bx-def-margin-sec-lefttopright-neg', 'bx-base-text-unit-gallery-wrapper bx-def-margin-sec-bottom-neg'));
  30. }
  31. if ('unit_showcase.html' == $this->sUnitTemplate){
  32. $this->bShowcaseView = true;
  33. }
  34. }
  35. function getAlterOrder()
  36. {
  37. $CNF = &$this->oModule->_oConfig->CNF;
  38. $sTable = $this->aCurrent['table'];
  39. $aSql = array();
  40. switch ($this->aCurrent['sorting']) {
  41. case 'last':
  42. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_ADDED'] . '` DESC';
  43. break;
  44. case 'updated':
  45. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_CHANGED'] . '` DESC';
  46. break;
  47. case 'featured':
  48. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`featured` DESC';
  49. break;
  50. case 'popular':
  51. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_VIEWS'] . '` DESC';
  52. break;
  53. case 'top':
  54. $aSql['order'] = '';
  55. $aPartsUp = $aPartsDown = array(0);
  56. if(!empty($CNF['OBJECT_VOTES']) && ($oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], 0, false)) !== false && $oVote->isEnabled()) {
  57. $aVote = $oVote->getSystemInfo();
  58. if(!empty($aVote['trigger_table']) && !empty($aVote['trigger_field_count']))
  59. $aPartsUp[] = '`' . $aVote['trigger_table'] . '`.`' . $aVote['trigger_field_count'] . '`';
  60. }
  61. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], 0, false)) !== false && $oReaction->isEnabled()) {
  62. $aReaction = $oReaction->getSystemInfo();
  63. if(!empty($aReaction['trigger_table']) && !empty($aReaction['trigger_field_count']))
  64. $aPartsUp[] = '`' . $aReaction['trigger_table'] . '`.`' . $aReaction['trigger_field_count'] . '`';
  65. }
  66. if(!empty($CNF['OBJECT_SCORES']) && ($oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], 0, false)) !== false && $oScore->isEnabled()) {
  67. $aScore = $oScore->getSystemInfo();
  68. if(!empty($aScore['trigger_table']) && !empty($aScore['trigger_field_cup']) && !empty($aScore['trigger_field_cdown'])) {
  69. $aPartsUp[] = '`' . $aScore['trigger_table'] . '`.`' . $aScore['trigger_field_cup'] . '`';
  70. $aPartsDown[] = '`' . $aScore['trigger_table'] . '`.`' . $aScore['trigger_field_cdown'] . '`';
  71. }
  72. }
  73. if(empty($aPartsUp) && empty($aPartsDown))
  74. break;
  75. $aSql['order'] = ' ORDER BY ' . pow(10, 8) . ' * ((' . implode(' + ', $aPartsUp) . ') - (' . implode(' + ', $aPartsDown) . ')) / (UNIX_TIMESTAMP() - `' . $sTable . '`.`' . $CNF['FIELD_ADDED'] . '`) DESC';
  76. break;
  77. }
  78. return $aSql;
  79. }
  80. function getRssUnitImage (&$a, $sField)
  81. {
  82. $CNF = &$this->oModule->_oConfig->CNF;
  83. if(empty($sField) || empty($a[$sField]) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  84. return '';
  85. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  86. if(!$oTranscoder)
  87. return '';
  88. return $oTranscoder->getFileUrl($a[$sField]);
  89. }
  90. protected function processReplaceableMarkers($oProfileAuthor)
  91. {
  92. if ($oProfileAuthor) {
  93. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replaceable
  94. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replaceable
  95. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replaceable
  96. }
  97. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  98. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  99. }
  100. protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
  101. {
  102. // always add UnitView as additional param
  103. $sUnitView = bx_process_input(bx_get($this->sUnitViewParamName));
  104. if ($sUnitView && isset($this->aUnitViews[$sUnitView]))
  105. $aAdditionalParams = array_merge(array($this->sUnitViewParamName => $sUnitView), $aAdditionalParams);
  106. return parent::getCurrentOnclick($aAdditionalParams, $bReplacePagesParams);
  107. }
  108. protected function _updateCurrentForAuthor($sMode, $aParams, &$oProfileAuthor)
  109. {
  110. $CNF = &$this->oModule->_oConfig->CNF;
  111. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  112. if (!$oProfileAuthor)
  113. return false;
  114. $iProfileAuthor = $oProfileAuthor->id();
  115. if (bx_get_logged_profile_id() == $iProfileAuthor || $this->oModule->_isModerator()) {
  116. // for real owner and for moderators show anonymous posts
  117. $this->aCurrent['restriction']['author']['operator'] = 'in';
  118. $this->aCurrent['restriction']['author']['value'] = array($iProfileAuthor, -$iProfileAuthor);
  119. }
  120. else {
  121. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  122. }
  123. if(!empty($aParams['except']))
  124. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  125. if(!empty($aParams['per_page']))
  126. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  127. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  128. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  129. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  130. return true;
  131. }
  132. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  133. {
  134. $CNF = &$this->oModule->_oConfig->CNF;
  135. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  136. if (!$oProfileContext)
  137. return false;
  138. $iProfileIdContext = $oProfileContext->id();
  139. $this->aCurrent['restriction']['context'] = array(
  140. 'value' => -$iProfileIdContext,
  141. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  142. 'operator' => '=',
  143. );
  144. if(!empty($aParams['per_page']))
  145. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  146. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  147. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  148. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  149. return true;
  150. }
  151. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  152. {
  153. $CNF = &$this->oModule->_oConfig->CNF;
  154. $sSystem = '';
  155. $iListId = 0;
  156. if(!empty($aParams['system'])) {
  157. $sSystem = $aParams['system'];
  158. unset($aParams['system']);
  159. }
  160. if(!empty($aParams['list_id'])) {
  161. $iListId = $aParams['list_id'];
  162. unset($aParams['list_id']);
  163. }
  164. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  165. if(!$oProfileAuthor)
  166. return false;
  167. $iProfileAuthor = $oProfileAuthor->id();
  168. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  169. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  170. return false;
  171. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor, $iListId);
  172. if(!empty($aConditions) && is_array($aConditions)) {
  173. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  174. $this->aCurrent['restriction'] = array();
  175. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  176. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  177. $this->aCurrent['join'] = array();
  178. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  179. }
  180. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  181. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  182. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  183. return true;
  184. }
  185. function _getPseud ()
  186. {
  187. return array(
  188. 'id' => 'id',
  189. 'title' => 'title',
  190. 'text' => 'text',
  191. 'added' => 'added',
  192. 'author' => 'author',
  193. 'photo' => 'photo',
  194. );
  195. }
  196. }
  197. /** @} */