BxNotesSearchResult.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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('BxBaseModTextSearchResult');
  12. class BxNotesSearchResult extends BxBaseModTextSearchResult
  13. {
  14. function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->aCurrent = array(
  18. 'name' => 'bx_notes',
  19. 'title' => _t('_bx_notes_page_title_browse'),
  20. 'table' => 'bx_notes_posts',
  21. 'ownFields' => array('id', 'title', 'text', 'thumb', 'author', 'added'),
  22. 'searchFields' => array('title', 'text'),
  23. 'restriction' => array(
  24. 'author' => array('value' => '', 'field' => 'author', 'operator' => '='),
  25. ),
  26. 'paginate' => array('perPage' => getParam('bx_notes_per_page_browse'), 'start' => 0),
  27. 'sorting' => 'last',
  28. 'rss' => array(
  29. 'title' => '',
  30. 'link' => '',
  31. 'image' => '',
  32. 'profile' => 0,
  33. 'fields' => array (
  34. 'Guid' => 'link',
  35. 'Link' => 'link',
  36. 'Title' => 'title',
  37. 'DateTimeUTS' => 'added',
  38. 'Desc' => 'text',
  39. ),
  40. ),
  41. 'ident' => 'id',
  42. );
  43. $this->sFilterName = 'bx_notes_filter';
  44. $this->oModule = $this->getMain();
  45. $oProfileAuthor = null;
  46. $CNF = &$this->oModule->_oConfig->CNF;
  47. switch ($sMode) {
  48. case 'search':
  49. if ($sValue)
  50. $this->aCurrent['restriction']['keyword'] = array('value' => $sValue,'field' => '','operator' => 'against');
  51. $this->sBrowseUrl = "search/?q=" . $sValue;
  52. $this->aCurrent['title'] = _t('_bx_notes_page_title_search_results', $sValue);
  53. unset($this->aCurrent['rss']); // no RSS for search results
  54. break;
  55. case 'author':
  56. bx_import('BxDolProfile');
  57. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  58. if (!$oProfileAuthor) {
  59. $this->isError = true;
  60. break;
  61. }
  62. $this->aCurrent['restriction']['author']['value'] = $oProfileAuthor->id();
  63. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  64. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_by_author');
  65. $this->aCurrent['rss']['link'] = 'modules/?r=notes/rss/' . $sMode . '/' . $oProfileAuthor->id();
  66. break;
  67. case 'public':
  68. bx_import('BxDolPermalinks');
  69. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  70. $this->aCurrent['title'] = _t('_bx_notes_page_title_browse_recent');
  71. $this->aCurrent['rss']['link'] = 'modules/?r=notes/rss/' . $sMode;
  72. break;
  73. case '': // search results
  74. $this->sBrowseUrl = '';
  75. $this->aCurrent['title'] = _t('_bx_notes');
  76. unset($this->aCurrent['rss']);
  77. break;
  78. default:
  79. $sMode = '';
  80. $this->isError = true;
  81. }
  82. // add replacable markers and replace them
  83. if ($oProfileAuthor) {
  84. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replacable
  85. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replacable
  86. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replacable
  87. }
  88. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  89. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  90. // add conditions for private content
  91. bx_import('BxDolPrivacy');
  92. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  93. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  94. if (isset($a['restriction']))
  95. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  96. if (isset($a['join']))
  97. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  98. $this->setProcessPrivateContent(false);
  99. }
  100. function displayResultBlock ()
  101. {
  102. $s = parent::displayResultBlock ();
  103. $s = '<div class="bx-notes-wrapper ' . ('unit_gallery.html' == $this->sUnitTemplate ? 'bx-def-margin-neg bx-clearfix' : '') . '">' . $s . '</div>';
  104. return $s;
  105. }
  106. function getAlterOrder()
  107. {
  108. if ($this->aCurrent['sorting'] == 'last') {
  109. $aSql = array();
  110. $aSql['order'] = " ORDER BY `bx_notes_posts`.`added` DESC";
  111. return $aSql;
  112. }
  113. return array();
  114. }
  115. }
  116. /** @} */