[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/include/admin/importers/ -> nucleus.inc.php (source)

   1  <?php # $Id: nucleus.inc.php 1463 2006-10-27 09:20:03Z garvinhicking $
   2  # Copyright (c) 2003-2005, Jannis Hermanns (on behalf the Serendipity Developer Team)
   3  # All rights reserved.  See LICENSE file for licensing details
   4  
   5  /*****************************************************************
   6   *  Nucleus  Importer, by Garvin Hicking *
   7   * ****************************************************************/
   8  
   9  class Serendipity_Import_Nucleus extends Serendipity_Import {
  10      var $info        = array('software' => 'Nucleus');
  11      var $data        = array();
  12      var $inputFields = array();
  13  
  14  
  15      function Serendipity_Import_Nucleus($data) {
  16          $this->data = $data;
  17          $this->inputFields = array(array('text' => INSTALL_DBHOST,
  18                                           'type' => 'input',
  19                                           'name' => 'host'),
  20  
  21                                     array('text' => INSTALL_DBUSER,
  22                                           'type' => 'input',
  23                                           'name' => 'user'),
  24  
  25                                     array('text' => INSTALL_DBPASS,
  26                                           'type' => 'protected',
  27                                           'name' => 'pass'),
  28  
  29                                     array('text' => INSTALL_DBNAME,
  30                                           'type' => 'input',
  31                                           'name' => 'name'),
  32  
  33                                     array('text' => INSTALL_DBPREFIX,
  34                                           'type' => 'input',
  35                                           'name' => 'prefix',
  36                                           'default' => 'nucleus_'),
  37  
  38                                     array('text'    => CHARSET,
  39                                           'type'    => 'list',
  40                                           'name'    => 'charset',
  41                                           'value'   => 'native',
  42                                           'default' => $this->getCharsets()),
  43  
  44                                     array('text'    => CONVERT_HTMLENTITIES,
  45                                           'type'    => 'bool',
  46                                           'name'    => 'use_strtr',
  47                                           'default' => 'true'),
  48  
  49                                     array('text'    => ACTIVATE_AUTODISCOVERY,
  50                                           'type'    => 'bool',
  51                                           'name'    => 'autodiscovery',
  52                                           'default' => 'false')
  53                              );
  54      }
  55  
  56      function validateData() {
  57          return sizeof($this->data);
  58      }
  59  
  60      function getInputFields() {
  61          return $this->inputFields;
  62      }
  63  
  64      function import() {
  65          global $serendipity;
  66  
  67          // Save this so we can return it to its original value at the end of this method.
  68          $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
  69  
  70          if ($this->data['autodiscovery'] == 'false') {
  71              $serendipity['noautodiscovery'] = 1;
  72          }
  73          
  74          $this->getTransTable();
  75  
  76          $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
  77          $users = array();
  78          $categories = array();
  79          $entries = array();
  80  
  81          if (!extension_loaded('mysql')) {
  82              return MYSQL_REQUIRED;;
  83          }
  84  
  85          $nucdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
  86          if (!$nucdb) {
  87              return sprintf(COULDNT_CONNECT, $this->data['host']);
  88          }
  89  
  90          if (!@mysql_select_db($this->data['name'])) {
  91              return sprintf(COULDNT_SELECT_DB, mysql_error($nucdb));
  92          }
  93  
  94          /* Users */
  95          $res = @$this->nativeQuery("SELECT mnumber AS ID, mname AS user_login, mpassword AS user_pass, memail AS user_email, madmin AS user_level FROM {$this->data['prefix']}member;", $nucdb);
  96          if (!$res) {
  97              return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($nucdb));
  98          }
  99  
 100          for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
 101              $users[$x] = mysql_fetch_assoc($res);
 102  
 103              $data = array('right_publish' => ($users[$x]['user_level'] >= 1) ? 1 : 0,
 104                            'realname'      => $users[$x]['user_login'],
 105                            'username'      => $users[$x]['user_login'],
 106                            'email'         => $users[$x]['user_email'],
 107                            'password'      => $users[$x]['user_pass']); // Nucleus uses md5, too.
 108  
 109              if ( $users[$x]['user_level'] < 1 ) {
 110                  $data['userlevel'] = USERLEVEL_EDITOR;
 111              } else {
 112                  $data['userlevel'] = USERLEVEL_ADMIN;
 113              }
 114  
 115              if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
 116                  $data['userlevel'] = $serendipity['serendipityUserlevel'];
 117              }
 118  
 119              serendipity_db_insert('authors', $this->strtrRecursive($data));
 120              $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
 121          }
 122  
 123          /* Categories */
 124          $res = @$this->nativeQuery("SELECT catid AS cat_ID, cname AS cat_name, cdesc AS category_description FROM {$this->data['prefix']}category ORDER BY catid;", $nucdb);
 125          if (!$res) {
 126              return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($nucdb));
 127          }
 128  
 129          // Get all the info we need
 130          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
 131              $categories[] = mysql_fetch_assoc($res);
 132          }
 133  
 134          // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
 135          for ($x=0, $max_x = sizeof($categories) ; $x < $max_x ; $x++ ) {
 136              $cat = array('category_name'        => $categories[$x]['cat_name'],
 137                           'category_description' => $categories[$x]['category_description'],
 138                           'parentid'             => 0, // <---
 139                           'category_left'        => 0,
 140                           'category_right'       => 0);
 141  
 142              serendipity_db_insert('category', $this->strtrRecursive($cat));
 143              $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
 144          }
 145  
 146          serendipity_rebuildCategoryTree();
 147  
 148          /* Entries */
 149          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}item ORDER BY itime;", $nucdb);
 150          if (!$res) {
 151              return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($nucdb));
 152          }
 153  
 154          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
 155              $entries[$x] = mysql_fetch_assoc($res);
 156  
 157              $entry = array('title'          => $this->decode($entries[$x]['ititle']),
 158                             'isdraft'        => ($entries[$x]['idraft'] != '1') ? 'false' : 'true',
 159                             'allow_comments' => ($entries[$x]['iclosed'] == '1' ) ? 'false' : 'true',
 160                             'timestamp'      => strtotime($entries[$x]['itime']),
 161                             'extended'       => $this->strtr($entries[$x]['imore']),
 162                             'body'           => $this->strtr($entries[$x]['ibody']));
 163  
 164              $entry['authorid'] = '';
 165              $entry['author']   = '';
 166              foreach ($users as $user) {
 167                  if ($user['ID'] == $entries[$x]['iauthor']) {
 168                      $entry['authorid'] = $user['authorid'];
 169                      $entry['author']   = $user['realname'];
 170                      break;
 171                  }
 172              }
 173  
 174              if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
 175                  return $entries[$x]['entryid'];
 176              }
 177  
 178              /* Entry/category */
 179              foreach ($categories as $category) {
 180                  if ($category['cat_ID'] == $entries[$x]['icat'] ) {
 181                      $data = array('entryid'    => $entries[$x]['entryid'],
 182                                    'categoryid' => $category['categoryid']);
 183                      serendipity_db_insert('entrycat', $this->strtrRecursive($data));
 184                      break;
 185                  }
 186              }
 187          }
 188  
 189          /* Comments */
 190          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comment;", $nucdb);
 191          if (!$res) {
 192              return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($nucdb));
 193          }
 194  
 195          while ($a = mysql_fetch_assoc($res)) {
 196              foreach ($entries as $entry) {
 197                  if ($entry['inumber'] == $a['citem'] ) {
 198                      $author   = '';
 199                      $mail     = '';
 200                      if (!empty($a['cmember'])) {
 201                          foreach($users AS $user) {
 202                              if ($user['ID'] == $a['cmember']) {
 203                                  $author = $user['user_login'];
 204                                  $mail = $user['user_email'];
 205                                  break;
 206                              }
 207                          }
 208                      }
 209  
 210                      if (empty($author) && empty($mail)) {
 211                          $author = $a['cuser'];
 212                          $mail = $a['cmail'];
 213                      }
 214  
 215                      $comment = array('entry_id ' => $entry['entryid'],
 216                                       'parent_id' => 0,
 217                                       'timestamp' => strtotime($a['ctime']),
 218                                       'author'    => $author,
 219                                       'email'     => $mail,
 220                                       'url'       => $a['chost'],
 221                                       'ip'        => $a['cip'],
 222                                       'status'    => 'approved',
 223                                       'body'      => $a['cbody'],
 224                                       'subscribed'=> 'false',
 225                                       'type'      => 'NORMAL');
 226  
 227                      serendipity_db_insert('comments', $this->strtrRecursive($comment));
 228                      $cid = serendipity_db_insert_id('comments', 'id');
 229                      serendipity_approveComment($cid, $entry['entryid'], true);
 230                  }
 231              }
 232          }
 233  
 234          $serendipity['noautodiscovery'] = $noautodiscovery;
 235  
 236          // That was fun.
 237          return true;
 238      }
 239  }
 240  
 241  return 'Serendipity_Import_Nucleus';
 242  
 243  /* vim: set sts=4 ts=4 expandtab : */
 244  ?>


Généré le : Sat Nov 24 09:00:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics