コード例 #1
0
ファイル: class.mailing.php プロジェクト: naka211/kkvn
 /** 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
ファイル: class.templates.php プロジェクト: naka211/kkvn
 /**
  * public static function that will upload template
  */
 public static function uploadTemplate()
 {
     jimport('joomla.filesystem.archive');
     $name = $_FILES['tempupload']['name'];
     $tempPath = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS;
     // check and set permission of the template folder
     if (!empty($name)) {
         $mediacomjNewsdir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION);
         $mediacomjNewsTemplatesdir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates');
         $mediacomjNewsTemplatesThumbnaildir = jNews_Templates::_checkpermission(JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates' . DS . 'thumbnail');
         if (!$mediacomjNewsdir or !$mediacomjNewsTemplatesdir or !$mediacomjNewsTemplatesThumbnaildir) {
             echo jnews::printM('notice', 'The following directory is not writable: ' . JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION);
             return false;
         }
     } else {
         //failed
         echo jnews::printM('notice', 'Did not found a file to upload.');
         return false;
     }
     // upload template
     $status = true;
     $path = JNEWS_JPATH_ROOT_NO_ADMIN . DS . 'media' . DS . JNEWS_OPTION . DS . 'templates';
     $folderName = substr($name, 0, -4);
     $result = jNews_Mailing::uploadFiles($path);
     $nameRealFolder = jNews_Templates::openZip($tempPath . $name);
     jNews_Templates::$nameNewFolder = "";
     if ($folderName !== $nameRealFolder) {
         jNews_Templates::$nameNewFolder = $nameRealFolder;
     }
     if (jNews_Templates::$nameNewFolder === "") {
         if (!is_dir($tempPath . $folderName)) {
             $status = mkdir($tempPath . $folderName, 0755);
         }
     }
     if (!$status) {
         echo jnews::printM('notice', 'The following directory is not writable: ' . $tempPath);
         return false;
     }
     if ($status && !empty($result)) {
         $resultArchive = JArchive::extract($tempPath . $name, $path);
         if ($resultArchive) {
             // delete zip afterwards
             if (fopen($tempPath . $name, 'w')) {
                 @unlink($tempPath . $name);
             }
             //we prompt a message that the upload was successful
             echo jnews::printM('green', 'Successfully uploaded the template');
             if (is_dir($tempPath . $folderName)) {
                 chmod($tempPath . $folderName, 0755);
             }
             if (jNews_Templates::$nameNewFolder === "") {
                 return file_exists($tempPath . $folderName . DS . 'index.html') ? true : false;
             } else {
                 return file_exists($tempPath . $nameRealFolder . DS . 'index.html') ? true : false;
             }
         } else {
             echo 'Joomla is unable to extract the file :' . $tempPath . $name;
         }
     } else {
         return false;
     }
 }