Location: PHPKode > projects > Simple Way to Usenet > libs/core/pgen/pfeats/pfeat_autorefresh.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 pfeat_autorefresh {
	
	private static $CC;
	const PROFILE = TRUE;
	const max = 3600;	
	
	public static function implent($pid){
		$conf 	= self::get_client_conf($pid);
		if ( $conf == FALSE ){ return; }
		if ( !$conf['inuse'] ){ return; }
		thm_mediaq::append_js_file('refresh_swapstate');
		thm_mediaq::append_js_file('autorefresh');
		if ( $conf['method'] == 'ajx' ){ ajax::RegisterFunction("contentrefresh"); }

	}
	
	public static function genpart($part, $of=FALSE){
		$pid 	= browsing::get_active();
		$conf 	= self::get_client_conf($pid);
		if ( $conf == FALSE ){ $conf['inuse'] = FALSE; }
		$o='';
		if ( $conf['inuse'] ){
			$o .= '| '.langs::translate('autorefresh', NULL, 'base');
			$resume = langs::dico_translate('resume', NULL, 'base');
			$pause = langs::dico_translate('pause', NULL, 'base');
			$o .= ' <span 	id="refreshtimer">'.$conf['time'].'</span>s :: 
					<span 	style="cursor:pointer" 
							id="refreshbutton" 
							onclick="refresh_swapstate(\''.$resume.'\', \''.$pause.'\', \''.$conf['method'].'\')" 
							>Pause</span>';
			$o .= '<script type="text/javascript" >autorefresh(\''.$resume.'\', \''.$pause.'\', \''.$conf['method'].'\');</script>';
		}
		if ( FALSE !== $of ){ call_user_func($of, $o);return; }
		return $o;
	}
	
	public static function genform($pids){
		foreach($pids as $pid => &$conf){
			$tmp = self::get_client_conf($pid);
			if ( $tmp == FALSE ){ 
				$o['inuse'] = FALSE; 
				$o['to'] = $conf;
				$o['method'] = 'js';
			} else {
				$o['to'] = $tmp['time'];
				$o['inuse'] = $tmp['inuse'];
				if ( $o['inuse'] ){
					$o['inuse'] = TRUE;
					if ( $o['to'] < $conf OR $o['to'] > self::max ){ $o['to'] = $conf; }
				} else {
					$o['to'] = $conf;
				}
				$o['method'] = $tmp['method'];
			}
			$o['pname'] = pages::get_title($pid);
			$o['min'] = $conf;
			$b['pages'][$pid] = $o;
			unset($o);
		}
		return $b;
	}
	
	public static function get_client_conf($pid, $min=NULL, $dft=30){
		if ( ! isset(self::$CC) ){ 
			$run 		= Array(client_configs::SESSION=>'profile');
			$store		= Array(client_configs::PROFILE=>'site_profile');
			$run_update  = Array(client_configs::POST=>'');
			$store_update= Array(client_configs::POST=>'');
			self::$CC = new client_configs($run, $store, $run_update, $store_update);
			unset($run, $store, $run_update, $store_update);
		} 
		$k = 'autorefresh_'.$pid;
		if ( self::$CC->is_updated($k) ){
			$new = self::$CC->get_updated($k);
			if ( !isset($new['inuse']) ){ $new['inuse'] = FALSE; }
			if ( isset($new['time']) ){
				if ( $min !== NULL AND $new['time'] < $min ){ $new['time']=$dft; }
			} else {
				$new['time']=$dft;
			}
			if ( isset($new['method']) ){
				if ( $new['method'] !== 'js' AND $new['method'] !== 'ajx' ){ $new['method']='js'; }
			} else {
				$new['method']='js';
			}
			self::$CC->store($k, $new, NULL);
		}
		return self::$CC->get_stored($k);
	}
		
}
return TRUE;
Return current item: Simple Way to Usenet