diff --git a/wp-includes/atomlib.php b/wp-includes/atomlib.php index f2cba56361aa..c326de20631b 100644 --- a/wp-includes/atomlib.php +++ b/wp-includes/atomlib.php @@ -94,8 +94,8 @@ 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' ); } /** @@ -105,6 +105,32 @@ 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"; diff --git a/wp-includes/pomo/po.php b/wp-includes/pomo/po.php index 65d65ff39eb1..1fc8a469d214 100644 --- a/wp-includes/pomo/po.php +++ b/wp-includes/pomo/po.php @@ -167,14 +167,20 @@ public static function unpoify($string) { * @param string $with prepend lines with this string */ public static function prepend_each_line($string, $with) { - $php_with = var_export($with, true); $lines = explode("\n", $string); - // do not prepend the string on the last empty line, artefact by explode - if ("\n" == substr($string, -1)) unset($lines[count($lines) - 1]); - $res = implode("\n", array_map(create_function('$x', "return $php_with.\$x;"), $lines)); - // give back the empty line, we ignored above - if ("\n" == substr($string, -1)) $res .= "\n"; - return $res; + $append = ''; + if ('' === end($lines)) { + // Last line might be empty because $string was terminated + // with a newline, remove it from the $lines array, + // we'll restore state by re-terminating the string at the end + array_pop($lines); + $append = "\n"; + } + foreach ($lines as &$line) { + $line = $with . $line; + } + unset($line); + return implode("\n", $lines) . $append; } /** @@ -279,6 +285,15 @@ function import_from_file($filename) { return true; } + /** + * Helper function for read_entry + * @param string $context + * @return bool + */ + protected static function is_final($context) { + return ($context === 'msgstr') || ($context === 'msgstr_plural'); + } + /** * @param resource $f * @param int $lineno @@ -290,13 +305,12 @@ function read_entry($f, $lineno = 0) { // can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural $context = ''; $msgstr_index = 0; - $is_final = create_function('$context', 'return $context == "msgstr" || $context == "msgstr_plural";'); while (true) { $lineno++; $line = PO::read_line($f); if (!$line) { if (feof($f)) { - if ($is_final($context)) + if (self::is_final($context)) break; elseif (!$context) // we haven't read a line and eof came return null; @@ -310,7 +324,7 @@ function read_entry($f, $lineno = 0) { $line = trim($line); if (preg_match('/^#/', $line, $m)) { // the comment is the start of a new entry - if ($is_final($context)) { + if (self::is_final($context)) { PO::read_line($f, 'put-back'); $lineno--; break; @@ -322,7 +336,7 @@ function read_entry($f, $lineno = 0) { // add comment $this->add_comment_to_entry($entry, $line); } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) { - if ($is_final($context)) { + if (self::is_final($context)) { PO::read_line($f, 'put-back'); $lineno--; break; @@ -333,7 +347,7 @@ function read_entry($f, $lineno = 0) { $context = 'msgctxt'; $entry->context .= PO::unpoify($m[1]); } elseif (preg_match('/^msgid\s+(".*")/', $line, $m)) { - if ($is_final($context)) { + if (self::is_final($context)) { PO::read_line($f, 'put-back'); $lineno--; break; @@ -383,9 +397,18 @@ function read_entry($f, $lineno = 0) { return false; } } - if (array() == array_filter($entry->translations, create_function('$t', 'return $t || "0" === $t;'))) { + + $have_translations = false; + foreach ( $entry->translations as $t ) { + if ( $t || ('0' === $t) ) { + $have_translations = true; + break; + } + } + if ( false === $have_translations ) { $entry->translations = array(); } + return array('entry' => $entry, 'lineno' => $lineno); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 341e5f06bef7..74a1289a5d87 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.8-alpha-39590'; +$wp_version = '4.8-alpha-39591'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.