<?php
/**
* This is the template that displays XML based feeds on your sidebar
*
* This is rev2 - with StayPuft Improvements!
* http://forums.b2evolution.net/viewtopic.php?t=2258
*
* This file is not meant to be called directly.
* It is meant to be called by an include in the _main.php template.
*
* This requires magpieRSS which is not part of the b2evolution distribution
* magpieRSS is released under the GPL License and the author holds copyright
* This application makes absolutely no modifications to the magpieRSS files!
* Download it, unzip it, and upload the files to your /skins/skinname folder
*
* This file is made possible by my complete lack of a life and any responsibilities
* normally associated with a life. This file utilizes code copyrighted by Kellan
* and has no value outside of code copyrighted by Francois, and still I get to say
* @copyright (c) 2004 by Ed Bennett - {@link http://wonderwinds.com}
* Released under the GNU GPL - {@link http://www.gnu.org/copyleft/gpl.html}
* Feel free to tweak/hack/fix/improve or otherwise modify this file as you see fit.
*
* magpieRSS - {@link http://magpierss.sourceforge.net/}
* Released under the GNU General Public License.
* @copyright(c) 2002
kellan@protest.net. All rights reserved.
* Please read the disclaimer at the top of the /extlib/Snoopy.class.inc file.
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evoskins
* @subpackage custom
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
# This section allows you to control some features with true/false and decorate your display
# set this to false if you don't want to show the name of the site your feed comes from
# if this is false then 'header_start' and 'header_end' and 'header_linked' don't get used
$show_site_name = true;
# this is for the name of the site you are getting your feed from
if(!isset($header_start)) $header_start = '<h4>';
if(!isset($header_end)) $header_end = '</h4>';
# set this to false if you don't want the site's title linked to it's url
$header_linked = true;
# this is for the start and end of each block of items from each feed
if(!isset($block_start)) $block_start = '<ul>';
if(!isset($block_end)) $block_end = '</ul>';
# this is for the start and end of each individual item in each feed
if(!isset($item_start)) $item_start = '<li>';
if(!isset($item_end)) $item_end = '</li>';
# this is for the start and end of each item's title
if(!isset($item_title_start)) $item_title_start = '<strong>';
if(!isset($item_title_end)) $item_title_end = '</strong>';
# set this to false if you don't want the each item linked to it's url
$item_title_linked = true;
# set this to false if you don't want to show the author's name for each item
# if this is false then 'author_start' and 'author_end' don't get used
$show_author_name = true;
# this is for before and after the author's name for each item
# if there is no author information then these do not get used
if(!isset($author_start)) $author_start = ' (By: ';
if(!isset($author_end)) $author_end = ')<br />';
# for atom feeds, link to the author's website if they have one?
# note that for rss2 feeds email ids are not linked or displayed.
$link_atom_author = true;
# should really long items be cut short?
$cut_item_desc = true;
# how short should they be cut down to?
$cut_item_desc_to = 374;
# set this to false if you don't want a link to the end of a shortened item
$link_truncated_item = true;
# this is how many items to show if it is not set in _main.php
if(!isset($show_me)) $show_me = 15;
# set this to false if you do not want to fix invalid tags in your feeds
# this will not fix ALL bad stuff in your feeds but it catches some common problems
$fix_bad_tags = true;
$remove_tags = true; // StayPuft improvement
// BEYOND HERE BE DRAGONS!
if ( $rss )
{
if ( $show_site_name )
{ // do this if the site name gets displayed
$site_title = $rss->channel['title'];
$site_url = $rss->channel['link'];
$site_desc = $rss->channel['description'];
if ( isset($rss->channel['tagline']) )
{ // get the atom tagline as the description
$site_desc = $rss->channel['tagline'];
}
$header_string = "";
$header_string .= $header_start;
if ( $header_linked )
{ // do this if the site name gets linked
$header_string .= "<a href=\"".$site_url."\" title=\"".$site_desc."\">".$site_title."</a>";
}
else
{ // do this if the site name is not linked
$header_string .= $site_title;
}
$header_string .= $header_end."\n";
echo $header_string;
}
echo $block_start."\n";
$ii = 1;
foreach ($rss->items as $item )
{ // now start cycling through items
if ( $ii <= $show_me )
{ // do it again if we have not reached the limit
$item_title = $item[title];
$item_url = $item[link];
$item_desc = $item[description];
if ( isset($item[atom_content]) )
{ // get the atom content as the description
$item_desc = $item[atom_content];
}
if ( $show_author_name )
{ // do this if the authors name gets displayed
if ( isset($item[author]) )
{ // is it rss2?
$item_auth = $item[author];
$have_auth = true;
// remove the author's email id if present
$has_email = strpos($item_auth, '@');
if ( $has_email !== false )
{ // we found an email id so remove it and starve a spam-bot
$item_auth = substr($item_auth, 0, strrpos($item_auth, ' '));
}
}
if ( isset($item[dc][creator]) )
{ // is it rdf?
$item_auth = $item[dc][creator];
$have_auth = true;
}
if ( isset($item[author_name]) )
{ // is it atom?
$item_auth = $item[author_name];
$have_auth = true;
// link to the author's website if they have one
if ( isset($item[author_url]) && $link_atom_author )
{ // website present so build a good link
$item_auth_url = $item[author_url];
if( !preg_match('#://#', $item_auth_url) )
{ // add the http part if it's not there
$item_auth_url = 'http://'.$item_auth_url;
}
$item_auth = "<a href=\"$item_auth_url\" title=\"".$item_auth."'s website: $item_auth_url\">".$item_auth."</a>";
}
}
}
if ( $item_title == '' )
{ // if the item is untitled then make one up
$item_title = substr(strip_tags($item_desc), 0, 20).'...';
}
if ( $item_url == '' )
{ // if the item has no link then use the site link
$item_url = $rss->channel['link'];
}
if ( $fix_bad_tags )
{ // clean up some bad xhtml that might be in the feed - keep your page valid!
$item_desc = preg_replace("(<br>)", "<br />", $item_desc);
$item_desc = preg_replace("(.gif>)", ".gif\" alt=\"image\" />", $item_desc);
$item_desc = preg_replace("(.jpg>)", ".jpg\" alt=\"image\" />", $item_desc);
$item_desc = preg_replace("(.png>)", ".png\" alt=\"image\" />", $item_desc);
$item_desc = preg_replace("(src=htt)", "src=\"htt", $item_desc);
}
// START TAG Removal added by StayPuft
if ( $remove_tags ) // added by StayPuft
{ // remove HTML tags
$item_desc = strip_tags($item_desc);
}
// END TAG Removal added by StayPuft
if ( $cut_item_desc )
{ // do this if long descriptions are to be cut down
if ( $remove_tags )
{ // tags have already been removed
$strip_item_desc = $item_desc;
} else { // remove HTML tags
$strip_item_desc = strip_tags($item_desc);
}
$strip_item_desc_len = strlen($strip_item_desc);
if ( $strip_item_desc_len >= $cut_item_desc_to )
{
if ( $link_truncated_item )
{ // do this if cut down items get linked to the article
$continued_text = "<a href=\"".$item_url."\" title=\"read more!\"><em> (read more)</em></a>";
} else { // do this if truncated items do not get linked to the article
$continued_text = "<em> (read more)</em>";
}
$item_desc = substr($strip_item_desc, 0, $cut_item_desc_to).$continued_text;
} else {
$item_desc = $strip_item_desc;
}
}
$item_title_string = "";
$item_title_string .= $item_start.$item_title_start;
if ( $item_title_linked )
{ // do this if the item title gets linked
$item_title_string .= "<a href=\"".$item_url."\" title=\"link to this item\">".$item_title."</a>";
} else { // do this if the item title does not get linked
$item_title_string .= $item_title;
}
$item_title_string .= $item_title_end."\n";
echo $item_title_string;
if ( ( $show_author_name ) && ( $have_auth ) )
{ // do this if we want to show the author and have one to show
echo $author_start.$item_auth.$author_end;
}
echo $item_desc.$item_end;
}
$ii++;
}
echo $block_end."\n";
}
else {
echo "<p>Houston we have a problem</p>";
}
?>