_shared = array(); add_shortcode( 'php', array( __CLASS__, "shortcode" ) ); add_shortcode( 'PHP', array( __CLASS__, "shortcode" ) ); add_shortcode( 'allowphp', array( __CLASS__, "shortcode" ) ); add_shortcode( 'ALLOWPHP', array( __CLASS__, "shortcode" ) ); add_action( "admin_menu", array( __CLASS__, "menu_register" ) ); add_action( 'admin_init', array( __CLASS__, "menu_register_extras"),0); add_filter('widget_text', 'do_shortcode'); add_filter('the_content', array( __CLASS__, "shortcode_advanced" ),0); } function menu_register_extras(){ wp_register_style( self::$stylesheet_slug, plugins_url('additional-styles.css', __FILE__) ); } function menu_register(){ $page = add_menu_page( self::$menu_page_title, self::$menu_title, self::$capabilities, self::$menu_slug, array(__CLASS__, "menu_primary"), plugins_url("ap.png", __FILE__) ); $page2 = add_submenu_page( self::$menu_slug, self::$submenu_title, self::$submenu_page_title, self::$capabilities, self::$submenu_slug, array(__CLASS__, "menu_sub")); add_action( 'admin_print_styles-' . $page, array( __CLASS__, "menu_styles" ) ); add_action( 'admin_print_styles-' . $page2, array( __CLASS__, "menu_styles" ) ); } function menu_styles(){ wp_enqueue_style( self::$stylesheet_slug ); } function menu_primary(){ echo '
'; echo '

'.self::$plugin_title.'

'; self::check_post(); $option = self::option_get(); echo '

General Options

'; self::form_general_options($option); echo "

 

"; echo '

Code Snippets

'; $snippets = self::snippet_get_all(); foreach($snippets as $id=>$snippet){ echo "
"; echo "

Edit Snippet ID: ".$snippet->id."

"; echo "

Shortcode: [php function=".$snippet->id."]

"; self::form_edit_snippet($snippet); echo "
"; } echo "
"; echo "

ADD A NEW SNIPPET

"; echo "

Shortcode: [php][/php]

"; self::form_add_snippet(); echo "
"; echo '
'; } function menu_sub(){ echo '
'; echo '

' . self::$plugin_title . '

'; echo '

' . self::$submenu_title . '

'; include( "information.php" ); echo '
'; } function check_post(){ if( isset( $_REQUEST[self::$post_prefix] ) ){ $expected = array( "opt"=>array(), "action"=>"", "action_code" => "", "verification"=>""); $outcome = array_merge($expected, $_REQUEST[self::$post_prefix]); extract($outcome); if( wp_verify_nonce( $action_code, $action) ){ if($action === "update_plugin_options"){ $options = self::option_get(); foreach($opt as $key=>$value){ if((int)$value === 1 || (int)$value === 0){ $options[$key] = (int)$value; } } $res = self::option_set($options); if($res === true || $res === NULL){ self::display_message("Plugin Options Updated"); } else{ self::display_message("Could Not Update Options, they may not have changed!", false); } } elseif( $action ==="snippet_add" ){ $opt["snippet_title"] = esc_html($opt["snippet_title"]); $id = self::snippet_add( array( "name"=>$opt["snippet_title"], "function"=>$opt["snippet_code"] ) ); if( $id > 0){ self::display_message ("Code Snippet Added, you can use this snippet using the shortcode [php function={$id}]"); } else{ self::display_message ("Oh dear, could not add the code snippet", false); } } elseif ($action ==="snippet_edit"){ if( wp_verify_nonce( $verification, $action.$opt["snippet_id"] ) ){ $opt["snippet_title"] = esc_html($opt["snippet_title"]); $id = self::snippet_edit( $opt["snippet_id"], array( "name"=>$opt["snippet_title"], "function"=>$opt["snippet_code"] ) ); if( $id > 0){ self::display_message ("Code snippet has been updated"); } else{ self::display_message ("Oh dear, could not update that code snippet", false); } } } elseif ($action === "snippet_delete"){ if( wp_verify_nonce( $verification, $action.$opt["snippet_id"] ) ){ self::snippet_delete( $opt["snippet_id"] ); self::display_message ("Code snippet has been deleted"); } } } else{ self::display_message( "An error occured, please try again", false ); } } } function display_message( $message="", $good = true){ $clas = "updated"; if( $good === false){$clas='error';} echo '

'.$message.'

'; } function snippet_add( $snippet = array( "name" => "", "function"=>"" ) ){ global $wpdb; if( $wpdb->insert( $wpdb->prefix.self::$database_prefix, $snippet, array("%s", "%s") ) ){ return $wpdb->insert_id; } else{ return 0; } } function snippet_edit( $id = 0, $snippet = array( "name" => "", "function"=>"" ) ){ global $wpdb; return $wpdb->update( $wpdb->prefix.self::$database_prefix, $snippet, array( "id" => $id ), array("%s", "%s"), array("%d") ); } function snippet_delete( $snippet_id = 0){ global $wpdb; return $wpdb->get_results( $wpdb->prepare( "DELETE FROM `".$wpdb->prefix.self::$database_prefix."` WHERE `id` = %d LIMIT 1", $snippet_id ) ); } function snippet_get( $snippet_id = 0 ){ global $wpdb; $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM `".$wpdb->prefix.self::$database_prefix."` WHERE `id` = %d", $snippet_id ) ); if(sizeof($row) > 0){ $row->function = htmlspecialchars_decode($row->function); } return $row; } function snippet_get_all( ){ global $wpdb; $rows = $wpdb->get_results( "SELECT * FROM `".$wpdb->prefix.self::$database_prefix."`" ); return $rows; } function snippet_swap( $snippet_id = 0){ $snippet = self::snippet_get($snippet_id); if(sizeof($snippet) == 0){ echo self::snippet_404(); } else{ eval( stripslashes($snippet->function)); } } function snippet_404(){ $option = self::option_get(); if( $option["show404"] == 1 ){ if( is_int( $option["fourohfourmsg"] ) && $option["fourohfourmsg"] !== 0 ){ $snippet = self::snippet_get( $option["fourohfourmsg"] ); return $snippet->function; } else{ return "Function does not exist";; } } return ""; } function form_add_snippet(){ ?>

id, self::$post_prefix."[verification]");?>

