twitter sns クチコミ comments neta

2007/11/25 14:34:43 | comment(101)

文字数値参照の記事を文字に変換するConveyorプラグイン

twitterが全部エンコードしてくるので、カッとなって作った。
おかしいところがあるかもしれないけど、気にしない。

<?php
Rhaco::import('model.FilterBase');

class FilterDecodeNumericentity extends FilterBase
{
    function execute($rss){
        $filter = array_map('trim', explode("\n", $this->variable('filter')));
        $items = $rss->getItem();

        $rss20_filtered = new Rss20();
        $rss20_filtered->channel = $rss->getChannel();

        foreach($items as $item){
            foreach($filter as $f){
                if(preg_match('/' . preg_quote($f) . '/i', $item->getLink())){
                    $item->setDescription(mb_decode_numericentity($item->getDescription(), array(0, 0xffff, 0, 0xffff), 'utf-8'));
                    $item->setTitle(mb_decode_numericentity($item->getTitle(), array(0, 0xffff, 0, 0xffff), 'utf-8'));
                }
            }
            $rss20_filtered->setItem($item);
        }

        return $rss20_filtered;
    }

    function description(){
        return '数値参照を元に戻す';
    }

    function config(){
        return array('filter' => array('変換対象になるURL', 'textarea', 'twitter.com', true));
    }
}