[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

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


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