Location: PHPKode > projects > Simple Way to Usenet > libs/core/themes/tfeats/tfeat_ajaxupload.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 tfeat_ajaxupload {
	
	const PROFILE = FALSE;
	
	public function __construct(){ }
	
	public static function implent(){
		if ( !isset($_GET['ajxupl']) ){
			ajax::RegisterFunction('uplsend');
			ajax::RegisterFunction('uplreply'); 
			return; 
		}
		$tpl = new template();
		$tpl->output_function('langs::output_for_client');
		$data['hash'] = '';
		if ( FALSE === $tpl->load_file('core/ajaxuplcb.tpl') ){ return FALSE; }
		if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
			$hash = CORE::hash();
			sessions::set('ajxupl_vars_'.$hash, $_POST);
			sessions::set('ajxupl_files_'.$hash, self::recur_uplfile_move($_FILES));
			$data['hash'] = $hash;
		}
		$data['lang'] = langs::lang();
		$data['charset'] = langs::charset();
		$tpl->setdata($data);
		$tpl->parse();
		exit;
	}
	
	private static function recur_uplfile_move($file){
		if ( is_array($file) ){
			if ( isset($file['tmp_name']) ){
				if ( !$file['error'] ){
					$n = CORE::tempfile();
					if ( FALSE !== file_abstract::move(NULL, $file['tmp_name'], NULL, $n) ){
						$file['tmp_name'] = $n;
						$file['catched'] = TRUE;
					}
				} 
			} else {
				foreach($file as $k => &$entry){ $entry = self::recur_uplfile_move($entry); }
			}
		}
		return $file;
	}
	
	public static function genpart($part, $of=FALSE){
		$o = '<input type="hidden" id="ajxuplcb_'.$part.'" name="ajxuplcb" value="" />';
		$o .= '<iframe style="visibility:hidden;overflow:hidden;position:absolute;height:0px;width:0px" name="ajxuplreceptor_'.$part.'" src="?ajxupl="></iframe>';
		if ( !$of ){ return $o; } 
		call_user_func($of, $o); 
	}
}
return TRUE;
Return current item: Simple Way to Usenet