@@ -8,25 +8,25 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class IXR_Server |
10 | 10 | { |
11 | - var $data; |
|
12 | - var $callbacks = array(); |
|
13 | - var $message; |
|
14 | - var $capabilities; |
|
11 | + var $data; |
|
12 | + var $callbacks = array(); |
|
13 | + var $message; |
|
14 | + var $capabilities; |
|
15 | 15 | |
16 | 16 | /** |
17 | 17 | * PHP5 constructor. |
18 | 18 | */ |
19 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
20 | - { |
|
21 | - $this->setCapabilities(); |
|
22 | - if ($callbacks) { |
|
23 | - $this->callbacks = $callbacks; |
|
24 | - } |
|
25 | - $this->setCallbacks(); |
|
26 | - if (!$wait) { |
|
27 | - $this->serve($data); |
|
28 | - } |
|
29 | - } |
|
19 | + function __construct( $callbacks = false, $data = false, $wait = false ) |
|
20 | + { |
|
21 | + $this->setCapabilities(); |
|
22 | + if ($callbacks) { |
|
23 | + $this->callbacks = $callbacks; |
|
24 | + } |
|
25 | + $this->setCallbacks(); |
|
26 | + if (!$wait) { |
|
27 | + $this->serve($data); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * PHP4 constructor. |
@@ -35,46 +35,46 @@ discard block |
||
35 | 35 | self::__construct( $callbacks, $data, $wait ); |
36 | 36 | } |
37 | 37 | |
38 | - function serve($data = false) |
|
39 | - { |
|
40 | - if (!$data) { |
|
41 | - if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
42 | - if ( function_exists( 'status_header' ) ) { |
|
43 | - status_header( 405 ); // WP #20986 |
|
44 | - header( 'Allow: POST' ); |
|
45 | - } |
|
46 | - header('Content-Type: text/plain'); // merged from WP #9093 |
|
47 | - die('XML-RPC server accepts POST requests only.'); |
|
48 | - } |
|
49 | - |
|
50 | - global $HTTP_RAW_POST_DATA; |
|
51 | - if (empty($HTTP_RAW_POST_DATA)) { |
|
52 | - // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
53 | - $data = file_get_contents('php://input'); |
|
54 | - } else { |
|
55 | - $data =& $HTTP_RAW_POST_DATA; |
|
56 | - } |
|
57 | - } |
|
58 | - $this->message = new IXR_Message($data); |
|
59 | - if (!$this->message->parse()) { |
|
60 | - $this->error(-32700, 'parse error. not well formed'); |
|
61 | - } |
|
62 | - if ($this->message->messageType != 'methodCall') { |
|
63 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
64 | - } |
|
65 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
66 | - |
|
67 | - // Is the result an error? |
|
68 | - if (is_a($result, 'IXR_Error')) { |
|
69 | - $this->error($result); |
|
70 | - } |
|
71 | - |
|
72 | - // Encode the result |
|
73 | - $r = new IXR_Value($result); |
|
74 | - $resultxml = $r->getXml(); |
|
75 | - |
|
76 | - // Create the XML |
|
77 | - $xml = <<<EOD |
|
38 | + function serve($data = false) |
|
39 | + { |
|
40 | + if (!$data) { |
|
41 | + if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
|
42 | + if ( function_exists( 'status_header' ) ) { |
|
43 | + status_header( 405 ); // WP #20986 |
|
44 | + header( 'Allow: POST' ); |
|
45 | + } |
|
46 | + header('Content-Type: text/plain'); // merged from WP #9093 |
|
47 | + die('XML-RPC server accepts POST requests only.'); |
|
48 | + } |
|
49 | + |
|
50 | + global $HTTP_RAW_POST_DATA; |
|
51 | + if (empty($HTTP_RAW_POST_DATA)) { |
|
52 | + // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
|
53 | + $data = file_get_contents('php://input'); |
|
54 | + } else { |
|
55 | + $data =& $HTTP_RAW_POST_DATA; |
|
56 | + } |
|
57 | + } |
|
58 | + $this->message = new IXR_Message($data); |
|
59 | + if (!$this->message->parse()) { |
|
60 | + $this->error(-32700, 'parse error. not well formed'); |
|
61 | + } |
|
62 | + if ($this->message->messageType != 'methodCall') { |
|
63 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
64 | + } |
|
65 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
66 | + |
|
67 | + // Is the result an error? |
|
68 | + if (is_a($result, 'IXR_Error')) { |
|
69 | + $this->error($result); |
|
70 | + } |
|
71 | + |
|
72 | + // Encode the result |
|
73 | + $r = new IXR_Value($result); |
|
74 | + $resultxml = $r->getXml(); |
|
75 | + |
|
76 | + // Create the XML |
|
77 | + $xml = <<<EOD |
|
78 | 78 | <methodResponse> |
79 | 79 | <params> |
80 | 80 | <param> |
@@ -86,140 +86,140 @@ discard block |
||
86 | 86 | </methodResponse> |
87 | 87 | |
88 | 88 | EOD; |
89 | - // Send it |
|
90 | - $this->output($xml); |
|
91 | - } |
|
92 | - |
|
93 | - function call($methodname, $args) |
|
94 | - { |
|
95 | - if (!$this->hasMethod($methodname)) { |
|
96 | - return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
97 | - } |
|
98 | - $method = $this->callbacks[$methodname]; |
|
99 | - |
|
100 | - // Perform the callback and send the response |
|
101 | - if (count($args) == 1) { |
|
102 | - // If only one parameter just send that instead of the whole array |
|
103 | - $args = $args[0]; |
|
104 | - } |
|
105 | - |
|
106 | - // Are we dealing with a function or a method? |
|
107 | - if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
108 | - // It's a class method - check it exists |
|
109 | - $method = substr($method, 5); |
|
110 | - if (!method_exists($this, $method)) { |
|
111 | - return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
112 | - } |
|
113 | - |
|
114 | - //Call the method |
|
115 | - $result = $this->$method($args); |
|
116 | - } else { |
|
117 | - // It's a function - does it exist? |
|
118 | - if (is_array($method)) { |
|
119 | - if (!is_callable(array($method[0], $method[1]))) { |
|
120 | - return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
121 | - } |
|
122 | - } else if (!function_exists($method)) { |
|
123 | - return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
124 | - } |
|
125 | - |
|
126 | - // Call the function |
|
127 | - $result = call_user_func($method, $args); |
|
128 | - } |
|
129 | - return $result; |
|
130 | - } |
|
131 | - |
|
132 | - function error($error, $message = false) |
|
133 | - { |
|
134 | - // Accepts either an error object or an error code and message |
|
135 | - if ($message && !is_object($error)) { |
|
136 | - $error = new IXR_Error($error, $message); |
|
137 | - } |
|
138 | - $this->output($error->getXml()); |
|
139 | - } |
|
140 | - |
|
141 | - function output($xml) |
|
142 | - { |
|
143 | - $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
144 | - if ($charset) |
|
145 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
146 | - else |
|
147 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
148 | - $length = strlen($xml); |
|
149 | - header('Connection: close'); |
|
150 | - if ($charset) |
|
151 | - header('Content-Type: text/xml; charset='.$charset); |
|
152 | - else |
|
153 | - header('Content-Type: text/xml'); |
|
154 | - header('Date: '.date('r')); |
|
155 | - echo $xml; |
|
156 | - exit; |
|
157 | - } |
|
158 | - |
|
159 | - function hasMethod($method) |
|
160 | - { |
|
161 | - return in_array($method, array_keys($this->callbacks)); |
|
162 | - } |
|
163 | - |
|
164 | - function setCapabilities() |
|
165 | - { |
|
166 | - // Initialises capabilities array |
|
167 | - $this->capabilities = array( |
|
168 | - 'xmlrpc' => array( |
|
169 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
170 | - 'specVersion' => 1 |
|
171 | - ), |
|
172 | - 'faults_interop' => array( |
|
173 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
174 | - 'specVersion' => 20010516 |
|
175 | - ), |
|
176 | - 'system.multicall' => array( |
|
177 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
178 | - 'specVersion' => 1 |
|
179 | - ), |
|
180 | - ); |
|
181 | - } |
|
182 | - |
|
183 | - function getCapabilities($args) |
|
184 | - { |
|
185 | - return $this->capabilities; |
|
186 | - } |
|
187 | - |
|
188 | - function setCallbacks() |
|
189 | - { |
|
190 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
191 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
192 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
193 | - } |
|
194 | - |
|
195 | - function listMethods($args) |
|
196 | - { |
|
197 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
198 | - // methods are listed before server defined methods |
|
199 | - return array_reverse(array_keys($this->callbacks)); |
|
200 | - } |
|
201 | - |
|
202 | - function multiCall($methodcalls) |
|
203 | - { |
|
204 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
205 | - $return = array(); |
|
206 | - foreach ($methodcalls as $call) { |
|
207 | - $method = $call['methodName']; |
|
208 | - $params = $call['params']; |
|
209 | - if ($method == 'system.multicall') { |
|
210 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
211 | - } else { |
|
212 | - $result = $this->call($method, $params); |
|
213 | - } |
|
214 | - if (is_a($result, 'IXR_Error')) { |
|
215 | - $return[] = array( |
|
216 | - 'faultCode' => $result->code, |
|
217 | - 'faultString' => $result->message |
|
218 | - ); |
|
219 | - } else { |
|
220 | - $return[] = array($result); |
|
221 | - } |
|
222 | - } |
|
223 | - return $return; |
|
224 | - } |
|
89 | + // Send it |
|
90 | + $this->output($xml); |
|
91 | + } |
|
92 | + |
|
93 | + function call($methodname, $args) |
|
94 | + { |
|
95 | + if (!$this->hasMethod($methodname)) { |
|
96 | + return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
|
97 | + } |
|
98 | + $method = $this->callbacks[$methodname]; |
|
99 | + |
|
100 | + // Perform the callback and send the response |
|
101 | + if (count($args) == 1) { |
|
102 | + // If only one parameter just send that instead of the whole array |
|
103 | + $args = $args[0]; |
|
104 | + } |
|
105 | + |
|
106 | + // Are we dealing with a function or a method? |
|
107 | + if (is_string($method) && substr($method, 0, 5) == 'this:') { |
|
108 | + // It's a class method - check it exists |
|
109 | + $method = substr($method, 5); |
|
110 | + if (!method_exists($this, $method)) { |
|
111 | + return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
|
112 | + } |
|
113 | + |
|
114 | + //Call the method |
|
115 | + $result = $this->$method($args); |
|
116 | + } else { |
|
117 | + // It's a function - does it exist? |
|
118 | + if (is_array($method)) { |
|
119 | + if (!is_callable(array($method[0], $method[1]))) { |
|
120 | + return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
|
121 | + } |
|
122 | + } else if (!function_exists($method)) { |
|
123 | + return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
|
124 | + } |
|
125 | + |
|
126 | + // Call the function |
|
127 | + $result = call_user_func($method, $args); |
|
128 | + } |
|
129 | + return $result; |
|
130 | + } |
|
131 | + |
|
132 | + function error($error, $message = false) |
|
133 | + { |
|
134 | + // Accepts either an error object or an error code and message |
|
135 | + if ($message && !is_object($error)) { |
|
136 | + $error = new IXR_Error($error, $message); |
|
137 | + } |
|
138 | + $this->output($error->getXml()); |
|
139 | + } |
|
140 | + |
|
141 | + function output($xml) |
|
142 | + { |
|
143 | + $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
|
144 | + if ($charset) |
|
145 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
146 | + else |
|
147 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
148 | + $length = strlen($xml); |
|
149 | + header('Connection: close'); |
|
150 | + if ($charset) |
|
151 | + header('Content-Type: text/xml; charset='.$charset); |
|
152 | + else |
|
153 | + header('Content-Type: text/xml'); |
|
154 | + header('Date: '.date('r')); |
|
155 | + echo $xml; |
|
156 | + exit; |
|
157 | + } |
|
158 | + |
|
159 | + function hasMethod($method) |
|
160 | + { |
|
161 | + return in_array($method, array_keys($this->callbacks)); |
|
162 | + } |
|
163 | + |
|
164 | + function setCapabilities() |
|
165 | + { |
|
166 | + // Initialises capabilities array |
|
167 | + $this->capabilities = array( |
|
168 | + 'xmlrpc' => array( |
|
169 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
170 | + 'specVersion' => 1 |
|
171 | + ), |
|
172 | + 'faults_interop' => array( |
|
173 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
174 | + 'specVersion' => 20010516 |
|
175 | + ), |
|
176 | + 'system.multicall' => array( |
|
177 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
178 | + 'specVersion' => 1 |
|
179 | + ), |
|
180 | + ); |
|
181 | + } |
|
182 | + |
|
183 | + function getCapabilities($args) |
|
184 | + { |
|
185 | + return $this->capabilities; |
|
186 | + } |
|
187 | + |
|
188 | + function setCallbacks() |
|
189 | + { |
|
190 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
191 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
192 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
193 | + } |
|
194 | + |
|
195 | + function listMethods($args) |
|
196 | + { |
|
197 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
198 | + // methods are listed before server defined methods |
|
199 | + return array_reverse(array_keys($this->callbacks)); |
|
200 | + } |
|
201 | + |
|
202 | + function multiCall($methodcalls) |
|
203 | + { |
|
204 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
205 | + $return = array(); |
|
206 | + foreach ($methodcalls as $call) { |
|
207 | + $method = $call['methodName']; |
|
208 | + $params = $call['params']; |
|
209 | + if ($method == 'system.multicall') { |
|
210 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
211 | + } else { |
|
212 | + $result = $this->call($method, $params); |
|
213 | + } |
|
214 | + if (is_a($result, 'IXR_Error')) { |
|
215 | + $return[] = array( |
|
216 | + 'faultCode' => $result->code, |
|
217 | + 'faultString' => $result->message |
|
218 | + ); |
|
219 | + } else { |
|
220 | + $return[] = array($result); |
|
221 | + } |
|
222 | + } |
|
223 | + return $return; |
|
224 | + } |
|
225 | 225 | } |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * PHP5 constructor. |
18 | 18 | */ |
19 | - function __construct( $callbacks = false, $data = false, $wait = false ) |
|
19 | + function __construct($callbacks = false, $data = false, $wait = false) |
|
20 | 20 | { |
21 | 21 | $this->setCapabilities(); |
22 | 22 | if ($callbacks) { |
23 | 23 | $this->callbacks = $callbacks; |
24 | 24 | } |
25 | 25 | $this->setCallbacks(); |
26 | - if (!$wait) { |
|
26 | + if ( ! $wait) { |
|
27 | 27 | $this->serve($data); |
28 | 28 | } |
29 | 29 | } |
@@ -31,17 +31,17 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * PHP4 constructor. |
33 | 33 | */ |
34 | - public function IXR_Server( $callbacks = false, $data = false, $wait = false ) { |
|
35 | - self::__construct( $callbacks, $data, $wait ); |
|
34 | + public function IXR_Server($callbacks = false, $data = false, $wait = false) { |
|
35 | + self::__construct($callbacks, $data, $wait); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function serve($data = false) |
39 | 39 | { |
40 | - if (!$data) { |
|
40 | + if ( ! $data) { |
|
41 | 41 | if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] !== 'POST') { |
42 | - if ( function_exists( 'status_header' ) ) { |
|
43 | - status_header( 405 ); // WP #20986 |
|
44 | - header( 'Allow: POST' ); |
|
42 | + if (function_exists('status_header')) { |
|
43 | + status_header(405); // WP #20986 |
|
44 | + header('Allow: POST'); |
|
45 | 45 | } |
46 | 46 | header('Content-Type: text/plain'); // merged from WP #9093 |
47 | 47 | die('XML-RPC server accepts POST requests only.'); |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | // workaround for a bug in PHP 5.2.2 - http://bugs.php.net/bug.php?id=41293 |
53 | 53 | $data = file_get_contents('php://input'); |
54 | 54 | } else { |
55 | - $data =& $HTTP_RAW_POST_DATA; |
|
55 | + $data = & $HTTP_RAW_POST_DATA; |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 | $this->message = new IXR_Message($data); |
59 | - if (!$this->message->parse()) { |
|
59 | + if ( ! $this->message->parse()) { |
|
60 | 60 | $this->error(-32700, 'parse error. not well formed'); |
61 | 61 | } |
62 | 62 | if ($this->message->messageType != 'methodCall') { |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | |
93 | 93 | function call($methodname, $args) |
94 | 94 | { |
95 | - if (!$this->hasMethod($methodname)) { |
|
95 | + if ( ! $this->hasMethod($methodname)) { |
|
96 | 96 | return new IXR_Error(-32601, 'server error. requested method '.$methodname.' does not exist.'); |
97 | 97 | } |
98 | 98 | $method = $this->callbacks[$methodname]; |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | if (is_string($method) && substr($method, 0, 5) == 'this:') { |
108 | 108 | // It's a class method - check it exists |
109 | 109 | $method = substr($method, 5); |
110 | - if (!method_exists($this, $method)) { |
|
110 | + if ( ! method_exists($this, $method)) { |
|
111 | 111 | return new IXR_Error(-32601, 'server error. requested class method "'.$method.'" does not exist.'); |
112 | 112 | } |
113 | 113 | |
@@ -116,10 +116,10 @@ discard block |
||
116 | 116 | } else { |
117 | 117 | // It's a function - does it exist? |
118 | 118 | if (is_array($method)) { |
119 | - if (!is_callable(array($method[0], $method[1]))) { |
|
119 | + if ( ! is_callable(array($method[0], $method[1]))) { |
|
120 | 120 | return new IXR_Error(-32601, 'server error. requested object method "'.$method[1].'" does not exist.'); |
121 | 121 | } |
122 | - } else if (!function_exists($method)) { |
|
122 | + } else if ( ! function_exists($method)) { |
|
123 | 123 | return new IXR_Error(-32601, 'server error. requested function "'.$method.'" does not exist.'); |
124 | 124 | } |
125 | 125 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | function error($error, $message = false) |
133 | 133 | { |
134 | 134 | // Accepts either an error object or an error code and message |
135 | - if ($message && !is_object($error)) { |
|
135 | + if ($message && ! is_object($error)) { |
|
136 | 136 | $error = new IXR_Error($error, $message); |
137 | 137 | } |
138 | 138 | $this->output($error->getXml()); |
@@ -534,17 +534,19 @@ |
||
534 | 534 | function output($xml) |
535 | 535 | { |
536 | 536 | $charset = function_exists('get_option') ? get_option('blog_charset') : ''; |
537 | - if ($charset) |
|
538 | - $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
539 | - else |
|
540 | - $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
537 | + if ($charset) { |
|
538 | + $xml = '<?xml version="1.0" encoding="'.$charset.'"?>'."\n".$xml; |
|
539 | + } else { |
|
540 | + $xml = '<?xml version="1.0"?>'."\n".$xml; |
|
541 | + } |
|
541 | 542 | $length = strlen($xml); |
542 | 543 | header('Connection: close'); |
543 | 544 | header('Content-Length: '.$length); |
544 | - if ($charset) |
|
545 | - header('Content-Type: text/xml; charset='.$charset); |
|
546 | - else |
|
547 | - header('Content-Type: text/xml'); |
|
545 | + if ($charset) { |
|
546 | + header('Content-Type: text/xml; charset='.$charset); |
|
547 | + } else { |
|
548 | + header('Content-Type: text/xml'); |
|
549 | + } |
|
548 | 550 | header('Date: '.date('r')); |
549 | 551 | echo $xml; |
550 | 552 | exit; |
@@ -8,17 +8,17 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class IXR_Error |
10 | 10 | { |
11 | - var $code; |
|
12 | - var $message; |
|
11 | + var $code; |
|
12 | + var $message; |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * PHP5 constructor. |
16 | 16 | */ |
17 | - function __construct( $code, $message ) |
|
18 | - { |
|
19 | - $this->code = $code; |
|
20 | - $this->message = htmlspecialchars($message); |
|
21 | - } |
|
17 | + function __construct( $code, $message ) |
|
18 | + { |
|
19 | + $this->code = $code; |
|
20 | + $this->message = htmlspecialchars($message); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * PHP4 constructor. |
@@ -27,9 +27,9 @@ discard block |
||
27 | 27 | self::__construct( $code, $message ); |
28 | 28 | } |
29 | 29 | |
30 | - function getXml() |
|
31 | - { |
|
32 | - $xml = <<<EOD |
|
30 | + function getXml() |
|
31 | + { |
|
32 | + $xml = <<<EOD |
|
33 | 33 | <methodResponse> |
34 | 34 | <fault> |
35 | 35 | <value> |
@@ -48,6 +48,6 @@ discard block |
||
48 | 48 | </methodResponse> |
49 | 49 | |
50 | 50 | EOD; |
51 | - return $xml; |
|
52 | - } |
|
51 | + return $xml; |
|
52 | + } |
|
53 | 53 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * PHP5 constructor. |
16 | 16 | */ |
17 | - function __construct( $code, $message ) |
|
17 | + function __construct($code, $message) |
|
18 | 18 | { |
19 | 19 | $this->code = $code; |
20 | 20 | $this->message = htmlspecialchars($message); |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * PHP4 constructor. |
25 | 25 | */ |
26 | - public function IXR_Error( $code, $message ) { |
|
27 | - self::__construct( $code, $message ); |
|
26 | + public function IXR_Error($code, $message) { |
|
27 | + self::__construct($code, $message); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | function getXml() |
@@ -8,32 +8,32 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class IXR_Request |
10 | 10 | { |
11 | - var $method; |
|
12 | - var $args; |
|
13 | - var $xml; |
|
11 | + var $method; |
|
12 | + var $args; |
|
13 | + var $xml; |
|
14 | 14 | |
15 | 15 | /** |
16 | 16 | * PHP5 constructor. |
17 | 17 | */ |
18 | - function __construct($method, $args) |
|
19 | - { |
|
20 | - $this->method = $method; |
|
21 | - $this->args = $args; |
|
22 | - $this->xml = <<<EOD |
|
18 | + function __construct($method, $args) |
|
19 | + { |
|
20 | + $this->method = $method; |
|
21 | + $this->args = $args; |
|
22 | + $this->xml = <<<EOD |
|
23 | 23 | <?xml version="1.0"?> |
24 | 24 | <methodCall> |
25 | 25 | <methodName>{$this->method}</methodName> |
26 | 26 | <params> |
27 | 27 | |
28 | 28 | EOD; |
29 | - foreach ($this->args as $arg) { |
|
30 | - $this->xml .= '<param><value>'; |
|
31 | - $v = new IXR_Value($arg); |
|
32 | - $this->xml .= $v->getXml(); |
|
33 | - $this->xml .= "</value></param>\n"; |
|
34 | - } |
|
35 | - $this->xml .= '</params></methodCall>'; |
|
36 | - } |
|
29 | + foreach ($this->args as $arg) { |
|
30 | + $this->xml .= '<param><value>'; |
|
31 | + $v = new IXR_Value($arg); |
|
32 | + $this->xml .= $v->getXml(); |
|
33 | + $this->xml .= "</value></param>\n"; |
|
34 | + } |
|
35 | + $this->xml .= '</params></methodCall>'; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * PHP4 constructor. |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | self::__construct( $method, $args ); |
43 | 43 | } |
44 | 44 | |
45 | - function getLength() |
|
46 | - { |
|
47 | - return strlen($this->xml); |
|
48 | - } |
|
45 | + function getLength() |
|
46 | + { |
|
47 | + return strlen($this->xml); |
|
48 | + } |
|
49 | 49 | |
50 | - function getXml() |
|
51 | - { |
|
52 | - return $this->xml; |
|
53 | - } |
|
50 | + function getXml() |
|
51 | + { |
|
52 | + return $this->xml; |
|
53 | + } |
|
54 | 54 | } |
@@ -38,8 +38,8 @@ |
||
38 | 38 | /** |
39 | 39 | * PHP4 constructor. |
40 | 40 | */ |
41 | - public function IXR_Request( $method, $args ) { |
|
42 | - self::__construct( $method, $args ); |
|
41 | + public function IXR_Request($method, $args) { |
|
42 | + self::__construct($method, $args); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function getLength() |
@@ -9,47 +9,47 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class IXR_Client |
11 | 11 | { |
12 | - var $server; |
|
13 | - var $port; |
|
14 | - var $path; |
|
15 | - var $useragent; |
|
16 | - var $response; |
|
17 | - var $message = false; |
|
18 | - var $debug = false; |
|
19 | - var $timeout; |
|
20 | - var $headers = array(); |
|
21 | - |
|
22 | - // Storage place for an error message |
|
23 | - var $error = false; |
|
12 | + var $server; |
|
13 | + var $port; |
|
14 | + var $path; |
|
15 | + var $useragent; |
|
16 | + var $response; |
|
17 | + var $message = false; |
|
18 | + var $debug = false; |
|
19 | + var $timeout; |
|
20 | + var $headers = array(); |
|
21 | + |
|
22 | + // Storage place for an error message |
|
23 | + var $error = false; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * PHP5 constructor. |
27 | 27 | */ |
28 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
29 | - { |
|
30 | - if (!$path) { |
|
31 | - // Assume we have been given a URL instead |
|
32 | - $bits = parse_url($server); |
|
33 | - $this->server = $bits['host']; |
|
34 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
35 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
36 | - |
|
37 | - // Make absolutely sure we have a path |
|
38 | - if (!$this->path) { |
|
39 | - $this->path = '/'; |
|
40 | - } |
|
41 | - |
|
42 | - if ( ! empty( $bits['query'] ) ) { |
|
43 | - $this->path .= '?' . $bits['query']; |
|
44 | - } |
|
45 | - } else { |
|
46 | - $this->server = $server; |
|
47 | - $this->path = $path; |
|
48 | - $this->port = $port; |
|
49 | - } |
|
50 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
51 | - $this->timeout = $timeout; |
|
52 | - } |
|
28 | + function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
29 | + { |
|
30 | + if (!$path) { |
|
31 | + // Assume we have been given a URL instead |
|
32 | + $bits = parse_url($server); |
|
33 | + $this->server = $bits['host']; |
|
34 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
35 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
36 | + |
|
37 | + // Make absolutely sure we have a path |
|
38 | + if (!$this->path) { |
|
39 | + $this->path = '/'; |
|
40 | + } |
|
41 | + |
|
42 | + if ( ! empty( $bits['query'] ) ) { |
|
43 | + $this->path .= '?' . $bits['query']; |
|
44 | + } |
|
45 | + } else { |
|
46 | + $this->server = $server; |
|
47 | + $this->path = $path; |
|
48 | + $this->port = $port; |
|
49 | + } |
|
50 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
51 | + $this->timeout = $timeout; |
|
52 | + } |
|
53 | 53 | |
54 | 54 | /** |
55 | 55 | * PHP4 constructor. |
@@ -58,109 +58,109 @@ discard block |
||
58 | 58 | self::__construct( $server, $path, $port, $timeout ); |
59 | 59 | } |
60 | 60 | |
61 | - function query() |
|
62 | - { |
|
63 | - $args = func_get_args(); |
|
64 | - $method = array_shift($args); |
|
65 | - $request = new IXR_Request($method, $args); |
|
66 | - $length = $request->getLength(); |
|
67 | - $xml = $request->getXml(); |
|
68 | - $r = "\r\n"; |
|
69 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
70 | - |
|
71 | - // Merged from WP #8145 - allow custom headers |
|
72 | - $this->headers['Host'] = $this->server; |
|
73 | - $this->headers['Content-Type'] = 'text/xml'; |
|
74 | - $this->headers['User-Agent'] = $this->useragent; |
|
75 | - $this->headers['Content-Length']= $length; |
|
76 | - |
|
77 | - foreach( $this->headers as $header => $value ) { |
|
78 | - $request .= "{$header}: {$value}{$r}"; |
|
79 | - } |
|
80 | - $request .= $r; |
|
81 | - |
|
82 | - $request .= $xml; |
|
83 | - |
|
84 | - // Now send the request |
|
85 | - if ($this->debug) { |
|
86 | - echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
87 | - } |
|
88 | - |
|
89 | - if ($this->timeout) { |
|
90 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
91 | - } else { |
|
92 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
93 | - } |
|
94 | - if (!$fp) { |
|
95 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
96 | - return false; |
|
97 | - } |
|
98 | - fputs($fp, $request); |
|
99 | - $contents = ''; |
|
100 | - $debugContents = ''; |
|
101 | - $gotFirstLine = false; |
|
102 | - $gettingHeaders = true; |
|
103 | - while (!feof($fp)) { |
|
104 | - $line = fgets($fp, 4096); |
|
105 | - if (!$gotFirstLine) { |
|
106 | - // Check line for '200' |
|
107 | - if (strstr($line, '200') === false) { |
|
108 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
109 | - return false; |
|
110 | - } |
|
111 | - $gotFirstLine = true; |
|
112 | - } |
|
113 | - if (trim($line) == '') { |
|
114 | - $gettingHeaders = false; |
|
115 | - } |
|
116 | - if (!$gettingHeaders) { |
|
117 | - // merged from WP #12559 - remove trim |
|
118 | - $contents .= $line; |
|
119 | - } |
|
120 | - if ($this->debug) { |
|
121 | - $debugContents .= $line; |
|
122 | - } |
|
123 | - } |
|
124 | - if ($this->debug) { |
|
125 | - echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
126 | - } |
|
127 | - |
|
128 | - // Now parse what we've got back |
|
129 | - $this->message = new IXR_Message($contents); |
|
130 | - if (!$this->message->parse()) { |
|
131 | - // XML error |
|
132 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
133 | - return false; |
|
134 | - } |
|
135 | - |
|
136 | - // Is the message a fault? |
|
137 | - if ($this->message->messageType == 'fault') { |
|
138 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
139 | - return false; |
|
140 | - } |
|
141 | - |
|
142 | - // Message must be OK |
|
143 | - return true; |
|
144 | - } |
|
145 | - |
|
146 | - function getResponse() |
|
147 | - { |
|
148 | - // methodResponses can only have one param - return that |
|
149 | - return $this->message->params[0]; |
|
150 | - } |
|
151 | - |
|
152 | - function isError() |
|
153 | - { |
|
154 | - return (is_object($this->error)); |
|
155 | - } |
|
156 | - |
|
157 | - function getErrorCode() |
|
158 | - { |
|
159 | - return $this->error->code; |
|
160 | - } |
|
161 | - |
|
162 | - function getErrorMessage() |
|
163 | - { |
|
164 | - return $this->error->message; |
|
165 | - } |
|
61 | + function query() |
|
62 | + { |
|
63 | + $args = func_get_args(); |
|
64 | + $method = array_shift($args); |
|
65 | + $request = new IXR_Request($method, $args); |
|
66 | + $length = $request->getLength(); |
|
67 | + $xml = $request->getXml(); |
|
68 | + $r = "\r\n"; |
|
69 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
70 | + |
|
71 | + // Merged from WP #8145 - allow custom headers |
|
72 | + $this->headers['Host'] = $this->server; |
|
73 | + $this->headers['Content-Type'] = 'text/xml'; |
|
74 | + $this->headers['User-Agent'] = $this->useragent; |
|
75 | + $this->headers['Content-Length']= $length; |
|
76 | + |
|
77 | + foreach( $this->headers as $header => $value ) { |
|
78 | + $request .= "{$header}: {$value}{$r}"; |
|
79 | + } |
|
80 | + $request .= $r; |
|
81 | + |
|
82 | + $request .= $xml; |
|
83 | + |
|
84 | + // Now send the request |
|
85 | + if ($this->debug) { |
|
86 | + echo '<pre class="ixr_request">'.htmlspecialchars($request)."\n</pre>\n\n"; |
|
87 | + } |
|
88 | + |
|
89 | + if ($this->timeout) { |
|
90 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
91 | + } else { |
|
92 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
|
93 | + } |
|
94 | + if (!$fp) { |
|
95 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
96 | + return false; |
|
97 | + } |
|
98 | + fputs($fp, $request); |
|
99 | + $contents = ''; |
|
100 | + $debugContents = ''; |
|
101 | + $gotFirstLine = false; |
|
102 | + $gettingHeaders = true; |
|
103 | + while (!feof($fp)) { |
|
104 | + $line = fgets($fp, 4096); |
|
105 | + if (!$gotFirstLine) { |
|
106 | + // Check line for '200' |
|
107 | + if (strstr($line, '200') === false) { |
|
108 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
109 | + return false; |
|
110 | + } |
|
111 | + $gotFirstLine = true; |
|
112 | + } |
|
113 | + if (trim($line) == '') { |
|
114 | + $gettingHeaders = false; |
|
115 | + } |
|
116 | + if (!$gettingHeaders) { |
|
117 | + // merged from WP #12559 - remove trim |
|
118 | + $contents .= $line; |
|
119 | + } |
|
120 | + if ($this->debug) { |
|
121 | + $debugContents .= $line; |
|
122 | + } |
|
123 | + } |
|
124 | + if ($this->debug) { |
|
125 | + echo '<pre class="ixr_response">'.htmlspecialchars($debugContents)."\n</pre>\n\n"; |
|
126 | + } |
|
127 | + |
|
128 | + // Now parse what we've got back |
|
129 | + $this->message = new IXR_Message($contents); |
|
130 | + if (!$this->message->parse()) { |
|
131 | + // XML error |
|
132 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
133 | + return false; |
|
134 | + } |
|
135 | + |
|
136 | + // Is the message a fault? |
|
137 | + if ($this->message->messageType == 'fault') { |
|
138 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
139 | + return false; |
|
140 | + } |
|
141 | + |
|
142 | + // Message must be OK |
|
143 | + return true; |
|
144 | + } |
|
145 | + |
|
146 | + function getResponse() |
|
147 | + { |
|
148 | + // methodResponses can only have one param - return that |
|
149 | + return $this->message->params[0]; |
|
150 | + } |
|
151 | + |
|
152 | + function isError() |
|
153 | + { |
|
154 | + return (is_object($this->error)); |
|
155 | + } |
|
156 | + |
|
157 | + function getErrorCode() |
|
158 | + { |
|
159 | + return $this->error->code; |
|
160 | + } |
|
161 | + |
|
162 | + function getErrorMessage() |
|
163 | + { |
|
164 | + return $this->error->message; |
|
165 | + } |
|
166 | 166 | } |
@@ -25,9 +25,9 @@ discard block |
||
25 | 25 | /** |
26 | 26 | * PHP5 constructor. |
27 | 27 | */ |
28 | - function __construct( $server, $path = false, $port = 80, $timeout = 15 ) |
|
28 | + function __construct($server, $path = false, $port = 80, $timeout = 15) |
|
29 | 29 | { |
30 | - if (!$path) { |
|
30 | + if ( ! $path) { |
|
31 | 31 | // Assume we have been given a URL instead |
32 | 32 | $bits = parse_url($server); |
33 | 33 | $this->server = $bits['host']; |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
36 | 36 | |
37 | 37 | // Make absolutely sure we have a path |
38 | - if (!$this->path) { |
|
38 | + if ( ! $this->path) { |
|
39 | 39 | $this->path = '/'; |
40 | 40 | } |
41 | 41 | |
42 | - if ( ! empty( $bits['query'] ) ) { |
|
43 | - $this->path .= '?' . $bits['query']; |
|
42 | + if ( ! empty($bits['query'])) { |
|
43 | + $this->path .= '?'.$bits['query']; |
|
44 | 44 | } |
45 | 45 | } else { |
46 | 46 | $this->server = $server; |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * PHP4 constructor. |
56 | 56 | */ |
57 | - public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) { |
|
58 | - self::__construct( $server, $path, $port, $timeout ); |
|
57 | + public function IXR_Client($server, $path = false, $port = 80, $timeout = 15) { |
|
58 | + self::__construct($server, $path, $port, $timeout); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | function query() |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | $length = $request->getLength(); |
67 | 67 | $xml = $request->getXml(); |
68 | 68 | $r = "\r\n"; |
69 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
69 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
70 | 70 | |
71 | 71 | // Merged from WP #8145 - allow custom headers |
72 | 72 | $this->headers['Host'] = $this->server; |
73 | 73 | $this->headers['Content-Type'] = 'text/xml'; |
74 | 74 | $this->headers['User-Agent'] = $this->useragent; |
75 | - $this->headers['Content-Length']= $length; |
|
75 | + $this->headers['Content-Length'] = $length; |
|
76 | 76 | |
77 | - foreach( $this->headers as $header => $value ) { |
|
77 | + foreach ($this->headers as $header => $value) { |
|
78 | 78 | $request .= "{$header}: {$value}{$r}"; |
79 | 79 | } |
80 | 80 | $request .= $r; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } else { |
92 | 92 | $fp = @fsockopen($this->server, $this->port, $errno, $errstr); |
93 | 93 | } |
94 | - if (!$fp) { |
|
94 | + if ( ! $fp) { |
|
95 | 95 | $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
96 | 96 | return false; |
97 | 97 | } |
@@ -100,9 +100,9 @@ discard block |
||
100 | 100 | $debugContents = ''; |
101 | 101 | $gotFirstLine = false; |
102 | 102 | $gettingHeaders = true; |
103 | - while (!feof($fp)) { |
|
103 | + while ( ! feof($fp)) { |
|
104 | 104 | $line = fgets($fp, 4096); |
105 | - if (!$gotFirstLine) { |
|
105 | + if ( ! $gotFirstLine) { |
|
106 | 106 | // Check line for '200' |
107 | 107 | if (strstr($line, '200') === false) { |
108 | 108 | $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | if (trim($line) == '') { |
114 | 114 | $gettingHeaders = false; |
115 | 115 | } |
116 | - if (!$gettingHeaders) { |
|
116 | + if ( ! $gettingHeaders) { |
|
117 | 117 | // merged from WP #12559 - remove trim |
118 | 118 | $contents .= $line; |
119 | 119 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | |
128 | 128 | // Now parse what we've got back |
129 | 129 | $this->message = new IXR_Message($contents); |
130 | - if (!$this->message->parse()) { |
|
130 | + if ( ! $this->message->parse()) { |
|
131 | 131 | // XML error |
132 | 132 | $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
133 | 133 | return false; |
@@ -7,26 +7,26 @@ discard block |
||
7 | 7 | * @since 1.5.0 |
8 | 8 | */ |
9 | 9 | class IXR_Date { |
10 | - var $year; |
|
11 | - var $month; |
|
12 | - var $day; |
|
13 | - var $hour; |
|
14 | - var $minute; |
|
15 | - var $second; |
|
16 | - var $timezone; |
|
10 | + var $year; |
|
11 | + var $month; |
|
12 | + var $day; |
|
13 | + var $hour; |
|
14 | + var $minute; |
|
15 | + var $second; |
|
16 | + var $timezone; |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * PHP5 constructor. |
20 | 20 | */ |
21 | - function __construct( $time ) |
|
22 | - { |
|
23 | - // $time can be a PHP timestamp or an ISO one |
|
24 | - if (is_numeric($time)) { |
|
25 | - $this->parseTimestamp($time); |
|
26 | - } else { |
|
27 | - $this->parseIso($time); |
|
28 | - } |
|
29 | - } |
|
21 | + function __construct( $time ) |
|
22 | + { |
|
23 | + // $time can be a PHP timestamp or an ISO one |
|
24 | + if (is_numeric($time)) { |
|
25 | + $this->parseTimestamp($time); |
|
26 | + } else { |
|
27 | + $this->parseIso($time); |
|
28 | + } |
|
29 | + } |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * PHP4 constructor. |
@@ -35,40 +35,40 @@ discard block |
||
35 | 35 | self::__construct( $time ); |
36 | 36 | } |
37 | 37 | |
38 | - function parseTimestamp($timestamp) |
|
39 | - { |
|
40 | - $this->year = date('Y', $timestamp); |
|
41 | - $this->month = date('m', $timestamp); |
|
42 | - $this->day = date('d', $timestamp); |
|
43 | - $this->hour = date('H', $timestamp); |
|
44 | - $this->minute = date('i', $timestamp); |
|
45 | - $this->second = date('s', $timestamp); |
|
46 | - $this->timezone = ''; |
|
47 | - } |
|
38 | + function parseTimestamp($timestamp) |
|
39 | + { |
|
40 | + $this->year = date('Y', $timestamp); |
|
41 | + $this->month = date('m', $timestamp); |
|
42 | + $this->day = date('d', $timestamp); |
|
43 | + $this->hour = date('H', $timestamp); |
|
44 | + $this->minute = date('i', $timestamp); |
|
45 | + $this->second = date('s', $timestamp); |
|
46 | + $this->timezone = ''; |
|
47 | + } |
|
48 | 48 | |
49 | - function parseIso($iso) |
|
50 | - { |
|
51 | - $this->year = substr($iso, 0, 4); |
|
52 | - $this->month = substr($iso, 4, 2); |
|
53 | - $this->day = substr($iso, 6, 2); |
|
54 | - $this->hour = substr($iso, 9, 2); |
|
55 | - $this->minute = substr($iso, 12, 2); |
|
56 | - $this->second = substr($iso, 15, 2); |
|
57 | - $this->timezone = substr($iso, 17); |
|
58 | - } |
|
49 | + function parseIso($iso) |
|
50 | + { |
|
51 | + $this->year = substr($iso, 0, 4); |
|
52 | + $this->month = substr($iso, 4, 2); |
|
53 | + $this->day = substr($iso, 6, 2); |
|
54 | + $this->hour = substr($iso, 9, 2); |
|
55 | + $this->minute = substr($iso, 12, 2); |
|
56 | + $this->second = substr($iso, 15, 2); |
|
57 | + $this->timezone = substr($iso, 17); |
|
58 | + } |
|
59 | 59 | |
60 | - function getIso() |
|
61 | - { |
|
62 | - return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
63 | - } |
|
60 | + function getIso() |
|
61 | + { |
|
62 | + return $this->year.$this->month.$this->day.'T'.$this->hour.':'.$this->minute.':'.$this->second.$this->timezone; |
|
63 | + } |
|
64 | 64 | |
65 | - function getXml() |
|
66 | - { |
|
67 | - return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
68 | - } |
|
65 | + function getXml() |
|
66 | + { |
|
67 | + return '<dateTime.iso8601>'.$this->getIso().'</dateTime.iso8601>'; |
|
68 | + } |
|
69 | 69 | |
70 | - function getTimestamp() |
|
71 | - { |
|
72 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
73 | - } |
|
70 | + function getTimestamp() |
|
71 | + { |
|
72 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
73 | + } |
|
74 | 74 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | /** |
19 | 19 | * PHP5 constructor. |
20 | 20 | */ |
21 | - function __construct( $time ) |
|
21 | + function __construct($time) |
|
22 | 22 | { |
23 | 23 | // $time can be a PHP timestamp or an ISO one |
24 | 24 | if (is_numeric($time)) { |
@@ -31,8 +31,8 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * PHP4 constructor. |
33 | 33 | */ |
34 | - public function IXR_Date( $time ) { |
|
35 | - self::__construct( $time ); |
|
34 | + public function IXR_Date($time) { |
|
35 | + self::__construct($time); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | function parseTimestamp($timestamp) |
@@ -6,31 +6,31 @@ discard block |
||
6 | 6 | * @since 1.5.0 |
7 | 7 | */ |
8 | 8 | class IXR_Value { |
9 | - var $data; |
|
10 | - var $type; |
|
9 | + var $data; |
|
10 | + var $type; |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * PHP5 constructor. |
14 | 14 | */ |
15 | 15 | function __construct( $data, $type = false ) |
16 | - { |
|
17 | - $this->data = $data; |
|
18 | - if (!$type) { |
|
19 | - $type = $this->calculateType(); |
|
20 | - } |
|
21 | - $this->type = $type; |
|
22 | - if ($type == 'struct') { |
|
23 | - // Turn all the values in the array in to new IXR_Value objects |
|
24 | - foreach ($this->data as $key => $value) { |
|
25 | - $this->data[$key] = new IXR_Value($value); |
|
26 | - } |
|
27 | - } |
|
28 | - if ($type == 'array') { |
|
29 | - for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
30 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
31 | - } |
|
32 | - } |
|
33 | - } |
|
16 | + { |
|
17 | + $this->data = $data; |
|
18 | + if (!$type) { |
|
19 | + $type = $this->calculateType(); |
|
20 | + } |
|
21 | + $this->type = $type; |
|
22 | + if ($type == 'struct') { |
|
23 | + // Turn all the values in the array in to new IXR_Value objects |
|
24 | + foreach ($this->data as $key => $value) { |
|
25 | + $this->data[$key] = new IXR_Value($value); |
|
26 | + } |
|
27 | + } |
|
28 | + if ($type == 'array') { |
|
29 | + for ($i = 0, $j = count($this->data); $i < $j; $i++) { |
|
30 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
31 | + } |
|
32 | + } |
|
33 | + } |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * PHP4 constructor. |
@@ -39,100 +39,100 @@ discard block |
||
39 | 39 | self::__construct( $data, $type ); |
40 | 40 | } |
41 | 41 | |
42 | - function calculateType() |
|
43 | - { |
|
44 | - if ($this->data === true || $this->data === false) { |
|
45 | - return 'boolean'; |
|
46 | - } |
|
47 | - if (is_integer($this->data)) { |
|
48 | - return 'int'; |
|
49 | - } |
|
50 | - if (is_double($this->data)) { |
|
51 | - return 'double'; |
|
52 | - } |
|
42 | + function calculateType() |
|
43 | + { |
|
44 | + if ($this->data === true || $this->data === false) { |
|
45 | + return 'boolean'; |
|
46 | + } |
|
47 | + if (is_integer($this->data)) { |
|
48 | + return 'int'; |
|
49 | + } |
|
50 | + if (is_double($this->data)) { |
|
51 | + return 'double'; |
|
52 | + } |
|
53 | 53 | |
54 | - // Deal with IXR object types base64 and date |
|
55 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
56 | - return 'date'; |
|
57 | - } |
|
58 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
59 | - return 'base64'; |
|
60 | - } |
|
54 | + // Deal with IXR object types base64 and date |
|
55 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
56 | + return 'date'; |
|
57 | + } |
|
58 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
59 | + return 'base64'; |
|
60 | + } |
|
61 | 61 | |
62 | - // If it is a normal PHP object convert it in to a struct |
|
63 | - if (is_object($this->data)) { |
|
64 | - $this->data = get_object_vars($this->data); |
|
65 | - return 'struct'; |
|
66 | - } |
|
67 | - if (!is_array($this->data)) { |
|
68 | - return 'string'; |
|
69 | - } |
|
62 | + // If it is a normal PHP object convert it in to a struct |
|
63 | + if (is_object($this->data)) { |
|
64 | + $this->data = get_object_vars($this->data); |
|
65 | + return 'struct'; |
|
66 | + } |
|
67 | + if (!is_array($this->data)) { |
|
68 | + return 'string'; |
|
69 | + } |
|
70 | 70 | |
71 | - // We have an array - is it an array or a struct? |
|
72 | - if ($this->isStruct($this->data)) { |
|
73 | - return 'struct'; |
|
74 | - } else { |
|
75 | - return 'array'; |
|
76 | - } |
|
77 | - } |
|
71 | + // We have an array - is it an array or a struct? |
|
72 | + if ($this->isStruct($this->data)) { |
|
73 | + return 'struct'; |
|
74 | + } else { |
|
75 | + return 'array'; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - function getXml() |
|
80 | - { |
|
81 | - // Return XML for this value |
|
82 | - switch ($this->type) { |
|
83 | - case 'boolean': |
|
84 | - return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
85 | - break; |
|
86 | - case 'int': |
|
87 | - return '<int>'.$this->data.'</int>'; |
|
88 | - break; |
|
89 | - case 'double': |
|
90 | - return '<double>'.$this->data.'</double>'; |
|
91 | - break; |
|
92 | - case 'string': |
|
93 | - return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
94 | - break; |
|
95 | - case 'array': |
|
96 | - $return = '<array><data>'."\n"; |
|
97 | - foreach ($this->data as $item) { |
|
98 | - $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
99 | - } |
|
100 | - $return .= '</data></array>'; |
|
101 | - return $return; |
|
102 | - break; |
|
103 | - case 'struct': |
|
104 | - $return = '<struct>'."\n"; |
|
105 | - foreach ($this->data as $name => $value) { |
|
79 | + function getXml() |
|
80 | + { |
|
81 | + // Return XML for this value |
|
82 | + switch ($this->type) { |
|
83 | + case 'boolean': |
|
84 | + return '<boolean>'.(($this->data) ? '1' : '0').'</boolean>'; |
|
85 | + break; |
|
86 | + case 'int': |
|
87 | + return '<int>'.$this->data.'</int>'; |
|
88 | + break; |
|
89 | + case 'double': |
|
90 | + return '<double>'.$this->data.'</double>'; |
|
91 | + break; |
|
92 | + case 'string': |
|
93 | + return '<string>'.htmlspecialchars($this->data).'</string>'; |
|
94 | + break; |
|
95 | + case 'array': |
|
96 | + $return = '<array><data>'."\n"; |
|
97 | + foreach ($this->data as $item) { |
|
98 | + $return .= ' <value>'.$item->getXml()."</value>\n"; |
|
99 | + } |
|
100 | + $return .= '</data></array>'; |
|
101 | + return $return; |
|
102 | + break; |
|
103 | + case 'struct': |
|
104 | + $return = '<struct>'."\n"; |
|
105 | + foreach ($this->data as $name => $value) { |
|
106 | 106 | $name = htmlspecialchars($name); |
107 | - $return .= " <member><name>$name</name><value>"; |
|
108 | - $return .= $value->getXml()."</value></member>\n"; |
|
109 | - } |
|
110 | - $return .= '</struct>'; |
|
111 | - return $return; |
|
112 | - break; |
|
113 | - case 'date': |
|
114 | - case 'base64': |
|
115 | - return $this->data->getXml(); |
|
116 | - break; |
|
117 | - } |
|
118 | - return false; |
|
119 | - } |
|
107 | + $return .= " <member><name>$name</name><value>"; |
|
108 | + $return .= $value->getXml()."</value></member>\n"; |
|
109 | + } |
|
110 | + $return .= '</struct>'; |
|
111 | + return $return; |
|
112 | + break; |
|
113 | + case 'date': |
|
114 | + case 'base64': |
|
115 | + return $this->data->getXml(); |
|
116 | + break; |
|
117 | + } |
|
118 | + return false; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Checks whether or not the supplied array is a struct or not |
|
123 | - * |
|
124 | - * @param array $array |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - function isStruct($array) |
|
128 | - { |
|
129 | - $expected = 0; |
|
130 | - foreach ($array as $key => $value) { |
|
131 | - if ((string)$key !== (string)$expected) { |
|
132 | - return true; |
|
133 | - } |
|
134 | - $expected++; |
|
135 | - } |
|
136 | - return false; |
|
137 | - } |
|
121 | + /** |
|
122 | + * Checks whether or not the supplied array is a struct or not |
|
123 | + * |
|
124 | + * @param array $array |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + function isStruct($array) |
|
128 | + { |
|
129 | + $expected = 0; |
|
130 | + foreach ($array as $key => $value) { |
|
131 | + if ((string)$key !== (string)$expected) { |
|
132 | + return true; |
|
133 | + } |
|
134 | + $expected++; |
|
135 | + } |
|
136 | + return false; |
|
137 | + } |
|
138 | 138 | } |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * PHP5 constructor. |
14 | 14 | */ |
15 | - function __construct( $data, $type = false ) |
|
15 | + function __construct($data, $type = false) |
|
16 | 16 | { |
17 | 17 | $this->data = $data; |
18 | - if (!$type) { |
|
18 | + if ( ! $type) { |
|
19 | 19 | $type = $this->calculateType(); |
20 | 20 | } |
21 | 21 | $this->type = $type; |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | /** |
36 | 36 | * PHP4 constructor. |
37 | 37 | */ |
38 | - public function IXR_Value( $data, $type = false ) { |
|
39 | - self::__construct( $data, $type ); |
|
38 | + public function IXR_Value($data, $type = false) { |
|
39 | + self::__construct($data, $type); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | function calculateType() |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $this->data = get_object_vars($this->data); |
65 | 65 | return 'struct'; |
66 | 66 | } |
67 | - if (!is_array($this->data)) { |
|
67 | + if ( ! is_array($this->data)) { |
|
68 | 68 | return 'string'; |
69 | 69 | } |
70 | 70 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | { |
129 | 129 | $expected = 0; |
130 | 130 | foreach ($array as $key => $value) { |
131 | - if ((string)$key !== (string)$expected) { |
|
131 | + if ((string) $key !== (string) $expected) { |
|
132 | 132 | return true; |
133 | 133 | } |
134 | 134 | $expected++; |
@@ -7,16 +7,16 @@ discard block |
||
7 | 7 | */ |
8 | 8 | class IXR_ClientMulticall extends IXR_Client |
9 | 9 | { |
10 | - var $calls = array(); |
|
10 | + var $calls = array(); |
|
11 | 11 | |
12 | 12 | /** |
13 | 13 | * PHP5 constructor. |
14 | 14 | */ |
15 | - function __construct( $server, $path = false, $port = 80 ) |
|
16 | - { |
|
17 | - parent::IXR_Client($server, $path, $port); |
|
18 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
19 | - } |
|
15 | + function __construct( $server, $path = false, $port = 80 ) |
|
16 | + { |
|
17 | + parent::IXR_Client($server, $path, $port); |
|
18 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
19 | + } |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * PHP4 constructor. |
@@ -25,20 +25,20 @@ discard block |
||
25 | 25 | self::__construct( $server, $path, $port ); |
26 | 26 | } |
27 | 27 | |
28 | - function addCall() |
|
29 | - { |
|
30 | - $args = func_get_args(); |
|
31 | - $methodName = array_shift($args); |
|
32 | - $struct = array( |
|
33 | - 'methodName' => $methodName, |
|
34 | - 'params' => $args |
|
35 | - ); |
|
36 | - $this->calls[] = $struct; |
|
37 | - } |
|
28 | + function addCall() |
|
29 | + { |
|
30 | + $args = func_get_args(); |
|
31 | + $methodName = array_shift($args); |
|
32 | + $struct = array( |
|
33 | + 'methodName' => $methodName, |
|
34 | + 'params' => $args |
|
35 | + ); |
|
36 | + $this->calls[] = $struct; |
|
37 | + } |
|
38 | 38 | |
39 | - function query() |
|
40 | - { |
|
41 | - // Prepare multicall, then call the parent::query() method |
|
42 | - return parent::query('system.multicall', $this->calls); |
|
43 | - } |
|
39 | + function query() |
|
40 | + { |
|
41 | + // Prepare multicall, then call the parent::query() method |
|
42 | + return parent::query('system.multicall', $this->calls); |
|
43 | + } |
|
44 | 44 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | /** |
13 | 13 | * PHP5 constructor. |
14 | 14 | */ |
15 | - function __construct( $server, $path = false, $port = 80 ) |
|
15 | + function __construct($server, $path = false, $port = 80) |
|
16 | 16 | { |
17 | 17 | parent::IXR_Client($server, $path, $port); |
18 | 18 | $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * PHP4 constructor. |
23 | 23 | */ |
24 | - public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) { |
|
25 | - self::__construct( $server, $path, $port ); |
|
24 | + public function IXR_ClientMulticall($server, $path = false, $port = 80) { |
|
25 | + self::__construct($server, $path, $port); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | function addCall() |
@@ -9,31 +9,31 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class IXR_Message |
11 | 11 | { |
12 | - var $message; |
|
13 | - var $messageType; // methodCall / methodResponse / fault |
|
14 | - var $faultCode; |
|
15 | - var $faultString; |
|
16 | - var $methodName; |
|
17 | - var $params; |
|
18 | - |
|
19 | - // Current variable stacks |
|
20 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
21 | - var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
22 | - var $_currentStructName = array(); // A stack as well |
|
23 | - var $_param; |
|
24 | - var $_value; |
|
25 | - var $_currentTag; |
|
26 | - var $_currentTagContents; |
|
27 | - // The XML parser |
|
28 | - var $_parser; |
|
12 | + var $message; |
|
13 | + var $messageType; // methodCall / methodResponse / fault |
|
14 | + var $faultCode; |
|
15 | + var $faultString; |
|
16 | + var $methodName; |
|
17 | + var $params; |
|
18 | + |
|
19 | + // Current variable stacks |
|
20 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
21 | + var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
22 | + var $_currentStructName = array(); // A stack as well |
|
23 | + var $_param; |
|
24 | + var $_value; |
|
25 | + var $_currentTag; |
|
26 | + var $_currentTagContents; |
|
27 | + // The XML parser |
|
28 | + var $_parser; |
|
29 | 29 | |
30 | 30 | /** |
31 | 31 | * PHP5 constructor. |
32 | 32 | */ |
33 | - function __construct( $message ) |
|
34 | - { |
|
35 | - $this->message =& $message; |
|
36 | - } |
|
33 | + function __construct( $message ) |
|
34 | + { |
|
35 | + $this->message =& $message; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * PHP4 constructor. |
@@ -42,193 +42,193 @@ discard block |
||
42 | 42 | self::__construct( $message ); |
43 | 43 | } |
44 | 44 | |
45 | - function parse() |
|
46 | - { |
|
47 | - if ( ! function_exists( 'xml_parser_create' ) ) { |
|
48 | - trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
49 | - return false; |
|
50 | - } |
|
51 | - |
|
52 | - // first remove the XML declaration |
|
53 | - // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
54 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
55 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
56 | - if ( '' == $this->message ) { |
|
57 | - return false; |
|
58 | - } |
|
59 | - |
|
60 | - // Then remove the DOCTYPE |
|
61 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
62 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
63 | - if ( '' == $this->message ) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - |
|
67 | - // Check that the root tag is valid |
|
68 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
69 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
70 | - return false; |
|
71 | - } |
|
72 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
73 | - return false; |
|
74 | - } |
|
75 | - |
|
76 | - // Bail if there are too many elements to parse |
|
77 | - $element_limit = 30000; |
|
78 | - if ( function_exists( 'apply_filters' ) ) { |
|
79 | - /** |
|
80 | - * Filters the number of elements to parse in an XML-RPC response. |
|
81 | - * |
|
82 | - * @since 4.0.0 |
|
83 | - * |
|
84 | - * @param int $element_limit Default elements limit. |
|
85 | - */ |
|
86 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
87 | - } |
|
88 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
89 | - return false; |
|
90 | - } |
|
91 | - |
|
92 | - $this->_parser = xml_parser_create(); |
|
93 | - // Set XML parser to take the case of tags in to account |
|
94 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
95 | - // Set XML parser callback functions |
|
96 | - xml_set_object($this->_parser, $this); |
|
97 | - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
98 | - xml_set_character_data_handler($this->_parser, 'cdata'); |
|
99 | - |
|
100 | - // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
101 | - $chunk_size = 262144; |
|
102 | - |
|
103 | - /** |
|
104 | - * Filters the chunk size that can be used to parse an XML-RPC reponse message. |
|
105 | - * |
|
106 | - * @since 4.4.0 |
|
107 | - * |
|
108 | - * @param int $chunk_size Chunk size to parse in bytes. |
|
109 | - */ |
|
110 | - $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
111 | - |
|
112 | - $final = false; |
|
113 | - do { |
|
114 | - if (strlen($this->message) <= $chunk_size) { |
|
115 | - $final = true; |
|
116 | - } |
|
117 | - $part = substr($this->message, 0, $chunk_size); |
|
118 | - $this->message = substr($this->message, $chunk_size); |
|
119 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
120 | - return false; |
|
121 | - } |
|
122 | - if ($final) { |
|
123 | - break; |
|
124 | - } |
|
125 | - } while (true); |
|
126 | - xml_parser_free($this->_parser); |
|
127 | - |
|
128 | - // Grab the error messages, if any |
|
129 | - if ($this->messageType == 'fault') { |
|
130 | - $this->faultCode = $this->params[0]['faultCode']; |
|
131 | - $this->faultString = $this->params[0]['faultString']; |
|
132 | - } |
|
133 | - return true; |
|
134 | - } |
|
135 | - |
|
136 | - function tag_open($parser, $tag, $attr) |
|
137 | - { |
|
138 | - $this->_currentTagContents = ''; |
|
139 | - $this->currentTag = $tag; |
|
140 | - switch($tag) { |
|
141 | - case 'methodCall': |
|
142 | - case 'methodResponse': |
|
143 | - case 'fault': |
|
144 | - $this->messageType = $tag; |
|
145 | - break; |
|
146 | - /* Deal with stacks of arrays and structs */ |
|
147 | - case 'data': // data is to all intents and puposes more interesting than array |
|
148 | - $this->_arraystructstypes[] = 'array'; |
|
149 | - $this->_arraystructs[] = array(); |
|
150 | - break; |
|
151 | - case 'struct': |
|
152 | - $this->_arraystructstypes[] = 'struct'; |
|
153 | - $this->_arraystructs[] = array(); |
|
154 | - break; |
|
155 | - } |
|
156 | - } |
|
157 | - |
|
158 | - function cdata($parser, $cdata) |
|
159 | - { |
|
160 | - $this->_currentTagContents .= $cdata; |
|
161 | - } |
|
162 | - |
|
163 | - function tag_close($parser, $tag) |
|
164 | - { |
|
165 | - $valueFlag = false; |
|
166 | - switch($tag) { |
|
167 | - case 'int': |
|
168 | - case 'i4': |
|
169 | - $value = (int)trim($this->_currentTagContents); |
|
170 | - $valueFlag = true; |
|
171 | - break; |
|
172 | - case 'double': |
|
173 | - $value = (double)trim($this->_currentTagContents); |
|
174 | - $valueFlag = true; |
|
175 | - break; |
|
176 | - case 'string': |
|
177 | - $value = (string)trim($this->_currentTagContents); |
|
178 | - $valueFlag = true; |
|
179 | - break; |
|
180 | - case 'dateTime.iso8601': |
|
181 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
182 | - $valueFlag = true; |
|
183 | - break; |
|
184 | - case 'value': |
|
185 | - // "If no type is indicated, the type is string." |
|
186 | - if (trim($this->_currentTagContents) != '') { |
|
187 | - $value = (string)$this->_currentTagContents; |
|
188 | - $valueFlag = true; |
|
189 | - } |
|
190 | - break; |
|
191 | - case 'boolean': |
|
192 | - $value = (boolean)trim($this->_currentTagContents); |
|
193 | - $valueFlag = true; |
|
194 | - break; |
|
195 | - case 'base64': |
|
196 | - $value = base64_decode($this->_currentTagContents); |
|
197 | - $valueFlag = true; |
|
198 | - break; |
|
199 | - /* Deal with stacks of arrays and structs */ |
|
200 | - case 'data': |
|
201 | - case 'struct': |
|
202 | - $value = array_pop($this->_arraystructs); |
|
203 | - array_pop($this->_arraystructstypes); |
|
204 | - $valueFlag = true; |
|
205 | - break; |
|
206 | - case 'member': |
|
207 | - array_pop($this->_currentStructName); |
|
208 | - break; |
|
209 | - case 'name': |
|
210 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
211 | - break; |
|
212 | - case 'methodName': |
|
213 | - $this->methodName = trim($this->_currentTagContents); |
|
214 | - break; |
|
215 | - } |
|
216 | - |
|
217 | - if ($valueFlag) { |
|
218 | - if (count($this->_arraystructs) > 0) { |
|
219 | - // Add value to struct or array |
|
220 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
221 | - // Add to struct |
|
222 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
223 | - } else { |
|
224 | - // Add to array |
|
225 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
226 | - } |
|
227 | - } else { |
|
228 | - // Just add as a parameter |
|
229 | - $this->params[] = $value; |
|
230 | - } |
|
231 | - } |
|
232 | - $this->_currentTagContents = ''; |
|
233 | - } |
|
45 | + function parse() |
|
46 | + { |
|
47 | + if ( ! function_exists( 'xml_parser_create' ) ) { |
|
48 | + trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
49 | + return false; |
|
50 | + } |
|
51 | + |
|
52 | + // first remove the XML declaration |
|
53 | + // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
|
54 | + $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
55 | + $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
56 | + if ( '' == $this->message ) { |
|
57 | + return false; |
|
58 | + } |
|
59 | + |
|
60 | + // Then remove the DOCTYPE |
|
61 | + $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
62 | + $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
63 | + if ( '' == $this->message ) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + |
|
67 | + // Check that the root tag is valid |
|
68 | + $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
69 | + if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
70 | + return false; |
|
71 | + } |
|
72 | + if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
73 | + return false; |
|
74 | + } |
|
75 | + |
|
76 | + // Bail if there are too many elements to parse |
|
77 | + $element_limit = 30000; |
|
78 | + if ( function_exists( 'apply_filters' ) ) { |
|
79 | + /** |
|
80 | + * Filters the number of elements to parse in an XML-RPC response. |
|
81 | + * |
|
82 | + * @since 4.0.0 |
|
83 | + * |
|
84 | + * @param int $element_limit Default elements limit. |
|
85 | + */ |
|
86 | + $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
87 | + } |
|
88 | + if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
89 | + return false; |
|
90 | + } |
|
91 | + |
|
92 | + $this->_parser = xml_parser_create(); |
|
93 | + // Set XML parser to take the case of tags in to account |
|
94 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
95 | + // Set XML parser callback functions |
|
96 | + xml_set_object($this->_parser, $this); |
|
97 | + xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
98 | + xml_set_character_data_handler($this->_parser, 'cdata'); |
|
99 | + |
|
100 | + // 256Kb, parse in chunks to avoid the RAM usage on very large messages |
|
101 | + $chunk_size = 262144; |
|
102 | + |
|
103 | + /** |
|
104 | + * Filters the chunk size that can be used to parse an XML-RPC reponse message. |
|
105 | + * |
|
106 | + * @since 4.4.0 |
|
107 | + * |
|
108 | + * @param int $chunk_size Chunk size to parse in bytes. |
|
109 | + */ |
|
110 | + $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
111 | + |
|
112 | + $final = false; |
|
113 | + do { |
|
114 | + if (strlen($this->message) <= $chunk_size) { |
|
115 | + $final = true; |
|
116 | + } |
|
117 | + $part = substr($this->message, 0, $chunk_size); |
|
118 | + $this->message = substr($this->message, $chunk_size); |
|
119 | + if (!xml_parse($this->_parser, $part, $final)) { |
|
120 | + return false; |
|
121 | + } |
|
122 | + if ($final) { |
|
123 | + break; |
|
124 | + } |
|
125 | + } while (true); |
|
126 | + xml_parser_free($this->_parser); |
|
127 | + |
|
128 | + // Grab the error messages, if any |
|
129 | + if ($this->messageType == 'fault') { |
|
130 | + $this->faultCode = $this->params[0]['faultCode']; |
|
131 | + $this->faultString = $this->params[0]['faultString']; |
|
132 | + } |
|
133 | + return true; |
|
134 | + } |
|
135 | + |
|
136 | + function tag_open($parser, $tag, $attr) |
|
137 | + { |
|
138 | + $this->_currentTagContents = ''; |
|
139 | + $this->currentTag = $tag; |
|
140 | + switch($tag) { |
|
141 | + case 'methodCall': |
|
142 | + case 'methodResponse': |
|
143 | + case 'fault': |
|
144 | + $this->messageType = $tag; |
|
145 | + break; |
|
146 | + /* Deal with stacks of arrays and structs */ |
|
147 | + case 'data': // data is to all intents and puposes more interesting than array |
|
148 | + $this->_arraystructstypes[] = 'array'; |
|
149 | + $this->_arraystructs[] = array(); |
|
150 | + break; |
|
151 | + case 'struct': |
|
152 | + $this->_arraystructstypes[] = 'struct'; |
|
153 | + $this->_arraystructs[] = array(); |
|
154 | + break; |
|
155 | + } |
|
156 | + } |
|
157 | + |
|
158 | + function cdata($parser, $cdata) |
|
159 | + { |
|
160 | + $this->_currentTagContents .= $cdata; |
|
161 | + } |
|
162 | + |
|
163 | + function tag_close($parser, $tag) |
|
164 | + { |
|
165 | + $valueFlag = false; |
|
166 | + switch($tag) { |
|
167 | + case 'int': |
|
168 | + case 'i4': |
|
169 | + $value = (int)trim($this->_currentTagContents); |
|
170 | + $valueFlag = true; |
|
171 | + break; |
|
172 | + case 'double': |
|
173 | + $value = (double)trim($this->_currentTagContents); |
|
174 | + $valueFlag = true; |
|
175 | + break; |
|
176 | + case 'string': |
|
177 | + $value = (string)trim($this->_currentTagContents); |
|
178 | + $valueFlag = true; |
|
179 | + break; |
|
180 | + case 'dateTime.iso8601': |
|
181 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
182 | + $valueFlag = true; |
|
183 | + break; |
|
184 | + case 'value': |
|
185 | + // "If no type is indicated, the type is string." |
|
186 | + if (trim($this->_currentTagContents) != '') { |
|
187 | + $value = (string)$this->_currentTagContents; |
|
188 | + $valueFlag = true; |
|
189 | + } |
|
190 | + break; |
|
191 | + case 'boolean': |
|
192 | + $value = (boolean)trim($this->_currentTagContents); |
|
193 | + $valueFlag = true; |
|
194 | + break; |
|
195 | + case 'base64': |
|
196 | + $value = base64_decode($this->_currentTagContents); |
|
197 | + $valueFlag = true; |
|
198 | + break; |
|
199 | + /* Deal with stacks of arrays and structs */ |
|
200 | + case 'data': |
|
201 | + case 'struct': |
|
202 | + $value = array_pop($this->_arraystructs); |
|
203 | + array_pop($this->_arraystructstypes); |
|
204 | + $valueFlag = true; |
|
205 | + break; |
|
206 | + case 'member': |
|
207 | + array_pop($this->_currentStructName); |
|
208 | + break; |
|
209 | + case 'name': |
|
210 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
211 | + break; |
|
212 | + case 'methodName': |
|
213 | + $this->methodName = trim($this->_currentTagContents); |
|
214 | + break; |
|
215 | + } |
|
216 | + |
|
217 | + if ($valueFlag) { |
|
218 | + if (count($this->_arraystructs) > 0) { |
|
219 | + // Add value to struct or array |
|
220 | + if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
221 | + // Add to struct |
|
222 | + $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
223 | + } else { |
|
224 | + // Add to array |
|
225 | + $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
226 | + } |
|
227 | + } else { |
|
228 | + // Just add as a parameter |
|
229 | + $this->params[] = $value; |
|
230 | + } |
|
231 | + } |
|
232 | + $this->_currentTagContents = ''; |
|
233 | + } |
|
234 | 234 | } |
@@ -10,16 +10,16 @@ discard block |
||
10 | 10 | class IXR_Message |
11 | 11 | { |
12 | 12 | var $message; |
13 | - var $messageType; // methodCall / methodResponse / fault |
|
13 | + var $messageType; // methodCall / methodResponse / fault |
|
14 | 14 | var $faultCode; |
15 | 15 | var $faultString; |
16 | 16 | var $methodName; |
17 | 17 | var $params; |
18 | 18 | |
19 | 19 | // Current variable stacks |
20 | - var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
20 | + var $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
21 | 21 | var $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
22 | - var $_currentStructName = array(); // A stack as well |
|
22 | + var $_currentStructName = array(); // A stack as well |
|
23 | 23 | var $_param; |
24 | 24 | var $_value; |
25 | 25 | var $_currentTag; |
@@ -30,52 +30,52 @@ discard block |
||
30 | 30 | /** |
31 | 31 | * PHP5 constructor. |
32 | 32 | */ |
33 | - function __construct( $message ) |
|
33 | + function __construct($message) |
|
34 | 34 | { |
35 | - $this->message =& $message; |
|
35 | + $this->message = & $message; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * PHP4 constructor. |
40 | 40 | */ |
41 | - public function IXR_Message( $message ) { |
|
42 | - self::__construct( $message ); |
|
41 | + public function IXR_Message($message) { |
|
42 | + self::__construct($message); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | function parse() |
46 | 46 | { |
47 | - if ( ! function_exists( 'xml_parser_create' ) ) { |
|
48 | - trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) ); |
|
47 | + if ( ! function_exists('xml_parser_create')) { |
|
48 | + trigger_error(__("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.")); |
|
49 | 49 | return false; |
50 | 50 | } |
51 | 51 | |
52 | 52 | // first remove the XML declaration |
53 | 53 | // merged from WP #10698 - this method avoids the RAM usage of preg_replace on very large messages |
54 | - $header = preg_replace( '/<\?xml.*?\?'.'>/s', '', substr( $this->message, 0, 100 ), 1 ); |
|
55 | - $this->message = trim( substr_replace( $this->message, $header, 0, 100 ) ); |
|
56 | - if ( '' == $this->message ) { |
|
54 | + $header = preg_replace('/<\?xml.*?\?'.'>/s', '', substr($this->message, 0, 100), 1); |
|
55 | + $this->message = trim(substr_replace($this->message, $header, 0, 100)); |
|
56 | + if ('' == $this->message) { |
|
57 | 57 | return false; |
58 | 58 | } |
59 | 59 | |
60 | 60 | // Then remove the DOCTYPE |
61 | - $header = preg_replace( '/^<!DOCTYPE[^>]*+>/i', '', substr( $this->message, 0, 200 ), 1 ); |
|
62 | - $this->message = trim( substr_replace( $this->message, $header, 0, 200 ) ); |
|
63 | - if ( '' == $this->message ) { |
|
61 | + $header = preg_replace('/^<!DOCTYPE[^>]*+>/i', '', substr($this->message, 0, 200), 1); |
|
62 | + $this->message = trim(substr_replace($this->message, $header, 0, 200)); |
|
63 | + if ('' == $this->message) { |
|
64 | 64 | return false; |
65 | 65 | } |
66 | 66 | |
67 | 67 | // Check that the root tag is valid |
68 | - $root_tag = substr( $this->message, 0, strcspn( substr( $this->message, 0, 20 ), "> \t\r\n" ) ); |
|
69 | - if ( '<!DOCTYPE' === strtoupper( $root_tag ) ) { |
|
68 | + $root_tag = substr($this->message, 0, strcspn(substr($this->message, 0, 20), "> \t\r\n")); |
|
69 | + if ('<!DOCTYPE' === strtoupper($root_tag)) { |
|
70 | 70 | return false; |
71 | 71 | } |
72 | - if ( ! in_array( $root_tag, array( '<methodCall', '<methodResponse', '<fault' ) ) ) { |
|
72 | + if ( ! in_array($root_tag, array('<methodCall', '<methodResponse', '<fault'))) { |
|
73 | 73 | return false; |
74 | 74 | } |
75 | 75 | |
76 | 76 | // Bail if there are too many elements to parse |
77 | 77 | $element_limit = 30000; |
78 | - if ( function_exists( 'apply_filters' ) ) { |
|
78 | + if (function_exists('apply_filters')) { |
|
79 | 79 | /** |
80 | 80 | * Filters the number of elements to parse in an XML-RPC response. |
81 | 81 | * |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @param int $element_limit Default elements limit. |
85 | 85 | */ |
86 | - $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit ); |
|
86 | + $element_limit = apply_filters('xmlrpc_element_limit', $element_limit); |
|
87 | 87 | } |
88 | - if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) { |
|
88 | + if ($element_limit && 2 * $element_limit < substr_count($this->message, '<')) { |
|
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @param int $chunk_size Chunk size to parse in bytes. |
109 | 109 | */ |
110 | - $chunk_size = apply_filters( 'xmlrpc_chunk_parsing_size', $chunk_size ); |
|
110 | + $chunk_size = apply_filters('xmlrpc_chunk_parsing_size', $chunk_size); |
|
111 | 111 | |
112 | 112 | $final = false; |
113 | 113 | do { |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | $part = substr($this->message, 0, $chunk_size); |
118 | 118 | $this->message = substr($this->message, $chunk_size); |
119 | - if (!xml_parse($this->_parser, $part, $final)) { |
|
119 | + if ( ! xml_parse($this->_parser, $part, $final)) { |
|
120 | 120 | return false; |
121 | 121 | } |
122 | 122 | if ($final) { |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | { |
138 | 138 | $this->_currentTagContents = ''; |
139 | 139 | $this->currentTag = $tag; |
140 | - switch($tag) { |
|
140 | + switch ($tag) { |
|
141 | 141 | case 'methodCall': |
142 | 142 | case 'methodResponse': |
143 | 143 | case 'fault': |
@@ -163,18 +163,18 @@ discard block |
||
163 | 163 | function tag_close($parser, $tag) |
164 | 164 | { |
165 | 165 | $valueFlag = false; |
166 | - switch($tag) { |
|
166 | + switch ($tag) { |
|
167 | 167 | case 'int': |
168 | 168 | case 'i4': |
169 | - $value = (int)trim($this->_currentTagContents); |
|
169 | + $value = (int) trim($this->_currentTagContents); |
|
170 | 170 | $valueFlag = true; |
171 | 171 | break; |
172 | 172 | case 'double': |
173 | - $value = (double)trim($this->_currentTagContents); |
|
173 | + $value = (double) trim($this->_currentTagContents); |
|
174 | 174 | $valueFlag = true; |
175 | 175 | break; |
176 | 176 | case 'string': |
177 | - $value = (string)trim($this->_currentTagContents); |
|
177 | + $value = (string) trim($this->_currentTagContents); |
|
178 | 178 | $valueFlag = true; |
179 | 179 | break; |
180 | 180 | case 'dateTime.iso8601': |
@@ -184,12 +184,12 @@ discard block |
||
184 | 184 | case 'value': |
185 | 185 | // "If no type is indicated, the type is string." |
186 | 186 | if (trim($this->_currentTagContents) != '') { |
187 | - $value = (string)$this->_currentTagContents; |
|
187 | + $value = (string) $this->_currentTagContents; |
|
188 | 188 | $valueFlag = true; |
189 | 189 | } |
190 | 190 | break; |
191 | 191 | case 'boolean': |
192 | - $value = (boolean)trim($this->_currentTagContents); |
|
192 | + $value = (boolean) trim($this->_currentTagContents); |
|
193 | 193 | $valueFlag = true; |
194 | 194 | break; |
195 | 195 | case 'base64': |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | if ($valueFlag) { |
218 | 218 | if (count($this->_arraystructs) > 0) { |
219 | 219 | // Add value to struct or array |
220 | - if ($this->_arraystructstypes[count($this->_arraystructstypes)-1] == 'struct') { |
|
220 | + if ($this->_arraystructstypes[count($this->_arraystructstypes) - 1] == 'struct') { |
|
221 | 221 | // Add to struct |
222 | - $this->_arraystructs[count($this->_arraystructs)-1][$this->_currentStructName[count($this->_currentStructName)-1]] = $value; |
|
222 | + $this->_arraystructs[count($this->_arraystructs) - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
223 | 223 | } else { |
224 | 224 | // Add to array |
225 | - $this->_arraystructs[count($this->_arraystructs)-1][] = $value; |
|
225 | + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
226 | 226 | } |
227 | 227 | } else { |
228 | 228 | // Just add as a parameter |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Usually used in conjunction with `$meta_key`. |
179 | 179 | * } |
180 | 180 | */ |
181 | - public function __construct( $query = '' ) { |
|
181 | + public function __construct($query = '') { |
|
182 | 182 | $this->query_var_defaults = array( |
183 | 183 | 'taxonomy' => null, |
184 | 184 | 'object_ids' => null, |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | 'meta_compare' => '', |
214 | 214 | ); |
215 | 215 | |
216 | - if ( ! empty( $query ) ) { |
|
217 | - $this->query( $query ); |
|
216 | + if ( ! empty($query)) { |
|
217 | + $this->query($query); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
@@ -226,12 +226,12 @@ discard block |
||
226 | 226 | * |
227 | 227 | * @param string|array $query WP_Term_Query arguments. See WP_Term_Query::__construct() |
228 | 228 | */ |
229 | - public function parse_query( $query = '' ) { |
|
230 | - if ( empty( $query ) ) { |
|
229 | + public function parse_query($query = '') { |
|
230 | + if (empty($query)) { |
|
231 | 231 | $query = $this->query_vars; |
232 | 232 | } |
233 | 233 | |
234 | - $taxonomies = isset( $query['taxonomy'] ) ? (array) $query['taxonomy'] : null; |
|
234 | + $taxonomies = isset($query['taxonomy']) ? (array) $query['taxonomy'] : null; |
|
235 | 235 | |
236 | 236 | /** |
237 | 237 | * Filters the terms query default arguments. |
@@ -243,19 +243,19 @@ discard block |
||
243 | 243 | * @param array $defaults An array of default get_terms() arguments. |
244 | 244 | * @param array $taxonomies An array of taxonomies. |
245 | 245 | */ |
246 | - $this->query_var_defaults = apply_filters( 'get_terms_defaults', $this->query_var_defaults, $taxonomies ); |
|
246 | + $this->query_var_defaults = apply_filters('get_terms_defaults', $this->query_var_defaults, $taxonomies); |
|
247 | 247 | |
248 | - $query = wp_parse_args( $query, $this->query_var_defaults ); |
|
248 | + $query = wp_parse_args($query, $this->query_var_defaults); |
|
249 | 249 | |
250 | - $query['number'] = absint( $query['number'] ); |
|
251 | - $query['offset'] = absint( $query['offset'] ); |
|
250 | + $query['number'] = absint($query['number']); |
|
251 | + $query['offset'] = absint($query['offset']); |
|
252 | 252 | |
253 | 253 | // 'parent' overrides 'child_of'. |
254 | - if ( 0 < intval( $query['parent'] ) ) { |
|
254 | + if (0 < intval($query['parent'])) { |
|
255 | 255 | $query['child_of'] = false; |
256 | 256 | } |
257 | 257 | |
258 | - if ( 'all' == $query['get'] ) { |
|
258 | + if ('all' == $query['get']) { |
|
259 | 259 | $query['childless'] = false; |
260 | 260 | $query['child_of'] = 0; |
261 | 261 | $query['hide_empty'] = 0; |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @param WP_Term_Query $this Current instance of WP_Term_Query. |
276 | 276 | */ |
277 | - do_action( 'parse_term_query', $this ); |
|
277 | + do_action('parse_term_query', $this); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | * @param string|array $query Array or URL query string of parameters. |
287 | 287 | * @return array|int List of terms, or number of terms when 'count' is passed as a query var. |
288 | 288 | */ |
289 | - public function query( $query ) { |
|
290 | - $this->query_vars = wp_parse_args( $query ); |
|
289 | + public function query($query) { |
|
290 | + $this->query_vars = wp_parse_args($query); |
|
291 | 291 | return $this->get_terms(); |
292 | 292 | } |
293 | 293 | |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | public function get_terms() { |
305 | 305 | global $wpdb; |
306 | 306 | |
307 | - $this->parse_query( $this->query_vars ); |
|
307 | + $this->parse_query($this->query_vars); |
|
308 | 308 | $args = &$this->query_vars; |
309 | 309 | |
310 | 310 | // Set up meta_query so it's available to 'pre_get_terms'. |
311 | 311 | $this->meta_query = new WP_Meta_Query(); |
312 | - $this->meta_query->parse_query_vars( $args ); |
|
312 | + $this->meta_query->parse_query_vars($args); |
|
313 | 313 | |
314 | 314 | /** |
315 | 315 | * Fires before terms are retrieved. |
@@ -318,31 +318,31 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @param WP_Term_Query $this Current instance of WP_Term_Query. |
320 | 320 | */ |
321 | - do_action( 'pre_get_terms', $this ); |
|
321 | + do_action('pre_get_terms', $this); |
|
322 | 322 | |
323 | 323 | $taxonomies = $args['taxonomy']; |
324 | 324 | |
325 | 325 | // Save queries by not crawling the tree in the case of multiple taxes or a flat tax. |
326 | 326 | $has_hierarchical_tax = false; |
327 | - if ( $taxonomies ) { |
|
328 | - foreach ( $taxonomies as $_tax ) { |
|
329 | - if ( is_taxonomy_hierarchical( $_tax ) ) { |
|
327 | + if ($taxonomies) { |
|
328 | + foreach ($taxonomies as $_tax) { |
|
329 | + if (is_taxonomy_hierarchical($_tax)) { |
|
330 | 330 | $has_hierarchical_tax = true; |
331 | 331 | } |
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
335 | - if ( ! $has_hierarchical_tax ) { |
|
335 | + if ( ! $has_hierarchical_tax) { |
|
336 | 336 | $args['hierarchical'] = false; |
337 | 337 | $args['pad_counts'] = false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | // 'parent' overrides 'child_of'. |
341 | - if ( 0 < intval( $args['parent'] ) ) { |
|
341 | + if (0 < intval($args['parent'])) { |
|
342 | 342 | $args['child_of'] = false; |
343 | 343 | } |
344 | 344 | |
345 | - if ( 'all' == $args['get'] ) { |
|
345 | + if ('all' == $args['get']) { |
|
346 | 346 | $args['childless'] = false; |
347 | 347 | $args['child_of'] = 0; |
348 | 348 | $args['hide_empty'] = 0; |
@@ -358,50 +358,50 @@ discard block |
||
358 | 358 | * @param array $args An array of get_terms() arguments. |
359 | 359 | * @param array $taxonomies An array of taxonomies. |
360 | 360 | */ |
361 | - $args = apply_filters( 'get_terms_args', $args, $taxonomies ); |
|
361 | + $args = apply_filters('get_terms_args', $args, $taxonomies); |
|
362 | 362 | |
363 | 363 | // Avoid the query if the queried parent/child_of term has no descendants. |
364 | 364 | $child_of = $args['child_of']; |
365 | 365 | $parent = $args['parent']; |
366 | 366 | |
367 | - if ( $child_of ) { |
|
367 | + if ($child_of) { |
|
368 | 368 | $_parent = $child_of; |
369 | - } elseif ( $parent ) { |
|
369 | + } elseif ($parent) { |
|
370 | 370 | $_parent = $parent; |
371 | 371 | } else { |
372 | 372 | $_parent = false; |
373 | 373 | } |
374 | 374 | |
375 | - if ( $_parent ) { |
|
375 | + if ($_parent) { |
|
376 | 376 | $in_hierarchy = false; |
377 | - foreach ( $taxonomies as $_tax ) { |
|
378 | - $hierarchy = _get_term_hierarchy( $_tax ); |
|
377 | + foreach ($taxonomies as $_tax) { |
|
378 | + $hierarchy = _get_term_hierarchy($_tax); |
|
379 | 379 | |
380 | - if ( isset( $hierarchy[ $_parent ] ) ) { |
|
380 | + if (isset($hierarchy[$_parent])) { |
|
381 | 381 | $in_hierarchy = true; |
382 | 382 | } |
383 | 383 | } |
384 | 384 | |
385 | - if ( ! $in_hierarchy ) { |
|
385 | + if ( ! $in_hierarchy) { |
|
386 | 386 | return array(); |
387 | 387 | } |
388 | 388 | } |
389 | 389 | |
390 | 390 | // 'term_order' is a legal sort order only when joining the relationship table. |
391 | 391 | $_orderby = $this->query_vars['orderby']; |
392 | - if ( 'term_order' === $_orderby && empty( $this->query_vars['object_ids'] ) ) { |
|
392 | + if ('term_order' === $_orderby && empty($this->query_vars['object_ids'])) { |
|
393 | 393 | $_orderby = 'term_id'; |
394 | 394 | } |
395 | - $orderby = $this->parse_orderby( $_orderby ); |
|
395 | + $orderby = $this->parse_orderby($_orderby); |
|
396 | 396 | |
397 | - if ( $orderby ) { |
|
397 | + if ($orderby) { |
|
398 | 398 | $orderby = "ORDER BY $orderby"; |
399 | 399 | } |
400 | 400 | |
401 | - $order = $this->parse_order( $this->query_vars['order'] ); |
|
401 | + $order = $this->parse_order($this->query_vars['order']); |
|
402 | 402 | |
403 | - if ( $taxonomies ) { |
|
404 | - $this->sql_clauses['where']['taxonomy'] = "tt.taxonomy IN ('" . implode( "', '", array_map( 'esc_sql', $taxonomies ) ) . "')"; |
|
403 | + if ($taxonomies) { |
|
404 | + $this->sql_clauses['where']['taxonomy'] = "tt.taxonomy IN ('".implode("', '", array_map('esc_sql', $taxonomies))."')"; |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | $exclude = $args['exclude']; |
@@ -409,48 +409,48 @@ discard block |
||
409 | 409 | $include = $args['include']; |
410 | 410 | |
411 | 411 | $inclusions = ''; |
412 | - if ( ! empty( $include ) ) { |
|
412 | + if ( ! empty($include)) { |
|
413 | 413 | $exclude = ''; |
414 | 414 | $exclude_tree = ''; |
415 | - $inclusions = implode( ',', wp_parse_id_list( $include ) ); |
|
415 | + $inclusions = implode(',', wp_parse_id_list($include)); |
|
416 | 416 | } |
417 | 417 | |
418 | - if ( ! empty( $inclusions ) ) { |
|
419 | - $this->sql_clauses['where']['inclusions'] = 't.term_id IN ( ' . $inclusions . ' )'; |
|
418 | + if ( ! empty($inclusions)) { |
|
419 | + $this->sql_clauses['where']['inclusions'] = 't.term_id IN ( '.$inclusions.' )'; |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | $exclusions = array(); |
423 | - if ( ! empty( $exclude_tree ) ) { |
|
424 | - $exclude_tree = wp_parse_id_list( $exclude_tree ); |
|
423 | + if ( ! empty($exclude_tree)) { |
|
424 | + $exclude_tree = wp_parse_id_list($exclude_tree); |
|
425 | 425 | $excluded_children = $exclude_tree; |
426 | - foreach ( $exclude_tree as $extrunk ) { |
|
426 | + foreach ($exclude_tree as $extrunk) { |
|
427 | 427 | $excluded_children = array_merge( |
428 | 428 | $excluded_children, |
429 | - (array) get_terms( $taxonomies[0], array( |
|
430 | - 'child_of' => intval( $extrunk ), |
|
429 | + (array) get_terms($taxonomies[0], array( |
|
430 | + 'child_of' => intval($extrunk), |
|
431 | 431 | 'fields' => 'ids', |
432 | 432 | 'hide_empty' => 0 |
433 | - ) ) |
|
433 | + )) |
|
434 | 434 | ); |
435 | 435 | } |
436 | - $exclusions = array_merge( $excluded_children, $exclusions ); |
|
436 | + $exclusions = array_merge($excluded_children, $exclusions); |
|
437 | 437 | } |
438 | 438 | |
439 | - if ( ! empty( $exclude ) ) { |
|
440 | - $exclusions = array_merge( wp_parse_id_list( $exclude ), $exclusions ); |
|
439 | + if ( ! empty($exclude)) { |
|
440 | + $exclusions = array_merge(wp_parse_id_list($exclude), $exclusions); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | // 'childless' terms are those without an entry in the flattened term hierarchy. |
444 | 444 | $childless = (bool) $args['childless']; |
445 | - if ( $childless ) { |
|
446 | - foreach ( $taxonomies as $_tax ) { |
|
447 | - $term_hierarchy = _get_term_hierarchy( $_tax ); |
|
448 | - $exclusions = array_merge( array_keys( $term_hierarchy ), $exclusions ); |
|
445 | + if ($childless) { |
|
446 | + foreach ($taxonomies as $_tax) { |
|
447 | + $term_hierarchy = _get_term_hierarchy($_tax); |
|
448 | + $exclusions = array_merge(array_keys($term_hierarchy), $exclusions); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | |
452 | - if ( ! empty( $exclusions ) ) { |
|
453 | - $exclusions = 't.term_id NOT IN (' . implode( ',', array_map( 'intval', $exclusions ) ) . ')'; |
|
452 | + if ( ! empty($exclusions)) { |
|
453 | + $exclusions = 't.term_id NOT IN ('.implode(',', array_map('intval', $exclusions)).')'; |
|
454 | 454 | } else { |
455 | 455 | $exclusions = ''; |
456 | 456 | } |
@@ -464,57 +464,57 @@ discard block |
||
464 | 464 | * @param array $args An array of terms query arguments. |
465 | 465 | * @param array $taxonomies An array of taxonomies. |
466 | 466 | */ |
467 | - $exclusions = apply_filters( 'list_terms_exclusions', $exclusions, $args, $taxonomies ); |
|
467 | + $exclusions = apply_filters('list_terms_exclusions', $exclusions, $args, $taxonomies); |
|
468 | 468 | |
469 | - if ( ! empty( $exclusions ) ) { |
|
469 | + if ( ! empty($exclusions)) { |
|
470 | 470 | // Must do string manipulation here for backward compatibility with filter. |
471 | - $this->sql_clauses['where']['exclusions'] = preg_replace( '/^\s*AND\s*/', '', $exclusions ); |
|
471 | + $this->sql_clauses['where']['exclusions'] = preg_replace('/^\s*AND\s*/', '', $exclusions); |
|
472 | 472 | } |
473 | 473 | |
474 | - if ( ! empty( $args['name'] ) ) { |
|
474 | + if ( ! empty($args['name'])) { |
|
475 | 475 | $names = (array) $args['name']; |
476 | - foreach ( $names as &$_name ) { |
|
476 | + foreach ($names as &$_name) { |
|
477 | 477 | // `sanitize_term_field()` returns slashed data. |
478 | - $_name = stripslashes( sanitize_term_field( 'name', $_name, 0, reset( $taxonomies ), 'db' ) ); |
|
478 | + $_name = stripslashes(sanitize_term_field('name', $_name, 0, reset($taxonomies), 'db')); |
|
479 | 479 | } |
480 | 480 | |
481 | - $this->sql_clauses['where']['name'] = "t.name IN ('" . implode( "', '", array_map( 'esc_sql', $names ) ) . "')"; |
|
481 | + $this->sql_clauses['where']['name'] = "t.name IN ('".implode("', '", array_map('esc_sql', $names))."')"; |
|
482 | 482 | } |
483 | 483 | |
484 | - if ( ! empty( $args['slug'] ) ) { |
|
485 | - if ( is_array( $args['slug'] ) ) { |
|
486 | - $slug = array_map( 'sanitize_title', $args['slug'] ); |
|
487 | - $this->sql_clauses['where']['slug'] = "t.slug IN ('" . implode( "', '", $slug ) . "')"; |
|
484 | + if ( ! empty($args['slug'])) { |
|
485 | + if (is_array($args['slug'])) { |
|
486 | + $slug = array_map('sanitize_title', $args['slug']); |
|
487 | + $this->sql_clauses['where']['slug'] = "t.slug IN ('".implode("', '", $slug)."')"; |
|
488 | 488 | } else { |
489 | - $slug = sanitize_title( $args['slug'] ); |
|
489 | + $slug = sanitize_title($args['slug']); |
|
490 | 490 | $this->sql_clauses['where']['slug'] = "t.slug = '$slug'"; |
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | - if ( ! empty( $args['term_taxonomy_id'] ) ) { |
|
495 | - if ( is_array( $args['term_taxonomy_id'] ) ) { |
|
496 | - $tt_ids = implode( ',', array_map( 'intval', $args['term_taxonomy_id'] ) ); |
|
494 | + if ( ! empty($args['term_taxonomy_id'])) { |
|
495 | + if (is_array($args['term_taxonomy_id'])) { |
|
496 | + $tt_ids = implode(',', array_map('intval', $args['term_taxonomy_id'])); |
|
497 | 497 | $this->sql_clauses['where']['term_taxonomy_id'] = "tt.term_taxonomy_id IN ({$tt_ids})"; |
498 | 498 | } else { |
499 | - $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare( "tt.term_taxonomy_id = %d", $args['term_taxonomy_id'] ); |
|
499 | + $this->sql_clauses['where']['term_taxonomy_id'] = $wpdb->prepare("tt.term_taxonomy_id = %d", $args['term_taxonomy_id']); |
|
500 | 500 | } |
501 | 501 | } |
502 | 502 | |
503 | - if ( ! empty( $args['name__like'] ) ) { |
|
504 | - $this->sql_clauses['where']['name__like'] = $wpdb->prepare( "t.name LIKE %s", '%' . $wpdb->esc_like( $args['name__like'] ) . '%' ); |
|
503 | + if ( ! empty($args['name__like'])) { |
|
504 | + $this->sql_clauses['where']['name__like'] = $wpdb->prepare("t.name LIKE %s", '%'.$wpdb->esc_like($args['name__like']).'%'); |
|
505 | 505 | } |
506 | 506 | |
507 | - if ( ! empty( $args['description__like'] ) ) { |
|
508 | - $this->sql_clauses['where']['description__like'] = $wpdb->prepare( "tt.description LIKE %s", '%' . $wpdb->esc_like( $args['description__like'] ) . '%' ); |
|
507 | + if ( ! empty($args['description__like'])) { |
|
508 | + $this->sql_clauses['where']['description__like'] = $wpdb->prepare("tt.description LIKE %s", '%'.$wpdb->esc_like($args['description__like']).'%'); |
|
509 | 509 | } |
510 | 510 | |
511 | - if ( ! empty( $args['object_ids'] ) ) { |
|
511 | + if ( ! empty($args['object_ids'])) { |
|
512 | 512 | $object_ids = $args['object_ids']; |
513 | - if ( ! is_array( $object_ids ) ) { |
|
514 | - $object_ids = array( $object_ids ); |
|
513 | + if ( ! is_array($object_ids)) { |
|
514 | + $object_ids = array($object_ids); |
|
515 | 515 | } |
516 | 516 | |
517 | - $object_ids = implode( ', ', array_map( 'intval', $object_ids ) ); |
|
517 | + $object_ids = implode(', ', array_map('intval', $object_ids)); |
|
518 | 518 | $this->sql_clauses['where']['object_ids'] = "tr.object_id IN ($object_ids)"; |
519 | 519 | } |
520 | 520 | |
@@ -522,20 +522,20 @@ discard block |
||
522 | 522 | * When querying for object relationships, the 'count > 0' check |
523 | 523 | * added by 'hide_empty' is superfluous. |
524 | 524 | */ |
525 | - if ( ! empty( $args['object_ids'] ) ) { |
|
525 | + if ( ! empty($args['object_ids'])) { |
|
526 | 526 | $args['hide_empty'] = false; |
527 | 527 | } |
528 | 528 | |
529 | - if ( '' !== $parent ) { |
|
529 | + if ('' !== $parent) { |
|
530 | 530 | $parent = (int) $parent; |
531 | 531 | $this->sql_clauses['where']['parent'] = "tt.parent = '$parent'"; |
532 | 532 | } |
533 | 533 | |
534 | 534 | $hierarchical = $args['hierarchical']; |
535 | - if ( 'count' == $args['fields'] ) { |
|
535 | + if ('count' == $args['fields']) { |
|
536 | 536 | $hierarchical = false; |
537 | 537 | } |
538 | - if ( $args['hide_empty'] && !$hierarchical ) { |
|
538 | + if ($args['hide_empty'] && ! $hierarchical) { |
|
539 | 539 | $this->sql_clauses['where']['count'] = 'tt.count > 0'; |
540 | 540 | } |
541 | 541 | |
@@ -543,19 +543,19 @@ discard block |
||
543 | 543 | $offset = $args['offset']; |
544 | 544 | |
545 | 545 | // Don't limit the query results when we have to descend the family tree. |
546 | - if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) { |
|
547 | - if ( $offset ) { |
|
548 | - $limits = 'LIMIT ' . $offset . ',' . $number; |
|
546 | + if ($number && ! $hierarchical && ! $child_of && '' === $parent) { |
|
547 | + if ($offset) { |
|
548 | + $limits = 'LIMIT '.$offset.','.$number; |
|
549 | 549 | } else { |
550 | - $limits = 'LIMIT ' . $number; |
|
550 | + $limits = 'LIMIT '.$number; |
|
551 | 551 | } |
552 | 552 | } else { |
553 | 553 | $limits = ''; |
554 | 554 | } |
555 | 555 | |
556 | 556 | |
557 | - if ( ! empty( $args['search'] ) ) { |
|
558 | - $this->sql_clauses['where']['search'] = $this->get_search_sql( $args['search'] ); |
|
557 | + if ( ! empty($args['search'])) { |
|
558 | + $this->sql_clauses['where']['search'] = $this->get_search_sql($args['search']); |
|
559 | 559 | } |
560 | 560 | |
561 | 561 | // Meta query support. |
@@ -563,45 +563,45 @@ discard block |
||
563 | 563 | $distinct = ''; |
564 | 564 | |
565 | 565 | // Reparse meta_query query_vars, in case they were modified in a 'pre_get_terms' callback. |
566 | - $this->meta_query->parse_query_vars( $this->query_vars ); |
|
567 | - $mq_sql = $this->meta_query->get_sql( 'term', 't', 'term_id' ); |
|
566 | + $this->meta_query->parse_query_vars($this->query_vars); |
|
567 | + $mq_sql = $this->meta_query->get_sql('term', 't', 'term_id'); |
|
568 | 568 | $meta_clauses = $this->meta_query->get_clauses(); |
569 | 569 | |
570 | - if ( ! empty( $meta_clauses ) ) { |
|
570 | + if ( ! empty($meta_clauses)) { |
|
571 | 571 | $join .= $mq_sql['join']; |
572 | - $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $mq_sql['where'] ); |
|
572 | + $this->sql_clauses['where']['meta_query'] = preg_replace('/^\s*AND\s*/', '', $mq_sql['where']); |
|
573 | 573 | $distinct .= "DISTINCT"; |
574 | 574 | |
575 | 575 | } |
576 | 576 | |
577 | 577 | $selects = array(); |
578 | - switch ( $args['fields'] ) { |
|
578 | + switch ($args['fields']) { |
|
579 | 579 | case 'all': |
580 | 580 | case 'all_with_object_id' : |
581 | 581 | case 'tt_ids' : |
582 | 582 | case 'slugs' : |
583 | - $selects = array( 't.*', 'tt.*' ); |
|
584 | - if ( 'all_with_object_id' === $args['fields'] && ! empty( $args['object_ids'] ) ) { |
|
583 | + $selects = array('t.*', 'tt.*'); |
|
584 | + if ('all_with_object_id' === $args['fields'] && ! empty($args['object_ids'])) { |
|
585 | 585 | $selects[] = 'tr.object_id'; |
586 | 586 | } |
587 | 587 | break; |
588 | 588 | case 'ids': |
589 | 589 | case 'id=>parent': |
590 | - $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' ); |
|
590 | + $selects = array('t.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy'); |
|
591 | 591 | break; |
592 | 592 | case 'names': |
593 | - $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' ); |
|
593 | + $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy'); |
|
594 | 594 | break; |
595 | 595 | case 'count': |
596 | 596 | $orderby = ''; |
597 | 597 | $order = ''; |
598 | - $selects = array( 'COUNT(*)' ); |
|
598 | + $selects = array('COUNT(*)'); |
|
599 | 599 | break; |
600 | 600 | case 'id=>name': |
601 | - $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' ); |
|
601 | + $selects = array('t.term_id', 't.name', 'tt.count', 'tt.taxonomy'); |
|
602 | 602 | break; |
603 | 603 | case 'id=>slug': |
604 | - $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' ); |
|
604 | + $selects = array('t.term_id', 't.slug', 'tt.count', 'tt.taxonomy'); |
|
605 | 605 | break; |
606 | 606 | } |
607 | 607 | |
@@ -623,15 +623,15 @@ discard block |
||
623 | 623 | * @param array $args An array of term query arguments. |
624 | 624 | * @param array $taxonomies An array of taxonomies. |
625 | 625 | */ |
626 | - $fields = implode( ', ', apply_filters( 'get_terms_fields', $selects, $args, $taxonomies ) ); |
|
626 | + $fields = implode(', ', apply_filters('get_terms_fields', $selects, $args, $taxonomies)); |
|
627 | 627 | |
628 | 628 | $join .= " INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id"; |
629 | 629 | |
630 | - if ( ! empty( $this->query_vars['object_ids'] ) ) { |
|
630 | + if ( ! empty($this->query_vars['object_ids'])) { |
|
631 | 631 | $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id"; |
632 | 632 | } |
633 | 633 | |
634 | - $where = implode( ' AND ', $this->sql_clauses['where'] ); |
|
634 | + $where = implode(' AND ', $this->sql_clauses['where']); |
|
635 | 635 | |
636 | 636 | /** |
637 | 637 | * Filters the terms query SQL clauses. |
@@ -642,17 +642,17 @@ discard block |
||
642 | 642 | * @param array $taxonomies An array of taxonomies. |
643 | 643 | * @param array $args An array of terms query arguments. |
644 | 644 | */ |
645 | - $clauses = apply_filters( 'terms_clauses', compact( 'fields', 'join', 'where', 'distinct', 'orderby', 'order', 'limits' ), $taxonomies, $args ); |
|
645 | + $clauses = apply_filters('terms_clauses', compact('fields', 'join', 'where', 'distinct', 'orderby', 'order', 'limits'), $taxonomies, $args); |
|
646 | 646 | |
647 | - $fields = isset( $clauses[ 'fields' ] ) ? $clauses[ 'fields' ] : ''; |
|
648 | - $join = isset( $clauses[ 'join' ] ) ? $clauses[ 'join' ] : ''; |
|
649 | - $where = isset( $clauses[ 'where' ] ) ? $clauses[ 'where' ] : ''; |
|
650 | - $distinct = isset( $clauses[ 'distinct' ] ) ? $clauses[ 'distinct' ] : ''; |
|
651 | - $orderby = isset( $clauses[ 'orderby' ] ) ? $clauses[ 'orderby' ] : ''; |
|
652 | - $order = isset( $clauses[ 'order' ] ) ? $clauses[ 'order' ] : ''; |
|
653 | - $limits = isset( $clauses[ 'limits' ] ) ? $clauses[ 'limits' ] : ''; |
|
647 | + $fields = isset($clauses['fields']) ? $clauses['fields'] : ''; |
|
648 | + $join = isset($clauses['join']) ? $clauses['join'] : ''; |
|
649 | + $where = isset($clauses['where']) ? $clauses['where'] : ''; |
|
650 | + $distinct = isset($clauses['distinct']) ? $clauses['distinct'] : ''; |
|
651 | + $orderby = isset($clauses['orderby']) ? $clauses['orderby'] : ''; |
|
652 | + $order = isset($clauses['order']) ? $clauses['order'] : ''; |
|
653 | + $limits = isset($clauses['limits']) ? $clauses['limits'] : ''; |
|
654 | 654 | |
655 | - if ( $where ) { |
|
655 | + if ($where) { |
|
656 | 656 | $where = "WHERE $where"; |
657 | 657 | } |
658 | 658 | |
@@ -664,73 +664,73 @@ discard block |
||
664 | 664 | $this->request = "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['orderby']} {$this->sql_clauses['limits']}"; |
665 | 665 | |
666 | 666 | // $args can be anything. Only use the args defined in defaults to compute the key. |
667 | - $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $this->query_var_defaults ) ) ) . serialize( $taxonomies ) . $this->request ); |
|
668 | - $last_changed = wp_cache_get_last_changed( 'terms' ); |
|
667 | + $key = md5(serialize(wp_array_slice_assoc($args, array_keys($this->query_var_defaults))).serialize($taxonomies).$this->request); |
|
668 | + $last_changed = wp_cache_get_last_changed('terms'); |
|
669 | 669 | $cache_key = "get_terms:$key:$last_changed"; |
670 | - $cache = wp_cache_get( $cache_key, 'terms' ); |
|
671 | - if ( false !== $cache ) { |
|
672 | - if ( 'all' === $_fields ) { |
|
673 | - $cache = array_map( 'get_term', $cache ); |
|
670 | + $cache = wp_cache_get($cache_key, 'terms'); |
|
671 | + if (false !== $cache) { |
|
672 | + if ('all' === $_fields) { |
|
673 | + $cache = array_map('get_term', $cache); |
|
674 | 674 | } |
675 | 675 | |
676 | 676 | $this->terms = $cache; |
677 | 677 | return $this->terms; |
678 | 678 | } |
679 | 679 | |
680 | - if ( 'count' == $_fields ) { |
|
681 | - $count = $wpdb->get_var( $this->request ); |
|
682 | - wp_cache_set( $cache_key, $count, 'terms' ); |
|
680 | + if ('count' == $_fields) { |
|
681 | + $count = $wpdb->get_var($this->request); |
|
682 | + wp_cache_set($cache_key, $count, 'terms'); |
|
683 | 683 | return $count; |
684 | 684 | } |
685 | 685 | |
686 | - $terms = $wpdb->get_results( $this->request ); |
|
687 | - if ( 'all' == $_fields || 'all_with_object_id' === $_fields ) { |
|
688 | - update_term_cache( $terms ); |
|
686 | + $terms = $wpdb->get_results($this->request); |
|
687 | + if ('all' == $_fields || 'all_with_object_id' === $_fields) { |
|
688 | + update_term_cache($terms); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | // Prime termmeta cache. |
692 | - if ( $args['update_term_meta_cache'] ) { |
|
693 | - $term_ids = wp_list_pluck( $terms, 'term_id' ); |
|
694 | - update_termmeta_cache( $term_ids ); |
|
692 | + if ($args['update_term_meta_cache']) { |
|
693 | + $term_ids = wp_list_pluck($terms, 'term_id'); |
|
694 | + update_termmeta_cache($term_ids); |
|
695 | 695 | } |
696 | 696 | |
697 | - if ( empty( $terms ) ) { |
|
698 | - wp_cache_add( $cache_key, array(), 'terms', DAY_IN_SECONDS ); |
|
697 | + if (empty($terms)) { |
|
698 | + wp_cache_add($cache_key, array(), 'terms', DAY_IN_SECONDS); |
|
699 | 699 | return array(); |
700 | 700 | } |
701 | 701 | |
702 | - if ( $child_of ) { |
|
703 | - foreach ( $taxonomies as $_tax ) { |
|
704 | - $children = _get_term_hierarchy( $_tax ); |
|
705 | - if ( ! empty( $children ) ) { |
|
706 | - $terms = _get_term_children( $child_of, $terms, $_tax ); |
|
702 | + if ($child_of) { |
|
703 | + foreach ($taxonomies as $_tax) { |
|
704 | + $children = _get_term_hierarchy($_tax); |
|
705 | + if ( ! empty($children)) { |
|
706 | + $terms = _get_term_children($child_of, $terms, $_tax); |
|
707 | 707 | } |
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
711 | 711 | // Update term counts to include children. |
712 | - if ( $args['pad_counts'] && 'all' == $_fields ) { |
|
713 | - foreach ( $taxonomies as $_tax ) { |
|
714 | - _pad_term_counts( $terms, $_tax ); |
|
712 | + if ($args['pad_counts'] && 'all' == $_fields) { |
|
713 | + foreach ($taxonomies as $_tax) { |
|
714 | + _pad_term_counts($terms, $_tax); |
|
715 | 715 | } |
716 | 716 | } |
717 | 717 | |
718 | 718 | // Make sure we show empty categories that have children. |
719 | - if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) { |
|
720 | - foreach ( $terms as $k => $term ) { |
|
721 | - if ( ! $term->count ) { |
|
722 | - $children = get_term_children( $term->term_id, $term->taxonomy ); |
|
723 | - if ( is_array( $children ) ) { |
|
724 | - foreach ( $children as $child_id ) { |
|
725 | - $child = get_term( $child_id, $term->taxonomy ); |
|
726 | - if ( $child->count ) { |
|
719 | + if ($hierarchical && $args['hide_empty'] && is_array($terms)) { |
|
720 | + foreach ($terms as $k => $term) { |
|
721 | + if ( ! $term->count) { |
|
722 | + $children = get_term_children($term->term_id, $term->taxonomy); |
|
723 | + if (is_array($children)) { |
|
724 | + foreach ($children as $child_id) { |
|
725 | + $child = get_term($child_id, $term->taxonomy); |
|
726 | + if ($child->count) { |
|
727 | 727 | continue 2; |
728 | 728 | } |
729 | 729 | } |
730 | 730 | } |
731 | 731 | |
732 | 732 | // It really is empty. |
733 | - unset( $terms[ $k ] ); |
|
733 | + unset($terms[$k]); |
|
734 | 734 | } |
735 | 735 | } |
736 | 736 | } |
@@ -741,14 +741,14 @@ discard block |
||
741 | 741 | * `$fields` is 'all_with_object_id', but should otherwise be |
742 | 742 | * removed. |
743 | 743 | */ |
744 | - if ( ! empty( $args['object_ids'] ) && 'all_with_object_id' != $_fields ) { |
|
744 | + if ( ! empty($args['object_ids']) && 'all_with_object_id' != $_fields) { |
|
745 | 745 | $_tt_ids = $_terms = array(); |
746 | - foreach ( $terms as $term ) { |
|
747 | - if ( isset( $_tt_ids[ $term->term_id ] ) ) { |
|
746 | + foreach ($terms as $term) { |
|
747 | + if (isset($_tt_ids[$term->term_id])) { |
|
748 | 748 | continue; |
749 | 749 | } |
750 | 750 | |
751 | - $_tt_ids[ $term->term_id ] = 1; |
|
751 | + $_tt_ids[$term->term_id] = 1; |
|
752 | 752 | $_terms[] = $term; |
753 | 753 | } |
754 | 754 | |
@@ -756,53 +756,53 @@ discard block |
||
756 | 756 | } |
757 | 757 | |
758 | 758 | $_terms = array(); |
759 | - if ( 'id=>parent' == $_fields ) { |
|
760 | - foreach ( $terms as $term ) { |
|
761 | - $_terms[ $term->term_id ] = $term->parent; |
|
759 | + if ('id=>parent' == $_fields) { |
|
760 | + foreach ($terms as $term) { |
|
761 | + $_terms[$term->term_id] = $term->parent; |
|
762 | 762 | } |
763 | - } elseif ( 'ids' == $_fields ) { |
|
764 | - foreach ( $terms as $term ) { |
|
763 | + } elseif ('ids' == $_fields) { |
|
764 | + foreach ($terms as $term) { |
|
765 | 765 | $_terms[] = (int) $term->term_id; |
766 | 766 | } |
767 | - } elseif ( 'tt_ids' == $_fields ) { |
|
768 | - foreach ( $terms as $term ) { |
|
767 | + } elseif ('tt_ids' == $_fields) { |
|
768 | + foreach ($terms as $term) { |
|
769 | 769 | $_terms[] = (int) $term->term_taxonomy_id; |
770 | 770 | } |
771 | - } elseif ( 'names' == $_fields ) { |
|
772 | - foreach ( $terms as $term ) { |
|
771 | + } elseif ('names' == $_fields) { |
|
772 | + foreach ($terms as $term) { |
|
773 | 773 | $_terms[] = $term->name; |
774 | 774 | } |
775 | - } elseif ( 'slugs' == $_fields ) { |
|
776 | - foreach ( $terms as $term ) { |
|
775 | + } elseif ('slugs' == $_fields) { |
|
776 | + foreach ($terms as $term) { |
|
777 | 777 | $_terms[] = $term->slug; |
778 | 778 | } |
779 | - } elseif ( 'id=>name' == $_fields ) { |
|
780 | - foreach ( $terms as $term ) { |
|
781 | - $_terms[ $term->term_id ] = $term->name; |
|
779 | + } elseif ('id=>name' == $_fields) { |
|
780 | + foreach ($terms as $term) { |
|
781 | + $_terms[$term->term_id] = $term->name; |
|
782 | 782 | } |
783 | - } elseif ( 'id=>slug' == $_fields ) { |
|
784 | - foreach ( $terms as $term ) { |
|
785 | - $_terms[ $term->term_id ] = $term->slug; |
|
783 | + } elseif ('id=>slug' == $_fields) { |
|
784 | + foreach ($terms as $term) { |
|
785 | + $_terms[$term->term_id] = $term->slug; |
|
786 | 786 | } |
787 | 787 | } |
788 | 788 | |
789 | - if ( ! empty( $_terms ) ) { |
|
789 | + if ( ! empty($_terms)) { |
|
790 | 790 | $terms = $_terms; |
791 | 791 | } |
792 | 792 | |
793 | 793 | // Hierarchical queries are not limited, so 'offset' and 'number' must be handled now. |
794 | - if ( $hierarchical && $number && is_array( $terms ) ) { |
|
795 | - if ( $offset >= count( $terms ) ) { |
|
794 | + if ($hierarchical && $number && is_array($terms)) { |
|
795 | + if ($offset >= count($terms)) { |
|
796 | 796 | $terms = array(); |
797 | 797 | } else { |
798 | - $terms = array_slice( $terms, $offset, $number, true ); |
|
798 | + $terms = array_slice($terms, $offset, $number, true); |
|
799 | 799 | } |
800 | 800 | } |
801 | 801 | |
802 | - wp_cache_add( $cache_key, $terms, 'terms', DAY_IN_SECONDS ); |
|
802 | + wp_cache_add($cache_key, $terms, 'terms', DAY_IN_SECONDS); |
|
803 | 803 | |
804 | - if ( 'all' === $_fields || 'all_with_object_id' === $_fields ) { |
|
805 | - $terms = array_map( 'get_term', $terms ); |
|
804 | + if ('all' === $_fields || 'all_with_object_id' === $_fields) { |
|
805 | + $terms = array_map('get_term', $terms); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | $this->terms = $terms; |
@@ -820,22 +820,22 @@ discard block |
||
820 | 820 | * @param string $orderby_raw Alias for the field to order by. |
821 | 821 | * @return string|false Value to used in the ORDER clause. False otherwise. |
822 | 822 | */ |
823 | - protected function parse_orderby( $orderby_raw ) { |
|
824 | - $_orderby = strtolower( $orderby_raw ); |
|
823 | + protected function parse_orderby($orderby_raw) { |
|
824 | + $_orderby = strtolower($orderby_raw); |
|
825 | 825 | $maybe_orderby_meta = false; |
826 | 826 | |
827 | - if ( in_array( $_orderby, array( 'term_id', 'name', 'slug', 'term_group' ), true ) ) { |
|
827 | + if (in_array($_orderby, array('term_id', 'name', 'slug', 'term_group'), true)) { |
|
828 | 828 | $orderby = "t.$_orderby"; |
829 | - } elseif ( in_array( $_orderby, array( 'count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description' ), true ) ) { |
|
829 | + } elseif (in_array($_orderby, array('count', 'parent', 'taxonomy', 'term_taxonomy_id', 'description'), true)) { |
|
830 | 830 | $orderby = "tt.$_orderby"; |
831 | - } elseif ( 'term_order' === $_orderby ) { |
|
831 | + } elseif ('term_order' === $_orderby) { |
|
832 | 832 | $orderby = 'tr.term_order'; |
833 | - } elseif ( 'include' == $_orderby && ! empty( $this->query_vars['include'] ) ) { |
|
834 | - $include = implode( ',', wp_parse_id_list( $this->query_vars['include'] ) ); |
|
833 | + } elseif ('include' == $_orderby && ! empty($this->query_vars['include'])) { |
|
834 | + $include = implode(',', wp_parse_id_list($this->query_vars['include'])); |
|
835 | 835 | $orderby = "FIELD( t.term_id, $include )"; |
836 | - } elseif ( 'none' == $_orderby ) { |
|
836 | + } elseif ('none' == $_orderby) { |
|
837 | 837 | $orderby = ''; |
838 | - } elseif ( empty( $_orderby ) || 'id' == $_orderby || 'term_id' === $_orderby ) { |
|
838 | + } elseif (empty($_orderby) || 'id' == $_orderby || 'term_id' === $_orderby) { |
|
839 | 839 | $orderby = 't.term_id'; |
840 | 840 | } else { |
841 | 841 | $orderby = 't.name'; |
@@ -853,12 +853,12 @@ discard block |
||
853 | 853 | * @param array $args An array of terms query arguments. |
854 | 854 | * @param array $taxonomies An array of taxonomies. |
855 | 855 | */ |
856 | - $orderby = apply_filters( 'get_terms_orderby', $orderby, $this->query_vars, $this->query_vars['taxonomy'] ); |
|
856 | + $orderby = apply_filters('get_terms_orderby', $orderby, $this->query_vars, $this->query_vars['taxonomy']); |
|
857 | 857 | |
858 | 858 | // Run after the 'get_terms_orderby' filter for backward compatibility. |
859 | - if ( $maybe_orderby_meta ) { |
|
860 | - $maybe_orderby_meta = $this->parse_orderby_meta( $_orderby ); |
|
861 | - if ( $maybe_orderby_meta ) { |
|
859 | + if ($maybe_orderby_meta) { |
|
860 | + $maybe_orderby_meta = $this->parse_orderby_meta($_orderby); |
|
861 | + if ($maybe_orderby_meta) { |
|
862 | 862 | $orderby = $maybe_orderby_meta; |
863 | 863 | } |
864 | 864 | } |
@@ -875,35 +875,35 @@ discard block |
||
875 | 875 | * @param string $orderby_raw Raw 'orderby' value passed to WP_Term_Query. |
876 | 876 | * @return string ORDER BY clause. |
877 | 877 | */ |
878 | - protected function parse_orderby_meta( $orderby_raw ) { |
|
878 | + protected function parse_orderby_meta($orderby_raw) { |
|
879 | 879 | $orderby = ''; |
880 | 880 | |
881 | 881 | // Tell the meta query to generate its SQL, so we have access to table aliases. |
882 | - $this->meta_query->get_sql( 'term', 't', 'term_id' ); |
|
882 | + $this->meta_query->get_sql('term', 't', 'term_id'); |
|
883 | 883 | $meta_clauses = $this->meta_query->get_clauses(); |
884 | - if ( ! $meta_clauses || ! $orderby_raw ) { |
|
884 | + if ( ! $meta_clauses || ! $orderby_raw) { |
|
885 | 885 | return $orderby; |
886 | 886 | } |
887 | 887 | |
888 | 888 | $allowed_keys = array(); |
889 | 889 | $primary_meta_key = null; |
890 | - $primary_meta_query = reset( $meta_clauses ); |
|
891 | - if ( ! empty( $primary_meta_query['key'] ) ) { |
|
890 | + $primary_meta_query = reset($meta_clauses); |
|
891 | + if ( ! empty($primary_meta_query['key'])) { |
|
892 | 892 | $primary_meta_key = $primary_meta_query['key']; |
893 | 893 | $allowed_keys[] = $primary_meta_key; |
894 | 894 | } |
895 | 895 | $allowed_keys[] = 'meta_value'; |
896 | 896 | $allowed_keys[] = 'meta_value_num'; |
897 | - $allowed_keys = array_merge( $allowed_keys, array_keys( $meta_clauses ) ); |
|
897 | + $allowed_keys = array_merge($allowed_keys, array_keys($meta_clauses)); |
|
898 | 898 | |
899 | - if ( ! in_array( $orderby_raw, $allowed_keys, true ) ) { |
|
899 | + if ( ! in_array($orderby_raw, $allowed_keys, true)) { |
|
900 | 900 | return $orderby; |
901 | 901 | } |
902 | 902 | |
903 | - switch( $orderby_raw ) { |
|
903 | + switch ($orderby_raw) { |
|
904 | 904 | case $primary_meta_key: |
905 | 905 | case 'meta_value': |
906 | - if ( ! empty( $primary_meta_query['type'] ) ) { |
|
906 | + if ( ! empty($primary_meta_query['type'])) { |
|
907 | 907 | $orderby = "CAST({$primary_meta_query['alias']}.meta_value AS {$primary_meta_query['cast']})"; |
908 | 908 | } else { |
909 | 909 | $orderby = "{$primary_meta_query['alias']}.meta_value"; |
@@ -915,9 +915,9 @@ discard block |
||
915 | 915 | break; |
916 | 916 | |
917 | 917 | default: |
918 | - if ( array_key_exists( $orderby_raw, $meta_clauses ) ) { |
|
918 | + if (array_key_exists($orderby_raw, $meta_clauses)) { |
|
919 | 919 | // $orderby corresponds to a meta_query clause. |
920 | - $meta_clause = $meta_clauses[ $orderby_raw ]; |
|
920 | + $meta_clause = $meta_clauses[$orderby_raw]; |
|
921 | 921 | $orderby = "CAST({$meta_clause['alias']}.meta_value AS {$meta_clause['cast']})"; |
922 | 922 | } |
923 | 923 | break; |
@@ -935,12 +935,12 @@ discard block |
||
935 | 935 | * @param string $order The 'order' query variable. |
936 | 936 | * @return string The sanitized 'order' query variable. |
937 | 937 | */ |
938 | - protected function parse_order( $order ) { |
|
939 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
938 | + protected function parse_order($order) { |
|
939 | + if ( ! is_string($order) || empty($order)) { |
|
940 | 940 | return 'DESC'; |
941 | 941 | } |
942 | 942 | |
943 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
943 | + if ('ASC' === strtoupper($order)) { |
|
944 | 944 | return 'ASC'; |
945 | 945 | } else { |
946 | 946 | return 'DESC'; |
@@ -958,11 +958,11 @@ discard block |
||
958 | 958 | * @param string $string |
959 | 959 | * @return string |
960 | 960 | */ |
961 | - protected function get_search_sql( $string ) { |
|
961 | + protected function get_search_sql($string) { |
|
962 | 962 | global $wpdb; |
963 | 963 | |
964 | - $like = '%' . $wpdb->esc_like( $string ) . '%'; |
|
964 | + $like = '%'.$wpdb->esc_like($string).'%'; |
|
965 | 965 | |
966 | - return $wpdb->prepare( '((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like ); |
|
966 | + return $wpdb->prepare('((t.name LIKE %s) OR (t.slug LIKE %s))', $like, $like); |
|
967 | 967 | } |
968 | 968 | } |