-
+ F45F3C68986E47E93BE96141A8B8DB6C4A1354B19F75196DCCF2D1B49331BF4665C0FBA3E9B1C16EC7EE95E0DDD7117FB3D5D7C35589D2AD6FAD1DC9597D5636mp-wp/wp-admin/import/greymatter.php(0 . 0)(1 . 334)
18572 <?php
18573 /**
18574 * GreyMatter Importer
18575 *
18576 * @package WordPress
18577 * @subpackage Importer
18578 */
18579
18580 /**
18581 * GreyMatter Importer class
18582 *
18583 * Basic GreyMatter to WordPress importer, will import posts, comments, and
18584 * posts karma.
18585 *
18586 * @since unknown
18587 */
18588 class GM_Import {
18589
18590 var $gmnames = array ();
18591
18592 function header() {
18593 echo '<div class="wrap">';
18594 screen_icon();
18595 echo '<h2>'.__('Import GreyMatter').'</h2>';
18596 }
18597
18598 function footer() {
18599 echo '</div>';
18600 }
18601
18602 function greet() {
18603 $this->header();
18604 ?>
18605 <p><?php _e('This is a basic GreyMatter to WordPress import script.') ?></p>
18606 <p><?php _e('What it does:') ?></p>
18607 <ul>
18608 <li><?php _e('Parses gm-authors.cgi to import (new) authors. Everyone is imported at level 1.') ?></li>
18609 <li><?php _e('Parses the entries cgi files to import posts, comments, and karma on posts (although karma is not used on WordPress yet).<br />If authors are found not to be in gm-authors.cgi, imports them at level 0.') ?></li>
18610 <li><?php _e("Detects duplicate entries or comments. If you don't import everything the first time, or this import should fail in the middle, duplicate entries will not be made when you try again.") ?></li>
18611 </ul>
18612 <p><?php _e('What it does not:') ?></p>
18613 <ul>
18614 <li><?php _e('Parse gm-counter.cgi, gm-banlist.cgi, gm-cplog.cgi (you can make a CP log hack if you really feel like it, but I question the need of a CP log).') ?></li>
18615 <li><?php _e('Import gm-templates.') ?></li>
18616 <li><?php _e("Doesn't keep entries on top.")?></li>
18617 </ul>
18618 <p> </p>
18619
18620 <form name="stepOne" method="get" action="">
18621 <input type="hidden" name="import" value="greymatter" />
18622 <input type="hidden" name="step" value="1" />
18623 <?php wp_nonce_field('import-greymatter'); ?>
18624 <h3><?php _e('Second step: GreyMatter details:') ?></h3>
18625 <table class="form-table">
18626 <tr>
18627 <td><label for="gmpath"><?php _e('Path to GM files:') ?></label></td>
18628 <td><input type="text" style="width:300px" name="gmpath" id="gmpath" value="/home/my/site/cgi-bin/greymatter/" /></td>
18629 </tr>
18630 <tr>
18631 <td><label for="archivespath"><?php _e('Path to GM entries:') ?></label></td>
18632 <td><input type="text" style="width:300px" name="archivespath" id="archivespath" value="/home/my/site/cgi-bin/greymatter/archives/" /></td>
18633 </tr>
18634 <tr>
18635 <td><label for="lastentry"><?php _e("Last entry's number:") ?></label></td>
18636 <td><input type="text" name="lastentry" id="lastentry" value="00000001" /><br />
18637 <?php _e("This importer will search for files 00000001.cgi to 000-whatever.cgi,<br />so you need to enter the number of the last GM post here.<br />(if you don't know that number, just log into your FTP and look it out<br />in the entries' folder)") ?></td>
18638 </tr>
18639 </table>
18640 <p class="submit"><input type="submit" name="submit" class="button" value="<?php _e('Start Importing') ?>" /></p>
18641 </form>
18642 <?php
18643 $this->footer();
18644 }
18645
18646
18647
18648 function gm2autobr($string) { // transforms GM's |*| into b2's <br />\n
18649 $string = str_replace("|*|","<br />\n",$string);
18650 return($string);
18651 }
18652
18653 function import() {
18654 global $wpdb;
18655
18656 $wpvarstoreset = array('gmpath', 'archivespath', 'lastentry');
18657 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
18658 $wpvar = $wpvarstoreset[$i];
18659 if (!isset($$wpvar)) {
18660 if (empty($_POST["$wpvar"])) {
18661 if (empty($_GET["$wpvar"])) {
18662 $$wpvar = '';
18663 } else {
18664 $$wpvar = $_GET["$wpvar"];
18665 }
18666 } else {
18667 $$wpvar = $_POST["$wpvar"];
18668 }
18669 }
18670 }
18671
18672 if (!chdir($archivespath))
18673 wp_die(__("Wrong path, the path to the GM entries does not exist on the server"));
18674
18675 if (!chdir($gmpath))
18676 wp_die(__("Wrong path, the path to the GM files does not exist on the server"));
18677
18678 $lastentry = (int) $lastentry;
18679
18680 $this->header();
18681 ?>
18682 <p><?php _e('The importer is running...') ?></p>
18683 <ul>
18684 <li><?php _e('importing users...') ?><ul><?php
18685
18686 chdir($gmpath);
18687 $userbase = file("gm-authors.cgi");
18688
18689 foreach($userbase as $user) {
18690 $userdata=explode("|", $user);
18691
18692 $user_ip="127.0.0.1";
18693 $user_domain="localhost";
18694 $user_browser="server";
18695
18696 $s=$userdata[4];
18697 $user_joindate=substr($s,6,4)."-".substr($s,0,2)."-".substr($s,3,2)." 00:00:00";
18698
18699 $user_login=$wpdb->escape($userdata[0]);
18700 $pass1=$wpdb->escape($userdata[1]);
18701 $user_nickname=$wpdb->escape($userdata[0]);
18702 $user_email=$wpdb->escape($userdata[2]);
18703 $user_url=$wpdb->escape($userdata[3]);
18704 $user_joindate=$wpdb->escape($user_joindate);
18705
18706 $user_id = username_exists($user_login);
18707 if ($user_id) {
18708 printf('<li>'.__('user %s').'<strong>'.__('Already exists').'</strong></li>', "<em>$user_login</em>");
18709 $this->gmnames[$userdata[0]] = $user_id;
18710 continue;
18711 }
18712
18713 $user_info = array("user_login"=>"$user_login", "user_pass"=>"$pass1", "user_nickname"=>"$user_nickname", "user_email"=>"$user_email", "user_url"=>"$user_url", "user_ip"=>"$user_ip", "user_domain"=>"$user_domain", "user_browser"=>"$user_browser", "dateYMDhour"=>"$user_joindate", "user_level"=>"1", "user_idmode"=>"nickname");
18714 $user_id = wp_insert_user($user_info);
18715 $this->gmnames[$userdata[0]] = $user_id;
18716
18717 printf('<li>'.__('user %s...').' <strong>'.__('Done').'</strong></li>', "<em>$user_login</em>");
18718 }
18719
18720 ?></ul><strong><?php _e('Done') ?></strong></li>
18721 <li><?php _e('importing posts, comments, and karma...') ?><br /><ul><?php
18722
18723 chdir($archivespath);
18724
18725 for($i = 0; $i <= $lastentry; $i = $i + 1) {
18726
18727 $entryfile = "";
18728
18729 if ($i<10000000) {
18730 $entryfile .= "0";
18731 if ($i<1000000) {
18732 $entryfile .= "0";
18733 if ($i<100000) {
18734 $entryfile .= "0";
18735 if ($i<10000) {
18736 $entryfile .= "0";
18737 if ($i<1000) {
18738 $entryfile .= "0";
18739 if ($i<100) {
18740 $entryfile .= "0";
18741 if ($i<10) {
18742 $entryfile .= "0";
18743 }}}}}}}
18744
18745 $entryfile .= "$i";
18746
18747 if (is_file($entryfile.".cgi")) {
18748
18749 $entry=file($entryfile.".cgi");
18750 $postinfo=explode("|",$entry[0]);
18751 $postmaincontent=$this->gm2autobr($entry[2]);
18752 $postmorecontent=$this->gm2autobr($entry[3]);
18753
18754 $post_author=trim($wpdb->escape($postinfo[1]));
18755
18756 $post_title=$this->gm2autobr($postinfo[2]);
18757 printf('<li>'.__('entry # %s : %s : by %s'), $entryfile, $post_title, $postinfo[1]);
18758 $post_title=$wpdb->escape($post_title);
18759
18760 $postyear=$postinfo[6];
18761 $postmonth=zeroise($postinfo[4],2);
18762 $postday=zeroise($postinfo[5],2);
18763 $posthour=zeroise($postinfo[7],2);
18764 $postminute=zeroise($postinfo[8],2);
18765 $postsecond=zeroise($postinfo[9],2);
18766
18767 if (($postinfo[10]=="PM") && ($posthour!="12"))
18768 $posthour=$posthour+12;
18769
18770 $post_date="$postyear-$postmonth-$postday $posthour:$postminute:$postsecond";
18771
18772 $post_content=$postmaincontent;
18773 if (strlen($postmorecontent)>3)
18774 $post_content .= "<!--more--><br /><br />".$postmorecontent;
18775 $post_content=$wpdb->escape($post_content);
18776
18777 $post_karma=$postinfo[12];
18778
18779 $post_status = 'publish'; //in greymatter, there are no drafts
18780 $comment_status = 'open';
18781 $ping_status = 'closed';
18782
18783 if ($post_ID = post_exists($post_title, '', $post_date)) {
18784 echo ' ';
18785 _e('(already exists)');
18786 } else {
18787 //just so that if a post already exists, new users are not created by checkauthor
18788 // we'll check the author is registered, or if it's a deleted author
18789 $user_id = username_exists($post_author);
18790 if (!$user_id) { // if deleted from GM, we register the author as a level 0 user
18791 $user_ip="127.0.0.1";
18792 $user_domain="localhost";
18793 $user_browser="server";
18794 $user_joindate="1979-06-06 00:41:00";
18795 $user_login=$wpdb->escape($post_author);
18796 $pass1=$wpdb->escape("password");
18797 $user_nickname=$wpdb->escape($post_author);
18798 $user_email=$wpdb->escape("user@deleted.com");
18799 $user_url=$wpdb->escape("");
18800 $user_joindate=$wpdb->escape($user_joindate);
18801
18802 $user_info = array("user_login"=>$user_login, "user_pass"=>$pass1, "user_nickname"=>$user_nickname, "user_email"=>$user_email, "user_url"=>$user_url, "user_ip"=>$user_ip, "user_domain"=>$user_domain, "user_browser"=>$user_browser, "dateYMDhour"=>$user_joindate, "user_level"=>0, "user_idmode"=>"nickname");
18803 $user_id = wp_insert_user($user_info);
18804 $this->gmnames[$postinfo[1]] = $user_id;
18805
18806 echo ': ';
18807 printf(__('registered deleted user %s at level 0 '), "<em>$user_login</em>");
18808 }
18809
18810 if (array_key_exists($postinfo[1], $this->gmnames)) {
18811 $post_author = $this->gmnames[$postinfo[1]];
18812 } else {
18813 $post_author = $user_id;
18814 }
18815
18816 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_modified', 'post_modified_gmt');
18817 $post_ID = wp_insert_post($postdata);
18818 if ( is_wp_error( $post_ID ) )
18819 return $post_ID;
18820 }
18821
18822 $c=count($entry);
18823 if ($c>4) {
18824 $numAddedComments = 0;
18825 $numComments = 0;
18826 for ($j=4;$j<$c;$j++) {
18827 $entry[$j]=$this->gm2autobr($entry[$j]);
18828 $commentinfo=explode("|",$entry[$j]);
18829 $comment_post_ID=$post_ID;
18830 $comment_author=$wpdb->escape($commentinfo[0]);
18831 $comment_author_email=$wpdb->escape($commentinfo[2]);
18832 $comment_author_url=$wpdb->escape($commentinfo[3]);
18833 $comment_author_IP=$wpdb->escape($commentinfo[1]);
18834
18835 $commentyear=$commentinfo[7];
18836 $commentmonth=zeroise($commentinfo[5],2);
18837 $commentday=zeroise($commentinfo[6],2);
18838 $commenthour=zeroise($commentinfo[8],2);
18839 $commentminute=zeroise($commentinfo[9],2);
18840 $commentsecond=zeroise($commentinfo[10],2);
18841 if (($commentinfo[11]=="PM") && ($commenthour!="12"))
18842 $commenthour=$commenthour+12;
18843 $comment_date="$commentyear-$commentmonth-$commentday $commenthour:$commentminute:$commentsecond";
18844
18845 $comment_content=$wpdb->escape($commentinfo[12]);
18846
18847 if (!comment_exists($comment_author, $comment_date)) {
18848 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_author_IP', 'comment_date', 'comment_content', 'comment_approved');
18849 $commentdata = wp_filter_comment($commentdata);
18850 wp_insert_comment($commentdata);
18851 $numAddedComments++;
18852 }
18853 $numComments++;
18854 }
18855 if ($numAddedComments > 0) {
18856 echo ': ';
18857 printf( __ngettext('imported %s comment', 'imported %s comments', $numAddedComments) , $numAddedComments);
18858 }
18859 $preExisting = $numComments - numAddedComments;
18860 if ($preExisting > 0) {
18861 echo ' ';
18862 printf( __ngettext( 'ignored %s pre-existing comment', 'ignored %s pre-existing comments', $preExisting ) , $preExisting);
18863 }
18864 }
18865 echo '... <strong>'.__('Done').'</strong></li>';
18866 }
18867 }
18868 do_action('import_done', 'greymatter');
18869 ?>
18870 </ul><strong><?php _e('Done') ?></strong></li></ul>
18871 <p> </p>
18872 <p><?php _e('Completed GreyMatter import!') ?></p>
18873 <?php
18874 $this->footer();
18875 return;
18876 }
18877
18878 function dispatch() {
18879 if (empty ($_GET['step']))
18880 $step = 0;
18881 else
18882 $step = (int) $_GET['step'];
18883
18884 switch ($step) {
18885 case 0 :
18886 $this->greet();
18887 break;
18888 case 1:
18889 check_admin_referer('import-greymatter');
18890 $result = $this->import();
18891 if ( is_wp_error( $result ) )
18892 echo $result->get_error_message();
18893 break;
18894 }
18895 }
18896
18897 function GM_Import() {
18898 // Nothing.
18899 }
18900 }
18901
18902 $gm_import = new GM_Import();
18903
18904 register_importer('greymatter', __('GreyMatter'), __('Import users, posts, and comments from a Greymatter blog.'), array ($gm_import, 'dispatch'));
18905 ?>