1
0

BxBaseServiceProfiles.php 45 KB

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