1
0

BxBaseModTextSearchResult.php 5.6 KB

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