Beispiel #1
0
 public static function generateVersionInfo($filename)
 {
     static $info;
     if ($info) {
         return $info;
     }
     if (!is_file($filename)) {
         v("Can't find Version information file (%s), skipping!", $filename, E_USER_WARNING);
         return array();
     }
     $r = new \XMLReader();
     if (!$r->open($filename)) {
         v("Can't open the version info file (%s)", $filename, E_USER_ERROR);
     }
     $versions = array();
     while ($r->read()) {
         if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("-", "-", "-", "-", ""), $r->value)) && $r->moveToAttribute("from") && ($from = $r->value)) {
             $versions[strtolower($funcname)] = $from;
             $r->moveToElement();
         }
     }
     $r->close();
     $info = $versions;
     return $versions;
 }
Beispiel #2
0
 public static function generateVersionInfo($filename)
 {
     static $info;
     if ($info) {
         return $info;
     }
     $r = new \XMLReader();
     if (!$r->open($filename)) {
         throw new \Exception("Could not open file for accessing version information: {$filename}");
     }
     $versions = array();
     while ($r->read()) {
         if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("-", "-", "-", "-", ""), $r->value)) && $r->moveToAttribute("from") && ($from = $r->value)) {
             $versions[strtolower($funcname)] = $from;
             $r->moveToElement();
         }
     }
     $r->close();
     $info = $versions;
     return $versions;
 }
