Example #1
0
 public function clicked()
 {
     JRequest::setVar('view', 'campaigns');
     JRequest::setVar('layout', 'clicked');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
Example #2
0
File: sync.php Project: rodhoff/MNW
 public function highrise()
 {
     JRequest::setVar('view', 'sync');
     JRequest::setVar('layout', 'highrise');
     JRequest::setVar('hidemainmenu', 0);
     parent::display();
 }
Example #3
0
 public function edit()
 {
     JRequest::setVar('view', 'joomailermailchimpintegration');
     JRequest::setVar('layout', 'form');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
Example #4
0
 public function upload()
 {
     JRequest::setVar('view', 'templates');
     JRequest::setVar('layout', 'upload');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
Example #5
0
 public function edit()
 {
     JRequest::setVar('view', 'fields');
     JRequest::setVar('layout', 'form');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
Example #6
0
 public function edit()
 {
     $db = JFactory::getDBO();
     $cid = JRequest::getVar('cid', '', 'post', 'array');
     $query = $db->getQuery(true);
     $query->select($db->qn(array('cdata', 'folder_id')))->from('#__joomailermailchimpintegration_campaigns')->where($db->qn('creation_date') . ' = ' . $db->q($cid[0]));
     $db->setQuery($query);
     $result = $db->loadAssocList();
     $cdata = json_decode($result[0]['cdata']);
     JRequest::setVar('cid', $cid[0]);
     foreach ($cdata as $k => $v) {
         JRequest::setVar($k, $v);
     }
     JRequest::setVar('view', 'create');
     JRequest::setVar('action', 'edit');
     JRequest::setVar('layout', 'default');
     JRequest::setVar('hidemainmenu', 0);
     JRequest::setVar('offset', 0);
     parent::display();
 }
Example #7
0
File: send.php Project: rodhoff/MNW
 public function __construct()
 {
     parent::__construct();
 }
Example #8
0
 public function save()
 {
     $error = false;
     // plugin support
     JPluginHelper::importPlugin('joomlamailer');
     $dispatcher = JDispatcher::getInstance();
     $params = JComponentHelper::getParams('com_joomailermailchimpintegration');
     $archiveDir = $params->get('params.archiveDir', '/administrator/components/com_joomailermailchimpintegration/archive');
     // get POST data
     $creationDate = JRequest::getVar('cid', 0, 'post', 'string');
     $action = JRequest::getVar('action', 'save', 'post', 'string');
     $campaignName = JRequest::getVar('campaign_name', 0, 'post', 'string');
     $campaignNameEsc = JApplication::stringURLSafe($campaignName);
     $subject = stripslashes(JRequest::getVar('subject', 0, 'post', 'string'));
     $fromName = stripslashes(str_ireplace(array('"', '@'), array(' ', '(at)'), JRequest::getVar('from_name', 0, 'post', 'string')));
     $fromEmail = JRequest::getVar('from_email', 0, 'post', 'string');
     $replyEmail = JRequest::getVar('reply_email', 0, 'post', 'string');
     $confirmationEmail = JRequest::getVar('confirmation_email', 0, 'post', 'string');
     $textOnly = JRequest::getVar('text_only', 0, 'post', 'int');
     $textOnlyContent = JRequest::getVar('text_only_content', '', 'post', 'string');
     $templateFolder = JRequest::getVar('template', 0, 'post', 'string');
     $facebookShareIt = JRequest::getVar('facebookShare', 0, 'post', 'string');
     $facebookShareDesc = JRequest::getVar('facebookShareDesc', '', 'post', 'string');
     $fbImage = JRequest::getVar('fbImage', '', 'post', 'string');
     $gaEnabled = JRequest::getVar('gaEnabled', 0, 'post', 'int');
     $gaExcluded = JRequest::getVar('gaExcluded', '', 'post', 'string');
     $gaSource = JApplication::stringURLSafe(JRequest::getVar('gaSource', 'newsletter', 'post', 'string'));
     $gaMedium = JApplication::stringURLSafe(JRequest::getVar('gaMedium', 'email', 'post', 'string'));
     $gaName = JApplication::stringURLSafe(JRequest::getVar('gaName', $campaignNameEsc, 'post', 'string'));
     // define abs path for regex
     $absPath = '$1="' . JURI::root() . '$2$3';
     $imagepath = '$1="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/templates/' . $templateFolder . '/$2$3';
     // get folder id or name
     $folder_id = JRequest::getVar('folder_id', 0, 'post', 'int');
     $folder_name = JRequest::getVar('folder_name', 0, 'post', 'string');
     if (!$folder_id && $folder_name) {
         $folder_id = $this->getModel('create')->createFolder($folder_name);
     }
     if ($textOnly) {
         $template = $textOnlyContent;
         // create google analytics tracking links
         if ($gaEnabled) {
             $ga = 'utm_source=' . $gaSource . '&utm_medium=' . $gaMedium . '&utm_campaign=' . $gaName;
             $gaEx = explode("\n", $gaExcluded);
             for ($i = 0; $i < count($gaEx); $i++) {
                 $gaEx[$i] = trim($gaEx[$i]);
             }
             $gaEx[] = '*|UNSUB|*';
             $regex = '#https?://.*?(?:\\s|\\n|\\r)#i';
             preg_match_all($regex, $template, $templateLinks, PREG_PATTERN_ORDER);
             if (isset($templateLinks[0])) {
                 foreach ($templateLinks[0] as $link) {
                     $glue = strstr($link, '?') ? $glue = '&' : ($glue = '?');
                     $oldHref = substr($link, 0, -1);
                     $addGA = true;
                     foreach ($gaEx as $ex) {
                         if (stristr($link, $ex)) {
                             $addGA = false;
                             break;
                         }
                     }
                     if ($addGA) {
                         $link = str_replace(array("\\s", "\n", "\r", " ", '%'), array('', '', '', '', '\\%'), $link);
                         $template = preg_replace('%' . $link . '(\\s|\\n|\\r)%i', $oldHref . $glue . $ga . '$1', $template);
                     }
                 }
             }
         }
         $filename = JPATH_SITE . $archiveDir . '/' . $campaignNameEsc . '.txt';
         if (!JFile::write($filename, $template)) {
             $error = true;
         }
     } else {
         $introText = JRequest::getVar('intro', '', 'post', 'string', JREQUEST_ALLOWRAW);
         // display popular articles?
         $popularlist = '';
         $popularCheckbox = JRequest::getVar('populararticles', 0, 'post', 'int');
         $populararticlesAmount = JRequest::getVar('populararticlesAmount', 5, 'post', 'int');
         $popularEx = JRequest::getVar('popExclude', false, 'post');
         $popularIn = JRequest::getVar('popInclude', false, 'post');
         // include K2 in populars?
         $popularK2Checkbox = JRequest::getVar('populark2', 0, 'post', 'int');
         $popularK2Ex = JRequest::getVar('popk2Exclude', false, 'post');
         $popularK2In = JRequest::getVar('popk2Include', false, 'post');
         // only K2 articles in populars?
         $popularK2Only = JRequest::getVar('populark2_only', 0, 'post', 'int');
         // convert relative to absolute href paths
         $introText = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $absPath, $introText);
         // open the template file
         $filename = JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/templates/' . $templateFolder . '/template.html';
         $template = JFile::read($filename, false, filesize($filename));
         // popular articles
         $regex = '!<#populararticles#[^>]*>(.*)<#/populararticles#>!is';
         if (preg_match($regex, $template, $populararticles)) {
             $populararticles = $populararticles[0];
             $regex = '!<#popular_repeater#[^>]*>(.*)<#/popular_repeater#>!is';
             if (preg_match($regex, $template, $popular_repeater)) {
                 $popular_repeater = $popular_repeater[0];
             }
             // create list of popular articles
             if ($popularCheckbox && !$popularK2Checkbox) {
                 $query = 'SELECT c.id, c.title, c.hits FROM #__content as c
                 WHERE (c.state = 1 OR c.state = -2)
                 AND c.hits != 0
                 ' . $where . '
                 ORDER BY c.hits DESC
                 LIMIT 0 , ' . $populararticlesAmount;
             } else {
                 if ($popularCheckbox && $popularK2Checkbox && !$popularK2Only) {
                     $query = 'SELECT c.id, c.title, c.hits
                 FROM #__content as c
                 WHERE (c.state = 1 OR c.state = -2)
                 AND c.hits != 0
                 ' . $where . '
                 UNION ALL SELECT k.id, k.title, k.hits
                 FROM #__k2_items as k
                 WHERE k.published = 1
                 AND k.hits != 0
                 ' . $whereK2 . '
                 ORDER BY hits DESC
                 LIMIT 0 , ' . $populararticlesAmount;
                 } else {
                     if ($popularCheckbox && $popularK2Checkbox && $popularK2Only) {
                         $query = 'SELECT k.id, k.title, k.hits
                 FROM #__k2_items as k
                 WHERE k.published = 1
                 AND k.hits != 0
                 ' . $whereK2 . '
                 ORDER BY k.hits DESC
                 LIMIT 0 , ' . $populararticlesAmount;
                     }
                 }
             }
             if ($popularCheckbox) {
                 $this->db->setQuery($query);
                 $popular = $this->db->loadObjectList();
                 $i = 0;
                 foreach ($popular as $pop) {
                     if ($i++ > 5) {
                         break;
                     }
                     $query = $this->db->getQuery(true)->select($this->db->qn('id'))->from($this->db->qn('#__content'))->where($this->db->qn('title') . ' = ' . $this->db->q($pop->title));
                     $this->db->setQuery($query);
                     if ($this->db->loadResult()) {
                         $url = '<a href="' . JURI::root() . 'index.php?option=com_content&view=article&id=' . $pop->id . '">' . $pop->title . '</a>';
                     } else {
                         $url = '<a href="' . JURI::root() . 'index.php?option=com_k2&view=item&id=' . $pop->id . '">' . $pop->title . '</a>';
                     }
                     $popularlist .= str_ireplace('<#popular_title#>', $url, $popular_repeater);
                 }
             }
             $popularlist = preg_replace('!<#popular_repeater#[^>]*>(.*)<#/popular_repeater#>!is', $popularlist, $populararticles);
             $toReplace = array('<#populararticles#>', '<#/populararticles#>', '<#popular_repeater#>', '<#/popular_repeater#>');
             $popularlist = str_ireplace($toReplace, '', $popularlist);
         }
         $filename = JPATH_ADMINISTRATOR . '/components/com_joomailermailchimpintegration/templates/' . $templateFolder . '/template.html';
         $template = JFile::read($filename, false, filesize($filename));
         // create absolute image paths
         $imagepath = ' src="' . JURI::base() . 'components/com_joomailermailchimpintegration/templates/' . $templateFolder . '/' . '$2$3';
         $template = preg_replace('#(src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $template);
         $imagepath = " url('" . JURI::base() . "components/com_joomailermailchimpintegration/templates/" . $templateFolder . "/";
         $template = preg_replace('#(\\s*)url?\\([\'"]?[../]*[\'"]?#i', $imagepath, $template);
         $imagepath = ' background="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/templates/' . $templateFolder . '/';
         $template = preg_replace('#(\\s*)background=[\'"]?[../]*[\'"]?#i', $imagepath, $template);
         JRequest::setVar('template_folder', $templateFolder);
         // call plugin event to insert content
         $dispatcher->trigger('insert', array(&$template));
         // modify paths of intro-text
         // remove tiny mce stuff like mce_src="..."
         $introText = preg_replace('(mce_style=".*?")', '', $introText);
         $introText = preg_replace('(mce_src=".*?")', '', $introText);
         $introText = preg_replace('(mce_href=".*?")', '', $introText);
         $introText = preg_replace('(mce_bogus=".*?")', '', $introText);
         // convert relative to absolute paths
         $absPath = '$1="' . JURI::root() . '$2$3';
         $introText = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $absPath, $introText);
         // end paths intro-text
         // insert intro-text
         $template = str_ireplace('<#intro_content#>', $introText, $template);
         // insert page title
         $template = str_ireplace('<#subject#>', $subject, $template);
         //insert popular articles
         if ($popularlist && $popularCheckbox) {
             $popularlist = str_ireplace('$', '\\$', $popularlist);
             $template = preg_replace('!<#populararticles#[^>]*>(.*?)<#/populararticles#>!is', $popularlist, $template);
         } else {
             $template = preg_replace('!<#populararticles#[^>]*>(.*?)<#/populararticles#>!is', '', $template);
         }
         //insert facebook share link
         if ($facebookShareIt) {
             $template = preg_replace('!<#facebook_share#[^>]*>(.*?)<#/facebook_share#>!is', $fbs, $template);
             $metaData = "<meta name=\"title\" content=\"{$campaignName}\" />\n" . "<meta name=\"description\" content=\"{$facebookShareDesc}\" />\n" . "<link rel=\"image_src\" href=\"{$fbImage}\" />\n";
             $metaData = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $absPath, $metaData);
             $template = str_ireplace('</head>', $metaData . '</head>', $template);
         } else {
             $template = preg_replace('!<#facebook_share#[^>]*>(.*?)<#/facebook_share#>!is', '', $template);
         }
         // remove unused placeholders
         $template = preg_replace('!<#([^#]+)#>.*?<#/\\1#>!s', '', $template);
         $template = preg_replace('/<#[^#]+#>/', '', $template);
         // create google analytics tracking links
         if ($gaEnabled) {
             $ga = 'utm_source=' . $gaSource . '&utm_medium=' . $gaMedium . '&utm_campaign=' . $gaName . '"';
             $gaEx = explode("\n", $gaExcluded);
             for ($i = 0; $i < count($gaEx); $i++) {
                 $gaEx[$i] = trim($gaEx[$i]);
             }
             $gaEx[] = '*|UNSUB|*';
             $regex = '#<a(.*?)>(.*?)</a>#i';
             preg_match_all($regex, $template, $templateLinks, PREG_PATTERN_ORDER);
             if (isset($templateLinks[0])) {
                 foreach ($templateLinks[0] as $link) {
                     preg_match_all('#((href)="(?!\\.css)[^"]+)"#i', $link, $oldLink, PREG_PATTERN_ORDER);
                     if (isset($oldLink[0][0])) {
                         $glue = strstr($oldLink[0][0], '?') ? $glue = '&' : ($glue = '?');
                         $oldHref = substr($oldLink[0][0], 0, -1);
                         $addGA = true;
                         foreach ($gaEx as $ex) {
                             if (stristr($oldHref, $ex)) {
                                 $addGA = false;
                             }
                         }
                         if ($addGA) {
                             $newLink = preg_replace('#((href)="(?!\\.css)[^"]+)"#i', $oldHref . $glue . $ga . '"', $link);
                             $template = str_ireplace($oldLink[0][0], $oldHref . $glue . $ga . '"', $template);
                         }
                     }
                 }
             }
         }
         // prevent preview from being cached
         $metaData = "\n<meta http-Equiv=\"Cache-Control\" Content=\"no-cache\">\n" . "<meta http-Equiv=\"Pragma\" Content=\"no-cache\">\n" . "<meta http-Equiv=\"Expires\" Content=\"0\">\n" . "<base href=\"\">\n";
         if (!stristr($template, "<head>")) {
             $template = str_ireplace('<html>', '<html><head>' . $metaData . '</head>', $template);
         } else {
             $template = str_ireplace('</head>', $metaData . '</head>', $template);
         }
         // create html version
         $filename = JPATH_SITE . $archiveDir . '/' . $campaignNameEsc . '.html';
         if (!JFile::write($filename, $template)) {
             $error = true;
         }
         // create txt version
         if (!$error) {
             $txtContent = $template;
             $txtContent = preg_replace("!<head[^>]*>(.*?)</head>!is", '', $txtContent);
             $txtContent = preg_replace("!<style[^>]*>(.*?)</style>!is", '', $txtContent);
             $txtContent = preg_replace("!<forwardtoafriend[^>]*>(.*?)</forwardtoafriend>!is", 'Forward to a friend: *|FORWARD|*', $txtContent);
             $txtContent = preg_replace("!<preferences[^>]*>(.*?)</preferences>!is", 'Preference center: *|UPDATE_PROFILE|*', $txtContent);
             $txtContent = preg_replace("!<unsubscribe[^>]*>(.*?)</unsubscribe>!is", '*|UNSUB|*', $txtContent);
             $txtContent = preg_replace("!<webversion[^>]*>(.*?)</webversion>!is", '*|ARCHIVE|*', $txtContent);
             $txtContent = strip_tags($txtContent);
             $txtContent = htmlspecialchars($txtContent);
             $txtContent = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n\n", $txtContent);
             $txtContent = preg_replace("/^ +/m", '', $txtContent);
             $txtContent = $campaignNameEsc . "\n" . $txtContent;
             $filename = JPATH_SITE . $archiveDir . '/' . $campaignNameEsc . '.txt';
             @JFile::write($filename, $txtContent);
         }
     }
     // set the redirection link and message
     if ($error) {
         foreach ($_POST as $k => $v) {
             JRequest::setVar($k, $v);
         }
         if ($creationDate) {
             JRequest::setVar('cid', $creationDate);
         }
         if ($campaignName) {
             JRequest::setVar('cn', $campaignName);
         }
         if ($subject) {
             JRequest::setVar('sj', $subject);
         }
         if ($fromName) {
             JRequest::setVar('fn', $fromName);
         }
         if ($fromEmail) {
             JRequest::setVar('fe', $fromEmail);
         }
         if ($replyEmail) {
             JRequest::setVar('re', $replyEmail);
         }
         if ($confirmationEmail) {
             JRequest::setVar('ce', $confirmationEmail);
         }
         if ($templateFolder) {
             JRequest::setVar('tpl', $templateFolder);
         }
         if ($popularCheckbox) {
             JRequest::setVar('pop', $popularCheckbox);
         }
         if ($popularIn) {
             JRequest::setVar('pin', implode(';', $popularIn));
         }
         if ($popularEx) {
             JRequest::setVar('pex', implode(';', $popularEx));
         }
         if ($popularK2Checkbox) {
             JRequest::setVar('pk2', $popularK2Checkbox);
         }
         if ($popularK2In) {
             JRequest::setVar('pk2in', implode(';', $popularK2In));
         }
         if ($popularK2Ex) {
             JRequest::setVar('pk2ex', implode(';', $popularK2Ex));
         }
         if ($popularK2Only) {
             JRequest::setVar('pk2o', $popularK2Only);
         }
         if ($introText) {
             JRequest::setVar('intro', urlencode(htmlentities(urlencode($introText))));
         }
         if ($gaSource) {
             JRequest::setVar('gaS', urlencode(htmlentities(urlencode($gaSource))));
         }
         if ($gaMedium) {
             JRequest::setVar('gaM', urlencode(htmlentities(urlencode($gaMedium))));
         }
         if ($gaName) {
             JRequest::setVar('gaN', urlencode(htmlentities(urlencode($gaName))));
         }
         if ($gaExcluded) {
             JRequest::setVar('gaE', $gaExcluded);
         }
         JRequest::setVar('view', 'create');
         JRequest::setVar('layout', 'default');
         JRequest::setVar('action', JRequest::getVar('action', ''));
         JRequest::setVar('hidemainmenu', 0);
         JRequest::setVar('offset', 0);
         jimport('joomla.error.error');
         JError::raiseWarning(100, JText::sprintf('JM_CAMPAIGN_CREATION_FAILED', $archiveDir));
         parent::display();
     } else {
         $timeStamp = time();
         $postData = array();
         foreach ($_POST as $key => $value) {
             if (in_array($key, array('cid', 'offset', 'activeTab', 'option', 'task', 'action', 'boxchecked', 'controller', 'type'))) {
                 continue;
             }
             if (is_string($value) && stristr($value, 'http')) {
                 $value = urlencode(htmlentities(urlencode($value)));
             }
             $postData[$key] = $value;
         }
         $query = $this->db->getQuery(true);
         // store campaign details locally
         if ($creationDate && $action != 'copy') {
             $query->update($this->db->qn('#__joomailermailchimpintegration_campaigns'))->set($this->db->qn('subject') . ' = ' . $this->db->q($subject))->set($this->db->qn('from_name') . ' = ' . $this->db->q($fromName))->set($this->db->qn('from_email') . ' = ' . $this->db->q($fromEmail))->set($this->db->qn('reply') . ' = ' . $this->db->q($replyEmail))->set($this->db->qn('confirmation') . ' = ' . $this->db->q($confirmationEmail))->set($this->db->qn('creation_date') . ' = ' . $this->db->q($timeStamp))->set($this->db->qn('cdata') . ' = ' . $this->db->q(json_encode($postData)))->set($this->db->qn('folder_id') . ' = ' . $this->db->q($folder_id))->where($this->db->qn('creation_date') . ' = ' . $this->db->q($creationDate));
         } else {
             $query->insert($this->db->qn('#__joomailermailchimpintegration_campaigns'))->set($this->db->qn('name') . ' = ' . $this->db->q($campaignName))->set($this->db->qn('subject') . ' = ' . $this->db->q($subject))->set($this->db->qn('from_name') . ' = ' . $this->db->q($fromName))->set($this->db->qn('from_email') . ' = ' . $this->db->q($fromEmail))->set($this->db->qn('reply') . ' = ' . $this->db->q($replyEmail))->set($this->db->qn('confirmation') . ' = ' . $this->db->q($confirmationEmail))->set($this->db->qn('creation_date') . ' = ' . $this->db->q($timeStamp))->set($this->db->qn('cdata') . ' = ' . $this->db->q(json_encode($postData)))->set($this->db->qn('folder_id') . ' = ' . $this->db->q($folder_id));
         }
         $this->db->setQuery($query);
         try {
             $this->db->execute();
             $msg = sprintf(JText::_('JM_DRAFT_SAVED'), $campaignName);
             $this->app->enqueueMessage($msg);
         } catch (Exception $e) {
             jimport('joomla.error.error');
             JError::raiseWarning(100, $e->getMessage());
         }
         JRequest::setVar('view', 'send');
         JRequest::setVar('layout', 'default');
         JRequest::setVar('campaign', $timeStamp);
         JRequest::setVar('hidemainmenu', 0);
         parent::display();
     }
 }