Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F9785681
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/plugins/libkolab/lib/kolab_format.php b/plugins/libkolab/lib/kolab_format.php
index bcad59e7..9fb0d8be 100644
--- a/plugins/libkolab/lib/kolab_format.php
+++ b/plugins/libkolab/lib/kolab_format.php
@@ -1,182 +1,182 @@
<?php
/**
* Kolab format model class wrapping libkolabxml bindings
*
* @version @package_version@
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
abstract class kolab_format
{
public static $timezone;
/**
* Factory method to instantiate a kolab_format object of the given type
*/
public static function factory($type)
{
if (!isset(self::$timezone))
self::$timezone = new DateTimeZone('UTC');
$suffix = preg_replace('/[^a-z]+/', '', $type);
$classname = 'kolab_format_' . $suffix;
if (class_exists($classname))
return new $classname();
return PEAR::raiseError(sprintf("Failed to load Kolab Format wrapper for type %s", $type));
}
/**
* Generate random UID for Kolab objects
*
- * @return string MD5 hash with a unique value
+ * @return string UUID with a unique MD5 value
*/
public static function generate_uid()
{
- return md5(uniqid(mt_rand(), true));
+ return 'urn:uuid:' . md5(uniqid(mt_rand(), true));
}
/**
* Convert the given date/time value into a cDateTime object
*
* @param mixed Date/Time value either as unix timestamp, date string or PHP DateTime object
* @param DateTimeZone The timezone the date/time is in. Use global default if empty
* @param boolean True of the given date has no time component
* @return object The libkolabxml date/time object or null on error
*/
public static function get_datetime($datetime, $tz = null, $dateonly = false)
{
if (!$tz) $tz = self::$timezone;
$result = null;
if (is_numeric($datetime))
$datetime = new DateTime('@'.$datetime, $tz);
else if (is_string($datetime) && strlen($datetime))
$datetime = new DateTime($datetime, $tz);
if (is_a($datetime, 'DateTime')) {
$result = new cDateTime();
$result->setDate($datetime->format('Y'), $datetime->format('n'), $datetime->format('j'));
if (!$dateonly)
$result->setTime($datetime->format('G'), $datetime->format('i'), $datetime->format('s'));
if ($tz)
$result->setTimezone($tz->getName());
}
return $result;
}
/**
* Convert the given cDateTime into a PHP DateTime object
*
* @param object cDateTime The libkolabxml datetime object
* @return object DateTime PHP datetime instance
*/
public static function php_datetime($cdt)
{
if (!is_object($cdt) || !$cdt->isValid())
return null;
$d = new DateTime;
$d->setTimezone(self::$timezone);
try {
if ($tzs = $cdt->timezone()) {
$tz = new DateTimeZone($tzs);
$d->setTimezone($tz);
}
}
catch (Exception $e) { }
$d->setDate($cdt->year(), $cdt->month(), $cdt->day());
if ($cdt->isDateOnly()) {
$d->_dateonly = true;
$d->setTime(12, 0, 0); // set time to noon to avoid timezone troubles
}
else {
$d->setTime($cdt->hour(), $cdt->minute(), $cdt->second());
}
return $d;
}
/**
* Convert a libkolabxml vector to a PHP array
*
* @param object vector Object
* @return array Indexed array contaning vector elements
*/
public static function vector2array($vec, $max = PHP_INT_MAX)
{
$arr = array();
for ($i=0; $i < $vec->size() && $i < $max; $i++)
$arr[] = $vec->get($i);
return $arr;
}
/**
* Build a libkolabxml vector (string) from a PHP array
*
* @param array Array with vector elements
* @return object vectors
*/
public static function array2vector($arr)
{
$vec = new vectors;
foreach ((array)$arr as $val)
$vec->push($val);
return $vec;
}
/**
* Load Kolab object data from the given XML block
*
* @param string XML data
*/
abstract public function load($xml);
/**
* Set properties to the kolabformat object
*
* @param array Object data as hash array
*/
abstract public function set(&$object);
/**
*
*/
abstract public function is_valid();
/**
* Write object data to XML format
*
* @return string XML data
*/
abstract public function write();
/**
* Convert the Kolab object into a hash array data structure
*
* @return array Kolab object data as hash array
*/
abstract public function to_array();
}
diff --git a/plugins/libkolab/lib/kolab_format_distributionlist.php b/plugins/libkolab/lib/kolab_format_distributionlist.php
index a1f5891b..d6297815 100644
--- a/plugins/libkolab/lib/kolab_format_distributionlist.php
+++ b/plugins/libkolab/lib/kolab_format_distributionlist.php
@@ -1,126 +1,119 @@
<?php
class kolab_format_distributionlist extends kolab_format
{
public $CTYPE = 'application/vcard+xml';
private $data;
private $obj;
function __construct()
{
- $obj = new DistList;
+ $this->obj = new DistList;
}
/**
* Load Kolab object data from the given XML block
*
* @param string XML data
*/
public function load($xml)
{
$this->obj = kolabformat::readDistlist($xml, false);
}
/**
* Write object data to XML format
*
* @return string XML data
*/
public function write()
{
return kolabformat::writeDistlist($this->obj);
}
public function set(&$object)
{
- // TODO: do the hard work of setting object values
+ // set some automatic values if missing
+ if (empty($object['uid']))
+ $object['uid'] = self::generate_uid();
+
+ // do the hard work of setting object values
+ $this->obj->setUid($object['uid']);
+ $this->obj->setName($object['name']);
+
+ $members = new vectormember;
+ foreach ($object['member'] as $member) {
+ $m = new Member;
+ $m->setName($member['name']);
+ $m->setEmail($member['mailto']);
+ $m->setUid($member['uid']);
+ $members->push($m);
+ }
+ $this->obj->setMembers($members);
}
public function is_valid()
{
- return $this->data || (is_object($this->obj) && true /*$this->obj->isValid()*/);
+ return $this->data || (is_object($this->obj) && $this->obj->isValid());
}
/**
* Load data from old Kolab2 format
*/
public function fromkolab2($record)
{
$object = array(
'uid' => $record['uid'],
'changed' => $record['last-modification-date'],
'name' => $record['last-name'],
'member' => array(),
);
foreach ($record['member'] as $member) {
$object['member'][] = array(
'mailto' => $member['smtp-address'],
'name' => $member['display-name'],
'uid' => $member['uid'],
);
}
$this->data = $object;
}
/**
* Convert the Distlist object into a hash array data structure
*
* @return array Distribution list data as hash array
*/
public function to_array()
{
// return cached result
if (!empty($this->data))
return $this->data;
// read object properties
$object = array(
'uid' => $this->obj->uid(),
# 'changed' => $this->obj->lastModified(),
'name' => $this->obj->name(),
'member' => array(),
);
$members = $this->obj->members();
for ($i=0; $i < $members->size(); $i++) {
- $adr = self::decode_member($members->get($i));
- if ($adr[0]['mailto'])
+ $member = $members->get($i);
+ if ($mailto = $member->email())
$object['member'][] = array(
- 'mailto' => $adr[0]['mailto'],
- 'name' => $adr[0]['name'],
- 'uid' => '????',
+ 'mailto' => $mailto,
+ 'name' => $member->name(),
+ 'uid' => $member->uid(),
);
}
+ $this->data = $object;
return $this->data;
}
- /**
- * Compose a valid Mailto URL according to RFC 822
- *
- * @param string E-mail address
- * @param string Person name
- * @return string Formatted string
- */
- public static function format_member($email, $name = '')
- {
- // let Roundcube internals do the job
- return 'mailto:' . format_email_recipient($email, $name);
- }
-
- /**
- * Split a mailto: url into a structured member component
- *
- * @param string RFC 822 mailto: string
- * @return array Hash array with member properties
- */
- public static function decode_member($str)
- {
- $adr = rcube_mime::decode_address_list(preg_replace('/^mailto:/', '', $str));
- return $adr[0];
- }
}
diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php
index ec93213f..9d00d336 100644
--- a/plugins/libkolab/lib/kolab_storage.php
+++ b/plugins/libkolab/lib/kolab_storage.php
@@ -1,206 +1,227 @@
<?php
/**
* Kolab storage class providing static methods to access groupware objects on a Kolab server.
*
* @version @package_version@
* @author Thomas Bruederli <bruederli@kolabsys.com>
*
* Copyright (C) 2012, Kolab Systems AG <contact@kolabsys.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class kolab_storage
{
const CTYPE_KEY = '/shared/vendor/kolab/folder-type';
public static $last_error;
private static $ready = false;
private static $config;
private static $cache;
private static $imap;
/**
* Setup the environment needed by the libs
*/
public static function setup()
{
if (self::$ready)
return;
$rcmail = rcmail::get_instance();
self::$config = $rcmail->config;
self::$imap = $rcmail->get_storage();
self::$ready = class_exists('kolabformat') && $rcmail->storage_connect() &&
(self::$imap->get_capability('METADATA') || self::$imap->get_capability('ANNOTATEMORE') || self::$imap->get_capability('ANNOTATEMORE2'));
if (self::$ready) {
// set imap options
self::$imap->set_options(array(
'skip_deleted' => true,
'threading' => false,
));
self::$imap->set_pagesize(9999);
}
}
/**
* Get a list of storage folders for the given data type
*
* @param string Data type to list folders for (contact,event,task,note)
*
* @return array List of Kolab_Folder objects (folder names in UTF7-IMAP)
*/
public static function get_folders($type)
{
self::setup();
$folders = array();
if (self::$ready) {
foreach ((array)self::$imap->list_folders('', '*', $type) as $foldername) {
$folders[$foldername] = new kolab_storage_folder($foldername, self::$imap);
}
}
return $folders;
}
/**
* Getter for a specific storage folder
*
* @param string IMAP folder to access (UTF7-IMAP)
* @return object Kolab_Folder The folder object
*/
public static function get_folder($folder)
{
self::setup();
return self::$ready ? new kolab_storage_folder($folder, null, self::$imap) : null;
}
/**
*
*/
public static function get_freebusy_server()
{
return unslashify(self::$config->get('kolab_freebusy_server', 'https://' . $_SESSION['imap_host'] . '/freebusy'));
}
/**
* Compose an URL to query the free/busy status for the given user
*/
public static function get_freebusy_url($email)
{
return self::get_freebusy_server() . '/' . $email . '.ifb';
}
/**
* Creates folder ID from folder name
*
* @param string $folder Folder name (UTF7-IMAP)
*
* @return string Folder ID string
*/
public static function folder_id($folder)
{
return asciiwords(strtr($folder, '/.-', '___'));
}
/**
* Getter for human-readable name of Kolab object (folder)
* See http://wiki.kolab.org/UI-Concepts/Folder-Listing for reference
*
* @param string $folder IMAP folder name (UTF7-IMAP)
* @param string $folder_ns Will be set to namespace name of the folder
*
* @return string Name of the folder-object
*/
public static function object_name($folder, &$folder_ns=null)
{
self::setup();
$found = false;
$namespace = self::$imap->get_namespace();
if (!empty($namespace['shared'])) {
foreach ($namespace['shared'] as $ns) {
if (strlen($ns[0]) && strpos($folder, $ns[0]) === 0) {
$prefix = '';
$folder = substr($folder, strlen($ns[0]));
$delim = $ns[1];
$found = true;
$folder_ns = 'shared';
break;
}
}
}
if (!$found && !empty($namespace['other'])) {
foreach ($namespace['other'] as $ns) {
if (strlen($ns[0]) && strpos($folder, $ns[0]) === 0) {
// remove namespace prefix
$folder = substr($folder, strlen($ns[0]));
$delim = $ns[1];
// get username
$pos = strpos($folder, $delim);
if ($pos) {
$prefix = '('.substr($folder, 0, $pos).') ';
$folder = substr($folder, $pos+1);
}
else {
$prefix = '('.$folder.')';
$folder = '';
}
$found = true;
$folder_ns = 'other';
break;
}
}
}
if (!$found && !empty($namespace['personal'])) {
foreach ($namespace['personal'] as $ns) {
if (strlen($ns[0]) && strpos($folder, $ns[0]) === 0) {
// remove namespace prefix
$folder = substr($folder, strlen($ns[0]));
$prefix = '';
$delim = $ns[1];
$found = true;
break;
}
}
}
if (empty($delim))
$delim = self::$imap->get_hierarchy_delimiter();
$folder = rcube_charset::convert($folder, 'UTF7-IMAP');
$folder = str_replace($delim, ' » ', $folder);
if ($prefix)
$folder = $prefix . ' ' . $folder;
if (!$folder_ns)
$folder_ns = 'personal';
return $folder;
}
+ /**
+ * Creates a SELECT field with folders list
+ *
+ * @param string $type Folder type
+ * @param array $attrs SELECT field attributes (e.g. name)
+ * @param string $current The name of current folder (to skip it)
+ *
+ * @return html_select SELECT object
+ */
+ public static function folder_selector($type, $attrs, $current = '')
+ {
+ // TODO: implement this
+
+
+ // Build SELECT field of parent folder
+ $select = new html_select($attrs);
+ $select->add('---', '');
+
+
+ return $select;
+ }
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Aug 17, 8:24 PM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1261603
Default Alt Text
(17 KB)
Attached To
Mode
R14 roundcubemail-plugins-kolab
Attached
Detach File
Event Timeline
Log In to Comment