BxBaseServiceProfiles.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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 UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * System service for profiles handling functionality.
  11. */
  12. class BxBaseServiceProfiles extends BxDol
  13. {
  14. protected $_bIsApi;
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. $this->_bIsApi = bx_is_api();
  19. }
  20. public function serviceGetProfileTypes()
  21. {
  22. $aTypes = array(
  23. '' => _t('_Select_one')
  24. );
  25. $aModules = $this->_getProfilesModules();
  26. foreach($aModules as $aModule) {
  27. if(empty($aModule) || !is_array($aModule))
  28. continue;
  29. $sTitleKey = '_' . $aModule['name'];
  30. $sTitle = _t($sTitleKey);
  31. $aTypes[$aModule['name']] = !empty($sTitle) && $sTitle != $sTitleKey ? $sTitle : $aModule['title'];
  32. }
  33. return $aTypes;
  34. }
  35. public function serviceProfileAvatar ($iProfileId = 0)
  36. {
  37. if (!$iProfileId && !($iProfileId = bx_get_logged_profile_id()))
  38. return '';
  39. $oProfile = BxDolProfile::getInstance($iProfileId);
  40. if(!$oProfile)
  41. return '';
  42. if(bx_is_api())
  43. return [
  44. bx_api_get_block ('profile_avatar', $oProfile->getData())
  45. ];
  46. $oTemplate = BxDolTemplate::getInstance();
  47. $sSwitcher = '';
  48. $aSwitcher = bx_srv('system', 'account_profile_switcher', array(false, null, '', true), 'TemplServiceProfiles');
  49. if($aSwitcher !== false)
  50. $sSwitcher = BxTemplFunctions::getInstance()->popupBox('bx-profile-switcher', _t('_sys_txt_switch_profiles'), $oTemplate->parseHtmlByName('profile_avatar_switcher.html', array(
  51. 'profile_switcher' => $aSwitcher['content'],
  52. 'bx_if:multiple_profiles_mode' => array(
  53. 'condition' => empty($aSwitcher['content']) || BxDolAccount::isAllowedCreateMultiple($oProfile->id()),
  54. 'content' => array(
  55. 'url_switch_profile' => BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher')
  56. )
  57. )
  58. )), true);
  59. $bSwitcher = !empty($sSwitcher);
  60. $sSwitcherUrl = $bSwitcher ? 'javascript:void(0)' : $sUrl;
  61. $sSwitcherOnclick = $bSwitcher ? "javascript:$('#bx-profile-switcher').dolPopup({});" : "";
  62. $sDisplayName = $oProfile->getDisplayName();
  63. $sUrl = $oProfile->getUrl();
  64. $oAcl = BxDolAcl::getInstance();
  65. $aAcl = $oAcl->getMemberMembershipInfo($iProfileId);
  66. $aAclInfo = $oAcl->getMembershipInfo($aAcl['id']);
  67. list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getIcon($aAclInfo['icon']);
  68. $aVars = array(
  69. 'profile_id' => $oProfile->id(),
  70. 'profile_url' => $sUrl,
  71. 'profile_edit_url' => $oProfile->getEditUrl(),
  72. 'profile_title' => $sDisplayName,
  73. 'profile_title_attr' => bx_html_attribute($sDisplayName),
  74. 'profile_ava_url' => $oProfile->getAvatar(),
  75. 'profile_unit' => $oProfile->getUnit(0, array('template' => array(
  76. 'name' => 'unit_wo_info_links',
  77. 'size' => 'thumb'
  78. ))),
  79. 'profile_acl_title' => _t($aAclInfo['name']),
  80. 'bx_if:image' => array (
  81. 'condition' => (bool)$sIconUrl,
  82. 'content' => array('icon_url' => $sIconUrl),
  83. ),
  84. 'bx_if:image_inline' => array (
  85. 'condition' => false,
  86. 'content' => array('image' => ''),
  87. ),
  88. 'bx_if:icon' => array (
  89. 'condition' => (bool)$sIcon,
  90. 'content' => array('icon' => $sIcon),
  91. ),
  92. 'bx_if:icon-a' => array (
  93. 'condition' => (bool)$sIconA,
  94. 'content' => array('icon-a' => $sIconA),
  95. ),
  96. 'bx_if:icon-html' => array (
  97. 'condition' => (bool)$sIconHtml,
  98. 'content' => array('icon' => $sIconHtml),
  99. ),
  100. 'switcher_url' => $sSwitcherUrl,
  101. 'switcher_onclick' => $sSwitcherOnclick,
  102. 'bx_if:show_switcher_icon' => array(
  103. 'condition' => $bSwitcher,
  104. 'content' => array(
  105. 'switcher_url' => $sSwitcherUrl,
  106. 'switcher_onclick' => $bSwitcher ? "javascript:$('#bx-profile-switcher').dolPopup({});" : "",
  107. )
  108. ),
  109. 'switcher' => $sSwitcher
  110. );
  111. return $oTemplate->parseHtmlByName('profile_avatar.html', $aVars);
  112. }
  113. public function serviceProfileMenu ($iProfileId = 0)
  114. {
  115. if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_stats')) !== false) {
  116. if(bx_is_api())
  117. return [
  118. bx_api_get_block ('profile_menu', $oMenu->getCodeAPI())
  119. ];
  120. return $oMenu->getCode();
  121. }
  122. else
  123. return '';
  124. }
  125. public function serviceProfileFollowings ($iProfileId = 0)
  126. {
  127. if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_followings')) !== false)
  128. return $oMenu->getCode();
  129. else
  130. return '';
  131. }
  132. public function serviceBefriend ($sParams)
  133. {
  134. $aParams = json_decode($sParams, true);
  135. $iProfileId = $aParams['profile_id'];
  136. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  137. $oProfile = BxDolProfile::getInstance($iProfileId);
  138. if ($aParams['action'] == 'info'){
  139. return ['profile' => BxDolProfile::getData($iProfileId), 'result' => $oConnection->isConnected((int)bx_get_logged_profile_id(), $iProfileId, true)];
  140. }
  141. if ($oProfile && $oConnection){
  142. if ($oConnection->isConnected((int)bx_get_logged_profile_id(), $iProfileId, true)){
  143. return ['profile' => BxDolProfile::getData($iProfileId), 'result' => false];
  144. }
  145. else{
  146. $oConnection->addConnection((int)bx_get_logged_profile_id(), $iProfileId);
  147. $oConnection->addConnection($iProfileId, (int)bx_get_logged_profile_id());
  148. $oProfile = BxDolProfile::getInstance($iProfileId);
  149. return ['profile' => BxDolProfile::getData($iProfileId), 'result' => true];
  150. }
  151. }
  152. }
  153. public function serviceProfileStats ($iProfileId = 0)
  154. {
  155. if (!$iProfileId && !($iProfileId = bx_get_logged_profile_id()))
  156. return '';
  157. $oProfile = BxDolProfile::getInstance($iProfileId);
  158. if(!$oProfile)
  159. return '';
  160. $oMenu = BxDolMenu::getObjectInstance('sys_profile_stats');
  161. if(!$oMenu)
  162. return '';
  163. if(bx_is_api())
  164. return [
  165. bx_api_get_block ('profile_avatar', $oProfile->getData(), ['id' => 1]),
  166. bx_api_get_block ('profile_menu', $oMenu->getCodeAPI(), ['id' => 2])
  167. ];
  168. $oAcl = BxDolAcl::getInstance();
  169. $aAcl = $oAcl->getMemberMembershipInfo($iProfileId);
  170. $aAclInfo = $oAcl->getMembershipInfo($aAcl['id']);
  171. list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getIcon($aAclInfo['icon']);
  172. $aVars = array(
  173. 'profile_id' => $oProfile->id(),
  174. 'profile_url' => $oProfile->getUrl(),
  175. 'profile_edit_url' => $oProfile->getEditUrl(),
  176. 'profile_title' => $oProfile->getDisplayName(),
  177. 'profile_title_attr' => bx_html_attribute($oProfile->getDisplayName()),
  178. 'profile_ava_url' => $oProfile->getAvatar(),
  179. 'profile_unit' => $oProfile->getUnit(0, array('template' => array(
  180. 'name' => 'unit_wo_info',
  181. 'size' => 'ava'
  182. ))),
  183. 'profile_acl_title' => _t($aAclInfo['name']),
  184. 'menu' => $oMenu->getCode(),
  185. );
  186. $aVars['bx_if:image'] = array (
  187. 'condition' => (bool)$sIconUrl,
  188. 'content' => array('icon_url' => $sIconUrl),
  189. );
  190. $aVars['bx_if:image_inline'] = array (
  191. 'condition' => false,
  192. 'content' => array('image' => ''),
  193. );
  194. $aVars['bx_if:icon'] = array (
  195. 'condition' => (bool)$sIcon,
  196. 'content' => array('icon' => $sIcon),
  197. );
  198. $aVars['bx_if:icon-html'] = array (
  199. 'condition' => (bool)$sIconHtml,
  200. 'content' => array('icon' => $sIconHtml),
  201. );
  202. $aVars['bx_if:icon-a'] = array (
  203. 'condition' => (bool)$sIconA,
  204. 'content' => array('icon-a' => $sIconA),
  205. );
  206. return BxDolTemplate::getInstance()->parseHtmlByName('profile_stats.html', $aVars);
  207. }
  208. public function serviceGetMenuAddonProfileEdit($iProfileId = 0, $sCaption = '')
  209. {
  210. /**
  211. * Disabled.
  212. */
  213. return '';
  214. if(empty($sCaption))
  215. $sCaption = _t('_Edit');
  216. $oProfile = BxDolProfile::getInstance($iProfileId);
  217. if(!$oProfile)
  218. return '';
  219. $sModule = $oProfile->getModule();
  220. $sMethod = 'profile_edit_url';
  221. if(!BxDolRequest::serviceExists($sModule, $sMethod))
  222. return '';
  223. return BxDolTemplate::getInstance()->parseLink(BxDolService::call($sModule, $sMethod, array($oProfile->getContentId())), $sCaption);
  224. }
  225. public function serviceGetMenuAddonProfileConnections($iProfileId = 0)
  226. {
  227. $oProfile = BxDolProfile::getInstance($iProfileId);
  228. if(!$oProfile)
  229. return '';
  230. $iCount = 0;
  231. //--- Add friend requests.
  232. $iCount += (int)bx_srv('system', 'get_unconfirmed_connections_num', ['sys_profiles_friends'], 'TemplServiceConnections');
  233. //--- Add subscriptions.
  234. $iCount += (int)bx_srv('system', 'get_connected_content_num', ['sys_profiles_subscriptions'], 'TemplServiceConnections');
  235. //--- Add subscribed me.
  236. $iCount += (int)bx_srv('system', 'get_connected_initiators_num', ['sys_profiles_subscriptions'], 'TemplServiceConnections');
  237. return $iCount > 0 ? $iCount : '';
  238. }
  239. /**
  240. * @page service Service Calls
  241. * @section bx_system_general System Services
  242. * @subsection bx_system_general-profiles Profiles
  243. * @subsubsection bx_system_general-profile_membership profile_membership
  244. *
  245. * @code bx_srv('system', 'profile_membership', [2], 'TemplServiceProfiles'); @endcode
  246. * @code {{~system:profile_membership:TemplServiceProfiles[2]~}} @endcode
  247. *
  248. * Get membership level for specified profile.
  249. * @param $iProfileId profile ID
  250. *
  251. * @see BxBaseServiceProfiles::serviceProfileMembership
  252. */
  253. /**
  254. * @ref bx_system_general-profile_membership "profile_membership"
  255. */
  256. public function serviceProfileMembership ($iProfileId = 0)
  257. {
  258. if (!$iProfileId)
  259. $iProfileId = bx_get_logged_profile_id();
  260. return BxDolAcl::getInstance()->getProfileMembership($iProfileId);
  261. }
  262. public function serviceProfileMembershipStats ($iProfileId = 0)
  263. {
  264. if(!$iProfileId)
  265. $iProfileId = bx_get_logged_profile_id();
  266. $sTxtUnlimited = _t('_unlimited');
  267. $sTxtFiles = _t('_sys_storage_files');
  268. $aQuota = BxDolProfileQuery::getInstance()->getProfileQuota($iProfileId);
  269. $aTmplVarsStats = array();
  270. if(!empty($aQuota['quota_size'])) {
  271. $iWidth = (int)round(100 * $aQuota['current_size']/$aQuota['quota_size']);
  272. $sPercent = $iWidth . '%';
  273. }
  274. else {
  275. $iWidth = 0;
  276. $sPercent = $sTxtUnlimited;
  277. }
  278. $aTmplVarsStats[] = array('title' => _t('_sys_profile_storage_quota_size'), 'width' => $iWidth, 'value' => _t_format_size($aQuota['current_size']), 'percent' => $sPercent);
  279. if(!empty($aQuota['quota_number'])) {
  280. $iWidth = (int)round(100 * $aQuota['current_number']/$aQuota['quota_number']);
  281. $sPercent = $iWidth . '%';
  282. }
  283. else {
  284. $iWidth = 0;
  285. $sPercent = $sTxtUnlimited;
  286. }
  287. $aTmplVarsStats[] = array('title' => _t('_sys_profile_storage_quota_number'), 'width' => $iWidth, 'value' => $aQuota['current_number'] . ' ' . $sTxtFiles, 'percent' => $sPercent);
  288. return BxDolTemplate::getInstance()->parseHtmlByName('profile_membership_stats.html', array(
  289. 'membership' => BxDolAcl::getInstance()->getProfileMembership($iProfileId),
  290. 'bx_repeat:stat_items' => $aTmplVarsStats
  291. ));
  292. }
  293. /**
  294. * @page service Service Calls
  295. * @section bx_system_general System Services
  296. * @subsection bx_system_general-profiles Profiles
  297. * @subsubsection bx_system_general-profile_notifications profile_notifications
  298. *
  299. * @code bx_srv('system', 'profile_notifications', [], 'TemplServiceProfiles'); @endcode
  300. * @code {{~system:profile_notifications:TemplServiceProfiles~}} @endcode
  301. *
  302. * Get number of unread notifications for logged in profile
  303. *
  304. * @see BxBaseServiceProfiles::serviceProfileNotifications
  305. */
  306. /**
  307. * @ref bx_system_general-profile_notifications "profile_notifications"
  308. */
  309. public function serviceProfileNotifications ($iProfileId = 0)
  310. {
  311. if (!$iProfileId)
  312. $iProfileId = bx_get_logged_profile_id();
  313. $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications');
  314. if(!$oMenu)
  315. return 0;
  316. $iNum = 0;
  317. $aMenuItems = $oMenu->getMenuItems ();
  318. foreach ($aMenuItems as $r) {
  319. if (isset($r['bx_if:addon']) && $r['bx_if:addon']['condition'])
  320. $iNum += $r['bx_if:addon']['content']['addon'];
  321. }
  322. return $iNum;
  323. }
  324. /**
  325. * @page service Service Calls
  326. * @section bx_system_general System Services
  327. * @subsection bx_system_general-profiles Profiles
  328. * @subsubsection bx_system_general-get_count_online_profiles get_count_online_profiles
  329. *
  330. * @code bx_srv('system', 'get_count_online_profiles', [], 'TemplServiceProfiles'); @endcode
  331. * @code {{~system:get_count_online_profiles:TemplServiceProfiles~}} @endcode
  332. *
  333. * Get number of online profiles
  334. *
  335. * @see BxBaseServiceProfiles::serviceGetCountOnlineProfiles
  336. */
  337. /**
  338. * @ref bx_system_general-get_count_online_profiles "get_count_online_profiles"
  339. */
  340. public function serviceGetCountOnlineProfiles ()
  341. {
  342. $oProfilesQuery = BxDolProfileQuery::getInstance();
  343. return $oProfilesQuery->getOnlineCount();
  344. }
  345. public function serviceGetProfilesModules ($bForceActAsProfile = true)
  346. {
  347. if (getParam('sys_db_cache_enable')) { // get list of profiles modules from db cache, cache is invalidated when new module is installed
  348. $oDb = BxDolDb::getInstance();
  349. $oCache = $oDb->getDbCacheObject ();
  350. $sKey = $oDb->genDbCacheKey('profiles_' . (!$bForceActAsProfile ? 'all_' : '') . 'modules_array');
  351. $sKeyTs = $oDb->genDbCacheKey('profiles_modules_ts');
  352. $mixedRetTs = $oCache->getData($sKeyTs);
  353. $mixedRet = $oCache->getData($sKey);
  354. $iNewestModuleTs = $this->_getLatestModuleTimestamp ();
  355. if ($mixedRetTs != null && $mixedRet !== null && $mixedRetTs == $iNewestModuleTs) {
  356. $aModulesArray = $mixedRet;
  357. } else {
  358. $aModulesArray = $this->_getProfilesModules ($bForceActAsProfile);
  359. $oCache->setData($sKey, $aModulesArray);
  360. $oCache->setData($sKeyTs, $iNewestModuleTs);
  361. }
  362. } else {
  363. $aModulesArray = $this->_getProfilesModules ($bForceActAsProfile);
  364. }
  365. return $aModulesArray;
  366. }
  367. public function serviceProfilesFriends ($iLimit = 20)
  368. {
  369. if (!($iProfileId = bx_get_logged_profile_id()))
  370. return array();
  371. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  372. if (!$oConnection)
  373. return array();
  374. if (!($a = $oConnection->getConnectedContent ($iProfileId, true, 0, $iLimit)))
  375. return array();
  376. $aRet = array();
  377. foreach ($a as $iId) {
  378. $oProfile = BxDolProfile::getInstance($iId);
  379. $aRet[] = array (
  380. 'label' => $oProfile->getDisplayName(),
  381. 'value' => $iId,
  382. 'url' => $oProfile->getUrl(),
  383. 'thumb' => $oProfile->getThumb(),
  384. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  385. );
  386. }
  387. return $aRet;
  388. }
  389. public function serviceProfilesSearch ($sTerm, $mixedParems = [])
  390. {
  391. $iLimit = (int)getParam('sys_profiles_search_limit');
  392. if(is_int($mixedParems))
  393. $iLimit = (int)$mixedParems;
  394. else if(is_array($mixedParems) && isset($mixedParems['limit']))
  395. $iLimit = (int)$mixedParems['limit'];
  396. // display friends by default
  397. if (!$sTerm)
  398. return $this->serviceProfilesFriends($iLimit);
  399. // get list of "profiles" modules
  400. $aModules = $this->serviceGetProfilesModules();
  401. // search in each module
  402. $a = array();
  403. foreach ($aModules as $aModule) {
  404. if (!BxDolService::call($aModule['name'], 'act_as_profile'))
  405. continue;
  406. $a = array_merge($a, BxDolService::call($aModule['name'], 'profiles_search', array($sTerm, getParam('sys_per_page_search_keyword_single'))));
  407. }
  408. // sort result
  409. usort($a, function($r1, $r2) {
  410. return strcmp($r1['label'], $r2['label']);
  411. });
  412. /**
  413. * @hooks
  414. * @hookdef hook-system-profiles_search_by_location 'system', 'profiles_search_by_location' - hook on serach profiles by location
  415. * - $unit_name - equals `system`
  416. * - $action - equals `profiles_search_by_location`
  417. * - $object_id - not used
  418. * - $sender_id - not used
  419. * - $extra_params - array of additional params with the following array keys:
  420. * - `module` - [string] module name
  421. * - `term` - [string] term for searching
  422. * - `result` - [array] by ref, array of results, can be overridden in hook processing
  423. * @hook @ref hook-account-profiles_search_by_location
  424. */
  425. bx_alert('system', 'profiles_search', 0, 0, array(
  426. 'module' => is_array($mixedParems) && isset($mixedParems['module']) ? $mixedParems['module'] : '',
  427. 'term' => $sTerm,
  428. 'result' => &$a
  429. ));
  430. // return as array
  431. return array_slice($a, 0, $iLimit);
  432. }
  433. public function serviceProfilesSearchByLocation ($aLocation, $iRadius, $mixedParems = [])
  434. {
  435. $sModule = !empty($mixedParems['module']) ? $mixedParems['module'] : '';
  436. $aModules = !empty($sModule) ? [BxDolModuleDb::getInstance()->getModuleByName($sModule)] : $this->serviceGetProfilesModules();
  437. $iStart = 0;
  438. $iLimit = 20;
  439. if(is_int($mixedParems))
  440. $iLimit = (int)$mixedParems;
  441. else if(is_array($mixedParems) && isset($mixedParems['limit']))
  442. $iLimit = (int)$mixedParems['limit'];
  443. $aLocation[] = $iRadius;
  444. $oProfileQuery = BxDolProfileQuery::getInstance();
  445. $aResult = [];
  446. foreach($aModules as $aModule) {
  447. if(!bx_srv($aModule['name'], 'act_as_profile'))
  448. continue;
  449. $aContentIds = bx_srv($aModule['name'], 'get_search_result_extended', [[
  450. 'location' => ['type' => 'location_radius', 'operator' => 'locate', 'value' => [
  451. 'array' => $aLocation
  452. ]]
  453. ], $iStart, $iLimit]);
  454. $aResult = array_merge($aResult, $oProfileQuery->getProfiles(['type' => 'id_by_module_content_id', 'module' => $aModule['name'], 'content_id' => $aContentIds]));
  455. }
  456. /**
  457. * @hooks
  458. * @hookdef hook-system-profiles_search_by_location 'system', 'profiles_search_by_location' - hook on serach profiles by location
  459. * - $unit_name - equals `system`
  460. * - $action - equals `profiles_search_by_location`
  461. * - $object_id - not used
  462. * - $sender_id - not used
  463. * - $extra_params - array of additional params with the following array keys:
  464. * - `module` - [string] module name
  465. * - `location` - [array] location's info
  466. * - `radius` - [int] radius for search
  467. * - `result` - [array] by ref, array of results, can be overridden in hook processing
  468. * @hook @ref hook-account-profiles_search_by_location
  469. */
  470. bx_alert('system', 'profiles_search_by_location', 0, 0, [
  471. 'module' => $sModule,
  472. 'location' => $aLocation,
  473. 'radius' => $iRadius,
  474. 'result' => &$aResult
  475. ]);
  476. return array_slice($aResult, 0, $iLimit);
  477. }
  478. public function serviceProfilesList ($iAccountId = 0)
  479. {
  480. $oProfilesQuery = BxDolProfileQuery::getInstance();
  481. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  482. if (!$aProfiles)
  483. return false;
  484. $s = '';
  485. foreach ($aProfiles as $aProfile)
  486. if ($aProfile['type'] != 'system')
  487. $s .= BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id']));
  488. if (!$s)
  489. $s = MsgBox(_t('_sys_txt_empty'));
  490. return $s . '<div class="bx-clear"></div>';
  491. }
  492. public function serviceBrowseFriends ($iProfileId = 0, $aParams = [])
  493. {
  494. if($this->_bIsApi)
  495. $aParams = bx_api_get_browse_params($aParams);
  496. if(!$iProfileId)
  497. $iProfileId = bx_get_logged_profile_id();
  498. if(!$iProfileId)
  499. return '';
  500. $aParams = array_merge([
  501. 'params' => false,
  502. 'design_box' => BX_DB_PADDING_DEF,
  503. 'empty_message' => false,
  504. 'ajax_paginate' => true,
  505. ], $aParams);
  506. $aParamsBrowse = ['profile' => $iProfileId];
  507. if(!empty($aParams['params']) && is_array($aParams['params']))
  508. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  509. return $this->_serviceBrowseConnections('friends', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  510. }
  511. public function serviceProfileFriendsRequestsCount ($iProfileId = 0)
  512. {
  513. if(!$iProfileId)
  514. $iProfileId = bx_get_logged_profile_id();
  515. if(!$iProfileId)
  516. return '';
  517. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  518. if(!$oConnection)
  519. return false;
  520. return $oConnection->getConnectedInitiatorsCount($iProfileId, false) - $oConnection->getConnectedInitiatorsCount($iProfileId, true);
  521. }
  522. public function serviceProfileSentFriendsRequestsCount ($iProfileId = 0)
  523. {
  524. if(!$iProfileId)
  525. $iProfileId = bx_get_logged_profile_id();
  526. if(!$iProfileId)
  527. return '';
  528. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  529. if(!$oConnection)
  530. return false;
  531. return $oConnection->getConnectedContentCount($iProfileId, false) - $oConnection->getConnectedContentCount($iProfileId, true);
  532. }
  533. public function serviceProfileFriendsCount ($iProfileId = 0)
  534. {
  535. if(!$iProfileId)
  536. $iProfileId = bx_get_logged_profile_id();
  537. if(!$iProfileId)
  538. return '';
  539. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  540. if(!$oConnection)
  541. return false;
  542. return $oConnection->getConnectedInitiatorsCount($iProfileId, true);
  543. }
  544. public function serviceProfileFollowersCount ($iProfileId = 0)
  545. {
  546. if(!$iProfileId)
  547. $iProfileId = bx_get_logged_profile_id();
  548. if(!$iProfileId)
  549. return '';
  550. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  551. if(!$oConnection)
  552. return false;
  553. return $oConnection->getConnectedInitiatorsCount($iProfileId);
  554. }
  555. public function serviceProfileFollowingCount ($iProfileId = 0, $bProfilesOnly = false)
  556. {
  557. if(!$iProfileId)
  558. $iProfileId = bx_get_logged_profile_id();
  559. if(!$iProfileId)
  560. return '';
  561. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  562. if(!$oConnection)
  563. return false;
  564. if(!$bProfilesOnly)
  565. return $oConnection->getConnectedContentCount($iProfileId);
  566. $aProfileModules = bx_srv('system', 'get_modules_by_type', ['profile']);
  567. $aProfileModulesNames = array_map(function($item) {
  568. return $item['name'];
  569. }, $aProfileModules);
  570. return $oConnection->getConnectedContentCountExt($iProfileId, false, ['by_type' => $aProfileModulesNames]);
  571. }
  572. public function serviceProfileRecommendationFollowingCount ($iProfileId = 0, $aParams = [])
  573. {
  574. if(!$iProfileId)
  575. $iProfileId = bx_get_logged_profile_id();
  576. if(!$iProfileId)
  577. return '';
  578. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_subscriptions');
  579. if(!$oRecommendation)
  580. return false;
  581. $aModules = bx_srv('system', 'get_modules_by_type', ['profile', ['name_as_key' => true]]);
  582. return $oRecommendation->getCount($iProfileId, array_merge([
  583. 'type' => !empty($aModules) && is_array($aModules) ? array_keys($aModules) : '',
  584. ], $aParams));
  585. }
  586. public function serviceProfileRecommendationFriendsCount ($iProfileId = 0, $aParams = [])
  587. {
  588. if(!$iProfileId)
  589. $iProfileId = bx_get_logged_profile_id();
  590. if(!$iProfileId)
  591. return '';
  592. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_friends');
  593. if(!$oRecommendation)
  594. return false;
  595. return $oRecommendation->getCount($iProfileId, $aParams);
  596. }
  597. public function serviceBrowseFriendRequests ($iProfileId = 0, $aParams = [])
  598. {
  599. if($this->_bIsApi)
  600. $aParams = bx_api_get_browse_params($aParams);
  601. if(!$iProfileId)
  602. $iProfileId = bx_get_logged_profile_id();
  603. if(!$iProfileId)
  604. return '';
  605. $aParams = array_merge([
  606. 'params' => false,
  607. 'design_box' => BX_DB_PADDING_DEF,
  608. 'empty_message' => false,
  609. 'ajax_paginate' => true,
  610. ], $aParams);
  611. $aParamsBrowse = ['profile' => $iProfileId];
  612. if(!empty($aParams['params']) && is_array($aParams['params']))
  613. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  614. return $this->_serviceBrowseConnections('friend_requests', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  615. }
  616. public function serviceBrowseFriendRequested ($iProfileId = 0, $aParams = [])
  617. {
  618. if($this->_bIsApi)
  619. $aParams = bx_api_get_browse_params($aParams);
  620. if(!$iProfileId)
  621. $iProfileId = bx_get_logged_profile_id();
  622. if(!$iProfileId)
  623. return '';
  624. $aParams = array_merge([
  625. 'params' => false,
  626. 'design_box' => BX_DB_PADDING_DEF,
  627. 'empty_message' => false,
  628. 'ajax_paginate' => true,
  629. ], $aParams);
  630. $aParamsBrowse = ['profile' => $iProfileId];
  631. if(!empty($aParams['params']) && is_array($aParams['params']))
  632. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  633. return $this->_serviceBrowseConnections('friend_requested', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  634. }
  635. public function serviceBrowseSubscriptions ($iProfileId = 0, $aParams = [])
  636. {
  637. if($this->_bIsApi)
  638. $aParams = bx_api_get_browse_params($aParams);
  639. if(!$iProfileId)
  640. $iProfileId = bx_get_logged_profile_id();
  641. if(!$iProfileId)
  642. return '';
  643. $aParams = array_merge([
  644. 'params' => false,
  645. 'design_box' => BX_DB_PADDING_DEF,
  646. 'empty_message' => false,
  647. 'ajax_paginate' => true,
  648. ], $aParams);
  649. $aParamsBrowse = ['profile' => $iProfileId];
  650. if(!empty($aParams['params']) && is_array($aParams['params']))
  651. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  652. return $this->_serviceBrowseConnections('subscriptions', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  653. }
  654. public function serviceBrowseSubscribedMe ($iProfileId = 0, $aParams = [])
  655. {
  656. if($this->_bIsApi)
  657. $aParams = bx_api_get_browse_params($aParams);
  658. if(!$iProfileId)
  659. $iProfileId = bx_get_logged_profile_id();
  660. if(!$iProfileId)
  661. return '';
  662. $aParams = array_merge([
  663. 'params' => false,
  664. 'design_box' => BX_DB_PADDING_DEF,
  665. 'empty_message' => false,
  666. 'ajax_paginate' => true,
  667. ], $aParams);
  668. $aParamsBrowse = ['profile' => $iProfileId];
  669. if(!empty($aParams['params']) && is_array($aParams['params']))
  670. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  671. return $this->_serviceBrowseConnections('subscribed_me', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  672. }
  673. public function serviceBrowseMembers($iProfileId, $sObject, $aParams = [])
  674. {
  675. if($this->_bIsApi)
  676. $aParams = bx_api_get_browse_params($aParams);
  677. if(!$iProfileId)
  678. $iProfileId = bx_get_logged_profile_id();
  679. if(!$iProfileId)
  680. return '';
  681. $aParams = array_merge([
  682. 'params' => false,
  683. 'design_box' => BX_DB_PADDING_DEF,
  684. 'empty_message' => false,
  685. 'ajax_paginate' => true,
  686. ], $aParams);
  687. $aParamsBrowse = [
  688. 'profile' => $iProfileId,
  689. 'object' => $sObject
  690. ];
  691. if(!empty($aParams['params']) && is_array($aParams['params']))
  692. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  693. return $this->_serviceBrowseConnections('members', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  694. }
  695. public function serviceBrowseConnections ($iProfileId = 0, $aParams = [])
  696. {
  697. if($this->_bIsApi)
  698. $aParams = bx_api_get_browse_params($aParams);
  699. if(!$iProfileId)
  700. $iProfileId = bx_get_logged_profile_id();
  701. if(!$iProfileId)
  702. return '';
  703. $aParams = array_merge([
  704. 'params' => false,
  705. 'design_box' => BX_DB_PADDING_DEF,
  706. 'empty_message' => false,
  707. 'ajax_paginate' => true,
  708. ], $aParams);
  709. $aParamsBrowse = [
  710. 'profile' => $iProfileId,
  711. 'object' => 'sys_profiles_friends',
  712. 'type' => 'content',
  713. 'mutual' => false,
  714. 'profile2' => 0
  715. ];
  716. if(!empty($aParams['params']) && is_array($aParams['params']))
  717. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  718. return $this->_serviceBrowseConnections('connections', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  719. }
  720. public function serviceBrowseRecommendationsFriends ($iProfileId = 0, $aParams = [])
  721. {
  722. if($this->_bIsApi)
  723. $aParams = bx_api_get_browse_params($aParams, true);
  724. if(!$iProfileId)
  725. $iProfileId = bx_get_logged_profile_id();
  726. if(!$iProfileId)
  727. return '';
  728. $aParams = array_merge([
  729. 'empty_message' => false,
  730. 'start' => 0,
  731. 'per_page' => 0
  732. ], $aParams);
  733. if(($iStartGet = bx_get('start')) !== false)
  734. $aParams['start'] = (int)$iStartGet;
  735. if(($iPerPageGet = bx_get('per_page')) !== false)
  736. $aParams['per_page'] = (int)$iPerPageGet;
  737. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_friends');
  738. if(!$oRecommendation)
  739. return false;
  740. if(bx_is_api()) {
  741. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  742. $aData = array_merge($aData, [
  743. 'module' => 'system',
  744. 'unit' => 'mixed',
  745. 'request_url' => '/api.php?r=system/browse_recommendations_friends/TemplServiceProfiles&params[]=' . $iProfileId . '&params[]='
  746. ]);
  747. return [bx_api_get_block('browse', $aData)];
  748. }
  749. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  750. if(!$sCode && $aParams['empty_message'])
  751. $sCode = MsgBox(_t('_Empty'));
  752. return $sCode;
  753. }
  754. public function serviceSetMembership($mixedProfileId, $iAclLevelId, $iAclLevelDuration = 0)
  755. {
  756. if(!is_array($mixedProfileId))
  757. $mixedProfileId = array($mixedProfileId);
  758. $iPerformerId = bx_get_logged_profile_id();
  759. $aCheck = checkActionModule($iPerformerId, 'set acl level', 'system', false);
  760. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  761. return true;//array('code' => 1, 'msg' => $aCheck[CHECK_ACTION_MESSAGE]);
  762. $iSet = 0;
  763. $oAcl = BxDolAcl::getInstance();
  764. foreach($mixedProfileId as $iProfileId) {
  765. if(!$oAcl->setMembership($iProfileId, $iAclLevelId, $iAclLevelDuration, true))
  766. continue;
  767. $iSet += 1;
  768. checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
  769. }
  770. if(count($mixedProfileId) != $iSet)
  771. return true;//array('code' => 2, 'msg' => _t('_error occured'));
  772. return true;//$aResult;
  773. }
  774. public function serviceBrowseRecommendationsSubscriptions ($iProfileId = 0, $aParams = [])
  775. {
  776. if($this->_bIsApi)
  777. $aParams = bx_api_get_browse_params($aParams, true);
  778. if(!$iProfileId)
  779. $iProfileId = bx_get_logged_profile_id();
  780. if(!$iProfileId)
  781. return '';
  782. $aModules = bx_srv('system', 'get_modules_by_type', ['profile', ['name_as_key' => true]]);
  783. $aParams = array_merge([
  784. 'empty_message' => false,
  785. 'type' => !empty($aModules) && is_array($aModules) ? array_keys($aModules) : '',
  786. 'start' => 0,
  787. 'per_page' => 0
  788. ], $aParams);
  789. if(($iStartGet = bx_get('start')) !== false)
  790. $aParams['start'] = (int)$iStartGet;
  791. if(($iPerPageGet = bx_get('per_page')) !== false)
  792. $aParams['per_page'] = (int)$iPerPageGet;
  793. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_subscriptions');
  794. if(!$oRecommendation)
  795. return false;
  796. if(bx_is_api()) {
  797. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  798. $aData = array_merge($aData, [
  799. 'module' => 'system',
  800. 'unit' => 'mixed',
  801. 'request_url' => '/api.php?r=system/browse_recommendations_subscriptions/TemplServiceProfiles&params[]=' . $iProfileId . '&params[]='
  802. ]);
  803. return [bx_api_get_block('browse', $aData)];
  804. }
  805. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  806. if(!$sCode && $aParams['empty_message'])
  807. $sCode = MsgBox(_t('_Empty'));
  808. return $sCode;
  809. }
  810. public function serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
  811. {
  812. $oTemplate = BxDolTemplate::getInstance();
  813. $oProfilesQuery = BxDolProfileQuery::getInstance();
  814. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  815. if (!$aProfiles)
  816. return false;
  817. if (null === $iActiveProfileId)
  818. $iActiveProfileId = bx_get_logged_profile_id();
  819. $oModuleDb = BxDolModuleQuery::getInstance();
  820. $aVars = array (
  821. 'bx_repeat:row' => array(),
  822. );
  823. /**
  824. * @hooks
  825. * @hookdef hook-system-account_profile_switcher 'system', 'account_profile_switcher' - hook to get account profile switcher
  826. * - $unit_name - equals `system`
  827. * - $action - equals `account_profile_switcher`
  828. * - $object_id - not used
  829. * - $sender_id - not used
  830. * - $extra_params - array of additional params with the following array keys:
  831. * - `account_id` - [int] account id
  832. * - `active_profile_id` - [int] by ref, current profile id, can be overridden in hook processing
  833. * - `url_profile_action` - [string] url profile action
  834. * - `show_all` - [bool] by ref, show all profiles or not, can be overridden in hook processing
  835. * - `button_title` - [string] by ref, title for button, can be overridden in hook processing
  836. * - `profile_template` - [string] by ref, profile template, can be overridden in hook processing
  837. * - `profiles` - [array] by ref, array of profiles info , can be overridden in hook processing
  838. * @hook @ref hook-system-account_profile_switcher
  839. */
  840. bx_alert('system', 'account_profile_switcher', 0, false, array(
  841. 'account_id' => $iAccountId,
  842. 'active_profile_id' => &$iActiveProfileId,
  843. 'url_profile_action' => &$sUrlProfileAction,
  844. 'show_all' => &$bShowAll,
  845. 'button_title' => &$sButtonTitle,
  846. 'profile_template' => &$sProfileTemplate,
  847. 'profiles' => &$aProfiles
  848. ));
  849. $aProfilesData = [];
  850. foreach ($aProfiles as $aProfile) {
  851. if (!$bShowAll && $iActiveProfileId == $aProfile['id'])
  852. continue;
  853. if(!$oModuleDb->isEnabledByName($aProfile['type']))
  854. continue;
  855. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  856. continue;
  857. if($this->_bIsApi){
  858. $o = BxDolProfile::getInstance($aProfile['id']);
  859. $aProfilesData[] = [
  860. 'id' => $o->id(),
  861. 'display_name' => $o->getDisplayName(),
  862. 'url' => bx_api_get_relative_url($o->getUrl()),
  863. 'avatar' => $o->getAvatar()
  864. ];
  865. }
  866. $aVars['bx_repeat:row'][] = array (
  867. 'class' => $iActiveProfileId == $aProfile['id'] ? '' : 'bx-def-color-bg-box',
  868. 'bx_if:active' => array (
  869. 'condition' => $iActiveProfileId == $aProfile['id'],
  870. 'content' => array('id' => $aProfile['id']),
  871. ),
  872. 'bx_if:inactive' => array (
  873. 'condition' => $iActiveProfileId != $aProfile['id'],
  874. 'content' => array(
  875. 'id' => $aProfile['id'],
  876. 'button_title' => $sButtonTitle ? $sButtonTitle : _t('_sys_txt_switch_profile_context'),
  877. 'url_switch' => $sUrlProfileAction ? str_replace('{profile_id}', $aProfile['id'], $sUrlProfileAction) : BxDolProfile::getSwitchToProfileRedirectUrl($aProfile['id'])
  878. ),
  879. ),
  880. 'unit' => BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id'], array('template' => $sProfileTemplate))),
  881. );
  882. }
  883. if($this->_bIsApi){
  884. return [bx_api_get_block ('profile_switcher', ['active_profile_id' => $iActiveProfileId, 'profiles' => $aProfilesData])];
  885. }
  886. $oTemplate->addCss('account.css');
  887. return array(
  888. 'content' => $oTemplate->parseHtmlByName('profile_switch_row.html', $aVars),
  889. );
  890. }
  891. public function serviceAccountProfileSwitcherAll ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = true, $sButtonTitle = '', $sProfileTemplate = '')
  892. {
  893. return $this->serviceAccountProfileSwitcher($iAccountId, $iActiveProfileId, $sUrlProfileAction, $bShowAll, $sButtonTitle, $sProfileTemplate);
  894. }
  895. public function serviceProfileSettingsCfilter($iProfileId = false)
  896. {
  897. if(!BxDolContentFilter::getInstance()->isEnabled()) {
  898. BxDolTemplate::getInstance()->displayPageNotFound();
  899. exit;
  900. }
  901. // set settings submenu
  902. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  903. if ($oMenuSubmenu) {
  904. $oMenuSubmenu->setObjectSubmenu('sys_account_settings_submenu', array (
  905. 'title' => _t('_sys_menu_item_title_account_settings'),
  906. 'link' => BX_DOL_URL_ROOT . 'member.php',
  907. 'icon' => '',
  908. ));
  909. }
  910. if($iProfileId === false)
  911. $iProfileId = bx_get_logged_profile_id();
  912. $oProfile = BxDolProfile::getInstance($iProfileId);
  913. $aProfileInfo = $oProfile ? $oProfile->getInfo() : false;
  914. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  915. return MsgBox(_t('_sys_txt_error_profile_is_not_defined'));
  916. $sForm = 'sys_profile';
  917. $sFormDisplay = 'sys_profile_cf_set';
  918. $oForm = BxDolForm::getObjectInstance($sForm, $sFormDisplay);
  919. if(!$oForm)
  920. return MsgBox(_t('_sys_txt_error_occured'));
  921. $oForm->initChecker($aProfileInfo);
  922. if(!$oForm->isSubmittedAndValid())
  923. return $sCode = $oForm->getCode();
  924. if(!$oForm->update($iProfileId)) {
  925. if (!$oForm->isValid())
  926. return $oForm->getCode();
  927. else
  928. return MsgBox(_t('_sys_txt_error_profile_update'));
  929. }
  930. // display result message
  931. $sMsg = MsgBox(_t('_' . $sFormDisplay . '_successfully_submitted'));
  932. return $sMsg . $oForm->getCode();
  933. }
  934. public function serviceIsAllowedCfilter($sAction, $iValue, $aProfileInfo)
  935. {
  936. if(!in_array($sAction, ['watch', 'use']) || !isset($aProfileInfo['birthday']))
  937. return false;
  938. $iAge = 0;
  939. if(!empty($aProfileInfo['birthday']) && !in_array($aProfileInfo['birthday'], array('0000-00-00', '0000-00-00 00:00:00')))
  940. $iAge = bx_birthday2age($aProfileInfo['birthday']);
  941. $iResult = 0;
  942. switch($iValue) {
  943. case 1:
  944. $iResult = $iValue;
  945. break;
  946. case 2:
  947. if($iAge >= 6)
  948. $iResult = $iValue;
  949. break;
  950. case 3:
  951. if($iAge >= 13)
  952. $iResult = $iValue;
  953. break;
  954. case 4:
  955. if($iAge >= 17)
  956. $iResult = $iValue;
  957. break;
  958. case 5:
  959. if($iAge >= 21)
  960. $iResult = $iValue;
  961. break;
  962. }
  963. if($iResult != 0)
  964. $iResult = 1 << ($iResult - 1);
  965. return $iResult;
  966. }
  967. public function serviceIsEnabledCfilter()
  968. {
  969. return BxDolContentFilter::getInstance()->isEnabled();
  970. }
  971. public function serviceUpdateSettings($iProfileId = false, $sSettings = '')
  972. {
  973. $oProfile = BxDolProfile::getInstance($iProfileId);
  974. if(!$oProfile)
  975. return '';
  976. $sModule = $oProfile->getModule();
  977. $sMethod = 'profile_settings_set';
  978. if(!BxDolRequest::serviceExists($sModule, $sMethod))
  979. return '';
  980. BxDolService::call($sModule, $sMethod, [$oProfile->getContentId(), json_decode($sSettings)]);
  981. }
  982. protected function _getIcon ($sIcon)
  983. {
  984. return BxTemplFunctions::getInstance()->getIcon($sIcon);
  985. }
  986. protected function _getLatestModuleTimestamp ()
  987. {
  988. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1, 'order_by' => '`date` ASC'));
  989. if (empty($aModules))
  990. return 0;
  991. $aModuleNewest = array_pop($aModules);
  992. return $aModuleNewest['date'];
  993. }
  994. protected function _getProfilesModules($bForceActAsProfile = true)
  995. {
  996. $aRet = array();
  997. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  998. foreach($aModules as $aModule) {
  999. $oModule = BxDolModule::getInstance($aModule['name']);
  1000. if(!($oModule instanceof iBxDolProfileService))
  1001. continue;
  1002. if($bForceActAsProfile && !$oModule->serviceActAsProfile())
  1003. continue;
  1004. $aRet[] = $aModule;
  1005. }
  1006. return $aRet;
  1007. }
  1008. protected function _serviceBrowseConnections ($sMode, $aParams = [], $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  1009. {
  1010. $sClass = 'BxTemplProfileSearchResult';
  1011. bx_import($sClass);
  1012. $o = new $sClass($sMode, $aParams);
  1013. $o->setDesignBoxTemplateId($iDesignBox);
  1014. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1015. $o->setAjaxPaginate($bAjaxPaginate);
  1016. $o->setUnitParams(['context' => $sMode]);
  1017. if ($o->isError)
  1018. return '';
  1019. if ($s = $o->processing()) {
  1020. if(!bx_is_api())
  1021. return $s;
  1022. return [bx_api_get_block('browse', $s)];
  1023. }
  1024. else
  1025. return '';
  1026. }
  1027. }
  1028. /** @} */