BxPostsSearchResult.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 TridentModules
  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. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  27. ),
  28. 'paginate' => array('perPage' => getParam('bx_posts_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->sFilterName = 'bx_posts_filter';
  46. $this->oModule = $this->getMain();
  47. $oProfileAuthor = null;
  48. $CNF = &$this->oModule->_oConfig->CNF;
  49. switch ($sMode) {
  50. case 'author':
  51. bx_import('BxDolProfile');
  52. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['author']);
  53. if (!$oProfileAuthor) {
  54. $this->isError = true;
  55. break;
  56. }
  57. $this->aCurrent['restriction']['author']['value'] = $oProfileAuthor->id();
  58. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id={profile_id}';
  59. $this->aCurrent['title'] = _t('_bx_posts_page_title_browse_by_author');
  60. $this->aCurrent['rss']['link'] = 'modules/?r=posts/rss/' . $sMode . '/' . $oProfileAuthor->id();
  61. break;
  62. case 'public':
  63. bx_import('BxDolPermalinks');
  64. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  65. $this->aCurrent['title'] = _t('_bx_posts_page_title_browse_recent');
  66. $this->aCurrent['rss']['link'] = 'modules/?r=posts/rss/' . $sMode;
  67. break;
  68. case 'popular':
  69. bx_import('BxDolPermalinks');
  70. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_POPULAR']);
  71. $this->aCurrent['title'] = _t('_bx_posts_page_title_browse_popular');
  72. $this->aCurrent['rss']['link'] = 'modules/?r=posts/rss/' . $sMode;
  73. $this->aCurrent['sorting'] = 'popular';
  74. break;
  75. case '': // search results
  76. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  77. $this->aCurrent['title'] = _t('_bx_posts');
  78. $this->aCurrent['paginate']['perPage'] = 3;
  79. unset($this->aCurrent['rss']);
  80. break;
  81. default:
  82. $sMode = '';
  83. $this->isError = true;
  84. }
  85. // add replaceable markers and replace them
  86. if ($oProfileAuthor) {
  87. $this->addMarkers($oProfileAuthor->getInfo()); // profile info is replacable
  88. $this->addMarkers(array('profile_id' => $oProfileAuthor->id())); // profile id is replacable
  89. $this->addMarkers(array('display_name' => $oProfileAuthor->getDisplayName())); // profile display name is replacable
  90. }
  91. $this->sBrowseUrl = $this->_replaceMarkers($this->sBrowseUrl);
  92. $this->aCurrent['title'] = $this->_replaceMarkers($this->aCurrent['title']);
  93. // add conditions for private content
  94. bx_import('BxDolPrivacy');
  95. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  96. $a = $oPrivacy ? $oPrivacy->getContentPublicAsCondition($oProfileAuthor ? $oProfileAuthor->id() : 0) : array();
  97. if (isset($a['restriction']))
  98. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  99. if (isset($a['join']))
  100. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  101. $this->setProcessPrivateContent(false);
  102. }
  103. function getAlterOrder()
  104. {
  105. $aSql = array();
  106. switch ($this->aCurrent['sorting']) {
  107. case 'last':
  108. $aSql['order'] = ' ORDER BY `bx_posts_posts`.`added` DESC';
  109. break;
  110. case 'popular':
  111. $aSql['order'] = ' ORDER BY `bx_posts_posts`.`views` DESC';
  112. break;
  113. }
  114. return $aSql;
  115. }
  116. }
  117. /** @} */