BxPostsSearchResult.php 4.8 KB

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