function upload()
 {
     JRequest::setVar('view', 'templates');
     JRequest::setVar('layout', 'upload');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
 /**
  * display the clicked list
  * @return void
  */
 function clicked()
 {
     JRequest::setVar('view', 'campaigns');
     JRequest::setVar('layout', 'clicked');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
 function edit()
 {
     JRequest::setVar('view', 'groups');
     JRequest::setVar('layout', 'form');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
 /**
  * display the edit form
  * @return void
  */
 function edit()
 {
     JRequest::setVar('view', 'joomailermailchimpintegration');
     JRequest::setVar('layout', 'form');
     JRequest::setVar('hidemainmenu', 1);
     parent::display();
 }
Esempio n. 5
0
 function highrise()
 {
     JRequest::setVar('view', 'sync');
     JRequest::setVar('layout', 'highrise');
     JRequest::setVar('hidemainmenu', 0);
     parent::display();
 }
 function __construct()
 {
     // remove obsolete files
     jimport('joomla.filesystem.file');
     jimport('joomla.filesystem.folder');
     $removeFiles = array();
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'js' . DS . 'jquery-1.4.2.min.js';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'js' . DS . 'jquery.clockpick.1.2.7.min.js';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'css' . DS . 'jquery.clockpick.1.2.7.css';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'images' . DS . 'ol_bg.jpg';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'models' . DS . 'archive.php';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'controllers' . DS . 'archive.php';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'models' . DS . 'suppression.php';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'controllers' . DS . 'suppression.php';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'helpers' . DS . 'cache.php';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'images' . DS . 'templateEditor.png';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'images' . DS . 'clearPosition.png';
     $removeFiles[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'images' . DS . 'apply.png';
     foreach ($removeFiles as $rf) {
         if (JFile::exists($rf)) {
             JFile::Delete($rf);
         }
     }
     // remove obsolete folders
     $removeFolders = array();
     $removeFolders[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'assets' . DS . 'scripts';
     $removeFolders[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'views' . DS . 'archive';
     $removeFolders[] = JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_joomailermailchimpintegration' . DS . 'views' . DS . 'suppression';
     foreach ($removeFolders as $rf) {
         if (JFolder::exists($rf)) {
             JFolder::Delete($rf);
         }
     }
     parent::__construct();
     $this->registerTask('install', 'install');
     $this->registerTask('upgrade', 'upgrade');
 }
    function save()
    {
        $error = false;
        $db =& JFactory::getDBO();
        $params =& JComponentHelper::getParams('com_joomailermailchimpintegration');
        $paramsPrefix = version_compare(JVERSION, '1.6.0', 'ge') ? 'params.' : '';
        $archiveDir = $params->get($paramsPrefix . 'archiveDir', '/administrator/components/com_joomailermailchimpintegration/archive');
        $model =& $this->getModel('create');
        $core_exists = $model->getCore();
        $k2_exists = $model->getK2();
        $vm_exists = $model->getVMproducts();
        // define abs path for regex
        $abs_path = '$1="' . JURI::root() . '$2$3';
        // get POST data
        $creation_date = JRequest::getVar('cid', 0, 'post', 'string');
        $action = JRequest::getVar('action', 'save', 'post', 'string');
        $campaign_name = JRequest::getVar('campaign_name', 0, 'post', 'string');
        $campaign_name_ent = $this->cleanString($campaign_name);
        $subject = JRequest::getVar('subject', 0, 'post', 'string');
        $from_name = str_ireplace(array('"', '@'), array(' ', '(at)'), JRequest::getVar('from_name', 0, 'post', 'string'));
        $from_email = JRequest::getVar('from_email', 0, 'post', 'string');
        $reply_email = JRequest::getVar('reply_email', 0, 'post', 'string');
        $confirmation_email = JRequest::getVar('confirmation_email', 0, 'post', 'string');
        $template_folder = JRequest::getVar('template', 0, 'post', 'string');
        $twitter_name = JRequest::getVar('twitter', 0, 'post', 'string');
        $facebook_url = JRequest::getVar('facebook', 0, 'post', 'string');
        $myspace_name = JRequest::getVar('myspace', 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 = $this->cleanString(JRequest::getVar('gaSource', 'newsletter', 'post', 'string'));
        $gaMedium = $this->cleanString(JRequest::getVar('gaMedium', 'email', 'post', 'string'));
        $gaName = $this->cleanString(JRequest::getVar('gaName', $campaign_name_ent, 'post', 'string'));
        $time = JRequest::getVar('time', 0, 'post', 'int');
        $time = strtotime(date('Y-m-d H:i:s'));
        $intro_text = JRequest::getVar('intro', '', 'post', 'string', JREQUEST_ALLOWRAW);
        $sidebar = JRequest::getVar('sidebar', '', 'post', 'string', JREQUEST_ALLOWRAW);
        $articles = JRequest::getVar('article', 0, 'post', 'array');
        $articles_k2 = JRequest::getVar('k2article', 0, 'post', 'array');
        $jomsocialProfiles = JRequest::getVar('jsProfiles', false, 'post');
        $jsFields = JRequest::getVar('jsProfileFields', false, 'post');
        $jsdisc = JRequest::getVar('jsdisc', false, 'post');
        $aec = JRequest::getVar('aec', false, 'post');
        $ambra = JRequest::getVar('ambra', false, 'post');
        $subject = stripslashes($subject);
        $from_name = stripslashes($from_name);
        $twitter_name = stripslashes($twitter_name);
        $facebook_url = stripslashes($facebook_url);
        $myspace_name = stripslashes($myspace_name);
        // display table of contents?
        $toc_checkbox = JRequest::getVar('tableofcontents', 0, 'post', 'int');
        $toc_type = JRequest::getVar('tableofcontents_type', 0, 'post', 'int');
        // display popular articles?
        $popular_checkbox = JRequest::getVar('populararticles', 0, 'post', 'int');
        $popular_ex = JRequest::getVar('popExclude', false, 'post');
        $popular_in = JRequest::getVar('popInclude', false, 'post');
        // include K2 in populars?
        $populark2_checkbox = JRequest::getVar('populark2', 0, 'post', 'int');
        $populark2_ex = JRequest::getVar('popk2Exclude', false, 'post');
        $populark2_in = JRequest::getVar('popk2Include', false, 'post');
        // only K2 articles in populars?
        $populark2_only = JRequest::getVar('populark2_only', 0, 'post', 'int');
        // display VM products in sidebar?
        $vm_sb = JRequest::getVar('vm_sidebar', 0, 'post', 'int');
        if ($vm_sb && $vm_exists) {
            if (JRequest::getVar('vm_sb_products', 0, 'post', 'array')) {
                $vm_sb_products = JRequest::getVar('vm_sb_products', 0, 'post', 'array');
            } else {
                $vm_sb_products = false;
            }
            if ($vm_sb_products) {
                $vm_sb_productids = array();
                $vm_sb_productprices = array();
                for ($i = 0; $i < count($vm_sb_products); $i++) {
                    $vm_sb_products[$i] = explode(';', $vm_sb_products[$i]);
                    $vm_sb_productids[$i] = $vm_sb_products[$i][0];
                    $vm_sb_productprices[$i] = $vm_sb_products[$i][1];
                    $vm_sb_productcats[$i] = $vm_sb_products[$i][2];
                }
            }
            $vm_sb_order = JRequest::getVar('vm_sidebar_order', 0, 'post', 'string');
            $vm_sb_price = JRequest::getVar('vm_sidebar_price', 0, 'post', 'int');
            $vm_sb_cf = JRequest::getVar('vm_sidebar_curr_first', 0, 'post', 'int');
            $vm_sb_img = JRequest::getVar('vm_sidebar_img', 0, 'post', 'int');
            $vm_sb_link = JRequest::getVar('vm_sidebar_link', 0, 'post', 'int');
            $vm_short_desc = JRequest::getVar('vm_short_desc', 0, 'post', 'int');
            $vm_desc = JRequest::getVar('vm_desc', 0, 'post', 'int');
        }
        // 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 = $model->createFolder($folder_name);
        }
        // convert relative to absolute href paths
        $intro_text = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $abs_path, $intro_text);
        $sidebar = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $abs_path, $sidebar);
        // open the template file
        $filename = JPATH_ADMINISTRATOR . DS . "components/com_joomailermailchimpintegration/templates/" . $template_folder . "/template.html";
        $template = JFile::read($filename, false, filesize($filename));
        $regex = '!<#repeater#[^>]*>(.*)<#/repeater#>!is';
        preg_match($regex, $template, $repeater);
        $imagepath = '$1="' . JURI::base() . 'components/com_joomailermailchimpintegration/templates/' . $template_folder . '/$2$3';
        $repeater[0] = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $repeater[0]);
        // JomSocial Profiles
        $regex = '!<#jomsocialprofiles#[^>]*>(.*)<#/jomsocialprofiles#>!is';
        preg_match($regex, $template, $jsp);
        if (isset($jsp[0])) {
            $jsp = $jsp[0];
        } else {
            $jsp = '';
        }
        $regex = '!<#jomsocialprofilesrepeater#[^>]*>(.*)<#/jomsocialprofilesrepeater#>!is';
        preg_match($regex, $template, $jspr);
        if (isset($jspr[0])) {
            $jspr = $jspr[0];
        } else {
            $jspr = '';
        }
        $regex = '!<#jsfieldsrepeater#[^>]*>(.*)<#/jsfieldsrepeater#>!is';
        preg_match($regex, $template, $jsfr);
        if (isset($jsfr[0])) {
            $jsfr = $jsfr[0];
        } else {
            $jsfr = '';
        }
        // JomSocial Discussions
        $regex = '!<#jomsocialdiscussions#[^>]*>(.*)<#/jomsocialdiscussions#>!is';
        preg_match($regex, $template, $jsd);
        if (isset($jsd[0])) {
            $jsd = $jsd[0];
        } else {
            $jsd = '';
        }
        $regex = '!<#jomsocialdiscussionsrepeater#[^>]*>(.*)<#/jomsocialdiscussionsrepeater#>!is';
        preg_match($regex, $template, $jsdr);
        if (isset($jsdr[0])) {
            $jsdr = $jsdr[0];
        } else {
            $jsdr = '';
        }
        // AEC plans
        $regex = '!<#aec#[^>]*>(.*)<#/aec#>!is';
        preg_match($regex, $template, $aecph);
        if (isset($aecph[0])) {
            $aecph = $aecph[0];
        } else {
            $aecph = '';
        }
        $regex = '!<#aecrepeater#[^>]*>(.*)<#/aecrepeater#>!is';
        preg_match($regex, $template, $aecr);
        if (isset($aecr[0])) {
            $aecr = $aecr[0];
        } else {
            $aecr = '';
        }
        // Ambra subscriptions
        $regex = '!<#ambra#[^>]*>(.*)<#/ambra#>!is';
        preg_match($regex, $template, $ambraph);
        if (isset($ambraph[0])) {
            $ambraph = $ambraph[0];
        } else {
            $ambraph = '';
        }
        $regex = '!<#ambrarepeater#[^>]*>(.*)<#/ambrarepeater#>!is';
        preg_match($regex, $template, $ambrar);
        if (isset($ambrar[0])) {
            $ambrar = $ambrar[0];
        } else {
            $ambrar = '';
        }
        // table of contents
        $regex = '!<#tableofcontents#[^>]*>(.*)<#/tableofcontents#>!is';
        preg_match($regex, $template, $tableofcontents);
        $tableofcontents = $tableofcontents[0];
        $regex = '!<#title_repeater#[^>]*>(.*)<#/title_repeater#>!is';
        preg_match($regex, $template, $title_repeater);
        $title_repeater = $title_repeater[0];
        // popular articles
        $regex = '!<#populararticles#[^>]*>(.*)<#/populararticles#>!is';
        preg_match($regex, $template, $populararticles);
        $populararticles = $populararticles[0];
        $regex = '!<#popular_repeater#[^>]*>(.*)<#/popular_repeater#>!is';
        preg_match($regex, $template, $popular_repeater);
        $popular_repeater = $popular_repeater[0];
        // VM products
        $regex = '!<#vm_products#[^>]*>(.*)<#/vm_products#>!is';
        preg_match($regex, $template, $vm_products);
        $vm_products = $vm_products[0];
        $regex = '!<#vm_repeater#[^>]*>(.*)<#/vm_repeater#>!is';
        preg_match($regex, $template, $vm_repeater);
        $vm_repeater = $vm_repeater[0];
        // Twitter
        $regex = '!<#twitter#[^>]*>(.*)<#/twitter#>!is';
        preg_match($regex, $template, $twitter);
        if (isset($twitter[0])) {
            $twitter = $twitter[0];
        } else {
            $twitter = '';
        }
        // Facebook
        $regex = '!<#facebook#[^>]*>(.*)<#/facebook#>!is';
        preg_match($regex, $template, $facebook);
        if (isset($facebook[0])) {
            $facebook = $facebook[0];
        } else {
            $facebook = '';
        }
        // MySpace
        $regex = '!<#myspace#[^>]*>(.*)<#/myspace#>!is';
        preg_match($regex, $template, $myspace);
        if (isset($myspace[0])) {
            $myspace = $myspace[0];
        } else {
            $myspace = '';
        }
        // Facebook share
        $regex = '!<#facebook_share#[^>]*>(.*)<#/facebook_share#>!is';
        preg_match($regex, $template, $facebookShare);
        if (isset($facebookShare[0])) {
            $fbs = $facebookShare[0];
        } else {
            $fbs = '';
        }
        $content = '';
        $art_titles = array();
        // Joomla core articles
        if ($articles) {
            foreach ($articles as $id) {
                $full = JRequest::getVar('article_full_' . $id, 0, 'post', 'int');
                $readmore = JRequest::getVar('readmore_' . $id, 0, 'post', 'int');
                $query = 'SELECT * FROM #__content WHERE id= ' . $id;
                $db->setQuery($query);
                $article = $db->loadObjectList();
                foreach ($article as $art) {
                    $html_title = $html_content = '';
                    if ($toc_type) {
                        $art_titles[] = '<a href="' . JURI::root() . 'index.php?option=com_content&view=article&id=' . $id . '">' . $art->title . '</a>';
                    } else {
                        $art_titles[] = '<a href="#' . $art->title . $id . '">' . $art->title . '</a>';
                    }
                    if ($readmore) {
                        $html_title = '<a href="' . JURI::root() . 'index.php?option=com_content&view=article&id=' . $id . '">' . $art->title . '</a><a name="' . $art->title . $id . '"></a>';
                    } else {
                        $html_title = $art->title . '<a name="' . $art->title . $id . '"></a>';
                    }
                    $html_content = $art->introtext;
                    if ($full == 1) {
                        $html_content .= ' ' . $art->fulltext;
                    }
                    // Read more link
                    if ($readmore) {
                        $html_content .= '<p><a href="' . JURI::root() . 'index.php?option=com_content&view=article&id=' . $id . '">' . JText::_('JM_READ_MORE') . '</a></p>';
                    }
                    $template = str_ireplace('<#title#>', $html_title, $repeater[0]);
                    $template = str_ireplace('<#content#>', $html_content, $template);
                    $content .= $template;
                }
            }
        }
        // K2 articles
        if ($articles_k2 && $k2_exists) {
            foreach ($articles_k2 as $id) {
                $full = JRequest::getVar('k2article_full_' . $id, 0, 'post', 'int');
                $readmore = JRequest::getVar('k2readmore_' . $id, 0, 'post', 'int');
                $query = 'SELECT * FROM #__k2_items WHERE id= ' . $id;
                $db->setQuery($query);
                $article = $db->loadObjectList();
                foreach ($article as $art) {
                    $html_title = $html_content = '';
                    if ($toc_type) {
                        $art_titles[] = '<a href="' . JURI::root() . 'index.php?option=com_k2&view=item&id=' . $id . '">' . $art->title . '</a>';
                    } else {
                        $art_titles[] = '<a href="#' . $art->title . $id . '">' . $art->title . '</a>';
                    }
                    if ($readmore) {
                        $html_title = '<a href="' . JURI::root() . 'index.php?option=com_k2&view=item&id=' . $id . '">' . $art->title . '</a><a name="' . $art->title . $id . '"></a>';
                    } else {
                        $html_title = $art->title . '<a name="' . $art->title . $id . '"></a>';
                    }
                    $html_content = $art->introtext;
                    if ($full == 1) {
                        $html_content .= ' ' . $art->fulltext;
                    }
                    // Read more link
                    if ($readmore) {
                        $html_content .= '<p><a href="' . JURI::root() . 'index.php?option=com_k2&view=item&id=' . $id . '">' . JText::_('JM_READ_MORE') . '</a></p>';
                    }
                    $template = str_ireplace('<#title#>', $html_title, $repeater[0]);
                    $template = str_ireplace('<#content#>', $html_content, $template);
                    $content .= $template;
                }
            }
        }
        // JomSocial Profiles
        $jsProfiles = '';
        if ($jomsocialProfiles) {
            foreach ($jomsocialProfiles as $jsProfile) {
                $jsUser = CFactory::getUser($jsProfile);
                $profileLink = JURI::root() . CRoute::_('index.php?option=com_community&view=profile&userid=' . $jsProfile);
                $thumb = '<a href="' . $profileLink . '"><img src="' . $jsUser->getThumbAvatar() . '" alt="' . $jsUser->name . '" title="' . $jsUser->name . '" border="0" /></a>';
                $profiles = str_ireplace('<#jsAvatar#>', $thumb, $jspr);
                $profiles = str_ireplace('<#jsName#>', '<a href="' . $profileLink . '">' . $jsUser->name . '</a>', $profiles);
                $fieldValues = $model->getFieldValues($jsProfile, $jsFields);
                $fields = '';
                foreach ($fieldValues as $f) {
                    if ($f->value) {
                        if ($f->type == 'date') {
                            $f->value = substr($f->value, 0, -9);
                        }
                        $fieldsTmp = str_ireplace('<#jsFieldTitle#>', $f->name, $jsfr);
                        $fieldsTmp = str_ireplace('<#jsFieldValue#>', $f->value, $fieldsTmp);
                        $fields .= $fieldsTmp;
                    }
                }
                $profiles = preg_replace('!<#jsfieldsrepeater#[^>]*>(.*)<#/jsfieldsrepeater#>!is', $fields, $profiles);
                $profiles = str_ireplace(array('<#jsfieldsrepeater#>', '<#/jsfieldsrepeater#>'), '', $profiles);
                $jsProfiles .= $profiles;
            }
            $jsProfiles = str_ireplace(array('<#jomsocialprofilesrepeater#>', '<#/jomsocialprofilesrepeater#>'), '', $jsProfiles);
        }
        // JomSocial Discussions
        $jsDiscussions = '';
        if ($jsdisc) {
            $lang =& JFactory::getLanguage();
            $lang->load('com_community', JPATH_SITE);
            $langString = JText::_('CC ACTIVITIES NEW GROUP DISCUSSION');
            $discussions = $model->getJomsocialDiscussions($jsdisc);
            foreach ($discussions as $d) {
                if ($d->creator) {
                    $jsUser = CFactory::getUser($d->creator);
                    $profileLink = JURI::root() . CRoute::_('index.php?option=com_community&view=profile&userid=' . $d->creator);
                    $discLink = JURI::root() . CRoute::_('index.php?option=com_community&view=groups&task=viewdiscussion&groupid=' . $d->groupid . '&topicid=' . $d->id);
                    $groupLink = JURI::root() . CRoute::_('index.php?option=com_community&view=groups&task=viewgroup&groupid=' . $d->groupid);
                    $thumb = '<a href="' . $profileLink . '"><img src="' . $jsUser->getThumbAvatar() . '" alt="' . $jsUser->name . '" title="' . $jsUser->name . '" border="0" /></a>';
                    $discTmp = str_ireplace('{actor}', $jsUser->name, $langString);
                    $discTmp = str_ireplace('{topic_url}', $discLink, $discTmp);
                    $discTmp = str_ireplace('{topic}', $d->title, $discTmp);
                    $discTmp = str_ireplace('%1$s', $groupLink, $discTmp);
                    $discTmp = str_ireplace('%2$s', $d->name, $discTmp);
                    $discTmp .= ':<br />' . $d->message;
                    $discTmp = '<table valign="top">
				    <tr>
					<td valign="top">' . $thumb . '</td>
					<td valign="top" style="padding: 0 0 0 10px;">' . $discTmp . '</td>
				    </tr>
				</table>';
                    $discTmp = str_ireplace('<#jsDiscussionContent#>', $discTmp, $jsdr);
                    $jsDiscussions .= $discTmp;
                }
            }
            $jsDiscussions = str_ireplace(array('<#jomsocialdiscussionsrepeater#>', '<#/jomsocialdiscussionsrepeater#>'), '', $jsDiscussions);
        }
        // AEC plans
        $aecContent = '';
        if ($aec) {
            $aecConfig = $model->getAECconfig();
            $aecPlans = $model->getAECplans($aec);
            foreach ($aecPlans as $a) {
                $aecParams = unserialize(base64_decode($a->params));
                $link = JURI::root() . JRoute::_('index.php?option=com_acctexp&view=subscribe');
                $aecTmp = '<tr>
				<td valign="top"><a href="' . $link . '">' . $a->name . '</a></td>
				<td valign="top" style="padding: 0 0 0 10px;">' . $a->desc . '</td>
				<td valign="top" style="padding: 0 0 0 10px;">' . $aecParams['full_amount'] . ' ' . $aecConfig['standard_currency'] . '</td>
			    </tr>';
                $aecTmp = str_ireplace('<#aeccontent#>', $aecTmp, $aecr);
                $aecContent .= $aecTmp;
            }
            $aecContent = str_ireplace(array('<#aecrepeater#>', '<#/aecrepeater#>'), '', $aecContent);
        }
        // Ambra subscriptions
        $ambraContent = '';
        if ($ambra) {
            require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ambrasubs' . DS . 'helpers' . DS . '_base.php';
            require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_ambrasubs' . DS . 'helpers' . DS . 'config.php';
            $ambraConfig = AmbrasubsConfig::getInstance();
            $ambraPre = str_ireplace('$', '\\$', $ambraConfig->get('currency_preval', '$'));
            $ambraPost = $ambraConfig->get('currency_postval', '');
            $ambraPlans = $model->getAmbra($ambra);
            foreach ($ambraPlans as $a) {
                $link = JURI::root() . JRoute::_('index.php?option=com_ambrasubs&controller=subscriptions&task=new&id=' . $a->id);
                $img = '<img src="' . JURI::root() . $a->img . '" alt="' . $a->title . '" title="' . $a->title . '" border="0" />';
                $ambraTmp = '<tr>
				<td valign="top"><a href="' . $link . '">' . $img . '</a></td>
				<td valign="top"><a href="' . $link . '">' . $a->title . '</a><br />' . $a->description . '</td>
				<td valign="top" style="padding: 0 0 0 10px;" nowrap="nowrap">' . $ambraPre . '' . $a->value . '' . $ambraPost . '</td>
			    </tr>';
                $ambraTmp = str_ireplace('<#ambracontent#>', $ambraTmp, $ambrar);
                $ambraContent .= $ambraTmp;
            }
            $ambraContent = str_ireplace(array('<#ambrarepeater#>', '<#/ambrarepeater#>'), '', $ambraContent);
        }
        // remove tiny mce stuff like mce_src="..."
        $content = preg_replace('(mce_style=".*?")', '', $content);
        $content = preg_replace('(mce_src=".*?")', '', $content);
        $content = preg_replace('(mce_href=".*?")', '', $content);
        $content = preg_replace('(mce_bogus=".*?")', '', $content);
        // convert relative to absolute paths
        $abs_path = '$1="' . JURI::root() . '$2$3';
        $content = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#', $abs_path, $content);
        // create table of contents
        $toc = '';
        foreach ($art_titles as $art_title) {
            $toc .= str_ireplace('<#article_title#>', $art_title, $title_repeater);
        }
        $tableofcontents = preg_replace('!<#title_repeater#[^>]*>(.*)<#/title_repeater#>!is', $toc, $tableofcontents);
        $to_replace = array('<#tableofcontents#>', '<#/tableofcontents#>', '<#title_repeater#>', '<#/title_repeater#>');
        $tableofcontents = str_ireplace($to_replace, '', $tableofcontents);
        $where = '';
        $wEx = array();
        $wIn = array();
        $wCore = array();
        if ($popular_checkbox) {
            if (isset($popular_ex[0])) {
                foreach ($popular_ex as $p) {
                    $wEx[] = ' c.catid != ' . $p;
                }
                $wCore[] = count($wEx) ? ' AND (' . implode(' AND ', $wEx) . ' )' : '';
            }
            if (isset($popular_in[0])) {
                foreach ($popular_in as $p) {
                    $wIn[] = ' c.catid = ' . $p;
                }
                $wCore[] = count($wIn) ? ' AND (' . implode(' OR ', $wIn) . ' )' : '';
            }
            $where = implode('', $wCore);
        }
        $whereK2 = '';
        $wEx = array();
        $wIn = array();
        $wK2 = array();
        if ($populark2_checkbox) {
            if (isset($populark2_ex[0])) {
                foreach ($populark2_ex as $p) {
                    $wEx[] = ' k.catid != ' . $p;
                }
                $wK2[] = count($wEx) ? ' AND (' . implode(' AND ', $wEx) . ' )' : '';
            }
            if (isset($populark2_in[0])) {
                foreach ($populark2_in as $p) {
                    $wIn[] = ' k.catid = ' . $p;
                }
                $wK2[] = count($wIn) ? ' AND (' . implode(' OR ', $wIn) . ' )' : '';
            }
        }
        $whereK2 = implode('', $wK2);
        // create list of popular articles
        if ($popular_checkbox && !$populark2_checkbox) {
            $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 , 5';
        } else {
            if ($popular_checkbox && $populark2_checkbox && !$populark2_only) {
                $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 , 5 ';
            } else {
                if ($popular_checkbox && $populark2_checkbox && $populark2_only) {
                    $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 , 5 ';
                }
            }
        }
        $db->setQuery($query);
        $popular = $db->loadObjectList();
        $popularlist = '';
        $i = 0;
        foreach ($popular as $pop) {
            $i++;
            $core = false;
            if ($i > 5) {
                break;
            }
            $query = 'SELECT title FROM #__content WHERE title = "' . $pop->title . '"';
            $db->setQuery($query);
            $core = $db->loadResult();
            if ($core) {
                $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);
        $to_replace = array('<#populararticles#>', '<#/populararticles#>', '<#popular_repeater#>', '<#/popular_repeater#>');
        $popularlist = str_ireplace($to_replace, '', $popularlist);
        // insert vm products into sidebar
        $vm = '';
        if ($vm_sb && $vm_exists) {
            require_once JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'virtuemart.cfg.php';
            $where = '';
            for ($i = 0; $i < count($vm_sb_productids); $i++) {
                $where .= !$where ? ' AND ' : ' OR ';
                $where .= ' ( a.product_id = ' . $vm_sb_productids[$i] . ' ' . 'AND b.product_price = ' . $vm_sb_productprices[$i] . ' ' . 'AND c.category_id = ' . $vm_sb_productcats[$i] . ' ) ';
            }
            if ($vm_sb_order == 'price_desc') {
                $order = ' ORDER BY b.product_price DESC ';
            } else {
                if ($vm_sb_order == 'price_asc') {
                    $order = ' ORDER BY b.product_price ASC ';
                } else {
                    if ($vm_sb_order == 'name_desc') {
                        $order = ' ORDER BY a.product_name DESC ';
                    } else {
                        if ($vm_sb_order == 'name_asc') {
                            $order = ' ORDER BY a.product_name ASC ';
                        } else {
                            if ($vm_sb_order == 'cat_desc') {
                                $order = ' ORDER BY d.category_name DESC ';
                            } else {
                                if ($vm_sb_order == 'cat_asc') {
                                    $order = ' ORDER BY d.category_name ASC ';
                                } else {
                                    if ($vm_sb_order == 'random') {
                                        $order = ' ORDER BY RAND() ';
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $query = 'SELECT a.product_id,a.product_name,a.product_thumb_image, a.product_s_desc, a.product_desc,
			b.product_price,b.product_currency,
			c.category_id,
			d.category_name
		      FROM #__vm_product as a
		      INNER JOIN #__vm_product_price as b
		      ON a.product_id = b.product_id
		      INNER JOIN #__vm_product_category_xref as c
		      ON a.product_id = c.product_id
		      INNER JOIN #__vm_category as d
		      ON c.category_id = d.category_id
		      WHERE a.product_publish = "Y"
		      ' . $where . '
		      AND a.product_thumb_image != ""
		      ' . $order;
            $db->setQuery($query);
            $products = $db->loadObjectList();
            foreach ($products as $prod) {
                $product_content = '';
                if ($vm_sb_link) {
                    $product_content .= '<a href="' . JURI::root() . 'index.php?page=shop.product_details&flypage=' . FLYPAGE . '&product_id=' . $prod->product_id . '&category_id=' . $prod->category_id . '&option=com_virtuemart">';
                }
                $product_content .= $prod->product_name . '<br />';
                if ($vm_sb_price) {
                    if ($vm_sb_cf) {
                        $product_content .= $prod->product_currency . ' ' . number_format($prod->product_price, 2) . '<br />';
                    } else {
                        $product_content .= number_format($prod->product_price, 2) . ' ' . $prod->product_currency . '<br />';
                    }
                }
                if ($vm_sb_img) {
                    $product_content .= '<img src="' . JURI::root() . 'components/com_virtuemart/shop_image/product/' . $prod->product_thumb_image . '" border="0" />';
                }
                if ($vm_sb_link) {
                    $product_content .= '</a>';
                }
                if ($vm_short_desc) {
                    $product_content .= '<p>' . $prod->product_s_desc . '</p>';
                }
                if ($vm_desc) {
                    $product_content .= '<p>' . $prod->product_desc . '</p>';
                }
                $vm .= str_ireplace('<#vm_content#>', $product_content, $vm_repeater);
            }
        }
        $vm = preg_replace('!<#vm_repeater#[^>]*>(.*)<#/vm_repeater#>!is', $vm, $vm_products);
        $to_replace = array('<#vm_products#>', '<#/vm_products#>', '<#vm_repeater#>', '<#/vm_repeater#>');
        $vm = str_ireplace($to_replace, '', $vm);
        $imagepath = '$1="' . JURI::root() . 'administrator/components/com_joomailermailchimpintegration/templates/' . $template_folder . '/$2$3';
        // twitter
        $tw = str_ireplace('<#twitter-name#>', $twitter_name, $twitter);
        $to_replace = array('<#twitter#>', '<#/twitter#>');
        $tw = str_ireplace($to_replace, '', $tw);
        // convert relative to absolute paths
        $tw = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $tw);
        // facebook
        $fb = str_ireplace('<#facebook-url#>', $facebook_url, $facebook);
        $to_replace = array('<#facebook#>', '<#/facebook#>');
        $fb = str_ireplace($to_replace, '', $fb);
        // convert relative to absolute paths
        $fb = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $fb);
        // myspace
        $ms = str_ireplace('<#myspace-name#>', $myspace_name, $myspace);
        $to_replace = array('<#myspace#>', '<#/myspace#>');
        $ms = str_ireplace($to_replace, '', $ms);
        // convert relative to absolute paths
        $ms = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $ms);
        // facebook share
        $to_replace = array('<#facebook_share#>', '<#/facebook_share#>');
        $fbs = str_ireplace($to_replace, '', $fbs);
        // convert relative to absolute paths
        $fbs = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $fbs);
        $filename = JPATH_ADMINISTRATOR . DS . "components/com_joomailermailchimpintegration/templates/" . $template_folder . "/template.html";
        $template = JFile::read($filename, false, filesize($filename));
        // create absolute image paths
        $imagepath = ' src="' . JURI::base() . 'components/com_joomailermailchimpintegration/templates/' . $template_folder . '/' . '$2$3';
        $template = preg_replace('#(src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $imagepath, $template);
        $imagepath = " url('" . JURI::base() . "components/com_joomailermailchimpintegration/templates/" . $template_folder . "/";
        $template = preg_replace('#(\\s*)url?\\([\'"]?[../]*[\'"]?#i', $imagepath, $template);
        // modify paths of intro-text
        // remove tiny mce stuff like mce_src="..."
        $intro_text = preg_replace('(mce_style=".*?")', '', $intro_text);
        $intro_text = preg_replace('(mce_src=".*?")', '', $intro_text);
        $intro_text = preg_replace('(mce_href=".*?")', '', $intro_text);
        $intro_text = preg_replace('(mce_bogus=".*?")', '', $intro_text);
        $sidebar = preg_replace('(mce_style=".*?")', '', $sidebar);
        $sidebar = preg_replace('(mce_src=".*?")', '', $sidebar);
        $sidebar = preg_replace('(mce_href=".*?")', '', $sidebar);
        $sidebar = preg_replace('(mce_bogus=".*?")', '', $sidebar);
        // convert relative to absolute paths
        $abs_path = '$1="' . JURI::root() . '$2$3';
        $intro_text = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $abs_path, $intro_text);
        $sidebar = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $abs_path, $sidebar);
        // end paths intro-text
        // insert page title and intro-text
        $template = str_ireplace('<#subject#>', $subject, $template);
        $template = str_ireplace('<#intro_content#>', $intro_text, $template);
        $template = str_ireplace('<#sidebar#>', $sidebar, $template);
        // insert articles
        $content = str_ireplace('$', '\\$', $content);
        $template = preg_replace('!<#repeater#[^>]*>(.*)<#/repeater#>!s', $content, $template);
        // remove placeholders
        $template = str_ireplace('<#repeater#>', '', $template);
        $template = str_ireplace('<#/repeater#>', '', $template);
        // insert JomSocial Profiles
        if ($jsProfiles) {
            $jsProfiles = str_ireplace('$', '\\$', $jsProfiles);
            $template = preg_replace('!<#jomsocialprofilesrepeater#[^>]*>(.*)<#/jomsocialprofilesrepeater#>!is', $jsProfiles, $template);
            $template = str_ireplace(array('<#jomsocialprofiles#>', '<#/jomsocialprofiles#>'), '', $template);
        } else {
            $template = preg_replace('!<#jomsocialprofiles#[^>]*>(.*)<#/jomsocialprofiles#>!is', '', $template);
        }
        // insert JomSocial Discussions
        if ($jsDiscussions) {
            $jsDiscussions = str_ireplace('$', '\\$', $jsDiscussions);
            $template = preg_replace('!<#jomsocialdiscussionsrepeater#[^>]*>(.*)<#/jomsocialdiscussionsrepeater#>!is', $jsDiscussions, $template);
            $template = str_ireplace(array('<#jomsocialdiscussions#>', '<#/jomsocialdiscussions#>'), '', $template);
        } else {
            $template = preg_replace('!<#jomsocialdiscussions#[^>]*>(.*)<#/jomsocialdiscussions#>!is', '', $template);
        }
        // insert AEC plans
        if ($aecContent) {
            $aecContent = str_ireplace('$', '\\$', $aecContent);
            $template = preg_replace('!<#aecrepeater#[^>]*>(.*)<#/aecrepeater#>!is', $aecContent, $template);
            $template = str_ireplace(array('<#aec#>', '<#/aec#>'), '', $template);
        } else {
            $template = preg_replace('!<#aec#[^>]*>(.*)<#/aec#>!is', '', $template);
        }
        // insert Ambra subscriptions
        if ($ambraContent) {
            $ambraContent = str_ireplace('$', '\\$', $ambraContent);
            $template = preg_replace('!<#ambrarepeater#[^>]*>(.*)<#/ambrarepeater#>!is', $ambraContent, $template);
            $template = str_ireplace(array('<#ambra#>', '<#/ambra#>'), '', $template);
        } else {
            $template = preg_replace('!<#ambra#[^>]*>(.*)<#/ambra#>!is', '', $template);
        }
        // insert table of contents
        if ($toc_checkbox && ($articles || $articles_k2)) {
            $tableofcontents = str_ireplace('$', '\\$', $tableofcontents);
            $template = preg_replace('!<#tableofcontents#[^>]*>(.*?)<#/tableofcontents#>!is', $tableofcontents, $template);
        } else {
            $template = preg_replace('!<#tableofcontents#[^>]*>(.*?)<#/tableofcontents#>!is', '', $template);
        }
        //insert popular articles
        if ($popular_checkbox) {
            $popularlist = str_ireplace('$', '\\$', $popularlist);
            $template = preg_replace('!<#populararticles#[^>]*>(.*?)<#/populararticles#>!is', $popularlist, $template);
        } else {
            $template = preg_replace('!<#populararticles#[^>]*>(.*?)<#/populararticles#>!is', '', $template);
        }
        //insert vm products
        if ($vm_sb) {
            $vm = str_ireplace('$', '\\$', $vm);
            $template = preg_replace('!<#vm_products#[^>]*>(.*?)<#/vm_products#>!is', $vm, $template);
        } else {
            $template = preg_replace('!<#vm_products#[^>]*>(.*?)<#/vm_products#>!is', '', $template);
        }
        //insert twitter link
        $tw = $twitter_name ? $tw : '';
        $template = preg_replace('!<#twitter#[^>]*>(.*?)<#/twitter#>!is', $tw, $template);
        //insert facebook link
        $fb = $facebook_url ? $fb : '';
        $template = preg_replace('!<#facebook#[^>]*>(.*?)<#/facebook#>!is', $fb, $template);
        //insert myspace link
        $ms = $myspace_name ? $ms : '';
        $template = preg_replace('!<#myspace#[^>]*>(.*?)<#/myspace#>!is', $ms, $template);
        //insert facebook share link
        if ($facebookShareIt) {
            $template = preg_replace('!<#facebook_share#[^>]*>(.*?)<#/facebook_share#>!is', $fbs, $template);
            $metaData = "<meta name=\"title\" content=\"" . $campaign_name . "\" />\n" . "<meta name=\"description\" content=\"" . $facebookShareDesc . "\" />\n" . "<link rel=\"image_src\" href=\"" . $fbImage . "\" />\n";
            $metaData = preg_replace('#(href|src)="([^:"]*)("|(?:(?:%20|\\s|[.]|\\+)[^"]*"))#i', $abs_path, $metaData);
            $template = str_ireplace('</head>', $metaData . '</head>', $template);
        } else {
            $template = preg_replace('!<#facebook_share#[^>]*>(.*?)<#/facebook_share#>!is', '', $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";
        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 . '/' . $campaign_name_ent . ".html";
        $handle = @JFile::write($filename, $template);
        if (!$handle) {
            $error = true;
        } else {
            $html_file = JURI::base() . substr($archiveDir, 1) . "/" . $campaign_name_ent . ".html";
        }
        // create txt version
        if (!$error) {
            $txt_content = $template;
            $txt_content = preg_replace("!<head[^>]*>(.*?)</head>!is", '', $txt_content);
            $txt_content = preg_replace("!<style[^>]*>(.*?)</style>!is", '', $txt_content);
            $txt_content = preg_replace("!<forwardtoafriend[^>]*>(.*?)</forwardtoafriend>!is", 'Forward to a friend: *|FORWARD|*', $txt_content);
            $txt_content = preg_replace("!<preferences[^>]*>(.*?)</preferences>!is", 'Preference center: *|UPDATE_PROFILE|*', $txt_content);
            $txt_content = preg_replace("!<unsubscribe[^>]*>(.*?)</unsubscribe>!is", '*|UNSUB|*', $txt_content);
            $txt_content = preg_replace("!<webversion[^>]*>(.*?)</webversion>!is", '*|ARCHIVE|*', $txt_content);
            $txt_content = strip_tags($txt_content);
            $txt_content = htmlspecialchars($txt_content);
            $txt_content = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n\n", $txt_content);
            $txt_content = $campaign_name_ent . "\n" . $txt_content;
            $filename = JPATH_SITE . $archiveDir . '/' . $campaign_name_ent . ".txt";
            $handle = @JFile::write($filename, $txt_content);
            $txt_file = JURI::base() . substr($archiveDir, 1) . "/" . $campaign_name_ent . ".txt";
        }
        // set the redirection link and message
        if ($error) {
            $msg = JText::sprintf('JM_CAMPAIGN_CREATION_FAILED', $archiveDir);
            $msgType = 'error';
            $link = 'index.php?option=com_joomailermailchimpintegration&view=create';
            if ($creation_date) {
                JRequest::setVar('cid', $creation_date);
            }
            if ($campaign_name) {
                JRequest::setVar('cn', $campaign_name);
            }
            if ($subject) {
                JRequest::setVar('sj', $subject);
            }
            if ($from_name) {
                JRequest::setVar('fn', $from_name);
            }
            if ($from_email) {
                JRequest::setVar('fe', $from_email);
            }
            if ($reply_email) {
                JRequest::setVar('re', $reply_email);
            }
            if ($confirmation_email) {
                JRequest::setVar('ce', $confirmation_email);
            }
            if ($template_folder) {
                JRequest::setVar('tpl', $template_folder);
            }
            if ($articles) {
                JRequest::setVar('arts', implode(';', $articles));
            }
            if ($articles_k2) {
                JRequest::setVar('artsk2', implode(';', $articles_k2));
            }
            if ($toc_checkbox) {
                JRequest::setVar('toc', $toc_checkbox);
            }
            if ($toc_type) {
                JRequest::setVar('toct', $toc_type);
            }
            if ($popular_checkbox) {
                JRequest::setVar('pop', $popular_checkbox);
            }
            if ($popular_in) {
                JRequest::setVar('pin', implode(';', $popular_in));
            }
            if ($popular_ex) {
                JRequest::setVar('pex', implode(';', $popular_ex));
            }
            if ($populark2_checkbox) {
                JRequest::setVar('pk2', $populark2_checkbox);
            }
            if ($populark2_in) {
                JRequest::setVar('pk2in', implode(';', $populark2_in));
            }
            if ($populark2_ex) {
                JRequest::setVar('pk2ex', implode(';', $populark2_ex));
            }
            if ($populark2_only) {
                JRequest::setVar('pk2o', $populark2_only);
            }
            if (isset($jomsocialProfiles)) {
                if (is_array($jomsocialProfiles)) {
                    JRequest::setVar('jsp', implode(';', $jomsocialProfiles));
                }
                if (is_array($jsFields)) {
                    JRequest::setVar('jsf', implode(';', $jsFields));
                }
                if (is_array($jsdisc)) {
                    JRequest::setVar('jsd', implode(';', $jsdisc));
                }
            }
            if (is_array($aec)) {
                JRequest::setVar('aec', implode(';', $aec));
            }
            if (is_array($ambra)) {
                JRequest::setVar('amb', implode(';', $ambra));
            }
            if ($vm_sb == 1) {
                JRequest::setVar('vmsb', $vm_sb);
                JRequest::setVar('vmid', implode(';', $vm_sb_productids));
                JRequest::setVar('vmpr', implode(';', $vm_sb_productprices));
                JRequest::setVar('vmct', implode(';', $vm_sb_productcats));
                JRequest::setVar('vmor', $vm_sb_order);
                JRequest::setVar('vmsp', $vm_sb_price);
                JRequest::setVar('vmcf', $vm_sb_cf);
                JRequest::setVar('vmimg', $vm_sb_img);
                JRequest::setVar('vmlnk', $vm_sb_link);
                JRequest::setVar('vmsdesc', $vm_short_desc);
                JRequest::setVar('vmdesc', $vm_desc);
            }
            if ($twitter_name) {
                JRequest::setVar('tw', $twitter_name);
            }
            if ($facebook_url) {
                JRequest::setVar('fb', urlencode(htmlentities(urlencode($facebook_url))));
            }
            if ($myspace_name) {
                JRequest::setVar('ms', $myspace_name);
            }
            if ($intro_text) {
                JRequest::setVar('intro', urlencode(htmlentities(urlencode($intro_text))));
            }
            if ($sidebar) {
                JRequest::setVar('sidebar', urlencode(htmlentities(urlencode($sidebar))));
            }
            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('coreOrder', JRequest::getVar('coreOrder', 0, 'post', 'string'));
            JRequest::setVar('k2Order', JRequest::getVar('k2Order', '', 'post', 'string'));
            JRequest::setVar('sec_filter', JRequest::getVar('sec_filter', 0, 'post', 'string'));
            JRequest::setVar('cat_filter', JRequest::getVar('cat_filter', 0, 'post', 'string'));
            JRequest::setVar('k2cat_filter', JRequest::getVar('k2cat_filter', 0, 'post', 'string'));
            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, $msg);
            parent::display();
        } else {
            $subject = $db->getEscaped($subject);
            $from_name = $db->getEscaped($from_name);
            $twitter_name = $db->getEscaped($twitter_name);
            $facebook_url = $db->getEscaped($facebook_url);
            $myspace_name = $db->getEscaped($myspace_name);
            $mainframe =& JFactory::getApplication();
            $postdata = array();
            $postdata['cn'] = $campaign_name;
            $postdata['sj'] = stripslashes($subject);
            $postdata['fn'] = stripslashes($from_name);
            $postdata['fe'] = $from_email;
            $postdata['re'] = $reply_email;
            $postdata['ce'] = $confirmation_email;
            $postdata['tpl'] = $template_folder;
            $postdata['intro'] = urlencode($intro_text);
            $postdata['sidebar'] = urlencode($sidebar);
            $postdata['arts'] = implode(';', $articles);
            $postdata['artsk2'] = implode(';', $articles_k2);
            $postdata['sec_filter'] = $mainframe->getUserStateFromRequest('sec_filter', 'sec_filter', 0, 'int');
            $postdata['cat_filter'] = $mainframe->getUserStateFromRequest('cat_filter', 'cat_filter', 0, 'int');
            $postdata['k2cat_filter'] = $mainframe->getUserStateFromRequest('k2cat_filter', 'k2cat_filter', 0, 'int');
            $postdata['coreOrder'] = JRequest::getVar('coreOrder', 0, 'post', 'string');
            $postdata['k2Order'] = JRequest::getVar('k2Order', 0, 'post', 'string');
            if (isset($jomsocialProfiles)) {
                if (is_array($jomsocialProfiles)) {
                    JRequest::setVar('jsp', implode(';', $jomsocialProfiles));
                }
                if (is_array($jsFields)) {
                    JRequest::setVar('jsf', implode(';', $jsFields));
                }
                if (is_array($jsdisc)) {
                    JRequest::setVar('jsd', implode(';', $jsdisc));
                }
            }
            if (isset($jomsocialProfiles)) {
                if (is_array($jomsocialProfiles)) {
                    $postdata['jsp'] = implode(';', $jomsocialProfiles);
                }
                if (is_array($jsFields)) {
                    $postdata['jsf'] = implode(';', $jsFields);
                }
                if (is_array($jsdisc)) {
                    $postdata['jsd'] = implode(';', $jsdisc);
                }
            }
            //	$postdata['jsdiscOrder'] = JRequest::getVar('jsdiscOrder', false, 'post');
            $aec = JRequest::getVar('aec', false, 'post');
            if ($aec) {
                $postdata['aec'] = implode(';', $aec);
            }
            //	$postdata['aecOrder'] = JRequest::getVar('aecOrder', false, 'post');
            $ambra = JRequest::getVar('ambra', false, 'post');
            if ($ambra) {
                $postdata['amb'] = implode(';', $ambra);
            }
            //	$postdata['ambraOrder'] = JRequest::getVar('ambraOrder', false, 'post');
            $postdata['toc'] = $toc_checkbox;
            $postdata['toct'] = $toc_type;
            $postdata['pop'] = $popular_checkbox;
            if ($popular_in) {
                $postdata['pin'] = implode(';', $popular_in);
            }
            if ($popular_ex) {
                $postdata['pex'] = implode(';', $popular_ex);
            }
            $postdata['pk2'] = $populark2_checkbox;
            if ($populark2_in) {
                $postdata['pk2in'] = implode(';', $populark2_in);
            }
            if ($populark2_ex) {
                $postdata['pk2ex'] = implode(';', $populark2_ex);
            }
            $postdata['pk2o'] = $populark2_only;
            if ($vm_sb == 1) {
                $postdata['vmsb'] = $vm_sb;
                $postdata['vmid'] = implode(';', $vm_sb_productids);
                $postdata['vmpr'] = implode(';', $vm_sb_productprices);
                $postdata['vmct'] = implode(';', $vm_sb_productcats);
                $postdata['vmor'] = $vm_sb_order;
                $postdata['vmsp'] = $vm_sb_price;
                $postdata['vmcf'] = $vm_sb_cf;
                $postdata['vmimg'] = $vm_sb_img;
                $postdata['vmlnk'] = $vm_sb_link;
                $postdata['vmsdesc'] = $vm_short_desc;
                $postdata['vmdesc'] = $vm_desc;
            }
            $postdata['tw'] = stripslashes($twitter_name);
            $postdata['fb'] = urlencode(htmlentities(urlencode(stripslashes($facebook_url))));
            $postdata['ms'] = stripslashes($myspace_name);
            $postdata['gaS'] = urlencode(htmlentities(urlencode($gaSource)));
            $postdata['gaM'] = urlencode(htmlentities(urlencode($gaMedium)));
            $postdata['gaN'] = urlencode(htmlentities(urlencode($gaName)));
            $postdata['gaE'] = urlencode(htmlentities(urlencode($gaExcluded)));
            $postdataJson = $db->getEscaped(json_encode($postdata));
            // store campaign details locally
            if ($creation_date && $action != 'copy') {
                $query = "UPDATE #__joomailermailchimpintegration_campaigns " . "SET `subject`='" . $subject . "', `from_name`='" . $from_name . "', `from_email`='" . $from_email . "', `reply`='" . $reply_email . "', `confirmation`='" . $confirmation_email . "', `creation_date`='" . $time . "', `cdata`='" . $postdataJson . "', `folder_id`='" . $folder_id . "'" . "WHERE `creation_date` = '" . $creation_date . "'";
            } else {
                $query = "INSERT INTO #__joomailermailchimpintegration_campaigns " . "(name, subject, from_name, from_email, reply, confirmation, creation_date, cdata, folder_id) " . "VALUES ('" . $campaign_name . "', '" . $subject . "', '" . $from_name . "', '" . $from_email . "', '" . $reply_email . "', '" . $confirmation_email . "', '" . $time . "', '" . $postdataJson . "', " . $folder_id . " )";
            }
            $db->setQuery($query);
            $db->query();
            if ($db->getErrorMsg()) {
                $msg = $db->getErrorMsg();
                jimport('joomla.error.error');
                JError::raiseWarning(100, $msg);
            } else {
                $msg = sprintf(JText::_('JM_DRAFT_SAVED'), $campaign_name);
                $mainframe->enqueueMessage($msg);
            }
            JRequest::setVar('view', 'send');
            JRequest::setVar('layout', 'default');
            JRequest::setVar('campaign', $time);
            JRequest::setVar('hidemainmenu', 0);
            parent::display();
            //   $link = 'index.php?option=com_joomailermailchimpintegration&view=send&campaign='.$time;
            //   $this->setRedirect($link, $msg, $msgType);
        }
    }
 /**
  * constructor (registers additional tasks to methods)
  * @return void
  */
 function __construct()
 {
     parent::__construct();
 }
 function display()
 {
     parent::display();
 }
 function copy()
 {
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('cid', '', 'post', 'array');
     $query = "SELECT cdata FROM #__joomailermailchimpintegration_campaigns WHERE `cid` = '" . $cid[0] . "'";
     $db->setQuery($query);
     $cdata = json_decode($db->loadResult());
     JRequest::setVar('cid', $cid[0]);
     foreach ($cdata as $k => $v) {
         JRequest::setVar($k, $v);
     }
     JRequest::setVar('view', 'create');
     JRequest::setVar('layout', 'default');
     JRequest::setVar('action', 'copy');
     JRequest::setVar('hidemainmenu', 0);
     parent::display();
 }
Esempio n. 11
0
 function edit()
 {
     $db =& JFactory::getDBO();
     $cid = JRequest::getVar('campaign', '', 'post', 'string');
     $query = "SELECT cdata, folder_id FROM #__joomailermailchimpintegration_campaigns WHERE `creation_date` = '" . $cid . "'";
     $db->setQuery($query);
     $result = $db->loadAssocList();
     $cdata = json_decode($result[0]['cdata']);
     JRequest::setVar('cid', $cid);
     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();
 }