BxNotesSearchResult.php 6.7 KB

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