Location: PHPKode > projects > Simple Way to Usenet > libs/core/themes/tfeats/tfeat_leftmenu.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

 *	**************************************************************
 */
/* used to output the implented blockvis following user setting
 * 
 */ 
class tfeat_leftmenu {
	
	private static $init=FALSE;
	
	public function __construct(){ }
	
	public static function implent(){
		thm_mediaq::append_css_file('blockvis');
		thm_mediaq::append_js_file('swap_blockvis'); //hmmm may need ajax too
		
		if ( isset($_POST['leftmenu']) ){
			$blks = thm_blockvis::getblockbygroup('leftmenu');
			foreach($blks as $ref => &$opt){
				if ( isset($_POST['block'][$ref]) ){
					if ( 'FALSE' == $_POST['block'][$ref] ){
						$n = FALSE;
					} elseif ( 'TRUE' == $_POST['block'][$ref] ){
						$n = TRUE;
					} else {
						$n = NULL;
					}
					thm_blockvis::setblockvis('leftmenu', $ref, $n);
				}
			}
			pagegen::add_event("Leftmenu block changes has been applyed");
		}
		self::$init=TRUE;
		return TRUE; 
	}
	
	public static function genform(){ 
		$blks = thm_blockvis::getblockbygroup('leftmenu');
		foreach($blks as $ref => &$opt){
			//$order = thm_blockvis::blockorder('leftmenu', $ref);
			//$ordered[$order] = $ref;
			$b['ref'] = $ref;
			if ( FALSE === thm_blockvis::blockisdisplayed('leftmenu', $ref) ){
				$b['vis'] = 'FALSE';
			} elseif ( FALSE === thm_blockvis::blockisopen('leftmenu', $ref) ){
				$b['vis'] = 'NULL';
			} else {
				$b['vis'] = 'TRUE';
			}
			$b['order'] = thm_blockvis::blockorder('leftmenu', $ref);
			$o['blocks'][] = $b;
		}
		//print_r($o);
		/*
		//ksort($ordered);
		foreach($ordered as $order => &$ref){
			$b['ref'] = $ref;
			$b['dsp'] = thm_blockvis::blockisdisplayed('leftmenu', $ref);
			$b['vis'] = thm_blockvis::blockisopen('leftmenu', $ref);
			$o['blocks'][] = $b;
		}
		*/
		return $o;
	}

	public static function genpart($gname, $of=FALSE){
		if ( !self::$init ){ self::implent(); }
		//called by parser, with block like {--TFEAT=blockvis;$gname --}
		//so need to implent available blockvis into theme __construct as gname leftmenu, linked to callbacks that will gen content when needed 
		//so here i loop them, and for each check available conf : fetch?order?open?
		//if fetch, set $buf[$order] = $ref;$obuf[$order]=$open;
		//foreach $buf as block => send block divopen, send callback return, send block divclose
		$blks = thm_blockvis::getblockbygroup('leftmenu');
		foreach($blks as $ref => &$opt){
			//? client doesn't want it displayed ?
			if ( FALSE === thm_blockvis::blockisdisplayed('leftmenu', $ref) ){ 
				unset($blks[$ref]); 
			}
		}
		//redorder? 
		$o='';
		foreach($blks as $ref => &$opt){
			$o .= '<div class="blockvis_leftmenu_container"><div class="blockvis_leftmenu_header">';
			$o .= '<span class="blockvis_leftmenu" onclick="swap_blockvis(1, \'block_leftmenu_'.$ref.'\', \'blockvis_leftmenu_\');">[&plusmn;] <b>';
			$o .= langs::dico_translate("block_$ref", NULL, 'layout').'</b></span></div>';
			if ( thm_blockvis::blockisopen('leftmenu', $ref) == TRUE ){ $dft = 'open'; } else { $dft = 'close'; }
			$o .= '<div id="block_leftmenu_'.$ref.'" class="blockvis_leftmenu_'.$dft.'">';
			if ( FALSE !== $of ){ 
				call_user_func($of, $o);
				call_user_func($opt[0], $of);
				$o=''; 
			} else {
				$o .= call_user_func($opt[0], $of);
			}
			$o .= '</div></div><div class="blockvis_leftmenu_interval"></div>';
			if ( FALSE !== $of ){ call_user_func($of, $o);$o=''; }
		}
		if ( !$of ){ return $o; } 
		return TRUE;
	}
}
return TRUE;
Return current item: Simple Way to Usenet