@@ -100,6 +100,9 @@ discard block |
||
| 100 | 100 | return $header; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | + /** |
|
| 104 | + * @param string[] $lines |
|
| 105 | + */ |
|
| 103 | 106 | function _lines($lines, $prefix = ' ', $encode = true) |
| 104 | 107 | { |
| 105 | 108 | if ($encode) { |
@@ -178,6 +181,9 @@ discard block |
||
| 178 | 181 | return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; |
| 179 | 182 | } |
| 180 | 183 | |
| 184 | + /** |
|
| 185 | + * @param string $string |
|
| 186 | + */ |
|
| 181 | 187 | function _splitOnWords($string, $newlineEscape = "\n") |
| 182 | 188 | { |
| 183 | 189 | // Ignore \0; otherwise the while loop will never finish. |
@@ -26,181 +26,181 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Text_Diff_Renderer_inline extends Text_Diff_Renderer { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Number of leading context "lines" to preserve. |
|
| 31 | - * |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 34 | - var $_leading_context_lines = 10000; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Number of trailing context "lines" to preserve. |
|
| 38 | - * |
|
| 39 | - * @var integer |
|
| 40 | - */ |
|
| 41 | - var $_trailing_context_lines = 10000; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Prefix for inserted text. |
|
| 45 | - * |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 48 | - var $_ins_prefix = '<ins>'; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Suffix for inserted text. |
|
| 52 | - * |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - var $_ins_suffix = '</ins>'; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Prefix for deleted text. |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - var $_del_prefix = '<del>'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Suffix for deleted text. |
|
| 66 | - * |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - var $_del_suffix = '</del>'; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Header for each change block. |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - var $_block_header = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Whether to split down to character-level. |
|
| 80 | - * |
|
| 81 | - * @var boolean |
|
| 82 | - */ |
|
| 83 | - var $_split_characters = false; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * What are we currently splitting on? Used to recurse to show word-level |
|
| 87 | - * or character-level changes. |
|
| 88 | - * |
|
| 89 | - * @var string |
|
| 90 | - */ |
|
| 91 | - var $_split_level = 'lines'; |
|
| 92 | - |
|
| 93 | - function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
|
| 94 | - { |
|
| 95 | - return $this->_block_header; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - function _startBlock($header) |
|
| 99 | - { |
|
| 100 | - return $header; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - function _lines($lines, $prefix = ' ', $encode = true) |
|
| 104 | - { |
|
| 105 | - if ($encode) { |
|
| 106 | - array_walk($lines, array(&$this, '_encode')); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($this->_split_level == 'lines') { |
|
| 110 | - return implode("\n", $lines) . "\n"; |
|
| 111 | - } else { |
|
| 112 | - return implode('', $lines); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - function _added($lines) |
|
| 117 | - { |
|
| 118 | - array_walk($lines, array(&$this, '_encode')); |
|
| 119 | - $lines[0] = $this->_ins_prefix . $lines[0]; |
|
| 120 | - $lines[count($lines) - 1] .= $this->_ins_suffix; |
|
| 121 | - return $this->_lines($lines, ' ', false); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - function _deleted($lines, $words = false) |
|
| 125 | - { |
|
| 126 | - array_walk($lines, array(&$this, '_encode')); |
|
| 127 | - $lines[0] = $this->_del_prefix . $lines[0]; |
|
| 128 | - $lines[count($lines) - 1] .= $this->_del_suffix; |
|
| 129 | - return $this->_lines($lines, ' ', false); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - function _changed($orig, $final) |
|
| 133 | - { |
|
| 134 | - /* If we've already split on characters, just display. */ |
|
| 135 | - if ($this->_split_level == 'characters') { |
|
| 136 | - return $this->_deleted($orig) |
|
| 137 | - . $this->_added($final); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /* If we've already split on words, just display. */ |
|
| 141 | - if ($this->_split_level == 'words') { |
|
| 142 | - $prefix = ''; |
|
| 143 | - while ($orig[0] !== false && $final[0] !== false && |
|
| 144 | - substr($orig[0], 0, 1) == ' ' && |
|
| 145 | - substr($final[0], 0, 1) == ' ') { |
|
| 146 | - $prefix .= substr($orig[0], 0, 1); |
|
| 147 | - $orig[0] = substr($orig[0], 1); |
|
| 148 | - $final[0] = substr($final[0], 1); |
|
| 149 | - } |
|
| 150 | - return $prefix . $this->_deleted($orig) . $this->_added($final); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $text1 = implode("\n", $orig); |
|
| 154 | - $text2 = implode("\n", $final); |
|
| 155 | - |
|
| 156 | - /* Non-printing newline marker. */ |
|
| 157 | - $nl = "\0"; |
|
| 158 | - |
|
| 159 | - if ($this->_split_characters) { |
|
| 160 | - $diff = new Text_Diff('native', |
|
| 161 | - array(preg_split('//', $text1), |
|
| 162 | - preg_split('//', $text2))); |
|
| 163 | - } else { |
|
| 164 | - /* We want to split on word boundaries, but we need to preserve |
|
| 29 | + /** |
|
| 30 | + * Number of leading context "lines" to preserve. |
|
| 31 | + * |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | + var $_leading_context_lines = 10000; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Number of trailing context "lines" to preserve. |
|
| 38 | + * |
|
| 39 | + * @var integer |
|
| 40 | + */ |
|
| 41 | + var $_trailing_context_lines = 10000; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Prefix for inserted text. |
|
| 45 | + * |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | + var $_ins_prefix = '<ins>'; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Suffix for inserted text. |
|
| 52 | + * |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + var $_ins_suffix = '</ins>'; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Prefix for deleted text. |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + var $_del_prefix = '<del>'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Suffix for deleted text. |
|
| 66 | + * |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + var $_del_suffix = '</del>'; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Header for each change block. |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + var $_block_header = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Whether to split down to character-level. |
|
| 80 | + * |
|
| 81 | + * @var boolean |
|
| 82 | + */ |
|
| 83 | + var $_split_characters = false; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * What are we currently splitting on? Used to recurse to show word-level |
|
| 87 | + * or character-level changes. |
|
| 88 | + * |
|
| 89 | + * @var string |
|
| 90 | + */ |
|
| 91 | + var $_split_level = 'lines'; |
|
| 92 | + |
|
| 93 | + function _blockHeader($xbeg, $xlen, $ybeg, $ylen) |
|
| 94 | + { |
|
| 95 | + return $this->_block_header; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + function _startBlock($header) |
|
| 99 | + { |
|
| 100 | + return $header; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + function _lines($lines, $prefix = ' ', $encode = true) |
|
| 104 | + { |
|
| 105 | + if ($encode) { |
|
| 106 | + array_walk($lines, array(&$this, '_encode')); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($this->_split_level == 'lines') { |
|
| 110 | + return implode("\n", $lines) . "\n"; |
|
| 111 | + } else { |
|
| 112 | + return implode('', $lines); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + function _added($lines) |
|
| 117 | + { |
|
| 118 | + array_walk($lines, array(&$this, '_encode')); |
|
| 119 | + $lines[0] = $this->_ins_prefix . $lines[0]; |
|
| 120 | + $lines[count($lines) - 1] .= $this->_ins_suffix; |
|
| 121 | + return $this->_lines($lines, ' ', false); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + function _deleted($lines, $words = false) |
|
| 125 | + { |
|
| 126 | + array_walk($lines, array(&$this, '_encode')); |
|
| 127 | + $lines[0] = $this->_del_prefix . $lines[0]; |
|
| 128 | + $lines[count($lines) - 1] .= $this->_del_suffix; |
|
| 129 | + return $this->_lines($lines, ' ', false); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + function _changed($orig, $final) |
|
| 133 | + { |
|
| 134 | + /* If we've already split on characters, just display. */ |
|
| 135 | + if ($this->_split_level == 'characters') { |
|
| 136 | + return $this->_deleted($orig) |
|
| 137 | + . $this->_added($final); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /* If we've already split on words, just display. */ |
|
| 141 | + if ($this->_split_level == 'words') { |
|
| 142 | + $prefix = ''; |
|
| 143 | + while ($orig[0] !== false && $final[0] !== false && |
|
| 144 | + substr($orig[0], 0, 1) == ' ' && |
|
| 145 | + substr($final[0], 0, 1) == ' ') { |
|
| 146 | + $prefix .= substr($orig[0], 0, 1); |
|
| 147 | + $orig[0] = substr($orig[0], 1); |
|
| 148 | + $final[0] = substr($final[0], 1); |
|
| 149 | + } |
|
| 150 | + return $prefix . $this->_deleted($orig) . $this->_added($final); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $text1 = implode("\n", $orig); |
|
| 154 | + $text2 = implode("\n", $final); |
|
| 155 | + |
|
| 156 | + /* Non-printing newline marker. */ |
|
| 157 | + $nl = "\0"; |
|
| 158 | + |
|
| 159 | + if ($this->_split_characters) { |
|
| 160 | + $diff = new Text_Diff('native', |
|
| 161 | + array(preg_split('//', $text1), |
|
| 162 | + preg_split('//', $text2))); |
|
| 163 | + } else { |
|
| 164 | + /* We want to split on word boundaries, but we need to preserve |
|
| 165 | 165 | * whitespace as well. Therefore we split on words, but include |
| 166 | 166 | * all blocks of whitespace in the wordlist. */ |
| 167 | - $diff = new Text_Diff('native', |
|
| 168 | - array($this->_splitOnWords($text1, $nl), |
|
| 169 | - $this->_splitOnWords($text2, $nl))); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /* Get the diff in inline format. */ |
|
| 173 | - $renderer = new Text_Diff_Renderer_inline |
|
| 174 | - (array_merge($this->getParams(), |
|
| 175 | - array('split_level' => $this->_split_characters ? 'characters' : 'words'))); |
|
| 176 | - |
|
| 177 | - /* Run the diff and get the output. */ |
|
| 178 | - return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - function _splitOnWords($string, $newlineEscape = "\n") |
|
| 182 | - { |
|
| 183 | - // Ignore \0; otherwise the while loop will never finish. |
|
| 184 | - $string = str_replace("\0", '', $string); |
|
| 185 | - |
|
| 186 | - $words = array(); |
|
| 187 | - $length = strlen($string); |
|
| 188 | - $pos = 0; |
|
| 189 | - |
|
| 190 | - while ($pos < $length) { |
|
| 191 | - // Eat a word with any preceding whitespace. |
|
| 192 | - $spaces = strspn(substr($string, $pos), " \n"); |
|
| 193 | - $nextpos = strcspn(substr($string, $pos + $spaces), " \n"); |
|
| 194 | - $words[] = str_replace("\n", $newlineEscape, substr($string, $pos, $spaces + $nextpos)); |
|
| 195 | - $pos += $spaces + $nextpos; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - return $words; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - function _encode(&$string) |
|
| 202 | - { |
|
| 203 | - $string = htmlspecialchars($string); |
|
| 204 | - } |
|
| 167 | + $diff = new Text_Diff('native', |
|
| 168 | + array($this->_splitOnWords($text1, $nl), |
|
| 169 | + $this->_splitOnWords($text2, $nl))); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /* Get the diff in inline format. */ |
|
| 173 | + $renderer = new Text_Diff_Renderer_inline |
|
| 174 | + (array_merge($this->getParams(), |
|
| 175 | + array('split_level' => $this->_split_characters ? 'characters' : 'words'))); |
|
| 176 | + |
|
| 177 | + /* Run the diff and get the output. */ |
|
| 178 | + return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + function _splitOnWords($string, $newlineEscape = "\n") |
|
| 182 | + { |
|
| 183 | + // Ignore \0; otherwise the while loop will never finish. |
|
| 184 | + $string = str_replace("\0", '', $string); |
|
| 185 | + |
|
| 186 | + $words = array(); |
|
| 187 | + $length = strlen($string); |
|
| 188 | + $pos = 0; |
|
| 189 | + |
|
| 190 | + while ($pos < $length) { |
|
| 191 | + // Eat a word with any preceding whitespace. |
|
| 192 | + $spaces = strspn(substr($string, $pos), " \n"); |
|
| 193 | + $nextpos = strcspn(substr($string, $pos + $spaces), " \n"); |
|
| 194 | + $words[] = str_replace("\n", $newlineEscape, substr($string, $pos, $spaces + $nextpos)); |
|
| 195 | + $pos += $spaces + $nextpos; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + return $words; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + function _encode(&$string) |
|
| 202 | + { |
|
| 203 | + $string = htmlspecialchars($string); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | 206 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | /** Text_Diff_Renderer */ |
| 15 | 15 | |
| 16 | 16 | // WP #7391 |
| 17 | -require_once dirname(dirname(__FILE__)) . '/Renderer.php'; |
|
| 17 | +require_once dirname(dirname(__FILE__)).'/Renderer.php'; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * "Inline" diff renderer. |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | if ($this->_split_level == 'lines') { |
| 110 | - return implode("\n", $lines) . "\n"; |
|
| 110 | + return implode("\n", $lines)."\n"; |
|
| 111 | 111 | } else { |
| 112 | 112 | return implode('', $lines); |
| 113 | 113 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | function _added($lines) |
| 117 | 117 | { |
| 118 | 118 | array_walk($lines, array(&$this, '_encode')); |
| 119 | - $lines[0] = $this->_ins_prefix . $lines[0]; |
|
| 119 | + $lines[0] = $this->_ins_prefix.$lines[0]; |
|
| 120 | 120 | $lines[count($lines) - 1] .= $this->_ins_suffix; |
| 121 | 121 | return $this->_lines($lines, ' ', false); |
| 122 | 122 | } |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | function _deleted($lines, $words = false) |
| 125 | 125 | { |
| 126 | 126 | array_walk($lines, array(&$this, '_encode')); |
| 127 | - $lines[0] = $this->_del_prefix . $lines[0]; |
|
| 127 | + $lines[0] = $this->_del_prefix.$lines[0]; |
|
| 128 | 128 | $lines[count($lines) - 1] .= $this->_del_suffix; |
| 129 | 129 | return $this->_lines($lines, ' ', false); |
| 130 | 130 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $orig[0] = substr($orig[0], 1); |
| 148 | 148 | $final[0] = substr($final[0], 1); |
| 149 | 149 | } |
| 150 | - return $prefix . $this->_deleted($orig) . $this->_added($final); |
|
| 150 | + return $prefix.$this->_deleted($orig).$this->_added($final); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | $text1 = implode("\n", $orig); |
@@ -170,12 +170,11 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /* Get the diff in inline format. */ |
| 173 | - $renderer = new Text_Diff_Renderer_inline |
|
| 174 | - (array_merge($this->getParams(), |
|
| 173 | + $renderer = new Text_Diff_Renderer_inline(array_merge($this->getParams(), |
|
| 175 | 174 | array('split_level' => $this->_split_characters ? 'characters' : 'words'))); |
| 176 | 175 | |
| 177 | 176 | /* Run the diff and get the output. */ |
| 178 | - return str_replace($nl, "\n", $renderer->render($diff)) . "\n"; |
|
| 177 | + return str_replace($nl, "\n", $renderer->render($diff))."\n"; |
|
| 179 | 178 | } |
| 180 | 179 | |
| 181 | 180 | function _splitOnWords($string, $newlineEscape = "\n") |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * @access public |
| 496 | 496 | * |
| 497 | 497 | * @param string $name Property to check if set. |
| 498 | - * @return bool Whether the property is set. |
|
| 498 | + * @return boolean|null Whether the property is set. |
|
| 499 | 499 | */ |
| 500 | 500 | public function __isset( $name ) { |
| 501 | 501 | if ( in_array( $name, $this->compat_fields ) ) { |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * @param string $string |
| 534 | 534 | * @param string $newlineEscape |
| 535 | - * @return string |
|
| 535 | + * @return string[] |
|
| 536 | 536 | */ |
| 537 | 537 | public function _splitOnWords($string, $newlineEscape = "\n") { |
| 538 | 538 | $string = str_replace("\0", '', $string); |
@@ -81,8 +81,9 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function __construct( $params = array() ) { |
| 83 | 83 | parent::__construct( $params ); |
| 84 | - if ( isset( $params[ 'show_split_view' ] ) ) |
|
| 85 | - $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 84 | + if ( isset( $params[ 'show_split_view' ] ) ) { |
|
| 85 | + $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 86 | + } |
|
| 86 | 87 | } |
| 87 | 88 | |
| 88 | 89 | /** |
@@ -280,8 +281,10 @@ discard block |
||
| 280 | 281 | // we double the length of chars not in those tags. |
| 281 | 282 | $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches; |
| 282 | 283 | $diff_ratio = $stripped_matches / $stripped_diff; |
| 283 | - if ( $diff_ratio > $this->_diff_threshold ) |
|
| 284 | - continue; // Too different. Don't save diffs. |
|
| 284 | + if ( $diff_ratio > $this->_diff_threshold ) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 287 | + // Too different. Don't save diffs. |
|
| 285 | 288 | } |
| 286 | 289 | |
| 287 | 290 | // Un-inline the diffs by removing del or ins |
@@ -292,23 +295,26 @@ discard block |
||
| 292 | 295 | |
| 293 | 296 | foreach ( array_keys($orig_rows) as $row ) { |
| 294 | 297 | // Both columns have blanks. Ignore them. |
| 295 | - if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) |
|
| 296 | - continue; |
|
| 298 | + if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) { |
|
| 299 | + continue; |
|
| 300 | + } |
|
| 297 | 301 | |
| 298 | 302 | // If we have a word based diff, use it. Otherwise, use the normal line. |
| 299 | - if ( isset( $orig_diffs[$orig_rows[$row]] ) ) |
|
| 300 | - $orig_line = $orig_diffs[$orig_rows[$row]]; |
|
| 301 | - elseif ( isset( $orig[$orig_rows[$row]] ) ) |
|
| 302 | - $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
|
| 303 | - else |
|
| 304 | - $orig_line = ''; |
|
| 305 | - |
|
| 306 | - if ( isset( $final_diffs[$final_rows[$row]] ) ) |
|
| 307 | - $final_line = $final_diffs[$final_rows[$row]]; |
|
| 308 | - elseif ( isset( $final[$final_rows[$row]] ) ) |
|
| 309 | - $final_line = htmlspecialchars($final[$final_rows[$row]]); |
|
| 310 | - else |
|
| 311 | - $final_line = ''; |
|
| 303 | + if ( isset( $orig_diffs[$orig_rows[$row]] ) ) { |
|
| 304 | + $orig_line = $orig_diffs[$orig_rows[$row]]; |
|
| 305 | + } elseif ( isset( $orig[$orig_rows[$row]] ) ) { |
|
| 306 | + $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
|
| 307 | + } else { |
|
| 308 | + $orig_line = ''; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + if ( isset( $final_diffs[$final_rows[$row]] ) ) { |
|
| 312 | + $final_line = $final_diffs[$final_rows[$row]]; |
|
| 313 | + } elseif ( isset( $final[$final_rows[$row]] ) ) { |
|
| 314 | + $final_line = htmlspecialchars($final[$final_rows[$row]]); |
|
| 315 | + } else { |
|
| 316 | + $final_line = ''; |
|
| 317 | + } |
|
| 312 | 318 | |
| 313 | 319 | if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row. |
| 314 | 320 | $r .= $this->_added( array($final_line), false ); |
@@ -360,8 +366,9 @@ discard block |
||
| 360 | 366 | $f = (int) $f; |
| 361 | 367 | |
| 362 | 368 | // Already have better matches for these guys |
| 363 | - if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) |
|
| 364 | - continue; |
|
| 369 | + if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) { |
|
| 370 | + continue; |
|
| 371 | + } |
|
| 365 | 372 | |
| 366 | 373 | // First match for these guys. Must be best match |
| 367 | 374 | if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) { |
@@ -371,12 +378,14 @@ discard block |
||
| 371 | 378 | } |
| 372 | 379 | |
| 373 | 380 | // Best match of this final is already taken? Must mean this final is a new row. |
| 374 | - if ( isset($orig_matches[$o]) ) |
|
| 375 | - $final_matches[$f] = 'x'; |
|
| 381 | + if ( isset($orig_matches[$o]) ) { |
|
| 382 | + $final_matches[$f] = 'x'; |
|
| 383 | + } |
|
| 376 | 384 | |
| 377 | 385 | // Best match of this orig is already taken? Must mean this orig is a deleted row. |
| 378 | - elseif ( isset($final_matches[$f]) ) |
|
| 379 | - $orig_matches[$o] = 'x'; |
|
| 386 | + elseif ( isset($final_matches[$f]) ) { |
|
| 387 | + $orig_matches[$o] = 'x'; |
|
| 388 | + } |
|
| 380 | 389 | } |
| 381 | 390 | |
| 382 | 391 | // We read the text in this order |
@@ -397,24 +406,28 @@ discard block |
||
| 397 | 406 | array_splice( $final_rows, $orig_pos, 0, -1 ); |
| 398 | 407 | } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. |
| 399 | 408 | $diff_pos = $final_pos - $orig_pos; |
| 400 | - while ( $diff_pos < 0 ) |
|
| 401 | - array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 409 | + while ( $diff_pos < 0 ) { |
|
| 410 | + array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 411 | + } |
|
| 402 | 412 | } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. |
| 403 | 413 | $diff_pos = $orig_pos - $final_pos; |
| 404 | - while ( $diff_pos < 0 ) |
|
| 405 | - array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 414 | + while ( $diff_pos < 0 ) { |
|
| 415 | + array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 416 | + } |
|
| 406 | 417 | } |
| 407 | 418 | } |
| 408 | 419 | |
| 409 | 420 | // Pad the ends with blank rows if the columns aren't the same length |
| 410 | 421 | $diff_count = count($orig_rows) - count($final_rows); |
| 411 | 422 | if ( $diff_count < 0 ) { |
| 412 | - while ( $diff_count < 0 ) |
|
| 413 | - array_push($orig_rows, $diff_count++); |
|
| 423 | + while ( $diff_count < 0 ) { |
|
| 424 | + array_push($orig_rows, $diff_count++); |
|
| 425 | + } |
|
| 414 | 426 | } elseif ( $diff_count > 0 ) { |
| 415 | 427 | $diff_count = -1 * $diff_count; |
| 416 | - while ( $diff_count < 0 ) |
|
| 417 | - array_push($final_rows, $diff_count++); |
|
| 428 | + while ( $diff_count < 0 ) { |
|
| 429 | + array_push($final_rows, $diff_count++); |
|
| 430 | + } |
|
| 418 | 431 | } |
| 419 | 432 | |
| 420 | 433 | return array($orig_matches, $final_matches, $orig_rows, $final_rows); |
@@ -438,8 +451,9 @@ discard block |
||
| 438 | 451 | $difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); |
| 439 | 452 | |
| 440 | 453 | // $string1 has zero length? Odd. Give huge penalty by not dividing. |
| 441 | - if ( !$string1 ) |
|
| 442 | - return $difference; |
|
| 454 | + if ( !$string1 ) { |
|
| 455 | + return $difference; |
|
| 456 | + } |
|
| 443 | 457 | |
| 444 | 458 | // Return distance per character (of string1). |
| 445 | 459 | return $difference / strlen($string1); |
@@ -8,13 +8,13 @@ discard block |
||
| 8 | 8 | * @subpackage Diff |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | -if ( ! class_exists( 'Text_Diff', false ) ) { |
|
| 11 | +if ( ! class_exists('Text_Diff', false)) { |
|
| 12 | 12 | /** Text_Diff class */ |
| 13 | - require( dirname(__FILE__).'/Text/Diff.php' ); |
|
| 13 | + require(dirname(__FILE__).'/Text/Diff.php'); |
|
| 14 | 14 | /** Text_Diff_Renderer class */ |
| 15 | - require( dirname(__FILE__).'/Text/Diff/Renderer.php' ); |
|
| 15 | + require(dirname(__FILE__).'/Text/Diff/Renderer.php'); |
|
| 16 | 16 | /** Text_Diff_Renderer_inline class */ |
| 17 | - require( dirname(__FILE__).'/Text/Diff/Renderer/inline.php' ); |
|
| 17 | + require(dirname(__FILE__).'/Text/Diff/Renderer/inline.php'); |
|
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | /** |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @access public |
| 32 | 32 | * @since 2.6.0 |
| 33 | 33 | */ |
| 34 | - public $_leading_context_lines = 10000; |
|
| 34 | + public $_leading_context_lines = 10000; |
|
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @see Text_Diff_Renderer::_trailing_context_lines |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | protected $_show_split_view = true; |
| 70 | 70 | |
| 71 | - protected $compat_fields = array( '_show_split_view', 'inline_diff_renderer', '_diff_threshold' ); |
|
| 71 | + protected $compat_fields = array('_show_split_view', 'inline_diff_renderer', '_diff_threshold'); |
|
| 72 | 72 | |
| 73 | 73 | /** |
| 74 | 74 | * Constructor - Call parent constructor with params array. |
@@ -79,10 +79,10 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @param array $params |
| 81 | 81 | */ |
| 82 | - public function __construct( $params = array() ) { |
|
| 83 | - parent::__construct( $params ); |
|
| 84 | - if ( isset( $params[ 'show_split_view' ] ) ) |
|
| 85 | - $this->_show_split_view = $params[ 'show_split_view' ]; |
|
| 82 | + public function __construct($params = array()) { |
|
| 83 | + parent::__construct($params); |
|
| 84 | + if (isset($params['show_split_view'])) |
|
| 85 | + $this->_show_split_view = $params['show_split_view']; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @param string $header |
| 92 | 92 | * @return string |
| 93 | 93 | */ |
| 94 | - public function _startBlock( $header ) { |
|
| 94 | + public function _startBlock($header) { |
|
| 95 | 95 | return ''; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @param array $lines |
| 102 | 102 | * @param string $prefix |
| 103 | 103 | */ |
| 104 | - public function _lines( $lines, $prefix=' ' ) { |
|
| 104 | + public function _lines($lines, $prefix = ' ') { |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param string $line HTML-escape the value. |
| 111 | 111 | * @return string |
| 112 | 112 | */ |
| 113 | - public function addedLine( $line ) { |
|
| 113 | + public function addedLine($line) { |
|
| 114 | 114 | return "<td class='diff-addedline'>{$line}</td>"; |
| 115 | 115 | |
| 116 | 116 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | * @param string $line HTML-escape the value. |
| 122 | 122 | * @return string |
| 123 | 123 | */ |
| 124 | - public function deletedLine( $line ) { |
|
| 124 | + public function deletedLine($line) { |
|
| 125 | 125 | return "<td class='diff-deletedline'>{$line}</td>"; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | * @param string $line HTML-escape the value. |
| 132 | 132 | * @return string |
| 133 | 133 | */ |
| 134 | - public function contextLine( $line ) { |
|
| 134 | + public function contextLine($line) { |
|
| 135 | 135 | return "<td class='diff-context'>{$line}</td>"; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | * @param bool $encode |
| 153 | 153 | * @return string |
| 154 | 154 | */ |
| 155 | - public function _added( $lines, $encode = true ) { |
|
| 155 | + public function _added($lines, $encode = true) { |
|
| 156 | 156 | $r = ''; |
| 157 | 157 | foreach ($lines as $line) { |
| 158 | - if ( $encode ) { |
|
| 159 | - $processed_line = htmlspecialchars( $line ); |
|
| 158 | + if ($encode) { |
|
| 159 | + $processed_line = htmlspecialchars($line); |
|
| 160 | 160 | |
| 161 | 161 | /** |
| 162 | 162 | * Contextually filter a diffed line. |
@@ -171,13 +171,13 @@ discard block |
||
| 171 | 171 | * @param String $line The unprocessed diffed line. |
| 172 | 172 | * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
| 173 | 173 | */ |
| 174 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' ); |
|
| 174 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'added'); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if ( $this->_show_split_view ) { |
|
| 178 | - $r .= '<tr>' . $this->emptyLine() . $this->emptyLine() . $this->addedLine( $line ) . "</tr>\n"; |
|
| 177 | + if ($this->_show_split_view) { |
|
| 178 | + $r .= '<tr>'.$this->emptyLine().$this->emptyLine().$this->addedLine($line)."</tr>\n"; |
|
| 179 | 179 | } else { |
| 180 | - $r .= '<tr>' . $this->addedLine( $line ) . "</tr>\n"; |
|
| 180 | + $r .= '<tr>'.$this->addedLine($line)."</tr>\n"; |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | return $r; |
@@ -191,19 +191,19 @@ discard block |
||
| 191 | 191 | * @param bool $encode |
| 192 | 192 | * @return string |
| 193 | 193 | */ |
| 194 | - public function _deleted( $lines, $encode = true ) { |
|
| 194 | + public function _deleted($lines, $encode = true) { |
|
| 195 | 195 | $r = ''; |
| 196 | 196 | foreach ($lines as $line) { |
| 197 | - if ( $encode ) { |
|
| 198 | - $processed_line = htmlspecialchars( $line ); |
|
| 197 | + if ($encode) { |
|
| 198 | + $processed_line = htmlspecialchars($line); |
|
| 199 | 199 | |
| 200 | 200 | /** This filter is documented in wp-includes/wp-diff.php */ |
| 201 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'deleted' ); |
|
| 201 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'deleted'); |
|
| 202 | 202 | } |
| 203 | - if ( $this->_show_split_view ) { |
|
| 204 | - $r .= '<tr>' . $this->deletedLine( $line ) . $this->emptyLine() . $this->emptyLine() . "</tr>\n"; |
|
| 203 | + if ($this->_show_split_view) { |
|
| 204 | + $r .= '<tr>'.$this->deletedLine($line).$this->emptyLine().$this->emptyLine()."</tr>\n"; |
|
| 205 | 205 | } else { |
| 206 | - $r .= '<tr>' . $this->deletedLine( $line ) . "</tr>\n"; |
|
| 206 | + $r .= '<tr>'.$this->deletedLine($line)."</tr>\n"; |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | } |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | * @param bool $encode |
| 219 | 219 | * @return string |
| 220 | 220 | */ |
| 221 | - public function _context( $lines, $encode = true ) { |
|
| 221 | + public function _context($lines, $encode = true) { |
|
| 222 | 222 | $r = ''; |
| 223 | 223 | foreach ($lines as $line) { |
| 224 | - if ( $encode ) { |
|
| 225 | - $processed_line = htmlspecialchars( $line ); |
|
| 224 | + if ($encode) { |
|
| 225 | + $processed_line = htmlspecialchars($line); |
|
| 226 | 226 | |
| 227 | 227 | /** This filter is documented in wp-includes/wp-diff.php */ |
| 228 | - $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'unchanged' ); |
|
| 228 | + $line = apply_filters('process_text_diff_html', $processed_line, $line, 'unchanged'); |
|
| 229 | 229 | } |
| 230 | - if ( $this->_show_split_view ) { |
|
| 231 | - $r .= '<tr>' . $this->contextLine( $line ) . $this->emptyLine() . $this->contextLine( $line ) . "</tr>\n"; |
|
| 230 | + if ($this->_show_split_view) { |
|
| 231 | + $r .= '<tr>'.$this->contextLine($line).$this->emptyLine().$this->contextLine($line)."</tr>\n"; |
|
| 232 | 232 | } else { |
| 233 | - $r .= '<tr>' . $this->contextLine( $line ) . "</tr>\n"; |
|
| 233 | + $r .= '<tr>'.$this->contextLine($line)."</tr>\n"; |
|
| 234 | 234 | } |
| 235 | 235 | } |
| 236 | 236 | return $r; |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | * @param array $final |
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | - public function _changed( $orig, $final ) { |
|
| 252 | + public function _changed($orig, $final) { |
|
| 253 | 253 | $r = ''; |
| 254 | 254 | |
| 255 | 255 | // Does the aforementioned additional processing |
@@ -259,66 +259,66 @@ discard block |
||
| 259 | 259 | // *_rows are column vectors for the orig column and the final column. |
| 260 | 260 | // row >= 0: an indix of the $orig or $final array |
| 261 | 261 | // row < 0: a blank row for that column |
| 262 | - list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines( $orig, $final ); |
|
| 262 | + list($orig_matches, $final_matches, $orig_rows, $final_rows) = $this->interleave_changed_lines($orig, $final); |
|
| 263 | 263 | |
| 264 | 264 | // These will hold the word changes as determined by an inline diff |
| 265 | 265 | $orig_diffs = array(); |
| 266 | 266 | $final_diffs = array(); |
| 267 | 267 | |
| 268 | 268 | // Compute word diffs for each matched pair using the inline diff |
| 269 | - foreach ( $orig_matches as $o => $f ) { |
|
| 270 | - if ( is_numeric($o) && is_numeric($f) ) { |
|
| 271 | - $text_diff = new Text_Diff( 'auto', array( array($orig[$o]), array($final[$f]) ) ); |
|
| 269 | + foreach ($orig_matches as $o => $f) { |
|
| 270 | + if (is_numeric($o) && is_numeric($f)) { |
|
| 271 | + $text_diff = new Text_Diff('auto', array(array($orig[$o]), array($final[$f]))); |
|
| 272 | 272 | $renderer = new $this->inline_diff_renderer; |
| 273 | - $diff = $renderer->render( $text_diff ); |
|
| 273 | + $diff = $renderer->render($text_diff); |
|
| 274 | 274 | |
| 275 | 275 | // If they're too different, don't include any <ins> or <dels> |
| 276 | - if ( preg_match_all( '!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches ) ) { |
|
| 276 | + if (preg_match_all('!(<ins>.*?</ins>|<del>.*?</del>)!', $diff, $diff_matches)) { |
|
| 277 | 277 | // length of all text between <ins> or <del> |
| 278 | - $stripped_matches = strlen(strip_tags( join(' ', $diff_matches[0]) )); |
|
| 278 | + $stripped_matches = strlen(strip_tags(join(' ', $diff_matches[0]))); |
|
| 279 | 279 | // since we count lengith of text between <ins> or <del> (instead of picking just one), |
| 280 | 280 | // we double the length of chars not in those tags. |
| 281 | - $stripped_diff = strlen(strip_tags( $diff )) * 2 - $stripped_matches; |
|
| 281 | + $stripped_diff = strlen(strip_tags($diff)) * 2 - $stripped_matches; |
|
| 282 | 282 | $diff_ratio = $stripped_matches / $stripped_diff; |
| 283 | - if ( $diff_ratio > $this->_diff_threshold ) |
|
| 283 | + if ($diff_ratio > $this->_diff_threshold) |
|
| 284 | 284 | continue; // Too different. Don't save diffs. |
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Un-inline the diffs by removing del or ins |
| 288 | - $orig_diffs[$o] = preg_replace( '|<ins>.*?</ins>|', '', $diff ); |
|
| 289 | - $final_diffs[$f] = preg_replace( '|<del>.*?</del>|', '', $diff ); |
|
| 288 | + $orig_diffs[$o] = preg_replace('|<ins>.*?</ins>|', '', $diff); |
|
| 289 | + $final_diffs[$f] = preg_replace('|<del>.*?</del>|', '', $diff); |
|
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - foreach ( array_keys($orig_rows) as $row ) { |
|
| 293 | + foreach (array_keys($orig_rows) as $row) { |
|
| 294 | 294 | // Both columns have blanks. Ignore them. |
| 295 | - if ( $orig_rows[$row] < 0 && $final_rows[$row] < 0 ) |
|
| 295 | + if ($orig_rows[$row] < 0 && $final_rows[$row] < 0) |
|
| 296 | 296 | continue; |
| 297 | 297 | |
| 298 | 298 | // If we have a word based diff, use it. Otherwise, use the normal line. |
| 299 | - if ( isset( $orig_diffs[$orig_rows[$row]] ) ) |
|
| 299 | + if (isset($orig_diffs[$orig_rows[$row]])) |
|
| 300 | 300 | $orig_line = $orig_diffs[$orig_rows[$row]]; |
| 301 | - elseif ( isset( $orig[$orig_rows[$row]] ) ) |
|
| 301 | + elseif (isset($orig[$orig_rows[$row]])) |
|
| 302 | 302 | $orig_line = htmlspecialchars($orig[$orig_rows[$row]]); |
| 303 | 303 | else |
| 304 | 304 | $orig_line = ''; |
| 305 | 305 | |
| 306 | - if ( isset( $final_diffs[$final_rows[$row]] ) ) |
|
| 306 | + if (isset($final_diffs[$final_rows[$row]])) |
|
| 307 | 307 | $final_line = $final_diffs[$final_rows[$row]]; |
| 308 | - elseif ( isset( $final[$final_rows[$row]] ) ) |
|
| 308 | + elseif (isset($final[$final_rows[$row]])) |
|
| 309 | 309 | $final_line = htmlspecialchars($final[$final_rows[$row]]); |
| 310 | 310 | else |
| 311 | 311 | $final_line = ''; |
| 312 | 312 | |
| 313 | - if ( $orig_rows[$row] < 0 ) { // Orig is blank. This is really an added row. |
|
| 314 | - $r .= $this->_added( array($final_line), false ); |
|
| 315 | - } elseif ( $final_rows[$row] < 0 ) { // Final is blank. This is really a deleted row. |
|
| 316 | - $r .= $this->_deleted( array($orig_line), false ); |
|
| 313 | + if ($orig_rows[$row] < 0) { // Orig is blank. This is really an added row. |
|
| 314 | + $r .= $this->_added(array($final_line), false); |
|
| 315 | + } elseif ($final_rows[$row] < 0) { // Final is blank. This is really a deleted row. |
|
| 316 | + $r .= $this->_deleted(array($orig_line), false); |
|
| 317 | 317 | } else { // A true changed row. |
| 318 | - if ( $this->_show_split_view ) { |
|
| 319 | - $r .= '<tr>' . $this->deletedLine( $orig_line ) . $this->emptyLine() . $this->addedLine( $final_line ) . "</tr>\n"; |
|
| 318 | + if ($this->_show_split_view) { |
|
| 319 | + $r .= '<tr>'.$this->deletedLine($orig_line).$this->emptyLine().$this->addedLine($final_line)."</tr>\n"; |
|
| 320 | 320 | } else { |
| 321 | - $r .= '<tr>' . $this->deletedLine( $orig_line ) . "</tr><tr>" . $this->addedLine( $final_line ) . "</tr>\n"; |
|
| 321 | + $r .= '<tr>'.$this->deletedLine($orig_line)."</tr><tr>".$this->addedLine($final_line)."</tr>\n"; |
|
| 322 | 322 | } |
| 323 | 323 | } |
| 324 | 324 | } |
@@ -340,13 +340,13 @@ discard block |
||
| 340 | 340 | * @param array $final |
| 341 | 341 | * @return array |
| 342 | 342 | */ |
| 343 | - public function interleave_changed_lines( $orig, $final ) { |
|
| 343 | + public function interleave_changed_lines($orig, $final) { |
|
| 344 | 344 | |
| 345 | 345 | // Contains all pairwise string comparisons. Keys are such that this need only be a one dimensional array. |
| 346 | 346 | $matches = array(); |
| 347 | - foreach ( array_keys($orig) as $o ) { |
|
| 348 | - foreach ( array_keys($final) as $f ) { |
|
| 349 | - $matches["$o,$f"] = $this->compute_string_distance( $orig[$o], $final[$f] ); |
|
| 347 | + foreach (array_keys($orig) as $o) { |
|
| 348 | + foreach (array_keys($final) as $f) { |
|
| 349 | + $matches["$o,$f"] = $this->compute_string_distance($orig[$o], $final[$f]); |
|
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | asort($matches); // Order by string distance. |
@@ -354,28 +354,28 @@ discard block |
||
| 354 | 354 | $orig_matches = array(); |
| 355 | 355 | $final_matches = array(); |
| 356 | 356 | |
| 357 | - foreach ( $matches as $keys => $difference ) { |
|
| 357 | + foreach ($matches as $keys => $difference) { |
|
| 358 | 358 | list($o, $f) = explode(',', $keys); |
| 359 | 359 | $o = (int) $o; |
| 360 | 360 | $f = (int) $f; |
| 361 | 361 | |
| 362 | 362 | // Already have better matches for these guys |
| 363 | - if ( isset($orig_matches[$o]) && isset($final_matches[$f]) ) |
|
| 363 | + if (isset($orig_matches[$o]) && isset($final_matches[$f])) |
|
| 364 | 364 | continue; |
| 365 | 365 | |
| 366 | 366 | // First match for these guys. Must be best match |
| 367 | - if ( !isset($orig_matches[$o]) && !isset($final_matches[$f]) ) { |
|
| 367 | + if ( ! isset($orig_matches[$o]) && ! isset($final_matches[$f])) { |
|
| 368 | 368 | $orig_matches[$o] = $f; |
| 369 | 369 | $final_matches[$f] = $o; |
| 370 | 370 | continue; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | 373 | // Best match of this final is already taken? Must mean this final is a new row. |
| 374 | - if ( isset($orig_matches[$o]) ) |
|
| 374 | + if (isset($orig_matches[$o])) |
|
| 375 | 375 | $final_matches[$f] = 'x'; |
| 376 | 376 | |
| 377 | 377 | // Best match of this orig is already taken? Must mean this orig is a deleted row. |
| 378 | - elseif ( isset($final_matches[$f]) ) |
|
| 378 | + elseif (isset($final_matches[$f])) |
|
| 379 | 379 | $orig_matches[$o] = 'x'; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -389,31 +389,31 @@ discard block |
||
| 389 | 389 | |
| 390 | 390 | // Interleaves rows with blanks to keep matches aligned. |
| 391 | 391 | // We may end up with some extraneous blank rows, but we'll just ignore them later. |
| 392 | - foreach ( $orig_rows_copy as $orig_row ) { |
|
| 392 | + foreach ($orig_rows_copy as $orig_row) { |
|
| 393 | 393 | $final_pos = array_search($orig_matches[$orig_row], $final_rows, true); |
| 394 | 394 | $orig_pos = (int) array_search($orig_row, $orig_rows, true); |
| 395 | 395 | |
| 396 | - if ( false === $final_pos ) { // This orig is paired with a blank final. |
|
| 397 | - array_splice( $final_rows, $orig_pos, 0, -1 ); |
|
| 398 | - } elseif ( $final_pos < $orig_pos ) { // This orig's match is up a ways. Pad final with blank rows. |
|
| 396 | + if (false === $final_pos) { // This orig is paired with a blank final. |
|
| 397 | + array_splice($final_rows, $orig_pos, 0, -1); |
|
| 398 | + } elseif ($final_pos < $orig_pos) { // This orig's match is up a ways. Pad final with blank rows. |
|
| 399 | 399 | $diff_pos = $final_pos - $orig_pos; |
| 400 | - while ( $diff_pos < 0 ) |
|
| 401 | - array_splice( $final_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 402 | - } elseif ( $final_pos > $orig_pos ) { // This orig's match is down a ways. Pad orig with blank rows. |
|
| 400 | + while ($diff_pos < 0) |
|
| 401 | + array_splice($final_rows, $orig_pos, 0, $diff_pos++); |
|
| 402 | + } elseif ($final_pos > $orig_pos) { // This orig's match is down a ways. Pad orig with blank rows. |
|
| 403 | 403 | $diff_pos = $orig_pos - $final_pos; |
| 404 | - while ( $diff_pos < 0 ) |
|
| 405 | - array_splice( $orig_rows, $orig_pos, 0, $diff_pos++ ); |
|
| 404 | + while ($diff_pos < 0) |
|
| 405 | + array_splice($orig_rows, $orig_pos, 0, $diff_pos++); |
|
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | // Pad the ends with blank rows if the columns aren't the same length |
| 410 | 410 | $diff_count = count($orig_rows) - count($final_rows); |
| 411 | - if ( $diff_count < 0 ) { |
|
| 412 | - while ( $diff_count < 0 ) |
|
| 411 | + if ($diff_count < 0) { |
|
| 412 | + while ($diff_count < 0) |
|
| 413 | 413 | array_push($orig_rows, $diff_count++); |
| 414 | - } elseif ( $diff_count > 0 ) { |
|
| 414 | + } elseif ($diff_count > 0) { |
|
| 415 | 415 | $diff_count = -1 * $diff_count; |
| 416 | - while ( $diff_count < 0 ) |
|
| 416 | + while ($diff_count < 0) |
|
| 417 | 417 | array_push($final_rows, $diff_count++); |
| 418 | 418 | } |
| 419 | 419 | |
@@ -429,16 +429,16 @@ discard block |
||
| 429 | 429 | * @param string $string2 |
| 430 | 430 | * @return int |
| 431 | 431 | */ |
| 432 | - public function compute_string_distance( $string1, $string2 ) { |
|
| 432 | + public function compute_string_distance($string1, $string2) { |
|
| 433 | 433 | // Vectors containing character frequency for all chars in each string |
| 434 | 434 | $chars1 = count_chars($string1); |
| 435 | 435 | $chars2 = count_chars($string2); |
| 436 | 436 | |
| 437 | 437 | // L1-norm of difference vector. |
| 438 | - $difference = array_sum( array_map( array($this, 'difference'), $chars1, $chars2 ) ); |
|
| 438 | + $difference = array_sum(array_map(array($this, 'difference'), $chars1, $chars2)); |
|
| 439 | 439 | |
| 440 | 440 | // $string1 has zero length? Odd. Give huge penalty by not dividing. |
| 441 | - if ( !$string1 ) |
|
| 441 | + if ( ! $string1) |
|
| 442 | 442 | return $difference; |
| 443 | 443 | |
| 444 | 444 | // Return distance per character (of string1). |
@@ -453,8 +453,8 @@ discard block |
||
| 453 | 453 | * @param int $b |
| 454 | 454 | * @return int |
| 455 | 455 | */ |
| 456 | - public function difference( $a, $b ) { |
|
| 457 | - return abs( $a - $b ); |
|
| 456 | + public function difference($a, $b) { |
|
| 457 | + return abs($a - $b); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -466,8 +466,8 @@ discard block |
||
| 466 | 466 | * @param string $name Property to get. |
| 467 | 467 | * @return mixed Property. |
| 468 | 468 | */ |
| 469 | - public function __get( $name ) { |
|
| 470 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 469 | + public function __get($name) { |
|
| 470 | + if (in_array($name, $this->compat_fields)) { |
|
| 471 | 471 | return $this->$name; |
| 472 | 472 | } |
| 473 | 473 | } |
@@ -482,8 +482,8 @@ discard block |
||
| 482 | 482 | * @param mixed $value Property value. |
| 483 | 483 | * @return mixed Newly-set property. |
| 484 | 484 | */ |
| 485 | - public function __set( $name, $value ) { |
|
| 486 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 485 | + public function __set($name, $value) { |
|
| 486 | + if (in_array($name, $this->compat_fields)) { |
|
| 487 | 487 | return $this->$name = $value; |
| 488 | 488 | } |
| 489 | 489 | } |
@@ -497,9 +497,9 @@ discard block |
||
| 497 | 497 | * @param string $name Property to check if set. |
| 498 | 498 | * @return bool Whether the property is set. |
| 499 | 499 | */ |
| 500 | - public function __isset( $name ) { |
|
| 501 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 502 | - return isset( $this->$name ); |
|
| 500 | + public function __isset($name) { |
|
| 501 | + if (in_array($name, $this->compat_fields)) { |
|
| 502 | + return isset($this->$name); |
|
| 503 | 503 | } |
| 504 | 504 | } |
| 505 | 505 | |
@@ -511,9 +511,9 @@ discard block |
||
| 511 | 511 | * |
| 512 | 512 | * @param string $name Property to unset. |
| 513 | 513 | */ |
| 514 | - public function __unset( $name ) { |
|
| 515 | - if ( in_array( $name, $this->compat_fields ) ) { |
|
| 516 | - unset( $this->$name ); |
|
| 514 | + public function __unset($name) { |
|
| 515 | + if (in_array($name, $this->compat_fields)) { |
|
| 516 | + unset($this->$name); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | } |
@@ -536,8 +536,8 @@ discard block |
||
| 536 | 536 | */ |
| 537 | 537 | public function _splitOnWords($string, $newlineEscape = "\n") { |
| 538 | 538 | $string = str_replace("\0", '', $string); |
| 539 | - $words = preg_split( '/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE ); |
|
| 540 | - $words = str_replace( "\n", $newlineEscape, $words ); |
|
| 539 | + $words = preg_split('/([^\w])/u', $string, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 540 | + $words = str_replace("\n", $newlineEscape, $words); |
|
| 541 | 541 | return $words; |
| 542 | 542 | } |
| 543 | 543 | |
@@ -169,7 +169,7 @@ |
||
| 169 | 169 | * |
| 170 | 170 | * @param String $processed_line The processed diffed line. |
| 171 | 171 | * @param String $line The unprocessed diffed line. |
| 172 | - * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
|
| 172 | + * @param string null The line context. Values are 'added', 'deleted' or 'unchanged'. |
|
| 173 | 173 | */ |
| 174 | 174 | $line = apply_filters( 'process_text_diff_html', $processed_line, $line, 'added' ); |
| 175 | 175 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | * |
| 21 | 21 | * @since 0.71 |
| 22 | 22 | * |
| 23 | - * @param mixed $error Whether there was an error. |
|
| 23 | + * @param integer $error Whether there was an error. |
|
| 24 | 24 | * Default '0'. Accepts '0' or '1', true or false. |
| 25 | 25 | * @param string $error_message Error message if an error occurred. |
| 26 | 26 | */ |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | if (empty($wp)) { |
| 12 | - require_once( dirname( __FILE__ ) . '/wp-load.php' ); |
|
| 13 | - wp( array( 'tb' => '1' ) ); |
|
| 12 | + require_once(dirname(__FILE__).'/wp-load.php'); |
|
| 13 | + wp(array('tb' => '1')); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @param string $error_message Error message if an error occurred. |
| 26 | 26 | */ |
| 27 | 27 | function trackback_response($error = 0, $error_message = '') { |
| 28 | - header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
|
| 28 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
| 29 | 29 | if ($error) { |
| 30 | 30 | echo '<?xml version="1.0" encoding="utf-8"?'.">\n"; |
| 31 | 31 | echo "<response>\n"; |
@@ -44,30 +44,30 @@ discard block |
||
| 44 | 44 | // Trackback is done by a POST. |
| 45 | 45 | $request_array = 'HTTP_POST_VARS'; |
| 46 | 46 | |
| 47 | -if ( !isset($_GET['tb_id']) || !$_GET['tb_id'] ) { |
|
| 47 | +if ( ! isset($_GET['tb_id']) || ! $_GET['tb_id']) { |
|
| 48 | 48 | $tb_id = explode('/', $_SERVER['REQUEST_URI']); |
| 49 | - $tb_id = intval( $tb_id[ count($tb_id) - 1 ] ); |
|
| 49 | + $tb_id = intval($tb_id[count($tb_id) - 1]); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | -$tb_url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
| 52 | +$tb_url = isset($_POST['url']) ? $_POST['url'] : ''; |
|
| 53 | 53 | $charset = isset($_POST['charset']) ? $_POST['charset'] : ''; |
| 54 | 54 | |
| 55 | 55 | // These three are stripslashed here so they can be properly escaped after mb_convert_encoding(). |
| 56 | -$title = isset($_POST['title']) ? wp_unslash($_POST['title']) : ''; |
|
| 57 | -$excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
|
| 58 | -$blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
|
| 56 | +$title = isset($_POST['title']) ? wp_unslash($_POST['title']) : ''; |
|
| 57 | +$excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
|
| 58 | +$blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
|
| 59 | 59 | |
| 60 | 60 | if ($charset) |
| 61 | - $charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) ); |
|
| 61 | + $charset = str_replace(array(',', ' '), '', strtoupper(trim($charset))); |
|
| 62 | 62 | else |
| 63 | 63 | $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS'; |
| 64 | 64 | |
| 65 | 65 | // No valid uses for UTF-7. |
| 66 | -if ( false !== strpos($charset, 'UTF-7') ) |
|
| 66 | +if (false !== strpos($charset, 'UTF-7')) |
|
| 67 | 67 | die; |
| 68 | 68 | |
| 69 | 69 | // For international trackbacks. |
| 70 | -if ( function_exists('mb_convert_encoding') ) { |
|
| 70 | +if (function_exists('mb_convert_encoding')) { |
|
| 71 | 71 | $title = mb_convert_encoding($title, get_option('blog_charset'), $charset); |
| 72 | 72 | $excerpt = mb_convert_encoding($excerpt, get_option('blog_charset'), $charset); |
| 73 | 73 | $blog_name = mb_convert_encoding($blog_name, get_option('blog_charset'), $charset); |
@@ -78,10 +78,10 @@ discard block |
||
| 78 | 78 | $excerpt = wp_slash($excerpt); |
| 79 | 79 | $blog_name = wp_slash($blog_name); |
| 80 | 80 | |
| 81 | -if ( is_single() || is_page() ) |
|
| 81 | +if (is_single() || is_page()) |
|
| 82 | 82 | $tb_id = $posts[0]->ID; |
| 83 | 83 | |
| 84 | -if ( !isset($tb_id) || !intval( $tb_id ) ) |
|
| 84 | +if ( ! isset($tb_id) || ! intval($tb_id)) |
|
| 85 | 85 | trackback_response(1, 'I really need an ID for this to work.'); |
| 86 | 86 | |
| 87 | 87 | if (empty($title) && empty($tb_url) && empty($blog_name)) { |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | exit; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | -if ( !empty($tb_url) && !empty($title) ) { |
|
| 94 | - header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
|
| 93 | +if ( ! empty($tb_url) && ! empty($title)) { |
|
| 94 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
| 95 | 95 | |
| 96 | - if ( !pings_open($tb_id) ) |
|
| 96 | + if ( ! pings_open($tb_id)) |
|
| 97 | 97 | trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
| 98 | 98 | |
| 99 | - $title = wp_html_excerpt( $title, 250, '…' ); |
|
| 100 | - $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
|
| 99 | + $title = wp_html_excerpt($title, 250, '…'); |
|
| 100 | + $excerpt = wp_html_excerpt($excerpt, 252, '…'); |
|
| 101 | 101 | |
| 102 | 102 | $comment_post_ID = (int) $tb_id; |
| 103 | 103 | $comment_author = $blog_name; |
@@ -106,8 +106,8 @@ discard block |
||
| 106 | 106 | $comment_content = "<strong>$title</strong>\n\n$excerpt"; |
| 107 | 107 | $comment_type = 'trackback'; |
| 108 | 108 | |
| 109 | - $dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) ); |
|
| 110 | - if ( $dupe ) |
|
| 109 | + $dupe = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url)); |
|
| 110 | + if ($dupe) |
|
| 111 | 111 | trackback_response(1, 'We already have a ping from that URL for this post.'); |
| 112 | 112 | |
| 113 | 113 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
@@ -122,6 +122,6 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @param int $trackback_id Trackback ID. |
| 124 | 124 | */ |
| 125 | - do_action( 'trackback_post', $trackback_id ); |
|
| 126 | - trackback_response( 0 ); |
|
| 125 | + do_action('trackback_post', $trackback_id); |
|
| 126 | + trackback_response(0); |
|
| 127 | 127 | } |
@@ -57,14 +57,16 @@ discard block |
||
| 57 | 57 | $excerpt = isset($_POST['excerpt']) ? wp_unslash($_POST['excerpt']) : ''; |
| 58 | 58 | $blog_name = isset($_POST['blog_name']) ? wp_unslash($_POST['blog_name']) : ''; |
| 59 | 59 | |
| 60 | -if ($charset) |
|
| 60 | +if ($charset) { |
|
| 61 | 61 | $charset = str_replace( array(',', ' '), '', strtoupper( trim($charset) ) ); |
| 62 | -else |
|
| 62 | +} else { |
|
| 63 | 63 | $charset = 'ASCII, UTF-8, ISO-8859-1, JIS, EUC-JP, SJIS'; |
| 64 | +} |
|
| 64 | 65 | |
| 65 | 66 | // No valid uses for UTF-7. |
| 66 | -if ( false !== strpos($charset, 'UTF-7') ) |
|
| 67 | +if ( false !== strpos($charset, 'UTF-7') ) { |
|
| 67 | 68 | die; |
| 69 | +} |
|
| 68 | 70 | |
| 69 | 71 | // For international trackbacks. |
| 70 | 72 | if ( function_exists('mb_convert_encoding') ) { |
@@ -78,11 +80,13 @@ discard block |
||
| 78 | 80 | $excerpt = wp_slash($excerpt); |
| 79 | 81 | $blog_name = wp_slash($blog_name); |
| 80 | 82 | |
| 81 | -if ( is_single() || is_page() ) |
|
| 83 | +if ( is_single() || is_page() ) { |
|
| 82 | 84 | $tb_id = $posts[0]->ID; |
| 85 | +} |
|
| 83 | 86 | |
| 84 | -if ( !isset($tb_id) || !intval( $tb_id ) ) |
|
| 87 | +if ( !isset($tb_id) || !intval( $tb_id ) ) { |
|
| 85 | 88 | trackback_response(1, 'I really need an ID for this to work.'); |
| 89 | +} |
|
| 86 | 90 | |
| 87 | 91 | if (empty($title) && empty($tb_url) && empty($blog_name)) { |
| 88 | 92 | // If it doesn't look like a trackback at all. |
@@ -93,8 +97,9 @@ discard block |
||
| 93 | 97 | if ( !empty($tb_url) && !empty($title) ) { |
| 94 | 98 | header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
| 95 | 99 | |
| 96 | - if ( !pings_open($tb_id) ) |
|
| 97 | - trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
|
| 100 | + if ( !pings_open($tb_id) ) { |
|
| 101 | + trackback_response(1, 'Sorry, trackbacks are closed for this item.'); |
|
| 102 | + } |
|
| 98 | 103 | |
| 99 | 104 | $title = wp_html_excerpt( $title, 250, '…' ); |
| 100 | 105 | $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
@@ -107,8 +112,9 @@ discard block |
||
| 107 | 112 | $comment_type = 'trackback'; |
| 108 | 113 | |
| 109 | 114 | $dupe = $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $comment_post_ID, $comment_author_url) ); |
| 110 | - if ( $dupe ) |
|
| 111 | - trackback_response(1, 'We already have a ping from that URL for this post.'); |
|
| 115 | + if ( $dupe ) { |
|
| 116 | + trackback_response(1, 'We already have a ping from that URL for this post.'); |
|
| 117 | + } |
|
| 112 | 118 | |
| 113 | 119 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
| 114 | 120 | |
@@ -40,11 +40,17 @@ discard block |
||
| 40 | 40 | return $translations; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | + /** |
|
| 44 | + * @param string $prefix |
|
| 45 | + */ |
|
| 43 | 46 | function extract_from_file( $file_name, $prefix ) { |
| 44 | 47 | $code = file_get_contents( $file_name ); |
| 45 | 48 | return $this->extract_from_code( $code, $prefix . $file_name ); |
| 46 | 49 | } |
| 47 | 50 | |
| 51 | + /** |
|
| 52 | + * @param string $path |
|
| 53 | + */ |
|
| 48 | 54 | function does_file_name_match( $path, $excludes, $includes ) { |
| 49 | 55 | if ( $includes ) { |
| 50 | 56 | $matched_any_include = false; |
@@ -128,6 +134,10 @@ discard block |
||
| 128 | 134 | return $entry; |
| 129 | 135 | } |
| 130 | 136 | |
| 137 | + /** |
|
| 138 | + * @param string $code |
|
| 139 | + * @param string $file_name |
|
| 140 | + */ |
|
| 131 | 141 | function extract_from_code( $code, $file_name ) { |
| 132 | 142 | $translations = new Translations; |
| 133 | 143 | $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
@@ -75,35 +75,35 @@ |
||
| 75 | 75 | for( $i = 0; $i < count( $rule ); ++$i ) { |
| 76 | 76 | if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
| 77 | 77 | switch( $rule[$i] ) { |
| 78 | - case 'string': |
|
| 79 | - if ( $complete ) { |
|
| 80 | - $multiple[] = $entry; |
|
| 81 | - $entry = new Translation_Entry; |
|
| 82 | - $complete = false; |
|
| 83 | - } |
|
| 84 | - $entry->singular = $call['args'][$i]; |
|
| 85 | - $complete = true; |
|
| 86 | - break; |
|
| 87 | - case 'singular': |
|
| 88 | - if ( $complete ) { |
|
| 89 | - $multiple[] = $entry; |
|
| 90 | - $entry = new Translation_Entry; |
|
| 91 | - $complete = false; |
|
| 92 | - } |
|
| 93 | - $entry->singular = $call['args'][$i]; |
|
| 94 | - $entry->is_plural = true; |
|
| 95 | - break; |
|
| 96 | - case 'plural': |
|
| 97 | - $entry->plural = $call['args'][$i]; |
|
| 98 | - $entry->is_plural = true; |
|
| 99 | - $complete = true; |
|
| 100 | - break; |
|
| 101 | - case 'context': |
|
| 102 | - $entry->context = $call['args'][$i]; |
|
| 103 | - foreach( $multiple as &$single_entry ) { |
|
| 104 | - $single_entry->context = $entry->context; |
|
| 105 | - } |
|
| 106 | - break; |
|
| 78 | + case 'string': |
|
| 79 | + if ( $complete ) { |
|
| 80 | + $multiple[] = $entry; |
|
| 81 | + $entry = new Translation_Entry; |
|
| 82 | + $complete = false; |
|
| 83 | + } |
|
| 84 | + $entry->singular = $call['args'][$i]; |
|
| 85 | + $complete = true; |
|
| 86 | + break; |
|
| 87 | + case 'singular': |
|
| 88 | + if ( $complete ) { |
|
| 89 | + $multiple[] = $entry; |
|
| 90 | + $entry = new Translation_Entry; |
|
| 91 | + $complete = false; |
|
| 92 | + } |
|
| 93 | + $entry->singular = $call['args'][$i]; |
|
| 94 | + $entry->is_plural = true; |
|
| 95 | + break; |
|
| 96 | + case 'plural': |
|
| 97 | + $entry->plural = $call['args'][$i]; |
|
| 98 | + $entry->is_plural = true; |
|
| 99 | + $complete = true; |
|
| 100 | + break; |
|
| 101 | + case 'context': |
|
| 102 | + $entry->context = $call['args'][$i]; |
|
| 103 | + foreach( $multiple as &$single_entry ) { |
|
| 104 | + $single_entry->context = $entry->context; |
|
| 105 | + } |
|
| 106 | + break; |
|
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | if ( isset( $call['line'] ) && $call['line'] ) { |
@@ -26,7 +26,9 @@ discard block |
||
| 26 | 26 | $translations = new Translations; |
| 27 | 27 | $file_names = (array) scandir( '.' ); |
| 28 | 28 | foreach ( $file_names as $file_name ) { |
| 29 | - if ( '.' == $file_name || '..' == $file_name ) continue; |
|
| 29 | + if ( '.' == $file_name || '..' == $file_name ) { |
|
| 30 | + continue; |
|
| 31 | + } |
|
| 30 | 32 | if ( preg_match( '/\.php$/', $file_name ) && $this->does_file_name_match( $prefix . $file_name, $excludes, $includes ) ) { |
| 31 | 33 | $extracted = $this->extract_from_file( $file_name, $prefix ); |
| 32 | 34 | $translations->merge_originals_with( $extracted ); |
@@ -54,7 +56,9 @@ discard block |
||
| 54 | 56 | break; |
| 55 | 57 | } |
| 56 | 58 | } |
| 57 | - if ( !$matched_any_include ) return false; |
|
| 59 | + if ( !$matched_any_include ) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 58 | 62 | } |
| 59 | 63 | if ( $excludes ) { |
| 60 | 64 | foreach( $excludes as $exclude ) { |
@@ -68,12 +72,16 @@ discard block |
||
| 68 | 72 | |
| 69 | 73 | function entry_from_call( $call, $file_name ) { |
| 70 | 74 | $rule = isset( $this->rules[$call['name']] )? $this->rules[$call['name']] : null; |
| 71 | - if ( !$rule ) return null; |
|
| 75 | + if ( !$rule ) { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 72 | 78 | $entry = new Translation_Entry; |
| 73 | 79 | $multiple = array(); |
| 74 | 80 | $complete = false; |
| 75 | 81 | for( $i = 0; $i < count( $rule ); ++$i ) { |
| 76 | - if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
|
| 82 | + if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) { |
|
| 83 | + return false; |
|
| 84 | + } |
|
| 77 | 85 | switch( $rule[$i] ) { |
| 78 | 86 | case 'string': |
| 79 | 87 | if ( $complete ) { |
@@ -133,11 +141,12 @@ discard block |
||
| 133 | 141 | $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
| 134 | 142 | foreach( $function_calls as $call ) { |
| 135 | 143 | $entry = $this->entry_from_call( $call, $file_name ); |
| 136 | - if ( is_array( $entry ) ) |
|
| 137 | - foreach( $entry as $single_entry ) |
|
| 144 | + if ( is_array( $entry ) ) { |
|
| 145 | + foreach( $entry as $single_entry ) |
|
| 138 | 146 | $translations->add_entry_or_merge( $single_entry ); |
| 139 | - elseif ( $entry) |
|
| 140 | - $translations->add_entry_or_merge( $entry ); |
|
| 147 | + } elseif ( $entry) { |
|
| 148 | + $translations->add_entry_or_merge( $entry ); |
|
| 149 | + } |
|
| 141 | 150 | } |
| 142 | 151 | return $translations; |
| 143 | 152 | } |
@@ -155,8 +164,12 @@ discard block |
||
| 155 | 164 | $in_func = false; |
| 156 | 165 | foreach( $tokens as $token ) { |
| 157 | 166 | $id = $text = null; |
| 158 | - if ( is_array( $token ) ) list( $id, $text, $line ) = $token; |
|
| 159 | - if ( T_WHITESPACE == $id ) continue; |
|
| 167 | + if ( is_array( $token ) ) { |
|
| 168 | + list( $id, $text, $line ) = $token; |
|
| 169 | + } |
|
| 170 | + if ( T_WHITESPACE == $id ) { |
|
| 171 | + continue; |
|
| 172 | + } |
|
| 160 | 173 | if ( T_STRING == $id && in_array( $text, $function_names ) && !$in_func ) { |
| 161 | 174 | $in_func = true; |
| 162 | 175 | $paren_level = -1; |
@@ -177,7 +190,9 @@ discard block |
||
| 177 | 190 | $latest_comment = $text; |
| 178 | 191 | } |
| 179 | 192 | } |
| 180 | - if ( !$in_func ) continue; |
|
| 193 | + if ( !$in_func ) { |
|
| 194 | + continue; |
|
| 195 | + } |
|
| 181 | 196 | if ( '(' == $token ) { |
| 182 | 197 | $paren_level++; |
| 183 | 198 | if ( 0 == $paren_level ) { // start of first argument |
@@ -197,7 +212,9 @@ discard block |
||
| 197 | 212 | $in_func = false; |
| 198 | 213 | $args[] = $current_argument; |
| 199 | 214 | $call = array( 'name' => $func_name, 'args' => $args, 'line' => $func_line ); |
| 200 | - if ( $func_comment ) $call['comment'] = $func_comment; |
|
| 215 | + if ( $func_comment ) { |
|
| 216 | + $call['comment'] = $func_comment; |
|
| 217 | + } |
|
| 201 | 218 | $function_calls[] = $call; |
| 202 | 219 | } |
| 203 | 220 | $paren_level--; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | -$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
|
| 2 | +$pomo = dirname(dirname(dirname(__FILE__))).'/src/wp-includes/pomo'; |
|
| 3 | 3 | require_once "$pomo/entry.php"; |
| 4 | 4 | require_once "$pomo/translations.php"; |
| 5 | 5 | |
@@ -10,55 +10,55 @@ discard block |
||
| 10 | 10 | class StringExtractor { |
| 11 | 11 | |
| 12 | 12 | var $rules = array( |
| 13 | - '__' => array( 'string' ), |
|
| 14 | - '_e' => array( 'string' ), |
|
| 15 | - '_n' => array( 'singular', 'plural' ), |
|
| 13 | + '__' => array('string'), |
|
| 14 | + '_e' => array('string'), |
|
| 15 | + '_n' => array('singular', 'plural'), |
|
| 16 | 16 | ); |
| 17 | 17 | var $comment_prefix = 'translators:'; |
| 18 | 18 | |
| 19 | - function __construct( $rules = array() ) { |
|
| 19 | + function __construct($rules = array()) { |
|
| 20 | 20 | $this->rules = $rules; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - function extract_from_directory( $dir, $excludes = array(), $includes = array(), $prefix = '' ) { |
|
| 23 | + function extract_from_directory($dir, $excludes = array(), $includes = array(), $prefix = '') { |
|
| 24 | 24 | $old_cwd = getcwd(); |
| 25 | - chdir( $dir ); |
|
| 25 | + chdir($dir); |
|
| 26 | 26 | $translations = new Translations; |
| 27 | - $file_names = (array) scandir( '.' ); |
|
| 28 | - foreach ( $file_names as $file_name ) { |
|
| 29 | - if ( '.' == $file_name || '..' == $file_name ) continue; |
|
| 30 | - if ( preg_match( '/\.php$/', $file_name ) && $this->does_file_name_match( $prefix . $file_name, $excludes, $includes ) ) { |
|
| 31 | - $extracted = $this->extract_from_file( $file_name, $prefix ); |
|
| 32 | - $translations->merge_originals_with( $extracted ); |
|
| 27 | + $file_names = (array) scandir('.'); |
|
| 28 | + foreach ($file_names as $file_name) { |
|
| 29 | + if ('.' == $file_name || '..' == $file_name) continue; |
|
| 30 | + if (preg_match('/\.php$/', $file_name) && $this->does_file_name_match($prefix.$file_name, $excludes, $includes)) { |
|
| 31 | + $extracted = $this->extract_from_file($file_name, $prefix); |
|
| 32 | + $translations->merge_originals_with($extracted); |
|
| 33 | 33 | } |
| 34 | - if ( is_dir( $file_name ) ) { |
|
| 35 | - $extracted = $this->extract_from_directory( $file_name, $excludes, $includes, $prefix . $file_name . '/' ); |
|
| 36 | - $translations->merge_originals_with( $extracted ); |
|
| 34 | + if (is_dir($file_name)) { |
|
| 35 | + $extracted = $this->extract_from_directory($file_name, $excludes, $includes, $prefix.$file_name.'/'); |
|
| 36 | + $translations->merge_originals_with($extracted); |
|
| 37 | 37 | } |
| 38 | 38 | } |
| 39 | - chdir( $old_cwd ); |
|
| 39 | + chdir($old_cwd); |
|
| 40 | 40 | return $translations; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - function extract_from_file( $file_name, $prefix ) { |
|
| 44 | - $code = file_get_contents( $file_name ); |
|
| 45 | - return $this->extract_from_code( $code, $prefix . $file_name ); |
|
| 43 | + function extract_from_file($file_name, $prefix) { |
|
| 44 | + $code = file_get_contents($file_name); |
|
| 45 | + return $this->extract_from_code($code, $prefix.$file_name); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - function does_file_name_match( $path, $excludes, $includes ) { |
|
| 49 | - if ( $includes ) { |
|
| 48 | + function does_file_name_match($path, $excludes, $includes) { |
|
| 49 | + if ($includes) { |
|
| 50 | 50 | $matched_any_include = false; |
| 51 | - foreach( $includes as $include ) { |
|
| 52 | - if ( preg_match( '|^'.$include.'$|', $path ) ) { |
|
| 51 | + foreach ($includes as $include) { |
|
| 52 | + if (preg_match('|^'.$include.'$|', $path)) { |
|
| 53 | 53 | $matched_any_include = true; |
| 54 | 54 | break; |
| 55 | 55 | } |
| 56 | 56 | } |
| 57 | - if ( !$matched_any_include ) return false; |
|
| 57 | + if ( ! $matched_any_include) return false; |
|
| 58 | 58 | } |
| 59 | - if ( $excludes ) { |
|
| 60 | - foreach( $excludes as $exclude ) { |
|
| 61 | - if ( preg_match( '|^'.$exclude.'$|', $path ) ) { |
|
| 59 | + if ($excludes) { |
|
| 60 | + foreach ($excludes as $exclude) { |
|
| 61 | + if (preg_match('|^'.$exclude.'$|', $path)) { |
|
| 62 | 62 | return false; |
| 63 | 63 | } |
| 64 | 64 | } |
@@ -66,17 +66,17 @@ discard block |
||
| 66 | 66 | return true; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - function entry_from_call( $call, $file_name ) { |
|
| 70 | - $rule = isset( $this->rules[$call['name']] )? $this->rules[$call['name']] : null; |
|
| 71 | - if ( !$rule ) return null; |
|
| 69 | + function entry_from_call($call, $file_name) { |
|
| 70 | + $rule = isset($this->rules[$call['name']]) ? $this->rules[$call['name']] : null; |
|
| 71 | + if ( ! $rule) return null; |
|
| 72 | 72 | $entry = new Translation_Entry; |
| 73 | 73 | $multiple = array(); |
| 74 | 74 | $complete = false; |
| 75 | - for( $i = 0; $i < count( $rule ); ++$i ) { |
|
| 76 | - if ( $rule[$i] && ( !isset( $call['args'][$i] ) || !is_string( $call['args'][$i] ) || '' == $call['args'][$i] ) ) return false; |
|
| 77 | - switch( $rule[$i] ) { |
|
| 75 | + for ($i = 0; $i < count($rule); ++$i) { |
|
| 76 | + if ($rule[$i] && ( ! isset($call['args'][$i]) || ! is_string($call['args'][$i]) || '' == $call['args'][$i])) return false; |
|
| 77 | + switch ($rule[$i]) { |
|
| 78 | 78 | case 'string': |
| 79 | - if ( $complete ) { |
|
| 79 | + if ($complete) { |
|
| 80 | 80 | $multiple[] = $entry; |
| 81 | 81 | $entry = new Translation_Entry; |
| 82 | 82 | $complete = false; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $complete = true; |
| 86 | 86 | break; |
| 87 | 87 | case 'singular': |
| 88 | - if ( $complete ) { |
|
| 88 | + if ($complete) { |
|
| 89 | 89 | $multiple[] = $entry; |
| 90 | 90 | $entry = new Translation_Entry; |
| 91 | 91 | $complete = false; |
@@ -100,27 +100,27 @@ discard block |
||
| 100 | 100 | break; |
| 101 | 101 | case 'context': |
| 102 | 102 | $entry->context = $call['args'][$i]; |
| 103 | - foreach( $multiple as &$single_entry ) { |
|
| 103 | + foreach ($multiple as &$single_entry) { |
|
| 104 | 104 | $single_entry->context = $entry->context; |
| 105 | 105 | } |
| 106 | 106 | break; |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | - if ( isset( $call['line'] ) && $call['line'] ) { |
|
| 110 | - $references = array( $file_name . ':' . $call['line'] ); |
|
| 109 | + if (isset($call['line']) && $call['line']) { |
|
| 110 | + $references = array($file_name.':'.$call['line']); |
|
| 111 | 111 | $entry->references = $references; |
| 112 | - foreach( $multiple as &$single_entry ) { |
|
| 112 | + foreach ($multiple as &$single_entry) { |
|
| 113 | 113 | $single_entry->references = $references; |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - if ( isset( $call['comment'] ) && $call['comment'] ) { |
|
| 117 | - $comments = rtrim( $call['comment'] ) . "\n"; |
|
| 116 | + if (isset($call['comment']) && $call['comment']) { |
|
| 117 | + $comments = rtrim($call['comment'])."\n"; |
|
| 118 | 118 | $entry->extracted_comments = $comments; |
| 119 | - foreach( $multiple as &$single_entry ) { |
|
| 119 | + foreach ($multiple as &$single_entry) { |
|
| 120 | 120 | $single_entry->extracted_comments = $comments; |
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - if ( $multiple && $entry ) { |
|
| 123 | + if ($multiple && $entry) { |
|
| 124 | 124 | $multiple[] = $entry; |
| 125 | 125 | return $multiple; |
| 126 | 126 | } |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | return $entry; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - function extract_from_code( $code, $file_name ) { |
|
| 131 | + function extract_from_code($code, $file_name) { |
|
| 132 | 132 | $translations = new Translations; |
| 133 | - $function_calls = $this->find_function_calls( array_keys( $this->rules ), $code ); |
|
| 134 | - foreach( $function_calls as $call ) { |
|
| 135 | - $entry = $this->entry_from_call( $call, $file_name ); |
|
| 136 | - if ( is_array( $entry ) ) |
|
| 137 | - foreach( $entry as $single_entry ) |
|
| 138 | - $translations->add_entry_or_merge( $single_entry ); |
|
| 139 | - elseif ( $entry) |
|
| 140 | - $translations->add_entry_or_merge( $entry ); |
|
| 133 | + $function_calls = $this->find_function_calls(array_keys($this->rules), $code); |
|
| 134 | + foreach ($function_calls as $call) { |
|
| 135 | + $entry = $this->entry_from_call($call, $file_name); |
|
| 136 | + if (is_array($entry)) |
|
| 137 | + foreach ($entry as $single_entry) |
|
| 138 | + $translations->add_entry_or_merge($single_entry); |
|
| 139 | + elseif ($entry) |
|
| 140 | + $translations->add_entry_or_merge($entry); |
|
| 141 | 141 | } |
| 142 | 142 | return $translations; |
| 143 | 143 | } |
@@ -148,70 +148,70 @@ discard block |
||
| 148 | 148 | * - args - array for the function arguments. Each string literal is represented by itself, other arguments are represented by null. |
| 149 | 149 | * - line - line number |
| 150 | 150 | */ |
| 151 | - function find_function_calls( $function_names, $code ) { |
|
| 152 | - $tokens = token_get_all( $code ); |
|
| 151 | + function find_function_calls($function_names, $code) { |
|
| 152 | + $tokens = token_get_all($code); |
|
| 153 | 153 | $function_calls = array(); |
| 154 | 154 | $latest_comment = false; |
| 155 | 155 | $in_func = false; |
| 156 | - foreach( $tokens as $token ) { |
|
| 156 | + foreach ($tokens as $token) { |
|
| 157 | 157 | $id = $text = null; |
| 158 | - if ( is_array( $token ) ) list( $id, $text, $line ) = $token; |
|
| 159 | - if ( T_WHITESPACE == $id ) continue; |
|
| 160 | - if ( T_STRING == $id && in_array( $text, $function_names ) && !$in_func ) { |
|
| 158 | + if (is_array($token)) list($id, $text, $line) = $token; |
|
| 159 | + if (T_WHITESPACE == $id) continue; |
|
| 160 | + if (T_STRING == $id && in_array($text, $function_names) && ! $in_func) { |
|
| 161 | 161 | $in_func = true; |
| 162 | 162 | $paren_level = -1; |
| 163 | 163 | $args = array(); |
| 164 | 164 | $func_name = $text; |
| 165 | 165 | $func_line = $line; |
| 166 | - $func_comment = $latest_comment? $latest_comment : ''; |
|
| 166 | + $func_comment = $latest_comment ? $latest_comment : ''; |
|
| 167 | 167 | |
| 168 | 168 | $just_got_into_func = true; |
| 169 | 169 | $latest_comment = false; |
| 170 | 170 | continue; |
| 171 | 171 | } |
| 172 | - if ( T_COMMENT == $id ) { |
|
| 173 | - $text = preg_replace( '%^\s+\*\s%m', '', $text ); |
|
| 174 | - $text = str_replace( array( "\r\n", "\n" ), ' ', $text );; |
|
| 175 | - $text = trim( preg_replace( '%^(/\*|//)%', '', preg_replace( '%\*/$%', '', $text ) ) ); |
|
| 176 | - if ( 0 === stripos( $text, $this->comment_prefix ) ) { |
|
| 172 | + if (T_COMMENT == $id) { |
|
| 173 | + $text = preg_replace('%^\s+\*\s%m', '', $text); |
|
| 174 | + $text = str_replace(array("\r\n", "\n"), ' ', $text); ; |
|
| 175 | + $text = trim(preg_replace('%^(/\*|//)%', '', preg_replace('%\*/$%', '', $text))); |
|
| 176 | + if (0 === stripos($text, $this->comment_prefix)) { |
|
| 177 | 177 | $latest_comment = $text; |
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | - if ( !$in_func ) continue; |
|
| 181 | - if ( '(' == $token ) { |
|
| 180 | + if ( ! $in_func) continue; |
|
| 181 | + if ('(' == $token) { |
|
| 182 | 182 | $paren_level++; |
| 183 | - if ( 0 == $paren_level ) { // start of first argument |
|
| 183 | + if (0 == $paren_level) { // start of first argument |
|
| 184 | 184 | $just_got_into_func = false; |
| 185 | 185 | $current_argument = null; |
| 186 | 186 | $current_argument_is_just_literal = true; |
| 187 | 187 | } |
| 188 | 188 | continue; |
| 189 | 189 | } |
| 190 | - if ( $just_got_into_func ) { |
|
| 190 | + if ($just_got_into_func) { |
|
| 191 | 191 | // there wasn't a opening paren just after the function name -- this means it is not a function |
| 192 | 192 | $in_func = false; |
| 193 | 193 | $just_got_into_func = false; |
| 194 | 194 | } |
| 195 | - if ( ')' == $token ) { |
|
| 196 | - if ( 0 == $paren_level ) { |
|
| 195 | + if (')' == $token) { |
|
| 196 | + if (0 == $paren_level) { |
|
| 197 | 197 | $in_func = false; |
| 198 | 198 | $args[] = $current_argument; |
| 199 | - $call = array( 'name' => $func_name, 'args' => $args, 'line' => $func_line ); |
|
| 200 | - if ( $func_comment ) $call['comment'] = $func_comment; |
|
| 199 | + $call = array('name' => $func_name, 'args' => $args, 'line' => $func_line); |
|
| 200 | + if ($func_comment) $call['comment'] = $func_comment; |
|
| 201 | 201 | $function_calls[] = $call; |
| 202 | 202 | } |
| 203 | 203 | $paren_level--; |
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | - if ( ',' == $token && 0 == $paren_level ) { |
|
| 206 | + if (',' == $token && 0 == $paren_level) { |
|
| 207 | 207 | $args[] = $current_argument; |
| 208 | 208 | $current_argument = null; |
| 209 | 209 | $current_argument_is_just_literal = true; |
| 210 | 210 | continue; |
| 211 | 211 | } |
| 212 | - if ( T_CONSTANT_ENCAPSED_STRING == $id && $current_argument_is_just_literal ) { |
|
| 212 | + if (T_CONSTANT_ENCAPSED_STRING == $id && $current_argument_is_just_literal) { |
|
| 213 | 213 | // we can use eval safely, because we are sure $text is just a string literal |
| 214 | - eval('$current_argument = '.$text.';' ); |
|
| 214 | + eval('$current_argument = '.$text.';'); |
|
| 215 | 215 | continue; |
| 216 | 216 | } |
| 217 | 217 | $current_argument_is_just_literal = false; |
@@ -51,6 +51,9 @@ discard block |
||
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $dir |
|
| 56 | + */ |
|
| 54 | 57 | function list_php_files($dir) { |
| 55 | 58 | $files = array(); |
| 56 | 59 | $items = scandir( $dir ); |
@@ -67,16 +70,25 @@ discard block |
||
| 67 | 70 | } |
| 68 | 71 | |
| 69 | 72 | |
| 73 | + /** |
|
| 74 | + * @param string $global_array_name |
|
| 75 | + */ |
|
| 70 | 76 | function make_string_aggregator($global_array_name, $filename) { |
| 71 | 77 | $a = $global_array_name; |
| 72 | 78 | return create_function('$string, $comment_id, $line_number', 'global $'.$a.'; $'.$a.'[] = array($string, $comment_id, '.var_export($filename, true).', $line_number);'); |
| 73 | 79 | } |
| 74 | 80 | |
| 81 | + /** |
|
| 82 | + * @param string $global_mo_name |
|
| 83 | + */ |
|
| 75 | 84 | function make_mo_replacer($global_mo_name) { |
| 76 | 85 | $m = $global_mo_name; |
| 77 | 86 | return create_function('$token, $string', 'global $'.$m.'; return var_export($'.$m.'->translate($string), true);'); |
| 78 | 87 | } |
| 79 | 88 | |
| 89 | + /** |
|
| 90 | + * @param string $register_action |
|
| 91 | + */ |
|
| 80 | 92 | function walk_tokens(&$tokens, $string_action, $other_action, $register_action=null) { |
| 81 | 93 | |
| 82 | 94 | $current_comment_id = ''; |
@@ -8,9 +8,9 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | 10 | if ( ! defined( 'T_ML_COMMENT' ) ) |
| 11 | - define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 11 | + define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 12 | 12 | else |
| 13 | - define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 13 | + define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 14 | 14 | |
| 15 | 15 | $pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
| 16 | 16 | require_once "$pomo/po.php"; |
@@ -7,12 +7,12 @@ discard block |
||
| 7 | 7 | * @subpackage tools |
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | -if ( ! defined( 'T_ML_COMMENT' ) ) |
|
| 11 | - define( 'T_ML_COMMENT', T_COMMENT ); |
|
| 10 | +if ( ! defined('T_ML_COMMENT')) |
|
| 11 | + define('T_ML_COMMENT', T_COMMENT); |
|
| 12 | 12 | else |
| 13 | - define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
|
| 13 | + define('T_DOC_COMMENT', T_ML_COMMENT); |
|
| 14 | 14 | |
| 15 | -$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
|
| 15 | +$pomo = dirname(dirname(dirname(__FILE__))).'/src/wp-includes/pomo'; |
|
| 16 | 16 | require_once "$pomo/po.php"; |
| 17 | 17 | require_once "$pomo/mo.php"; |
| 18 | 18 | |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | var $STAGE_WHITESPACE_AFTER = 4; |
| 27 | 27 | var $STAGE_END_COMMENT = 4; |
| 28 | 28 | |
| 29 | - var $commands = array('extract' => 'command_extract', 'replace' => 'command_replace' ); |
|
| 29 | + var $commands = array('extract' => 'command_extract', 'replace' => 'command_replace'); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | 32 | function logmsg() { |
@@ -34,8 +34,8 @@ discard block |
||
| 34 | 34 | if ($this->enable_logging) error_log(implode(' ', $args)); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - function stderr($msg, $nl=true) { |
|
| 38 | - fwrite(STDERR, $msg.($nl? "\n" : "")); |
|
| 37 | + function stderr($msg, $nl = true) { |
|
| 38 | + fwrite(STDERR, $msg.($nl ? "\n" : "")); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | function cli_die($msg) { |
@@ -43,19 +43,19 @@ discard block |
||
| 43 | 43 | exit(1); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - function unchanged_token($token, $s='') { |
|
| 47 | - return is_array($token)? $token[1] : $token; |
|
| 46 | + function unchanged_token($token, $s = '') { |
|
| 47 | + return is_array($token) ? $token[1] : $token; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - function ignore_token($token, $s='') { |
|
| 50 | + function ignore_token($token, $s = '') { |
|
| 51 | 51 | return ''; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | function list_php_files($dir) { |
| 55 | 55 | $files = array(); |
| 56 | - $items = scandir( $dir ); |
|
| 57 | - foreach ( (array) $items as $item ) { |
|
| 58 | - $full_item = $dir . '/' . $item; |
|
| 56 | + $items = scandir($dir); |
|
| 57 | + foreach ((array) $items as $item) { |
|
| 58 | + $full_item = $dir.'/'.$item; |
|
| 59 | 59 | if ('.' == $item || '..' == $item) |
| 60 | 60 | continue; |
| 61 | 61 | if ('.php' == substr($item, -4)) |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | return create_function('$token, $string', 'global $'.$m.'; return var_export($'.$m.'->translate($string), true);'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - function walk_tokens(&$tokens, $string_action, $other_action, $register_action=null) { |
|
| 80 | + function walk_tokens(&$tokens, $string_action, $other_action, $register_action = null) { |
|
| 81 | 81 | |
| 82 | 82 | $current_comment_id = ''; |
| 83 | 83 | $current_string = ''; |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | $result = ''; |
| 87 | 87 | $line = 1; |
| 88 | 88 | |
| 89 | - foreach($tokens as $token) { |
|
| 89 | + foreach ($tokens as $token) { |
|
| 90 | 90 | if (is_array($token)) { |
| 91 | 91 | list($id, $text) = $token; |
| 92 | 92 | $line += substr_count($text, "\n"); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | $stage = $this->STAGE_END_COMMENT; |
| 103 | 103 | $this->logmsg('end comment', $current_comment_id); |
| 104 | 104 | $result .= call_user_func($other_action, $token); |
| 105 | - if (!is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 105 | + if ( ! is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 106 | 106 | continue; |
| 107 | 107 | } |
| 108 | 108 | } else if (T_CONSTANT_ENCAPSED_STRING == $id) { |
@@ -149,21 +149,21 @@ discard block |
||
| 149 | 149 | $global_name = '__entries_'.mt_rand(1, 1000); |
| 150 | 150 | $GLOBALS[$global_name] = array(); |
| 151 | 151 | |
| 152 | - foreach($filenames as $filename) { |
|
| 152 | + foreach ($filenames as $filename) { |
|
| 153 | 153 | $tokens = token_get_all(file_get_contents($filename)); |
| 154 | 154 | $aggregator = $this->make_string_aggregator($global_name, $filename); |
| 155 | 155 | $this->walk_tokens($tokens, array($this, 'ignore_token'), array($this, 'ignore_token'), $aggregator); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $potf = '-' == $pot_filename? STDOUT : @fopen($pot_filename, 'a'); |
|
| 158 | + $potf = '-' == $pot_filename ? STDOUT : @fopen($pot_filename, 'a'); |
|
| 159 | 159 | if (false === $potf) { |
| 160 | 160 | $this->cli_die("Couldn't open pot file: $pot_filename"); |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - foreach($GLOBALS[$global_name] as $item) { |
|
| 163 | + foreach ($GLOBALS[$global_name] as $item) { |
|
| 164 | 164 | @list($string, $comment_id, $filename, $line_number) = $item; |
| 165 | - $filename = isset($filename)? preg_replace('|^\./|', '', $filename) : ''; |
|
| 166 | - $ref_line_number = isset($line_number)? ":$line_number" : ''; |
|
| 165 | + $filename = isset($filename) ? preg_replace('|^\./|', '', $filename) : ''; |
|
| 166 | + $ref_line_number = isset($line_number) ? ":$line_number" : ''; |
|
| 167 | 167 | $args = array( |
| 168 | 168 | 'singular' => $string, |
| 169 | 169 | 'extracted_comments' => "Not gettexted string $comment_id", |
@@ -192,9 +192,9 @@ discard block |
||
| 192 | 192 | if (false === $res) { |
| 193 | 193 | $this->cli_die("Couldn't read MO file '$mo_filename'!"); |
| 194 | 194 | } |
| 195 | - foreach($filenames as $filename) { |
|
| 195 | + foreach ($filenames as $filename) { |
|
| 196 | 196 | $source = file_get_contents($filename); |
| 197 | - if ( strlen($source) > 150000 ) continue; |
|
| 197 | + if (strlen($source) > 150000) continue; |
|
| 198 | 198 | $tokens = token_get_all($source); |
| 199 | 199 | $new_file = $this->walk_tokens($tokens, $replacer, array($this, 'unchanged_token')); |
| 200 | 200 | $f = fopen($filename, 'w'); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | function cli() { |
| 216 | 216 | global $argv, $commands; |
| 217 | - if (count($argv) < 4 || !in_array($argv[1], array_keys($this->commands))) { |
|
| 217 | + if (count($argv) < 4 || ! in_array($argv[1], array_keys($this->commands))) { |
|
| 218 | 218 | $this->usage(); |
| 219 | 219 | exit(1); |
| 220 | 220 | } |
@@ -7,10 +7,11 @@ discard block |
||
| 7 | 7 | * @subpackage tools |
| 8 | 8 | */ |
| 9 | 9 | // see: http://php.net/tokenizer |
| 10 | -if ( ! defined( 'T_ML_COMMENT' ) ) |
|
| 10 | +if ( ! defined( 'T_ML_COMMENT' ) ) { |
|
| 11 | 11 | define( 'T_ML_COMMENT', T_COMMENT ); |
| 12 | -else |
|
| 12 | +} else { |
|
| 13 | 13 | define( 'T_DOC_COMMENT', T_ML_COMMENT ); |
| 14 | +} |
|
| 14 | 15 | |
| 15 | 16 | $pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
| 16 | 17 | require_once "$pomo/po.php"; |
@@ -31,7 +32,9 @@ discard block |
||
| 31 | 32 | |
| 32 | 33 | function logmsg() { |
| 33 | 34 | $args = func_get_args(); |
| 34 | - if ($this->enable_logging) error_log(implode(' ', $args)); |
|
| 35 | + if ($this->enable_logging) { |
|
| 36 | + error_log(implode(' ', $args)); |
|
| 37 | + } |
|
| 35 | 38 | } |
| 36 | 39 | |
| 37 | 40 | function stderr($msg, $nl=true) { |
@@ -56,12 +59,15 @@ discard block |
||
| 56 | 59 | $items = scandir( $dir ); |
| 57 | 60 | foreach ( (array) $items as $item ) { |
| 58 | 61 | $full_item = $dir . '/' . $item; |
| 59 | - if ('.' == $item || '..' == $item) |
|
| 60 | - continue; |
|
| 61 | - if ('.php' == substr($item, -4)) |
|
| 62 | - $files[] = $full_item; |
|
| 63 | - if (is_dir($full_item)) |
|
| 64 | - $files += array_merge($files, NotGettexted::list_php_files($full_item, $files)); |
|
| 62 | + if ('.' == $item || '..' == $item) { |
|
| 63 | + continue; |
|
| 64 | + } |
|
| 65 | + if ('.php' == substr($item, -4)) { |
|
| 66 | + $files[] = $full_item; |
|
| 67 | + } |
|
| 68 | + if (is_dir($full_item)) { |
|
| 69 | + $files += array_merge($files, NotGettexted::list_php_files($full_item, $files)); |
|
| 70 | + } |
|
| 65 | 71 | } |
| 66 | 72 | return $files; |
| 67 | 73 | } |
@@ -102,7 +108,9 @@ discard block |
||
| 102 | 108 | $stage = $this->STAGE_END_COMMENT; |
| 103 | 109 | $this->logmsg('end comment', $current_comment_id); |
| 104 | 110 | $result .= call_user_func($other_action, $token); |
| 105 | - if (!is_null($register_action)) call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 111 | + if (!is_null($register_action)) { |
|
| 112 | + call_user_func($register_action, $current_string, $current_comment_id, $current_string_line); |
|
| 113 | + } |
|
| 106 | 114 | continue; |
| 107 | 115 | } |
| 108 | 116 | } else if (T_CONSTANT_ENCAPSED_STRING == $id) { |
@@ -141,10 +149,11 @@ discard block |
||
| 141 | 149 | function command_extract() { |
| 142 | 150 | $args = func_get_args(); |
| 143 | 151 | $pot_filename = $args[0]; |
| 144 | - if (isset($args[1]) && is_array($args[1])) |
|
| 145 | - $filenames = $args[1]; |
|
| 146 | - else |
|
| 147 | - $filenames = array_slice($args, 1); |
|
| 152 | + if (isset($args[1]) && is_array($args[1])) { |
|
| 153 | + $filenames = $args[1]; |
|
| 154 | + } else { |
|
| 155 | + $filenames = array_slice($args, 1); |
|
| 156 | + } |
|
| 148 | 157 | |
| 149 | 158 | $global_name = '__entries_'.mt_rand(1, 1000); |
| 150 | 159 | $GLOBALS[$global_name] = array(); |
@@ -172,17 +181,20 @@ discard block |
||
| 172 | 181 | $entry = new Translation_Entry($args); |
| 173 | 182 | fwrite($potf, "\n".PO::export_entry($entry)."\n"); |
| 174 | 183 | } |
| 175 | - if ('-' != $pot_filename) fclose($potf); |
|
| 184 | + if ('-' != $pot_filename) { |
|
| 185 | + fclose($potf); |
|
| 186 | + } |
|
| 176 | 187 | return true; |
| 177 | 188 | } |
| 178 | 189 | |
| 179 | 190 | function command_replace() { |
| 180 | 191 | $args = func_get_args(); |
| 181 | 192 | $mo_filename = $args[0]; |
| 182 | - if (isset($args[1]) && is_array($args[1])) |
|
| 183 | - $filenames = $args[1]; |
|
| 184 | - else |
|
| 185 | - $filenames = array_slice($args, 1); |
|
| 193 | + if (isset($args[1]) && is_array($args[1])) { |
|
| 194 | + $filenames = $args[1]; |
|
| 195 | + } else { |
|
| 196 | + $filenames = array_slice($args, 1); |
|
| 197 | + } |
|
| 186 | 198 | |
| 187 | 199 | $global_name = '__mo_'.mt_rand(1, 1000); |
| 188 | 200 | $GLOBALS[$global_name] = new MO(); |
@@ -194,7 +206,9 @@ discard block |
||
| 194 | 206 | } |
| 195 | 207 | foreach($filenames as $filename) { |
| 196 | 208 | $source = file_get_contents($filename); |
| 197 | - if ( strlen($source) > 150000 ) continue; |
|
| 209 | + if ( strlen($source) > 150000 ) { |
|
| 210 | + continue; |
|
| 211 | + } |
|
| 198 | 212 | $tokens = token_get_all($source); |
| 199 | 213 | $new_file = $this->walk_tokens($tokens, $replacer, array($this, 'unchanged_token')); |
| 200 | 214 | $f = fopen($filename, 'w'); |
@@ -49,6 +49,9 @@ |
||
| 49 | 49 | return $pot; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | + /** |
|
| 53 | + * @param string[] $headers |
|
| 54 | + */ |
|
| 52 | 55 | function append( $ext_filename, $pot_filename, $headers = null ) { |
| 53 | 56 | if ( $headers ) |
| 54 | 57 | $this->headers = (array) $headers; |
@@ -7,9 +7,9 @@ discard block |
||
| 7 | 7 | * @subpackage tools |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -$pomo = dirname( dirname( dirname( __FILE__ ) ) ) . '/src/wp-includes/pomo'; |
|
| 10 | +$pomo = dirname(dirname(dirname(__FILE__))).'/src/wp-includes/pomo'; |
|
| 11 | 11 | require_once "$pomo/po.php"; |
| 12 | -require_once dirname( __FILE__ ) . '/makepot.php'; |
|
| 12 | +require_once dirname(__FILE__).'/makepot.php'; |
|
| 13 | 13 | |
| 14 | 14 | class PotExtMeta { |
| 15 | 15 | |
@@ -36,9 +36,9 @@ discard block |
||
| 36 | 36 | $source = $makepot->get_first_lines($ext_filename); |
| 37 | 37 | $pot = ''; |
| 38 | 38 | $po = new PO; |
| 39 | - foreach($this->headers as $header) { |
|
| 39 | + foreach ($this->headers as $header) { |
|
| 40 | 40 | $string = $makepot->get_addon_header($header, $source); |
| 41 | - if (!$string) continue; |
|
| 41 | + if ( ! $string) continue; |
|
| 42 | 42 | $args = array( |
| 43 | 43 | 'singular' => $string, |
| 44 | 44 | 'extracted_comments' => $header.' of the plugin/theme', |
@@ -49,16 +49,16 @@ discard block |
||
| 49 | 49 | return $pot; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - function append( $ext_filename, $pot_filename, $headers = null ) { |
|
| 53 | - if ( $headers ) |
|
| 52 | + function append($ext_filename, $pot_filename, $headers = null) { |
|
| 53 | + if ($headers) |
|
| 54 | 54 | $this->headers = (array) $headers; |
| 55 | - if ( is_dir( $ext_filename ) ) { |
|
| 55 | + if (is_dir($ext_filename)) { |
|
| 56 | 56 | $pot = implode('', array_map(array($this, 'load_from_file'), glob("$ext_filename/*.php"))); |
| 57 | 57 | } else { |
| 58 | 58 | $pot = $this->load_from_file($ext_filename); |
| 59 | 59 | } |
| 60 | - $potf = '-' == $pot_filename? STDOUT : fopen($pot_filename, 'a'); |
|
| 61 | - if (!$potf) return false; |
|
| 60 | + $potf = '-' == $pot_filename ? STDOUT : fopen($pot_filename, 'a'); |
|
| 61 | + if ( ! $potf) return false; |
|
| 62 | 62 | fwrite($potf, $pot); |
| 63 | 63 | if ('-' != $pot_filename) fclose($potf); |
| 64 | 64 | return true; |
@@ -69,10 +69,10 @@ discard block |
||
| 69 | 69 | if ($included_files[0] == __FILE__) { |
| 70 | 70 | ini_set('display_errors', 1); |
| 71 | 71 | $potextmeta = new PotExtMeta; |
| 72 | - if (!isset($argv[1])) { |
|
| 72 | + if ( ! isset($argv[1])) { |
|
| 73 | 73 | $potextmeta->usage(); |
| 74 | 74 | } |
| 75 | - $potextmeta->append( $argv[1], isset( $argv[2] ) ? $argv[2] : '-', isset( $argv[3] ) ? $argv[3] : null ); |
|
| 75 | + $potextmeta->append($argv[1], isset($argv[2]) ? $argv[2] : '-', isset($argv[3]) ? $argv[3] : null); |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | ?> |
@@ -38,7 +38,9 @@ discard block |
||
| 38 | 38 | $po = new PO; |
| 39 | 39 | foreach($this->headers as $header) { |
| 40 | 40 | $string = $makepot->get_addon_header($header, $source); |
| 41 | - if (!$string) continue; |
|
| 41 | + if (!$string) { |
|
| 42 | + continue; |
|
| 43 | + } |
|
| 42 | 44 | $args = array( |
| 43 | 45 | 'singular' => $string, |
| 44 | 46 | 'extracted_comments' => $header.' of the plugin/theme', |
@@ -50,17 +52,22 @@ discard block |
||
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | function append( $ext_filename, $pot_filename, $headers = null ) { |
| 53 | - if ( $headers ) |
|
| 54 | - $this->headers = (array) $headers; |
|
| 55 | + if ( $headers ) { |
|
| 56 | + $this->headers = (array) $headers; |
|
| 57 | + } |
|
| 55 | 58 | if ( is_dir( $ext_filename ) ) { |
| 56 | 59 | $pot = implode('', array_map(array($this, 'load_from_file'), glob("$ext_filename/*.php"))); |
| 57 | 60 | } else { |
| 58 | 61 | $pot = $this->load_from_file($ext_filename); |
| 59 | 62 | } |
| 60 | 63 | $potf = '-' == $pot_filename? STDOUT : fopen($pot_filename, 'a'); |
| 61 | - if (!$potf) return false; |
|
| 64 | + if (!$potf) { |
|
| 65 | + return false; |
|
| 66 | + } |
|
| 62 | 67 | fwrite($potf, $pot); |
| 63 | - if ('-' != $pot_filename) fclose($potf); |
|
| 68 | + if ('-' != $pot_filename) { |
|
| 69 | + fclose($potf); |
|
| 70 | + } |
|
| 64 | 71 | return true; |
| 65 | 72 | } |
| 66 | 73 | } |
@@ -2,8 +2,11 @@ |
||
| 2 | 2 | |
| 3 | 3 | if (! isset($wp_did_header)): |
| 4 | 4 | if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) { |
| 5 | - if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = ''; |
|
| 6 | - else $path = 'wp-admin/'; |
|
| 5 | + if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) { |
|
| 6 | + $path = ''; |
|
| 7 | + } else { |
|
| 8 | + $path = 'wp-admin/'; |
|
| 9 | + } |
|
| 7 | 10 | |
| 8 | 11 | require_once( dirname(__FILE__) . '/wp-includes/classes.php'); |
| 9 | 12 | require_once( dirname(__FILE__) . '/wp-includes/functions.php'); |
@@ -1,23 +1,23 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -if (! isset($wp_did_header)): |
|
| 4 | -if ( !file_exists( dirname(__FILE__) . '/wp-config.php') ) { |
|
| 3 | +if ( ! isset($wp_did_header)): |
|
| 4 | +if ( ! file_exists(dirname(__FILE__).'/wp-config.php')) { |
|
| 5 | 5 | if (strpos($_SERVER['PHP_SELF'], 'wp-admin') !== false) $path = ''; |
| 6 | 6 | else $path = 'wp-admin/'; |
| 7 | 7 | |
| 8 | - require_once( dirname(__FILE__) . '/wp-includes/classes.php'); |
|
| 9 | - require_once( dirname(__FILE__) . '/wp-includes/functions.php'); |
|
| 10 | - require_once( dirname(__FILE__) . '/wp-includes/plugin.php'); |
|
| 11 | - wp_die( sprintf(/*WP_I18N_CONFIG*/" There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='https://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>" /*/WP_I18N_CONFIG*/, $path.'setup-config.php'), /*WP_I18N_ERROR*/ "WordPress › Error" /*/WP_I18N_ERROR*/); |
|
| 8 | + require_once(dirname(__FILE__).'/wp-includes/classes.php'); |
|
| 9 | + require_once(dirname(__FILE__).'/wp-includes/functions.php'); |
|
| 10 | + require_once(dirname(__FILE__).'/wp-includes/plugin.php'); |
|
| 11 | + wp_die(sprintf(/*WP_I18N_CONFIG*/" There doesn't seem to be a <code>wp-config.php</code> file. I need this before we can get started. Need more help? <a href='https://codex.wordpress.org/Editing_wp-config.php'>We got it</a>. You can create a <code>wp-config.php</code> file through a web interface, but this doesn't work for all server setups. The safest way is to manually create the file.</p><p><a href='%s' class='button'>Create a Configuration File</a>" /*/WP_I18N_CONFIG*/, $path.'setup-config.php'), /*WP_I18N_ERROR*/ "WordPress › Error" /*/WP_I18N_ERROR*/); |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | $wp_did_header = true; |
| 15 | 15 | |
| 16 | -require_once( dirname(__FILE__) . '/wp-config.php'); |
|
| 16 | +require_once(dirname(__FILE__).'/wp-config.php'); |
|
| 17 | 17 | |
| 18 | 18 | wp(); |
| 19 | 19 | |
| 20 | -require_once(ABSPATH . WPINC . '/template-loader.php'); |
|
| 20 | +require_once(ABSPATH.WPINC.'/template-loader.php'); |
|
| 21 | 21 | |
| 22 | 22 | endif; |
| 23 | 23 | |
@@ -5,8 +5,8 @@ discard block |
||
| 5 | 5 | * @package wordpress-i18n |
| 6 | 6 | * @subpackage tools |
| 7 | 7 | */ |
| 8 | -error_reporting( E_ALL ); |
|
| 9 | -require_once dirname( dirname( __FILE__ ) ) . '/not-gettexted.php'; |
|
| 8 | +error_reporting(E_ALL); |
|
| 9 | +require_once dirname(dirname(__FILE__)).'/not-gettexted.php'; |
|
| 10 | 10 | |
| 11 | 11 | class NotGettextedTest extends PHPUnit_Framework_TestCase { |
| 12 | 12 | |
@@ -16,10 +16,10 @@ discard block |
||
| 16 | 16 | |
| 17 | 17 | function test_make_string_aggregator() { |
| 18 | 18 | global $baba; |
| 19 | - $f = $this->ng->make_string_aggregator( 'baba', 'baba.php' ); |
|
| 20 | - call_user_func( $f, 'x', 'y', 'z' ); |
|
| 21 | - call_user_func( $f, 'a', 'b', 'c' ); |
|
| 22 | - $this->assertEquals( array( array( 'x', 'y', 'baba.php', 'z'), array( 'a', 'b', 'baba.php', 'c' ) ), $baba ); |
|
| 19 | + $f = $this->ng->make_string_aggregator('baba', 'baba.php'); |
|
| 20 | + call_user_func($f, 'x', 'y', 'z'); |
|
| 21 | + call_user_func($f, 'a', 'b', 'c'); |
|
| 22 | + $this->assertEquals(array(array('x', 'y', 'baba.php', 'z'), array('a', 'b', 'baba.php', 'c')), $baba); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | function test_walk() { |
@@ -30,17 +30,17 @@ discard block |
||
| 30 | 30 | if ($x == "18181") { wp_die(sprintf(/*WP_I18N_DIE*/\'We died %d times!\'/*WP_I18N_DIE*/)); } |
| 31 | 31 | ?>'; |
| 32 | 32 | $tokens = token_get_all($code); |
| 33 | - $this->assertEquals( '', $this->ng->walk_tokens( $tokens, array($this->ng, 'ignore_token'), array($this->ng, 'ignore_token') ) ); |
|
| 34 | - $this->assertEquals( '"yes"\'We died %d times!\'', $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'ignore_token') ) ); |
|
| 35 | - $this->assertEquals( $code, $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token') ) ); |
|
| 36 | - $this->assertEquals( $code, $this->ng->walk_tokens( $tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token') ) ); |
|
| 33 | + $this->assertEquals('', $this->ng->walk_tokens($tokens, array($this->ng, 'ignore_token'), array($this->ng, 'ignore_token'))); |
|
| 34 | + $this->assertEquals('"yes"\'We died %d times!\'', $this->ng->walk_tokens($tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'ignore_token'))); |
|
| 35 | + $this->assertEquals($code, $this->ng->walk_tokens($tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token'))); |
|
| 36 | + $this->assertEquals($code, $this->ng->walk_tokens($tokens, array($this->ng, 'unchanged_token'), array($this->ng, 'unchanged_token'))); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | function test_replace() { |
| 40 | 40 | # copy to a new file, so that we don't corrupt the old one |
| 41 | - copy( 'data/not-gettexted-0.php', 'data/not-gettexted-0-work.php' ); |
|
| 42 | - $this->ng->command_replace( 'data/not-gettexted-0.mo', 'data/not-gettexted-0-work.php' ); |
|
| 43 | - $this->assertEquals( file_get_contents( 'data/not-gettexted-0-result.php' ), file_get_contents( 'data/not-gettexted-0-work.php' ) ); |
|
| 44 | - unlink( 'data/not-gettexted-0-work.php' ); |
|
| 41 | + copy('data/not-gettexted-0.php', 'data/not-gettexted-0-work.php'); |
|
| 42 | + $this->ng->command_replace('data/not-gettexted-0.mo', 'data/not-gettexted-0-work.php'); |
|
| 43 | + $this->assertEquals(file_get_contents('data/not-gettexted-0-result.php'), file_get_contents('data/not-gettexted-0-work.php')); |
|
| 44 | + unlink('data/not-gettexted-0-work.php'); |
|
| 45 | 45 | } |
| 46 | 46 | } |
@@ -5,14 +5,14 @@ |
||
| 5 | 5 | * @package WordPress |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( !isset($wp_did_header) ) { |
|
| 8 | +if ( ! isset($wp_did_header)) { |
|
| 9 | 9 | |
| 10 | 10 | $wp_did_header = true; |
| 11 | 11 | |
| 12 | - require_once( dirname(__FILE__) . '/wp-load.php' ); |
|
| 12 | + require_once(dirname(__FILE__).'/wp-load.php'); |
|
| 13 | 13 | |
| 14 | 14 | wp(); |
| 15 | 15 | |
| 16 | - require_once( ABSPATH . WPINC . '/template-loader.php' ); |
|
| 16 | + require_once(ABSPATH.WPINC.'/template-loader.php'); |
|
| 17 | 17 | |
| 18 | 18 | } |