<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11964] trunk/wp-admin/import:
Use hard-coded functions instead of create_function() in importers.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11964">11964</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2009-09-23 22:03:39 +0000 (Wed, 23 Sep 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Use hard-coded functions instead of create_function() in importers. Props mdawaffe. fixes <a href="http://trac.wordpress.org/ticket/10836">#10836</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminimportbloggerphp">trunk/wp-admin/import/blogger.php</a></li>
<li><a href="#trunkwpadminimportblogwarephp">trunk/wp-admin/import/blogware.php</a></li>
<li><a href="#trunkwpadminimportlivejournalphp">trunk/wp-admin/import/livejournal.php</a></li>
<li><a href="#trunkwpadminimportrssphp">trunk/wp-admin/import/rss.php</a></li>
<li><a href="#trunkwpadminimportwordpressphp">trunk/wp-admin/import/wordpress.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminimportbloggerphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/blogger.php (11963 => 11964)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/blogger.php        2009-09-23 07:06:58 UTC (rev 11963)
+++ trunk/wp-admin/import/blogger.php        2009-09-23 22:03:39 UTC (rev 11964)
</span><span class="lines">@@ -529,6 +529,10 @@
</span><span class="cx">                 return preg_replace( '|\s+|', ' ', $string );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _normalize_tag( $matches ) {
+                return '<' . strtolower( $match[1] );
+        }
+
</ins><span class="cx">         function import_post( $entry ) {
</span><span class="cx">                 global $importing_blog;
</span><span class="cx">
</span><span class="lines">@@ -551,7 +555,7 @@
</span><span class="cx">                 $post_status = isset( $entry->draft ) ? 'draft' : 'publish';
</span><span class="cx">
</span><span class="cx">                 // Clean up content
</span><del>-                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
</del><ins>+                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
</ins><span class="cx">                 $post_content = str_replace('<br>', '<br />', $post_content);
</span><span class="cx">                 $post_content = str_replace('<hr>', '<hr />', $post_content);
</span><span class="cx">
</span><span class="lines">@@ -604,7 +608,7 @@
</span><span class="cx">                 $comment_content = addslashes( $this->no_apos( @html_entity_decode( $entry->content, ENT_COMPAT, get_option('blog_charset') ) ) );
</span><span class="cx">
</span><span class="cx">                 // Clean up content
</span><del>-                $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
</del><ins>+                $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
</ins><span class="cx">                 $comment_content = str_replace('<br>', '<br />', $comment_content);
</span><span class="cx">                 $comment_content = str_replace('<hr>', '<hr />', $comment_content);
</span><span class="cx">
</span><span class="lines">@@ -905,12 +909,21 @@
</span><span class="cx">         var $entry;
</span><span class="cx">
</span><span class="cx">         function AtomParser() {
</span><del>-
</del><span class="cx">                 $this->entry = new AtomEntry();
</span><del>-                $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]}\"";');
</del><span class="cx">         }
</span><span class="cx">
</span><ins>+        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]}\"";
+        }
+
</ins><span class="cx">         function parse($xml) {
</span><span class="cx">
</span><span class="cx">                 global $app_logging;
</span><span class="lines">@@ -950,12 +963,12 @@
</span><span class="cx">                         foreach($attrs as $key => $value) {
</span><span class="cx">                                 $attrs_prefix[$this->ns_to_prefix($key)] = $this->xml_escape($value);
</span><span class="cx">                         }
</span><del>-                        $attrs_str = join(' ', array_map($this->map_attrs_func, array_keys($attrs_prefix), array_values($attrs_prefix)));
</del><ins>+                        $attrs_str = join(' ', array_map( array( &$this, '_map_attrs_func' ), array_keys($attrs_prefix), array_values($attrs_prefix)));
</ins><span class="cx">                         if(strlen($attrs_str) > 0) {
</span><span class="cx">                                 $attrs_str = " " . $attrs_str;
</span><span class="cx">                         }
</span><span class="cx">
</span><del>-                        $xmlns_str = join(' ', array_map($this->map_xmlns_func, array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
</del><ins>+                        $xmlns_str = join(' ', array_map( array( &$this, '_map_xmlns_func' ), array_keys($this->ns_contexts[0]), array_values($this->ns_contexts[0])));
</ins><span class="cx">                         if(strlen($xmlns_str) > 0) {
</span><span class="cx">                                 $xmlns_str = " " . $xmlns_str;
</span><span class="cx">                         }
</span></span></pre></div>
<a id="trunkwpadminimportblogwarephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/blogware.php (11963 => 11964)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/blogware.php        2009-09-23 07:06:58 UTC (rev 11963)
+++ trunk/wp-admin/import/blogware.php        2009-09-23 22:03:39 UTC (rev 11964)
</span><span class="lines">@@ -42,6 +42,10 @@
</span><span class="cx">                 echo '</div>';
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _normalize_tag( $matches ) {
+                return '<' . strtolower( $match[1] );
+        }
+
</ins><span class="cx">         function import_posts() {
</span><span class="cx">                 global $wpdb, $current_user;
</span><span class="cx">
</span><span class="lines">@@ -89,7 +93,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         // Clean up content
</span><del>-                        $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
</del><ins>+                        $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
</ins><span class="cx">                         $post_content = str_replace('<br>', '<br />', $post_content);
</span><span class="cx">                         $post_content = str_replace('<hr>', '<hr />', $post_content);
</span><span class="cx">                         $post_content = $wpdb->escape($post_content);
</span><span class="lines">@@ -129,7 +133,7 @@
</span><span class="cx">                                         $comment_content = $this->unhtmlentities($comment_content);
</span><span class="cx">
</span><span class="cx">                                         // Clean up content
</span><del>-                                        $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $comment_content);
</del><ins>+                                        $comment_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content);
</ins><span class="cx">                                         $comment_content = str_replace('<br>', '<br />', $comment_content);
</span><span class="cx">                                         $comment_content = str_replace('<hr>', '<hr />', $comment_content);
</span><span class="cx">                                         $comment_content = $wpdb->escape($comment_content);
</span></span></pre></div>
<a id="trunkwpadminimportlivejournalphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/livejournal.php (11963 => 11964)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/livejournal.php        2009-09-23 07:06:58 UTC (rev 11963)
+++ trunk/wp-admin/import/livejournal.php        2009-09-23 22:03:39 UTC (rev 11964)
</span><span class="lines">@@ -324,6 +324,10 @@
</span><span class="cx">                 echo '</ol>';
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _normalize_tag( $matches ) {
+                return '<' . strtolower( $match[1] );
+        }
+
</ins><span class="cx">         function import_post( $post ) {
</span><span class="cx">                 global $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -350,7 +354,7 @@
</span><span class="cx">
</span><span class="cx">                 // Clean up content
</span><span class="cx">                 $post_content = $post['event'];
</span><del>-                $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $post_content );
</del><ins>+                $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
</ins><span class="cx">                 // XHTMLize some tags
</span><span class="cx">                 $post_content = str_replace( '<br>', '<br />', $post_content );
</span><span class="cx">                 $post_content = str_replace( '<hr>', '<hr />', $post_content );
</span><span class="lines">@@ -581,7 +585,7 @@
</span><span class="cx">                 $comment_content = wpautop( $comment_content );
</span><span class="cx">                 $comment_content = str_replace( '<br>', '<br />', $comment_content );
</span><span class="cx">                 $comment_content = str_replace( '<hr>', '<hr />', $comment_content );
</span><del>-                $comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', create_function( '$match', 'return "<" . strtolower( $match[1] );' ), $comment_content );
</del><ins>+                $comment_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $comment_content );
</ins><span class="cx">                 $comment_content = $wpdb->escape( trim( $comment_content ) );
</span><span class="cx">
</span><span class="cx">                 // Get and convert the date
</span></span></pre></div>
<a id="trunkwpadminimportrssphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/rss.php (11963 => 11964)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/rss.php        2009-09-23 07:06:58 UTC (rev 11963)
+++ trunk/wp-admin/import/rss.php        2009-09-23 22:03:39 UTC (rev 11964)
</span><span class="lines">@@ -43,6 +43,10 @@
</span><span class="cx">                 echo '</div>';
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _normalize_tag( $matches ) {
+                return '<' . strtolower( $match[1] );
+        }
+
</ins><span class="cx">         function get_posts() {
</span><span class="cx">                 global $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -103,7 +107,7 @@
</span><span class="cx">                         }
</span><span class="cx">
</span><span class="cx">                         // Clean up content
</span><del>-                        $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
</del><ins>+                        $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
</ins><span class="cx">                         $post_content = str_replace('<br>', '<br />', $post_content);
</span><span class="cx">                         $post_content = str_replace('<hr>', '<hr />', $post_content);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminimportwordpressphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/import/wordpress.php (11963 => 11964)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/import/wordpress.php        2009-09-23 07:06:58 UTC (rev 11963)
+++ trunk/wp-admin/import/wordpress.php        2009-09-23 22:03:39 UTC (rev 11964)
</span><span class="lines">@@ -357,6 +357,10 @@
</span><span class="cx">                 echo '<h3>'.sprintf(__('All done.').' <a href="%s">'.__('Have fun!').'</a>', get_option('home')).'</h3>';
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function _normalize_tag( $matches ) {
+                return '<' . strtolower( $match[1] );
+        }
+
</ins><span class="cx">         function process_post($post) {
</span><span class="cx">                 global $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -383,12 +387,12 @@
</span><span class="cx">                 $post_author = $this->get_tag( $post, 'dc:creator' );
</span><span class="cx">
</span><span class="cx">                 $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
</span><del>-                $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_excerpt);
</del><ins>+                $post_excerpt = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt);
</ins><span class="cx">                 $post_excerpt = str_replace('<br>', '<br />', $post_excerpt);
</span><span class="cx">                 $post_excerpt = str_replace('<hr>', '<hr />', $post_excerpt);
</span><span class="cx">
</span><span class="cx">                 $post_content = $this->get_tag( $post, 'content:encoded' );
</span><del>-                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', create_function('$match', 'return "<" . strtolower($match[1]);'), $post_content);
</del><ins>+                $post_content = preg_replace_callback('|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content);
</ins><span class="cx">                 $post_content = str_replace('<br>', '<br />', $post_content);
</span><span class="cx">                 $post_content = str_replace('<hr>', '<hr />', $post_content);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>