Skip to content

Commit

Permalink
backport improvements from master
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Nov 20, 2020
1 parent ca8bd0b commit c9270e9
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Roundcube Webmail Swipe
=======================

Version 0.3.1 (2020-11-20, rc-1.4.4)
=================================================
* Various code improvements

Version 0.3 (2020-04-27, rc-1.4.4)
=================================================
* Update command enabling after (req RC cb8c078)
Expand Down
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@
"role": "Developer"
}
],
"repositories": [
{
"type": "composer",
"url": "https://plugins.roundcube.net"
}
],
"require": {
"php": ">=5.2.1",
"php": ">=5.4.0",
"roundcube/plugin-installer": ">=0.1.2"
},
"extra": {
Expand Down
15 changes: 15 additions & 0 deletions localization/de_DE.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/* Author: double2ugly and NNowakowski */

$labels = array();
$labels['swipeoptions'] = 'Wisch-Optionen';
$labels['swipeleft'] = 'Nach links wischen';
$labels['swiperight'] = 'Nach rechts wischen';
$labels['swipedown'] = 'Nach unten wischen';
$labels['markasread'] = 'Als gelesen markieren';
$labels['markasunread'] = 'Ans ungelesen markieren';
$labels['markasflagged'] = 'Als wichtig markieren';
$labels['markasunflagged'] = 'Als unwichtig markieren';
$labels['deselect'] = 'Abwählen';

$messages = array();
132 changes: 75 additions & 57 deletions swipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,44 +28,43 @@
class swipe extends rcube_plugin
{
public $task = '^((?!login).)*$';
private $menu_file = null;
private $dont_override = array();
private $disabled_actions = array();
private $laoded_plugins = array();
private $config = array();
private $actions = array(
'messagelist' => array(
private $dont_override = [];
private $disabled_actions = [];
private $laoded_plugins = [];
private $config = [];
private $actions = [
'messagelist' => [
'list_name' => 'message_list',
'selection_id' => 'uid',
'vertical' => array(
'checkmail' => array('label' => 'checkmail')
),
'horizontal' => array(
'archive' => array('label' => 'archive.buttontext', 'plugin' => true, 'condition' => 'config:archive_folder !== false'),
'delete' => array('label' => 'delete'),
'forward' => array('label' => 'forward'),
'markasjunk' => array('label' => 'markasjunk.markasjunk', 'plugin' => true),
'move' => array('label' => 'moveto'),
'reply' => array('label' => 'reply'),
'reply-all' => array('label' => 'replyall'),
'swipe-flagged' => array('label' => 'swipe.markasflagged'),
'swipe-read' => array('label' => 'swipe.markasread'),
'swipe-select' => array('label' => 'select')
)
),
'contactlist' => array(
'vertical' => [
'checkmail' => ['label' => 'checkmail']
],
'horizontal' => [
'archive' => ['label' => 'archive.buttontext', 'plugin' => true, 'condition' => 'config:archive_folder !== false'],
'delete' => ['label' => 'delete'],
'forward' => ['label' => 'forward'],
'markasjunk' => ['label' => 'markasjunk.markasjunk', 'plugin' => true],
'move' => ['label' => 'moveto'],
'reply' => ['label' => 'reply'],
'reply-all' => ['label' => 'replyall'],
'swipe-flagged' => ['label' => 'swipe.markasflagged'],
'swipe-read' => ['label' => 'swipe.markasread'],
'swipe-select' => ['label' => 'select']
]
],
'contactlist' => [
'list_name' => 'contact_list',
'selection_id' => 'cid',
'vertical' => array(),
'horizontal' => array(
'vcard_attachments' => array('label' => 'vcard_attachments.forwardvcard', 'plugin' => true),
'compose' => array('label' => 'compose'),
'delete' => array('label' => 'delete'),
'swipe-select' => array('label' => 'select')
)
),
'vertical' => [],
'horizontal' => [
'vcard_attachments' => ['label' => 'vcard_attachments.forwardvcard', 'plugin' => true],
'compose' => ['label' => 'compose'],
'delete' => ['label' => 'delete'],
'swipe-select' => ['label' => 'select']
]
],
'none' => null
);
];
private $rcube;
private $list_type;

Expand All @@ -85,8 +84,8 @@ public function init()
$this->list_type = 'none';
}

$this->add_hook('ready', array($this, 'setup'));
$this->register_action('plugin.swipe.save_settings', array($this, 'save_settings'));
$this->add_hook('ready', [$this, 'setup']);
$this->register_action('plugin.swipe.save_settings', [$this, 'save_settings']);
}

public function setup()
Expand All @@ -97,11 +96,10 @@ public function setup()

$this->_load_config();

$this->menu_file = '/' . $this->local_skin_path() . '/includes/menu.html';
$filepath = slashify($this->home) . $this->menu_file;
if (is_file($filepath) && is_readable($filepath)) {
// check if current skin is supported (if menu template exists)
if ($file_info = $this->_get_include_file('menu.html')) {
// Allow other plugins to interact with the actions list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', array('list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]));
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', ['list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]]);
$this->list_type = $data['list_type'];
$this->actions[$this->list_type] = $data['actions'];

Expand All @@ -111,11 +109,11 @@ public function setup()
}

$config = $this->config[$this->list_type];
$this->rcube->output->set_env('swipe_actions', array(
$this->rcube->output->set_env('swipe_actions', [
'left' => $config['left'],
'right' => $config['right'],
'down' => $config['down']
));
]);
$this->rcube->output->set_env('swipe_list_name', $this->actions[$this->list_type]['list_name']);
$this->rcube->output->set_env('swipe_selection_id', $this->actions[$this->list_type]['selection_id']);

