BxBaseModGeneralSearchResult.php 7.9 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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. define('BX_SYS_PER_PAGE_BROWSE_SHOWCASE', 32);
  12. class BxBaseModGeneralSearchResult extends BxTemplSearchResult
  13. {
  14. protected $oModule;
  15. protected $bShowcaseView = false;
  16. protected $aUnitViews = array();
  17. protected $sUnitViewDefault = 'gallery';
  18. function __construct($sMode = '', $aParams = array())
  19. {
  20. $this->_sMode = $sMode;
  21. parent::__construct();
  22. }
  23. function getMain()
  24. {
  25. return BxDolModule::getInstance($this->aCurrent['module_name']);
  26. }
  27. function getContentInfoObject()
  28. {
  29. return BxDolContentInfo::getObjectInstance($this->aCurrent['name']);
  30. }
  31. function getRssUnitLink (&$a)
  32. {
  33. $CNF = &$this->oModule->_oConfig->CNF;
  34. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $a[$CNF['FIELD_ID']]));
  35. }
  36. function getRssPageUrl ()
  37. {
  38. if (false === parent::getRssPageUrl())
  39. return false;
  40. $oPermalinks = BxDolPermalinks::getInstance();
  41. return bx_absolute_url($oPermalinks->permalink($this->aCurrent['rss']['link']));
  42. }
  43. function rss ()
  44. {
  45. if (!isset($this->aCurrent['rss']))
  46. return '';
  47. $this->aCurrent['paginate']['perPage'] = empty($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']) ? 10 : getParam($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']);
  48. return parent::rss();
  49. }
  50. protected function addCustomConditions($CNF, $oProfile, $sMode, $aParams)
  51. {
  52. $this->addConditionsForAuthorStatus($CNF);
  53. $this->addConditionsForCf($CNF);
  54. if(!empty($aParams['filter']) && is_array($aParams['filter']))
  55. $this->addConditionsForFilter($CNF, $sMode, $aParams);
  56. }
  57. protected function addConditionsForAuthorStatus($CNF)
  58. {
  59. if (empty($CNF['FIELD_AUTHOR']))
  60. return;
  61. $this->aCurrent['restriction']['statusAuthor'] = [
  62. 'value' => 'active',
  63. 'field' => 'status',
  64. 'operator' => '=',
  65. 'table' => 'sys_profiles',
  66. ];
  67. $this->aCurrent['join']['statusAuthor'] = [
  68. 'type' => 'INNER',
  69. 'table' => 'sys_profiles',
  70. 'mainField' => $CNF['FIELD_AUTHOR'],
  71. 'onField' => 'id',
  72. 'joinFields' => array(),
  73. ];
  74. }
  75. protected function addConditionsForCf($CNF)
  76. {
  77. if(empty($CNF['FIELD_CF']))
  78. return;
  79. $oCf = BxDolContentFilter::getInstance();
  80. if(!$oCf->isEnabled())
  81. return;
  82. $aConditions = $oCf->getConditions($this->aCurrent['table'], $CNF['FIELD_CF']);
  83. if(!empty($aConditions) && is_array($aConditions))
  84. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions);
  85. }
  86. protected function addConditionsForFilter($CNF, $sMode, $aParams)
  87. {
  88. $aFilter = $aParams['filter'];
  89. if(empty($aFilter['field']) || empty($aFilter['value']))
  90. return;
  91. $aRestriction = [
  92. 'value' => $aFilter['value'],
  93. 'field' => $aFilter['field'],
  94. 'operator' => '=',
  95. ];
  96. if(isset($aFilter['operator']))
  97. $aRestriction['operator'] = $aFilter['operator'];
  98. if(isset($aFilter['table']))
  99. switch($aFilter['table']) {
  100. case 'table':
  101. $aRestriction['table'] = $this->aCurrent['table'];
  102. break;
  103. case 'tableSearch':
  104. $aRestriction['table'] = $this->aCurrent['tableSearch'];
  105. break;
  106. default:
  107. $aRestriction['table'] = $aFilter['table'];
  108. }
  109. $this->aCurrent['restriction']['filter'] = $aRestriction;
  110. }
  111. /**
  112. * Add conditions for private content
  113. */
  114. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  115. {
  116. // default is bProcessPrivateContent = 1,
  117. // so private items are shown as empty boxes with "Private" title
  118. // we can show public content when privacy object is available
  119. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  120. return;
  121. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  122. if(!$oPrivacy)
  123. return;
  124. // for posts in some context we need to show all items, not only public content
  125. if (!empty($this->aCurrent['restriction']['context']['value']) || !empty($this->aCurrent['restriction']['author']['value'])) {
  126. $this->setProcessPrivateContent(true);
  127. return;
  128. }
  129. // build condition to show only public content
  130. $aCondition = $oPrivacy->getContentPublicAsCondition($oProfile ? $oProfile->id() : 0, $aCustomGroup);
  131. if(empty($aCondition) || !is_array($aCondition))
  132. return;
  133. if(isset($aCondition['restriction'])) {
  134. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  135. $this->aPrivateConditionsIndexes['restriction'] = array_keys($aCondition['restriction']);
  136. }
  137. if(isset($aCondition['join'])) {
  138. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  139. $this->aPrivateConditionsIndexes['join'] = array_keys($aCondition['join']);
  140. }
  141. $this->setProcessPrivateContent(false);
  142. }
  143. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  144. {
  145. if($this->bShowcaseView)
  146. return '';
  147. $sPagination = parent::showPagination ($bAdmin, $bChangePage, $bPageReload);
  148. if(empty($sPagination))
  149. return '';
  150. return $sPagination;
  151. }
  152. protected function getItemPerPageInShowCase ()
  153. {
  154. $iPerPageInShowCase = BX_SYS_PER_PAGE_BROWSE_SHOWCASE;
  155. $CNF = &$this->oModule->_oConfig->CNF;
  156. if (isset($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']))
  157. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']);
  158. return $iPerPageInShowCase;
  159. }
  160. function displayResultBlock()
  161. {
  162. if ($this->bShowcaseView) {
  163. $this->addContainerClass(array('bx-base-unit-showcase-wrapper'));
  164. $this->aCurrent['paginate']['perPage'] = $this->getItemPerPageInShowCase();
  165. $this->oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'));
  166. $this->oModule->_oTemplate->addJs(array('flickity/flickity.pkgd.min.js','modules/base/general/js/|showcase.js'));
  167. }
  168. return parent::displayResultBlock();
  169. }
  170. function decodeData ($a)
  171. {
  172. $oContentInfo = $this->getContentInfoObject();
  173. $CNF = $this->oModule->_oConfig->CNF;
  174. foreach ($a as $i => $r) {
  175. if (isset($r['author']))
  176. $a[$i]['author_data'] = BxDolProfile::getData($r[$CNF['FIELD_AUTHOR']]);
  177. $a[$i]['url'] = $this->decodeDataUrl($oContentInfo, $r);
  178. $a[$i]['url_thumb'] = $oContentInfo->getContentThumb($r['id']);
  179. $a[$i]['summary_plain'] = $this->decodeDataSummaryPlain($oContentInfo, $r);
  180. }
  181. return $a;
  182. }
  183. function decodeDataUrl ($oContentInfo, $r)
  184. {
  185. return bx_ltrim_str($oContentInfo->getContentLink($r['id']), BX_DOL_URL_ROOT);
  186. }
  187. function decodeDataSummaryPlain ($oContentInfo, $r)
  188. {
  189. $CNF = $this->oModule->_oConfig->CNF;
  190. $sSummary = $this->oModule->_oTemplate->getText($r);
  191. return isset($CNF['PARAM_CHARS_SUMMARY_PLAIN']) && $CNF['PARAM_CHARS_SUMMARY_PLAIN'] ? BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) : '';
  192. }
  193. }
  194. /** @} */