<?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
* **************************************************************
*/
//in profile we keep block state FALSE, not fetch, NULL closed, TRUE opened
class thm_blockvis {
private static $BLKS=Array();
private static $CC;
private static function loadCC(){
if ( isset(self::$CC) ){ return; }
$run = Array(client_configs::SESSION=>'profile');
//$run = Array();
$store = Array(client_configs::PROFILE=>'site_profile');
self::$CC = new client_configs($run, $store, Array(), Array() );
}
private static function in_array($ref, $ar){
$r=FALSE;
if ( !is_array($ar) ){ return $r; }
foreach($ar as $bref => &$v){ if ( $bref == $ref ){ $r = TRUE; } }
return $r;
}
public static function append_block($ref, $gname, $cb, $dfto){
if ( !isset(self::$BLKS[$gname]) ){ self::$BLKS[$gname]=Array(); }
if ( FALSE !== self::in_array($ref, self::$BLKS[$gname]) ){ return TRUE; }
self::$BLKS[$gname][$ref] = Array($cb, $dfto);
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
} else {
$blks[$gname] = Array();
}
if ( FALSE === self::in_array($ref, @$blks[$gname]) ){ //do get it, with a array_search after the first TRUE is return the last key....
$blks[$gname][$ref] = $dfto;
self::$CC->store('blockvis', $blks);
}
return TRUE;
}
public static function getblockbygroup($gname){
if ( !isset(self::$BLKS[$gname]) ){ return Array(); }
return self::$BLKS[$gname];
}
public static function blockisdisplayed($gname, $ref){
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
//if ( FALSE !== array_search($ref, $blks[$gname]) ){
if ( FALSE !== self::in_array($ref, $blks[$gname]) ){
return (FALSE !== $blks[$gname][$ref]);
}
}
return FALSE;
/*
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
return (FALSE !== self::$BLKS[$gname][$ref][1]);
*/
}
public static function blockisopen($gname, $ref){
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
//if ( FALSE !== array_search($ref, $blks[$gname]) ){
if ( FALSE !== self::in_array($ref, $blks[$gname]) ){
return ( FALSE !== $blks[$gname][$ref] AND NULL !== $blks[$gname][$ref] );
}
}
return FALSE;
/*
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
return ( FALSE !== self::$BLKS[$gname][$ref][1] AND NULL !== self::$BLKS[$gname][$ref][1] );
*/
}
public static function setblockvis($gname, $ref, $vis=NULL){
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){ $blks = self::$CC->get_stored('blockvis'); }
$blks[$gname][$ref] = $vis;
self::$CC->store('blockvis', $blks);
}
public static function blockorder($gname, $ref){
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
//if ( FALSE !== array_search($ref, $blks[$gname]) ){
if ( FALSE !== self::in_array($ref, $blks[$gname]) ){
$blks = $blks[$gname];
} else {
$blks = self::$BLKS[$gname];
}
} else {
$blks = self::$BLKS[$gname];
}
$o=1;
foreach($blks as $bref => &$blk){
if ( $ref == $bref ){ $r=$o; }
$o++;
}
if ( isset($r) ){ return $r; }
return 0;
}
public static function move_top($gname, $ref){
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
} else {
$blks = self::$BLKS[$gname];
}
$new[] = $ref;
foreach($blks[$gname] as $bref => &$vis){
if ( $ref !== $bref){ $new[] = $bref; }
}
foreach($new as $k => &$bref){ $tmp[$bref] = $blks[$gname][$bref]; }
$blks[$gname] = $tmp;
self::$CC->store('blockvis', $blks);
}
public static function move_bottom($gname, $ref){
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
} else {
$blks = self::$BLKS[$gname];
}
foreach($blks[$gname] as $bref => &$vis){
if ( $ref !== $bref){ $new[] = $bref; }
}
$new[] = $ref;
foreach($new as $k => &$bref){ $tmp[$bref] = $blks[$gname][$bref]; }
$blks[$gname] = $tmp;
self::$CC->store('blockvis', $blks);
}
public static function move_up($gname, $ref){
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
} else {
$blks = self::$BLKS[$gname];
}
$c=0;
foreach($blks[$gname] as $bref => &$vis){
if ( $ref !== $bref){
$new[] = $bref;
} elseif ( isset($new[($c-1)]) ){
$new[$c] = $new[($c-1)];
$new[($c-1)] = $bref;
} else {
$new[] = $bref;
}
$c++;
}
foreach($new as $k => &$bref){ $tmp[$bref] = $blks[$gname][$bref]; }
$blks[$gname] = $tmp;
self::$CC->store('blockvis', $blks);
}
public static function move_down($gname, $ref){
if ( !isset(self::$BLKS[$gname][$ref]) ){ return FALSE; }
self::loadCC();
if ( self::$CC->is_stored('blockvis') ){
$blks = self::$CC->get_stored('blockvis');
} else {
$blks = self::$BLKS[$gname];
}
$c=0;
foreach($blks[$gname] as $bref => &$vis){
if ( $ref !== $bref){
$new[] = $bref;
} elseif ( isset($new[($c+1)]) ){
$new[$c] = $new[($c+1)];
$new[($c+1)] = $bref;
} else {
$new[] = $bref;
}
$c++;
}
foreach($new as $k => &$bref){ $tmp[$bref] = $blks[$gname][$bref]; }
$blks[$gname] = $tmp;
self::$CC->store('blockvis', $blks);
}
}
return TRUE;