Expand All @@ -126,19 +124,23 @@ public function setup()

if ($this->_allowed_action('*')) {
// add swipe actions link to the menu
$this->add_button(array(
$this->add_button([
'id' => 'plugin-swipe-options-btn',
'command' => 'plugin.swipe.options',
'type' => 'link',
'class' => 'button swipe disabled',
'classact' => 'button swipe',
'title' => 'swipe.swipeoptions',
'innerclass' => 'inner',
'label' => 'swipe.swipeoptions'
), 'listcontrols');
], 'listcontrols');

// add swipe actions popup menu
$this->rcube->output->add_handler('swipeoptionslist', array($this, 'options_list'));
$html = $this->rcube->output->just_parse("<roundcube:include file=\"$this->menu_file\" skinpath=\"plugins/swipe\" />");
$this->rcube->output->add_handler('swipeoptionslist', [$this, 'options_list']);

// parse swipe options menu and add to output
list($path, $include_path) = $file_info;
$html = $this->rcube->output->just_parse("<roundcube:include file=\"/$path\" skinpath=\"$include_path\" />");
$this->rcube->output->add_footer($html);
}
}
Expand All @@ -151,7 +153,7 @@ public function options_list($args)
$args['id'] = 'swipeoptions-' . $args['direction'];
$args['name'] = 'swipe_' . $args['direction'];

$options = array();
$options = [];
foreach ($swipe_actions as $action => $info) {
if (!$this->_allowed_action($args['direction'], $action, $info)) {
continue;
Expand All @@ -163,15 +165,15 @@ public function options_list($args)

// don't add none if there are no available actions, JS detects empty lists and hides the option
if (!empty($options)) {
$options = array('none' => $this->gettext('none')) + $options;
$options = ['none' => $this->gettext('none')] + $options;
}

$config = $this->config[$this->list_type];
switch ($args['type']) {
case 'radio':
foreach ($options as $val => $text) {
$fieldid = $args['id'] . '-' . $val;
$radio = new html_radiobutton(array('name' => $args['name'], 'id' => $fieldid, 'class' => $val, 'value' => $val));
$radio = new html_radiobutton(['name' => $args['name'], 'id' => $fieldid, 'class' => $val, 'value' => $val]);
$radio = $radio->show($config[$args['direction']]);
$field = $radio . html::label($fieldid, $text);
}
Expand All @@ -193,19 +195,19 @@ public function save_settings()
$this->_load_config();

// Allow other plugins to interact with the actions list
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', array('list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]));
$data = rcube::get_instance()->plugins->exec_hook('swipe_actions', ['list_type' => $this->list_type, 'actions' => $this->actions[$this->list_type]]);
$this->list_type = $data['list_type'];

$save = false;
foreach (array('left', 'right', 'down') as $direction) {
foreach (['left', 'right', 'down'] as $direction) {
if (($prop = rcube_utils::get_input_value('swipe_' . $direction, rcube_utils::INPUT_POST)) && $this->_allowed_action($direction)) {
$this->config[$this->list_type][$direction] = $prop;
$save = true;
}
}

if ($save) {
rcube::get_instance()->user->save_prefs(array('swipe_actions' => $this->config));
rcube::get_instance()->user->save_prefs(['swipe_actions' => $this->config]);
}
}

Expand All @@ -218,12 +220,12 @@ private function _load_config()
// initialize internal config
foreach (array_keys($this->actions) as $list) {
if ($list != 'none') {
$this->config[$list] = array('left' => 'none', 'right' => 'none', 'down' => 'none');
$this->config[$list] = ['left' => 'none', 'right' => 'none', 'down' => 'none'];
}
}

// get user config
$config = $this->rcube->config->get('swipe_actions', array());
$config = $this->rcube->config->get('swipe_actions', []);

// remove disabled actions
foreach ($config as $list => $opts) {
Expand Down Expand Up @@ -268,25 +270,41 @@ private function _eval_expression($expression)
{
// from rcmail_output_html::eval_expression()
$expression = preg_replace(
array(
[
'/session:([a-z0-9_]+)/i',
'/config:([a-z0-9_]+)(:([a-z0-9_]+))?/i',
'/env:([a-z0-9_]+)/i',
'/request:([a-z0-9_]+)/i',
'/cookie:([a-z0-9_]+)/i',
'/browser:([a-z0-9_]+)/i',
),
array(
],
[
"\$_SESSION['\\1']",
"\$this->rcube->config->get('\\1',rcube_utils::get_boolean('\\3'))",
"\$this->rcube->output->env['\\1']",
"rcube_utils::get_input_value('\\1', rcube_utils::INPUT_GPC)",
"\$_COOKIE['\\1']",
"\$this->rcmail->output->browser->{'\\1'}",
),
],
$expression
);

return eval("return ($expression);");
}

private function _get_include_file($file)
{
$file_info = false;

$base_path = slashify($this->home);
$rel_path = $this->local_skin_path() . '/includes/' . $file;
// path to skin folder relative to Roundcube root for template engine
$template_include_path = 'plugins/' . $this->ID;

if (is_file($base_path . $rel_path) && is_readable($base_path . $rel_path)) {
$file_info = [$rel_path, $template_include_path];
}

return $file_info;
}
}

0 comments on commit c9270e9

Please sign in to comment.