BxBaseModGeneralSearchResult.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. parent::__construct();
  21. }
  22. function getMain()
  23. {
  24. return BxDolModule::getInstance($this->aCurrent['module_name']);
  25. }
  26. function getRssUnitLink (&$a)
  27. {
  28. $CNF = &$this->oModule->_oConfig->CNF;
  29. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $a[$CNF['FIELD_ID']]);
  30. }
  31. function getRssPageUrl ()
  32. {
  33. if (false === parent::getRssPageUrl())
  34. return false;
  35. $oPermalinks = BxDolPermalinks::getInstance();
  36. return BX_DOL_URL_ROOT . $oPermalinks->permalink($this->aCurrent['rss']['link']);
  37. }
  38. function rss ()
  39. {
  40. if (!isset($this->aCurrent['rss']))
  41. return '';
  42. $this->aCurrent['paginate']['perPage'] = empty($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']) ? 10 : getParam($this->oModule->_oConfig->CNF['PARAM_NUM_RSS']);
  43. return parent::rss();
  44. }
  45. /**
  46. * Add conditions for private content
  47. */
  48. protected function addConditionsForPrivateContent($CNF, $oProfile, $aCustomGroup = array())
  49. {
  50. // default is bProcessPrivateContent = 1,
  51. // so private items are shown as empty boxes with "Private" title
  52. // we can show public content when privacy object is available
  53. if(empty($CNF['OBJECT_PRIVACY_VIEW']))
  54. return;
  55. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  56. if(!$oPrivacy)
  57. return;
  58. // for posts in some context we need to show all items, not only public content
  59. if (!empty($this->aCurrent['restriction']['context']['value']) || !empty($this->aCurrent['restriction']['author']['value'])) {
  60. $this->setProcessPrivateContent(true);
  61. return;
  62. }
  63. // build condition to show only public content
  64. $aCondition = $oPrivacy->getContentPublicAsCondition($oProfile ? $oProfile->id() : 0, $aCustomGroup);
  65. if(empty($aCondition) || !is_array($aCondition))
  66. return;
  67. if(isset($aCondition['restriction'])) {
  68. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  69. $this->aPrivateConditionsIndexes['restriction'] = array_keys($aCondition['restriction']);
  70. }
  71. if(isset($aCondition['join'])) {
  72. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  73. $this->aPrivateConditionsIndexes['join'] = array_keys($aCondition['join']);
  74. }
  75. $this->setProcessPrivateContent(false);
  76. }
  77. function showPagination($bAdmin = false, $bChangePage = true, $bPageReload = true)
  78. {
  79. if ($this->bShowcaseView){
  80. return '';
  81. }
  82. else{
  83. $sTmp = parent::showPagination ($bAdmin, $bChangePage, $bPageReload);
  84. if ($sTmp != '')
  85. return '<div class="bx-def-margin-top">' . $sTmp . '</div>';
  86. else
  87. return '';
  88. }
  89. }
  90. protected function getItemPerPageInShowCase ()
  91. {
  92. $iPerPageInShowCase = BX_SYS_PER_PAGE_BROWSE_SHOWCASE;
  93. $CNF = &$this->oModule->_oConfig->CNF;
  94. if (isset($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']))
  95. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_SHOWCASE']);
  96. return $iPerPageInShowCase;
  97. }
  98. function displayResultBlock ()
  99. {
  100. if ($this->bShowcaseView){
  101. $this->addContainerClass(array('bx-def-margin-sec-lefttopright-neg', 'bx-base-unit-showcase-wrapper'));
  102. $this->aCurrent['paginate']['perPage'] = $this->getItemPerPageInShowCase();
  103. $this->oModule->_oTemplate->addCss(array(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css'));
  104. $this->oModule->_oTemplate->addJs(array('flickity/flickity.pkgd.min.js','modules/base/general/js/|showcase.js'));
  105. }
  106. return parent::displayResultBlock ();
  107. }
  108. }
  109. /** @} */