main_file = str_replace('-class', '', __FILE__); $this->plugin_url = WP_PLUGIN_URL . '/' . basename(dirname($this->main_file)); if (strpos($this->plugin_url, 'http') === 0 && is_ssl()) $this->plugin_url = str_replace('http://', 'https://', $this->plugin_url); // Register (de)activation hook register_activation_hook($this->main_file, array(&$this, 'Activate')); register_deactivation_hook($this->main_file, array(&$this, 'Deactivate')); // Register actions add_action('init', array(&$this, 'Init'), 0); if (is_admin()) { if (WPShortcodeExecPHP::Is_multisite() && is_plugin_active_for_network(plugin_basename($this->main_file)) && version_compare($wp_version, '3.1') >= 0) add_action('network_admin_menu', array(&$this, 'Admin_menu_network')); else add_action('admin_menu', array(&$this, 'Admin_menu')); add_action('wp_ajax_scep_ajax', array(&$this, 'Check_ajax')); } // Enable shortcodes for widgets if (WPShortcodeExecPHP::Get_option(c_scep_option_widget)) add_filter('widget_text', 'do_shortcode'); // Enable shortcodes for excerpts if (WPShortcodeExecPHP::Get_option(c_scep_option_excerpt)) { add_filter('the_excerpt', 'do_shortcode'); if (WPShortcodeExecPHP::Get_option(c_scep_option_comment)) add_filter('comment_excerpt', 'do_shortcode'); } // Enable shortcodes for comments if (WPShortcodeExecPHP::Get_option(c_scep_option_comment)) add_filter('comment_text', 'do_shortcode'); // Enable shortcodes for RSS if (WPShortcodeExecPHP::Get_option(c_scep_option_rss)) { if (version_compare($wp_version, '2.9') < 0) add_filter('the_content_rss', 'do_shortcode'); else add_filter('the_content_feed', 'do_shortcode'); if (WPShortcodeExecPHP::Get_option(c_scep_option_excerpt)) add_filter('the_excerpt_rss', 'do_shortcode'); if (WPShortcodeExecPHP::Get_option(c_scep_option_comment)) add_filter('comment_text_rss', 'do_shortcode'); } // Wire shortcode handlers $name = WPShortcodeExecPHP::Get_option(c_scep_option_names); for ($i = 0; $i < count($name); $i++) if (WPShortcodeExecPHP::Get_option(c_scep_option_enabled . $name[$i])) add_shortcode($name[$i], array(&$this, 'Shortcode_handler')); $this->default_backtrack_limit = ini_get('pcre.backtrack_limit'); $this->default_recursion_limit = ini_get('pcre.recursion_limit'); $this->Configure_prce(); } function Configure_prce() { $backtrack_limit = WPShortcodeExecPHP::Get_option(c_scep_option_backtrack_limit); if ($backtrack_limit < $this->default_backtrack_limit) $backtrack_limit = $this->default_backtrack_limit; @ini_set('pcre.backtrack_limit', $backtrack_limit); $recursion_limit = WPShortcodeExecPHP::Get_option(c_scep_option_recursion_limit); if ($recursion_limit < $this->default_recursion_limit) $recursion_limit = $this->default_recursion_limit; @ini_set('pcre.recursion_limit', $recursion_limit); } function Init() { if (is_admin()) { // I18n load_plugin_textdomain(c_scep_text_domain, false, dirname(plugin_basename(__FILE__))); // Enqueue scripts wp_enqueue_script('jquery'); $plugin_dir = '/' . PLUGINDIR . '/' . basename(dirname($this->main_file)); wp_enqueue_script('editarea', $plugin_dir . '/editarea/edit_area/edit_area_full.js'); // Enqueue style sheet $css_name = $this->Change_extension(basename($this->main_file), '.css'); if (file_exists(WP_CONTENT_DIR . '/uploads/' . $css_name)) $css_url = WP_CONTENT_URL . '/uploads/' . $css_name; else if (file_exists(TEMPLATEPATH . '/' . $css_name)) $css_url = get_bloginfo('template_directory') . '/' . $css_name; else $css_url = $this->plugin_url . '/' . $css_name; wp_register_style('scep_style', $css_url); wp_enqueue_style('scep_style'); // Make sure capabilities are set if (!WPShortcodeExecPHP::Get_option(c_scep_option_tinymce_cap)) WPShortcodeExecPHP::Update_option(c_scep_option_tinymce_cap, 'edit_posts'); if (!WPShortcodeExecPHP::Get_option(c_scep_option_author_cap)) WPShortcodeExecPHP::Update_option(c_scep_option_author_cap, 'edit_posts'); // http://codex.wordpress.org/TinyMCE_Custom_Buttons if (WPShortcodeExecPHP::Get_option(c_scep_option_tinymce) && current_user_can(WPShortcodeExecPHP::Get_option(c_scep_option_tinymce_cap)) && current_user_can(WPShortcodeExecPHP::Get_option(c_scep_option_author_cap))) if (current_user_can('edit_posts') || current_user_can('edit_pages')) if (get_user_option('rich_editing') == 'true') { add_filter('tiny_mce_version', array(&$this, 'TinyMCE_version') ); add_filter('mce_external_plugins', array(&$this, 'TinyMCE_plugin')); add_filter('mce_buttons', array(&$this, 'TinyMCE_button')); } } } // Handle plugin activation function Activate() { if (!WPShortcodeExecPHP::Get_option(c_scep_option_codewidth)) WPShortcodeExecPHP::Update_option(c_scep_option_codewidth, 600); if (!WPShortcodeExecPHP::Get_option(c_scep_option_codeheight)) WPShortcodeExecPHP::Update_option(c_scep_option_codeheight, 200); if (!WPShortcodeExecPHP::Get_option(c_scep_option_names)) { // Define example shortcode $name = array(); $name[] = 'hello_world'; WPShortcodeExecPHP::Update_option(c_scep_option_names, $name); WPShortcodeExecPHP::Update_option(c_scep_option_enabled . $name[0], true); WPShortcodeExecPHP::Update_option(c_scep_option_buffer . $name[0], true); WPShortcodeExecPHP::Update_option(c_scep_option_description . $name[0], 'Example'); $phpcode = "extract(shortcode_atts(array('arg' => 'default'), \$atts));" . PHP_EOL; $phpcode .= "echo \"Hello world!\" . PHP_EOL;" . PHP_EOL; $phpcode .= "echo \"Arg=\" . \$arg . PHP_EOL;" . PHP_EOL; $phpcode .= "echo \"Content=\" . \$content . PHP_EOL;" . PHP_EOL; WPShortcodeExecPHP::Update_option(c_scep_option_phpcode . $name[0], $phpcode); } // Fix spelling mistake if (WPShortcodeExecPHP::Get_option('scep_backtrace_limit')) { WPShortcodeExecPHP::Update_option(c_scep_option_backtrack_limit, WPShortcodeExecPHP::Get_option('scep_backtrace_limit')); WPShortcodeExecPHP::Delete_option('scep_backtrace_limit'); } if (!WPShortcodeExecPHP::Get_option(c_scep_option_tinymce_cap)) WPShortcodeExecPHP::Update_option(c_scep_option_tinymce_cap, 'edit_posts'); if (!WPShortcodeExecPHP::Get_option(c_scep_option_author_cap)) WPShortcodeExecPHP::Update_option(c_scep_option_author_cap, 'edit_posts'); } // Handle plugin deactivation function Deactivate() { // Cleanup if requested if (WPShortcodeExecPHP::Get_option(c_scep_option_cleanup)) { delete_site_option(c_scep_option_global); WPShortcodeExecPHP::Delete_option(c_scep_option_widget); WPShortcodeExecPHP::Delete_option(c_scep_option_excerpt); WPShortcodeExecPHP::Delete_option(c_scep_option_comment); WPShortcodeExecPHP::Delete_option(c_scep_option_rss); WPShortcodeExecPHP::Delete_option(c_scep_option_noent); WPShortcodeExecPHP::Delete_option(c_scep_option_codewidth); WPShortcodeExecPHP::Delete_option(c_scep_option_codeheight); WPShortcodeExecPHP::Delete_option(c_scep_option_editarea_later); WPShortcodeExecPHP::Delete_option(c_scep_option_backtrack_limit); WPShortcodeExecPHP::Delete_option(c_scep_option_recursion_limit); WPShortcodeExecPHP::Delete_option(c_scep_option_cleanup); WPShortcodeExecPHP::Delete_option(c_scep_option_donated); $name = WPShortcodeExecPHP::Get_option(c_scep_option_names); for ($i = 0; $i < count($name); $i++) { WPShortcodeExecPHP::Delete_option(c_scep_option_enabled . $name[$i]); WPShortcodeExecPHP::Delete_option(c_scep_option_buffer . $name[$i]); WPShortcodeExecPHP::Delete_option(c_scep_option_description . $name[$i]); WPShortcodeExecPHP::Delete_option(c_scep_option_param . $name[$i]); WPShortcodeExecPHP::Delete_option(c_scep_option_phpcode . $name[$i]); } WPShortcodeExecPHP::Delete_option(c_scep_option_names); } } // Admin head function Admin_head() { // Initialize EditArea $name = WPShortcodeExecPHP::Get_option(c_scep_option_names); $display = WPShortcodeExecPHP::Get_option(c_scep_option_editarea_later) ? 'later' : 'onload'; echo '' . PHP_EOL; } // Register options page function Admin_menu() { if (WPShortcodeExecPHP::Is_multisite()) { if (function_exists('add_submenu_page')) $plugin_page = add_submenu_page( 'wpmu-admin.php', __('Shortcode Exec PHP Administration', c_scep_text_domain), __('Shortcode Exec PHP', c_scep_text_domain), 'manage_network', $this->main_file, array(&$this, 'Administration')); } else { if (function_exists('add_options_page')) $plugin_page = add_options_page( __('Shortcode Exec PHP Administration', c_scep_text_domain), __('Shortcode Exec PHP', c_scep_text_domain), 'manage_options', $this->main_file, array(&$this, 'Administration')); if (function_exists('add_submenu_page')) $tools_page = add_submenu_page( 'tools.php', __('Shortcode Exec PHP Administration', c_scep_text_domain), __('Shortcode Exec PHP', c_scep_text_domain), 'manage_options', $this->main_file, array(&$this, 'Administration')); } // Hook admin head for option page if (!empty($plugin_page)) add_action('admin_head-' . $plugin_page, array(&$this, 'Admin_head')); if (!empty($tools_page)) add_action('admin_head-' . $tools_page, array(&$this, 'Admin_head')); } function Admin_menu_network() { if (function_exists('add_submenu_page')) $plugin_page = add_submenu_page( 'settings.php', __('Shortcode Exec PHP Administration', c_scep_text_domain), __('Shortcode Exec PHP', c_scep_text_domain), 'manage_network', $this->main_file, array(&$this, 'Administration')); // Hook admin head for option page if (!empty($plugin_page)) add_action('admin_head-' . $plugin_page, array(&$this, 'Admin_head')); } // Handle option page function Administration() { // Secirity check if (!current_user_can(WPShortcodeExecPHP::Is_multisite() ? 'manage_network' : 'manage_options')) die('Unauthorized'); // Check post back if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { // Check security check_admin_referer(c_scep_nonce_form); if (empty($_POST[c_scep_option_global])) $_POST[c_scep_option_global] = null; if (empty($_POST[c_scep_option_widget])) $_POST[c_scep_option_widget] = null; if (empty($_POST[c_scep_option_excerpt])) $_POST[c_scep_option_excerpt] = null; if (empty($_POST[c_scep_option_comment])) $_POST[c_scep_option_comment] = null; if (empty($_POST[c_scep_option_rss])) $_POST[c_scep_option_rss] = null; if (empty($_POST[c_scep_option_noent])) $_POST[c_scep_option_noent] = null; if (empty($_POST[c_scep_option_editarea_later])) $_POST[c_scep_option_editarea_later] = null; if (empty($_POST[c_scep_option_tinymce])) $_POST[c_scep_option_tinymce] = null; if (empty($_POST[c_scep_option_cleanup])) $_POST[c_scep_option_cleanup] = null; if (empty($_POST[c_scep_option_donated])) $_POST[c_scep_option_donated] = null; // Update settings if (WPShortcodeExecPHP::Is_multisite() && function_exists('update_site_option')) update_site_option(c_scep_option_global, $_POST[c_scep_option_global]); WPShortcodeExecPHP::Update_option(c_scep_option_widget, $_POST[c_scep_option_widget]); WPShortcodeExecPHP::Update_option(c_scep_option_excerpt, $_POST[c_scep_option_excerpt]); WPShortcodeExecPHP::Update_option(c_scep_option_comment, $_POST[c_scep_option_comment]); WPShortcodeExecPHP::Update_option(c_scep_option_rss, $_POST[c_scep_option_rss]); WPShortcodeExecPHP::Update_option(c_scep_option_noent, $_POST[c_scep_option_noent]); WPShortcodeExecPHP::Update_option(c_scep_option_codewidth, trim($_POST[c_scep_option_codewidth])); WPShortcodeExecPHP::Update_option(c_scep_option_codeheight, trim($_POST[c_scep_option_codeheight])); WPShortcodeExecPHP::Update_option(c_scep_option_editarea_later, $_POST[c_scep_option_editarea_later]); WPShortcodeExecPHP::Update_option(c_scep_option_backtrack_limit, trim($_POST[c_scep_option_backtrack_limit])); WPShortcodeExecPHP::Update_option(c_scep_option_recursion_limit, trim($_POST[c_scep_option_recursion_limit])); WPShortcodeExecPHP::Update_option(c_scep_option_tinymce, $_POST[c_scep_option_tinymce]); WPShortcodeExecPHP::Update_option(c_scep_option_tinymce_cap, $_POST[c_scep_option_tinymce_cap]); WPShortcodeExecPHP::Update_option(c_scep_option_author_cap, $_POST[c_scep_option_author_cap]); WPShortcodeExecPHP::Update_option(c_scep_option_cleanup, $_POST[c_scep_option_cleanup]); WPShortcodeExecPHP::Update_option(c_scep_option_donated, $_POST[c_scep_option_donated]); $this->Configure_prce(); // Copy options to site wide if ($_POST[c_scep_option_global] && WPShortcodeExecPHP::Is_multisite() && function_exists('update_site_option')) { $name = get_option(c_scep_option_names); update_site_option(c_scep_option_names, $name); for ($i = 0; $i < count($name); $i++) { update_site_option(c_scep_option_enabled . $name[$i], get_option(c_scep_option_enabled . $name[$i])); update_site_option(c_scep_option_buffer . $name[$i], get_option(c_scep_option_buffer . $name[$i])); update_site_option(c_scep_option_description . $name[$i], get_option(c_scep_option_description . $name[$i])); update_site_option(c_scep_option_param . $name[$i], get_option(c_scep_option_param . $name[$i])); update_site_option(c_scep_option_phpcode . $name[$i], get_option(c_scep_option_phpcode . $name[$i])); } } echo '
' . __('Settings updated', c_scep_text_domain) . '
| [shortcode arg="value"] | extract(shortcode_atts(array('arg' => 'default'), $atts)); |
| [shortcode]content[/shortcode] | $content |