From 59478e06c25303a790a0840ab2ac30662c4ef781 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 5 Aug 2014 16:46:22 +0200 Subject: c'est la merde.. --- plugins/thunderbird_labels/localization/bg_BG.inc | 17 + plugins/thunderbird_labels/localization/ca_ES.inc | 17 + plugins/thunderbird_labels/localization/cs_CZ.inc | 18 + plugins/thunderbird_labels/localization/de_DE.inc | 18 + plugins/thunderbird_labels/localization/en_US.inc | 18 + plugins/thunderbird_labels/localization/fr_FR.inc | 17 + plugins/thunderbird_labels/localization/hu_HU.inc | 18 + plugins/thunderbird_labels/localization/lv_LV.inc | 17 + plugins/thunderbird_labels/localization/pl_PL.inc | 18 + plugins/thunderbird_labels/localization/ru_RU.inc | 18 + .../thunderbird_labels/skins/classic/tb_label.css | 183 ++++++++++ .../skins/classic/thunderbird_32.png | Bin 0 -> 3232 bytes .../thunderbird_labels/skins/default/tb_label.css | 183 ++++++++++ .../skins/default/thunderbird_32.png | Bin 0 -> 3232 bytes .../thunderbird_labels/skins/larry/tb_label.css | 170 ++++++++++ .../skins/larry/thunderbird_32.png | Bin 0 -> 2662 bytes plugins/thunderbird_labels/tb_label.js | 369 +++++++++++++++++++++ plugins/thunderbird_labels/thunderbird_labels.php | 210 ++++++++++++ 18 files changed, 1291 insertions(+) create mode 100644 plugins/thunderbird_labels/localization/bg_BG.inc create mode 100644 plugins/thunderbird_labels/localization/ca_ES.inc create mode 100644 plugins/thunderbird_labels/localization/cs_CZ.inc create mode 100644 plugins/thunderbird_labels/localization/de_DE.inc create mode 100644 plugins/thunderbird_labels/localization/en_US.inc create mode 100644 plugins/thunderbird_labels/localization/fr_FR.inc create mode 100644 plugins/thunderbird_labels/localization/hu_HU.inc create mode 100644 plugins/thunderbird_labels/localization/lv_LV.inc create mode 100644 plugins/thunderbird_labels/localization/pl_PL.inc create mode 100644 plugins/thunderbird_labels/localization/ru_RU.inc create mode 100644 plugins/thunderbird_labels/skins/classic/tb_label.css create mode 100644 plugins/thunderbird_labels/skins/classic/thunderbird_32.png create mode 100644 plugins/thunderbird_labels/skins/default/tb_label.css create mode 100644 plugins/thunderbird_labels/skins/default/thunderbird_32.png create mode 100644 plugins/thunderbird_labels/skins/larry/tb_label.css create mode 100644 plugins/thunderbird_labels/skins/larry/thunderbird_32.png create mode 100644 plugins/thunderbird_labels/tb_label.js create mode 100644 plugins/thunderbird_labels/thunderbird_labels.php (limited to 'plugins/thunderbird_labels') diff --git a/plugins/thunderbird_labels/localization/bg_BG.inc b/plugins/thunderbird_labels/localization/bg_BG.inc new file mode 100644 index 000000000..d4f9e45ad --- /dev/null +++ b/plugins/thunderbird_labels/localization/bg_BG.inc @@ -0,0 +1,17 @@ + -1) + tb_labels_for_message.splice(pos, 1); + } + // exit function when in detail mode. when preview is active keep going + if (!rcmail.env.messages) + return; + } + jQuery.each(flag_uids, function (idx, uid) { + var message = rcmail.env.messages[uid]; + var row = rcmail.message_list.rows[uid]; + if (onoff == true) + { + // add colors + var rowobj = $(row.obj); + rowobj.addClass('label'+toggle_label_no); + // add to flag list + message.flags.tb_labels.push(toggle_label_no); + } + else + { + // remove colors + var rowobj = $(row.obj); + rowobj.removeClass('label'+toggle_label_no); + // remove from flag list + var pos = jQuery.inArray(toggle_label_no, message.flags.tb_labels); + if (pos > -1) + message.flags.tb_labels.splice(pos, 1); + } + }); +} + +function rcm_tb_label_flag_msgs(flag_uids, toggle_label_no) +{ + rcm_tb_label_flag_toggle(flag_uids, toggle_label_no, true); +} + +function rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no) +{ + rcm_tb_label_flag_toggle(unflag_uids, toggle_label_no, false); +} + +// helper function to get selected/active messages +function rcm_tb_label_get_selection() +{ + var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; + if (selection.length == 0 && rcmail.env.uid) + selection = [rcmail.env.uid, ]; + return selection; +} + +function rcm_tb_label_create_popupmenu() +{ + for (i = 0; i < 6; i++) + { + var cur_a = $('li.label' + i +' a'); + + // add/remove active class + var selection = rcm_tb_label_get_selection(); + + if (selection.length == 0) + cur_a.removeClass('active'); + else + cur_a.addClass('active'); + } +} + +function rcm_tb_label_init_onclick() +{ + for (i = 0; i < 6; i++) + { + var cur_a = $('#tb_label_popup li.label' + i +' a'); + + // TODO check if click event is defined instead of unbinding? + cur_a.unbind('click'); + cur_a.click(function() { + var toggle_label = $(this).parent().attr('class'); + var toggle_label_no = parseInt(toggle_label.replace('label', '')); + var selection = rcm_tb_label_get_selection(); + + if (!selection.length) + return; + + var from = toggle_label_no; + var to = toggle_label_no + 1; + var unset_all = false; + // special case flag 0 means remove all flags + if (toggle_label_no == 0) + { + from = 1; + to = 6; + unset_all = true; + } + for (i = from; i < to; i++) + { + toggle_label = 'label' + i; + toggle_label_no = i; + // compile list of unflag and flag msgs and then send command + // Thunderbird modifies multiple message flags like it did the first in the selection + // e.g. first message has flag1, you click flag1, every message select loses flag1, the ones not having flag1 don't get it! + var first_toggle_mode = 'on'; + if (rcmail.env.messages) + { + var first_message = rcmail.env.messages[selection[0]]; + if (first_message.flags + && jQuery.inArray(toggle_label_no, + first_message.flags.tb_labels) >= 0 + ) + first_toggle_mode = 'off'; + else + first_toggle_mode = 'on'; + } + else // single message display + { + // flag already set? + if (jQuery.inArray(toggle_label_no, + tb_labels_for_message) >= 0) + first_toggle_mode = 'off'; + } + var flag_uids = []; + var unflag_uids = []; + jQuery.each(selection, function (idx, uid) { + // message list not available (example: in detailview) + if (!rcmail.env.messages) + { + if (first_toggle_mode == 'on') + flag_uids.push(uid); + else + unflag_uids.push(uid); + // make sure for unset all there is the single message id + if (unset_all && unflag_uids.length == 0) + unflag_uids.push(uid); + return; + } + var message = rcmail.env.messages[uid]; + if (message.flags + && jQuery.inArray(toggle_label_no, + message.flags.tb_labels) >= 0 + ) + { + if (first_toggle_mode == 'off') + unflag_uids.push(uid); + } + else + { + if (first_toggle_mode == 'on') + flag_uids.push(uid); + } + }); + + if (unset_all) + flag_uids = []; + + // skip sending flags to backend that are not set anywhere + if (flag_uids.length == 0 + && unflag_uids.length == 0) + continue; + + var str_flag_uids = flag_uids.join(','); + var str_unflag_uids = unflag_uids.join(','); + + var lock = rcmail.set_busy(true, 'loading'); + rcmail.http_request('plugin.thunderbird_labels.set_flags', '_flag_uids=' + str_flag_uids + '&_unflag_uids=' + str_unflag_uids + '&_mbox=' + urlencode(rcmail.env.mailbox) + "&_toggle_label=" + toggle_label, lock); + + // remove/add classes and tb labels from messages in JS + rcm_tb_label_flag_msgs(flag_uids, toggle_label_no); + rcm_tb_label_unflag_msgs(unflag_uids, toggle_label_no); + } + }); + } +} + +function rcmail_ctxm_label(command, el, pos) +{ + // my code works only on selected rows, contextmenu also on unselected + // so if no selection is available, use the uid set by contextmenu plugin + var selection = rcmail.message_list ? rcmail.message_list.get_selection() : []; + + if (!selection.length && !rcmail.env.uid) + return; + if (!selection.length && rcmail.env.uid) + rcmail.message_list.select_row(rcmail.env.uid); + + var cur_a = $('#tb_label_popup li.label' + rcmail.tb_label_no +' a'); + if (cur_a) + { + cur_a.click(); + } + + return; +} + +function rcmail_ctxm_label_set(which) +{ + // hack for my contextmenu submenu hack to propagate the selected label-no + rcmail.tb_label_no = which; +} + + +$(document).ready(function() { + rcm_tb_label_init_onclick(); + // add keyboard shortcuts for normal keyboard and keypad + $(document).keyup(function(e) { + //console.log('Handler for .keyup() called.' + e.which); + var k = e.which; + if ((k > 47 && k < 58) || (k > 95 && k < 106)) + { + var label_no = k % 48; + var cur_a = $('#tb_label_popup li.label' + label_no + ' a'); + + if (cur_a) + { + cur_a.click(); + } + } + }); + + // if exists add contextmenu entries + if (window.rcm_contextmenu_register_command) { + rcm_contextmenu_register_command('ctxm_tb_label', rcmail_ctxm_label, $('#tb_label_ctxm_mainmenu'), 'moreacts', 'after', true); + } + + // single message displayed? + if (window.tb_labels_for_message) + { + jQuery.each(tb_labels_for_message, function(idx, val) + { + rcm_tb_label_flag_msgs([-1,], val); + } + ); + } + + // add roundcube events + rcmail.addEventListener('insertrow', function(event) { rcm_tb_label_insert(event.uid, event.row); }); + + rcmail.addEventListener('init', function(evt) { + // create custom button, JS method, broken layout in Firefox 9 using PHP method now + /*var button = $('').attr('href', '#').attr('id', 'tb_label_popuplink').attr('title', rcmail.gettext('label', 'thunderbird_labels')).html(''); + + button.bind('click', function(e) { + rcmail.command('plugin.thunderbird_labels.rcm_tb_label_submenu', this); + return false; + }); + + // add and register + rcmail.add_element(button, 'toolbar'); + rcmail.register_button('plugin.thunderbird_labels.rcm_tb_label_submenu', 'tb_label_popuplink', 'link'); + */ + rcmail.register_command('plugin.thunderbird_labels.rcm_tb_label_submenu', rcm_tb_label_submenu, true); + }); + + // -- add my submenu to roundcubes UI (for roundcube classic only?) + if (window.rcube_mail_ui) + rcube_mail_ui.prototype.tb_label_popup_add = function() { + add = { + tb_label_popup: {id:'tb_label_popup'} + }; + this.popups = $.extend(this.popups, add); + var obj = $('#'+this.popups.tb_label_popup.id); + if (obj.length) + this.popups.tb_label_popup.obj = obj; + else + delete this.popups.tb_label_popup; + }; + + if (window.rcube_mail_ui) + rcube_mail_ui.prototype.check_tb_popup = function() { + // larry skin doesn't have that variable, popup works automagically, return true + if (typeof this.popups == 'undefined') + return true; + if (this.popups.tb_label_popup) + return true; + else + return false; + }; +}); + diff --git a/plugins/thunderbird_labels/thunderbird_labels.php b/plugins/thunderbird_labels/thunderbird_labels.php new file mode 100644 index 000000000..e6487ae95 --- /dev/null +++ b/plugins/thunderbird_labels/thunderbird_labels.php @@ -0,0 +1,210 @@ +action == 'print') + return; + + $this->include_script('tb_label.js'); + $this->add_texts('localization/', true); + $this->add_hook('messages_list', array($this, 'read_flags')); + $this->add_hook('message_load', array($this, 'read_single_flags')); + $this->add_hook('template_object_messageheaders', array($this, 'color_headers')); + $this->add_hook('render_page', array($this, 'tb_label_popup')); + $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); + + $this->name = get_class($this); + $this->prefs = array('show_labels' => true); + # -- additional TB flags + $this->add_tb_flags = array( + 'LABEL1' => '$Label1', + 'LABEL2' => '$Label2', + 'LABEL3' => '$Label3', + 'LABEL4' => '$Label4', + 'LABEL5' => '$Label5', + ); + $this->message_tb_labels = array(); + + $this->add_button( + array( + 'command' => 'plugin.thunderbird_labels.rcm_tb_label_submenu', + 'id' => 'tb_label_popuplink', + 'title' => 'label', # gets translated + 'domain' => $this->ID, + 'type' => 'link', + 'content' => ' ', # maybe put translated version of "Labels" here? + 'class' => ($rcmail->config->get('skin') == 'larry') ? 'button' : 'tb_noclass', + ), + 'toolbar' + ); + + $this->register_action('plugin.thunderbird_labels.set_flags', array($this, 'set_flags')); + + + if (method_exists($this, 'require_plugin') + && in_array('contextmenu', $rcmail->config->get('plugins')) + && $this->require_plugin('contextmenu')) + { + if ($rcmail->action == '') + $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu')); + } + } + + public function show_tb_label_contextmenu($args) + { + $rcmail = rcmail::get_instance(); + $this->add_texts('localization/'); + #$this->api->output->add_label('copymessage.copyingmessage'); + + $li = html::tag('li', array('class' => 'submenu'), Q($this->gettext('label')) . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu')); + $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li); + $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out)); + } + + private function _gen_label_submenu($args, $id) + { + $rcmail = rcmail::get_instance(); + $out = ''; + for ($i = 0; $i < 6; $i++) + { + $separator = ($i == 0)? ' separator_below' :''; + $out .= '
  • '.$i.' '.$this->gettext('label'.$i).'
  • '; + } + $out = html::tag('ul', array('class' => 'popupmenu toolbarmenu folders', 'id' => $id), $out); + return $out; + } + + public function read_single_flags($args) + { + #write_log($this->name, print_r(($args['object']), true)); + if (!count($this->prefs) + or !isset($args['object']) + ) + return; + + if (is_array($args['object']->headers->flags)) + { + $this->message_tb_labels = array(); + foreach ($args['object']->headers->flags as $flagname => $flagvalue) + { + $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 + $flag = strtolower($flag); + if (preg_match('/^\$?label/', $flag)) + { + $flag_no = preg_replace('/^\$?label/', '', $flag); + #write_log($this->name, "Single message Flag: ".$flag." Flag_no:".$flag_no); + $this->message_tb_labels[] = (int)$flag_no; + } + } + } + # -- no return value for this hook + } + + /** + * Writes labelnumbers for single message display + * Coloring of Message header table happens via Javascript + */ + public function color_headers($p) + { + #write_log($this->name, print_r($p, true)); + # -- always write array, even when empty + $p['content'] .= ''; + return $p; + } + + public function read_flags($args) + { + #write_log($this->name, print_r($args, true)); + // add color information for all messages + #$rcmail = rcmail::get_instance(); + #$this->prefs = $rcmail->config->get('thunderbird_labels', array()); + // dont loop over all messages if we dont have any highlights or no msgs + if (!count($this->prefs) + or !isset($args['messages']) + or !is_array($args['messages'])) + return $args; + + // loop over all messages and add $LabelX info to the extra_flags + foreach($args['messages'] as $message) + { + #write_log($this->name, print_r($message->flags, true)); + $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! + if (is_array($message->flags)) + foreach ($message->flags as $flagname => $flagvalue) + { + $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 + $flag = strtolower($flag); + if (preg_match('/^\$?label/', $flag)) + { + $flag_no = preg_replace('/^\$?label/', '', $flag); + #write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); + $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; + } + } + } + return($args); + } + + function set_flags() + { + #write_log($this->name, print_r($_GET, true)); + + $rcmail = rcmail::get_instance(); + $imap = $rcmail->imap; + $cbox = get_input_value('_cur', RCUBE_INPUT_GET); + $mbox = get_input_value('_mbox', RCUBE_INPUT_GET); + $toggle_label = get_input_value('_toggle_label', RCUBE_INPUT_GET); + $flag_uids = get_input_value('_flag_uids', RCUBE_INPUT_GET); + $flag_uids = explode(',', $flag_uids); + $unflag_uids = get_input_value('_unflag_uids', RCUBE_INPUT_GET); + $unflag_uids = explode(',', $unflag_uids); + + $imap->conn->flags = array_merge($imap->conn->flags, $this->add_tb_flags); + + #write_log($this->name, print_r($flag_uids, true)); + #write_log($this->name, print_r($unflag_uids, true)); + + if (!is_array($unflag_uids) + || !is_array($flag_uids)) + return false; + + $imap->set_flag($flag_uids, $toggle_label, $mbox); + $imap->set_flag($unflag_uids, "UN$toggle_label", $mbox); + + $this->api->output->send(); + } + + function tb_label_popup() + { + $rcmail = rcmail::get_instance(); + $out = '
    + +
    '; + $rcmail->output->add_gui_object('tb_label_popup_obj', 'tb_label_popup'); + $rcmail->output->add_footer($out); + } +} +?> -- cgit v1.2.3