module.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 382 行 · 第 1/2 页

PHP
382
字号
	// It is hard to believe but we have to consider the module being installed on Xoops installation, which some variables or objects are not available !
	$ID = is_object($GLOBALS["xoopsUser"])?$GLOBALS["xoopsUser"]->getVar("uid"):1;
	if(is_object($GLOBALS["xoopsUser"])){
		$theUser =& $GLOBALS["xoopsUser"];
	}else{
    	$member_handler =& xoops_gethandler('member');
		$theUser =& $member_handler->getUser($ID);
	}	
	
	// Change uid field
	$wpdb->query("ALTER TABLE $wpdb->posts CHANGE `post_author` `post_author` mediumint(8) NOT NULL DEFAULT '0'");
	
	// First post
	$now = date('Y-m-d H:i:s');
	$now_gmt = gmdate('Y-m-d H:i:s');
	$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, comment_count, to_ping, pinged, post_content_filtered) VALUES ('$ID', '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(__('hello-world'))."', '$now', '$now_gmt', '1', '', '', '')");

	$wpdb->query( "INSERT INTO $wpdb->post2cat (`rel_id`, `post_id`, `category_id`) VALUES (1, 1, 1)" );
	
	// Default comment
	$wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr XPress'))."', '', 'http://xoopsforge.com', '127.0.0.1', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.'))."')");

	
	// First Page
	
	$wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, post_status, to_ping, pinged, post_content_filtered) VALUES ('$ID', '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(__('about'))."', '$now', '$now_gmt', 'static', '', '', '')");
	generate_page_rewrite_rules();
        
	$GLOBALS["update_convert_encoding_to"] = wp_blog_charset();
	$GLOBALS["update_convert_encoding_from"] = _CHARSET;
	// Set up admin user
	$user_login = $theUser->getVar("uname");
	$user_login = encoding_xoops2wp($user_login);
	$display_name = $theUser->getVar("name")?encoding_xoops2wp($theUser->getVar("name")):$user_login;
   	$user_nicename = $ID;
	$password = $theUser->getVar("pass");
	$admin_email = $theUser->getVar("email");
	$wpdb->query("INSERT INTO $wpdb->users (ID, user_login, user_pass, user_email, user_registered, display_name, user_nicename) VALUES ( $ID, '$user_login', '$password', '$admin_email', NOW(), '$display_name', '$user_nicename')");
	$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ($ID, '{$table_prefix}user_level', '10');");
	$admin_caps = serialize(array('administrator' => true));
	$wpdb->query("INSERT INTO $wpdb->usermeta (user_id, meta_key, meta_value) VALUES ($ID, '{$table_prefix}capabilities', '{$admin_caps}');");
				
	return true;
}

 
function wp_setModuleConfig(&$module) 
{
	$modconfig =& $module->getInfo("config");
	$count = count($modconfig);
	for($i=0;$i<$count;$i++){
		if($modconfig[$i]["name"]=="theme_set"){
			$modconfig[$i]["options"][_NONE] = "0";			
		    foreach ($GLOBALS["xoopsConfig"]['theme_set_allowed'] as $theme) {
				$modconfig[$i]["options"][$theme] = $theme;
		    }
			break;
		}
	}
	//$module->setInfo("config", $modconfig);
	return true;
}

function wp_content_encoding($to, $from, &$module) 
{
	if (empty($to) || !strcasecmp($to, $from)) return false;
	global $wpdb,$wp_rewrite, $wp_queries, $table_prefix;
	
	$module = is_object($module)?$module:$GLOBALS["xoopsModule"];
	require_once(XOOPS_ROOT_PATH."/modules/".$module->getVar('dirname').'/wp-config.php');
        
	$GLOBALS["update_convert_encoding_to"] = $to;
	$GLOBALS["update_convert_encoding_from"] = $from;
	
	// posts encoding and views update
    $vars = array("post_title", "post_content", "post_excerpt", "post_name", "post_content_filtered");
    $id = "ID";
    $table = $wpdb->posts;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
	 
    // category encoding
    $vars = array("cat_name", "category_nicename", "category_description");
    $id = "cat_ID";
    $table = $wpdb->categories;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
    
    // comments encoding
    $vars = array("comment_content", "comment_author");
    $id = "comment_ID";
    $table = $wpdb->comments;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
    
    // linkcats encoding
    $vars = array("cat_name");
    $id = "cat_id";
    $table = $wpdb->linkcategories;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
    
    // links encoding
    $vars = array("link_name", "link_description", "link_notes");
    $id = "link_id";
    $table = $wpdb->links;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
    
    // options encoding
    $vars = array("option_value", "option_description");
    $id = "option_id";
    $table = $wpdb->options;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $wpdb->query("UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'");
		}
	}
    
    // users encoding
    $vars = array("user_login", "user_firstname", "user_lastname", "user_nickname", "user_description");
    $id = "ID";
    $table = $wpdb->users;
	$items = $wpdb->get_results("SELECT $id, ".implode(",",$vars)." FROM $table");
	if ($items) {
		foreach($items as $item) {
	        $var_string = array();
	        foreach($vars as $var){
            	$var_string[] = $var." = '".wp_update_convert_encoding($item->$var)."'";
	        }
	        $var_string = implode(",",$var_string);
            $sql = "UPDATE $table SET ".$var_string." WHERE $id = '".$item->$id."'";
            $wpdb->query($sql);
		}
	}

	return true;
}

?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?