BxBaseServiceProfiles.php 22 KB

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