Re: Custom RSS Feed

Brandon Knitter <[email protected]> Sat, 15 Jan 2005 20:48:54 -0800
Newsgroups gmane.comp.horde.jonah
Message-ID <[email protected]>
This message is in MIME format.

--=_3whyuei539z4
Content-Type: text/plain;
	charset=UTF-8;
	format="flowed"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Okay, attached is the same viewrss.php converted to using the Jonah 
parser.  You
can just drop the attached file into <horde>/jonah/lib/Block/custom.php 
and you
should see it working.

One thing that I would /really/ prefer to do is use Jonah's
News->renderChannel(...) function as it does all the pretty layout.  But since
this requires a channel_id, it doesn't work for my example.

Do you think it would make sense to change the way a set of stories is redered
in renderChannel so that either a url or a channel_id (or a channel object
itself, for that matter) could be passed instead?  I'm thinking this would be
more portable in the future.  In the case of a channel object, perhaps in the
"custom RSS feed" way, a channel object could be made on the fly.  That would
be a decent/cheap way to get abstraction.

That said, since this is my first endeavor into Jonah, I may not fully
understand the intended direction of things.  Also, I'm an ops geek, not a
software engineer extraordinaire, so be kind! :)

Feedback appreciated!

Cheers,

-- 
-bk


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


--=_3whyuei539z4
Content-Type: application/x-php;
	name="custom.php"
Content-Disposition: attachment;
	filename="custom.php"
Content-Transfer-Encoding: 7bit

<?php

$block_name = _("Custom Content Channel");

class Horde_Block_Jonah_custom extends Horde_Block {

    var $_app = 'horde';
    
    function _params()
    {
           return array('rssurl' => array('type' => 'text',
                                       'name' => _("URL"),
                                       'default' => ''),
                         'title'  => array('type' => 'text',
                                      'name' => _("Title")),
			'maxarticles' => array('type' => 'int',
				'name' => _("Max Articles"),
				'default' => 10)
			);
    }

    /**
     * The title to go in this block.
     *
     * @return string   The title text.
     */
    function _title()
    {

    	if ($this->_params['title'] != '') {
		return $this->_params['title'];
	} else {
        	return _("View RSS");
	}
	
    }

    /**
     * The content to go in this block.
     *
     * @return string   The content
     */
    function _content()
    {
	require JONAH_BASE . '/lib/RSSParse.php';

	$html='';
        
	//TODO: I think we are supposed to store our cached data 
	// here, but need to verify that first. The weatherdotcom 
	// block should have caching usage.
	$cacheDir = Horde::getTempDir();
        
	if ($this->_params['rssurl'] != '') {
		$rss=Jonah::_readURL($this->_params['rssurl']);
		$rssparse = &new Jonah_RSSParse();
		if (!$rssparse->parse($rss)) {
			$GLOBALS['notification']->push(sprintf(_("Error parsing external channel from %s: %s"), $url, $rssparse->error), 'warning');
		}
		$stories = $rssparse->structure;
		$rssparse->cleanup();

		$html.='<table width="100%" class="item">';
		$max=10;
		if (array_key_exists('maxarticles', $this->_params)) {
			$max=$this->_params['maxarticles'];
		}
		foreach($stories['items'] as $key => $story) {
	 		$html .= '<tr class="text"><td><span title="'.htmlspecialchars($story['description']).'"><a href="' . $story['story_url'] . '"' . 
				' target="_blank">'.
				htmlspecialchars($story['title']) . '</a></span></td></tr>';
			if (--$max<=0) {
				break;
			}
		}
		$html.='</table>';
	
	} else {
		$html = "No rss url found";
	}


        return $html;
    }

}

--=_3whyuei539z4
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-- 
Jonah mailing list - Join the hunt: http://horde.org/bounties/#jonah
Frequently Asked Questions: http://horde.org/faq/
To unsubscribe, mail: [email protected]

--=_3whyuei539z4--