Skip to content

Commit

Permalink
Merge pull request #45 from pascalchevrel/feeds
Browse files Browse the repository at this point in the history
use the correct Mime Type (application/atom+xml) for the self link in th...
  • Loading branch information
mauricesvay committed May 10, 2012
2 parents 0649e75 + 2c494ce commit d928ffa
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 66 deletions.
38 changes: 37 additions & 1 deletion custom/views/atom10/index.tpl.php → atom.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
<?php
include_once(dirname(__FILE__).'/app/app.php');
include_once(dirname(__FILE__).'/app/lib/Cache.php');

//Installed ?
if (!isset($Planet)) {
echo '<p>' . _g('You might want to <a href="install.php">install moonmoon</a>.') . '</p>';
exit;
}

//Load from cache
$items = Array();
if (0 < $Planet->loadOpml(dirname(__FILE__).'/custom/people.opml')) {
$Planet->loadFeeds();
$items = $Planet->getItems();
}

//Prepare output cache
Cache::$enabled = false;
$cache_key = (count($items)) ? $items[0]->get_id() : '';
$last_modified = (count($items)) ? $items[0]->get_date() : '';
$cache_duration = $PlanetConfig->getOutputTimeout()*60;

Cache::setStore(dirname(__FILE__) . '/' . $conf['cachedir'] . '/');
//Go display
if (!isset($_GET['type']) ||
!is_file(dirname(__FILE__).'/custom/views/'.$_GET['type'].'/index.tpl.php') ||
strpos($_GET['type'], DIRECTORY_SEPARATOR)){
$_GET['type'] = 'default';
}

if (!OutputCache::Start($_GET['type'], $cache_key, $cache_duration)) {
include_once(dirname(__FILE__).'/custom/views/'.$_GET['type'].'/index.tpl.php');
OutputCache::End();
}

var_dump($PlanetConfig, $Planet);
$limit = $PlanetConfig->getMaxDisplay();
$count = 0;

Expand All @@ -8,7 +44,7 @@
<title><?php echo htmlspecialchars($PlanetConfig->getName()); ?></title>
<subtitle><?php echo htmlspecialchars($PlanetConfig->getName()); ?></subtitle>
<id><?php echo $PlanetConfig->getUrl(); ?></id>
<link rel="self" type="text/html" href="<?php echo $PlanetConfig->getUrl(); ?>?type=atom10" />
<link rel="self" type="application/atom+xml" href="<?php echo $PlanetConfig->getUrl(); ?>atom.php" />
<link rel="alternate" type="text/html" href="<?php echo $PlanetConfig->getUrl(); ?>" />
<updated><?php echo date("Y-m-d\TH:i:s\Z") ?></updated>
<author><name>Author</name></author>
Expand Down
13 changes: 1 addition & 12 deletions custom/views.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?php
$views = array(
'rss10' => array(
'header' => 'Content-Type: text/xml; charset=UTF-8',
'prolog' => '<?xml version="1.0" encoding="UTF-8" ?>'."\n",
'template' => dirname(__FILE__).'/views/rss10/rss10.tpl.php'
),
'atom10' => array(
//'header' => 'Content-Type: text/xml; charset=UTF-8',
'header' => 'Content-Type: text/plain; charset=UTF-8',
'prolog' => '<?xml version="1.0" encoding="UTF-8" ?>'."\n",
'template' => dirname(__FILE__).'/views/atom10/atom10.tpl.php'
),
'archive' => array(
'header' => 'Content-type: text/html; charset=UTF-8',
'prolog' => '',
Expand All @@ -21,4 +10,4 @@
'prolog' => '',
'template' => dirname(__FILE__).'/views/default/index.tpl.php'
)
);
);
2 changes: 1 addition & 1 deletion custom/views/archive/head.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
<link rel="stylesheet" media="screen" type="text/css" href="custom/style/light.css" title="Light" />
<link rel="stylesheet" media="screen" type="text/css" href="custom/style/dark.css" title="Dark" />
<link rel="alternate" type="application/atom+xml" title="ATOM" href="?type=atom10" />
<link rel="alternate" type="application/atom+xml" title="ATOM" href="atom.php" />
2 changes: 1 addition & 1 deletion custom/views/archive/sidebar.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div>
<h2><?=_g('Syndicate')?></h2>
<ul>
<li><img src="custom/img/feed.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<a href="?type=atom10"><?=_g('Feed (ATOM)')?></a></li>
<li><img src="custom/img/feed.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<a href="atom.php"><?=_g('Feed (ATOM)')?></a></li>
</ul>
</div>

Expand Down
2 changes: 1 addition & 1 deletion custom/views/default/head.tpl.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<link rel="stylesheet" media="screen" type="text/css" href="custom/style/default.css" title="Default" />
<link rel="alternate" type="application/atom+xml" title="ATOM" href="?type=atom10" />
<link rel="alternate" type="application/atom+xml" title="ATOM" href="atom.php" />
2 changes: 1 addition & 1 deletion custom/views/default/sidebar.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="section">
<h2><?=_g('Syndicate')?></h2>
<ul>
<li><img src="custom/img/feed.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<a href="?type=atom10"><?=_g('Feed (ATOM)')?></a></li>
<li><img src="custom/img/feed.png" alt="<?=_g('Feed')?>" height="12" width="12" />&nbsp;<a href="atom.php"><?=_g('Feed (ATOM)')?></a></li>
</ul>
</div>

Expand Down
49 changes: 0 additions & 49 deletions custom/views/rss10/index.tpl.php

This file was deleted.

10 changes: 10 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@

Cache::setStore(dirname(__FILE__) . '/' . $conf['cachedir'] . '/');

if (isset($_GET['type']) && $_GET['type'] == 'atom10') {
/* XXX: Redirect old ATOM feeds to new url to make sure our users don't
* loose subscribers upon upgrading their moonmoon installation.
* Remove this check in a more distant future.
*/
header('Status: 301 Moved Permanently', false, 301);
header('Location: atom.php');
exit;
}

//Go display
if (!isset($_GET['type']) ||
!is_file(dirname(__FILE__).'/custom/views/'.$_GET['type'].'/index.tpl.php') ||
Expand Down

0 comments on commit d928ffa

Please sign in to comment.