BxDolCronAccount.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. class BxDolCronAccount extends BxDolCron
  10. {
  11. protected $_aParseParams;
  12. public function __construct()
  13. {
  14. parent::__construct();
  15. $this->_aParseParams = array(
  16. 'site_title' => getParam('site_title')
  17. );
  18. }
  19. public function processing()
  20. {
  21. set_time_limit(0);
  22. ignore_user_abort();
  23. /* password expired soon email */
  24. bx_import('BxTemplAcl');
  25. $oAclDb = BxDolAclQuery::getInstance();
  26. $aEmails = [];
  27. $aMemberships = [];
  28. $oAclDb->getLevels(['type' => 'password_expired_notify'], $aMemberships, false);
  29. foreach($aMemberships as $aMembership) {
  30. $aProfiles = $oAclDb->getProfilesByMembership([$aMembership['id']], [
  31. 'password_expired' => $aMembership['password_expired'],
  32. 'password_expired_notify' => $aMembership['password_expired_notify']
  33. ]);
  34. foreach($aProfiles as $aProfile) {
  35. if(in_array($aProfile['email'], $aEmails))
  36. continue;
  37. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_AccountPasswordExpired', [
  38. 'expired_date' => date('d.m.Y', $aProfile['password_expired'])
  39. ]);
  40. sendMail($aProfile['email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['id']);
  41. $aEmails[] = $aProfile['email'];
  42. }
  43. }
  44. /* new accounts email */
  45. if(getParam('enable_notification_account') != 'on')
  46. return;
  47. $this->processNewlyJoined();
  48. if(empty($this->_aParseParams['account_count']) || empty($this->_aParseParams['account_output']))
  49. return;
  50. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_Account', $this->_aParseParams);
  51. if(empty($aTemplate))
  52. return;
  53. $aSent = array();
  54. $aProfiles = BxDolAclQuery::getInstance()->getProfilesByMembership(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR));
  55. foreach($aProfiles as $aProfile) {
  56. $oProfile = BxDolProfile::getInstance($aProfile['id']);
  57. if(!$oProfile)
  58. continue;
  59. $oAccount = $oProfile->getAccountObject();
  60. if(!$oAccount || !$oAccount->isConfirmed())
  61. continue;
  62. $aAccount = $oAccount->getInfo();
  63. if((int)$aAccount['receive_news'] != 1)
  64. continue;
  65. if(in_array($aAccount['email'], $aSent))
  66. continue;
  67. if(sendMail($aAccount['email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['id']))
  68. $aSent[] = $aAccount['email'];
  69. }
  70. }
  71. protected function processNewlyJoined()
  72. {
  73. $aAccounts = BxDolAccountQuery::getInstance()->getAccounts(array('type' => 'by_join_date', 'date' => time() - 86400));
  74. if(empty($aAccounts) || !is_array($aAccounts))
  75. return;
  76. $iAccounts = 0;
  77. $aTmplVarsItems = array();
  78. foreach($aAccounts as $aAccount) {
  79. $oProfile = BxDolProfile::getInstance($aAccount['profile_id']);
  80. if(!$oProfile)
  81. continue;
  82. $iId = $oProfile->id();
  83. $sUrl = $oProfile->getUrl();
  84. $bUrl = $oProfile->getModule() != 'system';
  85. $sTitle = $oProfile->getDisplayName();
  86. $sTitleAttr = bx_html_attribute($sTitle);
  87. $sThumbUrl = $oProfile->getThumb();
  88. $bThumbUrl = $oProfile->hasImage();
  89. $aTmplVarsItems[] = array(
  90. 'bx_if:show_thumb_image' => array(
  91. 'condition' => $bThumbUrl,
  92. 'content' => array(
  93. 'thumb_url' => $sThumbUrl
  94. )
  95. ),
  96. 'bx_if:show_thumb_letter' => array(
  97. 'condition' => !$bThumbUrl,
  98. 'content' => array(
  99. 'color' => implode(', ', BxDolTemplate::getColorCode($iId, 1.0)),
  100. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  101. )
  102. ),
  103. 'bx_if:show_title_link' => array(
  104. 'condition' => $bUrl,
  105. 'content' => array(
  106. 'content_url' => $sUrl,
  107. 'content_title' => $sTitle,
  108. 'content_title_attr' => $sTitleAttr
  109. )
  110. ),
  111. 'bx_if:show_title_text' => array(
  112. 'condition' => !$bUrl,
  113. 'content' => array(
  114. 'content_title' => $sTitle,
  115. 'content_title_attr' => $sTitleAttr
  116. )
  117. ),
  118. 'email' => $aAccount['email']
  119. );
  120. $iAccounts += 1;
  121. }
  122. if(empty($aTmplVarsItems))
  123. return;
  124. $this->_aParseParams['account_count'] = $iAccounts;
  125. $this->_aParseParams['account_output'] = BxDolTemplate::getInstance()->parseHtmlByName('et_account.html', array(
  126. 'bx_repeat:items' => $aTmplVarsItems
  127. ));
  128. }
  129. }
  130. /** @} */