PageRenderTime 49ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/baser/plugins/blog/views/elements/widgets/blog_calendar.php

https://github.com/hashing/basercms
PHP | 198 lines | 143 code | 19 blank | 36 comment | 31 complexity | f576e15f17a2463dd6d3d313ee50e61c MD5 | raw file
Possible License(s): MIT
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * [PUBLISH] ブログカレンダー
  5. *
  6. * PHP versions 5
  7. *
  8. * baserCMS : Based Website Development Project <http://basercms.net>
  9. * Copyright 2008 - 2012, baserCMS Users Community <http://sites.google.com/site/baserusers/>
  10. *
  11. * @copyright Copyright 2008 - 2012, baserCMS Users Community
  12. * @link http://basercms.net baserCMS Project
  13. * @package baser.plugins.blog.views
  14. * @since baserCMS v 0.1.0
  15. * @version $Revision$
  16. * @modifiedby $LastChangedBy$
  17. * @lastmodified $Date$
  18. * @license http://basercms.net/license/index.html
  19. */
  20. if(isset($blogContent)){
  21. $id = $blogContent['BlogContent']['id'];
  22. }else{
  23. $id = $blog_content_id;
  24. }
  25. $url = '/blog/blog/get_calendar/'.$id;
  26. if(!empty($year)){
  27. $url.='/'.$year;
  28. }
  29. if(!empty($month)){
  30. $url.='/'.$month;
  31. }
  32. $data = $this->requestAction($url);
  33. $blogContent = $data['blogContent'];
  34. $entryDates = $data['entryDates'];
  35. ?>
  36. <?php // TODO コード整理する事 ?>
  37. <div class="widget widget-blog-calendar widget-blog-calendar-<?php echo $id ?> blog-widget">
  38. <?php if($name && $use_title): ?>
  39. <h2><?php echo $name ?></h2>
  40. <?php endif ?>
  41. <?php
  42. //本日の日付を取得する
  43. $time = time();
  44. //各日付をセットする
  45. $year = date("Y", $time);
  46. $month = date("n", $time);
  47. $day = date("j", $time);
  48. //GETにきた年月をチェックする
  49. if(isset($this->params['pass']['0']) && $this->params['pass']['0'] == 'date'){
  50. $year2=h(@$this->params['pass']['1']);
  51. $month2=h(@$this->params['pass']['2']);
  52. $day2=h(@$this->params['pass']['3']);
  53. }else{
  54. $year2='';
  55. $month2='';
  56. $day2='';
  57. }
  58. //先月、来月をクリックした場合の処理
  59. if($year2!="" || $month2!="" || $day2!=""){
  60. if($year2!=""){
  61. $year = $year2;
  62. }
  63. if($month2!=""){
  64. $month = $month2;
  65. }
  66. if($day2!=""){
  67. $day = $day2;
  68. }
  69. else{
  70. $day = 1;
  71. }
  72. $time = mktime(0,0,0,$month,$day,$year);
  73. }
  74. //今月の日付の数
  75. $num = date("t", $time);
  76. //曜日を取得するために時間をセット
  77. $today = mktime(0,0,0,$month,$day,$year);
  78. //曜日の配列
  79. $date = array('日','月','火','水','木','金','土');
  80. //カレンダーを表示する
  81. //先月の場合
  82. if($month==1){
  83. $year3 = $year-1;
  84. $month3 = 12;
  85. }
  86. else{
  87. $year3 = $year;
  88. $month3 = $month-1;
  89. }
  90. //来月の場合
  91. if($month==12){
  92. $year4 = $year+1;
  93. $month4 = 1;
  94. }
  95. else{
  96. $year4 = $year;
  97. $month4 = $month+1;
  98. }
  99. //カレンダーを表示するHTML
  100. print '<table class="blog-calendar"><tr><td colspan=7>';
  101. print "<center>";
  102. if($data['prev']) {
  103. print $bcBaser->getLink($month3."月",array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year3, $month3),null,false);
  104. } else {
  105. print $month3."月";
  106. }
  107. print " ".$year."年".$month."月 ";
  108. if($data['next']) {
  109. print $bcBaser->getLink($month4."月",array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year4, $month4),null,false);
  110. } else {
  111. print $month4."月";
  112. }
  113. print "</td></tr>";
  114. print '
  115. <tr>
  116. <th class="sunday"></th>
  117. <th></th>
  118. <th></th>
  119. <th></th>
  120. <th></th>
  121. <th></th>
  122. <th class="saturday"></th>
  123. </tr>
  124. ';
  125. //カレンダーの日付を作る
  126. for($i=1;$i<=$num;$i++){
  127. //本日の曜日を取得する
  128. $print_today = mktime(0, 0, 0, $month, $i, $year);
  129. //曜日は数値
  130. $w = date("w", $print_today);
  131. //一日目の曜日を取得する
  132. if($i==1){
  133. //一日目の曜日を提示するまでを繰り返し
  134. print "<tr>";
  135. for($j=1;$j<=$w;$j++){
  136. print "<td>&nbsp;</td>";
  137. }
  138. $data = check($i,$w,$year,$month,$day,$entryDates,$bcBaser,$blogContent);
  139. print "$data";
  140. if($w==6){
  141. print "</tr>";
  142. }
  143. }
  144. //一日目以降の場合
  145. else{
  146. if($w==0){
  147. print "<tr>";
  148. }
  149. $data = check($i,$w,$year,$month,$day,$entryDates,$bcBaser,$blogContent);
  150. print "$data";
  151. if($w==6){
  152. print "</tr>";
  153. }
  154. }
  155. }
  156. print "</table>";
  157. //特定の日付の場合の処理
  158. function check($i,$w,$year,$month,$day,$entryDates,$bcBaser,$blogContent){
  159. if(in_array(date('Y-m-d',strtotime($year.'-'.$month.'-'.$i)),$entryDates)){
  160. if(date('Y-m-d') == date('Y-m-d',strtotime($year.'-'.$month.'-'.$i))){
  161. $change = '<td class="today">'.$bcBaser->getLink($i,array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year, $month, $i),null,false).'</td>';
  162. }elseif($w==0){
  163. $change = '<td class="sunday">'.$bcBaser->getLink($i,array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year, $month, $i),null,false).'</td>';
  164. }elseif($w==6){
  165. $change = '<td class="saturday">'.$bcBaser->getLink($i,array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year, $month, $i),null,false).'</td>';
  166. }else{
  167. $change = '<td>'.$bcBaser->getLink($i,array('admin'=>false,'blog'=>false,'plugin'=>'','controller'=>$blogContent['BlogContent']['name'],'action'=>'archives', 'date', $year, $month, $i),null,false).'</td>';
  168. }
  169. }else{
  170. if(date('Y-m-d') == date('Y-m-d',strtotime($year.'-'.$month.'-'.$i))){
  171. $change = '<td class="today">'.$i.'</td>';
  172. }else{
  173. $change = '<td>'.$i.'</td>';
  174. }
  175. }
  176. return $change;
  177. }
  178. ?>
  179. </div>