1
0

BxBaseModTextSearchResult.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. function getRssUnitImage (&$a, $sField)
  36. {
  37. $CNF = &$this->oModule->_oConfig->CNF;
  38. if(empty($sField) || empty($a[$sField]) || empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  39. return '';
  40. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  41. if(!$oTranscoder)
  42. return '';
  43. return $oTranscoder->getFileUrl($a[$sField]);
  44. }
  45. protected function processReplaceableMarkers($oProfileAuthor)
  46. {
  47. if ($oProfileAuthor) {
  48. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replaceable
  49. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replaceable
  50. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replaceable
  51. }
  52. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  53. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  54. }
  55. protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
  56. {
  57. // always add UnitView as additional param
  58. $sUnitView = bx_process_input(bx_get($this->sUnitViewParamName));
  59. if ($sUnitView && isset($this->aUnitViews[$sUnitView]))
  60. $aAdditionalParams = array_merge(array($this->sUnitViewParamName => $sUnitView), $aAdditionalParams);
  61. return parent::getCurrentOnclick($aAdditionalParams, $bReplacePagesParams);
  62. }
  63. protected function _updateCurrentForAuthor($sMode, $aParams, &$oProfileAuthor)
  64. {
  65. $CNF = &$this->oModule->_oConfig->CNF;
  66. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  67. if (!$oProfileAuthor)
  68. return false;
  69. $iProfileAuthor = $oProfileAuthor->id();
  70. if (bx_get_logged_profile_id() == $iProfileAuthor || $this->oModule->_isModerator()) {
  71. // for real owner and for moderators show anonymous posts
  72. $this->aCurrent['restriction']['author']['operator'] = 'in';
  73. $this->aCurrent['restriction']['author']['value'] = array($iProfileAuthor, -$iProfileAuthor);
  74. }
  75. else {
  76. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  77. }
  78. if(!empty($aParams['except']))
  79. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  80. if(!empty($aParams['per_page']))
  81. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  82. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  83. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  84. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  85. return true;
  86. }
  87. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  88. {
  89. $CNF = &$this->oModule->_oConfig->CNF;
  90. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  91. if (!$oProfileContext)
  92. return false;
  93. $iProfileIdContext = $oProfileContext->id();
  94. $this->aCurrent['restriction']['context'] = array(
  95. 'value' => -$iProfileIdContext,
  96. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  97. 'operator' => '=',
  98. );
  99. if(!empty($aParams['per_page']))
  100. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  101. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  102. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  103. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  104. return true;
  105. }
  106. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  107. {
  108. $CNF = &$this->oModule->_oConfig->CNF;
  109. $sSystem = '';
  110. if(!empty($aParams['system'])) {
  111. $sSystem = $aParams['system'];
  112. unset($aParams['system']);
  113. }
  114. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  115. if(!$oProfileAuthor)
  116. return false;
  117. $iProfileAuthor = $oProfileAuthor->id();
  118. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  119. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  120. return false;
  121. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor);
  122. if(!empty($aConditions) && is_array($aConditions)) {
  123. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  124. $this->aCurrent['restriction'] = array();
  125. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  126. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  127. $this->aCurrent['join'] = array();
  128. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  129. }
  130. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  131. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  132. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  133. return true;
  134. }
  135. function _getPseud ()
  136. {
  137. return array(
  138. 'id' => 'id',
  139. 'title' => 'title',
  140. 'text' => 'text',
  141. 'added' => 'added',
  142. 'author' => 'author',
  143. 'photo' => 'photo',
  144. );
  145. }
  146. }
  147. /** @} */