- improve appData and related classes

- don't use a full table for queued appdata but only one field in theapplication and version tables
- simplify the code in many places
- fixes some bugs with screenshots
This commit is contained in:
Jonathan Ernst
2005-02-07 23:49:06 +00:00
committed by WineHQ
parent 7b12f89abf
commit e1c1489279
2 changed files with 63 additions and 109 deletions

View File

@@ -19,15 +19,15 @@ if(!$_SESSION['current']->hasPriv("admin"))
// shows the list of appdata in queue
if (!$_REQUEST['queueId'])
if (!$_REQUEST['id'])
{
apidb_header("Admin Application Data Queue");
// get available appData
$sQuery = "SELECT appDataQueue.*, appVersion.appId AS appId
FROM appDataQueue, appVersion
WHERE appVersion.versionId = appDataQueue.versionID;";
$sQuery = "SELECT appData.*, appVersion.appId AS appId
FROM appData, appVersion
WHERE appVersion.versionId = appData.versionID AND appData.queued = 'true';";
$hResult = query_appdb($sQuery);
if(!$hResult || !mysql_num_rows($hResult))
@@ -51,7 +51,7 @@ if (!$_REQUEST['queueId'])
echo "<tr class=color4>\n";
echo " <td><font color=white>Submission Date</font></td>\n";
echo " <td><font color=white>Queue Id</font></td>\n";
echo " <td><font color=white>Id</font></td>\n";
echo " <td><font color=white>Name (e-mail)</font></td>\n";
echo " <td><font color=white>Application Name</font></td>\n";
echo " <td><font color=white>Version</font></td>\n";
@@ -64,7 +64,7 @@ if (!$_REQUEST['queueId'])
if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
echo "<tr class=$bgcolor>\n";
echo " <td>".date("Y-n-t h:i:sa", $ob->submitTime)." &nbsp;</td>\n";
echo " <td><a href='adminAppDataQueue.php?queueId=$ob->queueId'>".$ob->queueId."</a></td>\n";
echo " <td><a href='adminAppDataQueue.php?id=$ob->id'>".$ob->id."</a></td>\n";
if($ob->userId)
{
$oUser = new User($ob->userId);
@@ -83,10 +83,10 @@ if (!$_REQUEST['queueId'])
}
} else // shows a particular appdata
{
$sQuery = "SELECT appDataQueue.*, appVersion.appId AS appId
FROM appDataQueue,appVersion
WHERE appVersion.versionId = appDataQueue.versionId
AND queueId='".$_REQUEST['queueId']."'";
$sQuery = "SELECT appData.*, appVersion.appId AS appId
FROM appData,appVersion
WHERE appVersion.versionId = appData.versionId
AND id='".$_REQUEST['id']."'";
$hResult = query_appdb($sQuery);
$obj_row = mysql_fetch_object($hResult);
@@ -120,19 +120,19 @@ if (!$_REQUEST['queueId'])
//data
if($obj_row->type == "image")
{
$oScreenshot = new Screenshot($obj_row->queueId,true);
$oScreenshot = new Screenshot($obj_row->id);
echo '<tr valign=top><td class=color0><b>Submited image</b></td>',"\n";
echo '<td>';
$imgSRC = '<img width="'.$oScreenshot->oThumbnailImage->width.'" height="'.$oScreenshot->oThumbnailImage->height.'" src="../appimage.php?queued=true&id='.$obj_row->queueId.'" />';
$imgSRC = '<img width="'.$oScreenshot->oThumbnailImage->width.'" height="'.$oScreenshot->oThumbnailImage->height.'" src="../appimage.php?queued=true&id='.$obj_row->id.'" />';
// generate random tag for popup window
$randName = generate_passwd(5);
// set image link based on user pref
$img = '<a href="javascript:openWin(\'../appimage.php?queued=true&id='.$obj_row->queueId.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>';
$img = '<a href="javascript:openWin(\'../appimage.php?queued=true&id='.$obj_row->id.'\',\''.$randName.'\','.$oScreenshot->oScreenshotImage->width.','.($oScreenshot->oScreenshotImage->height+4).');">'.$imgSRC.'</a>';
if ($_SESSION['current']->isLoggedIn())
{
if ($_SESSION['current']->getpref("window:screenshot") == "no")
{
$img = '<a href="../appimage.php?queued=true&id='.$obj_row->queueId.'">'.$imgSRC.'</a>';
$img = '<a href="../appimage.php?queued=true&id='.$obj_row->id.'">'.$imgSRC.'</a>';
}
}
echo $img;
@@ -157,7 +157,7 @@ if (!$_REQUEST['queueId'])
echo '</table>',"\n";
echo '<input type=hidden name="sub" value="inside_form" />',"\n";
echo '<input type=hidden name="queueId" value="'.$_REQUEST['queueId'].'" />',"\n";
echo '<input type=hidden name="id" value="'.$_REQUEST['id'].'" />',"\n";
echo '</form>';
} elseif ($_REQUEST['add']) // we accepted the request
{
@@ -166,7 +166,7 @@ if (!$_REQUEST['queueId'])
if($obj_row->type == "image")
{
$oScreenshot = new Screenshot($obj_row->queueId,true);
$oScreenshot = new Screenshot($obj_row->id);
$oScreenshot->unQueue();
}
elseif ($obj_row->type == "url")
@@ -178,7 +178,7 @@ if (!$_REQUEST['queueId'])
$statusMessage = "<p>The application data was successfully added into the database</p>\n";
//delete the item from the queue
query_appdb("DELETE from appDataQueue where queueId = ".$obj_row->queueId.";");
query_appdb("DELETE from appData where id = ".$obj_row->id.";");
//Send Status Email
$oUser = new User($obj_row->userId);
@@ -198,7 +198,7 @@ if (!$_REQUEST['queueId'])
{
if($obj_row->type == "image")
{
$oScreenshot = new Screenshot($obj_row->queueId,true);
$oScreenshot = new Screenshot($obj_row->id);
$oScreenshot->delete();
}
elseif ($obj_row->type == "url")
@@ -213,7 +213,7 @@ if (!$_REQUEST['queueId'])
}
//delete main item
$sQuery = "DELETE from appDataQueue where queueId = ".$obj_row->queueId.";";
$sQuery = "DELETE from appData where id = ".$obj_row->id.";";
$hResult = query_appdb($sQuery);
if($hResult)
{

View File

@@ -15,56 +15,39 @@ class Screenshot {
var $sDescription;
var $oScreenshotImage;
var $oThumbnailImage;
var $sTable;
var $sTableId;
var $userId;
var $bQueued;
var $iVersionId;
var $iAppId;
var $sDirectory;
var $sUrl;
var $sSubmitTime;
var $iSubmitterId;
/**
* Constructor, fetches the data and image objects if $iScreenshotId is given.
*/
function Screenshot($iScreenshotId = null,$bQueued = false)
function Screenshot($iScreenshotId = null)
{
if($bQueued)
{
$this->bQueued = true;
$this->sTable = appDataQueue;
$this->sTableId = queueId;
$this->sDirectory = "queued/screenshots";
} else
{
$this->bQueued = false;
$this->sTable = appData;
$this->sTableId = id;
$this->sDirectory = "screenshots";
}
// we are working on an existing screenshot
if($iScreenshotId)
{
$sQuery = "SELECT ".$this->sTable.".*, appVersion.appId AS appId
FROM ".$this->sTable.", appVersion
WHERE ".$this->sTable.".versionId = appVersion.versionId
AND ".$this->sTableId." = ".$iScreenshotId."
$sQuery = "SELECT appData.*, appVersion.appId AS appId
FROM appData, appVersion
WHERE appData.versionId = appVersion.versionId
AND id = ".$iScreenshotId."
AND type = 'image'";
if($hResult = query_appdb($sQuery))
{
$oRow = mysql_fetch_object($hResult);
$this->iScreenshotId = $iScreenshotId;
$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->oScreenshotImage = new Image("/data/screenshots/".$oRow->url);
$this->oThumbnailImage = new Image("/data/screenshots/thumbnails/".$oRow->url);
$this->iAppId = $oRow->appId;
$this->iVersionId = $oRow->versionId;
$this->sUrl = $oRow->url;
if(!$this->iSubmitterId && $oRow->userId)
$this->iSubmitterId = $oRow->userId;
$this->bQueued = $oRow->queued;
$this->sSubmitTime = $oRow->submitTime;
$this->iSubmitterId = $oRow->submitterId;
}
}
}
@@ -75,38 +58,31 @@ class 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->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."))
$aInsert = compile_insert_string(array( 'versionId' => $iVersionId,
'type' => "image",
'description' => $sDescription,
'queued' => $this->bQueued,
'submitterId' => $_SESSION['current']->iUserId ));
$sFields = "({$aInsert['FIELDS']})";
$sValues = "({$aInsert['VALUES']})";
if(query_appdb("INSERT INTO appData $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))
if(!move_uploaded_file($hFile['tmp_name'], "data/screenshots/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");
addmsg("Unable to move screenshot from ".$hFile['tmp_name']." to data/screenshots/originals/".$this->iScreenshotId, "red");
$sQuery = "DELETE
FROM ".$this->sTable."
WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
FROM appData
WHERE id = '".$this->iScreenshotId."'";
query_appdb($sQuery);
return false;
} else // we managed to copy the file, now we have to process the image
@@ -114,9 +90,9 @@ class Screenshot {
$this->sUrl = $this->iScreenshotId;
$this->generate();
// we have to update the entry now that we know its name
$sQuery = "UPDATE ".$this->sTable."
$sQuery = "UPDATE appData
SET url = '".$this->iScreenshotId."'
WHERE ".$this->sTableId." = '".$this->iScreenshotId."'";
WHERE id = '".$this->iScreenshotId."'";
if (!query_appdb($sQuery)) return false;
}
@@ -135,15 +111,15 @@ class Screenshot {
*/
function delete($bSilent=false)
{
$sQuery = "DELETE FROM ".$this->sTable."
WHERE ".$this->sTableId." = ".$this->iScreenshotId."
$sQuery = "DELETE FROM appData
WHERE id = ".$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);
unlink($_SERVER['DOCUMENT_ROOT']."/data/screenshots/originals/".$this->iScreenshotId);
if(!$bSilent)
$this->mailMaintainers(true);
}
@@ -163,36 +139,12 @@ class Screenshot {
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."))
$sUpdate = compile_update_string(array('queued' => "false"));
if(query_appdb("UPDATE appData SET ".$sUpdate." WHERE id=".$this->iScreenshotId))
{
$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();
// the screenshot has been unqueued
addmsg("The screenshot has been unqueued.", "green");
}
@@ -216,7 +168,7 @@ class Screenshot {
*/
function setDescription($sDescription)
{
$sQuery = "UPDATE ".$this->sTableId." SET description = '".$sDescription."' WHERE ".$this->sTableId." = ".$this->iScreenshotId." AND type = 'image'";
$sQuery = "UPDATE id SET description = '".$sDescription."' WHERE id = ".$this->iScreenshotId." AND type = 'image'";
if($hResult = query_appdb($sQuery))
$this->sDescription = $sDescription;
}
@@ -231,25 +183,25 @@ class Screenshot {
global $watermark;
// first we will create the thumbnail
// load the screenshot
$this->oThumbnailImage = new Image("/data/".$this->sDirectory."/originals/".$this->sUrl);
$this->oThumbnailImage = new Image("/data/screenshots/originals/".$this->sUrl);
$this->oThumbnailImage->make_thumb(0,0,1,'#000000');
// store the image
$this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/thumbnails/".$this->sUrl);
$this->oThumbnailImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/thumbnails/".$this->sUrl);
// now we'll process the screenshot image for watermarking
// load the screenshot
$this->oScreenshotImage = new Image("/data/".$this->sDirectory."/originals/".$this->sUrl);
$this->oScreenshotImage = new Image("/data/screenshots/originals/".$this->sUrl);
// resize the image
$this->oScreenshotImage->make_full();
// store the resized image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/".$this->sUrl);
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl);
// reload the resized screenshot
$this->oScreenshotImage = new Image("/data/".$this->sDirectory."/".$this->sUrl);
$this->oScreenshotImage = new Image("/data/screenshots/".$this->sUrl);
// add the watermark to the screenshot
$this->oScreenshotImage->add_watermark($watermark->get_image_resource());
// store the watermarked image
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/".$this->sDirectory."/".$this->sUrl);
$this->oScreenshotImage->output_to_file($_SERVER['DOCUMENT_ROOT']."/data/screenshots/".$this->sUrl);
}
@@ -358,7 +310,7 @@ function get_screenshot_img($iAppId = null, $iVersionId = null)
return $sImg;
}
function get_screenshots($iAppId = null, $iVersionId = null)
function get_screenshots($iAppId = null, $iVersionId = null, $bQueued = "false")
{
/*
* We want all screenshots for this app.
@@ -369,7 +321,8 @@ function get_screenshots($iAppId = null, $iVersionId = null)
FROM appData, appVersion
WHERE appVersion.versionId = appData.versionId
AND type = 'image'
AND appData.appId = ".$iAppId;
AND appVersion.appId = ".$iAppId."
AND appData.queued = '".$bQueued."'";
}
/*
* We want all screenshots for this version.
@@ -380,7 +333,8 @@ function get_screenshots($iAppId = null, $iVersionId = null)
FROM appData, appVersion
WHERE appVersion.versionId = appData.versionId
AND type = 'image'
AND appData.versionId = ".$iVersionId;
AND appData.versionId = ".$iVersionId."
AND appData.queued = '".$bQueued."'";
}
if($sQuery)
{