BxBaseServiceProfiles.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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. public function __construct()
  15. {
  16. parent::__construct();
  17. }
  18. public function serviceGetProfileTypes()
  19. {
  20. $aTypes = array(
  21. '' => _t('_Select_one')
  22. );
  23. $aModules = $this->_getProfilesModules();
  24. foreach($aModules as $aModule) {
  25. if(empty($aModule) || !is_array($aModule))
  26. continue;
  27. $sTitleKey = '_' . $aModule['name'];
  28. $sTitle = _t($sTitleKey);
  29. $aTypes[$aModule['name']] = !empty($sTitle) && $sTitle != $sTitleKey ? $sTitle : $aModule['title'];
  30. }
  31. return $aTypes;
  32. }
  33. public function serviceProfileAvatar ($iProfileId = 0)
  34. {
  35. if (!$iProfileId && !($iProfileId = bx_get_logged_profile_id()))
  36. return '';
  37. $oProfile = BxDolProfile::getInstance($iProfileId);
  38. if(!$oProfile)
  39. return '';
  40. if(bx_is_api())
  41. return [
  42. bx_api_get_block ('profile_avatar', $oProfile->getData())
  43. ];
  44. $oTemplate = BxDolTemplate::getInstance();
  45. $sSwitcher = '';
  46. $aSwitcher = bx_srv('system', 'account_profile_switcher', array(false, null, '', true), 'TemplServiceProfiles');
  47. if($aSwitcher !== false)
  48. $sSwitcher = BxTemplFunctions::getInstance()->popupBox('bx-profile-switcher', _t('_sys_txt_switch_profiles'), $oTemplate->parseHtmlByName('profile_avatar_switcher.html', array(
  49. 'profile_switcher' => $aSwitcher['content'],
  50. 'bx_if:multiple_profiles_mode' => array(
  51. 'condition' => empty($aSwitcher['content']) || BxDolAccount::isAllowedCreateMultiple($oProfile->id()),
  52. 'content' => array(
  53. 'url_switch_profile' => BxDolPermalinks::getInstance()->permalink('page.php?i=account-profile-switcher')
  54. )
  55. )
  56. )), true);
  57. $bSwitcher = !empty($sSwitcher);
  58. $sSwitcherUrl = $bSwitcher ? 'javascript:void(0)' : $sUrl;
  59. $sSwitcherOnclick = $bSwitcher ? "javascript:$('#bx-profile-switcher').dolPopup({});" : "";
  60. $sDisplayName = $oProfile->getDisplayName();
  61. $sUrl = $oProfile->getUrl();
  62. $oAcl = BxDolAcl::getInstance();
  63. $aAcl = $oAcl->getMemberMembershipInfo($iProfileId);
  64. $aAclInfo = $oAcl->getMembershipInfo($aAcl['id']);
  65. list($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getIcon($aAclInfo['icon']);
  66. $aVars = array(
  67. 'profile_id' => $oProfile->id(),
  68. 'profile_url' => $sUrl,
  69. 'profile_edit_url' => $oProfile->getEditUrl(),
  70. 'profile_title' => $sDisplayName,
  71. 'profile_title_attr' => bx_html_attribute($sDisplayName),
  72. 'profile_ava_url' => $oProfile->getAvatar(),
  73. 'profile_unit' => $oProfile->getUnit(0, array('template' => array(
  74. 'name' => 'unit_wo_info_links',
  75. 'size' => 'thumb'
  76. ))),
  77. 'profile_acl_title' => _t($aAclInfo['name']),
  78. 'bx_if:image' => array (
  79. 'condition' => (bool)$sIconUrl,
  80. 'content' => array('icon_url' => $sIconUrl),
  81. ),
  82. 'bx_if:image_inline' => array (
  83. 'condition' => false,
  84. 'content' => array('image' => ''),
  85. ),
  86. 'bx_if:icon' => array (
  87. 'condition' => (bool)$sIcon,
  88. 'content' => array('icon' => $sIcon),
  89. ),
  90. 'bx_if:icon-a' => array (
  91. 'condition' => (bool)$sIconA,
  92. 'content' => array('icon-a' => $sIconA),
  93. ),
  94. 'bx_if:icon-html' => array (
  95. 'condition' => (bool)$sIconHtml,
  96. 'content' => array('icon' => $sIconHtml),
  97. ),
  98. 'switcher_url' => $sSwitcherUrl,
  99. 'switcher_onclick' => $sSwitcherOnclick,
  100. 'bx_if:show_switcher_icon' => array(
  101. 'condition' => $bSwitcher,
  102. 'content' => array(
  103. 'switcher_url' => $sSwitcherUrl,
  104. 'switcher_onclick' => $bSwitcher ? "javascript:$('#bx-profile-switcher').dolPopup({});" : "",
  105. )
  106. ),
  107. 'switcher' => $sSwitcher
  108. );
  109. return $oTemplate->parseHtmlByName('profile_avatar.html', $aVars);
  110. }
  111. public function serviceProfileMenu ($iProfileId = 0)
  112. {
  113. if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_stats')) !== false) {
  114. if(bx_is_api())
  115. return [
  116. bx_api_get_block ('profile_menu', $oMenu->getCodeAPI())
  117. ];
  118. return $oMenu->getCode();
  119. }
  120. else
  121. return '';
  122. }
  123. public function serviceProfileFollowings ($iProfileId = 0)
  124. {
  125. if(($oMenu = BxDolMenu::getObjectInstance('sys_profile_followings')) !== false)
  126. return $oMenu->getCode();
  127. else
  128. return '';
  129. }
  130. public function serviceProfileStats ($iProfileId = 0)
  131. {
  132. if (!$iProfileId && !($iProfileId = bx_get_logged_profile_id()))
  133. return '';
  134. $oProfile = BxDolProfile::getInstance($iProfileId);
  135. if(!$oProfile)
  136. return '';
  137. $oMenu = BxDolMenu::getObjectInstance('sys_profile_stats');
  138. if(!$oMenu)
  139. return '';
  140. if(bx_is_api())
  141. return [
  142. bx_api_get_block ('profile_avatar', $oProfile->getData(), ['id' => 1]),
  143. bx_api_get_block ('profile_menu', $oMenu->getCodeAPI(), ['id' => 2])
  144. ];
  145. $oAcl = BxDolAcl::getInstance();
  146. $aAcl = $oAcl->getMemberMembershipInfo($iProfileId);
  147. $aAclInfo = $oAcl->getMembershipInfo($aAcl['id']);
  148. list ($sIcon, $sIconUrl, $sIconA, $sIconHtml) = $this->_getIcon($aAclInfo['icon']);
  149. $aVars = array(
  150. 'profile_id' => $oProfile->id(),
  151. 'profile_url' => $oProfile->getUrl(),
  152. 'profile_edit_url' => $oProfile->getEditUrl(),
  153. 'profile_title' => $oProfile->getDisplayName(),
  154. 'profile_title_attr' => bx_html_attribute($oProfile->getDisplayName()),
  155. 'profile_ava_url' => $oProfile->getAvatar(),
  156. 'profile_unit' => $oProfile->getUnit(0, array('template' => array(
  157. 'name' => 'unit_wo_info',
  158. 'size' => 'ava'
  159. ))),
  160. 'profile_acl_title' => _t($aAclInfo['name']),
  161. 'menu' => $oMenu->getCode(),
  162. );
  163. $aVars['bx_if:image'] = array (
  164. 'condition' => (bool)$sIconUrl,
  165. 'content' => array('icon_url' => $sIconUrl),
  166. );
  167. $aVars['bx_if:image_inline'] = array (
  168. 'condition' => false,
  169. 'content' => array('image' => ''),
  170. );
  171. $aVars['bx_if:icon'] = array (
  172. 'condition' => (bool)$sIcon,
  173. 'content' => array('icon' => $sIcon),
  174. );
  175. $aVars['bx_if:icon-html'] = array (
  176. 'condition' => (bool)$sIconHtml,
  177. 'content' => array('icon' => $sIconHtml),
  178. );
  179. $aVars['bx_if:icon-a'] = array (
  180. 'condition' => (bool)$sIconA,
  181. 'content' => array('icon-a' => $sIconA),
  182. );
  183. return BxDolTemplate::getInstance()->parseHtmlByName('profile_stats.html', $aVars);
  184. }
  185. public function serviceGetMenuAddonProfileEdit($iProfileId = 0, $sCaption = '')
  186. {
  187. /**
  188. * Disabled.
  189. */
  190. return '';
  191. if(empty($sCaption))
  192. $sCaption = _t('_Edit');
  193. $oProfile = BxDolProfile::getInstance($iProfileId);
  194. if(!$oProfile)
  195. return '';
  196. $sModule = $oProfile->getModule();
  197. $sMethod = 'profile_edit_url';
  198. if(!BxDolRequest::serviceExists($sModule, $sMethod))
  199. return '';
  200. return BxDolTemplate::getInstance()->parseLink(BxDolService::call($sModule, $sMethod, array($oProfile->getContentId())), $sCaption);
  201. }
  202. /**
  203. * @page service Service Calls
  204. * @section bx_system_general System Services
  205. * @subsection bx_system_general-profiles Profiles
  206. * @subsubsection bx_system_general-profile_membership profile_membership
  207. *
  208. * @code bx_srv('system', 'profile_membership', [2], 'TemplServiceProfiles'); @endcode
  209. * @code {{~system:profile_membership:TemplServiceProfiles[2]~}} @endcode
  210. *
  211. * Get membership level for specified profile.
  212. * @param $iProfileId profile ID
  213. *
  214. * @see BxBaseServiceProfiles::serviceProfileMembership
  215. */
  216. /**
  217. * @ref bx_system_general-profile_membership "profile_membership"
  218. */
  219. public function serviceProfileMembership ($iProfileId = 0)
  220. {
  221. if (!$iProfileId)
  222. $iProfileId = bx_get_logged_profile_id();
  223. return BxDolAcl::getInstance()->getProfileMembership($iProfileId);
  224. }
  225. public function serviceProfileMembershipStats ($iProfileId = 0)
  226. {
  227. if(!$iProfileId)
  228. $iProfileId = bx_get_logged_profile_id();
  229. $sTxtUnlimited = _t('_unlimited');
  230. $sTxtFiles = _t('_sys_storage_files');
  231. $aQuota = BxDolProfileQuery::getInstance()->getProfileQuota($iProfileId);
  232. $aTmplVarsStats = array();
  233. if(!empty($aQuota['quota_size'])) {
  234. $iWidth = (int)round(100 * $aQuota['current_size']/$aQuota['quota_size']);
  235. $sPercent = $iWidth . '%';
  236. }
  237. else {
  238. $iWidth = 0;
  239. $sPercent = $sTxtUnlimited;
  240. }
  241. $aTmplVarsStats[] = array('title' => _t('_sys_profile_storage_quota_size'), 'width' => $iWidth, 'value' => _t_format_size($aQuota['current_size']), 'percent' => $sPercent);
  242. if(!empty($aQuota['quota_number'])) {
  243. $iWidth = (int)round(100 * $aQuota['current_number']/$aQuota['quota_number']);
  244. $sPercent = $iWidth . '%';
  245. }
  246. else {
  247. $iWidth = 0;
  248. $sPercent = $sTxtUnlimited;
  249. }
  250. $aTmplVarsStats[] = array('title' => _t('_sys_profile_storage_quota_number'), 'width' => $iWidth, 'value' => $aQuota['current_number'] . ' ' . $sTxtFiles, 'percent' => $sPercent);
  251. return BxDolTemplate::getInstance()->parseHtmlByName('profile_membership_stats.html', array(
  252. 'membership' => BxDolAcl::getInstance()->getProfileMembership($iProfileId),
  253. 'bx_repeat:stat_items' => $aTmplVarsStats
  254. ));
  255. }
  256. /**
  257. * @page service Service Calls
  258. * @section bx_system_general System Services
  259. * @subsection bx_system_general-profiles Profiles
  260. * @subsubsection bx_system_general-profile_notifications profile_notifications
  261. *
  262. * @code bx_srv('system', 'profile_notifications', [], 'TemplServiceProfiles'); @endcode
  263. * @code {{~system:profile_notifications:TemplServiceProfiles~}} @endcode
  264. *
  265. * Get number of unread notifications for logged in profile
  266. *
  267. * @see BxBaseServiceProfiles::serviceProfileNotifications
  268. */
  269. /**
  270. * @ref bx_system_general-profile_notifications "profile_notifications"
  271. */
  272. public function serviceProfileNotifications ($iProfileId = 0)
  273. {
  274. if (!$iProfileId)
  275. $iProfileId = bx_get_logged_profile_id();
  276. $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications');
  277. if(!$oMenu)
  278. return 0;
  279. $iNum = 0;
  280. $aMenuItems = $oMenu->getMenuItems ();
  281. foreach ($aMenuItems as $r) {
  282. if (isset($r['bx_if:addon']) && $r['bx_if:addon']['condition'])
  283. $iNum += $r['bx_if:addon']['content']['addon'];
  284. }
  285. return $iNum;
  286. }
  287. /**
  288. * @page service Service Calls
  289. * @section bx_system_general System Services
  290. * @subsection bx_system_general-profiles Profiles
  291. * @subsubsection bx_system_general-get_count_online_profiles get_count_online_profiles
  292. *
  293. * @code bx_srv('system', 'get_count_online_profiles', [], 'TemplServiceProfiles'); @endcode
  294. * @code {{~system:get_count_online_profiles:TemplServiceProfiles~}} @endcode
  295. *
  296. * Get number of online profiles
  297. *
  298. * @see BxBaseServiceProfiles::serviceGetCountOnlineProfiles
  299. */
  300. /**
  301. * @ref bx_system_general-get_count_online_profiles "get_count_online_profiles"
  302. */
  303. public function serviceGetCountOnlineProfiles ()
  304. {
  305. $oProfilesQuery = BxDolProfileQuery::getInstance();
  306. return $oProfilesQuery->getOnlineCount();
  307. }
  308. public function serviceGetProfilesModules ($bForceActAsProfile = true)
  309. {
  310. if (getParam('sys_db_cache_enable')) { // get list of profiles modules from db cache, cache is invalidated when new module is installed
  311. $oDb = BxDolDb::getInstance();
  312. $oCache = $oDb->getDbCacheObject ();
  313. $sKey = $oDb->genDbCacheKey('profiles_' . (!$bForceActAsProfile ? 'all_' : '') . 'modules_array');
  314. $sKeyTs = $oDb->genDbCacheKey('profiles_modules_ts');
  315. $mixedRetTs = $oCache->getData($sKeyTs);
  316. $mixedRet = $oCache->getData($sKey);
  317. $iNewestModuleTs = $this->_getLatestModuleTimestamp ();
  318. if ($mixedRetTs != null && $mixedRet !== null && $mixedRetTs == $iNewestModuleTs) {
  319. $aModulesArray = $mixedRet;
  320. } else {
  321. $aModulesArray = $this->_getProfilesModules ($bForceActAsProfile);
  322. $oCache->setData($sKey, $aModulesArray);
  323. $oCache->setData($sKeyTs, $iNewestModuleTs);
  324. }
  325. } else {
  326. $aModulesArray = $this->_getProfilesModules ($bForceActAsProfile);
  327. }
  328. return $aModulesArray;
  329. }
  330. public function serviceProfilesFriends ($iLimit = 20)
  331. {
  332. if (!($iProfileId = bx_get_logged_profile_id()))
  333. return array();
  334. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_friends');
  335. if (!$oConnection)
  336. return array();
  337. if (!($a = $oConnection->getConnectedContent ($iProfileId, true, 0, $iLimit)))
  338. return array();
  339. $aRet = array();
  340. foreach ($a as $iId) {
  341. $oProfile = BxDolProfile::getInstance($iId);
  342. $aRet[] = array (
  343. 'label' => $oProfile->getDisplayName(),
  344. 'value' => $iId,
  345. 'url' => $oProfile->getUrl(),
  346. 'thumb' => $oProfile->getThumb(),
  347. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info'))
  348. );
  349. }
  350. return $aRet;
  351. }
  352. public function serviceProfilesSearch ($sTerm, $mixedParems = [])
  353. {
  354. $iLimit = 20;
  355. if(is_int($mixedParems))
  356. $iLimit = (int)$mixedParems;
  357. else if(is_array($mixedParems) && isset($mixedParems['limit']))
  358. $iLimit = (int)$mixedParems['limit'];
  359. // display friends by default
  360. if (!$sTerm)
  361. return $this->serviceProfilesFriends($iLimit);
  362. // get list of "profiles" modules
  363. $aModules = $this->serviceGetProfilesModules();
  364. // search in each module
  365. $a = array();
  366. foreach ($aModules as $aModule) {
  367. if (!BxDolService::call($aModule['name'], 'act_as_profile'))
  368. continue;
  369. $a = array_merge($a, BxDolService::call($aModule['name'], 'profiles_search', array($sTerm, getParam('sys_per_page_search_keyword_single'))));
  370. }
  371. // sort result
  372. usort($a, function($r1, $r2) {
  373. return strcmp($r1['label'], $r2['label']);
  374. });
  375. bx_alert('system', 'profiles_search', 0, 0, array(
  376. 'module' => is_array($mixedParems) && isset($mixedParems['module']) ? $mixedParems['module'] : '',
  377. 'term' => $sTerm,
  378. 'result' => &$a
  379. ));
  380. // return as array
  381. return array_slice($a, 0, $iLimit);
  382. }
  383. public function serviceProfilesList ($iAccountId = 0)
  384. {
  385. $oProfilesQuery = BxDolProfileQuery::getInstance();
  386. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  387. if (!$aProfiles)
  388. return false;
  389. $s = '';
  390. foreach ($aProfiles as $aProfile)
  391. if ($aProfile['type'] != 'system')
  392. $s .= BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id']));
  393. if (!$s)
  394. $s = MsgBox(_t('_sys_txt_empty'));
  395. return $s . '<div class="bx-clear"></div>';
  396. }
  397. public function serviceBrowseConnections ($iProfileId, $sObjectConnections = 'sys_profiles_friends', $sConnectionsType = 'content', $iMutual = false, $iProfileId2 = 0, $iDesignBox = BX_DB_PADDING_DEF, $bDisplayEmptyMsg = false, $bAjaxPaginate = true)
  398. {
  399. $sClass = 'BxTemplProfileSearchResult';
  400. bx_import($sClass);
  401. $o = new $sClass('connections', [
  402. 'object' => $sObjectConnections,
  403. 'type' => $sConnectionsType,
  404. 'mutual' => $iMutual,
  405. 'profile' => (int)$iProfileId,
  406. 'profile2' => (int)$iProfileId2
  407. ]);
  408. $o->setDesignBoxTemplateId($iDesignBox);
  409. $o->setDisplayEmptyMsg($bDisplayEmptyMsg);
  410. $o->setAjaxPaginate($bAjaxPaginate);
  411. if ($o->isError)
  412. return '';
  413. if ($s = $o->processing())
  414. return bx_is_api() ? [bx_api_get_block('browse', $s)] : $s;
  415. else
  416. return '';
  417. }
  418. public function serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
  419. {
  420. $oTemplate = BxDolTemplate::getInstance();
  421. $oProfilesQuery = BxDolProfileQuery::getInstance();
  422. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  423. if (!$aProfiles)
  424. return false;
  425. if (null === $iActiveProfileId)
  426. $iActiveProfileId = bx_get_logged_profile_id();
  427. $oModuleDb = BxDolModuleQuery::getInstance();
  428. $aVars = array (
  429. 'bx_repeat:row' => array(),
  430. );
  431. bx_alert('system', 'account_profile_switcher', 0, false, array(
  432. 'account_id' => $iAccountId,
  433. 'active_profile_id' => &$iActiveProfileId,
  434. 'url_profile_action' => &$sUrlProfileAction,
  435. 'show_all' => &$bShowAll,
  436. 'button_title' => &$sButtonTitle,
  437. 'profile_template' => &$sProfileTemplate,
  438. 'profiles' => &$aProfiles
  439. ));
  440. foreach ($aProfiles as $aProfile) {
  441. if (!$bShowAll && $iActiveProfileId == $aProfile['id'])
  442. continue;
  443. if(!$oModuleDb->isEnabledByName($aProfile['type']))
  444. continue;
  445. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  446. continue;
  447. $aVars['bx_repeat:row'][] = array (
  448. 'class' => $iActiveProfileId == $aProfile['id'] ? '' : 'bx-def-color-bg-box',
  449. 'bx_if:active' => array (
  450. 'condition' => $iActiveProfileId == $aProfile['id'],
  451. 'content' => array('id' => $aProfile['id']),
  452. ),
  453. 'bx_if:inactive' => array (
  454. 'condition' => $iActiveProfileId != $aProfile['id'],
  455. 'content' => array(
  456. 'id' => $aProfile['id'],
  457. 'button_title' => $sButtonTitle ? $sButtonTitle : _t('_sys_txt_switch_profile_context'),
  458. 'url_switch' => $sUrlProfileAction ? str_replace('{profile_id}', $aProfile['id'], $sUrlProfileAction) : BxDolProfile::getSwitchToProfileRedirectUrl($aProfile['id'])
  459. ),
  460. ),
  461. 'unit' => BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id'], array('template' => $sProfileTemplate))),
  462. );
  463. }
  464. $oTemplate->addCss('account.css');
  465. return array(
  466. 'content' => $oTemplate->parseHtmlByName('profile_switch_row.html', $aVars),
  467. );
  468. }
  469. public function serviceProfileSettingsCfilter($iProfileId = false)
  470. {
  471. if(!BxDolContentFilter::getInstance()->isEnabled()) {
  472. BxDolTemplate::getInstance()->displayPageNotFound();
  473. exit;
  474. }
  475. // set settings submenu
  476. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  477. if ($oMenuSubmenu) {
  478. $oMenuSubmenu->setObjectSubmenu('sys_account_settings_submenu', array (
  479. 'title' => _t('_sys_menu_item_title_account_settings'),
  480. 'link' => BX_DOL_URL_ROOT . 'member.php',
  481. 'icon' => '',
  482. ));
  483. }
  484. if($iProfileId === false)
  485. $iProfileId = bx_get_logged_profile_id();
  486. $oProfile = BxDolProfile::getInstance($iProfileId);
  487. $aProfileInfo = $oProfile ? $oProfile->getInfo() : false;
  488. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  489. return MsgBox(_t('_sys_txt_error_profile_is_not_defined'));
  490. $sForm = 'sys_profile';
  491. $sFormDisplay = 'sys_profile_cf_set';
  492. $oForm = BxDolForm::getObjectInstance($sForm, $sFormDisplay);
  493. if(!$oForm)
  494. return MsgBox(_t('_sys_txt_error_occured'));
  495. $oForm->initChecker($aProfileInfo);
  496. if(!$oForm->isSubmittedAndValid())
  497. return $sCode = $oForm->getCode();
  498. if(!$oForm->update($iProfileId)) {
  499. if (!$oForm->isValid())
  500. return $oForm->getCode();
  501. else
  502. return MsgBox(_t('_sys_txt_error_profile_update'));
  503. }
  504. // display result message
  505. $sMsg = MsgBox(_t('_' . $sFormDisplay . '_successfully_submitted'));
  506. return $sMsg . $oForm->getCode();
  507. }
  508. public function serviceIsAllowedCfilter($sAction, $iValue, $aProfileInfo)
  509. {
  510. if(!in_array($sAction, ['watch', 'use']) || !isset($aProfileInfo['birthday']))
  511. return false;
  512. $iAge = 0;
  513. if(!empty($aProfileInfo['birthday']) && !in_array($aProfileInfo['birthday'], array('0000-00-00', '0000-00-00 00:00:00')))
  514. $iAge = bx_birthday2age($aProfileInfo['birthday']);
  515. $iResult = 0;
  516. switch($iValue) {
  517. case 1:
  518. $iResult = $iValue;
  519. break;
  520. case 2:
  521. if($iAge >= 6)
  522. $iResult = $iValue;
  523. break;
  524. case 3:
  525. if($iAge >= 13)
  526. $iResult = $iValue;
  527. break;
  528. case 4:
  529. if($iAge >= 17)
  530. $iResult = $iValue;
  531. break;
  532. case 5:
  533. if($iAge >= 21)
  534. $iResult = $iValue;
  535. break;
  536. }
  537. if($iResult != 0)
  538. $iResult = 1 << ($iResult - 1);
  539. return $iResult;
  540. }
  541. public function serviceIsEnabledCfilter()
  542. {
  543. return BxDolContentFilter::getInstance()->isEnabled();
  544. }
  545. protected function _getIcon ($sIcon)
  546. {
  547. return BxTemplFunctions::getInstance()->getIcon($sIcon);
  548. }
  549. protected function _getLatestModuleTimestamp ()
  550. {
  551. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1, 'order_by' => '`date` ASC'));
  552. if (empty($aModules))
  553. return 0;
  554. $aModuleNewest = array_pop($aModules);
  555. return $aModuleNewest['date'];
  556. }
  557. protected function _getProfilesModules($bForceActAsProfile = true)
  558. {
  559. $aRet = array();
  560. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  561. foreach($aModules as $aModule) {
  562. $oModule = BxDolModule::getInstance($aModule['name']);
  563. if(!($oModule instanceof iBxDolProfileService))
  564. continue;
  565. if($bForceActAsProfile && !$oModule->serviceActAsProfile())
  566. continue;
  567. $aRet[] = $aModule;
  568. }
  569. return $aRet;
  570. }
  571. }
  572. /** @} */