Ticket #37082: 37082.diff
File 37082.diff, 4.7 KB (added by , 8 years ago) |
---|
-
src/wp-includes/atomlib.php
94 94 95 95 $this->feed = new AtomFeed(); 96 96 $this->current = null; 97 $this->map_attrs_func = create_function('$k,$v', 'return "$k=\"$v\"";');98 $this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');97 $this->map_attrs_func = array( __CLASS__, 'map_attrs' ); 98 $this->map_xmlns_func = array( __CLASS__, 'map_xmlns' ); 99 99 } 100 100 101 101 /** … … 105 105 self::__construct(); 106 106 } 107 107 108 /** 109 * Map attributes to key="val" 110 * 111 * @param string $k Key 112 * @param string $v Value 113 * @return string 114 */ 115 public static function map_attrs($k, $v) { 116 return "$k=\"$v\""; 117 } 118 119 /** 120 * Map XML namespace to string. 121 * 122 * @param indexish $p XML Namespace element index 123 * @param array $n Two-element array pair. [ 0 => {namespace}, 1 => {url} ] 124 * @return string 'xmlns="{url}"' or 'xmlns:{namespace}="{url}"' 125 */ 126 public static function map_xmlns($p, $n) { 127 $xd = "xmlns"; 128 if( 0 < strlen($n[0]) ) { 129 $xd .= ":{$n[0]}"; 130 } 131 return "{$xd}=\"{$n[1]}\""; 132 } 133 108 134 function _p($msg) { 109 135 if($this->debug) { 110 136 print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n"; -
src/wp-includes/pomo/po.php
167 167 * @param string $with prepend lines with this string 168 168 */ 169 169 public static function prepend_each_line($string, $with) { 170 $php_with = var_export($with, true);171 170 $lines = explode("\n", $string); 172 // do not prepend the string on the last empty line, artefact by explode 173 if ("\n" == substr($string, -1)) unset($lines[count($lines) - 1]); 174 $res = implode("\n", array_map(create_function('$x', "return $php_with.\$x;"), $lines)); 175 // give back the empty line, we ignored above 176 if ("\n" == substr($string, -1)) $res .= "\n"; 177 return $res; 171 $append = ''; 172 if ('' === end($lines)) { 173 // Last line might be empty because $string was terminated 174 // with a newline, remove it from the $lines array, 175 // we'll restore state by re-terminating the string at the end 176 array_pop($lines); 177 $append = "\n"; 178 } 179 foreach ($lines as &$line) { 180 $line = $with . $line; 181 } 182 unset($line); 183 return implode("\n", $lines) . $append; 178 184 } 179 185 180 186 /** … … 280 286 } 281 287 282 288 /** 289 * Helper function for read_entry 290 * @param string $context 291 * @return bool 292 */ 293 protected static function is_final($context) { 294 return ($context === 'msgstr') || ($context === 'msgstr_plural'); 295 } 296 297 /** 283 298 * @param resource $f 284 299 * @param int $lineno 285 300 * @return null|false|array … … 290 305 // can be: comment, msgctxt, msgid, msgid_plural, msgstr, msgstr_plural 291 306 $context = ''; 292 307 $msgstr_index = 0; 293 $is_final = create_function('$context', 'return $context == "msgstr" || $context == "msgstr_plural";');294 308 while (true) { 295 309 $lineno++; 296 310 $line = PO::read_line($f); 297 311 if (!$line) { 298 312 if (feof($f)) { 299 if ( $is_final($context))313 if (self::is_final($context)) 300 314 break; 301 315 elseif (!$context) // we haven't read a line and eof came 302 316 return null; … … 310 324 $line = trim($line); 311 325 if (preg_match('/^#/', $line, $m)) { 312 326 // the comment is the start of a new entry 313 if ( $is_final($context)) {327 if (self::is_final($context)) { 314 328 PO::read_line($f, 'put-back'); 315 329 $lineno--; 316 330 break; … … 322 336 // add comment 323 337 $this->add_comment_to_entry($entry, $line); 324 338 } elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) { 325 if ( $is_final($context)) {339 if (self::is_final($context)) { 326 340 PO::read_line($f, 'put-back'); 327 341 $lineno--; 328 342 break; … … 333 347 $context = 'msgctxt'; 334 348 $entry->context .= PO::unpoify($m[1]); 335 349 } elseif (preg_match('/^msgid\s+(".*")/', $line, $m)) { 336 if ( $is_final($context)) {350 if (self::is_final($context)) { 337 351 PO::read_line($f, 'put-back'); 338 352 $lineno--; 339 353 break; … … 383 397 return false; 384 398 } 385 399 } 386 if (array() == array_filter($entry->translations, create_function('$t', 'return $t || "0" === $t;'))) { 400 401 $have_translations = false; 402 foreach ( $entry->translations as $t ) { 403 if ( $t || ('0' === $t) ) { 404 $have_translations = true; 405 break; 406 } 407 } 408 if ( false === $have_translations ) { 387 409 $entry->translations = array(); 388 410 } 411 389 412 return array('entry' => $entry, 'lineno' => $lineno); 390 413 } 391 414