Location: PHPKode > projects > PHPture > phpture/info.php
<?php

header('Content-Type: text/html; charset=UTF-8');

?><!DOCTYPE html>
<html>
<head>
<title>info</title>
<link rel="stylesheet" href="style/info.css" type="text/css">
<script type="text/javascript" src="script/info.js"></script>
</head>
<body>
<?php

/**
 * @param string $name A filename with an extension seperated with a dot, for example 'image123.jpg'.
 * @return string The filename without the extension (any text after the last occuring dot. For example: 'image123'.
*/
function stripExtension($name) {
	
	if($pos = strrpos($name, '.')) {
		$name = substr($name, 0, $pos);
	}
		
	return $name;
}

function getFormattedDate($float) {

	if(is_array($float) && isset($float['date'])) {
		$float = $float['date'];
	}

	$date = intval($float);
	
	$year = intval(date('Y', $date)) + 31; //add 31 years
	$date += 86400; // add 1 day
	$date += 3600; //add 1 hour

	return date('m/d/'.$year.' H:i:s ', $date);
}

/**
Convert rating to a number of stars.
*/
function getRating($image, $png = false) {
	
	if($image['rating'] < 0) {
		
		if($png) {
			return '<img src="media/icon/rejected.png" alt="x">';
		}
		return 'x';
	}
	
	
	$output = '';
	
	for($i = 0; $i < $image['rating']; $i++) {
		
		if($png) {
			$output .= '<img src="media/icon/star.png" alt="*">';
		} else {
			$output .= '*';
		}
	}

	return $output;
}

/**
Convert a number of bytes to a string that is more easier to read for humans.
*/
function friendlyFileSize($bytes) {

	if($bytes < 1024) {
		// 1 - 1024 B
		return $bytes.' B';
	} elseif($bytes < 1048576) {
		// 1 - 1024 KB
		return round($bytes / 1024).' KB';
	} elseif($bytes < 104857600) {
		// 1 - 100 MB
		return (round(($bytes / 1048576) * 10) / 10).' MB';
	} elseif($bytes < 1073741824) {
		// 100 - 1024 MB
		return round($bytes / 1048576).' MB';
	} else {
		// 1 GB and up
		return round($bytes / 1073741824).' GB';
	}
}

/**
Extract the filename from a path.
* @param string $path A string containing a path on the file system or URL.
*/
function getLastFileFromPath($path) {
	
	$path = explode('/', $path);
	
	return array_pop($path);
}


require_once('conf.php');
require_once('language/lang.'.LANGUAGE.'.php');

$version_id = 0;

if(isset($_GET['id'])) {
	
	$version_id = intval($_GET['id']);
}

if(!$version_id > 0) {
	
	echo('No image selected.');
	exit();
}

$db = new PDO('sqlite:'.DATABASE_PATH);

$output ='';

$version = array();

//get the standard information from this version
foreach($db->query('SELECT ZVERSIONID, ZMASTERUUID, ZUUID, ZPROCESSEDWIDTH, ZPROCESSEDHEIGHT, ZMASTERHEIGHT, ZMASTERWIDTH, ZIMAGEDATE, ZTHUMBNAILPREVIEWPATH, ZPROJECTUUID, ZFULLSIZEPREVIEWPATH, ZMAINRATING, ZNAME, ZFILEUUID ZMASTER FROM ZRKVERSION WHERE ZVERSIONID='.sqlite_escape_string($version_id)) as $row) {

	$version = array(
		'PixelSize' => $row['ZPROCESSEDWIDTH'].' x '.$row['ZPROCESSEDHEIGHT'],
		'MasterSize' => $row['ZMASTERWIDTH'].' x '.$row['ZMASTERHEIGHT'],
		'VersionName' => $row['ZNAME'],
		'Rating' => getRating($row['ZMAINRATING'], true),
		'PreviewFile' => '<a href="image.preview.php?id='.$row['ZVERSIONID'].'" type="image/jpeg" target="_blank" title="Download preview file">'.getLastFileFromPath($row['ZFULLSIZEPREVIEWPATH']).'</a>'
	);
	
	$master_id = $row['ZMASTERUUID'];
}

//get all the properties of this version
foreach($db->query("SELECT PI.ZPROPERTYKEY, SP.ZPROPERTYSPECIFICSTRING FROM ZRKSEARCHABLEPROPERTY AS SP, ZRKPROPERTYIDENTIFIER AS PI WHERE PI.ZUUID=SP.ZPROPERTYIDENTIFIERUUID AND SP.ZPROPERTYSPECIFICSTRING NOTNULL AND SP.ZVERSIONID=".$version_id) as $row) {

	$version[$row[0]] = $row[1];
}

