erunyon / FeedCache

Simple PHP class for caching external feeds
17 stars 10 forks source link

filemtime problem in populate_data() #7

Open quechup opened 7 years ago

quechup commented 7 years ago

Fist delete remote files when the files expire, function cache_feed.

private function cache_feed() { if($this->remote_file_exists($this->remote)) {

  //---------------------line-added-begin
  //First delete localfiles
  unlink($this->local);
  //---------------------line-added-end

  //Second get and create the remote files, this refresh the filemtime used in check_expired
  $compressed_content = '';
  $remote_content = file_get_contents($this->remote);
  $compressed_content = preg_replace('/\s*?\n\s*/', "\n", $remote_content);
  $compressed_content = preg_replace('/( |\t)( |\t)*/', " ", $compressed_content);
  file_put_contents($this->local, $compressed_content);
  return true;
} else {
  return false;
}

}