We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24393
    • 83 Posts
    does anyone have an example of this snippet on a live site? even a demo would be great—so i can convince my client to use this instead of ical.
      stevesunderland.com
      GRAPHICS | INTERACTIVE | MARKETING
      xhtml + ajax + seo websites powered by modx
      • 3232
      • 380 Posts
      sure you can see a working version on http://canvasli.com/
        • 6747
        • 3 Posts
        I’m managing multiple calendars in google so that I can categorize the events (classes, talks, workshops), and display a list of the appropriate type of events individually.

        The problem is that I also want to be able to display a "master calendar" that integrates the events from these multiple calendars into a single calendar view. I want to do this without having to manage a "master calendar" that I add events to from the other calendars after I create the events. Is there any way to do this? I realize that I can post one after another with multiple snippet calls, but this is not what I’m after. I’d like to be able to display a calendar view with the events from multiple calendars all integrated into one.

        Thanks,
        Dave
          • 14050
          • 788 Posts
          Unfortunately, it will not handle such a task out of the box, unless you can find a Google Feed that provides all the events in a single Feed. The snippet uses SimplePie. Currently, the development version has the ability to merge multiple feeds together. I will not be adding this in until they release the 1.0 version. However, you could take a look at this:

          http://simplepie.org/wiki/tutorial/sort_multiple_feeds_by_time_and_date

          And likely upload the new development version into place and make a few changes to get it to work.

            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 6726
            • 7,075 Posts
            Quote from: jesster444 at Apr 14, 2007, 11:39 AM
            I have pulled out the English constants, and you can translate them, and that will get you started. I would also guess you need to change the function "strtotime" to "strftime" as "strtotime" requires an English date string. Once you get the date logic figured out, I think the rest should all work.

            Since I really need this - I think I’ll give this a go - might need some help since my PHP skills are quite basic, but I’ll be working on this !
              .: COO - Commerce Guys - Community Driven Innovation :.


              MODx est l'outil id
              • 14050
              • 788 Posts
              Good luck David. I will try to help anywhere I can.
                Jesse R.
                Consider trying something new and extraordinary.
                Illinois Wine

                Have you considered donating to MODx lately?
                Donate now. Every contribution helps.
                • 28559
                • 23 Posts
                Thanks for the great mod its going to be useful.

                I haven’t read the entire tread yet but is it possible to put up multiple calenders on the same page?

                ie mine and my GF’s?

                thanks
                steve
                  • 14050
                  • 788 Posts
                  Yes, that should be possible with two separate calls of the snippet on the same page.
                    Jesse R.
                    Consider trying something new and extraordinary.
                    Illinois Wine

                    Have you considered donating to MODx lately?
                    Donate now. Every contribution helps.
                    • 28559
                    • 23 Posts
                    So just pasting the same thing in twice doesn’t work. this is the error that I get.
                    any ideas? I through it together real late last night so I didn’t think to hard about it.

                    Fatal error: Cannot redeclare textbetween() (previously declared in /home/steveome/public_html/Domain/manager/includes/document.parser.class.inc.php(766) : eval()’d code:302) in /home/steveome/public_html/Domain/manager/includes/document.parser.class.inc.php(766) : eval()’d code on line 315

                    Thanks
                    Steveo
                      • 14050
                      • 788 Posts
                      At one point it used to work. Basically, it is trying to declare the function "textBetween" twice, which is not going to work.

                      Upload GoogleEvents.inc.php.txt to assets/snippets/GoogleEvents/include/

                      Make sure to rename it to "GoogleEvents.inc.php"

                      Then paste this into your snippet:

                      <?php
                      // Resource Name: GoogleEvents
                      // Author: Jesse Rochman
                      // Forum Alias: jesster444
                      // Version: 1.3.4
                      // Compatible with .951
                      // Released: 1/9/2007
                      // Modified: 3/1/2007 by KyleJ
                      // Modified: 3/2/2007 by Jesse
                      // Inspired by James Cridlands Google Calendar Code
                      //Calendar Class is from Giorgos Tsiledakis Active Calendar
                      
                      $basePath = $modx->config['base_path'];
                      $siteURL = $modx->config['site_url'];
                      
                      // Your Gmail address
                      $email = isset($email)? $email : "[email protected]";
                      
                      //Set month and day names.  You can translate here.
                      $dayNames1 = array('S','M','T','W','T','F','S');
                      $dayNames3 = array('Sun','Mon','Tue','Wed','Thur','Fri','Sat');
                      $dayNamesFull = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
                      $monthNames = array('January','February','March','April','May','June','July','August','September','October','November','December');
                      
                      if (!isset ($dayNameSize)) {
                      	$dayNameSize = $dayNames3;
                      	} elseif (strtolower($dayNameSize) == 'full') {
                      	$dayNameSize = $dayNamesFull;
                      	} elseif ($dayNameSize == 1) {
                      	$dayNameSize = $dayNames1;
                      	} else {
                      	$dayNameSize = $dayNames3;
                      	}
                      
                      //This will determine whether to output the calendar, the list, or both.
                      $outputType = isset($outputType)? $outputType : "both";
                      
                      // Format for date and time
                      $dateFormat = isset($dateFormat)? $dateFormat : "l, F, jS, Y"; // Thursday, 10 March - see http://www.php.net/date for details
                      $timeFormat = isset($timeFormat)? $timeFormat : "g:ia";
                      
                      //Order of Output.  True for Reverse Chronilogical and False for Chronilogical
                      $order = isset($order)? $order : 0;
                      
                      //Show Events For This Many Days Out
                      $lastEvent = isset($lastEvent)? $lastEvent : 30;
                      
                      //Show only this many events
                      $maxEvents = isset($maxEvents)? $maxEvents : 30;
                      
                      //Skip this many events.  This way you can make two snippet calls and jump around
                      $skipEvents = isset($skipEvents)? $skipEvents : 0;
                      
                      // Cache location for your XML file
                      $cache_location= $basePath.'assets/snippets/GoogleEvents/cache';
                      
                      // Here is where your copy of Simplepie lives
                      include_once ($basePath.'assets/snippets/GoogleEvents/php/simplepie.inc');
                      
                      // Here is where included functions get added
                      include_once ($basePath.'assets/snippets/GoogleEvents/include/GoogleEvents.inc.php');
                      
                      //Sets a big or small calendar
                      $calendarType = isset($calendarType)? $calendarType : '';
                      
                      //Determine the first day of the week
                      $firstDay = isset($firstDay)? $firstDay : 0;
                      
                      // Change this to 'true' to see some debug code
                      $debug = isset($debug)? $debug : 0;
                      
                      //Config ends
                      
                      if ($outputType == 'calendar' || $outputType == 'both') {
                      	include_once('assets/snippets/GoogleEvents/source/activecalendar.php');
                      	//For the calendar script
                      	//Variables for Calendar
                      	$myurl='?id='.$modx->documentIdentifier; // the links url is this page
                      	$yearID=false; // init false to display current year
                      	$monthID=false; // init false to display current month
                      	$dayID=false; // init false to display current day
                      	extract($_GET); // get the new values (if any) of $yearID,$monthID,$dayID
                      	$arrowBack="<img src=\"assets/snippets/GoogleEvents/data/img/back.png\" alt=\"<<\" />"; // use png arrow back
                      	$arrowForw="<img src=\"assets/snippets/GoogleEvents/data/img/forward.png\" alt=\">>\" />"; // use png arrow forward
                      	$cal = new activeCalendar($yearID,$monthID,$dayID);
                      }
                      
                      if ($outputType == 'list' || $outputType == 'both') {	
                      	//Grab the templates.  If one isn't passed to the program, then setup a default template.
                      	$defaultTemplate = '<div><h2><a href="[+linkURL+]">[+title+]</a></h2><p>[+startDate+] at [+startTime+]<br />Description: [+content+]</p></div>';
                      	$numberOfEvents = 0;
                      	$tpl = $modx->getChunk($tpl);
                      	$tplOddRow = $modx->getChunk($tplOddRow);
                      	$tplEvenRow = $modx->getChunk($tplEvenRow);
                      	$tplFirstRow = $modx->getChunk($tplFirstRow);
                      	$tplLastRow = $modx->getChunk($tplLastRow);
                      
                      	if ($tpl) {
                      	  $defaultTemplate = $tpl;
                      	}
                      	if (!$tplOddRow) {
                      	  $tplOddRow = $defaultTemplate;
                      	}
                      	if (!$tplEvenRow) {
                      	  $tplEvenRow = $defaultTemplate;
                      	}
                      	if (!$tplFirstRow) {
                      	  $tplFirstRow = $defaultTemplate;
                      	}
                      	if (!$tplLastRow) {
                      	  $tplLastRow = $defaultTemplate;
                      	}
                      }
                      
                      $startMax = date('Y-m-d',mktime(0, 0, 0, date("m")  , date("d")+$lastEvent, date("Y")));
                      
                      if ($debug) {echo "<p>Debug mode is on.</p>";}
                      
                      $calendar_xml_address = "http://www.google.com/calendar/feeds/".$email."/public/basic?start-min=".date("Y-m-d").'&start-max='.$startMax.'&singleevents=true';
                      
                      if ($debug) {echo "<p>Getting <a href='$calendar_xml_address'>XML feed</a></p>";}
                      
                      $feed = new SimplePie();
                      $feed->feed_url($calendar_xml_address);
                      $feed->cache_location($cache_location);
                      //$feed->enable_caching(FALSE);
                      //$feed->enable_xmldump(true);
                      $feed->init();
                      $feed->handle_content_type();
                      
                      if($feed->get_items()) {
                      	foreach($feed->get_items() as $item) {	
                      		//echo '<pre>' . print_r($item,1) . '</pre>';
                      	    $description = $item->get_description();
                      		if ($description) {
                      		    if ($debug) { echo "<p><b>Description to be parsed:</b> <br />".$description."</p>"; }
                      			
                      			//Remove some of the html entity oddities that Google produces like &amp; which displays "&"
                      			$description = str_replace ("&amp;","&",$description);
                      			$description = str_replace ("&#39;","&#39;",$description);
                      			$description = str_replace ("&quot;",""",$description);
                      			
                      			// Extract the 'when' information from the item summary, and ignore everything else
                      			$from = trim(textBetween("When:","<",$description));
                      			if (strlen($from) > 16) {
                      				$from = trim(textBetween("When:","&",$description));
                      			}
                      			
                      			//Put all event information into an array
                      			$from = str_replace(',','',$from);
                      			$fromInfo = explode(" ",$from);
                      			
                      			if (count($fromInfo) < 8 ) {
                      				$useInfo = array(
                      					'startDow' => $fromInfo[0],
                      					'startMon' => $fromInfo[1],
                      					'startDay' => $fromInfo[2],
                      					'startYear' => $fromInfo[3],
                      					'startTime' => $fromInfo[4],
                      					'endDow' => $fromInfo[0],
                      					'endMon' => $fromInfo[1],
                      					'endDay' => $fromInfo[2],
                      					'endYear' => $fromInfo[3],
                      					'endTime' => $fromInfo[6],
                      				);
                      			} else {
                      				$useInfo = array(
                      					'startDow' => $fromInfo[0],
                      					'startMon' => $fromInfo[1],
                      					'startDay' => $fromInfo[2],
                      					'startYear' => $fromInfo[3],
                      					'startTime' => $fromInfo[4],
                      					'endDow' => $fromInfo[6],
                      					'endMon' => $fromInfo[7],
                      					'endDay' => $fromInfo[8],
                      					'endYear' => $fromInfo[9],
                      					'endTime' => $fromInfo[10],
                      				);
                      			}
                      			//Add a leading zero to the day if none
                      			if (strlen($useInfo['startDay']) < 2) { $useInfo['startDay'] = "0{$useInfo['startDay']}"; }
                      			if (strlen($useInfo['endDay']) < 2) { $useInfo['endDay'] = "0{$useInfo['endDay']}"; }
                      			//Make start time include mintues and leading 0 if necessary for correct time calculation
                      			if (strlen($useInfo['startTime']) == 3) { $useInfo['startTime'] = '0' . substr($useInfo['startTime'],0,1) . ':00' . substr($fromInfo['startTime'],1,2); }
                      			if (strlen($useInfo['startTime']) == 4) { $useInfo['startTime'] = substr($useInfo['startTime'],0,2) . ':00' . substr($useInfo['startTime'],2,2); }
                      			if (strlen($useInfo['startTime']) == 6) { $useInfo['startTime'] = '0' . $useInfo['startTime']; }
                      			//Make end time include mintues and leading 0 if necessary for correct time calculation
                      			if (strlen($useInfo['endTime']) == 3) { $useInfo['endTime'] = '0' . substr($useInfo['endTime'],0,1) . ':00' . substr($useInfo['endTime'],1,2); }
                      			if (strlen($useInfo['endTime']) == 4) { $useInfo['endTime'] = substr($useInfo['endTime'],0,2) . ':00' . substr($useInfo['endTime'],2,2); }
                      			if (strlen($useInfo['endTime']) == 6) { $useInfo['endTime'] = '0' . $useInfo['endTime']; }
                      			
                      			//Convert start date & time to a unix time stamp & fill other vars
                      			$tempStartDate = strtotime("{$useInfo['startDay']} {$useInfo['startMon']} {$useInfo['startYear']} {$useInfo['startTime']}");
                      			$startDate = date($dateFormat,$tempStartDate);
                      			$startDay = $useInfo['startDay'];
                      			$startYear = $useInfo['startYear'];
                      			$startTime = $useInfo['startTime'] ? date($timeFormat,$tempStartDate) : '';
                      			$startMonthCal = date('n',$tempStartDate);
                      			
                      			//Convert end date & time to a unix time stamp & fill other vars
                      			$tempEndTime = strtotime("{$useInfo['endDay']} {$useInfo['endMon']} {$useInfo['endYear']} {$useInfo['endTime']}");
                      			$endDate = date($dateFormat,$tempEndTime);
                      			$endTime = $useInfo['endTime'] ? date($timeFormat,$tempEndTime) : '';
                      
                      			$time = $tempStartDate;	
                      			if ($debug) { 
                      			echo "<p><b>Atempting to parse the following date:</b><br />$from</p>
                      				  <p><b>Parsed Date:</b><br />
                      					 Starting Day: $startDate<br />
                      					 Starting Time: $startTime<br />
                      					 Ending Day: $endDate<br />
                      					 Ending Time: $endTime<br />
                      					 Time Greater Than 0? $time</p>";
                      					 }
                      
                      			// Extract the 'where' information from the item summary, and ignore everything else
                      			$where = textBetween("Where:","<",$description);
                      			if (empty ($where)) $where = '';
                      			if ($debug) {
                      				echo "<p><b>This is what I think the "Where" string should be:</b><br />$where</p>";
                      			}
                      			
                      			// Extract the "Event Description" information from the item summary, and ignore everything else
                      			if (strpos($description,"Event Description: ")) {
                      				$eventDescription = substr($description,strpos($description,"Event Description: ")+18);
                      			} else {
                      				$eventDescription = '';
                      			}
                      
                      			// Extract the link for Google Calendar
                      			$url=$item->get_links();
                      
                      			// Stick into a nice array if it has a valid timestamp (not a recurring event).
                      			if ($time > 0) {
                      				$events[]=array('time'=>$time,'where'=>$where,'title'=>$item->get_title(),'url'=>$url[0],'eventDescription'=>$eventDescription,'startDate'=>$startDate,'startTime'=>$startTime,'endDate'=>$endDate,'endTime'=>$endTime,'startYear'=>$startYear,'startDay'=>$startDay,'startMonthCal'=>$startMonthCal);
                      			}
                      		}
                      	}
                      
                      	// Sort the bookings into time order
                      	if (!$order){
                      		// Sort the events into chronilogical order.
                      		sort($events);
                      		} else {
                      		rsort($events);
                      		}
                      
                      	$counterMaxEvents = 0;
                      	$counterSkipEvents = 0;
                      	foreach($events as $event) {
                      		if ($outputType == 'list' || $outputType == 'both') {
                      			$numberOfEvents++;
                      			if ($counterSkipEvents >= $skipEvents){
                      				//Figure out what template to use
                      				if($numberOfEvents == 1 || $counterSkipEvents == $skipEvents) {
                      					$template = $tplFirstRow;
                      					} elseif ($numberOfEvents == count($events) || $counterMaxEvents == ($maxEvents-1)) {
                      					$template = $tplLastRow;
                      					} elseif (($numberOfEvents & 1) == 0) {
                      					$template = $tplEvenRow;
                      					} else {
                      					$template = $tplOddRow;
                      					}
                      				$counterSkipEvents++;
                      				//Output the data in the appropriate template
                      				if ($counterMaxEvents < $maxEvents) {
                      					$output = str_replace('[+title+]',$event['title'],$template);
                      					$output = str_replace('[+startDate+]',$event['startDate'],$output);
                      					$output = str_replace('[+startTime+]',$event['startTime'],$output);
                      					$output = str_replace('[+endDate+]',$event['endDate'],$output);
                      					$output = str_replace('[+endTime+]',$event['endTime'],$output);
                      					$output = str_replace('[+where+]',$event['where'],$output);
                      					$output = str_replace('[+content+]',$event['eventDescription'],$output);
                      					$output = str_replace('[+eventNumber+]',$numberOfEvents,$output);
                      					$output = str_replace('[+linkURL+]',$event['url'],$output);
                      					echo $output;
                      					$counterMaxEvents++;
                      					} 
                      			} else { 
                      				$counterSkipEvents++;
                      				}
                      			} 
                      			if($outputType == 'calendar' || $outputType == 'both') {
                      				$cal->setEvent($event['startYear'],$event['startMonthCal'],$event['startDay'],"event",$event['url']);
                      				if($calendarType == 'wide') {
                      					$multipleLinesEvent=array($event['title'],$event['startTime'].'-'.$event['endTime']);
                      					$cal->setEventContent($event['startYear'],$event['startMonthCal'],$event['startDay'],$multipleLinesEvent,$event['url']);
                      				}
                      			}
                      	}	
                      	if($outputType == 'calendar' || $outputType == 'both') {
                      			//outPutCalendar($fullMonths, $shortMonths,$mDays, $arrangedEvents);
                      			$cal->setDayNames($dayNameSize);
                      			$cal->setMonthNames($monthNames);
                      			$cal->setFirstWeekDay($firstDay);
                      			$cal->enableMonthNav($myurl,$arrowBack,$arrowForw); // enables navigation controls
                      			print $cal->showMonth();
                      	}
                      
                      	return '';
                      	} else {
                      	return "<p>The feed is unavailable.  This could be caused by the server being down, an incorrect feed address, or if you have no events in your feed.  The feed address you tried to load was <a href='$calendar_xml_address'>$calendar_xml_address</a>.</p>";
                      	}
                      ?>
                        Jesse R.
                        Consider trying something new and extraordinary.
                        Illinois Wine

                        Have you considered donating to MODx lately?
                        Donate now. Every contribution helps.