示例#1
0
 /** public static function that will save mailing
  * @param int $mailingId - mailing id
  * @param int $listId - list id
  */
 public static function saveMailing(&$mailingId, $listId)
 {
     $total = 0;
     $list = jNews_Lists::getOneList($listId);
     //		$allow_html = jNews_Tools::allow_html();
     $xf = new jNews_Config();
     $db = JFactory::getDBO();
     // check list type
     $mailingtype = JRequest::getVar('listype', 0);
     if (empty($mailingtype)) {
         $mySess = JFactory::getSession();
         $listType = $mySess->set('listype', '', 'LType');
     } else {
         $listType = $mailingtype;
     }
     $senddate = JRequest::getVar('senddate', 0);
     $task = JRequest::getVar('task', '');
     if ($task == 'saveSend') {
         $senddate = time();
     }
     $subject = JRequest::getVar('subject', '', 'request', 'string');
     //		$content = JRequest::getVar('content', '', 'request','string', JREQUEST_ALLOWRAW);
     $content = JRequest::getVar('jnewsContent', '', 'request', 'string', JREQUEST_ALLOWRAW);
     $alt_content = JRequest::getVar('altbody', '', JREQUEST_ALLOWRAW);
     $published = JRequest::getVar('published', 0);
     $visible = JRequest::getVar('visible', 1);
     $html = JRequest::getVar('html_mailings', 1);
     $new_list = JRequest::getVar('new_list', 0);
     $fromname = JRequest::getVar('fromname', '');
     $fromemail = JRequest::getVar('fromemail', '');
     $frombounce = JRequest::getVar('frombounce', '');
     $userid = JRequest::getVar('userid', 0);
     $delay = JRequest::getVar('delay', 0);
     $acc_level = JRequest::getVar('acc_level', $list->acc_id);
     $issue_nb = JRequest::getVar('issue_nb', 1);
     if ($mailingtype == 7) {
         $issue_nb = 1;
     }
     $attachments = JRequest::getVar('attachments', '');
     $follow_up = JRequest::getVar('follow_up', 0);
     $cat_id = JRequest::getVar('cat_id', '');
     $delay_max = JRequest::getVar('delay_max', 7);
     $delay_min = JRequest::getVar('delay_min', 0);
     $notify_id = JRequest::getVar('notify_id', 0);
     $next_date = JRequest::getVar('next_date', 0);
     $start_date = JRequest::getVar('start_date', 0);
     $smart_date = JRequest::getVar('smart_date', 0);
     $listIdA = JRequest::getVar('aca_mailing_addto', array());
     //clean up $cat_id
     if (!empty($cat_id)) {
         $cat_idA = explode(',', $cat_id);
         if (count($cat_idA) > 1) {
             //remove the all category
             $newcat_idA = array();
             foreach ($cat_idA as $oneCat_id) {
                 if ($oneCat_id != '0:0') {
                     $newcat_idA[] = $oneCat_id;
                 }
             }
             $cat_id = trim(implode(',', $newcat_idA), ',');
         }
     }
     $createdate = time();
     //get the default template
     $template = jNews_Templates::loadOneTemplate('*', '', 'template_id', 'DESC', true);
     $template_id = JRequest::getVar('template_id', $template->template_id);
     // change start_date type from string to int
     if (!empty($senddate) and $task != 'saveSend') {
         $senddate = strtotime($senddate);
         $senddate = $senddate - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
         if ($senddate <= time()) {
             $senddate = 0;
         }
     } elseif (!empty($senddate) && $task == 'saveSend') {
         //not used any more
         $senddate = $senddate;
     } else {
         $senddate = 0;
     }
     if (!empty($start_date)) {
         $start_date = strtotime($start_date);
         $start_date = $start_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
     }
     if (!empty($next_date)) {
         $next_date = strtotime($next_date);
         $next_date = $next_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
     }
     if (!empty($create_date)) {
         $create_date = strtotime($create_date);
         $create_date = $create_date - jnews::calculateOffset(JNEWS_TIME_OFFSET) + date('Z');
     }
     $delay = $delay * 24 * 60;
     $attach = '';
     if (!empty($attachments)) {
         foreach ($attachments as $attachment) {
             $attach .= $attachment . "\n";
         }
     }
     if (!empty($_FILES['file_0']['name'])) {
         $otherAttachs = jNews_Mailing::uploadFiles();
         if (!empty($otherAttachs)) {
             foreach ($otherAttachs as $otherAttach) {
                 $attach .= '/' . $otherAttach . "\n";
             }
         }
     }
     $images = JRequest::getVar('images', '');
     if (empty($alt_content)) {
         $alt_content = jNews_ProcessMail::htmlToText($content);
     } else {
         $alt_content = "<pre>" . $alt_content . "</pre>";
     }
     if ($listType == 2) {
         // auto-repsonders
         $senddate = time() + $delay * 60;
     } else {
         if ($senddate > time()) {
             $published = 2;
         }
     }
     if ($GLOBALS[JNEWS . 'show_subscriptionlink']) {
         if (substr_count($content, '{tag:subscriptions}') < 1) {
             $content .= "<br/> {tag:subscriptions} <br/>";
         }
         if (strlen($alt_content) > 10 and substr_count($alt_content, '{tag:subscriptions}') < 1) {
             $alt_content .= "\r\n {tag:subscriptions} \r\n";
         }
     }
     if ($GLOBALS[JNEWS . 'show_unsubscribelink']) {
         if (substr_count($content, '{tag:unsubscribe}') < 1) {
             $content .= "<br/> {tag:unsubscribe} <br/>";
         }
         if (strlen($alt_content) > 10 and substr_count($alt_content, '{tag:unsubscribe}') < 1) {
             $alt_content .= "\r\n {tag:unsubscribe}\r\n";
         }
     }
     // save to cross table
     if (!empty($listIdA) && !empty($listIdA)) {
         $myLIst2Add = array();
         foreach ($listIdA as $listid => $values) {
             if ($values == 1) {
                 $myLIst2Add[$listid] = true;
             }
         }
     } else {
         // we dont have any list selected
         return false;
     }
     //in saving in case there are still old tag format we will replace with new
     //we replce the oldtags to new tags
     $mailing = new stdClass();
     $mailing->htmlcontent = jNews_Mailing::replaceOldTagsToNew($content);
     $mailing->textonly = jNews_Mailing::replaceOldTagsToNew($alt_content);
     if ($new_list != 0) {
         //NEW MAILING
         //information to be inserted
         $mailing->list_id = $listId;
         $mailing->mailing_type = $mailingtype;
         $mailing->senddate = $senddate;
         $mailing->subject = $subject;
         $mailing->htmlcontent = $content;
         $mailing->textonly = $alt_content;
         $mailing->attachments = $attach;
         $mailing->images = $images;
         $mailing->published = $published;
         $mailing->visible = $visible;
         $mailing->fromname = $fromname;
         $mailing->fromemail = $fromemail;
         $mailing->frombounce = $frombounce;
         $mailing->html = $html;
         $mailing->delay = $delay;
         $mailing->issue_nb = $issue_nb;
         $mailing->acc_level = $acc_level;
         $mailing->createdate = $createdate;
         $mailing->follow_up = $follow_up;
         if (empty($mailing->follow_up)) {
             $mailing->follow_up = 0;
         }
         $mailing->cat_id = $cat_id;
         $mailing->delay_max = $delay_max;
         $mailing->delay_min = $delay_min;
         $mailing->notify_id = $notify_id;
         $mailing->next_date = $next_date;
         $mailing->start_date = $start_date;
         $mailing->smart_date = $smart_date;
         $mailing->mailing_type = $mailingtype;
         $mailing->list_id = $listId;
         $mailing->author_id = $userid;
         $mailing->template_id = $template_id;
         //insert the mailing data
         $mailingId = jNews_Mailing::insertMailingData($mailing);
         $db->setQuery('SELECT LAST_INSERT_ID()');
         $mailingId = $db->loadResult();
         $xf->plus('totalmailing0', 1);
         $xf->plus('act_totalmailing0', 1);
         $xf->plus('totalmailing' . $listType, 1);
         $xf->plus('act_totalmailing' . $listType, 1);
         if ($listType == 7) {
             jNews_Queue::addSNinQueue($mailingId, $delay_min, $start_date, $mailing->next_date);
         }
         //modified for smartnewsletter added next_date
         jNews_Mailing::saveMailingList($mailingId, array_keys($myLIst2Add), $senddate, $listType, $published, (bool) $new_list);
         //if we have an auto-responder we need to make sure the new auto-responders get added to all current subscribed users
         if ($published && $mailingtype == 2) {
             //add the this auto-responders to all users
             //select all user subscribe to this autoresponder
             $query = "SELECT L.`subscriber_id`, L.`subdate`+" . $delay . ", " . $mailingId . ", 2, 1  FROM `#__jnews_listssubscribers` AS L  ";
             $query .= " WHERE L.`list_id` =" . $listId;
             $query2 = "INSERT IGNORE `#__jnews_queue` ( `subscriber_id`, `send_date`, `mailing_id`, `type`, `priority` ) " . $query;
             $db->setQuery($query2);
             $db->query();
         }
     } else {
         //update mailing
         $query = 'SELECT `send_date`,`published`,`delay` FROM `#__jnews_mailings` WHERE `id` =' . $mailingId;
         $db->setQuery($query);
         $mailingInfoO = $db->loadObject();
         $queueSendDateUpdate = $mailingInfoO->send_date != $senddate ? true : false;
         $queuePublishUpdate = $mailingInfoO->published != $published ? true : false;
         $queueDelayUpdate = $mailingInfoO->delay != $delay ? $delay - $mailingInfoO->delay : 0;
         $query = "UPDATE `#__jnews_mailings` SET " . " `subject` = '" . addslashes($subject) . "', " . " `htmlcontent` = '" . addslashes($content) . "', " . " `textonly` = '" . addslashes($alt_content) . "', " . " `attachments` = '" . $attach . "', " . " `images` = '" . $images . "', " . " `published` = '" . $published . "', " . " `html` = " . $html . " , " . " `visible` = " . $visible . " , " . " `fromname` = '" . $fromname . "', " . " `fromemail` = '" . $fromemail . "', " . " `frombounce` = '" . $frombounce . "', " . " `author_id` =  '" . $userid . "' , " . " `delay` = " . $delay . ", " . " `acc_level` = '" . $acc_level . "', " . " `send_date` = '" . $senddate . "', " . " `follow_up` = " . $follow_up . ", " . " `cat_id` = '" . $cat_id . "', " . " `delay_max` = " . (int) $delay_max . ", " . " `delay_min` = " . (int) $delay_min . ", " . " `notify_id` = " . (int) $notify_id . ", " . " `next_date` = " . (int) $next_date . ", " . " `template_id` = " . (int) $template_id . ", " . " `start_date` = " . (int) $start_date . ", " . " `smart_date` = " . (int) $smart_date . " " . " WHERE `id` =" . $mailingId;
         $db->setQuery($query);
         $db->query();
         jNews_Mailing::saveMailingList($mailingId, array_keys($myLIst2Add), $senddate, $listType, $published, (bool) $new_list, $queueSendDateUpdate, $queuePublishUpdate, $queueDelayUpdate);
         if ($published && $mailingtype == 2) {
             $query_check = "SELECT `qid` FROM `#__jnews_queue` WHERE  `type` = '8' AND `mailing_id` = '{$mailingId}'";
             $db->setQuery($query_check);
             $additionInfo = $db->loadObjectList();
             if (is_array($additionInfo) && !empty($additionInfo)) {
                 $query_update = "UPDATE `#__jnews_queue` SET `type` = '2' WHERE mailing_id = {$mailingId}";
                 $db->setQuery($query_update);
                 $db->query();
             }
         }
     }
     return true;
 }
