Update of /cvsroot/php-blog/serendipity/include/admin/importers
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11598
Modified Files:
wordpress.inc.php
Log Message:
Encode UTF-8 characters, set noautodiscovery back to whatever it was after import is finished. Please test the former.
Index: wordpress.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/admin/importers/wordpress.inc.php,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- wordpress.inc.php 19 Nov 2004 11:05:33 -0000 1.2
+++ wordpress.inc.php 30 Nov 2004 00:26:15 -0000 1.3
@@ -47,12 +47,31 @@
return $this->inputFields;
}
+ function strtrRecursive($data, $trans_table) {
+ foreach ( $data as $key => $val ) {
+ if ( is_array([$val]) ) {
+ $data[$key] = $this->strtrRecursive($val);
+ }
+ else {
+ $data[$key] = strtr($val, $trans_table);
+ }
+ }
+
+ return $data;
+ }
+
function import() {
global $serendipity;
- if ($this->data['autodiscovery'] == 'false') {
- $serendipity['noautodiscovery'] = 1;
- }
+ // Save this so we can return it to its original value at the end of this method.
+ $noautodiscovery = isset($serendipity['noautodiscovery']) ? $serendipity['noautodiscovery'] : false;
+ $serendipity['noautodiscovery'] = true;
+
+ // We need to convert interesting characters to HTML entities, except for those with special relevance to HTML.
+ $trans_table = get_html_translation_table(HTML_ENTITIES);
+ foreach ( get_html_translation_table(HTML_SPECIALCHARS) as $char => $encoded )
+ if ( isset($trans_table[$char]) )
+ unset($trans_table[$char]);
$this->data['prefix'] = serendipity_db_escape_string($this->data['prefix']);
$users = array();
@@ -93,7 +112,7 @@
$data['userlevel'] = USERLEVEL_ADMIN;
}
- serendipity_db_insert('authors', $data);
+ serendipity_db_insert('authors', $this->strtrRecursive($data, $trans_table));
$users[$x]['authorid'] = serendipity_db_insert_id('authors', 'authorid');
}
@@ -115,7 +134,7 @@
'category_left' => 0,
'category_right' => 0);
- serendipity_db_insert('category', $cat);
+ serendipity_db_insert('category', $this->strtrRecursive($cat, $trans_table));
$categories[$x]['categoryid'] = serendipity_db_insert_id('category', 'categoryid');
}
@@ -148,11 +167,11 @@
for ( $x=0 ; $x<mysql_num_rows($res) ; $x++ ) {
$entries[$x] = mysql_fetch_assoc($res);
- $entry = array('title' => $entries[$x]['post_title'],
+ $entry = array('title' => $entries[$x]['post_title'], $trans_table, // htmlentities() is called later, so we can leave this.
'isdraft' => ($entries[$x]['post_status'] == 'publish') ? 'false' : 'true',
'allow_comments' => ($entries[$x]['comment_status '] == 'open ') ? 'true' : 'false',
'timestamp' => strtotime($entries[$x]['post_date']),
- 'body' => $entries[$x]['post_content']);
+ 'body' => strtr($entries[$x]['post_content'], $trans_table));
foreach ( $users as $user ) {
if ( $user['ID'] == $entries[$x]['post_author'] ) {
@@ -179,7 +198,7 @@
if ( $a['post_id'] == $entry['ID'] ) {
$data = array('entryid' => $entry['entryid'],
'categoryid' => $category['categoryid']);
- serendipity_db_insert('entrycat', $data);
+ serendipity_db_insert('entrycat', $this->strtrRecursive($data, $trans_table));
break;
}
}
@@ -208,12 +227,14 @@
'body' => $a['comment_content'],
'type' => 'NORMAL');
- serendipity_db_insert('comments', $comment);
+ serendipity_db_insert('comments', $this->strtrRecursive($comment, $trans_table));
serendipity_approveComment($cid, $id, true);
}
}
}
+ $serendipity['noautodiscovery'] = $noautodiscovery;
+
// That was fun.
return true;
}
|