* new screenshot and image classes

This commit is contained in:
Jonathan Ernst
2005-01-27 15:42:53 +00:00
committed by Jeremy Newman
parent fc4f7db66a
commit d5a50ecec4
9 changed files with 788 additions and 208 deletions

View File

@@ -5,6 +5,7 @@
include("path.php"); include("path.php");
require(BASE."include/"."incl.php"); require(BASE."include/"."incl.php");
require(BASE."include/"."screenshot.php");
require(BASE."include/"."tableve.php"); require(BASE."include/"."tableve.php");
require(BASE."include/"."category.php"); require(BASE."include/"."category.php");
@@ -123,18 +124,19 @@ if (!$_REQUEST['queueId'])
//data //data
if($obj_row->type == "image") if($obj_row->type == "image")
{ {
$oScreenshot = new Screenshot($obj_row->queueId,true);
echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n"; echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n";
echo '<td>'; echo '<td>';
$imgSRC = '<img width="'.APPDB_THUMBNAIL_WIDTH.'" height="'.APPDB_THUMBNAIL_HEIGHT.'" src="screenshotQueue.php?queueId='.$obj_row->queueId.'" />'; $imgSRC = '<img width="'.$oScreenshot->oThumbnailImage->width.'" height="'.$oScreenshot->oThumbnailImage->height.'" src="../appimage.php?queued=true&id='.$obj_row->queueId.'" />';
// generate random tag for popup window // generate random tag for popup window
$randName = generate_passwd(5); $randName = generate_passwd(5);
// set image link based on user pref // set image link based on user pref
$img = '<a href="javascript:openWin(\'screenshotQueue.php?queueId='.$obj_row->queueId.'\',\''.$randName.'\','.APPDB_SCREENSHOT_MAXWIDTH.','.APPDB_SCREENSHOT_MAXHEIGHT.');">'.$imgSRC.'</a>'; $img = '<a href="javascript:openWin(\'../appimage.php?queued=true&id='.$obj_row->queueId.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>';
if (loggedin()) if (loggedin())
{ {
if ($_SESSION['current']->getpref("window:screenshot") == "no") if ($_SESSION['current']->getpref("window:screenshot") == "no")
{ {
$img = '<a href="screenshotQueue.php?queueId='.$obj_row->queueId.'">'.$imgSRC.'</a>'; $img = '<a href="../appimage.php?queued=true&id='.$obj_row->queueId.'">'.$imgSRC.'</a>';
} }
} }
echo $img; echo $img;
@@ -171,13 +173,15 @@ if (!$_REQUEST['queueId'])
$sQuery = "INSERT INTO appData VALUES (null, ".$obj_row->appId.", ".$obj_row->versionId.", 'image', ". $sQuery = "INSERT INTO appData VALUES (null, ".$obj_row->appId.", ".$obj_row->versionId.", 'image', ".
"'".addslashes($_REQUEST['description'])."', '')"; "'".addslashes($_REQUEST['description'])."', '')";
query_appdb($sQuery); query_appdb($sQuery);
$int_id = mysql_insert_id(); $iId = mysql_insert_id();
// we move the content in the live directory // we move the content in the live directory
rename("../data/queued/screenshots/".$obj_row->queueId, "../data/screenshots/".$int_id); rename("../data/queued/screenshots/".$obj_row->queueId, "../data/screenshots/".$iId);
rename("../data/queued/screenshots/originals/".$obj_row->queueId, "../data/screenshots/originals/".$iId);
rename("../data/queued/screenshots/thumbnails/".$obj_row->queueId, "../data/screenshots/thumbnails/".$iId);
// we have to update the entry now that we know its name // we have to update the entry now that we know its name
$sQuery = "UPDATE appData SET url = '".$int_id."' WHERE id = '".$int_id."'"; $sQuery = "UPDATE appData SET url = '".$iId."' WHERE id = '".$iId."'";
} }
elseif ($obj_row->type == "url") { elseif ($obj_row->type == "url") {
@@ -229,6 +233,8 @@ if (!$_REQUEST['queueId'])
//delete main item //delete main item
$sQuery = "DELETE from appDataQueue where queueId = ".$obj_row->queueId.";"; $sQuery = "DELETE from appDataQueue where queueId = ".$obj_row->queueId.";";
unlink("../data/queued/screenshots/".$obj_row->queueId); unlink("../data/queued/screenshots/".$obj_row->queueId);
unlink("../data/queued/screenshots/originals/".$obj_row->queueId);
unlink("../data/queued/screenshots/thumbnails/".$obj_row->queueId);
$hResult = query_appdb($sQuery); $hResult = query_appdb($sQuery);
echo html_frame_start("Delete application data submission",400,"",0); echo html_frame_start("Delete application data submission",400,"",0);

140
admin/adminScreenshots.php Normal file
View File

@@ -0,0 +1,140 @@
<?php
/************************************************************/
/* Page for managing all of the screenshots in the AppDB */
/* Without having go into each application version to do so */
/************************************************************/
include("path.php");
include(BASE."include/"."incl.php");
require(BASE."include/"."screenshot.php");
apidb_header("Screenshots");
// deny access if not admin
if(!havepriv("admin"))
{
errorpage("Insufficient privileges.");
exit;
}
// regenerate all screenshots
if($_REQUEST['regenerate'])
{
$sQuery = "SELECT id FROM appData";
$hResult = query_appdb($sQuery);
while($oRow = mysql_fetch_object($hResult))
{
echo "REGENERATING IMAGE ".$oRow->id."<br/>";
$screenshot = new Screenshot($oRow->id);
$screenshot->generate();
$screenshot->free();
}
}
echo "<a href=\"".$_SERVER['PHP_SELF']."?regenerate=true\">Regenerate all screenshots ! (use only if you know what you are doing)</a><br />";
function display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage)
{
/* display the links to each of these pages */
if($currentPage != 0)
{
$previousPage = $currentPage - 1;
echo "<a href='adminScreenshots.php?page=$previousPage&screenshotsPerPage=$screenshotsPerPage'>Previous</a> ";
} else
echo "Previous ";
/* display the next 10 and previous 10 pages */
$pageRange = 10;
if($currentPage > $pageRange)
$startPage = $currentPage - $pageRange;
else
$startPage = 0;
if($currentPage + $pageRange < $totalPages)
$endPage = $currentPage + $pageRange;
else
$endPage = $totalPages;
/* display the desired range */
for($x = $startPage; $x <= $endPage; $x++)
{
if($x != $currentPage)
echo "<a href='adminScreenshots.php?page=$x&screenshotsPerPage=$screenshotsPerPage'>$x</a> ";
else
echo "$x ";
}
if($currentPage < $totalPages)
{
$nextPage = $currentPage + 1;
echo "<a href='adminScreenshots.php?page=$nextPage&screenshotsPerPage=$screenshotsPerPage'>Next</a> ";
} else
echo "Next ";
}
$screenshotsPerPage = 10;
$currentPage = 0;
if($_REQUEST['page'])
$currentPage = $_REQUEST['page'];
if($_REQUEST['screenshotsPerPage'])
$screenshotsPerPage = $_REQUEST['screenshotsPerPage'];
$totalPages = floor(getNumberOfComments()/$screenshotsPerPage);
if($screenshotsPerPage > 100) $screenshotsPerPage = 100;
/* display page selection links */
echo "<center>";
echo "<b>Page $currentPage of $totalPages</b><br />";
display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage);
echo "<br />";
echo "<br />";
/* display the option to choose how many comments per-page to disable */
echo "<form method=\"get\" name=\"message\" action=\"".$_SERVER['PHP_SELF']."\">";
echo "<b>Number of comments per page:</b>";
echo "<select name='screenshotsPerPage'>";
$screenshotsPerPageArray = array(10, 20, 50, 100);
foreach($screenshotsPerPageArray as $i => $value)
{
if($screenshotsPerPageArray[$i] == $screenshotsPerPage)
echo "<option value='$screenshotsPerPageArray[$i]' SELECTED>$screenshotsPerPageArray[$i]";
else
echo "<option value='$screenshotsPerPageArray[$i]'>$screenshotsPerPageArray[$i]";
}
echo "</select>";
echo "<input type=hidden name=page value=$currentPage>";
echo "<input type=submit value='Refresh'>";
echo "</form>";
echo "</center>";
/* query for all of the commentId's, ordering by their time in reverse order */
$offset = $currentPage * $screenshotsPerPage;
$commentIds = query_appdb("SELECT id from appData ORDER BY ".
"id ASC LIMIT $offset, $screenshotsPerPage;");
while ($ob = mysql_fetch_object($commentIds))
{
$qstring = "SELECT id, appId, versionId, type, description ".
"FROM appData WHERE id = $ob->id;";
$result = query_appdb($qstring);
/* call view_app_comment to display the comment */
$comment_ob = mysql_fetch_object($result);
// TODO: display the thumbnail with link to screenshot
}
/* display page selection links */
echo "<center>";
display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage);
echo "</center>";
apidb_footer();
?>

