-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrepeat.php
More file actions
634 lines (528 loc) · 19.7 KB
/
repeat.php
File metadata and controls
634 lines (528 loc) · 19.7 KB
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
<?php
require_once 'When.php'; // Include When library
/*
Given a start date, duedate, completion date and rrule string, finds and returns the new values.
$start = unix timestamp or DateTime object
$due = unix timestamp or DateTime object
$comp = unix timestamp or DateTime object
$rrule = string
returns array(newStart, newDue, newiCal)
*/
function rep_getNextDates($start,$due,$comp,$rrule)
{
$noNextOccur = array(-1,-1,"");
$today = new DateTime(date('Y-m-d H:i:s'));
if($start<=0 || $start=='0000-00-00') $start = 0;
if($due<=0 || $due=='0000-00-00') $due = 0;
if($start === 0 && $due === 0) {
$due = $today;
}
// If start and due are timestamps, convert them to dates
if($start !== 0) {
if(is_int($start)) {
$s = new DateTime();
$s->setTimestamp($start);
$s->setTimezone(new DateTimeZone(date_default_timezone_get()));
$start = $s;
}
if(!($start instanceof DateTime)) $start = 0;
}
if($due !== 0) {
if(is_int($due)) {
$d = new DateTime();
$d->setTimestamp($due);
$d->setTimezone(new DateTimeZone(date_default_timezone_get()));
$due = $d;
}
if(!($due instanceof DateTime)) $due = 0;
}
if($comp !== 0) {
if(is_int($comp)) {
$d = new DateTime();
$d->setTimestamp($comp);
$d->setTimezone(new DateTimeZone(date_default_timezone_get()));
$comp = $d;
}
if(!($comp instanceof DateTime)) $comp = 0;
}
$rs = new When();
$rd = new When();
$rc = new When();
$newstart = null;
$newdue = null;
$newrrule = $rrule;
// Optional Rules
$fromComp = false;
$fastFoward = false;
$count = false;
$subtractCount = 1;
$match = array();
preg_match("/(FROMCOMP[;]?)/i",$rrule,$match);
$fromComp = !empty($match[1]) && !empty($comp) && $comp !== 0;
$match = array();
preg_match("/(FASTFORWARD[;]?)/i",$rrule,$match);
$fastFoward = !empty($match[1]);
$countMatch = array();
preg_match("/(COUNT=([0-9]*)[;]?)/i",$rrule,$countMatch);
$count = !empty($countMatch[1]);
if( $fromComp ) $rrule = preg_replace("/FROMCOMP[;]?/i", "", $rrule);
if( $fastFoward ) $rrule = preg_replace("/FASTFORWARD[;]?/i", "", $rrule);
// Calculate DUE date
if( $due === 0) {
$newdue = 0;
} else {
try {
if($fromComp) { //repeat from completion
$rd->recur($comp,'')->rrule($rrule);
$d = $rd->next();
if($d == $comp) {
if($count) {
// Work around for When() lib behavior
$carray = explode("=", $countMatch[1]);
$newcount = ((int)($carray[1])) + 1;
$newcountstr = "COUNT=".$newcount;
$temprrule = preg_replace("/(COUNT=[0-9]*)/i", $newcountstr, $rrule);
$rd = new When();
$rd->recur($comp,'')->rrule($temprrule);
$d = $rd->next();
}
$d = $rd->next();
}
} else { //repeat from due-date
$rd->recur($due,'')->rrule($rrule);
$d = $rd->next();
if($d == $due) {
if($count) {
// Work around for When() lib behavior
$carray = explode("=", $countMatch[1]);
$newcount = ((int)($carray[1])) + 1;
$newcountstr = "COUNT=".$newcount;
$temprrule = preg_replace("/(COUNT=[0-9]*)/i", $newcountstr, $rrule);
$rd = new When();
$rd->recur($due,'')->rrule($temprrule);
$d = $rd->next();
}
$d = $rd->next();
}
}
} catch(Exception $e) {
//failed to parse iCal rule
return array($start->getTimestamp(),$due->getTimestamp(),"");
}
// No next occuraence
if( !( $d instanceof DateTime) ) {
return $noNextOccur;
}
//fast forward to the next future date
if($fastFoward) {
while( true ) {
$d = $rd->next();
if(!($d instanceof DateTime)) {
return $noNextOccur;
} else if ($d > $today) {
if($fromComp) {
$subtractCount = $comp->diff($d)->days;
} else {
$subtractCount = $due->diff($d)->days;
}
break;
}
}
}
// No next occurence after returned one
if( !( $rd->next() instanceof DateTime ) ) {
$newrrule = "";
}
$newdue = $d->getTimestamp();
if($start !== 0) {
$newstart = clone $d;
$newstart->sub($start->diff($due));
$newstart = $newstart->getTimestamp();
} else {
$newstart = 0;
}
}
// Calculate START date if not already done
if($newstart === null) {
if( $start === 0) {
$newstart = 0;
} else {
try {
if($fromComp) {
$rc->recur($comp,'')->rrule($rrule);
$d = $rc->next();
if($d == $comp) {
if($count) {
// Work around for When() lib behavior
$carray = explode("=", $countMatch[1]);
$newcount = ((int)($carray[1])) + 1;
$newcountstr = "COUNT=".$newcount;
$temprrule = preg_replace("/(COUNT=[0-9]*)/i", $newcountstr, $rrule);
$rc = new When();
$rc->recur($comp,'')->rrule($temprrule);
$d = $rc->next();
}
$d = $rc->next();
}
} else {
$rc->recur($start,'')->rrule($rrule);
$d = $rc->next();
if( $d == $start) {
if($count) {
// Work around for When() lib behavior
$carray = explode("=", $countMatch[1]);
$newcount = ((int)($carray[1])) + 1;
$newcountstr = "COUNT=".$newcount;
$temprrule = preg_replace("/(COUNT=[0-9]*)/i", $newcountstr, $rrule);
$rc = new When();
$rc->recur($start,'')->rrule($temprrule);
$d = $rc->next();
}
$d = $rc->next();
}
}
} catch(Exception $e) {
echo "excepto";
if($due!==0) $due = $due->getTimestamp();
if($start!==0) $start = $start->getTimestamp();
return array($start,$due,"");
}
// No next occuraence
if( !( $d instanceof DateTime) ) {
return $noNextOccur;
}
if($fastFoward) {
while( true ) {
$d = $rs->next();
if(!($d instanceof DateTime)) {
return $noNextOccur;
} else if ($d > $today) {
if($fromComp) {
$subtractCount = $comp->diff($d)->days;
} else {
$subtractCount = $due->diff($d)->days;
}
break;
}
}
}
// No next occurence after returned one
if( !( $rc->next() instanceof DateTime ) ) {
$newrrule = "";
}
$newstart = $d->getTimestamp();
}
}
// Update COUNT flag if exists and new rrule being returned
if($count && $newrrule != "") {
$carray = explode("=", $countMatch[1]);
$newcount = ((int)($carray[1])) - $subtractCount;
$newcountstr = "COUNT=".$newcount;
$newrrule = preg_replace("/(COUNT=[0-9]*)/i", $newcountstr, $newrrule);
}
return array($newstart,$newdue,$newrrule);
}
/*
Converts Toodledo's old repeat strings into iCal RRULEs
$text = the "repeatA" field from the db. Old "repeat" number will need to be pre-conveted into repeatA
$fromComp = boolean if we should repeat from the completion date. false means repeat from due-date (default)
No external dependencies
*/
function rep_convertToRRule($text, $fromcomp)
{
$repeat = '';
$text = trim(strtolower($text));
$every = strpos($text,'every');
$each = strpos($text,'each');
$parent = strpos($text,'parent');
if($parent !== FALSE) {
$repeat = "PARENT";
} else if(($every!==FALSE && $every<5) || ($each!==FALSE && $each<5)){ // Every|Each X T
preg_match("/[a-z]* ([0-9]*)([a-z ,]*)/i",$text,$match);
if(empty($match[1])) $match[1] = 1; // X
if(empty($match[2])) return ""; // T
$repeat = "WEEKLY;BYDAY=";
$and = '';
if(strpos($match[2],'sun')!==FALSE) { $repeat .= $and."SU"; $and=","; }
if(strpos($match[2],'mon')!==FALSE) { $repeat .= $and."MO"; $and=","; }
if(strpos($match[2],'tue')!==FALSE) { $repeat .= $and."TU"; $and=","; }
if(strpos($match[2],'wed')!==FALSE) { $repeat .= $and."WE"; $and=","; }
if(strpos($match[2],'thu')!==FALSE) { $repeat .= $and."TH"; $and=","; }
if(strpos($match[2],'fri')!==FALSE) { $repeat .= $and."FR"; $and=","; }
if(strpos($match[2],'sat')!==FALSE) { $repeat .= $and."SA"; $and=","; }
if(strpos($match[2],'day')!==FALSE && empty($and)) $repeat="DAILY";
else if(strpos($match[2],'week')!==FALSE) $repeat="WEEKLY";
else if(strpos($match[2],'month')!==FALSE) $repeat="MONTHLY";
else if(strpos($match[2],'year')!==FALSE) $repeat="YEARLY";
if($match[1]>1) $repeat.=";INTERVAL=".$match[1];
if(strpos($match[2],'weekday')!==FALSE) $repeat = "WEEKLY;BYDAY=MO,TU,WE,TH,FR";
else if(strpos($match[2],'weekend')!==FALSE) $repeat = "WEEKLY;BYDAY=SU,SA";
$repeat = "FREQ=" . $repeat;
} else { //on the ...
if(strpos($text,'first')!==FALSE) $num = 1;
else if(strpos($text,'second')!==FALSE) $num = 2;
else if(strpos($text,'third')!==FALSE) $num = 3;
else if(strpos($text,'fourth')!==FALSE) $num = 4;
else if(strpos($text,'fifth')!==FALSE) $num = 5;
else if(strpos($text,'last')!==FALSE) $num = -1;
else {
preg_match("/[a-z ]* ([0-9]*)([a-z ]*)/i",$text,$match);
if(empty($match[0])) return rep_convertToRRule("Every ".$text, $fromcomp);
if(empty($match[1])) return rep_convertToRRule("Every ".$match[2], $fromcomp);
$num = $match[1];
}
if(strpos($text,'mon')!==FALSE) $day = "MO";
if(strpos($text,'tue')!==FALSE) $day = "TU";
else if(strpos($text,'wed')!==FALSE) $day = "WE";
else if(strpos($text,'thu')!==FALSE) $day = "TH";
else if(strpos($text,'fri')!==FALSE) $day = "FR";
else if(strpos($text,'sat')!==FALSE) $day = "SA";
else if(strpos($text,'sun')!==FALSE) $day = "SU";
if($num>5) $num=-1;
$repeat = "FREQ=MONTHLY;BYDAY=".$num.$day;
}
if($fromcomp) $repeat.=";FROMCOMP";
return $repeat;
}
function rep_translateShortToLongDayNames($shorts) {
$all = explode(",", $shorts);
$longs = "";
foreach($all as $short) {
if($short=="MO") $longs .= ", Mon";
else if($short=="TU") $longs .= ", Tue";
else if($short=="WE") $longs .= ", Wed";
else if($short=="TH") $longs .= ", Thu";
else if($short=="FR") $longs .= ", Fri";
else if($short=="SA") $longs .= ", Sat";
else if($short=="SU") $longs .= ", Sun";
}
return substr($longs,2);
}
//converts iCal RRULEs back into old Toodledo repeatA strings
function rep_convertToToodledo($rrule) {
$ret = "";
if(strpos($rrule,'PARENT')!==FALSE) return "With Parent";
$parts = explode(";", $rrule);
$freq=$interval=$byday='';
foreach($parts as $p) {
if(stristr($p, "FREQ=")!==false) $freq = str_replace("FREQ=", "", $p);
else if(stristr($p, "INTERVAL=")!==false) $interval = str_replace("INTERVAL=", "", $p);
else if(stristr($p, "BYDAY=")!==false) $byday = str_replace("BYDAY=", "", $p);
}
if($freq=="DAILY") {
if(empty($interval)) {
$ret = "Every 1 day";
} else {
$ret = "Every ".intval($interval)." days";
}
} else if($freq=="WEEKLY") {
if(!empty($interval)) {
$ret = "Every ".intval($interval)." weeks";
} else if(!empty($byday)) {
$byday = rep_translateShortToLongDayNames($byday);
$ret = "Every ".$byday;
} else {
$ret = "Every 1 week";
}
} else if($freq=="MONTHLY") {
if(!empty($interval)) {
$ret = "Every ".intval($interval)." months";
} else if(!empty($byday)) {
$day = substr($byday,-2);
$num = str_replace($day,"",$byday);
$day = rep_translateShortToLongDayNames($day);
if($num==1) $ret = "The 1st ".$day;
else if($num==2) $ret = "The 2nd ".$day;
else if($num==3) $ret = "The 3rd ".$day;
else if($num==-1) $ret = "The last ".$day;
else $ret = "The ".$num."th ".$day;
$ret.=" of each month";
} else {
$ret = "Every 1 month";
}
} else if($freq=="YEARLY") {
if(empty($interval)) {
$ret = "Every 1 year";
} else {
$ret = "Every ".intval($interval)." years";
}
}
$ret = rep_formatAdvanced($ret);
return $ret;
}
// Takes a user entered text string and normalizes it into a proper advanced repeat string
function rep_formatAdvanced($text) {
$repeat = '';
$text = trim(strtolower($text));
$every = strpos($text,'every');
$each = strpos($text,'each');
$parent = strpos($text,'parent');
if($text=='daily') return "Every 1 day";
else if($text=='weekly') return "Every 1 week";
else if($text=='biweekly') return "Every 2 weeks";
else if($text=='monthly') return "Every 1 month";
else if($text=='bimonthly') return "Every 2 months";
else if($text=='quarterly') return "Every 3 months";
else if($text=='semiannually') return "Every 6 months";
else if($text=='yearly') return "Every 1 year";
else if($parent!==FALSE) return "With Parent";
if(($every!==FALSE && $every<5) || ($each!==FALSE && $each<5)) { //Every ...
preg_match("/[a-z]* ([0-9]*)([a-z ,]*)/i",$text,$match);
if(empty($match[1])) $match[1] = 1;
if(empty($match[2])) $match[2] = '';
$on = "Every ";
$and = "";
if(strpos($match[2],'mo')!==FALSE) { $repeat .= $on.$and."Mon"; $on=''; $and=", "; }
if(strpos($match[2],'tu')!==FALSE && strpos($match[2],'tur')===FALSE) { $repeat .= $on.$and."Tue"; $on=''; $and=", "; } //tur prevents saTUrday
if(strpos($match[2],'we')!==FALSE) { $repeat .= $on.$and."Wed"; $on=''; $and=", "; }
if(strpos($match[2],'th')!==FALSE) { $repeat .= $on.$and."Thu"; $on=''; $and=", "; }
if(strpos($match[2],'fr')!==FALSE) { $repeat .= $on.$and."Fri"; $on=''; $and=", "; }
if(strpos($match[2],'sa')!==FALSE) { $repeat .= $on.$and."Sat"; $on=''; $and=", "; }
if(strpos($match[2],'su')!==FALSE) { $repeat .= $on.$and."Sun"; $on=''; $and=", "; }
$plural = 's';
if($match[1]==1) $plural='';
if(strpos($match[2],'day')!==FALSE && empty($and)) $repeat="Every ".$match[1]." day".$plural;
else if(strpos($match[2],'week')!==FALSE) $repeat="Every ".$match[1]." week".$plural;
else if(strpos($match[2],'month')!==FALSE) $repeat="Every ".$match[1]." month".$plural;
else if(strpos($match[2],'year')!==FALSE) $repeat="Every ".$match[1]." year".$plural;
if(strpos($match[2],'weekday')!==FALSE) $repeat = "Every weekday";
else if(strpos($match[2],'weekend')!==FALSE) $repeat = "Every weekend";
} else { //on the ...
if(strpos($text,'first')!==FALSE) $num = 1;
else if(strpos($text,'second')!==FALSE) $num = 2;
else if(strpos($text,'third')!==FALSE) $num = 3;
else if(strpos($text,'fourth')!==FALSE) $num = 4;
else if(strpos($text,'fifth')!==FALSE) $num = 5;
else if(strpos($text,'last')!==FALSE) $num = -1;
else {
preg_match("/[a-z ]* ([0-9]*)([a-z ]*)/i",$text,$match);
if(empty($match[0])) return rep_formatAdvanced("Every ".$text);
if(empty($match[1])) return rep_formatAdvanced("Every ".$match[2]);
$num = $match[1];
}
if(strpos($text,' mo')!==FALSE) $day = "Mon";
if(strpos($text,' tu')!==FALSE) $day = "Tue";
else if(strpos($text,' we')!==FALSE) $day = "Wed";
else if(strpos($text,' th ')!==FALSE) $day = "Thu";
else if(strpos($text,' thu')!==FALSE) $day = "Thu";
else if(strpos($text,' fr')!==FALSE) $day = "Fri";
else if(strpos($text,' sa')!==FALSE) $day = "Sat";
else if(strpos($text,' su')!==FALSE) $day = "Sun";
if($num>5) $num=-1;
if($num==1) $repeat = "The 1st ".$day;
else if($num==2) $repeat = "The 2nd ".$day;
else if($num==3) $repeat = "The 3rd ".$day;
else if($num==-1) $repeat = "The last ".$day;
else $repeat = "The ".$num."th ".$day;
$repeat.=" of each month";
}
return $repeat;
}
function rep_simpleToRRule($number) {
if($number>=100) $number-=100;
if($number==1) return "FREQ=WEEKLY";
else if($number==2) return "FREQ=MONTHLY";
else if($number==3) return "FREQ=YEARLY";
else if($number==4) return "FREQ=DAILY";
else if($number==5) return "FREQ=WEEKLY;INTERVAL=2";
else if($number==6) return "FREQ=MONTHLY;INTERVAL=2";
else if($number==7) return "FREQ=MONTHLY;INTERVAL=6";
else if($number==8) return "FREQ=MONTHLY;INTERVAL=3";
else if($number==9) return "PARENT";
}
//converts advanced representations of simple repeats back to their simple counterpart
function rep_simplifyRepeat($rep,$adv) {
if($rep!=50 && $rep!=150) return $rep; //already simple
$fromCompletion=0;
if($rep>=100) $fromCompletion=100;
if(strtolower($adv)=="every 1 week") return $fromCompletion+1;
else if(strtolower($adv)=="every 1 month") return $fromCompletion+2;
else if(strtolower($adv)=="every 1 year") return $fromCompletion+3;
else if(strtolower($adv)=="every 1 day") return $fromCompletion+4;
else if(strtolower($adv)=="every 2 weeks") return $fromCompletion+5;
else if(strtolower($adv)=="every 2 months") return $fromCompletion+6;
else if(strtolower($adv)=="every 6 months") return $fromCompletion+7;
else if(strtolower($adv)=="every 3 months") return $fromCompletion+8;
else if(strtolower($adv)=="with parent") return $fromCompletion+9;
return $rep; //no change
}
//takes the repeat number and string and returns the string
function rep_format($number, $adv) {
if($number>=100) $number-=100;
if($number==1) return "Weekly";
else if($number==2) return "Monthly";
else if($number==3) return "Yearly";
else if($number==4) return "Daily";
else if($number==5) return "Biweekly";
else if($number==6) return "Bimonthly";
else if($number==7) return "Semiannually";
else if($number==8) return "Quarterly";
else if($number==9) return "With Parent";
else if($number==50 && empty($adv)) return "None";
else if($number==60 && empty($adv)) return "None";
else if($number==50 && $adv=="Every 1 week") return "Weekly";
else if($number==50 && $adv=="Every 1 month") return "Monthly";
else if($number==50 && $adv=="Every 1 year") return "Yearly";
else if($number==50 && $adv=="Every 1 day") return "Daily";
else if($number==50 && $adv=="Every 2 weeks") return "Biweekly";
else if($number==50 && $adv=="Every 2 months") return "Bimonthly";
else if($number==50 && $adv=="Every 3 months") return "Quarterly";
else if($number==50 && $adv=="Every 6 months") return "Semiannually";
else if($number==50) return $adv;
else if($number==60) return $adv;
return "None";
}
//Accepts any user input and turns it into iCal.
//Input can be simple(repeat only), advanced (repeatA + repeat) or iCal (repeatA)
//set enhanced=false for regular ical without our additions
function rep_normalize($repeat,$repeatA,$enhanced=true) {
$fromcomp = "";
if($repeat>=100) { //determine if the number part is repeat from comp
if($enhanced) $fromcomp = ";FROMCOMP";
$repeat-=100;
} else if(($repeat==50 || $repeat==60) && strpos(strtolower($repeatA),'fromcomp')!==FALSE) { //determine if the ical part has from comp
if($enhanced) $fromcomp = ";FROMCOMP";
}
//parent is special
if(strpos(strtolower($repeatA),'parent')!==FALSE || $repeat==9 || $repeat==109) {
if($enhanced) return "PARENT".$fromcomp;
return "";
}
//already in ical
if(strpos($repeatA,'FREQ=')!==FALSE) {
if(!$enhanced) {
$repeatA = str_replace(";FROMCOMP", "", $repeatA);
$repeatA = str_replace("FROMCOMP;", "", $repeatA);
} else {
//make sure it has fromcomp if it should or not if it shouldn't
//This code makes the %100 value of $repeat overwrite the FROMCOMP string in repeatA always which
//is necessary for subtasks repeating with parent to work correctly when the FROMCOMP differs from parent
//Once all repeats are converted to RRULE, we can adjust thist code by adding/removing fromcomp in the db_todo_completeSubtasks function instead
if(!empty($fromcomp) && strpos(strtolower($repeatA),'fromcomp')===FALSE) {
$repeatA .= $fromcomp; //add "FROMCOMP" if it should be there based on repeat (needed for repeat with parent to work correctly)
} else if(empty($fromcomp)) {
$repeatA = str_replace(";FROMCOMP", "", $repeatA); //remove FROMCOMP if it shouldn't be there based on repeat (needed for repeat with parent)
$repeatA = str_replace("FROMCOMP;", "", $repeatA);
}
}
return $repeatA;
//old Toodledo format
} else {
$repeatA = strtolower($repeatA);
$repeatA = rep_format($repeat,$repeatA);
if(!empty($repeatA)) {
$repeatA = rep_formatAdvanced($repeatA); //normalize the toodledo string
$rrule = rep_convertToRRule($repeatA,$fromcomp);
return $rrule;
}
}
return "";
}
//Takes a repeat and repeatA(ical or old) and converts it to the human readable string
function rep_display($repeat, $repeatA) {
$rrule = rep_normalize($repeat,$repeatA);
$repeatA = rep_convertToToodledo($rrule); //convert to old format
$repeatA = rep_format(50,$repeatA);
return $repeatA;
}
?>