[ Index ]

PHP Cross Reference of Textpattern 4.0.8

title

Body

[close]

/textpattern/include/import/ -> import_b2.php (source)

   1  <?php
   2      //Absolutely untested. Any volunteer with a b2 db dump to collaborate?
   3  
   4  	function doImportB2($b2dblogin, $b2db, $b2dbpass, $b2dbhost, $insert_into_section, $insert_with_status, $default_comment_invite)
   5      {
   6  
   7          global $txpcfg;
   8          //Keep some response on some part
   9          $results = array();
  10  
  11  
  12          // let's go - Dean says ;-).
  13          $b2link = mysql_connect($b2dbhost,$b2dblogin,$b2dbpass,true);
  14          if(!$b2link){
  15              return 'b2 database values don&#8217;t work. Go back, replace them and try again';
  16          }
  17          mysql_select_db($b2db,$b2link);
  18          $results[]='connected to b2 database. Importing Data';
  19  
  20          // Copy & Paste your table-definitions from b2config.php
  21          $tableposts = 'b2posts';
  22          $tableusers = 'b2users';
  23          $tablecategories = 'b2categories';
  24          $tablecomments = 'b2comments';
  25  
  26  
  27          $a = mysql_query("
  28              select
  29              ".$tableposts.".ID as ID,
  30              ".$tableposts.".post_date as Posted,
  31              ".$tableposts.".post_title as Title,
  32              ".$tableposts.".post_content as Body,
  33              ".$tablecategories.".cat_name as Category1,
  34              ".$tableusers.".user_login as AuthorID
  35              from ".$tableposts."
  36              left join ".$tablecategories." on
  37                  ".$tablecategories.".cat_ID = ".$tableposts.".post_category
  38              left join ".$tableusers." on
  39                  ".$tableusers.".ID = ".$tableposts.".post_author
  40              ORDER BY post_date DESC
  41          ",$b2link) or $results[]= mysql_error();
  42  
  43          while($b=mysql_fetch_array($a)) {
  44              $articles[] = $b;
  45          }
  46  
  47          $a = mysql_query("
  48              select
  49              ".$tablecomments.".comment_ID as discussid,
  50              ".$tablecomments.".comment_post_ID as parentid,
  51              ".$tablecomments.".comment_author_IP as ip,
  52              ".$tablecomments.".comment_author as name,
  53              ".$tablecomments.".comment_author_email as email,
  54              ".$tablecomments.".comment_author_url as web,
  55              ".$tablecomments.".comment_content as message,
  56              ".$tablecomments.".comment_date as posted
  57              from ".$tablecomments."
  58          ",$b2link) or $results[]= mysql_error();
  59  
  60  
  61  
  62          while($b=mysql_fetch_assoc($a)){
  63              $comments[] = $b;
  64          }
  65  
  66          mysql_close($b2link);
  67  
  68          //keep a handy copy of txpdb values, and do not alter Dean code
  69          // for now! ;-)
  70  
  71          $txpdb      = $txpcfg['db'];
  72          $txpdblogin = $txpcfg['user'];
  73          $txpdbpass  = $txpcfg['pass'];
  74          $txpdbhost  = $txpcfg['host'];
  75  
  76          //Yes, we have to make a new connection
  77          //otherwise doArray complains
  78          $DB = new DB;
  79          $txplink = &$DB->link;
  80  
  81          mysql_select_db($txpdb,$txplink);
  82  
  83          include txpath.'/lib/classTextile.php';
  84  
  85          $textile = new Textile;
  86  
  87          if (!empty($articles)) {
  88              foreach($articles as $a){
  89                  if (is_callable('utf8_encode'))
  90                  {
  91                      // Also fixing break-tags for users with b2s Auto-BR
  92                      $a['Body'] = utf8_encode(str_replace("<br />\n","\n",stripslashes($a['Body'])));
  93                      $a['Title'] = utf8_encode(stripslashes($a['Title']));
  94                      $a['Title'] = $textile->TextileThis($a['Title'],'',1);
  95                  }
  96                  // b2 uses the magic word "<!--more-->" to generate excerpts
  97                  if (strpos($a['Body'],'<!--more-->'))
  98                  {
  99                      //Everything that is before "more" can be treated as the excerpt.
 100                      $pos = strpos($a['Body'],'<!--more-->');
 101                      $a['Excerpt'] = substr($a['Body'],0,$pos);
 102                      $a['Excerpt_html'] = $textile->textileThis($a['Excerpt']);
 103                      $a['Body'] = str_replace('<!--more-->','',$a['Body']);
 104                  }
 105                  else
 106                  {
 107                      $a['Excerpt'] = '';
 108                      $a['Excerpt_html'] = '';
 109                  }
 110                  $a['url_title'] = stripSpace($a['Title'],1);
 111                  $a['Body_html'] = $textile->textileThis($a['Body']);
 112                  extract(array_slash($a));
 113                  $q = mysql_query("
 114                      insert into `".PFX."textpattern` set
 115                      ID        = '$ID',
 116                      Posted    = '$Posted',
 117                      Title     = '$Title',
 118                      url_title = '$url_title',
 119                      Body      = '$Body',
 120                      Body_html = '$Body_html',
 121                      Excerpt   = '$Excerpt',
 122                      Excerpt_html = '$Excerpt_html',
 123                      Category1 = '$Category1',
 124                      AuthorID  = '$AuthorID',
 125                      Section   = '$insert_into_section',
 126                      AnnotateInvite = '$default_comment_invite',
 127                      uid='".md5(uniqid(rand(),true))."',
 128                      feed_time='".substr($Posted,0,10)."',
 129                      Status    = '$insert_with_status'
 130                  ",$txplink) or $results[]= mysql_error();
 131  
 132                  if (mysql_insert_id() ) {
 133                      $results[]= 'inserted b2 entry '.$Title.
 134                          ' into Textpattern as article '.$ID.'';
 135                  }
 136              }
 137          }
 138  
 139          if (!empty($comments)) {
 140              foreach ($comments as $comment) {
 141                  extract(array_slash($comment));
 142                  if (is_callable('utf8_encode'))
 143                      $message = utf8_encode($message);
 144                  $message = nl2br($message);
 145  
 146                  $q = mysql_query("insert into `".PFX."txp_discuss` values
 147                      ($discussid,$parentid,'$name','$email','$web','$ip','$posted','$message',1)",
 148                  $txplink) or $results[]= mysql_error($q);
 149  
 150                  if(mysql_insert_id()) {
 151                      $results[]= 'inserted b2 comment <strong>'.$parentid
 152                          .'</strong> into txp_discuss';
 153                  }
 154              }
 155          }
 156          return join('<br />', $results);
 157      }
 158  
 159  ?>


Generated: Thu May 21 23:03:01 2009 Cross-referenced by PHPXref 0.7