I have published a new post [POST-TITLE].
[POST-EXCERPT]
Please visit my site [SITE-LINK] to read it and leave your comment about it.
Hope to see you online!

[SITE-LINK]'); if (!get_option('alo_em_list')) add_option('alo_em_list', ''); if (!get_option('alo_em_lastposts')) add_option('alo_em_lastposts', 10); if (!get_option('alo_em_dayrate')) add_option('alo_em_dayrate', 2000); if (!get_option('alo_em_batchrate')) add_option('alo_em_batchrate', 60); if (!get_option('alo_em_sleepvalue')) add_option('alo_em_sleepvalue', 0); if (!get_option('alo_em_sender_email')) { $admin_email = get_option('admin_email'); add_option('alo_em_sender_email', $admin_email); } if (!get_option('alo_em_sender_name')) { $sender_name = get_option('blogname'); add_option('alo_em_sender_name', $sender_name ); } update_option('alo_em_import_alert', "show" ); update_option('alo_em_timeout_alert', "show" ); if (!get_option('alo_em_delete_on_uninstall')) add_option('alo_em_delete_on_uninstall', 'no'); if (!get_option('alo_em_show_subscripage')) add_option('alo_em_show_subscripage', 'no'); if (!get_option('alo_em_embed_css')) add_option('alo_em_embed_css', 'no'); if (!get_option('alo_em_no_activation_mail')) add_option('alo_em_no_activation_mail', 'no'); if (!get_option('alo_em_show_credit_banners')) add_option('alo_em_show_credit_banners', 'yes'); if (!get_option('alo_em_filter_br')) add_option('alo_em_filter_br', 'no'); if (!get_option('alo_em_filter_the_content')) add_option('alo_em_filter_the_content', 'yes'); if (!get_option('alo_em_js_rec_list')) add_option('alo_em_js_rec_list', 'ajax_normal'); if (!get_option('alo_em_use_themes')) add_option('alo_em_use_themes', 'yes'); alo_em_setup_predomain_texts( false ); require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); //------------------------------------------------------------------------- if ( alo_em_db_tables_need_update() ) { if( defined( 'DB_COLLATE' ) && constant( 'DB_COLLATE' ) != '' ) { $collate = constant( 'DB_COLLATE' ); } else { $collate = constant( 'DB_CHARSET' ); } // Create the table structure $sql = "CREATE TABLE {$wpdb->prefix}easymail_subscribers ( ID int(11) unsigned NOT NULL auto_increment, email varchar(100) NOT NULL, name varchar(100) NOT NULL, join_date datetime NOT NULL, active INT( 1 ) NOT NULL DEFAULT '0', unikey varchar(24) NOT NULL, lists varchar(255) DEFAULT '|', lang varchar(5) DEFAULT NULL, PRIMARY KEY (ID), UNIQUE KEY email (email) ) DEFAULT CHARSET=".$collate."; CREATE TABLE {$wpdb->prefix}easymail_recipients ( ID int(11) unsigned NOT NULL auto_increment, newsletter int(11) unsigned NOT NULL, email varchar(100) NOT NULL, result varchar(3) NOT NULL DEFAULT '0', PRIMARY KEY (ID) ) DEFAULT CHARSET=".$collate."; CREATE TABLE {$wpdb->prefix}easymail_stats ( ID int(11) unsigned NOT NULL auto_increment, recipient int(11) unsigned NOT NULL, newsletter int(11) unsigned NOT NULL, added_on datetime NOT NULL, request varchar(225) DEFAULT NULL, PRIMARY KEY (ID) ) DEFAULT CHARSET=".$collate."; "; dbDelta($sql); // Update the old "lists" field if upgrading from v. 1.x $installed_db = get_option('alo_em_db_version'); if ( $installed_db < 2012 ) { $wpdb->query( "UPDATE ". $wpdb->prefix."easymail_subscribers SET lists = REPLACE( lists, '_', '|');" ); $wpdb->query( "UPDATE {$wpdb->options} SET option_name = REPLACE( option_name, 'ALO_em_', 'alo_em_');" ); } update_option( "alo_em_db_version", ALO_EM_DB_VERSION ); } //------------------------------------------------------------------------- // Create/update the page with subscription // check if page already exists $my_page_id = get_option('alo_em_subsc_page'); $my_page = array(); $my_page['post_title'] = 'Newsletter'; $my_page['post_content'] = '[ALO-EASYMAIL-PAGE]'; $my_page['post_status'] = 'publish'; $my_page['post_author'] = 1; $my_page['comment_status'] = 'closed'; $my_page['post_type'] = 'page'; if ( !$my_page_id ) { // insert the post into the database $my_page_id = wp_insert_post( $my_page ); update_option('alo_em_subsc_page', $my_page_id); } // add scheduled cleaner wp_schedule_event(time(), 'twicedaily', 'alo_em_schedule'); // add scheduled cron batch wp_schedule_event( time() +60, 'alo_em_interval', 'alo_em_batch' ); // default permission $wp_roles->add_cap( 'administrator', 'manage_easymail_options'); $wp_roles->add_cap( 'administrator', 'manage_easymail_subscribers'); //$wp_roles->add_cap( 'administrator', 'manage_easymail_newsletters'); //$wp_roles->add_cap( 'administrator', 'send_easymail_newsletters'); } /** * Check if plugin tables are already properly installed */ function alo_em_db_tables_need_update() { global $wpdb; $installed_db = get_option('alo_em_db_version'); $missing_table = false; // Check if tables not yet installed $tables = array ( $wpdb->prefix."easymail_subscribers", $wpdb->prefix."easymail_recipients", $wpdb->prefix."easymail_stats" ); foreach ( $tables as $table_name ) { if ( $wpdb->get_var("show tables like '$table_name'") != $table_name ) $missing_table = true; } return ( $missing_table || ALO_EM_DB_VERSION != $installed_db ) ? true : false; } /** * Manage plugin activation: on multisite and on standard (thanks to kzyz!) */ function alo_em_activate() { global $wpdb; if ( function_exists( 'is_multisite' ) && is_multisite() ) { // check if it is a network activation - if so, run the activation function for each blog id if ( isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) { $old_blog = $wpdb -> blogid; // Get all blog ids $blogids = $wpdb -> get_col( $wpdb -> prepare( "SELECT blog_id FROM {$wpdb -> blogs}" ) ); foreach ( $blogids as $blog_id ) { switch_to_blog( $blog_id ); alo_em_install(); } switch_to_blog( $old_blog ); return; } } alo_em_install(); } register_activation_hook(__FILE__,'alo_em_activate'); /** * For batch sending (every tot mins) */ function alo_em_more_reccurences() { return array( 'alo_em_interval' => array('interval' => 59*(ALO_EM_INTERVAL_MIN), 'display' => 'EasyMail every ' .ALO_EM_INTERVAL_MIN. ' minutes' ) ); } add_filter('cron_schedules', 'alo_em_more_reccurences'); /** * Clean the new subscription not yet activated after too much time */ function alo_em_clean_no_actived() { global $wpdb; // delete subscribes not yet activated after 5 days $limitdate = date ("Y-m-d",mktime(0,0,0,date("m"),date("d")-5,date("Y"))); $output = $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}easymail_subscribers WHERE join_date <= '%s' AND active = '0'", $limitdate ) ); //return $output;. } add_action('alo_em_schedule', 'alo_em_clean_no_actived'); add_action( 'alo_em_batch' , 'alo_em_batch_sending'); /** * On plugin adectivation */ function alo_em_uninstall() { global $wpdb, $wp_roles, $wp_version; // delete scheduled cleaner wp_clear_scheduled_hook('alo_em_schedule'); wp_clear_scheduled_hook('ALO_em_schedule'); // old versions // delete cron batch sending wp_clear_scheduled_hook('alo_em_batch'); wp_clear_scheduled_hook('ALO_em_batch'); // old versions // if required delete all plugin data (options, db tables, page) if ( get_option('alo_em_delete_on_uninstall') == "yes" ) { $tables = array ( "easymail_recipients", "easymail_subscribers", "easymail_stats", "easymail_sendings", "easymail_trackings" ); foreach ( $tables as $tab ) { $wpdb->query("DROP TABLE IF EXISTS {$wpdb->prefix}$tab"); } // delete option from db $wpdb->query( "DELETE FROM {$wpdb->prefix}options WHERE option_name LIKE 'alo_em_%'" ); // delete subscription page if ( version_compare ( $wp_version , '2.9', '>=' ) ) { wp_delete_post( get_option('alo_em_subsc_page'), true ); // skip trash, from wp 2.9 } else { wp_delete_post( get_option('alo_em_subsc_page') ); } // and the option with page id delete_option ('alo_em_subsc_page'); } // reset cap $roles = $wp_roles->get_names(); // get a list of values, containing pairs of: $role_name => $display_name foreach ( $roles as $rolename => $key) { $wp_roles->remove_cap( $rolename, 'manage_easymail_options'); $wp_roles->remove_cap( $rolename, 'manage_easymail_subscribers'); //$wp_roles->remove_cap( $rolename, 'manage_easymail_newsletters'); //$wp_roles->remove_cap( $rolename, 'send_easymail_newsletters'); } } /** * Manage plugin de-activation: on multisite and on standard (thanks to kzyz!) */ function alo_em_deactivate() { global $wpdb; if ( function_exists( 'is_multisite' ) && is_multisite() ) { // check if it is a network activation - if so, run the activation function for each blog id if ( isset( $_GET['networkwide'] ) && ( $_GET['networkwide'] == 1 ) ) { $old_blog = $wpdb->blogid; // Get all blog ids $blogids = $wpdb -> get_col( $wpdb -> prepare( "SELECT blog_id FROM {$wpdb -> blogs}" ) ); foreach ( $blogids as $blog_id ) { switch_to_blog( $blog_id ); alo_em_uninstall(); } switch_to_blog( $old_blog ); return; } } alo_em_uninstall(); } register_deactivation_hook( __FILE__, 'alo_em_deactivate' ); /** * Plugin activation whren new blog on multisite (thanks to kzyz!) */ function alo_em_new_blog( $blog_id ) { global $wpdb; if ( is_plugin_active_for_network( ALO_EM_PLUGIN_DIR. '/'. basename( __FILE__ ) ) ) { $old_blog = $wpdb -> blogid; switch_to_blog( $blog_id ); alo_em_install(); switch_to_blog( $old_blog ); } } add_action( 'wpmu_new_blog', 'alo_em_new_blog' ); /** * Add menu pages */ function alo_em_add_admin_menu() { if ( current_user_can('manage_easymail_subscribers') ) add_submenu_page( 'edit.php?post_type=newsletter', __("Subscribers", "alo-easymail"), __("Subscribers", "alo-easymail"), 'manage_easymail_subscribers', 'alo-easymail/alo-easymail_subscribers.php' ); if ( current_user_can('manage_easymail_options') ) add_submenu_page( 'edit.php?post_type=newsletter', __("Settings"), __("Settings"), 'manage_easymail_options', 'alo-easymail/alo-easymail_options.php' ); } add_action('admin_menu', 'alo_em_add_admin_menu'); /** * Contextual help */ function alo_em_contextual_help() { global $hook_suffix; if (function_exists('add_contextual_help')) { $html = __("Resources about EasyMail Newsletter", "alo-easymail") . ': homepage | guide | faq | for developers | forum | news'; $html .= " |

