การเขียนโค๊ดนำปฏิทินกิจกรรมของ SMF มาติดที่หน้าแรกของเว็บไซต์ของเรา
ตามหัวข้อเลยครับ หากเราไม่อยากคลิกเข้าไปที่เมนู ปฏิทิน ในบอร์ด SMF เราสามารถเขียนโค๊ดดึงปฎิทินมาแสดงในหน้าแรกของเว็บไซต์เราได้เอง
ดัดแปลงจากโค๊ดต้นฉบับนิดหน่อยจ๊ะ Credit
http://www.mkportal.it/support/showthread.php?t=28200ตรงนี้มีภาพ! แต่ท่านจะมองไม่เห็น , ท่านต้อง
สมัครสมาชิก หรือ
ลงชื่อเข้าระบบเริ่มจากสร้างไฟล์ calendar.php ภายในไฟล์เขียนโค๊ดดังนี้ โค๊ดส่วนแรกจะเป็นการสร้าง stylesheets แล้วก็ไปดึงไฟล์ ToolTip.js มาใช้งานเพื่อที่จะสร้างเป็น Tooltip ไฟล์ ToolTip.js โหลดได้ตามไฟล์แนบบครับ
<!--เอาเม๊าชี้แล้วขึ้น Tooltip-->
<style type="text/css">
#dhtmltooltip{
position: absolute;
left: -300px;
width: 150px;
border: 1px solid black;
padding: 5px;
background-color: #666666;
font-size:11px; color:#CCCCCC;
visibility: hidden;
z-index: 100;
/*Remove below line to remove shadow. Below line should always appear last within this CSS*/
filter: progid:DXImageTransform.Microsoft.Shadow(color=gray,direction=135);
}
#dhtmlpointer{
position:absolute;
left: -300px;
z-index: 101;
visibility: hidden;
}
</style>
<script src="ToolTip.js"></script>
<!---->
ยังอยู่ในไฟล์ calendar.php ต่อจากโค๊ดด้านบนให้เขียนโค๊ดดังนี้
<?php
require("forum/SSI.php");
global $scripturl, $modSettings, $sourcedir;
//require_once("/xxxx/xxxxxxx/m/i/c/xxxxxxxxxx/html/hraus/hraforums/SSI.php");
$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date("Y",$now);
if(!$_REQUEST['month_']){
$month = date("n",$now);
}else{
$month = date("n",$now)+$_REQUEST['month_'];
}
$days = array();
$day_name_length = 3;
$month_href = $scripturl . '?action=calendar';
$first_day = 0;
$pn = array();
$first_of_month = gmmktime(0,0,0,$month,1,$year);
#remember that mktime will automatically correct if invalid dates are entered
# for instance, mktime(0,0,0,12,32,1997) will be the date for Jan 1, 1998
# this provides a built in "rounding" feature to generate_calendar()
#retrieve this month events, holydays and birthdays
$days_in_month = gmdate('t',$first_of_month);
include_once($sourcedir . '/Calendar.php');
//$low_date = $year.'-'.$month.'-01';
$low_date = date("Y-m-d",gmmktime(0,0,0,$month,1,$year));
//$high_date = $year.'-'.$month.'-'.$days_in_month;
$high_date = gmmktime(0,0,0,$month,$days_in_month,$year);
$high_date = date("Y-m-d",$high_date);
$events = calendarEventArray($low_date, $high_date);
$birthdays = calendarBirthdayArray($low_date, $high_date);
#add important days to the days array
foreach($events as $startdate => $value){
foreach($value as $value1 =>$value2){
$tooltip = <<<Data
onMouseover="ddrivetip('กิจกรรมหัวข้อ : <strong><font color=#FF00CC>$value2[title]</font></strong> ',200)"; onMouseout="hideddrivetip()"
Data;
$days[substr($startdate,8)] = array(NULL,NULL,'<a href="'.$value2["href"].'" target="_blank" '.$tooltip.'><font style="background-color:yellow;padding: 0px 4px 0px 4px;border: solid 1px black;color: steelblue;font-weight: bold; " '.$tooltip.'>'.substr($startdate,8).'</font>[/url]');
}
}
foreach($birthdays as $startdate => $value){
//echo print_r($value);
foreach($value as $value1 =>$value2){
$startdate_show = ThaiDate($startdate);
$tooltip = <<<Data
onMouseover="ddrivetip('วันเกิดของ : <strong><font color=#FF00CC>$value2[name]</font></strong>',200)"; onMouseout="hideddrivetip()"
Data;
$days[substr($startdate,8)] = array(NULL,NULL,'<a href="'.$scripturl.'?action=profile;u='.$value2["id"].'" target="_blank" ><font style="background-color:lightblue;padding: 0px 4px 0px 4px;border: solid 1px black;color: steelblue;font-weight: bold; " '.$tooltip.'>'.substr($startdate,8).'</font>[/url]');
}
}
$today_date = $year.'-'.date("m").'-'.$today;
if(empty($events[$today_date])){
if($month==date("m")){
$days[$today] = array(NULL,NULL,'<font class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" >'.$today.'</font>');
}
}else{
foreach($events[$today_date] as $value1 =>$value2){
$tooltip = <<<Data
onMouseover="ddrivetip('กิจกรรมหัวข้อ : <strong><font color=#FF00CC>$value2[title]</font></strong> ',400)"; onMouseout="hideddrivetip()"
Data;
$days[$today] = array(NULL,NULL,'<a href="'.$value2["href"].'" target="_blank" '.$tooltip.'><font style="background-color:yellow;padding: 0px 4px 0px 4px;border: solid 1px black;color: steelblue;font-weight: bold; " '.$tooltip.'>'.$today.'</font>[/url]');
}
}
if(empty($birthdays[$today_date])){
if($month==date("m")){
$days[$today] = array(NULL,NULL,'<font class="smalltext" style="color: steelblue; font-weight: bold; border: solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" >'.$today.'</font>');
}
}else{
foreach($birthdays[$today_date] as $value1 =>$value2){
$tooltip = <<<Data
onMouseover="ddrivetip('วันเกิดของ : <strong><font color=#FF00CC>$value2[name]</font></strong> ',200)"; onMouseout="hideddrivetip()"
Data;
$days[$today] = array(NULL,NULL,'<a href="'.$scripturl.'?action=profile;u='.$value2["id"].'" target="_blank" ><font style="background-color:lightblue;padding: 0px 4px 0px 4px;border: solid 1px black;color: steelblue;font-weight: bold; " '.$tooltip.'>'.$today.'</font>[/url]');
}
}
$day_names = array(); #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400) #January 4, 1970 was a Sunday
$day_names[$n] = ucfirst(gmstrftime('%A',$t)); #%A means full textual day name
list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; #adjust for $first_day
$title = htmlentities(ucfirst($month_name)).' '.$year; #note that some locales don't capitalize month and day names
#Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03
$mn=$_REQUEST['month_']+1;
$mp=$_REQUEST['month_']-1;
$pn = array('<strong><u><</u></strong>'=>'calendar.php?month_='.$mp,'<strong><u>></u></strong>'=>'calendar.php?month_='.$mn);
@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'[/url]' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'[/url]' : $n).'</span>';
$calendar = '<table cellpadding="2">'."\n".
'<caption >'.$p.$title.$n;
if($month!=date("m")){
$calendar .="[br /]{<a href='calendar.php'>เดือนปัจจุบัน[/url]}";
}
$calendar .="</caption>\n<tr>";
if($day_name_length){ #if the day names should be shown ($day_name_length > 0)
#if day_name_length is >3, the full name of the day will be printed
foreach($day_names as $d)
$calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days
for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
if($weekday == 7){
$weekday = 0; #start a new week
$calendar .= "</tr>\n<tr style=\"text-align:right;\">";
}
if(isset($days[sprintf("%02d",$day)]) and is_array($days[sprintf("%02d",$day)])){
@list($link, $classes, $content) = $days[sprintf("%02d",$day)];
if(is_null($content)) $content = $day;
$calendar .= '<td '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').
($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'[/url]' : $content).'</td>';
}
else
{
$calendar .= "<td class=\"smalltext\" style=\"padding-right:4px;\"><font";
if(<img src="http://www.auto-nkp.com/Smileys/Emotion/2Hand.gif" alt="((" title="ปรบมือ" class="smiley" />($weekday+$first_day) % 7)==0))
{
$calendar .= ' style="color:#C00000;"';
}
$calendar .= ">$day</font></td>";
}
}
if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days
echo $calendar.'</tr>';
echo '</table>';
#crate notice for the next N days events. N is set in Settings.
echo '<table><tr><td>[hr /]</td><td colspan="5" class="smalltext" align="center"><b>วันเกิดเพื่อนๆ เดือน '.$title.' </b></td><td>[hr /]</td></tr><td colspan="7" class="smalltext">';
if (ssi_todaysCalendar('')) {
$result = ssi_todaysCalendar('');
// if(!empty($result['birthdays'])){
// $birthdays = $result['birthdays'];
// echo '
// <span style="color: #' . $modSettings['cal_bdaycolor'] . ';">' . $txt['calendar3b'] . '</span>[br /]';
// foreach( $birthdays as $member )
// echo $member['colored_link'], '[br /]';
// echo '</td></tr>';
// }
member_birthdays($low_date);
if(!empty($result['events']))
{
echo '<tr><td>[hr /]</td><td colspan="5" class="smalltext" align="center"><b>Upcomings</b></td><td>[hr /]</td></tr><td colspan="7" class="smalltext">';
echo '
<span style="color: #' . $modSettings['cal_eventcolor'] . ';">' . $txt['calendar4b'] . '</span>[br /] ';
$events = $result['events'];
foreach ($events as $event)
{
echo '
'.substr($event['start_date'],8).'/'.substr($event['start_date'],5 , 2).':';
if ($event['can_edit'])
echo '
<a href="' . $event['modify_href'] . '" style="color: #FF0000;">*[/url] ';
echo '
' . $event['link'] . '[br /]';
}
}
echo '</td></tr></table>';
}
?>