BxBaseModTextSearchResult.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 addConditionsForPrivateContent($CNF, $oProfileAuthor)
  39. {
  40. // add conditions for private content
  41. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  42. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  43. if (isset($a['restriction']))
  44. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  45. if (isset($a['join']))
  46. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  47. $this->setProcessPrivateContent(false);
  48. }
  49. protected function getCurrentOnclick($aAdditionalParams = array(), $bReplacePagesParams = true)
  50. {
  51. // always add UnitView as additional param
  52. $sUnitView = bx_process_input(bx_get($this->sUnitViewParamName));
  53. if ($sUnitView && isset($this->aUnitViews[$sUnitView]))
  54. $aAdditionalParams = array_merge(array($this->sUnitViewParamName => $sUnitView), $aAdditionalParams);
  55. return parent::getCurrentOnclick($aAdditionalParams, $bReplacePagesParams);
  56. }
  57. protected function _updateCurrentForAuthor($sMode, $aParams, &$oProfileAuthor)
  58. {
  59. $CNF = &$this->oModule->_oConfig->CNF;
  60. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  61. if (!$oProfileAuthor)
  62. return false;
  63. $iProfileAuthor = $oProfileAuthor->id();
  64. $this->aCurrent['restriction']['author']['value'] = $iProfileAuthor;
  65. if(!empty($aParams['except']))
  66. $this->aCurrent['restriction']['except']['value'] = is_array($aParams['except']) ? $aParams['except'] : array($aParams['except']);
  67. if(!empty($aParams['per_page']))
  68. $this->aCurrent['paginate']['perPage'] = is_numeric($aParams['per_page']) ? (int)$aParams['per_page'] : (int)getParam($aParams['per_page']);
  69. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  70. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  71. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  72. return true;
  73. }
  74. protected function _updateCurrentForFavorite($sMode, $aParams, &$oProfileAuthor)
  75. {
  76. $CNF = &$this->oModule->_oConfig->CNF;
  77. $sSystem = '';
  78. if(!empty($aParams['system'])) {
  79. $sSystem = $aParams['system'];
  80. unset($aParams['system']);
  81. }
  82. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  83. if(!$oProfileAuthor)
  84. return false;
  85. $iProfileAuthor = $oProfileAuthor->id();
  86. $oFavorite = $this->oModule->getObjectFavorite($sSystem);
  87. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  88. return false;
  89. $aConditions = $oFavorite->getConditionsTrack($this->aCurrent['table'], 'id', $iProfileAuthor);
  90. if(!empty($aConditions) && is_array($aConditions)) {
  91. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  92. $this->aCurrent['restriction'] = array();
  93. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  94. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  95. $this->aCurrent['join'] = array();
  96. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  97. }
  98. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  99. $this->aCurrent['title'] = _t($CNF['T']['txt_all_entries_by_author']);
  100. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  101. return true;
  102. }
  103. function _getPseud ()
  104. {
  105. return array(
  106. 'id' => 'id',
  107. 'title' => 'title',
  108. 'text' => 'text',
  109. 'added' => 'added',
  110. 'author' => 'author',
  111. 'photo' => 'photo',
  112. );
  113. }
  114. }
  115. /** @} */