"; /* $html .= "\n

". __("To enable the plugin work better you should increase the wp_cron and php timeouts", "alo-easymail") ."

\n"; $html .= "
\n"; $html .= "

". __("Here is a summary of some solutions that might help you", "alo-easymail") .":

\n"; $html .= "

» ". sprintf( __("increase the cron timeout in %s to 20 seconds or more", "alo-easymail"), "".includes_url()."cron.php" ) .":

"; $html .= '
'.__("FROM", "alo-easymail").":\t".'wp_remote_post( $cron_url, array(\'timeout\' => 0.01, \'blocking\' => false, \'sslverify\' => apply_filters(\'https_local_ssl_verify\', true)) );
'; $html .= '
'.__("TO", "alo-easymail").":\t".'wp_remote_post( $cron_url, array(\'timeout\' => 20, \'blocking\' => false, \'sslverify\' => apply_filters(\'https_local_ssl_verify\', true)) );
'; $html .= "

» ". sprintf( __("add this code in %s", "alo-easymail"), "".get_option('siteurl')."/wp-config.php" ) .":

"; $html .= "
define('WP_MEMORY_LIMIT', '96M');\n@ini_set( 'upload_max_size', '100M' );\n@ini_set( 'post_max_size', '105M');\n@ini_set( 'max_execution_time', '600' );
\n"; $html .= "

» ". sprintf( __("add this code in %s", "alo-easymail"), "".get_option('siteurl')."/.htaccess" ) ." (". __("if this file does not exist, create it", "alo-easymail") . "):

"; $html .= "
php_value memory_limit 96M\nphp_value upload_max_filesize 100M\nphp_value post_max_size 105M\nphp_value max_execution_time 600\nphp_value max_input_time 600
\n"; $html .= "

". __("If you have problems in sending you can try alterative cron", "alo-easymail") .": ". sprintf( __("add this code in %s", "alo-easymail"), "".get_option('siteurl')."/wp-config.php" ) .":

\n"; $html .= "
define('ALTERNATE_WP_CRON', true);
\n"; $html .= "

". __("For more info, visit the FAQ of the site.", "alo-easymail") . ' »' ."

\n"; $html .= "
"; */ if ( $hook_suffix == 'alo-easymail/alo-easymail_options.php' ) { // extra help } if ( $hook_suffix == 'alo-easymail/alo-easymail_subscribers.php' ) { // extra help } add_contextual_help( $hook_suffix, $html ); } } add_action( 'admin_head-alo-easymail/alo-easymail_options.php', 'alo_em_contextual_help' ); add_action( 'admin_head-alo-easymail/alo-easymail_subscribers.php', 'alo_em_contextual_help' ); /* * Add some links on the plugin page */ function alo_em_add_plugin_links($links, $file) { if ( $file == plugin_basename(__FILE__) ) { $links[] = 'Guide'; $links[] = 'Faq'; $links[] = 'Forum'; $links[] = 'News'; } return $links; } add_filter( 'plugin_row_meta', 'alo_em_add_plugin_links', 10, 2 ); /** * On plugin init */ function alo_em_init_method() { // if required, exclude the easymail page from pages' list if ( get_option('alo_em_show_subscripage') == "no" ) add_filter('get_pages','alo_em_exclude_page'); // load localization files load_plugin_textdomain ("alo-easymail", false, "alo-easymail/languages"); } add_action( 'init', 'alo_em_init_method' ); /** * New custom post type: Newsletter */ function alo_em_register_newsletter_type () { $labels = array( 'name' => __( 'Newsletters', "alo-easymail" ), 'singular_name' => __( 'Newsletter', "alo-easymail" ), 'add_new' => __( 'Add New', "alo-easymail" ), 'add_new_item' => __( 'Add New Newsletter', "alo-easymail" ), 'edit_item' => __( 'Edit Newsletter', "alo-easymail" ), 'new_item' => __( 'New Newsletter', "alo-easymail" ) , 'view_item' => __( 'View Newsletter', "alo-easymail" ), 'search_items' => __( 'Search Newsletters', "alo-easymail" ), 'not_found' => __( 'No Newsletters found', "alo-easymail" ), 'not_found_in_trash' => __( 'No Newsletters found in Trash', "alo-easymail" ), 'parent_item_colon' => __( 'Parent Newsletter', "alo-easymail" ), 'menu_name' => __( 'Newsletters', "alo-easymail" ), 'parent' => __( 'Parent Newsletter', "alo-easymail" ), ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'exclude_from_search' => false, 'rewrite' => array('slug' => 'newsletters'), 'capability_type' => 'post', /*'map_meta_cap' => true,*/ 'has_archive' => true, 'hierarchical' => false, 'menu_position' => false, 'menu_icon' => ALO_EM_PLUGIN_URL.'/images/16-email-letter.png', 'can_export' => true, 'supports' => array( 'title' , 'editor', 'thumbnail', 'excerpt', 'custom-fields' ) ); $args = apply_filters ( 'alo_easymail_register_newsletter_args', $args ); register_post_type( 'newsletter', $args ); } add_action('init', 'alo_em_register_newsletter_type'); /** * Texts when a Newsletter is updated */ function alo_em_newsletter_updated_messages( $messages ) { global $post, $post_ID; $messages['newsletter'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('Newsletter updated. View Newsletter', "alo-easymail" ), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.', "alo-easymail"), 3 => __('Custom field deleted.', "alo-easymail"), 4 => __('Newsletter updated.', "alo-easymail"), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('Newsletter restored to revision from %s', "alo-easymail"), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('Newsletter published. View Newsletter', "alo-easymail"), esc_url( get_permalink($post_ID) ) ), 7 => __('Newsletter saved.', "alo-easymail"), 8 => sprintf( __('Newsletter submitted. Preview Newsletter', "alo-easymail"), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Newsletter scheduled for: %1$s. Preview Newsletter', "alo-easymail"), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'j M Y @ G:i', "alo-easymail" ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Newsletter draft updated. Preview Newsletter', "alo-easymail"), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); return $messages; } add_filter('post_updated_messages', 'alo_em_newsletter_updated_messages'); /** * Adds media upload in thickbox in Newsletter */ function alo_em_newsletter_add_media_upload_scripts() { if ($GLOBALS['post_type'] == 'newsletter') { add_thickbox(); wp_enqueue_script('media-upload'); } } add_action('admin_print_styles-post-new.php', 'alo_em_newsletter_add_media_upload_scripts'); add_action('admin_print_styles-post.php', 'alo_em_newsletter_add_media_upload_scripts'); /** * Dirty hack to hide "Quick edit" button // TODO: add easymail option in Quick edit view: http://shibashake.com/wordpress-theme/expand-the-wordpress-quick-edit-menu */ /* function alo_em_inti_method () { add_action('admin_print_styles-edit.php','alo_em_hide_quick_edit_css'); } add_action('admin_init','alo_em_inti_method'); function alo_em_hide_quick_edit_css() { if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) : ?> "; $columns["title"] = __( 'Title' ) ." / " . __( 'Subject', "alo-easymail"); $columns["easymail_recipients"] = __( 'Recipients', "alo-easymail" ); $columns["easymail_status"] = __( 'Newsletter status', "alo-easymail" ); $columns["date"] = __( 'Start', "alo-easymail" ); $columns["author"] = __( 'Author' ); return $columns; } add_filter ('manage_edit-newsletter_columns', 'alo_em_edit_table_columns'); /** * Fills the columns of Newsletter display table */ function alo_em_table_column_value ( $columns ) { global $post; $count_recipients = alo_em_count_recipients_from_meta( $post->ID ); $recipients = alo_em_get_recipients_from_meta( $post->ID ); if ( $columns == "easymail_recipients" ) { if ( $count_recipients == 0 ) { if ( alo_em_user_can_edit_newsletter( $post->ID ) ) echo ''; echo ' ' . __( 'No recipients selected yet', "alo-easymail").''; if ( alo_em_user_can_edit_newsletter( $post->ID ) ) echo ''; } else { //echo "
". print_r ( $recipients, true ) . "
"; echo "". __( 'Total recipients', "alo-easymail") .": "; if ( alo_em_get_newsletter_status( $post->ID ) ) { // if already created list of recipients, count form db, otherwise from meta echo alo_em_count_newsletter_recipients( $post->ID ); } else { echo alo_em_count_recipients_from_meta ( $post->ID ); } echo "
\n"; echo "
\n". alo_em_recipients_short_summary ( $recipients ) ."
\n"; } } if ( $columns == "easymail_status" ) { if ( $count_recipients > 0 ) { echo ''; echo "ID}\">\n"; alo_em_update_column_status ( $post->ID ); echo "\n"; } } } add_action ('manage_posts_custom_column', 'alo_em_table_column_value' ); /** * Update status column after closing recipients thickbox */ function alo_em_ajax_column_status () { $newsletter = $_POST['post_id']; if ( $newsletter ) alo_em_update_column_status( $newsletter ); die(); } add_action('wp_ajax_alo_easymail_update_column_status', 'alo_em_ajax_column_status'); /** * Pause/Play Newsletter, then update status column after closing recipients thickbox */ function alo_em_ajax_pauseplay_column_status () { $newsletter = $_POST['post_id']; $button = $_POST['button']; // pause or play? if ( $newsletter ) { if ( $button == "pause" ) { alo_em_edit_newsletter_status ( $newsletter, 'paused' ); } else { alo_em_edit_newsletter_status ( $newsletter, 'sendable' ); } alo_em_update_column_status( $newsletter ); } die(); } add_action('wp_ajax_alo_easymail_pauseplay_column_status', 'alo_em_ajax_pauseplay_column_status'); /** * Return data for Subscriber edit inline */ function alo_em_ajax_alo_easymail_subscriber_edit_inline () { check_ajax_referer( "alo-easymail" ); $subscriber = $_POST['subscriber']; $row_index = $_POST['row_index']; $inline_action = $_POST['inline_action']; if ( $subscriber ) { $mailinglists = alo_em_get_mailinglists( 'admin,public' ); $languages = alo_em_get_all_languages ( true ); switch ( $inline_action ) { case 'save': // save data and return html row, red-only mode $subscriber_obj = alo_em_get_subscriber_by_id( $subscriber ); $new_name = ( isset( $_POST['new_name'] ) ) ? stripslashes( trim ( $_POST['new_name'] ) ): false ; $new_email = ( isset( $_POST['new_email'] ) && is_email( trim ( $_POST['new_email'] ) ) ) ? trim ( $_POST['new_email'] ) : false; $new_active = ( isset( $_POST['new_active'] ) && is_numeric( $_POST['new_active'] ) ) ? $_POST['new_active'] : 0; $new_lang = ( isset( $_POST['new_lang'] ) && in_array( $_POST['new_lang'], $languages) ) ? $_POST['new_lang'] : ""; $new_lists = ( isset( $_POST['new_lists'] ) ) ? trim( $_POST['new_lists'] ) : false; /* if ( !$new_name ) { echo "-error-name-is-empty"; break; } */ // Check if a subscriber with this email already exists $already = ( alo_em_is_subscriber ( $new_email ) ) ? alo_em_is_subscriber ( $new_email ) : false; if ( $already && $already != $subscriber && $subscriber_obj->email != $new_email ) { echo "-error-email-already-subscribed"; break; // Last check before save } else if ( $new_email ) { alo_em_update_subscriber_by_email ( $subscriber_obj->email, $new_email, $new_name, $new_active, $new_lang ); $new_lists = explode ( ",", rtrim ( $new_lists, "," ) ); if ( is_array( $mailinglists ) ) : foreach ( $mailinglists as $mailinglist => $val ) : if ( in_array ( $mailinglist, $new_lists ) ) { alo_em_add_subscriber_to_list ( $subscriber, $mailinglist ); } else { alo_em_delete_subscriber_from_list ( $subscriber, $mailinglist ); } endforeach; endif; echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); } else { echo "-error-email-is-not-valid"; } break; case 'delete': // Delete the subscriber if ( alo_em_delete_subscriber_by_id ( $subscriber ) ) { echo "-ok-deleted"; break; } else { echo "-1"; // error break; } echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); case 'cancel': // return html row, red-only mode echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, false, $mailinglists, $languages ); break; case 'edit': default: // return html row, edit mode echo alo_em_get_subscriber_table_row ( $subscriber, $row_index, true, $mailinglists, $languages ); } } die(); } add_action('wp_ajax_alo_easymail_subscriber_edit_inline', 'alo_em_ajax_alo_easymail_subscriber_edit_inline'); /** * Print html of Status column of Newsletter in display table */ function alo_em_update_column_status ( $newsletter ) { $recipients = alo_em_get_recipients_from_meta ( $newsletter ); if ( $recipients ) { $status = alo_em_get_newsletter_status( $newsletter ); $report_url = wp_nonce_url( ALO_EM_PLUGIN_URL . '/alo-easymail_report.php?', 'alo-easymail_report'); $goto_report = ""; $goto_report .= "\"\"". __( 'Report', "alo-easymail") .""; switch ( $status ) { case "sent": echo "". __("Completed", "alo-easymail"). ": 100%
"; $end = get_post_meta ( $newsletter, "_easymail_completed", current_time( 'mysql', 0 ) ); if ( $end ) echo date_i18n( __( 'j M Y @ G:i', "alo-easymail" ), strtotime( $end ) ). "
"; if ( alo_em_user_can_edit_newsletter( $newsletter ) ) echo $goto_report; break; case "sendable": $post_status = get_post_status( $newsletter ); switch ( $post_status ) { case "publish": echo "".__("On sending queue", "alo-easymail"). "...
"; echo __("Progress", "alo-easymail"). ": ". alo_em_newsletter_recipients_percentuage_already_sent( $newsletter ) . "%
"; if ( alo_em_user_can_edit_newsletter( $newsletter ) ) { echo ' '. __( 'refresh', '; echo ""; echo ' '. __( 'pause', '; echo ""; } if ( alo_em_user_can_edit_newsletter( $newsletter ) ) echo " ". $goto_report; break; case "pending": echo "".__("Pending Review"). "
"; break; case "future": echo "".__("Scheduled"). "
"; if ( alo_em_user_can_edit_newsletter( $newsletter ) ) { echo ' '. __( 'refresh', '; } break; case "draft": echo "".__("Draft"). "
"; break; default: echo "".__("Pending"). "
"; break; } // $post_status break; case "paused": echo "".__("Paused", "alo-easymail"). "!
"; echo __("Progress", "alo-easymail"). ": ". alo_em_newsletter_recipients_percentuage_already_sent( $newsletter ) . "%
"; //if ( alo_em_count_newsletter_recipients_already_sent ( $newsletter ) > 0 ) echo " (".alo_em_count_newsletter_recipients_already_sent ( $newsletter ) ."/". alo_em_count_newsletter_recipients ( $newsletter ). ")
"; if ( alo_em_user_can_edit_newsletter( $newsletter ) ) { echo ""; echo ' '. __( 'continue', '; echo ""; } if ( alo_em_user_can_edit_newsletter( $newsletter ) ) echo " ". $goto_report; break; case false: default: if ( get_option('alo_em_js_rec_list') != "no_ajax_onsavepost" ) { // if required, no link to ajax $rec_url = wp_nonce_url( ALO_EM_PLUGIN_URL . '/alo-easymail_recipients-list.php?', 'alo-easymail_recipients-list'); if ( alo_em_user_can_edit_newsletter( $newsletter ) ) echo ""; echo "\"\" " . __( 'Required', "alo-easymail") .": " . __( 'Create list of recipients', "alo-easymail"); if ( alo_em_user_can_edit_newsletter( $newsletter ) ) echo ""; } } } } /** * Add "views" button in edit newsletter table */ function alo_em_edit_table_views ( $views ) { $class = ( isset ( $_GET['easymail_status'] ) && $_GET['easymail_status'] == "sent" ) ? "current" : false; if ( alo_em_count_newsletters_by_status( 'sent' ) > 0 ) { // post_status=true: to avoid "All" view is the current $views[ "easymail_status" ] = "\t". __( 'Sent', "alo-easymail") . sprintf( " (%d)", alo_em_count_newsletters_by_status( 'sent' ) /*TODO*/ ) .""; } return $views; } add_filter( 'views_edit-newsletter', 'alo_em_edit_table_views' ); /** * Show required newsletters in edit newsletter table */ function alo_em_filter_newsletter_table ( $query ) { global $wp_version, $pagenow; if ( is_admin() && $pagenow == "edit.php" && isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) { if ( isset ( $_GET['easymail_status'] ) && $_GET['easymail_status'] == "sent" ) { // query meta: http://codex.wordpress.org/Function_Reference/WP_Query#Custom_Field_Parameters if ( version_compare ( $wp_version , '3.1', '>=' ) ) { $meta_1 = array( 'key' => '_easymail_status', 'value' => 'sent', 'compare' => '=' ); $query->set ('meta_query', array( $meta_1 ) ); } else { $query->set ('meta_key', '_easymail_status' ); $query->set ('meta_value', 'sent' ); $query->set ('meta_compare', '=' ); } } } return $query; } add_action('pre_get_posts', 'alo_em_filter_newsletter_table' ); /** * On User Profile */ function alo_em_user_profile_optin ( $user ) { // get the current setting //if (ALO_easymail_get_optin($user->ID)=='yes'){ // deleted ALO if (alo_em_is_subscriber($user->user_email)){ // added ALO $optin_selected = 'selected'; $optout_selected = ''; } else{ $optin_selected = ''; $optout_selected = 'selected'; } $html = "

". __("Newsletter", "alo-easymail") ."

\n"; $html .= "\n"; $html .= " \n"; $optin_txt = ( alo_em_translate_option ( alo_em_get_language (), 'alo_em_custom_optin_msg', false) !="") ? alo_em_translate_option ( alo_em_get_language (), 'alo_em_custom_optin_msg', false) : __("Yes, I would like to receive the Newsletter", "alo-easymail"); $html .= " \n"; $html .= " \n"; $html .= " \n"; $html .= "
\n"; $html .= " \n"; $html .= "
\n"; // add mailing lists html table $html .= alo_em_html_mailinglists_table_to_edit ( $user->user_email, "form-table" ); echo $html; } add_action( 'show_user_profile', 'alo_em_user_profile_optin' ); add_action( 'edit_user_profile', 'alo_em_user_profile_optin' ); function alo_em_save_profile_optin($user_id) { if ( !current_user_can( 'edit_user', $user_id ) ) return false; $user_info = get_userdata( $user_id ); $user_email = $user_info->user_email; if (isset($_POST['alo_easymail_option'])) { if ( $_POST['alo_easymail_option'] == "yes") { $todo_update = false; // if changed name and lastname if ( isset( $_POST[ 'first_name' ] ) && $user_info->first_name != $_POST[ 'first_name' ] ) { $user_first_name = stripslashes( trim( $_POST[ 'first_name' ] ) ); $todo_update = true; } else { $user_first_name = $user_info->first_name; } if ( isset( $_POST[ 'last_name' ] ) && $user_info->last_name != $_POST[ 'last_name' ] ) { $user_last_name = stripslashes( trim( $_POST[ 'last_name' ] ) ); $todo_update = true; } else { $user_last_name = $user_info->last_name; } $fullname = $user_first_name." ".$user_last_name; // if changed email if ( isset( $_POST[ 'email' ] ) && is_email( $_POST[ 'email' ] ) && $user_email != $_POST[ 'email' ] ) { $user_email = stripslashes( trim( $_POST[ 'email' ] ) ); $todo_update = true; } if ( $todo_update ) { //alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ); if ( alo_em_update_subscriber_by_email ( $user_info->user_email, $user_email, $fullname, 1, alo_em_get_language(true) ) ) { $subscriber = alo_em_get_subscriber ( $user_email ); do_action ( 'alo_easymail_subscriber_updated', $subscriber, $user_info->user_email ); } } else { alo_em_add_subscriber( $user_email, $fullname, 1, alo_em_get_language(true) ); } // if subscribing, save also lists $mailinglists = alo_em_get_mailinglists( 'public' ); if ($mailinglists) { $subscriber_id = alo_em_is_subscriber( $user_email ); foreach ( $mailinglists as $mailinglist => $val) { if ( isset ($_POST['alo_em_profile_lists']) && is_array ($_POST['alo_em_profile_lists']) && in_array ( $mailinglist, $_POST['alo_em_profile_lists'] ) ) { alo_em_add_subscriber_to_list ( $subscriber_id, $mailinglist ); // add to list } else { alo_em_delete_subscriber_from_list ( $subscriber_id, $mailinglist ); // remove from list } } } } else { alo_em_delete_subscriber_by_id( alo_em_is_subscriber($user_email) ); } } } add_action( 'personal_options_update', 'alo_em_save_profile_optin' ); add_action( 'edit_user_profile_update', 'alo_em_save_profile_optin' ); /** * Widget activation */ function alo_em_load_widgets() { register_widget( 'ALO_Easymail_Widget' ); } add_action( 'widgets_init', 'alo_em_load_widgets' ); /** * Add javascript on Admin panel */ function alo_em_add_admin_script () { global $post, $pagenow; if ( isset($_GET['page']) && $_GET['page'] == "alo-easymail/alo-easymail_options.php") { wp_enqueue_script('jquery-ui-tabs'); echo ''."\n"; } if ( $pagenow == "post.php" || ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) ) { wp_enqueue_script('thickbox'); wp_enqueue_script( 'alo-easymail-backend', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend.js' ); wp_localize_script( 'alo-easymail-backend', 'easymailJs', alo_em_localize_admin_script() ); } } add_action('admin_print_scripts', 'alo_em_add_admin_script' ); function alo_em_localize_admin_script () { global $post, $pagenow, $current_screen; $post_id = ( $post ) ? $post->ID : false; $screen_id = ( $current_screen ) ? $current_screen->id : false; return array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'pluginPath' => ALO_EM_PLUGIN_URL."/", 'postID' => $post_id, 'pagenow' => $pagenow, 'screenID' => $screen_id, 'reportPopupTitle' => esc_js( __("Newsletter report", "alo-easymail") ), 'subscribersPopupTitle' => esc_js( __("Newsletter subscribers creation", "alo-easymail") ), 'themePreviewUrl' => alo_easymail_get_themes_url(), 'nonce' => wp_create_nonce( 'alo-easymail' ), 'errEmailNotValid' => esc_js( __("The e-email address is not correct", "alo-easymail") ), 'errNameIsBlank' => esc_js( __("The name field is empty", "alo-easymail") ), 'errEmailAlreadySubscribed'=> esc_js( __("There is already a subscriber with this e-email address", "alo-easymail") ), 'confirmDelSubscriber'=> esc_js( __("Do you really want to DELETE this subscriber?", "alo-easymail") ) ); } /** * Add CSS on Admin panel */ function alo_em_add_admin_styles () { global $post, $pagenow; if ( $pagenow == "post.php" || ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) ) { wp_enqueue_style( 'alo-easymail-backend-css', ALO_EM_PLUGIN_URL.'/inc/alo-easymail-backend.css' ); wp_enqueue_style( 'thickbox' ); } } add_action( "admin_print_styles", 'alo_em_add_admin_styles' ); /** * Load scripts & styles on Frontend */ function alo_em_load_scripts() { if ( get_option('alo_em_embed_css') == "yes" ) { if ( @file_exists ( TEMPLATEPATH.'/alo-easymail.css' ) ) { wp_enqueue_style ('alo-easymail', get_bloginfo('template_directory') .'/alo-easymail.css' ); } else { wp_enqueue_style ('alo-easymail', ALO_EM_PLUGIN_URL.'/alo-easymail.css' ); } } /* // TODO use jquery external js! wp_enqueue_script( 'alo-easymail-frontend', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-frontend.js' ); wp_localize_script( 'alo-easymail-frontend', 'easymail', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'postID' => 2 ) ); */ } add_action('wp_enqueue_scripts', 'alo_em_load_scripts'); /** * Exclude the easymail page from pages' list */ function alo_em_exclude_page( $pages ) { if ( !is_admin() ) { for ( $i=0; $iID == get_option('alo_em_subsc_page')) unset ($pages[$i]); } } return $pages; } /** * Manage the newsletter subscription page */ function alo_em_subscr_page ( $atts, $content = null ) { ob_start(); include( ALO_EM_PLUGIN_ABS .'/alo-easymail_subscr-page.php' ); $contents = ob_get_contents(); ob_end_clean(); return $contents; } add_shortcode('ALO-EASYMAIL-PAGE', 'alo_em_subscr_page'); /** * Boxes meta in Newsletter edit/new pages */ function alo_em_newsletter_add_custom_box() { add_meta_box( "alo_easymail_newsletter_recipients", __("Recipients", "alo-easymail"), "alo_em_meta_recipients", "newsletter", "side", "high" ); if ( get_option('alo_em_use_themes') == 'yes' || get_option('alo_em_use_themes') == '' ) add_meta_box( "alo_easymail_newsletter_themes", __("Themes", "alo-easymail"), "alo_em_meta_themes", "newsletter", "normal", "high" ); add_meta_box( "alo_easymail_newsletter_placeholders", __("Placeholders", "alo-easymail"), "alo_em_meta_placeholders", "newsletter", "normal", "high" ); } add_action('add_meta_boxes', 'alo_em_newsletter_add_custom_box'); /** * Box meta: Recipients */ function alo_em_meta_recipients ( $post ) { wp_nonce_field( ALO_EM_PLUGIN_DIR, "edit_newsletter" ); //print_r ( alo_em_get_recipients_from_meta($post->ID) ); print_r ( alo_em_get_all_languages() ); echo "

ID ) == 0 ) ? "class=\"easymail-txtwarning\"" : "" ) ." >"; echo "" .__("Selected recipients", "alo-easymail") .": ". alo_em_count_recipients_from_meta( $post->ID ) ."

