BxBaseModTextSearchResult.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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-base-text-unit-gallery-wrapper', 'bx-def-margin-sec-neg'));
  30. }
  31. if ('unit_showcase.html' == $this->sUnitTemplate){
  32. $this->bShowcaseView = true;
  33. }
  34. }
  35. protected function checkRestrictionsForContext($sMode, $aParams, $oProfileAuthor){
  36. if(bx_get('context_id')){
  37. $aParams['context'] = bx_get('context_id');
  38. $oProfileAuthor = null;
  39. $this->_updateCurrentForContext($sMode, $aParams, $oProfileAuthor);
  40. }
  41. }
  42. function getAlterOrder()
  43. {
  44. $CNF = &$this->oModule->_oConfig->CNF;
  45. $sTable = $this->aCurrent['table'];
  46. $aSql = array();
  47. switch ($this->aCurrent['sorting']) {
  48. case 'last':
  49. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_ADDED'] . '` DESC';
  50. break;
  51. case 'updated':
  52. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_CHANGED'] . '` DESC';
  53. break;
  54. case 'featured':
  55. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`featured` DESC';
  56. break;
  57. case 'popular':
  58. $aSql['order'] = ' ORDER BY `' . $sTable . '`.`' . $CNF['FIELD_VIEWS'] . '` DESC';
  59. break;
  60. case 'top':
  61. $aSql['order'] = '';
  62. $aPartsUp = $aPartsDown = array(0);
  63. if(!empty($CNF['OBJECT_VOTES']) && ($oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], 0, false)) !== false && $oVote->isEnabled()) {
  64. $aVote = $oVote->getSystemInfo();
  65. if(!empty($aVote['trigger_table']) && !empty($aVote['trigger_field_count']))
  66. $aPartsUp[] = '`' . $aVote['trigger_table'] . '`.`' . $aVote['trigger_field_count'] . '`';
  67. }
  68. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReaction = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], 0, false)) !== false && $oReaction->isEnabled()) {
  69. $aReaction = $oReaction->getSystemInfo();
  70. if(!empty($aReaction['trigger_table']) && !empty($aReaction['trigger_field_count']))
  71. $aPartsUp[] = '`' . $aReaction['trigger_table'] . '`.`' . $aReaction['trigger_field_count'] . '`';
  72. }
  73. if(!empty($CNF['OBJECT_SCORES']) && ($oScore = BxDolScore::getObjectInstance($CNF['OBJECT_SCORES'], 0, false)) !== false && $oScore->isEnabled()) {
  74. $aScore = $oScore->getSystemInfo();
  75. if(!empty($aScore['trigger_table']) && !empty($aScore['trigger_field_cup']) && !empty($aScore['trigger_field_cdown'])) {
  76. $aPartsUp[] = '`' . $aScore['trigger_table'] . '`.`' . $aScore['trigger_field_cup'] . '`';
  77. $aPartsDown[] = '`' . $aScore['trigger_table'] . '`.`' . $aScore['trigger_field_cdown'] . '`';
  78. }
  79. }
  80. if(empty($aPartsUp) && empty($aPartsDown))
  81. break;
  82. $aSql['order'] = ' ORDER BY ' . pow(10, 8) . ' * ((' . implode(' + ', $aPartsUp) . ') - (' . implode(' + ', $aPartsDown) . ')) / (UNIX_TIMESTAMP() - `' . $sTable . '`.`' . $CNF['FIELD_ADDED'] . '`) DESC';
  83. break;
  84. }
  85. return $aSql;
  86. }
  87. function getRssUnitImage (&$a, $sField)
  88. {
  89. $CNF = &$this->oModule->_oConfig->CNF;
  90. if(empty($sField) || empty($a[$sField]) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  91. return '';
  92. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  93. if(!$oTranscoder)
  94. return '';
  95. return $oTranscoder->getFileUrl($a[$sField]);
  96. }
  97. protected function processReplaceableMarkers($oProfileAuthor)
  98. {
  99. if ($oProfileAuthor) {
  100. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replaceable
  101. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replaceable
  102. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replaceable
  103. }
  104. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  105. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  106. }
  107. protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
  108. {
  109. // always add UnitView as additional param
  110. $sUnitView = bx_process_input(bx_get($this->sUnitViewParamName));
  111. if ($sUnitView && isset($this->aUnitViews[$sUnitView]))
  112. $aAdditionalParams = array_merge(array($this->sUnitViewParamName => $sUnitView), $aAdditionalParams);
  113. return parent::getCurrentOnclick($aAdditionalParams, $bReplacePagesParams);
  114. }
  115. protected function _updateCurrentForAuthor($sMode, $aParams, &$oProfileAuthor)
  116. {
  117. $CNF = &$this->oModule->_oConfig->CNF;
  118. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  119. if (!$oProfileAuthor)
  120. return false;
  121. $iProfileAuthor = $oProfileAuthor->id();
  122. if (bx_get_logged_profile_id() == $iProfileAuthor || $this->oModule->_isModerator()) {
  123. // for real owner and for moderators show anonymous posts
  124. $this->aCurrent['restriction']['author']['operator'] = 'in';
  125. $this->aCurrent['restriction']['author']['value'] = array($iProfileAuthor, -$iProfileAuthor);
  126. }
  127. else {
  128. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  129. }
  130. if(!empty($aParams['except']))
  131. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  132. if(!empty($aParams['per_page']))
  133. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  134. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  135. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  136. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  137. return true;
  138. }
  139. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  140. {
  141. $CNF = &$this->oModule->_oConfig->CNF;
  142. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  143. if (!$oProfileContext)
  144. return false;
  145. $iProfileIdContext = $oProfileContext->id();
  146. $this->aCurrent['restriction']['context'] = array(
  147. 'value' => -$iProfileIdContext,
  148. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  149. 'operator' => '=',
  150. );
  151. if(!empty($aParams['per_page']))
  152. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  153. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  154. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  155. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  156. return true;
  157. }
  158. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  159. {
  160. $CNF = &$this->oModule->_oConfig->CNF;
  161. $sSystem = '';
  162. $iListId = 0;
  163. if(!empty($aParams['system'])) {
  164. $sSystem = $aParams['system'];
  165. unset($aParams['system']);
  166. }
  167. if(!empty($aParams['list_id'])) {
  168. $iListId = $aParams['list_id'];
  169. unset($aParams['list_id']);
  170. }
  171. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  172. if(!$oProfileAuthor)
  173. return false;
  174. $iProfileAuthor = $oProfileAuthor->id();
  175. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  176. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  177. return false;
  178. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor, $iListId);
  179. if(!empty($aConditions) && is_array($aConditions)) {
  180. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  181. $this->aCurrent['restriction'] = array();
  182. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  183. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  184. $this->aCurrent['join'] = array();
  185. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  186. }
  187. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  188. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  189. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  190. return true;
  191. }
  192. function decodeData ($a)
  193. {
  194. $CNF = &$this->oModule->_oConfig->CNF;
  195. $bMetaMenu = false;
  196. /**
  197. * Disabled for now, because Author is used only.
  198. $oMetaMenu = !empty($CNF['OBJECT_MENU_SNIPPET_META']) ? BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->oModule->_oTemplate) : false;
  199. $bMetaMenu = $oMetaMenu !== false;
  200. */
  201. $oContentInfo = $this->getContentInfoObject();
  202. foreach ($a as $i => $r) {
  203. $a[$i] = array_merge($a[$i], [
  204. 'author_data' => isset($r['author']) ? BxDolProfile::getData($r[$CNF['FIELD_AUTHOR']]) : '',
  205. 'url' => $this->decodeDataUrl($oContentInfo, $r),
  206. 'image' => $oContentInfo->getContentThumb($r['id']),
  207. 'summary_plain' => $this->decodeDataSummaryPlain($oContentInfo, $r)
  208. ]);
  209. if($bMetaMenu) {
  210. $oMetaMenu->setContentId($r['id']);
  211. $a[$i]['meta'] = $oMetaMenu->getCodeAPI();
  212. }
  213. }
  214. return $a;
  215. }
  216. function _getPseud ()
  217. {
  218. return array(
  219. 'id' => 'id',
  220. 'title' => 'title',
  221. 'text' => 'text',
  222. 'added' => 'added',
  223. 'author' => 'author',
  224. 'photo' => 'photo',
  225. );
  226. }
  227. }
  228. /** @} */