[ Index ]
 

Code source de e107 0.7.8

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

title

Body

[fermer]

/e107_files/import/ -> phpnuke.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/phpnuke.php,v $
  14  |     $Revision: 1.2 $
  15  |     $Date: 2005/12/25 02:02:41 $
  16  |     $Author: sweetas $
  17  +----------------------------------------------------------------------------+
  18  */
  19  
  20  require_once ("../../class2.php");
  21  require_once(e_ADMIN."auth.php");
  22  
  23  define("ASYSTEM", "php-nuke");
  24  define("DEFAULTPREFIX", "nuke_");
  25  
  26  if(!isset($_POST['do_conversion']))
  27  {
  28  
  29      $text = "
  30      <table style='width: 100%;' class='fborder'>
  31      <tr>
  32      <td class='forumheader3' style='text-align: center; margin-left: auto; margin-right: auto;'>
  33      This script will import your ".ASYSTEM." database to e107. <br /><br /><br /><b>*** IMPORTANT ***<br />Running this script will empty most of your e107 tables - make sure you have a backup before continuing!</b>
  34  
  35      <br /><br /><br />\n
  36  
  37  
  38      <form method='post' action='".e_SELF."'>
  39      Please enter the details for your ".ASYSTEM." database ...<br /><br />
  40  
  41      <table style='width: 50%;' class='fborder'>
  42      <tr>
  43      <td style='width: 50%; text-align: right;'>Host&nbsp;&nbsp;</td>
  44      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='dbHost' size='30' value='localhost' maxlength='100' />
  45      </tr>
  46      <tr>
  47      <td style='width: 50%; text-align: right;'>Username&nbsp;&nbsp;</td>
  48      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='dbUsername' size='30' value='' maxlength='100' />
  49      </tr>
  50      <tr>
  51      <td style='width: 50%; text-align: right;'>Password&nbsp;&nbsp;</td>
  52      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='dbPassword' size='30' value='' maxlength='100' />
  53      </tr>
  54      <tr>
  55      <td style='width: 50%; text-align: right;'>Database&nbsp;&nbsp;</td>
  56      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='dbDatabase' size='30' value='' maxlength='100' />
  57      </tr>
  58      <tr>
  59      <td style='width: 50%; text-align: right;'>Table Prefix&nbsp;&nbsp;</td>
  60      <td style='width: 50%; text-align: left;'><input class='tbox' type='text' name='dbPrefix' size='30' value='".DEFAULTPREFIX."' maxlength='100' />
  61      </tr>
  62      </table>
  63      <br /><br />
  64      <input class='button' type='submit' name='do_conversion' value='Continue' />
  65      </td>
  66      </tr>
  67      </table>";
  68      
  69      $ns -> tablerender(ASYSTEM." to e107 Conversion Script", $text);
  70      require_once(e_ADMIN."footer.php");
  71      exit;
  72  }
  73  
  74  if(!isset($_POST['dbHost']) || !isset($_POST['dbUsername']) || !isset($_POST['dbPassword']) || !isset($_POST['dbDatabase']))
  75  {
  76      echo "Field(s) left blank, please go back and re-enter values.";
  77      require_once(e_ADMIN."footer.php");
  78      exit;
  79  }
  80  
  81  if(!isset($_POST['dbPrefix']))
  82  {
  83      $nukePrefix = "";
  84  }
  85  
  86  extract($_POST);
  87  
  88  echo "<table style='width: 100%;' class='fborder'>
  89  <tr>
  90  <td class='forumheader3' style='text-align: center; margin-left: auto; margin-right: auto;'>
  91  Attempting to connect to ".ASYSTEM." database [ {$dbDatabase} @ {$dbHost} ] ...<br />\n";
  92  flush();
  93  
  94  $ASystemConnection = mysql_connect($dbHost, $dbUsername, $dbPassword, TRUE);
  95  if(!mysql_select_db($dbDatabase, $ASystemConnection))
  96  {
  97      goError("Error! Cound not connect to ".ASYSTEM." database. Please go back to the previous page and check your settings");
  98  }
  99  
 100  $e107Connection = mysql_connect($mySQLserver, $mySQLuser, $mySQLpassword, TRUE);
 101  if(!mysql_select_db($mySQLdefaultdb, $e107Connection))
 102  {
 103      goError("Error! Cound not connect to e107 database.");
 104  }
 105  
 106  echo "Successfully connected to ".ASYSTEM." and e107 databases ...<br><br />";
 107  
 108  /* ++++++++++++++ USERS ++++++++++++++ */
 109  $result = mysql_query("SELECT * FROM {$dbPrefix}users", $ASystemConnection);
 110  if(!$result)
 111  {
 112      goError("Error! Unable to access ".$dbPrefix."users table.");
 113  }
 114  $pass = 0; $fail = 0;
 115  while($aResult = mysql_fetch_array($result))
 116  {
 117      $aArray = convertUsers();
 118      $query = createQuery($aArray, $aResult, $mySQLprefix."user");        
 119      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 120      flush();
 121  }
 122  echo "Inserted $pass users into database ($fail fails).<br />";
 123  /* +++++++++++++++ END +++++++++++++++ */
 124  
 125  /* ++++++++++++++ NEWS ++++++++++++++ */
 126  $query = "SELECT * FROM {$dbPrefix}stories
 127  LEFT JOIN {$dbPrefix}users ON {$dbPrefix}stories.aid={$dbPrefix}users.username
 128  ORDER BY {$dbPrefix}stories.sid ASC";
 129  
 130  $result = mysql_query($query, $ASystemConnection);
 131  if(!$result)
 132  {
 133      goError("Error! Unable to access ".$dbPrefix."stories table.");
 134  }
 135  $pass = 0; $fail = 0;
 136  while($aResult = mysql_fetch_array($result))
 137  {
 138      $aArray = convertNews();
 139      $query = createQuery($aArray, $aResult, $mySQLprefix."news");        
 140      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 141      flush();
 142  }
 143  echo "Inserted $pass news items into database ($fail fails).<br />";
 144  /* +++++++++++++++ END +++++++++++++++ */
 145  
 146  /* ++++++++++++++ BANLIST ++++++++++++++ */
 147  $result = mysql_query("SELECT * FROM {$dbPrefix}banned_ip", $ASystemConnection);
 148  if(!$result)
 149  {
 150      goError("Error! Unable to access ".$dbPrefix."banned_ip table.");
 151  }
 152  $pass = 0; $fail = 0;
 153  while($aResult = mysql_fetch_array($result))
 154  {
 155      $aArray = convertBans();
 156      $query = createQuery($aArray, $aResult, $mySQLprefix."banlist");        
 157      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 158      flush();
 159  }
 160  echo "Inserted $pass banned IP addresses into database ($fail fails).<br />";
 161  /* +++++++++++++++ END +++++++++++++++ */
 162  
 163  /* ++++++++++++++ CUSTOM PAGES ++++++++++++++ */
 164  $result = mysql_query("SELECT * FROM {$dbPrefix}pages", $ASystemConnection);
 165  if(!$result)
 166  {
 167      goError("Error! Unable to access ".$dbPrefix."pages table.");
 168  }
 169  $pass = 0; $fail = 0;
 170  while($aResult = mysql_fetch_array($result))
 171  {
 172      $aArray = convertPages();
 173      $query = createQuery($aArray, $aResult, $mySQLprefix."page");        
 174      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 175      flush();
 176  }
 177  echo "Inserted $pass custom pages into database ($fail fails).<br />";
 178  /* +++++++++++++++ END +++++++++++++++ */
 179  
 180  
 181  /* ++++++++++++++ FORUMS ++++++++++++++ 
 182  
 183  $result = mysql_query("SHOW COLUMNS FROM {$mySQLprefix}forum", $e107Connection);
 184  if(!$result)
 185  {
 186      goError("Error! Unable to access the e107 'forum' table - have you installed the e107 Forum System plugin?");
 187  }
 188  $result = mysql_query("SELECT * FROM {$dbPrefix}bbforums ORDER BY forum_order ASC", $ASystemConnection);
 189  if(!$result)
 190  {
 191      goError("Error! Unable to access ".$dbPrefix."bbforums table.");
 192  }
 193  $pass = 0; $fail = 0;
 194  while($aResult = mysql_fetch_array($result))
 195  {
 196      $aArray = convertForums();
 197      $query = createQuery($aArray, $aResult, $mySQLprefix."forum");        
 198      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 199      flush();
 200  }
 201  
 202      $query = "INSERT INTO {$mySQLprefix}forum VALUES (0, 'Default Forum Parent', 'This parent has been created by the ".ASYSTEM." conversion script, you can edit it from admin -> forums', '0', '0', '".time()."', '', '0', '0', '', '', '', '0', '0')";
 203      mysql_query($query, $e107Connection);
 204      $id = mysql_insert_id();
 205      $query = "UPDATE {$mySQLprefix}forum SET forum_parent='$id' WHERE forum_name!='Default Forum Parent'";
 206      mysql_query($query, $e107Connection);
 207  
 208  echo "Inserted $pass forums into database ($fail fails).<br />";
 209  /* +++++++++++++++ END +++++++++++++++ */
 210  
 211  
 212  /* ++++++++++++++ FORUM POSTS ++++++++++++++ 
 213  $query = "SELECT * FROM {$dbPrefix}bbposts
 214  LEFT JOIN {$dbPrefix}bbposts_text ON {$dbPrefix}bbposts.post_id={$dbPrefix}bbposts_text.post_id 
 215  LEFT JOIN {$dbPrefix}users ON {$dbPrefix}bbposts.poster_id={$dbPrefix}users.user_id  
 216  ORDER BY {$dbPrefix}bbposts.post_id ASC";
 217  
 218  $result = mysql_query($query, $ASystemConnection);
 219  if(!$result)
 220  {
 221      goError("Error! Unable to access ".$dbPrefix."stories table.");
 222  }
 223  $pass = 0; $fail = 0;
 224  while($aResult = mysql_fetch_array($result))
 225  {
 226      $aArray = convertForumPosts();
 227      $query = createQuery($aArray, $aResult, $mySQLprefix."forum_t");
 228      $poster = ($aResult['poster_id'] == -1 ? "0.".($aResult['username'] ? $aResult['username'] : "Anonymous") : $aResult['poster_id'].".".$aResult['username']);
 229      $query = str_replace("''", "'$poster'", $query);
 230      if(mysql_query($query, $e107Connection)){$pass++;}else{$fail++;}
 231      flush();
 232  }
 233  echo "Inserted $pass forum posts into database ($fail fails).<br />";
 234   +++++++++++++++ END +++++++++++++++ */
 235  
 236  
 237  
 238  echo "</td></tr></table>";
 239  
 240  require_once(e_ADMIN."footer.php");
 241  
 242  
 243  function goError($error)
 244  {
 245      echo "<b>{$error}</b></td></tr></table>";
 246      require_once(e_ADMIN."footer.php");
 247      exit;
 248  }
 249  
 250  
 251  function convertUsers()
 252  {
 253      $rArray = array(
 254          array("asystem" => "user_id", "e107" => "user_id", "type" => "INT"),
 255          array("asystem" => "name", "e107" => "user_login", "type" => "STRING"),
 256          array("asystem" => "username", "e107" => "user_name", "type" => "STRING"),
 257          array("asystem" => "username", "e107" => "user_loginname", "type" => "STRING"),
 258          array("asystem" => "user_password", "e107" => "user_password", "type" => "STRING"),
 259          array("asystem" => "user_email", "e107" => "user_email", "type" => "STRING"),
 260          array("asystem" => "user_avatar", "e107" => "user_image", "type" => "STRING"),
 261          array("asystem" => "user_regdate", "e107" => "user_join", "type" => "STRTOTIME"),
 262          array("asystem" => "user_sig", "e107" => "user_signature", "type" => "STRING"),
 263          array("asystem" => "user_viewemail", "e107" => "user_hideemail", "type" => "INT"),
 264          array("asystem" => "user_posts", "e107" => "user_forums", "type" => "INT"), 
 265          array("asystem" => "user_lastvisit", "e107" => "user_lastvisit", "type" => "INT"), 
 266          array("asystem" => "user_timezone", "e107" => "user_timezone", "type" => "STRING")
 267      );
 268      return $rArray;
 269  }
 270  
 271  function convertNews()
 272  {
 273      $rArray = array(
 274          array("asystem" => "sid", "e107" => "news_id", "type" => "INT"),
 275          array("asystem" => "user_id", "e107" => "news_author", "type" => "INT"),
 276          array("asystem" => "title", "e107" => "news_title", "type" => "STRING"),
 277          array("asystem" => "time", "e107" => " news_datestamp", "type" => "STRTOTIME"),
 278          array("asystem" => "hometext", "e107" => " news_body", "type" => "STRING"),
 279          array("asystem" => "bodytext", "e107" => " news_extended", "type" => "STRING"),
 280          array("asystem" => "comments", "e107" => " news_comment_total", "type" => "INT"),
 281          array("asystem" => "catid", "e107" => " news_category", "type" => "INT")
 282      );
 283      return $rArray;
 284  }
 285  
 286  function convertBans()
 287  {
 288      $rArray = array(
 289          array("asystem" => "ip_address", "e107" => " banlist_ip", "type" => "STRING"),
 290          array("asystem" => "reason", "e107" => "banlist_reason", "type" => "STRING")
 291      );
 292      return $rArray;
 293  }
 294  
 295  
 296  function convertPages()
 297  {
 298      $rArray = array(
 299          array("asystem" => "pid", "e107" => "page_id", "type" => "INT"),
 300          array("asystem" => "title", "e107" => "page_title", "type" => "STRING"),
 301          array("asystem" => "text", "e107" => "page_text", "type" => "STRING"), 
 302          array("asystem" => "date", "e107" => "page_datestamp", "type" => "STRTOTIME")
 303      );
 304      return $rArray;
 305  }
 306  
 307  /*
 308  function convertForums()
 309  {
 310      $rArray = array(
 311          array("asystem" => "forum_id", "e107" => "forum_id", "type" => "INT"),
 312          array("asystem" => "forum_name", "e107" => "forum_name", "type" => "STRING"),
 313          array("asystem" => "forum_desc", "e107" => "forum_description", "type" => "STRING"), 
 314          array("asystem" => "forum_topics", "e107" => "forum_threads", "type" => "INT"), 
 315          array("asystem" => "forum_posts", "e107" => "forum_replies", "type" => "INT"), 
 316          array("asystem" => "null", "e107" => "forum_postclass", "type" => "INT", "value" => 253), 
 317          array("asystem" => "null", "e107" => "forum_moderators", "type" => "INT", "value" => 2), 
 318          array("asystem" => "null", "e107" => "forum_class", "type" => "INT", "value" => 0)
 319      );
 320      return $rArray;
 321  }
 322  
 323  
 324   function convertForumPosts()
 325  {
 326      $rArray = array(
 327          array("asystem" => "post_id", "e107" => "thread_id", "type" => "INT"),
 328          array("asystem" => "topic_id", "e107" => "thread_parent", "type" => "INT"),
 329          array("asystem" => "forum_id", "e107" => "thread_forum_id", "type" => "INT"), 
 330          array("asystem" => "null", "e107" => "thread_active", "type" => "INT", "value" => 1), 
 331          array("asystem" => "poster", "e107" => "thread_user", "type" => "STRING"), 
 332          array("asystem" => "post_time", "e107" => "thread_datestamp", "type" => "INT"), 
 333          array("asystem" => "post_subject", "e107" => "thread_name", "type" => "STRING"), 
 334          array("asystem" => "post_text", "e107" => "thread_thread", "type" => "STRING")
 335      );
 336      return $rArray;
 337  }
 338  */
 339  
 340  
 341  
 342  
 343  
 344  
 345  
 346  
 347  
 348  
 349  
 350  
 351  
 352  
 353  function createQuery($convertArray, $dataArray, $table)
 354  {
 355      global $tp;
 356  
 357      $columns = "(";
 358      $values = "(";
 359  
 360  
 361      foreach($convertArray as $convert)
 362      {
 363          if($convert['type'] == "STRING")
 364          {
 365              $dataArray[$convert['asystem']] = preg_replace("#\[.*\]#", "", $tp -> toDB($dataArray[$convert['asystem']]));
 366          }
 367          else if($convert['type'] == "STRTOTIME")
 368          {
 369              $dataArray[$convert['asystem']] = strtotime($dataArray[$convert['asystem']]);
 370          }
 371  
 372          $columns .= $convert['e107'].",";
 373          $values .= (array_key_exists("value", $convert) ? "'".$convert['value']."'," : "'".$dataArray[$convert['asystem']]."',");
 374      }
 375      
 376  
 377      $columns = substr($columns, 0, -1).")";
 378      $values = substr($values, 0, -1).")";
 379  
 380      return "INSERT INTO $table $columns VALUES $values";
 381      
 382  }    
 383  
 384  
 385  
 386  
 387  
 388  
 389  
 390  
 391  
 392  
 393  ?>


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