<?PHP


define("MODULE_FILE", true);

include("function/function.php");





define('ROOT_DIR', dirname (__FILE__));


function images_cod($sourse) {


		$bb = array();

		$html = array();

$bb[] = "#\[img\]([^?](?:[^\[]+|\[(?!url))*?)\[/img\]#i";
$html[] = "<img src=\"\\1\" border=\"0\" alt=\"\\1\" title=\"\\1\">";
$bb[] = "#\[img=([a-zA-Z]+)\]([^?](?:[^\[]+|\[(?!url))*?)\[/img\]#is";
$html[] = "<img src=\"\\2\" align=\"\\1\" border=\"0\" alt=\"\\2\" title=\"\\2\">";
$bb[] = "#\[img\ alt=([a-zA-Zà-ÿÀ-ß0-9\_\-\. ]+)\]([^?](?:[^\[]+|\[(?!url))*?)\[/img\]#is";
$html[] = "<img src=\"\\2\" align=\"\\1\" border=\"0\" alt=\"\\1\" title=\"\\1\">";
$bb[] = "#\[img=([a-zA-Z]+) alt=([a-zA-Zà-ÿÀ-ß0-9\_\-\. ]+)\]([^?](?:[^\[]+|\[(?!url))*?)\[/img\]#is";
$html[] = "<img src=\"\\3\" align=\"\\1\" border=\"0\" alt=\"\\2\" title=\"\\2\">";
$bb[] = "#\[url\](ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\[/url\]#is";
$html[] = "eMule/eDonkey: <a href=\"\\1\" target=\"_blank\" title=\"\\2\">\\2</a>";
$bb[] = "#\[url=(ed2k://\|file\|(.*?)\|\d+\|\w+\|(h=\w+\|)?/?)\](.*?)\[/url\]#si";
$html[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\2\">\\4</a>";
$bb[] = "#\[url\](ed2k://\|server\|([\d\.]+?)\|(\d+?)\|/?)\[/url\]#si";
$html[] = "ed2k Server: <a href=\"\\1\" target=\"_blank\" title=\"\\2\">\\2</a> - Port: \\3";
$bb[] = "#\[url=(ed2k://\|server\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
$html[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\2\">\\2</a>";
$bb[] = "#\[url\](ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\[/url\]#si";
$html[] = "Friend: <a href=\"\\1\" target=\"_blank\" title=\"\\2\">\\2</a>";
$bb[] = "#\[url=(ed2k://\|friend\|(.*?)\|[\d\.]+\|\d+\|/?)\](.*?)\[/url\]#si";
$html[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\3\">\\3</a>";
$bb[] = "#\[url\]([\w]+?://([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";

		$html[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\1\">\\1</a>";

		$bb[] = "#\[url\]((www|ftp)\.([\w\#$%&~/.\-;:=,?@\]+]+|\[(?!url=))*?)\[/url\]#is";

		$html[] = "<a href=\"http://\\1\" target=\"_blank\" title=\"\\1\">\\1</a>";

		$bb[] = "#\[url=([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";

		$html[] = "<a href=\"\\1\" target=\"_blank\" title=\"\\1\">\\2</a>";

		$bb[] = "#\[url=((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*?)\]([^?\n\r\t].*?)\[/url\]#is";

		$html[] = "<a href=\"http://\\1\" target=\"_blank\" title=\"\\1\">\\3</a>";

		$bb[] = "#\[mail\](\S+?)\[/mail\]#i";

		$html[] = "<a href=\"mailto:\\1\">\\1</a>";

		$bb[] = "#\[mail\s*=\s*([\.\w\-]+\@[\.\w\-]+\.[\w\-]+)\s*\](.*?)\[\/mail\]#i";

		$html[] = "<a href=\"mailto:\\1\">\\2</a>";

		$bb[] = "#\[color=(\#[0-9A-F]{6}|[a-z]+)\](.*?)\[/color\]#si";

		$html[] = "<span style=\"color: \\1\">\\2</span>";

		$bb[] = "#\[family=([A-Za-z ]+)\](.*?)\[/family\]#si";

		$html[] = "<span style=\"font-family: \\1\">\\2</span>";

		$bb[] = "#\[size=([0-9]{1,2}+)\](.*?)\[/size\]#si";

		$html[] = "<span style=\"font-size: \\1\">\\2</span>";

		$bb[] = "#\[(left|right|center|justify)\](.*?)\[/\\1\]#is";

		$html[] = "<div align=\"\\1\">\\2</div>";

		$bb[] = "#\[b\](.*?)\[/b\]#si";

		$html[] = "<b>\\1</b>";

		$bb[] = "#\[i\](.*?)\[/i\]#si";

		$html[] = "<i>\\1</i>";

		$bb[] = "#\[u\](.*?)\[/u\]#si";

		$html[] = "<u>\\1</u>";

		$bb[] = "#\[s\](.*?)\[/s\]#si";

		$html[] = "<s>\\1</s>";

		$bb[] = "#\[li\]#si";

		$html[] = "<li>";

		$bb[] = "#\[hr\]#si";

		$html[] = "<hr>";

		$bb[] = "#\*(\d{2})#";

		$html[] = "<img src=\"images/smilies/\\1.gif\" border=\"0\">";

		$sourse = preg_replace($bb, $html, $sourse);

return $sourse;}


function reneblock()
{
global $conf, $prefix;

include('config/config.php');

include("config/config_global.php");

$config['http_home_url']="".$homeurl."";



define ("DBHOST", "$dbhost"); 

define ("DBNAME", "$dbname");

define ("DBUSER", "$dbuname");

define ("DBPASS", "$dbpass");  


$db = new db;






	# Check homeURL:
	$old_conf_html = $config['http_home_url'];
	if ( $config['http_home_url'][strlen($config['http_home_url'])-1] == '/' )
		$config['http_home_url'] = substr( $config['http_home_url'], 0, strlen($config['http_home_url'])-1 );
	
	$out = '';
	$id = htmlspecialchars($_REQUEST['id']);
	if ( !$id ) return 'RNB: NO ID error';

	define( 'INF_ID', 		$id );
	define( 'RNB_CONF', 	'modules/informer/rnb_conf/' );
	define( 'RNB_HTTP', 	'/uploads/rnb/' );
	define( 'RNB_HTTP_IMG', RNB_HTTP.$id.'/' );
	define( 'RNB_ROOT', 	ROOT_DIR.RNB_HTTP );
	define( 'RNB_IMG', 		RNB_ROOT.$id.'/' );
	define( 'RNB_CACHE', 	RNB_IMG.'cache/' );
	//echo '<br>ID = '.$id;
	unset( $conf );
	# GET SETTINGS:
	if ( file_exists(RNB_CONF.$id.'.php') )
		require_once( RNB_CONF.$id.'.php' );
	else
		return '<br> RNB: NO CONFIGURATION FILE error';
	//echo '<br>CONF:<pre>'; print_r( $conf ); echo '</pre>';
	if (!$conf) return '<br> RNB: CONF error';

	# Check file system structure:
	if (!file_exists(RNB_ROOT))
	{
		if ( !(@mkdir(RNB_ROOT, 0777)) ) { return '<br> RNB: Unable to mkdir: "'.RNB_ROOT.'"'; }
		if ( !(@chmod(RNB_ROOT, 0777)) ) { return '<br> RNB: Unable to chmod: "'.RNB_ROOT.'"'; }
	}
	if (!file_exists(RNB_IMG))
	{
		if ( !(@mkdir(RNB_IMG, 0777)) ) { return '<br> RNB: Unable to mkdir: "'.RNB_IMG.'"'; }
		if ( !(@chmod(RNB_IMG, 0777)) ) { return '<br> RNB: Unable to chmod: "'.RNB_IMG.'"'; }
		if ( !(@mkdir(RNB_CACHE, 0777)) ) { return '<br> RNB: Unable to mkdir: "'.RNB_CACHE.'"'; }
		if ( !(@chmod(RNB_CACHE, 0777)) ) { return '<br> RNB: Unable to chmod: "'.RNB_CACHE.'"'; }
	}

	# find post count:
	$post_count = (int)$conf['x'] * (int)$conf['y'];
	//echo $post_count.'<br>';

	#--------------------------------------------------------------------------------------------------------------
	#	STAGE 1: = PREPARE QUERY =
	#--------------------------------------------------------------------------------------------------------------
	# select posts from categories:
	if ( $conf['cats'] == "all" )
		$show_from = '';
	else
	{
		$show_from = ' WHERE ( ';
		$show_cats_arr = explode(',', $conf['cats']);
		for ($i=0; $i < count($show_cats_arr); ++$i)
		{
			if ( $i == count($show_cats_arr)-1 )
				$show_from .= 'catid = '.$show_cats_arr[$i].' )';
			else
				$show_from .= 'catid = '.$show_cats_arr[$i].' OR ';
		}
	}
	
	# select from short or full story:
	if ( $conf['select_short'] == "0" )
		$story = "bodytext";
	else
		$story = "hometext";

	
	
	if ( $conf['with_pic_only'] )
	{
		if ( $show_from )
		{
			$show_from .= " AND ( `".$story."` LIKE '%[img%' ) ";
		}
		else
		{
			$show_from = " WHERE `".$story."` LIKE '%[img%' ";
		}
		/*
		//if ( $conf['exdir'] )
		//{
			if ( $show_from )
			//{ $show_from .= " OR ( `".$story."` NOT LIKE '%[img%".$conf['exdir']."%' ) "; }
			{ $show_from .= " OR ( `".$story."` NOT LIKE '%[img%/data/emoticons%' ) "; }
			else
			//{ $show_from = " WHERE `".$story."` NOT LIKE '%[img%".$conf['exdir']."%' "; }
			{ $show_from = " WHERE `".$story."` NOT LIKE '%[img%/data/emoticons%' "; }
		//}
		*/
	}

	

	# show posts in period:
	if ( $conf['days'] )
	{
		if ( $show_from )
		{
			$show_from .= " AND ( TO_DAYS(time) > ( TO_DAYS(CURRENT_DATE) - ".intval($conf['days']).") ) ";
		}
		else
		{
			$show_from = " WHERE TO_DAYS(time) > ( TO_DAYS(CURRENT_DATE) - ".intval($conf['days']).") ";
		}
	}
	//echo htmlspecialchars( $show_from );

	# select order:
	switch ( intval($conf['select_order']) )
	{
		case 1:	// Last:
			$ord = 'sid DESC';
			break;
		case 2: // By vote:
			$ord = 'ratings DESC';
			break;
		case 3: // By views:
			$ord = 'counter DESC';
			break;
		default: // Random:
			$ord = 'RAND()';
	}
	
	# query:


$query = "SELECT sid,catid,title,time,".$story." FROM ".$prefix."_stories ".$show_from." ORDER BY ".$ord." LIMIT ".$post_count;




	//return '<br>'.$query;

	#--------------------------------------------------------------------------------------------------------------
	#	STAGE 2: = SELECTING =
	#--------------------------------------------------------------------------------------------------------------
	//echo '<br>'. htmlspecialchars($query) .'<br>';
	$result = $db->query( $query, (int)$conf['cache'], RNB_CACHE, 'CACHE' );
	//foreach ( $result as $i => $j) { $result[$i]['hometext'] = htmlspecialchars( $result[$i]['hometext'] ); }
	//echo '<pre>'; print_r($result); echo '</pre>';
	for ( $i=0; $i<count($result); ++$i )
	{
		$rnb['id'][] = $result[$i]['sid'];
		$rnb['story'][] = images_cod($result[$i][$story]);
		$rnb['title'][] = stripslashes( $result[$i]['title'] );
		$rnb['date'][] = $result[$i]['time'];
		$rnb['category'][] = $result[$i]['catid'];
		
	} //echo 'RNB:<pre>'; print_r($rnb); echo '</pre>';

#--------------------------------------------------------------------------------------------------------------
#	STAGE 3: = IMAGE PROCESSING =
#--------------------------------------------------------------------------------------------------------------
	if ( intval($conf['with_pic_only']) )
	{
		# GET IMAGES:
		for ( $i=0; $i<count($rnb['id']); ++$i )
		{


preg_match_all("/<img(.+?)src=\"(.+?)\"(.+?)>/",$rnb['story'][$i], $matches);
			
			if ( $matches[2] )
			{	//echo '<pre>'; print_r($matches[2]); echo '</pre>';
				if ( !$conf['frst_rnd_pic'] )
					$rnb['img'][$i] = $matches[2][rand(0, count($matches[2])-1)]; // random pic :)
				else
					$rnb['img'][$i] = $matches[2][0]; // first pic
			}
		} //echo '<pre>'; print_r($rnb['img']); echo '</pre>';

		# MAKE THUMBS:
		for ( $i=0; $i<count($rnb['img']); ++$i )
		{
			$not_resized_image = $rnb['img'][$i];
			$resized_image = RNB_IMG.basename($rnb['img'][$i]);
			if ( 
					( $size_img = @getimagesize($not_resized_image) ) &&
					(
						($size_img[0] > (int)$conf['w']) || ($size_img[1] > (int)$conf['h']) )
					)
			{
				if (!file_exists( $resized_image ))
				{ # make resize:
					$cim = new fth_cropImage;
					$cim->cropImage( intval($conf['w']), intval($conf['h']), $not_resized_image, $resized_image );
					if ( !(@chmod ($resized_image, 0666)) ) { return '<br> RNB: Unable to chmod: "'.$resized_image.'"'; }
				}
				$rnb['img'][$i] = $config['http_home_url'].RNB_HTTP_IMG.basename($resized_image);
			} //$out .= $rnb['img'][$i].'<br>';
		} //echo '<pre>'; print_r($rnb['img']); echo '</pre>';
	}
		
	#--------------------------------------------------------------------------------------------------------------
	#	STAGE 4: = FORM BLOCK ELEMENTS =
	#--------------------------------------------------------------------------------------------------------------
	for ( $i=0; $i<count($rnb['id']); ++$i )
	{

$rnb['link'][$i] = $config['http_home_url'].'/index.php?name=news&op=view&id='.$rnb['id'][$i];

# Open in new window:
if ( $conf['open_new_wind'] )
			$open = 'target="_blank"';
		else
			$open = '';
		
		# Form TITLE:
		if ( $conf['title'] != '0' )
		{
			if ( $rnb['title'][$i] )
			{
				if ( strlen($rnb['title'][$i]) > $conf['title'] )
				{ 
					$rnb['title'][$i] = substr($rnb['title'][$i], 0, $conf['title']).'';
				}
				//$rnb['title'][$i] = wordwrap ( $rnb['title'][$i], 20, '<br>', 1 );
$rnb['title'][$i] = '<a href="'.$rnb['link'][$i].'" '.$open.' title="'.$rnb['hint'][$i].'" style="text-decoration:none; color:#'.$conf['title_color'].'; font-weight:bold;"> '.$rnb['title'][$i].' </a>';
			} //$out .= 'title = '.$rnb['title'][$i].'<br>';
		}
		else
		{ $rnb['title'][$i] = ''; }
		
		# Form IMAGE:
		if ( $conf['with_pic_only'] )
		{
$rnb['img'][$i] = '<a href="'.$rnb['link'][$i].'" '.$open.'><img border="0" src="'.$rnb['img'][$i].'" title="'.$rnb['hint'][$i].'" align=center></a>';
		}
		else
		{
			$rnb['img'][$i] = '';
		}
		
		# Form STORY:
		if ( $conf['text'] != '0' )
		{
			if ( $rnb['story'][$i] )
			{
				$rnb['story'][$i] = strip_tags( $rnb['story'][$i] );
				if ( strlen($rnb['story'][$i]) > $conf['text'] )
				{ 
					$rnb['story'][$i] = substr($rnb['story'][$i], 0, $conf['text']).'';
				}

$rnb['story'][$i] = '<a href="'.$rnb['link'][$i].'" '.$open.' title="'.$rnb['hint'][$i].'" style="text-decoration:none; color:#'.$conf['text_color'].';">'.$rnb['story'][$i].'</a>';
			} //$out .= 'story = '.$rnb['story'][$i].'<br>';
		}
		else
		{ $rnb['story'][$i] = ''; }
	} //end loop :)

	#--------------------------------------------------------------------------------------------------------------
	#	STAGE 5: FORMING OUTPUT
	#--------------------------------------------------------------------------------------------------------------
	$cell_width = $conf['w'] + 14;
	for ( $i=0; $i<count($rnb['id']); ++$i )
	{
		switch ( (int)$conf['type'] )
		{
			case 2:
				/*	#-->> TYPE 2:
					+-----------+-----------+
					|			|	TITLE	|
					|  PICTURE	|-----------|
					|			|	TEXT	|
					+-----------+-----------+ */
						$cell[$i]  = '<table border=0 align="left" cellpadding="0" cellspacing="0" style="margin:'.$conf['margin'].'px">';
						if ( !$conf['shadow'] )
							$cell[$i] .= '<tr> <td align="center" rowspan=2> '.$rnb['img'][$i].' </td>';
						elseif ( $conf['with_pic_only'] )
							$cell[$i] .= '<tr> <td align="center" rowspan=2> <div style="float:right; margin:0px; padding-left:12px;  padding-bottom:12px; background-image:url('.$config['http_home_url'].'/shadow.gif); background-repeat:no-repeat; background-position:left bottom;"> '.$rnb['img'][$i].' </div> </td>';
						//$cell[$i] .= '<td rowspan=2 style="width:5px"> &nbsp; </td>';
						$cell[$i] .= '<td align="left" valign="top" width='.$cell_width.'> <div style="font-size:11px; margin:2px;">'.$rnb['title'][$i].'</div> </td></tr>';
						$cell[$i] .= '<tr><td align="left" valign="top" width='.$cell_width.'><div style="font-size:11px; margin:2px;">'.nl2br($rnb['story'][$i]).'</div></td></tr>';
						$cell[$i] .= '</table>';
						break;
			default:
				/*	#-->> TYPE 1:
					+-----------+
					|	TITLE	|
					+-----------+
					|			|
					|  PICTURE	|
					|			|
					+-----------+
					|	TEXT	|
					+-----------+ */
				$cell[$i]  = '<center><table border=0 align="center" cellpadding="0" cellspacing="0" style="margin:'.$conf['margin'].'px">';
				$cell[$i] .= '<tr> <td align="center" width='.$cell_width.'> <div style="font-size:11px">'.$rnb['title'][$i].'</div> </td> </tr>';
				if ( !$conf['shadow'] )
					$cell[$i] .= '<tr> <td align="center"> '.$rnb['img'][$i].' </td> </tr>';
				elseif ( $conf['with_pic_only'] )
					$cell[$i] .= '<tr> <td align="right"> <table align=center><tr><td> <div style="float:left;margin:0px; padding-left:12px;  padding-bottom:12px; background-image:url('.$config['http_home_url'].'/shadow.gif); background-repeat:no-repeat; background-position:left bottom;">'.$rnb['img'][$i].' </td></tr></table> </div> </td> </tr>';
				$cell[$i] .= '<tr> <td align="center" width='.$cell_width.'> <div style="font-size:11px">'.nl2br($rnb['story'][$i]).'</div> </td> </tr>';
				$cell[$i] .= '</table></center>';
		} //$out .= 'cell = '.$cell[$i].'<br>';
	} //end loop :)

	$cnt_pic = 0; // position of post
	$out .= '<table border=0 align="center" cellpadding="0" cellspacing="0">';
	for ($i=0; $i < $conf['y']; ++$i)
	{
		$out .= '<tr valign=top>';
		for ($j=0; $j < $conf['x']; ++$j)
		{
			$out .= '<td align="center">';
			$out .= $cell[$cnt_pic];
			$out .= '</td>';
			++$cnt_pic;
		}
		$out .= '</tr>';
	}
	$out .= '</table>';
	
	$db->free();
	$config['http_home_url'] = $old_conf_html;

	//$out = str_replace( '"', '\'', $out );
	$out = str_replace( '<br />', ' ', $out );
	$out = str_replace( '<br>', ' ', $out );
	$out = str_replace(Chr(13), '', $out );
	$out = str_replace(Chr(10), '', $out );
	//echo htmlspecialchars( $out );
	//echo $db->log;

	$db->free();
	$db->close();
return $out;
}


/**
 * MySQL class
*/ 
class db
{
	/**
	 * DB variables
	*/ 
	var $db_id = false;
	var $connected = false;
	var $mysql_error = '';
	var $mysql_version = '';
	var $mysql_error_num = 0;
	var $query_id = false;

	/**
	 * CACHE variables
	*/ 
	var $filename;
	var $ttl = 0;
	var $data_ts;
   	var $ResultData=array();

	/**
	 * LOG variable
	*/ 
	var $log = '<br> :: MySQL class';

	/**
	 * Connect to DB
 	*/
 	function connect($db_user, $db_pass, $db_name, $db_location='localhost', $show_error=1)
	{
		if(!$this->db_id = @mysql_connect($db_location, $db_user, $db_pass)) {
			if($show_error == 1) {
				$this->display_error(mysql_error(), mysql_errno());
			} else {
				return false;
			}
		} 

		if(!@mysql_select_db($db_name, $this->db_id)) {
			if($show_error == 1) {
				$this->display_error(mysql_error(), mysql_errno());
			} else {
				return false;
			}
		}

		$this->mysql_version = mysql_get_server_info();

		if(!defined('COLLATE'))
		{ 
			define ('COLLATE', 'cp1251');
		}

		if (version_compare($this->mysql_version, '4.1', ">=")) mysql_query("/*!40101 SET NAMES '" . COLLATE . "' */");

		$this->connected = true;

		return true;
	}

	/**
	 * Get data from DB or Cache and return data array
 	*/
	function query($query, $ttl=0, $dir, $filename='', $show_error=true)
	{
		if(!$this->connected) $this->connect(DBUSER, DBPASS, DBNAME, DBHOST);
		if($this->connected) $this->log .= '<br>LOG:<hr> Connected to DB :: MySQL class';

		$this->ttl = $ttl;
		$this->filename = $filename;

		$data = '';
		unset( $this->ResultData );

		if ($this->ttl == "0") 
		{
			return $data = $this->getFromDB($query);
		} 
		else 
		{
			if (strlen(trim($this->filename)) == 0) { $this->filename = MD5($query); }
			$this->filename = $dir.'db_'.$this->filename;
			$this->getFile_ts();
			if ((time() - $this->data_ts) >= $this->ttl) 
			{
				if ( !$this->getFromDB($query) ) { return false; }
				$data = $this->getResultData();
				if ( !$this->saveToCache( $this->ResultData ) ) { return false; }
				return $data;
			} 
			else 
			{
				return $this->getFromCache();
			}
		}
	}
	
	/**
	 * Get query ID
 	*/
	function getFromDB($query)
	{
		$this->log .= '<br> call getFromDB($query)... when ttl = '.$this->ttl;
		if(!($this->query_id = mysql_query($query, $this->db_id) )) 
		{
			$this->log .= '<br> - Troubles while mysql_query()...';
			$this->mysql_error = mysql_error();
			$this->mysql_error_num = mysql_errno();
			if($show_error) {
				$this->display_error($this->mysql_error, $this->mysql_error_num, $query);
			}
		}
		return $this->query_id;
	}

	/**
	 * Get data from DB and return data array
 	*/
	function getResultData()
	{
		$this->log .= '<br> call getResultData()...';
		$nr = mysql_num_rows($this->query_id);
		for ($i=0; $i<$nr; $i++)
		{
			$this->ResultData[$i]= mysql_fetch_assoc($this->query_id);
		}
		return $this->ResultData;
	}

	/**
	 * Get file info
 	*/
	function getFile_ts() 
	{
		$this->log .= '<br> call getFile_ts() for file: '.$this->filename;
		if (!file_exists($this->filename)) 
		{
			$this->log .= '<br> - Can\'t get cache file info!';
			$this->data_ts = 0;
			return false;
		}
		$this->data_ts = filemtime($this->filename);
		return true;
	}

	/**
	 * Save data to Cache
 	*/
	function saveToCache($data) 
	{
		$this->log .= '<br> call saveToCache()...';
		if (!$fp=@fopen($this->filename,'w')) 
		{
			$this->log .= '<br> - Can\'t create cache file!'; 
			return false; 
		}
		@flock($fp, LOCK_EX);
		if (!@fwrite($fp, serialize($data))) 
		{
			$this->log .= '<br> - Can\'t save data to cache file!';
			fclose($fp);
			return false;
		}
		fclose($fp);
		return true;
	}

	/**
	 * Get data from Cache
 	*/
	function getFromCache() 
	{
		$this->log .= '<br> call getFromCache()...';
		if ( @$fp=fopen($this->filename, 'r') ) { flock($fp, LOCK_SH); }
		if ( !($x = file_get_contents($this->filename)) ) 
		{ 
			$this->log .= '<br> - Can\'t get data from cache file!'; 
			return false; 
		}
		if ( !($this->ResultData = unserialize($x)) ) { return false; }
		//echo '$this->ResultData:<pre>'; print_r($this->ResultData); echo '</pre>';
		return $this->ResultData;
	}

	/**
	 * Make safety data
 	*/
	function safesql( $source )
	{
		if ($this->db_id) return mysql_real_escape_string ($source, $this->db_id);
		else return mysql_escape_string($source);
	}

	/**
	 * Free result memory
 	*/
	function free( $query_id = '' )
	{
		if ($query_id == '') $query_id = $this->query_id;
		@mysql_free_result($query_id);
	}

	/**
	 * Close MySQL connection
 	*/
	function close()
	{
		@mysql_close($this->db_id);
	}

	/**
	 * Show MySQL error
 	*/
	function display_error($error, $error_num, $query = '')
	{
		if($query) {
			// Safify query
			$query = preg_replace("/([0-9a-f]){32}/", "********************************", $query); // Hides all hashes
			$query_str = "$query";
		}
		
		echo '<?xml version="1.0" encoding="iso-8859-1"?>
		<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		<html xmlns="http://www.w3.org/1999/xhtml">
		<head>
		<title>MySQL Fatal Error</title>
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
		<style type="text/css">
		<!--
		body {
			font-family: Verdana, Arial, Helvetica, sans-serif;
			font-size: 10px;
			font-style: normal;
			color: #000000;
		}
		-->
		</style>
		</head>
		<body>
			<font size="4">MySQL Error!</font> 
			<br />------------------------<br />
			<br />
			
			<u>The Error returned was:</u> 
			<br />
				<strong>'.$error.'</strong>

			<br /><br />
			</strong><u>Error Number:</u> 
			<br />
				<strong>'.$error_num.'</strong>
			<br />
				<br />
			
			<textarea name="" rows="15" cols="60" wrap="virtual">'.$query_str.'</textarea><br />
		</body>
		</html>';

		exit();
	}
}


/**
 * CropImage Class
 */ 
class fth_cropImage
{ // http://www.findmotive.com/2006/12/13/php-crop-image/
	var $log = '';
	
	function cropImage($nw, $nh, $source, $dest) 
	{
		$size = getimagesize($source);
		$w = $size[0];
		$h = $size[1];
		
		$stypeArr = explode( '.', $source );
		$stype = strtolower( end($stypeArr) );
		
		switch($stype) 
		{
			case 'gif':
				$simg = imagecreatefromgif($source);
				break;
			case 'jpeg':
				$simg = imagecreatefromjpeg($source);
				break;
			case 'jpg':
				$simg = imagecreatefromjpeg($source);
				break;
			case 'png':
				$simg = imagecreatefrompng($source);
				break;
		}
		
		$dimg = imagecreatetruecolor($nw, $nh);
		
		$wm = $w/$nw;
		$hm = $h/$nh;

		$h_height = $nh/2;
		$w_height = $nw/2;

		if($w> $h)
		{
			$adjusted_width = $w / $hm;
			$half_width = $adjusted_width / 2;
			$int_width = $half_width - $w_height;

			imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
		}
		elseif( ($w <$h) || ($w == $h) )
		{
			$adjusted_height = $h / $wm;
			$half_height = $adjusted_height / 2;
			$int_height = $half_height - $h_height;

			imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
		}
		else
		{
			imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
		}

		imagejpeg($dimg,$dest,85);
	}

}

/**

* For one informer per site:
var rnbAdBlock = document.getElementById('rnbAdBlock');
if(rnbAdBlock) rnbAdBlock.innerHTML = '<? echo reneblock(); ?>';

 * For many informers per site:
document.write("<?php echo reneblock(); ?>");

*/
$out = reneblock();
//$out = str_replace( '\'', '"', $out );


?>
var rnbAdBlock = document.getElementById('<? echo INF_ID; ?>');
if(rnbAdBlock) rnbAdBlock.innerHTML = '<? echo"".$out."<br><a href=\"http://ustal.net/\"><font color= #ffffff\">ustal.net</font></a>"; ?>';