[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: b2evolution.inc.php 1093 2006-04-13 10:49:52Z 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 * b2evolution Importer, by Garvin Hicking * 7 * ****************************************************************/ 8 9 class Serendipity_Import_b2evolution extends Serendipity_Import { 10 var $info = array('software' => 'b2Evolution 0.9.0.11 Paris'); 11 var $data = array(); 12 var $inputFields = array(); 13 var $categories = array(); 14 15 function getImportNotes() { 16 return ''; 17 } 18 19 function Serendipity_Import_b2evolution($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' => 'UTF-8', 41 'default' => $this->getCharsets(true)), 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 $b2db = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); 83 if (!$b2db) { 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($b2db)); 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 user_level AS user_level, 97 user_url AS user_url 98 FROM evo_users", $b2db); 99 if (!$res) { 100 return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($b2db)); 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'] <= 9) { 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 if (!$this->importCategories(null, 0, $b2db)) { 130 return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db)); 131 } 132 serendipity_rebuildCategoryTree(); 133 134 /* Entries */ 135 $res = @$this->nativeQuery("SELECT * FROM evo_posts ORDER BY ID;", $b2db); 136 if (!$res) { 137 return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($b2db)); 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]['post_title']), 144 'isdraft' => ($entries[$x]['post_status'] == 'published') ? 'false' : 'true', 145 'allow_comments' => ($entries[$x]['post_comments'] == 'open' ) ? 'true' : 'false', 146 'timestamp' => strtotime((isset($entries[$x]['post_issue_date']) ? $entries[$x]['post_issue_date'] : $entries[$x]['post_date'])), 147 'body' => $this->strtr($entries[$x]['post_content'])); 148 149 $entry['authorid'] = ''; 150 $entry['author'] = ''; 151 foreach ($users as $user) { 152 if ($user['ID'] == $entries[$x]['post_author']) { 153 $entry['authorid'] = $user['authorid']; 154 $entry['author'] = $user['user_login']; 155 break; 156 } 157 } 158 159 if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { 160 return $entries[$x]['entryid']; 161 } 162 163 /* Entry/category */ 164 foreach ($this->categories as $category) { 165 if ($category['cat_ID'] == $entries[$x]['post_category'] ) { 166 $data = array('entryid' => $entries[$x]['entryid'], 167 'categoryid' => $category['categoryid']); 168 serendipity_db_insert('entrycat', $this->strtrRecursive($data)); 169 break; 170 } 171 } 172 } 173 174 /* Even more category stuff */ 175 $res = @$this->nativeQuery("SELECT * FROM evo_postcats;", $b2db); 176 if (!$res) { 177 return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($b2db)); 178 } 179 180 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) { 181 $entrycat = mysql_fetch_assoc($res); 182 183 $entryid = 0; 184 $categoryid = 0; 185 foreach($entries AS $entry) { 186 if ($entry['ID'] == $entrycat['postcat_post_ID']) { 187 $entryid = $entry['entryid']; 188 break; 189 } 190 } 191 192 foreach($this->categories AS $category) { 193 if ($category['cat_ID'] == $entrycat['postcat_cat_ID']) { 194 $categoryid = $category['categoryid']; 195 } 196 } 197 198 if ($entryid > 0 && $categoryid > 0) { 199 $data = array('entryid' => $entryid, 200 'categoryid' => $categoryid); 201 serendipity_db_insert('entrycat', $this->strtrRecursive($data)); 202 } 203 } 204 205 /* Comments */ 206 $res = @$this->nativeQuery("SELECT * FROM evo_comments;", $b2db); 207 if (!$res) { 208 return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($b2db)); 209 } 210 211 while ($a = mysql_fetch_assoc($res)) { 212 foreach ($entries as $entry) { 213 if ($entry['ID'] == $a['comment_post_ID'] ) { 214 $author = ''; 215 $mail = ''; 216 $url = ''; 217 if (!empty($a['comment_author_ID'])) { 218 foreach($users AS $user) { 219 if ($user['ID'] == $a['comment_author_ID']) { 220 $author = $user['user_login']; 221 $mail = $user['user_email']; 222 $url = $user['user_url']; 223 break; 224 } 225 } 226 } 227 228 if (empty($author) && empty($mail)) { 229 $author = $a['comment_author']; 230 $mail = $a['comment_author_email']; 231 $url = $a['comment_author_url']; 232 } 233 234 $comment = array('entry_id ' => $entry['entryid'], 235 'parent_id' => 0, 236 'timestamp' => strtotime($a['comment_date']), 237 'author' => $author, 238 'email' => $mail, 239 'url' => $url, 240 'ip' => $a['comment_author_IP'], 241 'status' => ($a['comment_status'] == 'published' ? 'approved' : 'pending'), 242 'body' => $a['comment_content'], 243 'subscribed'=> 'false', 244 'type' => 'NORMAL'); 245 246 serendipity_db_insert('comments', $this->strtrRecursive($comment)); 247 if ($a['comment_status'] == 'published') { 248 $cid = serendipity_db_insert_id('comments', 'id'); 249 serendipity_approveComment($cid, $entry['entryid'], true); 250 } 251 } 252 } 253 } 254 255 $serendipity['noautodiscovery'] = $noautodiscovery; 256 257 // That was fun. 258 return true; 259 } 260 261 function importCategories($parentid = 0, $new_parentid = 0, $b2db) { 262 if (is_null($parentid)) { 263 $where = 'WHERE ISNULL(cat_parent_ID)'; 264 } else { 265 $where = "WHERE cat_parent_ID = '" . mysql_escape_string($parentid) . "'"; 266 } 267 268 $res = $this->nativeQuery("SELECT * FROM evo_categories 269 " . $where, $b2db); 270 if (!$res) { 271 echo mysql_error(); 272 return false; 273 } 274 275 // Get all the info we need 276 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) { 277 $row = mysql_fetch_assoc($res); 278 $cat = array('category_name' => $row['cat_name'], 279 'category_description' => $row['cat_description'], 280 'parentid' => (int)$new_parentid, 281 'category_left' => 0, 282 'category_right' => 0); 283 284 serendipity_db_insert('category', $this->strtrRecursive($cat)); 285 $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); 286 $this->categories[] = $row; 287 $this->importCategories($row['cat_ID'], $row['categoryid'], $b2db); 288 } 289 290 return true; 291 } 292 } 293 294 return 'Serendipity_Import_b2evolution'; 295 296 /* vim: set sts=4 ts=4 expandtab : */
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Nov 24 09:00:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |