[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

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


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