<?php
//
//	file: includes/class_file_handler.php
//	author: ptirhiik
//	begin: 05/03/2006
//	version: 1.6.0 - 10/06/2006
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//
//	based on : attachment_mod copyright (c) 2002 Meik Sievertsen (acydburn)
//

if ( !defined('IN_PHPBB') )
{
	die('Hacking attempt');
	exit;
}

class file_handler
{
	var $handler;
	var $method;

	function file_handler($ftp_config='')
	{
		if ( intval($ftp_config['allow_ftp_upload']) )
		{
			$this->handler = new file_handler_ftp($ftp_config['ftp_path'], $ftp_config['download_path'], $ftp_config['ftp_server'], $ftp_config['ftp_port'], $ftp_config['ftp_user'], $ftp_config['ftp_pass'], $ftp_config['ftp_pasv_mode']);
			$this->method = 'ftp';
		}
		else
		{
			$this->handler = new file_handler_copy($ftp_config['upload_dir'], $ftp_config['upload_dir']);
			$this->method = 'direct';
		}
	}

	function check_settings($ftp_dir='')
	{
		return $this->handler->check_settings($ftp_dir);
	}

	function get_download_url($src_file, $with_board_root=true)
	{
		return $this->handler->get_download_url($src_file, $with_board_root);
	}

	function path($filename)
	{
		return $this->handler->path($filename);
	}

	function open_channel($ftp_dir='')
	{
		return $this->handler->open_channel($ftp_dir);
	}

	function close_channel()
	{
		return $this->handler->close_channel();
	}

	function read_channel($ftp_dir, &$files, $file_prefix='')
	{
		return $this->handler->read_channel($ftp_dir, $files, $file_prefix);
	}

	function upload($src_file, $mimetype, $dst_file)
	{
		return $this->handler->upload($src_file, $mimetype, $dst_file);
	}

	function delete($filename)
	{
		return $this->handler->delete($filename);
	}

	function chmod($dst_file)
	{
		return $this->handler->chmod($dst_file);
	}

	function get_temporary_filename($src_file='', $dst_file='')
	{
		return $this->handler->get_temporary_filename($src_file, $dst_file);
	}

	function get_filesize($filename)
	{
		return $this->handler->get_filesize($filename);
	}

	function get_temporary($src_file, $mimetype)
	{
		return $this->handler->get_temporary($src_file, $mimetype);
	}

	function unlink_temporary($tmp_file)
	{
		return $this->handler->unlink_temporary($tmp_file);
	}

	function error()
	{
		global $user;
		return empty($this->handler->error) ? false : sprintf($user->lang($this->handler->error), $this->handler->error_parm);
	}

	function unlink($physical_filename, $thumbnail, $thumb_only=false)
	{
		if ( $physical_filename = basename($physical_filename) )
		{
			if ( !intval($thumb_only) )
			{
				$this->delete($this->path($physical_filename));
			}
			if ( intval($thumbnail) )
			{
				$this->delete($this->path(THUMB_DIR . '/t_' . $physical_filename));
			}
		}
	}
}

?>