summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwjames5 <will@tekimaki.com>2007-08-01 12:00:56 +0000
committerwjames5 <will@tekimaki.com>2007-08-01 12:00:56 +0000
commit85a02d9bb7c2e1cc5c5c88ab39eaa1e14534de1b (patch)
treec4a58e93d83e5efae62f881c16130abb80a2f78a
parenteb50f2632705b9048957f006a011aaf0c301260c (diff)
downloadrss-85a02d9bb7c2e1cc5c5c88ab39eaa1e14534de1b.tar.gz
rss-85a02d9bb7c2e1cc5c5c88ab39eaa1e14534de1b.tar.bz2
rss-85a02d9bb7c2e1cc5c5c88ab39eaa1e14534de1b.zip
move common processes into class
-rw-r--r--modules/mod_rss_feed.php36
-rw-r--r--rss_lib.php82
2 files changed, 114 insertions, 4 deletions
diff --git a/modules/mod_rss_feed.php b/modules/mod_rss_feed.php
index 66c6a82..879cd45 100644
--- a/modules/mod_rss_feed.php
+++ b/modules/mod_rss_feed.php
@@ -10,6 +10,38 @@
global $rsslib;
require_once( RSS_PKG_PATH.'rss_lib.php' );
+extract( $moduleParams );
+
+$listHash = Array();
+$listHash['id'] = $module_params['id'];
+$listHash['cache_time'] = !empty($cache_time)?$cache_time:1;
+
+if ( $items = $rsslib->parse_feeds( $listHash ) ){
+ $gBitSmarty->assign( 'modRSSItems', $items );
+
+ //if we want short descriptions get them
+ $shortdescs = Array();
+ if ( !empty($module_params['desc_length']) && is_numeric($module_params['desc_length']) && !empty($items)){
+ $shortdescs = $rsslib->get_short_descs( $items, $module_params['desc_length'] );
+ }
+
+ $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 );
+}
+
+
+
+/*
//load up SimplePie
require_once( UTIL_PKG_PATH.'simplepie/simplepie.inc' );
@@ -41,10 +73,9 @@ if( !is_dir( $cache_path ) && !mkdir_p( $cache_path ) ) {
}
}
- //$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
+ //Instead of only passing in one feed url, we'll pass in an array of multiple feeds
$feed->set_feed_url( $urls );
$feed->set_cache_location( $cache_path );
@@ -97,4 +128,5 @@ if( !is_dir( $cache_path ) && !mkdir_p( $cache_path ) ) {
$max = !empty( $module_params['max'] ) ? $module_params['max'] : 99;
$gBitSmarty->assign( 'max', $max );
}
+*/
?>
diff --git a/rss_lib.php b/rss_lib.php
index e7bc6c6..d4bd6d2 100644
--- a/rss_lib.php
+++ b/rss_lib.php
@@ -1,6 +1,6 @@
<?php
/**
- * @version $Header: /cvsroot/bitweaver/_bit_rss/rss_lib.php,v 1.15 2007/07/31 22:37:03 wjames5 Exp $
+ * @version $Header: /cvsroot/bitweaver/_bit_rss/rss_lib.php,v 1.16 2007/08/01 12:00:55 wjames5 Exp $
* @package rss
*
* Copyright (c) 2004 bitweaver.org
@@ -9,7 +9,7 @@
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: rss_lib.php,v 1.15 2007/07/31 22:37:03 wjames5 Exp $
+ * $Id: rss_lib.php,v 1.16 2007/08/01 12:00:55 wjames5 Exp $
*/
/**
@@ -342,6 +342,84 @@ class RSSLib extends BitBase {
return $matches[2];
}
+ function get_short_descs( $items, $length=1 ){
+ $shortdescs = Array();
+
+ if ( !empty($items) ){
+ foreach ($items as $item){
+ //we try to trim each story to given number of sentences
+ $sentences = $this->get_short_desc( $item->get_description() );
+
+ $shortdesc = NULL;
+ for ($n = 0; $n < $length; $n++){
+ $space = ($n > 0)?" ":NULL;
+ $shortdesc .= $space;
+ $shortdesc .= ( !empty( $sentences[$n] ) && $sentences[$n] != NULL ) ? $sentences[$n] : NULL;
+ }
+
+ $shortdescs[] = $shortdesc;
+ }
+ }
+
+ return $shortdescs;
+ }
+
+ function parse_feeds( $pParamHash ){
+ //set path to rss feed cache
+ $cache_path = TEMP_PKG_PATH.'rss/simplepie';
+
+ //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 );
+
+ return FALSE;
+ }else{
+ //load up parser SimplePie
+ require_once( UTIL_PKG_PATH.'simplepie/simplepie.inc' );
+
+ if (!is_array($pParamHash['id'])){
+ $ids = explode( ",", $pParamHash['id'] );
+ }else{
+ $ids = $pParamHash['id'];
+ }
+
+ $urls = Array();
+
+ foreach ($ids as $id){
+ if( @BitBase::verifyId( $id ) ) {
+ $feedHash = $this->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();
+
+ //Instead of only passing in one feed url, we'll pass in an array of multiple feeds
+ $feed->set_feed_url( $urls );
+
+ $feed->set_cache_location( $cache_path );
+
+ //set cache time
+ $cache_time = !empty($pParamHash['cache_time'])?$pParamHash['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();
+
+ return $items;
+ }
+ }
}
global $rsslib;