wp/wp-includes/atomlib.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 16 a86126ab1dd4
--- a/wp/wp-includes/atomlib.php	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-includes/atomlib.php	Mon Oct 14 17:39:30 2019 +0200
@@ -87,14 +87,50 @@
     var $feed;
     var $current;
 
-    function AtomParser() {
+	/**
+	 * PHP5 constructor.
+	 */
+    function __construct() {
 
         $this->feed = new AtomFeed();
         $this->current = null;
-        $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]}\"";');
+        $this->map_attrs_func = array( __CLASS__, 'map_attrs' );
+        $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' );
     }
 
+	/**
+	 * PHP4 constructor.
+	 */
+	public function AtomParser() {
+		self::__construct();
+	}
+
+	/**
+	 * Map attributes to key="val"
+	 *
+	 * @param string $k Key
+	 * @param string $v Value
+	 * @return string
+	 */
+	public static function map_attrs($k, $v) {
+		return "$k=\"$v\"";
+	}
+
+	/**
+	 * Map XML namespace to string.
+	 *
+	 * @param indexish $p XML Namespace element index
+	 * @param array $n Two-element array pair. [ 0 => {namespace}, 1 => {url} ]
+	 * @return string 'xmlns="{url}"' or 'xmlns:{namespace}="{url}"'
+	 */
+	public static function map_xmlns($p, $n) {
+		$xd = "xmlns";
+		if( 0 < strlen($n[0]) ) {
+			$xd .= ":{$n[0]}";
+		}
+		return "{$xd}=\"{$n[1]}\"";
+	}
+
     function _p($msg) {
         if($this->debug) {
             print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n";
@@ -111,6 +147,11 @@
 
         array_unshift($this->ns_contexts, array());
 
+        if ( ! function_exists( 'xml_parser_create_ns' ) ) {
+        	trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
+        	return false;
+        }
+
         $parser = xml_parser_create_ns();
         xml_set_object($parser, $this);
         xml_set_element_handler($parser, "start_element", "end_element");
@@ -130,7 +171,8 @@
             if($this->debug) $this->content .= $data;
 
             if(!xml_parse($parser, $data, feof($fp))) {
-                trigger_error(sprintf(__('XML error: %s at line %d')."\n",
+                /* translators: 1: error message, 2: line number */
+                trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n",
                     xml_error_string(xml_get_error_code($parser)),
                     xml_get_current_line_number($parser)));
                 $ret = false;
@@ -148,7 +190,7 @@
 
     function start_element($parser, $name, $attrs) {
 
-        $tag = array_pop(split(":", $name));
+        $tag = array_pop(explode(":", $name));
 
         switch($name) {
             case $this->NS . ':feed':
@@ -227,7 +269,7 @@
 
     function end_element($parser, $name) {
 
-        $tag = array_pop(split(":", $name));
+        $tag = array_pop(explode(":", $name));
 
         $ccount = count($this->in_content);
 
@@ -302,7 +344,7 @@
 
     function ns_to_prefix($qname, $attr=false) {
         # split 'http://www.w3.org/1999/xhtml:div' into ('http','//www.w3.org/1999/xhtml','div')
-        $components = split(":", $qname);
+        $components = explode(":", $qname);
 
         # grab the last one (e.g 'div')
         $name = array_pop($components);