[ Index ] |
|
Code source de Serendipity 1.2 |
1 <?php # $Id: textpattern.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 * textpattern Importer, by Garvin Hicking * 7 * ****************************************************************/ 8 9 class Serendipity_Import_textpattern extends Serendipity_Import { 10 var $info = array('software' => 'Textpattern 1.0rc1'); 11 var $data = array(); 12 var $inputFields = array(); 13 var $categories = array(); 14 15 function getImportNotes() { 16 return 'Textpattern uses MySQLs native PASSWORD() function to save passwords. Thus, those passwords are incompatible with the MD5 hashing of Serendipity. The passwords for all users have been set to "txp". <strong>You need to modify the passwords manually for each user</strong>, we are sorry for that inconvenience.<br />'; 17 } 18 19 function Serendipity_Import_textpattern($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' => ''), 41 42 array('text' => CHARSET, 43 'type' => 'list', 44 'name' => 'charset', 45 'value' => 'UTF-8', 46 'default' => $this->getCharsets(true)), 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 $txpdb = @mysql_connect($this->data['host'], $this->data['user'], $this->data['pass']); 89 if (!$txpdb) { 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($txpdb)); 95 } 96 97 /* Users */ 98 $res = @$this->nativeQuery("SELECT user_id AS ID, 99 name AS user_login, 100 `pass` AS user_pass, 101 email AS user_email, 102 privs AS user_level 103 FROM {$this->data['prefix']}txp_users", $txpdb); 104 if (!$res) { 105 return sprintf(COULDNT_SELECT_USER_INFO, mysql_error($txpdb)); 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' => ($users[$x]['user_level'] <= 4) ? 1 : 0, 112 'realname' => $users[$x]['user_login'], 113 'username' => $users[$x]['user_login'], 114 'email' => $users[$x]['user_email'], 115 'password' => md5('txp')); // blame TXP for using PASSWORD(). 116 117 if ( $users[$x]['user_level'] == 1 ) { 118 $data['userlevel'] = USERLEVEL_EDITOR; 119 } elseif ($users[$x]['user_level'] == 2) { 120 $data['userlevel'] = USERLEVEL_CHIEF; 121 } else { 122 $data['userlevel'] = USERLEVEL_ADMIN; 123 } 124 125 if ($serendipity['serendipityUserlevel'] < $data['userlevel']) { 126 $data['userlevel'] = $serendipity['serendipityUserlevel']; 127 } 128 129 serendipity_db_insert('authors', $this->strtrRecursive($data)); 130 $users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid'); 131 } 132 133 /* Categories */ 134 if (!$this->importCategories('root', 0, $txpdb)) { 135 return sprintf(COULDNT_SELECT_CATEGORY_INFO, mysql_error($txpdb)); 136 } 137 serendipity_rebuildCategoryTree(); 138 139 /* Entries */ 140 // Notice: Textpattern doesn't honor the prefix for this table. Wicked system. 141 $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}textpattern ORDER BY Posted;", $txpdb); 142 if (!$res) { 143 return sprintf(COULDNT_SELECT_ENTRY_INFO, mysql_error($txpdb)); 144 } 145 146 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++ ) { 147 $entries[$x] = mysql_fetch_assoc($res); 148 149 $entry = array('title' => $this->decode($entries[$x]['Title']), 150 'isdraft' => ($entries[$x]['Status'] == '4') ? 'false' : 'true', 151 'allow_comments' => ($entries[$x]['Annotate'] == '1' ) ? 'true' : 'false', 152 'timestamp' => strtotime($entries[$x]['Posted']), 153 'extended' => $this->strtr($entries[$x]['Body_html']), 154 'body' => $this->strtr($entries[$x]['Excerpt'])); 155 156 $entry['authorid'] = ''; 157 $entry['author'] = ''; 158 foreach ($users as $user) { 159 if ($user['user_login'] == $entries[$x]['AuthorID']) { 160 $entry['authorid'] = $user['authorid']; 161 $entry['author'] = $user['user_login']; 162 break; 163 } 164 } 165 166 if (!is_int($entries[$x]['entryid'] = serendipity_updertEntry($entry))) { 167 return $entries[$x]['entryid']; 168 } 169 170 /* Entry/category */ 171 foreach ($this->categories as $category) { 172 if ($category['name'] == $entries[$x]['Category1'] || $category['name'] == $entries[$x]['Category2']) { 173 $data = array('entryid' => $entries[$x]['entryid'], 174 'categoryid' => $category['categoryid']); 175 serendipity_db_insert('entrycat', $this->strtrRecursive($data)); 176 break; 177 } 178 } 179 } 180 181 /* Comments */ 182 $res = @$this->nativeQuery("SELECT * FROM {$this->data['prefix']}txp_discuss;", $txpdb); 183 if (!$res) { 184 return sprintf(COULDNT_SELECT_COMMENT_INFO, mysql_error($txpdb)); 185 } 186 187 while ($a = mysql_fetch_assoc($res)) { 188 foreach ($entries as $entry) { 189 if ($entry['ID'] == $a['parentid'] ) { 190 $author = $a['name']; 191 $mail = $a['email']; 192 $url = $a['web']; 193 194 $comment = array('entry_id ' => $entry['entryid'], 195 'parent_id' => 0, 196 'timestamp' => strtotime($a['posted']), 197 'author' => $author, 198 'email' => $mail, 199 'url' => $url, 200 'ip' => $a['ip'], 201 'status' => ($a['visible'] == '1' ? 'approved' : 'pending'), 202 'body' => $a['message'], 203 'subscribed'=> 'false', 204 'type' => 'NORMAL'); 205 206 serendipity_db_insert('comments', $this->strtrRecursive($comment)); 207 if ($a['visible'] == '1') { 208 $cid = serendipity_db_insert_id('comments', 'id'); 209 serendipity_approveComment($cid, $entry['entryid'], true); 210 } 211 } 212 } 213 } 214 215 $serendipity['noautodiscovery'] = $noautodiscovery; 216 217 // That was fun. 218 return true; 219 } 220 221 function importCategories($parentname = 'root', $parentid = 0, $txpdb) { 222 $res = $this->nativeQuery("SELECT * FROM {$this->data['prefix']}txp_category 223 WHERE parent = '" . mysql_escape_string($parentname) . "' AND type = 'article'", $txpdb); 224 if (!$res) { 225 echo mysql_error(); 226 return false; 227 } 228 229 // Get all the info we need 230 for ($x=0, $max_x = mysql_num_rows($res) ; $x < $max_x ; $x++) { 231 $row = mysql_fetch_assoc($res); 232 $cat = array('category_name' => $row['name'], 233 'category_description' => $row['name'], 234 'parentid' => $parentid, 235 'category_left' => 0, 236 'category_right' => 0); 237 238 serendipity_db_insert('category', $this->strtrRecursive($cat)); 239 $row['categoryid'] = serendipity_db_insert_id('category', 'categoryid'); 240 $this->categories[] = $row; 241 $this->importCategories($row['name'], $row['categoryid'], $txpdb); 242 } 243 244 return true; 245 } 246 } 247 248 return 'Serendipity_Import_textpattern'; 249 250 /* vim: set sts=4 ts=4 expandtab : */ 251 ?>
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 |
![]() |