[ Index ]
 

Code source de Serendipity 1.2

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php # $Id: pmachine.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   *  pMachine  Importer,  by Garvin Hicking *
   7   * ****************************************************************/
   8  
   9  class Serendipity_Import_pMachine extends Serendipity_Import {
  10      var $info        = array('software' => 'pMachine Pro 2.4');
  11      var $data        = array();
  12      var $inputFields = array();
  13  
  14  
  15      function Serendipity_Import_pMachine($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' => 'pm_'),
  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          $pmdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']);
  86          if (!$pmdb) {
  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($pmdb));
  92          }
  93  
  94          /* Users */
  95          $res = @$this->nativeQuery("SELECT id         AS ID,
  96                                      username   AS user_login,
  97                                      `password` AS user_pass,
  98                                      email      AS user_email,
  99                                      status     AS user_level,
 100                                      url        AS url
 101                                 FROM {$this->data['prefix']}members", $pmdb);
 102          if (!$res) {
 103              return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($pmdb));
 104          }
 105  
 106          for ($x=0, $max_x = mysql_num_rows($res); $x < $max_x ; $x++ ) {
 107              $users[$x] = mysql_fetch_assoc($res);
 108  
 109              $data = array('right_publish' => ($users[$x]['user_level'] >= 3) ? 1 : 0,
 110                            'realname'      => $users[$x]['user_login'],
 111                            'username'      => $users[$x]['user_login'],
 112                            'email'         => $users[$x]['user_email'],
 113                            'password'      => $users[$x]['user_pass']); // pMachine uses md5, too.
 114  
 115              if ( $users[$x]['user_level'] < 12 ) {
 116                  $data['userlevel'] = USERLEVEL_EDITOR;
 117              } else {
 118                  $data['userlevel'] = USERLEVEL_ADMIN;
 119              }
 120  
 121              if ($serendipity['serendipityUserlevel'] < $data['userlevel']) {
 122                  $data['userlevel'] = $serendipity['serendipityUserlevel'];
 123              }
 124  
 125              serendipity_db_insert('authors', $this->strtrRecursive($data));
 126              $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
 127          }
 128  
 129          /* Categories */
 130          $res = @$this->nativeQuery("SELECT id       AS cat_ID,
 131                                      category AS cat_name,
 132                                      category AS category_description
 133                                 FROM {$this->data['prefix']}categories ORDER BY id", $pmdb);
 134          if (!$res) {
 135              return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($pmdb));
 136          }
 137  
 138          // Get all the info we need
 139          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) {
 140              $categories[] = mysql_fetch_assoc($res);
 141          }
 142  
 143          // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy).
 144          for ($x=0, $max_x = sizeof($categories) ; $x < $max_x ; $x++ ) {
 145              $cat = array('category_name'        => $categories[$x]['cat_name'],
 146                           'category_description' => $categories[$x]['category_description'],
 147                           'parentid'             => 0, // <---
 148                           'category_left'        => 0,
 149                           'category_right'       => 0);
 150  
 151              serendipity_db_insert('category', $this->strtrRecursive($cat));
 152              $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
 153          }
 154  
 155          serendipity_rebuildCategoryTree();
 156  
 157          /* Entries */
 158          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}weblog ORDER BY t_stamp;", $pmdb);
 159          if (!$res) {
 160              return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($pmdb));
 161          }
 162  
 163          for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) {
 164              $entries[$x] = mysql_fetch_assoc($res);
 165  
 166              $entry = array('title'          => $this->decode($entries[$x]['title']),
 167                             'isdraft'        => ($entries[$x]['status'] == 'open') ? 'false' : 'true',
 168                             'allow_comments' => ($entries[$x]['showcomments'] == '1' ) ? 'true' : 'false',
 169                             'timestamp'      => $entries[$x]['t_stamp'],
 170                             'extended'       => $this->strtr($entries[$x]['more']),
 171                             'body'           => $this->strtr($entries[$x]['body']));
 172  
 173              $entry['authorid'] = '';
 174              $entry['author']   = '';
 175              foreach ($users as $user) {
 176                  if ($user['ID'] == $entries[$x]['member_id']) {
 177                      $entry['authorid'] = $user['authorid'];
 178                      $entry['author']   = $user['username'];
 179                      break;
 180                  }
 181              }
 182  
 183              if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) {
 184                  return $entries[$x]['entryid'];
 185              }
 186  
 187              /* Entry/category */
 188              foreach ($categories as $category) {
 189                  if ($category['cat_ID'] == $entries[$x]['category'] ) {
 190                      $data = array('entryid'    => $entries[$x]['entryid'],
 191                                    'categoryid' => $category['categoryid']);
 192                      serendipity_db_insert('entrycat', $this->strtrRecursive($data));
 193                      break;
 194                  }
 195              }
 196          }
 197  
 198          /* Comments */
 199          $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}comments;", $pmdb);
 200          if (!$res) {
 201              return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($pmdb));
 202          }
 203  
 204          while ($a = mysql_fetch_assoc($res)) {
 205              foreach ($entries as $entry) {
 206                  if ($entry['post_id'] == $a['post_id'] ) {
 207                      $author   = '';
 208                      $mail     = '';
 209                      $url      = '';
 210                      if (!empty($a['member_id'])) {
 211                          foreach($users AS $user) {
 212                              if ($user['ID'] == $a['member_id']) {
 213                                  $author = $user['user_login'];
 214                                  $mail     = $user['user_email'];
 215                                  $url      = $user['url'];
 216                                  break;
 217                              }
 218                          }
 219                      }
 220  
 221                      $comment = array('entry_id ' => $entry['entryid'],
 222                                       'parent_id' => 0,
 223                                       'timestamp' => $a['t_stamp'],
 224                                       'author'    => $author,
 225                                       'email'     => $mail,
 226                                       'url'       => $url,
 227                                       'ip'        => $a['comment_ip'],
 228                                       'status'    => ($a['status'] == 'open' ? 'approved' : 'pending'),
 229                                       'body'      => $a['body'],
 230                                       'subscribed'=> 'false',
 231                                       'type'      => 'NORMAL');
 232  
 233                      serendipity_db_insert('comments', $this->strtrRecursive($comment));
 234                      if ($a['status'] == 'open') {
 235                          $cid = serendipity_db_insert_id('comments', 'id');
 236                          serendipity_approveComment($cid, $entry['entryid'], true);
 237                      }
 238                  }
 239              }
 240          }
 241  
 242          $serendipity['noautodiscovery'] = $noautodiscovery;
 243  
 244          // That was fun.
 245          return true;
 246      }
 247  }
 248  
 249  return 'Serendipity_Import_pMachine';
 250  
 251  /* vim: set sts=4 ts=4 expandtab : */
 252  ?>


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