/** * ServiceLocator constructor. */ function ServiceLocator() { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $path_abs_root = JPATH_ADMINISTRATOR . DS . 'components' . DS; $path_rel = 'com_jinc' . DS . 'jinc.log'; $logger = new Logger(ParameterProvider::getLogLevel()); $loghandler = new FileLogger($path_abs_root . $path_rel); $logger->addHandler($loghandler); $this->_logger = $logger; }
/** * Method to send welcome message to the subscriber. * * @access public * @param array $user_info array of user info for tag substitution * @param array $attributes array of user attributes for tag substitution * @return The number of the next subscriber to send message * @since 0.7 */ function sendWelcome($user_info, $attributes) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); if (strlen(trim($this->get('welcome_subject'))) < 1) { $logger->finer('Newsletter: Empty Welcome Message subject. Welcome Message will not be sent.'); return true; } $usermail = ''; if (array_key_exists('email', $user_info)) { $usermail = $user_info['email']; } else { $this->setError('COM_JINC_ERR017'); return false; } $msg = $this->get('welcome') . $this->get('disclaimer'); if (array_key_exists('user_id', $user_info)) { $msg = preg_replace('/\\[USER_ID\\]/s', $user_info['user_id'], $msg); } if (array_key_exists('username', $user_info)) { $msg = preg_replace('/\\[USERNAME\\]/s', $user_info['username'], $msg); } if (array_key_exists('name', $user_info)) { $msg = preg_replace('/\\[NAME\\]/s', $user_info['name'], $msg); } $msg = preg_replace('/\\[EMAIL\\]/s', $usermail, $msg); $msg = preg_replace('/\\[SENDER\\]/s', $this->get('sendername'), $msg); $msg = preg_replace('/\\[SENDERMAIL\\]/s', $this->get('senderaddr'), $msg); $msg = preg_replace('/\\[NEWSLETTER\\]/s', $this->get('name'), $msg); $news_id = $this->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); foreach ($attributes as $attr_name => $attr_value) { $msg = preg_replace('/\\[ATTR_' . strtoupper($attr_name) . '\\]/s', $attr_value, $msg); } $message =& JFactory::getMailer(); $message->ContentType = "text/html"; $subject = $this->get('welcome_subject'); $subject = preg_replace('/\\[SENDER\\]/s', $this->get('sendername'), $subject); $subject = preg_replace('/\\[SENDERMAIL\\]/s', $this->get('senderaddr'), $subject); $subject = preg_replace('/\\[NEWSLETTER\\]/s', $this->get('name'), $subject); $message->setSubject($subject); $root_uri = JURI::root(); $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); $message->setBody($msg); if (strlen($this->get('senderaddr')) > 0) { $message->setSender(array($this->get('senderaddr'), $this->get('sendername'))); } if (strlen($this->get('replyto_addr')) > 0) { $message->addReplyTo(array($this->get('replyto_addr'), $this->get('replyto_name'))); } $message->addRecipient($usermail); $logger->finer('Newsletter: Sending mail to ' . $usermail . ' with body ' . $msg); jincimport('utility.parameterprovider'); $send_mail = ParameterProvider::getSendMail(); if ($send_mail) { if (!$message->send()) { $this->setError('COM_JINC_ERR010'); return false; } } else { $logger->info('Newsletter: simulate sending mail. Body = ' . $msg); } }
function statChart() { jincimport('utility.parameterprovider'); jincimport('graphics.chartrenderer'); $chart_system = ParameterProvider::getChartSystem(); if ($chart_system == STATSRENDERER_BUILTIN) { echo '<img align="center" src="index.php?option=com_jinc&task=newsletter.statsRender&format=json" alt="Chart">'; } else { jincimport('graphics.openflashrenderer'); $session = JFactory::getSession(); $values = $session->get('stats.values'); $legend = $session->get('stats.legend'); $renderer = new OpenFlashRenderer($values, $legend); $chart = $renderer->render(); ?> <br> <script type="text/javascript" src="components/com_jinc/assets/js/json2.js"></script> <script type="text/javascript" src="components/com_jinc/assets/js/swfobject.js"></script> <script type="text/javascript"> swfobject.embedSWF("components/com_jinc/assets/flash/open-flash-chart.swf", "my_chart", "750", "250", "9.0.0"); </script> <script type="text/javascript"> function ofc_ready() { } function open_flash_chart_data() { return JSON.stringify(data); } function findSWF(movieName) { if (navigator.appName.indexOf("Microsoft")!= -1) { return window[movieName]; } else { return document[movieName]; } } var data = <?php echo $chart->toPrettyString(); ?> ; </script> <div id="my_chart"></div> <?php } }
/** * Method to send the message preview. * * @access public * @return false if sometring wrong * @since 0.6 * @abstract */ function preview($to_logged_user = true, $addresses = array()) { jincimport('utility.servicelocator'); $servicelocator = ServiceLocator::getInstance(); $logger = $servicelocator->getLogger(); $user =& JFactory::getUser(); if ($user->guest) { $this->setError('COM_JINC_ERR024'); return false; } $mailmsg =& JFactory::getMailer(); jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.file'); $root_uri = JURI::root(); jincimport('utility.parameterprovider'); $send_mail = ParameterProvider::getSendMail(); $result = array(); if ($newsletter = $this->loadNewsletter()) { $logger->finer('Message: Newsletter loaded'); $msg = $this->get('body') . $newsletter->get('disclaimer'); $subject = $this->get('subject'); // Newsletter info substitution in message body $msg = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $msg); $subject = preg_replace('/\\[SENDER\\]/s', $newsletter->get('sendername'), $subject); $msg = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $msg); $subject = preg_replace('/\\[SENDERMAIL\\]/s', $newsletter->get('senderaddr'), $subject); $msg = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $msg); $subject = preg_replace('/\\[NEWSLETTER\\]/s', $newsletter->get('name'), $subject); $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); $subject = preg_replace('#src[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'src="' . $root_uri, $subject); $msg = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?!mailto?:)(?!tel?:)(?:\\.\\./|\\./|/)?#', 'href="' . $root_uri, $msg); $subject = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?!mailto?:)(?!tel?:)(?:\\.\\./|\\./|/)?#', 'href="' . $root_uri, $subject); $msg = preg_replace('#url[ ]*\\(\'(?!https?://)(?:\\.\\./|\\./|/)?#', 'url(\'' . $root_uri, $msg); // Setting message general properties $mailmsg->ContentType = $this->get('plaintext') ? "text/plain" : "text/html"; 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('Message: adding attachment ' . $path_abs_root . DIRECTORY_SEPARATOR . $attachment); $mailmsg->addAttachment($path_abs_root . DIRECTORY_SEPARATOR . $attachment); } } $recipients = array(); if ($to_logged_user) { $user_mail = $user->get('email'); $userid = $user->get('username'); $username = $user->get('name'); $logger->finer('Message: Adding logged user as preview recipient: ' . $user_mail); array_push($recipients, array('email' => $user_mail, 'user_id' => $userid, 'username' => $username)); } foreach ($addresses as $user_mail) { $user = substr($user_mail, 0, strpos($user_mail, '@')); $logger->finer('Message: Adding mail address as preview recipient: ' . $user_mail); array_push($recipients, array('email' => $user_mail, 'user_id' => $user, 'username' => $user)); } foreach ($recipients as $current) { $mailmsg->addRecipient($current['email']); foreach ($current as $key => $value) { $msg = preg_replace('/\\[' . strtoupper($key) . '\\]/s', $value, $msg); $subject = preg_replace('/\\[' . strtoupper($key) . '\\]/s', $value, $subject); } $mailmsg->setSubject($subject); $mailmsg->setBody($this->emogrify($msg)); if ($send_mail) { $success = $mailmsg->Send(); if ($success === true) { $logger->debug('Message: preview successfully sent to ' . $current['email']); array_push($result, $current['email']); } } else { $logger->info('Message: simulate sending preview. Body = ' . $msg); array_push($result, $current['email']); } $mailmsg->ClearAllRecipients(); } } else { $this->setError('COM_JINC_ERR001'); return false; } return $result; }
/** * 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); }
/** * 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(); }
/** * 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(); }
/** * Method to understand if a sending process must be stopped * in case of mail system failure. * * @return boolean */ function getStopOnFail() { $ret = (int) ParameterProvider::getParam('stop_on_failure', PARAMETERPROVIDER_STOP_ON_FAILURE); return $ret == 1 ? PARAMETERPROVIDER_STOP_ON_FAILURE : $ret; }
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with JINC. If not, see <http://www.gnu.org/licenses/>. */ defined('_JEXEC') or die('Restricted access'); isset($this->newsletter) || die('Newsletter not found'); $newsletter = $this->newsletter; $id = $newsletter->get('id'); $news_type = $newsletter->getType(); $front_theme = $newsletter->get('front_theme') . '.css'; echo JHTML::stylesheet($front_theme, 'components/com_jinc/assets/themes/'); echo JHTML::script('components/com_jinc/assets/js/jinc.js'); jincimport('utility.parameterprovider'); $num_msg = ParameterProvider::getDefaultNumMessages(); ?> <div class="jinc_caption"> <?php echo $newsletter->get('name'); ?> </div> <form action="<?php echo JRoute::_('index.php'); ?> " method="post"> <div class="jinc_frm_subscription"> <?php if ($news_type == NEWSLETTER_PUBLIC_NEWS) { ?> <?php