Ejemplo n.º 1
1
function processImage($uploadDir, $filename)
{
    $uploadedFile = combine($uploadDir, $filename);
    //save exif data
    $message = "File uploaded.";
    $exif = getImageMetadata($uploadedFile);
    $dateTaken = getExifDateTaken($uploadedFile, $exif);
    if (!$dateTaken) {
        $dateTaken = getDateFromFilename($filename);
    }
    if (!$dateTaken) {
        $dateTaken = getFileDate($uploadedFile);
    }
    $exif["dateTaken"] = $dateTaken;
    $description = arrayGetCoalesce($exif, "ImageDescription", "IPTC.Caption");
    $description = trim($description);
    writeCsvFile("{$uploadedFile}.txt", $exif);
    writeTextFile("{$uploadedFile}.js", jsValue($exif));
    //resize images and keep hd version
    $sizes = getConfig("thumbnails.sizes");
    $resized = resizeMultiple($uploadDir, $filename, $sizes);
    $keep = getConfig("thumbnails.keep");
    if ($keep) {
        moveFile("{$uploadDir}/.{$keep}", $filename, $uploadDir);
        deleteDir("{$uploadDir}/.{$keep}");
        unset($resized[$keep]);
    }
    if ($dateTaken) {
        setFileDate($uploadedFile, $dateTaken);
    }
    $vars = get_defined_vars();
    $result = array();
    $exif["meal"] = selectMeal($dateTaken);
    $result["_exif"] = $exif;
    $result["success"] = true;
    return addVarsToArray($result, "filename filesize mimeType dateTaken description", $vars);
}
Ejemplo n.º 2
0
function preview($currImage)
{
    global $baseURL, $scriptPath, $dir, $gallery_images_in_preview, $galleryWidth, $enable_caption_editing, $loadingGif, $enableHTMLlinks, $enableBBCodelinks;
    # Scan the folder for pictures & thumbnails
    $folder_scan_results = folder_scan();
    # Find Images with Thumbnails.
    $images_with_thumbs = images_with_thumbnails($folder_scan_results['images']);
    $noThumbs = count($folder_scan_results['images']) - count($images_with_thumbs);
    # Find where the current image is in the list of images.
    $imageIndex = array_search($currImage, $images_with_thumbs);
    if (empty($imageIndex)) {
        $imageIndex = 0;
    }
    # If somehow the user tries to preview an image  that doesn't exist, just go back to gallery view.
    if ($imageIndex === NULL) {
        header("Location:" . rrawurlencode($baseURL . $dir));
    }
    # Load the Captions
    $captions = get_captions();
    foreach ($images_with_thumbs as $idx => $image) {
        $captions[$idx] = str_replace(array("\r", "\n"), array("", "<br>"), htmlentities($captions[$image]));
    }
    /*
    In folder with 300 images in it, each of these functions was run 100 times. (30,000 times times per function). This is how long those took:
    getimagesize: 8.4805779743195
    captions: 0.11382412910461
    imgName: 0.13228607177734
    getFileSize: 1.2750179767609
    getFileDate: 13.157135009766
    fullLink : 0.33402609825134
    preview: 0.41940498352051
    gallery: 0.45263981819153
    So everything gets cached to disk if it can be.
    */
    # Attempt to load the cache file.
    if ($cache = @unserialize(file_get_contents($scriptPath . "cache/" . $dir . "cache"))) {
        #Extract all the variables
        //$num_cached_images = $cache["images_with_thumbs"];
        $fileSize = $cache["fileSize"];
        $exifDate = $cache["exifDate"];
        $imgName = $cache["imgName"];
        $fullLinkURL = $cache["fullLinkURL"];
        $preview = $cache["preview"];
        $gallery = $cache["gallery"];
        $bbCode = $cache["bbcode"];
        $html = $cache["html"];
    }
    # Determine the uncached images.
    $uncached_images = count($images_with_thumbs) - $num_cached_images;
    # Rebuild cache if there were any changes.
    if ($uncached_images) {
        //if (1) {
        # Clean out any old data and create arrays
        $bbCode = $html = $fileSize = $exifDate = $imgName = $fullLinkURL = $preview = $gallery = array();
        foreach ($images_with_thumbs as $idx => $image) {
            $hardlinks = hardlinks($image);
            $bbCode[$idx] = $hardlinks["bbCode"];
            $html[$idx] = $hardlinks["html"];
            $fileSize[$idx] = getFileSize($scriptPath . $dir . $image);
            $exifDate[$idx] = getFileDate($scriptPath . $dir . $image);
            $imgName[$idx] = addslashes(pathinfo($image, PATHINFO_FILENAME));
            $fullLinkURL[$idx] = rrawurlencode($baseURL . $dir . $image);
            $preview[$idx] = rrawurlencode($baseURL . "cache/" . $dir . "preview/" . $image);
            $gallery[$idx] = rrawurlencode($baseURL . "cache/" . $dir . "gallery/" . $image);
        }
        # If there was a cache change.
        $cache["images_with_thumbs"] = count($images_with_thumbs);
        $cache["fileSize"] = $fileSize;
        $cache["exifDate"] = $exifDate;
        $cache["imgName"] = $imgName;
        $cache["fullLinkURL"] = $fullLinkURL;
        $cache["preview"] = $preview;
        $cache["gallery"] = $gallery;
        $cache["bbcode"] = $bbCode;
        $cache["html"] = $html;
        file_put_contents($scriptPath . "cache/" . $dir . "cache", serialize($cache));
    }
    # Count the number of images, used for wrap around math.
    $imageCount = count($images_with_thumbs);
    for ($i = -$gallery_images_in_preview; $i <= $gallery_images_in_preview; $i++) {
        # Build the array +- image_previews.
        $slide_previews[$i] = $gallery[($imageIndex + $i + $imageCount) % $imageCount];
    }
    $title = $imgName[$imageIndex];
    if (function_exists("printheader")) {
        printheader($title);
    } else {
        html_header($title);
    }
    if ($enable_caption_editing) {
        echo "<a href=\"" . rrawurlencode($baseURL . "captions/" . $dir) . "\">Edit Captions</a>\n";
    }
    # Print the directory path.
    printPath();
    ?>
<!-- Begin Previews -->
<div id="preview">
<span id="navDirections"></span>
<div id="leftpreview">
<?php 
    for ($i = -$gallery_images_in_preview; $i <= -1; $i++) {
        echo "\t<img src=\"" . $slide_previews[$i] . "\" id=\"gallery{$i}\" width=\"{$galleryWidth}\" alt=\"gallery{$i}\" onclick=\"changePicture({$i});return false;\">\n";
    }
    ?>
</div>
<div id="rightpreview">
<?php 
    for ($i = 1; $i <= $gallery_images_in_preview; $i++) {
        echo "\t<img src=\"" . $slide_previews[$i] . "\" id=\"gallery{$i}\" width=\"{$galleryWidth}\" alt=\"gallery{$i}\" onclick=\"changePicture({$i});return false;\">\n";
    }
    ?>
</div>
<div id="centerpreview">
	<center>
		<a href="<?php 
    echo $preview[($imageIndex + 1 + $imageCount) % $imageCount];
    ?>
"  id="nextLink" onclick="changePicture(1);return false;">
			<img src="<?php 
    echo $preview[$imageIndex];
    ?>
" alt="Current Preview" id="mainPreview">
		</a>
		<br>
		<a href="<?php 
    echo $fullLinkURL[$imageIndex];
    ?>
" target="_new" id="fullLink">Link to Full Picture (<?php 
    echo $fileSize[$imageIndex];
    ?>
)</a><br>
		<div id="caption" style="display:<?php 
    echo empty($captions[$imageIndex]) ? "none" : "block";
    ?>
