Show
Ignore:
Timestamp:
10/01/08 07:39:26 (3 months ago)
Author:
anatoo
Message:

レスポンス周り追加

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/plain_php/trunk/core/RssRenderer.php

    r20040 r20336  
    11<?php 
    22 
     3class RssRenderer 
     4{ 
     5    function render(RssResponse $r) 
     6    { 
     7        header('Content-type: text/xml; charset=UTF-8'); 
     8         
     9        list($title, $link, $desc) = $r->getChannel(); 
     10        echo '<?xml version="1.0" encoding="UTF-8" ?> 
     11<rss version="2.0"> 
     12<channel> 
     13<title>' . h($title) . '</title> 
     14<link>' . h($link) . '</link> 
     15<description>' . h($desc) . '</description> 
     16'; 
     17        foreach ($r->getItems() as $item) { 
     18            list($title, $desc, $link, $author) = $item; 
     19            echo '<item> 
     20<title>' . h($title) . '</title> 
     21<description>' . $this->toCdata($desc) . '</description> 
     22<link>' . h($link) . '</link> 
     23<author>' . h($author) . '</author> 
     24</item> 
     25'; 
     26        } 
     27         
     28        echo '</channel> 
     29</rss> 
     30'; 
     31    } 
     32    protected function toCdata($v) 
     33    { 
     34        $v = str_replace(']]>', ']]>]]<![CDATA[>', $v); 
     35        return '<![CDATA[' . $v . ']]>'; 
     36    } 
     37}