diff --git a/admin/adminAppDataQueue.php b/admin/adminAppDataQueue.php
index d39c39f..17d88a3 100644
--- a/admin/adminAppDataQueue.php
+++ b/admin/adminAppDataQueue.php
@@ -5,6 +5,7 @@
include("path.php");
require(BASE."include/"."incl.php");
+require(BASE."include/"."screenshot.php");
require(BASE."include/"."tableve.php");
require(BASE."include/"."category.php");
@@ -123,18 +124,19 @@ if (!$_REQUEST['queueId'])
//data
if($obj_row->type == "image")
{
+ $oScreenshot = new Screenshot($obj_row->queueId,true);
echo '
| Submited image | ',"\n";
echo '';
- $imgSRC = ' ';
+ $imgSRC = ' ';
// generate random tag for popup window
$randName = generate_passwd(5);
// set image link based on user pref
- $img = ''.$imgSRC.'';
+ $img = ''.$imgSRC.'';
if (loggedin())
{
if ($_SESSION['current']->getpref("window:screenshot") == "no")
{
- $img = ''.$imgSRC.'';
+ $img = ''.$imgSRC.'';
}
}
echo $img;
@@ -171,13 +173,15 @@ if (!$_REQUEST['queueId'])
$sQuery = "INSERT INTO appData VALUES (null, ".$obj_row->appId.", ".$obj_row->versionId.", 'image', ".
"'".addslashes($_REQUEST['description'])."', '')";
query_appdb($sQuery);
- $int_id = mysql_insert_id();
+ $iId = mysql_insert_id();
// 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
- $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") {
@@ -229,6 +233,8 @@ if (!$_REQUEST['queueId'])
//delete main item
$sQuery = "DELETE from appDataQueue where queueId = ".$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);
echo html_frame_start("Delete application data submission",400,"",0);
diff --git a/admin/adminScreenshots.php b/admin/adminScreenshots.php
new file mode 100644
index 0000000..ed63a17
--- /dev/null
+++ b/admin/adminScreenshots.php
@@ -0,0 +1,140 @@
+id." ";
+ $screenshot = new Screenshot($oRow->id);
+ $screenshot->generate();
+ $screenshot->free();
+ }
+}
+
+echo "Regenerate all screenshots ! (use only if you know what you are doing) ";
+
+function display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage)
+{
+ /* display the links to each of these pages */
+ if($currentPage != 0)
+ {
+ $previousPage = $currentPage - 1;
+ echo "Previous ";
+ } 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 "$x ";
+ else
+ echo "$x ";
+ }
+
+ if($currentPage < $totalPages)
+ {
+ $nextPage = $currentPage + 1;
+ echo "Next ";
+ } 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 "";
+echo "Page $currentPage of $totalPages ";
+display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage);
+echo " ";
+echo " ";
+
+/* display the option to choose how many comments per-page to disable */
+echo "";
+
+echo "";
+
+/* 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 "";
+display_range($currentPage, $pageRange, $totalPages, $screenshotsPerPage);
+echo "";
+
+apidb_footer();
+
+?>
diff --git a/appimage.php b/appimage.php
index cd14274..4d85c57 100644
--- a/appimage.php
+++ b/appimage.php
@@ -1,113 +1,19 @@
oScreenshotImage->output_to_browser(1);
else
- handle_error("IDs wrong");
-
-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);
+ $oScreenshot->oThumbnailImage->output_to_browser(1);
?>
diff --git a/images/watermark.png b/images/watermark.png
new file mode 100644
index 0000000..5e3770c
Binary files /dev/null and b/images/watermark.png differ
diff --git a/include/image.php b/include/image.php
new file mode 100644
index 0000000..905692c
--- /dev/null
+++ b/include/image.php
@@ -0,0 +1,415 @@
+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}");
+ }
+}
+?>
diff --git a/include/screenshot.php b/include/screenshot.php
index 56bb154..14a686b 100644
--- a/include/screenshot.php
+++ b/include/screenshot.php
@@ -1,7 +1,162 @@
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.
diff --git a/include/sidebar_admin.php b/include/sidebar_admin.php
index ebd8732..55974b1 100644
--- a/include/sidebar_admin.php
+++ b/include/sidebar_admin.php
@@ -21,6 +21,7 @@ function global_admin_menu() {
$g->addmisc(" ");
$g->add("Users Management", BASE."admin/adminUsers.php");
$g->add("Comments Management", BASE."admin/adminCommentView.php");
+ $g->add("Screenshots Management", BASE."admin/adminScreenshots.php");
$g->done();
}
diff --git a/screenshots.php b/screenshots.php
index c40489c..bb1d797 100644
--- a/screenshots.php
+++ b/screenshots.php
@@ -10,6 +10,7 @@
*/
include("path.php");
require(BASE."include/"."incl.php");
+require(BASE."include/"."screenshot.php");
require(BASE."include/"."application.php");
if($_REQUEST['cmd'])
@@ -21,108 +22,66 @@ if($_REQUEST['cmd'])
(loggedin() && $_SESSION['current']->is_maintainer($_REQUEST['appId'],
$_REQUEST['versionId'])))
{
- $str_query = "INSERT INTO appData VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId'].
- ", 'image', '".addslashes($_REQUEST['screenshot_desc'])."', '')";
-
- if(debugging()) addmsg("query: $str_query ","green");
-
- if (query_appdb($str_query))
+ $oScreenshot = new Screenshot(null,false,$_SESSION['current']->userid,$_REQUEST['appId'],$_REQUEST['versionId'],$_REQUEST['screenshot_desc'],$_FILES['imagefile']);
+ if($oScreenshot)
{
- $int_id = mysql_insert_id();
-
- if(!copy($_FILES['imagefile']['tmp_name'], "data/screenshots/".$int_id))
+ //success
+ $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
+ if($email)
{
- // whoops, copy failed. do something
- errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']);
- $str_query = "DELETE FROM appData WHERE id = '".$int_id."'";
- query_appdb($str_query);
- exit;
- } else
- {
- // 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;
+ $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);
- } else
- {
- $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']));
- }
+ mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
+ } else
+ {
+ $email = "no one";
}
+ 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
{
- $str_query = "INSERT INTO appDataQueue VALUES (null, ".$_REQUEST['appId'].", ".$_REQUEST['versionId'].
- ", 'image', '".addslashes($_REQUEST['screenshot_desc'])."', '','".$_SESSION['current']->userid.
- "', NOW())";
-
- if(debugging()) addmsg("query: $str_query ","green");
-
- if (query_appdb($str_query))
+ $oScreenshot = new Screenshot(null,true,$_SESSION['current']->userid,$_REQUEST['appId'],$_REQUEST['versionId'],$_REQUEST['screenshot_desc'],$_FILES['imagefile']);
+ if($oScreenshot)
{
- $int_queueId = mysql_insert_id();
-
- if(!copy($_FILES['imagefile']['tmp_name'], "data/queued/screenshots/".$int_queueId))
+ //success
+ $email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
+ if($email)
{
- // whoops, copy failed. do something
- errorpage("debug: copy failed; (".$_FILES['imagefile']['tmp_name'].";".$_FILES['imagefile']['name']);
- $str_query = "DELETE FROM appDataQueue WHERE queueId = '".$int_queueId."'";
- query_appdb($str_query);
- exit;
- } else
- {
- // 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");
+ $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;
- 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']));
- }
+ mail(stripslashes($email), "[AppDB] ".$fullAppName ,$ms);
+ } 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") ||
$_SESSION['current']->is_maintainer($_REQUEST['appId'],
$_REQUEST['versionId']))
{
- $result = query_appdb("DELETE FROM appData WHERE id = ".$_REQUEST['imageId']);
- if($result)
+ $oScreenshot = new Screenshot($_REQUEST['imageId']);
+ if($oScreenshot && $oScreenshot->delete())
{
$email = getNotifyEmailAddressList($_REQUEST['appId'], $_REQUEST['versionId']);
if($email)
@@ -140,7 +99,7 @@ if($_REQUEST['cmd'])
{
$email = "no one";
}
- addmsg("mesage sent to: ".$email, "green");
+ addmsg("message sent to: ".$email, "green");
addmsg("Image deleted", "green");
redirect(apidb_fullurl("screenshots.php?appId=".$_REQUEST['appId']."&versionId=".$_REQUEST['versionId']));
} else
@@ -149,6 +108,7 @@ if($_REQUEST['cmd'])
}
}
}
+ $oScreenshot->free();
exit;
}
@@ -181,16 +141,14 @@ if($result && mysql_num_rows($result))
echo html_frame_start("Version ".lookupVersionName($_REQUEST['appId'], $currentVersionId));
echo " |