obține-htmluri-din-fluxuri.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * File name: ordonează-fluxul-după-dată.php
  4. * Sort an RSS feed by pubDate
  5. *
  6. * (C) Copyright 2013 Friedrich-Ebert-Stiftung (http://fes.ro)
  7. * Author: Tiberiu C. Turbureanu (tct@ceata.org)
  8. *
  9. * This file is part of the project funded by FES
  10. *
  11. * This is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. require_once 'utile.php';
  26. // Load the list of persons
  27. $persons = array();
  28. $xmla = new DOMDocument();
  29. $xmla->load('../20131013-consilieri.xml');
  30. $xpatha = new DOMXpath($xmla);
  31. $persons = $xpatha->query("/xml/person");
  32. foreach($persons as $person)
  33. {
  34. $comname = $xpatha->query("comname", $person)->item(0)->nodeValue;
  35. $surname = $xpatha->query("surname", $person)->item(0)->nodeValue;
  36. $rss_file = '../fluxuri/02-teste/'.$comname.'-'.$surname.'.xml';
  37. $xsl_file = '../stiluri/html-din-flux.xsl';
  38. $res_file = '../consilieri/știri/'.$comname.'-'.$surname.'.html';
  39. transformă($rss_file, $xsl_file, $res_file);
  40. $xml = new DOMDocument();
  41. $xml->load($res_file);
  42. $xpath = new DOMXpath($xml);
  43. $dates = $xpath->query('//td[@class="data"]');
  44. if ($dates->length > 0)
  45. {
  46. foreach($dates as $date)
  47. {
  48. $iso = $date->nodeValue;
  49. $match = "";
  50. $nice = trim(strftime("%e %B %Y", strtotime($iso)));
  51. preg_match('/[a-zA-Z]+/', $nice, $match);
  52. $month = $match[0];
  53. $month = $monthabr[$monthtrans[$month]];
  54. $nice = preg_replace('/[a-zA-Z]+/', $month, $nice);
  55. $date->nodeValue = $nice;
  56. }
  57. $xml->save($res_file);
  58. }
  59. }
  60. ?>