[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: sunlog.inc.php 558 2005-10-15 16:02:02Z 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   *  sunlog  Importer,    by Garvin Hicking *
   7   * ****************************************************************/
   8  
   9  class Serendipity_Import_sunlog extends Serendipity_Import {
  10      var $info        = array('software' => 'Sunlog 0.4.4');
  11      var $data        = array();
  12      var $inputFields = array();
  13      var $categories  = array();
  14  
  15      function getImportNotes() {
  16          return 'Sunlog uses a crypted string to represent stored passwords. Thus, those passwords are incompatible with the MD5 hashing of Serendipity and can not be reconstructed. The passwords for all users have been set to "sunlog". <strong>You need to modify the passwords manually for each user</strong>, we are sorry for that inconvenience.<br />'
  17               . '<br />'
  18               . 'Sunlog 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.';
  19      }
  20  
  21      function Serendipity_Import_sunlog($data) {
  22          $this->data = $data;
  23          $this->inputFields = array(array('text' => INSTALL_DBHOST,
  24                                           'type' => 'input',
  25                                           'name' => 'host'),
  26  
  27                                     array('text' => INSTALL_DBUSER,
  28                                           'type' => 'input',
  29                                           'name' => 'user'),
  30  
  31                                     array('text' => INSTALL_DBPASS,
  32                                           'type' => 'protected',
  33                                           'name' => 'pass'),
  34  
  35                                     array('text' => INSTALL_DBNAME,
  36                                           'type' => 'input',
  37                                           'name' => 'name'),
  38  
  39                                     array('text' => INSTALL_DBPREFIX,
  40                                           'type' => 'input',
  41                                           'name' => 'prefix',
  42                                           'default' => 'sunlog_'),
  43  
  44                                     array('text'    => CHARSET,
  45                                           'type'    => 'list',
  46                                           'name'    => 'charset',
  47                                           'value'   => 'native',
  48                                           'default' => $this->getCharsets()),
  49  
  50                                     array('text'    => CONVERT_HTMLENTITIES,
  51                                           'type'    => 'bool',
  52                                           'name'    => 'use_strtr',
  53                                           'default' => 'true'),
  54  
  55                                     array('text'    => ACTIVATE_AUTODISCOVERY,
  56                                           'type'    => 'bool',
  57                                           'name'    => 'autodiscovery',
  58                                           'default' => 'false')
  59                              );
  60      }
  61  
  62      function validateData() {
  63          return sizeof($this->data);
  64      }
  65  
  66      function getInputFields() {
  67          return $this->inputFields;
  68      }
  69  
  70      function import() {
  71          global $serendipity;
  72  
  73          // Save this so we can return it to its original value at the end of this method.
  74          $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
  75  
  76          if ($this->data['autodiscovery'] == 'false') {
  77              $serendipity['noautodiscovery'] = 1;
  78          }
  79  
  80          $this->getTransTable();
  81  
  82          $this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
  83          $users = array();
  84          $entries = array();
  85  
  86          if (!extension_loaded('mysql')) {
  87              return MYSQL_REQUIRED;
  88          }
  89  
  90          $sunlogdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
  91          if (!$sunlogdb) {
  92              return sprintf(COULDNT_CONNECT, $this->data['host']);
  93          }
  94  
  95          if (!@mysql_select_db($this->data['name'])) {
  96              return sprintf(COULDNT_SELECT_DB, mysql_error($sunlogdb));
  97          }
  98  
  99          /* Users */
 100          $res = @$this->nativeQuery("SELECT id         AS ID,
 101                                      name       AS user_login,
 102                                      email      AS user_email,
 103                                      homepage   AS user_url
 104                                 FROM {$this->data['prefix']}users", $sunlogdb);
 105          if (!$res) {
 106              return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($sunlogdb));
 107          }
 108  
 109          for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
 110              $users[$x] = mysql_fetch_assoc($res);
 111  
 112              $data = array('right_publish' => 1,
 113                            'realname'      => $users[$x]['user_login'],
 114                            'username'      => $users[$x]['user_login'],
 115                            'email'         => $users[$x]['user_email'],
 116                            'userlevel'     => USERLEVEL_ADMIN,
 117                            'password'      => md5('sunlog'));
 118  
 119              if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
 120                  $data['userlevel'] = $serendipity['serendipityUserlevel'];
 121              }
 122  
 123              serendipity_db_insert('authors', $this->strtrRecursive($data));
 124              echo mysql_error();
 125              $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
 126          }
 127  
 128          /* Categories */
 129          if (!$this->importCategories(null, 0, $sunlogdb)) {
 130              return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
 131          }
 132          serendipity_rebuildCategoryTree();
 133  
 134          /* Entries */
 135          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}articles ORDER BY id;", $sunlogdb);
 136          if (!$res) {
 137              return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($sunlogdb));
 138          }
 139  
 140          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
 141              $entries[$x] = mysql_fetch_assoc($res);
 142  
 143              $entry = array('title'          => $this->decode($entries[$x]['title']),
 144                             'isdraft'        => ($entries[$x]['draft'] == '0') ? 'false' : 'true',
 145                             'allow_comments' => ($entries[$x]['c_comments'] == '1' ) ? 'true' : 'false',
 146                             'timestamp'      => strtotime($entries[$x]['timestamp']),
 147                             'body'           => $this->strtr($entries[$x]['lead_converted']),
 148                             'extended'       => $this->strtr($entries[$x]['article_converted']),
 149                             );
 150  
 151              $entry['authorid'] = '';
 152              $entry['author']   = '';
 153              foreach ($users as $user) {
 154                  if ($user['ID'] == $entries[$x]['author']) {
 155                      $entry['authorid'] = $user['authorid'];
 156                      $entry['author']   = $user['user_login'];
 157                      break;
 158                  }
 159              }
 160  
 161              if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
 162                  return $entries[$x]['entryid'];
 163              }
 164          }
 165  
 166          /* Even more category stuff */
 167          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}transfer_c;", $sunlogdb);
 168          if (!$res) {
 169              return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($sunlogdb));
 170          }
 171  
 172          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
 173              $entrycat = mysql_fetch_assoc($res);
 174  
 175              $entryid = 0;
 176              $categoryid = 0;
 177              foreach($entries AS $entry) {
 178                  if ($entry['id'] == $entrycat['article']) {
 179                      $entryid = $entry['entryid'];
 180                      break;
 181                  }
 182              }
 183  
 184              foreach($this->categories AS $category) {
 185                  if ($category['id'] == $entrycat['category']) {
 186                      $categoryid = $category['categoryid'];
 187                  }
 188              }
 189  
 190              if ($entryid > 0 && $categoryid > 0) {
 191                  $data = array('entryid'    => $entryid,
 192                                'categoryid' => $categoryid);
 193                  serendipity_db_insert('entrycat', $this->strtrRecursive($data));
 194              }
 195          }
 196  
 197          /* Comments */
 198          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}c_comments;", $sunlogdb);
 199          if (!$res) {
 200              return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($sunlogdb));
 201          }
 202  
 203          while ($a = mysql_fetch_assoc($res)) {
 204              foreach ($entries as $entry) {
 205                  if ($entry['id'] == $a['for_entry'] ) {
 206                      $author   = '';
 207                      $mail     = '';
 208                      $url      = '';
 209  
 210                      foreach($users AS $user) {
 211                          if ($user['ID'] == $a['user']) {
 212                              $author = $user['user_login'];
 213                              $mail = $user['user_email'];
 214                              $url  = $user['user_url'];
 215                              break;
 216                          }
 217                      }
 218  
 219                      $comment = array('entry_id ' => $entry['entryid'],
 220                                       'parent_id' => 0,
 221                                       'timestamp' => strtotime($a['insertdate']),
 222                                       'author'    => $author,
 223                                       'email'     => $mail,
 224                                       'url'       => $url,
 225                                       'ip'        => '',
 226                                       'status'    => 'approved',
 227                                       'body'      => $a['comment'],
 228                                       'subscribed'=> 'false',
 229                                       'type'      => 'NORMAL');
 230  
 231                      serendipity_db_insert('comments', $this->strtrRecursive($comment));
 232                      $cid = serendipity_db_insert_id('comments', 'id');
 233                      serendipity_approveComment($cid, $entry['entryid'], true);
 234                  }
 235              }
 236          }
 237  
 238          $serendipity['noautodiscovery'] = $noautodiscovery;
 239  
 240          // That was fun.
 241          return true;
 242      }
 243  
 244      function importCategories($parentid = 0, $new_parentid = 0, $sunlogdb) {
 245          $where = "WHERE parent = '" . mysql_escape_string($parentid) . "'";
 246  
 247          $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}categories
 248                                       " . $where, $sunlogdb);
 249          if (!$res) {
 250              echo mysql_error();
 251              return false;
 252          }
 253  
 254          // Get all the info we need
 255          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
 256              $row = mysql_fetch_assoc($res);
 257              $cat = array('category_name'        => $row['title'],
 258                           'category_description' => $row['optional_1'] . ' ' . $row['optional_2'] . ' ' . $row['optional_3'],
 259                           'parentid'             => (int)$new_parentid,
 260                           'category_left'        => 0,
 261                           'category_right'       => 0);
 262  
 263              serendipity_db_insert('category', $this->strtrRecursive($cat));
 264              $row['categoryid']  = serendipity_db_insert_id('category', 'categoryid');
 265              $this->categories[] = $row;
 266              $this->importCategories($row['id'], $row['categoryid'], $sunlogdb);
 267          }
 268  
 269          return true;
 270      }
 271  }
 272  
 273  return 'Serendipity_Import_sunlog';
 274  
 275  /* vim: set sts=4 ts=4 expandtab : */
 276  ?>


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