We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14050
    • 788 Posts
    Quote from: ejcross at Mar 01, 2007, 05:55 PM

    Ok, thanks! I will play around with that and see what it does.

    As for the feed with recurring events, I am trying to figure it out also. When you parse the date in the snippet, is it pulling data for the Starting Day (which in recurring events I assume is the created on day) or is it pulling for the First Start day (which is what the recurring event date actually is)?

    Where would I find it in the snippet and other files for this?

    Thanks!

    For recurring events it just doesn’t parse the date at all.

    Description to be parsed:
    Recurring Event
    First start: 2007-03-03 EST
    Duration: 86400
    Where: A shift - on duty
    Event Status: confirmed
    Event Description: Lt. Webster, Lt. Jones, FFM Adams, FFE Maher, FFE Weaver, FFE Schwanenberger

    To parse the date, I look for the text string "When:"

    Look at this code here if you want to try and do something with recurring events:

    // Extract the 'when' information from the item summary, and ignore everything else
    			$from = textBetween("When:","<",$description);
    			if (strlen($from) > 17) {
    				$from = textBetween("When:","&",$description);
    				$startDate = date($dateFormat,strtotime(substr($from,0,17)));
    				$startTime = date($timeFormat,strtotime(textBetween(substr($from,0,17),"to",$description)));
    				$startMonthCal = date('n',strtotime(substr($from,0,17)));
    				$startDay = date('j',strtotime(substr($from,0,17)));
    				$startYear = date('Y',strtotime(substr($from,0,17)));
    				$endTime = substr($from, strpos($from,"to")+2);
    				$tempEndTime = $endTime;


    You could probably just add a conditional that says something like this:

    // Extract the 'when' information from the item summary, and ignore everything else
    			if (strpos($description, "When:")) {
                                                          $from = textBetween("First start:","<",$description);
                                                     }
                                                     else {
                                                   $from = textBetween("When:","<",$description);
                                                    }
    			if (strlen($from) > 17) {
    				$from = textBetween("When:","&",$description);
    				$startDate = date($dateFormat,strtotime(substr($from,0,17)));
    				$startTime = date($timeFormat,strtotime(textBetween(substr($from,0,17),"to",$description)));
    				$startMonthCal = date('n',strtotime(substr($from,0,17)));
    				$startDay = date('j',strtotime(substr($from,0,17)));
    				$startYear = date('Y',strtotime(substr($from,0,17)));
    				$endTime = substr($from, strpos($from,"to")+2);
    				$tempEndTime = $endTime;


    That should get you started.
      Jesse R.
      Consider trying something new and extraordinary.
      Illinois Wine

      Have you considered donating to MODx lately?
      Donate now. Every contribution helps.
      • 15987
      • 786 Posts
      Jesster, I think I’ve got it figured out for you. I re-wrote part of the snippet that process the feed information, so now the following works:

      • No more strtotime errors in the error log, I adjusted the calls to this and only make the call twice now.
      • All day events are processed correctly (I’m not sure if this was a problem before but at some point in my testing they went away.)
      • I made recurring events work, this was actually done by just adding a parameter to the request string to google. It just makes recurring events show up as single items each time they happen.
      • I remove the description if none is found in the xml.

      So let me know if it works ok for you, or if there are any questions about my changes.

      I only changed the snippet file and have included it below.

      Kyle
        • 8619
        • 229 Posts
        Kyle,

        Thanks a TON!

        It appears to work now, especially with the recurring events, however, some of them are not showing up. It is missing random days of recurring events.

        I’ll PM you with the login details for my site so you can see it.

        Thanks again!
          • 14050
          • 788 Posts
          I just threw it up on a test version and it seems to work fine. Thanks for improving the snippet. What do think is the best way for allowing the class attached to the event for CSS styling purposes? I was thinking of just having the user declare some separator and parsing that out of the description for the event to set the class as I described above. I think it would solve the problem with styling you were talking about ejcross.
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 8619
            • 229 Posts
            That would work for me. I’m wondering though how this snippet handles multiple calendars from the Google feed? If I have a calendar called ’Training’ and then the separate one called ’Staffing’, could I just pull the Training calendar data only for the feed and place only that information on a separate page? That would take care of the styling issue for me then.
              • 15987
              • 786 Posts
              here is how you would need to split out the calendars into separate calls:

              open up google calendar and go to settings.
              select the first calendar you would like to setup from the calendars page.
              where it says calendar address click the xml icon
              copy what it says the link should be between the words filter/xxxxxxx/public

              so whatever is in the xxxxxxx part should go in the parameter &email

              this should be different for each of your calendars.
                • 14050
                • 788 Posts
                Also...there is a small bug in the code that Kyle posted that can cause your afternoon start times to show up as morning start times...i.e. (pm becomes am).

                On line 180 change this:

                if (strlen($useInfo['startTime']) == 3) { $useInfo['startTime'] = '0' . substr($useInfo['startTime'],0,1) . ':00' . substr($fromInfo['startTime'],1,2); }


                to

                if (strlen($useInfo['startTime']) == 3) { $useInfo['startTime'] = '0' . substr($useInfo['startTime'],0,1) . ':00' . substr($useInfo['startTime'],1,2); }


                Fixed version is attached
                  Jesse R.
                  Consider trying something new and extraordinary.
                  Illinois Wine

                  Have you considered donating to MODx lately?
                  Donate now. Every contribution helps.
                  • 15987
                  • 786 Posts
                  Jesse,
                  I found that there is also a way to get a full feed with more information from google than the basic feed that is now being returned. I am going to look into it and see if it would require less parsing in the snippet if the full version is just pulled in. I’ll let you know if I find anything worth updating.
                    • 14050
                    • 788 Posts
                    In my older version I originally used the full feed, but it started causing problems and I reverted back to the basic as it was easier for a hobbyist coder to parse :-D It should be easier, if you know how to code, to just parse the XML by grabbing an "<entry></entry>" and then parsing out the "<link>,<content>,<gd:when>, and <gd:where>." And now that I think about it...I don’t remember the <entry></entry> tags before. That might have made things not that difficult, even for a hobbyist :-D

                    Ideally I could have figured out how to use the calendar API:

                    http://code.google.com/apis/calendar/overview.html

                    The PHP library for it:

                    http://framework.zend.com/download/gdata

                    Then we could provide for a way for users to add simple events from a MODx frontend form and do other neat things using Google as the calendar backend.

                    And I just started to look at the docs again since they didn’t have singleevents as a parameter before, and they now allow "sortorder" in both directions, yet it doesn’t seem to work. Any ideas Kyle?

                    Example feed:
                    http://www.google.com/calendar/feeds/[email protected]/public/basic?start-min=2007-03-02&start-max=2007-04-01&singleevents=true&sortorder=ascending

                    That would because we could then get rid of the sorting logic in the snippet to make it more efficient.
                      Jesse R.
                      Consider trying something new and extraordinary.
                      Illinois Wine

                      Have you considered donating to MODx lately?
                      Donate now. Every contribution helps.
                      • 15987
                      • 786 Posts
                      Looks like simplepie parses out all of the necessary information, so I’m not sure it is worth changing unless its worth re-writing the whole thing. Maybe there is a config in simplepie to include all of the necessary bits, but I have not used it much so I will do some searching on that.

                      Edit: Looks like simplepie will be adding support for retrieving all elements in a future version, so I think it will have to wait.