Events Calendar

showcal(); | | Set calendar display type: (full,mini,list,mini-list) | $cal = new CALENDAR(); // equals 'full' as default | $cal = new CALENDAR('full'); | $cal = new CALENDAR('mini'); | $cal = new CALENDAR('list'); | $cal = new CALENDAR('min-list'); | | Set start date: | $date = 2011-4; // 4 digit year | $cal = new CALENDAR('', $date); | echo $cal->showcal(); | | Add events: | | Settings: | | Suggested event/calendar colors: #D6FFDB,#FFF6D6,#D8E5F9,#FFD6D6 | | | */ /* |-------------------------------------------------------------------------- | DEBUG |-------------------------------------------------------------------------- | | Uncomment the following 2 lines to allow error reporting. | */ //error_reporting(E_ALL ^ E_NOTICE); //ini_set('display_errors','1'); $cal_ID = 0; // the ID of the first instance of the calendar, autoincrements if more than one per page class CALENDAR { /* |-------------------------------------------------------------------------- | CONFIGURATION |-------------------------------------------------------------------------- | | Default values for each instance. Can be set as defaults here or | when the calendar is created... | | E.g. | $cal = new CALENDAR(); | $cal->jqueryinclude = false; //-- sets the $jqueryinclude value for the $cal instance of the calendar | echo $cal->showcal(); | */ var $css = 'default'; // path to css file ('default' = default css, 'disable' = no css) var $js = 'default'; // path to js file ('default' = default js, 'disable' = no js) var $weekstartday = 0; // week start day (0-6 e.g. 0 = Sunday, 1 = Monday, etc.) var $jqueryinclude = true; // includes jquery from google (true,false) var $monthselector = true; // month/year select box (true=show selector,false=show month name) var $yearoffset = 5; // monthselector range of years (int) var $weeknumbers = false; // adds a column for week numbers (left,right,false) var $weeknumrotate = true; // rotate weeknumbers 90 degrees *currently only firefox is supported* (true,false) var $weeknames = 2; // controls how weekdays are displayed. (1=full,2=abbrev,3=single char) var $monthnames = 1; // controls how months are displayed. (1=full,2=abbrev) var $basecolor = '7D9AC0'; // base color for color scheme (hex) var $minicalwidth = '240px'; // width of mini calendar (any css measurement e.g. px,%,em,etc.) var $minilistwidth = '200px'; // width of minilist (any css measurement e.g. px,%,em,etc.) var $minilinkbase = ''; // base url for links on mini calendar (blank=disabled) var $tipwidth = '150px'; // width of the minical hover tip (any css measurement e.g. px,%,em,etc.) var $basesize = '10px'; // all sizes scale on this value (any css measurement e.g. px,%,em,etc.) var $eventlistbg = 'ffffff'; // event list view bg color (hex) var $eventemptytext = 'No additional details for this event.'; // default text in event view when details is empty (string) var $dateformat = 'F j, Y'; // default date format (passed to php date() function) var $timeformat = 'g:ia'; // default time format (passed to php date() function) var $font = '"Lucida Grande","Lucida Sans Unicode",sans-serif'; // font used to display the calendar (any css supported value) var $linktarget = 'parent'; // link target frame or window (e.g. 'parent.frameName'. Use '_blank' for new window/tab) var $listlimit = false; // limit the number of events in list and mini-list (false or int e.g. 10) var $listtitle = 'Event List'; // Title shown when displaying full event list var $ajax = false; // Enable/Disable ajax mode //-------------------------------------------------------------------------------------------- // Weekday names/abbreviations (array must start with Sunday=0) //-------------------------------------------------------------------------------------------- var $weekdays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var $abbrevweekdays = array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"); var $weekdayschar = array("S", "M", "T", "W", "H", "F", "S"); //-------------------------------------------------------------------------------------------- // Other vars used. (No need to edit below here) //-------------------------------------------------------------------------------------------- var $jd, $year, $month, $day, $displaytype, $numdaysinmonth, $monthstartday, $monthname, $previousmonth, $nextmonth; var $linkcolor, $calgradient, $nodatecolor, $nodatetextcolor, $weekdaycolor1, $weekdaycolor2, $currentdaycolor1, $currentdaycolor2, $weekendcolor1, $weekendcolor2, $bordercolor, $datetextcolor, $headingtextcolor, $headingcolor1, $headingcolor2, $shadowcolor; var $events = array(); //-------------------------------------------------------------------------------------------- // Class methods: //-------------------------------------------------------------------------------------------- function CALENDAR($type='full',$date='',$staticdisplaytype=false) { // types: mini,full,list,mini-list (default=full) // static displaytype if($staticdisplaytype===true) { $this->displaytype = $type; } else { // calendar display type if($type!='' && !isset($_REQUEST['t'])) { $this->displaytype = $type; // if type is not set in querystring set type to passed value } else { $this->displaytype = $_REQUEST['t']; // else set to type passed in querystring } } // calendar date if($date==''&&!isset($_REQUEST['date'])) $date = date('Y-n-j'); // set to todays date if no value is set if(isset($_REQUEST['date']) && $_REQUEST['date']!='') $date = $_REQUEST['date']; // check if date is in the querystring $date = date('Y-n-j',strtotime($date)); // format the date for parsing $date_part = explode('-',$date); // separate year/month/day $year = $date_part[0]; $month = $date_part[1]; $day = $date_part[2]; if(isset($_REQUEST['y'])&&$_REQUEST['y']!='') $year = $_REQUEST['y']; // if year is set in querystring it takes precedence if(isset($_REQUEST['m'])&&$_REQUEST['m']!='') $month = $_REQUEST['m']; // if month is set in querystring it takes precedence if(isset($_REQUEST['d'])&&$_REQUEST['d']!='') $day = $_REQUEST['d']; // if day is set in querystring it takes precedence // make sure we have year/month/day as int if($year == '') { $year = date('Y'); } if($month == '') { $month = date('n'); // set to january if year is known } if($day == '') { $day = date('j'); // set to the 1st is year and month is known } $this->month = ( int ) $month; $this->year = (int) $year; $this->day = (int) $day; // find out the number of days in the month $this->numdaysinmonth = cal_days_in_month( CAL_GREGORIAN, $this->month, $this->year ); // create a calendar object $this->jd = cal_to_jd( CAL_GREGORIAN, $this->month,date( 1 ), $this->year ); // get the month start day as an int (0 = Sunday, 1 = Monday, etc) $this->monthstartday = jddayofweek( $this->jd , 0 ); // get the month as a name $this->monthname = jdmonthname( $this->jd, 1 ); } // generates all the hex codes for the calendar color scheme function color_scheme() { if(!$this->linkcolor) $this->linkcolor = $this->colourBrightness($this->basecolor,-0.4); if(!$this->calgradient) $this->calgradient = $this->colourBrightness($this->basecolor,-0.8); if(!$this->bordercolor) $this->bordercolor = $this->colourBrightness($this->basecolor,0.7); if(!$this->shadowcolor) $this->shadowcolor = $this->colourBrightness($this->basecolor,-0.01); if(!$this->datetextcolor) $this->datetextcolor = $this->colourBrightness($this->basecolor,-0.3); if(!$this->headingtextcolor) $this->headingtextcolor = $this->colourBrightness($this->basecolor,0.01); if(!$this->nodatecolor) $this->nodatecolor = $this->colourBrightness($this->basecolor,0.1); if(!$this->nodatetextcolor) $this->nodatetextcolor = $this->colourBrightness($this->basecolor,0.4); if(!$this->weekdaycolor1) $this->weekdaycolor1 = $this->colourBrightness($this->basecolor,0.38); if(!$this->weekdaycolor2) $this->weekdaycolor2 = $this->colourBrightness($this->basecolor,0.15); if(!$this->currentdaycolor1) $this->currentdaycolor1 = $this->basecolor; if(!$this->currentdaycolor2) $this->currentdaycolor2 = $this->colourBrightness($this->basecolor,-0.9); if(!$this->weekendcolor1) $this->weekendcolor1 = $this->colourBrightness($this->basecolor,0.5); if(!$this->weekendcolor2) $this->weekendcolor2 = $this->colourBrightness($this->basecolor,0.3); if(!$this->headingcolor1) $this->headingcolor1 = $this->colourBrightness($this->basecolor,-0.8); if(!$this->headingcolor2) $this->headingcolor2 = $this->colourBrightness($this->basecolor,-0.6); } // css for all displaytypes function set_styles() { global $cal_ID; $html = ''; // generate the color scheme $this->color_scheme(); $cal_ID++; // increment the calendar id so we can assign css/js to the corresponding calendar if($this->css!='disable' && $this->css!='default') { // load css file defined in properties $html = ''; } else if($this->css!='disable') { // load default css // universal css $html .= ' '; } return $html; } // js for all displaytypes function set_js() { global $cal_ID; $html = ''; if($this->jqueryinclude && $cal_ID==1) // only include once if multiple calendars $html = ' '; if($this->js!='disable' && $this->js!='default') { // load js file defined in properties $html = ''; } else if($this->js!='disable') { // load default js $html .= ' '; } return $html; } // header area for all displaytypes function calendar_head($content='') { global $cal_ID; $html = ''; if(!in_array($this->displaytype,array("list","mini-list"))) { // mini and full cal $html = ' '; // render week number on left if($this->weeknumbers=='left') { $html .= ''; } $html .= ' '; // render week number on right if($this->weeknumbers=='right') { $html .= ''; } $html .= ' '; if($this->weeknames == 1) { $weekdays = $this->weekdays; // full } else if($this->weeknames == 3 || $this->displaytype=='mini') { $weekdays = $this->weekdayschar; // single char } else { $weekdays = $this->abbrevweekdays; // 3 char } for($i = 0; $i < count($weekdays); $i++) { $di = ($i + $this->weekstartday) % 7; $weekday = $weekdays[$di]; if($i==0) $thisclass = 'normal-day-heading week-start'; else $thisclass = 'normal-day-heading'; $html .= $this->calendar_cell($weekday, $thisclass); // calendar cells for full & mini } $html .= ' '; } else { // event list $html .= '
'; if($this->displaytype=='list') {// don't show viewmode buttons for mini-list if($this->listtitle!='') $html .= '

