Browse files

Implement RSS subfeeds using tags.

Now you can specify tags in the text with lines like "::tag1,tag2", and
request an RSS feed for the given tags by using eg. rss.php?tags=tag1
  • Loading branch information...
1 parent e546a48 commit d229fa4626c9212537e0c1a48cec900fa96508ba @apenwarr committed Apr 14, 2009
Showing with 29 additions and 3 deletions.
  1. +2 −2 index.php
  2. +3 −1 parser.inc.php
  3. +24 −0 rss.php
View
4 index.php
@@ -172,7 +172,7 @@ function read_layout()
. ' ' . substr( $nextmonth, 0, 4 );
}
$thismonth = $m;
- $this = month( substr( $m, 4, 2 ) )
+ $thism = month( substr( $m, 4, 2 ) )
. ' ' . substr( $m, 0, 4 );
$rss = "$absoluteurl/$topdir/rss.php";
@@ -201,7 +201,7 @@ function read_layout()
preg_replace( '/(?im)<## next ##>/', $next,
preg_replace( '/(?im)<## prevabbr ##>/', $prevabbr,
preg_replace( '/(?im)<## nextabbr ##>/', $nextabbr,
- preg_replace( '/(?im)<## this ##>/', $this,
+ preg_replace( '/(?im)<## this ##>/', $thism,
preg_replace( '/(?im)<## rsslink ##>/', $rss,
preg_replace( '/(?im)<## include-header ##>/',
join('', $headerfile),
View
4 parser.inc.php
@@ -26,7 +26,9 @@ function do_entrycontent( $when, $day )
// if ( match_entrytitle( $file[0] ) ) $file[0] = "";
foreach( $file as $line ) {
- if( substr( $line, 0, 6 ) === 'image ' ) {
+ if( substr( $line, 0, 2 ) === "::" ) {
+ continue; // skip over tag lines
+ } elseif( substr( $line, 0, 6 ) === 'image ' ) {
$num = substr( $line, 6, 4 );
$caption = substr( $line, 10 );
$httpdir = "../$topdir/$when";
View
24 rss.php
@@ -25,6 +25,26 @@ function escape( $string )
ereg_replace( '\.\.\/', "$absoluteurl/", $string ) ) ) ) ) ) );
}
+function tags_match( $file )
+{
+ if( $_GET["tags"] == "" ) return true;
+
+ $want_tags = split( "[ \t\r\n,]", $_GET["tags"] );
+
+ $lines = file( $file );
+ foreach( $lines as $line ) {
+ if( substr( $line, 0, 2 ) == "::" ) {
+ $tags = split( "[ \t\r\n,]", substr( $line, 2 ) );
+ var_dump( $tags );
+ foreach( $tags as $tag ) {
+ if( in_array( $tag, $want_tags ) ) return true;
+ }
+ }
+ }
+
+ return false;
+}
+
function do_entry( $file, $yearmonth, $day )
{
global $months;
@@ -37,6 +57,10 @@ function do_entry( $file, $yearmonth, $day )
$monthnum = substr( $yearmonth, 4, 2 );
$year = substr( $yearmonth, 0, 4 );
// $title = "$months[$monthnum] $day, $year";
+
+ if( !tags_match( $file ) )
+ return "";
+
$title = sprintf( "%04d-%02d-%02d", $year, $monthnum, $day );
$intitle = get_entrytitle( $yearmonth, $day );
$mtime = filemtime( $file );

0 comments on commit d229fa4

Please sign in to comment.