if(isset($version['VersionName'])) {
	$output .= '<h2>'.$version['VersionName'].'</h2>';
}

foreach($version as $key => $value) {
	
	$output .= '<p><b>'.strtr($key, $translation).':</b> <span>'.$value.'</span></p>';
}

//get information about the master image
if(isset($master_id)) {

	foreach($db->query("SELECT M.Z_PK, M.ZIMPORTGROUP, M.ZNAME, FI.ZIMAGEPATH, FI.ZFILESIZE, FI.ZNAME AS ZFILENAME, FI.ZFILEISREFERENCE, FI.ZFILEMODIFICATIONDATE, FI.ZEXTENSION, FI.ZFILESIZE, F.ZNAME AS PROJECTNAME, FI.ZISMISSING FROM ZRKMASTER AS M, ZRKFILE AS FI, ZRKFOLDER AS F WHERE M.ZORIGINALFILEUUID=FI.ZUUID AND M.ZPROJECTUUID=F.ZUUID AND M.ZUUID='".$master_id."'") as $row) {


		$master = array(		
		'MasterName' => $row['ZNAME'],
		'MasterFile' => $row['ZFILENAME'],
		'MasterFileSize' => friendlyFileSize($row['ZFILESIZE']),
		'MasterDateModified' => getFormattedDate($row['ZFILEMODIFICATIONDATE']),
		'MasterLocation' => stripExtension($row['PROJECTNAME']),
		'ImportGroup' => stripExtension($row['ZIMPORTGROUP'])

		);
		
		if(intval($row['ZFILEISREFERENCE']) && !empty($row['ZIMAGEPATH'])) {
			$master['ReferencedMasterPath'] = $row['ZIMAGEPATH'];
		
			if(intval($row['ZISMISSING'])) {
				$master['ReferencedMasterPath'] .= ' <span style="color:red">(is missing)</span>';	
			} if(!is_readable($master['ReferencedMasterPath'])) {
				$master['ReferencedMasterPath'] .= ' <span style="color:red">(not readable)</span>';
			}
		}
		
		if(intval($row['ZISMISSING'])) {
			$master['MasterFile'] .= ' <span style="color:red">(is missing)</span>';
		} elseif(SHARE_MASTER) {
			$master['MasterFile'] = '<a href="image.master.php?id='.$row['Z_PK'].'" target="_blank">'.$master['MasterFile'].'</a>';
		}
	}

}

$output .= '<h2>Master</h2>';

if(isset($master)) {

	foreach($master as $key => $value) {
	
		if(!empty($value)) {
	
			$output .= '<p><b>'.strtr($key,$translation).':</b> <span>'.$value.'</span></p>';
		}
}


}

$keyword_list = array();
$keywords = array();
$parents = array();

foreach($db->query("SELECT ZUUID, ZNAME, ZPARENTUUID FROM ZRKKEYWORD") as $row) {
	
	$keyword = array(
		'id' => $row['ZUUID'],
		'name' => $row['ZNAME'],
		'parent' => $row['ZPARENTUUID']
	);
	
	$keywords[$keyword['id']] = $keyword;
	$parents[$keyword['parent']] = $keyword['id'];
}

/**
Get all keywords with $id as parent.
*/
function getKeywords($id) {

	global $keywords, $parents;

	if(!empty($id)) {
	
		$keyword = $keywords[$id];
	
		$output = array('<a href="browser.php?keyword_id='.$keyword['id'].'" onclick="return setBrowser(\'keyword_id='.$keyword['id'].'\')" target="browser">'.$keyword['name'].'</a>');

		if($words = getKeywords($keyword['parent'])) {
			$output = array_merge($output, $words);
		}

		return $output;
	}
}

/**
Create a path in HTML to the keyword with clickable parents.
*/
function getKeywordPath($id) {
	
	$path = getKeywords($id);
	
	$output = $path[0];
	
	if(count($path) > 1) {
	
		unset($path[0]);
		
		$output .= ' <small>('.implode(' &gt; ', $path).')</small>';
	}
	
	return $output;
}

//get all keywords for this version, create a path and put it in a list.
foreach($db->query("SELECT ZKEYWORDUUID FROM ZRKXKEYWORDVERSION WHERE ZVERSIONID='".$version_id."'") as $row) {
	
	$keyword_list[] = getKeywordPath($row[0]);	
}

//if there are keywords associated with this version, display them.
if(count($keyword_list) > 0) {
	
	$output .= '<h2>Keywords</h2>';

	foreach($keyword_list as $keyword) {
			
		$output .= '<p>'.$keyword.'</p>';
	}
}

echo($output);

?>
</body>
</html>
Return current item: PHPture