We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27731
    • 9 Posts
    Hello,

    Well, yes... I at least think that I’ve made my calendar public - there is this fairly straight forward setting for this.

    Anyway - just to be sure is why I tried with the public swedish holiday calendar, but neither that one works...?

    Or maybe I should put the question like this: How do I best find "truly" public calendars to test with?

    taiyo1578 - could you possibly expose which calendar address you’re using - then I can test with yours?
      • 29201
      • 239 Posts
      smf,

      slam this into your snippet:

      [!Calendar? &emails=`[email protected]` &offset=`-2 hours` &template=`default`!]

      just tested it and it works fine.

      eliot
        • 27731
        • 9 Posts
        There is some magic going on... You would not believe how many times I’ve tried this, but no result. Now when I copy your sting in, it works at once...

        I’ve tried so many variants; spaces ahead and after the parameter, copying from the demo site, and then strictly just replacing the address. No success - until now!

        Thanks!
          • 27731
          • 9 Posts
          Ah, now figured it out!

          What’s happening is that when I manually type the snippet call (the address), MODx (of some reason) automatically creates a link of the "&emails=`[email protected]`". That is, it gets blue and underlined.

          If I select the snippet call, and does the "Break links" command, then the blue underlining disappears. Then the snippet call works!
            • 40045
            • 534 Posts
            Hi,

            thanks for this great snippet (before I found it I tried it with pieX only, meaning SimplePie, but I couldn’t control the things pulled from the feed very good...for example the description has data in it, I don’t want to display and I didn’t find a solution to get rid of it...)

            I use the list-template and I have a problem: It displays only 3 events, it doesn’t matter if I set a limit or not (should display 10 then or am I wrong?), when I take another template, the events are there, so I don’t know where to search for the problem...tried also the "finite"-list-thing from page 4 (of this thread) but with no success...but on your demo I see 5 events, so I guess I’m doing something wrong =)...anybody has an idea what it could be?

            here my snippet call:
            [[Calendar? &emails=`[email protected]` &offset=`0 hours` &template=`list` &display=`finitelist` &useCache=`false` &showPastEvents=`false` &dayplus=`10` limit=`5`]]


            (it also didn’t work without limit & dayplus)

            thx for any advice!

            EDIT: I’m not sure, but could it be that only the events from one month are displayed?
              • 15510
              • 70 Posts
              ChuckTrukk--

              I see so many accolades for this snippit that it must be the case that I am doing something really stupid. I get nothing from the call--nothing is returned. My call is below (with a few characters changed to protect the privacy of the calendar.

              [!Calendar? &emails=`[email protected]/private-f83cea10dd8b86170f1c0f529a14f0c08` &offset=`-2 hours` &template=`list` &display=`list` &dayplus=`10` limit=`5`!]


              Any suggestions? Are there dependencies that are not mentioned in the installation instructions?

              Thanks,
              kc64
                • 15510
                • 70 Posts
                I’ve done a little probing and found the cause of my problem. Similar to this post http://modxcms.com/forums/index.php/topic,29262.0.html, the code makes the use of the private XML email impossible. I will search for a simple way to grok the address into the needed structure and post back.
                  • 15510
                  • 70 Posts
                  ChuckTrukk--

                  At around line 53 of calendar.inc.php, I modified the code to this:

                  $emails = explode(',', $emails);
                  $urls 	= array();
                  foreach ($emails as $email){
                      if (preg_match('/([\w\d]*@[\w.]*google.com)\/private-([\w\d]*)/', $email, $email_chunks))
                      $urls[] = trim(SimplePie_GCalendar::create_feed_url($email_chunks[1], $email_chunks[2]));
                      else
                      $urls[] = trim(SimplePie_GCalendar::create_feed_url($email));
                  }
                  


                  This seems to have worked for my need to use the private address as shown in my penultimate post. Would you mind to look it over and consider incorporating it into a future version?

                  Thanks,
                  kc64
                    • 15510
                    • 70 Posts
                    @mrhaw: thanks for the note.

                    I have hacked a little more on the code. (I hope you don’t mind, ChuckTrukk.) I needed to customize the chunks that are used so I added some tpl parameters that can be used to stow the templates into MODx chunks rather than in the file system. The moded file is shown below. (Can I make an attachment to this post?) I named the new parameters "tplEachEvent", "tplEachEventAlt", and "tplWrapper". These are used if the "display" param is set to "custom" rather than "calendar" or "list".

                    <?php
                    #$basePath = '/Users/prowebscape/Sites/CMS/MODx/current/assets/snippets/calendar/';
                    require_once($basePath.'classes/simplepie/simplepie.inc');
                    require_once($basePath.'classes/class.simplepie-gcalendar.php');
                    require_once($basePath.'classes/class.Calendar_Events.php');
                    
                    /* Snippet Parameters */
                    $useModx     	= (isset($useModx))			? $useModx	 		: true;
                    $emails      	= (isset($emails))   		? $emails    		: "[email protected]";
                    $offset     	= (isset($offset))  		? $offset   		: "now";
                    $order      	= (isset($order))   		? $order    		: true;
                    $useCache   	= (isset($useCache))		? $useCache 		: true;
                    $template   	= (isset($template))		? $template 		: 'default';
                    $tplEachEvent   = (isset($tplEachEvent))    ? $tplEachEvent     : 'default';
                    $tplEachEventAlt= (isset($tplEachEventAlt)) ? $tplEachEventAlt  : 'default';
                    $tplWrapper     = (isset($tplWrapper))      ? $tplWrapper       : 'default';
                    $display    	= (isset($display)) 		? $display  		: 'calendar';
                    $limit      	= (isset($limit))   		? $limit    		: 10;
                    $showPastEvents	= (isset($showPastEvents))  ? $showPastEvents   : true;
                    /* end of Snippet Parameters */
                    
                    extract($_GET);    
                    $year  = isset($_GET['year'])   ? $year     : date('Y');
                    $month = isset($_GET['month'])  ? $month    : date('m');
                    
                    $startMin = gmdate('Y-m-d',mktime(0, 0, 0, gmdate($month)-2  , gmdate("d"), gmdate($year)));
                    $startMax = gmdate('Y-m-d',mktime(0, 0, 0, gmdate($month)+2  , gmdate("d"), gmdate($year)));
                    
                    if (!$showPastEvents) {
                        $startMin = date("Y-m-d");
                    }
                    
                    /* Set Correct Offset */
                    $offset = (strtotime("now")-strtotime($offset));
                    
                    /* Set URL to use */
                    if ($useModx) {
                    	/* Modx Site */
                    	$docId     	= $modx->documentIdentifier;
                    	$this_page 	= $modx->makeUrl($docId);
                    
                    	$url_arg	= '&';
                    	if($modx->config['friendly_urls'] == 1) {
                      		$arg = '?';
                    	}
                    	
                    	$this_page .= $url_arg;
                    } else {
                    	/* Non-Modx Site */
                    	$this_page = basename($_SERVER['REQUEST_URI']);
                    	if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page));
                    	$this_page  = 'index.php';
                    	$this_page .= '?';
                    }
                    
                    $emails = explode(',', $emails);
                    $urls 	= array();
                    foreach ($emails as $email){
                        if (preg_match('/([\w\d]*@[\w.]*google.com)\/private-([\w\d]*)/', $email, $email_chunks))
                        $urls[] = trim(SimplePie_GCalendar::create_feed_url($email_chunks[1], $email_chunks[2]));
                    	else
                    	$urls[] = trim(SimplePie_GCalendar::create_feed_url($email));
                    }
                    
                    $feed = new SimplePie_GCalendar();
                    
                        /* GCalendar Parameters */
                        $feed->set_show_past_events(1);
                        $feed->set_sort_ascending(1);
                        $feed->set_orderby_by_start_date(1);
                        $feed->set_expand_single_events(1);
                        $feed->set_start_min_date($startMin);
                        $feed->set_start_max_date($startMax);
                        $feed->set_max_results();
                        $feed->set_cal_query();
                    
                        /* SimplePie Parameters */
                        if ($useCache)
                        $feed->set_cache_location($basePath . 'cache');
                        else
                        $feed->enable_cache(false);
                        
                        $feed->set_feed_url($urls);
                    	$feed->enable_order_by_date(FALSE);
                    	$feed->init();
                    	$feed->handle_content_type();
                    	$gcalendar_data = $feed->get_items();
                    	
                    	$cal_dates = array();
                    	
                    	for ($i = 0; $i < sizeof($gcalendar_data) ; $i++){
                            $item = $gcalendar_data[$i];
                    		
                    		$startDate = $item->get_start_time();
                    		$endDate   = $item->get_end_time();
                    		$calName   = $item->get_name();
                            $cal_dates[] = array(
                                    'sortDate'      => $item->get_start_time(),
                                    'startDate'     => date("M j, y g:i", $startDate - $offset),
                                    'endDate'       => date("M j, y g:i", $endDate - $offset),
                                    'pubDate'       => date("M j, y g:i", $item->get_publish_date()),
                                    'title'         => $item->get_title(),
                                    'where'         => $item->get_location(),
                                    'link'          => $item->get_link(),
                                    'status'        => $item->get_status(),
                                    'description'   => $item->get_description(),
                                    'startDay'      => date('j', $startDate - $offset),
                                    'startMonth'    => date('n', $startDate - $offset),
                                    'startYear'     => date('Y', $startDate - $offset),
                                    'startHour'     => date('g', $startDate - $offset),
                                    'startMinute'   => date('i', $startDate - $offset),
                                    'startMeridiem' => date('A', $startDate - $offset),
                                    'endDay'        => date('j', $endDate - $offset),
                                    'endMonth'      => date('n', $endDate - $offset),
                                    'endYear'       => date('Y', $endDate - $offset),
                                    'endHour'       => date('g', $endDate - $offset),
                                    'endMinute'     => date('i', $endDate - $offset),
                                    'endMeridiem'   => date('A', $endDate - $offset),
                                    'calName'		=> $calName,
                                    'calNameClean'	=> str_replace(' ', '-', strtolower($calName)),
                                    'calEmail'		=> $item->get_email()
                                );
                    	}
                    
                    	
                    $feed->__destruct();
                    unset($feed);
                    /* end of SimplePie code */
                    
                    /* beginning of Sorting */
                    if ($cal_dates)
                    {
                        $date = array();
                        foreach ($cal_dates as $key => $row) {
                            $date[$key]  = $row['sortDate'];
                        }
                    
                        if ($order)
                        array_multisort($date, SORT_ASC, $cal_dates);
                        else
                        array_multisort($date, SORT_DESC, $cal_dates);
                    }
                    /* end of Sorting */
                    
                    /* Beginning of Calendar Output Code */
                    if ($display == 'calendar')
                    {
                        $cal = new Calendar_Events ($year, $month);
                            /*Calendar Parser parameters */
                            $cal->setDayNameFormat('%a');
                            $cal->url = $this_page;
                            if ($template)
                            {
                                $cal->tpl['calendar']      = file_get_contents($basePath. 'templates/' .$template. '/calendar.tpl');
                                $cal->tpl['dayNoEvent']    = file_get_contents($basePath. 'templates/' .$template. '/dayNoEvent.tpl');
                                $cal->tpl['dayWithEvent']  = file_get_contents($basePath. 'templates/' .$template. '/dayWithEvent.tpl');
                                $cal->tpl['eachEvent']     = file_get_contents($basePath. 'templates/' .$template. '/eachEvent.tpl');
                                $cal->tpl['notInMonth']    = file_get_contents($basePath. 'templates/' .$template. '/notInMonth.tpl');
                            } else {
                                $cal->tpl['calendar']      = file_get_contents($basePath. 'templates/default/calendar.tpl');
                                $cal->tpl['dayNoEvent']    = file_get_contents($basePath. 'templates/default/dayNoEvent.tpl');
                                $cal->tpl['dayWithEvent']  = file_get_contents($basePath. 'templates/default/dayWithEvent.tpl');
                                $cal->tpl['eachEvent']     = file_get_contents($basePath. 'templates/default/eachEvent.tpl');
                                $cal->tpl['notInMonth']    = file_get_contents($basePath. 'templates/default/notInMonth.tpl');
                            }
                        
                            if ($cal_dates)
                            {
                        
                                foreach ($cal_dates as $date)
                                {
                                    if ($date['status'] != "canceled" && $date['startMonth'] == $month && strlen(trim($date['sortDate'])) > 0)
                                    {
                                        $cal->addEvent($date['startDay'], $date);
                                    }
                                }
                                
                                #echo '<pre>';
                                #print_r($cal_dates);
                                #echo '</pre>';
                            }
                        $output = $cal->display();
                    }
                    /* End of Calendar Output */
                    
                    /* Beginning of List Output */
                    if ($display == 'list')
                    {
                        $tpl['wrapper']      = file_get_contents($basePath. 'templates/' .$template. '/wrapper.tpl');
                        $tpl['eachEvent']    = file_get_contents($basePath. 'templates/' .$template. '/eachEvent.tpl');
                        $tpl['eachEventAlt'] = file_get_contents($basePath. 'templates/' .$template. '/eachEventAlt.tpl');
                    
                        if ($cal_dates)
                        {
                            $innerList = '';
                            for ($i = 0; $i < $limit; $i++)
                            {
                            	if ($cal_dates[$i]['startMonth'] == $month )
                            	{
                    	            if($i % 2) 
                                    $eachEvent = $tpl['eachEvent'];
                    	            else
                    	            $eachEvent = $tpl['eachEventAlt'];
                    	            
                    	            foreach ($cal_dates[$i] as $key => $value)
                    	            {
                    	                $eachEvent = str_replace('[+' . $key . '+]', $value, $eachEvent);
                    	            }
                    	            $innerList .= $eachEvent;
                            	}
                            }
                            $output = str_replace('[+events+]', $innerList, $tpl['wrapper']);
                        }
                    
                    }
                    /* End of List Output */
                    
                    /* Beginning of Custom Output */
                    if ($display == 'custom')
                    {
                        $tpl['wrapper']      = $modx->getChunk('tplWrapper');
                        $tpl['eachEvent']    = $modx->getChunk('tplEachEvent');
                        $tpl['eachEventAlt'] = $modx->getChunk('tplEachEventAlt');
                    
                        if ($cal_dates)
                        {
                            $innerList = '';
                            for ($i = 0; $i < $limit; $i++)
                            {
                            	if ($cal_dates[$i]['startMonth'] == $month )
                            	{
                    	            if($i % 2) 
                    	            $eachEvent = $tpl['eachEvent'];
                    	            else
                    	            $eachEvent = $tpl['eachEventAlt'];
                    	            
                    	            foreach ($cal_dates[$i] as $key => $value)
                    	            {
                    	                $eachEvent = str_replace('[+' . $key . '+]', $value, $eachEvent);
                    	            }
                    	            $innerList .= $eachEvent;
                            	}
                            }
                            $output = str_replace('[+events+]', $innerList, $tpl['wrapper']);
                        }
                    }/* End of Custom Output */
                    
                    /*Do the Output */
                    
                    echo $output;
                    
                      • 34017
                      • 898 Posts
                      Hey KC,

                      Glad to see you improving on it. I’m in the middle of a few big projects. Just wanted to say go ahead, and Im glad it’s accomplishing what you need.
                        Chuck the Trukk
                        ProWebscape.com :: Nashville-WebDesign.com
                        - - - - - - - -
                        What are TV's? Here's some info below.
                        http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
                        http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008