37 public $open_tags = Array();
44 public $parent_tags = Array();
51 public $item = Array();
58 public $image = Array();
65 public $channel = Array();
72 public $textinput = Array();
79 public $attributes = Array();
86 public $unrecognised = Array();
121 public $parsed = FALSE;
130 $this->parser = xml_parser_create();
132 xml_set_object($this->parser, $this);
133 xml_set_element_handler($this->parser,
'startElementHandler',
'endElementHandler');
134 xml_set_character_data_handler($this->parser,
'characterHandler');
156 $file = preg_replace(
'/^feed:(\/\/)?(http:\/\/)?/',
'http://',$file);
158 if (preg_match(
'%^(http[s]*|ftp)://%', substr($file, 0, 10))) {
159 if (!ini_get(
'allow_url_fopen')) {
160 trigger_error(
'Remote Files Cannot Be Parsed', E_USER_WARNING);
163 require_once(SQ_INCLUDE_PATH.
'/general_occasional.inc');
164 $this->fp = open_socket_connection($file, $errno, $errstr);
166 $this->fp = fopen($file,
'r');
171 trigger_error(
'Error occured during opening the file '.$file, E_USER_WARNING);
175 trigger_error(
'No File Path Or URL Entered', E_USER_ERROR);
194 trigger_error(
'Empty Strings Cannot Be Parsed', E_USER_ERROR);
197 if (!is_string($xml)) {
198 trigger_error(
'Only XML Strings Can Be Parsed', E_USER_ERROR);
219 trigger_error(
'Invalid file pointer', E_USER_WARNING);
220 return 'Invalid file pointer';
222 $this->parsed = TRUE;
223 if (!is_string($this->fp)) {
227 $data = fread($fp, 4096);
230 $data = explode(
'<?xml', $data);
231 if (count($data) > 1) {
233 $data =
'<?xml'.implode(
'<?xml', $data);
237 $start_tags = Array (
'rss',
'rdf',
'feed');
238 foreach ($start_tags as $tag){
239 $test_data = str_ireplace(
"<$tag",
"<$tag", $data[0]);
240 $test_data = explode(
"<$tag", $test_data);
241 if (count($test_data) > 1) {
242 array_shift($test_data);
243 $data =
"<$tag".implode(
"<$tag", $test_data);
251 if ($found_xml && !xml_parse($this->parser, $data)) {
252 return 'Error in the feed';
258 return 'Error in the feed';
262 if (!xml_parse($this->parser, $this->fp)) {
263 return 'Error in the feed';
307 if ($this->
_issetFile())
return $this->textinput;
320 if ($this->
_issetFile())
return $this->channel;
346 if ($this->
_issetFile())
return $this->unrecognised;
377 $this->type =
'atom_1.0';
381 $this->type =
'rss_';
382 $this->type .= isset($attributes[
'VERSION']) ? $attributes[
'VERSION'] :
'';
385 $this->type =
'rss_1.0';
388 $this->open_tags[] = $name;
391 $this->parent_tags[] = $name;
393 $this->element = $name;
396 if (!empty($attributes)) {
397 $this->attributes = $attributes;
427 if ($key = array_search($name, $this->open_tags)) {
428 if ($key == count($this->open_tags)-1) {
429 $element = array_pop($this->open_tags);
432 $count = count($this->parent_tags);
434 if ($this->element == $this->parent_tags[$count-1]) {
435 $element = array_pop($this->parent_tags);
458 if ((is_array($data) && !empty($data)) || (is_string($data) && trim($data) !=
'')) {
459 $element = $this->element;
470 $key = array_search($element, $this->open_tags);
473 $class_vars = get_class_vars(get_class($this));
474 for ( ; $key != -1; $key--) {
475 if (isset($class_vars[strtolower($this->open_tags[$key])]) && ($this->open_tags[$key] !=
'TYPE')) {
481 $var = strtolower($this->open_tags[$key]);
482 $key = array_search($element, $this->open_tags) - 1;
483 if (isset($this->open_tags[$key])) {
484 if (strcasecmp($this->open_tags[$key], $var) != 0) {
485 $parent = strtolower($this->open_tags[$key]);
489 $var =
'unrecognised';
490 $key = array_search($element, $this->open_tags) - 1;
491 if (isset($this->open_tags[$key])) {
492 $parent = strtolower($this->open_tags[$key]);
494 $parent = strtolower($element);
498 if ($var ==
'unrecognised') {
501 if (!empty($this->{$var})) {
502 $required = $this->{$var};
503 if (array_search(strtoupper($parent), $this->parent_tags)) {
505 foreach ($this->parent_tags as $key => $name) {
506 if (strcasecmp($name, $parent) == 0) $keys[] = $key;
508 $index = count($keys) - 1;
517 $this->{$var}[$parent][$index][$element][
'value'] = $data;
519 $this->{$var}[$parent][$index][$element][
'_attributes'] = $data;
527 if ($element ==
'LINK') {
528 if ((is_array ($data)) && (array_key_exists(
'REL', $data)) && ($data[
'REL'] !=
'alternate'))
return;
533 if (!empty($this->{$var})) {
538 if (array_search(strtoupper($var), $this->parent_tags)) {
540 foreach ($this->parent_tags as $key => $value) {
541 if (strcasecmp($value, $var) == 0) $count++;
553 if (!empty($element)) {
554 $element = strtolower($element);
557 if (empty($parent)) {
558 if (isset($this->{$var}[$index][$element][
'value']) && (!$attributes)) {
559 $value = $this->{$var}[$index][$element][
'value'];
560 $data = $value.$data;
563 if (isset($this->{$var}[$index][$parent][$element][
'value']) && (!$attributes)) {
564 $value = $this->{$var}[$index][$parent][$element][
'value'];
565 $data = $value.$data;
572 if (empty($parent)) {
573 $this->{$var}[$index][$element][
'value'] = $data;
575 $this->{$var}[$index][$parent][$element][
'value'] = $data;
579 if ($var != $element) {
580 if (empty($parent)) {
581 $this->{$var}[$index][$element][
'_attributes'] = $data;
583 $this->{$var}[$index][$parent][$element][
'_attributes'] = $data;
586 $this->{$var}[$index][
'_attributes'] = $data;
604 if (!isset($this->fp)) {
605 trigger_error(
'The XML That Has To Be Parsed Is To Be Set First Using setInputFile or setInputString');
608 if (!$this->parsed) {
609 trigger_error(
'The XML That Has To Be Parsed First Using parse() Function');