+

Last commit for functions.php: b21ea0944bb04230d9c0acab56d83a22e9c5e6e8

Initial commit

Benjamin Renard [2015-01-04 23:39:08]
Initial commit
  1. <?php
  2.  
  3. function day2int($day,$inv=false) {
  4. $days=array(
  5. 'lun' => 1,
  6. 'mar' => 2,
  7. 'mer' => 3,
  8. 'jeu' => 4,
  9. 'ven' => 5,
  10. 'sam' => 6,
  11. 'dim' => 7,
  12. );
  13. if ($inv) {
  14. foreach($days as $d => $i) if ($day==$i) return $d;
  15. return false;
  16. }
  17. else {
  18. return (isset($days[$day])?$days[$day]:false);
  19. }
  20. }
  21.  
  22. function group_days($movies) {
  23. $ret=array();
  24. foreach($movies as $m => $days) {
  25. //echo $m."\n";
  26. $times=array();
  27. $ret[$m]=array();
  28. foreach ($days as $d => $hs) {
  29. foreach ($hs as $h) {
  30. if (!isset($times[$h])) {
  31. $times[$h]=array();
  32. }
  33. $times[$h][]=$d;
  34. }
  35. }
  36. foreach($times as $h => $days) {
  37. $f=null;
  38. $l=null;
  39. $ps=array();
  40. //echo "$m - $h : ".implode('-',$days)."\n";
  41. foreach(array(3,4,5,6,7,1,2,0) as $d) {
  42. $day=day2int($d,1);
  43. //echo "$h : $day ?\n";
  44. if (in_array($day,$days)) {
  45. if ($f==null) {
  46. //echo "$h : debut $day\n";
  47. $f=$day;
  48. }
  49. //else echo "$day : on continue\n";
  50. $prev=$day;
  51. }
  52. elseif ($f!=null) {
  53. //echo "$h : fin $prev\n";
  54. $l=$prev;
  55. if ($f==$l) $ps[]=$f; else $ps[]="$f-$l";
  56. $f=null;
  57. $l=null;
  58. }
  59. }
  60. //echo "$m - $h => ".implode('&',$ps)."\n";
  61. foreach($ps as $p) {
  62. if (!isset($ret[$m][$p])) {
  63. $ret[$m][$p]=array();
  64. }
  65. $ret[$m][$p][]=$h;
  66. }
  67. }
  68. }
  69. return $ret;
  70. }
  71.  
  72. function withoutAccents($string){
  73. $replaceAccent = Array(
  74. "à" => "a",
  75. "á" => "a",
  76. "â" => "a",
  77. "ã" => "a",
  78. "ä" => "a",
  79. "ç" => "c",
  80. "è" => "e",
  81. "é" => "e",
  82. "ê" => "e",
  83. "ë" => "e",
  84. "ì" => "i",
  85. "í" => "i",
  86. "î" => "i",
  87. "ï" => "i",
  88. "ñ" => "n",
  89. "ò" => "o",
  90. "ó" => "o",
  91. "ô" => "o",
  92. "õ" => "o",
  93. "ö" => "o",
  94. "ù" => "u",
  95. "ú" => "u",
  96. "û" => "u",
  97. "ü" => "u",
  98. "ý" => "y",
  99. "ÿ" => "y",
  100. "À" => "A",
  101. "Á" => "A",
  102. "Â" => "A",
  103. "Ã" => "A",
  104. "Ä" => "A",
  105. "Ç" => "C",
  106. "È" => "E",
  107. "É" => "E",
  108. "Ê" => "E",
  109. "Ë" => "E",
  110. "Ì" => "I",
  111. "Í" => "I",
  112. "Î" => "I",
  113. "Ï" => "I",
  114. "Ñ" => "N",
  115. "Ò" => "O",
  116. "Ó" => "O",
  117. "Ô" => "O",
  118. "Õ" => "O",
  119. "Ö" => "O",
  120. "Ù" => "U",
  121. "Ú" => "U",
  122. "Û" => "U",
  123. "Ü" => "U",
  124. "Ý" => "Y"
  125. );
  126. return strtr($string, $replaceAccent);
  127. }