BxBaseModTextSearchResult.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  71. if(!empty($aParams['except']))
  72. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  73. if(!empty($aParams['per_page']))
  74. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  75. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  76. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  77. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  78. return true;
  79. }
  80. protected function _updateCurrentForContext($sMode, $aParams, &$oProfileContext)
  81. {
  82. $CNF = &$this->oModule->_oConfig->CNF;
  83. $oProfileContext = BxDolProfile::getInstance((int)$aParams['context']);
  84. if (!$oProfileContext)
  85. return false;
  86. $iProfileIdContext = $oProfileContext->id();
  87. $this->aCurrent['restriction']['context'] = array(
  88. 'value' => -$iProfileIdContext,
  89. 'field' => $CNF['FIELD_ALLOW_VIEW_TO'],
  90. 'operator' => '=',
  91. );
  92. if(!empty($aParams['per_page']))
  93. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  94. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id={profile_id}';
  95. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_context']);
  96. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileIdContext;
  97. return true;
  98. }
  99. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  100. {
  101. $CNF = &$this->oModule->_oConfig->CNF;
  102. $sSystem = '';
  103. if(!empty($aParams['system'])) {
  104. $sSystem = $aParams['system'];
  105. unset($aParams['system']);
  106. }
  107. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  108. if(!$oProfileAuthor)
  109. return false;
  110. $iProfileAuthor = $oProfileAuthor->id();
  111. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  112. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  113. return false;
  114. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor);
  115. if(!empty($aConditions) && is_array($aConditions)) {
  116. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  117. $this->aCurrent['restriction'] = array();
  118. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  119. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  120. $this->aCurrent['join'] = array();
  121. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  122. }
  123. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  124. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  125. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  126. return true;
  127. }
  128. function _getPseud ()
  129. {
  130. return array(
  131. 'id' => 'id',
  132. 'title' => 'title',
  133. 'text' => 'text',
  134. 'added' => 'added',
  135. 'author' => 'author',
  136. 'photo' => 'photo',
  137. );
  138. }
  139. }
  140. /** @} */