1
0

BxDolAccount.php 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. bx_import('BxDolAcl');
  10. class BxDolAccount extends BxDolFactory implements iBxDolSingleton
  11. {
  12. protected $_bIsApi;
  13. protected $_iAccountID;
  14. protected $_aInfo;
  15. protected $_oQuery;
  16. protected $_sImageField;
  17. protected $_aImageTranscoders;
  18. /**
  19. * Constructor
  20. */
  21. protected function __construct ($iAccountId)
  22. {
  23. $iAccountId = (int)$iAccountId;
  24. $sClass = get_class($this) . '_' . $iAccountId;
  25. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  26. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  27. parent::__construct();
  28. $this->_bIsApi = bx_is_api();
  29. $this->_iAccountID = $iAccountId; // since constructor is protected $iAccountId is always valid
  30. $this->_oQuery = BxDolAccountQuery::getInstance();
  31. $this->_sImageField = 'picture';
  32. $this->_aImageTranscoders = [
  33. 'icon' => 'sys_accounts_icon',
  34. 'thumb' => 'sys_accounts_thumb',
  35. 'ava' => 'sys_accounts_avatar',
  36. 'ava_big' => 'sys_accounts_avatar_big',
  37. 'picture' => 'sys_accounts_picture'
  38. ];
  39. }
  40. /**
  41. * Prevent cloning the instance
  42. */
  43. public function __clone()
  44. {
  45. $sClass = get_class($this) . '_' . $this->_iProfileID;
  46. if (isset($GLOBALS['bxDolClasses'][$sClass]))
  47. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  48. }
  49. /**
  50. * Get singleton instance of the class
  51. */
  52. public static function getInstance($mixedAccountId = false, $bClearCache = false)
  53. {
  54. if (!$mixedAccountId)
  55. $mixedAccountId = getLoggedId();
  56. $iAccountId = self::getID($mixedAccountId);
  57. if (!$iAccountId)
  58. return false;
  59. $sClass = __CLASS__ . '_' . $iAccountId;
  60. if ($bClearCache && isset($GLOBALS['bxDolClasses'][$sClass]))
  61. unset($GLOBALS['bxDolClasses'][$sClass]);
  62. if(!isset($GLOBALS['bxDolClasses'][$sClass]))
  63. $GLOBALS['bxDolClasses'][$sClass] = new BxDolAccount($iAccountId);
  64. return $GLOBALS['bxDolClasses'][$sClass];
  65. }
  66. /**
  67. * Get studio operator account singleton instance on the class
  68. */
  69. public static function getInstanceStudioOperator()
  70. {
  71. $oQuery = BxDolAccountQuery::getInstance();
  72. if (!($iId = $oQuery->getStudioOperatorId()))
  73. return false;
  74. return self::getInstance($iId);
  75. }
  76. /**
  77. * Get account id
  78. */
  79. public function id()
  80. {
  81. $a = $this->getInfo($this->_iAccountID);
  82. return isset($a['id']) ? $a['id'] : false;
  83. }
  84. /**
  85. * Check if account is confirmed, it is checked by email confirmation
  86. */
  87. public function isConfirmed($iAccountId = false)
  88. {
  89. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  90. $a = $this->getInfo($iId);
  91. $bResult = false;
  92. $sConfirmationType = getParam('sys_account_confirmation_type');
  93. switch($sConfirmationType) {
  94. case BX_ACCOUNT_CONFIRMATION_NONE:
  95. $bResult = true;
  96. break;
  97. case BX_ACCOUNT_CONFIRMATION_EMAIL:
  98. if($a['email_confirmed'])
  99. $bResult = true;
  100. break;
  101. case BX_ACCOUNT_CONFIRMATION_PHONE:
  102. if($a['phone_confirmed'])
  103. $bResult = true;
  104. break;
  105. case BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE:
  106. if($a['email_confirmed'] && $a['phone_confirmed'])
  107. $bResult = true;
  108. break;
  109. case BX_ACCOUNT_CONFIRMATION_EMAIL_OR_PHONE:
  110. if($a['email_confirmed'] || $a['phone_confirmed'])
  111. $bResult = true;
  112. break;
  113. }
  114. /**
  115. * @hooks
  116. * @hookdef hook-account-is_confirmed 'account', 'is_confirmed' - hook in $oAccount->isConfirmed check
  117. * - $unit_name - equals `account`
  118. * - $action - equals `is_confirmed`
  119. * - $object_id - account id
  120. * - $sender_id - not used
  121. * - $extra_params - array of additional params with the following array keys:
  122. * - `type` - [string] confirmation type can be none/phone/email/email_and_phone/email_or_phone
  123. * - `override_result` - [bool] by ref, if account confirmed = true, otherwise false, can be overridden in hook processing
  124. * @hook @ref hook-account-is_confirmed
  125. */
  126. bx_alert('account', 'is_confirmed', $iId, false, array('type' => $sConfirmationType, 'override_result' => &$bResult));
  127. return $bResult;
  128. }
  129. public function getCurrentConfirmationStatusValue($iAccountId = false)
  130. {
  131. $a = $this->getInfo((int)$iAccountId);
  132. $sTmp = $a['email_confirmed'] . $a['phone_confirmed'];
  133. switch ($sTmp) {
  134. case '01':
  135. return BX_ACCOUNT_CONFIRMATION_PHONE;
  136. case '10':
  137. return BX_ACCOUNT_CONFIRMATION_EMAIL;
  138. case '11':
  139. return BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE;
  140. }
  141. return BX_ACCOUNT_CONFIRMATION_NONE;
  142. }
  143. public function isConfirmedEmail($iAccountId = false)
  144. {
  145. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  146. $bResult = false;
  147. if(self::isNeedConfirmEmail()) {
  148. $a = $this->getInfo($iId);
  149. $bResult = $a['email_confirmed'] ? true : false;
  150. }
  151. else
  152. $bResult = true;
  153. /**
  154. * @hooks
  155. * @hookdef hook-account-is_confirmed 'account', 'is_confirmed_email' - hook in $oAccount->isConfirmedEmail check
  156. * - $unit_name - equals `account`
  157. * - $action - equals `is_confirmed_email`
  158. * - $object_id - account id
  159. * - $sender_id - not used
  160. * - $extra_params - array of additional params with the following array keys:
  161. * - `override_result` - [bool] by ref, if email confirmed = true, otherwise false, can be overridden in hook processing
  162. * @hook @ref hook-account-is_confirmed_email
  163. */
  164. bx_alert('account', 'is_confirmed_email', $iId, false, array('override_result' => &$bResult));
  165. return $bResult;
  166. }
  167. public function isConfirmedPhone($iAccountId = false)
  168. {
  169. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  170. $bResult = false;
  171. if(self::isNeedConfirmPhone()) {
  172. $a = $this->getInfo((int)$iAccountId);
  173. $bResult = $a['phone_confirmed'] ? true : false;
  174. }
  175. else
  176. $bResult = true;
  177. /**
  178. * @hooks
  179. * @hookdef hook-account-is_confirmed_phone 'account', 'is_confirmed_phone' - hook in $oAccount->isConfirmedPhone check
  180. * - $unit_name - equals `account`
  181. * - $action - equals `is_confirmed_phone`
  182. * - $object_id - account id
  183. * - $sender_id - not used
  184. * - $extra_params - array of additional params with the following array keys:
  185. * - `override_result` - [bool] by ref, if phone confirmed = true, otherwise false, can be overridden in hook processing
  186. * @hook @ref hook-account-is_confirmed_phone
  187. */
  188. bx_alert('account', 'is_confirmed_phone', $iId, false, array('override_result' => &$bResult));
  189. return $bResult;
  190. }
  191. static public function isNeedConfirmEmail()
  192. {
  193. if(in_array(getParam('sys_account_confirmation_type'), array(BX_ACCOUNT_CONFIRMATION_EMAIL, BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE, BX_ACCOUNT_CONFIRMATION_EMAIL_OR_PHONE)))
  194. return true;
  195. return false;
  196. }
  197. static public function isNeedConfirmPhone()
  198. {
  199. if(in_array(getParam('sys_account_confirmation_type'), array(BX_ACCOUNT_CONFIRMATION_PHONE, BX_ACCOUNT_CONFIRMATION_EMAIL_PHONE, BX_ACCOUNT_CONFIRMATION_EMAIL_OR_PHONE)))
  200. return true;
  201. return false;
  202. }
  203. public function isLocked($iAccountId = false)
  204. {
  205. $a = $this->getInfo((int)$iAccountId);
  206. return $a['locked'] ? true : false;
  207. }
  208. //
  209. /**
  210. * Set account email to confirmed or unconfirmed
  211. * @param int $isConfirmed - false: mark email as unconfirmed, true: as confirmed
  212. * @param int $iAccountId - optional account id
  213. * @return true on success or false on error
  214. */
  215. public function updateEmailConfirmed($isConfirmed, $isAutoSendConfrmationEmail = true, $iAccountId = false)
  216. {
  217. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  218. if (!$isConfirmed && $isAutoSendConfrmationEmail && self::isNeedConfirmEmail()) // if email_confirmation procedure is enabled - send email confirmation letter
  219. $this->sendConfirmationEmail($iId);
  220. if ($this->_oQuery->updateEmailConfirmed($isConfirmed, $iId)) {
  221. $this->_aInfo = false;
  222. /**
  223. * @hooks
  224. * @hookdef hook-account-confirm 'account', 'confirm' - hook in email confirmation $oAccount->updateEmailConfirmed
  225. * - $unit_name - equals `account`
  226. * - $action - can be confirm/unconfirm
  227. * - $object_id - account id
  228. * - $sender_id - not used
  229. * - $extra_params - not used
  230. * @hook @ref hook-account-confirm
  231. */
  232. bx_alert('account', $this->isConfirmed() ? 'confirm' : 'unconfirm', $iId);
  233. return true;
  234. }
  235. return false;
  236. }
  237. /**
  238. * Set account phone to confirmed or unconfirmed
  239. * @param int $isConfirmed - false: mark phone as unconfirmed, true: as confirmed
  240. * @param int $iAccountId - optional account id
  241. * @return true on success or false on error
  242. */
  243. public function updatePhoneConfirmed($isConfirmed, $iAccountId = false)
  244. {
  245. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  246. if ($this->_oQuery->updatePhoneConfirmed($isConfirmed, $iId)) {
  247. $this->_aInfo = false;
  248. bx_alert('account', $this->isConfirmed() ? 'confirm' : 'unconfirm', $iId);
  249. return true;
  250. }
  251. return false;
  252. }
  253. /**
  254. * Change account password
  255. * @param string $sPassword - new password
  256. * @param int $iAccountId - optional account id
  257. * @return true on success or false on error
  258. */
  259. public function updatePassword($sPassword, $iAccountId = false)
  260. {
  261. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  262. $sSalt = genRndSalt();
  263. $sPasswordHash = encryptUserPwd($sPassword, $sSalt);
  264. $this->_oQuery->logPassword($iId);
  265. if((int)$this->_oQuery->updatePassword($sPasswordHash, $sSalt, $iId) > 0) {
  266. /**
  267. * @hooks
  268. * @hookdef hook-account-edited 'account', 'edited' - hook on account edited $oAccount->updatePassword
  269. * - $unit_name - equals `account`
  270. * - $action - equals edited
  271. * - $object_id - account id
  272. * - $sender_id - account sender id
  273. * - $extra_params - array of additional params with the following array keys:
  274. * - `action` - [string] action's name, can be reset_password
  275. * @hook @ref hook-account-edited
  276. */
  277. bx_alert('account', 'edited', $iId, ($iSenderId = getLoggedId()) != 0 ? $iSenderId : $iId, [
  278. 'action' => 'reset_password'
  279. ]);
  280. $this->doAudit($iId, '_sys_audit_action_account_reset_password');
  281. return true;
  282. }
  283. return false;
  284. }
  285. /**
  286. * Set account phone
  287. * @param string $sPhone - phone number
  288. * @param int $iAccountId - optional account id
  289. * @return true on success or false on error
  290. */
  291. public function updatePhone($sPhone, $iAccountId = false)
  292. {
  293. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  294. if ($this->_oQuery->updatePhone($sPhone, $iId)) {
  295. /**
  296. * @hooks
  297. * @hookdef hook-account-set_phone 'account', 'set_phone' - hook after accout password changed
  298. * - $unit_name - equals `account`
  299. * - $action - equals `set_phone`
  300. * - $object_id - account id
  301. * - $sender_id - not used
  302. * - $extra_params - not used
  303. * @hook @ref hook-account-set_phone
  304. */
  305. bx_alert('account', 'set_phone', $iId);
  306. return true;
  307. }
  308. return false;
  309. }
  310. /**
  311. * Switch context automatically to the first available profile
  312. * @param $iProfileIdFilterOut profile ID to exclude from the list of possible profiles
  313. * @param $iAccountId account ID to use istead of current account
  314. * @return true on success or false on error
  315. */
  316. public function updateProfileContextAuto($iProfileIdFilterOut = false, $iAccountId = false)
  317. {
  318. $oAccount = (!$iAccountId || $iAccountId == $this->_iAccountID ? $this : BxDolAccount::getInstance ($iAccountId));
  319. if (!$oAccount)
  320. return false;
  321. $aAccountInfo = $oAccount->getInfo();
  322. $aProfiles = $oAccount->getProfiles();
  323. $oProfileAccount = BxDolProfile::getInstanceAccountProfile($oAccount->id());
  324. // unset deleted profile and account profile
  325. if ($iProfileIdFilterOut)
  326. unset($aProfiles[$iProfileIdFilterOut]);
  327. unset($aProfiles[$oProfileAccount->id()]);
  328. if ($aProfiles) {
  329. // try to use another profile
  330. reset($aProfiles);
  331. $iProfileId = key($aProfiles);
  332. }
  333. else {
  334. // if no profiles exist, use account profile
  335. $iProfileId = $oProfileAccount->id();
  336. }
  337. return $oAccount->updateProfileContext($iProfileId);
  338. }
  339. public function updateProfileContext($iSwitchToProfileId, $iAccountId = false)
  340. {
  341. $iId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  342. $aInfo = $this->getInfo((int)$iId);
  343. if (!$aInfo)
  344. return false;
  345. $ret = null;
  346. /**
  347. * @hooks
  348. * @hookdef hook-account-before_switch_context 'account', 'before_switch_context' - hook before switch profile_id from current logged user
  349. * - $unit_name - equals `account`
  350. * - $action - equals `before_switch_context`
  351. * - $object_id - account id
  352. * - $sender_id - profile_id to switch to
  353. * - $extra_params - array of additional params with the following array keys:
  354. * - `profile_id_current` - [int] current profile_id
  355. * - `override_result` - [int] by ref, profile_id to switch to, can be overridden in hook processing
  356. * @hook @ref hook-account-before_switch_context
  357. */
  358. bx_alert('account', 'before_switch_context', $iId, $iSwitchToProfileId, array('profile_id_current' => $aInfo['profile_id'], 'override_result' => &$ret));
  359. if ($ret !== null)
  360. return $ret;
  361. if (!$this->_oQuery->updateCurrentProfile($iId, $iSwitchToProfileId))
  362. return false;
  363. $this->_aInfo = false;
  364. /**
  365. * @hooks
  366. * @hookdef hook-account-switch_context 'account', 'switch_context' - hook before switch profile_id from current logged user
  367. * - $unit_name - equals `account`
  368. * - $action - equals `switch_context`
  369. * - $object_id - account id
  370. * - $sender_id - profile_id to switch to
  371. * - $extra_params - array of additional params with the following array keys:
  372. * - `profile_id_old` - [int] old profile_id
  373. * @hook @ref hook-account-switch_context
  374. */
  375. bx_alert('account', 'switch_context', $iId, $iSwitchToProfileId, array('profile_id_old' => $aInfo['profile_id']));
  376. return true;
  377. }
  378. /**
  379. * Send "confirmation" email
  380. */
  381. public function sendConfirmationEmail($iAccountId = false)
  382. {
  383. $iAccountId = (int)$iAccountId;
  384. if(!$iAccountId)
  385. $iAccountId = $this->_iAccountID;
  386. $aAccountInfo = $this->getInfo($iAccountId);
  387. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  388. return false;
  389. $oKey = BxDolKey::getInstance();
  390. $sConfirmationCode = $oKey->getNewKeyNumeric(['account_id' => $iAccountId]);
  391. $sConfirmationLink = bx_append_url_params(BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email'), ['code' => $sConfirmationCode]);
  392. $sEmailTemplate = 't_Confirmation';
  393. $aEmailReplaceVars = [
  394. 'name' => $this->getDisplayName($iAccountId),
  395. 'email' => $aAccountInfo['email'],
  396. 'conf_code' => $sConfirmationCode,
  397. 'conf_link' => $sConfirmationLink,
  398. 'conf_form_link' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email')
  399. ];
  400. $bResult = sendMailTemplate($sEmailTemplate, $iAccountId, (int)$aAccountInfo['profile_id'], $aEmailReplaceVars, BX_EMAIL_SYSTEM);
  401. if($bResult)
  402. $this->doAudit($iAccountId, '_sys_audit_action_account_resend_confirmation_email');
  403. return $bResult;
  404. }
  405. /**
  406. * Send "welcome" email
  407. */
  408. public function sendWelcomeEmail($iAccountId = false)
  409. {
  410. if(getParam('sys_account_welcome_letter') != 'on')
  411. return false;
  412. $iAccountId = (int)$iAccountId;
  413. if(!$iAccountId)
  414. $iAccountId = $this->_iAccountID;
  415. $aAccountInfo = $this->getInfo($iAccountId);
  416. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  417. return false;
  418. if((int)$aAccountInfo['welcome_sent'] != 0)
  419. return true;
  420. $sEmailTemplate = 't_Welcome';
  421. $aEmailReplaceVars = [
  422. 'name' => $this->getDisplayName($iAccountId),
  423. ];
  424. $bResult = sendMailTemplate($sEmailTemplate, $iAccountId, (int)$aAccountInfo['profile_id'], $aEmailReplaceVars, BX_EMAIL_SYSTEM);
  425. if($bResult)
  426. $this->_oQuery->updateWelcomeSent(1, $iAccountId);
  427. return $bResult;
  428. }
  429. public function sendResetPasswordEmail($iAccountId = false)
  430. {
  431. $iAccountId = (int)$iAccountId;
  432. if(!$iAccountId)
  433. $iAccountId = $this->_iAccountID;
  434. $aAccountInfo = $this->getInfo($iAccountId);
  435. if(empty($aAccountInfo) || !is_array($aAccountInfo))
  436. return false;
  437. $sKey = bx_get_reset_password_key($aAccountInfo['email']);
  438. $aReplaceVars = array(
  439. 'name' => $this->getDisplayName($iAccountId),
  440. 'email' => $aAccountInfo['email'],
  441. 'key' => $sKey,
  442. 'forgot_password_url' => bx_get_reset_password_link_by_key($sKey)
  443. );
  444. return sendMailTemplate('t_Forgot', $iAccountId, (int)$aAccountInfo['profile_id'], $aReplaceVars, BX_EMAIL_SYSTEM);
  445. }
  446. /**
  447. * Get account info
  448. */
  449. public function getInfo($iAccountId = false)
  450. {
  451. if ($iAccountId && $iAccountId != $this->_iAccountID)
  452. return $this->_oQuery->getInfoById((int)$iAccountId ? (int)$iAccountId : $this->_iAccountID);
  453. if ($this->_aInfo)
  454. return $this->_aInfo;
  455. $this->_aInfo = $this->_oQuery->getInfoById($this->_iAccountID);
  456. return $this->_aInfo;
  457. }
  458. /**
  459. * Get account display name
  460. */
  461. public function getDisplayName($iAccountId = false)
  462. {
  463. $aInfo = $this->getInfo($iAccountId);
  464. $sDisplayName = !empty($aInfo['name']) ? $aInfo['name'] : _t('_sys_txt_user_n', $aInfo['id']);
  465. /**
  466. * @hooks
  467. * @hookdef hook-account-account_name 'account', 'account_name' - hook on get account display name
  468. * - $unit_name - equals `account`
  469. * - $action - equals `account_name`
  470. * - $object_id - account id
  471. * - $sender_id - not used
  472. * - $extra_params - array of additional params with the following array keys:
  473. * - `info` - [array] contains account info from $oAccount->getInfo()
  474. * - `display_name` - [string] by ref, account display name, can be overridden in hook processing
  475. * @hook @ref hook-account-account_name
  476. */
  477. bx_alert('account', 'account_name', $iAccountId, 0, array('info' => $aInfo, 'display_name' => &$sDisplayName, 'display_name_ref' => &$sDisplayName));
  478. return bx_process_output($sDisplayName);
  479. }
  480. /**
  481. * Get account url
  482. */
  483. public function getUrl($iAccountId = false)
  484. {
  485. return 'javascript:void(0);';
  486. }
  487. /**
  488. * Get account url
  489. */
  490. public function getUnit($iAccountId = false, $aParams = array())
  491. {
  492. $sTemplate = 'unit';
  493. $sTemplateSize = false;
  494. $aTemplateVars = array();
  495. if(!empty($aParams['template'])) {
  496. if(is_string($aParams['template']))
  497. $sTemplate = $aParams['template'];
  498. else if(is_array($aParams['template'])) {
  499. if(!empty($aParams['template']['name']))
  500. $sTemplate = $aParams['template']['name'];
  501. if(!empty($aParams['template']['size']))
  502. $sTemplateSize = $aParams['template']['size'];
  503. if(!empty($aParams['template']['vars']))
  504. $aTemplateVars = $aParams['template']['vars'];
  505. }
  506. }
  507. $sTemplate = 'account_' . $sTemplate . '.html';
  508. if(empty($sTemplateSize))
  509. $sTemplateSize = 'thumb';
  510. $sTitle = $this->getDisplayName($iAccountId);
  511. $aInfo = $this->getInfo($iAccountId);
  512. $sImageUrl = $this->_getImageUrl($sTemplateSize, $aInfo);
  513. $bImageUrl = !empty($sImageUrl);
  514. $aTmplVars = [
  515. 'size' => $sTemplateSize,
  516. 'content_url' => $this->getUrl($iAccountId),
  517. 'title' => $sTitle,
  518. 'title_attr' => bx_html_attribute($sTitle),
  519. 'bx_if:show_thumb_image' => [
  520. 'condition' => $bImageUrl,
  521. 'content' => [
  522. 'size' => $sTemplateSize,
  523. 'url' => $sImageUrl
  524. ]
  525. ],
  526. 'bx_if:show_thumb_letter' => [
  527. 'condition' => !$bImageUrl,
  528. 'content' => [
  529. 'size' => $sTemplateSize,
  530. 'color' => implode(', ', BxDolTemplate::getColorCode(($iAccountId ? $iAccountId : $this->_iAccountID), 1.0)),
  531. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1)),
  532. ]
  533. ],
  534. 'bx_if:show_online' => [
  535. 'condition' => $this->isOnline($iAccountId),
  536. 'content' => []
  537. ]
  538. ];
  539. if(!empty($aTemplateVars) && is_array($aTemplateVars))
  540. $aTmplVars = array_merge ($aTmplVars, $aTemplateVars);
  541. return BxDolTemplate::getInstance()->parseHtmlByName($sTemplate, $aTmplVars);
  542. }
  543. public function getUnitApi($iAccountId = false, $aParams = array())
  544. {
  545. if(!$iAccountId)
  546. $iAccountId = $this->_iAccountID;
  547. $sModule = 'system';
  548. $iAuthorId = 0;
  549. $aAuthorData = [];
  550. if(($oProfile = BxDolProfile::getInstanceByContentAndType($iAccountId, $sModule)) !== false) {
  551. $iAuthorId = $oProfile->id();
  552. $aAuthorData = BxDolProfile::getData($iAuthorId);
  553. }
  554. $aInfo = $this->getInfo($iAccountId);
  555. return [
  556. 'id' => $aInfo['id'],
  557. 'module' => $sModule,
  558. 'module_title' => $sModule,
  559. 'added' => $aInfo['added'],
  560. 'author' => $iAuthorId,
  561. 'author_data' => $aAuthorData,
  562. 'title' => $this->getDisplayName($iAccountId),
  563. ];
  564. }
  565. /**
  566. * Get picture url
  567. */
  568. public function getPicture($iAccountId = false)
  569. {
  570. if($this->_bIsApi)
  571. return '';
  572. $sImageUrl = $this->_getImageUrl('picture', $iAccountId);
  573. if(!$sImageUrl)
  574. $sImageUrl = BxDolTemplate::getInstance()->getImageUrl('account.svg');
  575. return $sImageUrl;
  576. }
  577. /**
  578. * Get big (2x) avatar url
  579. */
  580. public function getAvatarBig($iAccountId = false)
  581. {
  582. if($this->_bIsApi)
  583. return '';
  584. $sImageUrl = $this->_getImageUrl('ava_big', $iAccountId);
  585. if(!$sImageUrl)
  586. $sImageUrl = BxDolTemplate::getInstance()->getImageUrl('account.svg');
  587. return $sImageUrl;
  588. }
  589. /**
  590. * Get avatar url
  591. */
  592. public function getAvatar($iAccountId = false)
  593. {
  594. if($this->_bIsApi)
  595. return '';
  596. $sImageUrl = $this->_getImageUrl('ava', $iAccountId);
  597. if(!$sImageUrl)
  598. $sImageUrl = BxDolTemplate::getInstance()->getImageUrl('account.svg');
  599. return $sImageUrl;
  600. }
  601. /**
  602. * Get thumb picture url
  603. */
  604. public function getThumb($iAccountId = false)
  605. {
  606. if($this->_bIsApi)
  607. return '';
  608. $sImageUrl = $this->_getImageUrl('thumb', $iAccountId);
  609. if(!$sImageUrl)
  610. $sImageUrl = BxDolTemplate::getInstance()->getImageUrl('account.svg');
  611. return $sImageUrl;
  612. }
  613. /**
  614. * Get icon picture url
  615. */
  616. public function getIcon($iAccountId = false)
  617. {
  618. if($this->_bIsApi)
  619. return '';
  620. $sImageUrl = $this->_getImageUrl('icon', $iAccountId);
  621. if(!$sImageUrl)
  622. $sImageUrl = BxDolTemplate::getInstance()->getImageUrl('account.svg');
  623. return $sImageUrl;
  624. }
  625. /**
  626. * Get account email
  627. */
  628. public function getEmail($iAccountId = false)
  629. {
  630. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  631. $aAccountInfo = $this->getInfo($iAccountId);
  632. return $aAccountInfo['email'];
  633. }
  634. /**
  635. * Get language ID
  636. */
  637. public function getLanguageId($iAccountId = false)
  638. {
  639. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  640. $aAccountInfo = $this->getInfo($iAccountId);
  641. return $aAccountInfo['lang_id'];
  642. }
  643. /**
  644. * Is account online
  645. */
  646. public function isOnline($iAccountId = false)
  647. {
  648. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  649. return $this->_oQuery->isOnline($iAccountId);
  650. }
  651. /**
  652. * Validate account.
  653. * @param $s - account identifier (id or email)
  654. * @return account id or false if account was not found
  655. */
  656. static public function getID($s)
  657. {
  658. $oQuery = BxDolAccountQuery::getInstance();
  659. bx_import('BxDolForm');
  660. if (BxDolFormCheckerHelper::checkEmail($s)) {
  661. $iId = (int)$oQuery->getIdByEmail($s);
  662. return $iId ? $iId : false;
  663. }
  664. if (preg_match("/^\+[0-9\s]+$/", $s)) {
  665. $iId = (int)$oQuery->getIdByPhone($s);
  666. return $iId ? $iId : false;
  667. }
  668. $iId = $oQuery->getIdById((int)$s);
  669. return $iId ? $iId : false;
  670. }
  671. /**
  672. * Check if profiles limit reached
  673. */
  674. public function isProfilesLimitReached ()
  675. {
  676. $iProfilesLimit = (int)getParam('sys_account_limit_profiles_number');
  677. /**
  678. * @hooks
  679. * @hookdef hook-account-get_limit_profiles_number 'account', 'get_limit_profiles_number' - hook on get account limit on the number of profiles
  680. * - $unit_name - equals `account`
  681. * - $action - equals `get_limit_profiles_number`
  682. * - $object_id - not used
  683. * - $sender_id - not used
  684. * - $extra_params - array of additional params with the following array keys:
  685. * - `account_id` - [int] account id
  686. * - `number` - [int] by ref, account limit on the number of profiles, can be overridden in hook processing
  687. * @hook @ref hook-account-get_limit_profiles_number
  688. */
  689. bx_alert('account', 'get_limit_profiles_number', 0, 0, array('account_id' => $this->_iAccountID, 'number' => &$iProfilesLimit, 'number_ref' => &$iProfilesLimit));
  690. if (!isAdmin() && $iProfilesLimit && ($iProfilesNum = $this->getProfilesNumber()) && $iProfilesNum >= $iProfilesLimit)
  691. return true;
  692. return false;
  693. }
  694. /**
  695. * Get number of profiles associated with the account
  696. */
  697. public function getProfilesNumber ($isFilterNonSwitchableProfiles = true)
  698. {
  699. $a = $this->getProfilesIds($isFilterNonSwitchableProfiles);
  700. return count($a);
  701. }
  702. /**
  703. * Get all profile ids associated with the account
  704. */
  705. public function getProfilesIds ($isFilterNonSwitchableProfiles = true, $isFilterSystemProfiles = true)
  706. {
  707. $a = $this->getProfiles ($isFilterNonSwitchableProfiles, $isFilterSystemProfiles);
  708. return $a ? array_keys($a) : array();
  709. }
  710. /**
  711. * Get all profiles associated with the account
  712. */
  713. public function getProfiles ($isFilterNonSwitchableProfiles = true, $isFilterSystemProfiles = true)
  714. {
  715. $oProfileQuery = BxDolProfileQuery::getInstance();
  716. $aProfiles = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
  717. if ($isFilterNonSwitchableProfiles) {
  718. foreach ($aProfiles as $iProfileId => $aProfile) {
  719. if ('system' == $aProfile['type'])
  720. continue;
  721. if (!BxDolService::call($aProfile['type'], 'act_as_profile'))
  722. unset($aProfiles[$iProfileId]);
  723. }
  724. }
  725. if ($isFilterSystemProfiles) {
  726. foreach ($aProfiles as $iProfileId => $aProfile) {
  727. if ('system' == $aProfile['type'])
  728. unset($aProfiles[$iProfileId]);
  729. }
  730. }
  731. return $aProfiles;
  732. }
  733. /**
  734. * Delete profile.
  735. * @param $bDeleteWithContent - delete associated profiles with all its contents
  736. * @param $bScheduled - delete account using background jobs.
  737. */
  738. function delete($bDeleteWithContent = false, $bScheduled = false)
  739. {
  740. if ($bScheduled)
  741. return BxDolBackgroundJobs::getInstance()->add('account_delete_' . $this->_iAccountID, ['system', 'account_delete', [$this->_iAccountID, $bDeleteWithContent], 'TemplServiceAccount']);
  742. $aAccountInfo = $this->_oQuery->getInfoById($this->_iAccountID);
  743. if (!$aAccountInfo)
  744. return false;
  745. // create system event before deletion
  746. $isStopDeletion = false;
  747. /**
  748. * @hooks
  749. * @hookdef hook-account-before_delete 'account', 'before_delete' - hook on before delete account,
  750. * - $unit_name - equals `account`
  751. * - $action - equals `before_delete`
  752. * - $object_id - account id
  753. * - $sender_id - not used
  754. * - $extra_params - array of additional params with the following array keys:
  755. * - `delete_with_content` - [bool] if account will delete with content = true, otherwise = false
  756. * - `stop_deletion` - [bool] by ref, if it set to true account deletion will stopped, can be overridden in hook processing
  757. * @hook @ref hook-account-before_delete
  758. */
  759. bx_alert('account', 'before_delete', $this->_iAccountID, 0, array('delete_with_content' => $bDeleteWithContent, 'stop_deletion' => &$isStopDeletion, 'stop_deletion_ref' => &$isStopDeletion));
  760. if ($isStopDeletion)
  761. return false;
  762. $oAccountQuery = BxDolAccountQuery::getInstance();
  763. $oProfileQuery = BxDolProfileQuery::getInstance();
  764. $aProfiles = $oProfileQuery->getProfilesByAccount($this->_iAccountID);
  765. foreach ($aProfiles as $iProfileId => $aRow) {
  766. $oProfile = BxDolProfile::getInstance($iProfileId);
  767. if (!$oProfile)
  768. continue;
  769. $oProfile->delete(false, $bDeleteWithContent, true);
  770. }
  771. // delete profile
  772. if (!$oAccountQuery->delete($this->_iAccountID))
  773. return false;
  774. // unset class instance to prevent creating the instance again
  775. $sClass = __CLASS__ . '_' . $this->_iAccountID;
  776. unset($GLOBALS['bxDolClasses'][$sClass]);
  777. /**
  778. * @hooks
  779. * @hookdef hook-account-delete 'account', 'delete' - hook on after delete account
  780. * - $unit_name - equals `account`
  781. * - $action - equals `delete`
  782. * - $object_id - account id
  783. * - $sender_id - not used
  784. * - $extra_params - array of additional params with the following array keys:
  785. * - `delete_with_content` - [bool] if account will delete with content = true, otherwise = false
  786. * @hook @ref hook-account-delete
  787. */
  788. bx_alert('account', 'delete', $this->_iAccountID, 0, array ('delete_with_content' => $bDeleteWithContent));
  789. $this->doAudit($this->_iAccountID, $bDeleteWithContent ? '_sys_audit_action_account_deleted_with_content' : '_sys_audit_action_account_deleted');
  790. return true;
  791. }
  792. /**
  793. * Add permament messages.
  794. */
  795. public function addInformerPermanentMessages ($oInformer)
  796. {
  797. if (!$this->isConfirmed()) {
  798. if (!$this->isConfirmedEmail()) {
  799. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-email');
  800. $aAccountInfo = $this->getInfo();
  801. $oInformer->add('sys-account-unconfirmed-email', _t('_sys_txt_account_unconfirmed_email', $sUrl . '&resend=1', $aAccountInfo['email'], $sUrl), BX_INFORMER_ALERT);
  802. }
  803. if (!$this->isConfirmedPhone()) {
  804. $sUrl = BxDolPermalinks::getInstance()->permalink('page.php?i=confirm-phone') . '';
  805. $aAccountInfo = $this->getInfo();
  806. $oInformer->add('sys-account-unconfirmed-phone', _t('_sys_txt_account_unconfirmed_phone', $sUrl), BX_INFORMER_ALERT);
  807. }
  808. }
  809. $this->isNeedChangePassword(false, $oInformer);
  810. }
  811. public function addInformerDeletionScheduled($oInformer)
  812. {
  813. if(BxDolBackgroundJobs::getInstance()->exists('account_delete_' . $this->_iAccountID))
  814. $oInformer->add('sys-account-deletion-scheduled', _t('_sys_txt_account_deletion_scheduled'), BX_INFORMER_ALERT);
  815. }
  816. /**
  817. * Get unsubscribe link for the specified mesage type
  818. */
  819. public function getUnsubscribeLink($iEmailType, $iAccountId = false)
  820. {
  821. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  822. $sUrl = '';
  823. switch ($iEmailType) {
  824. case BX_EMAIL_NOTIFY:
  825. $sUrl = 'page.php?i=unsubscribe-notifications';
  826. break;
  827. case BX_EMAIL_MASS:
  828. $sUrl = 'page.php?i=unsubscribe-news';
  829. break;
  830. default:
  831. return '';
  832. }
  833. return BxDolPermalinks::getInstance()->permalink($sUrl) . '&id=' . $iAccountId . '&code=' . $this->getEmailHash();
  834. }
  835. public function getEmailHash($iAccountId = false)
  836. {
  837. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  838. $a = $this->getInfo();
  839. return md5($a['email'] . $a['salt'] . BX_DOL_SECRET);
  840. }
  841. public function getPasswordChangedDate($mixedAccount = false)
  842. {
  843. if(($bEmpty = empty($mixedAccount)) || !is_array($mixedAccount))
  844. $mixedAccount = $this->_oQuery->getInfoById(!$bEmpty ? (int)$mixedAccount : $this->_iAccountID);
  845. $iLastChanged = (int)$mixedAccount['password_changed'];
  846. return $iLastChanged ? $iLastChanged : (int)$mixedAccount['added'];
  847. }
  848. public function getPasswordExpiredDate($iPasswordExpiredForMembership, $mixedAccount = false)
  849. {
  850. if($iPasswordExpiredForMembership == 0)
  851. return 0;
  852. return $iPasswordExpiredForMembership * 86400 + $this->getPasswordChangedDate($mixedAccount);
  853. }
  854. public function isNeedChangePassword($iAccountId = false, $oInformer = false)
  855. {
  856. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  857. list($sPageLink, $aPageParams) = bx_get_base_url_inline();
  858. $sChangePasswordUri = 'account-settings-password';
  859. $bNeedRedirectToChangePassword = true;
  860. if(isset($aPageParams['i']) && $aPageParams['i'] == $sChangePasswordUri)
  861. $bNeedRedirectToChangePassword = false;
  862. /**
  863. * @hooks
  864. * @hookdef hook-account-is_need_to_change_password 'account', 'is_need_to_change_password' - hook on after delete account
  865. * - $unit_name - equals `account`
  866. * - $action - equals `is_need_to_change_password`
  867. * - $object_id - account id
  868. * - $sender_id - not used
  869. * - $extra_params - array of additional params with the following array keys:
  870. * - `override_result` - [bool] by ref, if Need Redirect To Change Password = true, otherwise = false, can be overridden in hook processing
  871. * @hook @ref hook-account-is_need_to_change_password
  872. */
  873. bx_alert('account', 'is_need_to_change_password', $iAccountId, false, [
  874. 'override_result' => &$bNeedRedirectToChangePassword
  875. ]);
  876. if(!$bNeedRedirectToChangePassword)
  877. return;
  878. $aAccountInfo = $this->getInfo();
  879. $aMembershipInfo = BxDolAcl::getInstance()->getMemberMembershipInfo($aAccountInfo['profile_id']);
  880. $sChangePasswordUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $sChangePasswordUri);
  881. if(($iPasswordExpiredDate = $this->getPasswordExpiredDate($aMembershipInfo['password_expired'], $aAccountInfo)) && $iPasswordExpiredDate < time()) {
  882. if(getParam('sys_account_accounts_force_password_change_after_expiration') == 'on') {
  883. header('Location: ' . $sChangePasswordUrl);
  884. exit;
  885. }
  886. else {
  887. if(!$oInformer)
  888. $oInformer = BxDolInformer::getInstance();
  889. $oInformer->add('sys-account-need-to-change-password', _t('_sys_txt_account_need_to_change_password', $sChangePasswordUrl), BX_INFORMER_ALERT);
  890. }
  891. }
  892. }
  893. public function doAudit($iAccountId, $sAction, $aData = [])
  894. {
  895. $iAccountId = (int)$iAccountId ? (int)$iAccountId : $this->_iAccountID;
  896. bx_audit($iAccountId, 'bx_accounts', $sAction, [
  897. 'content_title' => $this->getEmail(),
  898. 'data' => $aData
  899. ]);
  900. }
  901. /**
  902. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  903. */
  904. static public function isAllowedCreate ($iProfileId, $isPerformAction = false)
  905. {
  906. $aCheck = checkActionModule($iProfileId, 'create account', 'system', $isPerformAction);
  907. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  908. return MsgBox($aCheck[CHECK_ACTION_MESSAGE]);
  909. return CHECK_ACTION_RESULT_ALLOWED;
  910. }
  911. static public function isAllowedCreateMultiple ($iProfileId, $isPerformAction = false)
  912. {
  913. $iLimit = (int)getParam('sys_account_limit_profiles_number');
  914. $bResult = false;
  915. if(isAdmin() || $iLimit != 1)
  916. $bResult = true;
  917. $oProfile = BxDolProfile::getInstance($iProfileId);
  918. if($iLimit == 1 && $oProfile->getModule() == 'system')
  919. $bResult = true;
  920. if($oProfile && $oProfile->getAccountId() != getLoggedId())
  921. $bResult = false;
  922. /**
  923. * @hooks
  924. * @hookdef hook-account-allow_create_another_profile 'profile', 'allow_create_another_profile' - hook on check allow create profile
  925. * - $unit_name - equals `profile`
  926. * - $action - equals `allow_create_another_profile`
  927. * - $object_id - profile id
  928. * - $sender_id - not used
  929. * - $extra_params - array of additional params with the following array keys:
  930. * - `override_result` - [bool] by ref, if allow create another profile = true, otherwise = false, can be overridden in hook processing
  931. * @hook @ref hook-account-allow_create_another_profile
  932. */
  933. bx_alert('profile', 'allow_create_another_profile', $iProfileId, 0, [
  934. 'override_result' => &$bResult
  935. ]);
  936. return $bResult;
  937. }
  938. /**
  939. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  940. */
  941. static public function isAllowedEdit ($iProfileId, $aContentInfo, $isPerformAction = false)
  942. {
  943. $oProfile = BxDolProfile::getInstance($iProfileId);
  944. if (!$oProfile)
  945. return _t('_sys_txt_access_denied');
  946. $aProfileInfo = $oProfile->getInfo();
  947. if (!$aProfileInfo || getLoggedId() != $aProfileInfo['account_id'])
  948. return _t('_sys_txt_access_denied');
  949. return CHECK_ACTION_RESULT_ALLOWED;
  950. }
  951. /**
  952. * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden.
  953. */
  954. static public function isAllowedDelete ($iProfileId, $aContentInfo, $isPerformAction = false)
  955. {
  956. $iAccountId = (int)BxDolProfile::getInstance($iProfileId)->getAccountId();
  957. if(isAdmin($iAccountId) && $iAccountId == (int)$aContentInfo['id'])
  958. return _t('_sys_txt_account_cannot_delete');
  959. if(!isAdmin($iAccountId) && $iAccountId != (int)$aContentInfo['id'])
  960. return _t('_sys_txt_access_denied');
  961. $aCheck = checkActionModule($iProfileId, 'delete account', 'system', $isPerformAction);
  962. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  963. return $aCheck[CHECK_ACTION_MESSAGE];
  964. return CHECK_ACTION_RESULT_ALLOWED;
  965. }
  966. static public function pruning ()
  967. {
  968. $iCount = 0;
  969. $iTime = time() - getParam('sys_account_accounts_pruning_interval') * 86400;
  970. $oAccountQuery = BxDolAccountQuery::getInstance();
  971. $aAccounts = [];
  972. $aAccountsSuspend = [];
  973. $bSuspend = false;
  974. $aPruning = explode(',', getParam('sys_account_accounts_pruning'));
  975. foreach ($aPruning as $sPruning) {
  976. switch($sPruning) {
  977. case 'no_login_suspend':
  978. $aAccountsSuspend = $oAccountQuery->getAccountsForPruning('no_login', $iTime);
  979. break;
  980. case 'no_login_delete':
  981. $aAccounts = array_merge($aAccounts, $oAccountQuery->getAccountsForPruning('no_login', $iTime));
  982. break;
  983. case 'no_confirm_delete':
  984. $aAccounts1 = $oAccountQuery->getAccountsForPruning('no_confirm', $iTime);
  985. foreach ($aAccounts1 as $k => $aAccount) {
  986. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  987. if($oAccount->isConfirmed()){
  988. unset($aAccounts1[$k]);
  989. }
  990. }
  991. $aAccounts = array_merge($aAccounts, $aAccounts1);
  992. break;
  993. case 'no_profile_delete':
  994. $aAccounts = array_merge($aAccounts, $aAccounts = $oAccountQuery->getAccountsForPruning('no_profile', $iTime));
  995. break;
  996. }
  997. }
  998. foreach ($aAccountsSuspend as $k => $aAccount) {
  999. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  1000. $oProfile = BxDolProfile::getInstanceAccountProfile($aAccount['id']);
  1001. $oProfile->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
  1002. $aProfiles = $oAccount->getProfiles();
  1003. foreach($aProfiles as $aProfile){
  1004. BxDolProfile::getInstance($aProfile['id'])->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
  1005. }
  1006. $iCount++;
  1007. }
  1008. foreach ($aAccounts as $k => $aAccount) {
  1009. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  1010. $oAccount->delete(false);
  1011. $iCount++;
  1012. }
  1013. return $iCount;
  1014. }
  1015. protected function _getImageUrl($sSize, $mixedData)
  1016. {
  1017. if(!is_array($mixedData))
  1018. $mixedData = $this->getInfo((int)$mixedData);
  1019. $sImageUrl = '';
  1020. if(!empty($mixedData[$this->_sImageField]) && !empty($this->_aImageTranscoders[$sSize]) && ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_aImageTranscoders[$sSize])) !== false)
  1021. $sImageUrl = $oImagesTranscoder->getFileUrl($mixedData[$this->_sImageField]);
  1022. return $sImageUrl;
  1023. }
  1024. }
  1025. /** @} */