-
Notifications
You must be signed in to change notification settings - Fork 1
/
widgets.php
1304 lines (1162 loc) · 34.4 KB
/
widgets.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* We are trying to use heredoc syntax to preparing some
* common view and forms.
*/
/**
* clean up the textarea input value to remove
* un-necessary characters, such as \r\n
*/
function wptc_widget_clean_textarea($input) {
$ret = str_replace("\r\n", "\n", stripslashes($input));
return apply_filters('wptc_widget_clean_textarea', $ret);
}
/**
* using mediawiki api to parse wiki content
*/
function wptc_widget_mw_parse_content($wiki) {
$wiki_client = get_wiki_client();
$wiki_client->setParameterGet('action', 'parse');
$wiki_client->setParameterGet('format', 'xml');
$wiki_client->setParameterGet('text', $wiki);
$response = $wiki_client->request('GET');
$result = simplexml_load_string(trim($response->getBody()));
//print_r($result);
//echo $result->text();
return (string)$result->parse->text;
}
/**
* parse wiki format to prepare HTML.
*/
function wptc_widget_parse_content($wiki) {
$wkr = new WikiRenderer('trac_to_xhtml');
$ret = $wkr->render($wiki);
//$ret = wptc_widget_mw_parse_content($wiki);
// apply filters to allow user to tweak.
return apply_filters('wptc_widget_parse_content', $ret);
}
/**
* genarate time since for the given time.
* the given time is on UTC/GMT, that is
* the centre time zone. it has no offset.
* trac is save time in UTC format.
*/
function wptc_widget_time_age($time) {
$date = new DateTime($time, new DateTimeZone('UTC'));
$interval = $date->diff(new DateTime('now'));
$totalDays = $interval->days;
$minutes = $interval->m;
$hours = $interval->h;
$days = $interval->d;
$years = $interval->y;
$months = $interval->m;
if ($totalDays >= 42) {
// older than 6 weeks, show month only
$age = $years * 12 + $months + 1;
$age = $age . ' months';
} else if ($totalDays >= 14) {
// older than 2 weeks, show weeks only
$weeks = (int)($totalDays / 7);
$age = $weeks . ' weeks';
} else if ($totalDays > 0) {
// older than 1 day, show days only
$age = $totalDays . ' days';
} else if ($hours > 0) {
$age = $hours . ' hours';
} else if ($minutes > 0) {
$age = $minutes . ' minutes';
} else {
$age = $interval->s . ' seconds';
}
$fullAge =
$interval->format('%y years, %m months, %d days, %h hours and %i minutes');
$ret = <<<EOT
<a title="$fullAge">$age</a>
EOT;
return $ret;
}
/**
* preparing the options for select tag.
* this could be used by type, milestone, version,
* priority dropdown
*/
function wptc_widget_options_html($options, $selected,
$hasEmpty=true,
$useNumeric=false) {
$ret = $hasEmpty ? "<option></option>" : "";
foreach ($options as $option => $label) {
$sel = "";
if (is_numeric($option)) {
if (!$useNumeric) {
// not use numeric!
$option = $label;
}
}
if($option === $selected) {
$sel = "selected=\"selected\"";
}
$opt = <<<EOT
<option value="{$option}" {$sel}>{$label}</option>
EOT;
$ret = $ret . $opt;
}
return apply_filters('wptc_widget_options_html', $ret);
}
/**
*
*/
function wptc_widget_optgroups_html($optgroups, $selected,
$hasEmpty=True) {
$groups = $hasEmpty ? "<option></option>" : "";
foreach($optgroups as $group => $options) {
$optsHtml =
wptc_widget_options_html($options, $selected, false);
$group = <<<EOT
<optgroup label="{$group}">
{$optsHtml}
</optgroup>
EOT;
$groups = $groups . $group;
}
return apply_filters('wptc_widget_optgroups_html', $groups);
}
/**
* prepare the field change maeesage. default format for
* a field change is from trac project and looks like
* following:
* <li>
* <strong>Status</strong>
* changed from <em>new</em> to <em>closed</em>
* </li>
* <li>
* <strong>Resolution</strong>
* set to <em>fixed</em>
* </li>
*/
function wptc_widget_field_change_msg($field, $old, $new) {
if ($field === 'description') {
// only flag description as modified for now.
// TODO: add the diff view for the change.
$change_msg = "modified";
} else if (empty($old)) {
$change_msg = "set to <em>" . $new . "</em>";
} else {
$change_msg = "changed from <em>" . $old .
"</em> to <em>" . $new . "</em>";
}
$msg = <<<EOT
<li>
<strong>{$field}</strong>
{$change_msg}
</li>
EOT;
return apply_filters('wptc_widget_field_change_msg', $msg);
}
/**
* preparing the sprint navigation bar.
*/
function wptc_widget_version_nav($project) {
if(!isset($project)) {
// let using the default project.
$defaults = wptc_widget_ticket_defaults();
$project = $defaults['project'];
}
$mandv = wptc_get_project_mandv($project);
$milestones = array_keys($mandv);
$stoneLis = array();
foreach($milestones as $milestone) {
$stone = $mandv[$milestone][0];
$versions = array_slice($mandv[$milestone], 1);
$versionHrefs = array();
foreach($versions as $version) {
$versionHref = wptc_widget_version_href($version['name']);
$versionHrefs[] = <<<EOT
<li>
<a href="{$versionHref}">{$version['name']}</a>
</li>
EOT;
}
$vHrefs = implode('', $versionHrefs);
$stoneLis[] = <<<EOT
<li>{$stone['name']}
<ul>
$vHrefs
</ul>
</li>
EOT;
}
$ret = "<ul>" . implode('', $stoneLis) . "</ul>";
return apply_filters('wptc_widget_version_nav', $ret);
}
/**
* the ticket finder widget.
* this is more like a sample.
*/
function wptc_widget_ticket_finder($page_slug=null) {
global $post, $current_blog;
$blog_path = $current_blog->path;
$goImageUrl = plugins_url('wp-trac-client/images/ticketGo.gif');
if($page_slug == null) {
// using the current page to display the ticket.
$page_slug = $post->post_name;
}
$form = <<<EOT
<div id="findTicket">
<div style="float: left;">
<label for="ticketnumber"><b>Find Ticket by ID: </b></label>
<input id="ticketnumber" type="text"
maxlength="10" size="8" name="ticket_id">
</div>
<input id="ticketGo" type="image" alt="Go to Ticket"
name="ticketGo" src="{$goImageUrl}"
title="Go to Ticket">
<p><br/><b>
<a href="{$blog_path}{$page_slug}">Create New Ticket</a>
</b></p>
<script type="text/javascript" charset="utf-8">
function gotoTicket(ticket_id) {
if((ticket_id != "") && !isNaN(parseInt(ticket_id))) {
// only handle number
// redirect to ticket details page.
ticket_url = "{$blog_path}{$page_slug}?id=" + ticket_id;
window.location = ticket_url;
}
}
jQuery("#ticketGo").click(function(){
var ticket_id = jQuery("#ticketnumber").val();
gotoTicket(ticket_id);
});
jQuery("#ticketnumber").keypress(function(event) {
if(event.which == 13) {
var ticket_id = this.value;
gotoTicket(ticket_id);
}
});
</script>
</div>
EOT;
return apply_filters('wptc_widget_ticket_finder', $form);
}
/**
* preparing the user href by using wordpress user information.
*/
function wptc_widget_user_href($userName) {
// get WordPress user object.
$wpUser = get_user_by('login', $userName);
if (empty($wpUser)) {
// could not find the user in wordpress database,
// just return the user name.
$href = <<<EOT
<a title="$userName">$userName</a>
EOT;
} else {
$href = <<<EOT
<a href="{$server_url}/members/{$wpUser->user_login}/profile"
title="Email: {$wpUser->user_email}">
{$wpUser->display_name}
</a>
EOT;
}
return apply_filters('wptc_widget_user_href', $href);
}
/**
* generate the href link for version field.
*/
function wptc_widget_version_href($version) {
// using the global variables.
global $post, $current_blog;
$blog_path = $current_blog->path;
$page_slug = $post->post_parent ?
get_page($post->post_parent)->post_name :
$post->post_name;
$href = $blog_path . $page_slug . '?version=' . $version;
return apply_filters('wptc_widget_version_href', $href);
}
/**
* preparing the ticket list
*/
function wptc_widget_tickets_list($tickets, $subpageSlug='ticket') {
global $current_blog;
$blog_path = $current_blog->path;
$ticketTr = array();
$index = 1;
foreach($tickets as $ticket) {
$ticket_owner_href =
wptc_widget_user_href($ticket['owner']);
if($index % 2) {
$evenOrOdd = "odd";
} else {
$evenOrOdd = "even";
}
$index = $index + 1;
$ticketHref = <<<EOT
{$blog_path}{$subpageSlug}?id={$ticket['id']}
EOT;
// TODO: get from priority object.
$prioId = 3;
$ticketTr[] = <<<EOT
<tr class="{$evenOrOdd} prio{$prioId}">
<td class="id">
<a href="{$ticketHref}"
title="View Ticket" class="{$ticket['status']}">
#{$ticket['id']}
</a></td>
<td class="summary">
<a href="{$ticketHref}"
title="View Ticket">
{$ticket['summary']}
</a></td>
<td class="status">
{$ticket['status']}
</td>
<td class="owner">
{$ticket_owner_href}
</td>
<td class="priority">
{$ticket['priority']}
</td>
<td class="type">
{$ticket['type']}
</td>
</tr>
EOT;
}
$ticketTrs = implode('', $ticketTr);
$list = <<<EOT
<div>
<table width="100%" class="listing tickets">
<tbody>
<tr class="trac-columns">
<th class="id">Id</th>
<th class="summary">Summary</th>
<th class="status">Status</th>
<th class="owner">Owner</th>
<th class="priority">Priority</th>
<th class="type">Type</th>
</tr>
{$ticketTrs}
</tbody>
</table>
</div>
EOT;
return apply_filters('wptc_widget_tickets_list', $list);
}
/**
* preparing the ticket properties update/creation form.
*/
function wptc_widget_ticket_fieldset($ticket) {
// let's check this is a new ticket or not
if(isset($ticket)) {
// existing ticket.
$ticket_reporter = $ticket['reporter'];
// no need project and owner field for
// tiecket modification.
$project_owner_tr = "";
} else {
// new ticket.
global $current_user;
$ticket_reporter = $current_user->user_login;
// set up some NECESSARY default values
$ticket = wptc_widget_ticket_defaults();
// preparing for project and owner fiels.
// default owner will be reporter.
$project_owner_tr = <<<EOT
<tr>
<th class="col1">
<label for="field_owner">Owner:</label>
</th>
<td class="col1">
<input id="field_owner" name="field_owner"
value="{$ticket_reporter}">
</td>
<th class="col2">
</th>
<td class="col2">
</td>
</tr>
EOT;
}
// have to define it first.
// project is a custom field.
$project = array_key_exists('project', $ticket) ?
$ticket['project'] : "";
if($project === "") {
$defaults = wptc_widget_ticket_defaults();
$project = $defaults['project'];
}
// preparing options for select tag
$ticket_project_options =
wptc_widget_options_html(wptc_get_ticket_projects(),
$project);
$ticket_type_options =
wptc_widget_options_html(wptc_get_ticket_types(),
$ticket['type']);
$ticket_priority_options =
wptc_widget_options_html(wptc_get_ticket_priorities(),
$ticket['priority']);
$ticket_milestone_options =
wptc_widget_optgroups_html(
wptc_get_ticket_milestones($project),
$ticket['milestone']);
$ticket_component_options =
wptc_widget_options_html(wptc_get_ticket_components(),
$ticket['component']);
$ticket_version_options =
wptc_widget_optgroups_html(
wptc_get_ticket_versions($project, $ticket['milestone']),
$ticket['version']);
$ticket_summary = htmlspecialchars($ticket['summary']);
// the form table.
$propsTable = <<<EOT
<fieldset id="properties">
<legend>Ticket Properties</legend>
<table><tbody>
<tr>
<th><label for="field_summary">Summary:</label></th>
<td class="fullrow" colspan="3">
<input type="text" id="field_summary" name="field_summary"
value="{$ticket_summary}" size="70">
</td>
</tr>
<tr>
<th><label for="field_reporter">Reporter:</label></th>
<td class="fullrow" colspan="3">
<input type="text" id="field_reporter"
name="field_reporter"
value="{$ticket_reporter}" size="70">
</td>
</tr>
<tr>
<th><label for="field-description">Description:</label></th>
<td class="fullrow" colspan="3">
<fieldset class="iefix">
<label for="field-description" id="field-description-help">You may use
<a tabindex="42" href="http://trac.edgewall.org/wiki/WikiFormatting">WikiFormatting</a> here.</label>
<div class="trac-resizable"><div>
<textarea id="field-description" name="field_description" class="wikitext trac-resizable" rows="10" cols="68">{$ticket['description']}</textarea>
<div class="trac-grip" style="margin-left: 2px; margin-right: -2px;">
</div>
</div></div>
</fieldset>
</td>
</tr>
{$project_owner_tr}
<tr>
<th class="col1">
<label for="field-project">Project:</label>
</th>
<td class="col1">
<select id="field-project" name="field_project">
{$ticket_project_options}
</select>
</td>
<th class="col2">
<label for="field-type">Type:</label>
</th>
<td class="col2">
<select id="field-type" name="field_type">
{$ticket_type_options}
</select>
</td>
</tr>
<tr>
<th class="col1">
<label for="field-milestone">Milestone:</label>
</th>
<td class="col1">
<select id="field-milestone" name="field_milestone">
{$ticket_milestone_options}
</select>
</td>
<th class="col2">
<label for="field-priority">Priority:</label>
</th>
<td class="col2">
<select id="field-priority" name="field_priority">
{$ticket_priority_options}
</select>
</td>
</tr>
<tr>
<th class="col1">
<label for="field-version">Sprint:</label>
</th>
<td class="col1">
<select id="field-version" name="field_version">
{$ticket_version_options}
</select>
</td>
<th class="col2">
<label for="field-component">Component:</label>
</th>
<td class="col2">
<select id="field-component" name="field_component">
{$ticket_component_options}
</select>
</td>
</tr>
<tr>
<th>
<label for="field-keywords">Keywords:</label>
</th>
<td class="fullrow" colspan="3">
<input type="text" id="field-keywords" name="field_keywords"
value="{$ticket['keywords']}" size="70">
</td>
</tr>
</tbody></table>
<input type="hidden" id="field-cc" name="field_cc"
value="{$ticket['cc']}" size="70">
</fieldset>
EOT;
return apply_filters('wptc_widget_ticket_fieldset',
$propsTable);
}
/**
* preparing the fieldset for action form.
* available actions,
* current status
* current ownder
*/
function wptc_widget_action_fieldset($actions, $status) {
$actionDivs = array();
foreach($actions as $action) {
// each action has the following format:
// [action, label, hints, [input_fields]]
// now we handle actions one by one
$the_action = "";
$action_checked = '';
switch($action[0]) {
case "leave":
// leave as current status.
$the_action = "as " . $status;
// leave as should alway be the default
// checked option.
$action_checked = 'checked="checked"';
break;
case "reopen":
// nothing here.
$the_action = "";
break;
case "accept":
// nothing here.
$the_action = "";
break;
case "resolve":
$the_action = wptc_widget_action_resolve($action);
break;
case "reassign":
$the_action = wptc_widget_action_reassign($action);
break;
}
// each action is a radio button.
$actionDivs[] = <<<EOT
<div>
<input type="radio" name="action" id="action_{$action[0]}"
value="{$action[0]}" {$action_checked}>
<label for="action_{$action[0]}">{$action[1]}</label>
{$the_action}
<span class="hint">{$action[2]}</span>
</div>
EOT;
}
$divs = implode('', $actionDivs);
$ret = <<<EOT
<fieldset id="action">
<legend>Action</legend>
{$divs}
</fieldset>
EOT;
return apply_filters('wptc_widget_action_fieldset', $ret);
}
/**
* preparing the resolve action fields.
*/
function wptc_widget_action_resolve($action) {
$fields = $action[3][0];
$options = wptc_widget_options_html($fields[2], $fields[1],
false, false);
// the resolve is a select element.
// it will be disabled untile the radio button is selected.
$select = <<<EOT
as
<select name="{$fields[0]}" id="{$fields[0]}" disabled="">
{$options}
</select>
EOT;
return apply_filters('wptc_widget_action_resolve', $select);
}
/**
* preparing the ressign action.
*/
function wptc_widget_action_reassign($action) {
$fields = $action[3][0];
//$options = wptc_widget_options_html($fields[2], $fields[1]);
// the resolve is a select element.
// it will be disabled untile the radio button is selected.
// The following is the right one for default workflow,
// which has the **set_owner** operation for reassign
// action.
// <select name="{$fields[0]}" id="{$fields[0]}" disabled="">
// {$options}
// </select>
$select = <<<EOT
to
<input name="field_owner"
id="field_owner" disabled="">
EOT;
return apply_filters('wptc_widget_action_reassign', $select);
}
/**
* preparing the comment fieldset.
*/
function wptc_widget_comment_fieldset() {
$fieldset = <<<EOT
<fieldset class="iefix">
<label for="wikicomment">You may use
<a tabindex="42" target="_blank"
href="http://trac.edgewall.org/wiki/WikiFormatting">
WikiFormatting</a>
here.</label>
<div class="trac-resizable"><div>
<textarea id="wikicomment" name="wikicomment" class="wikitext trac-resizable" rows="10" cols="78"></textarea>
<div class="trac-grip" style="margin-left: -1px; margin-right: 1px;">
</div>
</div></div>
</fieldset>
EOT;
return apply_filters('wptc_widget_comment_fieldset', $fieldset);
}
/**
* the login reminder for not logged in users.
*/
function wptc_widget_ticket_info_topnav($ticket_id) {
if(is_user_logged_in()) {
// user logged in, return empty string
// to leave topnav empty.
return "";
}
$loginHref = get_option('siteurl') .
"/wp-login.php?redirect_to=" .
urlencode(get_permalink() . "?id=" . $ticket_id);
$topnav = <<<EOT
<div class="trac-topnav">
Please <a href="{$loginHref}">log in</a> to update/comment
</div>
EOT;
return $topnav;
}
/**
* preparing the details info for a ticket
*/
function wptc_widget_ticket_info($ticket) {
// the type and status for this ticket.
$ticket_type_status = $ticket['status'] . " " .
$ticket['type'];
if ($ticket['resolution']) {
$ticket_type_status = $ticket_type_status . ": " .
$ticket['resolution'];
}
// get details info for the reportor
// assume the username is the same as WordPress login_name
$ticket_reporter_href =
wptc_widget_user_href($ticket['reporter']);
$ticket_owner_href =
wptc_widget_user_href($ticket['owner']);
$ticket_version_href =
wptc_widget_version_href($ticket['version']);
// preparing the descriptions.
$ticket_description =
wptc_widget_parse_content($ticket['description']);
$ticket_openedAge =
wptc_widget_time_age($ticket['created']);
$ticket_modifiedAge =
wptc_widget_time_age($ticket['modified']);
$permalink = get_permalink() . "?id=" . $ticket['id'];
$topnav = wptc_widget_ticket_info_topnav($ticket['id']);
$ticketInfo = <<<EOT
{$topnav}
<h1 id="ticket-title">
<a href="{$permalink}">Ticket #{$ticket['id']}</a>
<span class="status">({$ticket_type_status})</span>
</h1>
<div id="ticket">
<div id="ticket-age" class="date">
<p>Opened {$ticket_openedAge} ago</p>
<p>Last modified {$ticket_modifiedAge} ago</p>
</div> <!-- END ticket-age -->
<h2 class="summary searchable">{$ticket['summary']}</h2>
<table class="properties"><tbody>
<tr>
<th id="h_reporter">Reported by:</th>
<td headers="h_reporter" class="searchable">
{$ticket_reporter_href}
</td>
<th id="h_owner">Owned by:</th>
<td headers="h_owner">
{$ticket_owner_href}
</td>
</tr>
<tr>
<th id="h_project">
Project:
</th>
<td headers="h_project">
{$ticket['project']}
</td>
<th id="h_priority">
Priority:
</th>
<td headers="h_priority">
{$ticket['priority']}
</td>
</tr>
<tr>
<th id="h_milestone">
Milestone:
</th>
<td headers="h_milestone">
{$ticket['milestone']}
</td>
<th id="h_component">
Component:
</th>
<td headers="h_component">
{$ticket['component']}
</td>
</tr>
<tr>
<th id="h_version">
Sprint:
</th>
<td headers="h_version">
<a href="{$ticket_version_href}">{$ticket['version']}</a>
</td>
<th id="h_keywords">
Keywords:
</th>
<td headers="h_keywords" class="searchable">
{$ticket['keywords']}
</td>
</tr>
</tbody></table>
<div class="description">
<h3 id="comment:description">
Description
<a class="anchor" href="#comment:description" title="Link to this section"> ¶</a></h3>
<div class="searchable">
{$ticket_description}
</div>
</div><!-- END ticket-description -->
</div><!-- END ticket -->
EOT;
return apply_filters('wptc_widget_ticket_info', $ticketInfo);
}
/**
* preparting the change history for a ticket.
*/
function wptc_widget_ticket_changelog($changelog) {
$changes = array();
// reformat the change log to the following format.
// change time is the array key.
// $changes[time] =
// 'id' => comment id,
// 'author' => change arthor.
// 'comment' =>
// 'change_fields' =>
foreach($changelog as $log) {
// get message from each log.
// trac tracking field's change in one log,
// even it appears to user as one change.
$change_time = $log[0];
$change_author = $log[1];
// time and author will keep the same for all logs
// within one change.
$change_field = $log[2];
$change_oldvalue = $log[3];
$change_newvalue = $log[4];
if ($change_field === "cc") {
// skip changes on cc field, we will have long
// value for cc field. Since we use is as watch list.
continue;
}
// start formating for each field.
// we are using time as the key.
$change = array();
if (array_key_exists($change_time, $changes)) {
// we have this 'time' already, keep working on it.
$change = $changes[$change_time];
} else {
// this is a new 'time', create new change,
$changes[$change_time] = $change;
$change['author'] = $change_author;
}
// we handle comment field differently!
if ($change_field === "comment") {
$change['id'] = $change_oldvalue;
// need a little parse for the comment content
$change['comment'] =
wptc_widget_parse_content($change_newvalue);
} else if (strpos($change_field, '_comm') !== false) {
// do nothing here,
// this log is tracking the comments'
// change history, it looks like '_comment0'
// We do NOT need now!
} else {
$msg = wptc_widget_field_change_msg($change_field,
$change_oldvalue, $change_newvalue);
$change['fields'][] = $msg;
}
// set it back.
$changes[$change_time] = $change;
} // End of foreach, what long one!
$ticketChanges = array();
// one time one change.
// one change one record
//$ticketChange[]
foreach ($changes as $change_time => $change) {
// preparing the fields.
$change_age = wptc_widget_time_age($change_time);
$change_author_href =
wptc_widget_user_href($change['author']);
// check fields is exist or not.
// have to reset here, otherwise it will keep the
// previous change's value.
$change_fields_list = "";
if (array_key_exists('fields', $change)) {
$change_fields_list = implode(" ", $change['fields']);
$change_fields_list = <<<EOT
<ul>
{$change_fields_list}
</ul>
EOT;
}
$ticketChanges[] = <<<EOT
<div class="change" id="trac-change-{$change_id}">
<h3 class="change">
<span class="threading">
<span id="comment:{$change['id']}" class="cnum">
<a href="#comment:{$change['id']}">comment:{$change['id']}</a>
</span>
</span>
Changed {$change_age} ago by {$change_author_href}
</h3>
{$change_fields_list}
<div class="comment searchable">
<p>{$change['comment']}</p>
</div>
</div>
EOT;
}
$changes_html = implode(" ", array_reverse($ticketChanges));
$ticketChangelog = <<<EOT
<div>
<h2 class="foldable">
<a id="no3" href="#no3">Change History</a>
</h2>
<div id="changelog">
{$changes_html}
</div>
</div>
EOT;
return apply_filters('wptc_widget_ticket_changelog', $ticketChangelog);
}
/**
* preparing the ticket ediging form, mainly for
* update ticket properties.
*/
function wptc_widget_new_ticket_form() {
if (! is_user_logged_in()) {
// user not logged in. do nothing here.
$loginHref = get_option('siteurl') .
"/wp-login.php?redirect_to=" .
urlencode(get_permalink());
echo <<<EOT
<div>
<h1 id="ticket-title">
Please <a href="{$loginHref}">log in</a> to
create new ticket!
</h1>
</div>
EOT;
return;
}
// preparing the form.
echo <<<EOT
<div>
<h1 id="ticket-title">Create New Ticket</h1>
<form method="post" id="ticketform">
<div id="modify">
EOT;
// pass a not set variable
echo wptc_widget_ticket_fieldset($ticket);
echo wptc_widget_ticket_fieldset_js();
echo <<<EOT