[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: bblog.inc.php 144 2005-06-05 17:53:31Z 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   *  bblog  Importer,    by Garvin Hicking *
   7   * ****************************************************************/
   8  
   9  class Serendipity_Import_bblog extends Serendipity_Import {
  10      var $info        = array('software' => 'bBlog 0.7.4');
  11      var $data        = array();
  12      var $inputFields = array();
  13      var $categories  = array();
  14  
  15      function Serendipity_Import_bblog($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' => 'bB_'),
  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          $entries = array();
  79  
  80          if (!extension_loaded('mysql')) {
  81              return MYSQL_REQUIRED;
  82          }
  83  
  84          $bblogdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
  85          if (!$bblogdb) {
  86              return sprintf(COULDNT_CONNECT, $this->data['host']);
  87          }
  88  
  89          if (!@mysql_select_db($this->data['name'])) {
  90              return sprintf(COULDNT_SELECT_DB, mysql_error($bblogdb));
  91          }
  92  
  93          /* Users */
  94          $res = @$this->nativeQuery("SELECT id         AS ID,
  95                                      password   AS pw,
  96                                      nickname   AS user_login,
  97                                      email      AS user_email,
  98                                      url        AS user_url
  99                                 FROM {$this->data['prefix']}authors", $bblogdb);
 100          if (!$res) {
 101              return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($bblogdb));
 102          }
 103  
 104          for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
 105              $users[$x] = mysql_fetch_assoc($res);
 106  
 107              $data = array('right_publish' => 1,
 108                            'username'      => $users[$x]['user_login'],
 109                            'email'         => $users[$x]['user_email'],
 110                            'userlevel'     => USERLEVEL_ADMIN,
 111                            'password'      => md5($users[$x]['pw'])); // Wicked. This is the first blog I've seen storing cleartext passwords :-D
 112  
 113              if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
 114                  $data['userlevel'] = $serendipity['serendipityUserlevel'];
 115              }
 116  
 117              serendipity_db_insert('authors', $this->strtrRecursive($data));
 118              echo mysql_error();
 119              $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
 120          }
 121  
 122          /* Categories */
 123          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}sections", $bblogdb);
 124          if (!$res) {
 125              return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($bblogdb));
 126          }
 127  
 128          // Get all the info we need
 129          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
 130              $row = mysql_fetch_assoc($res);
 131              $cat = array('category_name'        => $row['nicename'],
 132                           'category_description' => $row['nicename'],
 133                           'parentid'             => 0,
 134                           'category_left'        => 0,
 135                           'category_right'       => 0);
 136  
 137              serendipity_db_insert('category', $this->strtrRecursive($cat));
 138              $row['categoryid']  = serendipity_db_insert_id('category', 'categoryid');
 139              $this->categories[] = $row;
 140          }
 141  
 142          serendipity_rebuildCategoryTree();
 143  
 144          /* Entries */
 145          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}posts ORDER BY postid;", $bblogdb);
 146          if (!$res) {
 147              return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($bblogdb));
 148          }
 149  
 150          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
 151              $entries[$x] = mysql_fetch_assoc($res);
 152  
 153              $entry = array('title'          => $this->decode($entries[$x]['title']),
 154                             'isdraft'        => ($entries[$x]['status'] == 'live') ? 'false' : 'true',
 155                             'allow_comments' => ($entries[$x]['allowcomments'] == 'allow' ) ? 'true' : 'false',
 156                             'timestamp'      => $entries[$x]['posttime'],
 157                             'body'           => $this->strtr($entries[$x]['body']),
 158                             'extended'       => '',
 159                             );
 160  
 161              $entry['authorid'] = '';
 162              $entry['author']   = '';
 163              foreach ($users as $user) {
 164                  if ($user['ID'] == $entries[$x]['author']) {
 165                      $entry['authorid'] = $user['authorid'];
 166                      $entry['author']   = $user['user_login'];
 167                      break;
 168                  }
 169              }
 170  
 171              if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
 172                  return $entries[$x]['entryid'];
 173              }
 174  
 175              $sections = explode(':', $entries[$x]['sections']);
 176              foreach($sections AS $section) {
 177                  if (empty($section)) {
 178                      continue;
 179                  }
 180  
 181                  foreach($this->categories AS $category) {
 182                      if ($category['sectionid'] == $section) {
 183                          $categoryid = $category['categoryid'];
 184                      }
 185                  }
 186  
 187                  if ($categoryid > 0) {
 188                      $data = array('entryid'    => $entries[$x]['entryid'],
 189                                    'categoryid' => $categoryid);
 190                      serendipity_db_insert('entrycat', $this->strtrRecursive($data));
 191                  }
 192              }
 193          }
 194  
 195          /* Comments */
 196          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'comment';", $bblogdb);
 197          if (!$res) {
 198              return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($bblogdb));
 199          }
 200  
 201          while ($a = mysql_fetch_assoc($res)) {
 202              foreach ($entries as $entry) {
 203                  if ($entry['postid'] == $a['postid'] ) {
 204                      $comment = array('entry_id ' => $entry['entryid'],
 205                                       'parent_id' => 0,
 206                                       'timestamp' => $a['posttime'],
 207                                       'author'    => $a['postername'],
 208                                       'email'     => $a['posteremail'],
 209                                       'url'       => $a['posterwebsite'],
 210                                       'ip'        => $a['ip'],
 211                                       'status'    => 'approved',
 212                                       'body'      => $a['commenttext'],
 213                                       'subscribed'=> 'false',
 214                                       'type'      => 'NORMAL');
 215  
 216                      serendipity_db_insert('comments', $this->strtrRecursive($comment));
 217                      $cid = serendipity_db_insert_id('comments', 'id');
 218                      serendipity_approveComment($cid, $entry['entryid'], true);
 219                  }
 220              }
 221          }
 222  
 223          /* Trackbacks */
 224          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments WHERE type = 'trackback';", $bblogdb);
 225          if (!$res) {
 226              return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($bblogdb));
 227          }
 228  
 229          while ($a = mysql_fetch_assoc($res)) {
 230              foreach ($entries as $entry) {
 231                  if ($entry['postid'] == $a['postid'] ) {
 232                      $trackback = array('entry_id ' => $entry['entryid'],
 233                                       'parent_id' => 0,
 234                                       'timestamp' => $a['posttime'],
 235                                       'title'     => $a['title'],
 236                                       'author'    => $a['postername'],
 237                                       'email'     => $a['posteremail'],
 238                                       'url'       => $a['posterwebsite'],
 239                                       'ip'        => $a['ip'],
 240                                       'status'    => 'approved',
 241                                       'body'      => $a['commenttext'],
 242                                       'subscribed'=> 'false',
 243                                       'type'      => 'TRACKBACK');
 244  
 245                      serendipity_db_insert('comments', $this->strtrRecursive($trackback));
 246                      $cid = serendipity_db_insert_id('comments', 'id');
 247                      serendipity_approveComment($cid, $entry['entryid'], true);
 248                  }
 249              }
 250          }
 251  
 252  
 253          $serendipity['noautodiscovery'] = $noautodiscovery;
 254  
 255          // That was fun.
 256          return true;
 257      }
 258  }
 259  
 260  return 'Serendipity_Import_bblog';
 261  
 262  /* vim: set sts=4 ts=4 expandtab : */
 263  ?>


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