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

Added simple RSS feed for recent questions #42

Open
wants to merge 1 commit into
base: 3fc26dfb7351db0e78647d4b1880d6b9b0552ea0
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
30 changes: 30 additions & 0 deletions app/controllers/rss_controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Controller to generate RSS feeds containing the recent questions.
*
* @author Paul de Raaij <[email protected]>
*/
class RssController extends AppController {
var $name = 'Rss';
var $uses = array('Post', 'User');

var $components = array('RequestHandler');
var $helpers = array('Text');

/**
* By default return an rss feed with the latest 15 questions
*/
public function feeds() {

if( !$this->RequestHandler->isRss() ) {
$this->redirect('/');
}
$questions = $this->Post->find('all', array('conditions' => array('Post.type' => 'question',),
'order' => 'Post.timestamp DESC',
'limit' => 15));

return $this->set(compact('questions'));
}
}

?>
5 changes: 5 additions & 0 deletions app/views/layouts/rss/default.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
echo $rss->header();

echo $content_for_layout;
?>
24 changes: 16 additions & 8 deletions app/views/posts/display.ctp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?
<?php
foreach($questions as $question) { ?>
<div class="list_question wrapper">

Expand Down Expand Up @@ -55,20 +55,20 @@ foreach($questions as $question) { ?>
</div>
</div>
<div class="wrapper tags">
<? foreach($question['Tag'] as $tag) { ?>
<?php foreach($question['Tag'] as $tag) { ?>
<div class="tag wrapper">
<?=$html->link(
$tag['tag'],
'/tags/' . $tag['tag']
);
?>
</div>
<? } ?>
<?php } ?>
</div>
</div>

</div>
<? }
<?php }
if((($end_page - $current) > 3) && $current > 3) { ?>
<span class="left"><a href="/search/type:<?=$type;?>/page:1/search:<?=$search;?>"><u>1</u>&nbsp;</a></span>
<span class="left"><a href="/search/type:<?=$type;?>/page:<?=$current-2;?>/search:<?=$search;?>"><u><?=$current-2;?></u>&nbsp;</a></span>
Expand All @@ -77,15 +77,23 @@ foreach($questions as $question) { ?>
<span class="left"><a href="/search/type:<?=$type;?>/page:<?=$current+1;?>/search:<?=$search;?>"><u><?=$current+1;?></u>&nbsp;</a></span>
<span class="left"><a href="/search/type:<?=$type;?>/page:<?=$current+2;?>/search:<?=$search;?>"><u><?=$current+2;?></u>&nbsp;</a></span>
<span class="left"><a href="/search/type:<?=$type;?>/page:<?=$end_page;?>/search:<?=$search;?>"><u><?=$end_page;?></u></a></span>
<? }elseif($current < $end_page) { ?>
<?php }elseif($current < $end_page) { ?>
<span class="left">page <?=$current;?> of <a href="/search/type:<?=$type;?>/page:<?=$end_page;?>/search:<?=$search;?>"><?=$end_page;?></a></span>
<? }else { ?>
<?php }else { ?>
<span class="left">page <?=$current;?> of <?=$end_page;?></span>
<? }
<?php }
if(isset($next)) { ?>
<span class="right"><a href="/search/type:<?=$type;?>/page:<?=$next;?>/search:<?=$search;?>">&nbsp;&nbsp;Next >></a></span>
<?
}
if(isset($previous)) { ?>
<span class="right"><a href="/search/type:<?=$type;?>/page:<?=$previous;?>/search:<?=$search;?>"><< Previous&nbsp;&nbsp;</a></span>
<? } ?>
<?php } ?>

<?php if ( $type == 'recent'): ?>
<div class="questionFeed">
<a href="<?php echo $html->url(array('controller' => 'rss','action' => 'feeds', 'ext' =>'rss'), true);?>">
recent questions feed
</a>
</div>
<?php endif; ?>
53 changes: 53 additions & 0 deletions app/views/rss/rss/feeds.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
$homeUrl = $html->url($this->webroot, true);
$currentDate = new DateTime();

$feedLink = $html->url(array( 'controller' => 'rss',
'action' => 'feeds', 'ext' => 'rss'), true);

?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">Recent Questions</title>
<link rel="self" href="<?php echo $feedLink; ?>" type="application/atom+xml" />
<updated><?php echo $currentDate->format(DateTime::ATOM);?></updated>
<id><?php echo $homeUrl; ?></id>
<?php

foreach ($questions as $question) {
$questionLink = $html->url(array( 'controller' => 'posts',
'action' => 'view', 'public_key' => $question['Post']['public_key'], 'title' => Inflector::slug($question['Post']['title'])), true);

$userLink = $html->url(array( 'controller' => 'users',
'action' => 'view', 'public_key' => $question['User']['public_key'], 'title' => Inflector::slug($question['User']['username'])), true);

$dateCreated = new DateTime();
$dateCreated->setTimestamp($question['Post']['timestamp']);

$dateModified = new DateTime();


if( $question['Post']['last_edited_timestamp'] == 0 ) {
$dateModified = $dateCreated;
} else {
$dateModified->setTimestamp($question['Post']['last_edited_timestamp']);
}

?>
<entry>
<id><?php echo $questionLink; ?></id>
<title type="text"><?php echo $question['Post']['title']; ?></title>
<author>
<name><?php echo $question['User']['username']; ?></name>
<uri><?php echo $userLink; ?></uri>
</author>
<link rel="alternate" href="<?php echo $questionLink; ?>" />
<published><?php echo $dateCreated->format(DateTime::ATOM);?></published>
<updated><?php echo $dateModified->format(DateTime::ATOM);?></updated>
<summary type="html">
<?php echo htmlspecialchars($question['Post']['content']); ?>
</summary>
</entry>
<?php
}
?>
</feed>
16 changes: 16 additions & 0 deletions app/webroot/css/skin.css
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,20 @@ a:hover {
background-color: #d05024;
border-bottom: 1px solid #FFECE5;
border-right: 1px solid #FFECE5;
}


/* --------------------------------------------------------------
RSS Feed
-------------------------------------------------------------- */
div.questionFeed {
float: right;
margin-top: 50px;
}

div.questionFeed a {
color: #666;
background: transparent url(/img/rss.gif) no-repeat;
padding-left: 22px;
height: 18px;
}
Binary file added app/webroot/img/rss.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.