示例#2
0
 function getContent($images, &$content, &$textonly, &$subject, $send = false, $isEdit = false, $queueInfo = null)
 {
     $replaceTag = array('href="mailto:', '@', 'href="#');
     $replaceBy = array('9aca7aca5', '9aca4aca1', '9aca12aca3');
     $content = str_replace($replaceTag, $replaceBy, $content);
     $content = str_replace('{mospagebreak}', '<br style="clear: both;" /><br />', $content);
     if (strlen(trim($textonly)) < 2 && $send) {
         $textonly = jNews_ProcessMail::htmlToText($content);
         $textonly = str_replace('{mosimage}', '', $textonly);
     }
     if (version_compare(JVERSION, '1.6.0', '<')) {
         //j15
         $imgfolders = '/images/stories';
     } else {
         //j16
         $imgfolders = '/images/sampledata';
     }
     if (!empty($images)) {
         foreach ($images as $image) {
             $image_string = '<img src="' . JNEWS_JPATH_LIVE . $imgfolders . $image . '" />';
             $content = preg_replace('/{mosimage}/', $image_string, $content, 1);
         }
     }
     if (!$isEdit) {
         $mainframe = JFactory::getApplication();
         JPluginHelper::importPlugin('jnews');
         $bot_results = $mainframe->triggerEvent('jnewsbot_transformall', array(&$content, &$textonly, &$subject, $queueInfo));
         if (empty($queueInfo->mailingid)) {
             $queueInfo->mailingid = 0;
         }
         if (empty($queueInfo->listid)) {
             $queueInfo->listid = 0;
         }
         //we replace the empty p tags with br tag
         $content = str_replace('<p> </p>', '<br />', $content);
         $content = str_replace('<p></p>', '<br />', $content);
         $content = str_replace('<p>&nbsp;</p>', '<br />', $content);
         $fwdObj = new stdClass();
         $fwdObj->mailingid = !empty($queueInfo->id) ? $queueInfo->id : 0;
         $fwdObj->listid = !empty($queueInfo->list_id) ? $queueInfo->list_id : 0;
         $jomsocial = $mainframe->triggerEvent('jnewsbot_jomsocial_members', array(&$content, &$textonly, ''));
         //to replace jomsocial tags
     }
     $content = jNews_Mailing::replaceOldTagsToNew($content);
     if (empty($subject)) {
         //we have no subject probably because one of the bot define that we should not send the newsletter
         //we cancel this mail
         $this->cancelMailing = true;
         return false;
     }
     $content = str_replace($replaceTag, $replaceBy, $content);
     $content = preg_replace('#src[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'src="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/', $content);
     $content = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'href="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/', $content);
     $content = str_replace($replaceBy, $replaceTag, $content);
     return true;
 }
