Changeset 20336

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

レスポンス周り追加

Location:
events/phpframework/plain_php/trunk/core
Files:
1 added
4 modified

Legend:

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

    r20040 r20336  
    1313        $this->context = $c; 
    1414        $this->baseUrl = $c->baseUrl; 
    15         if (in_array($req->REQUEST_METHOD, array('POST', 'GET')))  
    16             return $this->{$req->REQUEST_METHOD}(); 
     15        if (in_array($req->REQUEST_METHOD, array('POST', 'GET'))) { 
     16            $_ = $this->{'before' . $req->REQUEST_METHOD}()  
     17                or $_ = $this->{$req->REQUEST_METHOD}(); 
     18            $this->{'after' . $req->REQUEST_METHOD}(); 
     19            return $_; 
     20        } 
    1721        throw new Exception; 
    1822    } 
     23    function beforePOST() { } 
     24    function beforeGET() { } 
     25     
     26    function afterGET() { } 
     27    function afterPOST() { }  
     28     
    1929    function POST() 
    2030    { 
     
    4555    protected function hasExternalReferer() 
    4656    { 
    47         return  
    48             strpos($this->req->HTTP_REFERER, $this->baseUrl . '/') !== 0 || 
    49             $this->req->HTTP_REFERER === $this->baseUrl; 
     57        if ($this->req->HTTP_REFERER === $this->baseUrl) return false; 
     58        return strpos($this->req->HTTP_REFERER, $this->baseUrl . '/') !== 0; 
    5059    } 
    5160     
  • events/phpframework/plain_php/trunk/core/ObjectBuilder.php

    r20040 r20336  
    4040    function buildTimelineService() 
    4141    { 
    42         return new TimelineService($this->pool->fetchPDO(), $this->pool->fetchApplicationContext()); 
     42        return new TimelineService($this->pool->fetchPDO(), self::$context->baseUrl); 
    4343    } 
    4444     
     
    5353        $o->page_limit = 15; 
    5454        $o->cookie_timeout = 60 * 60 * 7; 
     55        $o->encoding = 'UTF-8'; 
     56        $o->mail_from = 'Phwittr'; 
     57         
    5558        return $o; 
    5659    } 
     
    5861    function buildStatusService() 
    5962    { 
    60         return new StatusService($this->pool->fetchPDO()); 
     63        return new StatusService($this->pool->fetchPDO(), self::$context->baseUrl); 
    6164    } 
    6265     
  • 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} 
  • events/phpframework/plain_php/trunk/core/RssResponse.php

    r20040 r20336  
    11<?php 
    22 
     3class RssResponse implements IResponse 
     4{ 
     5    protected $channel, $items = array(); 
     6    function buildRenderer(RendererBuilder $b) 
     7    { 
     8        return $b->buildRssRenderer(); 
     9    } 
     10    function setChannel($title, $url, $desc) 
     11    { 
     12        $this->channel = func_get_args(); 
     13    } 
     14    function setDescription($d) 
     15    { 
     16        $this->desc = $d; 
     17    } 
     18    function addItem($title, $desc, $link, $author) 
     19    { 
     20        $this->items[] = func_get_args(); 
     21    } 
     22    function getChannel() 
     23    { 
     24        return $this->channel; 
     25    } 
     26    function getItems() 
     27    { 
     28        return $this->items; 
     29    } 
     30}