[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: phpbb.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 * phpbb Importer, by Garvin Hicking * 7 * ****************************************************************/ 8 9 class Serendipity_Import_phpbb extends Serendipity_Import { 10 var $info = array('software' => 'phpBB'); 11 var $data = array(); 12 var $inputFields = array(); 13 var $categories = array(); 14 15 function Serendipity_Import_phpbb($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' => 'phpbb_'), 37 38 array('text' => CHARSET, 39 'type' => 'list', 40 'name' => 'charset', 41 'value' => 'native', 42 'default' => $this->getCharsets(false)), 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 $entries = array(); 79 80 if (!extension_loaded('mysql')) { 81 return MYSQL_REQUIRED; 82 } 83 84 $gdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); 85 if (!$gdb) { 86 return sprintf(COULDNT_CONNECT, $this->data['host']); 87 } 88 89 if (!@mysql_select_db($this->data['name'])) { 90 return sprintf(COULDNT_SELECT_DB, mysql_error($gdb)); 91 } 92 93 /* Users */ 94 $res = @$this->nativeQuery("SELECT user_id AS ID, 95 username AS user_login, 96 user_password AS user_pass, 97 user_email AS user_email, 98 user_website AS user_url, 99 user_level 100 FROM {$this->data['prefix']}users 101 WHERE user_active = 1", $gdb); 102 if (!$res) { 103 return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($gdb)); 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' => 1, 110 'realname' => $users[$x]['user_login'], 111 'username' => $users[$x]['user_login'], 112 'email' => $users[$x]['user_email'], 113 'userlevel' => ($users[$x]['user_level'] == 0 ? USERLEVEL_EDITOR : USERLEVEL_ADMIN), 114 'password' => $users[$x]['user_pass']); // MD5 compatible 115 116 if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { 117 $data['userlevel'] = $serendipity['serendipityUserlevel']; 118 } 119 120 serendipity_db_insert('authors', $this->strtrRecursive($data)); 121 echo mysql_error(); 122 $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); 123 } 124 125 /* Categories */ 126 $res = @$this->nativeQuery("SELECT cat_id AS cat_ID, 127 cat_title AS cat_name 128 FROM {$this->data['prefix']}categories", $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 $parent_categories[] = mysql_fetch_assoc($res); 136 } 137 138 for ($x=0, $max_x = sizeof($parent_categories) ; $x < $max_x ; $x++ ) { 139 $cat = array('category_name' => $parent_categories[$x]['cat_name'], 140 'category_description' => '', 141 'parentid' => 0, // <--- 142 'category_left' => 0, 143 'category_right' => 0); 144 145 serendipity_db_insert('category', $this->strtrRecursive($cat)); 146 $parent_categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); 147 } 148 149 /* Categories */ 150 $res = @$this->nativeQuery("SELECT forum_id AS cat_ID, 151 cat_id AS parent_cat_id, 152 forum_name AS cat_name, 153 forum_desc AS category_description 154 FROM {$this->data['prefix']}forums ORDER BY forum_order;", $gdb); 155 if (!$res) { 156 return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($gdb)); 157 } 158 159 // Get all the info we need 160 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) { 161 $categories[] = mysql_fetch_assoc($res); 162 } 163 164 // Insert all categories as top level (we need to know everyone's ID before we can represent the hierarchy). 165 for ($x=0, $max_x = sizeof($categories) ; $x < $max_x ; $x++ ) { 166 $pcatid = 0; 167 foreach($parent_categories AS $pcat) { 168 if ($pcat['cat_ID'] == $categories[$x]['parent_cat_id']) { 169 $pcatid = $pcat['cat_ID']; 170 break; 171 } 172 } 173 174 $cat = array('category_name' => $categories[$x]['cat_name'], 175 'category_description' => $categories[$x]['category_description'], 176 'parentid' => $pcatid, // <--- 177 'category_left' => 0, 178 'category_right' => 0); 179 180 serendipity_db_insert('category', $this->strtrRecursive($cat)); 181 $categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); 182 } 183 184 serendipity_rebuildCategoryTree(); 185 186 /* Entries */ 187 $res = @$this->nativeQuery("SELECT t.topic_title, 188 t.topic_poster, 189 t.forum_id, 190 p.post_time, 191 pt.post_subject, 192 pt.post_text, 193 count(p.topic_id) AS ccount, 194 p.topic_id, 195 MIN(p.post_id) AS post_id 196 FROM {$this->data['prefix']}topics AS t 197 LEFT OUTER JOIN {$this->data['prefix']}posts AS p 198 ON t.topic_id = p.topic_id 199 LEFT OUTER JOIN {$this->data['prefix']}posts_text AS pt 200 ON pt.post_id = p.post_id 201 GROUP BY p.topic_id 202 ", $gdb); 203 if (!$res) { 204 return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($gdb)); 205 } 206 207 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) { 208 $entries[$x] = mysql_fetch_assoc($res); 209 210 $entry = array('title' => $this->decode($entries[$x]['post_subject']), 211 'isdraft' => 'false', 212 'allow_comments' => 'true', 213 'timestamp' => $entries[$x]['post_time'], 214 'body' => $this->strtr($entries[$x]['post_text']), 215 'extended' => '' 216 ); 217 218 $entry['authorid'] = ''; 219 $entry['author'] = ''; 220 foreach ($users as $user) { 221 if ($user['ID'] == $entries[$x]['topic_poster']) { 222 $entry['authorid'] = $user['authorid']; 223 $entry['author'] = $user['user_login']; 224 break; 225 } 226 } 227 228 if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { 229 return $entries[$x]['entryid']; 230 } 231 232 /* Entry/category */ 233 foreach ($categories as $category) { 234 if ($category['cat_ID'] == $entries[$x]['forum_id'] ) { 235 $data = array('entryid' => $entries[$x]['entryid'], 236 'categoryid' => $category['categoryid']); 237 serendipity_db_insert('entrycat', $this->strtrRecursive($data)); 238 break; 239 } 240 } 241 242 /* Comments */ 243 $topic_id = $entries[$x]['topic_id']; 244 $c_res = @$this->nativeQuery("SELECT t.topic_title, 245 t.topic_poster, 246 p.poster_id, 247 t.forum_id, 248 p.post_time, 249 pt.post_subject, 250 pt.post_text, 251 pt.post_id 252 FROM {$this->data['prefix']}topics AS t 253 LEFT OUTER JOIN {$this->data['prefix']}posts AS p 254 ON t.topic_id = p.topic_id 255 LEFT OUTER JOIN {$this->data['prefix']}posts_text AS pt 256 ON pt.post_id = p.post_id 257 WHERE p.topic_id = {$topic_id} 258 ", $gdb); 259 if (!$c_res) { 260 return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($gdb)); 261 } 262 263 while ($a = mysql_fetch_assoc($c_res)) { 264 if ($a['post_id'] == $entries[$x]['post_id']) { 265 continue; 266 } 267 $author = ''; 268 $mail = ''; 269 $url = ''; 270 271 foreach($users AS $user) { 272 if ($user['ID'] == $a['poster_id']) { 273 $author = $user['user_login']; 274 $mail = $user['user_email']; 275 $url = $user['user_url']; 276 break; 277 } 278 } 279 280 $comment = array('entry_id ' => $entries[$x]['entryid'], 281 'parent_id' => 0, 282 'timestamp' => $a['post_time'], 283 'author' => $author, 284 'email' => $mail, 285 'url' => $url, 286 'ip' => '', 287 'status' => 'approved', 288 'body' => $a['post_text'], 289 'subscribed'=> 'false', 290 'type' => 'NORMAL'); 291 292 serendipity_db_insert('comments', $this->strtrRecursive($comment)); 293 $cid = serendipity_db_insert_id('comments', 'id'); 294 serendipity_approveComment($cid, $entries[$x]['entryid'], true); 295 } 296 } 297 298 $serendipity['noautodiscovery'] = $noautodiscovery; 299 300 // That was fun. 301 return true; 302 } 303 } 304 305 return 'Serendipity_Import_phpbb'; 306 307 /* vim: set sts=4 ts=4 expandtab : */ 308 ?>
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 |
![]() |