class.xblog.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. # ***** BEGIN LICENSE BLOCK *****
  3. # This file is part of DotClear.
  4. # Copyright (c) 2004 Olivier Meunier and contributors. All rights
  5. # reserved.
  6. #
  7. # DotClear is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # DotClear is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with DotClear; if not, write to the Free Software
  19. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. #
  21. # ***** END LICENSE BLOCK *****
  22. #
  23. # Extension de la classe blog
  24. #
  25. class xblog extends blog
  26. {
  27. var $use_smilies = false;
  28. var $smilies_path = '';
  29. var $smilies_url = '';
  30. function setUseSmilies($v=false)
  31. {
  32. $this->use_smilies = (boolean) $v;
  33. }
  34. function setSmiliesPath($p,$url)
  35. {
  36. $this->smilies_path = $p;
  37. $this->smilies_url = $url;
  38. # Tableau des smilies
  39. $def_path = $this->smilies_path.'/smilies.txt';
  40. if ($this->use_smilies && file_exists($def_path))
  41. {
  42. $def = file($def_path);
  43. $this->arry_smilies = array();
  44. foreach($def as $v)
  45. {
  46. $v = trim($v);
  47. if (preg_match('|^([^\t]*)[\t]+(.*)$|',$v,$matches))
  48. {
  49. $r = '/(\A|[\s]+|>)('.preg_quote($matches[1],'/').')([\s]+|[<]|\Z)/ms';
  50. $s = '$1<img src="'.$this->smilies_url.$matches[2].'" '.
  51. 'alt="$2" class="smiley" />$3';
  52. $this->arry_smilies[$r] = $s;
  53. }
  54. }
  55. }
  56. }
  57. function addSmilies($str)
  58. {
  59. if (!empty($this->arry_smilies) && is_array($this->arry_smilies))
  60. {
  61. return preg_replace(array_keys($this->arry_smilies),array_values($this->arry_smilies),$str);
  62. }
  63. else
  64. {
  65. return $str;
  66. }
  67. }
  68. function xCalendar($year,$month,$day,$cat_id,$lang,
  69. $block='<table summary="calendrier">%s</table>')
  70. {
  71. $arry_months = $GLOBALS['arry_months'];
  72. $comp_url = '';
  73. if ($lang) {
  74. $comp_url .= $lang.'/';
  75. }
  76. if($cat_id) {
  77. $comp_url .= $cat_id.'/';
  78. }
  79. if($month == '' || $year == '') {
  80. $recent = $this->getEarlierDate($cat_id);
  81. $actual_month = date('m',strtotime($recent));
  82. $actual_year = date('Y',strtotime($recent));
  83. } else {
  84. $actual_month = $month;
  85. $actual_year = $year;
  86. }
  87. $days = $this->getAllDates('d',$actual_year,$actual_month,'',$cat_id);
  88. $ts = strtotime($actual_year.'-'.$actual_month.'-01');
  89. $first = date('w',$ts);
  90. $first = ($first == 0) ? 6 : ($first-1);
  91. # Limite de fin du mois
  92. $limit = date('t',$ts);
  93. # Mois suivant / précédent
  94. $link_next = $link_prev = '';
  95. if (($l_next = util::getNextPrev($arry_months,$ts,'prev')) !== NULL) {
  96. $ts_next = key($l_next);
  97. $m_next = date('m',$ts_next);
  98. $y_next = date('Y',$ts_next);
  99. $link_next = ' <a href="'.
  100. sprintf($this->front_url['archive'],$comp_url.$y_next,$m_next).'" '.
  101. ' title="'.dt::str('%B %Y',$ts_next).'">&#187;</a>';
  102. }
  103. if (($l_prev = util::getNextPrev($arry_months,$ts,'next')) !== NULL) {
  104. $ts_prev = key($l_prev);
  105. $m_prev = date('m',$ts_prev);
  106. $y_prev = date('Y',$ts_prev);
  107. $link_prev = '<a href="'.
  108. sprintf($this->front_url['archive'],$comp_url.$y_prev,$m_prev).'" '.
  109. ' title="'.dt::str('%B %Y',$ts_prev).'">&#171;</a> ';
  110. }
  111. $d=1; $i=0; $dstart=false;
  112. $res = "\n<caption>".$link_prev.dt::str('%B %Y',$ts).$link_next.'</caption>';
  113. $res .= '<thead><tr>';
  114. $monday_ts = strtotime('2003-01-06 00:00:00');
  115. $sunday_ts = strtotime('2003-01-12 00:00:00');
  116. for($j=$monday_ts;$j<=$sunday_ts;$j=$j+86400) {
  117. $res .= '<th scope="col"><abbr title="'.dt::str('%A',$j).'">'.
  118. dt::str('%a',$j).'</abbr></th>';
  119. }
  120. $res .= "</tr></thead>\n";
  121. $res .= '<tbody>';
  122. while($i<42)
  123. {
  124. if($i%7 == 0)
  125. $res .= '<tr>';
  126. if($i == $first) {
  127. $dstart = true;
  128. }
  129. if($dstart && !checkdate($actual_month,$d,$actual_year)) {
  130. $dstart = false;
  131. }
  132. if(!empty($days[strtotime($actual_year.'-'.$actual_month.'-'.$d)])) {
  133. $url = sprintf($this->front_url['day'],$comp_url.$actual_year,$actual_month,$d);
  134. $link = '<a href="'.$url.'">%s</a>';
  135. } else {
  136. $link = '%s';
  137. }
  138. $class = ($day == $d && $dstart) ? ' class="active"' : '';
  139. $res .= '<td'.$class.'>';
  140. $res .= ($dstart) ? sprintf($link,$d) : ' ';
  141. $res .= '</td>';
  142. if(($i+1)%7 == 0)
  143. {
  144. $res .= '</tr>'."\n";
  145. if ($d>=$limit) { $i=42; }
  146. }
  147. $i++;
  148. if($dstart) { $d++; }
  149. }
  150. $res .= "</tbody>\n";
  151. return sprintf($block,$res);
  152. }
  153. }
  154. ?>