textpattern.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 664 行 · 第 1/2 页
PHP
664 行
<?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_exists')){ function link_exists($linkname) { global $wpdb; return $wpdb->get_var('SELECT link_id FROM '.$wpdb->links.' WHERE link_name = "'.$wpdb->escape($linkname).'"'); }}/** The Main Importer Class**/class Textpattern_Import { function header() { echo '<div class="wrap">'; echo '<h2>'.__('Import Textpattern').'</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 any Textpattern 4.0.2+ into your blog. This has not been tested on previous versions of Textpattern. Mileage may vary.').'</p>'; echo '<p>'.__('Your Textpattern Configuration settings are as follows:').'</p>'; echo '<form action="admin.php?import=textpattern&step=1" method="post">'; $this->db_form(); echo '<input type="submit" name="submit" value="'.__('Import Categories').'" />'; echo '</form>'; } function get_txp_cats() { global $wpdb; // General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Categories return $txpdb->get_results('SELECT id, name, title FROM '.$prefix.'txp_category WHERE type = "article"', ARRAY_A); } function get_txp_users() { global $wpdb; // General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Users return $txpdb->get_results('SELECT user_id, name, RealName, email, privs FROM '.$prefix.'txp_users', ARRAY_A); } function get_txp_posts() { // General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Posts return $txpdb->get_results('SELECT ID, Posted, AuthorID, LastMod, Title, Body, Excerpt, Category1, Category2, Status, Keywords, url_title, comments_count FROM '.$prefix.'textpattern ', ARRAY_A); } function get_txp_comments() { global $wpdb; // General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); // Get Comments return $txpdb->get_results('SELECT * FROM '.$prefix.'txp_discuss', ARRAY_A); } function get_txp_links() { //General Housekeeping $txpdb = new wpdb(get_option('txpuser'), get_option('txppass'), get_option('txpname'), get_option('txphost')); set_magic_quotes_runtime(0); $prefix = get_option('tpre'); return $txpdb->get_results('SELECT id, date, category, url, linkname, description FROM '.$prefix.'txp_link', ARRAY_A); } function cat2wp($categories='') { // General Housekeeping global $wpdb; $count = 0; $txpcat2wpcat = 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($name); $title = $wpdb->escape($title); if($cinfo = category_exists($name)) { $ret_id = wp_insert_category(array('cat_ID' => $cinfo, 'category_nicename' => $name, 'cat_name' => $title)); } else { $ret_id = wp_insert_category(array('category_nicename' => $name, 'cat_name' => $title)); } $txpcat2wpcat[$id] = $ret_id; } // Store category translation for future use add_option('txpcat2wpcat',$txpcat2wpcat); 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; $txpid2wpid = 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($name); $RealName = $wpdb->escape($RealName); if($uinfo = get_userdatabylogin($name)) { $ret_id = wp_insert_user(array( 'ID' => $uinfo->ID, 'user_login' => $name, 'user_nicename' => $RealName, 'user_email' => $email, 'user_url' => 'http://', 'display_name' => $name) ); } else { $ret_id = wp_insert_user(array( 'user_login' => $name, 'user_nicename' => $RealName, 'user_email' => $email, 'user_url' => 'http://', 'display_name' => $name) ); } $txpid2wpid[$user_id] = $ret_id; // Set Textpattern-to-WordPress permissions translation $transperms = array(1 => '10', 2 => '9', 3 => '5', 4 => '4', 5 => '3', 6 => '2', 7 => '0'); // Update Usermeta Data $user = new WP_User($ret_id); if('10' == $transperms[$privs]) { $user->set_role('administrator'); } if('9' == $transperms[$privs]) { $user->set_role('editor'); } if('5' == $transperms[$privs]) { $user->set_role('editor'); } if('4' == $transperms[$privs]) { $user->set_role('author'); } if('3' == $transperms[$privs]) { $user->set_role('contributor'); } if('2' == $transperms[$privs]) { $user->set_role('contributor'); } if('0' == $transperms[$privs]) { $user->set_role('subscriber'); } update_usermeta( $ret_id, 'wp_user_level', $transperms[$privs] ); update_usermeta( $ret_id, 'rich_editing', 'false'); }// End foreach($users as $user) // Store id translation array for future use add_option('txpid2wpid',$txpid2wpid); 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; $txpposts2wpposts = 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 Textpattern-to-WordPress status translation $stattrans = array(1 => 'draft', 2 => 'private', 3 => 'draft', 4 => 'publish', 5 => 'publish'); //Can we do this more efficiently? $uinfo = ( get_userdatabylogin( $AuthorID ) ) ? get_userdatabylogin( $AuthorID ) : 1; $authorid = ( is_object( $uinfo ) ) ? $uinfo->ID : $uinfo ; $Title = $wpdb->escape($Title); $Body = $wpdb->escape($Body); $Excerpt = $wpdb->escape($Excerpt); $post_status = $stattrans[$Status]; // Import Post data into WordPress if($pinfo = post_exists($Title,$Body)) { $ret_id = wp_insert_post(array( 'ID' => $pinfo, 'post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count) ); } else { $ret_id = wp_insert_post(array( 'post_date' => $Posted, 'post_date_gmt' => $post_date_gmt, 'post_author' => $authorid, 'post_modified' => $LastMod, 'post_modified_gmt' => $post_modified_gmt, 'post_title' => $Title, 'post_content' => $Body, 'post_excerpt' => $Excerpt, 'post_status' => $post_status, 'post_name' => $url_title, 'comment_count' => $comments_count) );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?