| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | private $parsedPath; |
| 10 | 10 | private $feed_type; |
| 11 | 11 | private $xmlns; |
| 12 | 12 | private $urlHash = array(); |
| 13 | - | |
| 13 | + | |
| 14 | 14 | /** |
| 15 | 15 | * SyndicatedPostXPathQuery::__construct |
| 16 | 16 | * |
| 17 | 17 | * @param array $args |
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | public function __construct ($args = array()) { |
| 22 | 22 | if (is_string($args)) : |
| 23 | 23 | $args = array("path" => $args); |
| 24 | 24 | endif; |
| 25 | - | |
| 25 | + | |
| 26 | 26 | $args = wp_parse_args($args, array( |
| 27 | 27 | "path" => "", |
| 28 | 28 | )); |
| 29 | 29 | |
| @@ -28,9 +28,9 @@ | ||
| 28 | 28 | )); |
| 29 | 29 | |
| 30 | 30 | $this->setPath($args['path']); |
| 31 | 31 | } /* SyndicatedPostXPathQuery::__construct() */ |
| 32 | - | |
| 32 | + | |
| 33 | 33 | /** |
| 34 | 34 | * SyndicatedPostXPathQuery::getPath |
| 35 | 35 | * |
| 36 | 36 | * @param array $args |
| @@ -42,9 +42,9 @@ | ||
| 42 | 42 | )); |
| 43 | 43 | |
| 44 | 44 | return ($args['parsed'] ? $this->parsedPath : $this->path); |
| 45 | 45 | } /* SyndicatedPostXPathQuery::getPath () */ |
| 46 | - | |
| 46 | + | |
| 47 | 47 | /** |
| 48 | 48 | * SyndicatedPostXPathQuery::setPath |
| 49 | 49 | * |
| 50 | 50 | * @param string $path |
| @@ -50,9 +50,9 @@ | ||
| 50 | 50 | * @param string $path |
| 51 | 51 | */ |
| 52 | 52 | public function setPath ($path) { |
| 53 | 53 | $this->urlHash = array(); |
| 54 | - | |
| 54 | + | |
| 55 | 55 | $this->path = $path; |
| 56 | 56 | |
| 57 | 57 | // Allow {url} notation for namespaces. URLs will contain : and /, so... |
| 58 | 58 | preg_match_all('/{([^}]+)}/', $path, $match, PREG_SET_ORDER); |
| @@ -64,13 +64,13 @@ | ||
| 64 | 64 | $path = str_replace('{'.$url.'}', '{#'.$hash.'}', $path); |
| 65 | 65 | endforeach; |
| 66 | 66 | |
| 67 | 67 | $path = $this->parsePath(/*cur=*/ $path, /*orig=*/ $path); |
| 68 | - | |
| 68 | + | |
| 69 | 69 | $this->parsedPath = $path; |
| 70 | 70 | |
| 71 | 71 | } /* SyndicatedPostXPathQuery::setPath() */ |
| 72 | - | |
| 72 | + | |
| 73 | 73 | /** |
| 74 | 74 | * SyndicatedPostXPathQuery::snipSlug |
| 75 | 75 | * |
| 76 | 76 | * @return string |
| @@ -89,9 +89,9 @@ | ||
| 89 | 89 | endif; |
| 90 | 90 | endif; |
| 91 | 91 | return $slug; |
| 92 | 92 | } /* SyndicatedPostXPathQuery::snipSlug () */ |
| 93 | - | |
| 93 | + | |
| 94 | 94 | /** |
| 95 | 95 | * SyndicatedPostXPathQuery::parsePath () |
| 96 | 96 | * |
| 97 | 97 | * @param mixed $path |
| @@ -103,9 +103,9 @@ | ||
| 103 | 103 | // This looks like it's already been parsed. |
| 104 | 104 | $pp = $path; |
| 105 | 105 | else : |
| 106 | 106 | $pp = array(); |
| 107 | - | |
| 107 | + | |
| 108 | 108 | // Okay let's parse this thing. |
| 109 | 109 | $n = 0; $start = 0; $state = 'slug'; |
| 110 | 110 | while ($state != '$') : |
| 111 | 111 | switch ($state) : |
| @@ -117,11 +117,11 @@ | ||
| 117 | 117 | |
| 118 | 118 | $n++; |
| 119 | 119 | // don't include the slash in our next slug |
| 120 | 120 | $start = $n; |
| 121 | - | |
| 121 | + | |
| 122 | 122 | $state = (($n < strlen($path)) ? 'slug' : '$'); |
| 123 | - | |
| 123 | + | |
| 124 | 124 | break; |
| 125 | 125 | case 'brackets' : |
| 126 | 126 | |
| 127 | 127 | // first, snip off what we've consumed so far |
| @@ -132,9 +132,9 @@ | ||
| 132 | 132 | |
| 133 | 133 | // now, chase the ] |
| 134 | 134 | $depth = 1; |
| 135 | 135 | $n++; $start = $n; |
| 136 | - | |
| 136 | + | |
| 137 | 137 | // find the end of the [square-bracketed] expression |
| 138 | 138 | while ($depth > 0 and $n != '') : |
| 139 | 139 | $tok = ((strlen($path) > $n) ? $path[$n] : ''); |
| 140 | 140 | switch ($tok) : |
| @@ -162,15 +162,15 @@ | ||
| 162 | 162 | $oFilter = new stdClass; |
| 163 | 163 | $oFilter->verb = 'has'; |
| 164 | 164 | $oFilter->query = $this->parsePath($bracketed, $rootPath); |
| 165 | 165 | $pp[] = $oFilter; |
| 166 | - | |
| 166 | + | |
| 167 | 167 | $start = $n; |
| 168 | - | |
| 168 | + | |
| 169 | 169 | $state = 'slash-expected'; |
| 170 | 170 | endif; |
| 171 | 171 | break; |
| 172 | - | |
| 172 | + | |
| 173 | 173 | case 'slash-expected' : |
| 174 | 174 | $tok = ((strlen($path) > $n) ? $path[$n] : ''); |
| 175 | 175 | if ($tok == '/' or $tok == '') : |
| 176 | 176 | $state = 'slash'; |
| @@ -200,9 +200,9 @@ | ||
| 200 | 200 | endwhile; |
| 201 | 201 | endif; |
| 202 | 202 | return $pp; |
| 203 | 203 | } /* SyndicatedPostXPathQuery::parsePath() */ |
| 204 | - | |
| 204 | + | |
| 205 | 205 | /** |
| 206 | 206 | * SyndicatedPostXPathQuery::match |
| 207 | 207 | * |
| 208 | 208 | * @param string $path |
| @@ -209,9 +209,9 @@ | ||
| 209 | 209 | * @return array |
| 210 | 210 | */ |
| 211 | 211 | public function match ($r = array()) { |
| 212 | 212 | $path = $this->parsedPath; |
| 213 | - | |
| 213 | + | |
| 214 | 214 | $r = wp_parse_args($r, array( |
| 215 | 215 | "type" => SIMPLEPIE_TYPE_ATOM_10, |
| 216 | 216 | "xmlns" => array(), |
| 217 | 217 | "map" => array(), |
| @@ -221,9 +221,9 @@ | ||
| 221 | 221 | )); |
| 222 | 222 | |
| 223 | 223 | $this->feed_type = $r['type']; |
| 224 | 224 | $this->xmlns = $r['xmlns']; |
| 225 | - | |
| 225 | + | |
| 226 | 226 | // Start out with a get_item_tags query. |
| 227 | 227 | $node = ''; |
| 228 | 228 | while (strlen($node)==0 and !is_null($node)) : |
| 229 | 229 | $node = array_shift($path); |
| @@ -236,9 +236,9 @@ | ||
| 236 | 236 | $data = $r['map']['/']; |
| 237 | 237 | endif; |
| 238 | 238 | |
| 239 | 239 | $matches = $data; |
| 240 | - while ( !is_null($node)) : | |
| 240 | + while (!is_null($node)) : | |
| 241 | 241 | if (is_object($node) OR strlen($node) > 0) : |
| 242 | 242 | list($axis, $element) = $this->xpath_name_and_axis($node); |
| 243 | 243 | if ('self'==$axis) : |
| 244 | 244 | if (is_object($element) and property_exists($element, 'verb')) : |
| @@ -253,14 +253,14 @@ | ||
| 253 | 253 | "context" => $matches, |
| 254 | 254 | "parent" => $r['parent'], |
| 255 | 255 | "format" => "object", |
| 256 | 256 | )); |
| 257 | - | |
| 257 | + | |
| 258 | 258 | // when format = 'object' we should get back |
| 259 | 259 | // a sparse array of arrays, with indices = indices |
| 260 | 260 | // from the input array, each element = an array of |
| 261 | 261 | // one or more matching elements |
| 262 | - | |
| 262 | + | |
| 263 | 263 | if ($element->verb = 'has' and is_array($result)) : |
| 264 | 264 | |
| 265 | 265 | $results = array(); |
| 266 | 266 | foreach (array_keys($result) as $a) : |
| @@ -265,13 +265,13 @@ | ||
| 265 | 265 | $results = array(); |
| 266 | 266 | foreach (array_keys($result) as $a) : |
| 267 | 267 | $results[$a] = $matches[$a]; |
| 268 | 268 | endforeach; |
| 269 | - | |
| 269 | + | |
| 270 | 270 | $matches = $results; |
| 271 | 271 | $data = $matches; |
| 272 | 272 | endif; |
| 273 | - | |
| 273 | + | |
| 274 | 274 | elseif (is_numeric($node)) : |
| 275 | 275 | |
| 276 | 276 | // according to W3C, sequence starts at position 1, not 0 |
| 277 | 277 | // so subtract 1 to line up with PHP array starting at 0 |
| @@ -280,17 +280,17 @@ | ||
| 280 | 280 | $data = array($idx => $matches[$idx]); |
| 281 | 281 | else : |
| 282 | 282 | $data = array(); |
| 283 | 283 | endif; |
| 284 | - | |
| 284 | + | |
| 285 | 285 | $matches = array($idx => $data); |
| 286 | 286 | endif; |
| 287 | - | |
| 287 | + | |
| 288 | 288 | else : |
| 289 | 289 | $matches = array(); |
| 290 | 290 | |
| 291 | 291 | foreach ($data as $idx => $datum) : |
| 292 | - if ( !is_string($datum) and isset($datum[$axis])) : | |
| 292 | + if (!is_string($datum) and isset($datum[$axis])) : | |
| 293 | 293 | foreach ($datum[$axis] as $ns => $elements) : |
| 294 | 294 | if (isset($elements[$element])) : |
| 295 | 295 | // Potential match. |
| 296 | 296 | // Check namespace. |
| @@ -296,9 +296,9 @@ | ||
| 296 | 296 | // Check namespace. |
| 297 | 297 | if (is_string($elements[$element])) : // Attribute |
| 298 | 298 | $addenda = array($elements[$element]); |
| 299 | 299 | $contexts = array($datum); |
| 300 | - | |
| 300 | + | |
| 301 | 301 | // Element |
| 302 | 302 | else : |
| 303 | 303 | $addenda = $elements[$element]; |
| 304 | 304 | $contexts = $elements[$element]; |
| @@ -334,12 +334,12 @@ | ||
| 334 | 334 | else : |
| 335 | 335 | $matches[$idx] = $datum; |
| 336 | 336 | endif; |
| 337 | 337 | endforeach; |
| 338 | - | |
| 338 | + | |
| 339 | 339 | return $matches; |
| 340 | 340 | } /* SyndicatedPostXPathQuery::match() */ |
| 341 | - | |
| 341 | + | |
| 342 | 342 | public function xpath_default_namespace () { |
| 343 | 343 | // Get the default namespace. |
| 344 | 344 | $type = $this->feed_type; |
| 345 | 345 | if ($type & SIMPLEPIE_TYPE_ATOM_10) : |
| @@ -358,10 +358,9 @@ | ||
| 358 | 358 | return $defaultNS; |
| 359 | 359 | } /* SyndicatedPostXPathQuery::xpath_default_namespace() */ |
| 360 | 360 | |
| 361 | 361 | public function xpath_name_and_axis ($node) { |
| 362 | - // $ns = NULL; // Was unused. (gwyneth 20230920) | |
| 363 | - $element = NULL; | |
| 362 | + $ns = NULL; $element = NULL; | |
| 364 | 363 | |
| 365 | 364 | $axis = 'child'; // "In effect, `child` is the default axis." |
| 366 | 365 | if (is_object($node) and property_exists($node, 'verb')): |
| 367 | 366 | if ('has'==$node->verb) : |
| @@ -394,12 +393,10 @@ | ||
| 394 | 393 | return array($axis, $element); |
| 395 | 394 | } /* SyndicatedPostXPathQuery::xpath_name_and_axis () */ |
| 396 | 395 | |
| 397 | 396 | public function xpath_possible_namespaces ($node, $datum = array()) { |
| 398 | - $ns = NULL; | |
| 399 | - // $element = NULL; // reverse of before: now it's the $element that's never used (gwyneth 20230920) | |
| 397 | + $ns = NULL; $element = NULL; | |
| 400 | 398 | |
| 401 | - // Is $attr really the correct thing to assign to? It's never used... (gwyneth 20230920) | |
| 402 | 399 | if (substr($node, 0, 1)=='@') : |
| 403 | 400 | $attr = '@'; $node = substr($node, 1); |
| 404 | 401 | else : |
| 405 | 402 | $attr = ''; |