From 55513b2a19173b7f40761f99598adcf832b1b5db Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 14 May 2012 15:45:21 +0200 Subject: [PATCH] Ported to libkolab. @TODO: remove caching, metadata is already cached by Roundcube storage --- plugins/kolab_zpush/kolab_zpush.php | 51 ++++++++++++++------------ plugins/kolab_zpush/kolab_zpush_ui.php | 18 ++++----- plugins/kolab_zpush/package.xml | 7 ++-- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/plugins/kolab_zpush/kolab_zpush.php b/plugins/kolab_zpush/kolab_zpush.php index 4ef242cf..b65f39ca 100644 --- a/plugins/kolab_zpush/kolab_zpush.php +++ b/plugins/kolab_zpush/kolab_zpush.php @@ -26,7 +26,7 @@ class kolab_zpush extends rcube_plugin { public $task = 'settings'; public $urlbase; - + private $rc; private $ui; private $cache; @@ -34,7 +34,7 @@ class kolab_zpush extends rcube_plugin private $folders; private $folders_meta; private $root_meta; - + const ROOT_MAILBOX = 'INBOX'; const CTYPE_KEY = '/shared/vendor/kolab/folder-type'; const ACTIVESYNC_KEY = '/private/vendor/kolab/activesync'; @@ -45,17 +45,18 @@ class kolab_zpush extends rcube_plugin public function init() { $this->rc = rcmail::get_instance(); - + $this->require_plugin('jqueryui'); $this->add_texts('localization/', true); - + $this->include_script('kolab_zpush.js'); - + $this->register_action('plugin.zpushconfig', array($this, 'config_view')); $this->register_action('plugin.zpushjson', array($this, 'json_command')); - - if ($this->rc->action == 'plugin.zpushconfig') - $this->require_plugin('kolab_core'); + + if ($this->rc->action == 'plugin.zpushconfig') { + $this->require_plugin('libkolab'); + } } @@ -66,6 +67,8 @@ class kolab_zpush extends rcube_plugin { $storage = $this->rc->get_storage(); + // @TODO: Metadata is already cached by rcube storage, get rid of cache here + $this->cache = $this->rc->get_cache('zpush', 'db', 900); $this->cache->expunge(); @@ -120,7 +123,7 @@ class kolab_zpush extends rcube_plugin $laxpic = intval(get_input_value('laxpic', RCUBE_INPUT_POST)); $subsciptions = get_input_value('subscribed', RCUBE_INPUT_POST); $err = false; - + if ($device = $devices[$imei]) { // update device config if changed if ($devicealias != $this->root_meta['DEVICE'][$imei]['ALIAS'] || @@ -146,12 +149,12 @@ class kolab_zpush extends rcube_plugin // skip root folder (already handled above) if ($folder == self::ROOT_MAILBOX) continue; - + if ($subsciptions[$folder] != $meta[$imei]['S']) { $meta[$imei]['S'] = intval($subsciptions[$folder]); $this->folders_meta[$folder] = $meta; unset($meta['TYPE']); - + // read metadata first $folderdata = $storage->get_metadata($folder, array(self::ACTIVESYNC_KEY)); if ($asyncdata = $folderdata[$folder][self::ACTIVESYNC_KEY]) @@ -161,24 +164,24 @@ class kolab_zpush extends rcube_plugin $err |= !$storage->set_metadata($folder, array(self::ACTIVESYNC_KEY => $this->serialize_metadata($metadata))); } } - + // update cache $this->cache->remove('folders'); $this->cache->write('folders', $this->folders_meta); - + $this->rc->output->command('plugin.zpush_save_complete', array('success' => !$err, 'id' => $imei, 'devicealias' => Q($devicealias))); } - + if ($err) $this->rc->output->show_message($this->gettext('savingerror'), 'error'); else $this->rc->output->show_message($this->gettext('successfullysaved'), 'confirmation'); - + break; case 'delete': $devices = $this->list_devices(); - + if ($device = $devices[$imei]) { unset($this->root_meta['DEVICE'][$imei], $this->root_meta['FOLDER'][$imei]); @@ -236,20 +239,20 @@ class kolab_zpush extends rcube_plugin public function config_view() { require_once $this->home . '/kolab_zpush_ui.php'; - + $storage = $this->rc->get_storage(); - + // checks if IMAP server supports any of METADATA, ANNOTATEMORE, ANNOTATEMORE2 if (!($storage->get_capability('METADATA') || $storage->get_capability('ANNOTATEMORE') || $storage->get_capability('ANNOTATEMORE2'))) { $this->rc->output->show_message($this->gettext('notsupported'), 'error'); } - + $this->ui = new kolab_zpush_ui($this); - + $this->register_handler('plugin.devicelist', array($this->ui, 'device_list')); $this->register_handler('plugin.deviceconfigform', array($this->ui, 'device_config_form')); $this->register_handler('plugin.foldersubscriptions', array($this->ui, 'folder_subscriptions')); - + $this->rc->output->set_env('devicecount', count($this->list_devices())); $this->rc->output->send('kolab_zpush.config'); } @@ -266,7 +269,7 @@ class kolab_zpush extends rcube_plugin $this->init_imap(); $this->devices = (array)$this->root_meta['DEVICE']; } - + return $this->devices; } @@ -299,7 +302,7 @@ class kolab_zpush extends rcube_plugin } $this->folders_meta[$folder]['TYPE'] = !empty($foldertype[0]) ? $foldertype[0] : 'mail'; } - + // cache it! $this->cache->write('folders', $this->folders_meta); } @@ -317,7 +320,7 @@ class kolab_zpush extends rcube_plugin { if (!isset($this->folders_meta)) $this->list_folders(); - + return $this->folders_meta; } diff --git a/plugins/kolab_zpush/kolab_zpush_ui.php b/plugins/kolab_zpush/kolab_zpush_ui.php index e651e982..4c99cf78 100644 --- a/plugins/kolab_zpush/kolab_zpush_ui.php +++ b/plugins/kolab_zpush/kolab_zpush_ui.php @@ -67,18 +67,18 @@ class kolab_zpush_ui $input = new html_inputfield(array('name' => 'devicealias', 'id' => $field_id, 'size' => 40)); $table->add('title', html::label($field_id, $this->config->gettext('devicealias'))); $table->add(null, $input->show()); - + $field_id = 'config-device-mode'; $select = new html_select(array('name' => 'syncmode', 'id' => $field_id)); $select->add(array($this->config->gettext('modeauto'), $this->config->gettext('modeflat'), $this->config->gettext('modefolder')), array('-1', '0', '1')); $table->add('title', html::label($field_id, $this->config->gettext('syncmode'))); $table->add(null, $select->show('-1')); - + $field_id = 'config-device-laxpic'; $checkbox = new html_checkbox(array('name' => 'laxpic', 'value' => '1', 'id' => $field_id)); $table->add('title', $this->config->gettext('imageformat')); $table->add(null, html::label($field_id, $checkbox->show() . ' ' . $this->config->gettext('laxpiclabel'))); - + if ($attrib['form']) $this->rc->output->add_gui_object('editform', $attrib['form']); @@ -90,7 +90,7 @@ class kolab_zpush_ui { if (!$attrib['id']) $attrib['id'] = 'foldersubscriptions'; - + // group folders by type (show only known types) $folder_groups = array('mail' => array(), 'contact' => array(), 'event' => array(), 'task' => array()); $folder_meta = $this->config->folders_meta(); @@ -99,7 +99,7 @@ class kolab_zpush_ui if (is_array($folder_groups[$type])) $folder_groups[$type][] = $folder; } - + // build block for every folder type foreach ($folder_groups as $type => $group) { if (empty($group)) @@ -111,14 +111,14 @@ class kolab_zpush_ui } $this->rc->output->add_gui_object('subscriptionslist', $attrib['id']); - + return html::div($attrib, $html); } public function folder_subscriptions_block($a_folders, $attrib) { $alarms = ($attrib['type'] == 'event' || $attrib['type'] == 'task'); - + $table = new html_table(array('cellspacing' => 0)); $table->add_header('subscription', $attrib['syncicon'] ? html::img(array('src' => $this->skin_path . $attrib['syncicon'], 'title' => $this->config->gettext('synchronize'))) : ''); $table->add_header('alarm', $alarms && $attrib['alarmicon'] ? html::img(array('src' => $this->skin_path . $attrib['alarmicon'], 'title' => $this->config->gettext('withalarms'))) : ''); @@ -129,7 +129,7 @@ class kolab_zpush_ui $names = array(); foreach ($a_folders as $folder) { - $foldername = $origname = preg_replace('/^INBOX »\s+/', '', rcube_kolab::object_name($folder)); + $foldername = $origname = preg_replace('/^INBOX »\s+/', '', kolab_storage::object_name($folder)); // find folder prefix to truncate (the same code as in kolab_addressbook plugin) for ($i = count($names)-1; $i >= 0; $i--) { @@ -161,7 +161,7 @@ class kolab_zpush_ui $table->add('alarm', $checkbox_alarm->show('', array('value' => $folder, 'id' => $folder_id.'_alarm'))); else $table->add('alarm', ''); - + $table->add(join(' ', $classes), html::label($folder_id, $padding . Q($foldername))); } diff --git a/plugins/kolab_zpush/package.xml b/plugins/kolab_zpush/package.xml index 61478795..ef6dfd72 100644 --- a/plugins/kolab_zpush/package.xml +++ b/plugins/kolab_zpush/package.xml @@ -13,10 +13,10 @@ bruederli@kolabsys.com yes - 2011-11-14 - + 2012-05-14 - 0.3 + 1.0 + 1.0 stable @@ -29,6 +29,7 @@ +