View File

@@ -1,113 +1,19 @@
<?php <?php
/*************************************************************/ /*************************/
/* app image handler */ /* code to show an image */
/* */ /*************************/
/* valid arguments: */
/* */
/* appId (required) */
/* versionId */
/* */
/* imageId (no appId required if this is specified) */
/* */
/* width */
/* height */
/* */
/* When both width/height are specified, the image is scaled */
/*************************************************************/
include("path.php"); include("path.php");
require(BASE."include/"."incl.php"); require(BASE."include/"."incl.php");
require(BASE."include/"."screenshot.php");
if(!havepriv("admin") && $_REQUEST['queued'])
function handle_error($text)
{ {
echo $text; errorpage("Insufficient privileges.");
// output image with the text, or something
exit; exit;
} }
$oScreenshot = new screenshot($_REQUEST['id'],$_REQUEST['queued']);
$appId = $_GET['appid']; if(!$_REQUEST['thumbnail'])
$imageId = $_GET['imageId']; $oScreenshot->oScreenshotImage->output_to_browser(1);
$versionId = $_GET['versionId'];
$width = $_GET['width'];
$height = $_GET['height'];
if(!$versionId) {
$versionId = 0;
}
// We have input, but wrong input
if( ( $width AND !is_numeric($width) ) || ( $height AND !is_numeric($height) ) )
{
$width = 100;
$height = 75;
}
if($imageId AND is_numeric($imageId) )
$result = query_appdb("SELECT * FROM appData WHERE id = $imageId");
else if($appId AND $versionId AND is_numeric($appId) AND is_numeric($versionId) )
$result = query_appdb("SELECT * FROM appData WHERE appId = $appId AND ".
"versionId = $versionId AND type = 'image' LIMIT 1");
else else
handle_error("IDs wrong"); $oScreenshot->oThumbnailImage->output_to_browser(1);
if(mysql_num_rows($result) == 0)
handle_error("No image found");
$ob = mysql_fetch_object($result);
// atm assumes the image is in png format
if(!ereg("/", $ob->url))
$url = "data/screenshots/$ob->url";
else
$url = $ob->url;
$imageInfo = getimagesize($url);
if( $imageInfo[2] == 2 )
{
$type = 'jpeg';
$im = imagecreatefromjpeg($url);
}
else if( $imageInfo[2] == 3 )
{
$type = 'png';
$im = imagecreatefrompng($url);
}
else
handle_error("Unhandeled image type");
if( !$imageInfo || !$im)
handle_error("Error handeling file.");
if($width && $height)
{
// do scaling
$sim = ImageCreate($width, $height);
ImageCopyResized($sim, $im, 0, 0, 0, 0, $width, $height, ImageSX($im), ImageSY($im));
}
else
{
// display full image
$sim = $im;
}
// output the image
if($type == "png")
{
header("Content-type: image/png");
ImagePNG($sim);
}
else
if($type == "jpeg")
{
header("Content-type: image/jpeg");
ImageJPEG($sim);
}
// Clear the memory
imagedestroy($im);
if(is_resource($sim))imagedestroy($sim);
?> ?>

