EzPortal - Portal Software for Forums

EzPortal - Made to Fit Your SMF Forum - Glad You Found Us!
+- +-

UserBox

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Recent Posts

New built in translations for six langauges! by EzPortal
March 26, 2024, 11:15:32 pm

Smiley missing in shoutbox 2.1.4 by hustreamload
July 26, 2023, 08:14:02 am

Re: Theme Select Box question? by Shades
March 15, 2023, 06:49:49 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 02:09:24 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 01:55:53 pm

Re: Theme Select Box question? by EzPortal
March 09, 2023, 01:47:42 pm

Re: Theme Select Box question? by Shades
March 09, 2023, 01:34:07 pm

Re: Theme Select Box question? by EzPortal
March 09, 2023, 12:20:17 pm

+- HTML Menu


Sample HTML Block Usage - You May Custom Code it, as needed!

Recent Topics ezBlock

New built in translations for six langauges! by EzPortal
March 26, 2024, 11:15:32 pm

Smiley missing in shoutbox 2.1.4 by hustreamload
July 26, 2023, 08:14:02 am

Theme Select Box question? by Shades
March 15, 2023, 06:49:49 pm

Where is the facebook button color? by EzPortal
February 28, 2023, 06:45:09 pm

Display on Mobile - SMF 2.1.3 and EZ 5.5.2 by BugginIn
December 29, 2022, 04:07:13 pm

Blocks Help by Riggs1973
November 20, 2022, 12:59:30 pm

Surface ol lite theme release Free! by Steffen K.
November 18, 2022, 03:57:24 am

Undefined index: href by EzPortal
October 04, 2022, 08:49:59 pm

SMF-ezportal_column_5.cache): failed to open stream: No such file or directory by EzPortal
June 04, 2022, 11:40:13 am

Arcade block error: failed to open stream: No such file or directory by Shades
May 20, 2022, 02:47:13 pm

Author Topic: Calendar block  (Read 21035 times)

0 Members and 1 Guest are viewing this topic.

Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Calendar block
« on: March 21, 2009, 06:33:41 pm »
I found this code on the official SMF site (on a Spanish topic). It works great for me, I just pasted it into a PHP block and presto! The calendar block that I have been searching for!

Code: [Select]
/*
Calender DIN1031 Version 08-11-2008-1
This is a costumizable calendar php block
It will show a calendar, and add the Today Events, Holidays and Birthdays.
Normal it's programmed and tested for SMF 1.1.X
I don't use any SSI.php, because all data that needed is loaded.
*/
global $scripturl, $modSettings, $sourcedir, $txt;

//With that you can start the calander on a other day
//-1 = Start on Saturaday, 0 = Start on Sunday, 1 = Start on Monday, 2 = Start on Thusday...
$first_day = 0;

//How long should the day, if the number higher 3 than the complete dayname will be shown
$day_name_length = 0; //0 is short day name 1 is full day name :)

//The background color of days with Events, birthdays or holidays, you can use css colors
$color_background_items_mixed = 'lightblue';
$color_background_items_event = 'lightblue';
$color_background_items_birthday = 'lightblue';
$color_background_items_holiday = 'lightblue';

//The textcolor of days with Events, birthdays or holidays, you can use css colors
$color_text_items_mixed = 'steelblue';
$color_text_items_event = 'steelblue';
$color_text_items_birthday = 'steelblue';
$color_text_items_holiday = 'steelblue';

//The Color of the todays background / text
$color_background_today = 'white';
$color_text_today = 'green';

//The Textcolor for the standard days
$color_text = 'steelblue';

//The Textcolor for the Sundays
$color_text_sunday = '#C00000';

//If you have a diffrent calender you can change the link to it here
$month_href = $scripturl . '?action=calendar';

//What should the callendar show?
$show_events = 1; //0 No, 1 Yes
$show_birthdays = 1; //0 No, 1 Yes
$show_holidays = 1; //0 No, 1 Yes
//Show the single events and items of the day :)
$show_today = 1; //0 No, 1 Yes

//Okay please don't do anything here if you not now what you do
/**************************************************************/
// You can't do anything if the calendar is off!
if (empty($modSettings['cal_enabled']))
   fatal_lang_error('calendar_off', false);

$now = mktime() + $modSettings['time_offset'] * 3600;
$today = date('j',$now);
$year = date("Y",$now);
$month = date("n",$now);
$monthtxt = ucfirst(strftime("%B",$now));
$days = array();
$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';
$high_date = $year.'-'.$month.'-'.$days_in_month;
$can_post_calendar = allowedTo('calendar_post');
$calendarDataToday = array('events' => array(), 'birthdays' => array(), 'holidays' => array());
$todayDate = date("Y-m-d", time());

//add important days to the days array
if(!empty($show_events)) {
   $events = calendarEventArray($low_date, $high_date);
   foreach($events as $startdate => $event) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['events'] = $event;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      $days[$cday] = '<a class="smalltext" style="color: '.$color_text_items_event.'; font-weight: bold; background-color: '.$color_background_items_event.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}
