gunnar: server/php-kolab/Kolab_Freebusy/Freebusy freebusy.class.php, 1.1, 1.2
cvs at kolab.org
cvs at kolab.org
Mon Aug 13 11:41:11 CEST 2007
Author: gunnar
Update of /kolabrepository/server/php-kolab/Kolab_Freebusy/Freebusy
In directory doto:/tmp/cvs-serv13228
Modified Files:
freebusy.class.php
Log Message:
Fix a php5 reference issue and add the draft patch for using the newer Horde libraries.
Index: freebusy.class.php
===================================================================
RCS file: /kolabrepository/server/php-kolab/Kolab_Freebusy/Freebusy/freebusy.class.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- freebusy.class.php 7 Aug 2007 15:45:56 -0000 1.1
+++ freebusy.class.php 13 Aug 2007 09:41:09 -0000 1.2
@@ -34,9 +34,6 @@
require_once 'Kolab/Freebusy/freebusyimapcache.class.php';
require_once 'Kolab/Freebusy/recurrence.class.php';
-if (version_compare(PHP_VERSION,'5', '>='))
- require_once('Kolab/Freebusy/domxml-php4-to-php5.php');
-
class FreeBusyRecurrence extends Recurrence {
function FreeBusyRecurrence( &$imapcache, &$imapuid, &$vfb, &$extra ) {
$this->imapcache =& $imapcache;
@@ -55,20 +52,21 @@
};
class FreeBusy {
- function FreeBusy( $cache_dir,
- $owner_email,
+ function FreeBusy( $owner_email,
$username,
- $password,
- $imaphost,
- $imapoptions,
- $fbfuture=60,
- $fbpast=0 ) {
- $this->cache_dir = $cache_dir;
+ $password,
+ $imaphost,
+ $params,
+ $fbfuture=60,
+ $fbpast=0 ) {
+
+ $this->params = $params;
+ $this->cache_dir = $params['cache_dir'];
$this->owner_email = $owner_email;
$this->username = $username;
$this->password = $password;
$this->imaphost = $imaphost;
- $this->imapoptions = $imapoptions;
+ $this->imapoptions = $params['imap_options'];
$this->fbfuture = $fbfuture;
$this->fbpast = $fbpast;
$this->relevance = null;
@@ -214,12 +212,12 @@
$imapcache->cache_store();
$imapcache->output_fb($vFb);
- $xvCal = $vCal;
- $xvCal->addComponent($vFb);
+ $vCal->addComponent($vFb);
+ $extended = $vCal->exportvCalendar();
$vCal->addComponent($this->clearExtra($vFb));
// Generate the vCal file.
- $result = array( $vCal->exportvCalendar(), $xvCal->exportvCalendar() );
+ $result = array( $vCal->exportvCalendar(), $extended );
return $result;
}
@@ -397,81 +395,100 @@
$date['month'], $date['mday'], $date['year']);
}
- function getEventHash($xml_text) {
- $xmldoc = domxml_open_mem($xml_text, DOMXML_LOAD_PARSING +
- DOMXML_LOAD_COMPLETE_ATTRS + DOMXML_LOAD_SUBSTITUTE_ENTITIES +
- DOMXML_LOAD_DONT_KEEP_BLANKS, $error);
-
- if (!empty($error)) {
- // There were errors parsing the XML data - abort
- myLog( "Error parsing \"$xml_txt\": $error", RM_LOG_ERROR);
- return false;
- }
-
- $noderoot = $xmldoc->document_element();
- $childnodes = $noderoot->child_nodes();
-
- $event_hash = array();
+ function getEventHash($xml_text)
+ {
+
+ if (!$this->params['use_new_horde']) {
+ if (version_compare(PHP_VERSION,'5', '>=')) {
+ require_once('Kolab/Freebusy/domxml-php4-to-php5.php');
+ }
+
+ $xmldoc = domxml_open_mem($xml_text,
+ DOMXML_LOAD_PARSING +
+ DOMXML_LOAD_COMPLETE_ATTRS +
+ DOMXML_LOAD_SUBSTITUTE_ENTITIES +
+ DOMXML_LOAD_DONT_KEEP_BLANKS,
+ $error);
- // Build the event hash
- foreach ($childnodes as $value) {
- //myLog("Looking at tag ".($value->tagname), RM_LOG_DEBUG);
- if( $value->tagname == 'recurrence' ) {
- $rhash = array();
- $attrs = $value->attributes();
- foreach( $attrs as $attr ) {
- //myLog("getEventHash setting rhash[".$attr->name."] = ".$attr->value, RM_LOG_DEBUG);
- $rhash[$attr->name] = $attr->value;
- }
- foreach( $value->child_nodes() as $v ) {
- if( $v->tagname == 'day' || $v->tagname == 'exclusion' ) {
- $rhash[$v->tagname][] = $v->get_content();
- } else {
- $rhash[$v->tagname] = $v->get_content();
- if( $v->tagname == 'range' && $v->has_attribute('type') ) {
- $rhash['rangetype'] = $v->get_attribute('type');
- }
- }
- }
- $event_hash[$value->tagname] = $rhash;
+ if (!empty($error)) {
+ // There were errors parsing the XML data - abort
+ myLog( "Error parsing \"$xml_txt\": $error", RM_LOG_ERROR);
+ return false;
+ }
} else {
- $event_hash[$value->tagname] = $value->get_content();
+ require_once 'Horde/DOM.php';
+ $xmldoc = = Horde_DOM_Document::factory(array('xml' => $xml_text));
}
- }
-
- //myLog("RAW Event: ".print_r($event_hash, true), RM_LOG_DEBUG);
- // Perform some sanity checks on the event
- if (
- empty($event_hash['uid']) ||
- empty($event_hash['start-date']) ||
- empty($event_hash['end-date'])
- ) {
- return false;
- }
-
+ $noderoot = $xmldoc->document_element();
+ $childnodes = $noderoot->child_nodes();
- if (empty($event_hash['sensitivity'])) {
- $event_hash['sensitivity'] = 'public';
- }
-
- // Set the summary if it's not present, so we don't get PHP warnings
- // about accessing non-present keys
- if (empty($event_hash['summary'])) {
- $event_hash['summary'] = '';
- }
-
- // Convert our date-time values to timestamps
- if( strpos( $event_hash['start-date'], 'T' ) === false &&
- strpos( $event_hash['end-date'], 'T' ) === false ) {
- $event_hash['allday'] = true;
- } else {
- $event_hash['allday'] = false;
- }
- $event_hash['start-date'] = FreeBusy::parseDateTime($event_hash['start-date']);
- $event_hash['end-date'] = FreeBusy::parseDateTime($event_hash['end-date']);
-
- return $event_hash;
+ $event_hash = array();
+
+ // Build the event hash
+ foreach ($childnodes as $value) {
+
+ if ($this->params['use_new_horde'] &&
+ $value->type != XML_ELEMENT_NODE) {
+ continue;
+ }
+
+ //myLog("Looking at tag ".($value->tagname), RM_LOG_DEBUG);
+ if( $value->tagname == 'recurrence' ) {
+ $rhash = array();
+ $attrs = $value->attributes();
+ foreach( $attrs as $attr ) {
+ //myLog("getEventHash setting rhash[".$attr->name."] = ".$attr->value, RM_LOG_DEBUG);
+ $rhash[$attr->name] = $attr->value;
+ }
+ foreach( $value->child_nodes() as $v ) {
+ if( $v->tagname == 'day' || $v->tagname == 'exclusion' ) {
+ $rhash[$v->tagname][] = $v->get_content();
+ } else {
+ $rhash[$v->tagname] = $v->get_content();
+ if( $v->tagname == 'range' && $v->has_attribute('type') ) {
+ $rhash['rangetype'] = $v->get_attribute('type');
+ }
+ }
+ }
+ $event_hash[$value->tagname] = $rhash;
+ } else {
+ $event_hash[$value->tagname] = $value->get_content();
+ }
+ }
+
+ //myLog("RAW Event: ".print_r($event_hash, true), RM_LOG_DEBUG);
+
+ // Perform some sanity checks on the event
+ if (
+ empty($event_hash['uid']) ||
+ empty($event_hash['start-date']) ||
+ empty($event_hash['end-date'])
+ ) {
+ return false;
+ }
+
+ if (empty($event_hash['sensitivity'])) {
+ $event_hash['sensitivity'] = 'public';
+ }
+
+ // Set the summary if it's not present, so we don't get PHP warnings
+ // about accessing non-present keys
+ if (empty($event_hash['summary'])) {
+ $event_hash['summary'] = '';
+ }
+
+ // Convert our date-time values to timestamps
+ if( strpos( $event_hash['start-date'], 'T' ) === false &&
+ strpos( $event_hash['end-date'], 'T' ) === false ) {
+ $event_hash['allday'] = true;
+ } else {
+ $event_hash['allday'] = false;
+ }
+ $event_hash['start-date'] = FreeBusy::parseDateTime($event_hash['start-date']);
+ $event_hash['end-date'] = FreeBusy::parseDateTime($event_hash['end-date']);
+
+ return $event_hash;
}
function clearExtra( $vFb ) {
More information about the commits
mailing list