dotclear.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 742 行 · 第 1/2 页
PHP
742 行
<?php/** Add These Functions to make our lives easier**/if(!function_exists('get_catbynicename')){ function get_catbynicename($category_nicename) { global $wpdb; $cat_id -= 0; // force numeric $name = $wpdb->get_var('SELECT cat_ID FROM '.$wpdb->categories.' WHERE category_nicename="'.$category_nicename.'"'); return $name; }}if(!function_exists('get_comment_count')){ function get_comment_count($post_ID) { global $wpdb; return $wpdb->get_var('SELECT count(*) FROM '.$wpdb->comments.' WHERE comment_post_ID = '.$post_ID); }}if(!function_exists('link_cat_exists')){ function link_cat_exists($catname) { global $wpdb; return $wpdb->get_var('SELECT cat_id FROM '.$wpdb->linkcategories.' WHERE cat_name = "'.$wpdb->escape($catname).'"'); }}if(!function_exists('link_exists')){ function link_exists($linkname) { global $wpdb; return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$linkname.'"'); }}/* Identify UTF-8 text Taken from http://www.php.net/manual/fr/function.mb-detect-encoding.php#50087*///// utf8 encoding validation developed based on Wikipedia entry at:// http://en.wikipedia.org/wiki/UTF-8//// Implemented as a recursive descent parser based on a simple state machine// copyright 2005 Maarten Meijer//// This cries out for a C-implementation to be included in PHP core// function valid_1byte($char) { if(!is_int($char)) return false; return ($char & 0x80) == 0x00; } function valid_2byte($char) { if(!is_int($char)) return false; return ($char & 0xE0) == 0xC0; } function valid_3byte($char) { if(!is_int($char)) return false; return ($char & 0xF0) == 0xE0; } function valid_4byte($char) { if(!is_int($char)) return false; return ($char & 0xF8) == 0xF0; } function valid_nextbyte($char) { if(!is_int($char)) return false; return ($char & 0xC0) == 0x80; } function valid_utf8($string) { $len = strlen($string); $i = 0; while( $i < $len ) { $char = ord(substr($string, $i++, 1)); if(valid_1byte($char)) { // continue continue; } else if(valid_2byte($char)) { // check 1 byte if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; } else if(valid_3byte($char)) { // check 2 bytes if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; } else if(valid_4byte($char)) { // check 3 bytes if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; if(!valid_nextbyte(ord(substr($string, $i++, 1)))) return false; } // goto next char } return true; // done }function csc ($s) { if (valid_utf8 ($s)) { return $s; } else { return iconv(get_option ("dccharset"),"UTF-8",$s); }}function textconv ($s) { return csc (preg_replace ('|(?<!<br />)\s*\n|', ' ', $s));}/** The Main Importer Class**/class Dotclear_Import { function header() { echo '<div class="wrap">'; echo '<h2>'.__('Import Dotclear').'</h2>'; echo '<p>'.__('Steps may take a few minutes depending on the size of your database. Please be patient.').'</p>'; } function footer() { echo '</div>'; } function greet() { echo '<p>'.__('Howdy! This importer allows you to extract posts from a Dotclear database into your blog. Mileage may vary.').'</p>'; echo '<p>'.__('Your Dotclear Configuration settings are as follows:').'</p>'; echo '<form action="admin.php?import=dotclear&step=1" method="post">'; $this->db_form(); echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />'; echo '</form>'; } function get_dc_cats() { global $wpdb; // General Housekeeping $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Categories return $dcdb->get_results('SELECT * FROM dc_categorie', ARRAY_A); } function get_dc_users() { global $wpdb; // General Housekeeping $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Users return $dcdb->get_results('SELECT * FROM dc_user', ARRAY_A); } function get_dc_posts() { // General Housekeeping $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Posts return $dcdb->get_results('SELECT dc_post.*, dc_categorie.cat_libelle_url AS post_cat_name FROM dc_post INNER JOIN dc_categorie ON dc_post.cat_id = dc_categorie.cat_id', ARRAY_A); } function get_dc_comments() { global $wpdb; // General Housekeeping $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Comments return $dcdb->get_results('SELECT * FROM dc_comment', ARRAY_A); } function get_dc_links() { //General Housekeeping $dcdb = new wpdb(get_option('dcuser'), get_option('dcpass'), get_option('dcname'), get_option('dchost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); return $dcdb->get_results('SELECT * FROM dc_link ORDER BY position', ARRAY_A); } function cat2wp($categories='') { // General Housekeeping global $wpdb; $count = 0; $dccat2wpcat = array(); // Do the Magic if(is_array($categories)) { echo '<p>'.__('Importing Categories...').'<br /><br /></p>'; foreach ($categories as $category) { $count++; extract($category); // Make Nice Variables $name = $wpdb->escape($cat_libelle_url); $title = $wpdb->escape(csc ($cat_libelle)); $desc = $wpdb->escape(csc ($cat_desc)); if($cinfo = category_exists($name)) { $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); } else { $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title, 'category_description' => $desc)); } $dccat2wpcat[$id] = $ret_id; } // Store category translation for future use add_option('dccat2wpcat',$dccat2wpcat); echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> categories imported.'), $count).'<br /><br /></p>'; return true; } echo __('No Categories to Import!'); return false; } function users2wp($users='') { // General Housekeeping global $wpdb; $count = 0; $dcid2wpid = array(); // Midnight Mojo if(is_array($users)) { echo '<p>'.__('Importing Users...').'<br /><br /></p>'; foreach($users as $user) { $count++; extract($user); // Make Nice Variables $name = $wpdb->escape(csc ($name)); $RealName = $wpdb->escape(csc ($user_pseudo)); if($uinfo = get_userdatabylogin($name)) { $ret_id = wp_insert_user(array( 'ID' => $uinfo->ID, 'user_login' => $user_id, 'user_nicename' => $Realname, 'user_email' => $user_email, 'user_url' => 'http://', 'display_name' => $Realname) ); } else { $ret_id = wp_insert_user(array( 'user_login' => $user_id, 'user_nicename' => csc ($user_pseudo), 'user_email' => $user_email, 'user_url' => 'http://', 'display_name' => $Realname) ); } $dcid2wpid[$user_id] = $ret_id; // Set Dotclear-to-WordPress permissions translation // Update Usermeta Data $user = new WP_User($ret_id); $wp_perms = $user_level + 1; if(10 == $wp_perms) { $user->set_role('administrator'); } else if(9 == $wp_perms) { $user->set_role('editor'); } else if(5 <= $wp_perms) { $user->set_role('editor'); } else if(4 <= $wp_perms) { $user->set_role('author'); } else if(3 <= $wp_perms) { $user->set_role('contributor'); } else if(2 <= $wp_perms) { $user->set_role('contributor'); } else { $user->set_role('subscriber'); } update_usermeta( $ret_id, 'wp_user_level', $wp_perms); update_usermeta( $ret_id, 'rich_editing', 'false'); update_usermeta( $ret_id, 'first_name', csc ($user_prenom)); update_usermeta( $ret_id, 'last_name', csc ($user_nom)); }// End foreach($users as $user) // Store id translation array for future use add_option('dcid2wpid',$dcid2wpid); echo '<p>'.sprintf(__('Done! <strong>%1$s</strong> users imported.'), $count).'<br /><br /></p>'; return true; }// End if(is_array($users) echo __('No Users to Import!'); return false; }// End function user2wp() function posts2wp($posts='') { // General Housekeeping global $wpdb; $count = 0; $dcposts2wpposts = array(); $cats = array(); // Do the Magic if(is_array($posts)) { echo '<p>'.__('Importing Posts...').'<br /><br /></p>'; foreach($posts as $post) { $count++; extract($post); // Set Dotclear-to-WordPress status translation $stattrans = array(0 => 'draft', 1 => 'publish'); $comment_status_map = array (0 => 'closed', 1 => 'open'); //Can we do this more efficiently? $uinfo = ( get_userdatabylogin( $user_id ) ) ? get_userdatabylogin( $user_id ) : 1; $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; $Title = $wpdb->escape(csc ($post_titre)); $post_content = textconv ($post_content); if ($post_chapo != "") { $post_excerpt = textconv ($post_chapo); $post_content = $post_excerpt ."\n<!--more-->\n".$post_content; } $post_excerpt = $wpdb->escape ($post_excerpt); $post_content = $wpdb->escape ($post_content); $post_status = $stattrans[$post_pub]; // Import Post data into WordPress if($pinfo = post_exists($Title,$post_content)) { $ret_id = wp_insert_post(array( 'ID' => $pinfo, 'post_author' => $authorid, 'post_date' => $post_dt, 'post_date_gmt' => $post_dt, 'post_modified' => $post_upddt, 'post_modified_gmt' => $post_upddt, 'post_title' => $Title,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?