forked from extern/egroupware
Adding more capabilites. Can now build a text string of a vCal card.
This commit is contained in:
parent
f43d2d1589
commit
9ba26f9b58
@ -28,19 +28,45 @@
|
||||
echo "Product ID = ".$vcalendar->prodid."<br>\n";
|
||||
echo "Method = ".$vcalendar->method."<br>\n";
|
||||
echo "Version = ".$vcalendar->version."<br>\n";
|
||||
echo "Summary = ".$vcalendar->event[0]->summary."<br>\n";
|
||||
echo "Location = ".$vcalendar->event[0]->location."<br>\n";
|
||||
echo "Sequence = ".$vcalendar->event[0]->sequence."<br>\n";
|
||||
echo "Date Start : ".$phpgw->common->show_date(mktime($vcalendar->event[0]->dtstart->hour,$vcalendar->event[0]->dtstart->min,$vcalendar->event[0]->dtstart->sec,$vcalendar->event[0]->dtstart->month,$vcalendar->event[0]->dtstart->mday,$vcalendar->event[0]->dtstart->year))."<br>\n";
|
||||
echo "Organizer = ".$vcalendar->event[0]->organizer->mailto->user.'@'.$vcalendar->event[0]->organizer->mailto->host."<br>\n";
|
||||
for($i=0;$i<3;$i++)
|
||||
|
||||
for($i=0;$i<count($vcalendar->event);$i++)
|
||||
{
|
||||
echo "Attendee[$i] CN = ".$vcalendar->event[0]->attendee[$i]->cn."<br>\n";
|
||||
echo "Attendee[$i] Address= ".$vcalendar->event[0]->attendee[$i]->mailto->user.'@'.$vcalendar->event[0]->attendee[$i]->mailto->host."<br>\n";
|
||||
echo "Attendee[$i] Role = ".$vcal->switch_role($vcalendar->event[0]->attendee[$i]->role)."<br>\n";
|
||||
// echo "Attendee[$i] RSVP = ".$vcal->switch_rsvp($vcalendar->event[0]->attendee[$i]->rsvp)."<br>\n";
|
||||
echo "Attendee[$i] RSVP = ".$vcalendar->event[0]->attendee[$i]->rsvp."<br>\n";
|
||||
echo "<br>\nEVENT<br>\n";
|
||||
echo "Summary = ".$vcalendar->event[$i]->summary."<br>\n";
|
||||
echo "Description = ".$vcalendar->event[$i]->description."<br>\n";
|
||||
echo "Location = ".$vcalendar->event[$i]->location."<br>\n";
|
||||
echo "Sequence = ".$vcalendar->event[$i]->sequence."<br>\n";
|
||||
echo "Date Start : ".$phpgw->common->show_date(mktime($vcalendar->event[$i]->dtstart->hour,$vcalendar->event[$i]->dtstart->min,$vcalendar->event[$i]->dtstart->sec,$vcalendar->event[$i]->dtstart->month,$vcalendar->event[$i]->dtstart->mday,$vcalendar->event[$i]->dtstart->year) - $phpgw->calendar->datatime->tz_offset)."<br>\n";
|
||||
echo "Class = ".$vcal->switch_class($vcalendar->event[$i]->class)."<br>\n";
|
||||
echo "Organizer = ".$vcalendar->event[$i]->organizer->mailto->user.'@'.$vcalendar->event[$i]->organizer->mailto->host."<br>\n";
|
||||
for($j=0;$j<count($vcalendar->event[$i]->attendee);$j++)
|
||||
{
|
||||
echo "Attendee[$j] CN = ".$vcalendar->event[$i]->attendee[$j]->cn."<br>\n";
|
||||
echo "Attendee[$j] Address= ".$vcalendar->event[$i]->attendee[$j]->mailto->user.'@'.$vcalendar->event[0]->attendee[$j]->mailto->host."<br>\n";
|
||||
echo "Attendee[$j] Role = ".$vcal->switch_role($vcalendar->event[$i]->attendee[$j]->role)."<br>\n";
|
||||
echo "Attendee[$j] RSVP = ".$vcal->switch_rsvp($vcalendar->event[$i]->attendee[$j]->rsvp)."<br>\n";
|
||||
// echo "Attendee[$j] RSVP = ".$vcalendar->event[$i]->attendee[$j]->rsvp."<br>\n";
|
||||
if($vcalendar->event[$i]->attendee[$j]->delegated_from->user && $vcalendar->event[$i]->attendee[$j]->delegated_from->host)
|
||||
{
|
||||
echo "Attendee[$j] DELEGATED_FROM = ".$vcalendar->event[$i]->attendee[$j]->delegated_from->user.'@'.$vcalendar->event[$i]->attendee[$j]->delegated_from->host."<br>\n";
|
||||
}
|
||||
echo "Class = ".$vcalendar->event[0]->class."<br>\n";
|
||||
}
|
||||
}
|
||||
for($i=0;$i<count($vcalendar->todo);$i++)
|
||||
{
|
||||
echo "<br>\nTODO<br>\n";
|
||||
echo "Summary = ".$vcalendar->todo[$i]->summary."<br>\n";
|
||||
echo "Description = ".$vcalendar->todo[$i]->description."<br>\n";
|
||||
echo "Location = ".$vcalendar->todo[$i]->location."<br>\n";
|
||||
echo "Sequence = ".$vcalendar->todo[$i]->sequence."<br>\n";
|
||||
echo "Date Start : ".$phpgw->common->show_date(mktime($vcalendar->todo[$i]->dtstart->hour,$vcalendar->todo[$i]->dtstart->min,$vcalendar->todo[$i]->dtstart->sec,$vcalendar->todo[$i]->dtstart->month,$vcalendar->todo[$i]->dtstart->mday,$vcalendar->todo[$i]->dtstart->year) - $phpgw->calendar->datatime->tz_offset)."<br>\n";
|
||||
echo "Class = ".$vcal->switch_class($vcalendar->todo[$i]->class)."<br>\n";
|
||||
}
|
||||
|
||||
include(PHPGW_APP_INC.'/../setup/setup.inc.php');
|
||||
|
||||
$vcal->set_var($vcalendar,'prodid','-//phpGroupWare//phpGroupWare '.$setup_info['calendar']['version'].' MIMEDIR//'.strtoupper($phpgw_info['user']['preferences']['common']['lang']));
|
||||
echo "<br><br><br>\n";
|
||||
echo nl2br($vcal->build_vcal($vcalendar));
|
||||
$phpgw->common->phpgw_footer();
|
||||
?>
|
||||
|
@ -12,6 +12,8 @@
|
||||
|
||||
/* $Id$ */
|
||||
|
||||
define('FOLD_LENGTH',79);
|
||||
|
||||
define('VEVENT',1);
|
||||
define('VTODO',2);
|
||||
|
||||
@ -98,7 +100,7 @@ class rrule
|
||||
var $byday;
|
||||
}
|
||||
|
||||
class vCalendar_event
|
||||
class vCalendar_item
|
||||
{
|
||||
var $type;
|
||||
var $attendee = Array();
|
||||
@ -128,6 +130,8 @@ class vCal
|
||||
class vCalendar
|
||||
{
|
||||
var $vcal;
|
||||
var $event = Array();
|
||||
var $todo = Array();
|
||||
|
||||
function splitdate($value)
|
||||
{
|
||||
@ -157,6 +161,12 @@ class vCalendar
|
||||
|
||||
function split_address($address)
|
||||
{
|
||||
if(strpos(' '.$address,':'))
|
||||
{
|
||||
$parts = explode(':',$address);
|
||||
$address = $parts[1];
|
||||
}
|
||||
|
||||
$parts = explode('@',$address);
|
||||
if(count($parts) == 2)
|
||||
{
|
||||
@ -198,6 +208,16 @@ class vCalendar
|
||||
}
|
||||
}
|
||||
|
||||
function fold($str)
|
||||
{
|
||||
// $temp_str = $str;
|
||||
// if(strlen($str) > FOLD_LENGTH)
|
||||
// {
|
||||
return chunk_split($str,FOLD_LENGTH,"\n");
|
||||
// }
|
||||
// return $temp_str;
|
||||
}
|
||||
|
||||
function strip_quotes($str)
|
||||
{
|
||||
return str_replace('"','',$str);
|
||||
@ -347,7 +367,7 @@ class vCalendar
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
elseif(gettype($var) == 'boolean')
|
||||
elseif(gettype($var) == 'integer')
|
||||
{
|
||||
if($var == 1)
|
||||
{
|
||||
@ -364,9 +384,108 @@ class vCalendar
|
||||
}
|
||||
}
|
||||
|
||||
function switch_class($var)
|
||||
{
|
||||
if(gettype($var) == 'string')
|
||||
{
|
||||
switch($var)
|
||||
{
|
||||
case 'PRIVATE':
|
||||
return PRIVATE;
|
||||
break;
|
||||
case 'PUBLIC':
|
||||
return PUBLIC;
|
||||
break;
|
||||
case 'CONFIDENTIAL':
|
||||
return CONFIDENTIAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif(gettype($var) == 'integer')
|
||||
{
|
||||
switch($var)
|
||||
{
|
||||
case PRIVATE:
|
||||
return 'PRIVATE';
|
||||
break;
|
||||
case PUBLIC:
|
||||
return 'PUBLIC';
|
||||
break;
|
||||
case CONFIDENTIAL:
|
||||
return 'CONFIDENTIAL';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
function switch_transp($var)
|
||||
{
|
||||
if(gettype($var) == 'string')
|
||||
{
|
||||
switch($var)
|
||||
{
|
||||
case 'TRANSPARENT':
|
||||
return TRANSPARENT;
|
||||
break;
|
||||
case 'OPAQUE':
|
||||
return OPAQUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
elseif(gettype($var) == 'integer')
|
||||
{
|
||||
switch($var)
|
||||
{
|
||||
case TRANSPARENT:
|
||||
return 'TRANSPARENT';
|
||||
break;
|
||||
case OPAQUE:
|
||||
return 'OPAQUE';
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $var;
|
||||
}
|
||||
}
|
||||
|
||||
function parse_attendee(&$event,$value)
|
||||
{
|
||||
$param = explode(':',$value);
|
||||
// Here down needs to be faster....
|
||||
$j = 0;
|
||||
while($j<count($param))
|
||||
{
|
||||
if(strpos(' '.$param[$j],'DELEGATED-'))
|
||||
{
|
||||
$param[$j] .= ':'.$param[$j + 1];
|
||||
$i = j + 1;
|
||||
while($i + 1 <= count($param))
|
||||
{
|
||||
$param[$i] = $param[$i + 1];
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$j++;
|
||||
}
|
||||
// Here up needs to be faster....
|
||||
|
||||
// $j = 0;
|
||||
// while(($j - 1)<count($param))
|
||||
// {
|
||||
// if(strpos(' '.$param[$j],'DELEGATED-'))
|
||||
// {
|
||||
// $param[$j] .= ':'.$param[$j + 1];
|
||||
// unset($param[$j + 1]);
|
||||
// }
|
||||
// $j++;
|
||||
// }
|
||||
|
||||
for($j=0;$j<count($param);$j++)
|
||||
{
|
||||
$param_sub = explode(';',$param[$j]);
|
||||
@ -388,6 +507,11 @@ class vCalendar
|
||||
case 'rsvp':
|
||||
$val = $this->switch_rsvp($type[1]);
|
||||
break;
|
||||
case 'delegated-from':
|
||||
case 'delegated-to':
|
||||
$type[0] = str_replace('-','_',$type[0]);
|
||||
$val = $this->split_address($type[1]);
|
||||
break;
|
||||
default:
|
||||
$val = $type[1];
|
||||
break;
|
||||
@ -434,6 +558,11 @@ class vCalendar
|
||||
}
|
||||
}
|
||||
|
||||
function new_vcal()
|
||||
{
|
||||
return new vCal;
|
||||
}
|
||||
|
||||
function read($vcal_text)
|
||||
{
|
||||
$i = 0;
|
||||
@ -498,20 +627,21 @@ class vCalendar
|
||||
switch(strtolower($value))
|
||||
{
|
||||
case 'vcalendar':
|
||||
$vcal = new vCal;
|
||||
$vcal = $this->new_vcal();
|
||||
break;
|
||||
case 'vevent':
|
||||
$event = new vCalendar_event;
|
||||
case 'vtodo':
|
||||
$event = new vCalendar_item;
|
||||
$event->type = strtolower($value);
|
||||
break;
|
||||
// case 'vtodo':
|
||||
// $event = new vCalendar_item;
|
||||
// $event->type = strtolower($value);
|
||||
// break;
|
||||
}
|
||||
break;
|
||||
case 'prodid':
|
||||
$this->set_var($vcal,$majortype,$value);
|
||||
break;
|
||||
case 'version':
|
||||
$this->set_var($vcal,$majortype,$value);
|
||||
break;
|
||||
case 'method':
|
||||
$this->set_var($vcal,$majortype,$value);
|
||||
break;
|
||||
@ -530,10 +660,16 @@ class vCalendar
|
||||
{
|
||||
case 'vevent':
|
||||
$this->event[] = $event;
|
||||
unset($event);
|
||||
break;
|
||||
case 'vtodo':
|
||||
$this->todo[] = $event;
|
||||
unset($event);
|
||||
break;
|
||||
case 'vcalendar':
|
||||
$this->vcal = $vcal;
|
||||
$this->vcal->event = $this->event;
|
||||
$this->vcal->todo = $this->todo;
|
||||
break 2;
|
||||
}
|
||||
break;
|
||||
@ -543,31 +679,10 @@ class vCalendar
|
||||
$this->set_var($event,$majortype,$this->splitdate($value));
|
||||
break;
|
||||
case 'class':
|
||||
switch(strtolower($value))
|
||||
{
|
||||
case 'private':
|
||||
$class = PRIVATE;
|
||||
break;
|
||||
case 'public':
|
||||
$class = PUBLIC;
|
||||
break;
|
||||
case 'confidential':
|
||||
$class = CONFIDENTIAL;
|
||||
break;
|
||||
}
|
||||
$this->set_var($event,$majortype,$class);
|
||||
$this->set_var($event,$majortype,$this->switch_class($value));
|
||||
break;
|
||||
case 'transp':
|
||||
switch(strtolower($value))
|
||||
{
|
||||
case 'transparent':
|
||||
$transp = TRANSPARENT;
|
||||
break;
|
||||
case 'opaque':
|
||||
$transp = OPAQUE;
|
||||
break;
|
||||
}
|
||||
$this->set_var($event,$majortype,$transp);
|
||||
$this->set_var($event,$majortype,$this->switch_transp($value));
|
||||
break;
|
||||
case 'rrule':
|
||||
$event->$majortype = new $majortype;
|
||||
@ -581,5 +696,125 @@ class vCalendar
|
||||
}
|
||||
return $this->vcal;
|
||||
}
|
||||
|
||||
function out_organizer_attendee($event)
|
||||
{
|
||||
$str = '';
|
||||
if(!empty($event->cn))
|
||||
{
|
||||
$str .= ';CN="'.$event->cn.'"';
|
||||
}
|
||||
if(!empty($event->role))
|
||||
{
|
||||
$str .= ';ROLE='.$this->switch_role($event->role);
|
||||
}
|
||||
if(!empty($event->rsvp))
|
||||
{
|
||||
$str .= ';RSVP='.$this->switch_rsvp($event->rsvp);
|
||||
}
|
||||
if(!empty($event->delegated_from->user) && !empty($event->delegated_from->host))
|
||||
{
|
||||
$str .= ';DELEGATED-FROM:MAILTO:"'.$event->delegated_from->user.'@'.$event->delegated_from->host.'"';
|
||||
}
|
||||
if(!empty($event->delegated_to->user) && !empty($event->delegated_to->host))
|
||||
{
|
||||
$str .= ';DELEGATED-TO:MAILTO:"'.$event->delegated_to->user.'@'.$event->delegated_to->host.'"';
|
||||
}
|
||||
if(!empty($event->mailto->user) && !empty($event->mailto->host))
|
||||
{
|
||||
$str .= ':MAILTO:'.$event->mailto->user.'@'.$event->mailto->host;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
|
||||
function build_card_internals($event)
|
||||
{
|
||||
$str .= 'DTSART:'.sprintf("%4d%02d%02dT%02d%02d%02dZ",$event->dtstart->year,$event->dtstart->month,$event->dtstart->mday,$event->dtstart->hour,$event->dtstart->min,$event->dtstart->sec)."\n";
|
||||
$str .= 'DTEND:'.sprintf("%4d%02d%02dT%02d%02d%02dZ",$event->dtend->year,$event->dtend->month,$event->dtend->mday,$event->dtend->hour,$event->dtend->min,$event->dtend->sec)."\n";
|
||||
// Still need to build recurrence portion......
|
||||
iF(!empty($event->location))
|
||||
{
|
||||
$str .= $this->fold('LOCATION:'.$event->location);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= 'LOCATION:\n'."\n";
|
||||
}
|
||||
$str .= 'TRANSP:'.$this->switch_transp($event->transp)."\n";
|
||||
if(!empty($event->sequence))
|
||||
{
|
||||
$str .= 'SEQUENCE:'.$event->sequence."\n";
|
||||
}
|
||||
if(!empty($event->uid))
|
||||
{
|
||||
$str .= $this->fold('UID:'.$event->uid);
|
||||
}
|
||||
$str .= 'DTSTAMP:'.gmdate('Ymd\THms\Z')."\n";
|
||||
if(!empty($event->description))
|
||||
{
|
||||
$str .= $this->fold('DESCRIPTION:'.$event->description);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= 'DESCRIPTION:\n'."\n";
|
||||
}
|
||||
if(!empty($event->summary))
|
||||
{
|
||||
$str .= $this->fold('SUMMARY:'.$event->summary);
|
||||
}
|
||||
else
|
||||
{
|
||||
$str .= 'SUMMARY:\n'."\n";
|
||||
}
|
||||
if(!empty($event->priority))
|
||||
{
|
||||
$str .= 'PRIORITY:'.$event->priority."\n";
|
||||
}
|
||||
$str .= 'CLASS:'.$this->switch_class($event->class)."\n";
|
||||
|
||||
return $str;
|
||||
}
|
||||
|
||||
function build_vcal($vcal)
|
||||
{
|
||||
$str = 'BEGIN:VCALENDAR'."\n";
|
||||
$str .= 'PRODID:'.$vcal->prodid."\n";
|
||||
$str .= 'VERSION:'.$vcal->version."\n";
|
||||
$str .= 'METHOD:'.$vcal->method."\n";
|
||||
if($vcal->event)
|
||||
{
|
||||
for($i=0;$i<count($vcal->event);$i++)
|
||||
{
|
||||
$str .= 'BEGIN:VEVENT'."\n";
|
||||
for($j=0;$j<count($vcal->event[$i]->attendee);$j++)
|
||||
{
|
||||
$temp_attendee = $this->out_organizer_attendee($vcal->event[$i]->attendee[$j]);
|
||||
|
||||
if($temp_attendee)
|
||||
{
|
||||
$str .= 'ATTENDEE'.$temp_attendee."\n";
|
||||
}
|
||||
}
|
||||
if(!empty($vcal->event[$i]->organizer))
|
||||
{
|
||||
$str .= 'ORGANIZER'.$this->out_organizer_attendee($vcal->event[$i]->organizer)."\n";
|
||||
}
|
||||
$str .= $this->build_card_internals($vcal->event[$i]);
|
||||
$str .= 'END:VEVENT'."\n";
|
||||
}
|
||||
}
|
||||
if($vcal->todo)
|
||||
{
|
||||
for($i=0;$i<count($vcal->todo);$i++)
|
||||
{
|
||||
$str .= 'BEGIN:VTODO'."\n";
|
||||
$str .= $this->build_card_internals($vcal->todo[$i]);
|
||||
$str .= 'END:VTODO'."\n";
|
||||
}
|
||||
}
|
||||
$str .= 'END:VCALENDAR'."\n";
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -4,7 +4,7 @@ VERSION:2.0
|
||||
METHOD:REQUEST
|
||||
BEGIN:VEVENT
|
||||
ATTENDEE;CN="Doe John (Marketing)";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:John.Doe@somewhere.com
|
||||
ATTENDEE;CN="Jones Bill (IT)";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:Bill.Jones@somewhere.com
|
||||
ATTENDEE;CN="Jones Bill (IT)";ROLE=REQ-PARTICIPANT;RSVP=TRUE;DELEGATED-FROM="MAILTO:immud@host3.com":MAILTO:Bill.Jones@somewhere.com
|
||||
ATTENDEE;CN="Smith Mary (PR)";ROLE=NON-PARTICIPANT;RSVP=FALSE:MAILTO:Mary.Smith@elsewhere.com
|
||||
ORGANIZER:MAILTO:John.Doe@somewhere.com
|
||||
DTSTART:20010302T150000Z
|
||||
@ -20,4 +20,31 @@ SUMMARY:Web Site Redesign
|
||||
PRIORITY:5
|
||||
CLASS:PUBLIC
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
ATTENDEE;CN="Doe2 John (Marketing)";ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:John.Doe2@somewhere.com
|
||||
ATTENDEE;CN="Jones2 Bill (IT)";ROLE=REQ-PARTICIPANT;RSVP=TRUE;DELEGATED-FROM="MAILTO:immud2@host3.com":MAILTO:Bill.Jones2@somewhere.com
|
||||
ATTENDEE;CN="Smith2 Mary (PR)";ROLE=NON-PARTICIPANT;RSVP=FALSE:MAILTO:Mary.Smith2@elsewhere.com
|
||||
ORGANIZER:MAILTO:John.Doe2@somewhere.com
|
||||
DTSTART:20010302T160000Z
|
||||
DTEND:20010302T163000Z
|
||||
LOCATION:Conference Room #3
|
||||
TRANSP:OPAQUE
|
||||
SEQUENCE:0
|
||||
UID:023007208203E60074C5B7107A82E00803730C0D40A12C0042A2C001009384EA000F00B100
|
||||
184029BDFF7C7650ED5118DF7028059A01231
|
||||
DTSTAMP:20010301T172412Z
|
||||
DESCRIPTION:\n
|
||||
SUMMARY:Web Site Redesign (2)
|
||||
PRIORITY:2
|
||||
CLASS:PRIVATE
|
||||
END:VEVENT
|
||||
BEGIN:VTODO
|
||||
DTSTART:20010301T160000Z
|
||||
DTEND:20010301T163000Z
|
||||
LOCATION:My Desk
|
||||
DTSTAMP:20010301T172312Z
|
||||
DESCRIPTION:\n
|
||||
SUMMARY:Prepare for tomrrow's meeting
|
||||
CLASS:PRIVATE
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
|
Loading…
Reference in New Issue
Block a user