/**
  * Retrieve subscribers list. It overrides the abstract method defined
  * in SubsRetriever Class, implementing a concrete method of the strategy
  * pattern.
  *
  * Hint: it starts to retrieve from the $start-th subscribers and returns
  * $multiplexer * $max_mails results, where $max_mails is the max number
  * of mails to send every step of a sending process
  *
  * @access	public
  * @param   integer $start_time The starting subscription time
  * @param   integer $start_id The starting subscriber identifier
  * @param   integer $multiplexer The limit multiplexer
  * @param   array $attributes array of attributes to retrieve: $attributes['attr_name'] = 0 | 1
  * @return	mixed   the subscribers list or false if something wrong.
  * @since	0.6
  */
 function getSubscribersList($start_time = 0, $start_id = 0, $multiplexer = 1, $attributes = null)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $logger->finer('JUserInfoRetriever: Start time ' . $start_time . ' Start id ' . $start_id . ' Multiplexer ' . $multiplexer);
     jincimport('utility.parameterprovider');
     $max_mails = ParameterProvider::getMaxXStep();
     if (is_null($attributes) || !is_array($attributes)) {
         $attributes = array();
     }
     $query = 'SELECT s.id as id, u.email as email, u.username as username, u.name as name, u.id as user_id, ' . 'c.name as con_name, c.con_position as con_con_position, c.address as con_address, ' . 'c.suburb as con_suburb, c.state as con_state, c.country as con_country, ' . 'c.postcode as con_postcode, c.telephone as con_telephone, c.fax as con_fax, ' . 'c.email_to as con_email_to, c.mobile as con_mobile, c.webpage as con_webpage, ' . 'UNIX_TIMESTAMP(s.datasub) as last_time, s.id as last_id, INET_NTOA(s.ipaddr) as ipaddr ';
     $i = 0;
     foreach ($attributes as $attr_name => $attr_value) {
         $table_name = '`#__jinc_attribute_' . $attr_name . '`';
         $table_alias = 'att' . $i;
         $query .= ', ' . $table_alias . '.value as `attr_' . $attr_name . '`';
         $i++;
     }
     $query .= ' FROM #__jinc_newsletter n ' . 'LEFT JOIN #__jinc_subscriber s ON n.id = s.news_id ' . 'LEFT JOIN #__users u ON s.user_id = u.id ' . 'LEFT JOIN #__contact_details c ON u.id = c.user_id ';
     $i = 0;
     foreach ($attributes as $attr_name => $attr_value) {
         $table_name = '`#__jinc_attribute_' . $attr_name . '`';
         $table_alias = 'att' . $i;
         $query .= ' LEFT JOIN ' . $table_name . ' ' . $table_alias . ' ON s.id = ' . $table_alias . '.id AND n.id = ' . $table_alias . '.news_id ';
         $i++;
     }
     $query .= 'WHERE n.id = ' . (int) $this->getNewsId() . ' ' . 'AND ( UNIX_TIMESTAMP(s.datasub) > ' . (int) $start_time . ' ' . 'OR (UNIX_TIMESTAMP(s.datasub) = ' . (int) $start_time . ' AND s.id > ' . (int) $start_id . ') ) ' . ' ' . 'ORDER BY s.datasub, s.id ' . 'LIMIT 0, ' . $max_mails * $multiplexer;
     $dbo =& JFactory::getDBO();
     $dbo->setQuery($query);
     $logger->debug('JContactInfoRetriever: executing query: ' . $query);
     return $dbo->loadAssocList();
 }