BIN
images/watermark.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

415
include/image.php Normal file
View File

@@ -0,0 +1,415 @@
<?php
/*************************************/
/* image and image_resource classes */
/*************************************/
/**
* Image class for handling screenshot and thumbnail image files.
*/
class Image {
var $file; // absolute path from the docroot
var $debug_log;
var $image;
var $width;
var $height;
var $type;
/**
* Constructor:
* $file is the full path to the image. $this->is_loaded()
* should really be checked after making a new object.
*/
function Image($sRelativePath)
{
$this->file = $_SERVER['DOCUMENT_ROOT'].$sRelativePath;
$info = @getimagesize($this->file);
if( empty($info) )
{
$this->set_debuglog("Failed to load file ".$this->file);
return;
}
switch( $info[2] )
{
case 2:
$data = imagecreatefromjpeg($this->file);
break;
case 3:
$data = imagecreatefrompng($this->file);
break;
default;
$this->set_debuglog("Image type ({$info[2]}) unkown");
return;
return;
}
$this->image = $data;
$this->width = $info[0];
$this->height = $info[1];
$this->type = $info[2];
$this->set_debuglog("New image class created with as $file as"
." file and {$info[2]} as type. Dimensions"
." {$info[0]}x{$info[1]}");
}
/**
* is_loaded()
* This function should always be checked after loading a file
* with the constructor. Rteturns true if the image has been
* succesfully loaded.
*/
function is_loaded()
{
if($this->width > 0 AND $this->height > 0)
return true;
else
return false;
}
/**
* Returns the latest debug log made for the last function. If $full is
* set it will return the full log as array of the object.
*/
function get_debuglog($full = 0)
{
if($full)
return $this->debug_log;
else
return end($this->debug_log);
}
function get_width()
{
return $this->width;
}
function get_height()
{
return $this->height;
}
/**
* Returns the image resource identifier.
*/
function get_image_resource()
{
return $this->image;
}
/**
* make_thumb()
*
* Calculates resize based on one parameter and calculates the other
* with the right aspect ratio. If you want to use $new_height set
* $new_width to 0.
*
* If none are set APPDB_THUMBNAIL_WIDTH is used. If both are set
* $new_width is used.
*
* If you want to make a border, look at resize_image_border() comment
* and set $border_width and $border_color as appropriate.
*
*/
function make_thumb($new_width, $new_height, $border_width = 0, $border_color = '')
{
if($new_width == 0 AND $new_height == 0)
{
$new_width = APPDB_THUMBNAIL_WIDTH;
$new_height = $this->calculate_proportions($this->width, $this->height,$new_width);
}
else if($new_width > 0)
{
$new_height = $this->calculate_proportions($this->width, $this->height,$new_width);
}
else if($new_height > 0)
{
$new_width = $this->calculate_proportions($this->width, $this->height, 0, $new_height);
}
$this->set_debuglog("Resizing image to $new_width x $new_height");
if(!empty($border_color) and $border_width > 0)
$this->resize_image_border($border_color,$border_width,$new_height,$new_width);
else
$this->resize_image($new_width,$new_height);
}
/**
* make_full()
*
* Function will make sure your image is as big or smaller than the sizes
* set here with $max_width and $max_height. Aspect ratio will be mantained.
*
* If none are set APPDB_SCREENSHOT_MAXWIDTH and APPDB_SCREENSHOT_MAXHEIGHT
* are used.
*/
function make_full($max_width = 0, $max_height = 0)
{
if(!$max_width > 0)
$max_width = APPDB_SCREENSHOT_MAXWIDTH;
if(!$max_height > 0)
$max_height = APPDB_SCREENSHOT_MAXHEIGHT;
if($this->width > $max_width)
{
/* The width is too much */
$new_width = $max_width;
$new_height = $this->calculate_proportions($this->width,$this->height,$new_width);
/* Check if the height is also within the limits */
if($new_height > $max_height )
{
$new_width = $this->calculate_proportions($new_width,$new_height,0,$max_height);
$new_height = $max_height;
}
}
else if($this->height > $max_height)
{
/* Width was ok, height not */
$new_width = $this->calculate_proportions($this->width,$this->height,0,$max_height);
$new_height = $max_height;
}
else
{
/* All ok */
$new_width = $this->width;
$new_height = $this->height;
}
$this->set_debuglog("Resizing image to $new_width x $new_height");
$this->resize_image($new_width, $new_height);
}
/**
* resize_image()
*
* Resizes the image with the width and height specified with
* $new_height and $new_width.
*/
function resize_image($new_width, $new_height)
{
// GD 2.x
if(function_exists("imagecreatetruecolor"))
$new = imagecreatetruecolor($new_width, $new_height);
else // GD 1.x
$new = imagecreate($new_width, $new_height);
// GD 2.x
if(function_exists("imagecopyresampled"))
imagecopyresampled($new,$this->image,0,0,0,0,$new_width,$new_height,$this->width,$this->height);
else // GD 1.x
imagecopyresized($new,$this->image,0,0,0,0,$new_width,$new_height,$this->width,$this->height);
$this->set_debuglog("imagecopyresized($new,$this->image,0,0,0,0,$new_width,$new_height,$this->width,$this->height);");
imagedestroy($this->image);
$this->image = $new;
$this->width = $new_witdh;
$this->height= $new_height;
}
/**
* resize_image_border()
*
* Resizes the image. With the $new_width + $border_width*2
* and $new_height + $border_width*2 as size. $border_color is a
* HTML hexadecimal color (like #0000FF)
*/
function resize_image_border($border_color, $border_width, $new_height, $new_width)
{
$r = hexdec(substr($border_color, 1, 2));
$g = hexdec(substr($border_color, 3, 2));
$b = hexdec(substr($border_color, 5, 2));
/* We multiply the border width by two because there are are borders
at both sides */
// GD 2.x
if(function_exists("imagecreatetruecolor"))
$new = imagecreatetruecolor($new_width + ($border_width*2), $new_height + ($border_width*2));
else // GD 1.x
$new = imagecreate($new_width + ($border_width*2), $new_height + ($border_width*2));
/* Make the border by filling it completely,
later on we will overwrite everything except the border */
$color = ImageColorAllocate( $new, $r, $g, $b );
imagefill($new,0,0,$color);
// GD 2.x
if(function_exists("imagecopyresampled"))
imagecopyresampled($new,$this->image,$border_width,$border_width,0,0, $new_width,$new_height,$this->width,$this->height);
else // GD 1.x
imagecopyresized($new,$this->image,$border_width,$border_width,0,0,$new_width,$new_height,$this->width,$this->height);
$this->set_debuglog("imagecopyresized($new,$this->image,$border_width,$border_width,0,0,"
." $new_width,$new_height,$this->width,$this->height); with a $border_width px border"
." in $border_color");
imagedestroy($this->image);
$this->image = $new;
$this->width = $new_witdh;
$this->height= $new_height;
}
/**
* add_watermark()
*
* $watermark is a image resource identifier to any image resource.
*
* $min_mark_wwidth and $min_mark_height are the minimum sizes of the
* destination image before the watermark is added. If none are set
* both will be 0.
*
* A warning for transparency. If you resize an image down with make_thumb()
* you loose the transparency on png images.
*/
function add_watermark($watermark,$min_mark_width = 0,$min_mark_height = 0)
{
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
if($this->width > $min_mark_width AND $this->height > $min_mark_height)
{
$watermark_x = $this->width - $watermark_width;
$watermark_y = $this->height - $watermark_height;
imagecopy($this->image, $watermark, $watermark_x, $watermark_y, 0, 0, $watermark_width, $watermark_height);
$this->set_debuglog("imagecopy($this->image, $watermark, $watermark_x, $watermark_y, 0, 0, $watermark_width, $watermark_height);");
}
}
/**
* Output the image to a file set with $store.
*
* $type is optional and is set like the second index of getimagesize().
* If none (or 0) is set the orginal type of the file is used.
* If $store is not give, the current file name will be used.
* $quality is the jpeg output quality (100 best, 0 worst). Default is 75
*/
function output_to_file($store=null, $type = 0, $quality = 75)
{
if(!$store)
$store = $this->file;
if($type == 0)
$type = $this->type;
switch($type)
{
case 2:
imagejpeg($this->image,$store,$quality);
$this->set_debuglog("Outputed file as jpeg to $store");
break;
case 3:
imagepng($this->image,$store);
$this->set_debuglog("Outputed file as png to $store");
break;
default:
$this->set_debuglog("Unkown output type");
return;
}
return true;
}
/**
* Output the files to the browser.
*
* If $header is true a Content-type header with the correct type
* is set.
* $type is optional and is set like the second index of getimagesize().
* If none (or 0) is set the orginal type of the file is used.
*
* $quality is the jpeg output quality (100 best, 0 worst)
*/
function output_to_browser($header, $type = 0, $quality = 75)
{
if($type == 0 )
$type = $this->type;
switch($type)
{
case 2:
if($header)
header('Content-type: image/jpeg');
imagejpeg($this->image,'',$quality);
$this->set_debuglog("Outputed file as jpeg to browser");
break;
case 3:
if($header)
header('Content-type: image/png');
imagepng($this->image);
$this->set_debuglog("Outputed file as png to browser");
break;
default:
$this->set_debuglog("Unkown output type");
}
}
/**
* Destroys the image resource. Be sure to do this at the end of your
* actions with this object.
*/
function destroy()
{
if(is_resource($this->image))
imagedestroy($this->image);
}
/**
* Deletes the screenshot from the file system.
*/
function delete()
{
unlink($this->file);
}
/***********************
* PRIVATE FUNCTIONS
************************/
function set_debuglog( $log ) {
$this->debug_log[] = $log;
}
function calculate_proportions($width, $height, $new_width, $new_height = '0')
{
if($new_width > 0)
// we want to calculate the new height
return ($height * $new_width) / $width;
else if( $new_height > 0 )
return ($width * $new_height) / $height;
else
return 0;
}
}
class ImageResource extends Image {
function ImageResource($data,$type){
$this->image = $data;
$this->width = imagesx($data);
$this->height = imagesy($data);
$this->type = $type;
$this->set_debuglog("New image class created with as $data as"
." image resource and $type as type. Dimensions"
." {$this->width}x{$this->height}");
}
}
?>

