BxBaseServiceProfiles.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274
  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. BxDolProfileQuery::getInstance()->updateProfileTrack($iProfileId, 'view_friend_requests');
  617. return $this->_serviceBrowseConnections('friend_requests', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  618. }
  619. public function serviceBrowseFriendRequested ($iProfileId = 0, $aParams = [])
  620. {
  621. if($this->_bIsApi)
  622. $aParams = bx_api_get_browse_params($aParams);
  623. if(!$iProfileId)
  624. $iProfileId = bx_get_logged_profile_id();
  625. if(!$iProfileId)
  626. return '';
  627. $aParams = array_merge([
  628. 'params' => false,
  629. 'design_box' => BX_DB_PADDING_DEF,
  630. 'empty_message' => false,
  631. 'ajax_paginate' => true,
  632. ], $aParams);
  633. $aParamsBrowse = ['profile' => $iProfileId];
  634. if(!empty($aParams['params']) && is_array($aParams['params']))
  635. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  636. return $this->_serviceBrowseConnections('friend_requested', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  637. }
  638. public function serviceBrowseSubscriptions ($iProfileId = 0, $aParams = [])
  639. {
  640. if($this->_bIsApi)
  641. $aParams = bx_api_get_browse_params($aParams);
  642. if(!$iProfileId)
  643. $iProfileId = bx_get_logged_profile_id();
  644. if(!$iProfileId)
  645. return '';
  646. $aParams = array_merge([
  647. 'params' => false,
  648. 'design_box' => BX_DB_PADDING_DEF,
  649. 'empty_message' => false,
  650. 'ajax_paginate' => true,
  651. ], $aParams);
  652. $aParamsBrowse = ['profile' => $iProfileId];
  653. if(!empty($aParams['params']) && is_array($aParams['params']))
  654. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  655. return $this->_serviceBrowseConnections('subscriptions', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  656. }
  657. public function serviceBrowseSubscribedMe ($iProfileId = 0, $aParams = [])
  658. {
  659. if($this->_bIsApi)
  660. $aParams = bx_api_get_browse_params($aParams);
  661. if(!$iProfileId)
  662. $iProfileId = bx_get_logged_profile_id();
  663. if(!$iProfileId)
  664. return '';
  665. $aParams = array_merge([
  666. 'params' => false,
  667. 'design_box' => BX_DB_PADDING_DEF,
  668. 'empty_message' => false,
  669. 'ajax_paginate' => true,
  670. ], $aParams);
  671. $aParamsBrowse = ['profile' => $iProfileId];
  672. if(!empty($aParams['params']) && is_array($aParams['params']))
  673. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  674. return $this->_serviceBrowseConnections('subscribed_me', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  675. }
  676. public function serviceBrowseMembers($iProfileId, $sObject, $aParams = [])
  677. {
  678. if($this->_bIsApi)
  679. $aParams = bx_api_get_browse_params($aParams);
  680. if(!$iProfileId)
  681. $iProfileId = bx_get_logged_profile_id();
  682. if(!$iProfileId)
  683. return '';
  684. $aParams = array_merge([
  685. 'params' => false,
  686. 'design_box' => BX_DB_PADDING_DEF,
  687. 'empty_message' => false,
  688. 'ajax_paginate' => true,
  689. ], $aParams);
  690. $aParamsBrowse = [
  691. 'profile' => $iProfileId,
  692. 'object' => $sObject
  693. ];
  694. if(!empty($aParams['params']) && is_array($aParams['params']))
  695. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  696. return $this->_serviceBrowseConnections('members', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  697. }
  698. public function serviceBrowseConnections ($iProfileId = 0, $aParams = [])
  699. {
  700. if($this->_bIsApi)
  701. $aParams = bx_api_get_browse_params($aParams);
  702. if(!$iProfileId)
  703. $iProfileId = bx_get_logged_profile_id();
  704. if(!$iProfileId)
  705. return '';
  706. $aParams = array_merge([
  707. 'params' => false,
  708. 'design_box' => BX_DB_PADDING_DEF,
  709. 'empty_message' => false,
  710. 'ajax_paginate' => true,
  711. ], $aParams);
  712. $aParamsBrowse = [
  713. 'profile' => $iProfileId,
  714. 'object' => 'sys_profiles_friends',
  715. 'type' => 'content',
  716. 'mutual' => false,
  717. 'profile2' => 0
  718. ];
  719. if(!empty($aParams['params']) && is_array($aParams['params']))
  720. $aParamsBrowse = array_merge($aParamsBrowse, $aParams['params']);
  721. return $this->_serviceBrowseConnections('connections', $aParamsBrowse, $aParams['design_box'], $aParams['empty_message'], $aParams['ajax_paginate']);
  722. }
  723. public function serviceBrowseRecommendationsFriends ($iProfileId = 0, $aParams = [])
  724. {
  725. if($this->_bIsApi)
  726. $aParams = bx_api_get_browse_params($aParams, true);
  727. if(!$iProfileId)
  728. $iProfileId = bx_get_logged_profile_id();
  729. if(!$iProfileId)
  730. return '';
  731. $aParams = array_merge([
  732. 'empty_message' => false,
  733. 'start' => 0,
  734. 'per_page' => 0
  735. ], $aParams);
  736. if(($iStartGet = bx_get('start')) !== false)
  737. $aParams['start'] = (int)$iStartGet;
  738. if(($iPerPageGet = bx_get('per_page')) !== false)
  739. $aParams['per_page'] = (int)$iPerPageGet;
  740. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_friends');
  741. if(!$oRecommendation)
  742. return false;
  743. if(bx_is_api()) {
  744. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  745. $aData = array_merge($aData, [
  746. 'module' => 'system',
  747. 'unit' => 'mixed',
  748. 'request_url' => '/api.php?r=system/browse_recommendations_friends/TemplServiceProfiles&params[]=' . $iProfileId . '&params[]='
  749. ]);
  750. return [bx_api_get_block('browse', $aData)];
  751. }
  752. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  753. if(!$sCode && $aParams['empty_message'])
  754. $sCode = MsgBox(_t('_Empty'));
  755. return $sCode;
  756. }
  757. public function serviceSetMembership($mixedProfileId, $iAclLevelId, $iAclLevelDuration = 0)
  758. {
  759. if(!is_array($mixedProfileId))
  760. $mixedProfileId = array($mixedProfileId);
  761. $iPerformerId = bx_get_logged_profile_id();
  762. $aCheck = checkActionModule($iPerformerId, 'set acl level', 'system', false);
  763. if(!isAdmin() && $aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  764. return true;//array('code' => 1, 'msg' => $aCheck[CHECK_ACTION_MESSAGE]);
  765. $iSet = 0;
  766. $oAcl = BxDolAcl::getInstance();
  767. foreach($mixedProfileId as $iProfileId) {
  768. if(!$oAcl->setMembership($iProfileId, $iAclLevelId, $iAclLevelDuration, true))
  769. continue;
  770. $iSet += 1;
  771. checkActionModule($iPerformerId, 'set acl level', 'system', true); // perform action
  772. }
  773. if(count($mixedProfileId) != $iSet)
  774. return true;//array('code' => 2, 'msg' => _t('_error occured'));
  775. return true;//$aResult;
  776. }
  777. public function serviceBrowseRecommendationsSubscriptions ($iProfileId = 0, $aParams = [])
  778. {
  779. if($this->_bIsApi)
  780. $aParams = bx_api_get_browse_params($aParams, true);
  781. if(!$iProfileId)
  782. $iProfileId = bx_get_logged_profile_id();
  783. if(!$iProfileId)
  784. return '';
  785. $aModules = bx_srv('system', 'get_modules_by_type', ['profile', ['name_as_key' => true]]);
  786. $aParams = array_merge([
  787. 'empty_message' => false,
  788. 'type' => !empty($aModules) && is_array($aModules) ? array_keys($aModules) : '',
  789. 'start' => 0,
  790. 'per_page' => 0
  791. ], $aParams);
  792. if(($iStartGet = bx_get('start')) !== false)
  793. $aParams['start'] = (int)$iStartGet;
  794. if(($iPerPageGet = bx_get('per_page')) !== false)
  795. $aParams['per_page'] = (int)$iPerPageGet;
  796. $oRecommendation = BxDolRecommendation::getObjectInstance('sys_subscriptions');
  797. if(!$oRecommendation)
  798. return false;
  799. if(bx_is_api()) {
  800. $aData = $oRecommendation->getCodeAPI($iProfileId, $aParams);
  801. $aData = array_merge($aData, [
  802. 'module' => 'system',
  803. 'unit' => 'mixed',
  804. 'request_url' => '/api.php?r=system/browse_recommendations_subscriptions/TemplServiceProfiles&params[]=' . $iProfileId . '&params[]='
  805. ]);
  806. return [bx_api_get_block('browse', $aData)];
  807. }
  808. $sCode = $oRecommendation->getCode($iProfileId, $aParams);
  809. if(!$sCode && $aParams['empty_message'])
  810. $sCode = MsgBox(_t('_Empty'));
  811. return $sCode;
  812. }
  813. public function serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
  814. {
  815. $oTemplate = BxDolTemplate::getInstance();
  816. $oProfilesQuery = BxDolProfileQuery::getInstance();
  817. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  818. if (!$aProfiles)
  819. return false;
  820. if (null === $iActiveProfileId)
  821. $iActiveProfileId = bx_get_logged_profile_id();
  822. $oModuleDb = BxDolModuleQuery::getInstance();
  823. $aVars = array (
  824. 'bx_repeat:row' => array(),
  825. );
  826. /**
  827. * @hooks
  828. * @hookdef hook-system-account_profile_switcher 'system', 'account_profile_switcher' - hook to get account profile switcher
  829. * - $unit_name - equals `system`
  830. * - $action - equals `account_profile_switcher`
  831. * - $object_id - not used
  832. * - $sender_id - not used
  833. * - $extra_params - array of additional params with the following array keys:
  834. * - `account_id` - [int] account id
  835. * - `active_profile_id` - [int] by ref, current profile id, can be overridden in hook processing
  836. * - `url_profile_action` - [string] url profile action
  837. * - `show_all` - [bool] by ref, show all profiles or not, can be overridden in hook processing
  838. * - `button_title` - [string] by ref, title for button, can be overridden in hook processing
  839. * - `profile_template` - [string] by ref, profile template, can be overridden in hook processing
  840. * - `profiles` - [array] by ref, array of profiles info , can be overridden in hook processing
  841. * @hook @ref hook-system-account_profile_switcher
  842. */
  843. bx_alert('system', 'account_profile_switcher', 0, false, array(
  844. 'account_id' => $iAccountId,
  845. 'active_profile_id' => &$iActiveProfileId,
  846. 'url_profile_action' => &$sUrlProfileAction,
  847. 'show_all' => &$bShowAll,
  848. 'button_title' => &$sButtonTitle,
  849. 'profile_template' => &$sProfileTemplate,
  850. 'profiles' => &$aProfiles
  851. ));
  852. $aProfilesData = [];
  853. foreach ($aProfiles as $aProfile) {
  854. if (!$bShowAll && $iActiveProfileId == $aProfile['id'])
  855. continue;
  856. if(!$oModuleDb->isEnabledByName($aProfile['type']))
  857. continue;
  858. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  859. continue;
  860. if($this->_bIsApi){
  861. $o = BxDolProfile::getInstance($aProfile['id']);
  862. $aProfilesData[] = [
  863. 'id' => $o->id(),
  864. 'display_name' => $o->getDisplayName(),
  865. 'url' => bx_api_get_relative_url($o->getUrl()),
  866. 'avatar' => $o->getAvatar()
  867. ];
  868. }
  869. $aVars['bx_repeat:row'][] = array (
  870. 'class' => $iActiveProfileId == $aProfile['id'] ? '' : 'bx-def-color-bg-box',
  871. 'bx_if:active' => array (
  872. 'condition' => $iActiveProfileId == $aProfile['id'],
  873. 'content' => array('id' => $aProfile['id']),
  874. ),
  875. 'bx_if:inactive' => array (
  876. 'condition' => $iActiveProfileId != $aProfile['id'],
  877. 'content' => array(
  878. 'id' => $aProfile['id'],
  879. 'button_title' => $sButtonTitle ? $sButtonTitle : _t('_sys_txt_switch_profile_context'),
  880. 'url_switch' => $sUrlProfileAction ? str_replace('{profile_id}', $aProfile['id'], $sUrlProfileAction) : BxDolProfile::getSwitchToProfileRedirectUrl($aProfile['id'])
  881. ),
  882. ),
  883. 'unit' => BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id'], array('template' => $sProfileTemplate))),
  884. );
  885. }
  886. if($this->_bIsApi){
  887. return [bx_api_get_block ('profile_switcher', ['active_profile_id' => $iActiveProfileId, 'profiles' => $aProfilesData])];
  888. }
  889. $oTemplate->addCss('account.css');
  890. return array(
  891. 'content' => $oTemplate->parseHtmlByName('profile_switch_row.html', $aVars),
  892. );
  893. }
  894. public function serviceAccountProfileSwitcherAll ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = true, $sButtonTitle = '', $sProfileTemplate = '')
  895. {
  896. return $this->serviceAccountProfileSwitcher($iAccountId, $iActiveProfileId, $sUrlProfileAction, $bShowAll, $sButtonTitle, $sProfileTemplate);
  897. }
  898. public function serviceProfileSettingsCfilter($iProfileId = false)
  899. {
  900. if(!BxDolContentFilter::getInstance()->isEnabled()) {
  901. BxDolTemplate::getInstance()->displayPageNotFound();
  902. exit;
  903. }
  904. // set settings submenu
  905. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  906. if ($oMenuSubmenu) {
  907. $oMenuSubmenu->setObjectSubmenu('sys_account_settings_submenu', array (
  908. 'title' => _t('_sys_menu_item_title_account_settings'),
  909. 'link' => BX_DOL_URL_ROOT . 'member.php',
  910. 'icon' => '',
  911. ));
  912. }
  913. if($iProfileId === false)
  914. $iProfileId = bx_get_logged_profile_id();
  915. $oProfile = BxDolProfile::getInstance($iProfileId);
  916. $aProfileInfo = $oProfile ? $oProfile->getInfo() : false;
  917. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  918. return MsgBox(_t('_sys_txt_error_profile_is_not_defined'));
  919. $sForm = 'sys_profile';
  920. $sFormDisplay = 'sys_profile_cf_set';
  921. $oForm = BxDolForm::getObjectInstance($sForm, $sFormDisplay);
  922. if(!$oForm)
  923. return MsgBox(_t('_sys_txt_error_occured'));
  924. $oForm->initChecker($aProfileInfo);
  925. if(!$oForm->isSubmittedAndValid())
  926. return $sCode = $oForm->getCode();
  927. if(!$oForm->update($iProfileId)) {
  928. if (!$oForm->isValid())
  929. return $oForm->getCode();
  930. else
  931. return MsgBox(_t('_sys_txt_error_profile_update'));
  932. }
  933. // display result message
  934. $sMsg = MsgBox(_t('_' . $sFormDisplay . '_successfully_submitted'));
  935. return $sMsg . $oForm->getCode();
  936. }
  937. public function serviceIsAllowedCfilter($sAction, $iValue, $aProfileInfo)
  938. {
  939. if(!in_array($sAction, ['watch', 'use']) || !isset($aProfileInfo['birthday']))
  940. return false;
  941. $iAge = 0;
  942. if(!empty($aProfileInfo['birthday']) && !in_array($aProfileInfo['birthday'], array('0000-00-00', '0000-00-00 00:00:00')))
  943. $iAge = bx_birthday2age($aProfileInfo['birthday']);
  944. $iResult = 0;
  945. switch($iValue) {
  946. case 1:
  947. $iResult = $iValue;
  948. break;
  949. case 2:
  950. if($iAge >= 6)
  951. $iResult = $iValue;
  952. break;
  953. case 3:
  954. if($iAge >= 13)
  955. $iResult = $iValue;
  956. break;
  957. case 4:
  958. if($iAge >= 17)
  959. $iResult = $iValue;
  960. break;
  961. case 5:
  962. if($iAge >= 21)
  963. $iResult = $iValue;
  964. break;
  965. }
  966. if($iResult != 0)
  967. $iResult = 1 << ($iResult - 1);
  968. return $iResult;
  969. }
  970. public function serviceIsEnabledCfilter()
  971. {
  972. return BxDolContentFilter::getInstance()->isEnabled();
  973. }
  974. public function serviceProfileCounters()
  975. {
  976. if(bx_is_api() && ($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
  977. return $oLiveUpdates->performApi();
  978. }
  979. public function serviceUpdateSettings($iProfileId = false, $sSettings = '')
  980. {
  981. $oProfile = BxDolProfile::getInstance($iProfileId);
  982. if(!$oProfile)
  983. return '';
  984. $sModule = $oProfile->getModule();
  985. $sMethod = 'profile_settings_set';
  986. if(!BxDolRequest::serviceExists($sModule, $sMethod))
  987. return '';
  988. BxDolService::call($sModule, $sMethod, [$oProfile->getContentId(), json_decode($sSettings)]);
  989. }
  990. protected function _getIcon ($sIcon)
  991. {
  992. return BxTemplFunctions::getInstance()->getIcon($sIcon);
  993. }
  994. protected function _getLatestModuleTimestamp ()
  995. {
  996. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1, 'order_by' => '`date` ASC'));
  997. if (empty($aModules))
  998. return 0;
  999. $aModuleNewest = array_pop($aModules);
  1000. return $aModuleNewest['date'];
  1001. }
  1002. protected function _getProfilesModules($bForceActAsProfile = true)
  1003. {
  1004. $aRet = array();
  1005. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  1006. foreach($aModules as $aModule) {
  1007. $oModule = BxDolModule::getInstance($aModule['name']);
  1008. if(!($oModule instanceof iBxDolProfileService))
  1009. continue;
  1010. if($bForceActAsProfile && !$oModule->serviceActAsProfile())
  1011. continue;
  1012. $aRet[] = $aModule;
  1013. }
  1014. return $aRet;
  1015. }
  1016. protected function _serviceBrowseConnections ($sMode, $aParams = [], $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  1017. {
  1018. $sClass = 'BxTemplProfileSearchResult';
  1019. bx_import($sClass);
  1020. $o = new $sClass($sMode, $aParams);
  1021. $o->setDesignBoxTemplateId($iDesignBox);
  1022. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  1023. $o->setAjaxPaginate($bAjaxPaginate);
  1024. $o->setUnitParams(['context' => $sMode]);
  1025. if ($o->isError)
  1026. return '';
  1027. if ($s = $o->processing()) {
  1028. if(!bx_is_api())
  1029. return $s;
  1030. return [bx_api_get_block('browse', $s)];
  1031. }
  1032. else
  1033. return '';
  1034. }
  1035. }
  1036. /** @} */