//Add holidays into the day array?
if(!empty($show_birthdays)) {
   $birthdays = calendarBirthdayArray($low_date, $high_date);
   foreach($birthdays as $startdate => $birth) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['birthdays'] = $birth;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      //Mixed color?
      $text_color = !empty($days[$cday]) ? $color_text_items_mixed : $color_text_items_birthday;
      $background_color = !empty($days[$cday]) ? $color_background_items_mixed : $color_background_items_birthday;
      $days[$cday] = '<a class="smalltext" style="color: '.$text_color.'; font-weight: bold; background-color: '.$background_color.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}
//Add holidays into the day array?
if(!empty($show_holidays)) {
   $holidays = calendarHolidayArray($low_date, $high_date);
   foreach($holidays as $startdate => $holiday) {
      //This insert the today events if they exist
      if($todayDate == $startdate)
         $calendarDataToday['holidays'] = $holiday;
      $cday = (int) substr($startdate,8,2);
      //We must select between create or only show!
      $text_color = !empty($days[$cday]) ? $color_text_items_mixed : $color_text_items_holiday;
      $background_color = !empty($days[$cday]) ? $color_background_items_mixed : $color_background_items_holiday;
      $href_calendar = $can_post_calendar && $cday >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$cday : $scripturl.'?action=calendar';
      $days[$cday] = '<a class="smalltext" style="color: '.$text_color.'; font-weight: bold; background-color: '.$background_color.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$cday.'</a>';
   }
}

//So Todays it's an diffrent color :D
$href_calendar = $can_post_calendar ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today : $scripturl.'?action=calendar';
$days[$today] = '<a class="smalltext" style="color: '.$color_text_today.'; font-weight: bold; border: solid 1px black; background-color: '.$color_background_today.'; padding: 0px 4px 0px 4px;" href="'.$href_calendar.'" target="_self">'.$today.'</a>';

//Wellcome to the smf way of Day building with existing Language strings :D
$day_names = $txt['days'];
$day_names_short = $txt['days_short'];
//So lets see $firstday = 0 means sunday this is the first day :)
//if there is a higher number than i need to resort them
//negativ values can also be used :)
if(!empty($first_day)) {
   if($first_day < 0)
      $first_day = 7-(abs($first_day)%7);
   else
      $first_day = ($first_day%7);
}
if(!empty($first_day)) {
   $old = $day_names;
   $old_s = $day_names_short;
   $day_names = array();
   $day_names_short = array();
//Create the new day order :)
   for($n=0; $n<7; $n++) {
      $c = (($first_day+$n)%7);
      $day_names[$n] = $old[$c];
      $day_names_short[$n] = $old_s[$c];
   }
}

list($month, $year, $weekday) = explode(',',gmstrftime('%m,%Y,%w',$first_of_month));
$weekday = ($weekday + 7 - $first_day) % 7; //adjust for $first_day
$title = $monthtxt.' '.$year;  //This is the SMF Text string, so it should be corrected for ut8 or iso

/* Begin calendar. Uses a real <caption>. See http://diveintomark.org/archives/2002/07/03 */
$calendar = '
<table>
   <caption>'.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title)."</caption>
   <tr>";

//Put out the Daynames :)
foreach($day_names as $k => $d)
   $calendar .= '
      <th class="smalltext" abbr="'.$d.'">'.(!empty($day_name_length) ? $d : $day_names_short[$k]).'</th>';
$calendar .= "
   </tr>
   <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>
   <tr style=\"text-align:right;\">";
   }
   if(isset($days[$day])){
      $calendar .= '
      <td>'.$days[$day].'</td>';
   }
   else
   {
      $href_calendar = $can_post_calendar && $day >= $today ? $scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day : $scripturl.'?action=calendar';
      $calendar .= "
      <td class=\"smalltext\" style=\"padding-right:4px;\"><a";
      if(((($weekday+$first_day) % 7)==0))
      {
         $calendar .= ' style="color:'.$color_text_sunday.';"';
      }
      $calendar .= " href=\"".$href_calendar."\" target=\"_self\">$day</a></td>";
   }
}
if($weekday != 7) $calendar .= '
      <td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; //remaining "empty" days

echo $calendar.'
   </tr>';