View File

@@ -1,7 +1,162 @@
<?php <?php
/********************************/ /******************************************/
/* screenshot related functions */ /* screenshot class and related functions */
/********************************/ /******************************************/
require(BASE."include/"."image.php");
/**
* Screenshot class for handling screenshots and thumbnails
*/
class Screenshot {
var $iScreenshotId;
var $sDescription;
var $oScreenshotImage;
var $oThumbnailImage;
var $sTable;
var $sTableId;
var $userId;
var $bQueued;
var $iVersionId;
var $iAppId;
var $sDirectory;
/**
* constructor, fetches the description and creates the Image objects and files if needed.
*/
function Screenshot($iScreenshotId,$bQueued = false,$iUserId = null,$iAppId = null,$iVersionId = null,$sDescription = null,$hFile = null)
{
if($bQueued)
{
$this->sTable = appDataQueue;
$this->sTableId = queueId;
$this->iUserId = $userId;
$this->sDirectory = "queued/screenshots";
} else
{
$this->sTable = appData;
$this->sTableId = id;
$this->sDirectory = "screenshots";
}
// we are working on an existing screenshot
if($iScreenshotId)
{
$this->iScreenshotId = $iScreenshotId;
$sQuery = "SELECT * FROM ".$this->sTable." WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image'";
if($hResult = query_appdb($sQuery))
{
$oRow = mysql_fetch_object($hResult);
$this->iScreenshotId = $oRow->id;
$this->sDescription = $oRow->description;
$this->oScreenshotImage = new Image("/data/".$this->sDirectory."/".$oRow->url);
$this->oThumbnailImage = new Image("/data/".$this->sDirectory."/thumbnails/".$oRow->url);
$this->sSubmitTime = $oRow->submitTime;
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
}
} else // we are working on a non-existing screenshot
{
$this->sDescription = $sDescription;
if($bQueued)
$sQuery = "INSERT INTO $this->sTable VALUES (null, ".$iAppId.", ".$iVersionId.", 'image', '".addslashes($this->sDescription)."', '','".$_SESSION['current']->userid."', NOW())";
else
$sQuery = "INSERT INTO $this->sTable VALUES (null, ".$iAppId.", ".$iVersionId.", 'image', '".addslashes($this->sDescription)."', '')";
if (query_appdb($sQuery))
{
$this->iScreenshotId = mysql_insert_id();
}
else return false;
if(!rename($hFile['tmp_name'], "data/".$this->sDirectory."/originals/".$this->iScreenshotId))
{
// whoops, moving failed, do something
addmsg("Unable to move screenshot", "red");
$sQuery = "DELETE FROM ".$this->sTable." WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
query_appdb($sQuery);
return false;
} else // we managed to copy the file, now we have to process the image
{
$this->generate();
// we have to update the entry now that we know its name
$sQuery = "UPDATE ".$this->sTable." SET url = '".$this->iScreenshotId."' WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
if (!query_appdb($sQuery)) return false;
}
}
}
/**
* delete the screenshot from the database
* and request it's deletion from the filesystem (including the thumbnail).
*/
function delete()
{
$sQuery = "DELETE FROM ".$this->sTable." WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image' LIMIT 1";
if($hResult = query_appdb($sQuery))
{
$this->oScreenshotImage->delete();
$this->oThumbnailImage->delete();
unlink($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/originals/".$this->iScreenshotId);
}
}
/**
* clean up the memory
*/
function free()
{
$this->oScreenshotImage->destroy();
$this->oThumbnailImage->destroy();
}
/**
* sets the screenshot description.
*/
function setDescription($sDescription)
{
$sQuery = "UPDATE ".$this->sTableId." SET description = '".$sDescription."' WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image'";
if($hResult = query_appdb($sQuery))
$this->sDescription = $sDescription;
}
/**
* This method generates a watermarked screenshot and thumbnail from the original file.
* Usefull when changing thumbnail, upgrading GD, adding an image, etc.
*/
function generate()
{
// first we will create the thumbnail
// load the screenshot
$this->oThumbnailImage = new Image("/data/".$this->sDirectory."/originals/".$this->iScreenshotId);
$this->oThumbnailImage->make_thumb(0,0,1,'#000000');
// store the image
$this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/thumbnails/".$this->iScreenshotId);
// now we'll process the screenshot image for watermarking
// load the screenshot
$this->oScreenshotImage = new Image("/data/".$this->sDirectory."/originals/".$this->iScreenshotId);
// resize the image
$this->oScreenshotImage->make_full();
// store the resized image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/".$this->iScreenshotId);
// reload the resized screenshot
$this->oScreenshotImage = new Image("/data/".$this->sDirectory."/".$this->iScreenshotId);
// load the watermark
$watermark = new image("/images/watermark.png");
// add the watermark to the screenshot
$this->oScreenshotImage->add_watermark($watermark->get_image_resource());
// clean up the memory
$watermark->destroy();
// store the watermarked image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/".$this->iScreenshotId);
}
}
/*
* Screenshot functions that are not part of the class
*/
/** /**
* Get a random image for a particular version of an app. * Get a random image for a particular version of an app.

View File

@@ -21,6 +21,7 @@ function global_admin_menu() {
$g->addmisc("&nbsp;"); $g->addmisc("&nbsp;");
$g->add("Users Management", BASE."admin/adminUsers.php"); $g->add("Users Management", BASE."admin/adminUsers.php");
$g->add("Comments Management", BASE."admin/adminCommentView.php"); $g->add("Comments Management", BASE."admin/adminCommentView.php");
$g->add("Screenshots Management", BASE."admin/adminScreenshots.php");
$g->done(); $g->done();
} }

View File

@@ -10,6 +10,7 @@
*/ */
include("path.php"); include("path.php");
require(BASE."include/"."incl.php"); require(BASE."include/"."incl.php");
require(BASE."include/"."screenshot.php");
require(BASE."include/"."application.php"); require(BASE."include/"."application.php");
if($_REQUEST['cmd']) if($_REQUEST['cmd'])
@@ -21,108 +22,66 @@ if($_REQUEST['cmd'])
(loggedin() && $_SESSION['current']->is_maintainer($_REQUEST['appId'], (loggedin() && $_SESSION['current']->is_maintainer($_REQUEST['appId'],
$_REQUEST['versionId']))) $_REQUEST['versionId'])))
{ {
$str_query = "INSERT INTO appData VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId']. $oScreenshot = new Screenshot(null,false,$_SESSION['current']->userid,$_REQUEST['appId'],$_REQUEST['versionId'],$_REQUEST['screenshot_desc'],$_FILES['imagefile']);
", 'image', '".addslashes($_REQUEST['screenshot_desc'])."', '')"; if($oScreenshot)
if(debugging()) addmsg("<p align=center><b>query:</b> $str_query </p>","green");
if (query_appdb($str_query))
{ {
$int_id = mysql_insert_id(); //success
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if(!copy($_FILES['imagefile']['tmp_name'], "data/screenshots/".$int_id)) if($email)
{ {
// whoops, copy failed. do something $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']); $ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
$str_query = "DELETE FROM appData WHERE id = '".$int_id."'"; $ms .= "\n";
query_appdb($str_query); $ms .= $_SESSION['current']->realname." added screenshot ".$_REQUEST['screenshot_desc']." to ".$fullAppName."\n";
exit; $ms .= "\n";
} else $ms .= STANDARD_NOTIFY_FOOTER;
{
// we have to update the entry now that we know it's name
$str_query = "UPDATE appData SET url = '".$int_id."' WHERE id = '".$int_id."'";
if (query_appdb($str_query))
{
//success
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if($email)
{
$fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
$ms .= APPDB_ROOT."screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']."\n";
$ms .= "\n";
$ms .= $_SESSION['current']->realname." added screenshot ".$_REQUEST['screenshot_desc']." to ".$fullAppName."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms); mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else } else
{ {
$email = "no one"; $email = "no one";
}
addmsg("mesage sent to: ".$email, "green");
addmsg("The image was successfully added into the database", "green");
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
}
} }
addmsg("message sent to: ".$email, "green");
addmsg("The image was successfully added into the database", "green");
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
} }
} else // we are a normal user or an anonymous and submitted a screenshot } else // we are a normal user or an anonymous and submitted a screenshot
{ {
$str_query = "INSERT INTO appDataQueue VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId']. $oScreenshot = new Screenshot(null,true,$_SESSION['current']->userid,$_REQUEST['appId'],$_REQUEST['versionId'],$_REQUEST['screenshot_desc'],$_FILES['imagefile']);
", 'image', '".addslashes($_REQUEST['screenshot_desc'])."', '','".$_SESSION['current']->userid. if($oScreenshot)
"', NOW())";
if(debugging()) addmsg("<p align=center><b>query:</b> $str_query </p>","green");
if (query_appdb($str_query))
{ {
$int_queueId = mysql_insert_id(); //success
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if(!copy($_FILES['imagefile']['tmp_name'], "data/queued/screenshots/".$int_queueId)) if($email)
{ {
// whoops, copy failed. do something $fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']); $ms .= APPDB_ROOT."admin/adminAppDataQueue.php?queueId=".mysql_insert_id()."\n";
$str_query = "DELETE FROM appDataQueue WHERE queueId = '".$int_queueId."'"; $ms .= "\n";
query_appdb($str_query); $ms .= ($_SESSION['current']->realname ? $_SESSION['current']->realname : "an anonymous user")." submitted a screenshot ".$_REQUEST['screenshot_desc']." for ".$fullAppName."\n";
exit; $ms .= "\n";
} else $ms .= STANDARD_NOTIFY_FOOTER;
{
// we have to update the queued entry now that we know its name
$str_query = "UPDATE appDataQueue SET url = '".$int_queueId."' WHERE queueId = '".$int_queueId."'";
if (query_appdb($str_query))
{
//success
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if($email)
{
$fullAppName = "Application: ".lookupAppName($_REQUEST['appId'])." Version: ".lookupVersionName($_REQUEST['appId'], $_REQUEST['versionId']);
$ms .= APPDB_ROOT."admin/adminAppDataQueue.php?queueId=".mysql_insert_id()."\n";
$ms .= "\n";
$ms .= ($_SESSION['current']->realname ? $_SESSION['current']->realname : "an anonymous user")." submitted a screenshot ".$_REQUEST['screenshot_desc']." for ".$fullAppName."\n";
$ms .= "\n";
$ms .= STANDARD_NOTIFY_FOOTER;
mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
} else
{
$email = "no one";
}
addmsg("mesage sent to: ".$email, "green");
addmsg("The image you submitted will be added to the database database after being reviewed", "green"); mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId'])); } else
} {
$email = "no one";
} }
addmsg("message sent to: ".$email, "green");
addmsg("The image you submitted will be added to the database database after being reviewed", "green");
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
} }
} }
} elseif($_REQUEST['cmd'] == "delete") $oScreenshot->free();
} elseif($_REQUEST['cmd'] == "delete" && is_numeric($_REQUEST['imageId']))
{ {
if(havepriv("admin") || if(havepriv("admin") ||
$_SESSION['current']->is_maintainer($_REQUEST['appId'], $_SESSION['current']->is_maintainer($_REQUEST['appId'],
$_REQUEST['versionId'])) $_REQUEST['versionId']))
{ {
$result = query_appdb("DELETE FROM appData WHERE id = ".$_REQUEST['imageId']); $oScreenshot = new Screenshot($_REQUEST['imageId']);
if($result) if($oScreenshot && $oScreenshot->delete())
{ {
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']); $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if($email) if($email)
@@ -140,7 +99,7 @@ if($_REQUEST['cmd'])
{ {
$email = "no one"; $email = "no one";
} }
addmsg("mesage sent to: ".$email, "green"); addmsg("message sent to: ".$email, "green");
addmsg("Image deleted", "green"); addmsg("Image deleted", "green");
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId'])); redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
} else } else
@@ -149,6 +108,7 @@ if($_REQUEST['cmd'])
} }
} }
} }
$oScreenshot->free();
exit; exit;
} }
@@ -181,16 +141,14 @@ if($result && mysql_num_rows($result))
echo html_frame_start("Version ".lookupVersionName($_REQUEST['appId'], $currentVersionId)); echo html_frame_start("Version ".lookupVersionName($_REQUEST['appId'], $currentVersionId));
echo "<div align=center><table><tr>\n"; echo "<div align=center><table><tr>\n";
} }
// set img tag $oScreenshot = new Screenshot($ob->id);
$imgSRC = '<img src="appimage.php?imageId='.$ob->id.'&width=128&height=128" border=0 alt="'.$ob->description.'">';
// get image size
$size = getimagesize("data/screenshots/".$ob->url);
// generate random tag for popup window // generate random tag for popup window
$randName = generate_passwd(5); $randName = generate_passwd(5);
// set img tag
$imgSRC = '<img src="appimage.php?thumbnail=true&id='.$ob->id.'" alt="'.$oScreenshot->description.'" width="'.$oScreenshot->oThumnailImage->width.'" height="'.$oScreenshot->oThumnailImage->height.'">';
// set image link based on user pref // set image link based on user pref
$img = '<a href="javascript:openWin(\'appimage.php?imageId='.$ob->id.'\',\''.$randName.'\','.$size[0].','.$size[1].');">'.$imgSRC.'</a>'; $img = '<a href="javascript:openWin(\'appimage.php?id='.$ob->id.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>';
if (loggedin()) if (loggedin())
{ {
if ($_SESSION['current']->getpref("window:screenshot") == "no") if ($_SESSION['current']->getpref("window:screenshot") == "no")
@@ -249,5 +207,4 @@ if($_REQUEST['versionId'])
} }
echo html_back_link(1); echo html_back_link(1);
apidb_footer(); apidb_footer();
?> ?>

View File

@@ -4,12 +4,12 @@ function openWin(fileToOpen,nameOfWindow,width,height) {
myWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">'); myWindow.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">');
myWindow.document.write('<html><head><title>Screenshot Viewer</title>') myWindow.document.write('<html><head><title>Screenshot Viewer</title>')
myWindow.document.write('<style type="text/css">'); myWindow.document.write('<style type="text/css">');
myWindow.document.write('body { margin: 0; padding: 0; background-color: black; }'); myWindow.document.write('body { margin: 0; padding: 0; background-color: lightgrey; }');
myWindow.document.write('img { border: 0; }'); myWindow.document.write('img { border: 0; }');
myWindow.document.write('p { display: inline; }'); myWindow.document.write('p { display: inline; }');
myWindow.document.write('</style></head><body><p>'); myWindow.document.write('</style></head><body>');
myWindow.document.write('<a onclick="self.close();" href=""><img src="'+ fileToOpen +'" alt="Screenshot"></a>'); myWindow.document.write('<a onclick="self.close();" href=""><img src="'+ fileToOpen +'" alt="Screenshot"></a>');
myWindow.document.write('</p></body></html>'); myWindow.document.write('</body></html>');
myWindow.document.close(); myWindow.document.close();
} }