@@ -33,457 +33,457 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | class MagpieRSS |
| 35 | 35 | { |
| 36 | - public $parser; |
|
| 37 | - |
|
| 38 | - public $current_item = array(); // item currently being parsed |
|
| 39 | - public $items = array(); // collection of parsed items |
|
| 40 | - public $channel = array(); // hash of channel fields |
|
| 41 | - public $textinput = array(); |
|
| 42 | - public $image = array(); |
|
| 43 | - public $feed_type; |
|
| 44 | - public $feed_version; |
|
| 45 | - public $encoding = ''; // output encoding of parsed rss |
|
| 46 | - |
|
| 47 | - public $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 48 | - |
|
| 49 | - public $ERROR = ''; |
|
| 50 | - public $WARNING = ''; |
|
| 51 | - |
|
| 52 | - // define some constants |
|
| 53 | - |
|
| 54 | - public $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
|
| 55 | - public $_KNOWN_ENCODINGS = array('UTF-8', 'US-ASCII', 'ISO-8859-1'); |
|
| 56 | - |
|
| 57 | - // parser variables, useless if you're not a parser, treat as private |
|
| 58 | - public $stack = array(); // parser stack |
|
| 59 | - public $inchannel = false; |
|
| 60 | - public $initem = false; |
|
| 61 | - public $incontent = false; // if in Atom <content mode="xml"> field |
|
| 62 | - public $intextinput = false; |
|
| 63 | - public $inimage = false; |
|
| 64 | - public $current_field = ''; |
|
| 65 | - public $current_namespace = false; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Set up XML parser, parse source, and return populated RSS object.. |
|
| 69 | - * |
|
| 70 | - * @param string $source string containing the RSS to be parsed |
|
| 71 | - * |
|
| 72 | - * NOTE: Probably a good idea to leave the encoding options alone unless |
|
| 73 | - * you know what you're doing as PHP's character set support is |
|
| 74 | - * a little weird. |
|
| 75 | - * |
|
| 76 | - * NOTE: A lot of this is unnecessary but harmless with PHP5 |
|
| 77 | - * |
|
| 78 | - * |
|
| 79 | - * @param string $output_encoding output the parsed RSS in this character |
|
| 80 | - * set defaults to ISO-8859-1 as this is PHP's |
|
| 81 | - * default. |
|
| 82 | - * |
|
| 83 | - * NOTE: might be changed to UTF-8 in future |
|
| 84 | - * versions. |
|
| 85 | - * |
|
| 86 | - * @param string $input_encoding the character set of the incoming RSS source. |
|
| 87 | - * Leave blank and Magpie will try to figure it |
|
| 88 | - * out. |
|
| 89 | - * |
|
| 90 | - * |
|
| 91 | - * @param bool $detect_encoding if false Magpie won't attempt to detect |
|
| 92 | - * source encoding. (caveat emptor) |
|
| 93 | - * |
|
| 94 | - */ |
|
| 95 | - public function __construct( |
|
| 96 | - $source, |
|
| 97 | - $output_encoding = 'ISO-8859-1', |
|
| 98 | - $input_encoding = null, |
|
| 99 | - $detect_encoding = true |
|
| 100 | - ) { |
|
| 101 | - # if PHP xml isn't compiled in, die |
|
| 102 | - # |
|
| 103 | - if (!function_exists('xml_parser_create')) { |
|
| 104 | - $this->error("Failed to load PHP's XML Extension. " . 'http://www.php.net/manual/en/ref.xml.php', |
|
| 105 | - E_USER_ERROR); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - list($parser, $source) = $this->create_parser($source, $output_encoding, $input_encoding, $detect_encoding); |
|
| 109 | - |
|
| 110 | - if (!is_resource($parser)) { |
|
| 111 | - $this->error("Failed to create an instance of PHP's XML parser. " |
|
| 112 | - . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $this->parser = $parser; |
|
| 116 | - |
|
| 117 | - # pass in parser, and a reference to this object |
|
| 118 | - # setup handlers |
|
| 119 | - # |
|
| 120 | - xml_set_object($this->parser, $this); |
|
| 121 | - xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element'); |
|
| 122 | - |
|
| 123 | - xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
| 124 | - |
|
| 125 | - $status = @xml_parse($this->parser, $source); |
|
| 126 | - |
|
| 127 | - if (!$status) { |
|
| 128 | - $errorcode = xml_get_error_code($this->parser); |
|
| 129 | - if ($errorcode != XML_ERROR_NONE) { |
|
| 130 | - $xml_error = xml_error_string($errorcode); |
|
| 131 | - $error_line = xml_get_current_line_number($this->parser); |
|
| 132 | - $error_col = xml_get_current_column_number($this->parser); |
|
| 133 | - $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
| 134 | - |
|
| 135 | - $this->error($errormsg); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - xml_parser_free($this->parser); |
|
| 140 | - |
|
| 141 | - $this->normalize(); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param $p |
|
| 146 | - * @param $element |
|
| 147 | - * @param $attrs |
|
| 148 | - */ |
|
| 149 | - public function feed_start_element($p, $element, &$attrs) { |
|
| 150 | - $el = $element = strtolower($element); |
|
| 151 | - $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
| 152 | - |
|
| 153 | - // check for a namespace, and split if found |
|
| 154 | - $ns = false; |
|
| 155 | - if (strpos($element, ':')) { |
|
| 156 | - list($ns, $el) = explode(':', $element, 2); |
|
| 157 | - } |
|
| 158 | - if ($ns && $ns !== 'rdf') { |
|
| 159 | - $this->current_namespace = $ns; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - # if feed type isn't set, then this is first element of feed |
|
| 163 | - # identify feed from root element |
|
| 164 | - # |
|
| 165 | - if (!isset($this->feed_type)) { |
|
| 166 | - if ($el === 'rdf') { |
|
| 167 | - $this->feed_type = RSS; |
|
| 168 | - $this->feed_version = '1.0'; |
|
| 169 | - } elseif ($el === 'rss') { |
|
| 170 | - $this->feed_type = RSS; |
|
| 171 | - $this->feed_version = $attrs['version']; |
|
| 172 | - } elseif ($el === 'feed') { |
|
| 173 | - $this->feed_type = ATOM; |
|
| 174 | - $this->feed_version = $attrs['version']; |
|
| 175 | - $this->inchannel = true; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if ($el === 'channel') { |
|
| 182 | - $this->inchannel = true; |
|
| 183 | - } elseif ($el === 'item' || $el === 'entry') { |
|
| 184 | - $this->initem = true; |
|
| 185 | - if (isset($attrs['rdf:about'])) { |
|
| 186 | - $this->current_item['about'] = $attrs['rdf:about']; |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // if we're in the default namespace of an RSS feed, |
|
| 191 | - // record textinput or image fields |
|
| 192 | - elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'textinput') { |
|
| 193 | - $this->intextinput = true; |
|
| 194 | - } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'image') { |
|
| 195 | - $this->inimage = true; |
|
| 196 | - } # handle atom content constructs |
|
| 197 | - elseif ($this->feed_type == ATOM && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 198 | - // avoid clashing w/ RSS mod_content |
|
| 199 | - if ($el === 'content') { |
|
| 200 | - $el = 'atom_content'; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $this->incontent = $el; |
|
| 204 | - } // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
| 205 | - elseif ($this->feed_type == ATOM && $this->incontent) { |
|
| 206 | - // if tags are inlined, then flatten |
|
| 207 | - $attrs_str = implode(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs))); |
|
| 208 | - |
|
| 209 | - $this->append_content("<$element $attrs_str>"); |
|
| 210 | - |
|
| 211 | - array_unshift($this->stack, $el); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // Atom support many links per containging element. |
|
| 215 | - // Magpie treats link elements of type rel='alternate' |
|
| 216 | - // as being equivalent to RSS's simple link element. |
|
| 217 | - // |
|
| 218 | - elseif ($this->feed_type == ATOM && $el === 'link') { |
|
| 219 | - if (isset($attrs['rel']) && $attrs['rel'] === 'alternate') { |
|
| 220 | - $link_el = 'link'; |
|
| 221 | - } else { |
|
| 222 | - $link_el = 'link_' . $attrs['rel']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $this->append($link_el, $attrs['href']); |
|
| 226 | - } // set stack[0] to current element |
|
| 227 | - else { |
|
| 228 | - array_unshift($this->stack, $el); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param $p |
|
| 234 | - * @param $text |
|
| 235 | - */ |
|
| 236 | - public function feed_cdata($p, $text) { |
|
| 237 | - if ($this->feed_type == ATOM && $this->incontent) { |
|
| 238 | - $this->append_content($text); |
|
| 239 | - } else { |
|
| 240 | - $current_el = implode('_', array_reverse($this->stack)); |
|
| 241 | - $this->append($current_el, $text); |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @param $p |
|
| 247 | - * @param $el |
|
| 248 | - */ |
|
| 249 | - public function feed_end_element($p, $el) { |
|
| 250 | - $el = strtolower($el); |
|
| 251 | - |
|
| 252 | - if ($el === 'item' || $el === 'entry') { |
|
| 253 | - $this->items[] = $this->current_item; |
|
| 254 | - $this->current_item = array(); |
|
| 255 | - $this->initem = false; |
|
| 256 | - } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'textinput') { |
|
| 257 | - $this->intextinput = false; |
|
| 258 | - } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'image') { |
|
| 259 | - $this->inimage = false; |
|
| 260 | - } elseif ($this->feed_type == ATOM && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 261 | - $this->incontent = false; |
|
| 262 | - } elseif ($el === 'channel' || $el === 'feed') { |
|
| 263 | - $this->inchannel = false; |
|
| 264 | - } elseif ($this->feed_type == ATOM && $this->incontent) { |
|
| 265 | - // balance tags properly |
|
| 266 | - // note: i don't think this is actually neccessary |
|
| 267 | - if ($this->stack[0] == $el) { |
|
| 268 | - $this->append_content("</$el>"); |
|
| 269 | - } else { |
|
| 270 | - $this->append_content("<$el />"); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - array_shift($this->stack); |
|
| 274 | - } else { |
|
| 275 | - array_shift($this->stack); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - $this->current_namespace = false; |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * @param $str1 |
|
| 283 | - * @param string $str2 |
|
| 284 | - */ |
|
| 285 | - public function concat(&$str1, $str2 = '') { |
|
| 286 | - if (!isset($str1)) { |
|
| 287 | - $str1 = ''; |
|
| 288 | - } |
|
| 289 | - $str1 .= $str2; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * @param $text |
|
| 294 | - */ |
|
| 295 | - public function append_content($text) { |
|
| 296 | - if ($this->initem) { |
|
| 297 | - $this->concat($this->current_item[$this->incontent], $text); |
|
| 298 | - } elseif ($this->inchannel) { |
|
| 299 | - $this->concat($this->channel[$this->incontent], $text); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // smart append - field and namespace aware |
|
| 304 | - /** |
|
| 305 | - * @param $el |
|
| 306 | - * @param $text |
|
| 307 | - */ |
|
| 308 | - public function append($el, $text) { |
|
| 309 | - if (!$el) { |
|
| 310 | - return; |
|
| 311 | - } |
|
| 312 | - if ($this->current_namespace) { |
|
| 313 | - if ($this->initem) { |
|
| 314 | - $this->concat($this->current_item[$this->current_namespace][$el], $text); |
|
| 315 | - } elseif ($this->inchannel) { |
|
| 316 | - $this->concat($this->channel[$this->current_namespace][$el], $text); |
|
| 317 | - } elseif ($this->intextinput) { |
|
| 318 | - $this->concat($this->textinput[$this->current_namespace][$el], $text); |
|
| 319 | - } elseif ($this->inimage) { |
|
| 320 | - $this->concat($this->image[$this->current_namespace][$el], $text); |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - if ($this->initem) { |
|
| 324 | - $this->concat($this->current_item[$el], $text); |
|
| 325 | - } elseif ($this->intextinput) { |
|
| 326 | - $this->concat($this->textinput[$el], $text); |
|
| 327 | - } elseif ($this->inimage) { |
|
| 328 | - $this->concat($this->image[$el], $text); |
|
| 329 | - } elseif ($this->inchannel) { |
|
| 330 | - $this->concat($this->channel[$el], $text); |
|
| 331 | - } |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - public function normalize() { |
|
| 336 | - // if atom populate rss fields |
|
| 337 | - if ($this->is_atom()) { |
|
| 338 | - $this->channel['description'] = $this->channel['tagline']; |
|
| 339 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 340 | - $item = $this->items[$i]; |
|
| 341 | - if (isset($item['summary'])) { |
|
| 342 | - $item['description'] = $item['summary']; |
|
| 343 | - } |
|
| 344 | - if (isset($item['atom_content'])) { |
|
| 345 | - $item['content']['encoded'] = $item['atom_content']; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - $atom_date = isset($item['issued']) ? $item['issued'] : @$item['modified']; |
|
| 349 | - if ($atom_date) { |
|
| 350 | - $epoch = @parse_w3cdtf($atom_date); |
|
| 351 | - if ($epoch && $epoch > 0) { |
|
| 352 | - $item['date_timestamp'] = $epoch; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $this->items[$i] = $item; |
|
| 357 | - } |
|
| 358 | - } elseif ($this->is_rss()) { |
|
| 359 | - $this->channel['tagline'] = $this->channel['description']; |
|
| 360 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 361 | - $item = $this->items[$i]; |
|
| 362 | - if (isset($item['description'])) { |
|
| 363 | - $item['summary'] = $item['description']; |
|
| 364 | - } |
|
| 365 | - if (isset($item['content']['encoded'])) { |
|
| 366 | - $item['atom_content'] = $item['content']['encoded']; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - if ($this->is_rss() === '1.0' && isset($item['dc']['date'])) { |
|
| 370 | - $epoch = @parse_w3cdtf($item['dc']['date']); |
|
| 371 | - if ($epoch && $epoch > 0) { |
|
| 372 | - $item['date_timestamp'] = $epoch; |
|
| 373 | - } |
|
| 374 | - } elseif (isset($item['pubdate'])) { |
|
| 375 | - $epoch = @strtotime($item['pubdate']); |
|
| 376 | - if ($epoch > 0) { |
|
| 377 | - $item['date_timestamp'] = $epoch; |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - $this->items[$i] = $item; |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * @return bool |
|
| 388 | - */ |
|
| 389 | - public function is_rss() { |
|
| 390 | - if ($this->feed_type == RSS) { |
|
| 391 | - return $this->feed_version; |
|
| 392 | - } else { |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @return bool |
|
| 399 | - */ |
|
| 400 | - public function is_atom() { |
|
| 401 | - if ($this->feed_type == ATOM) { |
|
| 402 | - return $this->feed_version; |
|
| 403 | - } else { |
|
| 404 | - return false; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * return XML parser, and possibly re-encoded source |
|
| 410 | - * @param $source |
|
| 411 | - * @param $out_enc |
|
| 412 | - * @param $in_enc |
|
| 413 | - * @param $detect |
|
| 414 | - * @return array |
|
| 415 | - */ |
|
| 416 | - public function create_parser($source, $out_enc, $in_enc, $detect) { |
|
| 417 | - if (substr(phpversion(), 0, 1) == 5) { |
|
| 418 | - $parser = $this->php5_create_parser($in_enc, $detect); |
|
| 419 | - } else { |
|
| 420 | - list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
| 421 | - } |
|
| 422 | - if ($out_enc) { |
|
| 423 | - $this->encoding = $out_enc; |
|
| 424 | - xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - return array($parser, $source); |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Instantiate an XML parser under PHP5 |
|
| 432 | - * |
|
| 433 | - * PHP5 will do a fine job of detecting input encoding |
|
| 434 | - * if passed an empty string as the encoding. |
|
| 435 | - * |
|
| 436 | - * All hail libxml2! |
|
| 437 | - * @param $in_enc |
|
| 438 | - * @param $detect |
|
| 439 | - * @return resource |
|
| 440 | - */ |
|
| 441 | - public function php5_create_parser($in_enc, $detect) { |
|
| 442 | - // by default php5 does a fine job of detecting input encodings |
|
| 443 | - if (!$detect && $in_enc) { |
|
| 444 | - return xml_parser_create($in_enc); |
|
| 445 | - } else { |
|
| 446 | - return xml_parser_create(''); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Instaniate an XML parser under PHP4 |
|
| 452 | - * |
|
| 453 | - * Unfortunately PHP4's support for character encodings |
|
| 454 | - * and especially XML and character encodings sucks. As |
|
| 455 | - * long as the documents you parse only contain characters |
|
| 456 | - * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 457 | - * and a subset of UTF-8) you're fine. However once you |
|
| 458 | - * step out of that comfy little world things get mad, bad, |
|
| 459 | - * and dangerous to know. |
|
| 460 | - * |
|
| 461 | - * The following code is based on SJM's work with FoF |
|
| 462 | - * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 463 | - * @param $source |
|
| 464 | - * @param $in_enc |
|
| 465 | - * @param $detect |
|
| 466 | - * @return array |
|
| 467 | - */ |
|
| 468 | - public function php4_create_parser($source, $in_enc, $detect) { |
|
| 469 | - if (!$detect) { |
|
| 470 | - return array(xml_parser_create($in_enc), $source); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - if (!$in_enc) { |
|
| 474 | - if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
| 475 | - $in_enc = strtoupper($m[1]); |
|
| 476 | - $this->source_encoding = $in_enc; |
|
| 477 | - } else { |
|
| 478 | - $in_enc = 'UTF-8'; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - if ($this->known_encoding($in_enc)) { |
|
| 483 | - return array(xml_parser_create($in_enc), $source); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /* |
|
| 36 | + public $parser; |
|
| 37 | + |
|
| 38 | + public $current_item = array(); // item currently being parsed |
|
| 39 | + public $items = array(); // collection of parsed items |
|
| 40 | + public $channel = array(); // hash of channel fields |
|
| 41 | + public $textinput = array(); |
|
| 42 | + public $image = array(); |
|
| 43 | + public $feed_type; |
|
| 44 | + public $feed_version; |
|
| 45 | + public $encoding = ''; // output encoding of parsed rss |
|
| 46 | + |
|
| 47 | + public $_source_encoding = ''; // only set if we have to parse xml prolog |
|
| 48 | + |
|
| 49 | + public $ERROR = ''; |
|
| 50 | + public $WARNING = ''; |
|
| 51 | + |
|
| 52 | + // define some constants |
|
| 53 | + |
|
| 54 | + public $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright'); |
|
| 55 | + public $_KNOWN_ENCODINGS = array('UTF-8', 'US-ASCII', 'ISO-8859-1'); |
|
| 56 | + |
|
| 57 | + // parser variables, useless if you're not a parser, treat as private |
|
| 58 | + public $stack = array(); // parser stack |
|
| 59 | + public $inchannel = false; |
|
| 60 | + public $initem = false; |
|
| 61 | + public $incontent = false; // if in Atom <content mode="xml"> field |
|
| 62 | + public $intextinput = false; |
|
| 63 | + public $inimage = false; |
|
| 64 | + public $current_field = ''; |
|
| 65 | + public $current_namespace = false; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Set up XML parser, parse source, and return populated RSS object.. |
|
| 69 | + * |
|
| 70 | + * @param string $source string containing the RSS to be parsed |
|
| 71 | + * |
|
| 72 | + * NOTE: Probably a good idea to leave the encoding options alone unless |
|
| 73 | + * you know what you're doing as PHP's character set support is |
|
| 74 | + * a little weird. |
|
| 75 | + * |
|
| 76 | + * NOTE: A lot of this is unnecessary but harmless with PHP5 |
|
| 77 | + * |
|
| 78 | + * |
|
| 79 | + * @param string $output_encoding output the parsed RSS in this character |
|
| 80 | + * set defaults to ISO-8859-1 as this is PHP's |
|
| 81 | + * default. |
|
| 82 | + * |
|
| 83 | + * NOTE: might be changed to UTF-8 in future |
|
| 84 | + * versions. |
|
| 85 | + * |
|
| 86 | + * @param string $input_encoding the character set of the incoming RSS source. |
|
| 87 | + * Leave blank and Magpie will try to figure it |
|
| 88 | + * out. |
|
| 89 | + * |
|
| 90 | + * |
|
| 91 | + * @param bool $detect_encoding if false Magpie won't attempt to detect |
|
| 92 | + * source encoding. (caveat emptor) |
|
| 93 | + * |
|
| 94 | + */ |
|
| 95 | + public function __construct( |
|
| 96 | + $source, |
|
| 97 | + $output_encoding = 'ISO-8859-1', |
|
| 98 | + $input_encoding = null, |
|
| 99 | + $detect_encoding = true |
|
| 100 | + ) { |
|
| 101 | + # if PHP xml isn't compiled in, die |
|
| 102 | + # |
|
| 103 | + if (!function_exists('xml_parser_create')) { |
|
| 104 | + $this->error("Failed to load PHP's XML Extension. " . 'http://www.php.net/manual/en/ref.xml.php', |
|
| 105 | + E_USER_ERROR); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + list($parser, $source) = $this->create_parser($source, $output_encoding, $input_encoding, $detect_encoding); |
|
| 109 | + |
|
| 110 | + if (!is_resource($parser)) { |
|
| 111 | + $this->error("Failed to create an instance of PHP's XML parser. " |
|
| 112 | + . 'http://www.php.net/manual/en/ref.xml.php', E_USER_ERROR); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $this->parser = $parser; |
|
| 116 | + |
|
| 117 | + # pass in parser, and a reference to this object |
|
| 118 | + # setup handlers |
|
| 119 | + # |
|
| 120 | + xml_set_object($this->parser, $this); |
|
| 121 | + xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element'); |
|
| 122 | + |
|
| 123 | + xml_set_character_data_handler($this->parser, 'feed_cdata'); |
|
| 124 | + |
|
| 125 | + $status = @xml_parse($this->parser, $source); |
|
| 126 | + |
|
| 127 | + if (!$status) { |
|
| 128 | + $errorcode = xml_get_error_code($this->parser); |
|
| 129 | + if ($errorcode != XML_ERROR_NONE) { |
|
| 130 | + $xml_error = xml_error_string($errorcode); |
|
| 131 | + $error_line = xml_get_current_line_number($this->parser); |
|
| 132 | + $error_col = xml_get_current_column_number($this->parser); |
|
| 133 | + $errormsg = "$xml_error at line $error_line, column $error_col"; |
|
| 134 | + |
|
| 135 | + $this->error($errormsg); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + xml_parser_free($this->parser); |
|
| 140 | + |
|
| 141 | + $this->normalize(); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param $p |
|
| 146 | + * @param $element |
|
| 147 | + * @param $attrs |
|
| 148 | + */ |
|
| 149 | + public function feed_start_element($p, $element, &$attrs) { |
|
| 150 | + $el = $element = strtolower($element); |
|
| 151 | + $attrs = array_change_key_case($attrs, CASE_LOWER); |
|
| 152 | + |
|
| 153 | + // check for a namespace, and split if found |
|
| 154 | + $ns = false; |
|
| 155 | + if (strpos($element, ':')) { |
|
| 156 | + list($ns, $el) = explode(':', $element, 2); |
|
| 157 | + } |
|
| 158 | + if ($ns && $ns !== 'rdf') { |
|
| 159 | + $this->current_namespace = $ns; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + # if feed type isn't set, then this is first element of feed |
|
| 163 | + # identify feed from root element |
|
| 164 | + # |
|
| 165 | + if (!isset($this->feed_type)) { |
|
| 166 | + if ($el === 'rdf') { |
|
| 167 | + $this->feed_type = RSS; |
|
| 168 | + $this->feed_version = '1.0'; |
|
| 169 | + } elseif ($el === 'rss') { |
|
| 170 | + $this->feed_type = RSS; |
|
| 171 | + $this->feed_version = $attrs['version']; |
|
| 172 | + } elseif ($el === 'feed') { |
|
| 173 | + $this->feed_type = ATOM; |
|
| 174 | + $this->feed_version = $attrs['version']; |
|
| 175 | + $this->inchannel = true; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if ($el === 'channel') { |
|
| 182 | + $this->inchannel = true; |
|
| 183 | + } elseif ($el === 'item' || $el === 'entry') { |
|
| 184 | + $this->initem = true; |
|
| 185 | + if (isset($attrs['rdf:about'])) { |
|
| 186 | + $this->current_item['about'] = $attrs['rdf:about']; |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // if we're in the default namespace of an RSS feed, |
|
| 191 | + // record textinput or image fields |
|
| 192 | + elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'textinput') { |
|
| 193 | + $this->intextinput = true; |
|
| 194 | + } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'image') { |
|
| 195 | + $this->inimage = true; |
|
| 196 | + } # handle atom content constructs |
|
| 197 | + elseif ($this->feed_type == ATOM && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 198 | + // avoid clashing w/ RSS mod_content |
|
| 199 | + if ($el === 'content') { |
|
| 200 | + $el = 'atom_content'; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $this->incontent = $el; |
|
| 204 | + } // if inside an Atom content construct (e.g. content or summary) field treat tags as text |
|
| 205 | + elseif ($this->feed_type == ATOM && $this->incontent) { |
|
| 206 | + // if tags are inlined, then flatten |
|
| 207 | + $attrs_str = implode(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs))); |
|
| 208 | + |
|
| 209 | + $this->append_content("<$element $attrs_str>"); |
|
| 210 | + |
|
| 211 | + array_unshift($this->stack, $el); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // Atom support many links per containging element. |
|
| 215 | + // Magpie treats link elements of type rel='alternate' |
|
| 216 | + // as being equivalent to RSS's simple link element. |
|
| 217 | + // |
|
| 218 | + elseif ($this->feed_type == ATOM && $el === 'link') { |
|
| 219 | + if (isset($attrs['rel']) && $attrs['rel'] === 'alternate') { |
|
| 220 | + $link_el = 'link'; |
|
| 221 | + } else { |
|
| 222 | + $link_el = 'link_' . $attrs['rel']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $this->append($link_el, $attrs['href']); |
|
| 226 | + } // set stack[0] to current element |
|
| 227 | + else { |
|
| 228 | + array_unshift($this->stack, $el); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param $p |
|
| 234 | + * @param $text |
|
| 235 | + */ |
|
| 236 | + public function feed_cdata($p, $text) { |
|
| 237 | + if ($this->feed_type == ATOM && $this->incontent) { |
|
| 238 | + $this->append_content($text); |
|
| 239 | + } else { |
|
| 240 | + $current_el = implode('_', array_reverse($this->stack)); |
|
| 241 | + $this->append($current_el, $text); |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * @param $p |
|
| 247 | + * @param $el |
|
| 248 | + */ |
|
| 249 | + public function feed_end_element($p, $el) { |
|
| 250 | + $el = strtolower($el); |
|
| 251 | + |
|
| 252 | + if ($el === 'item' || $el === 'entry') { |
|
| 253 | + $this->items[] = $this->current_item; |
|
| 254 | + $this->current_item = array(); |
|
| 255 | + $this->initem = false; |
|
| 256 | + } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'textinput') { |
|
| 257 | + $this->intextinput = false; |
|
| 258 | + } elseif ($this->feed_type == RSS && $this->current_namespace === '' && $el === 'image') { |
|
| 259 | + $this->inimage = false; |
|
| 260 | + } elseif ($this->feed_type == ATOM && in_array($el, $this->_CONTENT_CONSTRUCTS)) { |
|
| 261 | + $this->incontent = false; |
|
| 262 | + } elseif ($el === 'channel' || $el === 'feed') { |
|
| 263 | + $this->inchannel = false; |
|
| 264 | + } elseif ($this->feed_type == ATOM && $this->incontent) { |
|
| 265 | + // balance tags properly |
|
| 266 | + // note: i don't think this is actually neccessary |
|
| 267 | + if ($this->stack[0] == $el) { |
|
| 268 | + $this->append_content("</$el>"); |
|
| 269 | + } else { |
|
| 270 | + $this->append_content("<$el />"); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + array_shift($this->stack); |
|
| 274 | + } else { |
|
| 275 | + array_shift($this->stack); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + $this->current_namespace = false; |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * @param $str1 |
|
| 283 | + * @param string $str2 |
|
| 284 | + */ |
|
| 285 | + public function concat(&$str1, $str2 = '') { |
|
| 286 | + if (!isset($str1)) { |
|
| 287 | + $str1 = ''; |
|
| 288 | + } |
|
| 289 | + $str1 .= $str2; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * @param $text |
|
| 294 | + */ |
|
| 295 | + public function append_content($text) { |
|
| 296 | + if ($this->initem) { |
|
| 297 | + $this->concat($this->current_item[$this->incontent], $text); |
|
| 298 | + } elseif ($this->inchannel) { |
|
| 299 | + $this->concat($this->channel[$this->incontent], $text); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // smart append - field and namespace aware |
|
| 304 | + /** |
|
| 305 | + * @param $el |
|
| 306 | + * @param $text |
|
| 307 | + */ |
|
| 308 | + public function append($el, $text) { |
|
| 309 | + if (!$el) { |
|
| 310 | + return; |
|
| 311 | + } |
|
| 312 | + if ($this->current_namespace) { |
|
| 313 | + if ($this->initem) { |
|
| 314 | + $this->concat($this->current_item[$this->current_namespace][$el], $text); |
|
| 315 | + } elseif ($this->inchannel) { |
|
| 316 | + $this->concat($this->channel[$this->current_namespace][$el], $text); |
|
| 317 | + } elseif ($this->intextinput) { |
|
| 318 | + $this->concat($this->textinput[$this->current_namespace][$el], $text); |
|
| 319 | + } elseif ($this->inimage) { |
|
| 320 | + $this->concat($this->image[$this->current_namespace][$el], $text); |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + if ($this->initem) { |
|
| 324 | + $this->concat($this->current_item[$el], $text); |
|
| 325 | + } elseif ($this->intextinput) { |
|
| 326 | + $this->concat($this->textinput[$el], $text); |
|
| 327 | + } elseif ($this->inimage) { |
|
| 328 | + $this->concat($this->image[$el], $text); |
|
| 329 | + } elseif ($this->inchannel) { |
|
| 330 | + $this->concat($this->channel[$el], $text); |
|
| 331 | + } |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + public function normalize() { |
|
| 336 | + // if atom populate rss fields |
|
| 337 | + if ($this->is_atom()) { |
|
| 338 | + $this->channel['description'] = $this->channel['tagline']; |
|
| 339 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 340 | + $item = $this->items[$i]; |
|
| 341 | + if (isset($item['summary'])) { |
|
| 342 | + $item['description'] = $item['summary']; |
|
| 343 | + } |
|
| 344 | + if (isset($item['atom_content'])) { |
|
| 345 | + $item['content']['encoded'] = $item['atom_content']; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + $atom_date = isset($item['issued']) ? $item['issued'] : @$item['modified']; |
|
| 349 | + if ($atom_date) { |
|
| 350 | + $epoch = @parse_w3cdtf($atom_date); |
|
| 351 | + if ($epoch && $epoch > 0) { |
|
| 352 | + $item['date_timestamp'] = $epoch; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $this->items[$i] = $item; |
|
| 357 | + } |
|
| 358 | + } elseif ($this->is_rss()) { |
|
| 359 | + $this->channel['tagline'] = $this->channel['description']; |
|
| 360 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 361 | + $item = $this->items[$i]; |
|
| 362 | + if (isset($item['description'])) { |
|
| 363 | + $item['summary'] = $item['description']; |
|
| 364 | + } |
|
| 365 | + if (isset($item['content']['encoded'])) { |
|
| 366 | + $item['atom_content'] = $item['content']['encoded']; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + if ($this->is_rss() === '1.0' && isset($item['dc']['date'])) { |
|
| 370 | + $epoch = @parse_w3cdtf($item['dc']['date']); |
|
| 371 | + if ($epoch && $epoch > 0) { |
|
| 372 | + $item['date_timestamp'] = $epoch; |
|
| 373 | + } |
|
| 374 | + } elseif (isset($item['pubdate'])) { |
|
| 375 | + $epoch = @strtotime($item['pubdate']); |
|
| 376 | + if ($epoch > 0) { |
|
| 377 | + $item['date_timestamp'] = $epoch; |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + $this->items[$i] = $item; |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * @return bool |
|
| 388 | + */ |
|
| 389 | + public function is_rss() { |
|
| 390 | + if ($this->feed_type == RSS) { |
|
| 391 | + return $this->feed_version; |
|
| 392 | + } else { |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @return bool |
|
| 399 | + */ |
|
| 400 | + public function is_atom() { |
|
| 401 | + if ($this->feed_type == ATOM) { |
|
| 402 | + return $this->feed_version; |
|
| 403 | + } else { |
|
| 404 | + return false; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * return XML parser, and possibly re-encoded source |
|
| 410 | + * @param $source |
|
| 411 | + * @param $out_enc |
|
| 412 | + * @param $in_enc |
|
| 413 | + * @param $detect |
|
| 414 | + * @return array |
|
| 415 | + */ |
|
| 416 | + public function create_parser($source, $out_enc, $in_enc, $detect) { |
|
| 417 | + if (substr(phpversion(), 0, 1) == 5) { |
|
| 418 | + $parser = $this->php5_create_parser($in_enc, $detect); |
|
| 419 | + } else { |
|
| 420 | + list($parser, $source) = $this->php4_create_parser($source, $in_enc, $detect); |
|
| 421 | + } |
|
| 422 | + if ($out_enc) { |
|
| 423 | + $this->encoding = $out_enc; |
|
| 424 | + xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $out_enc); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + return array($parser, $source); |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Instantiate an XML parser under PHP5 |
|
| 432 | + * |
|
| 433 | + * PHP5 will do a fine job of detecting input encoding |
|
| 434 | + * if passed an empty string as the encoding. |
|
| 435 | + * |
|
| 436 | + * All hail libxml2! |
|
| 437 | + * @param $in_enc |
|
| 438 | + * @param $detect |
|
| 439 | + * @return resource |
|
| 440 | + */ |
|
| 441 | + public function php5_create_parser($in_enc, $detect) { |
|
| 442 | + // by default php5 does a fine job of detecting input encodings |
|
| 443 | + if (!$detect && $in_enc) { |
|
| 444 | + return xml_parser_create($in_enc); |
|
| 445 | + } else { |
|
| 446 | + return xml_parser_create(''); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Instaniate an XML parser under PHP4 |
|
| 452 | + * |
|
| 453 | + * Unfortunately PHP4's support for character encodings |
|
| 454 | + * and especially XML and character encodings sucks. As |
|
| 455 | + * long as the documents you parse only contain characters |
|
| 456 | + * from the ISO-8859-1 character set (a superset of ASCII, |
|
| 457 | + * and a subset of UTF-8) you're fine. However once you |
|
| 458 | + * step out of that comfy little world things get mad, bad, |
|
| 459 | + * and dangerous to know. |
|
| 460 | + * |
|
| 461 | + * The following code is based on SJM's work with FoF |
|
| 462 | + * @see http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss |
|
| 463 | + * @param $source |
|
| 464 | + * @param $in_enc |
|
| 465 | + * @param $detect |
|
| 466 | + * @return array |
|
| 467 | + */ |
|
| 468 | + public function php4_create_parser($source, $in_enc, $detect) { |
|
| 469 | + if (!$detect) { |
|
| 470 | + return array(xml_parser_create($in_enc), $source); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + if (!$in_enc) { |
|
| 474 | + if (preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/m', $source, $m)) { |
|
| 475 | + $in_enc = strtoupper($m[1]); |
|
| 476 | + $this->source_encoding = $in_enc; |
|
| 477 | + } else { |
|
| 478 | + $in_enc = 'UTF-8'; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + if ($this->known_encoding($in_enc)) { |
|
| 483 | + return array(xml_parser_create($in_enc), $source); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /* |
|
| 487 | 487 | // the dectected encoding is not one of the simple encodings PHP knows |
| 488 | 488 | |
| 489 | 489 | // attempt to use the iconv extension to |
@@ -512,44 +512,44 @@ discard block |
||
| 512 | 512 | E_USER_NOTICE); |
| 513 | 513 | */ |
| 514 | 514 | |
| 515 | - return array(xml_parser_create(), $source); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * @param $enc |
|
| 520 | - * @return bool|string |
|
| 521 | - */ |
|
| 522 | - public function known_encoding($enc) { |
|
| 523 | - $enc = strtoupper($enc); |
|
| 524 | - if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
| 525 | - return $enc; |
|
| 526 | - } else { |
|
| 527 | - return false; |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - /** |
|
| 532 | - * @param $errormsg |
|
| 533 | - * @param int $lvl |
|
| 534 | - */ |
|
| 535 | - public function error($errormsg, $lvl = E_USER_WARNING) { |
|
| 536 | - // append PHP's error message if track_errors enabled |
|
| 537 | - if (!empty($php_errormsg)) { |
|
| 538 | - $errormsg .= " ($php_errormsg)"; |
|
| 539 | - } |
|
| 540 | - if (MAGPIE_DEBUG) { |
|
| 541 | - trigger_error($errormsg, $lvl); |
|
| 542 | - } else { |
|
| 543 | - error_log($errormsg, 0); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - $notices = E_USER_NOTICE | E_NOTICE; |
|
| 547 | - if ($lvl & $notices) { |
|
| 548 | - $this->WARNING = $errormsg; |
|
| 549 | - } else { |
|
| 550 | - $this->ERROR = $errormsg; |
|
| 551 | - } |
|
| 552 | - } |
|
| 515 | + return array(xml_parser_create(), $source); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * @param $enc |
|
| 520 | + * @return bool|string |
|
| 521 | + */ |
|
| 522 | + public function known_encoding($enc) { |
|
| 523 | + $enc = strtoupper($enc); |
|
| 524 | + if (in_array($enc, $this->_KNOWN_ENCODINGS)) { |
|
| 525 | + return $enc; |
|
| 526 | + } else { |
|
| 527 | + return false; |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + /** |
|
| 532 | + * @param $errormsg |
|
| 533 | + * @param int $lvl |
|
| 534 | + */ |
|
| 535 | + public function error($errormsg, $lvl = E_USER_WARNING) { |
|
| 536 | + // append PHP's error message if track_errors enabled |
|
| 537 | + if (!empty($php_errormsg)) { |
|
| 538 | + $errormsg .= " ($php_errormsg)"; |
|
| 539 | + } |
|
| 540 | + if (MAGPIE_DEBUG) { |
|
| 541 | + trigger_error($errormsg, $lvl); |
|
| 542 | + } else { |
|
| 543 | + error_log($errormsg, 0); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + $notices = E_USER_NOTICE | E_NOTICE; |
|
| 547 | + if ($lvl & $notices) { |
|
| 548 | + $this->WARNING = $errormsg; |
|
| 549 | + } else { |
|
| 550 | + $this->ERROR = $errormsg; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | 553 | } // end class RSS |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | * @return string |
| 559 | 559 | */ |
| 560 | 560 | function map_attrs($k, $v) { |
| 561 | - return "$k=\"$v\""; |
|
| 561 | + return "$k=\"$v\""; |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | /** |
@@ -566,50 +566,50 @@ discard block |
||
| 566 | 566 | * @return int |
| 567 | 567 | */ |
| 568 | 568 | function parse_w3cdtf($date_str) { |
| 569 | - # regex to match wc3dtf |
|
| 570 | - $pat = "/(\d{4})-(\d{2})-(\d{2})[T]?(\d{2})?[:]?(\d{2})?(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
|
| 571 | - |
|
| 572 | - if (preg_match($pat, $date_str, $match)) { |
|
| 573 | - list($year, $month, $day, $hours, $minutes, $seconds) = array( |
|
| 574 | - $match[1], |
|
| 575 | - $match[2], |
|
| 576 | - $match[3], |
|
| 577 | - $match[4], |
|
| 578 | - $match[5], |
|
| 579 | - $match[6] |
|
| 580 | - ); |
|
| 581 | - |
|
| 582 | - # calc epoch for current date assuming GMT |
|
| 583 | - $epoch = gmmktime((int)$hours, (int)$minutes, (int)$seconds, (int)$month, (int)$day, (int)$year); |
|
| 584 | - |
|
| 585 | - $offset = 0; |
|
| 586 | - if ($match[10] === 'Z') { |
|
| 587 | - # zulu time, aka GMT |
|
| 588 | - } else { |
|
| 589 | - list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]); |
|
| 590 | - |
|
| 591 | - # zero out the variables |
|
| 592 | - if (!$tz_hour) { |
|
| 593 | - $tz_hour = 0; |
|
| 594 | - } |
|
| 595 | - if (!$tz_min) { |
|
| 596 | - $tz_min = 0; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
| 600 | - |
|
| 601 | - # is timezone ahead of GMT? then subtract offset |
|
| 602 | - # |
|
| 603 | - if ($tz_mod == '+') { |
|
| 604 | - $offset_secs = $offset_secs * -1; |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - $offset = $offset_secs; |
|
| 608 | - } |
|
| 609 | - $epoch = $epoch + $offset; |
|
| 610 | - |
|
| 611 | - return $epoch; |
|
| 612 | - } else { |
|
| 613 | - return -1; |
|
| 614 | - } |
|
| 569 | + # regex to match wc3dtf |
|
| 570 | + $pat = "/(\d{4})-(\d{2})-(\d{2})[T]?(\d{2})?[:]?(\d{2})?(:(\d{2}))?(?:([-+])(\d{2}):?(\d{2})|(Z))?/"; |
|
| 571 | + |
|
| 572 | + if (preg_match($pat, $date_str, $match)) { |
|
| 573 | + list($year, $month, $day, $hours, $minutes, $seconds) = array( |
|
| 574 | + $match[1], |
|
| 575 | + $match[2], |
|
| 576 | + $match[3], |
|
| 577 | + $match[4], |
|
| 578 | + $match[5], |
|
| 579 | + $match[6] |
|
| 580 | + ); |
|
| 581 | + |
|
| 582 | + # calc epoch for current date assuming GMT |
|
| 583 | + $epoch = gmmktime((int)$hours, (int)$minutes, (int)$seconds, (int)$month, (int)$day, (int)$year); |
|
| 584 | + |
|
| 585 | + $offset = 0; |
|
| 586 | + if ($match[10] === 'Z') { |
|
| 587 | + # zulu time, aka GMT |
|
| 588 | + } else { |
|
| 589 | + list($tz_mod, $tz_hour, $tz_min) = array($match[8], $match[9], $match[10]); |
|
| 590 | + |
|
| 591 | + # zero out the variables |
|
| 592 | + if (!$tz_hour) { |
|
| 593 | + $tz_hour = 0; |
|
| 594 | + } |
|
| 595 | + if (!$tz_min) { |
|
| 596 | + $tz_min = 0; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + $offset_secs = (($tz_hour * 60) + $tz_min) * 60; |
|
| 600 | + |
|
| 601 | + # is timezone ahead of GMT? then subtract offset |
|
| 602 | + # |
|
| 603 | + if ($tz_mod == '+') { |
|
| 604 | + $offset_secs = $offset_secs * -1; |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + $offset = $offset_secs; |
|
| 608 | + } |
|
| 609 | + $epoch = $epoch + $offset; |
|
| 610 | + |
|
| 611 | + return $epoch; |
|
| 612 | + } else { |
|
| 613 | + return -1; |
|
| 614 | + } |
|
| 615 | 615 | } |
@@ -44,29 +44,29 @@ discard block |
||
| 44 | 44 | **/ |
| 45 | 45 | if (!class_exists('Bblog')): |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class Bblog |
|
| 49 | - */ |
|
| 50 | - class Bblog extends XoopsObject |
|
| 51 | - { |
|
| 52 | - /** |
|
| 53 | - * Constructor |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - // parent:__construct(); |
|
| 57 | - $this->table = planet_DB_prefix('blog'); |
|
| 58 | - $this->initVar('blog_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | - $this->initVar('blog_title', XOBJ_DTYPE_TXTBOX, null, true); |
|
| 60 | - $this->initVar('blog_desc', XOBJ_DTYPE_TXTBOX, null); |
|
| 61 | - /* rss URI */ |
|
| 62 | - $this->initVar('blog_feed', XOBJ_DTYPE_TXTBOX, null, true); |
|
| 63 | - $this->initVar('blog_language', XOBJ_DTYPE_TXTBOX, null); |
|
| 64 | - $this->initVar('blog_charset', XOBJ_DTYPE_TXTBOX, null); |
|
| 65 | - /* blog website */ |
|
| 66 | - $this->initVar('blog_link', XOBJ_DTYPE_TXTBOX, null); |
|
| 67 | - $this->initVar('blog_image', XOBJ_DTYPE_TXTBOX, null); |
|
| 68 | - |
|
| 69 | - /* regexp for blog article trackback |
|
| 47 | + /** |
|
| 48 | + * Class Bblog |
|
| 49 | + */ |
|
| 50 | + class Bblog extends XoopsObject |
|
| 51 | + { |
|
| 52 | + /** |
|
| 53 | + * Constructor |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + // parent:__construct(); |
|
| 57 | + $this->table = planet_DB_prefix('blog'); |
|
| 58 | + $this->initVar('blog_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | + $this->initVar('blog_title', XOBJ_DTYPE_TXTBOX, null, true); |
|
| 60 | + $this->initVar('blog_desc', XOBJ_DTYPE_TXTBOX, null); |
|
| 61 | + /* rss URI */ |
|
| 62 | + $this->initVar('blog_feed', XOBJ_DTYPE_TXTBOX, null, true); |
|
| 63 | + $this->initVar('blog_language', XOBJ_DTYPE_TXTBOX, null); |
|
| 64 | + $this->initVar('blog_charset', XOBJ_DTYPE_TXTBOX, null); |
|
| 65 | + /* blog website */ |
|
| 66 | + $this->initVar('blog_link', XOBJ_DTYPE_TXTBOX, null); |
|
| 67 | + $this->initVar('blog_image', XOBJ_DTYPE_TXTBOX, null); |
|
| 68 | + |
|
| 69 | + /* regexp for blog article trackback |
|
| 70 | 70 | * From article url to article trackback URI |
| 71 | 71 | * |
| 72 | 72 | * For example: http://www.example.com/blog/111.html => http://www.example.com/blog/trackback/111.html |
@@ -77,71 +77,71 @@ discard block |
||
| 77 | 77 | * The input shall be: pattern[SPACE]replacement |
| 78 | 78 | * (.*wordpress/)(index.php)?(\?p.*) $1wp-trackback/$3 |
| 79 | 79 | */ |
| 80 | - $this->initVar('blog_trackback', XOBJ_DTYPE_TXTBOX, ''); |
|
| 81 | - |
|
| 82 | - /* blog submitter: is_numeric - uid; is_string - IP */ |
|
| 83 | - $this->initVar('blog_submitter', XOBJ_DTYPE_TXTBOX, ''); |
|
| 84 | - |
|
| 85 | - /* blog status: 0 - pending; 1 - active; 2 - featured */ |
|
| 86 | - $this->initVar('blog_status', XOBJ_DTYPE_INT, 1); |
|
| 87 | - |
|
| 88 | - /* key for blog content */ |
|
| 89 | - $this->initVar('blog_key', XOBJ_DTYPE_TXTBOX, ''); |
|
| 90 | - |
|
| 91 | - $this->initVar('blog_time', XOBJ_DTYPE_INT, 0); |
|
| 92 | - $this->initVar('blog_rating', XOBJ_DTYPE_INT, 0); |
|
| 93 | - $this->initVar('blog_rates', XOBJ_DTYPE_INT, 0); |
|
| 94 | - /* bookmark times */ |
|
| 95 | - $this->initVar('blog_marks', XOBJ_DTYPE_INT, 0); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * get formatted publish time of the article |
|
| 100 | - * |
|
| 101 | - * {@link Config} |
|
| 102 | - * |
|
| 103 | - * @param string $format format of time |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public function getTime($format = '') { |
|
| 107 | - $time = planet_formatTimestamp($this->getVar('blog_time'), $format); |
|
| 108 | - |
|
| 109 | - return $time; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * get verified image url of the category |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 117 | - public function getImage() { |
|
| 118 | - $image = $this->getVar('blog_image'); |
|
| 119 | - |
|
| 120 | - return $image; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * get rating average of the article |
|
| 125 | - * |
|
| 126 | - * @param int $decimals decimal length |
|
| 127 | - * @return numeric |
|
| 128 | - */ |
|
| 129 | - public function getRatingAverage($decimals = 1) { |
|
| 130 | - $ave = 3; |
|
| 131 | - if ($this->getVar('blog_rates')) { |
|
| 132 | - $ave = number_format($this->getVar('blog_rating') / $this->getVar('blog_rates'), $decimals); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $ave; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return numeric |
|
| 140 | - */ |
|
| 141 | - public function getStar() { |
|
| 142 | - return $this->getRatingAverage(0); |
|
| 143 | - } |
|
| 144 | - } |
|
| 80 | + $this->initVar('blog_trackback', XOBJ_DTYPE_TXTBOX, ''); |
|
| 81 | + |
|
| 82 | + /* blog submitter: is_numeric - uid; is_string - IP */ |
|
| 83 | + $this->initVar('blog_submitter', XOBJ_DTYPE_TXTBOX, ''); |
|
| 84 | + |
|
| 85 | + /* blog status: 0 - pending; 1 - active; 2 - featured */ |
|
| 86 | + $this->initVar('blog_status', XOBJ_DTYPE_INT, 1); |
|
| 87 | + |
|
| 88 | + /* key for blog content */ |
|
| 89 | + $this->initVar('blog_key', XOBJ_DTYPE_TXTBOX, ''); |
|
| 90 | + |
|
| 91 | + $this->initVar('blog_time', XOBJ_DTYPE_INT, 0); |
|
| 92 | + $this->initVar('blog_rating', XOBJ_DTYPE_INT, 0); |
|
| 93 | + $this->initVar('blog_rates', XOBJ_DTYPE_INT, 0); |
|
| 94 | + /* bookmark times */ |
|
| 95 | + $this->initVar('blog_marks', XOBJ_DTYPE_INT, 0); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * get formatted publish time of the article |
|
| 100 | + * |
|
| 101 | + * {@link Config} |
|
| 102 | + * |
|
| 103 | + * @param string $format format of time |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public function getTime($format = '') { |
|
| 107 | + $time = planet_formatTimestamp($this->getVar('blog_time'), $format); |
|
| 108 | + |
|
| 109 | + return $time; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * get verified image url of the category |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | + public function getImage() { |
|
| 118 | + $image = $this->getVar('blog_image'); |
|
| 119 | + |
|
| 120 | + return $image; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * get rating average of the article |
|
| 125 | + * |
|
| 126 | + * @param int $decimals decimal length |
|
| 127 | + * @return numeric |
|
| 128 | + */ |
|
| 129 | + public function getRatingAverage($decimals = 1) { |
|
| 130 | + $ave = 3; |
|
| 131 | + if ($this->getVar('blog_rates')) { |
|
| 132 | + $ave = number_format($this->getVar('blog_rating') / $this->getVar('blog_rates'), $decimals); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $ave; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return numeric |
|
| 140 | + */ |
|
| 141 | + public function getStar() { |
|
| 142 | + return $this->getRatingAverage(0); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | 145 | endif; |
| 146 | 146 | /** |
| 147 | 147 | * Topic object handler class. |
@@ -30,26 +30,26 @@ |
||
| 30 | 30 | mod_loadFunctions('', $GLOBALS['moddirname']); |
| 31 | 31 | |
| 32 | 32 | if (!class_exists('Brate')): |
| 33 | - /** |
|
| 34 | - * Class Brate |
|
| 35 | - */ |
|
| 36 | - class Brate extends XoopsObject |
|
| 37 | - { |
|
| 38 | - /** |
|
| 39 | - * Brate constructor. |
|
| 40 | - * @param null $id |
|
| 41 | - */ |
|
| 42 | - public function __construct($id = null) { |
|
| 43 | - // $this->ArtObject(); |
|
| 44 | - $this->table = planet_DB_prefix('rate'); |
|
| 45 | - $this->initVar('rate_id', XOBJ_DTYPE_INT, null, false); |
|
| 46 | - $this->initVar('art_id', XOBJ_DTYPE_INT, 0, true); |
|
| 47 | - $this->initVar('rate_uid', XOBJ_DTYPE_INT, 0); |
|
| 48 | - $this->initVar('rate_ip', XOBJ_DTYPE_INT, 0); |
|
| 49 | - $this->initVar('rate_rating', XOBJ_DTYPE_INT, 0, true); |
|
| 50 | - $this->initVar('rate_time', XOBJ_DTYPE_INT, 0, true); |
|
| 51 | - } |
|
| 52 | - } |
|
| 33 | + /** |
|
| 34 | + * Class Brate |
|
| 35 | + */ |
|
| 36 | + class Brate extends XoopsObject |
|
| 37 | + { |
|
| 38 | + /** |
|
| 39 | + * Brate constructor. |
|
| 40 | + * @param null $id |
|
| 41 | + */ |
|
| 42 | + public function __construct($id = null) { |
|
| 43 | + // $this->ArtObject(); |
|
| 44 | + $this->table = planet_DB_prefix('rate'); |
|
| 45 | + $this->initVar('rate_id', XOBJ_DTYPE_INT, null, false); |
|
| 46 | + $this->initVar('art_id', XOBJ_DTYPE_INT, 0, true); |
|
| 47 | + $this->initVar('rate_uid', XOBJ_DTYPE_INT, 0); |
|
| 48 | + $this->initVar('rate_ip', XOBJ_DTYPE_INT, 0); |
|
| 49 | + $this->initVar('rate_rating', XOBJ_DTYPE_INT, 0, true); |
|
| 50 | + $this->initVar('rate_time', XOBJ_DTYPE_INT, 0, true); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | endif; |
| 54 | 54 | |
| 55 | 55 | planet_parse_class(' |
@@ -81,93 +81,93 @@ |
||
| 81 | 81 | * @link |
| 82 | 82 | */ |
| 83 | 83 | if (!class_exists('Xmlfeed')) { |
| 84 | - /** |
|
| 85 | - * Class Bxmlfeed |
|
| 86 | - */ |
|
| 87 | - class Bxmlfeed extends UniversalFeedCreator |
|
| 88 | - { |
|
| 89 | - public $version; |
|
| 90 | - public $filename = ''; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Bxmlfeed constructor. |
|
| 94 | - * @param $version |
|
| 95 | - */ |
|
| 96 | - public function __construct($version) { |
|
| 97 | - $this->filename = XOOPS_CACHE_PATH . '/feed.xml'; |
|
| 98 | - $this->version = $version; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param $var |
|
| 103 | - * @param $val |
|
| 104 | - * @param bool $encoding |
|
| 105 | - */ |
|
| 106 | - public function setVar($var, $val, $encoding = false) { |
|
| 107 | - if (!empty($encoding)) { |
|
| 108 | - $val = $this->convert_encoding($val); |
|
| 109 | - } |
|
| 110 | - $this->$var = $val; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param $val |
|
| 115 | - * @return array|mixed|string |
|
| 116 | - */ |
|
| 117 | - public function convert_encoding($val) { |
|
| 118 | - if (is_array($val)) { |
|
| 119 | - foreach (array_keys($val) as $key) { |
|
| 120 | - $val[$key] = $this->convert_encoding($val[$key]); |
|
| 121 | - } |
|
| 122 | - } else { |
|
| 123 | - $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return $val; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param $var |
|
| 131 | - * @return mixed |
|
| 132 | - */ |
|
| 133 | - public function getVar($var) { |
|
| 134 | - return $this->$var; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param $img |
|
| 139 | - */ |
|
| 140 | - public function setImage(&$img) { |
|
| 141 | - $image = new FeedImage(); |
|
| 142 | - foreach ($img as $key => $val) { |
|
| 143 | - $image->$key = $this->convert_encoding($val); |
|
| 144 | - } |
|
| 145 | - $this->setVar('image', $image); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * @param $itm |
|
| 150 | - */ |
|
| 151 | - public function _addItem(&$itm) { |
|
| 152 | - $item = new FeedItem(); |
|
| 153 | - foreach ($itm as $key => $val) { |
|
| 154 | - $item->$key = $this->convert_encoding($val); |
|
| 155 | - } |
|
| 156 | - $this->addItem($item); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * @param $items |
|
| 161 | - */ |
|
| 162 | - public function addItems(&$items) { |
|
| 163 | - if (!is_array($items) || count($items) == 0) { |
|
| 164 | - return; |
|
| 165 | - } |
|
| 166 | - foreach ($items as $item) { |
|
| 167 | - $this->_addItem($item); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 84 | + /** |
|
| 85 | + * Class Bxmlfeed |
|
| 86 | + */ |
|
| 87 | + class Bxmlfeed extends UniversalFeedCreator |
|
| 88 | + { |
|
| 89 | + public $version; |
|
| 90 | + public $filename = ''; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Bxmlfeed constructor. |
|
| 94 | + * @param $version |
|
| 95 | + */ |
|
| 96 | + public function __construct($version) { |
|
| 97 | + $this->filename = XOOPS_CACHE_PATH . '/feed.xml'; |
|
| 98 | + $this->version = $version; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param $var |
|
| 103 | + * @param $val |
|
| 104 | + * @param bool $encoding |
|
| 105 | + */ |
|
| 106 | + public function setVar($var, $val, $encoding = false) { |
|
| 107 | + if (!empty($encoding)) { |
|
| 108 | + $val = $this->convert_encoding($val); |
|
| 109 | + } |
|
| 110 | + $this->$var = $val; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param $val |
|
| 115 | + * @return array|mixed|string |
|
| 116 | + */ |
|
| 117 | + public function convert_encoding($val) { |
|
| 118 | + if (is_array($val)) { |
|
| 119 | + foreach (array_keys($val) as $key) { |
|
| 120 | + $val[$key] = $this->convert_encoding($val[$key]); |
|
| 121 | + } |
|
| 122 | + } else { |
|
| 123 | + $val = XoopsLocal::convert_encoding($val, $this->encoding, _CHARSET); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return $val; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param $var |
|
| 131 | + * @return mixed |
|
| 132 | + */ |
|
| 133 | + public function getVar($var) { |
|
| 134 | + return $this->$var; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param $img |
|
| 139 | + */ |
|
| 140 | + public function setImage(&$img) { |
|
| 141 | + $image = new FeedImage(); |
|
| 142 | + foreach ($img as $key => $val) { |
|
| 143 | + $image->$key = $this->convert_encoding($val); |
|
| 144 | + } |
|
| 145 | + $this->setVar('image', $image); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * @param $itm |
|
| 150 | + */ |
|
| 151 | + public function _addItem(&$itm) { |
|
| 152 | + $item = new FeedItem(); |
|
| 153 | + foreach ($itm as $key => $val) { |
|
| 154 | + $item->$key = $this->convert_encoding($val); |
|
| 155 | + } |
|
| 156 | + $this->addItem($item); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * @param $items |
|
| 161 | + */ |
|
| 162 | + public function addItems(&$items) { |
|
| 163 | + if (!is_array($items) || count($items) == 0) { |
|
| 164 | + return; |
|
| 165 | + } |
|
| 166 | + foreach ($items as $item) { |
|
| 167 | + $this->_addItem($item); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | planet_parse_class(' |
@@ -44,22 +44,22 @@ |
||
| 44 | 44 | **/ |
| 45 | 45 | if (!class_exists('Bcategory')): |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class Bcategory |
|
| 49 | - */ |
|
| 50 | - class Bcategory extends XoopsObject |
|
| 51 | - { |
|
| 52 | - /** |
|
| 53 | - * Constructor |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - // $this->ArtObject(); |
|
| 57 | - $this->table = planet_DB_prefix('category'); |
|
| 58 | - $this->initVar('cat_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | - $this->initVar('cat_title', XOBJ_DTYPE_TXTBOX, '', true); |
|
| 60 | - $this->initVar('cat_order', XOBJ_DTYPE_INT, 1, false); |
|
| 61 | - } |
|
| 62 | - } |
|
| 47 | + /** |
|
| 48 | + * Class Bcategory |
|
| 49 | + */ |
|
| 50 | + class Bcategory extends XoopsObject |
|
| 51 | + { |
|
| 52 | + /** |
|
| 53 | + * Constructor |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + // $this->ArtObject(); |
|
| 57 | + $this->table = planet_DB_prefix('category'); |
|
| 58 | + $this->initVar('cat_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | + $this->initVar('cat_title', XOBJ_DTYPE_TXTBOX, '', true); |
|
| 60 | + $this->initVar('cat_order', XOBJ_DTYPE_INT, 1, false); |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | 64 | endif; |
| 65 | 65 | /** |
@@ -14,132 +14,132 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class IXR_Value |
| 16 | 16 | { |
| 17 | - public $data; |
|
| 18 | - public $type; |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * IXR_Value constructor. |
|
| 22 | - * @param $data |
|
| 23 | - * @param bool $type |
|
| 24 | - */ |
|
| 25 | - public function __construct($data, $type = false) { |
|
| 26 | - $this->data = $data; |
|
| 27 | - if (!$type) { |
|
| 28 | - $type = $this->calculateType(); |
|
| 29 | - } |
|
| 30 | - $this->type = $type; |
|
| 31 | - if ($type === 'struct') { |
|
| 32 | - /* Turn all the values in the array in to new IXR_Value objects */ |
|
| 33 | - foreach ($this->data as $key => $value) { |
|
| 34 | - $this->data[$key] = new IXR_Value($value); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - if ($type === 'array') { |
|
| 38 | - for ($i = 0, $j = count($this->data); $i < $j; ++$i) { |
|
| 39 | - $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return string |
|
| 46 | - */ |
|
| 47 | - public function calculateType() { |
|
| 48 | - if ($this->data === true || $this->data === false) { |
|
| 49 | - return 'boolean'; |
|
| 50 | - } |
|
| 51 | - if (is_int($this->data)) { |
|
| 52 | - return 'int'; |
|
| 53 | - } |
|
| 54 | - if (is_float($this->data)) { |
|
| 55 | - return 'double'; |
|
| 56 | - } |
|
| 57 | - // Deal with IXR object types base64 and date |
|
| 58 | - if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 59 | - return 'date'; |
|
| 60 | - } |
|
| 61 | - if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 62 | - return 'base64'; |
|
| 63 | - } |
|
| 64 | - // If it is a normal PHP object convert it in to a struct |
|
| 65 | - if (is_object($this->data)) { |
|
| 66 | - $this->data = get_object_vars($this->data); |
|
| 67 | - |
|
| 68 | - return 'struct'; |
|
| 69 | - } |
|
| 70 | - if (!is_array($this->data)) { |
|
| 71 | - return 'string'; |
|
| 72 | - } |
|
| 73 | - /* We have an array - is it an array or a struct ? */ |
|
| 74 | - if ($this->isStruct($this->data)) { |
|
| 75 | - return 'struct'; |
|
| 76 | - } else { |
|
| 77 | - return 'array'; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return bool|string |
|
| 83 | - */ |
|
| 84 | - public function getXml() { |
|
| 85 | - /* Return XML for this value */ |
|
| 86 | - switch ($this->type) { |
|
| 87 | - case 'boolean': |
|
| 88 | - return '<boolean>' . ($this->data ? '1' : '0') . '</boolean>'; |
|
| 89 | - break; |
|
| 90 | - case 'int': |
|
| 91 | - return '<int>' . $this->data . '</int>'; |
|
| 92 | - break; |
|
| 93 | - case 'double': |
|
| 94 | - return '<double>' . $this->data . '</double>'; |
|
| 95 | - break; |
|
| 96 | - case 'string': |
|
| 97 | - return '<string>' . htmlspecialchars($this->data) . '</string>'; |
|
| 98 | - break; |
|
| 99 | - case 'array': |
|
| 100 | - $return = '<array><data>' . "\n"; |
|
| 101 | - foreach ($this->data as $item) { |
|
| 102 | - $return .= ' <value>' . $item->getXml() . "</value>\n"; |
|
| 103 | - } |
|
| 104 | - $return .= '</data></array>'; |
|
| 105 | - |
|
| 106 | - return $return; |
|
| 107 | - break; |
|
| 108 | - case 'struct': |
|
| 109 | - $return = '<struct>' . "\n"; |
|
| 110 | - foreach ($this->data as $name => $value) { |
|
| 111 | - $return .= " <member><name>$name</name><value>"; |
|
| 112 | - $return .= $value->getXml() . "</value></member>\n"; |
|
| 113 | - } |
|
| 114 | - $return .= '</struct>'; |
|
| 115 | - |
|
| 116 | - return $return; |
|
| 117 | - break; |
|
| 118 | - case 'date': |
|
| 119 | - case 'base64': |
|
| 120 | - return $this->data->getXml(); |
|
| 121 | - break; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return false; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @param $array |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - public function isStruct($array) { |
|
| 132 | - /* Nasty function to check if an array is a struct or not */ |
|
| 133 | - $expected = 0; |
|
| 134 | - foreach ($array as $key => $value) { |
|
| 135 | - if ((string)$key != (string)$expected) { |
|
| 136 | - return true; |
|
| 137 | - } |
|
| 138 | - ++$expected; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return false; |
|
| 142 | - } |
|
| 17 | + public $data; |
|
| 18 | + public $type; |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * IXR_Value constructor. |
|
| 22 | + * @param $data |
|
| 23 | + * @param bool $type |
|
| 24 | + */ |
|
| 25 | + public function __construct($data, $type = false) { |
|
| 26 | + $this->data = $data; |
|
| 27 | + if (!$type) { |
|
| 28 | + $type = $this->calculateType(); |
|
| 29 | + } |
|
| 30 | + $this->type = $type; |
|
| 31 | + if ($type === 'struct') { |
|
| 32 | + /* Turn all the values in the array in to new IXR_Value objects */ |
|
| 33 | + foreach ($this->data as $key => $value) { |
|
| 34 | + $this->data[$key] = new IXR_Value($value); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + if ($type === 'array') { |
|
| 38 | + for ($i = 0, $j = count($this->data); $i < $j; ++$i) { |
|
| 39 | + $this->data[$i] = new IXR_Value($this->data[$i]); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return string |
|
| 46 | + */ |
|
| 47 | + public function calculateType() { |
|
| 48 | + if ($this->data === true || $this->data === false) { |
|
| 49 | + return 'boolean'; |
|
| 50 | + } |
|
| 51 | + if (is_int($this->data)) { |
|
| 52 | + return 'int'; |
|
| 53 | + } |
|
| 54 | + if (is_float($this->data)) { |
|
| 55 | + return 'double'; |
|
| 56 | + } |
|
| 57 | + // Deal with IXR object types base64 and date |
|
| 58 | + if (is_object($this->data) && is_a($this->data, 'IXR_Date')) { |
|
| 59 | + return 'date'; |
|
| 60 | + } |
|
| 61 | + if (is_object($this->data) && is_a($this->data, 'IXR_Base64')) { |
|
| 62 | + return 'base64'; |
|
| 63 | + } |
|
| 64 | + // If it is a normal PHP object convert it in to a struct |
|
| 65 | + if (is_object($this->data)) { |
|
| 66 | + $this->data = get_object_vars($this->data); |
|
| 67 | + |
|
| 68 | + return 'struct'; |
|
| 69 | + } |
|
| 70 | + if (!is_array($this->data)) { |
|
| 71 | + return 'string'; |
|
| 72 | + } |
|
| 73 | + /* We have an array - is it an array or a struct ? */ |
|
| 74 | + if ($this->isStruct($this->data)) { |
|
| 75 | + return 'struct'; |
|
| 76 | + } else { |
|
| 77 | + return 'array'; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return bool|string |
|
| 83 | + */ |
|
| 84 | + public function getXml() { |
|
| 85 | + /* Return XML for this value */ |
|
| 86 | + switch ($this->type) { |
|
| 87 | + case 'boolean': |
|
| 88 | + return '<boolean>' . ($this->data ? '1' : '0') . '</boolean>'; |
|
| 89 | + break; |
|
| 90 | + case 'int': |
|
| 91 | + return '<int>' . $this->data . '</int>'; |
|
| 92 | + break; |
|
| 93 | + case 'double': |
|
| 94 | + return '<double>' . $this->data . '</double>'; |
|
| 95 | + break; |
|
| 96 | + case 'string': |
|
| 97 | + return '<string>' . htmlspecialchars($this->data) . '</string>'; |
|
| 98 | + break; |
|
| 99 | + case 'array': |
|
| 100 | + $return = '<array><data>' . "\n"; |
|
| 101 | + foreach ($this->data as $item) { |
|
| 102 | + $return .= ' <value>' . $item->getXml() . "</value>\n"; |
|
| 103 | + } |
|
| 104 | + $return .= '</data></array>'; |
|
| 105 | + |
|
| 106 | + return $return; |
|
| 107 | + break; |
|
| 108 | + case 'struct': |
|
| 109 | + $return = '<struct>' . "\n"; |
|
| 110 | + foreach ($this->data as $name => $value) { |
|
| 111 | + $return .= " <member><name>$name</name><value>"; |
|
| 112 | + $return .= $value->getXml() . "</value></member>\n"; |
|
| 113 | + } |
|
| 114 | + $return .= '</struct>'; |
|
| 115 | + |
|
| 116 | + return $return; |
|
| 117 | + break; |
|
| 118 | + case 'date': |
|
| 119 | + case 'base64': |
|
| 120 | + return $this->data->getXml(); |
|
| 121 | + break; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @param $array |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + public function isStruct($array) { |
|
| 132 | + /* Nasty function to check if an array is a struct or not */ |
|
| 133 | + $expected = 0; |
|
| 134 | + foreach ($array as $key => $value) { |
|
| 135 | + if ((string)$key != (string)$expected) { |
|
| 136 | + return true; |
|
| 137 | + } |
|
| 138 | + ++$expected; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -147,185 +147,185 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | class IXR_Message |
| 149 | 149 | { |
| 150 | - public $message; |
|
| 151 | - public $messageType; // methodCall / methodResponse / fault |
|
| 152 | - public $faultCode; |
|
| 153 | - public $faultString; |
|
| 154 | - public $methodName; |
|
| 155 | - public $params; |
|
| 156 | - // Current variable stacks |
|
| 157 | - public $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 158 | - public $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 159 | - public $_currentStructName = array(); // A stack as well |
|
| 160 | - public $_param; |
|
| 161 | - public $_value; |
|
| 162 | - public $_currentTag; |
|
| 163 | - public $_currentTagContents; |
|
| 164 | - // The XML parser |
|
| 165 | - public $_parser; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * IXR_Message constructor. |
|
| 169 | - * @param $message |
|
| 170 | - */ |
|
| 171 | - public function __construct($message) { |
|
| 172 | - $this->message = $message; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @return bool |
|
| 177 | - */ |
|
| 178 | - public function parse() { |
|
| 179 | - // first remove the XML declaration |
|
| 180 | - $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); |
|
| 181 | - if (trim($this->message) == '') { |
|
| 182 | - return false; |
|
| 183 | - } |
|
| 184 | - $this->_parser = xml_parser_create(); |
|
| 185 | - // Set XML parser to take the case of tags in to account |
|
| 186 | - xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 187 | - // Set XML parser callback functions |
|
| 188 | - xml_set_object($this->_parser, $this); |
|
| 189 | - xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 190 | - xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 191 | - if (!xml_parse($this->_parser, $this->message)) { |
|
| 192 | - /* die(sprintf('XML error: %s at line %d', |
|
| 150 | + public $message; |
|
| 151 | + public $messageType; // methodCall / methodResponse / fault |
|
| 152 | + public $faultCode; |
|
| 153 | + public $faultString; |
|
| 154 | + public $methodName; |
|
| 155 | + public $params; |
|
| 156 | + // Current variable stacks |
|
| 157 | + public $_arraystructs = array(); // The stack used to keep track of the current array/struct |
|
| 158 | + public $_arraystructstypes = array(); // Stack keeping track of if things are structs or array |
|
| 159 | + public $_currentStructName = array(); // A stack as well |
|
| 160 | + public $_param; |
|
| 161 | + public $_value; |
|
| 162 | + public $_currentTag; |
|
| 163 | + public $_currentTagContents; |
|
| 164 | + // The XML parser |
|
| 165 | + public $_parser; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * IXR_Message constructor. |
|
| 169 | + * @param $message |
|
| 170 | + */ |
|
| 171 | + public function __construct($message) { |
|
| 172 | + $this->message = $message; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @return bool |
|
| 177 | + */ |
|
| 178 | + public function parse() { |
|
| 179 | + // first remove the XML declaration |
|
| 180 | + $this->message = preg_replace('/<\?xml(.*)?\?' . '>/', '', $this->message); |
|
| 181 | + if (trim($this->message) == '') { |
|
| 182 | + return false; |
|
| 183 | + } |
|
| 184 | + $this->_parser = xml_parser_create(); |
|
| 185 | + // Set XML parser to take the case of tags in to account |
|
| 186 | + xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false); |
|
| 187 | + // Set XML parser callback functions |
|
| 188 | + xml_set_object($this->_parser, $this); |
|
| 189 | + xml_set_element_handler($this->_parser, 'tag_open', 'tag_close'); |
|
| 190 | + xml_set_character_data_handler($this->_parser, 'cdata'); |
|
| 191 | + if (!xml_parse($this->_parser, $this->message)) { |
|
| 192 | + /* die(sprintf('XML error: %s at line %d', |
|
| 193 | 193 | xml_error_string(xml_get_error_code($this->_parser)), |
| 194 | 194 | xml_get_current_line_number($this->_parser))); */ |
| 195 | 195 | |
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - xml_parser_free($this->_parser); |
|
| 199 | - // Grab the error messages, if any |
|
| 200 | - if ($this->messageType === 'fault') { |
|
| 201 | - $this->faultCode = $this->params[0]['faultCode']; |
|
| 202 | - $this->faultString = $this->params[0]['faultString']; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return true; |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * @param $parser |
|
| 210 | - * @param $tag |
|
| 211 | - * @param $attr |
|
| 212 | - */ |
|
| 213 | - public function tag_open($parser, $tag, $attr) { |
|
| 214 | - $this->currentTag = $tag; |
|
| 215 | - switch ($tag) { |
|
| 216 | - case 'methodCall': |
|
| 217 | - case 'methodResponse': |
|
| 218 | - case 'fault': |
|
| 219 | - $this->messageType = $tag; |
|
| 220 | - break; |
|
| 221 | - /* Deal with stacks of arrays and structs */ |
|
| 222 | - case 'data': // data is to all intents and puposes more interesting than array |
|
| 223 | - $this->_arraystructstypes[] = 'array'; |
|
| 224 | - $this->_arraystructs[] = array(); |
|
| 225 | - break; |
|
| 226 | - case 'struct': |
|
| 227 | - $this->_arraystructstypes[] = 'struct'; |
|
| 228 | - $this->_arraystructs[] = array(); |
|
| 229 | - break; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @param $parser |
|
| 235 | - * @param $cdata |
|
| 236 | - */ |
|
| 237 | - public function cdata($parser, $cdata) { |
|
| 238 | - $this->_currentTagContents .= $cdata; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * @param $parser |
|
| 243 | - * @param $tag |
|
| 244 | - */ |
|
| 245 | - public function tag_close($parser, $tag) { |
|
| 246 | - $valueFlag = false; |
|
| 247 | - switch ($tag) { |
|
| 248 | - case 'int': |
|
| 249 | - case 'i4': |
|
| 250 | - $value = (int)trim($this->_currentTagContents); |
|
| 251 | - $this->_currentTagContents = ''; |
|
| 252 | - $valueFlag = true; |
|
| 253 | - break; |
|
| 254 | - case 'double': |
|
| 255 | - $value = (double)trim($this->_currentTagContents); |
|
| 256 | - $this->_currentTagContents = ''; |
|
| 257 | - $valueFlag = true; |
|
| 258 | - break; |
|
| 259 | - case 'string': |
|
| 260 | - $value = (string)trim($this->_currentTagContents); |
|
| 261 | - $this->_currentTagContents = ''; |
|
| 262 | - $valueFlag = true; |
|
| 263 | - break; |
|
| 264 | - case 'dateTime.iso8601': |
|
| 265 | - $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 266 | - // $value = $iso->getTimestamp(); |
|
| 267 | - $this->_currentTagContents = ''; |
|
| 268 | - $valueFlag = true; |
|
| 269 | - break; |
|
| 270 | - case 'value': |
|
| 271 | - // "If no type is indicated, the type is string." |
|
| 272 | - if (trim($this->_currentTagContents) != '') { |
|
| 273 | - $value = (string)$this->_currentTagContents; |
|
| 274 | - $this->_currentTagContents = ''; |
|
| 275 | - $valueFlag = true; |
|
| 276 | - } |
|
| 277 | - break; |
|
| 278 | - case 'boolean': |
|
| 279 | - $value = (boolean)trim($this->_currentTagContents); |
|
| 280 | - $this->_currentTagContents = ''; |
|
| 281 | - $valueFlag = true; |
|
| 282 | - break; |
|
| 283 | - case 'base64': |
|
| 284 | - $value = base64_decode(trim($this->_currentTagContents)); |
|
| 285 | - $this->_currentTagContents = ''; |
|
| 286 | - $valueFlag = true; |
|
| 287 | - break; |
|
| 288 | - /* Deal with stacks of arrays and structs */ |
|
| 289 | - case 'data': |
|
| 290 | - case 'struct': |
|
| 291 | - $value = array_pop($this->_arraystructs); |
|
| 292 | - array_pop($this->_arraystructstypes); |
|
| 293 | - $valueFlag = true; |
|
| 294 | - break; |
|
| 295 | - case 'member': |
|
| 296 | - array_pop($this->_currentStructName); |
|
| 297 | - break; |
|
| 298 | - case 'name': |
|
| 299 | - $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 300 | - $this->_currentTagContents = ''; |
|
| 301 | - break; |
|
| 302 | - case 'methodName': |
|
| 303 | - $this->methodName = trim($this->_currentTagContents); |
|
| 304 | - $this->_currentTagContents = ''; |
|
| 305 | - break; |
|
| 306 | - } |
|
| 307 | - if ($valueFlag) { |
|
| 308 | - /* |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + xml_parser_free($this->_parser); |
|
| 199 | + // Grab the error messages, if any |
|
| 200 | + if ($this->messageType === 'fault') { |
|
| 201 | + $this->faultCode = $this->params[0]['faultCode']; |
|
| 202 | + $this->faultString = $this->params[0]['faultString']; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * @param $parser |
|
| 210 | + * @param $tag |
|
| 211 | + * @param $attr |
|
| 212 | + */ |
|
| 213 | + public function tag_open($parser, $tag, $attr) { |
|
| 214 | + $this->currentTag = $tag; |
|
| 215 | + switch ($tag) { |
|
| 216 | + case 'methodCall': |
|
| 217 | + case 'methodResponse': |
|
| 218 | + case 'fault': |
|
| 219 | + $this->messageType = $tag; |
|
| 220 | + break; |
|
| 221 | + /* Deal with stacks of arrays and structs */ |
|
| 222 | + case 'data': // data is to all intents and puposes more interesting than array |
|
| 223 | + $this->_arraystructstypes[] = 'array'; |
|
| 224 | + $this->_arraystructs[] = array(); |
|
| 225 | + break; |
|
| 226 | + case 'struct': |
|
| 227 | + $this->_arraystructstypes[] = 'struct'; |
|
| 228 | + $this->_arraystructs[] = array(); |
|
| 229 | + break; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @param $parser |
|
| 235 | + * @param $cdata |
|
| 236 | + */ |
|
| 237 | + public function cdata($parser, $cdata) { |
|
| 238 | + $this->_currentTagContents .= $cdata; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * @param $parser |
|
| 243 | + * @param $tag |
|
| 244 | + */ |
|
| 245 | + public function tag_close($parser, $tag) { |
|
| 246 | + $valueFlag = false; |
|
| 247 | + switch ($tag) { |
|
| 248 | + case 'int': |
|
| 249 | + case 'i4': |
|
| 250 | + $value = (int)trim($this->_currentTagContents); |
|
| 251 | + $this->_currentTagContents = ''; |
|
| 252 | + $valueFlag = true; |
|
| 253 | + break; |
|
| 254 | + case 'double': |
|
| 255 | + $value = (double)trim($this->_currentTagContents); |
|
| 256 | + $this->_currentTagContents = ''; |
|
| 257 | + $valueFlag = true; |
|
| 258 | + break; |
|
| 259 | + case 'string': |
|
| 260 | + $value = (string)trim($this->_currentTagContents); |
|
| 261 | + $this->_currentTagContents = ''; |
|
| 262 | + $valueFlag = true; |
|
| 263 | + break; |
|
| 264 | + case 'dateTime.iso8601': |
|
| 265 | + $value = new IXR_Date(trim($this->_currentTagContents)); |
|
| 266 | + // $value = $iso->getTimestamp(); |
|
| 267 | + $this->_currentTagContents = ''; |
|
| 268 | + $valueFlag = true; |
|
| 269 | + break; |
|
| 270 | + case 'value': |
|
| 271 | + // "If no type is indicated, the type is string." |
|
| 272 | + if (trim($this->_currentTagContents) != '') { |
|
| 273 | + $value = (string)$this->_currentTagContents; |
|
| 274 | + $this->_currentTagContents = ''; |
|
| 275 | + $valueFlag = true; |
|
| 276 | + } |
|
| 277 | + break; |
|
| 278 | + case 'boolean': |
|
| 279 | + $value = (boolean)trim($this->_currentTagContents); |
|
| 280 | + $this->_currentTagContents = ''; |
|
| 281 | + $valueFlag = true; |
|
| 282 | + break; |
|
| 283 | + case 'base64': |
|
| 284 | + $value = base64_decode(trim($this->_currentTagContents)); |
|
| 285 | + $this->_currentTagContents = ''; |
|
| 286 | + $valueFlag = true; |
|
| 287 | + break; |
|
| 288 | + /* Deal with stacks of arrays and structs */ |
|
| 289 | + case 'data': |
|
| 290 | + case 'struct': |
|
| 291 | + $value = array_pop($this->_arraystructs); |
|
| 292 | + array_pop($this->_arraystructstypes); |
|
| 293 | + $valueFlag = true; |
|
| 294 | + break; |
|
| 295 | + case 'member': |
|
| 296 | + array_pop($this->_currentStructName); |
|
| 297 | + break; |
|
| 298 | + case 'name': |
|
| 299 | + $this->_currentStructName[] = trim($this->_currentTagContents); |
|
| 300 | + $this->_currentTagContents = ''; |
|
| 301 | + break; |
|
| 302 | + case 'methodName': |
|
| 303 | + $this->methodName = trim($this->_currentTagContents); |
|
| 304 | + $this->_currentTagContents = ''; |
|
| 305 | + break; |
|
| 306 | + } |
|
| 307 | + if ($valueFlag) { |
|
| 308 | + /* |
|
| 309 | 309 | if (!is_array($value) && !is_object($value)) { |
| 310 | 310 | $value = trim($value); |
| 311 | 311 | } |
| 312 | 312 | */ |
| 313 | - if (count($this->_arraystructs) > 0) { |
|
| 314 | - // Add value to struct or array |
|
| 315 | - if ($this->_arraystructstypes[count($this->_arraystructstypes) - 1] === 'struct') { |
|
| 316 | - // Add to struct |
|
| 317 | - $this->_arraystructs[count($this->_arraystructs) |
|
| 318 | - - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 319 | - } else { |
|
| 320 | - // Add to array |
|
| 321 | - $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 322 | - } |
|
| 323 | - } else { |
|
| 324 | - // Just add as a paramater |
|
| 325 | - $this->params[] = $value; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 313 | + if (count($this->_arraystructs) > 0) { |
|
| 314 | + // Add value to struct or array |
|
| 315 | + if ($this->_arraystructstypes[count($this->_arraystructstypes) - 1] === 'struct') { |
|
| 316 | + // Add to struct |
|
| 317 | + $this->_arraystructs[count($this->_arraystructs) |
|
| 318 | + - 1][$this->_currentStructName[count($this->_currentStructName) - 1]] = $value; |
|
| 319 | + } else { |
|
| 320 | + // Add to array |
|
| 321 | + $this->_arraystructs[count($this->_arraystructs) - 1][] = $value; |
|
| 322 | + } |
|
| 323 | + } else { |
|
| 324 | + // Just add as a paramater |
|
| 325 | + $this->params[] = $value; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -333,53 +333,53 @@ discard block |
||
| 333 | 333 | */ |
| 334 | 334 | class IXR_Server |
| 335 | 335 | { |
| 336 | - public $data; |
|
| 337 | - public $callbacks = array(); |
|
| 338 | - public $message; |
|
| 339 | - public $capabilities; |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * IXR_Server constructor. |
|
| 343 | - * @param bool $callbacks |
|
| 344 | - * @param bool $data |
|
| 345 | - */ |
|
| 346 | - public function __construct($callbacks = false, $data = false) { |
|
| 347 | - $this->setCapabilities(); |
|
| 348 | - if ($callbacks) { |
|
| 349 | - $this->callbacks = $callbacks; |
|
| 350 | - } |
|
| 351 | - $this->setCallbacks(); |
|
| 352 | - $this->serve($data); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * @param bool $data |
|
| 357 | - */ |
|
| 358 | - public function serve($data = false) { |
|
| 359 | - if (!$data) { |
|
| 360 | - $http_raw_post_data = file_get_contents('php://input'); |
|
| 361 | - if (!$http_raw_post_data) { |
|
| 362 | - die('XML-RPC server accepts POST requests only.'); |
|
| 363 | - } |
|
| 364 | - $data = $http_raw_post_data; |
|
| 365 | - } |
|
| 366 | - $this->message = new IXR_Message($data); |
|
| 367 | - if (!$this->message->parse()) { |
|
| 368 | - $this->error(-32700, 'parse error. not well formed'); |
|
| 369 | - } |
|
| 370 | - if ($this->message->messageType !== 'methodCall') { |
|
| 371 | - $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 372 | - } |
|
| 373 | - $result = $this->call($this->message->methodName, $this->message->params); |
|
| 374 | - // Is the result an error? |
|
| 375 | - if (is_a($result, 'IXR_Error')) { |
|
| 376 | - $this->error($result); |
|
| 377 | - } |
|
| 378 | - // Encode the result |
|
| 379 | - $r = new IXR_Value($result); |
|
| 380 | - $resultxml = $r->getXml(); |
|
| 381 | - // Create the XML |
|
| 382 | - $xml = <<<EOD |
|
| 336 | + public $data; |
|
| 337 | + public $callbacks = array(); |
|
| 338 | + public $message; |
|
| 339 | + public $capabilities; |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * IXR_Server constructor. |
|
| 343 | + * @param bool $callbacks |
|
| 344 | + * @param bool $data |
|
| 345 | + */ |
|
| 346 | + public function __construct($callbacks = false, $data = false) { |
|
| 347 | + $this->setCapabilities(); |
|
| 348 | + if ($callbacks) { |
|
| 349 | + $this->callbacks = $callbacks; |
|
| 350 | + } |
|
| 351 | + $this->setCallbacks(); |
|
| 352 | + $this->serve($data); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * @param bool $data |
|
| 357 | + */ |
|
| 358 | + public function serve($data = false) { |
|
| 359 | + if (!$data) { |
|
| 360 | + $http_raw_post_data = file_get_contents('php://input'); |
|
| 361 | + if (!$http_raw_post_data) { |
|
| 362 | + die('XML-RPC server accepts POST requests only.'); |
|
| 363 | + } |
|
| 364 | + $data = $http_raw_post_data; |
|
| 365 | + } |
|
| 366 | + $this->message = new IXR_Message($data); |
|
| 367 | + if (!$this->message->parse()) { |
|
| 368 | + $this->error(-32700, 'parse error. not well formed'); |
|
| 369 | + } |
|
| 370 | + if ($this->message->messageType !== 'methodCall') { |
|
| 371 | + $this->error(-32600, 'server error. invalid xml-rpc. not conforming to spec. Request must be a methodCall'); |
|
| 372 | + } |
|
| 373 | + $result = $this->call($this->message->methodName, $this->message->params); |
|
| 374 | + // Is the result an error? |
|
| 375 | + if (is_a($result, 'IXR_Error')) { |
|
| 376 | + $this->error($result); |
|
| 377 | + } |
|
| 378 | + // Encode the result |
|
| 379 | + $r = new IXR_Value($result); |
|
| 380 | + $resultxml = $r->getXml(); |
|
| 381 | + // Create the XML |
|
| 382 | + $xml = <<<EOD |
|
| 383 | 383 | <methodResponse> |
| 384 | 384 | <params> |
| 385 | 385 | <param> |
@@ -391,154 +391,154 @@ discard block |
||
| 391 | 391 | </methodResponse> |
| 392 | 392 | |
| 393 | 393 | EOD; |
| 394 | - // Send it |
|
| 395 | - $this->output($xml); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @param $methodname |
|
| 400 | - * @param $args |
|
| 401 | - * @return IXR_Error|mixed |
|
| 402 | - */ |
|
| 403 | - public function call($methodname, $args) { |
|
| 404 | - if (!$this->hasMethod($methodname)) { |
|
| 405 | - return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); |
|
| 406 | - } |
|
| 407 | - $method = $this->callbacks[$methodname]; |
|
| 408 | - // Perform the callback and send the response |
|
| 409 | - if (count($args) == 1) { |
|
| 410 | - // If only one paramater just send that instead of the whole array |
|
| 411 | - $args = $args[0]; |
|
| 412 | - } |
|
| 413 | - // Are we dealing with a function or a method? |
|
| 414 | - if (substr($method, 0, 5) === 'this:') { |
|
| 415 | - // It's a class method - check it exists |
|
| 416 | - $method = substr($method, 5); |
|
| 417 | - if (!method_exists($this, $method)) { |
|
| 418 | - return new IXR_Error(-32601, 'server error. requested class method "' . $method . '" does not exist.'); |
|
| 419 | - } |
|
| 420 | - // Call the method |
|
| 421 | - $result = $this->$method($args); |
|
| 422 | - } else { |
|
| 423 | - // It's a function - does it exist? |
|
| 424 | - if (is_array($method)) { |
|
| 425 | - if (!method_exists($method[0], $method[1])) { |
|
| 426 | - return new IXR_Error(-32601, |
|
| 427 | - 'server error. requested object method "' . $method[1] . '" does not exist.'); |
|
| 428 | - } |
|
| 429 | - } elseif (!function_exists($method)) { |
|
| 430 | - return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); |
|
| 431 | - } |
|
| 432 | - // Call the function |
|
| 433 | - $result = call_user_func($method, $args); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $result; |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param $error |
|
| 441 | - * @param bool $message |
|
| 442 | - */ |
|
| 443 | - public function error($error, $message = false) { |
|
| 444 | - // Accepts either an error object or an error code and message |
|
| 445 | - if ($message && !is_object($error)) { |
|
| 446 | - $error = new IXR_Error($error, $message); |
|
| 447 | - } |
|
| 448 | - $this->output($error->getXml()); |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * @param $xml |
|
| 453 | - */ |
|
| 454 | - public function output($xml) { |
|
| 455 | - $xml = '<?xml version="1.0"?>' . "\n" . $xml; |
|
| 456 | - $length = strlen($xml); |
|
| 457 | - header('Connection: close'); |
|
| 458 | - header('Content-Length: ' . $length); |
|
| 459 | - header('Content-Type: text/xml'); |
|
| 460 | - header('Date: ' . date('r')); |
|
| 461 | - echo $xml; |
|
| 462 | - exit; |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * @param $method |
|
| 467 | - * @return bool |
|
| 468 | - */ |
|
| 469 | - public function hasMethod($method) { |
|
| 470 | - return in_array($method, array_keys($this->callbacks)); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - public function setCapabilities() { |
|
| 474 | - // Initialises capabilities array |
|
| 475 | - $this->capabilities = array( |
|
| 476 | - 'xmlrpc' => array( |
|
| 477 | - 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 478 | - 'specVersion' => 1 |
|
| 479 | - ), |
|
| 480 | - 'faults_interop' => array( |
|
| 481 | - 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 482 | - 'specVersion' => 20010516 |
|
| 483 | - ), |
|
| 484 | - 'system.multicall' => array( |
|
| 485 | - 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 486 | - 'specVersion' => 1 |
|
| 487 | - ) |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * @param $args |
|
| 493 | - * @return mixed |
|
| 494 | - */ |
|
| 495 | - public function getCapabilities($args) { |
|
| 496 | - return $this->capabilities; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - public function setCallbacks() { |
|
| 500 | - $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 501 | - $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 502 | - $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * @param $args |
|
| 507 | - * @return array |
|
| 508 | - */ |
|
| 509 | - public function listMethods($args) { |
|
| 510 | - // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 511 | - // methods are listed before server defined methods |
|
| 512 | - return array_reverse(array_keys($this->callbacks)); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * @param $methodcalls |
|
| 517 | - * @return array |
|
| 518 | - */ |
|
| 519 | - public function multiCall($methodcalls) { |
|
| 520 | - // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 521 | - $return = array(); |
|
| 522 | - foreach ($methodcalls as $call) { |
|
| 523 | - $method = $call['methodName']; |
|
| 524 | - $params = $call['params']; |
|
| 525 | - if ($method === 'system.multicall') { |
|
| 526 | - $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 527 | - } else { |
|
| 528 | - $result = $this->call($method, $params); |
|
| 529 | - } |
|
| 530 | - if (is_a($result, 'IXR_Error')) { |
|
| 531 | - $return[] = array( |
|
| 532 | - 'faultCode' => $result->code, |
|
| 533 | - 'faultString' => $result->message |
|
| 534 | - ); |
|
| 535 | - } else { |
|
| 536 | - $return[] = array($result); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - return $return; |
|
| 541 | - } |
|
| 394 | + // Send it |
|
| 395 | + $this->output($xml); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @param $methodname |
|
| 400 | + * @param $args |
|
| 401 | + * @return IXR_Error|mixed |
|
| 402 | + */ |
|
| 403 | + public function call($methodname, $args) { |
|
| 404 | + if (!$this->hasMethod($methodname)) { |
|
| 405 | + return new IXR_Error(-32601, 'server error. requested method ' . $methodname . ' does not exist.'); |
|
| 406 | + } |
|
| 407 | + $method = $this->callbacks[$methodname]; |
|
| 408 | + // Perform the callback and send the response |
|
| 409 | + if (count($args) == 1) { |
|
| 410 | + // If only one paramater just send that instead of the whole array |
|
| 411 | + $args = $args[0]; |
|
| 412 | + } |
|
| 413 | + // Are we dealing with a function or a method? |
|
| 414 | + if (substr($method, 0, 5) === 'this:') { |
|
| 415 | + // It's a class method - check it exists |
|
| 416 | + $method = substr($method, 5); |
|
| 417 | + if (!method_exists($this, $method)) { |
|
| 418 | + return new IXR_Error(-32601, 'server error. requested class method "' . $method . '" does not exist.'); |
|
| 419 | + } |
|
| 420 | + // Call the method |
|
| 421 | + $result = $this->$method($args); |
|
| 422 | + } else { |
|
| 423 | + // It's a function - does it exist? |
|
| 424 | + if (is_array($method)) { |
|
| 425 | + if (!method_exists($method[0], $method[1])) { |
|
| 426 | + return new IXR_Error(-32601, |
|
| 427 | + 'server error. requested object method "' . $method[1] . '" does not exist.'); |
|
| 428 | + } |
|
| 429 | + } elseif (!function_exists($method)) { |
|
| 430 | + return new IXR_Error(-32601, 'server error. requested function "' . $method . '" does not exist.'); |
|
| 431 | + } |
|
| 432 | + // Call the function |
|
| 433 | + $result = call_user_func($method, $args); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $result; |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param $error |
|
| 441 | + * @param bool $message |
|
| 442 | + */ |
|
| 443 | + public function error($error, $message = false) { |
|
| 444 | + // Accepts either an error object or an error code and message |
|
| 445 | + if ($message && !is_object($error)) { |
|
| 446 | + $error = new IXR_Error($error, $message); |
|
| 447 | + } |
|
| 448 | + $this->output($error->getXml()); |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * @param $xml |
|
| 453 | + */ |
|
| 454 | + public function output($xml) { |
|
| 455 | + $xml = '<?xml version="1.0"?>' . "\n" . $xml; |
|
| 456 | + $length = strlen($xml); |
|
| 457 | + header('Connection: close'); |
|
| 458 | + header('Content-Length: ' . $length); |
|
| 459 | + header('Content-Type: text/xml'); |
|
| 460 | + header('Date: ' . date('r')); |
|
| 461 | + echo $xml; |
|
| 462 | + exit; |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * @param $method |
|
| 467 | + * @return bool |
|
| 468 | + */ |
|
| 469 | + public function hasMethod($method) { |
|
| 470 | + return in_array($method, array_keys($this->callbacks)); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + public function setCapabilities() { |
|
| 474 | + // Initialises capabilities array |
|
| 475 | + $this->capabilities = array( |
|
| 476 | + 'xmlrpc' => array( |
|
| 477 | + 'specUrl' => 'http://www.xmlrpc.com/spec', |
|
| 478 | + 'specVersion' => 1 |
|
| 479 | + ), |
|
| 480 | + 'faults_interop' => array( |
|
| 481 | + 'specUrl' => 'http://xmlrpc-epi.sourceforge.net/specs/rfc.fault_codes.php', |
|
| 482 | + 'specVersion' => 20010516 |
|
| 483 | + ), |
|
| 484 | + 'system.multicall' => array( |
|
| 485 | + 'specUrl' => 'http://www.xmlrpc.com/discuss/msgReader$1208', |
|
| 486 | + 'specVersion' => 1 |
|
| 487 | + ) |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * @param $args |
|
| 493 | + * @return mixed |
|
| 494 | + */ |
|
| 495 | + public function getCapabilities($args) { |
|
| 496 | + return $this->capabilities; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + public function setCallbacks() { |
|
| 500 | + $this->callbacks['system.getCapabilities'] = 'this:getCapabilities'; |
|
| 501 | + $this->callbacks['system.listMethods'] = 'this:listMethods'; |
|
| 502 | + $this->callbacks['system.multicall'] = 'this:multiCall'; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * @param $args |
|
| 507 | + * @return array |
|
| 508 | + */ |
|
| 509 | + public function listMethods($args) { |
|
| 510 | + // Returns a list of methods - uses array_reverse to ensure user defined |
|
| 511 | + // methods are listed before server defined methods |
|
| 512 | + return array_reverse(array_keys($this->callbacks)); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * @param $methodcalls |
|
| 517 | + * @return array |
|
| 518 | + */ |
|
| 519 | + public function multiCall($methodcalls) { |
|
| 520 | + // See http://www.xmlrpc.com/discuss/msgReader$1208 |
|
| 521 | + $return = array(); |
|
| 522 | + foreach ($methodcalls as $call) { |
|
| 523 | + $method = $call['methodName']; |
|
| 524 | + $params = $call['params']; |
|
| 525 | + if ($method === 'system.multicall') { |
|
| 526 | + $result = new IXR_Error(-32600, 'Recursive calls to system.multicall are forbidden'); |
|
| 527 | + } else { |
|
| 528 | + $result = $this->call($method, $params); |
|
| 529 | + } |
|
| 530 | + if (is_a($result, 'IXR_Error')) { |
|
| 531 | + $return[] = array( |
|
| 532 | + 'faultCode' => $result->code, |
|
| 533 | + 'faultString' => $result->message |
|
| 534 | + ); |
|
| 535 | + } else { |
|
| 536 | + $return[] = array($result); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + return $return; |
|
| 541 | + } |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | /** |
@@ -546,47 +546,47 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | class IXR_Request |
| 548 | 548 | { |
| 549 | - public $method; |
|
| 550 | - public $args; |
|
| 551 | - public $xml; |
|
| 552 | - |
|
| 553 | - /** |
|
| 554 | - * IXR_Request constructor. |
|
| 555 | - * @param $method |
|
| 556 | - * @param $args |
|
| 557 | - */ |
|
| 558 | - public function __construct($method, $args) { |
|
| 559 | - $this->method = $method; |
|
| 560 | - $this->args = $args; |
|
| 561 | - $this->xml = <<<EOD |
|
| 549 | + public $method; |
|
| 550 | + public $args; |
|
| 551 | + public $xml; |
|
| 552 | + |
|
| 553 | + /** |
|
| 554 | + * IXR_Request constructor. |
|
| 555 | + * @param $method |
|
| 556 | + * @param $args |
|
| 557 | + */ |
|
| 558 | + public function __construct($method, $args) { |
|
| 559 | + $this->method = $method; |
|
| 560 | + $this->args = $args; |
|
| 561 | + $this->xml = <<<EOD |
|
| 562 | 562 | <?xml version="1.0"?> |
| 563 | 563 | <methodCall> |
| 564 | 564 | <methodName>{$this->method}</methodName> |
| 565 | 565 | <params> |
| 566 | 566 | |
| 567 | 567 | EOD; |
| 568 | - foreach ($this->args as $arg) { |
|
| 569 | - $this->xml .= '<param><value>'; |
|
| 570 | - $v = new IXR_Value($arg); |
|
| 571 | - $this->xml .= $v->getXml(); |
|
| 572 | - $this->xml .= "</value></param>\n"; |
|
| 573 | - } |
|
| 574 | - $this->xml .= '</params></methodCall>'; |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * @return int |
|
| 579 | - */ |
|
| 580 | - public function getLength() { |
|
| 581 | - return strlen($this->xml); |
|
| 582 | - } |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * @return string |
|
| 586 | - */ |
|
| 587 | - public function getXml() { |
|
| 588 | - return $this->xml; |
|
| 589 | - } |
|
| 568 | + foreach ($this->args as $arg) { |
|
| 569 | + $this->xml .= '<param><value>'; |
|
| 570 | + $v = new IXR_Value($arg); |
|
| 571 | + $this->xml .= $v->getXml(); |
|
| 572 | + $this->xml .= "</value></param>\n"; |
|
| 573 | + } |
|
| 574 | + $this->xml .= '</params></methodCall>'; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * @return int |
|
| 579 | + */ |
|
| 580 | + public function getLength() { |
|
| 581 | + return strlen($this->xml); |
|
| 582 | + } |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * @return string |
|
| 586 | + */ |
|
| 587 | + public function getXml() { |
|
| 588 | + return $this->xml; |
|
| 589 | + } |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -594,144 +594,144 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | class IXR_Client |
| 596 | 596 | { |
| 597 | - public $server; |
|
| 598 | - public $port; |
|
| 599 | - public $path; |
|
| 600 | - public $useragent; |
|
| 601 | - public $response; |
|
| 602 | - public $timeout; |
|
| 603 | - public $vendor = ''; |
|
| 604 | - public $message = false; |
|
| 605 | - public $debug = false; |
|
| 606 | - // Storage place for an error message |
|
| 607 | - public $error = false; |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * IXR_Client constructor. |
|
| 611 | - * @param $server |
|
| 612 | - * @param bool $path |
|
| 613 | - * @param int $port |
|
| 614 | - * @param int $timeout |
|
| 615 | - * @param string $vendor |
|
| 616 | - */ |
|
| 617 | - public function __construct($server, $path = false, $port = 80, $timeout = 30, $vendor = '') { |
|
| 618 | - if (!$path) { |
|
| 619 | - // Assume we have been given a URL instead |
|
| 620 | - $bits = parse_url($server); |
|
| 621 | - $this->server = $bits['host']; |
|
| 622 | - $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 623 | - $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 624 | - // Make absolutely sure we have a path |
|
| 625 | - if (!$this->path) { |
|
| 626 | - $this->path = '/'; |
|
| 627 | - } |
|
| 628 | - } else { |
|
| 629 | - $this->server = $server; |
|
| 630 | - $this->path = $path; |
|
| 631 | - $this->port = $port; |
|
| 632 | - $this->timeout = $timeout; |
|
| 633 | - } |
|
| 634 | - $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * @return bool |
|
| 639 | - */ |
|
| 640 | - public function query() { |
|
| 641 | - $args = func_get_args(); |
|
| 642 | - $method = array_shift($args); |
|
| 643 | - $request = new IXR_Request($method, $args); |
|
| 644 | - $length = $request->getLength(); |
|
| 645 | - $xml = $request->getXml(); |
|
| 646 | - $r = "\r\n"; |
|
| 647 | - $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 648 | - $request .= "Host: {$this->server}$r"; |
|
| 649 | - $request .= "Content-Type: text/xml$r"; |
|
| 650 | - $request .= "User-Agent: {$this->useragent}$r"; |
|
| 651 | - $request .= "Content-length: {$length}$r$r"; |
|
| 652 | - $request .= $xml; |
|
| 653 | - // Now send the request |
|
| 654 | - if ($this->debug) { |
|
| 655 | - echo '<pre>' . htmlspecialchars($request) . "\n</pre>\n\n"; |
|
| 656 | - } |
|
| 657 | - $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 658 | - if (!$fp) { |
|
| 659 | - $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 660 | - |
|
| 661 | - return false; |
|
| 662 | - } |
|
| 663 | - fwrite($fp, $request); |
|
| 664 | - $contents = ''; |
|
| 665 | - $gotFirstLine = false; |
|
| 666 | - $gettingHeaders = true; |
|
| 667 | - while (!feof($fp)) { |
|
| 668 | - $line = fgets($fp, 4096); |
|
| 669 | - if (!$gotFirstLine) { |
|
| 670 | - // Check line for '200' |
|
| 671 | - if (false === strpos($line, '200')) { |
|
| 672 | - $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 673 | - |
|
| 674 | - return false; |
|
| 675 | - } |
|
| 676 | - $gotFirstLine = true; |
|
| 677 | - } |
|
| 678 | - if (trim($line) == '') { |
|
| 679 | - $gettingHeaders = false; |
|
| 680 | - } |
|
| 681 | - if (!$gettingHeaders) { |
|
| 682 | - $contents .= trim($line) . "\n"; |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - if ($this->debug) { |
|
| 686 | - echo '<pre>' . htmlspecialchars($contents) . "\n</pre>\n\n"; |
|
| 687 | - } |
|
| 688 | - // Now parse what we've got back |
|
| 689 | - $this->message = new IXR_Message($contents); |
|
| 690 | - if (!$this->message->parse()) { |
|
| 691 | - // XML error |
|
| 692 | - $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 693 | - |
|
| 694 | - return false; |
|
| 695 | - } |
|
| 696 | - // Is the message a fault? |
|
| 697 | - if ($this->message->messageType === 'fault') { |
|
| 698 | - $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 699 | - |
|
| 700 | - return false; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - // Message must be OK |
|
| 704 | - return true; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * @return mixed |
|
| 709 | - */ |
|
| 710 | - public function getResponse() { |
|
| 711 | - // methodResponses can only have one param - return that |
|
| 712 | - return $this->message->params[0]; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * @return bool |
|
| 717 | - */ |
|
| 718 | - public function isError() { |
|
| 719 | - return is_object($this->error); |
|
| 720 | - } |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * @return mixed |
|
| 724 | - */ |
|
| 725 | - public function getErrorCode() { |
|
| 726 | - return $this->error->code; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * @return mixed |
|
| 731 | - */ |
|
| 732 | - public function getErrorMessage() { |
|
| 733 | - return $this->error->message; |
|
| 734 | - } |
|
| 597 | + public $server; |
|
| 598 | + public $port; |
|
| 599 | + public $path; |
|
| 600 | + public $useragent; |
|
| 601 | + public $response; |
|
| 602 | + public $timeout; |
|
| 603 | + public $vendor = ''; |
|
| 604 | + public $message = false; |
|
| 605 | + public $debug = false; |
|
| 606 | + // Storage place for an error message |
|
| 607 | + public $error = false; |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * IXR_Client constructor. |
|
| 611 | + * @param $server |
|
| 612 | + * @param bool $path |
|
| 613 | + * @param int $port |
|
| 614 | + * @param int $timeout |
|
| 615 | + * @param string $vendor |
|
| 616 | + */ |
|
| 617 | + public function __construct($server, $path = false, $port = 80, $timeout = 30, $vendor = '') { |
|
| 618 | + if (!$path) { |
|
| 619 | + // Assume we have been given a URL instead |
|
| 620 | + $bits = parse_url($server); |
|
| 621 | + $this->server = $bits['host']; |
|
| 622 | + $this->port = isset($bits['port']) ? $bits['port'] : 80; |
|
| 623 | + $this->path = isset($bits['path']) ? $bits['path'] : '/'; |
|
| 624 | + // Make absolutely sure we have a path |
|
| 625 | + if (!$this->path) { |
|
| 626 | + $this->path = '/'; |
|
| 627 | + } |
|
| 628 | + } else { |
|
| 629 | + $this->server = $server; |
|
| 630 | + $this->path = $path; |
|
| 631 | + $this->port = $port; |
|
| 632 | + $this->timeout = $timeout; |
|
| 633 | + } |
|
| 634 | + $this->useragent = 'The Incutio XML-RPC PHP Library'; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * @return bool |
|
| 639 | + */ |
|
| 640 | + public function query() { |
|
| 641 | + $args = func_get_args(); |
|
| 642 | + $method = array_shift($args); |
|
| 643 | + $request = new IXR_Request($method, $args); |
|
| 644 | + $length = $request->getLength(); |
|
| 645 | + $xml = $request->getXml(); |
|
| 646 | + $r = "\r\n"; |
|
| 647 | + $request = "POST {$this->path} HTTP/1.0$r"; |
|
| 648 | + $request .= "Host: {$this->server}$r"; |
|
| 649 | + $request .= "Content-Type: text/xml$r"; |
|
| 650 | + $request .= "User-Agent: {$this->useragent}$r"; |
|
| 651 | + $request .= "Content-length: {$length}$r$r"; |
|
| 652 | + $request .= $xml; |
|
| 653 | + // Now send the request |
|
| 654 | + if ($this->debug) { |
|
| 655 | + echo '<pre>' . htmlspecialchars($request) . "\n</pre>\n\n"; |
|
| 656 | + } |
|
| 657 | + $fp = @fsockopen($this->server, $this->port, $errno, $errstr, $this->timeout); |
|
| 658 | + if (!$fp) { |
|
| 659 | + $this->error = new IXR_Error(-32300, 'transport error - could not open socket'); |
|
| 660 | + |
|
| 661 | + return false; |
|
| 662 | + } |
|
| 663 | + fwrite($fp, $request); |
|
| 664 | + $contents = ''; |
|
| 665 | + $gotFirstLine = false; |
|
| 666 | + $gettingHeaders = true; |
|
| 667 | + while (!feof($fp)) { |
|
| 668 | + $line = fgets($fp, 4096); |
|
| 669 | + if (!$gotFirstLine) { |
|
| 670 | + // Check line for '200' |
|
| 671 | + if (false === strpos($line, '200')) { |
|
| 672 | + $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200'); |
|
| 673 | + |
|
| 674 | + return false; |
|
| 675 | + } |
|
| 676 | + $gotFirstLine = true; |
|
| 677 | + } |
|
| 678 | + if (trim($line) == '') { |
|
| 679 | + $gettingHeaders = false; |
|
| 680 | + } |
|
| 681 | + if (!$gettingHeaders) { |
|
| 682 | + $contents .= trim($line) . "\n"; |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + if ($this->debug) { |
|
| 686 | + echo '<pre>' . htmlspecialchars($contents) . "\n</pre>\n\n"; |
|
| 687 | + } |
|
| 688 | + // Now parse what we've got back |
|
| 689 | + $this->message = new IXR_Message($contents); |
|
| 690 | + if (!$this->message->parse()) { |
|
| 691 | + // XML error |
|
| 692 | + $this->error = new IXR_Error(-32700, 'parse error. not well formed'); |
|
| 693 | + |
|
| 694 | + return false; |
|
| 695 | + } |
|
| 696 | + // Is the message a fault? |
|
| 697 | + if ($this->message->messageType === 'fault') { |
|
| 698 | + $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString); |
|
| 699 | + |
|
| 700 | + return false; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + // Message must be OK |
|
| 704 | + return true; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * @return mixed |
|
| 709 | + */ |
|
| 710 | + public function getResponse() { |
|
| 711 | + // methodResponses can only have one param - return that |
|
| 712 | + return $this->message->params[0]; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * @return bool |
|
| 717 | + */ |
|
| 718 | + public function isError() { |
|
| 719 | + return is_object($this->error); |
|
| 720 | + } |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * @return mixed |
|
| 724 | + */ |
|
| 725 | + public function getErrorCode() { |
|
| 726 | + return $this->error->code; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * @return mixed |
|
| 731 | + */ |
|
| 732 | + public function getErrorMessage() { |
|
| 733 | + return $this->error->message; |
|
| 734 | + } |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -739,24 +739,24 @@ discard block |
||
| 739 | 739 | */ |
| 740 | 740 | class IXR_Error |
| 741 | 741 | { |
| 742 | - public $code; |
|
| 743 | - public $message; |
|
| 744 | - |
|
| 745 | - /** |
|
| 746 | - * IXR_Error constructor. |
|
| 747 | - * @param $code |
|
| 748 | - * @param $message |
|
| 749 | - */ |
|
| 750 | - public function __construct($code, $message) { |
|
| 751 | - $this->code = $code; |
|
| 752 | - $this->message = $message; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * @return string |
|
| 757 | - */ |
|
| 758 | - public function getXml() { |
|
| 759 | - $xml = <<<EOD |
|
| 742 | + public $code; |
|
| 743 | + public $message; |
|
| 744 | + |
|
| 745 | + /** |
|
| 746 | + * IXR_Error constructor. |
|
| 747 | + * @param $code |
|
| 748 | + * @param $message |
|
| 749 | + */ |
|
| 750 | + public function __construct($code, $message) { |
|
| 751 | + $this->code = $code; |
|
| 752 | + $this->message = $message; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * @return string |
|
| 757 | + */ |
|
| 758 | + public function getXml() { |
|
| 759 | + $xml = <<<EOD |
|
| 760 | 760 | <methodResponse> |
| 761 | 761 | <fault> |
| 762 | 762 | <value> |
@@ -776,8 +776,8 @@ discard block |
||
| 776 | 776 | |
| 777 | 777 | EOD; |
| 778 | 778 | |
| 779 | - return $xml; |
|
| 780 | - } |
|
| 779 | + return $xml; |
|
| 780 | + } |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | /** |
@@ -785,73 +785,73 @@ discard block |
||
| 785 | 785 | */ |
| 786 | 786 | class IXR_Date |
| 787 | 787 | { |
| 788 | - public $year; |
|
| 789 | - public $month; |
|
| 790 | - public $day; |
|
| 791 | - public $hour; |
|
| 792 | - public $minute; |
|
| 793 | - public $second; |
|
| 794 | - public $timezone; |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * IXR_Date constructor. |
|
| 798 | - * @param $time |
|
| 799 | - */ |
|
| 800 | - public function __construct($time) { |
|
| 801 | - // $time can be a PHP timestamp or an ISO one |
|
| 802 | - if (is_numeric($time)) { |
|
| 803 | - $this->parseTimestamp($time); |
|
| 804 | - } else { |
|
| 805 | - $this->parseIso($time); |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - /** |
|
| 810 | - * @param $timestamp |
|
| 811 | - */ |
|
| 812 | - public function parseTimestamp($timestamp) { |
|
| 813 | - $this->year = date('Y', $timestamp); |
|
| 814 | - $this->month = date('Y', $timestamp); |
|
| 815 | - $this->day = date('Y', $timestamp); |
|
| 816 | - $this->hour = date('H', $timestamp); |
|
| 817 | - $this->minute = date('i', $timestamp); |
|
| 818 | - $this->second = date('s', $timestamp); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * @param $iso |
|
| 823 | - */ |
|
| 824 | - public function parseIso($iso) { |
|
| 825 | - $this->year = substr($iso, 0, 4); |
|
| 826 | - $this->month = substr($iso, 4, 2); |
|
| 827 | - $this->day = substr($iso, 6, 2); |
|
| 828 | - $this->hour = substr($iso, 9, 2); |
|
| 829 | - $this->minute = substr($iso, 12, 2); |
|
| 830 | - $this->second = substr($iso, 15, 2); |
|
| 831 | - $this->timezone = substr($iso, 17); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - /** |
|
| 835 | - * @return string |
|
| 836 | - */ |
|
| 837 | - public function getIso() { |
|
| 838 | - return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second |
|
| 839 | - . $this->timezone; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * @return string |
|
| 844 | - */ |
|
| 845 | - public function getXml() { |
|
| 846 | - return '<dateTime.iso8601>' . $this->getIso() . '</dateTime.iso8601>'; |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * @return int |
|
| 851 | - */ |
|
| 852 | - public function getTimestamp() { |
|
| 853 | - return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 854 | - } |
|
| 788 | + public $year; |
|
| 789 | + public $month; |
|
| 790 | + public $day; |
|
| 791 | + public $hour; |
|
| 792 | + public $minute; |
|
| 793 | + public $second; |
|
| 794 | + public $timezone; |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * IXR_Date constructor. |
|
| 798 | + * @param $time |
|
| 799 | + */ |
|
| 800 | + public function __construct($time) { |
|
| 801 | + // $time can be a PHP timestamp or an ISO one |
|
| 802 | + if (is_numeric($time)) { |
|
| 803 | + $this->parseTimestamp($time); |
|
| 804 | + } else { |
|
| 805 | + $this->parseIso($time); |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + /** |
|
| 810 | + * @param $timestamp |
|
| 811 | + */ |
|
| 812 | + public function parseTimestamp($timestamp) { |
|
| 813 | + $this->year = date('Y', $timestamp); |
|
| 814 | + $this->month = date('Y', $timestamp); |
|
| 815 | + $this->day = date('Y', $timestamp); |
|
| 816 | + $this->hour = date('H', $timestamp); |
|
| 817 | + $this->minute = date('i', $timestamp); |
|
| 818 | + $this->second = date('s', $timestamp); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * @param $iso |
|
| 823 | + */ |
|
| 824 | + public function parseIso($iso) { |
|
| 825 | + $this->year = substr($iso, 0, 4); |
|
| 826 | + $this->month = substr($iso, 4, 2); |
|
| 827 | + $this->day = substr($iso, 6, 2); |
|
| 828 | + $this->hour = substr($iso, 9, 2); |
|
| 829 | + $this->minute = substr($iso, 12, 2); |
|
| 830 | + $this->second = substr($iso, 15, 2); |
|
| 831 | + $this->timezone = substr($iso, 17); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + /** |
|
| 835 | + * @return string |
|
| 836 | + */ |
|
| 837 | + public function getIso() { |
|
| 838 | + return $this->year . $this->month . $this->day . 'T' . $this->hour . ':' . $this->minute . ':' . $this->second |
|
| 839 | + . $this->timezone; |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * @return string |
|
| 844 | + */ |
|
| 845 | + public function getXml() { |
|
| 846 | + return '<dateTime.iso8601>' . $this->getIso() . '</dateTime.iso8601>'; |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * @return int |
|
| 851 | + */ |
|
| 852 | + public function getTimestamp() { |
|
| 853 | + return mktime($this->hour, $this->minute, $this->second, $this->month, $this->day, $this->year); |
|
| 854 | + } |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | /** |
@@ -859,22 +859,22 @@ discard block |
||
| 859 | 859 | */ |
| 860 | 860 | class IXR_Base64 |
| 861 | 861 | { |
| 862 | - public $data; |
|
| 863 | - |
|
| 864 | - /** |
|
| 865 | - * IXR_Base64 constructor. |
|
| 866 | - * @param $data |
|
| 867 | - */ |
|
| 868 | - public function __construct($data) { |
|
| 869 | - $this->data = $data; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - /** |
|
| 873 | - * @return string |
|
| 874 | - */ |
|
| 875 | - public function getXml() { |
|
| 876 | - return '<base64>' . base64_encode($this->data) . '</base64>'; |
|
| 877 | - } |
|
| 862 | + public $data; |
|
| 863 | + |
|
| 864 | + /** |
|
| 865 | + * IXR_Base64 constructor. |
|
| 866 | + * @param $data |
|
| 867 | + */ |
|
| 868 | + public function __construct($data) { |
|
| 869 | + $this->data = $data; |
|
| 870 | + } |
|
| 871 | + |
|
| 872 | + /** |
|
| 873 | + * @return string |
|
| 874 | + */ |
|
| 875 | + public function getXml() { |
|
| 876 | + return '<base64>' . base64_encode($this->data) . '</base64>'; |
|
| 877 | + } |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -882,161 +882,161 @@ discard block |
||
| 882 | 882 | */ |
| 883 | 883 | class IXR_IntrospectionServer extends IXR_Server |
| 884 | 884 | { |
| 885 | - public $signatures; |
|
| 886 | - public $help; |
|
| 887 | - |
|
| 888 | - /** |
|
| 889 | - * IXR_IntrospectionServer constructor. |
|
| 890 | - */ |
|
| 891 | - public function __construct() { |
|
| 892 | - $this->setCallbacks(); |
|
| 893 | - $this->setCapabilities(); |
|
| 894 | - $this->capabilities['introspection'] = array( |
|
| 895 | - 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 896 | - 'specVersion' => 1 |
|
| 897 | - ); |
|
| 898 | - $this->addCallback('system.methodSignature', 'this:methodSignature', array('array', 'string'), |
|
| 899 | - 'Returns an array describing the return type and required parameters of a method'); |
|
| 900 | - $this->addCallback('system.getCapabilities', 'this:getCapabilities', array('struct'), |
|
| 901 | - 'Returns a struct describing the XML-RPC specifications supported by this server'); |
|
| 902 | - $this->addCallback('system.listMethods', 'this:listMethods', array('array'), |
|
| 903 | - 'Returns an array of available methods on this server'); |
|
| 904 | - $this->addCallback('system.methodHelp', 'this:methodHelp', array('string', 'string'), |
|
| 905 | - 'Returns a documentation string for the specified method'); |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - /** |
|
| 909 | - * @param $method |
|
| 910 | - * @param $callback |
|
| 911 | - * @param $args |
|
| 912 | - * @param $help |
|
| 913 | - */ |
|
| 914 | - public function addCallback($method, $callback, $args, $help) { |
|
| 915 | - $this->callbacks[$method] = $callback; |
|
| 916 | - $this->signatures[$method] = $args; |
|
| 917 | - $this->help[$method] = $help; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * @param $methodname |
|
| 922 | - * @param $args |
|
| 923 | - * @return IXR_Error|mixed |
|
| 924 | - */ |
|
| 925 | - public function call($methodname, $args) { |
|
| 926 | - // Make sure it's in an array |
|
| 927 | - if ($args && !is_array($args)) { |
|
| 928 | - $args = array($args); |
|
| 929 | - } |
|
| 930 | - // Over-rides default call method, adds signature check |
|
| 931 | - if (!$this->hasMethod($methodname)) { |
|
| 932 | - return new IXR_Error(-32601, |
|
| 933 | - 'server error. requested method "' . $this->message->methodName . '" not specified.'); |
|
| 934 | - } |
|
| 935 | - $method = $this->callbacks[$methodname]; |
|
| 936 | - $signature = $this->signatures[$methodname]; |
|
| 937 | - $returnType = array_shift($signature); |
|
| 938 | - // Check the number of arguments |
|
| 939 | - if (count($args) != count($signature)) { |
|
| 940 | - // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
| 941 | - return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 942 | - } |
|
| 943 | - // Check the argument types |
|
| 944 | - $ok = true; |
|
| 945 | - $argsbackup = $args; |
|
| 946 | - for ($i = 0, $j = count($args); $i < $j; ++$i) { |
|
| 947 | - $arg = array_shift($args); |
|
| 948 | - $type = array_shift($signature); |
|
| 949 | - switch ($type) { |
|
| 950 | - case 'int': |
|
| 951 | - case 'i4': |
|
| 952 | - if (is_array($arg) || !is_int($arg)) { |
|
| 953 | - $ok = false; |
|
| 954 | - } |
|
| 955 | - break; |
|
| 956 | - case 'base64': |
|
| 957 | - case 'string': |
|
| 958 | - if (!is_string($arg)) { |
|
| 959 | - $ok = false; |
|
| 960 | - } |
|
| 961 | - break; |
|
| 962 | - case 'boolean': |
|
| 963 | - if ($arg !== false && $arg !== true) { |
|
| 964 | - $ok = false; |
|
| 965 | - } |
|
| 966 | - break; |
|
| 967 | - case 'float': |
|
| 968 | - case 'double': |
|
| 969 | - if (!is_float($arg)) { |
|
| 970 | - $ok = false; |
|
| 971 | - } |
|
| 972 | - break; |
|
| 973 | - case 'date': |
|
| 974 | - case 'dateTime.iso8601': |
|
| 975 | - if (!is_a($arg, 'IXR_Date')) { |
|
| 976 | - $ok = false; |
|
| 977 | - } |
|
| 978 | - break; |
|
| 979 | - } |
|
| 980 | - if (!$ok) { |
|
| 981 | - return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 982 | - } |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - // It passed the test - run the "real" method call |
|
| 986 | - return parent::call($methodname, $argsbackup); |
|
| 987 | - } |
|
| 988 | - |
|
| 989 | - /** |
|
| 990 | - * @param $method |
|
| 991 | - * @return array|IXR_Error |
|
| 992 | - */ |
|
| 993 | - public function methodSignature($method) { |
|
| 994 | - if (!$this->hasMethod($method)) { |
|
| 995 | - return new IXR_Error(-32601, 'server error. requested method "' . $method . '" not specified.'); |
|
| 996 | - } |
|
| 997 | - // We should be returning an array of types |
|
| 998 | - $types = $this->signatures[$method]; |
|
| 999 | - $return = array(); |
|
| 1000 | - foreach ($types as $type) { |
|
| 1001 | - switch ($type) { |
|
| 1002 | - case 'string': |
|
| 1003 | - $return[] = 'string'; |
|
| 1004 | - break; |
|
| 1005 | - case 'int': |
|
| 1006 | - case 'i4': |
|
| 1007 | - $return[] = 42; |
|
| 1008 | - break; |
|
| 1009 | - case 'double': |
|
| 1010 | - $return[] = 3.1415; |
|
| 1011 | - break; |
|
| 1012 | - case 'dateTime.iso8601': |
|
| 1013 | - $return[] = new IXR_Date(time()); |
|
| 1014 | - break; |
|
| 1015 | - case 'boolean': |
|
| 1016 | - $return[] = true; |
|
| 1017 | - break; |
|
| 1018 | - case 'base64': |
|
| 1019 | - $return[] = new IXR_Base64('base64'); |
|
| 1020 | - break; |
|
| 1021 | - case 'array': |
|
| 1022 | - $return[] = array('array'); |
|
| 1023 | - break; |
|
| 1024 | - case 'struct': |
|
| 1025 | - $return[] = array('struct' => 'struct'); |
|
| 1026 | - break; |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - return $return; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - /** |
|
| 1034 | - * @param $method |
|
| 1035 | - * @return mixed |
|
| 1036 | - */ |
|
| 1037 | - public function methodHelp($method) { |
|
| 1038 | - return $this->help[$method]; |
|
| 1039 | - } |
|
| 885 | + public $signatures; |
|
| 886 | + public $help; |
|
| 887 | + |
|
| 888 | + /** |
|
| 889 | + * IXR_IntrospectionServer constructor. |
|
| 890 | + */ |
|
| 891 | + public function __construct() { |
|
| 892 | + $this->setCallbacks(); |
|
| 893 | + $this->setCapabilities(); |
|
| 894 | + $this->capabilities['introspection'] = array( |
|
| 895 | + 'specUrl' => 'http://xmlrpc.usefulinc.com/doc/reserved.html', |
|
| 896 | + 'specVersion' => 1 |
|
| 897 | + ); |
|
| 898 | + $this->addCallback('system.methodSignature', 'this:methodSignature', array('array', 'string'), |
|
| 899 | + 'Returns an array describing the return type and required parameters of a method'); |
|
| 900 | + $this->addCallback('system.getCapabilities', 'this:getCapabilities', array('struct'), |
|
| 901 | + 'Returns a struct describing the XML-RPC specifications supported by this server'); |
|
| 902 | + $this->addCallback('system.listMethods', 'this:listMethods', array('array'), |
|
| 903 | + 'Returns an array of available methods on this server'); |
|
| 904 | + $this->addCallback('system.methodHelp', 'this:methodHelp', array('string', 'string'), |
|
| 905 | + 'Returns a documentation string for the specified method'); |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + /** |
|
| 909 | + * @param $method |
|
| 910 | + * @param $callback |
|
| 911 | + * @param $args |
|
| 912 | + * @param $help |
|
| 913 | + */ |
|
| 914 | + public function addCallback($method, $callback, $args, $help) { |
|
| 915 | + $this->callbacks[$method] = $callback; |
|
| 916 | + $this->signatures[$method] = $args; |
|
| 917 | + $this->help[$method] = $help; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * @param $methodname |
|
| 922 | + * @param $args |
|
| 923 | + * @return IXR_Error|mixed |
|
| 924 | + */ |
|
| 925 | + public function call($methodname, $args) { |
|
| 926 | + // Make sure it's in an array |
|
| 927 | + if ($args && !is_array($args)) { |
|
| 928 | + $args = array($args); |
|
| 929 | + } |
|
| 930 | + // Over-rides default call method, adds signature check |
|
| 931 | + if (!$this->hasMethod($methodname)) { |
|
| 932 | + return new IXR_Error(-32601, |
|
| 933 | + 'server error. requested method "' . $this->message->methodName . '" not specified.'); |
|
| 934 | + } |
|
| 935 | + $method = $this->callbacks[$methodname]; |
|
| 936 | + $signature = $this->signatures[$methodname]; |
|
| 937 | + $returnType = array_shift($signature); |
|
| 938 | + // Check the number of arguments |
|
| 939 | + if (count($args) != count($signature)) { |
|
| 940 | + // print 'Num of args: '.count($args).' Num in signature: '.count($signature); |
|
| 941 | + return new IXR_Error(-32602, 'server error. wrong number of method parameters'); |
|
| 942 | + } |
|
| 943 | + // Check the argument types |
|
| 944 | + $ok = true; |
|
| 945 | + $argsbackup = $args; |
|
| 946 | + for ($i = 0, $j = count($args); $i < $j; ++$i) { |
|
| 947 | + $arg = array_shift($args); |
|
| 948 | + $type = array_shift($signature); |
|
| 949 | + switch ($type) { |
|
| 950 | + case 'int': |
|
| 951 | + case 'i4': |
|
| 952 | + if (is_array($arg) || !is_int($arg)) { |
|
| 953 | + $ok = false; |
|
| 954 | + } |
|
| 955 | + break; |
|
| 956 | + case 'base64': |
|
| 957 | + case 'string': |
|
| 958 | + if (!is_string($arg)) { |
|
| 959 | + $ok = false; |
|
| 960 | + } |
|
| 961 | + break; |
|
| 962 | + case 'boolean': |
|
| 963 | + if ($arg !== false && $arg !== true) { |
|
| 964 | + $ok = false; |
|
| 965 | + } |
|
| 966 | + break; |
|
| 967 | + case 'float': |
|
| 968 | + case 'double': |
|
| 969 | + if (!is_float($arg)) { |
|
| 970 | + $ok = false; |
|
| 971 | + } |
|
| 972 | + break; |
|
| 973 | + case 'date': |
|
| 974 | + case 'dateTime.iso8601': |
|
| 975 | + if (!is_a($arg, 'IXR_Date')) { |
|
| 976 | + $ok = false; |
|
| 977 | + } |
|
| 978 | + break; |
|
| 979 | + } |
|
| 980 | + if (!$ok) { |
|
| 981 | + return new IXR_Error(-32602, 'server error. invalid method parameters'); |
|
| 982 | + } |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + // It passed the test - run the "real" method call |
|
| 986 | + return parent::call($methodname, $argsbackup); |
|
| 987 | + } |
|
| 988 | + |
|
| 989 | + /** |
|
| 990 | + * @param $method |
|
| 991 | + * @return array|IXR_Error |
|
| 992 | + */ |
|
| 993 | + public function methodSignature($method) { |
|
| 994 | + if (!$this->hasMethod($method)) { |
|
| 995 | + return new IXR_Error(-32601, 'server error. requested method "' . $method . '" not specified.'); |
|
| 996 | + } |
|
| 997 | + // We should be returning an array of types |
|
| 998 | + $types = $this->signatures[$method]; |
|
| 999 | + $return = array(); |
|
| 1000 | + foreach ($types as $type) { |
|
| 1001 | + switch ($type) { |
|
| 1002 | + case 'string': |
|
| 1003 | + $return[] = 'string'; |
|
| 1004 | + break; |
|
| 1005 | + case 'int': |
|
| 1006 | + case 'i4': |
|
| 1007 | + $return[] = 42; |
|
| 1008 | + break; |
|
| 1009 | + case 'double': |
|
| 1010 | + $return[] = 3.1415; |
|
| 1011 | + break; |
|
| 1012 | + case 'dateTime.iso8601': |
|
| 1013 | + $return[] = new IXR_Date(time()); |
|
| 1014 | + break; |
|
| 1015 | + case 'boolean': |
|
| 1016 | + $return[] = true; |
|
| 1017 | + break; |
|
| 1018 | + case 'base64': |
|
| 1019 | + $return[] = new IXR_Base64('base64'); |
|
| 1020 | + break; |
|
| 1021 | + case 'array': |
|
| 1022 | + $return[] = array('array'); |
|
| 1023 | + break; |
|
| 1024 | + case 'struct': |
|
| 1025 | + $return[] = array('struct' => 'struct'); |
|
| 1026 | + break; |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + return $return; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + /** |
|
| 1034 | + * @param $method |
|
| 1035 | + * @return mixed |
|
| 1036 | + */ |
|
| 1037 | + public function methodHelp($method) { |
|
| 1038 | + return $this->help[$method]; |
|
| 1039 | + } |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | /** |
@@ -1044,34 +1044,34 @@ discard block |
||
| 1044 | 1044 | */ |
| 1045 | 1045 | class IXR_ClientMulticall extends IXR_Client |
| 1046 | 1046 | { |
| 1047 | - public $calls = array(); |
|
| 1048 | - |
|
| 1049 | - /** |
|
| 1050 | - * IXR_ClientMulticall constructor. |
|
| 1051 | - * @param $server |
|
| 1052 | - * @param bool $path |
|
| 1053 | - * @param int $port |
|
| 1054 | - */ |
|
| 1055 | - public function __construct($server, $path = false, $port = 80) { |
|
| 1056 | - parent::IXR_Client($server, $path, $port); |
|
| 1057 | - $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - public function addCall() { |
|
| 1061 | - $args = func_get_args(); |
|
| 1062 | - $methodName = array_shift($args); |
|
| 1063 | - $struct = array( |
|
| 1064 | - 'methodName' => $methodName, |
|
| 1065 | - 'params' => $args |
|
| 1066 | - ); |
|
| 1067 | - $this->calls[] = $struct; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * @return bool |
|
| 1072 | - */ |
|
| 1073 | - public function query() { |
|
| 1074 | - // Prepare multicall, then call the parent::query() method |
|
| 1075 | - return parent::query('system.multicall', $this->calls); |
|
| 1076 | - } |
|
| 1047 | + public $calls = array(); |
|
| 1048 | + |
|
| 1049 | + /** |
|
| 1050 | + * IXR_ClientMulticall constructor. |
|
| 1051 | + * @param $server |
|
| 1052 | + * @param bool $path |
|
| 1053 | + * @param int $port |
|
| 1054 | + */ |
|
| 1055 | + public function __construct($server, $path = false, $port = 80) { |
|
| 1056 | + parent::IXR_Client($server, $path, $port); |
|
| 1057 | + $this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + public function addCall() { |
|
| 1061 | + $args = func_get_args(); |
|
| 1062 | + $methodName = array_shift($args); |
|
| 1063 | + $struct = array( |
|
| 1064 | + 'methodName' => $methodName, |
|
| 1065 | + 'params' => $args |
|
| 1066 | + ); |
|
| 1067 | + $this->calls[] = $struct; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * @return bool |
|
| 1072 | + */ |
|
| 1073 | + public function query() { |
|
| 1074 | + // Prepare multicall, then call the parent::query() method |
|
| 1075 | + return parent::query('system.multicall', $this->calls); |
|
| 1076 | + } |
|
| 1077 | 1077 | } |
@@ -43,169 +43,169 @@ |
||
| 43 | 43 | **/ |
| 44 | 44 | class xmlparser extends MagpieRSS |
| 45 | 45 | { |
| 46 | - public $content; |
|
| 47 | - public $charset_in; |
|
| 48 | - public $charset_out; |
|
| 46 | + public $content; |
|
| 47 | + public $charset_in; |
|
| 48 | + public $charset_out; |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Set up XML parser, parse source, and return populated RSS object.. |
|
| 52 | - * |
|
| 53 | - * @param string $content string containing the RSS to be parsed |
|
| 54 | - * |
|
| 55 | - * |
|
| 56 | - * @param string $input_charset |
|
| 57 | - * @param null|string $output_charset |
|
| 58 | - * @param array $tags |
|
| 59 | - * @internal param string $output_encoding output the parsed RSS in this character |
|
| 60 | - * set defaults to ISO-8859-1 as this is PHP's |
|
| 61 | - * default. |
|
| 62 | - * |
|
| 63 | - * @internal param string $input_encoding the character set of the incoming RSS source. |
|
| 64 | - * Leave blank and Magpie will try to figure it |
|
| 65 | - * out. |
|
| 66 | - */ |
|
| 67 | - public function __construct($content, $input_charset, $output_charset = _CHARSET, $tags = array()) { |
|
| 68 | - if (!in_array(strtoupper($input_charset), array('UTF-8', 'US-ASCII', 'ISO-8859-1'))) { |
|
| 69 | - $content = XoopsLocal::convert_encoding($content, 'UTF-8', $input_charset); |
|
| 70 | - $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
|
| 71 | - $input_charset = 'UTF-8'; |
|
| 72 | - } |
|
| 73 | - $this->content = $content; |
|
| 74 | - $this->charset_in = $input_charset; |
|
| 75 | - $this->charset_out = $output_charset; |
|
| 50 | + /** |
|
| 51 | + * Set up XML parser, parse source, and return populated RSS object.. |
|
| 52 | + * |
|
| 53 | + * @param string $content string containing the RSS to be parsed |
|
| 54 | + * |
|
| 55 | + * |
|
| 56 | + * @param string $input_charset |
|
| 57 | + * @param null|string $output_charset |
|
| 58 | + * @param array $tags |
|
| 59 | + * @internal param string $output_encoding output the parsed RSS in this character |
|
| 60 | + * set defaults to ISO-8859-1 as this is PHP's |
|
| 61 | + * default. |
|
| 62 | + * |
|
| 63 | + * @internal param string $input_encoding the character set of the incoming RSS source. |
|
| 64 | + * Leave blank and Magpie will try to figure it |
|
| 65 | + * out. |
|
| 66 | + */ |
|
| 67 | + public function __construct($content, $input_charset, $output_charset = _CHARSET, $tags = array()) { |
|
| 68 | + if (!in_array(strtoupper($input_charset), array('UTF-8', 'US-ASCII', 'ISO-8859-1'))) { |
|
| 69 | + $content = XoopsLocal::convert_encoding($content, 'UTF-8', $input_charset); |
|
| 70 | + $content = preg_replace('/(<\?xml.*encoding=[\'"])(.*?)([\'"].*\?>)/m', '$1UTF-8$3', $content); |
|
| 71 | + $input_charset = 'UTF-8'; |
|
| 72 | + } |
|
| 73 | + $this->content = $content; |
|
| 74 | + $this->charset_in = $input_charset; |
|
| 75 | + $this->charset_out = $output_charset; |
|
| 76 | 76 | |
| 77 | - /* TODO: parse specified tags only */ |
|
| 78 | - parent::__construct($content, $input_charset, $input_charset, false); |
|
| 77 | + /* TODO: parse specified tags only */ |
|
| 78 | + parent::__construct($content, $input_charset, $input_charset, false); |
|
| 79 | 79 | |
| 80 | - //xoops_message($this); |
|
| 81 | - unset($this->content); |
|
| 82 | - $this->encoding_convert($tags); |
|
| 83 | - } |
|
| 80 | + //xoops_message($this); |
|
| 81 | + unset($this->content); |
|
| 82 | + $this->encoding_convert($tags); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @return bool|string |
|
| 87 | - */ |
|
| 88 | - public function is_atom() { |
|
| 89 | - if ($this->feed_type == ATOM) { |
|
| 90 | - $this->feed_version = empty($this->feed_version) ? '0.3' : $this->feed_version; |
|
| 85 | + /** |
|
| 86 | + * @return bool|string |
|
| 87 | + */ |
|
| 88 | + public function is_atom() { |
|
| 89 | + if ($this->feed_type == ATOM) { |
|
| 90 | + $this->feed_version = empty($this->feed_version) ? '0.3' : $this->feed_version; |
|
| 91 | 91 | |
| 92 | - return $this->feed_version; |
|
| 93 | - } else { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - } |
|
| 92 | + return $this->feed_version; |
|
| 93 | + } else { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - public function normalize() { |
|
| 99 | - if ($this->is_atom()): |
|
| 100 | - if (empty($this->channel['tagline'])) { |
|
| 101 | - /* ATOM */ |
|
| 102 | - $this->channel['tagline'] = @$this->channel['subtitle']; |
|
| 103 | - unset($this->channel['subtitle']); |
|
| 104 | - } |
|
| 105 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 106 | - // ATOM time |
|
| 107 | - if ($date = @$this->items[$i]['modified']) { |
|
| 108 | - continue; |
|
| 109 | - } |
|
| 110 | - if (empty($date)) { |
|
| 111 | - $date = @$this->items[$i]['updated']; |
|
| 112 | - } |
|
| 113 | - if (empty($date)) { |
|
| 114 | - $date = @$this->items[$i]['issued']; |
|
| 115 | - } |
|
| 116 | - if (empty($date)) { |
|
| 117 | - $date = @$this->items[$i]['created']; |
|
| 118 | - } |
|
| 119 | - if (empty($date)) { |
|
| 120 | - $date = @$this->items[$i]['created']; |
|
| 121 | - } |
|
| 122 | - $this->items[$i]['modified'] = $date; |
|
| 123 | - } |
|
| 124 | - elseif ($this->is_rss() !== '1.0'): |
|
| 125 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 126 | - if ($date = @$this->items[$i]['pubdate']) { |
|
| 127 | - continue; |
|
| 128 | - } |
|
| 129 | - $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
| 130 | - } |
|
| 131 | - endif; |
|
| 132 | - parent::normalize(); |
|
| 133 | - /* ATOM */ |
|
| 134 | - if (empty($this->channel['language']) && !empty($this->channel['dc']['language'])) { |
|
| 135 | - $this->channel['language'] = $this->channel['dc']['language']; |
|
| 136 | - unset($this->channel['dc']['language']); |
|
| 137 | - } |
|
| 138 | - if (empty($this->channel['language']) |
|
| 139 | - && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) |
|
| 140 | - ) { |
|
| 141 | - $this->channel['language'] = $match[1]; |
|
| 142 | - } |
|
| 143 | - if (empty($this->channel['language']) |
|
| 144 | - && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) |
|
| 145 | - ) { |
|
| 146 | - $this->channel['language'] = $match[1]; |
|
| 147 | - } |
|
| 148 | - /* remove to avoid redundant encoding conversion */ |
|
| 149 | - if (!empty($this->channel['tagline'])) { |
|
| 150 | - unset($this->channel['tagline']); |
|
| 151 | - } |
|
| 98 | + public function normalize() { |
|
| 99 | + if ($this->is_atom()): |
|
| 100 | + if (empty($this->channel['tagline'])) { |
|
| 101 | + /* ATOM */ |
|
| 102 | + $this->channel['tagline'] = @$this->channel['subtitle']; |
|
| 103 | + unset($this->channel['subtitle']); |
|
| 104 | + } |
|
| 105 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 106 | + // ATOM time |
|
| 107 | + if ($date = @$this->items[$i]['modified']) { |
|
| 108 | + continue; |
|
| 109 | + } |
|
| 110 | + if (empty($date)) { |
|
| 111 | + $date = @$this->items[$i]['updated']; |
|
| 112 | + } |
|
| 113 | + if (empty($date)) { |
|
| 114 | + $date = @$this->items[$i]['issued']; |
|
| 115 | + } |
|
| 116 | + if (empty($date)) { |
|
| 117 | + $date = @$this->items[$i]['created']; |
|
| 118 | + } |
|
| 119 | + if (empty($date)) { |
|
| 120 | + $date = @$this->items[$i]['created']; |
|
| 121 | + } |
|
| 122 | + $this->items[$i]['modified'] = $date; |
|
| 123 | + } |
|
| 124 | + elseif ($this->is_rss() !== '1.0'): |
|
| 125 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 126 | + if ($date = @$this->items[$i]['pubdate']) { |
|
| 127 | + continue; |
|
| 128 | + } |
|
| 129 | + $this->items[$i]['pubdate'] = @$this->items[$i]['dc']['date']; |
|
| 130 | + } |
|
| 131 | + endif; |
|
| 132 | + parent::normalize(); |
|
| 133 | + /* ATOM */ |
|
| 134 | + if (empty($this->channel['language']) && !empty($this->channel['dc']['language'])) { |
|
| 135 | + $this->channel['language'] = $this->channel['dc']['language']; |
|
| 136 | + unset($this->channel['dc']['language']); |
|
| 137 | + } |
|
| 138 | + if (empty($this->channel['language']) |
|
| 139 | + && preg_match('/<link.*hreflang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) |
|
| 140 | + ) { |
|
| 141 | + $this->channel['language'] = $match[1]; |
|
| 142 | + } |
|
| 143 | + if (empty($this->channel['language']) |
|
| 144 | + && preg_match('/<feed.*xml:lang=[\'"](.*?)[\'"].*?>/m', $this->content, $match) |
|
| 145 | + ) { |
|
| 146 | + $this->channel['language'] = $match[1]; |
|
| 147 | + } |
|
| 148 | + /* remove to avoid redundant encoding conversion */ |
|
| 149 | + if (!empty($this->channel['tagline'])) { |
|
| 150 | + unset($this->channel['tagline']); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 154 | - if ($date_timestamp = @$this->items[$i]['date_timestamp']) { |
|
| 155 | - continue; |
|
| 156 | - } |
|
| 157 | - if ($date_timestamp = @$this->items[$i]['pubdate']) { |
|
| 158 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 159 | - } elseif ($date_timestamp = @$this->items[$i]['dc']['date']) { |
|
| 160 | - $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 161 | - } else { |
|
| 162 | - $this->items[$i]['date_timestamp'] = time(); |
|
| 163 | - } |
|
| 164 | - if (!is_numeric($this->items[$i]['date_timestamp'])) { |
|
| 165 | - if ($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
| 166 | - $this->items[$i]['date_timestamp'] = $date; |
|
| 167 | - } elseif ($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
| 168 | - $this->items[$i]['date_timestamp'] = $date; |
|
| 169 | - } |
|
| 170 | - } |
|
| 153 | + for ($i = 0, $iMax = count($this->items); $i < $iMax; ++$i) { |
|
| 154 | + if ($date_timestamp = @$this->items[$i]['date_timestamp']) { |
|
| 155 | + continue; |
|
| 156 | + } |
|
| 157 | + if ($date_timestamp = @$this->items[$i]['pubdate']) { |
|
| 158 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 159 | + } elseif ($date_timestamp = @$this->items[$i]['dc']['date']) { |
|
| 160 | + $this->items[$i]['date_timestamp'] = $date_timestamp; |
|
| 161 | + } else { |
|
| 162 | + $this->items[$i]['date_timestamp'] = time(); |
|
| 163 | + } |
|
| 164 | + if (!is_numeric($this->items[$i]['date_timestamp'])) { |
|
| 165 | + if ($date = parse_w3cdtf($this->items[$i]['date_timestamp'])) { |
|
| 166 | + $this->items[$i]['date_timestamp'] = $date; |
|
| 167 | + } elseif ($date = strtotime($this->items[$i]['date_timestamp'])) { |
|
| 168 | + $this->items[$i]['date_timestamp'] = $date; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - /* remove to avoid redundant encoding conversion */ |
|
| 173 | - if (isset($this->items[$i]['summary'])) { |
|
| 174 | - unset($this->items[$i]['summary']); |
|
| 175 | - } |
|
| 176 | - if (isset($this->items[$i]['atom_content'])) { |
|
| 177 | - unset($this->items[$i]['atom_content']); |
|
| 178 | - } |
|
| 179 | - } |
|
| 172 | + /* remove to avoid redundant encoding conversion */ |
|
| 173 | + if (isset($this->items[$i]['summary'])) { |
|
| 174 | + unset($this->items[$i]['summary']); |
|
| 175 | + } |
|
| 176 | + if (isset($this->items[$i]['atom_content'])) { |
|
| 177 | + unset($this->items[$i]['atom_content']); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | 180 | |
| 181 | - return; |
|
| 182 | - } |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * @param array $tags |
|
| 186 | - */ |
|
| 187 | - public function encoding_convert($tags = array()) { |
|
| 188 | - if (empty($tags) || in_array('channel', $tags)) { |
|
| 189 | - $this->channel = $this->_encoding($this->channel); |
|
| 190 | - } |
|
| 191 | - if (empty($tags) || in_array('items', $tags)) { |
|
| 192 | - $this->items = $this->_encoding($this->items); |
|
| 193 | - } |
|
| 194 | - } |
|
| 184 | + /** |
|
| 185 | + * @param array $tags |
|
| 186 | + */ |
|
| 187 | + public function encoding_convert($tags = array()) { |
|
| 188 | + if (empty($tags) || in_array('channel', $tags)) { |
|
| 189 | + $this->channel = $this->_encoding($this->channel); |
|
| 190 | + } |
|
| 191 | + if (empty($tags) || in_array('items', $tags)) { |
|
| 192 | + $this->items = $this->_encoding($this->items); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * @param $val |
|
| 198 | - * @return array|mixed|string |
|
| 199 | - */ |
|
| 200 | - public function _encoding($val) { |
|
| 201 | - if (is_array($val)) { |
|
| 202 | - foreach (array_keys($val) as $key) { |
|
| 203 | - $val[$key] = $this->_encoding($val[$key]); |
|
| 204 | - } |
|
| 205 | - } else { |
|
| 206 | - $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
| 207 | - } |
|
| 196 | + /** |
|
| 197 | + * @param $val |
|
| 198 | + * @return array|mixed|string |
|
| 199 | + */ |
|
| 200 | + public function _encoding($val) { |
|
| 201 | + if (is_array($val)) { |
|
| 202 | + foreach (array_keys($val) as $key) { |
|
| 203 | + $val[$key] = $this->_encoding($val[$key]); |
|
| 204 | + } |
|
| 205 | + } else { |
|
| 206 | + $val = XoopsLocal::convert_encoding($val, $this->charset_out, $this->charset_in); |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return $val; |
|
| 210 | - } |
|
| 209 | + return $val; |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -30,70 +30,70 @@ |
||
| 30 | 30 | mod_loadFunctions('', $GLOBALS['moddirname']); |
| 31 | 31 | |
| 32 | 32 | if (!class_exists('Xmlrpc_client')) { |
| 33 | - /** |
|
| 34 | - * Class Xmlrpc_client |
|
| 35 | - */ |
|
| 36 | - class Xmlrpc_client |
|
| 37 | - { |
|
| 38 | - /** |
|
| 39 | - * Xmlrpc_client constructor. |
|
| 40 | - */ |
|
| 41 | - public function __construct() { |
|
| 42 | - } |
|
| 33 | + /** |
|
| 34 | + * Class Xmlrpc_client |
|
| 35 | + */ |
|
| 36 | + class Xmlrpc_client |
|
| 37 | + { |
|
| 38 | + /** |
|
| 39 | + * Xmlrpc_client constructor. |
|
| 40 | + */ |
|
| 41 | + public function __construct() { |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @param $article |
|
| 46 | - */ |
|
| 47 | - public function setObject(&$article) { |
|
| 48 | - $this->$var = $val; |
|
| 49 | - } |
|
| 44 | + /** |
|
| 45 | + * @param $article |
|
| 46 | + */ |
|
| 47 | + public function setObject(&$article) { |
|
| 48 | + $this->$var = $val; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param $var |
|
| 53 | - * @param $val |
|
| 54 | - */ |
|
| 55 | - public function setVar($var, $val) { |
|
| 56 | - $this->$var = $val; |
|
| 57 | - } |
|
| 51 | + /** |
|
| 52 | + * @param $var |
|
| 53 | + * @param $val |
|
| 54 | + */ |
|
| 55 | + public function setVar($var, $val) { |
|
| 56 | + $this->$var = $val; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $var |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public function getVar($var) { |
|
| 64 | - return $this->$var; |
|
| 65 | - } |
|
| 66 | - } |
|
| 59 | + /** |
|
| 60 | + * @param $var |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public function getVar($var) { |
|
| 64 | + return $this->$var; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | if (!class_exists('Xmlrpc_server')) { |
| 70 | - /** |
|
| 71 | - * Class Xmlrpc_server |
|
| 72 | - */ |
|
| 73 | - class Xmlrpc_server |
|
| 74 | - { |
|
| 75 | - /** |
|
| 76 | - * Xmlrpc_server constructor. |
|
| 77 | - */ |
|
| 78 | - public function __construct() { |
|
| 79 | - } |
|
| 70 | + /** |
|
| 71 | + * Class Xmlrpc_server |
|
| 72 | + */ |
|
| 73 | + class Xmlrpc_server |
|
| 74 | + { |
|
| 75 | + /** |
|
| 76 | + * Xmlrpc_server constructor. |
|
| 77 | + */ |
|
| 78 | + public function __construct() { |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param $var |
|
| 83 | - * @param $val |
|
| 84 | - */ |
|
| 85 | - public function setVar($var, $val) { |
|
| 86 | - $this->$var = $val; |
|
| 87 | - } |
|
| 81 | + /** |
|
| 82 | + * @param $var |
|
| 83 | + * @param $val |
|
| 84 | + */ |
|
| 85 | + public function setVar($var, $val) { |
|
| 86 | + $this->$var = $val; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * @param $var |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 93 | - public function getVar($var) { |
|
| 94 | - return $this->$var; |
|
| 95 | - } |
|
| 96 | - } |
|
| 89 | + /** |
|
| 90 | + * @param $var |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | + public function getVar($var) { |
|
| 94 | + return $this->$var; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | planet_parse_class(' |
@@ -44,24 +44,24 @@ |
||
| 44 | 44 | **/ |
| 45 | 45 | if (!class_exists('Bookmark')): |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Class Bookmark |
|
| 49 | - */ |
|
| 50 | - class Bookmark extends XoopsObject |
|
| 51 | - { |
|
| 52 | - /** |
|
| 53 | - * Constructor |
|
| 54 | - */ |
|
| 55 | - public function __construct() { |
|
| 56 | - // $this->ArtObject(); |
|
| 57 | - $this->table = planet_DB_prefix('bookmark'); |
|
| 58 | - $this->initVar('bm_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | - /* user ID */ |
|
| 60 | - $this->initVar('bm_uid', XOBJ_DTYPE_INT, 0, true); |
|
| 61 | - /* blog ID */ |
|
| 62 | - $this->initVar('blog_id', XOBJ_DTYPE_INT, 0, true); |
|
| 63 | - } |
|
| 64 | - } |
|
| 47 | + /** |
|
| 48 | + * Class Bookmark |
|
| 49 | + */ |
|
| 50 | + class Bookmark extends XoopsObject |
|
| 51 | + { |
|
| 52 | + /** |
|
| 53 | + * Constructor |
|
| 54 | + */ |
|
| 55 | + public function __construct() { |
|
| 56 | + // $this->ArtObject(); |
|
| 57 | + $this->table = planet_DB_prefix('bookmark'); |
|
| 58 | + $this->initVar('bm_id', XOBJ_DTYPE_INT, null, false); |
|
| 59 | + /* user ID */ |
|
| 60 | + $this->initVar('bm_uid', XOBJ_DTYPE_INT, 0, true); |
|
| 61 | + /* blog ID */ |
|
| 62 | + $this->initVar('blog_id', XOBJ_DTYPE_INT, 0, true); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | endif; |
| 66 | 66 | /** |
| 67 | 67 | * Topic object handler class. |