Beispiel #3
0
/** GET WEATHER * */
function getWeather($w = '', $u = 'c')
{
    $wURI = 'API';
    $weather = array();
    $reader = new XMLReader();
    $reader->open($wURI);
    $i = -1;
    while ($reader->read()) {
        if (strpos($reader->name, "yweather") !== false && $reader->hasAttributes) {
            switch ($reader->localName) {
                case 'atmosphere':
                    $reader->moveToAttribute('humidity');
                    $weather['humidity'] = $reader->value;
                    $reader->moveToAttribute('pressure');
                    $weather['pressure'] = $reader->value;
                    break;
                case 'astronomy':
                    $reader->moveToAttribute('sunrise');
                    $weather['sunrise'] = $reader->value;
                    $reader->moveToAttribute('sunset');
                    $weather['sunset'] = $reader->value;
                    break;
                case 'condition':
                    $reader->moveToAttribute('text');
                    $weather['text'] = $reader->value;
                    $reader->moveToAttribute('code');
                    $weather['code'] = $reader->value;
                    $reader->moveToAttribute('temp');
                    $weather['temperature'] = $reader->value;
                    break;
                case 'forecast':
                    $i++;
                    $reader->moveToAttribute('date');
                    $weather['forecast'][$i]['date'] = $reader->value;
                    $reader->moveToAttribute('low');
                    $weather['forecast'][$i]['low'] = $reader->value;
                    $reader->moveToAttribute('high');
                    $weather['forecast'][$i]['high'] = $reader->value;
                    $reader->moveToAttribute('text');
                    $weather['forecast'][$i]['text'] = $reader->value;
                    break;
            }
        }
    }
    if ($i == -1) {
        return false;
    } else {
        return $weather;
    }
}
 /**
  * Generates the report by processing the XML file.
  * @param array $params 
  */
 public function generate($params)
 {
     $report = $this->getReport();
     $reader = new XMLReader();
     $reader->XML($this->xml->asXML());
     while ($reader->read()) {
         if ($reader->nodeType !== XMLReader::ELEMENT) {
             continue;
         }
         switch ($reader->name) {
             case "rapi:logo":
                 if ($_POST["hide_logo"] == 1) {
                     $text = new TextContent();
                     $text->style["flow"] = true;
                     $text->setText("\n\n\n\n\n\n\n\n");
                     $report->add($text);
                 } else {
                     $reader->moveToAttribute("class");
                     $class = $reader->value;
                     $logo = $class == '' ? new LogoContent() : new $class();
                     $report->add($logo);
                     $report->logo = $logo;
                 }
                 break;
             case "rapi:text":
                 $text = new TextContent();
                 $reader->moveToAttribute("style");
                 switch ($reader->value) {
                     case "heading":
                         $text->style["size"] = 16;
                         $text->style["font"] = "Helvetica";
                         $text->style["bold"] = true;
                         $report->label = $text;
                         break;
                     default:
                         $text->style["size"] = $reader->moveToAttribute("size") ? $reader->value : 12;
                         $text->style["font"] = $reader->value ? $reader->moveToAttribute("font") : "Helvetica";
                         break;
                 }
                 $reader->read();
                 $text->setText($reader->value);
                 $report->add($text);
                 break;
             case "rapi:table":
                 $numConcatFields = 0;
                 $reader->moveToAttribute("name");
                 $name = $reader->value;
                 $tableConditionsArray = array();
                 if ($reader->moveToAttribute("conditions")) {
                     $tableConditionsArray[] = $reader->value;
                 }
                 if ($this->tableConditions != '') {
                     $tableConditionsArray[] = $this->tableConditions;
                 }
                 $tableConditions = implode(" AND ", $tableConditionsArray);
                 $fields = $this->xml->xpath("/rapi:report/rapi:table[@name='{$name}']/rapi:fields/rapi:field");
                 $headers = $this->xml->xpath("/rapi:report/rapi:table[@name='{$name}']/rapi:fields/rapi:field[@label!='']/@label");
                 $dontJoins = $this->xml->xpath("/rapi:report/rapi:table[@name='{$name}']/rapi:dont_join/rapi:pair");
                 $ignoredFields = array();
                 $dataParams["total"] = array();
                 $hardCodedSorting = array();
                 $reportGroupingFields = array();
                 $models = array();
                 $fieldInfos = array();
                 // Generate filter conditions
                 $filters = array();
                 $filterSummaries = array();
                 $keyOffset = 0;
                 foreach ($fields as $key => $field) {
                     // Load the model for this field if it hasn't been
                     // loaded already. I have a hunch that this check
                     // is really not necessary since the model loader
                     // sort of caches loaded models now.
                     $modelInfo = Model::resolvePath((string) $field);
                     if (array_search($modelInfo["model"], array_keys($models)) === false) {
                         $models[$modelInfo["model"]] = Model::load($modelInfo["model"]);
                     }
                     $model = $models[$modelInfo["model"]];
                     $fieldInfo = $model->getFields(array($modelInfo["field"]));
                     $fieldInfo = $fieldInfo[0];
                     $fieldInfos[(string) $field] = $fieldInfo;
                     //Ignore fields which are not needed.
                     if (isset($_POST[$name . "_" . $fieldInfo["name"] . "_ignore"])) {
                         $ignoredFields[] = $key;
                     }
                     if (isset($field["sort"])) {
                         $sortField = "{$model->database}.{$fieldInfo["name"]}";
                         $hardCodedSorting[] = array("field" => $sortField, "type" => $field["sort"]);
                     }
                     if (isset($field["labelsField"])) {
                         $dynamicFields[] = (string) $field;
                         $dynamicHeaders[] = (string) $field["labelsField"];
                         $labelModelInfo = Model::resolvePath($field["labelsField"]);
                         $headersModel = Model::load($labelModelInfo["model"]);
                         $dynamicHeaderValues = $headersModel->get(array("fields" => array($labelModelInfo["field"])), SQLDataBaseModel::MODE_ARRAY);
                         foreach ($dynamicHeaderValues as $headerValue) {
                             $tableHeaders[] = $headerValue[0];
                             if ($field["total"] == "true") {
                                 $dataParams["total"][] = true;
                                 //$key + $keyOffset;
                                 $dataParams["type"][] = "double";
                             }
                             $keyOffset++;
                         }
                         $keyOffset--;
                     } else {
                         $tableHeaders[] = (string) $field["label"];
                         switch ($fieldInfo["type"]) {
                             case "integer":
                                 $dataParams["type"][] = "number";
                                 break;
                             case "double":
                                 $dataParams["type"][] = "double";
                                 break;
                             default:
                                 $dataParams["type"][] = "";
                         }
                         $dataParams["total"][] = $field["total"] == "true" ? true : false;
                     }
                     $fields[$key] = (string) $field;
                     $value = $field["value"];
                     $field = (string) $field;
                     if (array_search($model->getKeyField(), $this->referencedFields) === false || $fieldInfo["type"] == "double" || $fieldInfo["type"] == "date") {
                         if ($value != null) {
                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}='{$value}'";
                             continue;
                         }
                         switch ($fieldInfo["type"]) {
                             case "string":
                             case "text":
                                 if ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] != "") {
                                     switch ($_POST[$name . "_" . $fieldInfo["name"] . "_option"]) {
                                         case "CONTAINS":
                                             $filterSummaries[] = "{$headers[$key]} containing {$_POST[$name . "_" . $fieldInfo["name"] . "_value"]}";
                                             $filters[] = $models[$modelInfo["model"]]->getSearch($models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_value"]), "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}");
                                             break;
                                         case "EXACTLY":
                                             $filterSummaries[] = "{$headers[$key]} being exactly {$_POST[$name . "_" . $fieldInfo["name"] . "_value"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}='" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_value"]) . "'";
                                             break;
                                     }
                                 }
                                 break;
                             case "integer":
                             case "double":
                                 if ($_POST[$name . "_" . $fieldInfo["name"] . "_start_value"] != "") {
                                     switch ($_POST[$name . "_" . $fieldInfo["name"] . "_option"]) {
                                         case "EQUALS":
                                             $filterSummaries[] = "{$headers[$key]} equals {$_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}='" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]) . "'";
                                             break;
                                         case "GREATER":
                                             $filterSummaries[] = "{$headers[$key]} greater than {$_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}>'" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]) . "'";
                                             break;
                                         case "LESS":
                                             $filterSummaries[] = "{$headers[$key]} less than {$_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}<'" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]) . "'";
                                             break;
                                         case "BETWEEN":
                                             $filterSummaries[] = "{$headers[$key]} between {$_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]} and {$_POST[$name . "_" . $fieldInfo["name"] . "_end_value"]}";
                                             $filters[] = "({$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}>='" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_start_value"]) . "' AND {$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}<='" . $models[$modelInfo["model"]]->escape($_POST[$name . "_" . $fieldInfo["name"] . "_end_value"]) . "')";
                                             break;
                                     }
                                 }
                                 break;
                             case "reference":
                                 break;
                             case "datetime":
                             case "date":
                                 if ($_POST[$name . "_" . $fieldInfo["name"] . "_start_date"] != "") {
                                     switch ($_POST[$name . "_" . $fieldInfo["name"] . "_option"]) {
                                         case "EQUALS":
                                             $filterSummaries[] = "{$headers[$key]} on {$_POST[$name . "_" . $fieldInfo["name"] . "_start_date"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}='" . $models[$modelInfo["model"]]->escape(Common::stringToDatabaseDate($_POST[$name . "_" . $fieldInfo["name"] . "_start_date"])) . "'";
                                             break;
                                         case "GREATER":
                                             $filterSummaries[] = "{$headers[$key]} after {$_POST[$name . "_" . $fieldInfo["name"] . "_start_date"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}>'" . $models[$modelInfo["model"]]->escape(Common::stringToDatabaseDate($_POST[$name . "_" . $fieldInfo["name"] . "_start_date"])) . "'";
                                             break;
                                         case "LESS":
                                             $filterSummaries[] = "{$headers[$key]} before {$_POST[$name . "_" . $fieldInfo["name"] . "_start_date"]}";
                                             $filters[] = "{$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}<'" . $models[$modelInfo["model"]]->escape(Common::stringToDatabaseDate($_POST[$name . "_" . $fieldInfo["name"] . "_start_date"])) . "'";
                                             break;
                                         case "BETWEEN":
                                             $filterSummaries[] = "{$headers[$key]} from {$_POST[$name . "_" . $fieldInfo["name"] . "_start_date"]} to {$_POST[$name . "_" . $fieldInfo["name"] . "_end_date"]}";
                                             $filters[] = "({$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}>='" . $models[$modelInfo["model"]]->escape(Common::stringToDatabaseDate($_POST[$name . "_" . $fieldInfo["name"] . "_start_date"])) . "' AND {$models[$modelInfo["model"]]->getDatabase()}.{$fieldInfo["name"]}<='" . $models[$modelInfo["model"]]->escape(Common::stringToDatabaseDate($_POST[$name . "_" . $fieldInfo["name"] . "_end_date"])) . "')";
                                             break;
                                     }
                                 }
                                 break;
                             case "enum":
                                 if (count($_POST[$name . "_" . $fieldInfo["name"] . "_value"]) >= 1 && $_POST[$name . "_" . $fieldInfo["name"] . "_value"][0] != "") {
                                     $m = $models[$modelInfo["model"]];
                                     if ($_POST[$name . "_" . $fieldInfo["name"] . "_option"] == "INCLUDE") {
                                         $summary = array();
                                         foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                             $summary[] = $fieldInfo["options"][$value];
                                         }
                                         $filterSummaries[] = "{$headers[$key]} being " . implode(", ", $summary);
                                         $condition = array();
                                         foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                             if ($value != "") {
                                                 $condition[] = "{$m->getDatabase()}.{$fieldInfo["name"]}='" . $m->escape($value) . "'";
                                             }
                                         }
                                     } else {
                                         if ($_POST[$name . "_" . $fieldInfo["name"] . "_option"] == "EXCLUDE") {
                                             $summary = array();
                                             foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                                 $summary[] = $fieldInfo["options"][$value];
                                             }
                                             $filterSummaries[] = "{$headers[$key]} excluding " . implode(", ", $summary);
                                             $condition = array();
                                             foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                                 if ($value != "") {
                                                     $condition[] = "{$m->getDatabase()}.{$fieldInfo["name"]}<>'" . $m->escape($value) . "'";
                                                 }
                                             }
                                         }
                                     }
                                     if (count($condition) > 0) {
                                         $filters[] = "(" . implode(" OR ", $condition) . ")";
                                     }
                                 }
                                 break;
                         }
                     } else {
                         if ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] != "") {
                             if ($_POST[$name . "_" . $fieldInfo["name"] . "_option"] == "IS_ANY_OF") {
                                 foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                     if ($value != "") {
                                         $condition[] = "{$model->getDatabase()}.{$fieldInfo["name"]}='" . $model->escape($value) . "'";
                                     }
                                 }
                             } else {
                                 if ($_POST[$name . "_" . $fieldInfo["name"] . "_option"] == "IS_NONE_OF") {
                                     foreach ($_POST[$name . "_" . $fieldInfo["name"] . "_value"] as $value) {
                                         if ($value != "") {
                                             $condition[] = "{$model->getDatabase()}.{$fieldInfo["name"]}<>'" . $model->escape($value) . "'";
                                         }
                                     }
                                 }
                             }
                             if (count($condition) > 0) {
                                 $filters[] = "(" . implode(" OR ", $condition) . ")";
                             }
                         }
                     }
                 }
                 $this->updateFilterSummaries($filterSummaries);
                 // Generate the various tables taking into consideration grouping
                 if (count($filterSummaries) > 0) {
                     $report->filterSummary = new TextContent(str_replace("\\n", " ", implode("\n", $filterSummaries)), array("size" => 8, "bottom_margin" => 3));
                     $report->filterSummary->style["flow"] = true;
                     $report->add($report->filterSummary);
                 }
                 $params = array("fields" => $fields, "dynamicFields" => $dynamicFields, "dynamicHeaders" => $dynamicHeaders, "conditions" => implode(" AND ", $filters), "report" => $report, "headers" => $tableHeaders, "dont_join" => array());
                 foreach ($dontJoins as $pair) {
                     $params['dont_join'][] = (string) $pair;
                 }
                 if ($tableConditions != "") {
                     $params["conditions"] = $params['conditions'] . ($params['conditions'] != '' ? " AND " : '') . "({$tableConditions})";
                 }
                 if ($_POST[$name . "_sorting"] != "") {
                     array_unshift($hardCodedSorting, array("field" => $_POST[$name . "_sorting"], "type" => $_POST[$name . "_sorting_direction"]));
                 }
                 if (is_array($_POST[$name . "_grouping"])) {
                     foreach ($_POST[$name . "_grouping"] as $postGrouping) {
                         if ($postGrouping != "") {
                             $groupingFields = explode(",", $postGrouping);
                             foreach ($groupingFields as $key => $groupingField) {
                                 $modelInfo = Model::resolvePath($groupingField);
                                 $model = Model::load($modelInfo["model"]);
                                 $groupingFields[$key] = "{$model->database}.{$modelInfo["field"]}";
                             }
                             $reportGroupingFields[] = array("field" => $model->datastore->concatenate($groupingFields), "type" => "ASC");
                         }
                     }
                     //$reportGroupingFields = array_reverse($reportGroupingFields);
                     $hardCodedSorting = array_merge($reportGroupingFields, $hardCodedSorting);
                 }
                 $params["sort_field"] = $hardCodedSorting;
                 if ($_POST[$name . "_limit"] != '') {
                     $params['limit'] = $_POST[$name . "_limit"];
                 }
                 $params["no_num_formatting"] = true;
                 $params = $this->paramsCallback($params);
                 $this->reportData = ReportController::getReportData($params, SQLDatabaseModel::MODE_ARRAY);
                 unset($params["sort_field"]);
                 $wparams = $params;
                 $wparams["global_functions"] = array("LENGTH", "MAX");
                 $wparams["global_functions_set"] = true;
                 $this->widths = ReportController::getReportData($wparams, SQLDatabaseModel::MODE_ARRAY);
                 //SQLDBDataStore::getMulti($wparams,SQLDatabaseModel::MODE_ARRAY);
                 $this->widths = $this->widths[0];
                 foreach ($tableHeaders as $i => $header) {
                     foreach (explode("\\n", $header) as $line) {
                         if (strlen($line) / 2 > $this->widths[$i]) {
                             $this->widths[$i] = strlen($line) / 2;
                         }
                     }
                 }
                 $dataParams["widths"] = $this->widths;
                 $params["data_params"] = $dataParams;
                 if (count($ignoredFields) > 0) {
                     foreach ($this->reportData as $key => $row) {
                         foreach ($ignoredFields as $ignored) {
                             unset($this->reportData[$key][$ignored]);
                             unset($params["headers"][$ignored]);
                             unset($params["fields"][$ignored]);
                             unset($params["data_params"]["type"][$ignored]);
                             unset($params["data_params"]["total"][$ignored]);
                             unset($params["data_params"]["widths"][$ignored]);
                             unset($this->widths[$key]);
                         }
                         $this->reportData[$key] = array_values($this->reportData[$key]);
                     }
                     $params["headers"] = array_values($params["headers"]);
                     $params["fields"] = array_values($params["fields"]);
                     $params["data_params"]["type"] = array_values($params["data_params"]["type"]);
                     $params["data_params"]["total"] = array_values($params["data_params"]["total"]);
                     $params["data_params"]["widths"] = array_values($params["data_params"]["widths"]);
                     $this->widths = array_values($this->widths);
                 }
                 if ($_POST[$name . "_grouping"][0] == "") {
                     $total = $this->drawTable($this->reportData, $params, $params["data_params"], true, $heading);
                 } else {
                     if ($_POST[$name . "_grouping"][0] != "" && $_POST["grouping_1_summary"] == '1') {
                         $params["grouping_fields"] = $_POST[$name . "_grouping"];
                         $params["grouping_level"] = 0;
                         $params["previous_headings"] = array();
                         $params["ignored_fields"] = array();
                         $total = $this->generateSummaryTable($params);
                     } else {
                         $params["grouping_fields"] = $_POST[$name . "_grouping"];
                         $params["grouping_level"] = 0;
                         $params["previous_headings"] = array();
                         $params["ignored_fields"] = array();
                         $total = $this->generateTable($params);
                         if (is_array($total) && count($total) > 0) {
                             $total[0] = $total[0] == "" ? "Overall Total" : $total[0];
                             $dataParams["widths"] = $this->widths;
                             $totalTable = new TableContent($tableHeaders, null);
                             $totalTable->data_params = $dataParams;
                             $totalTable->style["totalsBox"] = true;
                             foreach ($total as $key => $value) {
                                 if (is_numeric($value)) {
                                     $total[$key] = $value;
                                 }
                             }
                             $totalTable->setData($total);
                             $report->add($totalTable);
                         }
                     }
                 }
                 break;
         }
     }
     $report->output();
     //die();
 }
