[EventCalendar] Synchronizing events using ical

Christian Kuratle christian.kuratle at gmx.net
Thu Feb 3 19:57:54 GMT 2011


Hi

 

Thanks for the great plugin!

 

I made a few code changes to get full calendar-posts in MS-Outlook. It
supports multi-line post content and even content with HTML tags (HTML will
be removed in the ical  for Outlook). Just replace the original function and
the Event Calendar can be synchronized by Outlook

 

If you are interested, below is the code. 

 

Another problem: The transferred  time is not correct in the ical file. The
local time is transferred, but the time tag is formatted as UTC time

 

I did a hack in tz.php:

 

/** Converts a WordPress timestamp to UTC. */

function ec3_to_utc($timestamp,$fmt='%Y%m%dT%H%M0')

{

  $result = gmstrftime($fmt,ec3_to_time($timestamp));

  return $result;

}

 

This hack formats the time as local time and you will get the correct time
in Outlook.

May be you will have some time to fix this hack in a future release

 

Regards

Christian

-------------------------------------------------------------

To be replaced in eventcalendar3.php:

 

/** If the parameter ec3_ical is set, then brutally hijack the page and
replace

*  it with iCalendar data.

* (Includes fixes contributed by Matthias Tarasiewicz & Marc Schumann.)*/

function ec3_filter_query_vars_ical($wpvarstoreset=NULL)

{

  //

  // Generate the iCalendar

 

  $name=preg_replace('/([\\,;])/','\\\\$1',get_bloginfo_rss('name'));

  $filename=preg_replace('/[^0-9a-zA-Z]/','',$name).'.ics';

 

  header("Content-Type: text/calendar; charset=" .
get_option('blog_charset'));

  header("Content-Disposition: inline; filename=$filename");

  header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');

  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');

  header('Cache-Control: no-cache, must-revalidate, max-age=0');

  header('Pragma: no-cache');

 

  echo "BEGIN:VCALENDAR\r\n";

  echo "VERSION:2.0\r\n";

  echo "X-WR-CALNAME:$name\r\n";

 

  global $ec3,$wpdb;

 

  $calendar_entries = $wpdb->get_results(

    "SELECT

         post_id,

         sched_id,

         post_title,

         post_excerpt,

         post_content,

         DATE_FORMAT(start,IF(allday,'%Y%m%d','%Y-%m-%d %H:%i')) AS
dt_start,

         IF( allday,

             DATE_FORMAT(DATE_ADD(end, INTERVAL 1 DAY),'%Y%m%d'),

             DATE_FORMAT(end,'%Y-%m-%d %H:%i')

           ) AS dt_end,

         $ec3->wp_user_nicename AS user_nicename,

         IF(allday,'TRANSPARENT','OPAQUE') AS transp,

         allday

       FROM $wpdb->posts p

       LEFT  JOIN $wpdb->users   u ON p.post_author=u.ID

       INNER JOIN $ec3->schedule s ON p.id=s.post_id

       WHERE post_status='publish'

       ORDER BY start"

  );

 

  if($calendar_entries)

    foreach($calendar_entries as $entry)

    {

      // ?? Should add line folding at 75 octets at some time as per RFC
2445.

      $summary=preg_replace('/([\\,;])/','\\\\$1',$entry->post_title);

      $permalink=get_permalink($entry->post_id);

 

      echo "BEGIN:VEVENT\r\n";

      echo "SUMMARY:$summary\r\n";

      echo "URL;VALUE=URI:$permalink\r\n";

      echo "UID:$entry->sched_id-$permalink\r\n";

      $description='';

      

                 $searchItems = array ("'<script[^>]*?>.*?</script>'si",  //
remove JavaScript

                "'<[\/\!]*?[^<>]*?>'si",           // remove HTML-Tags 

                "'([\r\n])[\s]+'",                        // remove spaces 

                "'&(quot|#34);'i",                    // remove
HTML-entities

                "'&(amp|#38);'i",

                "'&(lt|#60);'i",

                "'&(gt|#62);'i",

                "'&(nbsp|#160);'i",

                "'&(iexcl|#161);'i",

                "'&(cent|#162);'i",

                "'&(pound|#163);'i",

                "'&(copy|#169);'i",

                "'&#(\d+);'e",                         //  as  PHP  

                "/\r\n|\r|\n/");                     // line breaks

 

                 $replacements = array ("",

                  "",

                  "\\1",

                  "\"",

                  "&",

                  "<",

                  ">",

                  " ",

                  chr(161),

                  chr(162),

                  chr(163),

                  chr(169),

                  "chr(\\1)",

                  "\\n");

 

     if(strlen($entry->post_content)>0)

      {

                              $description= preg_replace($searchItems,
$replacements, $entry->post_content);

               $description.=' \r\n['.sprintf(__('Autor:
%s'),$entry->user_nicename).']';

      }

      else if(strlen($entry->post_excerpt)>0)

 

      {

                              $description= preg_replace($searchItems,
$replacements, $entry->post_excerpt);

               $description.=' \r\n['.sprintf(__('Autor:
%s'),$entry->user_nicename).']';

      }

      echo "DESCRIPTION:$description\r\n";

      echo "TRANSP:$entry->transp\r\n"; // for availability.

      if($entry->allday)

      {

        echo "DTSTART;VALUE=DATE:$entry->dt_start\r\n";

        echo "DTEND;VALUE=DATE:$entry->dt_end\r\n";

      }

      else

      {

        // Convert timestamps to UTC

        echo
sprintf("DTSTART;VALUE=DATE-TIME:%s\r\n",ec3_to_utc($entry->dt_start));

        echo
sprintf("DTEND;VALUE=DATE-TIME:%s\r\n",ec3_to_utc($entry->dt_end));

      }

      echo "END:VEVENT\r\n";

    }

 

  echo "END:VCALENDAR\r\n";

  exit(0);

}

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://penguin.firetree.net/pipermail/eventcalendar/attachments/20110203/46236ac2/attachment.htm>


More information about the EventCalendar mailing list