summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2010-02-22 20:57:17 +0000
committerdeva <deva>2010-02-22 20:57:17 +0000
commit184bed72a9da81a4de621ef62ab7aab0c61c0ddf (patch)
treee266ddc88277eb0b347fe5b1c0700ea661294262
parent3a08ef9c94e6f5c92a7f3885fb316b53d13cfd5c (diff)
Make rss feed generator atom 2.0 compliant.
-rw-r--r--utils/markdown.php34
-rw-r--r--utils/rss.php7
2 files changed, 31 insertions, 10 deletions
diff --git a/utils/markdown.php b/utils/markdown.php
index 89a85b2..eabd01d 100644
--- a/utils/markdown.php
+++ b/utils/markdown.php
@@ -38,7 +38,7 @@ define( 'MARKDOWNEXTRA_VERSION', "1.2.2" ); # Sat 21 Jun 2008
@define( 'MARKDOWN_PARSER_CLASS', 'MarkdownExtra_Parser' );
-function Markdown($text) {
+function Markdown($text, $simple = false) {
#
# Initialize the parser and return the result of its transform method.
#
@@ -47,6 +47,7 @@ function Markdown($text) {
if (!isset($parser)) {
$parser_class = MARKDOWN_PARSER_CLASS;
$parser = new $parser_class;
+ $parser->simple = $simple;
}
# Transform text using parser.
@@ -83,6 +84,7 @@ class Markdown_Parser {
var $predef_urls = array();
var $predef_titles = array();
+ public $simple;
function Markdown_Parser() {
#
@@ -2092,14 +2094,23 @@ class MarkdownExtra_Parser extends Markdown_Parser {
$level = $matches[3]{0} == '=' ? 1 : 2;
$attr = $this->_doHeaders_attr($id =& $matches[2]);
$class = strtolower(str_replace(" ", "_", $this->runSpanGamut($matches[1])));
- $block = "<div class=\"header\"><h$level$attr class=\"header_$class\"><span class=\"header_text\">".$this->runSpanGamut($matches[1])."</span></h$level></div>";
+ if($this->simple) {
+ $block = "<h$level$attr>".$this->runSpanGamut($matches[1])."</h$level>";
+ } else {
+ $block = "<div class=\"header\"><h$level$attr class=\"header_$class\"><span class=\"header_text\">".$this->runSpanGamut($matches[1])."</span></h$level></div>";
+ }
return "\n" . $this->hashBlock($block) . "\n\n";
}
function _doHeaders_callback_atx($matches) {
$level = strlen($matches[1]);
$attr = $this->_doHeaders_attr($id =& $matches[3]);
$class = strtolower(str_replace(" ", "_", $this->runSpanGamut($matches[2])));
- $block = "<div class=\"header\"><h$level$attr class=\"header_$class\"><span class=\"header_text\">".$this->runSpanGamut($matches[2])."</span></h$level></div>";
+ if($this->simple) {
+ $block = "<h$level$attr>".$this->runSpanGamut($matches[2])."</h$level>";
+ } else {
+ $block = "<div class=\"header\"><h$level$attr class=\"header_$class\"><span class=\"header_text\">".$this->runSpanGamut($matches[2])."</span></h$level></div>";
+ }
+
return "\n" . $this->hashBlock($block) . "\n\n";
}
@@ -2453,12 +2464,21 @@ class MarkdownExtra_Parser extends Markdown_Parser {
$centerr = "";
if(strlen($value) > 2 && $value[0] == '=' &&
$value[strlen($value)-1] == '=') {
- $centerl = "<div style=\"text-align: center;\">";
- $centerr = "</div>";
+ if($this->simple) {
+ $centerl = "<div style=\"text-align: center;\">";
+ $centerr = "</div>";
+ } else {
+ $centerl = "<center>";
+ $centerr = "</center>";
+ }
$value = substr($value, 1, strlen($value) - 2);
}
- $value = "<div class=\"paragraph\">" .
- $centerl . $value . $centerr . "</div>";
+ if($this->simple) {
+ $value = "<p>" . $centerl . $value . $centerr . "</p>";
+ } else {
+ $value = "<div class=\"paragraph\">" .
+ $centerl . $value . $centerr . "</div>";
+ }
}
$grafs[$key] = $value;
}
diff --git a/utils/rss.php b/utils/rss.php
index 6f909d3..bed69ce 100644
--- a/utils/rss.php
+++ b/utils/rss.php
@@ -56,9 +56,10 @@ class RSS {
$fp = fopen($this->rssfile, "w");
fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- fwrite($fp, "<rss version=\"2.0\">\n");
+ fwrite($fp, "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n");
fwrite($fp, " <channel>\n");
fwrite($fp, " <title>".$RSS_TITLE."</title>\n");
+ fwrite($fp, " <atom:link href=\"".$RSS_URL."/rss.xml\" rel=\"self\" type=\"application/rss+xml\" />\n");
fwrite($fp, " <link>".$RSS_URL."</link>\n");
fwrite($fp, " <description>".$RSS_DESCRIPTION."</description>\n");
fwrite($fp, " <language>en-us</language>\n");
@@ -74,7 +75,7 @@ class RSS {
fwrite($fp, " <item>\n");
fwrite($fp, " <title>".$newsentry->title."</title>\n");
fwrite($fp, " <link>".$RSS_URL."/?page=".$RSS_TARGET_PAGE."&amp;newsid=".$newsentry->time."</link>\n");
- $content = Markdown(htmlspecialchars_decode($newsentry->description));
+ $content = htmlspecialchars(Markdown(htmlspecialchars_decode($newsentry->description), true));
fwrite($fp, " <description>".$content."</description>\n");
fwrite($fp, " <pubDate>".$this->date($newsentry->time)."</pubDate>\n");
fwrite($fp, " <guid>".$RSS_URL."/?page=".$RSS_TARGET_PAGE."&amp;newsid=".$newsentry->time."</guid>\n");
@@ -101,7 +102,7 @@ class RSS {
$rssentry = new RSSEntry($param->getAttribute('title'),
$param->getAttribute('time'),
$param->getAttribute('category'),
- $param->getAttribute('description'));
+ $param->textContent);
$this->add($rssentry);
}