<?php

// -----------------------------------------------------------------------
// This file is part of AROUNDMe
//
// Copyright (C) 2003 - 2007 Barnraiser
// http://www.barnraiser.org/
// info@barnraiser.org
//
// 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, 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.
//
// You should have received a copy of the GNU General Public License
// along with program; see the file COPYING. If not, write to the Free
// Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
// 02110-1301, USA.
// -----------------------------------------------------------------------

include "components/core/config/aroundme_core.config.php";


if (!empty($_REQUEST['reloadsession'])) {
	session_name($core_config['node']['php_session_name']);
	session_start();
	$_SESSION['last_session_access_time'] = time();
	session_write_close();
}


$temp = explode('-', $_REQUEST['file']);

if (isset($core_config['module'][$temp[0]]['prefix'])) {
	$directory = $core_config['module'][$temp[0]]['prefix'] . "/";
}
else {
	$directory = "core/";
}

$file = $temp[1];

if (count($temp) == 3) {
	$directory .= "thumbs/";
	$file .= $temp[2];
}


$path = $core_config['file']['dir'] . $directory . $file;
//echo $path;
//exit;
	
if (is_file($path)) {
	// we check to see if we got a MIME type
	if (isset($temp[3])) {
		foreach($core_config['file']['mime'] as $key => $i):
			if ($i['mime'] == $temp[3]) {
				header("Content-type: ".$temp[3]);
				break;
			}
		endforeach;
	}
	
	readfile($path);

} 
else {
// 	header("Content-type: image/png");
	readfile($core_config['file']['dir'] . 'core/broken_image.png');
}

?>