Changeset 71

Show
Ignore:
Timestamp:
06/19/07 19:30:19 (19 months ago)
Author:
verbosus
Message:

Cosmetic tweaks to feed.php: thanks, Federico Marzocchi!

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • hacks/trunk/feedphp/feed.php

    r70 r71  
    66   *  
    77   * author: Antonio Cavedoni <http://cavedoni.com/> 
    8    * version: 0.1 
     8   * version: 0.11 
    99   * revision: $Id$ 
    1010   * license: BSD 
     11   *  
     12   * acknowledgements: Ludovico Magnocavallo, Simon Willison, Adrian 
     13   * Holovaty, Jacob Kaplan-Moss and the Django project, Federico 
     14   * Marzocchi 
    1115   *  
    1216   * Feed::serve() outputs the feed with the proper MIME type and 
     
    2125   * require_once('feed.php'); 
    2226   *  
    23    * $feed = new AtomFeed(Array( 
     27   * $feed = new AtomFeed(array( 
    2428   *     'title' => 'My feed',  
    2529   *     'link' => 'http://localhost/myfeed.php',  
     
    2731   * )); 
    2832   *  
    29    * $feed->addItem(Array( 
     33   * $feed->addItem(array( 
    3034   *    'title' => 'mytitle',  
    3135   *    'link' => 'http://example.org/1',  
     
    3741   * )); 
    3842   *  
    39    * $feed->addItem(Array( 
     43   * $feed->addItem(array( 
    4044   *     'title' => 'another title',  
    4145   *     'link' => 'http://example.org/2',  
     
    6367 
    6468class Feed { 
    65     public $items = Array(); 
     69    public $items = array(); 
    6670    public $writer; 
    6771    public $charset = 'UTF-8'; 
     
    7377    public function __construct($params) 
    7478    { 
    75         if (array_key_exists('charset', $params))  
     79        if (array_key_exists('charset', $params)) { 
    7680            $this->charset = $params['charset']; 
    77         if (array_key_exists('title', $params)) 
     81        } 
     82        if (array_key_exists('title', $params)) { 
    7883            $this->title = $params['title']; 
    79         if (array_key_exists('link', $params)) 
     84        } 
     85        if (array_key_exists('link', $params)) { 
    8086            $this->link = $params['link']; 
    81         if (array_key_exists('description', $params))  
     87        } 
     88        if (array_key_exists('description', $params)) { 
    8289            $this->description = $params['description']; 
     90        } 
    8391    } 
    8492 
     
    92100    public function latestPostDate()  
    93101    { 
    94         $updates = Array(); 
     102        $updates = array(); 
    95103        foreach ($this->items as $item) { 
    96             array_push($updates, $item['pubDate']); 
     104            $this->updates[] = $item['pubDate']; 
    97105        } 
    98106        rsort($updates); 
     
    102110    public function addItem($params)  
    103111    { 
    104         $item = Array( 
     112        $item = array( 
    105113            'title' => $params['title'],  
    106114            'link' => $params['link'],  
     
    109117        ); 
    110118 
    111         if (array_key_exists('author', $params))  
     119        if (array_key_exists('author', $params)) { 
    112120            $item['author'] = $params['author']; 
    113         if (array_key_exists('authorEmail', $params)) 
     121        } 
     122        if (array_key_exists('authorEmail', $params)) { 
    114123            $item['authorEmail'] = $params['authorEmail']; 
    115         if (array_key_exists('uniqueId', $params)) 
     124        } 
     125        if (array_key_exists('uniqueId', $params)) { 
    116126            $item['uniqueId'] = $params['uniqueId']; 
     127        } 
    117128        array_push($this->items, $item); 
    118129    } 
     
    165176        // See if the client has provided the required headers 
    166177        $if_modified_since = $if_none_match = false; 
    167         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) 
     178        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { 
    168179            $if_modified_since = stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']); 
    169         if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) 
     180        } 
     181        if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { 
    170182            $if_none_match = stripslashes($_SERVER['HTTP_IF_NONE_MATCH']); 
     183        } 
    171184        if (!$if_modified_since && !$if_none_match) { 
    172185            // both are missing 
     
    229242            $this->rfc3339Date($this->latestPostDate())); 
    230243        $this->writer->elementWithAttrs('link',  
    231             Array('rel' => 'self', 'href' => $this->link)); 
     244            array('rel' => 'self', 'href' => $this->link)); 
    232245        $this->writeItems(); 
    233246        $this->writer->endElement(); 
     
    241254            $this->writer->writeElement('title', $item['title']); 
    242255            $this->writer->elementWithAttrs('link',  
    243                 Array('rel' => 'alternate', 'href' => $item['link'])); 
     256                array('rel' => 'alternate', 'href' => $item['link'])); 
    244257            $this->writer->elementWithAttrs('content',  
    245                 Array('type' => 'html'), $item['description']); 
     258                array('type' => 'html'), $item['description']); 
    246259            $this->writer->writeElement('id', $item['link']); 
    247260            $this->writer->writeElement('updated',