<?php /* يَستخدم ملف تحويل XSLT لإنتاج ملف Atom بناء على بيانات في صيغة XML تمثل نتائج بحث عن محتوى منشور في أرشيف الإنترنت archive.org حقوق الطبع محفوظة: أحمد غربية، مارس 2009 منشور برخصة جنو العمومية، الإصدارة الثالثة Uses an XSLT to produce an Atom feed file from a sarch result in XML retrieved from archive.org Copyright Ahmad Gharbeia, March 2009 Published under a GNU Pulic License version 3 (GPLv3) */ $xml_dataset_URL = 'http://www.archive.org/advancedsearch.php?q=subject%3A%22%D8%A7%D9%84%D8%A8%D8%B1%D9%86%D8%A7%D9%85%D8%AC+%D8%A7%D9%84%D8%AB%D8%A7%D9%86%D9%8A%22+AND+mediatype%3Aaudio+AND+uploader%3Aagharbeia&fl[]=identifier&fl[]=title&fl[]=description&fl[]=creator&fl[]=oai_updatedate&fl[]=publicdate&fl[]=subject&sort[]=publicdate+desc&sort[]=&sort[]=&rows=50&save=yes&fmt=xml&xmlsearch=Search'; $xml_dataset_cache_path = 'search_result.xml'; $atom_path = 'atom.xml'; $xsl_path = 'atom.xsl'; $xml_date_xpath = '/response/result/doc[position()=1]/arr[@name="oai_updatedate"]/date[last()]'; $atom_date_xpath = '/atom:feed/atom:entry[position()=1]/atom:updated'; function latest_public_date(DOMDocument $xml, $xpath) { $domxpath = new DOMXPath($xml); $domxpath->registerNamespace('atom', 'http://www.w3.org/2005/Atom'); } try { $search = new DOMDocument(); if ($search->load($xml_dataset_URL)) { echo "Loaded search from result: {$xml_dataset_URL}<br />"; $latest_in_xml = latest_public_date($search, $xml_date_xpath); $atom = new DOMDocument(); if ((($atom_exists = $atom->load($atom_path)) === false) || ($latest_in_xml > ($latest_in_atom = latest_public_date($atom, $atom_date_xpath)))) { echo (!$atom_exists?"No current feed":"search result has updated items") . "<br />"; if (($cachedsize = $search->save($xml_dataset_cache_path)) !== false) { echo "Search result cached to: {$xml_dataset_cache_path}; {$cachedsize} bytes writ.<br />"; } else { echo "Saving cache file failed!<br />"; } $xslt = new XSLTProcessor(); $xslt->importStyleSheet(DOMDocument::load($xsl_path)); if (($atom = $xslt->transformToDoc($search)) !== false) { echo "XML transformed into Atom using: {$xsl_path}<br />"; if (($atomsize = $atom->save($atom_path)) !== false) { echo "Atom saved to: {$atom_path}; {$atomsize} bytes writ.<br />"; } else { echo "Saving Atom file failed!<br />"; } } else { echo "Transformation faild!<br />"; } } else { echo "There was a feed AND there were no newer items in search result<br />"; } } else { echo "Couldn't retrieve search results<br />"; } echo "Done."; } catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "<br />"; } ?>
هذا الكود المصدري منشور في موقع أحمد غربية.
This source code listing is published in the web site of Ahmad Gharbeia.