示例#3
0
 /** public static function that would save the template to its table jnews _templates
  * @param string $task - task executed
  * @param int $template_id - template id
  */
 public static function saveTemplate($task, $template_id)
 {
     $template = new stdClass();
     $db = JFactory::getDBO();
     $template->template_id = $template_id;
     $template->name = JRequest::getVar('template_name', '', 'request', 'string');
     $template->description = JRequest::getVar('description', '', 'request', 'string');
     $template->altbody = JRequest::getVar('alt_body', '', JREQUEST_ALLOWRAW);
     $template->created = time();
     $template->published = JRequest::getVar('confirmed', 0);
     $template->premium = JRequest::getVar('premium', 0);
     $template->namekey = JRequest::getVar('template_namekey', '', 'request', 'string');
     $template->thumbnail = !empty($_FILES['file_0']['name']) ? JNEWS_PATH_ADMIN_THUMBNAIL_SHOW . $_FILES['file_0']['name'] : '';
     //		$template->body = JRequest::getVar('template_body', '', 'request', 'string');
     $template->body = JRequest::getVar('template_body', '', '', 'string', JREQUEST_ALLOWRAW);
     //either  boxes or file
     $styleChoseBox = JRequest::getVar('stylechosen');
     $styles = JRequest::getVar('styles', array(), '', 'array');
     $CSStyle = JRequest::getVar('template_customcss', '', 'request', 'string');
     $newStyles = JRequest::getVar('otherstyles', array(), '', 'array');
     if (!empty($newStyles)) {
         $countC = count($newStyles['classname']);
         for ($i = 0; $i < $countC; $i++) {
             $styles[$newStyles['classname'][$i]] = $newStyles['style'][$i];
         }
     }
     //remove empty style
     $wowStyle = array();
     foreach ($styles as $oneK => $oneS) {
         if (!empty($oneS)) {
             $wowStyle[$oneK] = $oneS;
         }
     }
     //we apply the background color defined in the bg color field
     if (!empty($styles['color_bg'])) {
         $pattern1 = '#^([^<]*<[^>]*background-color:)([^;">]{1,10})#i';
         $found = false;
         if (preg_match($pattern1, $template->body)) {
             $template->body = preg_replace($pattern1, '$1' . $styles['color_bg'], $template->body);
             $found = true;
         }
         $pattern2 = '#^([^<]*<[^>]*bgcolor=")([^;">]{1,10})#i';
         if (preg_match($pattern2, $template->body)) {
             $template->body = preg_replace($pattern2, '$1' . $styles['color_bg'], $template->body);
             $found = true;
         }
         if (!$found) {
             $template->body = '<div style="background-color:' . $styles['color_bg'] . ';" width="100%">' . $template->body . '</div>';
         }
     }
     $template->styles = serialize($wowStyle);
     $template->csstyle = $CSStyle;
     // check and create thumbnail folder
     $thumbPath = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS . 'thumbnail';
     if (is_dir($thumbPath)) {
         // change thumbnail folder permission
         if (!is_writable($thumbPath . DS)) {
             @chmod($thumbPath . DS, 0777);
         }
     } else {
         if (is_dir(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates')) {
             // change templates folder permission
             if (!is_writable(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS)) {
                 @chmod(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS, 0777);
             }
             // create thumbnail folder
             if (!is_dir($thumbPath)) {
                 @mkdir($thumbPath, 0777);
             }
         } else {
             // change component folder permission
             if (!is_writable(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS)) {
                 @chmod(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS, 0777);
             }
             // create templates folder
             if (!is_dir(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates')) {
                 @mkdir(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates', 0777);
             }
             // create thumbnail folder
             if (!is_dir($thumbPath)) {
                 @mkdir($thumbPath, 0777);
             }
         }
     }
     //set all template to not premium if the edited template is set to premium
     if ($template->premium) {
         jNews_Templates::updateTemplate($template->premium, 'default', false, false);
     }
     $template->body = jNews_Mailing::replaceOldTagsToNew($template->body);
     $template->altbody = jNews_Mailing::replaceOldTagsToNew($template->altbody);
     if ($template_id < 1) {
         //new template
         // upload file
         if (!empty($template->thumbnail) && !empty($_FILES['file_0'])) {
             // public static function source in class.mailing.php
             $path = JNEWS_PATH_ADMIN_THUMBNAIL_UPLOAD;
             jNews_Mailing::uploadFiles($path);
         }
         $query = "INSERT INTO `#__jnews_templates` (`name`,`description` , `body` , `altbody`, `created`, `premium` ," . " `namekey` , `published` ,`csstyle`, `styles`, `thumbnail` ) " . "\n VALUES ( '" . addslashes($template->name) . "', '" . addslashes($template->description) . "', " . "'" . addslashes($template->body) . "', " . "'" . addslashes($template->altbody) . "', " . "'" . $template->created . "', " . "'" . $template->premium . "', " . "'" . addslashes($template->namekey) . "', " . "'" . $template->published . "', " . "'" . addslashes($template->csstyle) . "', " . "'" . addslashes($template->styles) . "', " . "'" . $template->thumbnail . "' )";
         $db->setQuery($query);
         $db->query();
     } else {
         //edit here
         // upload file but first check and replaced old file
         if (!empty($template->thumbnail) && !empty($_FILES['file_0'])) {
             $path = JNEWS_PATH_ADMIN_THUMBNAIL_UPLOAD;
             // remove the previous image
             $query1 = "SELECT `thumbnail` FROM `#__jnews_templates` WHERE `template_id` = " . $template->template_id;
             $db->setQuery($query1);
             $result = $db->loadResult();
             $thumbnail = str_replace(JNEWS_PATH_ADMIN_THUMBNAIL_SHOW, '', $result);
             if (!empty($thumbnail)) {
                 $findposhttp = strpos($result, 'http://');
                 $findposwww = strpos($result, 'www.');
                 if ($findposhttp === false && $findposwww === false) {
                     jNews_Attachment::deleteAttachment($thumbnail, $path);
                 }
             }
             // public static function source in class.mailing.php
             // file is save to /root/components/.../templates/image
             jNews_Mailing::uploadFiles($path);
         }
         $query = "UPDATE `#__jnews_templates` SET " . "\t`name` = '" . addslashes($template->name) . "', " . "\t`description` = '" . addslashes($template->description) . "', " . "\t`body` = '" . addslashes($template->body) . "', " . "\t`altbody` = '" . addslashes($template->altbody) . "', " . "\t`created` = '" . $template->created . "', " . "\t`premium` = '" . $template->premium . "', " . "\t`namekey` = '" . addslashes($template->namekey) . "' , " . "\t`published` = '" . $template->published . "' , " . "\t`csstyle` = '" . addslashes($template->csstyle) . "' , " . "\t`styles` = '" . addslashes($template->styles) . '\'';
         $query .= !empty($template->thumbnail) ? ", `thumbnail` = '" . $template->thumbnail . "'" : "";
         $query .= "\tWHERE `template_id` = " . $template->template_id;
         $db->setQuery($query);
         $db->query();
     }
     return true;
 }