'', 'items'=>array() ); $file_content = @file_get_contents($filename); if (!$file_content) { $rArray['error'] = 'Unable to fetch or read ' . $filename . ' ON ' . WEBSITE_URL; return $rArray; } // parsing data $doc = new DOMDocument('1.0', 'UTF-8'); if (!@$doc->loadXML($file_content)) { $rArray['error'] = 'Unable to parse '.$filename.' ON ' . WEBSITE_URL; return $rArray; } // // // // (rel = hub, rel = self) // // <gr:continuation /> // <updated /> // <entry gr:crawl-timestamp-msec=""> // <id gr:original-id="">tag... // <title type="html" /> // <published>DATETZ</published> // <updated>DATETZ</published> // <link rel="alternate" href="" type="text/html" /> // <content type="html"></content> // <author gr:unknown-author="true"><name>(author unknown</name></author> // <source gr:stream-id=""><id></id><title type="html"> // $feedElement = $doc->documentElement; if ($feedElement->tagName != 'feed') { $rArray['error'] = 'Invalid first tag ON ' . WEBSITE_URL; return $rArray; } foreach($feedElement->childNodes as $child) { if ($child->nodeType != XML_ELEMENT_NODE) continue; switch($child->tagName) { case 'generator': case 'id': case 'title': case 'gr:continuation': case 'updated': break; case 'link': if ($child->hasAttribute('rel') && $child->getAttribute('rel') == 'self') { if ($child->getAttribute('href') != $filename) { $rArray['error'] = 'Bad self link inside file ON '. WEBSITE_URL; return $rArray; } } break; case 'entry': $data = array('link'=>'', 'content'=>'', 'title'=>'', 'published'=>'', 'updated'=>'', 'id'=>''); foreach($child->childNodes as $entryChild) { if ($entryChild->nodeType != XML_ELEMENT_NODE) { continue; } switch($entryChild->tagName) { case 'author': case 'source': break; case 'id': $data[$entryChild->tagName] = $entryChild->nodeValue; break; case 'updated': case 'published': $data[$entryChild->tagName] = date('Y-m-d H:i:s', strtotime($entryChild->nodeValue)); break; case 'link': if ($entryChild->getAttribute('rel') == 'alternate') { $data['link'] = $entryChild->getAttributE('href'); } break; case 'title': case 'content': $data[$entryChild->tagName] = trim(html_entity_decode(strip_tags($entryChild->nodeValue),ENT_COMPAT,'UTF-8')); break; } } if ($data['link'] != '') { $rArray['items'][] = $data; } break; } } return $rArray; } } ?>