1
0

BxBaseModTextSearchResult.php 5.3 KB

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