secret
Last active

Updated to WYSIJA Version 2.4, edits wysija-newsletters/controllers/front/email.php to allow only logged in users to see HTML version of newsletter.

  • Download Gist
email.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
<?php
defined('WYSIJA') or die('Restricted access');
 
include_once( ABSPATH . "wp-includes/pluggable.php");
global $current_user;
 
class WYSIJA_control_front_email extends WYSIJA_control_front{
var $model='email';
var $view='email';
 
function WYSIJA_control_front_email(){
parent::WYSIJA_control_front();
}
 
function view(){
 
if( is_user_logged_in() ) {
 
$data=array();
 
header('Content-type:text/html; charset=utf-8');
 
// Get email model as object.
$emailM =& WYSIJA::get('email','model');
$emailM->getFormat = OBJECT;
// Get config model
$configM =& WYSIJA::get('config','model');
 
// Helpers
$emailH =& WYSIJA::get('email','helper');
$mailerH =& WYSIJA::get('mailer','helper');
 
// Get current email object.
$current_email = $emailM->getOne((int)$_REQUEST['email_id']);
 
// Get current user object if possible
$current_user = null;
if(isset($_REQUEST['user_id'])){
// Get User Model
$userM = &WYSIJA::get('user','model');
$userM->getFormat = OBJECT;
$current_user = $userM->getOne((int)$_REQUEST['user_id']);
}
 
// Parse and replace user tags.
$mailerH->parseUserTags($current_email);
$mailerH->parseSubjectUserTags($current_email);
$mailerH->replaceusertags($current_email, $current_user);
 
// Parse and replace old shortcodes.
// $emailObject->subject = str_replace(
// array('[total]','[number]','[post_title]'),
// array($itemCount, $totalCount, $firstSubject),
// $emailChild['subject']);
 
// Set Body
$email_render = $current_email->body;
 
// Parse old shortcodes that we are parsing in the queue.
$find = array(
'[unsubscribe_linklabel]',
'[post_title]',
'[total]',
'[number]'
);
$replace = array(
$configM->getValue('unsubscribe_linkname'),
$current_email->params['autonl']['articles']['first_subject'],
$current_email->params['autonl']['articles']['total'],
$current_email->params['autonl']['articles']['ids']
);
$email_render = str_replace($find, $replace, $email_render);
 
// Strip unsubscribe links.
$email_render = $emailH->stripPersonalLinks($email_render);
 
do_action( 'wysija_preview', array(&$this));
 
echo $email_render;
 
exit;
 
}
 
else {
//echo "<p>This content available only to authorized users.</p>";
global $wp_query;
header("HTTP/1.0 404 Not Found - Archive Empty");
$wp_query->set_404();
require get_stylesheet_directory().'/404.php';
exit;
}
 
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.