BxBaseServiceProfiles.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 serviceAccountProfileSwitcher ($iAccountId = false, $iActiveProfileId = null, $sUrlProfileAction = '', $bShowAll = 0, $sButtonTitle = '', $sProfileTemplate = '')
  398. {
  399. $oTemplate = BxDolTemplate::getInstance();
  400. $oProfilesQuery = BxDolProfileQuery::getInstance();
  401. $aProfiles = $oProfilesQuery->getProfilesByAccount($iAccountId ? $iAccountId : getLoggedId());
  402. if (!$aProfiles)
  403. return false;
  404. if (null === $iActiveProfileId)
  405. $iActiveProfileId = bx_get_logged_profile_id();
  406. $oModuleDb = BxDolModuleQuery::getInstance();
  407. $aVars = array (
  408. 'bx_repeat:row' => array(),
  409. );
  410. bx_alert('system', 'account_profile_switcher', 0, false, array(
  411. 'account_id' => $iAccountId,
  412. 'active_profile_id' => &$iActiveProfileId,
  413. 'url_profile_action' => &$sUrlProfileAction,
  414. 'show_all' => &$bShowAll,
  415. 'button_title' => &$sButtonTitle,
  416. 'profile_template' => &$sProfileTemplate,
  417. 'profiles' => &$aProfiles
  418. ));
  419. foreach ($aProfiles as $aProfile) {
  420. if (!$bShowAll && $iActiveProfileId == $aProfile['id'])
  421. continue;
  422. if(!$oModuleDb->isEnabledByName($aProfile['type']))
  423. continue;
  424. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  425. continue;
  426. $aVars['bx_repeat:row'][] = array (
  427. 'class' => $iActiveProfileId == $aProfile['id'] ? '' : 'bx-def-color-bg-box',
  428. 'bx_if:active' => array (
  429. 'condition' => $iActiveProfileId == $aProfile['id'],
  430. 'content' => array('id' => $aProfile['id']),
  431. ),
  432. 'bx_if:inactive' => array (
  433. 'condition' => $iActiveProfileId != $aProfile['id'],
  434. 'content' => array(
  435. 'id' => $aProfile['id'],
  436. 'button_title' => $sButtonTitle ? $sButtonTitle : _t('_sys_txt_switch_profile_context'),
  437. 'url_switch' => $sUrlProfileAction ? str_replace('{profile_id}', $aProfile['id'], $sUrlProfileAction) : BxDolProfile::getSwitchToProfileRedirectUrl($aProfile['id'])
  438. ),
  439. ),
  440. 'unit' => BxDolService::call($aProfile['type'], 'profile_unit', array($aProfile['content_id'], array('template' => $sProfileTemplate))),
  441. );
  442. }
  443. $oTemplate->addCss('account.css');
  444. return array(
  445. 'content' => $oTemplate->parseHtmlByName('profile_switch_row.html', $aVars),
  446. );
  447. }
  448. public function serviceProfileSettingsCfilter($iProfileId = false)
  449. {
  450. if(!BxDolContentFilter::getInstance()->isEnabled()) {
  451. BxDolTemplate::getInstance()->displayPageNotFound();
  452. exit;
  453. }
  454. // set settings submenu
  455. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  456. if ($oMenuSubmenu) {
  457. $oMenuSubmenu->setObjectSubmenu('sys_account_settings_submenu', array (
  458. 'title' => _t('_sys_menu_item_title_account_settings'),
  459. 'link' => BX_DOL_URL_ROOT . 'member.php',
  460. 'icon' => '',
  461. ));
  462. }
  463. if($iProfileId === false)
  464. $iProfileId = bx_get_logged_profile_id();
  465. $oProfile = BxDolProfile::getInstance($iProfileId);
  466. $aProfileInfo = $oProfile ? $oProfile->getInfo() : false;
  467. if(empty($aProfileInfo) || !is_array($aProfileInfo))
  468. return MsgBox(_t('_sys_txt_error_profile_is_not_defined'));
  469. $sForm = 'sys_profile';
  470. $sFormDisplay = 'sys_profile_cf_set';
  471. $oForm = BxDolForm::getObjectInstance($sForm, $sFormDisplay);
  472. if(!$oForm)
  473. return MsgBox(_t('_sys_txt_error_occured'));
  474. $oForm->initChecker($aProfileInfo);
  475. if(!$oForm->isSubmittedAndValid())
  476. return $sCode = $oForm->getCode();
  477. if(!$oForm->update($iProfileId)) {
  478. if (!$oForm->isValid())
  479. return $oForm->getCode();
  480. else
  481. return MsgBox(_t('_sys_txt_error_profile_update'));
  482. }
  483. // display result message
  484. $sMsg = MsgBox(_t('_' . $sFormDisplay . '_successfully_submitted'));
  485. return $sMsg . $oForm->getCode();
  486. }
  487. public function serviceIsAllowedCfilter($sAction, $iValue, $aProfileInfo)
  488. {
  489. if(!in_array($sAction, ['watch', 'use']) || !isset($aProfileInfo['birthday']))
  490. return false;
  491. $iAge = 0;
  492. if(!empty($aProfileInfo['birthday']) && !in_array($aProfileInfo['birthday'], array('0000-00-00', '0000-00-00 00:00:00')))
  493. $iAge = bx_birthday2age($aProfileInfo['birthday']);
  494. $iResult = 0;
  495. switch($iValue) {
  496. case 1:
  497. $iResult = $iValue;
  498. break;
  499. case 2:
  500. if($iAge >= 6)
  501. $iResult = $iValue;
  502. break;
  503. case 3:
  504. if($iAge >= 13)
  505. $iResult = $iValue;
  506. break;
  507. case 4:
  508. if($iAge >= 17)
  509. $iResult = $iValue;
  510. break;
  511. case 5:
  512. if($iAge >= 21)
  513. $iResult = $iValue;
  514. break;
  515. }
  516. if($iResult != 0)
  517. $iResult = 1 << ($iResult - 1);
  518. return $iResult;
  519. }
  520. public function serviceIsEnabledCfilter()
  521. {
  522. return BxDolContentFilter::getInstance()->isEnabled();
  523. }
  524. protected function _getIcon ($sIcon)
  525. {
  526. return BxTemplFunctions::getInstance()->getIcon($sIcon);
  527. }
  528. protected function _getLatestModuleTimestamp ()
  529. {
  530. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1, 'order_by' => '`date` ASC'));
  531. if (empty($aModules))
  532. return 0;
  533. $aModuleNewest = array_pop($aModules);
  534. return $aModuleNewest['date'];
  535. }
  536. protected function _getProfilesModules($bForceActAsProfile = true)
  537. {
  538. $aRet = array();
  539. $aModules = BxDolModuleQuery::getInstance()->getModulesBy(array('type' => 'modules', 'active' => 1));
  540. foreach($aModules as $aModule) {
  541. $oModule = BxDolModule::getInstance($aModule['name']);
  542. if(!($oModule instanceof iBxDolProfileService))
  543. continue;
  544. if($bForceActAsProfile && !$oModule->serviceActAsProfile())
  545. continue;
  546. $aRet[] = $aModule;
  547. }
  548. return $aRet;
  549. }
  550. }
  551. /** @} */