[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_files/import/ -> phpbb2.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_files/import/phpbb2.php,v $
  14  |     $Revision: 1.8 $
  15  |     $Date: 2006/09/29 00:48:11 $
  16  |     $Author: mcfly_e107 $
  17  |
  18  |     31/1/2006  Changes by Albert Drent
  19  |                Aducom Software
  20  |                www.aducom.com
  21  |
  22  |      20/4/2006  Tweaks by steved, based on information from Prodigal and forum thread:
  23  |                    Processing routine made more generic
  24  |                    BBCode processing options - strip, phpbb processing, mapping
  25  |                    Allows setting of default for null field
  26  |                    Forces null integer field to zero (required for mySQL5?)
  27  |                    Sets forum_moderators to empty
  28  |                    User last visit and reg. date added (may not be suitable format)
  29  |
  30  |      17/5/2006  Tweak to bring across admins as well, other than user ID = 1 (which will be E107 main admin)
  31  |                 Include of mapper function moved to earlier in file to try and avoid error.
  32  |      18/5/2006  Table added to convert IMG and URL bbcodes to lower case.
  33  |      25/5/2006  Modifications to original script made by McFly (version 1.5) added where appropriate.
  34  |      10/6/2006  Bug fix - user_join mapping line specified twice
  35  |                 BBCodes now decoded in signatures as well as forums
  36  |      11/6/2006  zeronull code added to try and sort user_perms
  37  |
  38  | Note: Apparently no field in the phpbb database with which to populate 'last post' - but can
  39  |            be recalculated through E107.
  40  |
  41  | Note: Typically phpbb tables are prefixed '_phpbb_'
  42  +----------------------------------------------------------------------------+
  43  */
  44  
  45  require_once ("../../class2.php");
  46  require_once(e_ADMIN."auth.php");
  47  
  48  if(!isset($_POST['do_conversion']))
  49  {
  50  
  51      $text = "
  52      <table style='width: 100%;' class='fborder'>
  53      <tr>
  54      <td class='forumheader3' style='text-align: center; margin-left: auto; margin-right: auto;'>
  55      This script will import your phpBB2 database to e107. It will copy over users, forums, forum posts and polls.<br /><br /><br /><b>*** IMPORTANT ***<br />Running this script will empty your e107 forum, users and polls table - make sure you have a backup before continuing!</b>
  56  
  57      <br /><br /><br />\n
  58  
  59  
  60      <form method='post' action='".e_SELF."'>
  61      Please enter the details for your phpBB2 database ...<br /><br />
  62  
  63      <table style='width: 50%;' class='fborder'>
  64      <tr>
  65      <td style='width: 50%; text-align: right;'>Host&nbsp;&nbsp;</td>
  66      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='phpbb2Host' size='30' value='localhost' maxlength='100' />
  67      </tr>
  68      <tr>
  69      <td style='width: 50%; text-align: right;'>Username&nbsp;&nbsp;</td>
  70      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='phpbb2Username' size='30' value='' maxlength='100' />
  71      </tr>
  72      <tr>
  73      <td style='width: 50%; text-align: right;'>Password&nbsp;&nbsp;</td>
  74      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='phpbb2Password' size='30' value='' maxlength='100' />
  75      </tr>
  76      <tr>
  77      <td style='width: 50%; text-align: right;'>Database&nbsp;&nbsp;</td>
  78      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='phpbb2Database' size='30' value='phpbb2' maxlength='100' />
  79      </tr>
  80      <tr>
  81      <td style='width: 50%; text-align: right;'>Table Prefix&nbsp;&nbsp;</td>
  82      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='phpbb2Prefix' size='30' value='phpbb_' maxlength='100' />
  83      </tr>
  84      </table>
  85      <br /><br />
  86      <input class='button' type='submit' name='do_conversion' value='Continue' />
  87      </td>
  88      </tr>
  89      </table>";
  90      
  91      $ns -> tablerender("phpBB2 to e107 Conversion Script", $text);
  92      require_once(e_ADMIN."footer.php");
  93      exit;
  94  }
  95  
  96  if(!isset($_POST['phpbb2Host']) || !isset($_POST['phpbb2Username']) || !isset($_POST['phpbb2Password']) || !isset($_POST['phpbb2Database']))
  97  {
  98      echo "Field(s) left blank, please go back and re-enter values.";
  99      require_once(e_ADMIN."footer.php");
 100      exit;
 101  }
 102  
 103  if(!isset($_POST['phpbb2Prefix']))
 104  {
 105      $phpbb2Prefix = "";
 106  }
 107  
 108  extract($_POST);
 109  
 110  echo "<table style='width: 100%;' class='fborder'>
 111  <tr>
 112  <td class='forumheader3' style='text-align: center; margin-left: auto; margin-right: auto;'>
 113  Attempting to connect to phpBB database [ {$phpbb2Database} @ {$phpbb2Host} ] ...<br />\n";
 114  flush();
 115  
 116  $phpbbConnection = mysql_connect($phpbb2Host, $phpbb2Username, $phpbb2Password, TRUE);
 117  if(!mysql_select_db($phpbb2Database, $phpbbConnection))
 118  {
 119      goError("Error! Could not connect to phpBB database. Please go back to the previous page and check your settings");
 120  }
 121  
 122  $e107Connection = mysql_connect($mySQLserver, $mySQLuser, $mySQLpassword, TRUE);
 123  if(!mysql_select_db($mySQLdefaultdb, $e107Connection))
 124  {
 125      goError("Error! Could not connect to e107 database.");
 126  }
 127  
 128  echo "Successfully connected to phpBB and e107 databases ...<br><br />";
 129  
 130  
 131  $phpbb_res = mysql_query("SELECT * FROM {$phpbb2Prefix}users", $phpbbConnection);
 132  if(!$phpbb_res)
 133  {
 134      goError("Error! Unable to access ".$phpbb2Prefix."users table.");
 135  }
 136  
 137  require_once ('import_mapper.php');
 138  
 139  
 140  //------------------------------------------------------
 141  //      Convert users
 142  //------------------------------------------------------
 143  while($user = mysql_fetch_array($phpbb_res))
 144  {
 145      $userArray = convertUsers();
 146  //    if($user['user_level'] != 1 && $user['user_id'] != -1)
 147  // Convert any user other than ID=1 (which will be E107 main admin)
 148      if($user['user_id'] > 1)
 149      {
 150          $query = createQuery($userArray, $user, $mySQLprefix."user");        
 151          echo (mysql_query($query, $e107Connection) ? "Successfully inserted user: ".$user['user_id'].": ".$user['username'] : "Unable to insert user: ".$user['user_id'].": ".$user['username']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
 152          flush();
 153      }
 154  }
 155  
 156  
 157  //-----------------------------------------------------------
 158  // ### get phpbb categories and insert them as forum parents
 159  //-----------------------------------------------------------
 160  
 161  mysql_query("TRUNCATE TABLE {$mySQLprefix}forum", $e107Connection);
 162  
 163  
 164  $phpbb_res = mysql_query("SELECT * FROM {$phpbb2Prefix}categories", $phpbbConnection);
 165  if(!$phpbb_res)
 166  {
 167      goError("Error! Unable to access ".$phpbb2Prefix."categories table.");
 168  }
 169  
 170  $catcount = 500;
 171  while($parent = mysql_fetch_array($phpbb_res))
 172  {
 173  
 174      $parentArray = convertParents($catcount);
 175      
 176      $query = createQuery($parentArray, $parent, $mySQLprefix."forum");    
 177      echo (mysql_query($query, $e107Connection) ? "Successfully inserted parent: ".$parent['cat_id'].": ".$parent['cat_title'] : "Unable to insert parent: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
 178      flush();
 179  
 180      $phpbb_res2 = mysql_query("SELECT * FROM {$phpbb2Prefix}forums WHERE cat_id = ".$parent['cat_id'], $phpbbConnection);
 181      if($phpbb_res2)
 182      {
 183          while($forum = mysql_fetch_array($phpbb_res2))
 184          {
 185              $forumArray = convertForums($catcount);
 186              $query = createQuery($forumArray, $forum, $mySQLprefix."forum");
 187              echo (mysql_query($query, $e107Connection) ? "Successfully inserted forum: ".$parent['cat_id'].": ".$parent['cat_title'] : "Unable to insert forum: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
 188              flush();
 189          }
 190      }
 191      else
 192      {
 193          echo "Didn't find any forums for parent '".$parent['cat_title']."'<br />";
 194      }
 195      $catcount ++;
 196  }
 197  
 198  
 199  //------------------------------------------------------
 200  //          Read in forum topics
 201  //------------------------------------------------------
 202  
 203  mysql_query("TRUNCATE TABLE {$mySQLprefix}forum_t", $e107Connection);
 204  mysql_query("TRUNCATE TABLE {$mySQLprefix}polls", $e107Connection);
 205  
 206  $query = "SELECT * FROM {$phpbb2Prefix}topics
 207  LEFT JOIN {$phpbb2Prefix}posts_text ON ({$phpbb2Prefix}topics.topic_title = {$phpbb2Prefix}posts_text.post_subject)
 208  LEFT JOIN {$phpbb2Prefix}posts ON ({$phpbb2Prefix}posts.post_id = {$phpbb2Prefix}posts_text.post_id)
 209  ORDER BY topic_time ASC";
 210  
 211  $phpbb_res = mysql_query($query, $phpbbConnection);
 212  if(!$phpbb_res)
 213  {
 214      goError("Error! Unable to access ".$phpbb2Prefix."topics table.");
 215  }
 216  while($topic = mysql_fetch_array($phpbb_res))
 217  {
 218  
 219      //echo "<pre>"; print_r($topic); echo "</pre>";
 220  
 221      if($topic['topic_vote'])
 222      {
 223          // poll attached to this topic ...
 224          $topic['topic_title'] = "[poll] ".$topic['topic_title'];
 225          $query = "SELECT * FROM {$phpbb2Prefix}vote_desc WHERE topic_id=".$topic['topic_id'];
 226          $phpbb_res3 = mysql_query($query, $phpbbConnection);
 227          $pollQ = mysql_fetch_array($phpbb_res3);
 228  
 229          $query = "SELECT * FROM {$phpbb2Prefix}vote_results WHERE vote_id=".$pollQ['vote_id'];
 230          $phpbb_res3 = mysql_query($query, $phpbbConnection);
 231          $options = "";
 232          $votes = "";
 233          while($pollO = mysql_fetch_array($phpbb_res3))
 234          {
 235              $options .= $pollO['vote_option_text'].chr(1);
 236              $votes .= $pollO['vote_result'].chr(1);
 237          }
 238  
 239          extract($pollQ);
 240          $vote_text = $tp->toDB($vote_text);        // McFly added 25/5/06
 241          $options = $tp->toDB($options);            // McFly added 25/5/06
 242          $query = "INSERT INTO ".$mySQLprefix."polls VALUES ('0', {$vote_start}, {$vote_start}, 0, 0, '{$vote_text}', '{$options}', '{$votes}', '', 2, 0, 0, 0, 255, 0)";
 243          echo (mysql_query($query, $e107Connection) ? "Poll successfully inserted" : "Unable to insert poll ({$query})")."<br />";
 244      }
 245  
 246  
 247      if($topic['topic_poster'] == 2)
 248      {
 249          $topic['topic_poster'] = 1;
 250      }
 251  
 252      if($topic['topic_poster'] == -1)
 253      {
 254          $poster = ($topic['post_username'] ? $topic['post_username'] : "Anonymous");
 255          $topic['topic_poster'] = "0.".$poster;         // McFly moved, edited 25/5/06
 256      }
 257  
 258      $topicArray = convertTopics();                    // McFly edited 25/5/06
 259      $query = createQuery($topicArray, $topic, $mySQLprefix."forum_t");
 260  
 261      if(!mysql_query($query, $e107Connection))
 262      {
 263          echo "Unable to insert topic: ".$topic['topic_id']."<br />";
 264          flush();
 265      }
 266      else
 267      {
 268          echo "Successfully inserted topic: ".$topic['topic_id']."<br />";
 269          flush();
 270          $parent_id = mysql_insert_id();
 271          $topic_id = $topic['topic_id'];
 272  
 273          //echo "PARENT: $parent_id, TOPIC: $topic_id<br />"; 
 274  
 275          $query = "SELECT * FROM {$phpbb2Prefix}posts LEFT JOIN {$phpbb2Prefix}posts_text ON ({$phpbb2Prefix}posts.post_id = {$phpbb2Prefix}posts_text.post_id) WHERE topic_id='{$topic_id}' AND post_subject = '' ORDER BY post_time DESC";
 276          $phpbb_res2 = mysql_query($query, $phpbbConnection);
 277          if(!$phpbb_res2)
 278          {
 279              goError("Error! Unable to access ".$phpbb2Prefix."posts / ".$phpbb2Prefix."posts_text table.");
 280          }
 281          while($post = mysql_fetch_array($phpbb_res2))
 282          {
 283              
 284              if($post['poster_id'] == 2)
 285              {
 286                  $post['poster_id'] = 1;
 287              }
 288              if($post['poster_id'] == -1)
 289              {
 290                  $poster = ($post['post_username'] ? $post['post_username'] : "Anonymous");
 291                  $post['poster_id'] = "0.".$poster;        // McFly moved, edited 25/5/06
 292              }
 293      
 294  
 295              $postArray = convertForumPosts($parent_id, $poster);
 296              $query = createQuery($postArray, $post, $mySQLprefix."forum_t",$mapdata);    
 297              echo (mysql_query($query, $e107Connection) ? "Successfully inserted thread: ".$post['post_id'] : "Unable to insert thread: ".$parent['cat_id'].": ".$parent['cat_title']."<br />".mysql_errno() . ": " . mysql_error())."<br />";
 298              flush();
 299          }
 300      }
 301  }
 302  
 303  //------------------------------------------------------
 304  //          Consider polls here later
 305  //------------------------------------------------------
 306  
 307  echo "</td></tr></table>";
 308  
 309  require_once(e_ADMIN."footer.php");
 310  
 311  
 312  function goError($error)
 313  {
 314      echo "<b>{$error}</b></td></tr></table>";
 315      require_once(e_ADMIN."footer.php");
 316      exit;
 317  }
 318  
 319  //-----------------------------------------------------------
 320  //     Table to convert selected bbcodes to lower case
 321  //-----------------------------------------------------------
 322  //$mapdata = array("URL" => "url","IMG" => "img");
 323  $mapdata = array();
 324  
 325  function convertUsers()
 326  {
 327      $usersArray = array(
 328          array("srcdata" => "user_id", "e107" => "user_id", "type" => "INT"),
 329          array("srcdata" => "username", "e107" => "user_name", "type" => "STRING"),
 330          array("srcdata" => "username", "e107" => "user_loginname", "type" => "STRING"),
 331          array("srcdata" => "user_password", "e107" => "user_password", "type" => "STRING"),
 332          array("srcdata" => "user_email", "e107" => "user_email", "type" => "STRING"),
 333          array("srcdata" => "user_sig", "e107" => "user_signature", "type" => "STRING", "sproc" => "usebb,phpbb,bblower"),
 334          array("srcdata" => "user_viewemail", "e107" => "user_hideemail", "type" => "INT"),
 335          array("srcdata" => "user_regdate", "e107" => "user_join", "type" => "INT"),
 336          array("srcdata" => "user_posts", "e107" => "user_forums", "type" => "INT"),
 337          array("srcdata" => "user_level", "e107" => "user_admin", "type" => "INT"),
 338          array("srcdata" => "user_lastvisit","e107" => "user_lastvisit", "type" => "INT"),
 339  // Rest of these added by McFly 
 340          array("srcdata" => "null", "e107" => "user_prefs", "type" => "INT", "value" => 0),
 341          array("srcdata" => "null", "e107" => "user_new", "type" => "INT", "value" => 0),
 342          array("srcdata" => "null", "e107" => "user_realm", "type" => "INT", "value" => 0),
 343          array("srcdata" => "null", "e107" => "user_class", "type" => "INT", "value" => 0),
 344          array("srcdata" => "null", "e107" => "user_viewed", "type" => "INT", "value" => 0),
 345  // This one changed from McFly's code to try and get null string if non-admin
 346          array("srcdata" => "user_level", "e107" => "user_perms", "type" => "INT", "sproc" => "zeronull")    );
 347      return $usersArray;
 348  }
 349  
 350  function convertParents($catid)
 351  {
 352      $parentArray = array(
 353          array("srcdata" => "cat_id", "e107" => "forum_id", "type" => "INT", "value" => $catid),
 354          array("srcdata" => "cat_title", "e107" => "forum_name", "type" => "STRING"),
 355          array("srcdata" => "cat_order", "e107" => "forum_order", "type" => "INT"),
 356  // Rest of these added by McFly
 357          array("srcdata" => "cat_desc", "e107" => "forum_description", "type" => "STRING"),
 358          array("srcdata" => "null", "e107" => "forum_moderators", "type" => "INT", "value" => 254)
 359      );
 360      return $parentArray;
 361  }
 362  
 363  function convertForums($catid)
 364  {
 365      $forumArray = array(
 366          array("srcdata" => "forum_id", "e107" => "forum_id", "type" => "INT"),
 367          array("srcdata" => "cat_id", "e107" => "forum_parent", "type" => "STRING", "value" => $catid),
 368          array("srcdata" => "forum_name", "e107" => "forum_name", "type" => "STRING"),
 369          array("srcdata" => "forum_desc", "e107" => "forum_description", "type" => "STRING"),
 370          array("srcdata" => "forum_order", "e107" => "forum_order", "type" => "INT"),
 371          array("srcdata" => "forum_topics", "e107" => "forum_threads", "type" => "INT"),
 372          array("srcdata" => "forum_posts", "e107" => "forum_replies", "type" => "INT"),
 373  //        array("srcdata" => "null", "e107" => "forum_moderators", "type" => "STRING")
 374  // Previous line replaced with this on the basis that McFly knows best
 375          array("srcdata" => "null", "e107" => "forum_moderators", "type" => "INT", "value" => 254)
 376      );
 377      return $forumArray;
 378  }
 379  
 380  
 381  //function convertTopics($poster)
 382  // Changed by McFly
 383  function convertTopics()
 384  {
 385      $topicArray = array(
 386          array("srcdata" => "forum_id", "e107" => "thread_forum_id", "type" => "INT"),
 387          array("srcdata" => "topic_title", "e107" => "thread_name", "type" => "STRING"),
 388          array("srcdata" => "post_text", "e107" => "thread_thread", "type" => "STRING", "default" => "", "sproc" => "usebb,phpbb,bblower"),
 389  //        array("srcdata" => "topic_poster", "e107" => "thread_user", "type" => "INT"),
 390  // Previous line replaced by next - GAT McFly
 391          array("srcdata" => "topic_poster", "e107" => "thread_user", "type" => "STRING"),
 392          array("srcdata" => "null", "e107" => "thread_active", "type" => "INT", "value" => 1),
 393          array("srcdata" => "topic_time", "e107" => "thread_datestamp", "type" => "INT"),
 394          array("srcdata" => "topic_views", "e107" => "thread_views", "type" => "INT"),
 395          array("srcdata" => "topic_replies", "e107" => "thread_total_replies", "type" => "INT"),
 396          array("srcdata" => "null", "e107" => "thread_parent", "type" => "INT", "value" => 0),
 397      );
 398      return $topicArray;
 399  }
 400  
 401  
 402  
 403  
 404  function convertForumPosts($parent_id, $poster)
 405  {
 406      $postArray = array(
 407          array("srcdata" => "post_text", "e107" => "thread_thread", "type" => "STRING", "default" => "", "sproc" => "usebb,phpbb,bblower"),
 408          array("srcdata" => "forum_id", "e107" => "thread_forum_id", "type" => "INT"),
 409          array("srcdata" => "post_time", "e107" => "thread_datestamp", "type" => "INT"),
 410          array("srcdata" => "topic_views", "e107" => "thread_views", "type" => "INT"),
 411          array("srcdata" => "post_time", "e107" => "thread_lastpost", "type" => "INT"),
 412  //        array("srcdata" => "poster_id", "e107" => "thread_user", "type" => "INT"),
 413  // Previous line replaced by next - GAT McFly
 414          array("srcdata" => "poster_id", "e107" => "thread_user", "type" => "STRING"),
 415          array("srcdata" => "post_subject", "e107" => "thread_name", "type" => "STRING"),
 416          array("srcdata" => "null", "e107" => "thread_parent", "type" => "INT", "value" => $parent_id),
 417      );
 418      return $postArray;
 419  }
 420  
 421  
 422  /*
 423  -- --------------------------------------------------------
 424  PHPBB uses three tables to record a poll. Looks wildly different to E107!
 425  -- 
 426  -- Table structure for table `_phpbb_vote_desc`
 427  -- 
 428  
 429  CREATE TABLE `_phpbb_vote_desc` (
 430    `vote_id` mediumint(8) unsigned NOT NULL auto_increment,
 431    `topic_id` mediumint(8) unsigned NOT NULL default '0',
 432    `vote_text` text NOT NULL,
 433    `vote_start` int(11) NOT NULL default '0',
 434    `vote_length` int(11) NOT NULL default '0',
 435    PRIMARY KEY  (`vote_id`),
 436    KEY `topic_id` (`topic_id`)
 437  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;
 438  
 439  -- --------------------------------------------------------
 440  
 441  -- 
 442  -- Table structure for table `_phpbb_vote_results`
 443  -- 
 444  
 445  CREATE TABLE `_phpbb_vote_results` (
 446    `vote_id` mediumint(8) unsigned NOT NULL default '0',
 447    `vote_option_id` tinyint(4) unsigned NOT NULL default '0',
 448    `vote_option_text` varchar(255) NOT NULL default '',
 449    `vote_result` int(11) NOT NULL default '0',
 450    KEY `vote_option_id` (`vote_option_id`),
 451    KEY `vote_id` (`vote_id`)
 452  ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 453  
 454  -- --------------------------------------------------------
 455  
 456  -- 
 457  -- Table structure for table `_phpbb_vote_voters`
 458  -- 
 459  
 460  CREATE TABLE `_phpbb_vote_voters` (
 461    `vote_id` mediumint(8) unsigned NOT NULL default '0',
 462    `vote_user_id` mediumint(8) NOT NULL default '0',
 463    `vote_user_ip` char(8) NOT NULL default '',
 464    KEY `vote_id` (`vote_id`),
 465    KEY `vote_user_id` (`vote_user_id`),
 466    KEY `vote_user_ip` (`vote_user_ip`)
 467  ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 468  
 469  */
 470  
 471  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7