Changeset 2145 for trunk

Show
Ignore:
Timestamp:
08/16/10 09:55:22 (21 months ago)
Author:
nick_ramsay
Message:

[TRUNK] Important RSS fixes for 1.4.1

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/content/plugins

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • trunk/libs/Feeds.php

    r2134 r2145  
    3939                require_once(EXTENSIONS.'RSSWriterClass/rsswriter.php'); 
    4040                 
    41                 $feed = new RSS(); 
     41                $feed = new RSS($h->url(array('page'=>'rss'))); 
    4242                $feed->title = stripslashes(html_entity_decode(urldecode($title), ENT_QUOTES, 'UTF-8')); 
    4343                $feed->link = html_entity_decode($link, ENT_QUOTES, 'UTF-8'); 
  • trunk/libs/extensions/RSSWriterClass/rsswriter.php

    r2134 r2145  
    11<?php 
     2/* Publishes content as an RSS feed 
     3  http://snipplr.com/view/23/rss-writer-class/ 
    24 
    3 /* Publishes content as an RSS feed  
    4    http://snipplr.com/view/23/rss-writer-class/  
    5     
    6    E X A M P L E ----------------------------------------------- 
    7                 $feed = new RSS(); 
    8                 $feed->title       = "RSS Feed Title"; 
    9                 $feed->link        = "http://website.com"; 
    10                 $feed->description = "Recent articles on your website."; 
     5  E X A M P L E ----------------------------------------------- 
     6  $feed = new RSS(); 
     7  $feed->title       = "RSS Feed Title"; 
     8  $feed->link        = "http://website.com"; 
     9  $feed->description = "Recent articles on your website."; 
    1110 
    12                 $db->query($query); 
    13                 $result = $db->result; 
    14                 while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
    15                 { 
    16                         $item = new RSSItem(); 
    17                         $item->title = $title; 
    18                         $item->link  = $link; 
    19                         $item->setPubDate($create_date);  
    20                         $item->description = "<![CDATA[ $html ]]>"; 
    21                         $feed->addItem($item); 
    22                 } 
    23                 echo $feed->serve(); 
    24         ---------------------------------------------------------------- */ 
     11  $db->query($query); 
     12  $result = $db->result; 
     13  while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
     14  { 
     15  $item = new RSSItem(); 
     16  $item->title = $title; 
     17  $item->link  = $link; 
     18  $item->setPubDate($create_date); 
     19  $item->description = "<![CDATA[ $html ]]>"; 
     20  $feed->addItem($item); 
     21  } 
     22  echo $feed->serve(); 
     23  ---------------------------------------------------------------- */ 
    2524 
    2625class RSS { 
    2726 
    28                 var $title; 
    29                 var $link; 
    30                 var $description; 
    31                 var $language = "en-us"; 
    32                 var $pubDate; 
    33         var $items = array(); 
    34         var $tags = array(); 
     27        public $title; 
     28        public $rss_link; 
     29        public $link; 
     30        public $description; 
     31        public $language = "en-us"; 
     32        public $pubDate; 
     33        public $items = array(); 
     34        public $tags = array(); 
    3535 
    36         public function __construct() { 
     36        public function __construct($rss_link) { 
     37                $this->rss_link = (empty($rss_link))? SITEURL.'index.php?page=rss' : $rss_link ; 
     38        } 
    3739 
    38                 } 
    39  
    40                 function addItem($item) 
    41                 { 
    42                 if( is_array($item) ) 
    43                 { 
    44                         foreach( $item as $i ) 
    45                         { 
     40        public function addItem($item) { 
     41                if (is_array($item)) { 
     42                        foreach ($item as $i) { 
    4643                                array_push($this->items, new RSSItem($i)); 
    47                 } 
     44                        } 
    4845                } 
    4946                array_push($this->items, $item); 
    5047        } 
    5148 
    52         function setPubDate($when) { 
    53                 $this->pubDate = date("D, d M Y H:i:s ", ((strtotime($when)) ? strtotime($when) : $when))."GMT"; 
    54                 } 
     49        public function setPubDate($when) { 
     50                $this->pubDate = date("D, d M Y H:i:s O", ((strtotime($when)) ? strtotime($when) : $when)); 
     51        } 
    5552 
    56         function addTag($tag, $value) { 
    57                         $this->tags[$tag] = $value; 
    58                 } 
     53        public function addTag($tag, $value) { 
     54                $this->tags[$tag] = $value; 
     55        } 
    5956 
    60         function out($serve_contentType = FALSE) { 
     57        public function out($serve_contentType = FALSE) { 
    6158 
    6259                if (is_string($serve_contentType)) { 
     
    6764 
    6865                $out = '<?xml version="1.0" encoding="utf-8"?>'."\n"; 
    69                 $out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n"; 
    70                         $out .= "<channel>\n"; 
     66                $out .= '<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom">'."\n"; 
     67                $out .= "<channel>\n"; 
    7168                $out .= "<title>".$this->title."</title>\n"; 
     69                $out .= '<atom:link href="'.$this->rss_link.'" rel="self" type="application/rss+xml" />'."\n"; 
    7270                $out .= "<link>".$this->link."</link>\n"; 
    7371                $out .= "<description>".$this->description."</description>\n"; 
    7472                $out .= "<language>".$this->language."</language>\n"; 
    75                 $out .= "<pubDate>".((empty($this->pubDate)) ? date("D, d M Y H:i:s \G\M\T") : $this->pubDate)."</pubDate>\n"; 
     73                $out .= "<pubDate>".((empty($this->pubDate)) ? date("D, d M Y H:i:s O") : $this->pubDate)."</pubDate>\n"; 
    7674 
    7775                foreach ($this->tags as $key => $val) { 
     
    8078 
    8179                foreach ($this->items as $item) { 
    82                         if( $item instanceof RSSItem) { 
    83                         $out .= $item->out(); 
     80                        if ($item instanceof RSSItem) { 
     81                                $out .= $item->out(); 
    8482                        } 
    8583                } 
    8684 
    87                         $out .= "</channel>\n"; 
    88                          
     85                $out .= "</channel>\n"; 
     86 
    8987                $out .= "</rss>"; 
    9088 
    9189                return str_replace("&", "&amp;", $out); 
    92                 } 
    93                  
    94                 } 
     90        } 
     91 
     92} 
    9593 
    9694class RSSItem { 
     
    116114 
    117115                if (isset($options['date'])) { 
    118                         $this->pubDate = date("D, d M Y H:i:s ", ((strtotime($options['date'])) ? strtotime($options['date']) : $options['date']))."GMT"; 
     116                        $this->pubDate = date("D, d M Y H:i:s O", ((strtotime($options['date'])) ? strtotime($options['date']) : $options['date'])); 
    119117                } 
    120118 
     
    134132        } 
    135133 
    136         function out() { 
    137                         $out = "<item>\n"; 
     134        public function out() { 
     135                $out = "<item>\n"; 
    138136                $out .= "<title>".$this->title."</title>\n"; 
    139137                $out .= "<link>".$this->link."</link>\n"; 
    140138                $out .= "<description>".$this->description."</description>\n"; 
    141                 $out .= "<pubDate>".((empty($this->pubDate)) ? date("D, d M Y H:i:s \G\M\T") : $this->pubDate)."</pubDate>\n"; 
     139                $out .= "<pubDate>".((empty($this->pubDate)) ? date("D, d M Y H:i:s O") : $this->pubDate)."</pubDate>\n"; 
    142140 
    143141                if (!empty($this->attachment)) { 
    144                                 $out .= "<enclosure url='{$this->attachment}' length='{$this->length}' type='{$this->mimetype}' />"; 
     142                        $out .= "<enclosure url='{$this->attachment}' length='{$this->length}' type='{$this->mimetype}' />"; 
    145143                } 
    146144 
    147                 $this->guid = (empty($this->guid)) ? $this->guid : $this->link; 
     145                $this->guid = (empty($this->guid)) ?  $this->link : $this->guid; 
    148146 
    149147                $out .= "<guid>".$this->guid."</guid>\n"; 
     
    154152 
    155153                return $out."</item>\n"; 
    156                 } 
    157  
    158154        } 
    159155 
     156} 
     157 
    160158?>