<?php

//--------------class IframeContentHandler--------------->>>//
class IframeContentHandler extends FormHandler
	{
		public function populateForumResponse($cid)
		    {
				$sql = 'SELECT forum_response FROM '.$this->CFG['db']['tbl']['forum_response'].' WHERE response_id='.$this->dbObj->Param('cid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								 preg_match_all("/<\/?a+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">]))?)+\s*|\s*)\/?>/i", $row['forum_response'], $out);
								 $lc = 0;
								 foreach($out[0] as $key=>$links)
								 	{
										if($key == 0 or $key%2 == 1 and $key != 1)
											{
												$to_replace = substr($links, 0, -1).' target="_parent"/>';
												htmlentities($to_replace);
												$row['forum_response'] = str_ireplace($links, $to_replace, $row['forum_response']);
											}

										$lc++;
									}
								 $response = str_ireplace('<br />','',html_entity_decode($row['forum_response']));
								 $response = str_ireplace('<p> </p>','',$response);
								 $response = str_ireplace('<p>Â </p>','',$response);
								 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->CFG['site']['charset'].'" />';
								 echo $response = str_ireplace('Â','',$response);
							} // while
					}
		    }
		public function populateBlogContent($cid)
		    {
				$sql = 'SELECT message FROM '.$this->CFG['db']['tbl']['blogs'].' WHERE blog_id='.$this->dbObj->Param('cid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								 preg_match_all("/<\/?a+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">]))?)+\s*|\s*)\/?>/i", $row['message'], $out);
								 $lc = 0;
								 foreach($out[0] as $key=>$links)
								 	{
										if($key == 0 or $key%2 == 1 and $key != 1)
											{
												$to_replace = substr($links, 0, -1).' target="_parent"/>';
												htmlentities($to_replace);
												$row['message'] = str_ireplace($links, $to_replace, $row['message']);
											}

										$lc++;
									}
								 $response = str_ireplace('<br />','',html_entity_decode($row['message']));
								 $response = str_ireplace('<p> </p>','',$response);
								 $response = str_ireplace('<p>Â </p>','',$response);
								 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->CFG['site']['charset'].'" />';
								 echo $response = str_ireplace('Â','',$response);
							} // while
					}
		    }
		public function populateMailContent($cid)
		    {
				$sql = 'SELECT message FROM '.$this->CFG['db']['tbl']['messages'].' WHERE message_id='.$this->dbObj->Param('cid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								 preg_match_all("/<\/?a+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">]))?)+\s*|\s*)\/?>/i", $row['message'], $out);
								 $lc = 0;
								 foreach($out[0] as $key=>$links)
								 	{
										if($key == 0 or $key%2 == 1 and $key != 1)
											{
												$to_replace = substr($links, 0, -1).' target="_parent"/>';
												htmlentities($to_replace);
												$row['message'] = str_ireplace($links, $to_replace, $row['message']);
											}

										$lc++;
									}
								 $response = str_ireplace('<br />','',html_entity_decode($row['message']));
								 $response = str_ireplace('<p> </p>','',$response);
								 $response = str_ireplace('<p>Â </p>','',$response);
								 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->CFG['site']['charset'].'" />';
								 echo $response = str_ireplace('Â','',$response);
							} // while
					}
		    }
		public function populateStaticContent($cid)
		    {
				$sql = 'SELECT page_content FROM '.$this->CFG['db']['tbl']['static_pages'].' WHERE seo_title='.$this->dbObj->Param('cid');
				$stmt = $this->dbObj->Prepare($sql);
				$rs = $this->dbObj->Execute($stmt, array($cid));
				if (!$rs)
					    trigger_db_error($this->dbObj);
				if ($rs->PO_RecordCount())
					{
						while($row = $rs->FetchRow())
							{
								 preg_match_all("/<\/?a+((\s+\w+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">]))?)+\s*|\s*)\/?>/i", $row['page_content'], $out);
								 $lc = 0;
								 foreach($out[0] as $key=>$links)
								 	{
										if($key == 0 or $key%2 == 1 and $key != 1)
											{
												$to_replace = substr($links, 0, -1).' target="_parent"/>';
												htmlentities($to_replace);
												$row['page_content'] = str_ireplace($links, $to_replace, $row['page_content']);
											}

										$lc++;
									}
								 $response = str_ireplace('<br />','',html_entity_decode($row['page_content']));
								 $response = str_ireplace('<p> </p>','',$response);
								 $response = str_ireplace('<p>Â </p>','',$response);
								 echo '<meta http-equiv="content-type" content="application/xhtml+xml; charset='.$this->CFG['site']['charset'].'" />';
								 echo $response;
							} // while
					}
		    }

	}
//<<<<<<<--------------class CategoryFormHandler---------------//

//--------------------Code begins-------------->>>>>//
$iframe = new IframeContentHandler();

$iframe->setPageBlockNames();

$iframe->setFormField('fid','');
$iframe->setFormField('bid','');
$iframe->setFormField('mid','');
$iframe->setFormField('sid','');
$iframe->sanitizeFormInputs($_GET);

//<<<<--------------------Code Ends----------------------//
//--------------------Page block templates begins-------------------->>>>>//
if($iframe->getFormField('fid'))
	{
		$iframe->populateForumResponse($iframe->getFormField('fid'));
	}
elseif($iframe->getFormField('bid'))
	{
		$iframe->populateBlogContent($iframe->getFormField('bid'));
	}
elseif($iframe->getFormField('mid'))
	{
		$iframe->populateMailContent($iframe->getFormField('mid'));
	}
elseif($iframe->getFormField('sid'))
	{
		$iframe->populateStaticContent($iframe->getFormField('sid'));
	}
?>
