Mercurial > hg > rc1
comparison plugins/thunderbird_labels/thunderbird_labels.php @ 23:5a851d965bc1
sorting, some better displays
author | Charlie Root |
---|---|
date | Wed, 17 Jan 2018 09:13:17 -0500 |
parents | 678dcc5152a8 |
children | 4869fae20b88 |
comparison
equal
deleted
inserted
replaced
22:61316094e61d | 23:5a851d965bc1 |
---|---|
100 $c = $this->rc->config->get('tb_label_custom_labels'); | 100 $c = $this->rc->config->get('tb_label_custom_labels'); |
101 if (empty($c)) | 101 if (empty($c)) |
102 { | 102 { |
103 // if no user specific labels, use localized strings by default | 103 // if no user specific labels, use localized strings by default |
104 $max_id = $this->rc->config->get('tb_max_label'); | 104 $max_id = $this->rc->config->get('tb_max_label'); |
105 $parmLabs = array(); | |
105 $tb_flag_text = array(); | 106 $tb_flag_text = array(); |
106 for ($i = 0; $i <= $max_id; $i++) { | 107 for ($i = 0; $i <= $max_id; $i++) { |
107 $tb_flag_text[$i] = $this->getText('label'.$i); | 108 $lab=$this->getText('label'.$i); |
109 $isParm=($lab[-1]=='1'); | |
110 $lab=substr($lab,0,strlen($lab)-1); | |
111 $tb_flag_text[$i] = $lab; | |
112 if ($isParm) { | |
113 $parmLabs[$i]=strtolower($lab); | |
114 } | |
108 } | 115 } |
109 $this->rc->config->set('tb_label_custom_labels', | 116 $this->rc->config->set('tb_label_custom_labels', |
110 tb_flag_text); | 117 $tb_flag_text); |
118 $this->rc->config->set('tb_label_parm_labels', | |
119 $parmLabs); | |
111 } | 120 } |
112 // pass label strings to JS | 121 // pass label strings to JS |
113 $this->rc->output->set_env('tb_label_custom_labels', $this->rc->config->get('tb_label_custom_labels')); | 122 $this->rc->output->set_env('tb_label_custom_labels', $this->rc->config->get('tb_label_custom_labels')); |
123 $this->rc->output->set_env('tb_label_parm_labels', $this->rc->config->get('tb_label_parm_labels')); | |
114 } | 124 } |
115 | 125 |
116 // create a section for the tb-labels Settings | 126 // create a section for the tb-labels Settings |
117 public function prefs_section($args) | 127 public function prefs_section($args) |
118 { | 128 { |
185 $key = 'tb_label_custom_labels'; | 195 $key = 'tb_label_custom_labels'; |
186 if (!in_array($key, $dont_override) | 196 if (!in_array($key, $dont_override) |
187 && $this->rc->config->get('tb_label_modify_labels')) | 197 && $this->rc->config->get('tb_label_modify_labels')) |
188 { | 198 { |
189 $old = $this->rc->config->get($key); | 199 $old = $this->rc->config->get($key); |
200 $oldParms = $this->rc->config->get('tb_label_parm_labels'); | |
190 $max_id = $this->rc->config->get('tb_max_label'); | 201 $max_id = $this->rc->config->get('tb_max_label'); |
191 for($i=1; $i<=$max_id; $i++) | 202 for($i=1; $i<=$max_id; $i++) |
192 { | 203 { |
193 $oldVal = $old[$i]; | 204 $oldVal = $old[$i]; |
194 $oname=substr($oldVal,0,-1); | 205 $oparm=$oldParms[$i]?1:0; |
195 $oparm=substr($oldVal,-1); | |
196 $input = new html_inputfield(array( | 206 $input = new html_inputfield(array( |
197 'name' => $key.$i, | 207 'name' => $key.$i, |
198 'id' => $key.$i, | 208 'id' => $key.$i, |
199 'type' => 'text', | 209 'type' => 'text', |
200 'autocomplete' => 'off', | 210 'autocomplete' => 'off', |
201 'value' => $oname)); | 211 'value' => $oldVal)); |
202 $parmBox = new html_checkbox(array( | 212 $parmBox = new html_checkbox(array( |
203 'name' => $key.$i.'parm', | 213 'name' => $key.$i.'parm', |
204 'id' => $key.$i.'parm', | 214 'id' => $key.$i.'parm', |
205 'value' => 1)); | 215 'value' => 1)); |
206 $args['blocks']['tb_label']['options'][$key.$i] = array( | 216 $args['blocks']['tb_label']['options'][$key.$i] = array( |
236 if (!in_array('tb_label_custom_labels', $dont_override) | 246 if (!in_array('tb_label_custom_labels', $dont_override) |
237 && $this->rc->config->get('tb_label_modify_labels')) | 247 && $this->rc->config->get('tb_label_modify_labels')) |
238 { | 248 { |
239 $max_id = $this->rc->config->get('tb_max_label'); | 249 $max_id = $this->rc->config->get('tb_max_label'); |
240 $tb_lab_prefs = array(); | 250 $tb_lab_prefs = array(); |
251 $tb_parm_prefs = array(); | |
241 $tb_lab_prefs[0] = $this->gettext('label0'); | 252 $tb_lab_prefs[0] = $this->gettext('label0'); |
242 for ($i = 1; $i <= $max_id; $i++) { | 253 for ($i = 1; $i <= $max_id; $i++) { |
243 $parm=rcube_utils::get_input_value('tb_label_custom_labels'.$i.'parm', rcube_utils::INPUT_POST)?'1':'0'; | 254 $tb_lab_prefs[$i] = rcube_utils::get_input_value('tb_label_custom_labels'.$i, rcube_utils::INPUT_POST); |
244 $tb_lab_prefs[$i] = rcube_utils::get_input_value('tb_label_custom_labels'.$i, rcube_utils::INPUT_POST).$parm; | 255 if (rcube_utils::get_input_value('tb_label_custom_labels'.$i.'parm', rcube_utils::INPUT_POST)) { |
256 $tb_parm_prefs[$i] = strtolower($tb_lab_prefs[$i]); | |
257 } | |
245 } | 258 } |
246 $args['prefs']['tb_label_custom_labels'] = $tb_lab_prefs; | 259 $args['prefs']['tb_label_custom_labels'] = $tb_lab_prefs; |
260 $args['prefs']['tb_label_parm_labels'] = $tb_parm_prefs; | |
247 } | 261 } |
248 | 262 |
249 return $args; | 263 return $args; |
250 } | 264 } |
251 | 265 |
316 return $p; | 330 return $p; |
317 } | 331 } |
318 | 332 |
319 public function read_flags($args) | 333 public function read_flags($args) |
320 { | 334 { |
321 rcube::write_log($this->name, "read: ".print_r($args, true)); | 335 rcube::write_log($this->name, "read: ".$_SESSION['sort_col']); |
322 // add color information for all messages | 336 // add color information for all messages |
323 // dont loop over all messages if we dont have any highlights or no msgs | 337 // dont loop over all messages if we dont have any highlights or no msgs |
324 if (!isset($args['messages']) or !is_array($args['messages'])) { | 338 if (!isset($args['messages']) or !is_array($args['messages'])) { |
325 return $args; | 339 return $args; |
326 } | 340 } |
327 | |
328 // loop over all messages and add $LabelX info to the extra_flags | 341 // loop over all messages and add $LabelX info to the extra_flags |
329 foreach($args['messages'] as $message) | 342 foreach($args['messages'] as $message) |
330 { | 343 { |
331 #rcube::write_log($this->name, print_r($message->flags, true)); | 344 #rcube::write_log($this->name, print_r($message->flags, true)); |
332 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! | 345 $message->list_flags['extra_flags']['tb_labels'] = array(); # always set extra_flags, needed for javascript later! |
333 $message->list_flags['extra_flags']['tb_parms'] = array(); | 346 $message->list_flags['extra_flags']['tb_parms'] = array(); |
347 $keyPos = array_search($_SESSION['sort_col'],$this->rc->config->get('tb_label_parm_labels')); | |
348 rcube::write_log($this->name,"sort? $keyPos ".$_SESSION['sort_order']." ".print_r($this->rc->config->get('tb_label_parm_labels'),true)); | |
334 if (is_array($message->flags)) | 349 if (is_array($message->flags)) |
335 foreach ($message->flags as $flagname => $flagvalue) | 350 foreach ($message->flags as $flagname => $flagvalue) |
336 { | 351 { |
337 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 | 352 $flag = is_numeric("$flagvalue")? $flagname:$flagvalue;// for compatibility with < 0.5.4 |
338 $flag = strtolower($flag); | 353 $flag = strtolower($flag); |
340 { | 355 { |
341 $flag_no = preg_replace('/^\$?label/', '', $flag); | 356 $flag_no = preg_replace('/^\$?label/', '', $flag); |
342 rcube::write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); | 357 rcube::write_log($this->name, "Flag:".$flag." Flag_no:".$flag_no); |
343 if ($ppos = strpos($flag_no,'_') > -1) { | 358 if ($ppos = strpos($flag_no,'_') > -1) { |
344 // We have a flag parameter value... | 359 // We have a flag parameter value... |
360 $pn=(int)substr($flag_no,0,$ppos); | |
361 $pv=substr($flag_no,$ppos+1); | |
345 $message->list_flags['extra_flags']['tb_lparms'][]=array( | 362 $message->list_flags['extra_flags']['tb_lparms'][]=array( |
346 'number' => substr($flag_no,0,$ppos), | 363 'number' => $pn, |
347 'parm' => substr($flag_no,$ppos+1)); | 364 'parm' => $pv); |
365 if ($keyPos) { | |
366 $message->sortKey=array_map('intval',preg_split('/[/-]/',$pv)); | |
367 } | |
348 } | 368 } |
349 else { | 369 else { |
350 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; | 370 $message->list_flags['extra_flags']['tb_labels'][] = (int)$flag_no; |
351 } | 371 } |
352 } | 372 } |
353 } | 373 } |
374 } | |
375 if ($keyPos) { | |
376 $rev = $_SESSION['sort_order']=='DESC'; | |
377 usort($args['messages'], | |
378 function($a, $b) use ($rev) { | |
379 if ($ak=$a->sortKey) { | |
380 if ($bk=$b->sortKey) { | |
381 // each key is sd sm ed em | |
382 if ($ak[1]<$bk[1]) return $rev?1:-1; | |
383 if ($ak[1]>$bk[1]) return $rev?-1:1; | |
384 // start month is the same | |
385 if ($ak[0]<$bk[0]) return $rev?1:-1; | |
386 if ($ak[0]>$bk[0]) return $rev?-1:1; | |
387 // start date is the same | |
388 if ($ak[3]<$bk[3]) return $rev?1:-1; | |
389 if ($ak[3]>$bk[3]) return $rev?-1:1; | |
390 // end month is the same | |
391 if ($ak[2]<$bk[2]) return $rev?1:-1; | |
392 if ($ak[2]>$bk[2]) return $rev?-1:1; | |
393 // both dates are the same | |
394 return 0; | |
395 } | |
396 else { | |
397 return $rev?1:-1; | |
398 } | |
399 } | |
400 else if ($b->sortKey) { | |
401 return $rev?-1:1; | |
402 } | |
403 else { | |
404 return 0; | |
405 } | |
406 }); | |
354 } | 407 } |
355 return($args); | 408 return($args); |
356 } | 409 } |
357 | 410 |
358 // set flags in IMAP server | 411 // set flags in IMAP server |