BxDolAccount.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211
  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 frof 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 frof 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. $aCheck = checkActionModule($iProfileId, 'delete account', 'system', $isPerformAction);
  960. if ($aCheck[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED)
  961. return $aCheck[CHECK_ACTION_MESSAGE];
  962. return CHECK_ACTION_RESULT_ALLOWED;
  963. }
  964. static public function pruning ()
  965. {
  966. $iCount = 0;
  967. $iTime = time() - getParam('sys_account_accounts_pruning_interval') * 86400;
  968. $oAccountQuery = BxDolAccountQuery::getInstance();
  969. $aAccounts = [];
  970. $aAccountsSuspend = [];
  971. $bSuspend = false;
  972. $aPruning = explode(',', getParam('sys_account_accounts_pruning'));
  973. foreach ($aPruning as $sPruning) {
  974. switch($sPruning) {
  975. case 'no_login_suspend':
  976. $aAccountsSuspend = $oAccountQuery->getAccountsForPruning('no_login', $iTime);
  977. break;
  978. case 'no_login_delete':
  979. $aAccounts = array_merge($aAccounts, $oAccountQuery->getAccountsForPruning('no_login', $iTime));
  980. break;
  981. case 'no_confirm_delete':
  982. $aAccounts1 = $oAccountQuery->getAccountsForPruning('no_confirm', $iTime);
  983. foreach ($aAccounts1 as $k => $aAccount) {
  984. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  985. if($oAccount->isConfirmed()){
  986. unset($aAccounts1[$k]);
  987. }
  988. }
  989. $aAccounts = array_merge($aAccounts, $aAccounts1);
  990. break;
  991. case 'no_profile_delete':
  992. $aAccounts = array_merge($aAccounts, $aAccounts = $oAccountQuery->getAccountsForPruning('no_profile', $iTime));
  993. break;
  994. }
  995. }
  996. foreach ($aAccountsSuspend as $k => $aAccount) {
  997. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  998. $oProfile = BxDolProfile::getInstanceAccountProfile($aAccount['id']);
  999. $oProfile->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
  1000. $aProfiles = $oAccount->getProfiles();
  1001. foreach($aProfiles as $aProfile){
  1002. BxDolProfile::getInstance($aProfile['id'])->suspend(BX_PROFILE_ACTION_AUTO, 0 ,false);
  1003. }
  1004. $iCount++;
  1005. }
  1006. foreach ($aAccounts as $k => $aAccount) {
  1007. $oAccount = BxDolAccount::getInstance($aAccount['id']);
  1008. $oAccount->delete(false);
  1009. $iCount++;
  1010. }
  1011. return $iCount;
  1012. }
  1013. protected function _getImageUrl($sSize, $mixedData)
  1014. {
  1015. if(!is_array($mixedData))
  1016. $mixedData = $this->getInfo((int)$mixedData);
  1017. $sImageUrl = '';
  1018. if(!empty($mixedData[$this->_sImageField]) && !empty($this->_aImageTranscoders[$sSize]) && ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_aImageTranscoders[$sSize])) !== false)
  1019. $sImageUrl = $oImagesTranscoder->getFileUrl($mixedData[$this->_sImageField]);
  1020. return $sImageUrl;
  1021. }
  1022. }
  1023. /** @} */