"; if ( alo_em_get_newsletter_status ( $post->ID ) == "sent" ) { echo "

". __("This newsletter was already sent", "alo-easymail") .".

"; echo "
"; return; } if ( alo_em_count_newsletter_recipients ( $post->ID ) > 0 ) { echo "

". __("The creation of the recipients list has already started", "alo-easymail") .".

"; echo "

"; echo "

"; echo "
"; } $recipients = alo_em_get_recipients_from_meta ( $post->ID ); ?>
". print_r ( $themes, true ). ""; // DEBUG echo '\n"; echo "". __("View") .""; } } /** * Save Theme */ function alo_em_save_newsletter_theme_meta ( $post_id ) { if ( isset( $_POST['easymail-theme-select'] ) && array_key_exists( $_POST['easymail-theme-select'], alo_easymail_get_all_themes() ) ) { update_post_meta ( $post_id, '_easymail_theme', $_POST['easymail-theme-select'] ); } else { delete_post_meta ( $post_id, '_easymail_theme' ); } } add_action('alo_easymail_save_newsletter_meta_extra', 'alo_em_save_newsletter_theme_meta' ); /** * Box meta: Placeholders */ function alo_em_meta_placeholders ( $post ) { wp_nonce_field( ALO_EM_PLUGIN_DIR, "edit_newsletter" ); alo_em_tags_table ( $post->ID ); } /** * Add post select in Placeholders table */ function my_easymail_placeholders_title_easymail_post ( $post_id ) { $n_last_posts = (get_option('alo_em_lastposts'))? get_option('alo_em_lastposts'): 10; $args = array( 'numberposts' => $n_last_posts, 'order' => 'DESC', 'orderby' => 'date' ); $get_posts = get_posts($args); if ( $get_posts ) { echo esc_html( __("Choose a post", "alo-easymail") ). ": "; echo '
'; } else { echo "" . esc_html( __("There are no posts", "alo-easymail") ) . "!
"; } } add_action('alo_easymail_newsletter_placeholders_title_easymail_post', 'my_easymail_placeholders_title_easymail_post' ); /** * Save Post select in Placeholder Box meta in Newsletter */ function alo_em_save_newsletter_placeholders_easymail_post ( $post_id ) { if ( isset( $_POST['placeholder_easymail_post'] ) && is_numeric( $_POST['placeholder_easymail_post'] ) ) { update_post_meta ( $post_id, '_placeholder_easymail_post', $_POST['placeholder_easymail_post'] ); } } add_action('alo_easymail_save_newsletter_meta_extra', 'alo_em_save_newsletter_placeholders_easymail_post' ); /** * SAVE Boxes meta in Newsletter */ function alo_em_save_newsletter_meta ( $post_id ) { if ( @!wp_verify_nonce( $_POST["edit_newsletter"], ALO_EM_PLUGIN_DIR )) { return $post_id; } if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; // Check permissions if ( 'newsletter' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; } do_action ( 'alo_easymail_save_newsletter_meta_extra', $post_id ); // If a previous list exists already: if requested reset, otherwise don't save if ( alo_em_count_newsletter_recipients( $post_id ) > 0 ) { if ( isset( $_POST['easymail-reset-all-recipients'] ) ) { alo_em_delete_newsletter_recipients ( $post_id ); alo_em_delete_newsletter_status ( $post_id ); alo_em_delete_cache_recipients ( $post_id ); } else { return $post_id; // don't save, exit } } // Save Recipients $recipients = array (); if ( isset( $_POST['easymail-recipients-all-regusers'] ) ) { $recipients['registered'] = "1"; } if ( isset( $_POST['easymail-recipients-all-subscribers'] ) ) { $recipients['subscribers'] = "1"; } else { if ( isset($_POST['check_list']) && is_array ($_POST['check_list']) ) { foreach ( $_POST['check_list'] as $list ) { $recipients['list'][] = $list; } } } if ( isset($_POST['check_lang']) && is_array ($_POST['check_lang']) ) { foreach ( $_POST['check_lang'] as $lang ) { $recipients['lang'][] = $lang; } } // Save! delete_post_meta ( $post_id, "_easymail_recipients" ); add_post_meta ( $post_id, "_easymail_recipients", $recipients ); // If required, create list of recipient now, without ajax if ( get_option('alo_em_js_rec_list') == "no_ajax_onsavepost" && alo_em_count_recipients_from_meta( $post_id ) > 0 ) { alo_em_create_cache_recipients( $post_id ); alo_em_add_recipients_from_cache_to_db( $post_id, alo_em_count_recipients_from_meta( $post_id ), false ); } } add_action('save_post', 'alo_em_save_newsletter_meta'); /** * When a Newsletter is deleted: eg. delete recipients from db table */ function alo_em_newsletter_deleted ( $post_id ) { alo_em_delete_newsletter_recipients( $post_id ); } add_action( 'delete_post', 'alo_em_newsletter_deleted' ); /** * Add a dashboard widget */ function alo_em_dashboard_widget_function() { global $wpdb; echo "

". __("Newsletters scheduled for sending", "alo-easymail").": ". alo_em_count_newsletters_by_status( 'sendable' ) ."

"; $newsletter = alo_em_get_newsletters_in_queue( 1 ); if ( $newsletter ) { echo "

"; echo ''; echo " " . stripslashes ( alo_em___( $newsletter[0]->post_title ) ) ."
"; echo __("Progress", "alo-easymail") .": " . alo_em_newsletter_recipients_percentuage_already_sent( $newsletter[0]->ID ) . " %
" ; echo "".__("Added on", "alo-easymail") . " ". date_i18n( __( 'j M Y @ G:i', "alo-easymail" ), strtotime( $newsletter[0]->post_date ) ) . " - "; echo __("Scheduled by", "alo-easymail") . " ". get_user_meta($newsletter[0]->post_author, 'nickname',true). ""; echo "

"; } else { echo "

". __("There are no newsletters in queue", "alo-easymail") . ".

"; } echo "

". __("Subscribers", "alo-easymail") ."

"; list ( $total, $active, $noactive ) = alo_em_count_subscribers (); if ($total) { echo "

". sprintf( __("There are %d subscribers: %d activated, %d not activated", "alo-easymail"), $total, $active, $noactive ) . ".

"; } else { echo "

". __("No subscribers", "alo-easymail") . ".

"; } if ( current_user_can('administrator') ) { echo "
". __("Updates from plugin developer", "alo-easymail") ."
"; $rss = fetch_feed( 'http://www.eventualo.net/blog/category/alo-easymail-newsletter/feed/' ); if ( !is_wp_error( $rss ) ) { $maxitems = $rss->get_item_quantity( 3 ); $rss_items = $rss->get_items(0, $maxitems); echo "