"><?php 
    echo str_replace("\n", "<br>", htmlentities($captions[$imageIndex]));
    ?>
</div>
		<div id="timeStamp" style="display:<?php 
    echo empty($exifDate[$imageIndex]) ? "none" : "block";
    ?>
"><?php 
    echo $exifDate[$imageIndex];
    ?>
	</div>
		<?php 
    if ($enableBBCodelinks) {
        echo "<div><input type=\"text\" size=\"100\" value=\"" . $bbCode[$imageIndex] . "\" id=\"bbCodeLink\"></div>\n";
    }
    if ($enableHTMLlinks) {
        echo "<div><input type=\"text\" size=\"100\" value=\"" . $html[$imageIndex] . "\" id=\"htmlLink\"></div>\n";
    }
    ?>
	</center>
	<img src="<?php 
    echo $slide_previews[0];
    ?>
" id="gallery0" class="cache" alt='cache'>
	<?php 
    echo display_generating_thumbnails($noThumbs);
    ?>
	<?php 
    /* The current index of the image */
    ?>
	<div style="display:none" id="imageIndex"><?php 
    echo $imageIndex;
    ?>
</div>
	<div style="clear:both;"></div>
</div>
</div>
<div id="end_javascript">
<script type="text/javascript">
<!--
var previewSrc = Array();
var gallerySrc = Array();
var fullLinkURL = Array();
var imgSize = Array();
var timeStamp = Array();
var imgName = Array();
var caption = Array();
var bbCode= Array();
var html=Array();
<?php 
    for ($i = 0; $i < $imageCount; $i++) {
        echo "previewSrc[{$i}]=\"" . $preview[$i] . "\";\n";
        echo "gallerySrc[{$i}]=\"" . $gallery[$i] . "\";\n";
        echo "fullLinkURL[{$i}]=\"" . $fullLinkURL[$i] . "\";\n";
        echo "imgName[{$i}]=\"" . $imgName[$i] . "\";\n";
        echo "imgSize[{$i}]=\"Link To Full Picture (" . $fileSize[$i] . ")\";\n";
        echo "timeStamp[{$i}]=\"" . $exifDate[$i] . "\"\n";
        echo "bbCode[{$i}]=\"" . $bbCode[$i] . "\"\n";
        echo "html[{$i}]=\"" . str_replace("/", "\\/", $html[$i]) . "\"\n";
        echo "caption[{$i}]=\"" . $captions[$i] . "\";\n\n";
    }
    ?>
