* or write to the Free Software Foundation, Inc., 51 Franklin St,
* Fifth Floor, Boston, MA 02110-1301 USA
**/
// no direct access
defined( 'ABSPATH' ) or die('Restricted Access');
if ( isset($_POST['step']) ) {
$step = $_POST['step'];
} else if ( isset($_GET['step']) ) {
$step = $_GET['step'];
} else {
$step = 1;
add_action('admin_enqueue_scripts', 'my_admin_scripts');
function my_admin_scripts() {
if (isset($_GET['page']) && $_GET['page'] == 'my_plugin_page') {
wp_enqueue_media();
//wp_register_script('my-admin-js', WP_PLUGIN_URL.'/my-plugin/my-admin.js', array('jquery'));
//wp_enqueue_script('my-admin-js');
}
}
wp_enqueue_media();
if (function_exists('wp_tiny_mce')) wp_tiny_mce();
/*wp_enqueue_script( 'common' );
wp_enqueue_script( 'jquery-color' );
wp_print_scripts('editor');
if (function_exists('add_thickbox')) add_thickbox();
wp_print_scripts('media-upload');
wp_enqueue_script('media-upload');
wp_enqueue_script('utils');
wp_admin_css();
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
*/
}
echo '';
echo '';
echo '';
require_once( WP_PLUGIN_DIR . DS . 'chimpexpress' . DS . 'class-MCAPI.php' );
$MCAPI = new chimpexpressMCAPI;
//require_once( WP_PLUGIN_DIR . DS . 'chimpexpress' . DS . 'class-editor.php' );
?>
ChimpExpress
method != 'direct') {
$chimpexpress = new chimpexpress;
$ftpstream = @ftp_connect( $chimpexpress->_settings['ftpHost'] );
$login = @ftp_login($ftpstream, $chimpexpress->_settings['ftpUser'], $chimpexpress->_settings['ftpPasswd']);
$ftproot = @ftp_chdir($ftpstream, $chimpexpress->_settings['ftpPath'] );
$adminDir = @ftp_chdir($ftpstream, 'wp-admin' );
if ($wp_filesystem->method != 'direct' &&
(!$chimpexpress->_settings['ftpHost'] || !$chimpexpress->_settings['ftpUser']
|| !$chimpexpress->_settings['ftpPasswd'] || !$ftpstream || !$login || !$ftproot || !$adminDir)) {
?>
($_POST['sections']+1)) {
stepSubmit();
} else {
stepContent($step);
}
function step1() {
global $wp_filesystem;
$MCAPI = new chimpexpressMCAPI;
$cacheDir = 'wp-content' .DS. 'plugins' .DS. 'chimpexpress' .DS. 'cache';
if ($wp_filesystem->method == 'direct') {
$useFTP = false;
$handler = $wp_filesystem;
if(!is_dir(ABSPATH . $cacheDir)) {
$wp_filesystem->mkdir( ABSPATH . $cacheDir);
}
} else {
$useFTP = true;
$chimpexpress = new chimpexpress;
$handler = @ftp_connect( $chimpexpress->_settings['ftpHost'] );
$login = @ftp_login($handler, $chimpexpress->_settings['ftpUser'], $chimpexpress->_settings['ftpPasswd']);
@ftp_chdir($handler, $chimpexpress->_settings['ftpPath'] );
if( ! is_dir( ABSPATH . $cacheDir ) ){
@ftp_mkdir($handler, 'wp-content' .DS. 'plugins' .DS. 'chimpexpress' .DS. 'cache');
}
}
$cache = new chimpexpressJG_Cache($cacheDir, $useFTP, $handler);
$templates = $cache->get('templates');
if ($templates === FALSE){
$templates = $MCAPI->templates();
$cache->set('templates', $templates);
}
$templateInfo = array();
if( isset($templates['user']) ){
foreach($templates['user'] as $t){
$templateInfo[$t['id']] = $cache->get( 'templateInfo_'.$t['id'] );
if ($templateInfo[$t['id']] === FALSE){
$templateInfo[$t['id']] = $MCAPI->templateInfo($t['id']);
$cache->set('templateInfo_'.$t['id'], $templateInfo[$t['id']]);
}
}
}
$lists = $cache->get('lists');
if ($lists === FALSE){
$MCAPI = new chimpexpressMCAPI;
$result = true;
$lists = array();
$page = 0;
$limit = 100;
while( $result ){
$result = $MCAPI->lists( '', $page, $limit );
if( ! isset( $result['data'][0] ) ){
$result = false;
} else {
$lists = array_merge( $lists, $result['data']);
$page++;
}
}
$cache->set('lists', $lists);
}
if( !$templates || !$lists ){
_e('Templates and lists could not be retrieved! Please make sure you have set up templates and lists in MailChimp.
Click here to re-try. ', 'chimpexpress');
exit;
}
?>
templateInfo($t['id']);
$js .= "templates['".$t['id']."'] = new Array();\n";
// remove header and footer from template's editable sections
$i = 0;
$skipSections = array();
foreach ( $templateInfo[$t['id']]['sections'] as $tI ){
if ( $tI == 'header' || $tI == 'footer' ){
$skipSections[] = $i;
}
$i++;
}
$skipSectionsCount = count($skipSections);
$skipSections = implode(',', $skipSections);
$js .= "templates['".$t['id']."']['skipSections'] = '$skipSections'\n;";
$selected = (isset($_POST['template']) && $_POST['template'] == $t['id']) ? ' selected="selected"' : '';
echo ''.$t['name'].' ';
$js .= "templates['".$t['id']."']['templateName'] = '".$t['name']."';\n";
$js .= "templates['".$t['id']."']['sections'] = ".(count($templateInfo[$t['id']]['sections']) - $skipSectionsCount).";\n";
$js .= "templates['".$t['id']."']['preview'] = '".str_replace(array("'", "\n", "\r"),array("\'", " ", " "), $templateInfo[$t['id']]['preview'])."';\n";
$js .= "templates['".$t['id']."']['sectionNames'] = new Array();\n";
$js .= "templates['".$t['id']."']['editorContent'] = new Array();\n";
$x = 0;
for($i=0;$i
'.$l['name'].'';
$js .= "lists['".$l['id']."'] = new Array();\n";
$js .= "lists['".$l['id']."']['member_count'] = '".$l['stats']['member_count']."';\n";
$js .= "lists['".$l['id']."']['default_from_name'] = '".$l['default_from_name']."';\n";
$js .= "lists['".$l['id']."']['default_from_email'] = '".$l['default_from_email']."';\n";
} ?>
' />
" />
:
Reload cache if an expected entry does not appear in the list.', 'chimpexpress');?>
/wp-includes/js/thickbox/thickbox.css' type='text/css' media='all' />
100)) ? 15 : $rows;
wp_editor($content, $id, array(
'tab_index' => '2',
'teeny' => false,
'textarea_rows' => $rows,
'media_buttons' => true,
'tinymce' => array(
'plugins' => 'inlinepopups, fullscreen, wordpress, wplink, wpdialogs'
)
));
?>
posts}.* FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_status = 'publish'
AND {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_date < NOW()
ORDER BY {$wpdb->posts}.post_date DESC";
$posts = $wpdb->get_results($sql, OBJECT);
?>
:
ID.'" title="'.esc_attr(substr( $p->post_content, 0, 150)).' ...">'.$p->post_title.'';
$js .= "posts['".$p->ID."'] = '".esc_attr(urlencode($p->post_title))." ".esc_attr(urlencode(str_replace(array("\n"),'',$p->post_content)))."';\n";
}
?>
' />
" />
$v){
$MCAPI->campaignUpdate( $_POST['campaignId'], $k, $v );
}
$MCAPI->campaignUpdate( $_POST['campaignId'], 'content', $content );
$campaignId = $_POST['campaignId'];
} else {
$options['from_email'] = $_POST['default_from_email'];
$options['from_name'] = $_POST['default_from_name'];
$options['inline_css'] = true;
$options['generate_text'] = true;
$type = 'regular';
$campaignId = $MCAPI->campaignCreate( $type, $options, $content );
}
if($campaignId){
$campaign = $MCAPI->campaigns( array( 'campaign_id' => $campaignId ) );
$campaignContent = $MCAPI->campaignContent( $campaignId, false );
} else {
$campaignId = '';
}
if($campaign){
// create preview file
global $wp_filesystem;
$tmpDirAbs = WP_PLUGIN_DIR . DS . 'chimpexpress' . DS . 'tmp';
$tmpDirRel = get_option('home') . '/wp-content/plugins/chimpexpress/tmp/';
if( $wp_filesystem->method == 'direct' ){
// remove tmp folder
if ( is_dir( $tmpDirAbs ) ){
$wp_filesystem->delete( $tmpDirAbs, true);
}
// create new (empty) tmp folder
$wp_filesystem->mkdir( $tmpDirAbs );
// write preview file
$wp_filesystem->put_contents( $tmpDirAbs .DS. sanitize_title( $_POST['campaignSubject'] ) . '.html', $campaignContent['html'] );
} else {
$chimpexpress = new chimpexpress;
$ftpstream = @ftp_connect( $chimpexpress->_settings['ftpHost'] );
$login = @ftp_login($ftpstream, $chimpexpress->_settings['ftpUser'], $chimpexpress->_settings['ftpPasswd']);
@ftp_chdir($ftpstream, $chimpexpress->_settings['ftpPath'] );
// remove tmp folder
if ( is_dir( $tmpDirAbs ) ){
chimpexpress::ftp_delAll( $ftpstream, 'wp-content' .DS. 'plugins' .DS. 'chimpexpress' .DS. 'tmp' );
}
// create new (empty) tmp folder
@ftp_mkdir($ftpstream, 'wp-content' .DS. 'plugins' .DS. 'chimpexpress' .DS. 'tmp');
// write preview file
$temp = tmpfile();
fwrite($temp, $campaignContent['html']);
rewind($temp);
@ftp_chdir($ftpstream, 'wp-content' .DS. 'plugins' .DS. 'chimpexpress' .DS. 'tmp' );
@ftp_fput($ftpstream, sanitize_title( $_POST['campaignSubject'] ) . '.html', $temp, FTP_ASCII);
@ftp_close($ftpstream);
}
$link = $tmpDirRel . sanitize_title( $_POST['campaignSubject'] ) . '.html';
// $iframe = 'Note: '.__("Your email shouldn't be much more than 600 pixels wide.", 'chimpexpress').'
';
$iframe = '';
/*
$link = 'http://'.$MCAPI->dc.'.admin.mailchimp.com/campaigns/preview?id='.$campaign['data'][0]['web_id'];
// $link = $campaign['data'][0]['archive_url'];
$iframe = '';
*/
} else {
$iframe = '';
}
} else {
$MCAPI->_addError( array("error" => __('Campaign name and subject line must be supplied!', 'chimpexpress'), "code" => "-99") );
$MCAPI->showMessages();
$iframe = '';
$campaignId = '';
}
// var_dump($campaign);
$dc = substr( strrchr($MCAPI->api_key, '-'), 1 );
?>
' />
" />
showMessages();
function rrmdir($dir) {
if (is_dir($dir)) {
$objects = scandir($dir);
foreach ($objects as $object) {
if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
}
}
reset($objects);
rmdir($dir);
}
}