示例#2
0
 /**
  * Send a bulk message. It overrides the abstract method defined in Message
  * class.
  *
  * Hint: it starts to send messages from the the $start-th subscribers of
  * the message
  *
  * @access	public
  * @param	int $start_time subscription time to begin to
  * @param	int $start_id subscriber identifier to begin to
  * @return  array containing next suscription time, subscriber id and number of sent messages
  * @since	0.6
  */
 function send($start_time = 0, $start_id = 0, $continue_on_error = false)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     jimport('joomla.filesystem.folder');
     jimport('joomla.filesystem.file');
     jincimport('utility.parameterprovider');
     $mailmsg = JFactory::getMailer();
     $root_uri = JURI::root();
     $sleeptime = ParameterProvider::getMailTimeInterval();
     $max_mails = ParameterProvider::getMaxXStep();
     $max_bulk_bcc = ParameterProvider::getMailMaxBcc();
     $send_mail = ParameterProvider::getSendMail();
     $logger->finer('BulkMessage: Sleep time ' . $sleeptime . ' - Max mails ' . $max_mails . ' Max BCC ' . $max_bulk_bcc . ' Send mail ' . $send_mail);
     $last_time = $start_time;
     $last_id = $start_id;
     $nmessages = 0;
     $nsuccess = 0;
     if ($newsletter = $this->loadNewsletter()) {
         ob_start();
         $logger->finer('BulkMessage: Newsletter loaded');
         $msg = $this->get('body') . $newsletter->get('disclaimer');
         // Newsletter info substitution in message body
         $msg = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $msg);
         $msg = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $msg);
         $msg = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $msg);
         $news_id = $newsletter->get('id');
         $unsub_link = JURI::root() . 'index.php?option=com_jinc&view=newsletter&layout=unsubscription&id=' . $news_id;
         $msg = preg_replace('/\\[UNSUBSCRIPTIONURL\\]/s', $unsub_link, $msg);
         $msg = preg_replace('#src[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'src="' . $root_uri, $msg);
         $msg = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?!mailto?:)(?!tel?:)(?:\\.\\./|\\./|/)?#', 'href="' . $root_uri, $msg);
         $msg = preg_replace('#url[ ]*\\(\'(?!https?://)(?:\\.\\./|\\./|/)?#', 'url(\'' . $root_uri, $msg);
         $subject = $this->get('subject');
         $subject = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $subject);
         $subject = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $subject);
         $subject = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $subject);
         // Setting message general properties
         $mailmsg->ContentType = $this->get('plaintext') ? "text/plain" : "text/html";
         $mailmsg->setSubject($subject);
         if (strlen($newsletter->get('senderaddr')) > 0) {
             $mailmsg->setSender(array($newsletter->get('senderaddr'), $newsletter->get('sendername')));
         }
         if (strlen($newsletter->get('replyto_addr')) > 0) {
             $mailmsg->addReplyTo(array($newsletter->get('replyto_addr'), $newsletter->get('replyto_name')));
         }
         $path_abs_root = JPATH_ROOT;
         $msg_attachment = $this->get('attachment');
         $arr_attachment = $msg_attachment->toArray();
         foreach ($arr_attachment as $key => $value) {
             $attachment = str_replace('/', DIRECTORY_SEPARATOR, $value);
             if (strlen($attachment)) {
                 $logger->finer('BulkMessage: adding attachment ' . $path_abs_root . DIRECTORY_SEPARATOR . $attachment);
                 $mailmsg->addAttachment($path_abs_root . DIRECTORY_SEPARATOR . $attachment);
             }
         }
         $logger->finer('BulkMessage: going to add recipients');
         $recipients = $newsletter->getSubscribersList($start_time, $start_id, $max_bulk_bcc);
         $nrecips = count($recipients);
         $logger->finer('BulkMessage: found ' . $nrecips . ' subscribers');
         $success = true;
         ob_end_clean();
         for ($i = 0; $i < $nrecips && $success; $i += $max_bulk_bcc) {
             ob_start();
             $ndest = 0;
             for ($j = 0; $j < $max_bulk_bcc && $j + $i < $nrecips; $j++) {
                 $current = $recipients[$j + $i];
                 $this->reported_recipients[$current['id']] = 0;
                 if (!$mailmsg->addBCC($current['email'])) {
                     $this->reported_recipients[$current['id']] = 1;
                 }
                 $ndest = $ndest + 1;
                 $last_time = $current['last_time'];
                 $last_id = $current['last_id'];
             }
             $mailmsg->setBody($this->emogrify($msg));
             $nmessages = $nmessages + $ndest;
             if ($send_mail) {
                 $success = $mailmsg->Send();
                 if ($success === true) {
                     $nsuccess = $nsuccess + $ndest * $success;
                     $logger->finer('BulkMessage: success sending mail.');
                 } else {
                     $logger->warning('BulkMessage: error sending mail.');
                     $this->mail_system_error = ob_get_contents();
                     $logger->warning('BulkMessage: error sending mail. MSG = ' . $this->mail_system_error);
                     for ($j = 0; $j < $max_bulk_bcc && $j + $i < $nrecips; $j++) {
                         $current = $recipients[$j + $i];
                         $this->reported_recipients[$current['id']] = 2;
                     }
                     if (!$continue_on_error) {
                         $success = false;
                     }
                 }
             } else {
                 $bcc_addresses = array();
                 foreach ($mailmsg->bcc as $number_variable => $variable) {
                     array_push($bcc_addresses, $mailmsg->bcc[$number_variable][0]);
                 }
                 $logger->info('BulkMessage: simulate sending mail. BCC = ' . implode(', ', $bcc_addresses));
                 $logger->info('BulkMessage: simulate sending mail. Body = ' . $msg);
                 $nsuccess = $nsuccess + $ndest;
             }
             // socket_select($read = NULL, $write = NULL, $sock = array(socket_create (AF_INET, SOCK_RAW, 0)), 0, $sleeptime);
             usleep($sleeptime);
             $mailmsg->ClearAllRecipients();
             ob_end_clean();
         }
     } else {
         $this->setError('COM_JINC_ERR001');
         return false;
     }
     return array('last_time' => $last_time, 'last_id' => $last_id, 'nmessages' => $nmessages, 'nsuccess' => $nsuccess);
 }
