<?php if(!defined('master_script')) die();

/**
 * Default settings
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2009-09-07
 */

	global $system_data, $imageinfo;
	
	if(!isset($module_settings['image']['show image'])) $module_settings['image']['show image'] = '';
	if(!isset($module_settings['image']['image width'])) $module_settings['image']['image width'] = 800;
	if(!isset($module_settings['image']['image height'])) $module_settings['image']['image height'] = 0;
	if(!isset($module_settings['image']['show image title'])) $module_settings['image']['show image title'] = 1;
	if(!isset($module_settings['image']['show image description'])) $module_settings['image']['show image description'] = 1;

/**
 * Languages
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2010-07-28
 */

	$modules['image']['key'] = 'image';
	include_txt($modules['image']['key'], $system_data['folder']['modules'] . $modules['image']['key'] . '/languages/');
	include_txt($modules['image']['key'], $system_data['folder']['settings'] . 'modules/' . $modules['image']['key'] . '/languages/');

/**
 * Get data for image
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   2011-06-01
 */

	// Simulate content if feed strip tags
	if(defined('feed_script')) echo '&shy;';
	
	// Get image data
	if(is_file($module_settings['image']['show image'])) {
		$imageinfo = pathinfo($module_settings['image']['show image']);
		
		$imageinfo['file'] = $module_settings['image']['show image'];
		$imageinfo['xml file'] = $imageinfo['dirname'] . '/storage/' . $imageinfo['basename'] . '.xml';
		
		$imageinfo['title'] = '';
		$imageinfo['description'] = '';
		
    	// Set dimensions
		$imagedata = getimagesize($imageinfo['file']);
    	
   		if($module_settings["image"]["image width"] > $imagedata[0]) $module_settings["image"]["image width"] = $imagedata[0];
   		if($module_settings["image"]["image height"] > $imagedata[1]) $module_settings["image"]["image height"] = $imagedata[1];
   		
    	if($module_settings["image"]["image width"] != 0 && $module_settings["image"]["image height"] != 0)
    		$image_static_dimensions = $imagedata[0] > $imagedata[1] ? 'horizontal' : 'vertical';
    	else
    		$image_static_dimensions = 'none';
    	
    	if(($module_settings["image"]["image width"] == 0 && $module_settings["image"]["image height"] != 0) || $image_static_dimensions == 'vertical') {
   			$imageinfo['width'] = floor($module_settings["image"]["image height"] * $imagedata[0] / $imagedata[1]);
   			$imageinfo['height'] = $module_settings["image"]["image height"];
    	} else if(($module_settings["image"]["image height"] == 0 && $module_settings["image"]["image width"] != 0) || $image_static_dimensions == 'horizontal') {
   			$imageinfo['width'] = $module_settings["image"]["image width"];
   			$imageinfo['height'] = floor($module_settings["image"]["image width"] * $imagedata[1] / $imagedata[0]);
    	}
    	
		// Set default dimensions
		if(!isset($imageinfo['width'])) $imageinfo['width'] = $imagedata[0];
		if(!isset($imageinfo['height'])) $imageinfo['height'] = $imagedata[1];
    	
    	// Get image properties
    	if(is_file($imageinfo['xml file'])) {
    		$image_xml = simplexml_load_file($imageinfo['xml file']);
    		$imageinfo['title'] = $image_xml->title[0];
    		$imageinfo['description'] = $image_xml->description[0];
    	}
	}
	
/**
 * Include module frontend template
 *
 * @category   Module (image)
 * @author     Nico Wenig <nico.wenig@yellowgreen.de>
 * @version	   1.0
 */

	include_template('image');

?>