PhpSnip.com

User Stats

Thread class

This class can print out an array of threads in threaded or flat mode (any mode you want really) This can be usefull for discussion boards where you want both options

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 517

Source Code ( 37 lines )

<?

class Thread
{	var $beginLevel = "<ul>";
	var $endLevel = "</ul>";
	var $beginItem = "<li>";
	var $endItem = "</li>";
	var $wholeThread;
	
	function Thread($code="")
	{	if(!empty($code))
		{	$this->beginLevel = $code[beginLevel];
			$this->endLevel = $code[endLevel];
			$this->beginItem = $code[beginItem];
			$this->endItem = $code[endItem];
		}
	}
	
	function sortChilds($threads)
	{	while(list($var, $value) = each($threads))
			$childs[$value[parent]][$value[ID]] = $value;
		return $childs;
	}
	
	function convertToThread($threads, $thread)
	{	$this->wholeThread .= $this->beginLevel;
		while(list($parent, $value) = each($thread))
		{	$this->wholeThread .= $this->beginItem . $value[content] . $this->endItem;
			if($threads[$parent] && !$value[closed])
				$this->convertToThread($threads, $threads[$parent]);
		}
		$this->wholeThread .= $this->endLevel;
		return $this->wholeThread;
	}
}

?>

Search

Subscribe

  Rss Feeds

Sponsors

Advertise