From 160f739da867909846ffd00b1cd31da2e6f32ccd Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 11 Jul 2006 03:37:07 +0000 Subject: [PATCH] Screenshot class cleanups. Move screenshot related functions into the class. Rename get_screenshot_img() to get_random_screenshot_img() so the name of the function matches its purpose --- admin/adminScreenshots.php | 3 +- include/application.php | 2 +- include/screenshot.php | 210 ++++++++++++++++++------------------- include/util.php | 2 +- include/version.php | 2 +- screenshots.php | 5 +- viewScreenshots.php | 3 +- 7 files changed, 112 insertions(+), 115 deletions(-) diff --git a/admin/adminScreenshots.php b/admin/adminScreenshots.php index d015bc0..d98bdf3 100644 --- a/admin/adminScreenshots.php +++ b/admin/adminScreenshots.php @@ -118,7 +118,8 @@ while ($oRow = mysql_fetch_object($Ids)) // display thumbnail $oVersion = new version($oRow->versionId); $oApp = new Application($oVersion->iAppId); - $img = get_thumbnail($oRow->id); + $oScreenshot = new Screenshot($oRow->id); + $img = $oScreenshot->get_thumbnail_img(); echo "\n"; echo $img; echo "
". substr($oRow->description,0,20). "\n"; diff --git a/include/application.php b/include/application.php index 99c8468..f38ac1d 100644 --- a/include/application.php +++ b/include/application.php @@ -545,7 +545,7 @@ class Application { } // image - $img = get_screenshot_img($this->iAppId); + $img = Screenshot::get_random_screenshot_img($this->iAppId); echo "$img\n"; echo " \n"; /* close of name/vendor/bugs/url table */ diff --git a/include/screenshot.php b/include/screenshot.php index 47404f5..d570267 100644 --- a/include/screenshot.php +++ b/include/screenshot.php @@ -359,142 +359,136 @@ class Screenshot { if($sEmail) mail_appdb($sEmail, $sSubject ,$sMsg); } -} - -/* - * Screenshot functions that are not part of the class - */ - -/** - * Get a random image for a particular version of an app. - * If the version is not set, get a random app image - * - * $bFormatting == false turns off all extranious formatting applied to the returned image html - */ -function get_screenshot_img($iAppId = null, $iVersionId = null, - $bFormatting = true) -{ - // we want a random screenshots for this app - if($iAppId && !$iVersionId) + /** + * Get a random image for a particular version of an app. + * If the version is not set, get a random app image + * + * $bFormatting == false turns off all extranious formatting applied to the returned image html + */ + function get_random_screenshot_img($iAppId = null, $iVersionId = null, + $bFormatting = true) { - $hResult = query_parameters("SELECT appData.id, appData.description, RAND() AS rand + // we want a random screenshots for this app + if($iAppId && !$iVersionId) + { + $hResult = query_parameters("SELECT appData.id, appData.description, RAND() AS rand FROM appData, appVersion WHERE appData.versionId = appVersion.versionId AND appVersion.appId = '?' AND type = 'image' AND appData.queued = 'false' ORDER BY rand", $iAppId); - } else if ($iVersionId) // we want a random screenshot for this version - { - $hResult = query_parameters("SELECT id, description, RAND() AS rand + } else if ($iVersionId) // we want a random screenshot for this version + { + $hResult = query_parameters("SELECT id, description, RAND() AS rand FROM appData WHERE versionId = '?' AND type = 'image' AND queued = 'false' ORDER BY rand", $iVersionId); + } + + if($bFormatting) + $sImgFile .= '
'; + + if(!$hResult || !mysql_num_rows($hResult)) + { + $sImgFile = 'No Screenshot'; + } else + { + $oRow = mysql_fetch_object($hResult); + $sImgFile = ''.$oRow->description.''; + } + + if($bFormatting) + $sImgFile .= '
'; + + if($bFormatting) + $sImg = html_frame_start("",'128','',2); + + /* we have screenshots */ + if(mysql_num_rows($hResult)) + { + if($iVersionId) + $sImg .= "$sImgFile
View/Submit Screenshot
"; + else + $sImg .= "$sImgFile
View Screenshot
"; + } else if($iVersionId) /* we are asking for a specific app version but it has no screenshots */ + { + $sImg .= "$sImgFile
Submit Screenshot
"; + } else /* we have no screenshots and we aren't a specific version, we don't allow adding screenshots for an app */ + { + $sImg .= $sImgFile; + } + + if($bFormatting) + $sImg .= html_frame_end()."
"; + + return $sImg; } - if($bFormatting) - $sImgFile .= '
'; - - if(!$hResult || !mysql_num_rows($hResult)) + function get_screenshots($iAppId = null, $iVersionId = null, $bQueued = "false") { - $sImgFile = 'No Screenshot'; - } else - { - $oRow = mysql_fetch_object($hResult); - $sImgFile = ''.$oRow->description.''; - } - - if($bFormatting) - $sImgFile .= '
'; - - if($bFormatting) - $sImg = html_frame_start("",'128','',2); - - /* we have screenshots */ - if(mysql_num_rows($hResult)) - { - if($iVersionId) - $sImg .= "$sImgFile
View/Submit Screenshot
"; - else - $sImg .= "$sImgFile
View Screenshot
"; - } else if($iVersionId) /* we are asking for a specific app version but it has no screenshots */ - { - $sImg .= "$sImgFile
Submit Screenshot
"; - } else /* we have no screenshots and we aren't a specific version, we don't allow adding screenshots for an app */ - { - $sImg .= $sImgFile; - } - - if($bFormatting) - $sImg .= html_frame_end()."
"; - - return $sImg; -} - -function get_screenshots($iAppId = null, $iVersionId = null, $bQueued = "false") -{ - /* - * We want all screenshots for this app. - */ - if($iAppId && !$iVersionId) - { - $hResult = query_parameters("SELECT appData.*, appVersion.appId as appId + /* + * We want all screenshots for this app. + */ + if($iAppId && !$iVersionId) + { + $hResult = query_parameters("SELECT appData.*, appVersion.appId as appId FROM appData, appVersion WHERE appVersion.versionId = appData.versionId AND type = 'image' AND appVersion.appId = '?' AND appData.queued = '?'", $iAppId, $bQueued); - } - /* - * We want all screenshots for this version. - */ - else if ($iVersionId) - { - $hResult = query_parameters("SELECT appData.*, appVersion.appId as appId + } + /* + * We want all screenshots for this version. + */ + else if ($iVersionId) + { + $hResult = query_parameters("SELECT appData.*, appVersion.appId as appId FROM appData, appVersion WHERE appVersion.versionId = appData.versionId AND type = 'image' AND appData.versionId = '?' AND appData.queued = '?'", $iVersionId, $bQueued); - } else - { - return false; - } - - return $hResult; -} - -function get_thumbnail($id) -{ - $oScreenshot = new Screenshot($id); - - // generate random tag for popup window - $randName = User::generate_passwd(5); - // set img tag - $imgSRC = ''.$oScreenshot->sDescription.
-               ''; - $img = 'get_screenshot_width() + 20).','. - ($oScreenshot->get_screenshot_height() + 6). - ');return false;">'.$imgSRC.''; - - // set image link based on user pref - if ($_SESSION['current']->isLoggedIn()) - { - if ($_SESSION['current']->getpref("window:screenshot") == "no") + } else { - $img = ''.$imgSRC.''; + return false; } + + return $hResult; + } + + function get_thumbnail_img() + { + // generate random tag for popup window + $sRandName = User::generate_passwd(5); + // set img tag + $shImgSRC = 'iScreenshotId.'" alt="'.$this->sDescription. + '" width="'.$this->get_thumbnail_width(). + '" height="'.$this->get_thumbnail_height().'">'; + $shImg = 'get_screenshot_width() + 20).','. + ($this->get_screenshot_height() + 6). + ');return false;">'.$shImgSRC.''; + + // set image link based on user pref + if ($_SESSION['current']->isLoggedIn()) + { + if ($_SESSION['current']->getpref("window:screenshot") == "no") + { + $shImg = ''.$shImgSRC.''; + } + } + return $shImg; } - return $img; } + ?> diff --git a/include/util.php b/include/util.php index 37dd9f7..46a5c0c 100644 --- a/include/util.php +++ b/include/util.php @@ -291,7 +291,7 @@ function outputTopXRow($oRow) { $oVersion = new Version($oRow->versionId); $oApp = new Application($oVersion->iAppId); - $img = get_screenshot_img(null, $oRow->versionId, false); // image, disable extra formatting + $img = Screenshot::get_random_screenshot_img(null, $oRow->versionId, false); // image, disable extra formatting echo ' '.$oApp->sName.' '.$oVersion->sName.' diff --git a/include/version.php b/include/version.php index f45be9b..2063f8a 100644 --- a/include/version.php +++ b/include/version.php @@ -657,7 +657,7 @@ class Version { echo "Maintainers Version".$this->sTestedRelease."\n"; // image - $img = get_screenshot_img($oApp->iAppId, $this->iVersionId); + $img = Screenshot::get_random_screenshot_img($oApp->iAppId, $this->iVersionId); echo "$img\n"; // display all maintainers of this application diff --git a/screenshots.php b/screenshots.php index 03a0354..f7c9ab9 100644 --- a/screenshots.php +++ b/screenshots.php @@ -52,7 +52,7 @@ if($aClean['sCmd']) // we didn't issued any command -$hResult = get_screenshots($aClean['iAppId'], $aClean['iVersionId']); +$hResult = Screenshot::get_screenshots($aClean['iAppId'], $aClean['iVersionId']); apidb_header("Screenshots"); $oApp = new Application($aClean['iAppId']); $oVersion = new Version($aClean['iVersionId']); @@ -78,7 +78,8 @@ if($hResult && mysql_num_rows($hResult)) echo html_frame_start("Version ".Version::lookup_name($currentVersionId)); echo "
\n"; } - $img = get_thumbnail($oRow->id); + $oScreenshot = new Screenshot($oRow->id); + $img = $oScreenshot->get_thumbnail_img(); // display image echo "
\n"; echo $img; diff --git a/viewScreenshots.php b/viewScreenshots.php index 8e33431..61acb6b 100644 --- a/viewScreenshots.php +++ b/viewScreenshots.php @@ -69,7 +69,8 @@ while ($oRow = mysql_fetch_object($Ids)) // display thumbnail $oVersion = new version($oRow->versionId); $oApp = new Application($oVersion->iAppId); - $img = get_thumbnail($oRow->id); + $oScreenshot = new Screenshot($oRow->id); + $img = $oScreenshot->get_thumbnail_img(); echo "\n"; echo $img; echo "
". substr($oRow->description,0,20). "\n";