function $(e) {return document.getElementById(e);}
function keyBoardNav(e) {
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	switch(KeyID) {
		// Left Arrow
		case 37:
			changePicture(-1);
			break;
		// Space Bar
		case 32:
		// Right Arrow
		case 39:
			changePicture(1);
			break;
		default:
			return true;
	}	
}
function changePicture(imgChg) {
	var imgIdx=parseInt($('imageIndex').innerHTML)+imgChg;
	// Calculate the wrap around math. If the user scrolls past first or last image
	if (imgIdx<0) {
		imgIdx=previewSrc.length-1;
	} else if (imgIdx>=previewSrc.length) {
		imgIdx=0;
	}
	$('mainPreview').src=previewSrc[imgIdx];
	$('mainPreview').title=caption[imgIdx];
	try {
	<?php 
    if ($enableBBCodelinks) {
        echo "\$('bbCodeLink').value=bbCode[imgIdx];\n";
    }
    if ($enableHTMLlinks) {
        echo "\$('htmlLink').value=html[imgIdx];\n";
    }
    ?>
	} catch (e) {
		alert(e);
	}
	var l=previewSrc.length;
	for (i=-<?php 
    echo $gallery_images_in_preview;
    ?>
;i<=<?php 
    echo $gallery_images_in_preview;
    ?>
;i++) {
		try {
			$('gallery'+i).src=gallerySrc[(l+imgIdx+i)%l];
		} catch(err) {
		}
	}
	// Change the document title and hash.
	document.title=(imgName[imgIdx]);
	document.location.hash=(imgName[imgIdx]);
	// Set the new current image index.
	$('imageIndex').innerHTML=imgIdx;
	// Change the full image url
	$('fullLink').href=fullLinkURL[imgIdx];
	// Change the inner html
	$('fullLink').innerHTML=imgSize[imgIdx];
	if (timeStamp[imgIdx]=="") {
		$('timeStamp').style.display="none";
	} else {
		$('timeStamp').style.display="block";
		$('timeStamp').innerHTML=timeStamp[imgIdx];
	}
	if (caption[imgIdx]=="") {
		$('caption').style.display="none";
	} else {
		$('caption').style.display="block";
		$('caption').innerHTML=caption[imgIdx];
	}
	$('navDirections').innerHTML="";
}
<?php 
    /*
    If the url has a hash, attempt to locate the picture in the picture array. If it does, swap the image to that one. 
    This helps if people scroll left or right from a picture then send a link of the image to someone.
    */
    ?>
