Mercurial > hg > rc1
comparison plugins/thunderbird_labels/thunderbird_labels.php @ 9:7a7f68b4358e
allow open-ended label inventory
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 09:37:16 -0500 |
parents | c828b0fd4a6e |
children | 49706603be30 |
comparison
equal
deleted
inserted
replaced
8:899c8c6a0519 | 9:7a7f68b4358e |
---|---|
30 | 30 |
31 if (!$this->rc->config->get('tb_label_enable')) | 31 if (!$this->rc->config->get('tb_label_enable')) |
32 // disable plugin according to prefs | 32 // disable plugin according to prefs |
33 return; | 33 return; |
34 | 34 |
35 // pass 'tb_label_enable_shortcuts' and 'tb_label_style' prefs to JS | 35 // how many labels? |
36 $max_id = $this->rc->config->get('tb_max_label'); | |
37 // pass 'tb_max_label', 'tb_label_enable_shortcuts' | |
38 // and 'tb_label_style' prefs to JS | |
39 $this->rc->output->set_env('tb_max_label', $max_id); | |
36 $this->rc->output->set_env('tb_label_enable_shortcuts', $this->rc->config->get('tb_label_enable_shortcuts')); | 40 $this->rc->output->set_env('tb_label_enable_shortcuts', $this->rc->config->get('tb_label_enable_shortcuts')); |
37 $this->rc->output->set_env('tb_label_style', $this->rc->config->get('tb_label_style')); | 41 $this->rc->output->set_env('tb_label_style', $this->rc->config->get('tb_label_style')); |
38 | 42 |
39 $this->include_script('tb_label.js'); | 43 $this->include_script('tb_label.js'); |
40 $this->add_hook('messages_list', array($this, 'read_flags')); | 44 $this->add_hook('messages_list', array($this, 'read_flags')); |
44 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); | 48 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); |
45 | 49 |
46 $this->name = get_class($this); | 50 $this->name = get_class($this); |
47 # -- additional TB flags | 51 # -- additional TB flags |
48 $this->add_tb_flags = array(); | 52 $this->add_tb_flags = array(); |
49 $max_id = $this->rc->config->get('tb_max_label'); | |
50 for ($i = 1; $i <= $max_id; $i++) { | 53 for ($i = 1; $i <= $max_id; $i++) { |
51 $this->add_tb_flags['LABEL'.$i]='$Label'.$i; | 54 $this->add_tb_flags['LABEL'.$i]='$Label'.$i; |
52 } | 55 } |
53 $this->message_tb_labels = array(); | 56 $this->message_tb_labels = array(); |
54 | 57 |
75 && $this->require_plugin('contextmenu') | 78 && $this->require_plugin('contextmenu') |
76 && $this->rc->config->get('tb_label_enable_contextmenu')) | 79 && $this->rc->config->get('tb_label_enable_contextmenu')) |
77 { | 80 { |
78 if ($this->rc->action == 'list') | 81 if ($this->rc->action == 'list') |
79 $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu')); | 82 $this->add_hook('render_mailboxlist', array($this, 'show_tb_label_contextmenu')); |
80 rcube::write_log('lab','ctxt: '.$this->rc->action); | 83 #rcube::write_log('lab','ctxt: '.$this->rc->action); |
81 } | 84 } |
82 else { | 85 else { |
83 rcube::write_log('lab','no ctxt'); | 86 #rcube::write_log('lab','no ctxt'); |
84 } | 87 } |
85 } | 88 } |
86 elseif ($this->rc->task == 'settings') | 89 elseif ($this->rc->task == 'settings') |
87 { | 90 { |
88 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); | 91 $this->include_stylesheet($this->local_skin_path() . '/tb_label.css'); |
205 } | 208 } |
206 | 209 |
207 // save prefs after modified in UI | 210 // save prefs after modified in UI |
208 public function prefs_save($args) | 211 public function prefs_save($args) |
209 { | 212 { |
210 rcube::write_log('lab','saving: '.print_r($args,true)); | 213 #rcube::write_log('lab','saving: '.print_r($args,true)); |
211 if ($args['section'] != 'thunderbird_labels') | 214 if ($args['section'] != 'thunderbird_labels') |
212 return $args; | 215 return $args; |
213 | 216 |
214 | 217 |
215 $this->load_config(); | 218 $this->load_config(); |
240 } | 243 } |
241 | 244 |
242 public function show_tb_label_contextmenu($args) | 245 public function show_tb_label_contextmenu($args) |
243 { | 246 { |
244 #$this->api->output->add_label('copymessage.copyingmessage'); | 247 #$this->api->output->add_label('copymessage.copyingmessage'); |
245 rcube::write_log('lab',"stblc"); | 248 #rcube::write_log('lab',"stblc"); |
246 $li = html::tag('li', | 249 $li = html::tag('li', |
247 array('class' => 'submenu'), | 250 array('class' => 'submenu'), |
248 '<span>'.rcube::Q($this->gettext('tb_label_contextmenu_title')).'</span>' . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu')); | 251 '<span>'.rcube::Q($this->gettext('tb_label_contextmenu_title')).'</span>' . $this->_gen_label_submenu($args, 'tb_label_ctxm_submenu')); |
249 $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li); | 252 $out .= html::tag('ul', array('id' => 'tb_label_ctxm_mainmenu'), $li); |
250 $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out)); | 253 $this->api->output->add_footer(html::div(array('style' => 'display: none;'), $out)); |
267 return $out; | 270 return $out; |
268 } | 271 } |
269 | 272 |
270 public function read_single_flags($args) | 273 public function read_single_flags($args) |
271 { | 274 { |
272 rcube::write_log($this->name, print_r(($args['object']), true)); | 275 #rcube::write_log($this->name, print_r(($args['object']), true)); |
273 if (!isset($args['object'])) { | 276 if (!isset($args['object'])) { |
274 return; | 277 return; |
275 } | 278 } |
276 | 279 |
277 if (is_array($args['object']->headers->flags)) | 280 if (is_array($args['object']->headers->flags)) |
282 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 | 285 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 |
283 $flag = strtolower($flag); | 286 $flag = strtolower($flag); |
284 if (preg_match('/^\$?label/', $flag)) | 287 if (preg_match('/^\$?label/', $flag)) |
285 { | 288 { |
286 $flag_no = preg_replace('/^\$?label/', '', $flag); | 289 $flag_no = preg_replace('/^\$?label/', '', $flag); |
287 rcube::write_log($this->name, "Single message Flag: ".$flag." Flag_no:".$flag_no); | 290 #rcube::write_log($this->name, "Single message Flag: ".$flag." Flag_no:".$flag_no); |
288 $this->message_tb_labels[] = (int)$flag_no; | 291 $this->message_tb_labels[] = (int)$flag_no; |
289 } | 292 } |
290 } | 293 } |
291 } | 294 } |
292 # -- no return value for this hook | 295 # -- no return value for this hook |
296 * Writes labelnumbers for single message display | 299 * Writes labelnumbers for single message display |
297 * Coloring of Message header table happens via Javascript | 300 * Coloring of Message header table happens via Javascript |
298 */ | 301 */ |
299 public function color_headers($p) | 302 public function color_headers($p) |
300 { | 303 { |
301 rcube::write_log($this->name, print_r($p, true)); | 304 #rcube::write_log($this->name, print_r($p, true)); |
302 # -- always write array, even when empty | 305 # -- always write array, even when empty |
303 $p['content'] .= '<script type="text/javascript"> | 306 $p['content'] .= '<script type="text/javascript"> |
304 var tb_labels_for_message = ['.join(',', $this->message_tb_labels).']; | 307 var tb_labels_for_message = ['.join(',', $this->message_tb_labels).']; |
305 </script>'; | 308 </script>'; |
306 return $p; | 309 return $p; |
307 } | 310 } |
308 | 311 |
309 public function read_flags($args) | 312 public function read_flags($args) |
310 { | 313 { |
311 rcube::write_log($this->name, print_r($args, true)); | 314 #rcube::write_log($this->name, print_r($args, true)); |
312 // add color information for all messages | 315 // add color information for all messages |
313 // dont loop over all messages if we dont have any highlights or no msgs | 316 // dont loop over all messages if we dont have any highlights or no msgs |
314 if (!isset($args['messages']) or !is_array($args['messages'])) { | 317 if (!isset($args['messages']) or !is_array($args['messages'])) { |
315 return $args; | 318 return $args; |
316 } | 319 } |
317 | 320 |
318 // loop over all messages and add $LabelX info to the extra_flags | 321 // loop over all messages and add $LabelX info to the extra_flags |
319 foreach($args['messages'] as $message) | 322 foreach($args['messages'] as $message) |
320 { | 323 { |
321 rcube::write_log($this->name, print_r($message->flags, true)); | 324 #rcube::write_log($this->name, print_r($message->flags, true)); |
322 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! | 325 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! |
323 if (is_array($message->flags)) | 326 if (is_array($message->flags)) |
324 foreach ($message->flags as $flagname => $flagvalue) | 327 foreach ($message->flags as $flagname => $flagvalue) |
325 { | 328 { |
326 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 | 329 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 |
327 $flag = strtolower($flag); | 330 $flag = strtolower($flag); |
328 if (preg_match('/^\$?label/', $flag)) | 331 if (preg_match('/^\$?label/', $flag)) |
329 { | 332 { |
330 $flag_no = preg_replace('/^\$?label/', '', $flag); | 333 $flag_no = preg_replace('/^\$?label/', '', $flag); |
331 rcube::write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); | 334 #rcube::write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); |
332 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; | 335 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; |
333 } | 336 } |
334 } | 337 } |
335 } | 338 } |
336 return($args); | 339 return($args); |
337 } | 340 } |
338 | 341 |
339 // set flags in IMAP server | 342 // set flags in IMAP server |
340 function set_flags() | 343 function set_flags() |
341 { | 344 { |
342 rcube::write_log($this->name, print_r($_GET, true)); | 345 #rcube::write_log($this->name, print_r($_GET, true)); |
343 | 346 |
344 $imap = $this->rc->imap; | 347 $imap = $this->rc->imap; |
345 $cbox = rcube_utils::get_input_value('_cur', rcube_utils::INPUT_GET); | 348 $cbox = rcube_utils::get_input_value('_cur', rcube_utils::INPUT_GET); |
346 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET); | 349 $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GET); |
347 $toggle_label = rcube_utils::get_input_value('_toggle_label', rcube_utils::INPUT_GET); | 350 $toggle_label = rcube_utils::get_input_value('_toggle_label', rcube_utils::INPUT_GET); |
350 $unflag_uids = rcube_utils::get_input_value('_unflag_uids', rcube_utils::INPUT_GET); | 353 $unflag_uids = rcube_utils::get_input_value('_unflag_uids', rcube_utils::INPUT_GET); |
351 $unflag_uids = explode(',', $unflag_uids); | 354 $unflag_uids = explode(',', $unflag_uids); |
352 | 355 |
353 $imap->conn->flags = array_merge($imap->conn->flags, $this->add_tb_flags); | 356 $imap->conn->flags = array_merge($imap->conn->flags, $this->add_tb_flags); |
354 | 357 |
355 rcube::write_log($this->name, print_r($flag_uids, true)); | 358 #rcube::write_log($this->name, print_r($flag_uids, true)); |
356 rcube::write_log($this->name, print_r($unflag_uids, true)); | 359 #rcube::write_log($this->name, print_r($unflag_uids, true)); |
357 | 360 |
358 if (!is_array($unflag_uids) | 361 if (!is_array($unflag_uids) |
359 || !is_array($flag_uids)) | 362 || !is_array($flag_uids)) |
360 return false; | 363 return false; |
361 | 364 |