示例#3
0
 /**
  * Retrieve subscribers list. It overrides the abstract method defined
  * in SubsRetriever Class, implementing a concrete method of the strategy
  * pattern.
  *
  * Hint: it starts to retrieve from the $start-th subscribers and returns
  * $multiplexer * $max_mails results, where $max_mails is the max number
  * of mails to send every step of a sending process
  *
  * @access	public
  * @param   integer $start_time The starting subscription time
  * @param   integer $start_id The starting subscriber identifier
  * @param   integer $multiplexer The limit multiplexer
  * @param   array $attributes array of attributes to retrieve: $attributes['attr_name'] = 0 | 1
  * @return	mixed   the subscribers list or false if something wrong.
  * @since	0.6
  */
 function getSubscribersList($start_time = 0, $start_id = 0, $multiplexer = 1, $attributes = null)
 {
     jincimport('utility.servicelocator');
     $servicelocator = ServiceLocator::getInstance();
     $logger = $servicelocator->getLogger();
     $logger->finer('PublicRetriever: Start time ' . $start_time . ' Start id ' . $start_id . ' Multiplexer ' . $multiplexer);
     jincimport('utility.parameterprovider');
     $max_mails = ParameterProvider::getMaxXStep();
     if (is_null($attributes) || !is_array($attributes)) {
         $attributes = array();
     }
     $query = 'SELECT s.id as id, s.email as email, ' . 'UNIX_TIMESTAMP(s.datasub) as last_time, s.id as last_id';
     $i = 0;
     foreach ($attributes as $attr_name => $attr_value) {
         $table_name = '`#__jinc_attribute_' . $attr_name . '`';
         $table_alias = 'att' . $i;
         $query .= ', ' . $table_alias . '.value as `attr_' . $attr_name . '`';
         $i++;
     }
     $query .= ' FROM #__jinc_newsletter n ' . 'LEFT JOIN #__jinc_subscriber s ON s.news_id = n.id ';
     $i = 0;
     foreach ($attributes as $attr_name => $attr_value) {
         $table_name = '`#__jinc_attribute_' . $attr_name . '`';
         $table_alias = 'att' . $i;
         $query .= ' LEFT JOIN ' . $table_name . ' ' . $table_alias . ' ON s.id = ' . $table_alias . '.id AND n.id = ' . $table_alias . '.news_id ';
         $i++;
     }
     $query .= 'WHERE n.id = ' . (int) $this->getNewsId() . ' ' . 'AND (s.random = \'\' OR s.random IS NULL) ' . 'AND ( UNIX_TIMESTAMP(s.datasub) > ' . (int) $start_time . ' ' . 'OR (UNIX_TIMESTAMP(s.datasub) = ' . (int) $start_time . ' AND s.id > ' . (int) $start_id . ') ) ' . ' ' . 'ORDER BY s.datasub, s.id ' . 'LIMIT 0, ' . $max_mails * $multiplexer;
     $dbo = JFactory::getDBO();
     $dbo->setQuery($query);
     $logger->debug('PublicRetriever: executing query: ' . $query);
     return $dbo->loadAssocList();
 }