&[opt][snippet_id]=id?>&[verification]=id)?>" class='delete-button' onclick="return confirm('Are you sure you want to delete this snippet?')">Delete This Snippet
Yes: value="1" />
No: value="0" />
Yes: value="1" />
No: value="0" />
Yes: value="1" />
No: value="0" />
Yes: value="1" />
No: value="0" />

0, "fourohfourmsg" => 0, "dbVersion" => 0, "use_advanced_filter" => 0, "preparse" => 0, "total_uninstall" => 0, ); $options = get_option(self::$option_name,$defaults); return array_merge($defaults, $options); } function option_set( $new_options = array() ){ return update_option( self::$option_name, $new_options); } function shortcode($args, $content=""){ $option = self::option_get(); $default_args = array('debug' => 0,'silentdebug' => 0, 'function' => 0, 'mode'=>'new'); extract( shortcode_atts( $default_args, $args)); $four0four_used = false; //Debug settings if($debug == 1){ error_reporting(E_ALL); ini_set("display_errors","1"); } if($function == 0): if( $mode == "new" || ($option["preparse"] == 0 && $mode == "new") ){ $content = strip_tags($content); $content = preg_replace("/\[{1}([\/]*)([a-zA-z\/]{1}[a-zA-Z0-9]*[^\'\"])([a-zA-Z0-9 \!\"\£\$\%\^\&\*\*\(\)\_\-\+\=\|\\\,\.\/\?\:\;\@\'\#\~\{\}\¬\¦\`\<\>]*)([\/]*)([\]]{1})/ix","<$1$2$3>",$content,"-1"); $content = htmlspecialchars($content, ENT_NOQUOTES); $content = str_replace("&#8217;","'",$content); $content = str_replace("&#8216;","'",$content); $content = str_replace("&#8242;","'",$content); $content = str_replace("&#8220;","\"",$content); $content = str_replace("&#8221;","\"",$content); $content = str_replace("&#8243;","\"",$content); $content = str_replace("&#039;","'",$content); $content = str_replace("'","'",$content); $content = str_replace("&#038;","&",$content); $content = str_replace("&gt;",'>',$content); $content = str_replace("&lt;",'<',$content); $content = htmlspecialchars_decode($content); } else{ $content =(htmlspecialchars($content,ENT_QUOTES)); $content = str_replace("&#8217;","'",$content); $content = str_replace("&#8216;","'",$content); $content = str_replace("&#8242;","'",$content); $content = str_replace("&#8220;","\"",$content); $content = str_replace("&#8221;","\"",$content); $content = str_replace("&#8243;","\"",$content); $content = str_replace("&#039;","'",$content); $content = str_replace("'","'",$content); $content = str_replace("&#038;","&",$content); $content = str_replace("&lt;br /&gt;"," ", $content); $content = htmlspecialchars_decode($content); $content = str_replace("
"," ",$content); $content = str_replace("

"," ",$content); $content = str_replace("

"," ",$content); $content = str_replace("[br/]","
",$content); $content = str_replace("\\[","[",$content); $content = str_replace("\\]","]",$content); $content = str_replace("[","<",$content); $content = str_replace("]",">",$content); $content = str_replace("[",'[',$content); $content = str_replace("]",']',$content); $content = str_replace(">",'>',$content); $content = str_replace("<",'<',$content); } else: //function selected $snippet = self::snippet_get($function); if( sizeof( $snippet ) == 0){ $four0four_used = true; $content = self::snippet_404(); } else{ $content = stripslashes($snippet->function); } endif; ob_start(); eval($content); if($debug == 1||$silentdebug == 1){ if($silentdebug == 1){ echo "\n\n\n\n"; }else{ echo "

End Allow PHP Debug

"; } } return ob_get_clean(); } function shortcode_advanced($args){ $options = self::option_get(); if( isset( $options['use_advanced_filter'] ) ){ if( $options['use_advanced_filter'] == "1" ){ remove_shortcode("php"); remove_shortcode("PHP"); remove_shortcode("allowphp"); remove_shortcode("ALLOWPHP"); $args = str_ireplace("[php]","",$args); $args = str_ireplace("[php useadvancedfilter]","",$args); $args = str_ireplace("[allowphp]","",$args); $args = str_ireplace("[allowphp useadvancedfilter]","",$args); $args = preg_replace( "#\[php(.*?)function=([0-9]*)(.*?)\]#", "",$args); $args = preg_replace( "#\[allowphp(.*?)function=([0-9]*)(.*?)\]#", "",$args); ob_start(); eval("?>".$args); $return = ob_get_clean(); return $return; } else{ return $args; } } $args = str_ireplace("[php useadvancedfilter]","",$args); $args = str_ireplace("[allowphp useadvancedfilter]","",$args); ob_start(); eval("?>".$args); $returned = ob_get_clean(); return $returned; } function hook_activation(){ self::db_check(); } function hook_uninstall(){ $option = self::option_get(); if($option["total_uninstall"] === 1){ global $wpdb; $wpdb->query("DROP TABLE `".$wpdb->prefix.self::$database_prefix."`"); delete_option( self::$option_name ); } } function db_check(){ $opt = self::option_get(); if($opt["dbVersion"] != self::$database_version){ self::db_upgrade(); } } function db_upgrade(){ global $wpdb; $sql = "RENAME TABLE `".$wpdb->prefix."allowPHP_functions` TO `".$wpdb->prefix.self::$database_prefix."`"; $wpdb->get_results($sql); $sql = "CREATE TABLE IF NOT EXISTS ".$wpdb->prefix.self::$database_prefix."( id int NOT NULL AUTO_INCREMENT, name varchar(100) NOT NULL, function longtext NOT NULL, PRIMARY KEY(id) );"; require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql); //need to manually change existing function columns $wpdb->get_results("ALTER TABLE `".$wpdb->prefix.self::$database_prefix."` CHANGE `function` `function` LONGTEXT NOT NULL "); $opt = self::option_get(); $opt["dbVersion"] = self::$database_version; self::option_set($opt); } } function allow_php_init(){ global $allow_php; $allow_php = new allow_php_in_posts(); } add_action("init","allow_php_init"); register_activation_hook( __FILE__ , array( "allow_php_in_posts" , "hook_activation" ) ); register_uninstall_hook( __FILE__, array( "allow_php_in_posts", "hook_uninstall" ) ); }