BxNotesSearchResult.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Notes Notes
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxTemplSearchResult');
  12. class BxNotesSearchResult extends BxTemplSearchResult
  13. {
  14. protected $aUnitViews = array('extended' => 'unit.html', 'gallery' => 'unit_gallery.html');
  15. protected $sUnitViewDefault = 'gallery';
  16. protected $sUnitViewParamName = 'unit_view';
  17. function __construct($sMode = '', $aParams = array())
  18. {
  19. $this->aCurrent = array(
  20. 'name' => 'bx_notes',
  21. 'title' => '_bx_notes_page_title_browse',
  22. 'table' => 'bx_notes_posts',
  23. 'ownFields' => array('id', 'title', 'text', 'summary', 'thumb', 'author', 'added'),
  24. 'searchFields' => array('title', 'text'),
  25. 'restriction' => array(
  26. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  27. ),
  28. 'paginate' => array('perPage' => getParam('bx_notes_per_page_browse'), 'start' => 0),
  29. 'sorting' => 'last',
  30. 'rss' => array(
  31. 'title' => '',
  32. 'link' => '',
  33. 'image' => '',
  34. 'profile' => 0,
  35. 'fields' => array (
  36. 'Guid' => 'link',
  37. 'Link' => 'link',
  38. 'Title' => 'title',
  39. 'DateTimeUTS' => 'added',
  40. 'Desc' => 'text',
  41. ),
  42. ),
  43. 'ident' => 'id',
  44. );
  45. $this->aGetParams = array($this->sUnitViewParamName);
  46. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  47. if (isset($this->aUnitViews[bx_get($this->sUnitViewParamName)]))
  48. $this->sUnitTemplate = $this->aUnitViews[bx_get($this->sUnitViewParamName)];
  49. $oProfileAuthor = null;
  50. $oModuleMain = $this->getMain();
  51. switch ($sMode) {
  52. case 'search':
  53. if ($sValue)
  54. $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
  55. $this->sBrowseUrl = "search/?q=" . $sValue;
  56. $this->aCurrent['title'] = _t('_bx_notes_page_title_search_results', $sValue);
  57. unset($this->aCurrent['rss']);
  58. break;
  59. case 'author':
  60. bx_import('BxDolProfile');
  61. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  62. if (!$oProfileAuthor) {
  63. $this->isError = true;
  64. break;
  65. }
  66. $this->aCurrent['restriction']['author']['value'] = $oProfileAuthor->id();
  67. $this->sBrowseUrl = 'page.php?i=notes-author&profile_id={profile_id}';
  68. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_by_author');
  69. break;
  70. case 'public':
  71. case '':
  72. $this->sBrowseUrl = 'page.php?i=notes-home';
  73. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_recent');
  74. break;
  75. default:
  76. $this->isError = true;
  77. }
  78. // add replacable markers and replace them
  79. if ($oProfileAuthor) {
  80. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replacable
  81. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replacable
  82. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replacable
  83. }
  84. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  85. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  86. // add conditions for private content
  87. bx_import('BxDolPrivacy');
  88. $oPrivacy = BxDolPrivacy::getObjectInstance(BxNotesConfig::$OBJECT_PRIVACY_VIEW);
  89. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  90. if (isset($a['restriction']))
  91. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  92. if (isset($a['join']))
  93. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  94. $this->setProcessPrivateContent(false);
  95. // set rss links if required
  96. if (isset($this->aCurrent['rss']))
  97. $this->aCurrent['rss']['link'] = $this->sBrowseUrl;
  98. if (bx_get('rss'))
  99. $this->aCurrent['paginate']['perPage'] = getParam('bx_notes_rss_num');
  100. $this->sFilterName = 'bx_notes_filter';
  101. // $this->aCurrent['paginate']['perPage'] = $oModuleMain->_oDb->getParam('bx_groups_perpage_browse'); // TODO:
  102. parent::__construct();
  103. }
  104. function getMain()
  105. {
  106. return BxDolModule::getInstance($this->aCurrent['name']);
  107. }
  108. function displayResultBlock ()
  109. {
  110. $s = parent::displayResultBlock ();
  111. $s = '<div class="bx-notes-wrapper ' . ('unit_gallery.html' == $this->sUnitTemplate ? 'bx-def-margin-neg bx-clearfix' : '') . '">' . $s . '</div>';
  112. return $s;
  113. }
  114. function getDesignBoxMenu ()
  115. {
  116. $aMenu = parent::getDesignBoxMenu ();
  117. return array_merge(
  118. array(
  119. array('name' => 'gallery', 'title' => _t('_sys_menu_title_gallery'), 'link' => $this->getCurrentUrl(array($this->sUnitViewParamName => 'gallery')), 'icon' => 'th'),
  120. array('name' => 'extended', 'title' => _t('_sys_menu_title_extended'), 'link' => $this->getCurrentUrl(array($this->sUnitViewParamName => 'extended')), 'icon' => 'list'),
  121. ),
  122. $aMenu
  123. );
  124. }
  125. function getAlterOrder()
  126. {
  127. if ($this->aCurrent['sorting'] == 'last') {
  128. $aSql = array();
  129. $aSql['order'] = " ORDER BY `bx_notes_posts`.`added` DESC";
  130. return $aSql;
  131. }
  132. return array();
  133. }
  134. function getRssUnitLink (&$a)
  135. {
  136. bx_import('BxDolPermalinks');
  137. return BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=view-note&id=' . $a['id']);
  138. }
  139. function _getPseud ()
  140. {
  141. return array(
  142. 'id' => 'id',
  143. 'title' => 'title',
  144. 'text' => 'text',
  145. 'added' => 'added',
  146. 'author' => 'author',
  147. 'photo' => 'photo',
  148. );
  149. }
  150. }
  151. /** @} */