if (window.location.hash.substring(1)!="") {
	var newImg=window.location.hash.substring(1);
	for (i in imgName) {
		if (imgName[i]==newImg) {
			changePicture(i-parseInt($('imageIndex').innerHTML));
			break;
		}
	}
}
<?php 
    /*
    Display a 'loading previews' image. 
    
    Once the page is loaded (all images too) then display the 'use arrow keys' message.
    */
    ?>
$('navDirections').innerHTML="<img alt='Loading Previews' src='<?php 
    echo $loadingGif;
    ?>
' title='Loading Previews'><br>Loading Preview Images.<br>Use arrow keys to navigate pictures.";
window.onload=function(){document.onkeydown = keyBoardNav;$('navDirections').innerHTML=["Use arrow keys to navigate pictures"];};
// -->
</script>
</div>
<div id="cache">
<?php 
    /* Javascript or CSS Image Caching... */
    if (false) {
        echo "<script language=\"JavaScript\">";
        for ($i = $gallery_images_in_preview; $i < count($images_with_thumbs) - $gallery_images_in_preview; $i++) {
            $q = ($i + $imageIndex) % count($images_with_thumbs);
            $x++;
            echo "pic{$x}= new Image();";
            echo "pic{$x}.src=\"" . $preview[$q] . "\";\n";
            $x++;
            echo "pic{$x}= new Image();";
            echo "pic{$x}.src=\"" . $gallery[$q] . "\";\n";
        }
        echo "</script>";
    } else {
        for ($i = $gallery_images_in_preview; $i < count($images_with_thumbs) - $gallery_images_in_preview; $i++) {
            $q = ($i + $imageIndex) % count($images_with_thumbs);
            echo "<img src=\"" . $preview[$q] . "\" class='cache' alt='cache'>\n";
            echo "<img src=\"" . $gallery[$q] . "\" class='cache' alt='cache'>\n";
        }
    }
    ?>
</div>
<?php 
    if (function_exists("printfooter")) {
        printfooter($title);
    } else {
        html_footer($title);
    }
}
Ejemplo n.º 3
0
#var_dump(getFileList("log/420"));
print "<html><body><center>";
if (isset($_POST["idx"])) {
    remove_directory("log/" . $_POST["idx"]);
}
print "<table  border=\"2\" rules=\"all\">";
print "<tr>";
print "<th>idx</th>";
print "<th>date</th>";
print "<th>log</th>";
print "<th></th>";
print "</tr>";
foreach ($file_list as $fl) {
    $idx = $fl->idx;
    print "<tr><td>" . $fl->idx . "</td>";
    print "<td>" . getFileDate(log . "/" . $fl->idx) . "</td>";
    print "<td><center>";
    $room_cnt = array();
    foreach ($fl->file_list as $name) {
        #print $name.",";
        $split_name = explode("/", $name);
        if ($room_cnt[$split_name[2]] > 0) {
            continue;
        }
        $room_cnt[$split_name[2]]++;
        if (strstr($split_name[2], "room")) {
            $location = "log/{$fl->idx}/{$split_name['2']}/result";
        } else {
            $location = "log/{$fl->idx}/{$split_name['2']}";
        }
        print "<a href=\"{$location}\">" . $split_name[2] . "</a>" . ",";