' . $item['feeddate'] . '
';
}
// Determine if any extra data should be shown:
$extraData = '';
if (strlen($this->args['additional_fields'])){
// Magpie converts all key names to lowercase so we do too:
$this->args['additional_fields'] = strtolower($this->args['additional_fields']);
// Get each additional field:
$addFields = explode('~', $this->args['additional_fields']);
foreach ($addFields as $addField)
{
// Determine if the field was a nested field:
$fieldDef = explode('.', $addField);
$thisNode = $item;
foreach($fieldDef as $fieldName)
{
// Check to see if the fieldName has a COLON in it, if so then we are referencing an array:
$thisField = explode(':', $fieldName);
$fieldName = $thisField[0];
$thisNode = $thisNode[$fieldName];
if (count($thisField) == 2)
{
$fieldName = $thisField[1];
$thisNode = $thisNode[$fieldName];
}
}
if (is_string($thisNode) && isset($thisNode))
{
$extraData .= '';
}
}
}
if($this->args['show_description_only']){
$this->output .= $this->args['before'].$thisLink.$thisItemDate.$extraData;
} else if ($this->args['show_description']){
$this->output .= $this->args['before'].$thisLink.$thisItemDate.$thisDescription.$extraData;
}else{
$this->output .= $this->args['before'].$thisLink.$thisItemDate.$extraData;
}
if (is_numeric($this->args['max_characters']) && $this->args['max_characters'] > 0) {
$this->output .= '
';
}
$this->output .= $this->args['after'];
}
return $this->output;
}
function ArrayPush(&$arr) {
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $key => $value) {
$arr[$key] = $value;
$ret++;
}
}else{
$arr[$arg] = "";
}
}
return $ret;
}
/* utility functions */
function NormalizeDates(){
$newItems = array();
foreach($this->items as $item){
$this->ArrayPush($item,array("feeddate"=>$this->NormalizeDate($item)));
array_push($newItems,$item);
}
return $newItems;
}
function NormalizeDate($item){
$d="";
if(array_key_exists('pubdate',$item)) {
$d = date($this->dateFormat,strtotime($item['pubdate']));
} else if (array_key_exists('published',$item)) {
$d = date($this->dateFormat,strtotime($item['published']));
} else if (array_key_exists('dc',$item) && array_key_exists('date',$item['dc'])) {
$d = date($this->dateFormat,strtotime($item['dc']['date']));
} else if (array_key_exists('last_modified',$item)) {
$d = $this->TimezoneConvert($item['last_modified'],0,Date('I'));
} else {
$d = date($this->dateFormat);
}
return $d;
}
function TimezoneConvert($datetime,$tz_from,$tz_to,$format='d M Y h:ia T'){
return date($format,strtotime($datetime)+(3600*($tz_to - $tz_from)));
}
function MakeNumericOnly($val){
return ereg_replace( '[^0-9]+', '', $val);
}
function GetMonthNum($month){
$months = array('jan'=>'01','feb'=>'02','mar'=>'03','apr'=>'04','may'=>'05','jun'=>'06','jul'=>'07','aug'=>'08','sep'=>'09','oct'=>'10','nov'=>'11','dec'=>'12');
$month = strtolower($month);
return $months[$month];
}
function SortItems(){
$sort = strtolower($this->args['sort']);
$sort = explode(" ",$sort);
if((count($sort) ==1 || $sort[0] == 'asc') && $sort[0] != 'none'){
$sort[1] = SORT_ASC;
} elseif ($sort[1] == 'desc') {
$sort[1] = SORT_DESC;
} else {
$sort[1] = '';
}
if($sort[0] == 'feeddate'){
$sort[2] = SORT_NUMERIC;
} else {
$sort[2] = SORT_STRING;
}
if (($sort[1]!='') && count($this->items))
{
// Order by sortCol:
foreach($this->items as $item)
{
$sortBy[] = $item[$sort[0]];
}
// Make titles lowercase (otherwise capitals will come before lowercase):
$sortByLower = array_map('strtolower', $sortBy);
array_multisort($sortByLower, $sort[1], $sort[2], $this->items);
}
return $this->items;
}
function LoadFile($file){
/*
load the $feedListFile contents into an array, using the --NEXT-- text as
a delimeter between feeds and a tilde (~) between URL and TITLE
*/
$x = file($file);
return preg_split("/--NEXT--/", join('', file($file)));
}
function GetArgumentArray(){
$this->args = $this->AssignDefaults();
$a = array();
foreach($this->args as $d=>$v){
if($this->args[$d] === 'true') {
$a[$d] = 1;
}else if($this->args[$d] === 'false'){
$a[$d] = 0;
}else{
$a[$d] = $v;
}
$a[$d] = html_entity_decode($a[$d]);
}
return $a;
}
function AssignDefaults(){
$defaults = $this->GetDefaults();
$a = array();
$i=0;
foreach ($defaults as $d => $v)
{
$a[$d] = isset($this->args[$d]) ? $this->args[$d] : $v;
$a[$d] = isset($this->args[$i]) ? $this->args[$i] : $a[$d];
$i++;
}
return $a;
}
function GetFeed($feedUrl){
$this->feed = false;
if(function_exists('fetch_rss')){
$this->feed = fetch_rss($feedUrl);
}
return $this->feed;
}
function InitializeReader($ignore_cache){
$settings = $this->GetSettings();
if ($ignore_cache)
{
if (is_numeric($ignore_cache))
{
define('MAGPIE_CACHE_AGE', $ignore_cache);
}
else
{
define('MAGPIE_CACHE_ON', false);
}
}
else
{
define('MAGPIE_CACHE_AGE', $settings["cacheTimeout"]);
}
define('MAGPIE_DEBUG', false);
define('MAGPIE_FETCH_TIME_OUT', $settings["connectionTimeout"]);
}
function Debug($val,$name=''){
if(strlen($name)){
print('
'.$name.'
');
}
print('
');
print_r($val);
print('');
}
/* end utility functions */
}
function rssLinkListFilter($text)
{
return preg_replace_callback("//", "feedListFilter", $text);
}
/* Templates can call any of these functions */
function rssLinkList($args){
if(!is_array($args)){
$args = func_get_args();
}
return feedList($args);
}
function feedList($args){
if(!is_array($args)){
$args = func_get_args();
}
$feed = new FeedList($args);
return $feed->FeedListFeed();
}
function randomFeedList($args){
if(!is_array($args)){
$this->args = parse_str($args,$a);
$this->args = $a;
}
$feed = new FeedList($args);
return $feed->FeedListFile();
}
function feedListFilter($args){
$args = explode(",",$args[1]);
if(count($args) == 1 && !strpos($args[0],":=")){
$a = array();
$a["rss_feed_url"] = $args[0];
$args = $a;
} else {
$a = array();
foreach($args as $arg){
$arg = explode(":=",$arg);
$a[$arg[0]] = $arg[1];
}
$args = $a;
}
$feed = new FeedList($args);
return $feed->FeedListFilter();
}
/* end template functions */
if (function_exists('add_filter'))
{
add_filter('the_content', 'rssLinkListFilter');
}
if(function_exists('FeedListInitError')){
add_action('admin_head','FeedListInitError');
}
if(function_exists('add_action')) {
function rssLinkList_JS(){
$jsstring = '
';
echo $jsstring;
}
$jsFeed = new FeedList('');
$settings = $jsFeed->GetSettings();
if($settings["showRSSLinkListJS"]){
add_action('wp_head', 'rssLinkList_JS');
}
}
?>
WordPress
http://wordpress.org/
http://blog.desperatequilters.com