2012-10-16 5 views
1

에서 나는 위키에서 일하고 있어요 그리고 난 커뮤니티 달력을 짓고 있어요. SimpleCalendar 확장 프로그램을 사용하고 있으며 현재 월, 이전 및 다음 달을 표시하고 싶습니다. 현재 달의 기능은 잘 작동하지만 나는 이전 및 다음 달에게편집 현재 달 PHP 코드는 미디어 위키

위키

{{#calendar: month=$prevMonth | dayformat=%A | format=%A %B %d %Y }} 
{{#calendar: month={{CURRENTMONTH}} | dayformat=%A | format=%A %B %d %Y }} 
{{#calendar: month=$nextMonth | dayformat=%A | format=%A %B %d %Y }} 

PHP

function wfRenderMonth($m,$y,$prefix = '',$query = '',$format = '%e %B %Y',$dayformat = false) { 
$thisDay = date('d'); 
$thisMonth = date('n'); 
$thisYear = date('Y'); 
if (!$d = date('w',$ts = mktime(0,0,0,$m,1,$y))) $d = 7; 
$month = wfMsg(strtolower(strftime('%B',$ts))); 
//I've been editing these two lines to try to create a variable for the previous and following months 
$prevMonth = "strftime(%m - 1)"; 
$nextMonth = "strftime(%m + 1)"; 
$days = array(); 
foreach (array('M','T','W','T','F','S','S') as $i => $day) 
    $days[] = $dayformat ? wfMsg(strftime($dayformat,mktime(0,0,0,2,$i,2000))) : $day; 
$table = "\n{| class=\"month\"\n|- class=\"heading\"\n|colspan=\"7\"|$month\n|- class=\"dow\"\n"; 
$table .= '|'.join('||',$days)."\n"; 
if ($d > 1) $table .= "|-".str_repeat("\n| \n",$d-1); 
for ($i = $day = $d; $day < 32; $i++) { 
    $day = $i - $d + 1; 
    if ($day < 29 or checkdate($m,$day,$y)) { 
     if ($i%7 == 1) $table .= "\n|-\n"; 
     $t = ($day == $thisDay and $m == $thisMonth and $y == $thisYear) ? ' class="today"' : ''; 
     $ttext = $prefix.trim(strftime($format,mktime(0,0,0,$m,$day,$y))); 
     $title = Title::newFromText($ttext); 
     if (is_object($title)) { 
      $class = $title->exists() ? 'day-active' : 'day-empty'; 
      $url = $title->getFullURL($title->exists() ? '' : $query); 
     } else $url = $ttext; 
     $table .= "|$t|[$url <span class='$class'>$day</span>]\n"; 
    } 
} 
return "$table\n|}"; 

}

당신의 뜻을 표시하는 방법을 알아내는 데 문제가 내 멍청이를 용서해야 해. 나는 PHP에 아주 익숙하다.

답변

0

나는 그것을 알아 냈다! 난 그냥 내 LocalSettings.php에 ParserFunction 기능을 추가하고 사용하는 데 필요한

{{#calendar: month={{#expr:{{formatnum:{{CURRENTMONTH}}|R}}-1}} | dayformat=%A |format=%A %B %d %Y }} 
{{#calendar: month={{CURRENTMONTH}} | dayformat=%A | format=%A %B %d %Y }} 
{{#calendar: month={{#expr:{{formatnum:{{CURRENTMONTH}}|R}}+1}} | dayformat=%A | format=%A %B %d %Y }} 
0

코드는 이럴를 읽고 매우 어렵다. 당신은 당신이 실제로 단순히 개월 매개 변수 $ 월 - 1 시간 (mktime은 사용) 구성되어 수행 할 작업 등 "29"일 ...와 장난을 한 것으로 나타났습니다. 이 멋진 작은 기능은 모든 "월 = 0 그러므로 월 = 12 년 = 1 년 1"물건을 처리합니다. 당신이주는 날짜가 "31 년 4 월 2012"로 fn을받는 전송되는 및 "2012 4 월 30 일"돌아갑니다 5 월 2012 (31)의 경우 그것은 동등하게 처리합니다 :) 난 당신의 코드가 쉽게 경우 크기의 5 이하가 될 수 있다고 생각 이걸 선호해라. 도움이 더 필요하면 다시 게시하십시오. 제가 할 수있는 일을 볼 수 있습니다.

관련 문제