Skip to content

Commit

Permalink
Merge pull request #65 from mozillahispano/fix-feed-lock
Browse files Browse the repository at this point in the history
Avoid timeouts when any feed is down. Fix  #64
  • Loading branch information
mauricesvay committed Mar 26, 2014
2 parents b37de7f + 1b25767 commit 07aa4f5
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions admin/index.php
Expand Up @@ -99,6 +99,7 @@
<th><?=_g('Last entry')?></th>
<th><?=_g('Website link')?></th>
<th><?=_g('Feed link')?></th>
<th><?=_g('Unavailable')?></th>
</tr>
</thead>
<tbody>
Expand All @@ -118,10 +119,12 @@
} else {
echo _g('Not in cache');
}
$check_is_down = $opml_person->getIsDown() === '1' ? 'checked="cheched"' : '';
?>
</td>
<td><input type="text" size="30" class="text" name="opml[<?=$i; ?>][website]" value="<?=$opml_person->getWebsite(); ?>" /></td>
<td><input type="text" size="30" class="text" name="opml[<?=$i; ?>][feed]" value="<?=$opml_person->getFeed(); ?>" /></td>
<td><input type="checkbox" readonly="readonly" name="opml[<?=$i; ?>][isDown]" <?=$check_is_down?> value="1" /></td>
</tr>
<?php } ?>
</tbody>
Expand Down
1 change: 1 addition & 0 deletions admin/subscriptions.php
Expand Up @@ -48,6 +48,7 @@ function removeSlashes(&$item, $key){
$person['name'] = $feed->get_title();
$person['website'] = $feed->get_permalink();
$person['feed'] = $feed->feed_url;
$person['isDown'] = '0';

$oldOpml->entries[] = $person;
}
Expand Down
25 changes: 20 additions & 5 deletions app/classes/Planet.class.php
Expand Up @@ -97,7 +97,8 @@ public function loadOpml($file)
new PlanetFeed(
$opml_person['name'],
$opml_person['feed'],
$opml_person['website']
$opml_person['website'],
$opml_person['isDown']
)
);
}
Expand All @@ -110,10 +111,14 @@ public function loadOpml($file)
public function loadFeeds()
{
foreach ($this->people as $feed) {
$feed->init();
$this->items = array_merge($this->items, $feed->get_items());
}
//Is down it's filled by cron.php, $Planet->download(1.0) proccess
if (!$feed->isDown) {
$feed->set_timeout(-1);
$feed->init();
$this->items = array_merge($this->items, $feed->get_items());
}

}
$this->sort();
}

Expand All @@ -123,8 +128,8 @@ public function loadFeeds()
*/
public function download($max_load=0.1)
{

$max_load_feeds = ceil(count($this->people) * $max_load);
$opml = OpmlManager::load(dirname(__FILE__).'/../../custom/people.opml');

foreach ($this->people as $feed) {
//Avoid mass loading with variable cache duration
Expand All @@ -139,6 +144,7 @@ public function download($max_load=0.1)

//Load feed
$feed->init();
$isDown = '';

// http://simplepie.org/wiki/reference/simplepie/merge_items ?
//Add items to index
Expand All @@ -147,8 +153,17 @@ public function download($max_load=0.1)
$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, dirname(__FILE__).'/../../custom/people.opml');
}

public function sort()
Expand Down
9 changes: 8 additions & 1 deletion app/classes/PlanetFeed.php
Expand Up @@ -9,12 +9,14 @@ class PlanetFeed extends SimplePie
public $name;
public $feed;
public $website;
public $isDown;

public function __construct($name, $feed, $website)
public function __construct($name, $feed, $website, $isDown)
{
$this->name = $name;
$this->feed = $feed;
$this->website = $website;
$this->isDown = $isDown;
parent::__construct();
$this->set_item_class('PlanetItem');
$this->set_cache_location(dirname(__FILE__).'/../../cache');
Expand All @@ -39,6 +41,11 @@ public function getWebsite()
return $this->website;
}

public function getIsDown()
{
return $this->isDown;
}

public function compare($person1, $person2)
{
return strcasecmp($person1->name, $person2->name);
Expand Down
4 changes: 4 additions & 0 deletions app/l10n/en.lang
Expand Up @@ -113,6 +113,10 @@ Website link
Feed link


# Translation note: ** String needs translation **
;Unavailable
Unavailable

# Translation note: ** String needs translation **
;Not in cache
Not in cache
Expand Down
4 changes: 4 additions & 0 deletions app/l10n/fr.lang
Expand Up @@ -90,6 +90,10 @@ Lien du site
Lien du Flux


;Unavailable
Indisponible


;Not in cache
Pas en cache

Expand Down
5 changes: 3 additions & 2 deletions app/lib/lib.opml.php
Expand Up @@ -13,7 +13,8 @@ class opml
'TEXT' => 'name',
'TITLE' => 'name',
'XMLURL' => 'feed',
'DESCRIPTION' => 'description'
'DESCRIPTION' => 'description',
'ISDOWN' => 'isDown'
);


Expand Down Expand Up @@ -95,7 +96,7 @@ public function save($opml, $file){
$out.= '</head>'."\n";
$out.= '<body>'."\n";
foreach ($opml->entries as $person){
$out.= '<outline text="' . htmlspecialchars($person['name']) . '" htmlUrl="' . htmlspecialchars($person['website']) . '" xmlUrl="' . htmlspecialchars($person['feed']) . '"/>'."\n";
$out.= '<outline text="' . htmlspecialchars($person['name']) . '" htmlUrl="' . htmlspecialchars($person['website']) . '" xmlUrl="' . htmlspecialchars($person['feed']) . '" isDown="' . htmlspecialchars($person['isDown']) . '"/>'."\n";
}
$out.= '</body>'."\n";
$out.= '</opml>';
Expand Down

0 comments on commit 07aa4f5

Please sign in to comment.