Copyright (C) 2005 Ryan R. Varick This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MODULE: Alternate RSS output method designed for blogs USAGE: append ?action=blogrss to a page to show an RSS feed for that group. pages must be valid dates without any seperators (ie. 20070615). pages with valid dates may contain multiple entry blocks. each block is marked by (:blogentry :) (:blogentryend:). within each block the following page variables are used. (:Title value:) (:TimeStamp: value:) (:PermaLink: value:) */ $RecipeInfo['ParseBlog']['Version'] = '2007-06-15'; // Markup masked for blog entries Markup('parseblogentry', 'directives', "/\(:blogentry\s+(.*):\)/e", ""); Markup('parseblogentryend', 'directives', "/\(:blogentryend:\)/e", ""); // Action set for viewing alternate RSS feed SDV($HandleActions['blogrss'],'ParseBlog_PageBlocks'); // Array values for RSS header directives SDVA($ParseBlogHeadValues, array( "title"=>"My Blog", "link" =>$ScriptUrl."/Blog/HomePage?action=blogrss", "description" =>"My blog about things.", "copyright" =>"Choose a blog license", "managingeditor"=>"myname@myemailaddress.com", "webmaster"=>"myname@myemailaddress.com", "language"=>"en-US" ) ); SDVA($ParseBlogMUtoRss, array( "description" => "/\(:blogentry\s+(.*?):\)(.*?)\(:blogentryend:\)/esi", "title" => "/\(:Title\s+(.*?):\)/e", "pubdate" => "/\(:TimeStamp:\s+(.*?):\)/e", "link" => "/\(:PermaLink:\s+(.*?):\)/e" ) ); SDV($ParseBlogMonthsBack,3); SDV($ParseBlogMaxEntries,12); /* HANDLE_BLOG_RSS - Build an RSS 2.0 feed of a digest page. args: $pagename returns: XML string (RSS 2.0) */ function ParseBlog_PageBlocks($pagename) { global $ParseBlogHeadValues, $ParseBlogMUtoRss, $ParseBlogMonthsBack,$ParseBlogMaxEntries; // Check page authorization $contents = RetrieveAuthPage($pagename,"read",false,READPAGE_CURRENT); if (!$contents) Abort("?cannot read $pagename"); // Get the page and group from $pagename $parts = explode('.',$pagename); $group = $parts[0]; $page = $parts[1]; //Create the RSS file header directives $rssheader = ParseBlog_createheader($ParseBlogHeadValues, gmdate('D, d M Y H:i:s \G\M\T', $contents['time'])); //Get current date to start from $currentdate = mktime(0, 0, 0, date('m'), 16, date('Y')); $entriesfound = 0; // Cycle last number of months for Page Blocks containing blog entries for($i = $ParseBlogMonthsBack; $i > 0; $i--) { // Format page entry name with year and month from $currentdate $monthyear = strftime("%Y",$currentdate).strftime("%m",$currentdate); // Set $day to start creating an $entryname from and work backward $monthend = strftime("%d",mktime(0,0,0,$month+1,0,$year)); for($day = strftime("%d",$monthend); $day > 0; $day--) { // Format page entry name by appending day $dayformat = ($day < 10) ? "0".$day : $day; $currentpage = $group."/".$monthyear.$dayformat; // Check for blog entry for current entryname if(PageExists($currentpage)&&($entriesfound < $ParseBlogMaxEntries)){ // Create RSS Items from Page Blocks found on current page $rssitems .= ParseBlog_createitems($currentpage,$ParseBlogMUtoRss, $ParseBlogMaxEntries,$entriesfound); } } // Subtract One day from $currentdate $currentdate = $currentdate - 2592000; } // Combine rss head and items to create the feed and output to the client $rssfeed = $rssheader . $rssitems."\n \n"; header("Content-type: text/xml"); PrintFmt($pagename, $rssfeed); } /* ParseBlog_createheader - Build an RSS 2.0 feed header. args: Values Array, Build Date returns: XML string (RSS 2.0) */ function ParseBlog_createheader($values,$lastbuilddate){ $header = NULL; foreach ($values as $tag => $value){ $header .= "<".$tag.">".$value."\n"; } return "\n". "\n". "\n".$header. "".$lastbuilddate."\n". "PM-Wiki Blog Service .1\n"; } /* ParseBlog_createitems - Build an RSS 2.0 feed items. args: Page of Entries, RegEx Match Array, Max Entries, Found Entries returns: XML string (RSS 2.0) */ function ParseBlog_createitems($page,$regex,$maxentries,&$entriesfound){ global $ScriptUrl,$pagename; $contents = ReadPage($page); // Count and match the blocks in the contents $entrycount = preg_match_all($regex['description'],$contents['text'], $entry, PREG_SET_ORDER); // Cycle through each block and create an RSS item set from the Page Variables for ($entrynum = 0; $entrynum < $entrycount; $entrynum++) { if($entriesfound < $maxentries) { $items .= "\n"; foreach ($regex as $tag => $pattern) { switch ($tag) { case "link": preg_match_all($pattern,$entry[$entrynum][2],$value, PREG_SET_ORDER); $items .= "<".$tag.">".$ScriptUrl."/".$value[0][1]. "\n"; break; default: preg_match_all($pattern,$entry[$entrynum][2],$value, PREG_SET_ORDER); $items .= "<".$tag.">".$value[0][1]."\n"; break; } } $items .= "".MarkupToHTML($pagename,$entry[$entrynum][2]). "\n"."\n"; } } return $items; }