» Please visit plugin site for more info and feedback: www.eventualo.net

» If you use this plugin consider the idea of donating and supporting its development:


"); define("ALO_EM_INTERVAL_MIN", 10); // cron interval in minutes (default: 10) (NOTE: to apply the change you need to reactivate the plugin) define("ALO_EM_PLUGIN_DIR", basename(dirname(__FILE__)) ); define("ALO_EM_PLUGIN_URL", WP_PLUGIN_URL ."/" . ALO_EM_PLUGIN_DIR ); /** * Required functions */ require_once( 'alo-easymail_functions.php'); /** * On plugin activation */ function ALO_em_install() { global $wpdb, $wp_roles; if (!get_option('ALO_em_template')) add_option('ALO_em_template', 'Hi [USER-NAME],

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', 1500); if (!get_option('ALO_em_batchrate')) add_option('ALO_em_batchrate', 60); 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_optin_msg')) add_option('ALO_em_optin_msg', '' ); if (!get_option('ALO_em_optout_msg')) add_option('ALO_em_optout_msg', ''); if (!get_option('ALO_em_lists_msg')) add_option('ALO_em_lists_msg', ''); update_option('ALO_em_import_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'); require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); //------------------------------------------------------------------------- // TO MODIFY IF UPDATE NEEDED $database_version = '1.25'; // Db version $installed_db = get_option('ALO_em_db_version'); //if ( $database_version != $installed_db ) { $table_name = $wpdb->prefix . "easymail_subscribers"; if($wpdb->get_var("show tables like '$table_name'") != $table_name || $database_version != $installed_db) { if( defined( 'DB_COLLATE' ) && constant( 'DB_COLLATE' ) != '' ) { $collate = constant( 'DB_COLLATE' ); } else { $collate = constant( 'DB_CHARSET' ); } // Create the table structure $sql = "CREATE TABLE ".$table_name." ( 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 '_', PRIMARY KEY (ID), UNIQUE KEY `email` (`email`) ) DEFAULT CHARSET=".$collate."; CREATE TABLE {$wpdb->prefix}easymail_sendings ( ID int(11) unsigned NOT NULL auto_increment, start_at datetime DEFAULT NULL, last_at datetime DEFAULT NULL, user int(11) unsigned DEFAULT NULL, subject varchar(250) DEFAULT NULL, content text DEFAULT NULL, recipients longtext DEFAULT NULL, tracking varchar(10) DEFAULT NULL, sent INT( 1 ) NOT NULL DEFAULT '0', PRIMARY KEY (ID) ) DEFAULT CHARSET=".$collate."; CREATE TABLE {$wpdb->prefix}easymail_trackings ( ID int(11) unsigned NOT NULL auto_increment, newsletter int(11) unsigned DEFAULT NULL, email varchar(100) NOT NULL, type varchar(10) DEFAULT NULL, PRIMARY KEY (ID) ) DEFAULT CHARSET=".$collate."; "; dbDelta($sql); update_option( "ALO_em_db_version", $database_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) { // if exists update $my_page['ID'] = $my_page_id; wp_update_post($my_page); } else { // 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' ); /* hourly */ // 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'); $wp_roles->add_cap( 'editor', 'send_easymail_newsletters'); } register_activation_hook(__FILE__,'ALO_em_install'); /** * 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 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'); // delete scheduled cleaner wp_clear_scheduled_hook('ALO_em_schedule'); // delete cron batch sending wp_clear_scheduled_hook('ALO_em_batch'); // if required delete all plugin data (options, db tables) if ( get_option('ALO_em_delete_on_uninstall') == "yes" ) { $tables = array ( "easymail_sendings", "easymail_subscribers", "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%'" ); } // 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'); } } register_deactivation_hook( __FILE__, 'ALO_em_uninstall' ); /** * Add menu pages */ function ALO_em_add_admin_menu() { add_options_page( __("Newsletter", "alo-easymail") , __("Newsletter", "alo-easymail"), 'manage_easymail_options', 'alo-easymail/alo-easymail_options.php'); add_management_page ( __("Send newsletter", "alo-easymail"), __("Send newsletter", "alo-easymail"), 'send_easymail_newsletters', 'alo-easymail/alo-easymail_main.php'); add_submenu_page('users.php', __("Newsletter subscribers", "alo-easymail"), __("Newsletter subscribers", "alo-easymail"), 'manage_easymail_subscribers', 'alo-easymail/alo-easymail_subscribers.php'); } add_action('admin_menu', 'ALO_em_add_admin_menu'); //>>>>>>>>>>>>>>> added GAL require_once('alo-easymail-widget.php'); add_action( 'show_user_profile', 'ALO_em_user_profile_optin' ); add_action( 'edit_user_profile', 'ALO_em_user_profile_optin' ); 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"; $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( 'personal_options_update', 'ALO_em_save_profile_optin' ); add_action( 'edit_user_profile_update', 'ALO_em_save_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") { ALO_em_add_subscriber( $user_email, $user_info->first_name ." ".$user_info->first_name, 1); // 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) ); } } } // Widget activation add_action( 'widgets_init', 'ALO_em_load_widgets' ); function ALO_em_load_widgets() { register_widget( 'ALO_Easymail_Widget' ); } //<<<<<<<<<<<<<<< end added GAL /** * Add javascript on admin side */ function ALO_add_admin_js() { if (isset($_GET['page']) && $_GET['page'] == "alo-easymail/alo-easymail_options.php") { wp_enqueue_script('jquery-ui-tabs'); echo ''."\n"; } } add_action('admin_print_scripts', 'ALO_add_admin_js' ); /** * Add TinyMCE on admin side * http://blog.zen-dreams.com/en/2009/06/30/integrate-tinymce-into-your-wordpress-plugins/ */ function ALO_em_show_tinymce () { if (isset($_GET['page']) ) { switch ( $_GET['page'] ) { case "alo-easymail/alo-easymail_main.php": case "alo-easymail/alo-easymail_options.php": 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'); if (function_exists('wp_tiny_mce')) wp_tiny_mce(); wp_admin_css(); wp_enqueue_script('utils'); do_action("admin_print_styles-post-php"); do_action('admin_print_styles'); wp_enqueue_script( 'jquery-form' ); // extra } } } add_filter('admin_head','ALO_em_show_tinymce'); /** * Load scripts & styles */ 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' ); } } } add_action('wp_enqueue_scripts', 'ALO_em_load_scripts'); /** * 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_exclude_page'); // load localization files load_plugin_textdomain ("alo-easymail", false, "alo-easymail/languages"); } add_action( 'init', 'ALO_em_init_method' ); function ALO_exclude_page( $pages ) { 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(ABSPATH . 'wp-content/plugins/alo-easymail/easymail-subscr-page.php'); $contents = ob_get_contents(); ob_end_clean(); return $contents; } add_shortcode('ALO-EASYMAIL-PAGE', 'ALO_em_subscr_page'); /** * Add to favorites top menu */ function ALO_em_add_favorite ($actions) { if ( current_user_can( "send_easymail_newsletters") ) { $actions['edit.php?page=alo-easymail/alo-easymail_main.php'] = array( __("Newsletters", "alo-easymail") , 'send_easymail_newsletters' ); } return $actions; } add_filter('favorite_actions', 'ALO_em_add_favorite', 10000); // inspired by http://wordpress.org/extend/plugins/favorites-menu-manager/ /** * Add a dashboard widget */ function ALO_em_dashboard_widget_function() { global $wpdb; echo "

