We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29525
    • 388 Posts
    Hi all

    I’m really scratching my head on this one. I’m trying to setup a list view of a client calendar. I can get the mini and the custom calendar to display correctly showing the client events as it should. However, the list view comes up blank.

    If I replace the calendar id with the id from my test calendar, the list view works just fine. I just can’t get it to show the client events in the list.

    These display client events as expected.
    [!Calendar? &emails=`[email protected]` &useCache=`0` &offset=`0 hours` &template=`mini`!]
    
    [!Calendar? &emails=`[email protected]` &useCache=`0` &offset=`0 hours` &template=`custom` &display=`calendar`!]


    This displays no events
    [!Calendar? &emails=`[email protected]` &useCache=`0` &offset=`0 hours` &template=`list` &display=`list`!]


    Of course the client’s actual calendar id is in place of: clientcalendarid

    When I use this call with my test calendar it works just fine.

    [!Calendar? &emails=`[email protected]` &useCache=`0` &offset=`0 hours` &template=`list` &display=`list`!]


    I have cleared the cache on modx and my browser and removed the cache files from the assets/snippets/calendar/cache folder.

    Snippet outputs this on the page:
    <ul class="event-list"> </ul>


    Since the snippet is working just fine with my test calendar, is it possible there’s something unique about this particular calendar?

    I don’t know what else to try here. My client awaits. . .

    Any suggestions are much appreciated. Thank you!
      www.terrybarthdesign.com
      • 15510
      • 70 Posts
      Hello, Terry. Long time, no chat.

      I’ve been hacking this snippet for a long time on-and-off and don’t use the list option. Below find the modified version which is my latest release. It has support for private calendar URLs which are important to me.

      I hope this helps.

      kc64

      A typical call with this version is:
      [!Calendar? &emails=`[email protected]/private-63b1d6fab67efa23c590f0208ae5` &display=`custom` &wrapper=`tplEventWrapper` &eachEvent=`tplEachEvent` &eachAltEvent=`tplEachEvent` &limit=`5` !]
      


      tplEventWrapper:
      <div class="event-list">
      [+events+]
      </div>
      


      tplEachEvent:
      <p class="date">[+startMonthName+] [+startDay+], [+startHour+]:[+startMinute+][+startMeridiem+]</p>
      <p class="subject">[+title+]</p>
      


      <?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';
      $eachEvent       = (isset($eachEvent))       ? $eachEvent       : 'default';
      $eachAltEvent    = (isset($eachAltEvent))    ? $eachAltEvent    : 'default';
      $wrapper         = (isset($wrapper))         ? $wrapper         : 'default';
      $display         = (isset($display))         ? $display         : 'calendar';
      $limit           = (isset($limit))           ? $limit           : 10;
      $showPastEvents  = (isset($showPastEvents))  ? $showPastEvents  : true;
      $debug           = (isset($debug))           ? $debug           : false;
      
      /* end of Snippet Parameters */
      
      extract($_GET);    
      $year  = isset($_GET['year'])   ? $year     : date('Y');
      $month = isset($_GET['month'])  ? $month    : date('n');
      
      $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();
      
      $events = array();
      
      for ($i = 0; $i < sizeof($gcalendar_data) ; $i++){
        $items = $gcalendar_data[$i];
        
        $startDate = $items->get_start_time();
        $startDateOffset = $startDate - $offset;
        
        $endDate   = $items->get_end_time();
        $endDateOffset = $endDate - $offset;
        
        $calName   = $items->get_name();
      
        $events[] = array(
          'sortDate'      => $startDate,
          'startDate'     => date("M j, y g:i", $startDateOffset),
          'endDate'       => date("M j, y g:i", $endDateOffset),
          'pubDate'       => date("M j, y g:i", $items->get_publish_date()),
          'title'         => $items->get_title(),
          'where'         => $items->get_location(),
          'link'          => $items->get_link(),
          'status'        => $items->get_status(),
          'description'   => $items->get_description(),
          'startDay'      => date('j', $startDateOffset),
          'startMonth'    => date('n', $startDateOffset),
          'startMonthName'=> date('F', $startDateOffset),
          'startYear'     => date('Y', $startDateOffset),
          'startHour'     => date('g', $startDateOffset),
          'startMinute'   => date('i', $startDateOffset),
          'startMeridiem' => date('a', $startDateOffset),
          'endDay'        => date('j', $endDateOffset),
          'endMonth'      => date('n', $endDateOffset),
          'endYear'       => date('Y', $endDateOffset),
          'endHour'       => date('g', $endDateOffset),
          'endMinute'     => date('i', $endDateOffset),
          'endMeridiem'   => date('a', $endDateOffset),
          'calName'       => $calName,
          'calNameClean'  => str_replace(' ', '-', strtolower($calName)),
          'calEmail'      => $items->get_email()
        );
      }
      
      if ($debug) {
        echo '<h3>Event Data</h3>';
        print_r($events);
      }
        
      $feed->__destruct();
      unset($feed);
      /* end of SimplePie code */
      
      /* beginning of Sorting */
      if ($events) {
        $date = array();
        foreach ($events as $key => $row) {
          $date[$key]  = $row['sortDate'];
        }
      
        if ($order)
          array_multisort($date, SORT_ASC, $events);
        else
          array_multisort($date, SORT_DESC, $events);
      }
      /* end of Sorting */
      
      /* Beginning of Calendar Output Code */
      if ($display == 'calendar') {
        if ($debug) echo '<br/><br/><p>display = ' . $display . '</p>';
        $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 ($events) {
          foreach ($events as $date) {
            if ($date['status'] != "canceled" && $date['startMonth'] == $month && strlen(trim($date['sortDate'])) > 0) {
              $cal->addEvent($date['startDay'], $date);
            }
          }
      
          #echo '<pre>';
          #print_r($events);
          #echo '</pre>';
        }
        $output = $cal->display();
      }
      /* End of Calendar Output */
      
      /* Beginning of List Output */
      elseif ($display == 'list') {
        if ($debug) echo '<br/><br/><p>display = ' . $display . '</p>';
        $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 ($events)
        {
          $innerList = '';
          for ($i = 0; $i < $limit; $i++) {
            if ($events[$i]['startMonth'] == $month )
            {
              if($i % 2) 
                $eachEvent = $tpl['eachEvent'];
              else
                $eachEvent = $tpl['eachEventAlt'];
              
              foreach ($events[$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 */
      elseif ($display == 'custom') {
        if ($debug) echo '<br/><br/><p>display = ' . $display . '</p>';
      
        if ($events) {
          $innerList = '';
          $i = 0;
          foreach ($events as $event) {
            if ($event['startMonth'] == $month ) {
              if($i % 2) 
                $innerList .= $modx->parseChunk($eachEvent, $event, '[+', '+]');
              else
                $innerList .= $modx->parseChunk($eachAltEvent, $event, '[+', '+]');
            }
            $i = $i + 1;
          }
          $str = $modx->getChunk($wrapper);
          $output = str_replace('[+events+]', $innerList, $modx->getChunk($wrapper));
        }
      }
      /* End of Custom Output */
      
      /*Do the Output */
      
      echo $output;
      
        • 29525
        • 388 Posts
        kc64

        Thanks for the response.

        The client calendar is public and I’m able to display those events on the big calendar format and I do need the list format. Would your updates address this?

        In any case, I was in process of posting an update when you response came in. I’ve made some progress. Of sorts. . .

        I removed the big calendar from the page and suddenly the client event list appears. However it is not using the templates in the list folder, it is using the templates from the custom folder for the each of the events and there is no wrapper.

        I know that the list event tpls are working because, as a test, I’ve displayed a list from my test calendar on the same page and if I change the eventtpl in the list folder my test calendar changes accordingly.

        I’ve not specified the custom templates in any of the calls so I’m not sure why it would go there.

        Would you be interested in logging in to look at this for me?

          www.terrybarthdesign.com
          • 15510
          • 70 Posts
          The custom option can provide the same function as the list option but it uses the chunks rather the files for the templating. I recall that the list option has some bugs but don’t recall what they are, off-hand. I consider containing the templates in chunks as a better approach than the file-based solution.

          I’ll help you but first please try the custom option with the chunks for working out the design then, when you have the chunks the way you want them, you can switch back to list and put the chunk contents into the file templates. OK?
            • 29525
            • 388 Posts
            kc64

            Thank you for help!

            I copied your revised code in the calendar.inc.php file.

            I’ve revised the call to this
            [!Calendar? &emails=`[email protected]` &useCache=`0` &offset=`0 hours` &display=`custom` &tplWrapper=`wrappertpl` &tplEachEvent=`eacheventtpl`!]


            and have created the appropriate chunks with the list tpl.

            The list for the client calendar is still using the eachEvent.tpl in the custom folder while the other list call using my test calendar is using the eachEvent.tpl in the list folder (which is the template I want).

            Thank you!
              www.terrybarthdesign.com
              • 11887
              • 34 Posts
              Hi all

              I'm desperately looking for a calendar snippet for Evo that pulls from Google Calendar and came across a couple; this one plus another (I forget its name).

              Both use SimplePie, however SimplePie isn't really compatible with the latest version of PHP (bizarrely their website suggests it works perfectly fine, but loads of people have posted issues with the fact the latest version of PHP has withdrawn support for the operator =&... PHP gives the following error, "Assigning the return value of new by reference is deprecated")

              I've tried various hacks to the Simplepie.inc files included in the ModX Calendar distributions (e.g. this one!) to no avail.

              Does anyone know of a snippet that will allow me to pull from a public Google Events calendar and style the results somehow - that works with the latest version of PHP?

              Thanks! [ed. note: hazymat last edited this post 14 years, 4 months ago.]
                • 42816
                • 1 Posts
                I have been trying to sort a multi feed using the array or merging and using the google simplepie addon with no luck. Although I have gotten it to work with one feed by changing a few things as sort date to false and changing the calendar url '/public' to '/full'.

                Has this issue been resolved? I'd like a solution..


                Thanks
                  • 29201
                  • 239 Posts
                  Is SimplePie still incompatible with PHP 5.4.1?
                    • 29201
                    • 239 Posts
                    Did you ever resolve this? I've got three sites that use this and need a fix sad

                    Quote from: hazymat at May 15, 2012, 12:44 AM
                    Hi all

                    I'm desperately looking for a calendar snippet for Evo that pulls from Google Calendar and came across a couple; this one plus another (I forget its name).

                    Both use SimplePie, however SimplePie isn't really compatible with the latest version of PHP (bizarrely their website suggests it works perfectly fine, but loads of people have posted issues with the fact the latest version of PHP has withdrawn support for the operator =&... PHP gives the following error, "Assigning the return value of new by reference is deprecated")

                    I've tried various hacks to the Simplepie.inc files included in the ModX Calendar distributions (e.g. this one!) to no avail.

                    Does anyone know of a snippet that will allow me to pull from a public Google Events calendar and style the results somehow - that works with the latest version of PHP?

                    Thanks!
                      • 11887
                      • 34 Posts
                      Quote from: taiyo1578 at Dec 18, 2013, 04:28 PM
                      Did you ever resolve this? I've got three sites that use this and need a fix sad

                      I didn't resolve this.

                      Ended up integrating a php calendar script (paid script) into a basic snippet.