Beispiel #5
0
 public function parse($source)
 {
     if (preg_match('/flickr/', $source)) {
         $isFlickr = 1;
     }
     if (!$this->report) {
         error_reporting(0);
     }
     if ($this->returns) {
         $returns = $this->returns;
     } else {
         $returns = 5;
     }
     $feedLinks = -1;
     $feedCategories = -1;
     $feedAuthorsCount = -1;
     $itemLinks = -1;
     $itemCategories = -1;
     $reader = new \XMLReader();
     $cachedCopy = "pgcache/" . urlencode($source);
     if (file_exists($cachedCopy)) {
         $cacheTime = filemtime($cachedCopy);
         $now = time();
         $age = $now - $cacheTime;
     }
     if (file_exists($cachedCopy) && $this->cache && $age > $this->cache || !file_exists($cachedCopy)) {
         try {
             PGFeed::checkSource($source);
         } catch (Exception $e) {
             if ($this->report) {
                 echo 'Message: ' . $e->getMessage();
             }
             die;
         }
         if ($this->cache) {
             PGFeed::cacheFeed($source);
         }
         $reader->open($source);
     } else {
         $cachedContents = file_get_contents($cachedCopy);
         $reader->XML($cachedContents);
     }
     while ($reader->read()) {
         $name = $reader->name;
         if ($name == "feed" && $reader->nodeType == 1) {
             $isAtom = 1;
         } else {
             if (in_array("{$name}", $this->channelElements) && $reader->nodeType == 1 && !$isInItem && !$isInImage && !$isAtom) {
                 $reader->read();
                 $this->channel["{$name}"] = $reader->value;
             } else {
                 if ($name == "cloud" && $reader->nodeType == 1 && !$isAtom) {
                     foreach ($this->cloudAttributes as $att) {
                         if ($reader->moveToAttribute("{$att}")) {
                             $this->channel["cloud"]["{$att}"] = $reader->value;
                         }
                     }
                 } else {
                     if ($name == "image" && $reader->nodeType == 1 && !$isAtom) {
                         $isInImage = 1;
                     } else {
                         if ($name == "image" && $reader->nodeType == 15 && !$isAtom) {
                             $isInImage = 0;
                         } else {
                             if (in_array("{$name}", $this->imageElements) && $reader->nodeType == 1 && $isInImage && !$isAtom) {
                                 $reader->read();
                                 $this->channel["image"]["{$name}"] = $reader->value;
                             } else {
                                 if ($name == "textInput" && $reader->nodeType == 1 && !$isAtom) {
                                     $isInTextInput = 1;
                                 } else {
                                     if ($name == "textInput" && $reader->nodeType == 15 && !$isAtom) {
                                         $isInTextInput = 0;
                                     } else {
                                         if (in_array("{$name}", $this->textInputElements) && $reader->nodeType == 1 && $isInTextInput && !$isAtom) {
                                             $reader->read();
                                             $this->channel["textInput"]["{$name}"] = $reader->value;
                                         } else {
                                             if ($name == "item" && $reader->nodeType == 1 && !$isAtom) {
                                                 $isInItem = 1;
                                                 $itemNumber++;
                                                 $item = array();
                                             } else {
                                                 if (in_array("{$name}", $this->itemElements) && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                     $reader->read();
                                                     $item["{$name}"] = $reader->value;
                                                 } else {
                                                     if ($name == "description" && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                         $isInDescription = 1;
                                                         $reader->read();
                                                         $description = $reader->value;
                                                         if ($this->strip) {
                                                             $newDescription = preg_replace("/<.+?>/", "", $description);
                                                         } else {
                                                             $newDescription = $description;
                                                         }
                                                         $item["description"] = $newDescription;
                                                     } else {
                                                         if ($name == "description" && $reader->nodeType == 15) {
                                                             $isInDescription = 0;
                                                         } else {
                                                             if ($name == "enclosure" && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                                 foreach ($this->enclosureAttributes as $enatt) {
                                                                     if ($reader->moveToAttribute("{$enatt}")) {
                                                                         $item["enclosure"]["{$enatt}"] = $reader->value;
                                                                     }
                                                                 }
                                                             } else {
                                                                 if ($name == "item" && $reader->nodeType == 15 && !$isAtom) {
                                                                     $isInItem = 0;
                                                                     if ($itemNumber <= $returns) {
                                                                         array_push($this->items, $item);
                                                                     }
                                                                 } else {
                                                                     if ($name == "media:content" && $reader->nodeType == 1 && !$isAtom) {
                                                                         $isInMediaContent = 1;
                                                                         // URL of full-size image
                                                                         $reader->moveToAttribute("url");
                                                                         $item["mediaContentURL"] = $reader->value;
                                                                         $item["fullImageURL"] = $item["mediaContentURL"];
                                                                         // Type (e.g., image/jpeg)
                                                                         $reader->moveToAttribute("type");
                                                                         $item["mediaContentType"] = $reader->value;
                                                                         // Height of full-size image
                                                                         $reader->moveToAttribute("height");
                                                                         $item["mediaContentHeight"] = $reader->value;
                                                                         $item["fullImageHeight"] = $item["mediaContentHeight"];
                                                                         // Width of full-size image
                                                                         $reader->moveToAttribute("width");
                                                                         $item["mediaContentWidth"] = $reader->value;
                                                                         $item["fullImageWidth"] = $item["mediaContentWidth"];
                                                                     } else {
                                                                         if ($name == "media:content" && $reader->nodeType == 15 && !$isAtom) {
                                                                             $isInMediaContent = 0;
                                                                         } else {
                                                                             if ($name == "media:title" && $reader->nodeType == 1 && !$isAtom) {
                                                                                 $isInMediaTitle = 1;
                                                                                 $reader->read();
                                                                                 $item["mediaTitle"] = $reader->value;
                                                                             } else {
                                                                                 if ($name == "media:title" && $reader->nodeType == 15 && !$isAtom) {
                                                                                     $isInMediaTitle = 0;
                                                                                 } else {
                                                                                     if ($name == "media:description" && $reader->nodeType == 1 && !$isAtom) {
                                                                                         $isInMediaDescription = 1;
                                                                                         $reader->read();
                                                                                         $item["mediaDescription"] = $reader->value;
                                                                                         $item["caption"] = $item["mediaDescription"];
                                                                                     } else {
                                                                                         if ($name == "media:description" && $reader->nodeType == 15 && !$isAtom) {
                                                                                             $isInMediaDescription = 0;
                                                                                         } else {
                                                                                             if ($name == "media:thumbnail" && $reader->nodeType == 1 && !$isAtom) {
                                                                                                 $isInMediaThumbnail = 1;
                                                                                                 // URL of square thumbnail
                                                                                                 $reader->moveToAttribute("url");
                                                                                                 $item["mediaThumbnailURL"] = $reader->value;
                                                                                                 $item["squareThumbnailURL"] = $item["mediaThumbnailURL"];
                                                                                                 // Dimensions of square thumbnail
                                                                                                 $reader->moveToAttribute("height");
                                                                                                 $item["mediaThumbnailHeight"] = $reader->value;
                                                                                                 $item["squareThumbnailHeight"] = $item["mediaThumbnailHeight"];
                                                                                                 $item["mediaThumbnailWidth"] = $item["mediaThumbnailHeight"];
                                                                                                 $item["squareThumbnailWidth"] = $item["mediaThumbnailHeight"];
                                                                                                 // URL of regular thumbnail
                                                                                                 $item["thumbnailURL"] = preg_replace('/_s\\.(png|jpg|gif)/', '_t.$1', $item['mediaThumbnailURL']);
                                                                                                 // Dimensions of regular thumbnail
                                                                                                 if ($item["fullImageHeight"] > $item["fullImageWidth"]) {
                                                                                                     $item["thumbnailHeight"] = 100;
                                                                                                     $item["thumbnailWidth"] = round(100 * $item["fullImageWidth"] / $item["fullImageHeight"]);
                                                                                                 } else {
                                                                                                     if ($item["fullImageHeight"] < $item["fullImageWidth"]) {
                                                                                                         $item["thumbnailWidth"] = 100;
                                                                                                         $item["thumbnailHeight"] = round(100 * $item["fullImageHeight"] / $item["fullImageWidth"]);
                                                                                                     } else {
                                                                                                         $item["thumbnailWidth"] = 100;
                                                                                                         $item["thumbnailHeight"] = 100;
                                                                                                     }
                                                                                                 }
                                                                                             } else {
                                                                                                 if ($name == "media:thumbnail" && $reader->nodeType == 15 && !$isAtom) {
                                                                                                     $isInMediaThumbnail = 0;
                                                                                                 } else {
                                                                                                     if ($name == "media:credit" && $reader->nodeType == 1 && !$isAtom) {
                                                                                                         $isInMediaCredit = 1;
                                                                                                         $reader->read();
                                                                                                         $item["mediaCredit"] = $reader->value;
                                                                                                     } else {
                                                                                                         if ($name == "media:credit" && $reader->nodeType == 15 && !$isAtom) {
                                                                                                             $isInMediaCredit = 0;
                                                                                                         } else {
                                                                                                             if (in_array("{$name}", $this->feedElements) && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                                 $reader->read();
                                                                                                                 $this->channel["{$name}"] = $reader->value;
                                                                                                             } else {
                                                                                                                 if ($name == "title" && $reader->nodeType == 1 && !$isInSource && $isAtom) {
                                                                                                                     if ($reader->moveToAttribute("type")) {
                                                                                                                         if ($isInItem) {
                                                                                                                             $item["titleAttributes"]["type"] = $reader->value;
                                                                                                                         } else {
                                                                                                                             $this->channel["titleAttributes"]["type"] = $reader->value;
                                                                                                                         }
                                                                                                                     }
                                                                                                                     $reader->read();
                                                                                                                     if ($isInItem) {
                                                                                                                         $item["title"] = $reader->value;
                                                                                                                     } else {
                                                                                                                         $this->channel["title"] = $reader->value;
                                                                                                                     }
                                                                                                                 } else {
                                                                                                                     if ($name == "link" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                                         $feedLinks++;
                                                                                                                         foreach ($this->linkAttributes as $latt) {
                                                                                                                             if ($reader->moveToAttribute("{$latt}")) {
                                                                                                                                 $this->channel["links"]["{$feedLinks}"]["{$latt}"] = $reader->value;
                                                                                                                             }
                                                                                                                         }
                                                                                                                     } else {
                                                                                                                         if ($name == "generator" && $reader->nodeType == 1 && $isAtom) {
                                                                                                                             $reader->moveToAttribute("uri");
                                                                                                                             $this->channel["generatorURI"] = $reader->value;
                                                                                                                             $this->channel["link"] = $reader->value;
                                                                                                                             $reader->read();
                                                                                                                             $this->channel["{$name}"] = $reader->value;
                                                                                                                         } else {
                                                                                                                             if ($name == "author" && $reader->nodeType == 1 && $isAtom) {
                                                                                                                                 $isInAuthor = 1;
                                                                                                                                 $author = array();
                                                                                                                             } else {
                                                                                                                                 if (in_array($name, $this->authorElements) && $reader->nodeType == 1 && $isInAuthor && $isAtom) {
                                                                                                                                     $reader->read();
                                                                                                                                     $author["{$name}"] = $reader->value;
                                                                                                                                 } else {
                                                                                                                                     if ($name == "author" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                         $isInAuthor = 0;
                                                                                                                                         if ($isInItem) {
                                                                                                                                             array_push($this->authors, $author);
                                                                                                                                             $item["authors"] = $this->authors;
                                                                                                                                             $this->authors = array();
                                                                                                                                         } else {
                                                                                                                                             array_push($this->feedAuthors, $author);
                                                                                                                                             $this->channel["authors"] = $this->feedAuthors;
                                                                                                                                         }
                                                                                                                                     } else {
                                                                                                                                         if ($name == "category" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                                                             $feedCategories++;
                                                                                                                                             foreach ($this->categoryAttributes as $cat) {
                                                                                                                                                 if ($reader->moveToAttribute("{$cat}")) {
                                                                                                                                                     $this->channel["categories"]["{$feedCategories}"]["{$cat}"] = $reader->value;
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         } else {
                                                                                                                                             if ($name == "rights" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                                                                 if ($reader->moveToAttribute("src")) {
                                                                                                                                                     $this->channel["rights"]["src"] = $reader->value;
                                                                                                                                                 }
                                                                                                                                                 if ($reader->moveToAttribute("type")) {
                                                                                                                                                     $this->channel["rights"]["type"] = $reader->value;
                                                                                                                                                 }
                                                                                                                                                 $reader->read();
                                                                                                                                                 $this->channel["rights"]["rights"] = $reader->value;
                                                                                                                                             } else {
                                                                                                                                                 if ($name == "entry" && $reader->nodeType == 1 && $isAtom) {
                                                                                                                                                     $isInItem = 1;
                                                                                                                                                     $item = array();
                                                                                                                                                     $itemNumber++;
                                                                                                                                                     $itemLinks = -1;
                                                                                                                                                     $itemCategories = -1;
                                                                                                                                                 } else {
                                                                                                                                                     if ($name == "entry" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                                         $isInItem = 0;
                                                                                                                                                         if ($itemNumber <= $returns) {
                                                                                                                                                             array_push($this->items, $item);
                                                                                                                                                         }
                                                                                                                                                         $authors = array();
                                                                                                                                                     } else {
                                                                                                                                                         if (in_array("{$name}", $this->entryElements) && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                             $reader->read();
                                                                                                                                                             $item["{$name}"] = $reader->value;
                                                                                                                                                         } else {
                                                                                                                                                             if ($name == "rights" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                 if ($reader->moveToAttribute("src")) {
                                                                                                                                                                     $item["rights"]["src"] = $reader->value;
                                                                                                                                                                 }
                                                                                                                                                                 if ($reader->moveToAttribute("type")) {
                                                                                                                                                                     $item["rights"]["type"] = $reader->value;
                                                                                                                                                                 }
                                                                                                                                                                 $reader->read();
                                                                                                                                                                 $item["rights"]["rights"] = $reader->value;
                                                                                                                                                             } else {
                                                                                                                                                                 if ($name == "link" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                     $itemLinks++;
                                                                                                                                                                     foreach ($this->linkAttributes as $latt2) {
                                                                                                                                                                         if ($reader->moveToAttribute("{$latt2}")) {
                                                                                                                                                                             $item["links"]["{$itemLinks}"]["{$latt2}"] = $reader->value;
                                                                                                                                                                             $item["link"] = $item["links"][0]["href"];
                                                                                                                                                                         }
                                                                                                                                                                     }
                                                                                                                                                                 } else {
                                                                                                                                                                     if ($name == "category" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                         $itemCategories++;
                                                                                                                                                                         foreach ($this->categoryAttributes as $catt) {
                                                                                                                                                                             if ($reader->moveToAttribute("{$catt}")) {
                                                                                                                                                                                 $item["categories"]["{$itemCategories}"]["{$catt}"] = $reader->value;
                                                                                                                                                                             }
                                                                                                                                                                         }
                                                                                                                                                                     } else {
                                                                                                                                                                         if ($name == "contributor" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                             $isInContributor = 1;
                                                                                                                                                                             $contributor = array();
                                                                                                                                                                         } else {
                                                                                                                                                                             if (in_array($name, $this->authorElements) && $reader->nodeType == 1 && $isInContributor && $isAtom) {
                                                                                                                                                                                 $reader->read();
                                                                                                                                                                                 $contributor["{$name}"] = $reader->value;
                                                                                                                                                                             } else {
                                                                                                                                                                                 if ($name == "contributor" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                                                                     $isInContributor = 0;
                                                                                                                                                                                     array_push($this->contributors, $contributor);
                                                                                                                                                                                     $item["contributors"] = $this->contributors;
                                                                                                                                                                                 } else {
                                                                                                                                                                                     if ($name == "source" && $reader->nodeType == 1 && $isAtom) {
                                                                                                                                                                                         $isInSource = 1;
                                                                                                                                                                                     } else {
                                                                                                                                                                                         if ($name == "source" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                                                                             $isInSource = 0;
                                                                                                                                                                                         } else {
                                                                                                                                                                                             if ($name == "summary" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                                                 if ($reader->moveToAttribute("src")) {
                                                                                                                                                                                                     $item["sourceAttributes"]["src"] = $reader->value;
                                                                                                                                                                                                 }
                                                                                                                                                                                                 if ($reader->moveToAttribute("type")) {
                                                                                                                                                                                                     $item["sourceAttributes"]["type"] = $reader->value;
                                                                                                                                                                                                 }
                                                                                                                                                                                                 $reader->read();
                                                                                                                                                                                                 $summary = $reader->value;
                                                                                                                                                                                                 if ($this->strip) {
                                                                                                                                                                                                     $newSummary = preg_replace("/<.+?>/", "", $summary);
                                                                                                                                                                                                 } else {
                                                                                                                                                                                                     $newSummary = $summary;
                                                                                                                                                                                                 }
                                                                                                                                                                                                 $item["source"] = $newSummary;
                                                                                                                                                                                             } else {
                                                                                                                                                                                                 if ($name == "content" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                                                                     $isInDescription = 1;
                                                                                                                                                                                                     if ($reader->moveToAttribute("src")) {
                                                                                                                                                                                                         $item["contentAttributes"]["src"] = $reader->value;
                                                                                                                                                                                                     }
                                                                                                                                                                                                     if ($reader->moveToAttribute("type")) {
                                                                                                                                                                                                         $item["contentAttributes"]["type"] = $reader->value;
                                                                                                                                                                                                     }
                                                                                                                                                                                                     $reader->read();
                                                                                                                                                                                                     $content = $reader->value;
                                                                                                                                                                                                     if ($this->strip) {
                                                                                                                                                                                                         $newContent = preg_replace("/<.+?>/", "", $content);
                                                                                                                                                                                                     } else {
                                                                                                                                                                                                         $newContent = $content;
                                                                                                                                                                                                     }
                                                                                                                                                                                                     $item["content"] = $newContent;
                                                                                                                                                                                                     $item["description"] = $newContent;
                                                                                                                                                                                                 } else {
                                                                                                                                                                                                     if ($name == "content" && $reader->nodeType == 15 && $isInItem && $isAtom) {
                                                                                                                                                                                                         $isInDescription = 0;
                                                                                                                                                                                                     } else {
                                                                                                                                                                                                         if ($reader->nodeType == 4 && $isInDescription) {
                                                                                                                                                                                                             $cdata = $reader->value;
                                                                                                                                                                                                             if ($this->strip) {
                                                                                                                                                                                                                 $cdata = preg_replace("/<.+?>/", "", $cdata);
                                                                                                                                                                                                             }
                                                                                                                                                                                                             $item["content"] = $cdata;
                                                                                                                                                                                                             $item["description"] = $item["content"];
                                                                                                                                                                                                         }
                                                                                                                                                                                                     }
                                                                                                                                                                                                 }
                                                                                                                                                                                             }
                                                                                                                                                                                         }
                                                                                                                                                                                     }
                                                                                                                                                                                 }
                                                                                                                                                                             }
                                                                                                                                                                         }
                                                                                                                                                                     }
                                                                                                                                                                 }
                                                                                                                                                             }
                                                                                                                                                         }
                                                                                                                                                     }
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         }
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $reader->close;
     }
 }
Beispiel #6
0
 if ($reader->nodeType != XMLREADER::END_ELEMENT) {
     if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
         $attr = $reader->moveToFirstAttribute();
         echo $reader->name . ": ";
         echo $reader->value . "\n";
         if ($reader->getAttribute($reader->name) == $reader->value) {
             echo "1st attr (num) failed\n";
         }
         $attr = $reader->moveToNextAttribute();
         echo $reader->name . ": ";
         echo $reader->value . "\n";
         if ($reader->getAttribute($reader->name) == $reader->value) {
             echo "2nd attr (idx) failed\n";
         }
         // Named attribute
         $attr = $reader->moveToAttribute('num');
         echo $reader->name . ": ";
         echo $reader->value . "\n";
         if ($reader->getAttribute('num') == $reader->value) {
             echo "attr num failed\n";
         }
         $attr = $reader->moveToAttribute('idx');
         echo $reader->name . ": ";
         echo $reader->value . "\n";
         if ($reader->getAttribute('idx') == $reader->value) {
             echo "attr idx failed\n";
         }
         // Numeric positions of attributes
         $attr = $reader->moveToAttributeNo(0);
         echo $reader->name . ": ";
         echo $reader->value . "\n";
Beispiel #7
0
 public static function generateVersionInfo($filename)
 {
     static $info;
     if ($info) {
         return $info;
     }
     $r = new \XMLReader();
     if (!$r->open($filename)) {
         throw new \Exception();
     }
     $versions = array();
     while ($r->read()) {
         if ($r->moveToAttribute('name') && ($funcname = str_replace(array('::', '->', '__', '_', '$'), array('-', '-', '-', '-', ''), $r->value)) && $r->moveToAttribute('from') && ($from = $r->value)) {
             $versions[strtolower($funcname)] = $from;
             $r->moveToElement();
         }
     }
     $r->close();
     $info = $versions;
     return $versions;
 }
Beispiel #8
0
}
if (file_exists($uploadfile)) {
    $reader = new XMLReader();
    $reader->open($uploadfile);
    echo "<p align=\"center\"><b>XML file successfully opened.</b></p>";
} else {
    echo "<p align=\"center\"><b>Failed to open the xml file.</b></p>";
    exit;
}
echo "<hr>";
include '../main/config.php';
require_once 'DB.php';
$db = DB::connect("mysql://{$dbuser}:{$dbpass}@{$dbhost}/{$dbname}");
while ($reader->read()) {
    if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "XmlReport") {
        $reader->moveToAttribute('Name');
        $XmlReport_Name = mysql_prep($reader->value);
    }
    /*--------------------------------------------------------------------------
    		SUMMARY
    --------------------------------------------------------------------------*/
    if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "Summary") {
        $isSummary = "true";
    }
    if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "TotalIssues" && $isSummary == "true") {
        $reader->read();
        $TotalIssues = mysql_prep($reader->value);
    }
    if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == "TotalVariants" && $isSummary == "true") {
        $reader->read();
        $TotalVariants = mysql_prep($reader->value);
Beispiel #9
0
 protected static function generateDeprecatedInfo($filename)
 {
     static $info;
     if ($info) {
         return $info;
     }
     if (!is_file($filename)) {
         v("Can't find Version information file (%s), skipping!", $filename, E_USER_WARNING);
         return array();
     }
     $r = new \XMLReader();
     if (!$r->open($filename)) {
         v("Can't open the version info file (%s)", $filename, E_USER_ERROR);
     }
     $deprecated = array();
     while ($r->read()) {
         if ($r->moveToAttribute("name") && ($funcname = str_replace(array("::", "->", "__", "_", '$'), array("_", "_", "_", "_", ""), $r->value)) && $r->moveToAttribute("deprecated") && ($value = $r->value)) {
             $deprecated[strtolower($funcname)] = $value;
             $r->moveToElement();
         }
     }
     $r->close();
     $info = $deprecated;
     return $deprecated;
 }
<?php

$reader = new XMLReader();
$reader->XML($catalog);
/* Loop through document */
while ($reader->read()) {
    /* If you're at an element named 'book' */
    if ($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'book') {
        $reader->moveToAttribute('isbn');
        print $reader->value . "\n";
    }
}
Beispiel #11
0
 function parse($source)
 {
     if (!$this->report) {
         error_reporting(0);
     }
     if (!is_null($this->returns)) {
         $returns = $this->returns;
     } else {
         $returns = 12;
     }
     $feedLinks = -1;
     $feedCategories = -1;
     $feedAuthorsCount = -1;
     $itemLinks = -1;
     $itemCategories = -1;
     $reader = new XMLReader();
     $cachedCopy = "pgcache/" . urlencode($source);
     if (file_exists($cachedCopy)) {
         $cacheTime = filemtime($cachedCopy);
         $now = time();
         $age = $now - $cacheTime;
     }
     if (file_exists($cachedCopy) && $this->cache && $age > $this->cache || !file_exists($cachedCopy)) {
         try {
             PGFeed::checkSource($source);
         } catch (Exception $e) {
             if ($this->report) {
                 echo 'Message: ' . $e->getMessage();
             }
             die;
         }
         if ($this->cache) {
             PGFeed::cacheFeed($source);
         }
         $reader->open($source);
     } else {
         $cachedContents = file_get_contents($cachedCopy);
         $reader->XML($cachedContents);
     }
     while ($reader->read()) {
         $name = $reader->name;
         if ($name == "feed" && $reader->nodeType == 1) {
             $isAtom = 1;
         } else {
             if (in_array("{$name}", $this->channelElements) && $reader->nodeType == 1 && !$isInItem && !$isInImage && !$isAtom) {
                 $reader->read();
                 $this->channel["{$name}"] = $reader->value;
             } else {
                 if ($name == "cloud" && $reader->nodeType == 1 && !$isAtom) {
                     foreach ($this->cloudAttributes as $att) {
                         if ($reader->moveToAttribute("{$att}")) {
                             $this->channel["cloud"]["{$att}"] = $reader->value;
                         }
                     }
                 } else {
                     if ($name == "image" && $reader->nodeType == 1 && !$isAtom) {
                         $isInImage = 1;
                     } else {
                         if ($name == "image" && $reader->nodeType == 15 && !$isAtom) {
                             $isInImage = 0;
                         } else {
                             if (in_array("{$name}", $this->imageElements) && $reader->nodeType == 1 && $isInImage && !$isAtom) {
                                 $reader->read();
                                 $this->channel["image"]["{$name}"] = $reader->value;
                             } else {
                                 if ($name == "textInput" && $reader->nodeType == 1 && !$isAtom) {
                                     $isInTextInput = 1;
                                 } else {
                                     if ($name == "textInput" && $reader->nodeType == 15 && !$isAtom) {
                                         $isInTextInput = 0;
                                     } else {
                                         if (in_array("{$name}", $this->textInputElements) && $reader->nodeType == 1 && $isInTextInput && !$isAtom) {
                                             $reader->read();
                                             $this->channel["textInput"]["{$name}"] = $reader->value;
                                         } else {
                                             if ($name == "item" && $reader->nodeType == 1 && !$isAtom) {
                                                 $isInItem = 1;
                                                 $itemNumber++;
                                                 $item = array();
                                             } else {
                                                 if (in_array("{$name}", $this->itemElements) && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                     $reader->read();
                                                     $item["{$name}"] = $reader->value;
                                                 } else {
                                                     if ($name == "description" && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                         $isInDescription = 1;
                                                         $reader->read();
                                                         $description = $reader->value;
                                                         if ($this->strip) {
                                                             $newDescription = preg_replace("/<.+?>/", "", $description);
                                                         } else {
                                                             $newDescription = $description;
                                                         }
                                                         $item["description"] = $newDescription;
                                                     } else {
                                                         if ($name == "description" && $reader->nodeType == 15) {
                                                             $isInDescription = 0;
                                                         } else {
                                                             if ($name == "enclosure" && $reader->nodeType == 1 && $isInItem && !$isAtom) {
                                                                 foreach ($this->enclosureAttributes as $enatt) {
                                                                     if ($reader->moveToAttribute("{$enatt}")) {
                                                                         $item["enclosure"]["{$enatt}"] = $reader->value;
                                                                     }
                                                                 }
                                                             } else {
                                                                 if ($name == "item" && $reader->nodeType == 15 && !$isAtom) {
                                                                     $isInItem = 0;
                                                                     if ($itemNumber <= $returns) {
                                                                         array_push($this->items, $item);
                                                                     }
                                                                 } else {
                                                                     if (in_array("{$name}", $this->feedElements) && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                         $reader->read();
                                                                         $this->channel["{$name}"] = $reader->value;
                                                                     } else {
                                                                         if ($name == "title" && $reader->nodeType == 1 && !$isInSource && $isAtom) {
                                                                             if ($reader->moveToAttribute("type")) {
                                                                                 if ($isInItem) {
                                                                                     $item["titleAttributes"]["type"] = $reader->value;
                                                                                 } else {
                                                                                     $this->channel["titleAttributes"]["type"] = $reader->value;
                                                                                 }
                                                                             }
                                                                             $reader->read();
                                                                             if ($isInItem) {
                                                                                 $item["title"] = $reader->value;
                                                                             } else {
                                                                                 $this->channel["title"] = $reader->value;
                                                                             }
                                                                         } else {
                                                                             if ($name == "link" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                 $feedLinks++;
                                                                                 foreach ($this->linkAttributes as $latt) {
                                                                                     if ($reader->moveToAttribute("{$latt}")) {
                                                                                         $this->channel["links"]["{$feedLinks}"]["{$latt}"] = $reader->value;
                                                                                     }
                                                                                 }
                                                                             } else {
                                                                                 if ($name == "generator" && $reader->nodeType == 1 && $isAtom) {
                                                                                     $reader->moveToAttribute("uri");
                                                                                     $this->channel["generatorURI"] = $reader->value;
                                                                                     $this->channel["link"] = $reader->value;
                                                                                     $reader->read();
                                                                                     $this->channel["{$name}"] = $reader->value;
                                                                                 } else {
                                                                                     if ($name == "author" && $reader->nodeType == 1 && $isAtom) {
                                                                                         $isInAuthor = 1;
                                                                                         $author = array();
                                                                                     } else {
                                                                                         if (in_array($name, $this->authorElements) && $reader->nodeType == 1 && $isInAuthor && $isAtom) {
                                                                                             $reader->read();
                                                                                             $author["{$name}"] = $reader->value;
                                                                                         } else {
                                                                                             if ($name == "author" && $reader->nodeType == 15 && $isAtom) {
                                                                                                 $isInAuthor = 0;
                                                                                                 if ($isInItem) {
                                                                                                     array_push($this->authors, $author);
                                                                                                     $item["authors"] = $this->authors;
                                                                                                     $this->authors = array();
                                                                                                 } else {
                                                                                                     array_push($this->feedAuthors, $author);
                                                                                                     $this->channel["authors"] = $this->feedAuthors;
                                                                                                 }
                                                                                             } else {
                                                                                                 if ($name == "category" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                     $feedCategories++;
                                                                                                     foreach ($this->categoryAttributes as $cat) {
                                                                                                         if ($reader->moveToAttribute("{$cat}")) {
                                                                                                             $this->channel["categories"]["{$feedCategories}"]["{$cat}"] = $reader->value;
                                                                                                         }
                                                                                                     }
                                                                                                 } else {
                                                                                                     if ($name == "rights" && $reader->nodeType == 1 && !$isInItem && $isAtom) {
                                                                                                         if ($reader->moveToAttribute("src")) {
                                                                                                             $this->channel["rights"]["src"] = $reader->value;
                                                                                                         }
                                                                                                         if ($reader->moveToAttribute("type")) {
                                                                                                             $this->channel["rights"]["type"] = $reader->value;
                                                                                                         }
                                                                                                         $reader->read();
                                                                                                         $this->channel["rights"]["rights"] = $reader->value;
                                                                                                     } else {
                                                                                                         if ($name == "entry" && $reader->nodeType == 1 && $isAtom) {
                                                                                                             $isInItem = 1;
                                                                                                             $item = array();
                                                                                                             $itemNumber++;
                                                                                                             $itemLinks = -1;
                                                                                                             $itemCategories = -1;
                                                                                                         } else {
                                                                                                             if ($name == "entry" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                 $isInItem = 0;
                                                                                                                 if ($itemNumber <= $returns) {
                                                                                                                     array_push($this->items, $item);
                                                                                                                 }
                                                                                                                 $authors = array();
                                                                                                             } else {
                                                                                                                 if (in_array("{$name}", $this->entryElements) && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                     $reader->read();
                                                                                                                     $item["{$name}"] = $reader->value;
                                                                                                                 } else {
                                                                                                                     if ($name == "rights" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                         if ($reader->moveToAttribute("src")) {
                                                                                                                             $item["rights"]["src"] = $reader->value;
                                                                                                                         }
                                                                                                                         if ($reader->moveToAttribute("type")) {
                                                                                                                             $item["rights"]["type"] = $reader->value;
                                                                                                                         }
                                                                                                                         $reader->read();
                                                                                                                         $item["rights"]["rights"] = $reader->value;
                                                                                                                     } else {
                                                                                                                         if ($name == "link" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                             $itemLinks++;
                                                                                                                             foreach ($this->linkAttributes as $latt2) {
                                                                                                                                 if ($reader->moveToAttribute("{$latt2}")) {
                                                                                                                                     $item["links"]["{$itemLinks}"]["{$latt2}"] = $reader->value;
                                                                                                                                     $item["link"] = $item["links"][0]["href"];
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         } else {
                                                                                                                             if ($name == "category" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                 $itemCategories++;
                                                                                                                                 foreach ($this->categoryAttributes as $catt) {
                                                                                                                                     if ($reader->moveToAttribute("{$catt}")) {
                                                                                                                                         $item["categories"]["{$itemCategories}"]["{$catt}"] = $reader->value;
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             } else {
                                                                                                                                 if ($name == "contributor" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                     $isInContributor = 1;
                                                                                                                                     $contributor = array();
                                                                                                                                 } else {
                                                                                                                                     if (in_array($name, $this->authorElements) && $reader->nodeType == 1 && $isInContributor && $isAtom) {
                                                                                                                                         $reader->read();
                                                                                                                                         $contributor["{$name}"] = $reader->value;
                                                                                                                                     } else {
                                                                                                                                         if ($name == "contributor" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                             $isInContributor = 0;
                                                                                                                                             array_push($this->contributors, $contributor);
                                                                                                                                             $item["contributors"] = $this->contributors;
                                                                                                                                         } else {
                                                                                                                                             if ($name == "source" && $reader->nodeType == 1 && $isAtom) {
                                                                                                                                                 $isInSource = 1;
                                                                                                                                             } else {
                                                                                                                                                 if ($name == "source" && $reader->nodeType == 15 && $isAtom) {
                                                                                                                                                     $isInSource = 0;
                                                                                                                                                 } else {
                                                                                                                                                     if ($name == "summary" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                         if ($reader->moveToAttribute("src")) {
                                                                                                                                                             $item["sourceAttributes"]["src"] = $reader->value;
                                                                                                                                                         }
                                                                                                                                                         if ($reader->moveToAttribute("type")) {
                                                                                                                                                             $item["sourceAttributes"]["type"] = $reader->value;
                                                                                                                                                         }
                                                                                                                                                         $reader->read();
                                                                                                                                                         $summary = $reader->value;
                                                                                                                                                         if ($this->strip) {
                                                                                                                                                             $newSummary = preg_replace("/<.+?>/", "", $summary);
                                                                                                                                                         } else {
                                                                                                                                                             $newSummary = $summary;
                                                                                                                                                         }
                                                                                                                                                         $item["source"] = $newSummary;
                                                                                                                                                     } else {
                                                                                                                                                         if ($name == "content" && $reader->nodeType == 1 && $isInItem && $isAtom) {
                                                                                                                                                             $isInDescription = 1;
                                                                                                                                                             if ($reader->moveToAttribute("src")) {
                                                                                                                                                                 $item["contentAttributes"]["src"] = $reader->value;
                                                                                                                                                             }
                                                                                                                                                             if ($reader->moveToAttribute("type")) {
                                                                                                                                                                 $item["contentAttributes"]["type"] = $reader->value;
                                                                                                                                                             }
                                                                                                                                                             $reader->read();
                                                                                                                                                             $content = $reader->value;
                                                                                                                                                             if ($this->strip) {
                                                                                                                                                                 $newContent = preg_replace("/<.+?>/", "", $content);
                                                                                                                                                             } else {
                                                                                                                                                                 $newContent = $content;
                                                                                                                                                             }
                                                                                                                                                             $item["content"] = $newContent;
                                                                                                                                                             $item["description"] = $newContent;
                                                                                                                                                         } else {
                                                                                                                                                             if ($name == "content" && $reader->nodeType == 15 && $isInItem && $isAtom) {
                                                                                                                                                                 $isInDescription = 0;
                                                                                                                                                             } else {
                                                                                                                                                                 if ($reader->nodeType == 4 && $isInDescription) {
                                                                                                                                                                     $cdata = $reader->value;
                                                                                                                                                                     if ($this->strip) {
                                                                                                                                                                         $cdata = preg_replace("/<.+?>/", "", $cdata);
                                                                                                                                                                     }
                                                                                                                                                                     $item["content"] = $cdata;
                                                                                                                                                                     $item["description"] = $item["content"];
                                                                                                                                                                 }
                                                                                                                                                             }
                                                                                                                                                         }
                                                                                                                                                     }
                                                                                                                                                 }
                                                                                                                                             }
                                                                                                                                         }
                                                                                                                                     }
                                                                                                                                 }
                                                                                                                             }
                                                                                                                         }
                                                                                                                     }
                                                                                                                 }
                                                                                                             }
                                                                                                         }
                                                                                                     }
                                                                                                 }
                                                                                             }
                                                                                         }
                                                                                     }
                                                                                 }
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $reader->close;
     }
 }
$reader = new XMLReader();
$reader->XML($catalog);
// Perl Cookbook ISBN is 0596003137
// Use array to make it easy to add additional ISBNs
$isbns = array('0596003137' => true);
/* Loop through document to find first <book> */
while ($reader->read()) {
    /* If you're at an element named 'book' */
    if ($reader->nodeType == XMLREADER::ELEMENT && $reader->localName == 'book') {
        break;
    }
}
/* Loop through <book>s to find right ISBNs */
do {
    if ($reader->moveToAttribute('isbn') && isset($isbns[$reader->value])) {
        while ($reader->read()) {
            switch ($reader->nodeType) {
                case XMLREADER::ELEMENT:
                    print $reader->localName . ": ";
                    break;
                case XMLREADER::TEXT:
                    print $reader->value . "\n";
                    break;
                case XMLREADER::END_ELEMENT:
                    if ($reader->localName == 'book') {
                        break 2;
                    }
            }
        }
    }
Beispiel #13
0
 public function moveToAttribute($name)
 {
     return parent::moveToAttribute($name);
 }