BxDolCronAccount.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. if(getParam('enable_notification_account') != 'on')
  22. return;
  23. set_time_limit(0);
  24. ignore_user_abort();
  25. $this->processNewlyJoined();
  26. if(empty($this->_aParseParams['account_count']) || empty($this->_aParseParams['account_output']))
  27. return;
  28. $aTemplate = BxDolEmailTemplates::getInstance()->parseTemplate('t_Account', $this->_aParseParams);
  29. if(empty($aTemplate))
  30. return;
  31. $aSent = array();
  32. $aProfiles = BxDolAclQuery::getInstance()->getProfilesByMembership(array(MEMBERSHIP_ID_MODERATOR, MEMBERSHIP_ID_ADMINISTRATOR));
  33. foreach($aProfiles as $aProfile) {
  34. $oProfile = BxDolProfile::getInstance($aProfile['id']);
  35. if(!$oProfile)
  36. continue;
  37. $oAccount = $oProfile->getAccountObject();
  38. if(!$oAccount || !$oAccount->isConfirmed())
  39. continue;
  40. $aAccount = $oAccount->getInfo();
  41. if((int)$aAccount['receive_news'] != 1)
  42. continue;
  43. if(in_array($aAccount['email'], $aSent))
  44. continue;
  45. if(sendMail($aAccount['email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['id']))
  46. $aSent[] = $aAccount['email'];
  47. }
  48. }
  49. protected function processNewlyJoined()
  50. {
  51. $aAccounts = BxDolAccountQuery::getInstance()->getAccounts(array('type' => 'by_join_date', 'date' => time() - 86400));
  52. if(empty($aAccounts) || !is_array($aAccounts))
  53. return;
  54. $iAccounts = 0;
  55. $aTmplVarsItems = array();
  56. foreach($aAccounts as $aAccount) {
  57. $oProfile = BxDolProfile::getInstance($aAccount['profile_id']);
  58. if(!$oProfile)
  59. continue;
  60. $iId = $oProfile->id();
  61. $sUrl = $oProfile->getUrl();
  62. $bUrl = $oProfile->getModule() != 'system';
  63. $sTitle = $oProfile->getDisplayName();
  64. $sTitleAttr = bx_html_attribute($sTitle);
  65. $sThumbUrl = $oProfile->getThumb();
  66. $bThumbUrl = $oProfile->hasImage();
  67. $aTmplVarsItems[] = array(
  68. 'bx_if:show_thumb_image' => array(
  69. 'condition' => $bThumbUrl,
  70. 'content' => array(
  71. 'thumb_url' => $sThumbUrl
  72. )
  73. ),
  74. 'bx_if:show_thumb_letter' => array(
  75. 'condition' => !$bThumbUrl,
  76. 'content' => array(
  77. 'color' => implode(', ', BxDolTemplate::getColorCode($iId, 1.0)),
  78. 'letter' => mb_strtoupper(mb_substr($sTitle, 0, 1))
  79. )
  80. ),
  81. 'bx_if:show_title_link' => array(
  82. 'condition' => $bUrl,
  83. 'content' => array(
  84. 'content_url' => $sUrl,
  85. 'content_title' => $sTitle,
  86. 'content_title_attr' => $sTitleAttr
  87. )
  88. ),
  89. 'bx_if:show_title_text' => array(
  90. 'condition' => !$bUrl,
  91. 'content' => array(
  92. 'content_title' => $sTitle,
  93. 'content_title_attr' => $sTitleAttr
  94. )
  95. ),
  96. 'email' => $aAccount['email']
  97. );
  98. $iAccounts += 1;
  99. }
  100. if(empty($aTmplVarsItems))
  101. return;
  102. $this->_aParseParams['account_count'] = $iAccounts;
  103. $this->_aParseParams['account_output'] = BxDolTemplate::getInstance()->parseHtmlByName('et_account.html', array(
  104. 'bx_repeat:items' => $aTmplVarsItems
  105. ));
  106. }
  107. }
  108. /** @} */