2009年8月14日金曜日

spark43オフィシャルサイトのRSS

文字化けしてました。。。

恐らく環境の問題な気もしますが、
ソース修正で乗り切ることにしました。(汗


XOOPS_ROOT_PATH/modules/legacy/actions/BackendAction.class.php
を書き換えました。


/**
*
* @package Legacy
* @version $Id: BackendAction.class.php,v 1.4 2008/09/25 14:31:58 kilica Exp $
* @copyright Copyright 2005-2007 XOOPS Cube Project
* @license http://xoopscube.sourceforge.net/license/GPL_V2.txt GNU GENERAL PUBLIC LICENSE Version 2
*
*/

if (!defined('XOOPS_ROOT_PATH')) exit();

/***
* @internal
*/
class Legacy_BackendAction extends Legacy_Action
{
    var $mItems = array();
    
    /**
     * The spec of getRSS():
     * append your RSS item to $eventArgs array. You don't need to sanitize your values. Use raw value.
     *
     * $item['title']
     * $item['link'] ... permanent link
     * $item['guid'] ... permanent link
     * $item['pubdate'] ... unixtime
     * $item['description'] ... not required.
     * $item['category'] ... not required.
     * $item['author'] ... not required.
     *
     * @var XCube_Delegate
     */
    var $mGetRSSItems = null;
    
    function Legacy_BackendAction($flag)
    {
        parent::Legacy_Action($flag);
        
        $this->mGetRSSItems =& new XCube_Delegate();
        $this->mGetRSSItems->register('Legacy_BackendAction.GetRSSItems');
    }
    
    function getDefaultView(&$controll, &$xoopsUser)
    {
        $items = array();
        $this->mGetRSSItems->call(new XCube_Ref($items));

        $sortArr = array();
        foreach ($items as $item) {
            //shiraga (2009.08.14) ==>
            $item['title'] = mb_convert_encoding($item['title'], "EUC-JP", mb_detect_encoding($item['title']));
            $item['description'] = mb_convert_encoding($item['description'], "EUC-JP", mb_detect_encoding($item['description']));
            //shiraga (2009.08.14) <==
            
            $i = intval($item['pubdate']);
            for (; isset($sortArr[$i]) ; $i++);
            
            $sortArr[$i] = $item;
        }
        krsort($sortArr);
     $this->mItems = $sortArr;
        return LEGACY_FRAME_VIEW_INDEX;
    }
    
    function executeViewIndex(&$controller, &$xoopsUser, &$render)
    {
        $xoopsConfig = $controller->mRoot->mContext->mXoopsConfig;
        
        //
        // Set up the render buffer.
        //
        $renderSystem =& $controller->mRoot->getRenderSystem('Legacy_RenderSystem');
        
        $renderTarget =& $renderSystem->createRenderTarget('main');

        $renderTarget->setTemplateName("legacy_rss.html");
        
        $renderTarget->setAttribute('channel_title', $xoopsConfig['sitename']);
        $renderTarget->setAttribute('channel_link', XOOPS_URL . '/');
        $renderTarget->setAttribute('channel_desc', $xoopsConfig['slogan']);
        $renderTarget->setAttribute('channel_lastbuild', formatTimestamp(time(), 'rss'));
        $renderTarget->setAttribute('channel_webmaster', $xoopsConfig['adminmail']);
        $renderTarget->setAttribute('channel_editor', $xoopsConfig['adminmail']);
        $renderTarget->setAttribute('channel_category', 'News');
        $renderTarget->setAttribute('channel_generator', 'XOOPS Cube');
        $renderTarget->setAttribute('image_url', XOOPS_URL . '/images/logo.gif');
        
        $dimention = getimagesize(XOOPS_ROOT_PATH . '/images/logo.gif');

        $width = 0;        
        if (empty($dimention[0])) {
            $width = 88;
        }
        else {
            $width = ($dimention[0] > 144) ? 144 : $dimention[0];
        }
        
        $height = 0;
        if (empty($dimention[1])) {
            $height = 31;
        } else {
            $height = ($dimention[1] > 400) ? 400 : $dimention[1];
        }
        
        $renderTarget->setAttribute('image_width', $width);
        $renderTarget->setAttribute('image_height', $height);
        $renderTarget->setAttribute('items', $this->mItems);

        //
        // Rendering
        //
        $renderSystem->render($renderTarget);
        
//shiraga (2009.08.14) ==>
//        if (function_exists('mb_http_output')) {
//            mb_http_output('pass');
//        }
//shiraga (2009.08.14) <==
        header ('Content-Type:text/xml; charset=utf-8');
        
//shiraga (2009.08.14) ==>
//        print xoops_utf8_encode($renderTarget->getResult());
        print mb_convert_encoding($renderTarget->getResult(), "UTF-8", "EUC-JP");
//shiraga (2009.08.14) <==
        
        exit(0);
    }
}

0 件のコメント:

コメントを投稿

どうかお気軽にコメント頂ければ幸いです。