'.$this->listtitle.'

'; $html .= $this->cal_viewmode(); } } return $html; } // viewmode buttons function cal_viewmode() { $html = ' '; return $html; } // next month link function cal_next() { global $cal_ID; $html = ''; $next = $this->calcDate($this->year.'-'.$this->month, '+1', 'month'); $this->nextmonth = ($this->getMonth($next['year'].'-'.$next['month'],$this->monthnames).' '.$next['year']); if($this->displaytype == 'full') { $divider = $this->monthselector===false?' | ':''; $nexttext = $divider.$this->nextmonth.' »'; } else { $nexttext = '»'; } $html = ''; return $html; } // previous month link function cal_previous() { global $cal_ID; $previous = $this->calcDate($this->year.'-'.$this->month, '-1', 'month'); $this->previousmonth = ($this->getMonth($previous['year'].'-'.$previous['month'],$this->monthnames).' '.$previous['year']); if($this->displaytype == 'full') { $nexttext = '« '.$this->previousmonth; } else { $nexttext = '«'; } $html = ''; return $html; } // month/year select box function month_selector() { $html = '
'; if($this->js == 'disable') { $html .= ''; } $html .= ''; return $html; } // calendar cells for mini and full displaytypes function calendar_cell($day, $class, $date = '', $style = '') { global $cal_ID; $addclass = ''; if(strpos($class,'normal-day-heading')!==false) $tag = 'th'; else $tag = 'td'; if($day != '') { $bgColor = ''; $cellevents = array(); if(is_array($this->events)) { // events array populated from addEvent() foreach($this->events as $event) { $color = $event['color']; $title = $event['title']; $link = $event['link']; $eventdate = $event['date']; $from = strtotime($event['from']); $to = strtotime($event['to']); $starttime = $event['starttime']; $endtime = $event['endtime']; $details = $event['details']; $location = $event['location']; if($date == date('Y-n-j',strtotime($eventdate))) { $cellevents[] = array( 'color'=>$color, 'title'=>$title, 'link'=>$link, 'date'=>$eventdate, 'from'=>$from, 'to'=>$to, 'starttime'=>$starttime, 'endtime'=>$endtime, 'details'=>$details, 'location'=>$location ); } if($this->displaytype == 'mini' && $date == date('Y-n-j',strtotime($eventdate))) { // mini calendar $style .= 'background:' . $color . ';'; // shows the color for the last event listed for the day } } } // sort by starttime for the cell if(count($cellevents)>0){ $cellevents = $this->arraySort($cellevents,'starttime'); } if($date == date('Y-n-j')) { $addclass .= ' current-day'; // if processing the current day } if(in_array($this->getDay($date),array('Saturday','Sunday'))) { $addclass .= ' weekend'; // if a weekend } if($this->getDay($date,0)==$this->weekstartday) { $addclass .= ' week-start'; // if the weekstartday } if($this->arraySearch($date,$cellevents)!==false) { $addclass .= ' has-events'; // if the date has events } else if(strpos($class,'normal-day-heading')===false) { $addclass .= ' no-events'; // no events } $combinedclass = $class.$addclass; // combine all classes $html = '<'.$tag.' class="' . $combinedclass .'"'; // check/set links for mini calendar if($this->minilinkbase!='' && $this->displaytype=='mini') { if($this->linktarget=='_blank') $html .= ' onClick="window.open(\''.$this->minilinkbase.'?date='.$date.'\', \'_blank\')"'; else $html .= ' onClick="'.$this->linktarget.'.location=\''.$this->minilinkbase.'?date='.$date.'\'"'; } } if($style) $html .= ' style="' . $style . '"'; if($this->displaytype == 'mini') { $content = $day; // day number or prev/next month cell content } else { $content = '
'.$day.'
'; // day number or prev/next month cell content } if(count($cellevents) > 0) { $content .= '
    '; $eventcontent = ''; foreach($cellevents as $cellevent) { $cellevent['color2'] = $this->colourBrightness($cellevent['color'],-0.89); // set gradient color based on event color $eventcontent .= '
  • '; if($cellevent['starttime']!='') // add starttime to the event label if available $eventcontent .= ''.str_replace(array('am','pm'),array('a','p'),date($this->timeformat,$cellevent['starttime'])); $eventcontent .= ' '; $eventcontent .= $cellevent['title']; $eventcontent .= '
    '; if($cellevent['starttime']!='') { // event details - hidden until clicked (full) $eventtime = '
    Time: '.date($this->timeformat,$cellevent['starttime']); if($cellevent['endtime']!='') $eventtime .= "-".date($this->timeformat,$cellevent['endtime']); $eventtime .= '
    '; $eventcontent .= $eventtime; } if($cellevent['location']!='') $eventcontent .= '
    Location: '.$cellevent['location'].'
    '; if($cellevent['link']!='') $eventcontent .= ''; if($cellevent['details']!='') $eventcontent .= '
    Details:
    '.$cellevent['details'].'
    '; $eventcontent .= '
    '; $eventcontent .= '
  • '; } $content .= $eventcontent; $content .= '
