- no more appId in appData as appVersion implies an appId*

- screenshot class has been reworked to remove need of appId
- screenshot class has been improved to send e-mails so that email handling can be removed from other scripts
This commit is contained in:
Jonathan Ernst
2005-02-04 02:55:50 +00:00
committed by WineHQ
parent 76faddeef4
commit 3ebdbc9af5
8 changed files with 397 additions and 424 deletions

View File

@@ -3,7 +3,7 @@
/* screenshot class and related functions */
/******************************************/
require(BASE."include/"."image.php");
require(BASE."include/image.php");
// load the watermark
$watermark = new image("/images/watermark.png");
@@ -23,20 +23,22 @@ class Screenshot {
var $iAppId;
var $sDirectory;
var $sUrl;
var $iSubmitterId;
/**
* 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)
function Screenshot($iScreenshotId = null,$bQueued = false)
{
if($bQueued)
{
$this->bQueued = true;
$this->sTable = appDataQueue;
$this->sTableId = queueId;
$this->iUserId = $userId;
$this->sDirectory = "queued/screenshots";
} else
{
$this->bQueued = false;
$this->sTable = appData;
$this->sTableId = id;
$this->sDirectory = "screenshots";
@@ -46,11 +48,14 @@ class Screenshot {
if($iScreenshotId)
{
$this->iScreenshotId = $iScreenshotId;
$sQuery = "SELECT * FROM ".$this->sTable." WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image'";
$sQuery = "SELECT ".$this->sTable.".*, appVersion.appId AS appId
FROM ".$this->sTable.", appVersion
WHERE ".$this->sTable.".versionId = appVersion.versionId
AND ".$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);
@@ -58,24 +63,47 @@ class Screenshot {
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url;
if(!$this->iSubmitterId && $oRow->queueuserid)
$this->iSubmitterId = $oRow->queueuserid;
}
} else // we are working on a non-existing screenshot
}
}
function create($iVersionId = null, $sDescription = null, $hFile = null)
{
$aInsert = compile_insert_string(array( 'versionId' => $iVersionId,
'type' => "image",
'description' => $sDescription ));
// Security, if we are not an administrator or a maintainer, the screenshot must be queued.
if(!($_SESSION['current']->hasPriv("admin") || $_SESSION['current']->isMaintainer($_REQUEST['versionId'])))
{
$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;
$this->bQueued = true;
$this->sTable = appDataQueue;
$this->sTableId = queueId;
$this->iUserId = $userId;
$this->sDirectory = "queued/screenshots";
$sFields = "({$aInsert['FIELDS']}, userId)";
$sValues = "({$aInsert['VALUES']}, '".$_SESSION['current']->iUserId."')";
} else
{
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
}
if(query_appdb("INSERT INTO ".$this->sTable." $sFields VALUES $sValues", "Error while creating a new screenshot."))
{
$this->iScreenshotId = mysql_insert_id();
if(!move_uploaded_file($hFile['tmp_name'], "data/".$this->sDirectory."/originals/".$this->iScreenshotId))
{
// whoops, moving failed, do something
addmsg("Unable to move screenshot from ".$hFile['tmp_name']." to data/".$this->sDirectory."/originals/".$this->iScreenshotId, "red");
$sQuery = "DELETE FROM ".$this->sTable." WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
$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
@@ -83,38 +111,102 @@ class Screenshot {
$this->sUrl = $this->iScreenshotId;
$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."'";
$sQuery = "UPDATE ".$this->sTable."
SET url = '".$this->iScreenshotId."'
WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
if (!query_appdb($sQuery)) return false;
}
$this->screenshot($this->iScreenshotId,$this->bQueued);
$this->mailMaintainers();
return true;
}
else
return false;
}
/**
* delete the screenshot from the database
* and request it's deletion from the filesystem (including the thumbnail).
* Deletes the screenshot from the database.
* and request its deletion from the filesystem (including the thumbnail).
*/
function delete()
function delete($bSilent=false)
{
$sQuery = "DELETE FROM ".$this->sTable." WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image' LIMIT 1";
$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);
if(!$bSilent)
$this->mailMaintainers(true);
}
if($this->iSubmitterId)
{
$this->mailSubmitter(true);
}
}
/**
* clean up the memory
* Move screenshot out of the queue.
*/
function unQueue()
{
// If we are not in the queue, we can't move the screenshot out of the queue.
if(!$this->bQueued)
return false;
$aInsert = compile_insert_string(array( 'versionId' => $this->iVersionId,
'type' => "image",
'description' => $this->$sDescription ));
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
if(query_appdb("INSERT INTO appData $sFields VALUES $sValues", "Error while unqueueing a screenshot."))
{
$iId = mysql_insert_id();
// we move the content in the live directory
copy("../data/queued/screenshots/".$this->iScreenshotId, "../data/screenshots/".$iId);
copy("../data/queued/screenshots/originals/".$this->iScreenshotId, "../data/screenshots/originals/".$iId);
copy("../data/queued/screenshots/thumbnails/".$this->iScreenshotId, "../data/screenshots/thumbnails/".$iId);
// now that we know the url of the screenshot we can update the database
$sQuery = "UPDATE appData
SET url = '".$iId."'
WHERE id = '".$iId."'";
query_appdb($sQuery);
// we have to delete the queued entry
$this->delete(true);
// we fetch the new unqueued entry
$this->screenshot($iId);
// we send an e-mail to intersted people
$this->mailSubmitter();
$this->mailMaintainers();
}
}
/**
* Cleans up the memory.
*/
function free()
{
$this->oScreenshotImage->destroy();
$this->oThumbnailImage->destroy();
if($this->oScreenshotImage)
$this->oScreenshotImage->destroy();
if($this->oThumbnailImage)
$this->oThumbnailImage->destroy();
}
/**
* sets the screenshot description.
* Sets the screenshot description.
*/
function setDescription($sDescription)
{
@@ -154,6 +246,66 @@ class Screenshot {
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/".$this->sUrl);
}
function mailSubmitter($bRejected=false)
{
if($this->iSubmitterId)
{
$oSubmitter = new User($this->iSubmitterId);
if(!$bRejected)
{
$sSubject = "Submitted screenshot accepted";
$sMsg = "The screenshot you submitted for ".lookup_app_name($this->appId)." ".lookup_version_name($this->versionId)." has been accepted.";
} else
{
$sSubject = "Submitted screenshot rejected";
$sMsg = "The screenshot you submitted for ".lookup_app_name($this->appId)." ".lookup_version_name($this->versionId)." has been accepted.";
}
$sMsg .= $_REQUEST['replyText']."\n";
$sMsg .= "We appreciate your help in making the Application Database better for all users.";
mail_appdb($oSubmitter->sEmail, $sSubject ,$sMsg);
}
// the screenshot has been unqueued
addmsg("The screenshot has been unqueued.", "green");
}
function mailMaintainers($bDeleted=false)
{
if(!$bDeleted)
{
if(!$this->bQueued)
{
$sSubject = "Screenshot for ".lookup_app_name($this->iAppId)." ".lookup_version_name($this->iVersionId)." added by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
if($this->iSubmitterId)
{
$oSubmitter = new User($this->iSubmitterId);
$sMsg .= "This screenshot has been submitted by ".$oSubmitter->sRealname.".";
$sMsg .= "\n";
}
addmsg("The screenshot was successfully added into the database.", "green");
} else // Screenshot queued.
{
$sSubject = "Screenshot for ".lookup_app_name($this->iAppId)." ".lookup_version_name($this->iVersionId)." submitted by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
$sMsg .= "This screenshot has been queued.";
$sMsg .= "\n";
addmsg("The screenshot you submitted will be added to the database database after being reviewed.", "green");
}
} else // Screenshot deleted.
{
$sSubject = "Screenshot for ".lookup_app_name($this->iAppId)." ".lookup_version_name($this->iVersionId)." deleted by ".$_SESSION['current']->sRealname;
$sMsg = APPDB_ROOT."appview.php?versionId=".$this->iVersionId."\n";
addmsg("Screenshot deleted.", "green");
}
$sEmail = get_notify_email_address_list(null, $this->iVersionId);
if($sEmail)
mail_appdb($sEmail, $sSubject ,$sMsg);
}
}
@@ -165,34 +317,73 @@ class Screenshot {
* Get a random image for a particular version of an app.
* If the version is not set, get a random app image
*/
function get_screenshot_img($appId, $versionId="")
function get_screenshot_img($iAppId = null, $iVersionId = null)
{
if($versionId)
// we want a random screenshots for this app
if($iAppId)
{
$result = query_appdb("SELECT *, RAND() AS rand FROM appData WHERE appId = $appId AND versionId = $versionId AND type = 'image' ORDER BY rand");
$hResult = query_appdb("SELECT appData.*, RAND() AS rand
FROM appData, appVersion
WHERE appData.versionId = appVersion.versionId
AND appVersion.appId = $iAppId
AND type = 'image'
ORDER BY rand");
} else if ($iVersionId) // we want a random screenshot for this version
{
$hResult = query_appdb("SELECT *, RAND() AS rand
FROM appData
WHERE versionId = $iVersionId
AND type = 'image'
ORDER BY rand");
}
else {
$result = query_appdb("SELECT *, RAND() AS rand FROM appData WHERE appId = $appId AND type = 'image' ORDER BY rand");
if(!$hResult || !mysql_num_rows($hResult))
{
$sImgFile = '<img src="'.BASE.'images/no_screenshot.png" alt="No Screenshot" />';
} else
{
$oRow = mysql_fetch_object($hResult);
$sImgFile = '<img src="appimage.php?thumbnail=true&id='.$oRow->id.'" alt="'.$oRow->description.'" />';
}
if(!$result || !mysql_num_rows($result))
{
$imgFile = "<img src='".BASE."images/no_screenshot.png' alt='No Screenshot' />";
}
else
{
$ob = mysql_fetch_object($result);
$imgFile = "<img src=\"appimage.php?thumbnail=true&id=".$ob->id."\" ".
"alt=\"".$ob->description."\" />";
}
$img = html_frame_start("",'128','',2);
if($versionId || mysql_num_rows($result))
$img .= "<a href='screenshots.php?appId=$appId&versionId=$versionId'>$imgFile</a>";
$sImg = html_frame_start("",'128','',2);
if($iVersionId || mysql_num_rows($hResult))
$sImg .= "<a href='screenshots.php?appId=$iAppId&versionId=$iVersionId'>$sImgFile</a>";
else // no link for adding app screenshot as screenshots are linked to versions
$img .= $imgFile;
$img .= html_frame_end()."<br />";
$sImg .= $sImgFile;
$sImg .= html_frame_end()."<br />";
return $img;
return $sImg;
}
function get_screenshots($iAppId = null, $iVersionId = null)
{
/*
* We want all screenshots for this app.
*/
if($iAppId)
{
$sQuery = "SELECT appData.*, appVersion.appId as appId
FROM appData, appVersion
WHERE appVersion.versionId = appData.versionId
AND type = 'image'
AND appId = ".$iAppId;
}
/*
* We want all screenshots for this version.
*/
else if ($iVersionId)
{
$sQuery = "SELECT appData.*, appVersion.appId as appId
FROM appData, appVersion
WHERE appVersion.versionId = appData.versionId
AND type = 'image'
AND appData.versionId = ".$iVersionId;
}
if($sQuery)
{
$hResult = query_appdb($sQuery);
return $hResult;
}
return false;
}
?>