From fc9c345930fde9f2bbb78026904f2afd72755600 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 4 Apr 2016 23:45:39 +0000 Subject: [PATCH] move egw_ical_iterator to Api\CalDAV\IcalIterator --- .../class.addressbook_import_vcard.inc.php | 20 +++++++++--------- .../src/CalDAV/IcalIterator.php | 21 ++++++++++++------- calendar/inc/class.calendar_ical.inc.php | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) rename phpgwapi/inc/class.egw_ical_iterator.inc.php => api/src/CalDAV/IcalIterator.php (94%) diff --git a/addressbook/inc/class.addressbook_import_vcard.inc.php b/addressbook/inc/class.addressbook_import_vcard.inc.php index 0252778401..b219333e36 100644 --- a/addressbook/inc/class.addressbook_import_vcard.inc.php +++ b/addressbook/inc/class.addressbook_import_vcard.inc.php @@ -10,6 +10,7 @@ * @version $Id$ */ +use EGroupware\Api; /** * Plugin to import vCard files @@ -17,7 +18,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { private static $plugin_options = array( - + 'contact_owner' ); @@ -124,7 +125,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { // Fix for Apple Addressbook $vCard = preg_replace('/item\d\.(ADR|TEL|EMAIL|URL)/', '\1', stream_get_contents($_stream)); - $contacts = new egw_ical_iterator($vCard, '', $charset, array($this, '_vcard'),array( + $contacts = new Api\CalDAV\IcalIterator($vCard, '', $charset, array($this, '_vcard'),array( // Owner (addressbook) $contact_owner )); @@ -147,7 +148,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { $count++; $contacts->next(); } - + return $count; } @@ -166,8 +167,8 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { if(!array_key_exists($record['owner'], $this->bocontacts->get_addressbooks())) { $this->errors[$this->current] = lang("Unable to import into %1, using %2", - common::grab_owner_name($record['owner']), - common::grab_owner_name($this->user) + Api\Accounts::username($record['owner']), + Api\Accounts::username($this->user) ); $record['owner'] = $this->user; } @@ -220,7 +221,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { } else { //error_log(__METHOD__.__LINE__.array2string($changed).' Old:'.$old['adr_one_countryname'].' ('.$old['adr_one_countrycode'].') New:'.$_data['adr_one_countryname'].' ('.$_data['adr_one_countryname'].')'); } - + // Make sure n_fn gets updated unset($_data['n_fn']); @@ -249,8 +250,8 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { return $result; } default: - throw new egw_exception('Unsupported action: '. $_action); - + throw new Api\Exception('Unsupported action: '. $_action); + } } @@ -289,7 +290,7 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { $row += $record; $rows[] = $row; } - return html::table($rows); + return Api\Html::table($rows); } /** @@ -380,4 +381,3 @@ class addressbook_import_vcard implements importexport_iface_import_plugin { return $this->results; } } // end of iface_export_plugin -?> diff --git a/phpgwapi/inc/class.egw_ical_iterator.inc.php b/api/src/CalDAV/IcalIterator.php similarity index 94% rename from phpgwapi/inc/class.egw_ical_iterator.inc.php rename to api/src/CalDAV/IcalIterator.php index ee4b22c216..889861e3d6 100644 --- a/phpgwapi/inc/class.egw_ical_iterator.inc.php +++ b/api/src/CalDAV/IcalIterator.php @@ -5,12 +5,17 @@ * @link http://www.egroupware.org * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @package api - * @subpackage groupdav + * @subpackage caldav * @author Ralf Becker - * @copyright (c) 2010-15 by Ralf Becker + * @copyright (c) 2010-16 by Ralf Becker * @version $Id$ */ +namespace EGroupware\Api\CalDAV; + +use EGroupware\Api; +use Horde_Icalendar; + // required for tests at the end of this file (run if file called directly) if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE__) { @@ -20,7 +25,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ 'nonavbar' => 'true', ), ); - include('../../header.inc.php'); + include('../../../header.inc.php'); } /** @@ -28,7 +33,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ * * try { * $ical_file = fopen($path,'r'); - * $ical_it = new egw_ical_iterator($ical_file,'VCALENDAR'); + * $ical_it = new Api\CalDAV\IcalIterator($ical_file,'VCALENDAR'); * } * catch (Exception $e) * { @@ -40,7 +45,7 @@ if (isset($_SERVER['SCRIPT_FILENAME']) && $_SERVER['SCRIPT_FILENAME'] == __FILE_ * } * fclose($ical_file) */ -class egw_ical_iterator extends Horde_Icalendar implements Iterator +class IcalIterator extends Horde_Icalendar implements \Iterator { /** * File we work on @@ -124,7 +129,7 @@ class egw_ical_iterator extends Horde_Icalendar implements Iterator } if (!is_resource($this->ical_file)) { - throw new egw_exception_wrong_parameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file),0,100)); + throw new Api\Exception\WrongParameter(__METHOD__.'($ical_file, ...) NO resource! $ical_file='.substr(array2string($ical_file),0,100)); } } @@ -425,12 +430,12 @@ X-MS-OLK-CONFTYPE:0 END:VEVENT END:VCALENDAR '; - common::egw_header(); + $GLOBALS['egw']->framework->header(); //$ical_file = fopen('/tmp/KalenderFelicitasKubala.ics'); if (!is_resource($ical_file)) echo "
$ical_file
\n"; //$calendar_ical = new calendar_ical(); //$calendar_ical->setSupportedFields('file'); - $ical_it = new egw_ical_iterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin')); + $ical_it = new IcalIterator($ical_file);//,'VCALENDAR','iso-8859-1',array($calendar_ical,'_ical2egw_callback'),array('Europe/Berlin')); foreach($ical_it as $uid => $vevent) { echo "$uid
".print_r($vevent->toHash(), true)."
\n"; diff --git a/calendar/inc/class.calendar_ical.inc.php b/calendar/inc/class.calendar_ical.inc.php index 01d157b613..0de1966acb 100644 --- a/calendar/inc/class.calendar_ical.inc.php +++ b/calendar/inc/class.calendar_ical.inc.php @@ -2249,10 +2249,10 @@ class calendar_ical extends calendar_boupdate if (!is_array($this->supportedFields)) $this->setSupportedFields(); - // we use egw_ical_iterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0]) + // we use Api\CalDAV\IcalIterator only on resources, as calling importVCal() accesses single events like an array (eg. $events[0]) if (is_resource($_vcalData)) { - return new egw_ical_iterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($this->tzid,$principalURL)); + return new Api\CalDAV\IcalIterator($_vcalData,'VCALENDAR',$charset,array($this,'_ical2egw_callback'),array($this->tzid,$principalURL)); } if ($this->tzid) @@ -2317,7 +2317,7 @@ class calendar_ical extends calendar_boupdate } /** - * Callback for egw_ical_iterator to convert Horde_iCalendar_Vevent to EGw event array + * Callback for Api\CalDAV\IcalIterator to convert Horde_iCalendar_Vevent to EGw event array * * @param Horde_iCalendar $component * @param string $tzid timezone