BxBaseModTextSearchResult.php 5.6 KB

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