<?php if (!defined('PmWiki')) exit(); /* Copyright 2004-2006 Steffen Burmeister (der[at]dolph.de) Copyright 2006 Mark A. Matienzo (mark[at]thesecretmirror.com) Copyright 2011 F. Galcik (frantisek.galcik[at]gbox.sk) Version 1.3 (2011-11-15): * instead of anchor, user can specify other page (for rss changelog) * fixed bug in time generation Version 1.2 (2006-07-27): * added guid support Version 1.1 (2005-08-25): * added time support Version 1.0 (2005-08-17): * initial public release This file is an extension to PmWiki; 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. See pmwiki.php for full details. Based on the pmwiki file rss.php: Copyright 2002-2004 Patrick R. Michaud (pmichaud@pobox.com) This script defines "?action=rsss". It will read the current page for a specific wiki syntax, and then output an RSS 2.0 document with the current page as the channel and the separated (by !!! headings) content of the page as items. To add RSS capabilities to your site, simply add to config.php: if ($action == 'rsss') { include_once('cookbook/rsssimple-1.3.php'); } Site Format Definition (sample site): -------------------------------------------------------------------------- !:: Blog Here goes some text. You can describe your blog here, but it will be skipped in the feed. Everything depends on level three (!!!) headings. Let me explain it a bit more: The RSS channel options are defined in the rsssimple.php script. But every RSS item is extracted from the wikipage by separating the page into chunks between !!! headings. The heading itself will be the item-title. Everything up to the next !!! heading will be in the item-description. The date/time in the heading is also very important. Be shure it matches the date given at the beginning of the level 3 heading (see below). You can also give a RSS-link like that to your readers: \\ [[http://www.mysite.com/pmwiki2/pmwiki.php/Main/Blog?action=rsss | RSS-Feed]] !!!2011-08-16 22:05 :: blog item 5 [[AGroup/APage]] You can use blog also for producing rss-style changelog of your website !!!2005-08-16 22:05 :: blog item 4 [[#a2005-08-16T22:05]] Some text that will be shown. The anchor above is for emulating the permalink feature of other blogs. You can skip that anchor if you like. !!!2005-08-16 14:30 :: blog item 3 [[#a2005-08-16T14:30]] Another blog entry. Full '''wiki-syntax''' is supported [[Main.HomePage | here]]. Note, that you can also specify the time if you like. !!!2005-08-14 :: blog item 2 [[#a2005-08-14]] And another one. You can make paragraphs too. !!!2005-08-13 :: first blog item [[#a2005-08-13]] Welcome to my blog! -------------------------------------------------------------------------- See a working example at: http://www.dolph.de http://mark.thesecretmirror.com/ Have fun! */ SDV($HandleActions['rsss'],'HandleRssSimple'); /* **** feed configuration **** */ SDV($RssTitle,"My Blog"); # rss feed title SDV($RssLink,"http://www.mysite.com"); # rss feed link SDV($RssDesc,"This is my blog"); # rss feed description SDV($RssLanguage,"en-US"); # rss feed language SDV($RssCopyright,"Me"); # rss feed copyright SDV($RssEditor,"me@mysite.com"); # rss feed managing editor SDV($RssWebMaster,"webmaster@mysite.com"); # rss feed webmaster SDV($RssMaxItems,0); # maximum items to display (set to 0 for all) SDV($RssItems,array()); # RSS item elements /* ***************************** */ ### RSS 2.0 definitions SDV($RssChannelFmt,'<?xml version="1.0" encoding="iso-8859-1"?'.'> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel> <title>'.$RssTitle.'</title> <link>'.$RssLink.'</link> <description>'.$RssDesc.'</description> <language>'.$RssLanguage.'</language> <copyright>'.$RssCopyright.'</copyright> <managingEditor>'.$RssEditor.'</managingEditor> <webMaster>'.$RssWebMaster.'</webMaster> <lastBuildDate>$RssChannelBuildDate</lastBuildDate> <generator>$Version with rsssimple.php v1.1</generator>'); SDV($RssItemFmt,' <item> <title>$RssItemTitle</title> <link>$RssItemLink</link> <guid isPermaLink="true">$RssItemLink</guid> <description>$RssItemDesc</description> <pubDate>$RssItemPubDate</pubDate> </item>'); SDV($HandleRssFmt,array(&$RssChannelFmt,&$RssItems,'</channel></rss>')); function HandleRssSimple($pagename, $auth='read') { global $RssMaxItems,$RssEditor, $RssDesc, $RssChannelFmt,$RssChannelDesc,$RssChannelBuildDate, $RssItems,$RssItemFmt, $HandleRssFmt,$FmtV,$ScriptUrl,$Group,$Name; $t = ReadTrail($pagename,$pagename); $page = RetrieveAuthPage($pagename, $auth, false, READPAGE_CURRENT); if (!$page) Abort("?cannot read $pagename"); $cbgmt = $page['time']; SDV($RssChannelBuildDate, gmdate('D, d M Y H:i:s \G\M\T', $cbgmt)); $source = $page['text']; $number_of_items = preg_match_all('/!!!.*::\ /', $source, $dates); // get the number of items and the dates $dates = $dates[0]; $source_in_html = MarkupToHTML($pagename,$source); $entries = preg_split('/!!!.*\ ::\ /', $source, -1, PREG_SPLIT_DELIM_CAPTURE); array_shift($entries); // throw away everything before the first heading $noitems = count($dates); if ( $RssMaxItems > 0 && $noitems > $RssMaxItems ) { $noitems = $RssMaxItems; } for ($i=0; $i<$noitems; $i++) { # extract the date preg_match('/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/', $dates[$i], $date); $date = $date[0]; # extract the time preg_match('/[0-9][0-9]:[0-9][0-9]/', $dates[$i], $time); $time = $time[0]; # extract the title and the description $content = preg_split('/\n/', $entries[$i], 2); # extract link for rss item (anchor or link to a page) preg_match('/\[\[.*\]\]/', $content[0], $itemLink); $itemLink = str_replace('[[', '', $itemLink[0]); $itemLink = trim(str_replace(']]', '', $itemLink)); if (($itemLink != '') && (substr($itemLink, 0, 1) == '#')) $itemLink = $pagename.$itemLink; $title = preg_replace('/\[\[.*\]\]/', '', $content[0]); $title = trim($title); $description = $content[1]; $description = trim($description); $description = MarkupToHTML($pagename, $description); //$description = strip_tags($description); # without html tags $description = "<![CDATA[ " . $description . " ]]>"; # as cdata enclosure $link = MakeLink($pagename, $itemLink, NULL, NULL, '$LinkUrl'); // print_r("$date - $time - $title <br>$description<br>$link<br><br>"); // debug output SDV($RssDesc,entityencode(FmtPageName($RssDesc,$pagename))); $FmtV['$RssItemTitle'] = $title; $FmtV['$RssItemLink'] = $link; $FmtV['$RssItemDesc'] = $description; $FmtV['$RssItemAuthor'] = $RssEditor; $FmtV['$RssItemPubDate'] = gmdate("r", mktime(substr($time,0,2),substr($time,3,2),0,substr($date,5,2),substr($date,8,2),substr($date,0,4))); //$RssItems[] = entityencode(FmtPageName($RssItemFmt,$title)); // items with entity-encoding $RssItems[] = FmtPageName($RssItemFmt,$title); // items without entity-encoding } header("Content-type: text/xml"); PrintFmt($pagename,$HandleRssFmt); exit(); } # entityencode() and $EntitiesTable are used to convert non-ASCII characters # and named entities into numeric entities, since the RSS and RDF # specifications don't have a good way of incorporating them by default. function entityencode($s) { global $EntitiesTable; $s = str_replace(array_keys($EntitiesTable),array_values($EntitiesTable),$s); return preg_replace('/([\\x80-\\xff])/e',"'&#'.ord('\$1').';'",$s); } SDVA($EntitiesTable, array( # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent" ' ' => ' ', '¡' => '¡', '¢' => '¢', '£' => '£', '¤' => '¤', '¥' => '¥', '¦' => '¦', '§' => '§', '¨' => '¨', '©' => '©', 'ª' => 'ª', '«' => '«', '¬' => '¬', '­' => '­', '®' => '®', '¯' => '¯', '°' => '°', '±' => '±', '²' => '²', '³' => '³', '´' => '´', 'µ' => 'µ', '¶' => '¶', '·' => '·', '¸' => '¸', '¹' => '¹', 'º' => 'º', '»' => '»', '¼' => '¼', '½' => '½', '¾' => '¾', '¿' => '¿', 'À' => 'À', 'Á' => 'Á', 'Â' => 'Â', 'Ã' => 'Ã', 'Ä' => 'Ä', 'Å' => 'Å', 'Æ' => 'Æ', 'Ç' => 'Ç', 'È' => 'È', 'É' => 'É', 'Ê' => 'Ê', 'Ë' => 'Ë', 'Ì' => 'Ì', 'Í' => 'Í', 'Î' => 'Î', 'Ï' => 'Ï', 'Ð' => 'Ð', 'Ñ' => 'Ñ', 'Ò' => 'Ò', 'Ó' => 'Ó', 'Ô' => 'Ô', 'Õ' => 'Õ', 'Ö' => 'Ö', '×' => '×', 'Ø' => 'Ø', 'Ù' => 'Ù', 'Ú' => 'Ú', 'Û' => 'Û', 'Ü' => 'Ü', 'Ý' => 'Ý', 'Þ' => 'Þ', 'ß' => 'ß', 'à' => 'à', 'á' => 'á', 'â' => 'â', 'ã' => 'ã', 'ä' => 'ä', 'å' => 'å', 'æ' => 'æ', 'ç' => 'ç', 'è' => 'è', 'é' => 'é', 'ê' => 'ê', 'ë' => 'ë', 'ì' => 'ì', 'í' => 'í', 'î' => 'î', 'ï' => 'ï', 'ð' => 'ð', 'ñ' => 'ñ', 'ò' => 'ò', 'ó' => 'ó', 'ô' => 'ô', 'õ' => 'õ', 'ö' => 'ö', '÷' => '÷', 'ø' => 'ø', 'ù' => 'ù', 'ú' => 'ú', 'û' => 'û', 'ü' => 'ü', 'ý' => 'ý', 'þ' => 'þ', 'ÿ' => 'ÿ', # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent" '"' => '"', #'&' => '&#38;', #'<' => '&#60;', #'>' => '>', ''' => ''', 'Œ' => 'Œ', 'œ' => 'œ', 'Š' => 'Š', 'š' => 'š', 'Ÿ' => 'Ÿ', 'ˆ' => 'ˆ', '˜' => '˜', ' ' => ' ', ' ' => ' ', ' ' => ' ', '‌' => '‌', '‍' => '‍', '‎' => '‎', '‏' => '‏', '–' => '–', '—' => '—', '‘' => '‘', '’' => '’', '‚' => '‚', '“' => '“', '”' => '”', '„' => '„', '†' => '†', '‡' => '‡', '‰' => '‰', '‹' => '‹', '›' => '›', '€' => '€', # entities defined in "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent" 'ƒ' => 'ƒ', 'Α' => 'Α', 'Β' => 'Β', 'Γ' => 'Γ', 'Δ' => 'Δ', 'Ε' => 'Ε', 'Ζ' => 'Ζ', 'Η' => 'Η', 'Θ' => 'Θ', 'Ι' => 'Ι', 'Κ' => 'Κ', 'Λ' => 'Λ', 'Μ' => 'Μ', 'Ν' => 'Ν', 'Ξ' => 'Ξ', 'Ο' => 'Ο', 'Π' => 'Π', 'Ρ' => 'Ρ', 'Σ' => 'Σ', 'Τ' => 'Τ', 'Υ' => 'Υ', 'Φ' => 'Φ', 'Χ' => 'Χ', 'Ψ' => 'Ψ', 'Ω' => 'Ω', 'α' => 'α', 'β' => 'β', 'γ' => 'γ', 'δ' => 'δ', 'ε' => 'ε', 'ζ' => 'ζ', 'η' => 'η', 'θ' => 'θ', 'ι' => 'ι', 'κ' => 'κ', 'λ' => 'λ', 'μ' => 'μ', 'ν' => 'ν', 'ξ' => 'ξ', 'ο' => 'ο', 'π' => 'π', 'ρ' => 'ρ', 'ς' => 'ς', 'σ' => 'σ', 'τ' => 'τ', 'υ' => 'υ', 'φ' => 'φ', 'χ' => 'χ', 'ψ' => 'ψ', 'ω' => 'ω', 'ϑ' => 'ϑ', 'ϒ' => 'ϒ', 'ϖ' => 'ϖ', '•' => '•', '…' => '…', '′' => '′', '″' => '″', '‾' => '‾', '⁄' => '⁄', '℘' => '℘', 'ℑ' => 'ℑ', 'ℜ' => 'ℜ', '™' => '™', 'ℵ' => 'ℵ', '←' => '←', '↑' => '↑', '→' => '→', '↓' => '↓', '↔' => '↔', '↵' => '↵', '⇐' => '⇐', '⇑' => '⇑', '⇒' => '⇒', '⇓' => '⇓', '⇔' => '⇔', '∀' => '∀', '∂' => '∂', '∃' => '∃', '∅' => '∅', '∇' => '∇', '∈' => '∈', '∉' => '∉', '∋' => '∋', '∏' => '∏', '∑' => '∑', '−' => '−', '∗' => '∗', '√' => '√', '∝' => '∝', '∞' => '∞', '∠' => '∠', '∧' => '∧', '∨' => '∨', '∩' => '∩', '∪' => '∪', '∫' => '∫', '∴' => '∴', '∼' => '∼', '≅' => '≅', '≈' => '≈', '≠' => '≠', '≡' => '≡', '≤' => '≤', '≥' => '≥', '⊂' => '⊂', '⊃' => '⊃', '⊄' => '⊄', '⊆' => '⊆', '⊇' => '⊇', '⊕' => '⊕', '⊗' => '⊗', '⊥' => '⊥', '⋅' => '⋅', '⌈' => '⌈', '⌉' => '⌉', '⌊' => '⌊', '⌋' => '⌋', '⟨' => '〈', '⟩' => '〉', '◊' => '◊', '♠' => '♠', '♣' => '♣', '♥' => '♥', '♦' => '♦'));