예제 #1
0
 public static function replaceTags($content, $subscriber, $oneQueue, $html, $tags = null, $showSign = true)
 {
     $mailingId = $oneQueue->id;
     $Itemid = $GLOBALS[JNEWS . 'itemidAca'];
     $listId = '0';
     //can be empty
     $subscriptionslink = 'option=' . JNEWS_OPTION . '&Itemid=' . $Itemid . '&act=change&subscriber=' . $subscriber->id . '&cle=' . md5($subscriber->email);
     $unsubscribelink = 'option=' . JNEWS_OPTION . '&Itemid=' . $Itemid . '&act=unsubscribe&subscriber=' . $subscriber->id . '&mailingid=' . $mailingId . '&cle=' . md5($subscriber->email);
     $subscriptiontext = '';
     $subscriptionslink = jNews_Tools::completeLink($subscriptionslink, false, $GLOBALS[JNEWS . 'use_sef']);
     $unsubscribelink = jNews_Tools::completeLink($unsubscribelink, false, $GLOBALS[JNEWS . 'use_sef']);
     if ($html) {
         $subscriptionslink = '<a href="' . $subscriptionslink . '" target="_blank"><span class="aca_subscribe">' . _JNEWS_CHANGE_EMAIL_SUBSCRIPTION . '</span></a>';
         $unsubscribelink = '<a href="' . $unsubscribelink . '" target="_blank"><span class="aca_unsubscribe">' . _JNEWS_SAFEUNSUBSCRIBE . '</span></a>';
         $subscriptionstext = '<p>' . $subscriptionslink . '<br />' . $unsubscribelink . '</p>';
     } else {
         $subscriptionslink = _JNEWS_CHANGE_EMAIL_SUBSCRIPTION . ' ( ' . $subscriptionslink . ' )';
         $unsubscribelink = _JNEWS_SAFEUNSUBSCRIBE . ' ( ' . $unsubscribelink . ' )';
         $subscriptionstext = "\r\n" . $subscriptionslink . "\r\n" . $unsubscribelink;
     }
     $subscriptionstext = '';
     if ($showSign && $GLOBALS[JNEWS . 'show_signature']) {
         if ($html) {
             $signatureText = '<a href="http://www.joobi.co" target="_blank">';
             $signatureText .= '<br /><center><div style="width: 99%; color:#000; font-size: 0.8em; text-align: center; ">Powered by Joobi</div></center>';
             $signatureText .= '</a>';
         } else {
             $signatureText = '<br />Powered by Joobi ( http://www.joobi.co )';
         }
         $subscriptionstext .= "\r\n\r\n" . $signatureText;
     }
     $confirmlink = 'option=' . JNEWS_OPTION . '&act=confirm&listid=' . $listId . '&cle=' . md5($subscriber->email) . '&subscriber=' . $subscriber->id . '&Itemid=' . $Itemid;
     $confirmlink = jNews_Tools::completeLink($confirmlink, false, $GLOBALS[JNEWS . 'use_sef']);
     //for rpelacement of the {tag:title}
     $mailSubject = '';
     //		$mailingid = empty($oneQueue->mailing_id) OR !isset($oneQueue->mailing_id) ? jNews_Queue::getQueueMailingId($oneQueue->id) : $oneQueue->mailing_id;
     $mailSubject = jNews_Mailing::getMailingsSubject($oneQueue->id);
     if ($html) {
         $confirmlink = '<a href="' . $confirmlink . '" target="_blank">' . _JNEWS_CONFIRM_LINK . '</a>';
     } else {
         $confirmlink = _JNEWS_CONFIRM_LINK . "\n" . $confirmlink;
     }
     $tname = explode(" ", $subscriber->name);
     $firstname = $tname[0];
     $username = empty($subscriber->username) ? $firstname : $subscriber->username;
     $archiveLink = 'option=' . JNEWS_OPTION . '&act=mailing&task=view&mailingid=' . $mailingId . '&Itemid=' . $Itemid;
     $archiveLink = jNews_Tools::completeLink($archiveLink, false, $GLOBALS[JNEWS . 'use_sef']);
     $archiveAll = '<a href="' . $archiveLink . '">' . _JNEWS_VIEWARCHIVE . '</a>';
     //		$replaceWhat = array('[CONFIRM]','[NAME]','[FIRSTNAME]','[EMAIL]','[DATE]','[USERNAME]','[LINK]','[ARCHIVE]', '[SUBSCRIPTIONS]', '[UNSUBSCRIBE]');
     //		$replaceWhat = array('{tag:confirm}','{tag:name}','{tag:firstname}','{tag:email}','{tag:date}','{tag:username}','{tag:link}','{tag:archive}', '{tag:subscriptions}', '{tag:unsubscribe}', '{tag:title}');
     $replaceTagsA = array();
     $replaceTagsA['{tag:confirm}'] = $confirmlink;
     $replaceTagsA['{tag:name}'] = $subscriber->name;
     $replaceTagsA['{tag:firstname}'] = $firstname;
     $replaceTagsA['{tag:email}'] = $subscriber->email;
     if (version_compare(JVERSION, '3.0.0', '<')) {
         $replaceTagsA['{tag:date}'] = JHTML::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'));
         // , JNEWS_TIME_OFFSET
     } else {
         $replaceTagsA['{tag:date}'] = JHtml::_('date', jnews::getNow(), JText::_('DATE_FORMAT_LC1'));
         // , JNEWS_TIME_OFFSET
     }
     $replaceTagsA['{tag:username}'] = $username;
     $replaceTagsA['{tag:link}'] = $archiveLink;
     $replaceTagsA['{tag:archive}'] = $archiveAll;
     $mainframe = JFactory::getApplication();
     if (!$mainframe->isAdmin() && JRequest::getVar('act', '', '', 'WORD') == 'mailing' && JRequest::getVar('task') == 'view') {
         $replaceTagsA['{tag:subscriptions}'] = '';
         $replaceTagsA['{tag:unsubscribe}'] = '';
     } else {
         $replaceTagsA['{tag:subscriptions}'] = $subscriptionslink;
         $replaceTagsA['{tag:unsubscribe}'] = $unsubscribelink;
     }
     $replaceTagsA['{tag:title}'] = $mailSubject;
     if ($GLOBALS[JNEWS . 'level'] > 2) {
         //check if the version of jnews is pro
         $replaceTagsA['{tag:profile nb=1}'] = empty($subscriber->column1) ? '' : $subscriber->column1;
         $replaceTagsA['{tag:profile nb=2}'] = empty($subscriber->column2) ? '' : $subscriber->column2;
         $replaceTagsA['{tag:profile nb=3}'] = empty($subscriber->column3) ? '' : $subscriber->column3;
         $replaceTagsA['{tag:profile nb=4}'] = empty($subscriber->column4) ? '' : $subscriber->column4;
         $replaceTagsA['{tag:profile nb=5}'] = empty($subscriber->column5) ? '' : $subscriber->column5;
     }
     $replaceTagsKeysA = array_keys($replaceTagsA);
     $content = str_replace($replaceTagsKeysA, $replaceTagsA, $content);
     if (class_exists('jNews_Auto')) {
         jNews_Auto::tags($content, $tags);
     }
     $content = stristr($content, 'Powered by Joobi') !== false ? $content : $content . $subscriptionstext;
     if (class_exists('jNews_Tags')) {
         jNews_Tags::replace($content, $tags);
     }
     $mainframe = JFactory::getApplication();
     JPluginHelper::importPlugin('jnews');
     $plugin = JPluginHelper::getPlugin('jnews', 'forwardtofriend');
     if (!empty($plugin)) {
         jimport('joomla.html.parameter');
         $fwdObj = new stdClass();
         $fwdObj->subscriber = $subscriber;
         $fwdObj->mailingid = $mailingId;
         $fwdObj->listid = $listId;
         $bot_results = $mainframe->triggerEvent('jnewsbot_fwdtofriendTransform', array(&$content, $fwdObj));
     }
     if (!defined('JOOBI_SECURE')) {
         define('JOOBI_SECURE', true);
     }
     //check if we have Joobi install if so check for tags
     $joobiEntryPoint = '';
     if (defined('JPATH_ROOT')) {
         $path = JPATH_ROOT;
     } elseif (isset($mosConfig_absolute_path)) {
         $path = $mosConfig_absolute_path;
     }
     $status = @(include_once $path . DIRECTORY_SEPARATOR . 'joobi' . DIRECTORY_SEPARATOR . 'entry.php');
     if ($status) {
         //process joobi tag
         $tagProcessC = WClass::get('output.process', null, 'class', false);
         if (!empty($tagProcessC)) {
             $tagProcessC->replaceTags($content);
         }
     }
     if (!empty($mailingId) and $GLOBALS[JNEWS . 'enable_statistics'] == 1) {
         if ($GLOBALS[JNEWS . 'statistics_per_subscriber'] == 1) {
             if ($html) {
                 $content .= '<img src="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/index.php?option=' . JNEWS_OPTION . '&Itemid=' . $Itemid . '&act=log' . '&mailingid=' . $mailingId . '&subscriber=' . $subscriber->id . '" border="0" width="1" height="1" />';
             }
         } else {
             if ($html) {
                 $content .= '<img src="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/index.php?option=' . JNEWS_OPTION . '&Itemid=' . $Itemid . '&act=log' . '&mailingid=' . $mailingId . '" border="0" width="1" height="1" />';
             }
         }
     }
     // replace for images
     //  put the good mailto tag back (replaced before the content mambot)
     $replaceTag = array('href="mailto:', '@', 'href="#');
     $replaceBy = array('9aca7aca5', '9aca4aca1', '9aca12aca3');
     $content = str_replace($replaceTag, $replaceBy, $content);
     $content = preg_replace('#src[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'src="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/', $content);
     $content = preg_replace('#href[ ]*=[ ]*\\"(?!https?://)(?:\\.\\./|\\./|/)?#', 'href="' . JNEWS_JPATH_LIVE_NO_HTTPS . '/', $content);
     $content = str_replace($replaceBy, $replaceTag, $content);
     $content = preg_replace('#\\.(jpg|gif|jpeg|png)(?:(?!").)?"#', '.\\1"', $content);
     if (!$html) {
         $content = str_replace('&amp;', '&', $content);
     }
     return $content;
 }