Location: PHPKode > projects > Simple Way to Usenet > libs/core/pgen/core_pages/pg_profile.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 pg_profile extends pg_helper {
	
	public static $PFEAT= Array();
	public static $AJAX= Array('swapthmvariant', 'swaptheme', 'updatecharset');
	public static $PARG = Array('realm');
	
	private $REALM, $PFEATS;
	
	public function __construct($pageid=NULL, $args=NULL){
		if ( $pageid !== NULL AND $args !== NULL ){ parent::__construct($pageid, $args, self::$PFEAT, self::$AJAX); }
	}

	public static function getpfeats(){ return self::$PFEAT; }
	
	public function send_footer(){ return themes::send_footer(); }

	public function send_header(){
		$this->REALM = new realm($this->args['realm']);
		$data['title'] = langs::dico_translate('pg_profile', NULL, 'pgtitle');
		themes::send_header($data);	
	}
	
	public function send_content($pdata){
		$tpl = new template();
		$tpl->output_function('langs::output_for_client');
		if ( FALSE === $tpl->load_file('profile/pg_profile.tpl') ){ return FALSE; }
		//webopt: lang, charset, theme, variant
		$tpl->appendata($this->gen_webopt(), 'webopt');
		//Theme features
		$this->gen_tfeats(&$tpl);
		//Realm's Page features
		$this->gen_pfeats(&$tpl);
		//Realm information
		$this->gen_accinfo(&$tpl);
		$tpl->parse();
	}
	
	private function gen_webopt(){
		$o['active_charset']= langs::charset();
		$o['active_lang']	= langs::lang();
		$o['active_theme']	= themes::get_active();
		$o['active_img'] 	= themes::get_variant_key('img', $o['active_theme']);
		$o['active_css'] 	= themes::get_variant_key('css', $o['active_theme']);
		$o['charsets']		= langs::getcharsets();
		$o['langs']			= langs::getlangs();
		$buf = themes::gethemes();
		foreach($buf as $k => &$tid ){ $o['themes'][$tid] = themes::getname($tid); }
		unset($buf);
		$o['use_custum_img'] 	= configs::get('themes', 'themes', Array($o['active_theme'],'custum_img') );
		$o['imgvariant'] 	= configs::get('themes', 'themes', Array($o['active_theme'],'vars','img') );
		if ( $o['use_custum_img'] ){
			$o['imgvariant']['custum'] = Array('name'=>'Custum Set');
			$o['custum_img'] = themes::get_variant_key('custum_img', $o['active_theme']);
		}
		$o['use_custum_css'] 	= configs::get('themes', 'themes', Array($o['active_theme'],'custum_css') );
		$o['cssvariant'] 	= configs::get('themes', 'themes', Array($o['active_theme'],'vars','css') );
		if ( $o['use_custum_css'] ){
			$o['cssvariant']['custum'] = Array('name'=>'Custum Set');
			$o['custum_css'] = themes::get_variant_key('custum_css', $o['active_theme']);
		}
		return $o;		
	}
	
	private function gen_tfeats(&$tpl){
		$tfeats = themes::get_features();
		foreach($tfeats as $k => &$feat){
			if  ( FALSE === @constant("tfeat_$feat::PROFILE") ){
				errors::raise("Theme Feature '$feat' droped from profile", CORE_LOG_NOTICE, 'PGEN'); 
				unset($tfeats[$k]); 
			} elseif ( !isset($first) ){ $first = $feat; } 
		}
		$tpl->appendata((count($tfeats) != 0), 'showtfeat');
		$tpl->appendata($tfeats, 'tfeats');
		if ( !isset($_GET['tfeat']) ){ $_GET['tfeat'] = $first; }
		if ( FALSE === array_search($_GET['tfeat'], $tfeats) ){ $_GET['tfeat'] = $first; }
		$tpl->appendata($_GET['tfeat'], 'active_tfeat');
		$cb = "tfeat_".$_GET['tfeat']."::genform";
		$tpl->appendata(call_user_func($cb), 'tfeat_data');
	}
	
	private function gen_pfeats(&$tpl){
		$feats = $this->get_realm_pfeats();
		foreach($feats as $k => &$feat){
			if  ( FALSE === @constant("pfeat_$k::PROFILE") ){ unset($feats[$k]);	} 
		}
		if ( FALSE === is_array($feats) ){
			$tpl->appendata(FALSE, 'showpfeat');
			return;
		}
		$pfeats = array_keys($feats); 
		$tpl->appendata((count($pfeats) != 0), 'showpfeat');
		$tpl->appendata($pfeats, 'pfeats');
		if ( !isset($_GET['pfeat']) ){ $_GET['pfeat'] = $pfeats[0]; }
		if ( FALSE === array_search($_GET['pfeat'], $pfeats) ){ $_GET['pfeat'] = $pfeats[0]; }
		$tpl->appendata($_GET['pfeat'], 'active_pfeat');
		$cb = "pfeat_".$_GET['pfeat']."::genform";
		$tpl->appendata(call_user_func($cb, $feats[$_GET['pfeat']]), 'pfeat_data');
	}
	
	private function gen_accinfo(&$tpl){
		if ( FALSE === CORE_AUTH ){ 
			$tpl->appendata(FALSE, 'showauth');
			return;
		}
		$tpl->appendata(TRUE, 'showauth');
		$buf = $this->REALM->get_profiledata();
		$tpl->appendata($buf, 'AUTHDATA');
		$tpl->appendata($buf['user'], 'user');
		unset($buf);
	}
	
	private function get_realm_pfeats(){
		while( FALSE !== ($pid = pages::listall()) ){
			$ok=(  pages::get_type($pid) == 'b' );
			if ( @CORE_AUTH AND $ok ){
				//echo "checking access to page $pid on realm $realm.<br>";
				$realm = pages::get_realm($pid);
				if ( $realm == $this->args['realm'] ){
					$ok = $this->REALM->ispublic('pages', 'read', $pid);
					if ( FALSE === $ok ){
						if ( ! $this->REALM->isloged() ){ $this->REALM->authenticate(); } 
						$ok = $this->REALM->checks('pages', 'read', $pid); 
					}
				}
			}
			if ( $ok ){
				$pg = pages::get_conf($pid);
				$pfeats = call_user_func("pg_$pg::getpfeats");
				if ( is_array($pfeats) ){
					foreach($pfeats as $feat => &$conf ){ $o[$feat][$pid] = $conf; }
				}
				unset($pg, $pfeats);
			}
		}
		if ( isset($o) ){ return $o; }
		return FALSE; 
	}
}
Return current item: Simple Way to Usenet