Location: PHPKode > projects > Phpfastnews > phpfastnews/Lib/news.inc.php
<?php
/*	Copyright (c) 2001-02 by Ken Williams (hide@address.com)*/
/*	http://phpfastnews.sourceforge.net/ & http://www.phpfastnews.com*/
/*									*/
/*	You can redistribute and/or modify the following code under the	*/
/*	terms of the GNU General Public License as published by the	*/
/*	the Free Software Foundation.					*/
/*									*/
/*	LAST MODIFIED August 04, 2001 - 18:27:44 Eastern Standard Time	*/
/*	All code by Ken Williams (HDwebdev) unless otherwise noted	*/
/* This is an alpha test release -- not intended for live site	use	*/

// the main class for parsing tpl files and rendering then rendering the pages

class Render    {

        function headleft()	{
			global $r,$blox,$blocks;
		if ($blox["HEAD"]) {

                $r->set_block('TPL','HEAD');
                //note to self: add dynamic set_vars here
                $r->parse('body','HEAD',true);
        }

                if ($blox["LEFT"]) {
                        $blocks->pullblocks("left");

        }
                $r->set_block('TPL','CENTERSTART');
                $r->parse('body','CENTERSTART',true);
        }


        //same as above but deals with the right and footer
	function rightfoot()    {
		        global $r,$blox,$blocks;

        $r->set_block('TPL','CENTEREND');
        $r->parse('body','CENTEREND',true);

        if ($blox['RIGHT']) {
                $blocks->pullblocks("right");
        }

        if ($blox['FOOTER']) {
                $r->set_block('TPL','FOOTER');
                $r->parse('body','FOOTER',true);
        }
        }
}


class Blocks {

	var $pg = array();
	var $blok = array();
	var $bstyle = array();

                // $pg...this loads all the block #'s, ordering, and which side information for the named page

	function Blocks($pg)	{
		global $db;
		$this->pg["name"] = $pg;
		$query = "select def,lblox,lbloxdef,lcol,rblox,rbloxdef,rcol from fn_pages where page_name = '$pg'";
		$db->query($query);
		$db->next_record();

		$this->pg["def"]	= $db->f("def");
		$this->pg["lblox"]	= $db->f("lblox");
		$this->pg["lbloxdef"]	= $db->f("lbloxdef");
		$this->pg["lcol"]	= $db->f("lcol");
		$this->pg["rblox"]	= $db->f("rblox");
		$this->pg["rbloxdef"]	= $db->f("rbloxdef");
		$this->pg["rcol"]	= $db->f("rcol");

		// $BLOCK $this->block["left"] and ["right"] contain arrays in order of blocks they use
		if ($this->pg["def"]) { $block = $this->pg["lbloxdef"]; } else { $block = $this->pg["lblox"]; }
		$this->blok["left"] = explode(',',$block);
		if ($this->pg["def"]) { $block = $this->pg["rbloxdef"]; } else { $block = $this->pg["rblox"]; }
		$this->blok["right"] = explode(',',$block);

		// this loads the block names, and the styles they use
		$query = "select sb_id,sb_name,sb_style,sb_head,sb_content from fn_sblox";
		$db->query($query);
		while($db->next_record())	{
			$this->bstyle[$db->f(sb_id)]["sb_name"] = $db->f(sb_name);
			$this->bstyle[$db->f(sb_id)]["sb_style"] = $db->f(sb_style);
			$this->bstyle[$db->f(sb_id)]["sb_head"] = $db->f(sb_head);
			$this->bstyle[$db->f(sb_id)]["sb_content"] = $db->f(sb_content);
			}
	}

	function pullblocks($side)	{
		global $r,$tmp,$sideblocks;
	if ($side == "left")	{
		$r->set_block('TPL',"LEFTBLOCK");

		$r->set_block("LEFTBLOCK","LEFT1");
		$left["1"] = $r->get_var("LEFT1");
		$r->set_var("LEFT1",'');

		$r->set_block("LEFTBLOCK","LEFT2");
                $left["2"] = $r->get_var("LEFT2");
		$r->set_var("LEFT2",'');

		$r->set_block("LEFTBLOCK","LEFT3");
		$left["3"] = $r->get_var("LEFT3");
		$r->set_var("LEFT3",'');
		$str='';

	while(list($k,$v) = each($this->blok["left"]))
	        {
		$tmp = $this->bstyle[$v][sb_name];
		if($tmp == '') { return; }
		$tmp = $sideblocks->$tmp($v);
		$str = str_replace("{NAME}",$tmp[0],$left[$this->bstyle[$v]["sb_style"]]);
		$str = str_replace("{CONTENT}",$tmp[1],$str);
		$all .= $str;
		}
		$r->set_var('BLOCKS',$all);
		$r->parse('body','LEFTBLOCK',true);

	}

	if ($side == "right")	{
		$r->set_block('TPL',"RIGHTBLOCK");

		$r->set_block("RIGHTBLOCK","RIGHT1");
		$right["1"] = $r->get_var("RIGHT1");
		$r->set_var("RIGHT1",'');

		$r->set_block("RIGHTBLOCK","RIGHT2");
		$right["2"] = $r->get_var("RIGHT2");
		$r->set_var("RIGHT2",'');

		$r->set_block("RIGHTBLOCK","RIGHT3");
		$right["3"] = $r->get_var("RIGHT3");
		$r->set_var("RIGHT3",'');
		$str='';

		while(list($k,$v) = each($this->blok["right"]))
			{
				$tmp = $this->bstyle[$v][sb_name];
				if($tmp == '') { return; }
				$tmp = $sideblocks->$tmp($v);
				$str = str_replace("{NAME}",$tmp[0],$right[$this->bstyle[$v]["sb_style"]]);
				$str = str_replace("{CONTENT}",$tmp[1],$str);
				$all .= $str;
			}
		$r->set_var('BLOCKS2',$all);
		$r->parse('body',"RIGHTBLOCK",true);
	        }
        }
}

// add re: to reply titles in forms
function re_fix($thetext)	{
		if (ereg("re:",$thetext))	{
		return $thetext;
		}
		else
		{
		return "re: " . $thetext;
	}
}

//get rid of nasty stuff
function scrub($text,$type='')	{
	if ($type)	{
		}
		else
		{
		return preg_replace("/(\015\012)|(\015)|(\012)/","<br>",htmlspecialchars($text));
		}
}

//make sure the email address 'looks' like a real email address
function email_validate($email)	{
			return (eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email));
                        }

// use to add spaces (&nbsp;) around an item
function sp($input)	{
	return "&nbsp;" . $input . "&nbsp;";
	}
?>
Return current item: Phpfastnews