wap_folder = 'wap'; // 拷贝文件 register_activation_hook(__FILE__, array(&$this, 'init')); // 添加管理界面 add_action('admin_menu', array(&$this, 'add_options_page')); } // 插件启动时执行 function init(){ // 自动拷贝文件到站点根目录 $this->copyfile('append-form-advanced.php'); $this->copyfile('comment.php'); $this->copyfile('comments.php'); $this->copyfile('edit.php'); $this->copyfile('edit-comments.php'); $this->copyfile('edit-form-advanced.php'); $this->copyfile('edit-post-rows.php'); $this->copyfile('functions.php'); $this->copyfile('index.php'); $this->copyfile('index-wap.php'); $this->copyfile('index-wap2.php'); $this->copyfile('login.php'); $this->copyfile('post.php'); //$this->copyfile('wap-config.php'); $this->copy_config_file(); $this->copyfile('wap-settings.php'); $this->copyfile('wap-zh_CN.mo'); $this->copyfile('wap-comments-post.php'); $this->copyfile('writer.php'); $this->copyfile('wap.css'); update_option('wap_show_detail', 'yes'); update_option('wap_show_related_posts', 'yes'); update_option('wap_show_hot_posts', 'yes'); update_option('wap_show_last_comments', 'yes'); update_option('wap_sitetitle', get_bloginfo('name')); } function get_home_path() { $home = get_option( 'home' ); if ( $home != '' && $home != get_option( 'siteurl' ) ) { $home_path = parse_url( $home ); $home_path = $home_path['path']; $file_self = dirname($_SERVER["REQUEST_URI"]); $file_self = str_replace('\\', '/', $file_self); $file_self = str_replace('//', '/', $file_self); $file_self_full = realpath("."); $file_self_full = str_replace('\\', '/', $file_self_full); $file_self_full = str_replace('//', '/', $file_self_full); $root = str_replace( $file_self, '', $file_self_full ); $home_path = trailingslashit( $root . $home_path ); } else { $home_path = ABSPATH; } $home_path = str_replace('\\', '/', $home_path); $home_path = str_replace('//', '/', $home_path); return $home_path; } function copyfile($filename){ $home_path = $this->get_home_path() . $this->wap_folder .'/'; // 如果文件夹不存在,则创建文件夹 if(!file_exists($home_path)){ mkdir($home_path); } $file = dirname(__FILE__) . '/wap/' . $filename; $file = str_replace ( '\\','/',$file ); $newfile = $home_path . $filename; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; return; } /* if(($dataFile = fopen($newfile,'w')) === FALSE) { echo "failed to fopen $file...\n"; return; } $buffer = ''; fwrite($dataFile,$buffer); fclose($dataFile); */ } function copy_config_file() { $home_path = $this->get_home_path() . $this->wap_folder .'/'; $wap_plugin_root = dirname ( __FILE__ ) .'/'; $wap_plugin_root = str_replace("\\", "/", $wap_plugin_root); $wp_path = '..'; //if ( defined('ABSPATH') ) //{ // $wp_path = ABSPATH; //} //else //{ $wp_path = str_replace("/wp-content/plugins/wp-t-wap", "", $wap_plugin_root); //} $wp_path = str_replace("\\", "/", $wp_path); $filename = $wap_plugin_root . "wap/wap-config.php"; if ( file_exists ( $filename ) ) { $dataFile = fopen( $filename, "r" ); $buffer = ''; if ( $dataFile ) { $buffer = ''; while (!feof($dataFile)) { $buffer = $buffer . fgets($dataFile, 4096); } fclose($dataFile); $buffer = str_replace("../", $wp_path, $buffer); //echo $buffer; $newfile = $home_path . 'wap-config.php'; $dataFile = fopen( $newfile, "w" ); echo $newfile; fwrite($dataFile,$buffer); fclose($dataFile); } } } /* 在插件管理页面中显示你的插件菜单 */ function add_options_page(){ if (function_exists('add_options_page')) { add_options_page('WP-T-WAP','WP-T-WAP',8,'WP-T-WAP',array(&$this, 'mainpage')); } } /* 显示插件管理页面时即调用此函数 */ function mainpage(){ //require_once('wap-settings.php'); /* 更新选项 */ if($_POST['action']=="update"){ if ( $_POST['wap_show_detail'] == "yes" ) { update_option('wap_show_detail', "yes"); } else { update_option('wap_show_detail', "no"); } update_option('wap_show_related_posts',$_POST['wap_show_related_posts']); update_option('wap_show_hot_posts',$_POST['wap_show_hot_posts']); update_option('wap_show_last_comments',$_POST['wap_show_last_comments']); update_option('wap_wml_11',$_POST['wap_wml_11']); update_option('wap_sitetitle', $_POST['wap_sitetitle']); update_option('wap_copyright', $_POST['wap_copyright']); } ?>