Location: PHPKode > projects > Simple Way to Usenet > swun/libs/core/pgen/engine/page_conf.class.php
<?php
/**
 *  
 * @author  Benjamin Gillissen <hide@address.com>
 * 
 *	**************************************************************

	Copyright (C) 2009  Benjamin Gillissen
	
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details at:
	http://www.gnu.org/copyleft/gpl.html

 *	**************************************************************
 */
class page_conf {
		
	public function __construct(){
		if ( !is_array(configs::get('pagegen', 'pages')) ){
			errors::raise('Missing pages Array in pagegen configuration file !', CORE_LOG_FATAL, 'PGEN');
		}
	}
	
	public function exists($pid){ return is_array( configs::get('pagegen', 'pages', $pid) ); }
	
	public function pidby_namelvl($name, $lvl){
		$pages = configs::get('pagegen', 'pages');
		foreach($pages as $pid => $pg ){
			if ( $pg['title'] == $name ){
				if ( $this->compute_depth($pid) == $lvl ){ return $pid;	}
			}
		}
		return FALSE;
	}
	
	public function get_infobypid($info, $pid){
		if ( FALSE === $this->exists($pid) ){ return FALSE; }
		if ( $info == 'depth' ){
			return $this->compute_depth($pid);
		} else {
			return configs::get('pagegen', 'pages', Array($pid, $info));
		}
	}
		
	public function get_childs($pid){
		$pages = configs::get('pagegen', 'pages');
		foreach($pages as $id => $pg ){
			if ( $pg['parent'] == $pid ){ $o[] = $id; }
		}
		if ( isset($o) ){ return $o; }
		return FALSE;
	}
	
	public function got_childpage($pid){ return is_array($this->get_childs($pid)); }
	
	public function listall(){
		static $offset;
		$pages = configs::get('pagegen', 'pages');
		$pages = array_keys($pages);
		if ( !isset($offset) ){ $offset=0; }
		if ( !isset($pages[$offset]) ){
			unset($offset);return FALSE; 
		} else {
			$o = $pages[$offset];
			$offset++;
			return $o;
		}
		 
	}
	
	private function compute_depth($pid){
		$p = $this->get_infobypid('parent', $pid);
		$c=0;
		while( 0 != $p ){
			$c++; 
			$p = $this->get_infobypid('parent', $p);
		}
		return $c;
	}
}
Return current item: Simple Way to Usenet