Use hard-coded functions instead of create_function() in importers. Props mdawaffe. fixes #10836

git-svn-id: http://svn.automattic.com/wordpress/trunk@11964 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-09-23 22:03:39 +00:00
parent a86aa7b399
commit e1c0fad754
5 changed files with 43 additions and 14 deletions

View File

@ -529,6 +529,10 @@ class Blogger_Import {
return preg_replace( '|\s+|', ' ', $string );
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $match[1] );
}
function import_post( $entry ) {
global $importing_blog;
@ -551,7 +555,7 @@ class Blogger_Import {
$post_status = isset( $entry->draft ) ? 'draft' : 'publish';
// Clean up content
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);
@ -604,7 +608,7 @@ class Blogger_Import {
$comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) );
// Clean up content
$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
$comment_content = str_replace('<br>', '<br />', $comment_content);
$comment_content = str_replace('<hr>', '<hr />', $comment_content);
@ -905,10 +909,19 @@ class AtomParser {
var $entry;
function AtomParser() {
$this->entry = new AtomEntry();
$this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');
$this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
}
function _map_attrs_func( $k, $v ) {
return "$k=\"$v\"";
}
function _map_xmlns_func( $p, $n ) {
$xd = "xmlns";
if ( strlen( $n[0] ) > 0 )
$xd .= ":{$n[0]}";
return "{$xd}=\"{$n[1]}\"";
}
function parse($xml) {
@ -950,12 +963,12 @@ class AtomParser {
foreach($attrs as $key => $value) {
$attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value);
}
$attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix)));
$attrs_str = join(' ', array_map( array( &$this, '_map_attrs_func' ), array_keys($attrs_prefix), array_values($attrs_prefix)));
if(strlen($attrs_str) > 0) {
$attrs_str = " " . $attrs_str;
}
$xmlns_str = join(' ', array_map($this->map_xmlns_func, array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
$xmlns_str = join(' ', array_map( array( &$this, '_map_xmlns_func' ), array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
if(strlen($xmlns_str) > 0) {
$xmlns_str = " " . $xmlns_str;
}

View File

@ -42,6 +42,10 @@ class BW_Import {
echo '</div>';
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $match[1] );
}
function import_posts() {
global $wpdb, $current_user;
@ -89,7 +93,7 @@ class BW_Import {
}
// Clean up content
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);
$post_content = $wpdb->escape($post_content);
@ -129,7 +133,7 @@ class BW_Import {
$comment_content = $this->unhtmlentities($comment_content);
// Clean up content
$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
$comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
$comment_content = str_replace('<br>', '<br />', $comment_content);
$comment_content = str_replace('<hr>', '<hr />', $comment_content);
$comment_content = $wpdb->escape($comment_content);

View File

@ -324,6 +324,10 @@ class LJ_API_Import {
echo '</ol>';
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $match[1] );
}
function import_post( $post ) {
global $wpdb;
@ -350,7 +354,7 @@ class LJ_API_Import {
// Clean up content
$post_content = $post['event'];
$post_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $post_content );
$post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
// XHTMLize some tags
$post_content = str_replace( '<br>', '<br />', $post_content );
$post_content = str_replace( '<hr>', '<hr />', $post_content );
@ -581,7 +585,7 @@ class LJ_API_Import {
$comment_content = wpautop( $comment_content );
$comment_content = str_replace( '<br>', '<br />', $comment_content );
$comment_content = str_replace( '<hr>', '<hr />', $comment_content );
$comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $comment_content );
$comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content );
$comment_content = $wpdb->escape( trim( $comment_content ) );
// Get and convert the date

View File

@ -43,6 +43,10 @@ class RSS_Import {
echo '</div>';
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $match[1] );
}
function get_posts() {
global $wpdb;
@ -103,7 +107,7 @@ class RSS_Import {
}
// Clean up content
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);

View File

@ -357,6 +357,10 @@ class WP_Import {
echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
}
function _normalize_tag( $matches ) {
return '<' . strtolower( $match[1] );
}
function process_post($post) {
global $wpdb;
@ -383,12 +387,12 @@ class WP_Import {
$post_author = $this->get_tag( $post, 'dc:creator' );
$post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
$post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_excerpt);
$post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt);
$post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
$post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);
$post_content = $this->get_tag( $post, 'content:encoded' );
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
$post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
$post_content = str_replace('<br>', '<br />', $post_content);
$post_content = str_replace('<hr>', '<hr />', $post_content);