'; } $html .= '>' . $content . ''; return $html; } // calendar footer for all displaytypes function calendar_foot($content='') { if(in_array($this->displaytype,array('full','mini'))) { $html = '
 
'; $html .= $this->cal_previous(); // previous month link if($this->displaytype == 'full' && $this->monthselector === true) { $html .= $this->month_selector(); // month selector } else { $html .= ''.$this->monthname.' '.$this->year.''; } $html .= $this->cal_next(); // next month link if($this->displaytype!='mini') $html .= $this->cal_viewmode(); // viewmode buttons $html .= '
 
'; } else { $html = '
'; } return $html; } // add an event to the events array function addEvent($arr) { $from = array_key_exists('from',$arr)?$arr['from']:''; $to = array_key_exists('to',$arr)?$arr['to']:$arr['from']; $starttime = array_key_exists('starttime',$arr)?strtotime($arr['starttime']):''; $endtime = array_key_exists('endtime',$arr)?strtotime($arr['endtime']):''; $color = array_key_exists('color',$arr)?$arr['color']:''; $title = array_key_exists('title',$arr)?$arr['title']:''; $details = array_key_exists('details',$arr)?$arr['details']:''; $location = array_key_exists('location',$arr)?$arr['location']:''; $link = array_key_exists('link',$arr)?$arr['link']:''; if(!in_array($this->displaytype,array("list","mini-list"))) { // mini and full cal $eventdays = $this->dateDiff($from,$to); // get the difference in days between the two dates if($eventdays < 0) return; // return if $to < $from for( $i=0; $i <= $eventdays; $i++ ) { $date = strtotime(date("Y-m-d", strtotime($from)) . " +".$i." day"); $date = date("Y-n-j",$date); if($from >= strtotime($this->year.'-'.$this->month) || strtotime($to) >= strtotime($this->year.'-'.$this->month)) { $this->events[] = array( 'color'=>$color, 'title'=>$title, 'link'=>$link, 'date'=>$date, 'from'=>$from, 'to'=>$to, 'starttime'=>$starttime, 'endtime'=>$endtime, 'details'=>$details, 'location'=>$location); } } } else { // event list $date = $from; // only add events that start or end today or in the future if($from >= strtotime($this->year.'-'.$this->month.'-'.$this->day) || strtotime($to) >= strtotime($this->year.'-'.$this->month.'-'.$this->day)) { $this->events[] = array( // for event list it will display in the order events are added 'color'=>$color, 'title'=>$title, 'link'=>$link, 'date'=>$date, 'from'=>strtotime($from), 'to'=>strtotime($to), 'starttime'=>$starttime, 'endtime'=>$endtime, 'details'=>$details, 'location'=>$location); } } } // add an event to the events array function addGoogleCalendar($arr) { $feed = str_replace('basic','full',$arr['xmlfeed']); // make sure we are getting the full feed $start_min = array_key_exists('startdate',$arr)?$arr['startdate']:''; $start_max = array_key_exists('enddate',$arr)?$arr['enddate']:''; $color = $arr['color']; $link = array_key_exists('link',$arr)?$arr['link']:''; // prepare a few values for the google feed link if(in_array($this->displaytype,array('full','mini'))) { $startdate = $this->year.'-'.date('m',strtotime($this->year.'-'.$this->month.'-01')).'-'.date('d',strtotime($this->year.'-'.$this->month.'-01')); $enddate_parts = $this->calcDate($startdate,'+1','month'); $enddate = date('Y-m-d',strtotime($enddate_parts['year'].'-'.$enddate_parts['month'].'-'.$enddate_parts['day'])); } else { // list $startdate = $this->year.'-'.date('m',strtotime($this->year.'-'.$this->month.'-'.$this->day)).'-'.date('d',strtotime($this->year.'-'.$this->month.'-'.$this->day)); $enddate_parts = $this->calcDate($startdate,'+12','months'); $enddate = date('Y-m-d',strtotime($enddate_parts['year'].'-'.$enddate_parts['month'].'-'.$enddate_parts['day'])); } // modified google feed link $feed = $feed.'/?start-min='.$startdate.'&singleevents=true&recurrence-expansion-start='.$startdate.'&start-max='.$enddate.'&recurrence-expansion-end='.$enddate; // use cURL to get the feed into a PHP string variable $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$feed); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $xml = new SimpleXMLElement(curl_exec($ch)); curl_close($ch); // loop through the google calendar xml and assing to array foreach ($xml->entry as $cal){ $ns_gd = $cal->children('http://schemas.google.com/g/2005'); $startTime = explode('T',strval($ns_gd->when->attributes()->startTime)); $startDate = $startTime[0]; $startTime = array_key_exists(1,$startTime)&&$startTime[1]!=''?date($this->timeformat,strtotime($startTime[1])):''; $endTime = explode('T',strval($ns_gd->when->attributes()->endTime)); $endDate = $endTime[0]; $endTime = array_key_exists(1,$endTime)&&$endTime[1]!=''?date($this->timeformat,strtotime($endTime[1])):''; $events[] = array( 'id'=>strval($cal->id), 'published'=>strval($cal->published), 'updated'=>strval($cal->updated), 'title'=>strval($cal->title), 'content'=>nl2br(strval($cal->content)), 'where'=>strval($ns_gd->where->attributes()->valueString), 'link'=>strval($cal->link->attributes()->href), 'authorName'=>strval($cal->author->name), 'authorEmail'=>strval($cal->author->email), 'startTime'=> $startTime, 'endTime'=> $endTime, 'startDate'=> strtotime($startDate), 'endDate'=> strtotime($endDate) ); } if(count($events)>0) { // loop through google events array and add to our calendar foreach ($events as $event) { // fix full day events enddate if($event['startTime']=='') { $tmpdate = $this->calcDate(date($this->dateformat,$event['endDate']), '-1', 'day'); $event['endDate'] = strtotime($tmpdate['year'].'-'.$tmpdate['month'].'-'.$tmpdate['day']); } $this->addEvent( array( "from"=>date('Y-n-j',$event['startDate']), "to"=>date('Y-n-j',$event['endDate']), "starttime"=>$event['startTime'], "endtime"=>$event['endTime'], "color"=>$color, "title"=>$event['title'], "details"=>$event['content'], "location"=>$event['where'], "link"=>$link ) ); } } } // pulls everything together and returns the calendar for all displaytypes function showcal() { global $cal_ID; $html = ''; $html .= $this->set_styles(); // load css $html .= $this->set_js(); // load js $html .= $this->calendar_head(); // set table head if(!in_array($this->displaytype,array("list","mini-list"))) { // mini and full cal $html .= ' '; // render week number on left if($this->weeknumbers=='left' && $this->monthstartday!=$this->weekstartday) { $html .= ''.date('W',strtotime($this->year.'-'.$this->month)).''; } // render previous month cells $emptycells = 0; for($counter=0;$counter<$this->monthstartday-$this->weekstartday;$counter++) { if($counter == 0) $thisclass = 'day-without-date week-start'; // only on first else $thisclass = 'day-without-date'; if($this->displaytype == 'full') { $html .= $this->calendar_cell($this->previousmonth, $thisclass); } else { $html .= $this->calendar_cell(' ', $thisclass); } $emptycells ++; } // render days $rowcounter = $emptycells; $numinrow = 7; $weeknumadjust = $numinrow - ($this->monthstartday-$this->weekstartday); for($counter=1;$counter<=$this->numdaysinmonth;$counter++) { $date = $this->year.'-'.$this->month.'-'.$counter; // render week number on left if($this->weeknumbers=='left' && $this->weekstartday==$this->getDay($date,0)) { $adjustweek = $this->calcDate($date,'+'.$weeknumadjust,'day'); $adjustweek = $adjustweek['year'].'-'.$adjustweek['month'].'-'.$adjustweek['day']; $html .= ''.date('W',strtotime($adjustweek)).''; } $rowcounter ++; $html .= $this->calendar_cell($counter, 'day-with-date', $date); if( $rowcounter % $numinrow == 0 ) { // render week number on right if($this->weeknumbers=='right') { $html .= ''.date('W',strtotime($date)).''; } $html .= ""; if( $counter < $this->numdaysinmonth ) { $html .= ""; } $rowcounter = 0; } } // render next month cells $numcellsleft = $numinrow - $rowcounter; if( $numcellsleft != $numinrow ) { for( $counter = 0; $counter < $numcellsleft; $counter ++ ) { if($this->displaytype == 'full') $html .= $this->calendar_cell($this->nextmonth, 'day-without-date'); else $html .= $this->calendar_cell(' ', 'day-without-date'); $emptycells ++; } } // render week number on right if($this->weeknumbers=='right' && $numcellsleft!=7) { $html .= ''.date('W',strtotime($date)).''; } $html .= ' '; } else { // event list $html .= '
    displaytype=='mini-list') // set mini list width $html .= ' style="width:'.$this->minilistwidth.'"'; $html .= '>'; // sort the array by date if(count($this->events)>0){ $this->events = $this->arraySort($this->events,'from'); } // splice the array after the sort if listlimit is defined if($this->listlimit!==false) { $this->events = array_splice($this->events,0,$this->listlimit); } foreach($this->events as $event) { $event['color2'] = $this->colourBrightness($event['color'],-0.89); if($this->displaytype=='list') { // full event list $html.= '
  • '; $html.= '

    '.$event['title'].'

    '; $html.= '
    '.($event['details']?$event['details']:$this->eventemptytext).'
    '; $html.= '
    '; $html.= ''; if($event['from']!='') $html.= ''; if($event['to']!='' && $event['from']!=$event['to']) $html.= ''; if($event['starttime']!='') $html.= ''; if($event['location']!='') $html.= ''; if($event['link']!='') $html.= ''; $html.= '
    Start:
    '.date($this->dateformat,$event['from']).'
    End:
    '.date($this->dateformat,$event['to']).'
    Time:
    '.date($this->timeformat,$event['starttime']); if($event['endtime']!='') $html.= '-'.date($this->timeformat,$event['endtime']); if($event['starttime']!='') $html.= '
    Location:
    '.$event['location'].'
    Link:
    '.$event['link'].'
    '; } else { // mini event list $html.= '
  • minilinkbase!==false) { // enable link (good for linking to full calendar) $html .= ' class="event-link"'; if($this->linktarget=='_blank') $html .= ' onClick="window.open(\''.$this->minilinkbase.'\', \'_blank\')"'; else $html .= ' onClick="'.$this->linktarget.'.location=\''.$this->minilinkbase.'\'"'; } else if($event['link']!='') { // enable link (links to event url) $html .= ' class="event-link"'; if($this->linktarget=='_blank') $html .= 'onClick="window.open(\''.$event['link'].'\', \'_blank\')"'; else $html .= ' onClick="'.$this->linktarget.'.location=\''.$event['link'].'\'"'; } $html.= '>'; $html.= '
    '.$event['title'].'
    '; $html.= '
    '; if($event['from']!='') $html.= ''.date($this->dateformat,$event['from']); if($event['to']!='') $html.= '-'.date($this->dateformat,$event['to']); $html.= '
    '; } $html.= '
  • '; } if(count($this->events)<=0) { // if events array is empty $html.= '
  • '; $html.= '
    No Upcoming Events.
    '; $html.= '
  • '; } $html .= '
'; } $html .= $this->calendar_foot(); // remove tabs, line breaks, vertical tabs, null-byte $html = $this->stripWhitespace($html); return $html; } //-------------------------------------------------------------------------------------------- // Helper Functions //-------------------------------------------------------------------------------------------- // returns day of week from passed date (string), $type: 0=number,1=full(Monday,Tuesday,etc),2=abbreviation(Mon,Tue,etc) function getDay($date,$type=1) { $date = date('Y-n-j',strtotime($date)); $date_parts=explode('-', $date); $jd=cal_to_jd(CAL_GREGORIAN,$date_parts[1],$date_parts[2],$date_parts[0]); return jddayofweek($jd,$type); } // returns month from passed date (string), $type: 0=number,1=full(January,February,etc),2=abbreviation(Jan,Feb,etc) function getMonth($date,$type=1) { $date = date('Y-n-j',strtotime($date)); $date_parts=explode('-', $date); $jd=cal_to_jd(CAL_GREGORIAN,$date_parts[1],$date_parts[2],$date_parts[0]); return jdmonthname($jd,$type); } // returns # of days (int) between 2 dates (string) function dateDiff($beginDate, $endDate) { if($endDate=='') return 0; $fromDate = date('Y-n-j',strtotime($beginDate)); $toDate = date('Y-n-j',strtotime($endDate)); $date_parts1=explode('-', $beginDate); $date_parts2=explode('-', $endDate); $start_date=gregoriantojd($date_parts1[1], $date_parts1[2], $date_parts1[0]); $end_date=gregoriantojd($date_parts2[1], $date_parts2[2], $date_parts2[0]); return $end_date - $start_date; } // add/subtract day,week,month,days from startdate function calcDate($startdate,$increment,$unit) { $date = date("Y-n-j",strtotime(date("Y-n-j", strtotime($startdate)) . " ".$increment." ".$unit)); $date = explode('-',$date); $newdate = array('year'=>$date[0],'month'=>$date[1],'day'=>$date[2]); return $newdate; } // recursive array search returns the key of occurance (int) or false if not found function arraySearch($needle, $haystack, $index = null) { $aIt = new RecursiveArrayIterator($haystack); $it = new RecursiveIteratorIterator($aIt); while($it->valid()) { if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($it->current() == $needle)) { return $aIt->key(); } $it->next(); } return false; } function colourBrightness($hex, $percent) { // remove hash $hash = ''; if (stristr($hex,'#')) { $hex = str_replace('#','',$hex); $hash = '#'; } // change hex to rgb $rgb = array(hexdec(substr($hex,0,2)), hexdec(substr($hex,2,2)), hexdec(substr($hex,4,2))); // calculate for ($i=0; $i<3; $i++) { // check if brighter or darker if ($percent > 0) { // lighter $rgb[$i] = round($rgb[$i] * $percent) + round(255 * (1-$percent)); } else { // darker $positivePercent = $percent - ($percent*2); $rgb[$i] = round($rgb[$i] * $positivePercent) + round(0 * (1-$positivePercent)); } // don't allow values greater than 255 if ($rgb[$i] > 255) { $rgb[$i] = 255; } } // change rgb back to hex $hex = ''; for($i=0; $i < 3; $i++) { // convert the decimal digit to hex $hexDigit = dechex($rgb[$i]); // add a leading zero if necessary if(strlen($hexDigit) == 1) { $hexDigit = "0" . $hexDigit; } // append to the hex string $hex .= $hexDigit; } return $hash.$hex; // with hash back in string } function hex2RGB($hexStr, $returnAsString = false, $seperator = ',') { $hexStr = preg_replace("/[^0-9A-Fa-f]/", '', $hexStr); // check hex string $rgbArray = array(); if (strlen($hexStr) == 6) { // if a proper hex code e.g. #RRGGBB $colorVal = hexdec($hexStr); $rgbArray['red'] = 0xFF & ($colorVal >> 0x10); $rgbArray['green'] = 0xFF & ($colorVal >> 0x8); $rgbArray['blue'] = 0xFF & $colorVal; } elseif (strlen($hexStr) == 3) { // if shorthand notation e.g #RGB $rgbArray['red'] = hexdec(str_repeat(substr($hexStr, 0, 1), 2)); $rgbArray['green'] = hexdec(str_repeat(substr($hexStr, 1, 1), 2)); $rgbArray['blue'] = hexdec(str_repeat(substr($hexStr, 2, 1), 2)); } else { return false; // invalid hex color code } // returns the rgb string or the associative array return $returnAsString ? implode($seperator, $rgbArray) : $rgbArray; } // Removes tabs, line breaks, vertical tabs, null-byte. Everything but a regular space. function stripWhitespace($c) { $c = str_replace(array("\n", "\r", "\t", "\o", "\xOB"), '', $c); return trim($c); } // sorts an associative array by values of passed key function arraySort($a,$subkey) { foreach($a as $k=>$v) { $b[$k] = strtolower($v[$subkey]); } asort($b); foreach($b as $key=>$val) { $c[] = $a[$key]; } return $c; } } // end class ?>