diff options
author | pmichaud <pmichaud@524c5546-5005-0410-9a3e-e25e191bd360> | 2005-12-10 06:06:14 +0000 |
---|---|---|
committer | pmichaud <pmichaud@524c5546-5005-0410-9a3e-e25e191bd360> | 2005-12-10 06:06:14 +0000 |
commit | 52e61944afa4e493e3205b79c8e1e6c594ced87a (patch) | |
tree | 7d1cc347aec0b08336ee89a3acd7b26468079f2d /scripts/feeds.php | |
parent | 373d366c6b8bd9397615305f6458250c53518ff2 (diff) | |
download | pmwiki.svn-52e61944afa4e493e3205b79c8e1e6c594ced87a.tar.bz2 |
Switch to use feeds.php instead of rss.php.
git-svn-id: svn://pmwiki.org/pmwiki/trunk@1028 524c5546-5005-0410-9a3e-e25e191bd360
Diffstat (limited to 'scripts/feeds.php')
-rw-r--r-- | scripts/feeds.php | 460 |
1 files changed, 460 insertions, 0 deletions
diff --git a/scripts/feeds.php b/scripts/feeds.php new file mode 100644 index 00000000..5d48da11 --- /dev/null +++ b/scripts/feeds.php @@ -0,0 +1,460 @@ +<?php if (!defined('PmWiki')) exit(); +/* Copyright 2005 Patrick R. Michaud (pmichaud@pobox.com) + This file is part of 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. + + References: + http://dublincore.org/documents/dcmes-xml/ + http://www.atomenabled.org/developers/syndication/ +*/ + + +## Settings for ?action=atom +SDVA($FeedFmt['atom']['feed'], array( + '_start' => '<?xml version="1.0" encoding="$Charset"?'.'> +<!DOCTYPE rdf:RDF PUBLIC "-//DUBLIN CORE//DCMES DTD 2002/07/31//EN" + "http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml-dtd.dtd"> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n", + '_end' => "</rdf:RDF>\n", + 'title' => '$WikiTitle', + 'id' => '$PageUrl?action=atom', + 'updated' => '$FeedISOTime', + 'author' => "<author><name>Patrick R. Michaud</name></author>\n", + 'generator' => '$Version', + 'logo' => '$PageLogoUrl')); +SDVA($FeedFmt['atom']['item'], array( + '_start' => "<entry>\n", + 'id' => '$PageUrl', + 'title' => '$Title', + 'updated' => '$ItemISOTime', + 'link' => '<link rel="alternate" href="$PageUrl" />', + 'author' => '<author>$LastModifiedBy</author>', + 'summary' => '$ItemDesc', + 'category' => '<category term="$Category" />', + '_end' => "</entry>\n")); + +## Settings for ?action=dc +SDVA($FeedFmt['dc']['feed'], array( + '_start' => '<?xml version="1.0" encoding="$Charset"?'.'> +<!DOCTYPE rdf:RDF PUBLIC "-//DUBLIN CORE//DCMES DTD 2002/07/31//EN" + "http://dublincore.org/documents/2002/07/31/dcmes-xml/dcmes-xml-dtd.dtd"> +<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n", + '_end' => "</rdf:RDF>\n")); +SDVA($FeedFmt['dc']['item'], array( + '_start' => "<rdf:Description rdf:about=\"\$PageUrl\">\n", + 'dc:title' => '$Title', + 'dc:identifier' => '$PageUrl', + 'dc:date' => '$ItemISOTime', + 'dc:type' => 'Text', + 'dc:format' => 'text/html', + 'dc:description' => '$ItemDesc', + 'dc:subject' => "<dc:subject>\$Category</dc:subject>\n", + 'dc:publisher' => '$WikiTitle', + 'dc:author' => '$LastModifiedBy', + '_end' => "</rdf:Description>\n")); + +## RSS 2.0 settings for ?action=rss +SDVA($FeedFmt['rss']['feed'], array( + '_start' => '<?xml version="1.0" encoding="$Charset"?'.'> +<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"> +<channel>'."\n", + '_end' => "</channel>\n</rss>\n", + 'title' => '$WikiTitle | $Group / $Title', + 'link' => '$PageUrl?action=rss', + 'description' => '$Group.$Title', + 'lastBuildDate' => '$FeedRSSTime')); +SDVA($FeedFmt['rss']['item'], array( + '_start' => "<item>\n", + '_end' => "</item>\n", + 'title' => '$Group / $Title', + 'link' => '$PageUrl', + 'description' => '$ItemDesc', + 'dc:contributor' => '$LastModifiedBy', + 'dc:date' => '$ItemISOTime', + 'enclosure' => 'RSSEnclosure')); + +## RDF 1.0, for ?action=rdf +SDVA($FeedFmt['rdf']['feed'], array( + '_start' => '<?xml version="1.0" encoding="$Charset"?'.'> +<rdf:RDF xmlns="http://purl.org/rss/1.0/" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + <channel rdf:about="$PageUrl?action=rdf">'."\n", + 'title' => '$WikiTitle | $Group / $Title', + 'link' => '$PageUrl?action=rdf', + 'description' => '$Group.$Title', + 'dc:date' => '$FeedISOTime', + '_items' => "<rdf:Seq>\n<items>\n", + '_end' => "</items>\n</rdf:Seq>\n</channel>\n</rdf:RDF>\n")); +SDVA($FeedFmt['rdf']['item'], array( + '_start' => "<item rdf:about=\"\$PageUrl\">\n", + '_end' => "</item>\n", + 'title' => '$WikiTitle | $Group / $Title', + 'link' => '$PageUrl', + 'description' => '$ItemDesc', + 'dc:date' => '$ItemISOTime')); + +foreach(array_keys($FeedFmt) as $k) { + SDV($HandleActions[$k], 'HandleFeed'); + SDV($HandleAuth[$k], 'read'); +} + +function HandleFeed($pagename, $auth = 'read') { + global $FeedFmt, $action, $PCache, $FmtV, $ISOTimeFmt, $RSSTimeFmt, + $FeedOpt, $FeedDescPatterns, $CategoryGroup, $EntitiesTable; + SDV($ISOTimeFmt, '%Y-%m-%dT%H:%M:%SZ'); + SDV($RSSTimeFmt, 'D, d M Y H:i:s \G\M\T'); + SDVA($FeedOpt, array('count' => 20, 'trail' => $pagename, 'readf' => 1)); + SDV($FeedDescPatterns, array('/^.*<\\/\\w+>/s' => '$0', '/<[^>]+>/' => '')); + + $f = $FeedFmt[$action]; + $page = RetrieveAuthPage($pagename, $auth, true, READPAGE_CURRENT); + if (!$page) Abort("?cannot generate feed"); + $feedtime = $page['time']; + + # determine list of pages to display + if ($action=='dc') unset($FeedOpt['trail']); + $opt = array_merge($FeedOpt, @$_REQUEST); + if ($opt['trail'] || $opt['group'] || $opt['link']) + $pagelist = MakePageList($pagename, $opt); + if (!@$pagelist) + { PCache($pagename, $page); $pagelist = array(&$PCache[$pagename]); } + if (@$opt['count']) array_splice($pagelist, $opt['count']); + + # process list of pages in feed + foreach($pagelist as $page) { + $pn = $page['name']; + #$page = PageMetadata($pn, ReadPage($pn, READPAGE_CURRENT)); + $pl[] = $page; + if ($page['time'] > $feedtime) $feedtime = $page['time']; + } + $pagelist = $pl; + + $FmtV['$FeedISOTime'] = gmstrftime($ISOTimeFmt, $feedtime); + $FmtV['$FeedRSSTime'] = gmdate($RSSTimeFmt, $feedtime); + # format start of feed + $out = FmtPageName($f['feed']['_start'], $pagename); + + # format feed elements + foreach($f['feed'] as $k => $v) { + if ($k{0} == '_') continue; + $x = FmtPageName($v, $pagename); + if (!$x) continue; + $out .= ($v{0} == '<') ? $x : "<$k>$x</$k>\n"; + } + + # format items in feed + if (@$f['feed']['_items']) + $out .= FmtPageName($f['feed']['_items'], $pagename); + foreach($pagelist as $page) { + $pn = $page['name']; + $FmtV['$ItemDesc'] = (@$page['description']) + ? $page['description'] + : preg_replace(array_keys($FeedDescPatterns), + array_values($FeedDescPatterns), @$page['excerpt']); + $FmtV['$ItemISOTime'] = gmstrftime($ISOTimeFmt, $page['time']); + + $out .= FmtPageName($f['item']['_start'], $pn); + foreach((array)@$f['item'] as $k => $v) { + if ($k{0} == '_') continue; + if (is_callable($v)) { $out .= $v($pn, $page, $k); continue; } + if (strpos($v, '$Category') + && preg_match_all("/(?<=^|,)$CategoryGroup\\.([^,]+)/", + $page['targets'], $match)) { + foreach($match[1] as $c) { + $FmtV['$Category'] = $c; + $out .= FmtPageName($v, $pn); + } + continue; + } + $x = FmtPageName($v, $pn); + if (!$x) continue; + $out .= ($v{0} == '<') ? $x : "<$k>$x</$k>\n"; + } + $out .= FmtPageName($f['item']['_end'], $pn); + } + $out .= FmtPageName($f['feed']['_end'], $pagename); + header('Content-type: text/xml'); + print str_replace(array_keys($EntitiesTable), + array_values($EntitiesTable), $out); +} + +function RSSEnclosure($pagename, &$page, $k) { + global $RSSEnclosureFmt, $UploadFileFmt, $UploadExts; + if (!function_exists('MakeUploadName')) return ''; + SDV($RSSEnclosureFmt, array('$Name.mp3')); + foreach((array)$RSSEnclosureFmt as $fmt) { + $path = FmtPageName($fmt, $pagename); + $upname = MakeUploadName($pagename, $path); + $filepath = FmtPageName("$UploadFileFmt/$upname", $pagename); + if (file_exists($filepath)) break; + } + if (!file_exists($filepath)) return; + $length = filesize($filepath); + $type = @$UploadExts[preg_replace('/.*\\./', '', $filepath)]; + $url = LinkUpload($pagename, 'Attach:', $path, '', '', '$LinkUrl'); + return "<$k url='$url' length='$length' type='$type' />"; +} + +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" + 'ƒ' => 'ƒ', + 'Α' => 'Α', + 'Β' => 'Β', + 'Γ' => 'Γ', + 'Δ' => 'Δ', + 'Ε' => 'Ε', + 'Ζ' => 'Ζ', + 'Η' => 'Η', + 'Θ' => 'Θ', + 'Ι' => 'Ι', + 'Κ' => 'Κ', + 'Λ' => 'Λ', + 'Μ' => 'Μ', + 'Ν' => 'Ν', + 'Ξ' => 'Ξ', + 'Ο' => 'Ο', + 'Π' => 'Π', + 'Ρ' => 'Ρ', + 'Σ' => 'Σ', + 'Τ' => 'Τ', + 'Υ' => 'Υ', + 'Φ' => 'Φ', + 'Χ' => 'Χ', + 'Ψ' => 'Ψ', + 'Ω' => 'Ω', + 'α' => 'α', + 'β' => 'β', + 'γ' => 'γ', + 'δ' => 'δ', + 'ε' => 'ε', + 'ζ' => 'ζ', + 'η' => 'η', + 'θ' => 'θ', + 'ι' => 'ι', + 'κ' => 'κ', + 'λ' => 'λ', + 'μ' => 'μ', + 'ν' => 'ν', + 'ξ' => 'ξ', + 'ο' => 'ο', + 'π' => 'π', + 'ρ' => 'ρ', + 'ς' => 'ς', + 'σ' => 'σ', + 'τ' => 'τ', + 'υ' => 'υ', + 'φ' => 'φ', + 'χ' => 'χ', + 'ψ' => 'ψ', + 'ω' => 'ω', + 'ϑ' => 'ϑ', + 'ϒ' => 'ϒ', + 'ϖ' => 'ϖ', + '•' => '•', + '…' => '…', + '′' => '′', + '″' => '″', + '‾' => '‾', + '⁄' => '⁄', + '℘' => '℘', + 'ℑ' => 'ℑ', + 'ℜ' => 'ℜ', + '™' => '™', + 'ℵ' => 'ℵ', + '←' => '←', + '↑' => '↑', + '→' => '→', + '↓' => '↓', + '↔' => '↔', + '↵' => '↵', + '⇐' => '⇐', + '⇑' => '⇑', + '⇒' => '⇒', + '⇓' => '⇓', + '⇔' => '⇔', + '∀' => '∀', + '∂' => '∂', + '∃' => '∃', + '∅' => '∅', + '∇' => '∇', + '∈' => '∈', + '∉' => '∉', + '∋' => '∋', + '∏' => '∏', + '∑' => '∑', + '−' => '−', + '∗' => '∗', + '√' => '√', + '∝' => '∝', + '∞' => '∞', + '∠' => '∠', + '∧' => '∧', + '∨' => '∨', + '∩' => '∩', + '∪' => '∪', + '∫' => '∫', + '∴' => '∴', + '∼' => '∼', + '≅' => '≅', + '≈' => '≈', + '≠' => '≠', + '≡' => '≡', + '≤' => '≤', + '≥' => '≥', + '⊂' => '⊂', + '⊃' => '⊃', + '⊄' => '⊄', + '⊆' => '⊆', + '⊇' => '⊇', + '⊕' => '⊕', + '⊗' => '⊗', + '⊥' => '⊥', + '⋅' => '⋅', + '⌈' => '⌈', + '⌉' => '⌉', + '⌊' => '⌊', + '⌋' => '⌋', + '⟨' => '〈', + '⟩' => '〉', + '◊' => '◊', + '♠' => '♠', + '♣' => '♣', + '♥' => '♥', + '♦' => '♦')); + |