BxPostsSearchResult.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. '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 '': // search results
  69. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  70. $this->aCurrent['title'] = _t('_bx_posts');
  71. $this->aCurrent['paginate']['perPage'] = 3;
  72. unset($this->aCurrent['rss']);
  73. break;
  74. default:
  75. $sMode = '';
  76. $this->isError = true;
  77. }
  78. // add replaceable 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($CNF['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. }
  96. function displayResultBlock ()
  97. {
  98. $s = parent::displayResultBlock ();
  99. $s = '<div class="bx-posts-wrapper ' . ('unit_gallery.html' == $this->sUnitTemplate ? 'bx-def-margin-neg bx-clearfix' : '') . '">' . $s . '</div>';
  100. return $s;
  101. }
  102. function getAlterOrder()
  103. {
  104. if ($this->aCurrent['sorting'] == 'last') {
  105. $aSql = array();
  106. $aSql['order'] = " ORDER BY `bx_posts_posts`.`added` DESC";
  107. return $aSql;
  108. }
  109. return array();
  110. }
  111. }
  112. /** @} */