Author Topic: iCal server  (Read 14874 times)

sadysta

  • Newbie
  • *
  • Posts: 4
    • View Profile
iCal server
« on: March 07, 2009, 11:52:53 am »
This is a script I consider very handy. It dynamically generates calendars in iCal format for a given set of workspaces. It is poorly protected (single, fixed password in GET parameters) but since I'm running a small site for trusted users only and it is tranferred over https it seems sufficient for our needs. Using this script you can import calendar events from OpenGoo to, for example Thunderbird with Lightning extension installed, and stay up-to-date with changes easily (by pressing Reload button in Thunderbird/Lightning :))

Usage Example: https://some.site/opengoo/generate_ical.php?pass=abc123&calendars[]=workspace1&calendars[]=workspace2

Code: [Select]
<?php

define
('ROOT'dirname(__FILE__));
define('APPLICATION_PATH'ROOT '/application');

set_include_path(ROOT PATH_SEPARATOR APPLICATION_PATH);

require_once 
ROOT.'/config/config.php';
require_once 
ROOT.'/environment/environment.php';

require 
APPLICATION_PATH '/functions.php'// __autoload() function is defined here...
@include ROOT '/cache/autoloader.php';

require_once 
ROOT.'/environment/classes/event/CalFormatUtilities.php';

error_reporting(0);

function 
icalendar_export_by_name($project_name)
{
$project Projects::findOne(array('conditions' => 'name = "' $project_name '"'));
$pids $project->getAllSubWorkspacesCSV(truelogged_user());
icalendar_export($pids$project_name);
}

function 
icalendar_export($pids$calendar_name)
{
$cond_str "`project_id` IN ($pids)";
$events ProjectEvents::findAll(array(
'conditions' => array($cond_str)
)); // findAll

// $events = ProjectEvents::getAllEventsByProject($project);

$buffer CalFormatUtilities::generateICalInfo($events$calendar_name);

print($buffer);
}

try
{
DB::connect(DB_ADAPTER, array(
'host'    => DB_HOST,
'user'    => DB_USER,
'pass'    => DB_PASS,
'name'    => DB_NAME,
'persist' => DB_PERSIST
)); 
// connect
if(defined('DB_CHARSET') && trim(DB_CHARSET)) {
DB::execute("SET NAMES ?"DB_CHARSET);
// if
} catch(Exception $e)
{
print('Couldn\'t connect to DB.');
// try

$allowed_calendars = array('workspace1''workspace2''workspace3');

if(
$_GET['pass'] === 'abc123')
{
foreach($_GET['calendars'] as $calendar)
{
if (in_array($calendar$allowed_calendars))
{
icalendar_export_by_name($calendar);
}
}
}

?>

« Last Edit: March 07, 2009, 11:55:31 am by sadysta »

patrickGB

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: iCal server
« Reply #1 on: March 10, 2009, 07:54:52 pm »
Hi sadysta,
Your php script seems to be cool. But as I am not a php specialist, can I ask you a question ?
I tried to run it on my test server and I cannot figure out into which folder the exported file is written and what its name is ?

« Last Edit: March 10, 2009, 07:56:54 pm by patrickGB »

sadysta

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: iCal server
« Reply #2 on: March 15, 2009, 06:25:24 pm »
The answer is Matrix style: THERE IS _NO_ EXPORTED FILE.

But actually I mean it... go in your web browser to this address: http://yourserver/yourpath/generate_ical.php?pass=yourpasswd&calendars[]=yourworkspace (replace necessary fragments according to your configuration) and you will see that output is served simply as an HTTP content.

patrickGB

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: iCal server
« Reply #3 on: April 08, 2009, 05:48:57 pm »
Thanks a lot again sadysta !
Your code is so usefull. It is exactely what I needed.

I just tested it with Thunderbird and Lightning and it seems to be working fine.
Nevertheless, I noticed that recurring dates aren't passed thru. Only the first occurence is taken.

I don't know if it is a general problem or if it is related to thunderbird.
I will do some more tests with other clients and will come back to you.

Thanks again for your support.

added comment:
Coming back with this issue. It seems is is a general problem, as I had the same behaviour with another application (iCal from Macintosh). There must be a miswriting with the exported format.
« Last Edit: April 09, 2009, 04:24:07 am by patrickGB »

sadysta

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: iCal server
« Reply #4 on: April 09, 2009, 04:39:42 pm »
Thanks for your appreciation :)

Yes, I noticed it as well. That's because OpenGoo's CalFormatUtilities::generateICalInfo() method simply doesn't provide this kind of functionality. Perhaps it will be extended by the authors in next releases, otherwise I would have to implement my own version of such method.

max

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: iCal server
« Reply #5 on: April 18, 2009, 05:25:35 pm »
Thank you very much for this inspiring start, Sadysta!
I's actually moved me into considering OpenGoo to see how easy this one-way syncing is.

Having made the mistake of browsing through the iCal documentation I'd like to add more @todo to this unit. Perhaps we'll get there sometime soon. Don't take it personal, it's just a bunch of consideration to remember

* Alarms are not exported (ical: VALARM)
* Participation Status (PARTSTAT) would theoretically also be available
* time Zone? I haven't tested anything there yet.
* Tags from oGoo could go into CATEGORIES
* Workspace from oGoo could be replicated in DESCRIPTION, perhaps?
* LOCATION (not used in oGoo yet, but would be useful for the future, as I believe it's a heavily used field)
* ATTENDEE

And then of course there would be the whole VTODO to be integrated…!

And while we're at it - how about another server for VCARDs?

I'd put all this on my wishlist, but probably this whole discussion may become obsolete once the development team tells us about their future plans for synchronization. (I'd bet on a funambol server any time)…?


ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Re: iCal server
« Reply #6 on: April 21, 2009, 04:23:54 pm »
This script will be added on version 1.4. Thanks sadysta!

Answering to max, a Funambol plugin for OpenGoo is a strong candidate to manage synchronization with other programs, but we haven't discussed this in full yet.

Epistropheus

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: iCal server
« Reply #7 on: May 03, 2009, 07:36:49 am »
Thats really great, I was waiting for a sync solution.
Will it be possible to sync in both ways?

sadysta

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: iCal server
« Reply #8 on: May 03, 2009, 04:27:41 pm »
This script will be added on version 1.4. Thanks sadysta!
Glad to hear that :)

