Licensed under the MIT License, Copyright 2004 Owen Winkler. Version: 3.1.1 Author: Owen Winkler Author URI: http://www.asymptomatic.net Thanks to Stephen, aka "gravity", for help debugging the ob_ functions. */ /* EzStatic - Allows easy display of static content within the WP blog context. Copyright (c) 2005 Owen Winkler Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* INSTRUCTIONS: Detailed instructions at: http://redalt.com/wiki/EzStatic No edits to the WordPress source are required. Just drop this into your WordPress plugins directory, and then Activate it on the Plugins tab of the WordPress admin console. If you are a user of high enough level and you check the new option checkbox that appears below the post editing area, then posts that contain PHP tags will be executed in the posts that you write. Also, you can include existing files into your WordPress template: Add a querystring to your URL that points to your static file. Like this: http://www.example.com/index.php?static=mystaticfile EzStatic will try to open in order from your blog directory: mystaticfile mystaticfile.php mystaticfile.htm If the static file specified is PHP, it will execute the file and display the results. This file may contain WordPress template tags and functions. For plugin developers: You can use EzStatic in your own functions to create static-like pages from your plugins! Simply dump all of your output into a variable, then send it with a new page title to the function EzStatic_force(). EzStatic will automatically insert your content in place of the default post listing. If you receive reports that EzStatic isn't working, turn OFF gzip support in your WordPress admin panel. (Options, Reading) */ if(!function_exists('EzStatic_include_up')) : function EzStatic_include_up($filename) { $c=0; while(!is_file($filename)) { $filename = '../' . $filename; $c++; if($c==30) { echo 'Could not find ' . basename($filename) . '.'; return ''; } } return $filename; } endif; if(!defined('ABSPATH')) { // Things to do when the file is called solo include(EzStatic_include_up('wp-config.php')); $ezs_options = get_settings('ezstatic'); if($ezs_options == '') { $ezs_options = array( 'qs_key' => 'static', 'fileexts' => array('.php', '.htm', '.html', '.txt', '.asp'), 'block' => array('htaccess'), 'page_template' => '', ); update_option('ezstatic', $ezs_options); } if(isset($_POST['config'])) { // Things to do when the Ajax gets ya include_once(ABSPATH.'/wp-admin/admin-functions.php'); auth_redirect(); ?>
posts[0]->ID = -100; $wp_query->posts[0]->post_author = 1; $wp_query->posts[0]->post_date = date('Y-m-d h:i:s'); $wp_query->posts[0]->post_date_gmt = get_gmt_from_date(date('Y-m-d h:i:s')); $wp_query->posts[0]->post_content = $EzStatic_newcontent; $wp_query->posts[0]->post_title = $EzStatic_newtitle; $wp_query->posts[0]->post_category = 0; $wp_query->posts[0]->post_excerpt = ''; $wp_query->posts[0]->post_status = 'static'; $wp_query->posts[0]->comment_status = 'closed'; $wp_query->posts[0]->ping_status = 'closed'; $wp_query->posts[0]->post_password = ''; $wp_query->posts[0]->post_name = 'NAME'; $wp_query->posts[0]->to_ping = ''; $wp_query->posts[0]->pinged = ''; $wp_query->posts[0]->post_modified = date('Y-m-d h:i:s'); $wp_query->posts[0]->post_modified_gmt = get_gmt_from_date(date('Y-m-d h:i:s')); $wp_query->posts[0]->post_content_filtered = ''; $wp_query->posts[0]->post_parent = 0; $wp_query->posts[0]->guid = 'GUID'; $wp_query->posts[0]->menu_order = '0'; $wp_query->posts[0]->post_type = ''; $wp_query->post = $wp_query->posts[0]; $wp_query->post_count = 1; $wp_query->is_page = true; $post_cache[-100] = $wp_query->post; if ( ! empty($page_template) && file_exists(TEMPLATEPATH . "/$page_template") ) { include(TEMPLATEPATH . "/$page_template"); exit; } else if ( get_page_template() ) { include(get_page_template()); exit; } else if ( file_exists(TEMPLATEPATH . "/index.php") ) { include(TEMPLATEPATH . "/index.php"); exit; } } $ezs_options = get_settings('ezstatic'); if(($ezs_options['qs_key'] != '') && preg_match('!/' . $ezs_options['qs_key'] . '/([^?]+)/?(\?.*)?$!i', $_SERVER['REQUEST_URI'], $urimatch)) { $_REQUEST[$ezs_options['qs_key']] = trim($urimatch[1],'/'); } if(isset($_REQUEST[$ezs_options['qs_key']])) { $sfile = $_REQUEST[$ezs_options['qs_key']]; $sfile = str_replace('..', '', $sfile); if($ezs_options['block'] != '') { if(preg_match('/' . str_replace('/', '\/', implode("|",$ezs_options['block'])) . '/', $sfile)) { $sfile = '.blocked:'.$sfile; } } if($sfile{0} != '.') { $contentfile = ABSPATH . $sfile; if(is_dir($contentfile)) $sfile .= '/index'; // Get index page? foreach($ezs_options['fileexts'] as $ext) { if(is_file($contentfile)) break; $contentfile = ABSPATH . $sfile . $ext; } if(is_file($contentfile)) { if(stristr(substr($contentfile, -4), '.php')) { ob_start(); include $contentfile; $newcontent = ob_get_contents(); ob_end_clean(); } else { $newcontent = implode('', file($contentfile)); } if(isset($_REQUEST['autop'])) $newcontent = wpautop($newcontent); if(preg_match('|]*>(.*)]*>([^<]*)|i', $newhead, $titles); $newhead = preg_replace('|]*>[^<]*|i', '', $newhead); $EzStatic_newtitle = $titles[1]; $EzStatic_newhead = "\n\n$newhead\n"; $EzStatic_newhead = "\n\n$newhead\n\n"; } if(preg_match('|]*>(.*) 0) { $content = ob_get_contents(); ob_end_clean(); //foreach(ob_list_handlers() as $buf) echo "Using buffer callback: $buf
"; } $_POST['author'] = -1; $EzStatic_newcontent = $newcontent."\n"; } else { $EzStatic_newhead = "\n"; } } else { $EzStatic_newhead = "\n"; } } function EzStatic_head($content) { global $EzStatic_newhead; print $EzStatic_newhead; } /* The following functions handle the newfangled admin configuration system */ add_action('admin_head', 'EzStatic_admin_head'); if(strstr($_SERVER['REQUEST_URI'], '/wp-admin/plugins.php')) { ob_start('EzStatic_capture'); if(isset($_GET['pfile']) && ($_GET['page'] == EzStatic_basename(__FILE__))) { // Do something! } } function EzStatic_capture($content) { $content = preg_replace_callback('//', 'EzStatic_add_link', $content); return $content; } function EzStatic_add_link($c) { $replacement = $c[0] . '
' . __('Configure') . ''; return $replacement; } function EzStatic_admin_head($unused) { if(preg_match('/(plugins.php)/i', $_SERVER['SCRIPT_NAME'])) { ?>
ID, '_ezstatic', true) == 1) { $authordata = new WP_User($post->post_author); if($authordata->has_cap('ezstatic_execute')) { //$content = "
" . print_r($post, 1) . "
"; $content = preg_replace_callback('/(<[\\s]*\\?php)((\'.*?(?)/si', 'EzStatic_exec_PHP', $post->post_content); $content .= ""; } } return $content; } function EzStatic_exec_PHP($php) { ob_start(); eval($php[2]); $res = ob_get_contents(); ob_end_clean(); return $res; } function EzStatic_capabilities_list($caplist) { $caplist[] = 'ezstatic_execute'; return $caplist; } function EzStatic_admin_menu() { global $sack_js; if(strstr($_SERVER['REQUEST_URI'], 'plugins.php')) $sack_js = true; if(stripslashes($_GET['page']) == EzStatic_basename(__FILE__)) { add_submenu_page('plugins.php', 'Configure EzStatic', 'EzStatic', 'activate_plugins', EzStatic_basename(__FILE__), 'EzStatic_config'); } } function EzStatic_config() { ?>

Configure EzStatic

Configuration updated."; $ezs_options = array( 'qs_key' => $_POST['qs_key'], 'fileexts' => explode(',', $_POST['fileexts']), 'block' => explode(',', $_POST['block']), 'page_template' => $_POST['page_template'], ); update_option('ezstatic', $ezs_options); if(!is_array($_POST['roles'])) $_POST['roles'] = array(); foreach($wp_roles->role_names as $role => $name) { if(in_array($role, $_POST['roles'])) { $wp_roles->role_objects[$role]->add_cap('ezstatic_execute'); } else { $wp_roles->role_objects[$role]->remove_cap('ezstatic_execute'); } } } ?>
The querystring trigger for selecting static pages.
A comma-separated list of extensions in the order EzStatic will try them.
A comma-separated list of terms that will cause EzStatic to fail if they are used in the static file.
The page template to use when embedding static files
:
The user roles that may embed PHP code directly into posts and pages.
role_names as $role => $name) { echo "\n"; } ?>