'."\n"; } if ( $pagenow == "post.php" || ( isset( $_GET['post_type'] ) && $_GET['post_type'] == "newsletter" ) ) { //edit : added all this "$code" related lines $alo_em_cf = alo_easymail_get_custom_fields(); $code = ''; echo $code; wp_enqueue_script( 'json2' ); wp_enqueue_script( 'jquery', false, array( 'json2' ) ); wp_enqueue_script( 'thickbox' ); wp_enqueue_script( 'alo-easymail-smartupdater', ALO_EM_PLUGIN_URL . '/inc/smartupdater.js', array('jquery'), '3.2.00' ); //wp_enqueue_script( 'alo-easymail-backend-recipients-list', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend-recipients-list.js' ); wp_enqueue_style( 'alo-easymail-backend-css', ALO_EM_PLUGIN_URL.'/inc/alo-easymail-backend.css' ); wp_enqueue_script ( 'jquery-ui-dialog' ); wp_enqueue_script ( 'jquery-ui-resizable' ); wp_enqueue_script ( 'jquery-ui-draggable' ); wp_enqueue_style ( 'wp-jquery-ui-dialog'); wp_enqueue_script( 'alo-easymail-backend', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend.js', array( 'jquery' ) ); wp_localize_script( 'alo-easymail-backend', 'easymailJs', alo_em_localize_admin_script() ); } if ( $pagenow == "index.php" ) { wp_enqueue_script( 'alo-easymail-backend-index', ALO_EM_PLUGIN_URL . '/inc/alo-easymail-backend-index.js', array( 'jquery' ) ); wp_localize_script( 'alo-easymail-backend-index', 'easymailJsIndex', array( 'errGeneric' => esc_js( __("Error during operation.", "alo-easymail") ) ) ); } } 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' ), 'errGeneric' => esc_js( __("Error during operation.", "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") ), 'confirmDelSubscriberAndUnsubscribe'=> esc_js( __("Do you really want to DELETE this subscriber?", "alo-easymail").' '. __("The email address will be added to the list of who unsubscribed", "alo-easymail") .": ". __("so you cannot add or import these email addresses using the tools in admin pages", "alo-easymail") ), 'txtClose' => esc_js( __("close", "alo-easymail") ), 'titleRecListModal' => esc_js( __( 'Create list of recipients', "alo-easymail") ), 'txt_success_added' => esc_js( __( 'Recipients successfully added', "alo-easymail" ) ), 'txt_success_sent' => esc_js( __( 'Newsletter successfully sent to recipients', "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' ); /** * Add menu pages */ function alo_em_add_admin_menu() { if ( current_user_can('manage_newsletter_subscribers') ) { add_submenu_page( 'edit.php?post_type=newsletter', __("Subscribers", "alo-easymail"), __("Subscribers", "alo-easymail"), 'manage_newsletter_subscribers', 'alo-easymail/pages/alo-easymail-admin-subscribers.php' ); add_action( 'load-alo-easymail/pages/alo-easymail-admin-subscribers.php', 'alo_em_contextual_help_tabs' ); } if ( current_user_can('manage_newsletter_options') ) { add_submenu_page( 'edit.php?post_type=newsletter', __("Settings"), __("Settings"), 'manage_newsletter_options', 'alo-easymail/pages/alo-easymail-admin-options.php' ); add_action( 'load-alo-easymail/pages/alo-easymail-admin-options.php', 'alo_em_contextual_help_tabs' ); } add_action( 'load-edit.php', 'alo_em_contextual_help_tabs' ); add_action( 'load-post-new.php', 'alo_em_contextual_help_tabs' ); } add_action('admin_menu', 'alo_em_add_admin_menu'); /* * Add some links on the plugin page */ function alo_em_add_plugin_links($links, $file) { if ( $file == 'alo-easymail/alo-easymail.php' ) { $links[] = 'Guide'; $links[] = 'Faq'; $links[] = 'News'; $links[] = 'Forum'; } return $links; } add_filter( 'plugin_row_meta', 'alo_em_add_plugin_links', 10, 2 ); /** * 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 && current_user_can( "manage_newsletter_subscribers" )) { $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 ); $_POST = array_map( 'strip_tags', $_POST ); $_POST = array_map( 'stripslashes_deep', $_POST ); $new_name = ( isset( $_POST['new_name'] ) ) ? 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; $fields = array(); // to be saved //edit : added the following foreach and its content $alo_em_cf = alo_easymail_get_custom_fields(); if ($alo_em_cf) { foreach( $alo_em_cf as $key => $value ){ $var_name = "new_".$key; //$fields[$key] = ( isset( $_POST[$var_name] ) ) ? stripslashes( trim ( $_POST[$var_name] ) ): false; //$fields[$key] = false; if ( !empty( $_POST[$var_name] ) ) { switch ( $value['input_type'] ) { case "checkbox": $fields[$key] = 1; break; default: $fields[$key] = sanitize_text_field( trim ( $_POST[$var_name] ) ); } } else { switch ( $value['input_type'] ) { case "checkbox": $fields[$key] = 0; break; default: $fields[$key] = 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 ) { //$fields['old_email'] = $subscriber_obj->email; //edit : added all this line $fields['email'] = $new_email; //edit : added all this line $fields['name'] = $new_name; //edit : added all this line alo_em_update_subscriber_by_email ( $subscriber_obj->email, $fields, $new_active, $new_lang, false ); //edit : orig : 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': // If required, add email in unsubscribed db table if ( isset($_POST['to_unsubscribe']) && $_POST['to_unsubscribe'] == 1 ) { $subscriber_obj = alo_em_get_subscriber_by_id( $subscriber ); alo_em_add_email_in_unsubscribed ( $subscriber_obj->email ); } // 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'); /** * 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('manage_options') ) { echo "
". __("Updates from plugin developer", "alo-easymail") ."
"; echo ''; } } function alo_em_add_dashboard_widgets() { if ( current_user_can ( 'manage_newsletter_subscribers' ) && current_user_can ( 'edit_others_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' ); /** * Add Newsletter menu in Toolbar Admin bar (WP 3.1-3.2) */ function alo_em_add_menu_toolbar( $wp_admin_bar ) { if ( current_user_can('edit_newsletters') ) { $ico = ' '; $args = array('id' => 'alo_easymail', 'title' => $ico. __( 'Newsletters', "alo-easymail" ), 'parent' => false, 'href' => admin_url('edit.php')."?post_type=newsletter" ); $wp_admin_bar->add_node($args); $args = array('id' => 'alo_easymail-all', 'title' => __( 'Newsletters', "alo-easymail" ), 'parent' => 'alo_easymail', 'href' => admin_url('edit.php')."?post_type=newsletter" ); $wp_admin_bar->add_node($args); $args = array('id' => 'alo_easymail-new', 'title' => __( 'Add New', "alo-easymail" ), 'parent' => 'alo_easymail', 'href' => admin_url('post-new.php')."?post_type=newsletter" ); $wp_admin_bar->add_node($args); if ( current_user_can('manage_newsletter_subscribers') ) { $args = array('id' => 'alo_easymail-subscribers', 'title' => __( 'Subscribers', "alo-easymail" ), 'parent' => 'alo_easymail', 'href' => admin_url('edit.php')."?post_type=newsletter&page=alo-easymail/pages/alo-easymail-admin-subscribers.php" ); $wp_admin_bar->add_node($args); } if ( current_user_can('manage_newsletter_options') ) { $args = array('id' => 'alo_easymail-settings', 'title' => __( "Settings" ), 'parent' => 'alo_easymail', 'href' => admin_url('edit.php')."?post_type=newsletter&page=alo-easymail/pages/alo-easymail-admin-options.php" ); $wp_admin_bar->add_node($args); } } } add_action( 'admin_bar_menu', 'alo_em_add_menu_toolbar', 45 ); /** * Alert in admin panel */ function alo_em_admin_notice() { global $pagenow; $page = ( isset( $_GET['page'] ) ) ? $_GET['page'] : false; if ( $pagenow == "edit.php" && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'newsletter' && $page != 'alo-easymail/pages/alo-easymail-admin-subscribers.php' ) { if ( get_option('ALO_em_debug_newsletters') != "" ) { echo '
'; echo '

'. __("Debug mode is activated", "alo-easymail") .": "; if ( get_option('ALO_em_debug_newsletters') == "to_author" ) _e("all messages will be sent to the newsletter author", "alo-easymail"); if ( get_option('ALO_em_debug_newsletters') == "to_file" ) _e("all messages will be recorded into a log file", "alo-easymail"); echo ".

"; echo '
'; } } if ( alo_em_db_tables_need_update() ) { echo '
'; echo '

'. __("ALO Easymail Newsletter needs attention", "alo-easymail") ."!
"; echo __("The plugin database tables have not properly installed", "alo-easymail") .": " . __("you can try to deactivate and activate the plugin", "alo-easymail")."."; echo "
". __("For more info, visit the FAQ of the site.", "alo-easymail").""; echo ".

"; echo '
'; } } add_action('admin_notices', "alo_em_admin_notice"); /** * Html row of a Subscriber in subscriber table */ function alo_em_get_subscriber_table_row ( $subscriber_id, $row_index=0, $edit=false, $all_lists=false, $all_langs=false ) { if ( empty( $subscriber_id ) ) return false; $subscriber = alo_em_get_subscriber_by_id( $subscriber_id ); $html = ""; //$html .= "\n"; $html .= "". $row_index . "\n"; $html .= ""; $html .= "\n"; $html .= "\n"; if ( get_option('show_avatars') ) { $html .= "" . get_avatar($subscriber->email, 30). " "; } $html .= ""; if ( $edit ) { $html .= "email ) . "\" />\n"; } else { $html .= esc_html($subscriber->email); } $html .= " \n"; $html .= ""; if ( $edit ) { $html .= "name ). "\" />\n"; } else { $html .= esc_html($subscriber->name); } $html .= " \n"; //edit : added the following foreach and its content $alo_em_cf = alo_easymail_get_custom_fields(); if ($alo_em_cf) { foreach( $alo_em_cf as $key => $value ){ $field_id = "subscriber-".$subscriber_id."-".$key."-new"; // edit-by-alo: added $html .= ""; // edit-by-alo if ( $edit ) { $var_value = ""; if( ! empty( $subscriber->$key ) ){ $var_value = $subscriber->$key; } // edit-by-alo: added //$html .= sprintf( $value['edit_html'], $subscriber_id, $subscriber_id, format_to_edit( $var_value ) ); $html .= alo_easymail_custom_field_html ( $key, $value, $field_id, $var_value, true ); } else { $var_value = ""; // particular case: empty is a negative checkbox if( empty( $subscriber->$key ) && $value['input_type'] == 'checkbox' ) { $html .= alo_easymail_custom_field_html ( $key, $value, $field_id, $var_value, false ); } else if( ! empty( $subscriber->$key ) ){ $var_value = $subscriber->$key; $html .= alo_easymail_custom_field_html ( $key, $value, $field_id, $var_value, false ); } else { $html .= ""; } } $html .= " \n"; } } $html .= ""; $user_id = email_exists($subscriber->email); if ( !$user_id ) { $user_id = apply_filters ( 'alo_easymail_get_userid_by_subscriber', false, $subscriber ); // Hook } if ( $user_id ) { $user_info = get_userdata( $user_id ); if ( get_current_user_id() == $user_id ) { $profile_link = 'profile.php'; } else { $profile_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), "user-edit.php?user_id={$user_id}" ) ); } $html .= "{$user_info->user_login}"; } $html .= " \n"; $html .= "\n"; $join_date_datetime = date_i18n( __( "d/m/Y \h.H:i", "alo-easymail" ), strtotime( $subscriber->join_date ) ); $join_time_diff = sprintf( __( "%s ago", "alo-easymail" ), human_time_diff( strtotime( $subscriber->join_date ), current_time('timestamp') ) ); //$html .= $join_time_diff ." \"".\n"; $html .= "". $join_time_diff ."\n"; $html .= "\n"; $html .= "\n"; $last_act = !empty($subscriber->last_act) ? $subscriber->last_act : $subscriber->join_date; $last_act_datetime = date_i18n( __( "d/m/Y \h.H:i", "alo-easymail" ), strtotime( $last_act ) ); $last_act_diff = sprintf( __( "%s ago", "alo-easymail" ), human_time_diff( strtotime( $last_act ), current_time('timestamp') ) ); $html .= "". $last_act_diff ."\n"; if ( get_option('alo_em_collect_ip_address') == 'yes' && !empty($subscriber->ip_address) ) { $html .= "
ip_address}\" title=\"". esc_attr( $subscriber->ip_address .' @ whatismyipaddress.com') ."\" target=\"_blank\" class=\"ip-address\"/>IP ". $subscriber->ip_address ."\n"; } $html .= "\n"; $html .= "\n"; if ( $edit ) { $active_checked = ($subscriber->active == 1) ? " checked=\"checked\" ": ""; $html .= "\n"; } else { $html .= "active == 1) ? "yes.png":"no.png" ) ."\" />\n"; } $html .= "\n"; $html .= "\n"; $user_lists = alo_em_get_user_mailinglists ( $subscriber_id ); if ( $edit && is_array( $all_lists ) ) { foreach ( $all_lists as $list => $val ) { $checked = ( is_array( $user_lists ) && in_array( $list, $user_lists ) ) ? " checked=\"checked\" " : ""; $html .= "
\n"; } } else { if ( $user_lists && is_array ( $user_lists ) && $all_lists ) { $html .= "\n"; } } $html .= " \n"; $html .= "\n"; if ( $edit && is_array( $all_langs ) && !empty( $all_langs[0] ) ) { $html .= "\n"; } else { $html .= ( $subscriber->lang ) ? alo_em_get_lang_flag( $subscriber->lang, 'name') : ""; } $html .= " \n"; $html .= "\n"; // Actions $html .= "\n"; if ( $edit ) { $html .= "
"; $html .= "\n"; $html .= " "; $html .= "\n"; } else { $html .= ""; $html .= "\""."; $html .= " "; $html .= "\""."; $html .= " "; $html .= "\""."; } $html .= "\n"; return $html; } /* EOF */