Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Atom feed #29

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions run.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php if (!defined('ARCHIVE_MY_TWEETS')) exit('No direct access allowed.');

if (file_exists(dirname(__FILE__).'/config.php')) {

require_once('includes.php');
$config = (isset($config)) ? $config : array();
if(isset($_GET['atom']) && $_GET['atom'] == "1")
{
$config['theme'] = 'atom';
}
$amt = new \AMWhalen\ArchiveMyTweets\App($config);
$amt->run();

} else {

require_once('amt/installer.php');
$installer = new \AMWhalen\ArchiveMyTweets\Installer(dirname(__FILE__));
$installer->run();

}
}
37 changes: 37 additions & 0 deletions themes/atom/_layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; ?>
<feed
xmlns="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xml:lang="en-US"
>
<id>tag:archivemytweets.com,2012:<?php echo $config['system']['baseUrl']; ?></id>
<link type="text/html" rel="alternate" href="<?php echo $config['system']['baseUrl']; ?>"/>
<link rel="self" type="application/atom+xml" href="<?php
// From http://stackoverflow.com/a/2236887
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);

echo $protocol."://".$_SERVER['SERVER_NAME'].$port.str_replace('&', '&amp;', $_SERVER['REQUEST_URI']);

?>" />

<title><?php echo $config['twitter']['username']; ?> - <?php echo $config['twitter']['name']; ?> - Tweets</title>
<?php
// Get the first date of the first tweet
if($tweets !== false && $tweets[0])
{
$t = new \AMWhalen\ArchiveMyTweets\Tweet();
$t->load($tweets[0]);
$last_updated = $t->get_date("c");
}
else
{
// Do not know when the feed was last updated, so answer "now"
$last_updated = date("c");
}
?>
<updated><?php echo $last_updated ?></updated>
<?php echo $content; ?>
</feed>
35 changes: 35 additions & 0 deletions themes/atom/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!-- index -->

<?php

if ($tweets !== false) {
foreach ($tweets as $row):
$t = new \AMWhalen\ArchiveMyTweets\Tweet();
$t->load($row);

$classes = array('tweet');
if ($t->in_reply_to_status_id != 0) $classes[] = 'reply';
if ($t->truncated != 0) $classes[] = 'truncated';
$class = implode(' ', $classes);

?>

<entry>
<id>tag:archivemytweets.org,2012:<?php echo $config['system']['baseUrl'] ?>::Tweet/<?php echo $t->id; ?></id>
<link type="text/html" rel="alternate" href="<?php echo 'https://twitter.com/'.$config['twitter']['username'].'/status/'.$t->id; ?>"/>
<title><?php echo $t->tweet; ?></title>
<updated><?php echo $t->get_date("c"); ?></updated>
<author>
<name><?php echo $config['twitter']['username'] ?> - <?php echo $config['twitter']['name']; ?></name>
</author>
<content type="html">
<?php echo htmlspecialchars("<p>".$t->get_linked_tweet()."</p><hr/>");
echo htmlspecialchars($t->source);
echo ($t->in_reply_to_status_id != 0) ? htmlspecialchars(' <a href="http://twitter.com/'.$t->in_reply_to_screen_name.'/status/'.$t->in_reply_to_status_id.'">in reply to '.$t->in_reply_to_screen_name.'</a>') : '';
?>

</content>
</entry>
<?php endforeach; ?>
<?php } ?>
<!-- /index -->
1 change: 1 addition & 0 deletions themes/default/_layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<title>@<?php echo $config['twitter']['username']; ?> - <?php echo $config['twitter']['name']; ?> - Tweets</title>
<link href="<?php echo $config['system']['baseUrl']; ?>css/archive.css" rel="stylesheet">
<link href="<?php echo $config['system']['baseUrl']; ?>assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo $config['system']['baseUrl']; ?>/?atom=1" rel="alternate" title="Tweets for <?php echo $config['twitter']['name']; ?>" type="application/atom+xml" />
<!--[if lt IE 9]>
<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
Expand Down