BxBaseModProfileSearchResult.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. * @defgroup BaseProfile Base classes for profile modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModProfileSearchResult extends BxBaseModGeneralSearchResult
  12. {
  13. protected $bRecommendedView = false;
  14. public function __construct($sMode = '', $aParams = array())
  15. {
  16. parent::__construct($sMode, $aParams);
  17. $this->aUnitViews = [
  18. 'unit' => 'unit_wo_cover.html',
  19. 'unit_wo_info' => 'unit_wo_info.html',
  20. 'gallery' => 'unit_with_cover.html',
  21. 'showcase' => 'unit_with_cover_showcase.html',
  22. 'showcase_wo_info' => 'unit_wo_info_showcase.html',
  23. 'simple' => 'unit_wo_links.html'
  24. ];
  25. if (!empty($aParams['unit_views']) && is_array($aParams['unit_views']))
  26. $this->aUnitViews = array_merge ($this->aUnitViews, $aParams['unit_views']);
  27. if (!empty($aParams['unit_view']))
  28. $this->sUnitViewDefault = $aParams['unit_view'];
  29. $this->sUnitTemplate = $this->aUnitViews[$this->sUnitViewDefault];
  30. $this->sCenterContentUnitSelector = '.bx-base-pofile-unit';
  31. $this->addContainerClass (array(
  32. 'bx-base-pofile-units-wrapper',
  33. 'bx-base-puw-' . str_replace('_' , '-', $this->sUnitViewDefault),
  34. 'bx-def-margin-sec-neg'
  35. ));
  36. if(in_array($this->sUnitTemplate, ['unit_wo_cover.html', 'unit_wo_info.html', 'unit_wo_info_showcase.html']))
  37. $this->removeContainerClass('bx-def-margin-sec-neg');
  38. if(in_array($this->sUnitTemplate, ['unit_with_cover_showcase.html', 'unit_wo_info_showcase.html'])) {
  39. $this->bShowcaseView = true;
  40. if($this->sUnitTemplate == 'unit_wo_info_showcase.html')
  41. $this->addContainerAttribute(array('bx-sc-group-cells' => 3));
  42. }
  43. if ($sMode == 'recommended')
  44. $this->bRecommendedView=true;
  45. }
  46. function getRssUnitImage (&$a, $sField)
  47. {
  48. $CNF = &$this->oModule->_oConfig->CNF;
  49. if(empty($sField) || empty($a[$sField]))
  50. return '';
  51. $sTranscoder = '';
  52. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']))
  53. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'];
  54. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
  55. $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
  56. else
  57. return '';
  58. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  59. if(!$oTranscoder)
  60. return '';
  61. return $oTranscoder->getFileUrl($a[$sField]);
  62. }
  63. protected function _setAccountConfirmationConditions($aParams)
  64. {
  65. $sConfirmationType = getParam('sys_account_confirmation_type');
  66. $bHideUnconfirmed = getParam('sys_account_hide_unconfirmed_accounts') == 'on';
  67. if($sConfirmationType == BX_ACCOUNT_CONFIRMATION_NONE || !$bHideUnconfirmed)
  68. return;
  69. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], array(
  70. 'account_confirmed_email' => array('value' => '', 'field' => 'email_confirmed', 'operator' => '=', 'table' => 'sys_accounts'),
  71. 'account_confirmed_phone' => array('value' => '', 'field' => 'phone_confirmed', 'operator' => '=', 'table' => 'sys_accounts'),
  72. 'account_confirmed_email_and_phone' => array('value' => '', 'field' => 'phone_confirmed` | `sys_accounts`.`email_confirmed', 'operator' => '=', 'table' => 'sys_accounts'),
  73. ));
  74. switch($sConfirmationType) {
  75. case BX_ACCOUNT_CONFIRMATION_EMAIL:
  76. $this->aCurrent['restriction']['account_confirmed_email']['value'] = 1;
  77. break;
  78. case BX_ACCOUNT_CONFIRMATION_PHONE:
  79. $this->aCurrent['restriction']['account_confirmed_phone']['value'] = 1;
  80. break;
  81. case BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE:
  82. $this->aCurrent['restriction']['account_confirmed_email']['value'] = 1;
  83. $this->aCurrent['restriction']['account_confirmed_phone']['value'] = 1;
  84. break;
  85. case BX_ACCOUNT_CONFIRMATION_EMAIL_OR_PHONE:
  86. $this->aCurrent['restriction']['account_confirmed_email_and_phone']['value'] = 1;
  87. break;
  88. }
  89. }
  90. protected function _setConnectionsConditions ($aParams)
  91. {
  92. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  93. if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
  94. return false;
  95. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  96. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  97. $a = $oConnection->getConnectionsAsCondition ($sContentType, 'id', (int)$aParams['profile'], (int)$aParams['profile2'], $isMutual);
  98. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $a['restriction']);
  99. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $a['join']);
  100. return true;
  101. }
  102. protected function _setFamiliarConnectionsConditions ($aParams)
  103. {
  104. $oConnection = isset($aParams['object']) ? BxDolConnection::getObjectInstance($aParams['object']) : false;
  105. if (!$oConnection || !isset($aParams['profile']) || !(int)$aParams['profile'])
  106. return false;
  107. $iProfile = (int)$aParams['profile'];
  108. $sContentType = isset($aParams['type']) ? $aParams['type'] : BX_CONNECTIONS_CONTENT_TYPE_CONTENT;
  109. $isMutual = isset($aParams['mutual']) ? $aParams['mutual'] : false;
  110. $aIds = $oConnection->getConnectionsAsArray($sContentType, $iProfile, false, $isMutual);
  111. $aCondition = $oConnection->getConnectionsAsCondition ($sContentType, 'id', $aIds, false, $isMutual);
  112. $this->aCurrent['distinct'] = true;
  113. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  114. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction'], [
  115. 'connected' => [
  116. 'value' => array_merge([$iProfile], $aIds),
  117. 'field' => 'id',
  118. 'operator' => 'not in',
  119. ]
  120. ]);
  121. return true;
  122. }
  123. protected function _setConditionsForRecommended ()
  124. {
  125. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  126. $a = $oConnection->getConnectedContentAsSQLPartsExt ($this->aCurrent['table'], '', '');
  127. $aTmp = array(
  128. 'recommended' => array(
  129. 'type' => 'LEFT',
  130. 'table' => $a['join']['table'],
  131. 'mainField' => 'id` AND ' . bx_get_logged_profile_id() . ' = `' . $a['join']['table'] . '`.`initiator',
  132. 'onField' => 'content',
  133. 'joinFields' => array(),
  134. )
  135. );
  136. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aTmp);
  137. if (isset($this->aCurrent['restriction_sql']))
  138. $this->aCurrent['restriction_sql'] .= ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  139. else
  140. $this->aCurrent['restriction_sql'] = ' AND `' . $a['join']['table'] . '`.`initiator` IS NULL AND ' . bx_get_logged_profile_id() . ' <> `sys_profiles`.`id` ' ;
  141. }
  142. protected function _setAclConditions ($aParams)
  143. {
  144. $oAcl = BxDolAcl::getInstance();
  145. if(!$oAcl || empty($aParams['level']))
  146. return false;
  147. if(!is_array($aParams['level']))
  148. $aParams['level'] = array($aParams['level']);
  149. $this->aCurrent['title'] = array();
  150. foreach($aParams['level'] as $iLevelId) {
  151. $aInfo = $oAcl->getMembershipInfo($iLevelId);
  152. if(empty($aInfo) || !is_array($aInfo))
  153. continue;
  154. $this->aCurrent['title'][] = _t($aInfo['name']);
  155. }
  156. $aCondition = $oAcl->getContentByLevelAsCondition('id', $aParams['level']);
  157. $this->aCurrent['restriction_sql'] = (!empty($this->aCurrent['restriction_sql']) ? $this->aCurrent['restriction_sql'] : '') . $aCondition['restriction_sql'];
  158. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aCondition['restriction']);
  159. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aCondition['join']);
  160. return true;
  161. }
  162. protected function _setFavoriteConditions($sMode, $aParams, &$oProfileAuthor)
  163. {
  164. $CNF = &$this->oModule->_oConfig->CNF;
  165. $oProfileAuthor = BxDolProfile::getInstance((int)$aParams['user']);
  166. if(!$oProfileAuthor)
  167. return false;
  168. $iListId = 0;
  169. if(isset($aParams['list_id']))
  170. $iListId = (int)$aParams['list_id'];
  171. $iProfileAuthor = $oProfileAuthor->id();
  172. $oFavorite = $this->oModule->getObjectFavorite();
  173. if(!$oFavorite->isPublic() && $iProfileAuthor != bx_get_logged_profile_id())
  174. return false;
  175. $aConditions = $oFavorite->getConditionsTrack($CNF['TABLE_ENTRIES'], 'id', $iProfileAuthor, $iListId);
  176. if(!empty($aConditions) && is_array($aConditions)) {
  177. if(empty($this->aCurrent['restriction']) || !is_array($this->aCurrent['restriction']))
  178. $this->aCurrent['restriction'] = array();
  179. $this->aCurrent['restriction'] = array_merge($this->aCurrent['restriction'], $aConditions['restriction']);
  180. if(empty($this->aCurrent['join']) || !is_array($this->aCurrent['join']))
  181. $this->aCurrent['join'] = array();
  182. $this->aCurrent['join'] = array_merge($this->aCurrent['join'], $aConditions['join']);
  183. }
  184. $this->sBrowseUrl = 'page.php?i=' . $CNF['URI_VIEW_FAVORITES'] . '&profile_id={profile_id}';
  185. $this->aCurrent['title'] = _t($CNF['T']['txt_browse_favorites']);
  186. $this->aCurrent['rss']['link'] = 'modules/?r=' . $this->oModule->_oConfig->getUri() . '/rss/' . $sMode . '/' . $iProfileAuthor;
  187. return true;
  188. }
  189. function decodeData ($a)
  190. {
  191. $CNF = $this->oModule->_oConfig->CNF;
  192. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_VIEW']);
  193. $bPrivacy = $oPrivacy !== false;
  194. $oMetaMenu = !empty($CNF['OBJECT_MENU_SNIPPET_META']) ? BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this->oModule->_oTemplate) : false;
  195. $bMetaMenu = $oMetaMenu !== false;
  196. $oContentInfo = $this->getContentInfoObject();
  197. foreach ($a as $i => $r) {
  198. if (isset($r['author']))
  199. $a[$i]['author_data'] = BxDolProfile::getData($r[$CNF['FIELD_AUTHOR']]);
  200. $a[$i]['url'] = $this->decodeDataUrl($oContentInfo, $r);
  201. $a[$i]['image'] = $oContentInfo->getContentThumb($r['id']);
  202. $a[$i]['cover'] = $oContentInfo->getContentCover($r['id']);
  203. $a[$i]['summary_plain'] = $this->decodeDataSummaryPlain($oContentInfo, $r);
  204. if($bMetaMenu) {
  205. $bPublic = !$bPrivacy || $oPrivacy->check($r[$CNF['FIELD_ID']]) || $oPrivacy->isPartiallyVisible($r[$CNF['FIELD_ALLOW_VIEW_TO']]);
  206. $oMetaMenu->setContentId($r['id']);
  207. $oMetaMenu->setContentPublic($bPublic);
  208. $a[$i]['meta'] = $oMetaMenu->getCodeAPI();
  209. }
  210. }
  211. return $a;
  212. }
  213. function getItemPerPageInShowCase ()
  214. {
  215. $iPerPageInShowCase = parent::getItemPerPageInShowCase();
  216. $CNF = &$this->oModule->_oConfig->CNF;
  217. if ($this->bRecommendedView && isset($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED'])){
  218. $iPerPageInShowCase = getParam($CNF['PARAM_PER_PAGE_BROWSE_RECOMMENDED']);
  219. }
  220. return $iPerPageInShowCase;
  221. }
  222. function displayResultBlock ()
  223. {
  224. $this->oModule->_oTemplate->addJs(array('modules/base/profile/js/|searchresult.js'));
  225. return parent::displayResultBlock ();
  226. }
  227. }
  228. /** @} */