comparison plugins/thunderbird_labels/thunderbird_labels.php @ 1:5821049f1791

most of the way to allowing arbitrarily many labels
author Charlie Root
date Thu, 04 Jan 2018 16:23:36 -0500
parents 1e000243b222
children c828b0fd4a6e
comparison
equal deleted inserted replaced
0:1e000243b222 1:5821049f1791
43 $this->add_hook('render_page', array($this, 'tb_label_popup')); 43 $this->add_hook('render_page', array($this, 'tb_label_popup'));
44 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); 44 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css');
45 45
46 $this->name = get_class($this); 46 $this->name = get_class($this);
47 # -- additional TB flags 47 # -- additional TB flags
48 $this->add_tb_flags = array( 48 $this->add_tb_flags = array();
49 'LABEL1' => '$Label1', 49 $max_id = $this->rc->config->get('tb_max_label');
50 'LABEL2' => '$Label2', 50 for ($i = 1; $i <= $max_id; $i++) {
51 'LABEL3' => '$Label3', 51 $this->add_tb_flags['LABEL'.$i]='$Label'.$i;
52 'LABEL4' => '$Label4', 52 }
53 'LABEL5' => '$Label5',
54 );
55 $this->message_tb_labels = array(); 53 $this->message_tb_labels = array();
56 54
57 $this->add_button( 55 $this->add_button(
58 array( 56 array(
59 'command' => 'plugin.thunderbird_labels.rcm_tb_label_submenu', 57 'command' => 'plugin.thunderbird_labels.rcm_tb_label_submenu',
75 if (method_exists($this, 'require_plugin') 73 if (method_exists($this, 'require_plugin')
76 && in_array('contextmenu', $this->rc->config->get('plugins')) 74 && in_array('contextmenu', $this->rc->config->get('plugins'))
77 && $this->require_plugin('contextmenu') 75 && $this->require_plugin('contextmenu')
78 && $this->rc->config->get('tb_label_enable_contextmenu')) 76 && $this->rc->config->get('tb_label_enable_contextmenu'))
79 { 77 {
80 if ($this->rc->action == '') 78 if ($this->rc->action == 'list')
81 $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu')); 79 $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu'));
80 rcube::write_log('lab','ctxt: '.$this->rc->action);
81 }
82 else {
83 rcube::write_log('lab','no ctxt');
82 } 84 }
83 } 85 }
84 elseif ($this->rc->task == 'settings') 86 elseif ($this->rc->task == 'settings')
85 { 87 {
86 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); 88 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css');
94 { 96 {
95 $c = $this->rc->config->get('tb_label_custom_labels'); 97 $c = $this->rc->config->get('tb_label_custom_labels');
96 if (empty($c)) 98 if (empty($c))
97 { 99 {
98 // if no user specific labels, use localized strings by default 100 // if no user specific labels, use localized strings by default
99 $this->rc->config->set('tb_label_custom_labels', array( 101 $max_id = $this->rc->config->get('tb_max_label');
100 0 => $this->getText('label0'), 102 $tb_flag_text = array();
101 1 => $this->getText('label1'), 103 for ($i = 0; $i <= $max_id; $i++) {
102 2 => $this->getText('label2'), 104 $tb_flag_text[$i] = $this->getText('label'.$i);
103 3 => $this->getText('label3'), 105 }
104 4 => $this->getText('label4'), 106 $this->rc->config->set('tb_label_custom_labels',
105 5 => $this->getText('label5') 107 tb_flag_text);
106 ));
107 } 108 }
108 // pass label strings to JS 109 // pass label strings to JS
109 $this->rc->output->set_env('tb_label_custom_labels', $this->rc->config->get('tb_label_custom_labels')); 110 $this->rc->output->set_env('tb_label_custom_labels', $this->rc->config->get('tb_label_custom_labels'));
110 } 111 }
111 112
181 $key = 'tb_label_custom_labels'; 182 $key = 'tb_label_custom_labels';
182 if (!in_array($key, $dont_override) 183 if (!in_array($key, $dont_override)
183 && $this->rc->config->get('tb_label_modify_labels')) 184 && $this->rc->config->get('tb_label_modify_labels'))
184 { 185 {
185 $old = $this->rc->config->get($key); 186 $old = $this->rc->config->get($key);
186 for($i=1; $i<=5; $i++) 187 $max_id = $this->rc->config->get('tb_max_label');
188 for($i=1; $i<=$max_id; $i++)
187 { 189 {
188 $input = new html_inputfield(array( 190 $input = new html_inputfield(array(
189 'name' => $key.$i, 191 'name' => $key.$i,
190 'id' => $key.$i, 192 'id' => $key.$i,
191 'type' => 'text', 193 'type' => 'text',
222 $args['prefs']['tb_label_style'] = rcube_utils::get_input_value('tb_label_style', rcube_utils::INPUT_POST); 224 $args['prefs']['tb_label_style'] = rcube_utils::get_input_value('tb_label_style', rcube_utils::INPUT_POST);
223 225
224 if (!in_array('tb_label_custom_labels', $dont_override) 226 if (!in_array('tb_label_custom_labels', $dont_override)
225 && $this->rc->config->get('tb_label_modify_labels')) 227 && $this->rc->config->get('tb_label_modify_labels'))
226 { 228 {
227 $args['prefs']['tb_label_custom_labels'] = array( 229 $max_id = $this->rc->config->get('tb_max_label');
228 0 => $this->gettext('label0'), 230 $tb_lab_prefs = array();
229 1 => rcube_utils::get_input_value('tb_label_custom_labels1', rcube_utils::INPUT_POST), 231 $tb_lab_prefs[0] = $this->gettext('label0');
230 2 => rcube_utils::get_input_value('tb_label_custom_labels2', rcube_utils::INPUT_POST), 232 for ($i = 1; $i <= $max_id; $i++) {
231 3 => rcube_utils::get_input_value('tb_label_custom_labels3', rcube_utils::INPUT_POST), 233 $tb_lab_prefs[$i] = rcube_utils::get_input_value('tb_label_custom_labels'.$i, rcube_utils::INPUT_POST);
232 4 => rcube_utils::get_input_value('tb_label_custom_labels4', rcube_utils::INPUT_POST), 234 }
233 5 => rcube_utils::get_input_value('tb_label_custom_labels5', rcube_utils::INPUT_POST)
234 );
235 } 235 }
236 236
237 return $args; 237 return $args;
238 } 238 }
239 239
240 public function show_tb_label_contextmenu($args) 240 public function show_tb_label_contextmenu($args)
241 { 241 {
242 #$this->api->output->add_label('copymessage.copyingmessage'); 242 #$this->api->output->add_label('copymessage.copyingmessage');
243 243 rcube::write_log('lab',"stblc");
244 $li = html::tag('li', 244 $li = html::tag('li',
245 array('class' => 'submenu'), 245 array('class' => 'submenu'),
246 '<span>'.rcube::Q($this->gettext('tb_label_contextmenu_title')).'</span>' . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu')); 246 '<span>'.rcube::Q($this->gettext('tb_label_contextmenu_title')).'</span>' . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu'));
247 $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li); 247 $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li);
248 $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out)); 248 $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out));
250 250
251 private function _gen_label_submenu($args, $id) 251 private function _gen_label_submenu($args, $id)
252 { 252 {
253 $out = ''; 253 $out = '';
254 $custom_labels = $this->rc->config->get('tb_label_custom_labels'); 254 $custom_labels = $this->rc->config->get('tb_label_custom_labels');
255 for ($i = 0; $i < 6; $i++) 255 $max_id = $this->rc->config->get('tb_max_label');
256 for ($i = 0; $i <= $max_id; $i++)
256 { 257 {
257 $separator = ($i == 0)? ' separator_below' :''; 258 $separator = ($i == 0)? ' separator_below' :'';
258 $out .= '<li class="label'.$i.$separator. 259 $out .= '<li class="label'.$i.$separator.
259 ' ctxm_tb_label"><a href="#ctxm_tb_label" class="active" onclick="rcmail_ctxm_label_set('.$i.')"><span>'. 260 ' ctxm_tb_label"><a href="#ctxm_tb_label" class="active" onclick="rcmail_ctxm_label_set('.$i.')"><span>'.
260 $i.' '.$custom_labels[$i]. 261 $i.' '.$custom_labels[$i].
363 } 364 }
364 365
365 function tb_label_popup() 366 function tb_label_popup()
366 { 367 {
367 $custom_labels = $this->rc->config->get('tb_label_custom_labels'); 368 $custom_labels = $this->rc->config->get('tb_label_custom_labels');
369 $max_id = $this->rc->config->get('tb_max_label');
368 $out = '<div id="tb_label_popup" class="popupmenu"> 370 $out = '<div id="tb_label_popup" class="popupmenu">
369 <ul class="toolbarmenu">'; 371 <ul class="toolbarmenu">';
370 for ($i = 0; $i < 6; $i++) 372 for ($i = 0; $i <= $max_id; $i++)
371 { 373 {
372 $separator = ($i == 0)? ' separator_below' :''; 374 $separator = ($i == 0)? ' separator_below' :'';
373 $out .= '<li class="label'.$i.$separator.'"><a href="#" class="active">'.$i.' '.$custom_labels[$i].'</a></li>'; 375 $out .= '<li class="label'.$i.$separator.'"><a href="#" class="active">'.$i.' '.$custom_labels[$i].'</a></li>';
374 } 376 }
375 $out .= '</ul> 377 $out .= '</ul>