ข่าวประชาสัมพันธ์

มาร่วมเป็นกำลังใจให้เว็บด้วยการสมัครสมาชิกวีไอพี ~~ เลือกปีที่ท่านต้องการได้โดยไม่ต้องเรียงปี ~~ ปีละ 350 บาท สมัคร 2 ปีลดเหลือ 600 บาท ~~ มีไลน์กลุ่ม VIP จำนวนหลายร้อยท่าน เอาไว้ปรึกษางานซ่อม ~~ เข้าถึงข้อมูลด้านเทคนิค ข้อมูลเชิงลึกมากมาย.....


ผู้เขียน หัวข้อ: การเขียนโค๊ดนำปฏิทินกิจกรรมของ SMF มาติดที่หน้าแรกของเว็บไซต์ของเรา  (อ่าน 1834 ครั้ง)

0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้

ออฟไลน์ Auto Man

  • Administrator
  • หัวหน้าศูนย์ซ่อมสร้าง
  • *****
  • เจ้าของกระทู้
  • Joined: ก.ย. 2558
  • กระทู้: 37651
  • สมาชิกลำดับที่ : 1
  • เพศ: ชาย
  • มือผู้ให้ย่อมสูงกว่ามือผู้รับ
    • เว็บชุมชนคนรักช่างยนต์
    • อีเมล์
การเขียนโค๊ดนำปฏิทินกิจกรรมของ SMF มาติดที่หน้าแรกของเว็บไซต์ของเรา

ตามหัวข้อเลยครับ หากเราไม่อยากคลิกเข้าไปที่เมนู ปฏิทิน ในบอร์ด SMF เราสามารถเขียนโค๊ดดึงปฎิทินมาแสดงในหน้าแรกของเว็บไซต์เราได้เอง

ดัดแปลงจากโค๊ดต้นฉบับนิดหน่อยจ๊ะ Credit http://www.mkportal.it/support/showthread.php?t=28200

ตรงนี้มีภาพ! แต่ท่านจะมองไม่เห็น , ท่านต้อง  สมัครสมาชิก หรือ ลงชื่อเข้าระบบ


เริ่มจากสร้างไฟล์ calendar.php ภายในไฟล์เขียนโค๊ดดังนี้ โค๊ดส่วนแรกจะเป็นการสร้าง stylesheets แล้วก็ไปดึงไฟล์ ToolTip.js มาใช้งานเพื่อที่จะสร้างเป็น Tooltip ไฟล์ ToolTip.js โหลดได้ตามไฟล์แนบบครับ

โค๊ด: [Select]
<!--เอาเม๊าชี้แล้วขึ้น 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 ต่อจากโค๊ดด้านบนให้เขียนโค๊ดดังนี้

โค๊ด: [Select]
<?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 $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 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="&#40;&#40;" 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'],2).':';
         if (
$event['can_edit'])
            echo 
'
            <a href="' 
$event['modify_href'] . '" style="color: #FF0000;">*[/url] ';
         echo 
'
         ' 
$event['link'] . '[br /]';
      }
   }
  echo 
'</td></tr></table>';
}

?>
สวัสดีคุณ...ผู้เยี่ยมชม  กด ❤ ถูกใจโพสท์นี้ หรือยัง...
ต้องการสมัครสมาชิก VIP สมัครได้ที่นี่...   หรือทาง Line ID: k.sonchai

ออฟไลน์ Auto Man

  • Administrator
  • หัวหน้าศูนย์ซ่อมสร้าง
  • *****
  • เจ้าของกระทู้
  • Joined: ก.ย. 2558
  • กระทู้: 37651
  • สมาชิกลำดับที่ : 1
  • เพศ: ชาย
  • มือผู้ให้ย่อมสูงกว่ามือผู้รับ
    • เว็บชุมชนคนรักช่างยนต์
    • อีเมล์
ซึ่งในโค๊ดด้านบนจะมีการ require ไฟล์ SSI.php มาด้วย จบจากไฟล์ calendar.php

เราก็มาเพิ่มโค๊ดด้านล่างนี้ในไฟล์ SSI.php ก่อน ?>

โค๊ด: [Select]
function member_birthdays($low_date){
   global $db_prefix,$scripturl;
   $font_color = array("red", "orange", "green", "pink", "black", "blue", "#990099");
   
   $m = substr($low_date,5,2);
   $request = db_query("
      SELECT ID_MEMBER,birthdate, realName
      FROM {$db_prefix}members
      WHERE SUBSTR(birthdate,6,2)='$m' and birthdate!='0001-01-01' order by birthdate ASC " , __FILE__, __LINE__);
   while ($row = mysql_fetch_assoc($request))
   {
      $rand_color = array_rand($font_color,1);

      echo "<a href='".$scripturl."?action=profile;u=".$row['ID_MEMBER']."' target='_blank'><strong><font color='".$font_color[$rand_color]."'> ".$row['realName']."</font></strong>[/url]&nbsp;(".ThaiDate($row['birthdate']).") {<a href='".$scripturl."?action=pm;sa=send;u=".$row['ID_MEMBER']."' target='_blank'>ส่งคำอวยพร[/url]}[br /]";
   }   
}

 $ThaiMonth=array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฎาคม","สิงหาคม","กันยายน","ตุลาคม","พฤษจิกายน","ธันวาคม");

function ThaiDate($InputDate)
{
global $ThaiMonth;
$day=substr($InputDate,8,2);
$month=substr($InputDate,5,2);
$month=(int)$month-1;
$year=substr($InputDate,0,4);
$year=$year+543;
$month=$ThaiMonth[$month];
$thaidatenew= (int)$day." ".$month." ".$year;
return $thaidatenew;
}

วิธีใช้งานก็แค่ใช้ <iframe>...</iframe> ดึงมาแสดงในหน้าแรก

โค๊ด: [Select]
<iframe src="calendar.php" width="100%" height="190" frameborder="0" scrolling="no"></iframe>
แค่นี้ก็เราก็จะได้ปฏิทินกิจกรรมพร้อมทั้งแสดงวันเกิดในแต่ละเดือนด้วยจ๊ะ

มาจากที่นี่ ---> http://bc46.com/forum/index.php?topic=766.0
สวัสดีคุณ...ผู้เยี่ยมชม  กด ❤ ถูกใจโพสท์นี้ หรือยัง...
ต้องการสมัครสมาชิก VIP สมัครได้ที่นี่...   หรือทาง Line ID: k.sonchai