$button ) { if ( $button == 'spellchecker' ) { $buttons[$key] = 'AtD'; return $buttons; } } /* hrm... ok add us last plz */ array_push( $buttons, 'separator', 'AtD' ); return $buttons; } /* * Load the TinyMCE plugin : editor_plugin.js (wp2.5) */ function add_AtD_tinymce_plugin( $plugin_array ) { $plugin_array['AtD'] = WP_PLUGIN_URL . '/after-the-deadline/tinymce/editor_plugin.js'; return $plugin_array; } /* * Update the TinyMCE init block with AtD specific settings */ function AtD_change_mce_settings( $init_array ) { /* grab our user and validate their existence */ $user = wp_get_current_user(); if ( ! $user || $user->ID == 0 ) return; $init_array['atd_rpc_url'] = admin_url() . 'admin-ajax.php?action=proxy_atd&url='; $init_array['atd_ignore_rpc_url'] = admin_url() . 'admin-ajax.php?action=atd_ignore&phrase='; $init_array['atd_rpc_id'] = defined('ATD_KEY') ? ATD_KEY : get_option('AtD_api_key'); $init_array['atd_theme'] = 'wordpress'; $init_array['atd_ignore_enable'] = 'true'; $init_array['atd_strip_on_get'] = 'true'; $init_array['atd_ignore_strings'] = AtD_get_setting( $user->ID, 'AtD_ignored_phrases' ); $init_array['atd_show_types'] = AtD_get_setting( $user->ID, 'AtD_options' ); $init_array['gecko_spellcheck'] = 'false'; return $init_array; } /* * Sanitizes AtD AJAX data to acceptable chars, caller needs to make sure ' is escaped */ function AtD_sanitize( $untrusted ) { return preg_replace( '/[^a-zA-Z0-9\-\', ]/i', "", $untrusted ); } /* * AtD HTML Editor Stuff */ function AtD_settings() { $user = wp_get_current_user(); header( 'Content-Type: text/javascript' ); /* set the RPC URL for AtD */ echo "AtD.rpc = '" . admin_url() . "admin-ajax.php?action=proxy_atd&url=';\n"; /* set the API key for AtD */ echo "AtD.api_key = '" . (defined('ATD_KEY') ? ATD_KEY : get_option('AtD_api_key')) . "';\n"; /* set the ignored phrases for AtD */ echo "AtD.setIgnoreStrings('" . str_replace( "'", "\\'", AtD_get_setting( $user->ID, 'AtD_ignored_phrases' ) ) . "');\n"; /* honor the types we want to show */ echo "AtD.showTypes('" . str_replace( "'", "\\'", AtD_get_setting( $user->ID, 'AtD_options' ) ) ."');\n"; /* this is not an AtD/jQuery setting but I'm putting it in AtD to make it easy for the non-viz plugin to find it */ echo "AtD.rpc_ignore = '" . admin_url() . "admin-ajax.php?action=atd_ignore&phrase=';\n"; die; } function AtD_load_javascripts() { global $pagenow; if ( AtD_should_load_on_page() ) { wp_enqueue_script( 'AtD_core', WP_PLUGIN_URL . '/after-the-deadline/atd.core.js', array() ); wp_enqueue_script( 'AtD_quicktags', WP_PLUGIN_URL . '/after-the-deadline/atd-nonvis-editor-plugin.js', array('quicktags') ); wp_enqueue_script( 'AtD_jquery', WP_PLUGIN_URL . '/after-the-deadline/jquery.atd.js', array('jquery') ); wp_enqueue_script( 'AtD_settings', admin_url() . 'admin-ajax.php?action=atd_settings', array('AtD_jquery') ); wp_enqueue_script( 'AtD_autoproofread', WP_PLUGIN_URL . '/after-the-deadline/atd-autoproofread.js', array('AtD_jquery') ); } } /* Spits out user options for auto-proofreading on publish/update */ function AtD_load_submit_check_javascripts() { global $pagenow; $user = wp_get_current_user(); if ( ! $user || $user->ID == 0 ) return; if ( AtD_should_load_on_page() ) { $atd_check_when = AtD_get_setting( $user->ID, 'AtD_check_when' ); if ($atd_check_when) { $check_when = ''; /* Set up the options in json */ foreach( explode( ',', $atd_check_when ) as $option ) { $check_when .= ($check_when ? ', ' : '') . $option . ': true'; } echo '' . "\n"; } } } function AtD_load_css() { if ( AtD_should_load_on_page() ) wp_enqueue_style( 'AtD_style', WP_PLUGIN_URL . '/after-the-deadline/atd.css', null, '1.0', 'screen' ); } /* Helper used to check if javascript should be added to page. Helps avoid bloat in admin */ function AtD_should_load_on_page() { global $pagenow; $pages = array('post.php', 'post-new.php', 'page.php', 'page-new.php', 'admin.php'); if( in_array($pagenow, $pages) ) return true; return false; } /* add some vars into the AtD plugin */ add_filter( 'tiny_mce_before_init', 'AtD_change_mce_settings' ); /* load some stuff for non-visual editor */ add_action( 'admin_print_scripts', 'AtD_load_javascripts' ); add_action( 'admin_print_scripts', 'AtD_load_submit_check_javascripts' ); add_action( 'admin_print_styles', 'AtD_load_css' ); /* init process for button control */ add_action( 'init', 'AtD_addbuttons' ); /* setup hooks for our PHP functions we want to make available via an AJAX call */ add_action( 'wp_ajax_proxy_atd', 'AtD_redirect_call' ); add_action( 'wp_ajax_atd_ignore', 'AtD_ignore_call' ); add_action( 'wp_ajax_atd_settings', 'AtD_settings' ); /* add the AtD menu under the plugins menu */ add_action( 'admin_menu', 'AtD_setup_admin_menu' ); /* load and install the localization stuff */ include( 'atd-l10n.php' );