mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-18 11:58:24 +01:00
fix egw_ical_iterator to use new Horde_Icalendar
This commit is contained in:
parent
ed97ead93e
commit
be9cd16de4
@ -7,7 +7,7 @@
|
|||||||
* @package api
|
* @package api
|
||||||
* @subpackage groupdav
|
* @subpackage groupdav
|
||||||
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||||
* @copyright (c) 2010 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
* @copyright (c) 2010-15 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -16,12 +16,12 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_
|
|||||||
{
|
{
|
||||||
$GLOBALS['egw_info'] = array(
|
$GLOBALS['egw_info'] = array(
|
||||||
'flags' => array(
|
'flags' => array(
|
||||||
'currentapp' => 'calendar',
|
'currentapp' => 'login',
|
||||||
|
'nonavbar' => 'true',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
include('../../header.inc.php');
|
include('../../header.inc.php');
|
||||||
}
|
}
|
||||||
require_once EGW_API_INC.'/horde/lib/core.php';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator for iCal files
|
* Iterator for iCal files
|
||||||
@ -40,7 +40,7 @@ require_once EGW_API_INC.'/horde/lib/core.php';
|
|||||||
* }
|
* }
|
||||||
* fclose($ical_file)
|
* fclose($ical_file)
|
||||||
*/
|
*/
|
||||||
class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
class egw_ical_iterator extends Horde_Icalendar implements Iterator
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* File we work on
|
* File we work on
|
||||||
@ -73,7 +73,7 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
/**
|
/**
|
||||||
* Current component, as it get's returned by current() method
|
* Current component, as it get's returned by current() method
|
||||||
*
|
*
|
||||||
* @var Horde_iCalendar
|
* @var Horde_Icalendar
|
||||||
*/
|
*/
|
||||||
protected $component;
|
protected $component;
|
||||||
|
|
||||||
@ -95,15 +95,15 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string|resource $ical_file file opened for reading or string
|
* @param string|resource $ical_file file opened for reading or string
|
||||||
* @param string $base='VCALENDAR' container
|
* @param string $base ='VCALENDAR' container
|
||||||
* @param string $charset=null
|
* @param string $charset =null
|
||||||
* @param callback $callback=null callback to call with component in current() method, if returning false, item get's ignored
|
* @param callback $callback =null callback to call with component in current() method, if returning false, item get's ignored
|
||||||
* @param array $callback_params=array() further parameters for the callback, 1. parameter is component
|
* @param array $callback_params =array() further parameters for the callback, 1. parameter is component
|
||||||
*/
|
*/
|
||||||
public function __construct($ical_file,$base='VCALENDAR',$charset=null,$callback=null,array $callback_params=array())
|
public function __construct($ical_file,$base='VCALENDAR',$charset=null,$callback=null,array $callback_params=array())
|
||||||
{
|
{
|
||||||
// call parent constructor
|
// call parent constructor
|
||||||
parent::Horde_iCalendar();
|
parent::__construct();
|
||||||
|
|
||||||
$this->base = $base;
|
$this->base = $base;
|
||||||
$this->charset = $charset;
|
$this->charset = $charset;
|
||||||
@ -114,14 +114,9 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
}
|
}
|
||||||
if (is_string($ical_file))
|
if (is_string($ical_file))
|
||||||
{
|
{
|
||||||
$GLOBALS[$name = md5(microtime(true))] =& $ical_file;
|
$this->ical_file = fopen('php://temp', 'w+');
|
||||||
require_once(EGW_API_INC.'/class.global_stream_wrapper.inc.php');
|
fwrite($this->ical_file, $ical_file);
|
||||||
$this->ical_file = fopen('global://'.$name,'r');
|
fseek($this->ical_file, 0, SEEK_SET);
|
||||||
unset($GLOBALS[$name]);
|
|
||||||
// alternative: $this->unread_lines = explode("\n",$ical_file); return;
|
|
||||||
// uses less memory, but it can NOT rewind
|
|
||||||
|
|
||||||
//error_log(__METHOD__."(,'$base','$charset') using global stream wrapper fopen('global://$name')=".array2string($this->ical_file));
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -143,7 +138,7 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
/**
|
/**
|
||||||
* Read and return one line from file (or line-buffer)
|
* Read and return one line from file (or line-buffer)
|
||||||
*
|
*
|
||||||
* We do NOT handle folding, that's done by Horde_iCalendar and not necessary for us as BEGIN: or END: component is never folded
|
* We do NOT handle folding, that's done by Horde_Icalendar and not necessary for us as BEGIN: or END: component is never folded
|
||||||
*
|
*
|
||||||
* @return string|boolean string with line or false if end-of-file or end-of-container reached
|
* @return string|boolean string with line or false if end-of-file or end-of-container reached
|
||||||
*/
|
*/
|
||||||
@ -186,17 +181,17 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
/**
|
/**
|
||||||
* Return the current element
|
* Return the current element
|
||||||
*
|
*
|
||||||
* @return Horde_iCalendar or whatever a given callback returns
|
* @return Horde_Icalendar or whatever a given callback returns
|
||||||
*/
|
*/
|
||||||
public function current()
|
public function current()
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__."() returning a ".gettype($this->component));
|
//error_log(__METHOD__."() returning a ".gettype($this->component));
|
||||||
if ($this->callback)
|
if ($this->callback)
|
||||||
{
|
{
|
||||||
$ret = is_a($this->component,'Horde_iCalendar');
|
$ret = is_a($this->component,'Horde_Icalendar');
|
||||||
do {
|
do {
|
||||||
if ($ret === false) $this->next();
|
if ($ret === false) $this->next();
|
||||||
if (!is_a($this->component,'Horde_iCalendar')) return false;
|
if (!is_a($this->component,'Horde_Icalendar')) return false;
|
||||||
$params = $this->callback_params;
|
$params = $this->callback_params;
|
||||||
array_unshift($params,$this->component);
|
array_unshift($params,$this->component);
|
||||||
}
|
}
|
||||||
@ -245,11 +240,11 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
}
|
}
|
||||||
$data .= $line;
|
$data .= $line;
|
||||||
|
|
||||||
$this->component = &Horde_iCalendar::newComponent($type, $this);
|
$this->component = Horde_Icalendar::newComponent($type, $this);
|
||||||
//error_log(__METHOD__."() this->component = Horde_iCalendar::newComponent('$type', \$this) = ".array2string($this->component));
|
//error_log(__METHOD__."() this->component = Horde_Icalendar::newComponent('$type', \$this) = ".array2string($this->component));
|
||||||
if ($this->component === false)
|
if ($this->component === false)
|
||||||
{
|
{
|
||||||
error_log(__METHOD__."() Horde_iCalendar::newComponent('$type', \$this) returned FALSE");
|
error_log(__METHOD__."() Horde_Icalendar::newComponent('$type', \$this) returned FALSE");
|
||||||
return;
|
return;
|
||||||
//return PEAR::raiseError("Unable to create object for type $type");
|
//return PEAR::raiseError("Unable to create object for type $type");
|
||||||
}
|
}
|
||||||
@ -288,6 +283,7 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
// advance to first component
|
// advance to first component
|
||||||
while (($line = $this->read_line()) && substr($line,0,6) !== 'BEGIN:')
|
while (($line = $this->read_line()) && substr($line,0,6) !== 'BEGIN:')
|
||||||
{
|
{
|
||||||
|
$matches = null;
|
||||||
if (preg_match('/^VERSION:(\d\.\d)\s*$/ism', $line, $matches))
|
if (preg_match('/^VERSION:(\d\.\d)\s*$/ism', $line, $matches))
|
||||||
{
|
{
|
||||||
// define the version asap
|
// define the version asap
|
||||||
@ -315,8 +311,8 @@ class egw_ical_iterator extends Horde_iCalendar implements Iterator
|
|||||||
*/
|
*/
|
||||||
public function valid ()
|
public function valid ()
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__."() returning ".(is_a($this->component,'Horde_iCalendar') ? 'TRUE' : 'FALSE').' get_class($this->component)='.get_class($this->component));
|
//error_log(__METHOD__."() returning ".(is_a($this->component,'Horde_Icalendar') ? 'TRUE' : 'FALSE').' get_class($this->component)='.get_class($this->component));
|
||||||
return is_a($this->component,'Horde_iCalendar');
|
return is_a($this->component,'Horde_Icalendar');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,6 +425,7 @@ X-MS-OLK-CONFTYPE:0
|
|||||||
END:VEVENT
|
END:VEVENT
|
||||||
END:VCALENDAR
|
END:VCALENDAR
|
||||||
';
|
';
|
||||||
|
common::egw_header();
|
||||||
//$ical_file = fopen('/tmp/KalenderFelicitasKubala.ics');
|
//$ical_file = fopen('/tmp/KalenderFelicitasKubala.ics');
|
||||||
if (!is_resource($ical_file)) echo "<pre>$ical_file</pre>\n";
|
if (!is_resource($ical_file)) echo "<pre>$ical_file</pre>\n";
|
||||||
//$calendar_ical = new calendar_ical();
|
//$calendar_ical = new calendar_ical();
|
||||||
@ -436,7 +433,7 @@ END:VCALENDAR
|
|||||||
$ical_it = new egw_ical_iterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
|
$ical_it = new egw_ical_iterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin'));
|
||||||
foreach($ical_it as $uid => $vevent)
|
foreach($ical_it as $uid => $vevent)
|
||||||
{
|
{
|
||||||
echo "$uid<pre>".print_r($vevent,true)."</pre>\n";
|
echo "$uid<pre>".print_r($vevent->toHash(), true)."</pre>\n";
|
||||||
}
|
}
|
||||||
if (is_resource($ical_file)) fclose($ical_file);
|
if (is_resource($ical_file)) fclose($ical_file);
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user