utile.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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. // Number of month by name
  26. $monthnum = array(
  27. "Ianuarie" => "1",
  28. "Februarie" => "2",
  29. "Martie" => "3",
  30. "Aprilie" => "4",
  31. "Mai" => "5",
  32. "Iunie" => "6",
  33. "Iulie" => "7",
  34. "August" => "8",
  35. "Septembrie" => "9",
  36. "Octombrie" => "10",
  37. "Noiembrie" => "11",
  38. "Decembrie" => "12",
  39. );
  40. // Name of month by number
  41. $monthname = array(
  42. "01" => "ianuarie",
  43. "02" => "februarie",
  44. "03" => "martie",
  45. "04" => "aprilie",
  46. "05" => "mai",
  47. "06" => "iunie",
  48. "07" => "iulie",
  49. "08" => "august",
  50. "09" => "septembrie",
  51. "10" => "octombrie",
  52. "11" => "noiembrie",
  53. "12" => "decembrie",
  54. );
  55. // Name of month (1-2 digits) by number
  56. $monthname1 = array(
  57. "1" => "ianuarie",
  58. "2" => "februarie",
  59. "3" => "martie",
  60. "4" => "aprilie",
  61. "5" => "mai",
  62. "6" => "iunie",
  63. "7" => "iulie",
  64. "8" => "august",
  65. "9" => "septembrie",
  66. "10" => "octombrie",
  67. "11" => "noiembrie",
  68. "12" => "decembrie",
  69. );
  70. // Translate months from English to Romanian
  71. $monthtrans = array(
  72. "January" => "ianuarie",
  73. "February" => "februarie",
  74. "March" => "martie",
  75. "April" => "aprilie",
  76. "May" => "mai",
  77. "June" => "iunie",
  78. "July" => "iulie",
  79. "August" => "august",
  80. "September" => "septembrie",
  81. "October" => "octombrie",
  82. "November" => "noiembrie",
  83. "December" => "decembrie",
  84. );
  85. // Abbreviated months in Romanian
  86. $monthabr = array(
  87. "ianuarie" => "ian.",
  88. "februarie" => "feb.",
  89. "martie" => "mart.",
  90. "aprilie" => "apr.",
  91. "mai" => "mai",
  92. "iunie" => "iun.",
  93. "iulie" => "iul.",
  94. "august" => "aug.",
  95. "septembrie" => "sept.",
  96. "octombrie" => "oct.",
  97. "noiembrie" => "nov.",
  98. "decembrie" => "dec.",
  99. );
  100. function transformă($rss_file, $xsl_file, $res_file)
  101. {
  102. $xml = new DOMDocument();
  103. $xml->load($rss_file);
  104. $xsl = new DOMDocument();
  105. $xsl->load($xsl_file);
  106. $proc = new XSLTProcessor();
  107. $proc->importStylesheet($xsl);
  108. $res = $proc->transformToXML($xml);
  109. $file = fopen($res_file, "w");
  110. fwrite($file, $res);
  111. fclose($file);
  112. }
  113. function cuEtichetă($tag, $value)
  114. {
  115. return '<'.$tag.'>'.$value.'</'.$tag.'>'.PHP_EOL;
  116. }
  117. function extrageNumele($str)
  118. {
  119. return strtok($str, " ");
  120. }
  121. function extragePrenumele($str)
  122. {
  123. $surname = strtok($str, " ");
  124. $gnames = substr($str, strlen($surname)+1);
  125. return $gnames;
  126. }
  127. function inverseazăNumele($str)
  128. {
  129. $surname = strtok($str, " ");
  130. $gnames = substr($str, strlen($surname)+1);
  131. $str = $gnames.' '.$surname;
  132. return $str;
  133. }
  134. function fărăDiacritice($str)
  135. {
  136. $str = utf8_decode($str);
  137. $str = str_replace("ă", "a", $str);
  138. $str = str_replace("Ă", "a", $str);
  139. $str = str_replace("â", "a", $str);
  140. $str = str_replace("Â", "a", $str);
  141. $str = str_replace("î", "i", $str);
  142. $str = str_replace("Î", "i", $str);
  143. $str = str_replace("ş", "s", $str);
  144. $str = str_replace("Ş", "s", $str);
  145. $str = str_replace("ș", "s", $str);
  146. $str = str_replace("Ș", "s", $str);
  147. $str = str_replace("ţ", "t", $str);
  148. $str = str_replace("ț", "ț", $str);
  149. $str = str_replace("Ţ", "t", $str);
  150. return $str;
  151. }
  152. function cuDiacriticeCorecte($str)
  153. {
  154. $str = utf8_decode($str);
  155. $str = str_replace("ş", "ș", $str);
  156. $str = str_replace("Ş", "Ș", $str);
  157. $str = str_replace("ţ", "ț", $str);
  158. $str = str_replace("Ţ", "Ț", $str);
  159. return $str;
  160. }
  161. function cuLiniuță($str)
  162. {
  163. $str = str_replace(" - ", "-", $str);
  164. $str = str_replace(" – ", "-", $str);
  165. $str = str_replace(" -", "-", $str);
  166. return $str;
  167. }
  168. function fărăPunctuație($str)
  169. {
  170. $str = str_replace("-", "", $str);
  171. $str = str_replace(".", "", $str);
  172. return $str;
  173. }
  174. ?>