BxCnlSearchResult.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defdroup Channels Channels
  7. * @indroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxCnlSearchResult extends BxBaseModGroupsSearchResult
  12. {
  13. function __construct($sMode = '', $aParams = false)
  14. {
  15. parent::__construct($sMode, $aParams);
  16. $this->aCurrent = array(
  17. 'name' => 'bx_channels',
  18. 'module_name' => 'bx_channels',
  19. 'object_metatags' => 'bx_channels',
  20. 'title' => _t('_bx_channels_page_title_browse'),
  21. 'table' => 'sys_profiles',
  22. 'tableSearch' => 'bx_cnl_data',
  23. 'ownFields' => array(),
  24. 'searchFields' => array(),
  25. 'restriction' => array(
  26. 'account_id' => array('value' => '', 'field' => 'account_id', 'operator' => '='),
  27. 'perofileStatus' => array('value' => 'active', 'field' => 'status', 'operator' => '='),
  28. 'perofileType' => array('value' => 'bx_channels', 'field' => 'type', 'operator' => '='),
  29. 'owner' => array('value' => '', 'field' => 'author', 'operator' => '=', 'table' => 'bx_cnl_data'),
  30. 'featured' => array('value' => '', 'field' => 'featured', 'operator' => '<>', 'table' => 'bx_cnl_data'),
  31. 'status' => array('value' => 'active', 'field' => 'status', 'operator' => '=', 'table' => 'bx_cnl_data'),
  32. 'statusAdmin' => array('value' => 'active', 'field' => 'status_admin', 'operator' => '=', 'table' => 'bx_cnl_data'),
  33. ),
  34. 'join' => array (
  35. 'profile' => array(
  36. 'type' => 'INNER',
  37. 'table' => 'bx_cnl_data',
  38. 'mainField' => 'content_id',
  39. 'onField' => 'id',
  40. 'joinFields' => array('id', 'channel_name', 'picture', 'cover', 'added', 'author', 'allow_view_to'),
  41. ),
  42. 'account' => array(
  43. 'type' => 'INNER',
  44. 'table' => 'sys_accounts',
  45. 'mainField' => 'account_id',
  46. 'onField' => 'id',
  47. 'joinFields' => array(),
  48. ),
  49. ),
  50. 'paginate' => array('perPage' => getParam('bx_channels_per_page_browse'), 'start' => 0),
  51. 'sorting' => 'last',
  52. 'rss' => array(
  53. 'title' => '',
  54. 'link' => '',
  55. 'image' => '',
  56. 'profile' => 0,
  57. 'fields' => array (
  58. 'Guid' => 'link',
  59. 'Link' => 'link',
  60. 'Title' => 'channel_name',
  61. 'DateTimeUTS' => 'added',
  62. 'Desc' => 'channel_name',
  63. 'Image' => 'picture',
  64. ),
  65. ),
  66. 'ident' => 'id'
  67. );
  68. $this->sFilterName = 'bx_cnl_data_filter';
  69. $this->oModule = $this->getMain();
  70. $CNF = &$this->oModule->_oConfig->CNF;
  71. $sSearchFields = getParam($CNF['PARAM_SEARCHABLE_FIELDS']);
  72. $this->aCurrent['searchFields'] = !empty($sSearchFields) ? explode(',', $sSearchFields) : '';
  73. $oJoinedProfile = null;
  74. $bProcessConditionsForPrivateContent = true;
  75. switch ($sMode) {
  76. case 'created_entries':
  77. if(!$this->_setAuthorConditions($sMode, $aParams, $oJoinedProfile)) {
  78. $this->isError = true;
  79. break;
  80. }
  81. break;
  82. case 'connections':
  83. if ($this->_setConnectionsConditions($aParams)) {
  84. $bProcessConditionsForPrivateContent = false;
  85. $oProfile = BxDolProfile::getInstance($aParams['profile']);
  86. $oProfile2 = isset($aParams['profile2']) ? BxDolProfile::getInstance($aParams['profile2']) : null;
  87. if (isset($aParams['type']) && $aParams['type'] == 'common' && $oProfile && $oProfile2)
  88. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_connections_mutual', $oProfile->getDisplayName(), $oProfile2->getDisplayName());
  89. elseif ((!isset($aParams['type']) || $aParams['type'] != 'common') && $oProfile)
  90. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_connections', $oProfile->getDisplayName());
  91. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode . '/' . $aParams['object'] . '/' . $aParams['type'] . '/' . (int)$aParams['profile'] . '/' . (int)$aParams['profile2'] . '/' . (int)$aParams['mutual'];
  92. }
  93. break;
  94. case 'followed_entries':
  95. $oJoinedProfile = BxDolProfile::getInstance((int)$aParams['joined_profile']);
  96. if (!$oJoinedProfile) {
  97. $this->isError = true;
  98. break;
  99. }
  100. $bProcessConditionsForPrivateContent = false;
  101. $this->aCurrent['join']['subscriptions'] = array(
  102. 'type' => 'INNER',
  103. 'table' => 'sys_profiles_conn_subscriptions',
  104. 'mainField' => 'id',
  105. 'onField' => 'content',
  106. 'joinFields' => array('initiator'),
  107. );
  108. $this->aCurrent['restriction']['subscriptions'] = array('value' => $oJoinedProfile->id(), 'field' => 'initiator', 'operator' => '=', 'table' => 'sys_profiles_conn_subscriptions');
  109. break;
  110. case 'favorite':
  111. if(!$this->_setFavoriteConditions($sMode, $aParams, $oJoinedProfile)) {
  112. $this->isError = true;
  113. break;
  114. }
  115. break;
  116. case 'recent':
  117. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  118. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_recent');
  119. $this->aCurrent['sorting'] = 'last';
  120. $this->sBrowseUrl = 'page.php?i=channels-home';
  121. break;
  122. case 'featured':
  123. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  124. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_featured');
  125. $this->aCurrent['restriction']['featured']['value'] = '0';
  126. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  127. $this->aCurrent['sorting'] = 'featured';
  128. break;
  129. case 'recommended':
  130. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  131. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_recommended');
  132. $this->aCurrent['restriction']['featured']['value'] = '0';
  133. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  134. $this->aCurrent['sorting'] = 'recommended';
  135. $this->_setConditionsForRecommended();
  136. break;
  137. case 'top':
  138. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  139. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_top');
  140. $this->aCurrent['sorting'] = 'top';
  141. $this->sBrowseUrl = 'page.php?i=channels-top';
  142. break;
  143. case 'active':
  144. $this->aCurrent['join']['contents'] = [
  145. 'type' => 'INNER',
  146. 'table' => $CNF['TABLE_CONTENT'],
  147. 'mainTable' => 'bx_cnl_data',
  148. 'mainField' => 'id',
  149. 'onField' => 'cnl_id',
  150. 'joinFields' => [],
  151. 'groupTable' => 'bx_cnl_data',
  152. 'groupField' => 'id',
  153. 'groupHaving' => 'COUNT(`' . $CNF['TABLE_CONTENT'] . '`.`cnl_id`) >= ' . (int)getParam($CNF['PARAM_BROWSE_ACTIVE_N_POSTS'])
  154. ];
  155. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], [
  156. 'contents_period' => [
  157. 'value' => time() - 3600 * (int)getParam($CNF['PARAM_BROWSE_ACTIVE_X_HOURS']),
  158. 'field' => 'date',
  159. 'operator' => '>=',
  160. 'table' => $CNF['TABLE_CONTENT']
  161. ]
  162. ]);
  163. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  164. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_active');
  165. $this->aCurrent['sorting'] = 'active';
  166. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  167. break;
  168. case 'trending':
  169. $this->aCurrent['join']['contents'] = [
  170. 'type' => 'INNER',
  171. 'table' => $CNF['TABLE_CONTENT'],
  172. 'mainTable' => 'bx_cnl_data',
  173. 'mainField' => 'id',
  174. 'onField' => 'cnl_id',
  175. 'joinFields' => ['cnl_id'],
  176. 'operator' => 'COUNT',
  177. 'groupTable' => 'bx_cnl_data',
  178. 'groupField' => 'id',
  179. 'groupHaving' => 'COUNT(`' . $CNF['TABLE_CONTENT'] . '`.`cnl_id`) > 0'
  180. ];
  181. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], [
  182. 'contents_period' => [
  183. 'value' => time() - 3600 * (int)getParam($CNF['PARAM_BROWSE_TRENDING_X_HOURS']),
  184. 'field' => 'date',
  185. 'operator' => '>=',
  186. 'table' => $CNF['TABLE_CONTENT']
  187. ]
  188. ]);
  189. $this->aCurrent['rss']['link'] = 'modules/?r=channels/rss/' . $sMode;
  190. $this->aCurrent['title'] = _t('_bx_channels_page_title_browse_trending');
  191. $this->aCurrent['sorting'] = 'trending';
  192. $this->sBrowseUrl = BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']);
  193. break;
  194. case 'level':
  195. $this->aCurrent['join']['level'] = array(
  196. 'type' => 'INNER',
  197. 'table' => 'sys_labels',
  198. 'mainTable' => 'bx_cnl_data',
  199. 'mainField' => 'channel_name',
  200. 'onField' => 'value',
  201. 'joinFields' => array('value'),
  202. );
  203. $this->aCurrent['restriction']['level'] = array('value' => $aParams['level'], 'field' => 'level', 'operator' => '=', 'table' => 'sys_labels');
  204. $this->aCurrent['sorting'] = 'level';
  205. $this->sBrowseUrl = 'page.php?i=channels-toplevel';
  206. break;
  207. case '': // search results
  208. $this->sBrowseUrl = BX_DOL_SEARCH_KEYWORD_PAGE;
  209. $this->aCurrent['title'] = _t('_bx_channels');
  210. unset($this->aCurrent['paginate']['perPage'], $this->aCurrent['rss']);
  211. break;
  212. default:
  213. $this->isError = true;
  214. }
  215. if ($bProcessConditionsForPrivateContent) {
  216. $this->addConditionsForPrivateContent($CNF, $oJoinedProfile);
  217. $this->addCustomConditions($CNF, $oJoinedProfile, $sMode, $aParams);
  218. }
  219. $this->sCenterContentUnitSelector = false;
  220. }
  221. function getAlterOrder()
  222. {
  223. $aResult = [];
  224. switch ($this->aCurrent['sorting']) {
  225. case 'none':
  226. break;
  227. case 'featured':
  228. $aResult = ['order' => ' ORDER BY `bx_cnl_data`.`featured` DESC'];
  229. break;
  230. case 'recommended':
  231. $aResult = ['order' => ' ORDER BY RAND()'];
  232. break;
  233. case 'top':
  234. $aResult = ['order' => ' ORDER BY `bx_cnl_data`.`views` DESC'];
  235. break;
  236. case 'active':
  237. $aResult = ['order' => ' ORDER BY `bx_cnl_data`.`lc_date` DESC'];
  238. break;
  239. case 'trending':
  240. $aResult = ['order' => ' ORDER BY `contents_new` DESC'];
  241. break;
  242. case 'level':
  243. $aResult = ['order' => ' ORDER BY `bx_cnl_data`.`channel_name` DESC'];
  244. break;
  245. case 'last':
  246. default:
  247. $aResult = ['order' => ' ORDER BY `bx_cnl_data`.`added` DESC'];
  248. }
  249. return $aResult;
  250. }
  251. function _getPseud ()
  252. {
  253. return [
  254. 'id' => 'id',
  255. 'channel_name' => 'channel_name',
  256. 'added' => 'added',
  257. 'author' => 'author',
  258. 'picture' => 'picture',
  259. 'contents_new' => 'cnl_id_count'
  260. ];
  261. }
  262. }
  263. /** @} */