". __("Newsletters scheduled for sending", "alo-easymail")."

"; $news_on_queue = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}easymail_sendings WHERE sent = 0 ORDER BY ID ASC LIMIT 4"); if (count($news_on_queue)) { 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") . ".

"; } } function ALO_em_add_dashboard_widgets() { if ( current_user_can ( 'manage_easymail_subscribers' ) && current_user_can ( 'manage_easymail_newsletters' ) ) { wp_add_dashboard_widget('alo-easymail-widget', 'EasyMail Newsletter', 'ALO_em_dashboard_widget_function'); } } add_action('wp_dashboard_setup', 'ALO_em_add_dashboard_widgets' ); /** * SHOW the optin/optout on registration form */ function ALO_em_show_registration_optin () { echo '

'; echo '

'; } add_action('register_form','ALO_em_show_registration_optin'); /** * SAVE the optin/optout on registration form */ function ALO_em_save_registration_optin ($user_id, $password="", $meta=array()) { $user = get_userdata($user_id); if (!empty($user->first_name) && !empty($user->last_name)) { $name = $user->first_name.' '.$user->last_name; } else { $name = $user->display_name; } if ( isset ($_POST['alo_em_opt']) && $_POST['alo_em_opt'] == "yes" ) { ALO_em_add_subscriber( $user->user_email, $name , 1); } } add_action( 'user_register', 'ALO_em_save_registration_optin' ); ?>