You don't have an album description file. Please fix this.
";
}
}
function sortByTitle($a,$b) {
return strnatcasecmp($a['title'],$b['title']);
}
// Store images in photo Array
function numImages($albumGet) {
unset($this->photos);
if (file_exists(dirRoot."/".$albumGet.'/'.imageDir)) {
$dirimages = opendir(dirRoot."/".$albumGet."/".imageDir)
or print("We can't open the correct directory!");
$photocount = 0;
while ($files = readdir($dirimages) ) {
if (preg_match('/.*\.(jpg|png|gif|JPG|PNG|GIF)/',$files) && !@strstr($files,skipIfContains)) {
$photocount = $photocount + 1;
$this->photos[$photocount]['name'] = $files;
}
}
} else {
echo "',$page);
}
function head () {
echo '
PhotoStack
';
if($_COOKIE['PhotoStack'] && $_GET['logout'] != 'yes') {
echo '
';
if(
$_GET['__mode'] == 'deletePhotos' or
$_GET['__mode'] == 'addPhotos' or
$_GET['__mode'] == 'editAlbum' or
$_GET['__mode'] == 'editDesc' ) {
$this->displayData->rawTemplate('
');
}
}
echo '
';
}
function foot () {
echo '
';
}
function defaultDisplay() {
$this->displayData->rawTemplate('
Your Photo Albums
Tips
To the left are your current albums, click them to edit photos move the album to another folder, rename, the album, and edit photo descriptions.
Tasks
');
}
function ftpConnect() {
$ftp = ftp_connect(ftpHost);
$login_result = ftp_login($ftp, ftpUsername, ftpPassword);
// check connection
if (!$ftp or !$login_result) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
}
ftp_pasv($ftp, true);
ftp_chdir($ftp, ftpDir.'/');
return $ftp;
}
#This function is so fucked up looking.
function ftpUpload ($files, $ftp) {
if($files) {
$forshell = escapeshellcmd($_POST['albumFolder']);
$print .= '
';
# Count how many files to try and upload
$count = count($files['upload_file']['name']);
for($i = 0; $i <= $count - 1; $i++) {
# If the file is '' then don't upload it.
if(eregi('.*\.zip$',$files['upload_file']['name'][$i])) {
if(ftp_put($ftp, $files['upload_file']['name'][$i], $files['upload_file']['tmp_name'][$i], FTP_BINARY)) {
if(file_exists(dirRoot.'/'.$_POST['albumFolder'].'/'.$files['upload_file']['name'][$i])) {
$perms = substr(sprintf("%o", fileperms(dirRoot.'/'.$_POST['albumFolder'].'/')), '2');
if(ftp_site($ftp, 'CHMOD 777 '.ftpDir.'/'.$_POST['albumFolder'].'/')) {
exec('cd '.dirRoot.'/'.$forshell.'/; pwd; '.
'/usr/bin/unzip -o '.dirRoot.'/'.$forshell.'/'.$files['upload_file']['name'][$i]);
ftp_site($ftp, 'CHMOD '.$perms.' '.ftpDir.'/'.$_POST['albumFolder'].'/');
ftp_delete($ftp, ftpDir.'/'.$_POST['albumFolder'].'/'.$files['upload_file']['name'][$i]);
$print .= ''.$files['upload_file']['name'][$i].' was successfully unzipped. ';
} else {
$print .= 'An error occured. Your FTP server does not support the SITE set of commands. ';
}
}
}
} elseif ($files['upload_file']['name'][$i] != '' &&
preg_match('/.*\.(txt|jpg|png|gif|JPG|PNG|TXT|GIF)/',$files['upload_file']['name'][$i])) {
if(ftp_put($ftp, $files['upload_file']['name'][$i], $files['upload_file']['tmp_name'][$i], FTP_BINARY)) {
$print .= ''.$files['upload_file']['name'][$i].' was uploaded successfully. ';
}
} elseif ($files['upload_file']['name'][$i] != '') {
$print .= ''.$files['upload_file']['name'][$i].' - An encountered file has an unsuitable extension for uploading. ';
}
}
$print .= ' ';
return $print;
}
}
function addAlbum() {
if($_POST['edit'] == 'yes' && $_POST['albumFolder'] != '' && $_POST['albumTitle'] != '') {
/*$_POST['albumFolder'] = stripslashes($_POST['albumFolder']);
$_POST['albumTitle'] = stripslashes($_POST['albumTitle']);*/
echo '
Creating New Album ';
$ftp = $this->ftpConnect();
# Create temp file and get old album data
/*$temp = tmpfile();
if(@ftp_fget($ftp, $temp, albumListing, FTP_ASCII)) {
rewind ($temp);
$data = fread($temp, ftp_size($ftp, albumListing) );
}
fclose($temp);*/
#If the album does not exist make the directory for it and change to that directory
if(@ftp_mkdir($ftp, ftpDir.'/'.$_POST['albumFolder'].'/')) {
echo 'Album folder created';
} else {
echo 'Sorry but that album directory already exists.';
}
# Get old Album Listing (albums.txt or nonsense like that.)
$listing = fopen(dirRoot.'/'.albumListing, 'r');
$data = fread($listing, filesize(dirRoot.'/'.albumListing));
fclose($listing);
#append new album data to old album data
$data = trim($data);
if($_POST['albumFolder'] && $_POST['albumFolder'] != '') {
$data = $_POST['albumFolder'].":".$_POST['albumTitle']."\n".$data;
}
# Create temp file and write to server in ASCII
$temp = tmpfile();
fwrite($temp, $data);
rewind($temp);
$album = ftp_fput($ftp, albumListing, $temp, FTP_ASCII);
fclose($temp);
if(@ftp_chdir($ftp, ftpDir.'/'.$_POST['albumFolder'].'/')) {
$upload = $this->ftpUpload($_FILES, $ftp);
if (!$album) {
echo '
Album creation has failed! ';
} else {
echo '
Album added! ';
echo $upload;
}
} else {
echo 'There was an error creating your photo album.';
}
ftp_quit($ftp);
} else {
echo '
Add a New Album ';
echo '
Tips
Title:
This is the title of this album of photos. For example "John At Work".
Directory Name:
This is the directory that your album will be created in and should be unique to this album. For example "john".
Choose Photos:
You can upload as many or as few photos when you create this album.
To upload more photos select approximately how many you would like to
upload from the drop down menu. Upload more photos when you feel like it.
The accepted file formats are JPG, PNG, and ZIP. A zip archive must
contain the files you would like extracted into this album.
';
}
}
function deleteAlbum() {
if($_GET['edit'] == 'yes' && $_GET['delete']) {
echo '
Deleting Albums ';
$ftp = $this->ftpConnect();
ftp_chdir($ftp, ftpDir.'/');
$listing = fopen(dirRoot.'/'.albumListing, 'r');
$data = fread($listing, filesize(dirRoot.'/'.albumListing));
fclose($listing);
$data = trim($data);
for($i = 0; $i <= count($_GET['delete']) - 1;$i++) {
@ftp_chdir($ftp, ftpDir.'/'.$_GET['delete'][$i].'/');
if($contents = ftp_nlist($ftp, ftpDir.'/'.$_GET['delete'][$i])) {
foreach($contents as $file) {
ftp_delete($ftp, $file);
}
}
if(@ftp_rmdir($ftp, ftpDir.'/'.$_GET['delete'][$i].'/')) {
echo '
The album "'.$_GET['albumTitle'][$_GET['delete'][$i]].'" was deleted from the server. ';
} else {
echo '
'.$_GET['albumTitle'][$albumfolder].' album was unsuccessfully deleted from the server (it may not have had a directory).
';
}
$data = preg_replace('/^'.preg_quote($_GET['delete'][$i]).':'.preg_quote($_GET['albumTitle'][$_GET['delete'][$i]]).'.*$/m', '', $data);
$data = preg_replace('/^\s*$/m', '', $data);
$temp = tmpfile();
fwrite($temp, $data);
rewind($temp);
$upload = ftp_fput($ftp, ftpDir.'/'.albumListing, $temp, FTP_ASCII);
fclose($temp);
echo '
The album was deleted from '.albumListing.' ';
}
ftp_quit($ftp);
} else {
echo '
Delete Albums ';
$this->displayData->rawTemplate('
');
}
}
function editAlbum() {
$this->displayData->rawTemplate('
Edit <$PSCurrentAlbumTitle$> ');
if($_GET['edit'] == 'yes' && $_GET['albumFolder'] != '' or $_GET['albumTitle'] != '' or $_GET['albumDate']) {
/*$_GET['albumFolder'] = stripslashes($_GET['albumFolder']);
$_GET['albumTitle'] = stripslashes($_GET['albumTitle']);
$_GET['albumDate'] = stripslashes($_GET['albumDate']);
$_GET['oldFolder'] = stripslashes($_GET['oldFolder']);
$_GET['oldTitle'] = stripslashes($_GET['oldTitle']);*/
if($_GET['albumFolder'] == '') {
$_GET['albumFolder'] = $_GET['oldFolder'];
}
if($_GET['albumTitle'] == '') {
$_GET['albumTitle'] = $_GET['oldTitle'];
}
if($_GET['albumDate'] == '' or $_GET['albumDate'] == ' ') {
$_GET['albumDate'] = '';
} else {
$_GET['albumDate'] = ':'.$_GET['albumDate'];
}
$ftp = $this->ftpConnect();
ftp_chdir($ftp, ftpDir.'/');
# Get old Album Listing (albums.txt or nonsense like that.)
$listing = fopen(dirRoot.'/'.albumListing, 'r');
$data = fread($listing, filesize(dirRoot.'/'.albumListing));
fclose($listing);
$data = trim($data);
$pattern = "/".preg_quote($_GET['oldFolder']).":".preg_quote($_GET['oldTitle']).".*/";
$replacement = $_GET['albumFolder'].":".$_GET['albumTitle'].$_GET['albumDate'];
$data = preg_replace($pattern,$replacement,$data);
# Create temp file and write to server in ASCII
$temp = tmpfile();
fwrite($temp, $data);
rewind($temp);
$album = ftp_fput($ftp, albumListing, $temp, FTP_ASCII);
fclose($temp);
# Move if the directory has changed.
if($_GET['albumFolder'] != $_GET['oldFolder']) {
if(@ftp_chdir($ftp, ftpDir.'/'.$_GET['albumFolder'].'/') == 0) {
ftp_mkdir($ftp, ftpDir.'/'.$_GET['albumFolder'].'/');
} else {
echo 'That album folder is already being used.
';
}
#rename this bitch
ftp_rename($ftp, $_GET['oldFolder'], $_GET['albumFolder']);
if(ftp_rmdir($ftp, ftpDir.'/'.$_GET['oldFolder'].'/')) {
echo 'The album '.$_GET['albumFolder'].' was moved.
';
}
}
ftp_quit($ftp);
header('Location: '.webConfigURL.'?__mode=editAlbum&edited=yes&album='.$_GET['albumFolder']);
}
if ($_GET['edited'] == 'yes') {
echo '
Album Edited! ';
}
$this->displayData->rawTemplate('
Album Info:
Title: <$PSCurrentAlbumTitle$>
Directory: <$PSCurrentAlbumFolder$>
Date: <$PSCurrentAlbumDate$>
View | Flush
');
}
function editDesc() {
$this->displayData->rawTemplate('
Edit Descriptions ');
if($_GET['edit'] == 'yes') {
$ftp = $this->ftpConnect();
ftp_chdir($ftp, ftpDir.'/'.$_GET['album'].'/');
for($i = 0; $i <= count($_GET['photos']) - 1;$i++) {
if($_GET['desc'][$i] && $_GET['desc'][$i] != '' && $_GET['name'][$i] != $_GET['desc'][$i]) {
$page .= $_GET['photos'][$i].":".$_GET['desc'][$i]."\n";
}
}
$temp = tmpfile();
fwrite($temp, $page);
rewind($temp);
$upload = ftp_fput($ftp, ftpDir.'/'.$_GET['album'].'/'.photoDesc, $temp, FTP_ASCII);
fclose($temp);
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Descriptions and files adjusted accordingly!";
}
// close the FTP stream
ftp_quit($ftp);
} else {
$this->displayData->rawTemplate('
');
}
}
function addPhotos() {
$this->displayData->rawTemplate('
Add Photos to “<$PSCurrentAlbumTitle$>” ');
if($_POST['edit'] == 'yes' && $_POST['albumFolder'] && $_FILES) {
$ftp = $this->ftpConnect();
/*$_POST['albumFolder'] = stripslashes($_POST['albumFolder']);*/
#If the album does not exist make the directory for it and change to that directory
if(@ftp_chdir($ftp, ftpDir.'/'.$_POST['albumFolder'].'/') ) {
$upload = $this->ftpUpload($_FILES, $ftp);
if (!$upload) {
echo '
Photo adddition has failed! ';
} else {
echo '
Photos added to album! ';
echo $upload;
}
} else {
echo 'That album does not exist.';
}
ftp_quit($ftp);
} else {
echo '
Tips
Upload your files:
You can upload as many or as few photos when you create this album.
To upload more photos select approximately how many you would like to
upload from the drop down menu. Upload more photos when you feel like it.
File Types:
JPG, PNG, GIF, and ZIP files are acceptable. ZIP files should be a single zipped file of JPGs.
';
echo '
';
}
}
function deletePhotos() {
$this->displayData->rawTemplate('
Delete Photos from “<$PSCurrentAlbumTitle$>” ');
if($_GET['edit'] == 'yes' && $_GET['delete']) {
$ftp = $this->ftpConnect();
ftp_chdir($ftp, ftpDir.'/'.$_GET['album'].'/');
echo '
Photos Deleted Successfully
';
foreach($_GET['delete'] as $key => $value) {
if(file_exists(dirRoot.'/'.$_GET['album'].'/'.$value)) {
ftp_delete($ftp, ftpDir.'/'.$_GET['album'].'/'.$value);
echo ''.$value.' was deleted from this album. ';
}
}
echo ' ';
ftp_quit($ftp);
} else {
$this->displayData->rawTemplate('
');
}
}
#End of Class...
}
class exif {
//================================================================================================
//================================================================================================
// Converts from Intel to Motorola endien. Just reverses the bytes (assumes hex is passed in)
//================================================================================================
//================================================================================================
function intel2Moto($intel) {
$len = strlen($intel);
$moto="";
for($i=0; $i<=$len; $i+=2) {
$moto.=substr($intel,$len-$i,2);
}
return $moto;
}
//================================================================================================
//================================================================================================
// Looks up the name of the tag
//================================================================================================
//================================================================================================
function lookup_tag($tag) {
switch($tag) {
//used by IFD0
case "010e": $tag = "ImageDescription";break;
case "0132": $tag = "DateTime";break;
case "8769": $tag = "ExifOffset";break;
//used by Exif SubIFD
case "829a": $tag = "ExposureTime";break;
case "9000": $tag = "ExifVersion";break;
case "9003": $tag = "DateTimeOriginal";break;
case "9004": $tag = "DateTimedigitized";break;
default: $tag = "unknown:".$tag;break;
}
return $tag;
}
//================================================================================================
//================================================================================================
// Looks up the datatype
//================================================================================================
//================================================================================================
function lookup_type(&$type,&$size) {
switch($type) {
case "0001": $type = "UBYTE";$size=1;break;
case "0002": $type = "ASCII";$size=1;break;
case "0003": $type = "USHORT";$size=2;break;
case "0004": $type = "ULONG";$size=4;break;
case "0005": $type = "URATIONAL";$size=8;break;
case "0006": $type = "SBYTE";$size=1;break;
case "0007": $type = "UNDEFINED";$size=1;break;
case "0008": $type = "SSHORT";$size=2;break;
case "0009": $type = "SLONG";$size=4;break;
case "000a": $type = "SRATIONAL";$size=8;break;
case "000b": $type = "FLOAT";$size=4;break;
case "000c": $type = "DOUBLE";$size=8;break;
default: $type = "error:".$type;$size=0;break;
}
return $type;
}
//================================================================================================
//================================================================================================
// Formats Data for the data type
//================================================================================================
//================================================================================================
function formatData($type,$tag,$intel,$data) {
if($type=="ULONG") {
$data = bin2hex($data);
if($intel==1) $data = $this->intel2Moto($data);
if($intel==0 && ($type=="USHORT" || $type=="SSHORT")) $data = substr($data,0,4);
$data=hexdec($data);
}
return $data;
}
//================================================================================================
//================================================================================================
// Reads one standard IFD entry
//================================================================================================
//================================================================================================
function read_entry(&$result,$in,$seek,$intel,$ifd_name,$globalOffset) {
//2 byte tag
$tag = bin2hex(fread( $in, 2 ));
if($intel==1) $tag = $this->intel2Moto($tag);
$tag_name = $this->lookup_tag($tag);
//2 byte datatype
$type = bin2hex(fread( $in, 2 ));
if($intel==1) $type = $this->intel2Moto($type);
$this->lookup_type($type,$size);
//4 byte number of elements
$count = bin2hex(fread( $in, 4 ));
if($intel==1) $count = $this->intel2Moto($count);
$bytesofdata = $size*hexdec($count);
//4 byte value or pointer to value if larger than 4 bytes
$value = fread( $in, 4 );
if($bytesofdata<=4) { //if datatype is 4 bytes or less, its the value
$data = $value;
} else { //otherwise its a pointer to the value, so lets go get it
$value = bin2hex($value);
if($intel==1) $value = $this->intel2Moto($value);
$v = fseek($seek,$globalOffset+hexdec($value)); //offsets are from TIFF header which is 12 bytes from the start of the file
if($v==0) {
$data = fread($seek, $bytesofdata);
} else if($v==-1) {
$result['Errors'] = $result['Errors']++;
}
}
//Format the data depending on the type and tag
$formated_data = $this->formatData($type,$tag,$intel,$data);
$result[$ifd_name][$tag_name] = $formated_data;
}
//================================================================================================
//================================================================================================
// Pass in a file and this reads the EXIF data
//
// Usefull resources
// http://www.ba.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html
// http://www.w3.org/Graphics/JPEG/jfif.txt
// http://exif.org/
//================================================================================================
//================================================================================================
function read_exif_data_raw($path,$verbose) {
if($path=='' or $path=='none') return;
$in = fopen($path, "rb"); //the b is for windows machines to open in binary mode
$seek = fopen($path, "rb"); //There may be an elegant way to do this with one file handle.
$globalOffset = 0;
if(!isset($verbose)) $verbose=0;
$result['VerboseOutput'] = $verbose;
$result['Errors'] = 0;
//First 2 bytes of JPEG are 0xFFD8
$data = bin2hex(fread( $in, 2 ));
if($data=="ffd8") {
$result['ValidJpeg'] = 1;
} else {
$result['ValidJpeg'] = 0;
fclose($in);
fclose($seek);
return $result;
}
//Next 2 bytes are MARKER tag (0xFFE#)
$data = bin2hex(fread( $in, 2 ));
if($data=="ffe0") {
$result['ValidJFIFData'] = 1;
$size = bin2hex(fread( $in, 2 ));
$result['JFIF']['Size'] = hexdec($size);
$ident = fread( $in, 5 );
$result['JFIF']['Identifier'] = $ident;
$code = fread( $in, 1 );
$result['JFIF']['ExtensionCode'] = bin2hex($code);
$data = fread( $in, hexdec($size)-8 );
$result['JFIF']['Data'] = $data;
$globalOffset+=hexdec($size)+2;
$data = bin2hex(fread( $in, 2 ));
} else {
$result['ValidJFIFData'] = 0;
}
if($data=="ffe1") {
$result['ValidEXIFData'] = 1;
} else {
$result['ValidEXIFData'] = 0;
fclose($in);
fclose($seek);
return $result;
}
//Size of APP1
$size = bin2hex(fread( $in, 2 ));
$result['APP1Size'] = hexdec($size);
//Start of APP1 block starts with "Exif" header (6 bytes)
$header = fread( $in, 6 );
//Then theres a TIFF header with 2 bytes of endieness (II or MM)
$header = fread( $in, 2 );
if($header==="II") {
$intel=1;
$result['Endien'] = "Intel";
} else if($header==="MM") {
$intel=0;
$result['Endien'] = "Motorola";
}
//2 bytes of 0x002a
$tag = bin2hex(fread( $in, 2 ));
//Then 4 bytes of offset to IFD0 (usually 8 which includes all 8 bytes of TIFF header)
$offset = bin2hex(fread( $in, 4 ));
if($intel==1) $offset = $this->intel2Moto($offset);
if(hexdec($offset)>8) $unknown = fread( $in, hexdec($offset)-8); //fixed this bug in 1.3
//add 12 to the offset to account for TIFF header
$globalOffset+=12;
//===========================================================Start of IFD0
$num = bin2hex(fread( $in, 2 ));
if($intel==1) $num = $this->intel2Moto($num);
$result['IFD0NumTags'] = hexdec($num);
for($i=0;$i
read_entry($result,$in,$seek,$intel,"IFD0",$globalOffset);
}
//store offset to IFD1
$offset = bin2hex(fread( $in, 4 ));
if($intel==1) $offset = $this->intel2Moto($offset);
$result['IFD1Offset'] = hexdec($offset);
//Check for SubIFD
if(!isset($result['IFD0']['ExifOffset']) || $result['IFD0']['ExifOffset']==0) {
fclose($in);
fclose($seek);
return $result;
}
//seek to SubIFD (Value of ExifOffset tag) above.
$ExitOffset = $result['IFD0']['ExifOffset'];
$v = fseek($in,$globalOffset+$ExitOffset);
if($v==-1) {
$result['Errors'] = $result['Errors']++;
}
//===========================================================Start of SubIFD
$num = bin2hex(fread( $in, 2 ));
if($intel==1) $num = $this->intel2Moto($num);
$result['SubIFDNumTags'] = hexdec($num);
for($i=0;$iread_entry($result,$in,$seek,$intel,"SubIFD",$globalOffset);
}
fclose($in);
fclose($seek);
return $result;
}
}
?>