<?php
chdir('..');
require_once ('api/Simpla.php');

/*
$width = isset($_GET['w']) ? $_GET['w'] : 241;
$height = isset($_GET['h']) ? $_GET['h'] : 160;
$crop = isset($_GET['cr']) ? (int)$_GET['cr'] : 1;
$filename = 'files/categories/' . $_GET['file'];
$filename = str_replace('%2F', '/', $filename);
//print_r($_GET);die;
if(isset($_GET['cr'])){
	
	$file = Img::get($filename, array('width' => $width, 'height' => $height, 'crop' => $crop));

	header('Content-type: image');
    echo file_get_contents($_SERVER['DOCUMENT_ROOT'] . $file);
    exit;
	
	
}

*/






$filename = $_GET['file'];
$token = $_GET['token'];
$filename = str_replace('%2F', '/', $filename);

if (substr($filename, 0, 6) == 'http:/')
    $filename = 'http://' . substr($filename, 6);

$simpla = new Simpla();
//if (!$simpla->config->check_token($filename, $token)) exit('bad token');

if (is_readable($simpla->config->page_images_dir . $filename))
    $resized_filename = $simpla->config->page_images_dir . $filename;
else
    $resized_filename = $simpla->image->resizepage($filename);

if (is_readable($resized_filename))
{
    header('Content-type: image');
    print file_get_contents($resized_filename);
}
