@@ -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") |
@@ -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 | */ |
@@ -92,17 +92,17 @@ |
||
92 | 92 | |
93 | 93 | if ( !empty($tb_url) && !empty($title) ) { |
94 | 94 | /** |
95 | - * Fires before the trackback is added to a post. |
|
96 | - * |
|
97 | - * @since 4.7.0 |
|
98 | - * |
|
99 | - * @param int $tb_id Post ID related to the trackback. |
|
100 | - * @param string $tb_url Trackback URL. |
|
101 | - * @param string $charset Character Set. |
|
102 | - * @param string $title Trackback Title. |
|
103 | - * @param string $excerpt Trackback Excerpt. |
|
104 | - * @param string $blog_name Blog Name. |
|
105 | - */ |
|
95 | + * Fires before the trackback is added to a post. |
|
96 | + * |
|
97 | + * @since 4.7.0 |
|
98 | + * |
|
99 | + * @param int $tb_id Post ID related to the trackback. |
|
100 | + * @param string $tb_url Trackback URL. |
|
101 | + * @param string $charset Character Set. |
|
102 | + * @param string $title Trackback Title. |
|
103 | + * @param string $excerpt Trackback Excerpt. |
|
104 | + * @param string $blog_name Blog Name. |
|
105 | + */ |
|
106 | 106 | do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name ); |
107 | 107 | |
108 | 108 | header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
@@ -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,11 +78,11 @@ 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 ) ) |
|
85 | - trackback_response( 1, __( 'I really need an ID for this to work.' ) ); |
|
84 | +if ( ! isset($tb_id) || ! intval($tb_id)) |
|
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)) { |
88 | 88 | // If it doesn't look like a trackback at all. |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | exit; |
91 | 91 | } |
92 | 92 | |
93 | -if ( !empty($tb_url) && !empty($title) ) { |
|
93 | +if ( ! empty($tb_url) && ! empty($title)) { |
|
94 | 94 | /** |
95 | 95 | * Fires before the trackback is added to a post. |
96 | 96 | * |
@@ -103,15 +103,15 @@ discard block |
||
103 | 103 | * @param string $excerpt Trackback Excerpt. |
104 | 104 | * @param string $blog_name Blog Name. |
105 | 105 | */ |
106 | - do_action( 'pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name ); |
|
106 | + do_action('pre_trackback_post', $tb_id, $tb_url, $charset, $title, $excerpt, $blog_name); |
|
107 | 107 | |
108 | - header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
|
108 | + header('Content-Type: text/xml; charset='.get_option('blog_charset')); |
|
109 | 109 | |
110 | - if ( !pings_open($tb_id) ) |
|
111 | - trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) ); |
|
110 | + if ( ! pings_open($tb_id)) |
|
111 | + trackback_response(1, __('Sorry, trackbacks are closed for this item.')); |
|
112 | 112 | |
113 | - $title = wp_html_excerpt( $title, 250, '…' ); |
|
114 | - $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
|
113 | + $title = wp_html_excerpt($title, 250, '…'); |
|
114 | + $excerpt = wp_html_excerpt($excerpt, 252, '…'); |
|
115 | 115 | |
116 | 116 | $comment_post_ID = (int) $tb_id; |
117 | 117 | $comment_author = $blog_name; |
@@ -120,9 +120,9 @@ discard block |
||
120 | 120 | $comment_content = "<strong>$title</strong>\n\n$excerpt"; |
121 | 121 | $comment_type = 'trackback'; |
122 | 122 | |
123 | - $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) ); |
|
124 | - if ( $dupe ) |
|
125 | - trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) ); |
|
123 | + $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)); |
|
124 | + if ($dupe) |
|
125 | + trackback_response(1, __('We already have a ping from that URL for this post.')); |
|
126 | 126 | |
127 | 127 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
128 | 128 | |
@@ -136,6 +136,6 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @param int $trackback_id Trackback ID. |
138 | 138 | */ |
139 | - do_action( 'trackback_post', $trackback_id ); |
|
140 | - trackback_response( 0 ); |
|
139 | + do_action('trackback_post', $trackback_id); |
|
140 | + trackback_response(0); |
|
141 | 141 | } |
@@ -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. |
@@ -107,8 +111,9 @@ discard block |
||
107 | 111 | |
108 | 112 | header('Content-Type: text/xml; charset=' . get_option('blog_charset') ); |
109 | 113 | |
110 | - if ( !pings_open($tb_id) ) |
|
111 | - trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) ); |
|
114 | + if ( !pings_open($tb_id) ) { |
|
115 | + trackback_response( 1, __( 'Sorry, trackbacks are closed for this item.' ) ); |
|
116 | + } |
|
112 | 117 | |
113 | 118 | $title = wp_html_excerpt( $title, 250, '…' ); |
114 | 119 | $excerpt = wp_html_excerpt( $excerpt, 252, '…' ); |
@@ -121,8 +126,9 @@ discard block |
||
121 | 126 | $comment_type = 'trackback'; |
122 | 127 | |
123 | 128 | $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) ); |
124 | - if ( $dupe ) |
|
125 | - trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) ); |
|
129 | + if ( $dupe ) { |
|
130 | + trackback_response( 1, __( 'We already have a ping from that URL for this post.' ) ); |
|
131 | + } |
|
126 | 132 | |
127 | 133 | $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type'); |
128 | 134 |
@@ -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: https://secure.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: https://secure.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: https://secure.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*/'Translation: 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*/ 'Translation: 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*/'Translation: 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*/ 'Translation: 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 | } |
@@ -43,15 +43,15 @@ |
||
43 | 43 | <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> |
44 | 44 | <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" /> |
45 | 45 | <?php |
46 | - /** |
|
47 | - * Add additional APIs to the Really Simple Discovery (RSD) endpoint. |
|
48 | - * |
|
49 | - * @link http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html |
|
46 | + /** |
|
47 | + * Add additional APIs to the Really Simple Discovery (RSD) endpoint. |
|
50 | 48 | * |
51 | - * @since 3.5.0 |
|
52 | - */ |
|
53 | - do_action( 'xmlrpc_rsd_apis' ); |
|
54 | - ?> |
|
49 | + * @link http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html |
|
50 | + * |
|
51 | + * @since 3.5.0 |
|
52 | + */ |
|
53 | + do_action( 'xmlrpc_rsd_apis' ); |
|
54 | + ?> |
|
55 | 55 | </apis> |
56 | 56 | </service> |
57 | 57 | </rsd> |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | |
18 | 18 | // A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default, |
19 | 19 | // but we can do it ourself. |
20 | -if ( !isset( $HTTP_RAW_POST_DATA ) ) { |
|
21 | - $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' ); |
|
20 | +if ( ! isset($HTTP_RAW_POST_DATA)) { |
|
21 | + $HTTP_RAW_POST_DATA = file_get_contents('php://input'); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | // fix for mozBlog and other cases where '<?xml' isn't on the very first line |
25 | -if ( isset($HTTP_RAW_POST_DATA) ) |
|
25 | +if (isset($HTTP_RAW_POST_DATA)) |
|
26 | 26 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
27 | 27 | |
28 | 28 | /** Include the bootstrap for setting up WordPress environment */ |
29 | -include( dirname( __FILE__ ) . '/wp-load.php' ); |
|
29 | +include(dirname(__FILE__).'/wp-load.php'); |
|
30 | 30 | |
31 | -if ( isset( $_GET['rsd'] ) ) { // http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html |
|
32 | -header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true); |
|
31 | +if (isset($_GET['rsd'])) { // http://cyber.law.harvard.edu/blogs/gems/tech/rsd.html |
|
32 | +header('Content-Type: text/xml; charset='.get_option('blog_charset'), true); |
|
33 | 33 | ?> |
34 | 34 | <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?> |
35 | 35 | <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd"> |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @since 3.5.0 |
52 | 52 | */ |
53 | - do_action( 'xmlrpc_rsd_apis' ); |
|
53 | + do_action('xmlrpc_rsd_apis'); |
|
54 | 54 | ?> |
55 | 55 | </apis> |
56 | 56 | </service> |
@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | exit; |
60 | 60 | } |
61 | 61 | |
62 | -include_once(ABSPATH . 'wp-admin/includes/admin.php'); |
|
63 | -include_once(ABSPATH . WPINC . '/class-IXR.php'); |
|
64 | -include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php'); |
|
62 | +include_once(ABSPATH.'wp-admin/includes/admin.php'); |
|
63 | +include_once(ABSPATH.WPINC.'/class-IXR.php'); |
|
64 | +include_once(ABSPATH.WPINC.'/class-wp-xmlrpc-server.php'); |
|
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Posts submitted via the XML-RPC interface get that title |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @param string $class The name of the XML-RPC server class. |
79 | 79 | */ |
80 | -$wp_xmlrpc_server_class = apply_filters( 'wp_xmlrpc_server_class', 'wp_xmlrpc_server' ); |
|
80 | +$wp_xmlrpc_server_class = apply_filters('wp_xmlrpc_server_class', 'wp_xmlrpc_server'); |
|
81 | 81 | $wp_xmlrpc_server = new $wp_xmlrpc_server_class; |
82 | 82 | |
83 | 83 | // Fire off the request |
@@ -94,8 +94,8 @@ discard block |
||
94 | 94 | * @param string $io Whether input or output |
95 | 95 | * @param string $msg Information describing logging reason. |
96 | 96 | */ |
97 | -function logIO( $io, $msg ) { |
|
98 | - _deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' ); |
|
99 | - if ( ! empty( $GLOBALS['xmlrpc_logging'] ) ) |
|
100 | - error_log( $io . ' - ' . $msg ); |
|
97 | +function logIO($io, $msg) { |
|
98 | + _deprecated_function(__FUNCTION__, '3.4.0', 'error_log()'); |
|
99 | + if ( ! empty($GLOBALS['xmlrpc_logging'])) |
|
100 | + error_log($io.' - '.$msg); |
|
101 | 101 | } |
102 | 102 | \ No newline at end of file |
@@ -22,8 +22,9 @@ discard block |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | // fix for mozBlog and other cases where '<?xml' isn't on the very first line |
25 | -if ( isset($HTTP_RAW_POST_DATA) ) |
|
25 | +if ( isset($HTTP_RAW_POST_DATA) ) { |
|
26 | 26 | $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA); |
27 | +} |
|
27 | 28 | |
28 | 29 | /** Include the bootstrap for setting up WordPress environment */ |
29 | 30 | include( dirname( __FILE__ ) . '/wp-load.php' ); |
@@ -96,6 +97,7 @@ discard block |
||
96 | 97 | */ |
97 | 98 | function logIO( $io, $msg ) { |
98 | 99 | _deprecated_function( __FUNCTION__, '3.4.0', 'error_log()' ); |
99 | - if ( ! empty( $GLOBALS['xmlrpc_logging'] ) ) |
|
100 | - error_log( $io . ' - ' . $msg ); |
|
101 | -} |
|
102 | 100 | \ No newline at end of file |
101 | + if ( ! empty( $GLOBALS['xmlrpc_logging'] ) ) { |
|
102 | + error_log( $io . ' - ' . $msg ); |
|
103 | + } |
|
104 | + } |
|
103 | 105 | \ No newline at end of file |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | ignore_user_abort(true); |
13 | 13 | |
14 | -if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) |
|
14 | +if ( ! empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON')) |
|
15 | 15 | die(); |
16 | 16 | |
17 | 17 | /** |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | */ |
22 | 22 | define('DOING_CRON', true); |
23 | 23 | |
24 | -if ( !defined('ABSPATH') ) { |
|
24 | +if ( ! defined('ABSPATH')) { |
|
25 | 25 | /** Set up WordPress environment */ |
26 | - require_once( dirname( __FILE__ ) . '/wp-load.php' ); |
|
26 | + require_once(dirname(__FILE__).'/wp-load.php'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -40,44 +40,44 @@ discard block |
||
40 | 40 | global $wpdb; |
41 | 41 | |
42 | 42 | $value = 0; |
43 | - if ( wp_using_ext_object_cache() ) { |
|
43 | + if (wp_using_ext_object_cache()) { |
|
44 | 44 | /* |
45 | 45 | * Skip local cache and force re-fetch of doing_cron transient |
46 | 46 | * in case another process updated the cache. |
47 | 47 | */ |
48 | - $value = wp_cache_get( 'doing_cron', 'transient', true ); |
|
48 | + $value = wp_cache_get('doing_cron', 'transient', true); |
|
49 | 49 | } else { |
50 | - $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); |
|
51 | - if ( is_object( $row ) ) |
|
50 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron')); |
|
51 | + if (is_object($row)) |
|
52 | 52 | $value = $row->option_value; |
53 | 53 | } |
54 | 54 | |
55 | 55 | return $value; |
56 | 56 | } |
57 | 57 | |
58 | -if ( false === $crons = _get_cron_array() ) |
|
58 | +if (false === $crons = _get_cron_array()) |
|
59 | 59 | die(); |
60 | 60 | |
61 | -$keys = array_keys( $crons ); |
|
62 | -$gmt_time = microtime( true ); |
|
61 | +$keys = array_keys($crons); |
|
62 | +$gmt_time = microtime(true); |
|
63 | 63 | |
64 | -if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
|
64 | +if (isset($keys[0]) && $keys[0] > $gmt_time) |
|
65 | 65 | die(); |
66 | 66 | |
67 | 67 | |
68 | 68 | // The cron lock: a unix timestamp from when the cron was spawned. |
69 | -$doing_cron_transient = get_transient( 'doing_cron' ); |
|
69 | +$doing_cron_transient = get_transient('doing_cron'); |
|
70 | 70 | |
71 | 71 | // Use global $doing_wp_cron lock otherwise use the GET lock. If no lock, trying grabbing a new lock. |
72 | -if ( empty( $doing_wp_cron ) ) { |
|
73 | - if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { |
|
72 | +if (empty($doing_wp_cron)) { |
|
73 | + if (empty($_GET['doing_wp_cron'])) { |
|
74 | 74 | // Called from external script/job. Try setting a lock. |
75 | - if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) |
|
75 | + if ($doing_cron_transient && ($doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time)) |
|
76 | 76 | return; |
77 | - $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); |
|
78 | - set_transient( 'doing_cron', $doing_wp_cron ); |
|
77 | + $doing_cron_transient = $doing_wp_cron = sprintf('%.22F', microtime(true)); |
|
78 | + set_transient('doing_cron', $doing_wp_cron); |
|
79 | 79 | } else { |
80 | - $doing_wp_cron = $_GET[ 'doing_wp_cron' ]; |
|
80 | + $doing_wp_cron = $_GET['doing_wp_cron']; |
|
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
@@ -85,25 +85,25 @@ discard block |
||
85 | 85 | * The cron lock (a unix timestamp set when the cron was spawned), |
86 | 86 | * must match $doing_wp_cron (the "key"). |
87 | 87 | */ |
88 | -if ( $doing_cron_transient != $doing_wp_cron ) |
|
88 | +if ($doing_cron_transient != $doing_wp_cron) |
|
89 | 89 | return; |
90 | 90 | |
91 | -foreach ( $crons as $timestamp => $cronhooks ) { |
|
92 | - if ( $timestamp > $gmt_time ) |
|
91 | +foreach ($crons as $timestamp => $cronhooks) { |
|
92 | + if ($timestamp > $gmt_time) |
|
93 | 93 | break; |
94 | 94 | |
95 | - foreach ( $cronhooks as $hook => $keys ) { |
|
95 | + foreach ($cronhooks as $hook => $keys) { |
|
96 | 96 | |
97 | - foreach ( $keys as $k => $v ) { |
|
97 | + foreach ($keys as $k => $v) { |
|
98 | 98 | |
99 | 99 | $schedule = $v['schedule']; |
100 | 100 | |
101 | - if ( $schedule != false ) { |
|
101 | + if ($schedule != false) { |
|
102 | 102 | $new_args = array($timestamp, $schedule, $hook, $v['args']); |
103 | 103 | call_user_func_array('wp_reschedule_event', $new_args); |
104 | 104 | } |
105 | 105 | |
106 | - wp_unschedule_event( $timestamp, $hook, $v['args'] ); |
|
106 | + wp_unschedule_event($timestamp, $hook, $v['args']); |
|
107 | 107 | |
108 | 108 | /** |
109 | 109 | * Fires scheduled events. |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | * @param string $hook Name of the hook that was scheduled to be fired. |
115 | 115 | * @param array $args The arguments to be passed to the hook. |
116 | 116 | */ |
117 | - do_action_ref_array( $hook, $v['args'] ); |
|
117 | + do_action_ref_array($hook, $v['args']); |
|
118 | 118 | |
119 | 119 | // If the hook ran too long and another cron process stole the lock, quit. |
120 | - if ( _get_cron_lock() != $doing_wp_cron ) |
|
120 | + if (_get_cron_lock() != $doing_wp_cron) |
|
121 | 121 | return; |
122 | 122 | } |
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
126 | -if ( _get_cron_lock() == $doing_wp_cron ) |
|
127 | - delete_transient( 'doing_cron' ); |
|
126 | +if (_get_cron_lock() == $doing_wp_cron) |
|
127 | + delete_transient('doing_cron'); |
|
128 | 128 | |
129 | 129 | die(); |
@@ -11,8 +11,9 @@ discard block |
||
11 | 11 | |
12 | 12 | ignore_user_abort(true); |
13 | 13 | |
14 | -if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) |
|
14 | +if ( !empty($_POST) || defined('DOING_AJAX') || defined('DOING_CRON') ) { |
|
15 | 15 | die(); |
16 | +} |
|
16 | 17 | |
17 | 18 | /** |
18 | 19 | * Tell WordPress we are doing the CRON task. |
@@ -48,21 +49,24 @@ discard block |
||
48 | 49 | $value = wp_cache_get( 'doing_cron', 'transient', true ); |
49 | 50 | } else { |
50 | 51 | $row = $wpdb->get_row( $wpdb->prepare( "SELECT option_value FROM $wpdb->options WHERE option_name = %s LIMIT 1", '_transient_doing_cron' ) ); |
51 | - if ( is_object( $row ) ) |
|
52 | - $value = $row->option_value; |
|
52 | + if ( is_object( $row ) ) { |
|
53 | + $value = $row->option_value; |
|
54 | + } |
|
53 | 55 | } |
54 | 56 | |
55 | 57 | return $value; |
56 | 58 | } |
57 | 59 | |
58 | -if ( false === $crons = _get_cron_array() ) |
|
60 | +if ( false === $crons = _get_cron_array() ) { |
|
59 | 61 | die(); |
62 | +} |
|
60 | 63 | |
61 | 64 | $keys = array_keys( $crons ); |
62 | 65 | $gmt_time = microtime( true ); |
63 | 66 | |
64 | -if ( isset($keys[0]) && $keys[0] > $gmt_time ) |
|
67 | +if ( isset($keys[0]) && $keys[0] > $gmt_time ) { |
|
65 | 68 | die(); |
69 | +} |
|
66 | 70 | |
67 | 71 | |
68 | 72 | // The cron lock: a unix timestamp from when the cron was spawned. |
@@ -72,8 +76,9 @@ discard block |
||
72 | 76 | if ( empty( $doing_wp_cron ) ) { |
73 | 77 | if ( empty( $_GET[ 'doing_wp_cron' ] ) ) { |
74 | 78 | // Called from external script/job. Try setting a lock. |
75 | - if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) |
|
76 | - return; |
|
79 | + if ( $doing_cron_transient && ( $doing_cron_transient + WP_CRON_LOCK_TIMEOUT > $gmt_time ) ) { |
|
80 | + return; |
|
81 | + } |
|
77 | 82 | $doing_cron_transient = $doing_wp_cron = sprintf( '%.22F', microtime( true ) ); |
78 | 83 | set_transient( 'doing_cron', $doing_wp_cron ); |
79 | 84 | } else { |
@@ -85,12 +90,14 @@ discard block |
||
85 | 90 | * The cron lock (a unix timestamp set when the cron was spawned), |
86 | 91 | * must match $doing_wp_cron (the "key"). |
87 | 92 | */ |
88 | -if ( $doing_cron_transient != $doing_wp_cron ) |
|
93 | +if ( $doing_cron_transient != $doing_wp_cron ) { |
|
89 | 94 | return; |
95 | +} |
|
90 | 96 | |
91 | 97 | foreach ( $crons as $timestamp => $cronhooks ) { |
92 | - if ( $timestamp > $gmt_time ) |
|
93 | - break; |
|
98 | + if ( $timestamp > $gmt_time ) { |
|
99 | + break; |
|
100 | + } |
|
94 | 101 | |
95 | 102 | foreach ( $cronhooks as $hook => $keys ) { |
96 | 103 | |
@@ -117,13 +124,15 @@ discard block |
||
117 | 124 | do_action_ref_array( $hook, $v['args'] ); |
118 | 125 | |
119 | 126 | // If the hook ran too long and another cron process stole the lock, quit. |
120 | - if ( _get_cron_lock() != $doing_wp_cron ) |
|
121 | - return; |
|
127 | + if ( _get_cron_lock() != $doing_wp_cron ) { |
|
128 | + return; |
|
129 | + } |
|
122 | 130 | } |
123 | 131 | } |
124 | 132 | } |
125 | 133 | |
126 | -if ( _get_cron_lock() == $doing_wp_cron ) |
|
134 | +if ( _get_cron_lock() == $doing_wp_cron ) { |
|
127 | 135 | delete_transient( 'doing_cron' ); |
136 | +} |
|
128 | 137 | |
129 | 138 | die(); |