kopia lustrzana https://github.com/friendica/SG-iCalendar
fix and reenable cache creation when possible
rodzic
768197bd34
commit
1a63569868
|
@ -31,8 +31,9 @@ class SG_iCal_Freq {
|
||||||
protected $rules = array('freq'=>'yearly', 'interval'=>1);
|
protected $rules = array('freq'=>'yearly', 'interval'=>1);
|
||||||
protected $start = 0;
|
protected $start = 0;
|
||||||
protected $freq = '';
|
protected $freq = '';
|
||||||
protected $excluded;
|
|
||||||
|
protected $excluded; //EXDATE
|
||||||
|
|
||||||
public $cache;
|
public $cache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,13 +70,16 @@ class SG_iCal_Freq {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//set until
|
//set until, and cache
|
||||||
if( isset($this->rules['count']) ) {
|
if( isset($this->rules['count']) ) {
|
||||||
$ts = $this->firstOccurrence();
|
$ts = $this->start;
|
||||||
for($i=1; $i<$this->rules['count']; $i++) {
|
$cache[0] = $ts;
|
||||||
|
for($n=1; $n < $this->rules['count']; $n++) {
|
||||||
$ts = $this->findNext($ts);
|
$ts = $this->findNext($ts);
|
||||||
|
$cache[$n] = $ts;
|
||||||
}
|
}
|
||||||
$this->rules['until'] = $ts;
|
$this->rules['until'] = $ts;
|
||||||
|
$this->cache = $cache;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,14 +91,13 @@ class SG_iCal_Freq {
|
||||||
public function getAllOccurrences() {
|
public function getAllOccurrences() {
|
||||||
if (empty($this->cache)) {
|
if (empty($this->cache)) {
|
||||||
//build cache
|
//build cache
|
||||||
unset($this->cache);
|
$n=0; $cache[$n] = $this->start;
|
||||||
$this->cache[] = $this->start;
|
|
||||||
$next = $this->findNext($this->start);
|
$next = $this->findNext($this->start);
|
||||||
while ($next) {
|
while ($next) {
|
||||||
//if (!in_array($next, $this->excluded))
|
$n++; $cache[$n] = $next;
|
||||||
$this->cache[] = $next;
|
|
||||||
$next = $this->findNext($next);
|
$next = $this->findNext($next);
|
||||||
}
|
}
|
||||||
|
$this->cache = $cache;
|
||||||
}
|
}
|
||||||
return $this->cache;
|
return $this->cache;
|
||||||
}
|
}
|
||||||
|
@ -146,18 +149,14 @@ class SG_iCal_Freq {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds the absolute last occurrence of the rule from the given offset.
|
* Finds the absolute last occurrence of the rule from the given offset.
|
||||||
|
* Builds also the cache, if not set before...
|
||||||
* @return int timestamp
|
* @return int timestamp
|
||||||
*/
|
*/
|
||||||
public function lastOccurrence() {
|
public function lastOccurrence() {
|
||||||
if (!empty($this->cache)) {
|
//build cache if not done
|
||||||
return end($this->cache);
|
$this->getAllOccurrences();
|
||||||
}
|
//return last timestamp in cache
|
||||||
$ts = $next = $this->findNext($this->start);
|
return end($this->cache);
|
||||||
while ($next) {
|
|
||||||
$ts = $next;
|
|
||||||
$next = $this->findNext($ts);
|
|
||||||
}
|
|
||||||
return $ts;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,14 +210,16 @@ class SG_iCal_Freq {
|
||||||
|
|
||||||
if( $this->simpleMode ) {
|
if( $this->simpleMode ) {
|
||||||
if( $offset < $t ) {
|
if( $offset < $t ) {
|
||||||
return $t;
|
$ts = $t;
|
||||||
|
if ($ts && in_array($ts, $this->excluded))
|
||||||
|
$ts = $this->findNext($ts);
|
||||||
} else {
|
} else {
|
||||||
$next = $this->findStartingPoint( $t, $this->rules['interval'], false );
|
$ts = $this->findStartingPoint( $t, $this->rules['interval'], false );
|
||||||
if( !$this->validDate( $next ) ) {
|
if( !$this->validDate( $ts ) ) {
|
||||||
return $this->findNext($next);
|
$ts = $this->findNext($ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $next;
|
return $ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
$eop = $this->findEndOfPeriod($offset);
|
$eop = $this->findEndOfPeriod($offset);
|
||||||
|
|
Ładowanie…
Reference in New Issue