1
0

BxBaseModTextSearchResult.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 $aUnitViews = array('extended' => 'unit.html', 'gallery' => 'unit_gallery.html', 'full' => 'unit_full.html', 'showcase' => 'unit_showcase.html');
  14. protected $sUnitViewDefault = 'gallery';
  15. protected $sUnitViewParamName = 'unit_view';
  16. protected $bShowcaseView = false;
  17. function __construct($sMode = '', $aParams = array())
  18. {
  19. parent::__construct($sMode, $aParams);
  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. if ('unit_gallery.html' == $this->sUnitTemplate)
  27. $this->addContainerClass (array('bx-def-margin-sec-lefttopright-neg', 'bx-base-text-unit-gallery-wrapper'));
  28. if ('unit_showcase.html' == $this->sUnitTemplate){
  29. $this->bShowcaseView = true;
  30. $this->addContainerClass (array('bx-def-margin-sec-lefttopright-neg', 'bx-base-text-unit-showcase-wrapper'));
  31. }
  32. }
  33. protected function processReplaceableMarkers($oProfileAuthor)
  34. {
  35. if ($oProfileAuthor) {
  36. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replaceable
  37. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replaceable
  38. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replaceable
  39. }
  40. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  41. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  42. }
  43. protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
  44. {
  45. // always add UnitView as additional param
  46. $sUnitView = bx_process_input(bx_get($this->sUnitViewParamName));
  47. if ($sUnitView && isset($this->aUnitViews[$sUnitView]))
  48. $aAdditionalParams = array_merge(array($this->sUnitViewParamName => $sUnitView), $aAdditionalParams);
  49. return parent::getCurrentOnclick($aAdditionalParams, $bReplacePagesParams);
  50. }
  51. protected function _updateCurrentForAuthor($sMode, $aParams, &$oProfileAuthor)
  52. {
  53. $CNF = &$this->oModule->_oConfig->CNF;
  54. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  55. if (!$oProfileAuthor)
  56. return false;
  57. $iProfileAuthor = $oProfileAuthor->id();
  58. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  59. if(!empty($aParams['except']))
  60. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  61. if(!empty($aParams['per_page']))
  62. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  63. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  64. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  65. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  66. return true;
  67. }
  68. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  69. {
  70. $CNF = &$this->oModule->_oConfig->CNF;
  71. $sSystem = '';
  72. if(!empty($aParams['system'])) {
  73. $sSystem = $aParams['system'];
  74. unset($aParams['system']);
  75. }
  76. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  77. if(!$oProfileAuthor)
  78. return false;
  79. $iProfileAuthor = $oProfileAuthor->id();
  80. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  81. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  82. return false;
  83. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor);
  84. if(!empty($aConditions) && is_array($aConditions)) {
  85. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  86. $this->aCurrent['restriction'] = array();
  87. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  88. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  89. $this->aCurrent['join'] = array();
  90. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  91. }
  92. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  93. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  94. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  95. return true;
  96. }
  97. function _getPseud ()
  98. {
  99. return array(
  100. 'id' => 'id',
  101. 'title' => 'title',
  102. 'text' => 'text',
  103. 'added' => 'added',
  104. 'author' => 'author',
  105. 'photo' => 'photo',
  106. );
  107. }
  108. function displayResultBlock ()
  109. {
  110. $sAddJs = "";
  111. if ($this->bShowcaseView){
  112. $this->aCurrent['paginate']['perPage'] = getParam('bx_posts_per_page_browse_showcase');
  113. $this->aCurrent['paginate']['perPage'] = 0;
  114. $sAddJs = $this->oModule->_oTemplate->getJsCode('main');
  115. }
  116. $s = parent::displayResultBlock ();
  117. return $sAddJs . $s;
  118. }
  119. }
  120. /** @} */