diff options
| author | wjames5 <will@tekimaki.com> | 2007-07-31 22:37:03 +0000 |
|---|---|---|
| committer | wjames5 <will@tekimaki.com> | 2007-07-31 22:37:03 +0000 |
| commit | eb50f2632705b9048957f006a011aaf0c301260c (patch) | |
| tree | 71f17ddaaee136057eea8161ed9a4df788c47239 /modules | |
| parent | 776237bd0dc785b261de0b5fe5625c26769ae38f (diff) | |
| download | rss-eb50f2632705b9048957f006a011aaf0c301260c.tar.gz rss-eb50f2632705b9048957f006a011aaf0c301260c.tar.bz2 rss-eb50f2632705b9048957f006a011aaf0c301260c.zip | |
Migrate to SimplePie for parsing feeds - add support for multifeeds in modules and for first sentences descriptions - keep an eye on sites when using short desc - class still needs clean up and rss plugin needs to be addapted to SimplePie
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/mod_rss_feed.php | 92 | ||||
| -rw-r--r-- | modules/mod_rss_feed.tpl | 29 |
2 files changed, 103 insertions, 18 deletions
diff --git a/modules/mod_rss_feed.php b/modules/mod_rss_feed.php index d154c9f..66c6a82 100644 --- a/modules/mod_rss_feed.php +++ b/modules/mod_rss_feed.php @@ -10,21 +10,91 @@ global $rsslib; require_once( RSS_PKG_PATH.'rss_lib.php' ); -// moduleParams contains lots of goodies: extract for easier handling -extract( $moduleParams ); +//load up SimplePie +require_once( UTIL_PKG_PATH.'simplepie/simplepie.inc' ); -if( @BitBase::verifyId( $module_params['id'] ) ) { - $max = !empty( $module_params['max'] ) ? $module_params['max'] : 99; +//set path to rss feed cache +$cache_path = TEMP_PKG_PATH.'rss/simplepie'; - $rssdata = $rsslib->get_rss_module_content( $module_params['id'] ); - $items = $rsslib->parse_rss_data( $rssdata, $module_params['id'] ); +//we do this earlier instead of later because if we can't cache the source we shouldn't be pulling the rss feed. +if( !is_dir( $cache_path ) && !mkdir_p( $cache_path ) ) { + bit_log_error( 'Can not create the cache directory: '.$cache_path ); +}else{ + // moduleParams contains lots of goodies: extract for easier handling + extract( $moduleParams ); + + if (!is_array($module_params['id'])){ + $ids = explode( ",", $module_params['id'] ); + }else{ + $ids = $module_params['id']; + } + + $urls = Array(); + + foreach ($ids as $id){ + if( @BitBase::verifyId( $id ) ) { + $feedHash = $rsslib->get_rss_module( $id ); + $urls[] = $feedHash['url']; + }else{ + //todo assign this as an error + //$repl = '<b>rss can not be found, id must be a number</b>'; + } + } + + //$feed = new SimplePie( $urls, $cache_path, 1 ); + $feed = new SimplePie(); + + //Instead of only passing in one feed url, we'll pass in an array of three + $feed->set_feed_url( $urls ); + + $feed->set_cache_location( $cache_path ); + + //modules may not be cached so for now we relay the cache time to simplepie + $cache_time = !empty($cache_time)?$cache_time:1; + $feed->set_cache_duration( $cache_time ); + + //not sure - we may want to eventually use this + //$feed->set_stupidly_fast(TRUE); + + // Initialize the feed object + $feed->init(); + + // This will work if all of the feeds accept the same settings. + $feed->handle_content_type(); + $items = $feed->get_items(); + $gBitSmarty->assign( 'modRSSItems', $items ); - if (!empty($module_params['desc']) && $module_params['desc'] == 'n'){ - $gBitSmarty->assign( 'hideDesc', TRUE ); + + $shortdescs = Array(); + + if ( !empty($module_params['desc_length']) && is_numeric($module_params['desc_length']) && !empty($items)){ + foreach ($items as $item){ + //we try to trim each story to given number of sentences + $sentences = $rsslib->get_short_desc( $item->get_description() ); + + $shortdesc = NULL; + for ($n = 0; $n < $module_params['desc_length']; $n++){ + $space = ($n > 0)?" ":NULL; + $shortdesc .= $space; + $shortdesc .= ( !empty( $sentences[$n] ) && $sentences[$n] != NULL ) ? $sentences[$n] : NULL; + } + + $shortdescs[] = $shortdesc; + } } -}else{ - //todo assign this as an error - //$repl = '<b>rss can not be found, id must be a number</b>'; + + $gBitSmarty->assign( 'short_desc', $shortdescs ); + + //if desc is set and no desc_length is given then we present the full description/content of each item + $hideDesc = TRUE; + if (!empty($module_params['desc']) && $module_params['desc'] == 'y' && empty($module_params['desc_length']) ){ + $hideDesc = FALSE; + } + + $gBitSmarty->assign( 'hideDesc', $hideDesc ); + + $max = !empty( $module_params['max'] ) ? $module_params['max'] : 99; + $gBitSmarty->assign( 'max', $max ); } ?> diff --git a/modules/mod_rss_feed.tpl b/modules/mod_rss_feed.tpl index 9d67cfd..43e157b 100644 --- a/modules/mod_rss_feed.tpl +++ b/modules/mod_rss_feed.tpl @@ -2,14 +2,24 @@ {if $gBitSystem->isPackageActive('rss')} {bitmodule title="$moduleTitle" name="rss_feed"} <ul class="rss"> - {section name=ix loop=$modRSSItems} + {section name=ix loop=$modRSSItems max=$max} <li class="{cycle values="odd,even"}"> - <div class="title"><a href="{$modRSSItems[ix].link}">{$modRSSItems[ix].title}</a></div> - <div class="date">{$modRSSItems[ix].pubdate} + <div class="title"><a href="{$modRSSItems[ix]->get_permalink()}">{$modRSSItems[ix]->get_title()}</a></div> + <div class="date">{$modRSSItems[ix]->get_date('j M Y | g:i a T')} <br /> - {if $modRSSItems[ix].author}by {$modRSSItems[ix].author}{/if}</div> - {if !$hideDesc}{$modRSSItems[ix].description} {/if} - <a class="more" href="{$modRSSItems[ix].link|escape:"url"}">Read more</a> + {if $modRSSItems[ix]->get_author()} + {assign var='author' value=$modRSSItems[ix]->get_author()} + {if $author->get_name()} + by {$author->get_name()} + {elseif $author->get_email()} + by {$author->get_email()} + {/if} + {/if} + {assign var='source' value=$modRSSItems[ix]->get_feed()} at <a href="{$source->get_link()}">{$source->get_title()}</a> + </div> + {if !$hideDesc}{$modRSSItems[ix]->get_description()} {/if} + {if $short_desc[ix]}{$short_desc[ix]} {/if} + <a class="more" href="{$modRSSItems[ix]->get_link()}">{biticon iname=go-next iexplain="Read More"}</a> </li> {sectionelse} <li></li> @@ -17,4 +27,9 @@ </ul> {/bitmodule} {/if} -{/strip}
\ No newline at end of file +{/strip} + +{* +$story = $item->get_feed(); +print_r( "<a href='" . $item->get_permalink() . "'>" . $item->get_title() . "</a>" . " | " . $item->get_date('j M Y | g:i a T') . " | Source: " . $story->get_title() ); +*}
\ No newline at end of file |
