<?php
/*
	[UCenter Home] (C) 2007-2008 Comsenz Inc.
	$Id: site_desktop_show_empty.php 10953 2009-01-12 02:55:37Z liguode $
*/

if(!defined('IN_UCHOME')) {
	exit('Access Denied');
}
@include_once(S_ROOT.'./data/site_config.php');
$list = $bar = $desktop = $rsslist = array();
$cdtat_start = '****----****';
$cdtat_end = '####----####';
$arrow = '$';
$desktopId = 0;
if ( !empty($_SGLOBAL['supe_uid']) )
{
	if ( isset( $_POST['container'] ) )
	{
		$container = $_POST['container'];
		$str = explode("_", $_POST['container']);
		if ( $_POST['url'] != '' )
		{
			$rss = readFeedUrl($_POST['url']);
			$i = 1;
			if ( isset( $rss->data[items] ) && count( $rss->data[items] ) > 0 )
			{
				foreach( $rss->data[items] as $key => $val )
				{
					if ( $i <= 10 )
					{
						$rsslist[$key]['title'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$val->title));
						$tmp = strip_tags($val->description);
						$tmp = str_replace('&quot;','',str_replace('&ldquo;','',str_replace('&nbsp;','',str_replace('"','',str_replace('&rdquo;','',str_replace('&apos;','',str_replace('&gt;','',str_replace('&lt;','',str_replace('&amp;','',str_replace('"','',str_replace('\r','',$tmp)))))))))));
						$rsslist[$key]['description'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$tmp));
						$rsslist[$key]['date'] = $val->date;
						$rsslist[$key]['links'] = urlencode($val->links[0]);	
					}
					else
					{
						break;
					}
					$i++;
				}
			}
		}
		elseif( $_POST['icon_id'] != '' )
		{
			$tmp_id = str_replace('c','',$_POST['icon_id']);
			$id = intval($tmp_id);
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site')." WHERE id=".$id);
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$list[] = $value;
			}
			if ( $list[0]['type'] == 'feeds' )
			{
				$rss = readFeedUrl($list[0]['url']);
				$i = 1;
				if ( isset( $rss->data[items] ) && count( $rss->data[items] ) > 0 )
				{
					foreach( $rss->data[items] as $key => $val )
					{
						if ( $i <= 10 )
						{
							$rsslist[$key]['title'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$val->title));
							$tmp = strip_tags($val->description);
							$tmp = str_replace('&quot;','',str_replace('&ldquo;','',str_replace('&nbsp;','',str_replace('"','',str_replace('&rdquo;','',str_replace('&apos;','',str_replace('&gt;','',str_replace('&lt;','',str_replace('&amp;','',str_replace('"','',str_replace('\r','',$tmp)))))))))));
							$rsslist[$key]['description'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$tmp));
							$rsslist[$key]['date'] = $val->date;
							$rsslist[$key]['links'] = urlencode($val->links[0]);	
						}
						else
						{
							break;
						}
						$i++;
					}
				}
			}
		}
	}
}
else
{
	if ( isset( $_POST['container'] ) )
	{
		$container = $_POST['container'];
		$str = explode("_", $_POST['container']);
		if ( $_POST['url'] != '' )
		{
			$rss = readFeedUrl($_POST['url']);
			$i = 1;
			if ( isset( $rss->data[items] ) && count( $rss->data[items] ) > 0 )
			{
				foreach( $rss->data[items] as $key => $val )
				{
					if ( $i <= 10 )
					{
						$rsslist[$key]['title'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$val->title));
						$tmp = strip_tags($val->description);
						$tmp = str_replace('&quot;','',str_replace('&ldquo;','',str_replace('&nbsp;','',str_replace('"','',str_replace('&rdquo;','',str_replace('&apos;','',str_replace('&gt;','',str_replace('&lt;','',str_replace('&amp;','',str_replace('"','',str_replace('\r','',$tmp)))))))))));
						$rsslist[$key]['description'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$tmp));
						$rsslist[$key]['date'] = $val->date;
						$rsslist[$key]['links'] = urlencode($val->links[0]);	
					}
					else
					{
						break;
					}
					$i++;
				}
			}
		}
		elseif( $_POST['icon_id'] != '' )
		{
			$tmp_id = str_replace('c','',$_POST['icon_id']);
			$id = intval($tmp_id);
			$query = $_SGLOBAL['db']->query("SELECT * FROM ".tname('site')." WHERE id=".$id);
			while ($value = $_SGLOBAL['db']->fetch_array($query)) {
				$list[] = $value;
			}
			if ( $list[0]['type'] == 'feeds' )
			{
				$rss = readFeedUrl($list[0]['url']);
				$i = 1;
				if ( isset( $rss->data[items] ) && count( $rss->data[items] ) > 0 )
				{
					foreach( $rss->data[items] as $key => $val )
					{
						if ( $i <= 10 )
						{
							$rsslist[$key]['title'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$val->title));
							$tmp = strip_tags($val->description);
							$tmp = str_replace('&quot;','',str_replace('&ldquo;','',str_replace('&nbsp;','',str_replace('"','',str_replace('&rdquo;','',str_replace('&apos;','',str_replace('&gt;','',str_replace('&lt;','',str_replace('&amp;','',str_replace('"','',str_replace('\r','',$tmp)))))))))));
							$rsslist[$key]['description'] = str_replace('&','',preg_replace("/(&)(.*)(;)/",'',$tmp));
							$rsslist[$key]['date'] = $val->date;
							$rsslist[$key]['links'] = urlencode($val->links[0]);	
						}
						else
						{
							break;
						}
						$i++;
					}
				}
			}
		}
	}
}
function readFeedUrl($url)
{
	include_once('simplepie.inc.php');
	$feed = new SimplePie();
	$cacheloc = 'simplepie_cache';

	if(!is_dir($cacheloc)) mkdir($cacheloc);
	$feed->enable_caching(false);
	$feed->bypass_image_hotlink('');
	$feed->feed_url($url);
	$feed->init();
	if(!$feed->data){
		$e = new RssBOException('Invalid feed source '.$url);
		throw $e;
	}
	
	if(!$feed->get_feed_title()){
		$msg = 'title=' . $feed->get_feed_title() . '; description=' . $feed->get_feed_description() . '; items.length=' . $feed->get_item_quantity();
		$e = new RssBOException('Invalid structure from feed source '.$url . "; Detail: " . $msg);
		throw $e;
	}

	return $feed;
}
?>