/
Calendar.php
1474 lines (1133 loc) · 49 KB
/
Calendar.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
// this is the "refresh" code that allows the calendar to switch time periods
if (isset($_POST["calendar_info"]) ){
$today = getdate(); // today
$temp = split("`", $_POST["calendar_info"]); // calling calendar info (name,title, etc..)
// set the initial values
$month = $temp[0];
$day = $temp[1];
$year = $temp[2];
$title = $temp[3];
$name = $temp[4];
// the yearSelect and monthSelect must be on top... the onChange triggers
// whenever the other buttons are clicked
if(isset($_POST["yearSelect"])) $year = $_POST["yearSelect"];
if(isset($_POST["monthSelect"])) $month = $_POST["monthSelect"];
if(isset($_POST["yearBack"])) --$year;
if(isset($_POST["yearForward"])) ++$year;
if(isset($_POST["today"])){
$day = $today['mday'];
$month = $today['mon'];
$year = $today['year'];
}
if(isset($_POST["monthBack"])){
$year = ($month == 1 ? --$year : $year);
$month = ($month == 1 ? 12 : --$month);
}
if(isset($_POST["monthForward"])){
$year = ($month == 12 ? ++$year : $year);
$month = ($month == 12 ? 1 : ++$month);
}
if(isset($_POST["weekBack"])){
$arr = getdate( mktime(12, 0, 0,$month, $day-7, $year) );
$month = $arr['mon'];
$day = $arr['mday'];
$year = $arr['year'];
}
if(isset($_POST["weekForward"])){
$arr = getdate( mktime(12, 0, 0,$month, $day+7, $year) );
$month = $arr['mon'];
$day = $arr['mday'];
$year = $arr['year'];
}
if(isset($_POST["viewSelect"])){
$mode = $_POST["viewSelect"];
}
$cookie_name = preg_replace('/(\.|\s)/', '_', ($title . " " . $name)); //replace periods and spaces
$cookie_value = $month . "`" . $day . "`" . $year . "`" . $title . "`" . $name . "`" . $mode . "`";
setcookie($cookie_name, $cookie_value);
if(isset($_POST["ical"])){
$path = "images/";
$path = $path . basename( $_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $path);
setcookie('calendar_ical', $path);
}
// reload the page..clear any purge commands that may be in it from an ical load...
$url = str_replace("&action=purge", "", $_SERVER['REQUEST_URI']);
header("Location: " . $url);
}
# Confirm MW environment
//$gCalendarVersion = "trunk/beta";
# Credits
/*
// calendar conditionals, used to remove the commands from the page view
function calendar(){return "";}
*/
class Calendar extends CalendarArticles
{
var $arrSettings = array();
// [begin] set calendar parameter defaults
var $calendarMode = "normal";
var $title = "";
var $disableConfigLink = true;
var $arrAlerts = array();
var $subscribedPages = array();
var $tag_views = "";
var $invalidateCache = false;
var $isFullSubscribe = false;
function Calendar($wikiRoot) {
$this->wikiRoot = $wikiRoot;
// set the calendar's initial date
$now = getdate();
$this->month = $this->actualMonth = $now['mon'];
$this->year = $this->actualYear = $now['year'];
$this->day = $this->actualDay = $now['mday'];
}
// render the calendar
function renderCalendar($userMode){
$ret = "";
$this->mode = $userMode;
// need to change the running calendar date
// or the other functions wont set correctly
if($userMode == 'day')
$this->updateDate();
$this->initalizeHTML();
$this->readStylepage();
if($this->setting('usetemplates'))
$this->buildTemplateEvents();
if(!$this->setting('disablerecurrences'))
$this->buildVCalEvents();
if($this->paramstring != '')
$this->buildTagEvents($this->paramstring);
//grab last months events for overlapped repeating events
if($this->setting('enablerepeatevents')){
$daysBack = $this->setting('enablerepeatevents',false);
if($daysBack == '') $daysBack = 15; //default - this checks 1/2 way into the previous month
$this->initalizeMonth( ($this->day + $daysBack), 0);
}
else
$this->initalizeMonth($this->day, 0); // just go back to the 1st of the current month
// what mode we going into
if($userMode == 'year')
$ret = $this->renderYear();
if($userMode == 'month')
$ret = $this->renderMonth();
if($userMode == 'simplemonth')
$ret = $this->renderSimpleMonth();
if($userMode == 'week')
$ret = $this->renderWeek($this->setting('5dayweek'));
if($userMode == 'day')
$ret = $this->renderDate();
if($userMode == 'events')
$ret = $this->renderEventList();
//tag on extra info at the end of whatever is displayed
$ret .= $this->buildTrackTimeSummary();
return $ret;
}
// build the months articles into memory
// $back: days back from ($this->day)
// $forward: days ahead from ($this->day)
function initalizeMonth($back, $forward){
// just make sure we have a solid negitive here
$back = -(abs($back));
$cnt = abs($back) + $forward;
$arr_start = Common::datemath($back, $this->month, $this->day, $this->year);
$month = $arr_start['mon'];
$day = $arr_start['mday'];
$year = $arr_start['year'];
for ($i = 1; $i <= $cnt; $i++) {
$this->buildArticlesForDay($month, $day, $year);
Common::getNextValidDate($month, $day, $year);
}
}
function initalizeHTML() {
global $wgOut,$wgScriptPath, $wgVersion;
$cssURL = $this->getURLRelativePath() . "/templates/";
// set paths
$extensionPath = $this->setting('path');
$extensionPath = str_replace("\\", "/", $extensionPath);
$css = $this->setting('css');
$css_data = file_get_contents($extensionPath . "/templates/$css"); //ugly method
$this->html_template = file_get_contents($extensionPath . "/templates/calendar_template.html");
//add css; this is set as 'default.css' or an override
if($wgVersion >= '1.14'){
$wgOut->addStyle($cssURL . $css); //clean method
}
else{
$wgOut->addHTML($css_data); //ugly method
}
$this->templateHTML['normal'] = $this->searchHTML($this->html_template,"<!-- Day Start -->", "<!-- Day End -->");
$this->templateHTML['missing'] = $this->searchHTML($this->html_template,"<!-- Missing Start -->", "<!-- Missing End -->");
$year = Common::translate('year');
$month = Common::translate('month');
$week = Common::translate('week');
if(!$this->setting('disablemodes')){
$selected = "selected='true'";
$this->tag_views = "<select name='viewSelect' method='post' onChange='javascript:this.form.submit()'>";
($this->mode == 'year') ?
$this->tag_views .= "<option class='lst' value='year' $selected>$year</option>" :
$this->tag_views .= "<option class='lst' value='year'>$year</option>";
($this->mode == 'month') ?
$this->tag_views .= "<option class='lst' value='month' $selected>$month</option>" :
$this->tag_views .= "<option class='lst' value='month'>$month</option>";
($this->mode == 'week') ?
$this->tag_views .= "<option class='lst' value='week' $selected>$week</option>" :
$this->tag_views .= "<option class='lst' value='week'>$week</option>";
$this->tag_views .= "</select> ";
}
// build the hidden calendar date info (used to offset the calendar via sessions)
$this->tag_HiddenData = "<input class='btn' type='hidden' name='calendar_info' value='"
. $this->month . "`"
. $this->day . "`"
. $this->year . "`"
. $this->title . "`"
. $this->name . "`"
. "'>";
$this->tag_heading =
'<td class="calendarHeading">[[day1]]</td>
<td class="calendarHeading">[[day2]]</td>
<td class="calendarHeading">[[day3]]</td>
<td class="calendarHeading">[[day4]]</td>
<td class="calendarHeading">[[day5]]</td>';
if(!$this->setting('5dayweek') ){
$this->tag_heading .=
'<td class="calendarHeading">[[day6]]</td>
<td class="calendarHeading">[[day7]]</td>';
}
}
// Generate the HTML for a given month
// $day may be out of range; if so, give blank HTML
function getHTMLForDay($month, $day, $year, $dateFormat='default', $mode='month'){
$tag_eventList = $tag_dayCustom = "";
$tag_dayweekyear = "";
// return an empty plain table cell (includes style class )
if ($day <= 0) {
return $this->templateHTML['missing'];
}
if( $this->setting("5dayweek") ){
$dayOfWeek = date('N', mktime(12, 0, 0, $month, $day, $year)); // 0-6
if($dayOfWeek > 5){
return "";
}
}
// template table cell
$tempString = $this->templateHTML['normal'];
$thedate = getdate(mktime(12, 0, 0, $month, $day, $year));
$wday = $thedate['wday'];
$weekday = Common::translate($wday+1, 'weekday');
$display_day = $day;
if($dateFormat == 'long'){
$display_day = $weekday . ", " . Common::translate($month, 'month_short') . " $day";
}
if($dateFormat == 'none')
$display_day = "";
if ( ($thedate['mon'] == $this->actualMonth) && ($thedate['year'] == $this->actualYear) && ($thedate['mday'] == $this->actualDay) ) {
$tag_wday = "calendarToday";
}
elseif($wday==0 || $wday ==6){
$tag_wday = "calendarWeekend";
}
else {
$tag_wday = "calendarWeekday";
}
$tag_addEvent = $this->buildAddEventLink($month, $day, $year);
$tag_mode = 'monthMode';
if($mode == 'events'){
$tag_mode = 'eventsMode';
$tag_dayCustom = "eventsDay";
}
if($mode=='week'){
$tag_mode = 'weekMode';
}
if($mode == 'day'){
$tag_mode = 'dayMode';
$tag_dayCustom = "singleDay";
}
//build formatted event list
$tag_eventList = $this->getArticleLinks($month, $day, $year, true);
// no events, then return nothing!
if((strlen($tag_eventList) == 0) && ($mode == 'events')) return "";
$tag_alerts = $this->buildAlertLink($day, $month);
if($this->setting('dayofyear')){
$tag_dayweekyear = $this->getDayOfTheYear($month,$day,$year);
}
if($this->setting('weekofyear')){
$tag_dayweekyear .= $this->getWeekOfTheYear($month,$day,$year);
}
//kludge... for some reason, the "\n" is removed in full calendar mode
if($mode == "monthMode")
$tag_eventList = str_replace("\n", " ", $tag_eventList);
$tempString = str_replace("[[Day]]", $display_day, $tempString);
$tempString = str_replace("[[AddEvent]]", $tag_addEvent, $tempString);
$tempString = str_replace("[[EventList]]", "<ul>" . $tag_eventList . "</ul>", $tempString);
$tempString = str_replace("[[Alert]]", $tag_alerts, $tempString);
$tempString = str_replace("[[DayWeekYear]]", $tag_dayweekyear, $tempString);
$tempString = str_replace("[[mode]]", $tag_mode, $tempString);
$tempString = str_replace("[[wday]]", $tag_wday, $tempString);
$tempString = str_replace("[[dayCustom]]", $tag_dayCustom, $tempString);
return $tempString;
}
function buildAlertLink($day, $month){
$ret = "";
$alerts = $this->arrAlerts;
$alertList = "";
for ($i=0; $i < count($alerts); $i++){
$alert = split("-", $alerts[$i]);
if(($alert[0] == $day) && ($alert[1] == $month))
$alertList .= $alert[2];
}
if (strlen($alertList) > 0)
$ret = "<a style='color:red' href=\"javascript:alert('" .$alertList . "')\"><i>alert!</i></a>";
return $ret;
}
function getWeekOfTheYear($month, $day, $year, $noHTML=false){
$timestamp = mktime(12,0,0,$month, $day, $year);
$weekDay = date("w", $timestamp);
$week = date("W", $timestamp);
if($noHTML) return $week;
$translated = Common::translate('weekyearTranslated');
if($this->setting('dayofyear')){
$html = "<span title='" . $translated . "'>/$week</span>";
}
else{
$html = "<span title='" . $translated . "'>$week</span>";
}
return $html;
}
function getDayOfTheYear($month, $day, $year){
$timestamp = mktime(12,0,0,$month, $day, $year);
$dayYear = (date("z", $timestamp) +1);
$translated = Common::translate('dayyearTranslated');
$html = "<span title='" . $translated . "'>$dayYear</span>";
return $html;
}
// build the 'template' button
function buildTemplateLink(){
if(!$this->setting('usetemplates')) return "";
$articleName = $this->wikiRoot . wfUrlencode($this->calendarPageName) . "/" . $this->month . "-" . $this->year . " -Template&action=edit" . "'\">";
$value = Common::translate('template_btn');
$title = Common::translate('template_btn_tip');
if($this->setting('locktemplates'))
$ret = "<input class='btn' type='button' title='$title' disabled value=\"$value\" onClick=\"javascript:document.location='" . $articleName;
else
$ret = "<input class='btn' type='button' title='$title' value=\"$value\" onClick=\"javascript:document.location='" . $articleName;
return $ret;
}
function loadiCalLink(){
$ical_value = Common::translate('ical_btn');
$ical_title = Common::translate('ical_btn_tip');
$bws_title = Common::translate('ical_browse_tip');
$note = "";
$cookieName = str_replace(' ', '_', ($this->calendarPageName . "_ical_count"));
if(isset($_COOKIE[$cookieName])){
$cnt = $_COOKIE[$cookieName];
$note = "<font color=red>Completed the import of <b>$cnt</b> record(s).</font>";
setcookie($cookieName, "", time() -3600);
}
$ret = Common::translate('ical_inst') . "<br>"
. "<input name='uploadedfile' type='file' title=\"$bws_title\" size='50'><br>"
. "<input name='ical' class='btn' type='submit' title=\"$ical_title\" value=\"$ical_value\"> "
. $note;
return $ret;
}
// build the 'template' button
function buildConfigLink($bTextLink = false){
if(!$this->setting('useconfigpage')) return;
if($this->setting('useconfigpage',false) == 'disablelinks') return "";
$value = Common::translate('config_btn');
$title = Common::translate('config_btn_tip');
if(!$bTextLink){
$articleConfig = $this->wikiRoot . wfUrlencode($this->configPageName) . "&action=edit" . "';\">";
$ret = "<input class='btn' type='button' title='$title' value=\"$value\" onClick=\"javascript:document.location='" . $articleConfig;
}else
$ret = "<a href='" . $this->wikiRoot . wfUrlencode($this->configPageName) . "&action=edit'>($value...)</a>";
return $ret;
}
function renderEventList(){
$events = "";
$setting = $this->setting('useeventlist',false);
if($setting == "") return "";
if($setting > 0){
$this->calendarMode = "eventlist";
$daysOut = ($setting <= 120 ? $setting : 120);
$month = $this->month;
$day = $this->day;
$year = $this->year;
$this->updateSetting('charlimit',100);
//build the days out....
$this->initalizeMonth(0, $daysOut);
for($i=0; $i < $daysOut; $i++){
$temp = $this->getHTMLForDay($month, $day, $year, 'long', 'events');
if(strlen(trim($temp)) > 0 ){
$events .= "<tr>" . $temp . "</tr>";
}
Common::getNextValidDate($month,$day,$year);//bump the date up by 1
}
$ret = "<i> " . $this->buildConfigLink(true) . "</i>"
. $events;
return "<table width=100%>" . $ret . "</table>";
}
}
function buildTemplateEvents(){
$year = $this->year;
$month = 1;//$this->month;
$additionMonths = $this->month + 12;
// lets just grab the next 12 months...this load only takes about .01 second per subscribed calendar
for($i=0; $i < $additionMonths; $i++){ // loop thru 12 months
foreach($this->subscribedPages as $page)
$this->addTemplate($month, $year, $page);
$this->addTemplate($month, $year, ($this->calendarPageName));
$year = ($month == 12 ? ++$year : $year);
$month = ($month == 12 ? 1 : ++$month);
}
}
// load ical RRULE (recurrence) events into memory
function buildVCalEvents() {
$year = $this->year;
$month = 1;//$this->month;
$additionMonths = $this->month + 12;
// lets just grab the next 12 months...this load only takes about .01 second per subscribed calendar
for($i=0; $i < $additionMonths; $i++){ // loop thru 12 months
foreach($this->subscribedPages as $page){
$this->addVCalEvents($page, $year, $month);
}
$this->addVCalEvents($this->calendarPageName, $year, $month);
$year = ($month == 12 ? ++$year : $year);
$month = ($month == 12 ? 1 : ++$month);
}
}
// used for 'date' mode only...technically, this can be any date
function updateDate(){
$this->calendarMode = "date";
$setting = $this->setting("date",false);
if($setting == "") return "";
$this->arrSettings['charlimit'] = 100;
if (($setting == "today") || ($setting == "tomorrow") || ($setting == "yesterday") ){
if ($setting == "tomorrow" ){
Common::getNextValidDate($this->month, $this->day, $this->year);
}
if ($setting == "yesterday" ){
$yesterday= Common::datemath(-1, $this->month, $this->day, $this->year);
$this->month = $yesterday['mon'];
$this->day = $yesterday['mday'];
$this->year = $yesterday['year'];
}
}
else {
$useDash = split("-",$setting);
$useSlash = split("/",$setting);
$parseDate = (count($useDash) > 1 ? $useDash : $useSlash);
if(count($parseDate) == 3){
$this->month = $parseDate[0];
$this->day = $parseDate[1] + 0; // converts to integer
$this->year = $parseDate[2] + 0;
}
}
}
// specific date mode
function renderDate() {
$this->initalizeMonth(0,1);
$ret = $this->buildConfigLink(true)
. $this->getHTMLForDay($this->month, $this->day, $this->year, 'long', 'day');
return "<table>$ret</table>";
}
function renderSimpleMonth(){
$ret = $this->buildSimpleCalendar($this->month, $this->year);
return $ret;
}
function buildMonthSelectBox($shortMonths=false){
// build the month select box
$monthSelect = "<select name='monthSelect' method='post' onChange='javascript:this.form.submit()'>";
for ($i = 1; $i <= 12; $i++) {
if ($i == $this->month) {
$monthSelect .= "<option class='lst' value='" . ($i) . "' selected='true'>" .
Common::translate($i, 'month') . "</option>\n";
}
else {
$monthSelect .= "<option class='lst' value='" . ($i) . "'>" .
Common::translate($i, 'month') . "</option>\n";
}
}
$monthSelect .= "</select>";
return $monthSelect;
}
function buildYearSelectBox(){
$yearoffset = $this->setting('yearoffset',false);
// build the year select box, with +/- 5 years in relation to the currently selected year
$yearSelect = "<select name='yearSelect' method='post' onChange='javascript:this.form.submit()'>";
for ($i = ($this->year - $yearoffset); $i <= ($this->year + $yearoffset); $i += 1) {
if ($i == $this->year) {
$yearSelect .= "<option class='lst' value='$i' selected='true'>" .
$i . "</option>\n";
}
else {
$yearSelect .= "<option class='lst' value='$i'>$i</option>\n";
}
}
$yearSelect .= "</select>";
return $yearSelect;
}
function renderMonth() {
global $gCalendarVersion;
$tag_templateButton = "";
$this->calendarMode = "normal";
/***** Replacement tags *****/
$tag_monthSelect = ""; // the month select box [[MonthSelect]]
$tag_previousMonthButton = ""; // the previous month button [[PreviousMonthButton]]
$tag_nextMonthButton = ""; // the next month button [[NextMonthButton]]
$tag_yearSelect = ""; // the year select box [[YearSelect]]
$tag_previousYearButton = ""; // the previous year button [[PreviousYearButton]]
$tag_nextYearButton = ""; // the next year button [[NextYearButton]]
$tag_calendarName = ""; // the calendar name [[CalendarName]]
$tag_calendarMonth = ""; // the calendar month [[CalendarMonth]]
$tag_calendarYear = ""; // the calendar year [[CalendarYear]]
$tag_day = ""; // the calendar day [[Day]]
$tag_addEvent = ""; // the add event link [[AddEvent]]
$tag_eventList = ""; // the event list [[EventList]]
$tag_eventStyleButton = ""; // event style buttonn [[EventStyleBtn]]
$tag_templateButton = ""; // template button for multiple events [[TemplateButton]]
$tag_todayButton = ""; // today button [[TodayButton]]
$tag_configButton = ""; // config page button
$tag_timeTrackValues = ""; // summary of time tracked events
$tag_loadiCalButton = "";
$tag_about = "";
/***** Calendar parts (loaded from template) *****/
$html_header = ""; // the calendar header
$html_day_heading = ""; // the day heading
$html_week_start = ""; // the calendar week pieces
$html_week_end = "";
$html_footer = ""; // the calendar footer
/***** Other variables *****/
$ret = ""; // the string to return
//build events into memory for the remainder of the month
//the previous days have already been loaded
$this->initalizeMonth(0, (32 - $this->day));
/***** Build the known tag elements (non-dynamic) *****/
// set the month's name tag
if($this->name == 'Public')
$tag_calendarName = Common::translate('default_title');
else
$tag_calendarName = $this->name;
$about_translated = Common::translate('about');
$tag_about = "<a title='$about_translated' href='http://www.mediawiki.org/wiki/Extension:Calendar_(Kenyu73)' target='new'>about</a>...";
// set the month's mont and year tags
$tag_calendarMonth = Common::translate($this->month, 'month');
$tag_calendarYear = $this->year;
$tag_monthSelect = $this->buildMonthSelectBox();;
$tag_yearSelect = $this->buildYearSelectBox();
$tag_templateButton = $this->buildTemplateLink();
$tag_configButton = $this->buildConfigLink(false);
$style_value = Common::translate('styles_btn');
$style_tip = Common::translate('styles_btn_tip');
if(!$this->setting("disablestyles")){
$articleStyle = $this->wikiRoot . wfUrlencode($this->calendarPageName) . "/style&action=edit" . "';\">";
$tag_eventStyleButton = "<input class='btn' type=\"button\" title=\"$style_tip\" value=\"$style_value\" onClick=\"javascript:document.location='" . $articleStyle;
}
// build the 'today' button
$btnToday = Common::translate('today');
$tag_todayButton = "<input class='btn' name='today' type='submit' value=\"$btnToday\">";
$tag_previousMonthButton = "<input class='btn' name='monthBack' type='submit' value='<<'>";
$tag_nextMonthButton = "<input class='btn' name='monthForward' type='submit' value='>>'>";
$tag_previousYearButton = "<input class='btn' name='yearBack' type='submit' value='<<'>";
$tag_nextYearButton = "<input class='btn' name='yearForward' type='submit' value='>>'>";
// grab the HTML peices for the calendar
$html_header = $this->searchHTML($this->html_template,
"<!-- Header Start -->", "<!-- Header End -->");
$html_day_heading = $this->searchHTML($this->html_template,
"<!-- Heading Start -->","<!-- Heading End -->");
// the calendar week pieces
$html_week_start = "<tr>";
$html_week_end = "</tr>";
// the calendar footer
$html_footer = $this->searchHTML($this->html_template,
"<!-- Footer Start -->", "<!-- Footer End -->");
/***** Begin Building the Calendar (pre-week) *****/
// add the header to the calendar HTML code string
$ret .= $html_header;
$ret .= $html_day_heading;
//$ret = str_replace("[[HEADER]]", $this->tag_header_month_view, $ret);
/***** Search and replace variable tags at this point *****/
$ret = str_replace("[[TodayButton]]", $tag_todayButton, $ret);
$ret = str_replace("[[MonthSelect]]", $tag_monthSelect, $ret);
$ret = str_replace("[[PreviousMonthButton]]", $tag_previousMonthButton, $ret);
$ret = str_replace("[[NextMonthButton]]", $tag_nextMonthButton, $ret);
$ret = str_replace("[[YearSelect]]", $tag_yearSelect, $ret);
$ret = str_replace("[[PreviousYearButton]]", $tag_previousYearButton, $ret);
$ret = str_replace("[[NextYearButton]]", $tag_nextYearButton, $ret);
$ret = str_replace("[[CalendarName]]", $tag_calendarName, $ret);
$ret = str_replace("[[CalendarMonth]]", $tag_calendarMonth, $ret);
$ret = str_replace("[[CalendarYear]]", $tag_calendarYear, $ret);
$ret = str_replace("[[Views]]", $this->tag_views, $ret);
$heading = $this->tag_heading;
if($this->setting('monday')){
$heading = str_replace("[[day1]]", Common::translate(2,'weekday'), $heading);
$heading = str_replace("[[day2]]", Common::translate(3,'weekday'), $heading);
$heading = str_replace("[[day3]]", Common::translate(4,'weekday'), $heading);
$heading = str_replace("[[day4]]", Common::translate(5,'weekday'), $heading);
$heading = str_replace("[[day5]]", Common::translate(6,'weekday'), $heading);
if( !$this->setting('5dayweek') ){
$heading = str_replace("[[day6]]", Common::translate(7,'weekday'), $heading);
$heading = str_replace("[[day7]]", Common::translate(1,'weekday'), $heading);
}
}
else{
$heading = str_replace("[[day1]]", Common::translate(1,'weekday'), $heading);
$heading = str_replace("[[day2]]", Common::translate(2,'weekday'), $heading);
$heading = str_replace("[[day3]]", Common::translate(3,'weekday'), $heading);
$heading = str_replace("[[day4]]", Common::translate(4,'weekday'), $heading);
$heading = str_replace("[[day5]]", Common::translate(5,'weekday'), $heading);
if( !$this->setting('5dayweek') ){
$heading = str_replace("[[day6]]", Common::translate(6,'weekday'), $heading);
$heading = str_replace("[[day7]]", Common::translate(7,'weekday'), $heading);
}
}
$ret = str_replace("[[HEADING]]", $heading, $ret);
$ret .= $this->getMonthHTML($this->month, $this->year);
/***** Do footer *****/
$tempString = $html_footer;
if($this->setting('ical'))
$tag_loadiCalButton = $this->loadiCalLink();
// replace potential variables in footer
$tempString = str_replace("[[TodayData]]", $this->tag_HiddenData, $tempString);
$tempString = str_replace("[[TemplateButton]]", $tag_templateButton, $tempString);
$tempString = str_replace("[[EventStyleBtn]]", $tag_eventStyleButton, $tempString);
$tempString = str_replace("[[Version]]", $gCalendarVersion, $tempString);
$tempString = str_replace("[[ConfigurationButton]]", $tag_configButton, $tempString);
$tempString = str_replace("[[TimeTrackValues]]", $tag_timeTrackValues, $tempString);
$tempString = str_replace("[[Load_iCal]]", $tag_loadiCalButton, $tempString);
$tempString = str_replace("[[About]]", $tag_about, $tempString);
$ret .= $tempString;
$ret = $this->stripLeadingSpace($ret);
return $ret;
}
// this generates the logic and the html to organize where the days go in the "grid"
function getMonthHTML($month, $year, $simplemonth=false){
$offset = 1;
$dayOfWeek = date('N', mktime(12, 0, 0, $month, 1, $year)); // 0-6
$daysInMonth = Common::getDaysInMonth($month,$year); // 28-31
$weeksInMonth = ceil( ($dayOfWeek + $daysInMonth)/7 ) ; // 4-6
if( $this->setting("monday") && !$this->setting("5dayweek") ) $offset = 2;
$counter = $theDay = -($dayOfWeek-$offset);
$ret = "";
$bfiveDayWeek = $this->setting("5dayweek");
for ($week = 0; $week < $weeksInMonth; $week+=1){
$bValidWeek = false;
$temp = "<tr>";
for ($day = 0; $day < 7; $day+=1){
$bSkipDay = false;
if($counter > $daysInMonth) $theDay = 0; // we want these days to be grey or empty...etc
if( ($day == 0 or $day == 6) && $bfiveDayWeek ){
$bSkipDay = true;
}
if( !$bSkipDay ){
if($theDay > 0) $bValidWeek = true;
if($simplemonth){
$todayStyle = "style='background-color: #C0C0C0;font-weight:bold;'";
$link = $this->buildAddEventLink($month, $theDay, $year, $theDay);
$temp .= "<td class='yearWeekday $todayStyle'>$link</td>";
}
else{
$temp .= $this->getHTMLForDay($month, $theDay, $year);
}
}
$counter++;
$theDay++;
}
$temp .= "</tr>";
// dont display a completely "greyed" out 5 day week
if($bValidWeek == true){
$ret .= $temp;
}
}
return $ret;
}
// returns the HTML that appears between two search strings.
// the returned results include the text between the search strings,
// else an empty string will be returned if not found.
function searchHTML($html, $beginString, $endString) {
$temp = split($beginString, $html);
if (count($temp) > 1) {
$temp = split($endString, $temp[1]);
return $temp[0];
}
return "";
}
// strips the leading spaces and tabs from lines of HTML (to prevent <pre> tags in Wiki)
function stripLeadingSpace($html) {
$index = 0;
$temp = split("\n", $html);
$tempString = "";
while ($index < count($temp)) {
while (strlen($temp[$index]) > 0
&& (substr($temp[$index], 0, 1) == ' ' || substr($temp[$index], 0, 1) == '\t')) {
$temp[$index] = substr($temp[$index], 1);
}
$tempString .= $temp[$index];
$index += 1;
}
return $tempString;
}
function cleanDayHTML($tempString){
// kludge to clean classes from "day" only parameter; causes oddness if the main calendar
// was displayed with a single day calendar on the same page... the class defines carried over...
$tempString = str_replace("calendarTransparent", "", $tempString);
$tempString = str_replace("calendarDayNumber", "", $tempString);
$tempString = str_replace("calendarEventAdd", "", $tempString);
$tempString = str_replace("calendarEventList", "", $tempString);
$tempString = str_replace("calendarToday", "", $tempString);
$tempString = str_replace("calendarMonday", "", $tempString);
$tempString = str_replace("calendarTuesday", "", $tempString);
$tempString = str_replace("calendarWednesday", "", $tempString);
$tempString = str_replace("calendarThursday", "", $tempString);
$tempString = str_replace("calendarFriday", "", $tempString);
$tempString = str_replace("calendarSaturday", "", $tempString);
$tempString = str_replace("calendarSunday", "", $tempString);
return $tempString;
}
// builds the day events into memory
// uses prefix seaching (NS:page/name/date)... anything after doesn't matter
function buildArticlesForDay($month, $day, $year) {
//$date = "$month-$day-$year";
$date = $this->userDateFormat($month, $day, $year);
$search = "$this->calendarPageName/$date";
$pages = PrefixSearch::titleSearch( $search, '100');
$category = Category::newFromName("Event");
foreach ($category->getMembers() as $eventTitle) {
if ($eventTitle->getNamespace() == NS_CATEGORY) {
// TODO
// This is a sub-category. We should recusre into it.
} else if ($eventTitle->isContentPage()) {
$event = Event::newFromTitle($eventTitle);
}
}
foreach($pages as $page) {
$this->addArticle($month, $day, $year, $page);
}
unset ($pages);
// subscribed events
foreach($this->subscribedPages as $subscribedPage){
$search = "$subscribedPage/$date";
$pages = PrefixSearch::titleSearch( $search, '100' );
foreach($pages as $page) {
$this->addArticle($month, $day, $year, $page);
}
}
}
// this is a general find/replace for the date format
// users can define whatever format this wish
// ie: 20090731, 07-01-2009, 07.01.2009, etc
function userDateFormat($month, $day, $year) {
global $wgCalendarDateFormat;
$format = $wgCalendarDateFormat;
if($format == '') $format = 'M-D-YYYY'; //default
$format = str_ireplace('YYYY',$year,$format);
$format = str_ireplace('MM', str_pad($month, 2, '0', STR_PAD_LEFT), $format);
$format = str_ireplace('DD', str_pad($day, 2, '0', STR_PAD_LEFT), $format);
$format = str_ireplace('D',$day,$format);
if( stripos($format,'SM') !== false || stripos($format,'LM') !== false ){
$format = str_ireplace('SM', Common::translate($month, 'month_short'), $format);
$format = str_ireplace('LM', Common::translate($month, 'month'), $format);
}else{
$format = str_ireplace('M',$month,$format);
}
return $format;
}
function buildTagEvents($paramstring){
$events = split( "\n", trim($paramstring) );
foreach($events as $event) {
$arr = split(':', $event);
$date = array_shift($arr);
$event = array_shift($arr);
$body = implode(':',$arr);
$arrDate = split('-',$date);
// we must have a valid date to continue
if(count($arrDate) < 3 )
break;
$month = $arrDate[0];
$day = $arrDate[1];
$year = $arrDate[2];
$this->buildEvent($month, $day, $year, $event, $this->title);
}
}
function buildSimpleCalendar($month, $year,$disableNavButtons=false){
$prev = $next = "";
$monthname = Common::translate($month,'month_short');
if ( $this->isFullSubscribe ) {
$monthname = "<a title='$this->calendarPageName' href='" . $this->wikiRoot . substr($this->calendarPageName, 0, strrpos($this->calendarPageName, "/")) . "'>" . $monthname . "</a>";
}
$monthyear = "$monthname, $this->year";
if(!$disableNavButtons){
$prev = "<input class='btn' name='monthBack' type='submit' value='<<'>";
$next = "<input class='btn' name='monthForward' type='submit' value='>>'>";
}
$title = "<table class='yearCalendarMonth_x' width=100% cellpadding=0 cellspacing=0><td>$prev</td><td>" . $monthyear . "</td><td>$next</td></table>";
$header = "<table class='yearCalendarMonth'><tr><td style='font-size:9px' class='yearTitle'>$title</tr></table>";
$ret = "<tr>";