max

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: iCal server
« Reply #9 on: May 22, 2009, 11:48:16 am »
Hello ignacio,

has this script really made it into release 1.4? I just can't seem to find it...

What I found poking around in the code is somethin in feedcontroller.class.php which looks like an ical exporter... but it seems the function is not available externally?

I'm especially anxious because sadystas old script apparently is not working any longer. And we really used it all of the time.-

Any hints would be very appreciated!

ignacio

  • Hero Member
  • *****
  • Posts: 1703
    • View Profile
Re: iCal server
« Reply #10 on: May 23, 2009, 07:03:11 pm »
Hi,

You have to enable it on Administration -> Configuration -> General -> Show feed links. Then a little button will appear on the top right of the calendar. Once you have the link you can disable Show feed links again. Links are disabled by default because they contain information which allows you to login to the system, and some people here at the forums complained about security concerns. If you don't share this link with anyone you'll be safe. And for even better security use https to access your OpenGoo if available.

max

  • Jr. Member
  • **
  • Posts: 87
    • View Profile
Re: iCal server
« Reply #11 on: May 25, 2009, 05:42:00 am »
excellent! Works nicely.
thanks very much for this improvement...

William

  • Freshman
  • *
  • Posts: 13
    • View Profile
Re: iCal server
« Reply #12 on: June 01, 2009, 12:34:10 pm »
I'm new at streaming calendar info from web to Outlook so I don't know if this is something everyone already knew or even if it is the intended method or not, but to get it to work with Outlook 2007, I had to change my feed link from http:// to webcal://.  From there, it imports the event into the correct day, just not the right time.  Still working on that.

ylavi

  • Freshman
  • *
  • Posts: 19
    • View Profile
Re: iCal server
« Reply #13 on: November 01, 2011, 06:34:00 pm »
* Alarms are not exported (ical: VALARM)

I hope this tweak will get attention here

Here's some extra code for environment/classes/event/CalFormatUtilities.php which adds alarms (but not email reminders) to the iCal export - particularly useful for feeds to desktop/mobile apps which could implement those alarms.

The first and last lines are present in the original code (I'm working with the code for 1.7.3.1) and the rest is what I added:

Code: [Select]
                    $ical_info .= $rrule;

                    $reminders = ObjectReminders::getByObject($event);
                    foreach ($reminders as $reminder) {
                        if ($reminder->getType() == 'reminder_popup') {
                            $ical_info .= "BEGIN:VALARM\r\n";
                            $ical_info .= "TRIGGER:-PT".$reminder->getMinutesBefore()."M\r\n";
                            $ical_info .= "ACTION:DISPLAY\r\n";
                            $ical_info .= "DESCRIPTION:".$event->getSubject()."\r\n";
                            $ical_info .= "END:VALARM\r\n";
                        }
                    }
                   
                    $ical_info .= "END:VEVENT\r\n";