/** * Download * @var $max_load percentage of feeds to load */ public function download($max_load = 0.1) { $max_load_feeds = ceil(count($this->people) * $max_load); $opml = OpmlManager::load(__DIR__ . '/../../custom/people.opml'); foreach ($this->people as $feed) { //Avoid mass loading with variable cache duration //$feed->set_cache_duration($this->config->getCacheTimeout()+rand(0,30)); $feed->set_cache_duration($this->config->getCacheTimeout()); //Load only a few feeds, force other to fetch from the cache if (0 > $max_load_feeds--) { $feed->set_timeout(-1); $this->errors[] = new PlanetError(1, 'Forced from cache : ' . $feed->getFeed()); } //Load feed $feed->init(); $isDown = ''; // http://simplepie.org/wiki/reference/simplepie/merge_items ? //Add items to index if ($feed->data && $feed->get_item_quantity() > 0) { $items = $feed->get_items(); $this->items = array_merge($this->items, $items); } else { $this->errors[] = new PlanetError(1, 'No items : ' . $feed->getFeed()); $isDown = '1'; } //Mark if the feed is temporary unavailable foreach ($opml->entries as $key => $entrie) { if ($feed->getFeed() === $entrie['feed']) { $opml->entries[$key]['isDown'] = $isDown; } } } OpmlManager::save($opml, __DIR__ . '/../../custom/people.opml'); }
if (!isset($person['delete'])) { $newOpml->entries[] = $person; } } else { $newOpml->entries[] = $person; } } } // Add feed if (isset($_POST['add'])) { if ('http://' != $_POST['url']) { //autodiscover feed $feed = new SimplePie(); $feed->enable_cache(false); $feed->set_feed_url($_POST['url']); $feed->init(); $feed->handle_content_type(); $person['name'] = $feed->get_title(); $person['website'] = $feed->get_permalink(); $person['feed'] = $feed->feed_url; $oldOpml->entries[] = $person; $newOpml->entries = $oldOpml->entries; } } // Backup old OPML OpmlManager::backup(dirname(__FILE__) . '/../custom/people.opml'); // Save new OPML OpmlManager::save($newOpml, dirname(__FILE__) . '/../custom/people.opml'); } header("Location: index.php"); die;
$newOpml->entries[] = $person; } } else { $newOpml->entries[] = $person; } } } // Add feed if (isset($_POST['add'])) { if ('http://' != $_POST['url']) { //autodiscover feed $feed = new SimplePie(); $feed->enable_cache(false); $feed->set_feed_url($_POST['url']); $feed->init(); $feed->handle_content_type(); $person['name'] = $feed->get_title(); $person['website'] = $feed->get_permalink(); $person['feed'] = $feed->feed_url; $person['isDown'] = '0'; $oldOpml->entries[] = $person; } $newOpml->entries = $oldOpml->entries; } // Backup old OPML OpmlManager::backup(__DIR__ . '/../custom/people.opml'); // Save new OPML OpmlManager::save($newOpml, __DIR__ . '/../custom/people.opml'); } header("Location: index.php"); die;