if (!empty($show_today) && (!empty($calendarDataToday['events']) || !empty($calendarDataToday['birthdays']) || !empty($calendarDataToday['holidays']))) {

   if(!empty($calendarDataToday['holidays'])){
      echo '
   <tr><td>
      <hr />
   </td>
   <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_holiday . ';">
      <b>Holidays</b>
   </td><td>
      <hr />
   </td>
   </tr>
   <td colspan="7" class="smalltext">';
      foreach( $calendarDataToday['holidays'] as $holiday )
         echo '
            ', $holiday['name'], '<br />';
      echo '
      </td></tr>';   
   }

   if(!empty($calendarDataToday['birthdays'])){
      echo '
   <tr><td>
      <hr />
   </td>
   <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_birthday . ';">
      <b>Birthdays</b>
   </td><td>
      <hr />
   </td></tr>
      <td colspan="7" class="smalltext">';
      foreach( $calendarDataToday['birthdays'] as $member )
         echo '
            <a href="', $scripturl, '?action=profile;u=', $member['id'], '">', $member['name'], isset($member['age']) ? ' (' . $member['age'] . ')' : '', '</a>', '<br />';
      echo '
   </td></tr>';   
   }

   if(!empty($calendarDataToday['events']))
   {
      echo '
      <tr><td>
         <hr />
      </td>
      <td colspan="5" class="smalltext" align="center" style="color: ' . $color_text_items_event . ';">
         <b>Events</b>
      </td><td>
         <hr />
      </td></tr>
      <td colspan="7" class="smalltext">';
      foreach ($calendarDataToday['events'] as $event)
      {
         if ($event['can_edit'])
            echo '
            <a href="' . $event['modify_href'] . '" style="color: #FF0000;">*</a> ';
         echo '
         ' . $event['link'] . '<br />';
      }
   }
  echo '
     </td></tr>';
}

echo '
</table>';

Offline chinaren

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 4
  • www.TomeCity.com
    • Read Tired of Death for free!
Re: Calendar block
« Reply #1 on: March 25, 2009, 07:29:59 pm »
AAAAAAAAAAHHHHH!

I just tried this and now my forum index page doesn't come up!

How the heck am I going to fix this one without doing a restore?


Offline chinaren

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 4
  • www.TomeCity.com
    • Read Tired of Death for free!
Re: Calendar block
« Reply #2 on: March 25, 2009, 07:35:00 pm »
OKay, seriously, help

I cut and pasted this block and hit the <enter> key and nothing's coming up on my index page.   I can FTP into the host though, so is there some file I can adjust to fall this back?



Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Re: Calendar block
« Reply #3 on: March 25, 2009, 09:06:27 pm »
There is a way to load your forum without any portals... it is a certain path that you put in your browser. I saw it in the SMF forums somewhere and have been looking for it to no avail. I'd suggest looking for that then going in and turning off that block.

Offline chinaren

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 4
  • www.TomeCity.com
    • Read Tired of Death for free!
Re: Calendar block
« Reply #4 on: March 25, 2009, 09:12:10 pm »
I don't have the portal page turned on, I just go straight to the forum, which is what's not loaded.

Probably should have mentioned that!


Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Re: Calendar block
« Reply #5 on: March 25, 2009, 09:15:56 pm »
That's what I mean.... there is a way to load your forum minus the portals.... so you can go in and delete buggy block codes.... (sorry it is messing stuff up by the way)

Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Re: Calendar block
« Reply #6 on: March 25, 2009, 09:21:21 pm »
AAAAAAAAAAHHHHH!

I just tried this and now my forum index page doesn't come up!

How the heck am I going to fix this one without doing a restore?
I can access your site fine....

Offline chinaren

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 4
  • www.TomeCity.com
    • Read Tired of Death for free!
Re: Calendar block
« Reply #7 on: March 25, 2009, 09:28:07 pm »
Yes, I just managed to fix it.  :D

If anyone has this problem, check out the 'Help I've lost my forum' thread in the support area.



Offline chinaren

  • Jr. Member
  • **
  • Posts: 55
  • Karma: 4
  • www.TomeCity.com
    • Read Tired of Death for free!
Re: Calendar block
« Reply #8 on: March 25, 2009, 09:29:50 pm »
I like Star Treck.

Sorry, that's what I get for leaving the page open in the classroom.  ::)


Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Re: Calendar block
« Reply #9 on: March 25, 2009, 09:34:08 pm »
LOL!

I use this code now.... It is a bit better than the previous.

Offline Yahmez

  • Posts: 9
  • Karma: 0
  • Gender: Male
Re: Calendar block
« Reply #10 on: March 26, 2009, 05:07:42 am »
I should mention that I am using the default template. I found this calendar block on the tiny portal site. BTW you could look there under the 'block snippets' board for more calendar in a block ideas.

http://www.tinyportal.net/index.php?PHPSESSID=67612cd51824da44fe3599f11a74e7dc&board=46.0

 

Related Topics

  Subject / Started by Replies Last post
5 Replies
9655 Views
Last post September 02, 2014, 06:15:16 am
by Maxx
4 Replies
5687 Views
Last post December 15, 2014, 03:23:24 pm
by Eddy Matthews
0 Replies
4252 Views
Last post May 22, 2016, 04:39:46 pm
by Miker1029
3 Replies
10828 Views
Last post May 17, 2021, 01:05:41 pm
by EzPortal
2 Replies
4262 Views
Last post February 01, 2022, 11:16:38 am
by EzPortal

+-SMF Gallery

Quick Menu


Powered by EzPortal