示例#1
0
 public function getCurrentTransport()
 {
     $newsletter = AvisotaStatic::getNewsletter();
     $category = AvisotaStatic::getCategory();
     if ($category && $category->transport && $category->setTransport == 'category') {
         $transportModuleId = $category->transport;
     } else {
         if ($newsletter && $newsletter->transport) {
             $transportModuleId = $newsletter->transport;
         } else {
             if ($category && $category->transport) {
                 $transportModuleId = $category->transport;
             } else {
                 $transportModuleId = 0;
             }
         }
     }
     return AvisotaTransport::getTransportModule($transportModuleId);
 }
 public function __construct(Database_Result $resultSet)
 {
     parent::__construct($resultSet);
     $mailerConfig = $this->createMailerConfig();
     $this->mailer = $this->createMailer($mailerConfig);
 }
 /**
  * Send a reminder to the given mailing lists
  * or all unconfirmed, not reminded mailing lists, the recipient has subscribed.
  *
  * @param array|null $listIds
  *
  * @throws AvisotaSubscriptionException
  */
 public function sendRemind(array $listIds = null, $force = false)
 {
     if (!$GLOBALS['TL_CONFIG']['avisota_send_notification']) {
         return false;
     }
     if (!$this->id) {
         throw new AvisotaSubscriptionException($this, 'This recipient has no ID!');
     }
     if ($listIds !== null) {
         $listIds = array_filter(array_map('intval', $listIds));
         if (!count($listIds)) {
             return false;
         }
     }
     $this->loadLanguageFile('avisota_subscription');
     $time = time();
     $reminderTime = $GLOBALS['TL_CONFIG']['avisota_notification_time'] * 24 * 60 * 60;
     $list = \Database::getInstance()->prepare("SELECT l.* FROM orm_avisota_recipient_to_mailing_list t\n\t\t\t\t\t   INNER JOIN orm_avisota_mailing_list l\n\t\t\t\t\t   ON l.id=t.list\n\t\t\t\t\t   WHERE t.recipient=? AND t.confirmed=?" . ($force ? '' : "AND t.confirmationSent>0\n\t\t\t\t\t     AND (\n\t\t\t\t\t         (t.reminderSent=0 AND UNIX_TIMESTAMP()-t.confirmationSent>?)\n\t\t\t\t\t       OR\n\t\t\t\t\t         (t.reminderSent>0 AND UNIT_TIMESTAMP()-t.reminderSent>(?+(?*t.reminderCount/2) AND t.reminderCount<?)\n\t\t\t\t\t     )") . ($listIds !== null ? " AND t.list IN (" . implode(',', $listIds) . ")" : '') . "ORDER BY l.title")->execute($this->id, '', $reminderTime, $reminderTime, $reminderTime, $GLOBALS['TL_CONFIG']['avisota_notification_count']);
     $listsByPage = array();
     while ($list->next()) {
         $listData = $list->row();
         // generate a token
         if (empty($listData['token'])) {
             $listData['token'] = substr(md5(mt_rand() . '-' . $this->id . '-' . $list->id . '-' . $this->email . '-' . time()), 0, 8);
         }
         // set send time
         $listData['reminderSent'] = $time;
         $pageId = $list->integratedRecipientManageSubscriptionPage ? $list->integratedRecipientManageSubscriptionPage : $GLOBALS['objPage']->id;
         $listsByPage[$pageId][$list->id] = $listData;
     }
     foreach ($listsByPage as $pageId => $lists) {
         $page = $this->getPageDetails($pageId);
         $titles = array();
         $tokens = array();
         foreach ($lists as $listData) {
             $titles[] = $listData['title'];
             $tokens[] = $listData['token'];
         }
         $url = $this->generateFrontendUrl($page->row()) . '?subscribetoken=' . implode(',', $tokens);
         $plainTemplate = new AvisotaNewsletterTemplate($GLOBALS['TL_CONFIG']['avisota_template_notification_mail_plain']);
         $plainTemplate->content = sprintf($GLOBALS['TL_LANG']['avisota_subscription']['notification']['plain'], implode(', ', $titles), $url);
         $htmlTemplate = new AvisotaNewsletterTemplate($GLOBALS['TL_CONFIG']['avisota_template_notification_mail_html']);
         $htmlTemplate->title = $GLOBALS['TL_LANG']['avisota']['subscribe']['subject'];
         $htmlTemplate->content = sprintf($GLOBALS['TL_LANG']['avisota_subscription']['notification']['html'], implode(', ', $titles), $url);
         $email = new Mail();
         $email->setSubject($GLOBALS['TL_LANG']['avisota_subscription']['notification']['subject']);
         $email->setText($plainTemplate->parse());
         $email->setHtml($htmlTemplate->parse());
         $transport = AvisotaTransport::getTransportModule();
         $transport->transportEmail($this->email, $email);
         foreach ($lists as $listData) {
             $this->log('Send subscription reminder for recipient ' . $this->email . ' in mailing list "' . $listData['title'] . '"', 'AvisotaIntegratedRecipient::sendRemind', TL_INFO);
             \Database::getInstance()->prepare("UPDATE orm_avisota_recipient_to_mailing_list SET reminderSent=?, reminderCount=reminderCount+1, token=? WHERE recipient=? AND list=?")->execute($listData['reminderSent'], $listData['token'], $this->id, $listData['id']);
         }
     }
     // HOOK: add custom logic
     if (isset($GLOBALS['TL_HOOKS']['avisotaIntegratedRecipientSendSubscriptionReminder']) && is_array($GLOBALS['TL_HOOKS']['avisotaIntegratedRecipientSendSubscriptionReminder'])) {
         foreach ($GLOBALS['TL_HOOKS']['avisotaIntegratedRecipientSendSubscriptionReminder'] as $callback) {
             $this->import($callback[0]);
             $this->{$callback}[0]->{$callback}[1]($this, $listsByPage);
         }
     }
     return $listsByPage;
 }