public static function createFromFile($filename, $mime_type, $objAlbum) { $objPicture = new clsPicture(); /* Decide which incoming mime type it is. */ switch ($mime_type) { case 'image/jpeg': $img = ImageCreateFromJpeg($filename); break; case 'image/png': $img = ImageCreateFromPng($filename); break; case 'image/gif': $img = ImageCreateFromGif($filename); break; default: return 'image_filetype'; } list($intWidth, $intHeight) = getImageSize($filename); $intMaxWidth = $objAlbum->get('max_width'); $intMaxHeight = $objAlbum->get('max_height'); if ($intMaxWidth <= 0) { $intMaxWidth = DEFAULT_X; } if ($intMaxHeight <= 0) { $intMaxHeight = DEFAULT_Y; } if ($intWidth > $intMaxWidth || $intHeight > $intMaxHeight) { /* Check whether the image needs to be resized vertically or horizonally more. */ if ($intWidth / $intMaxWidth > $intHeight / $intMaxHeight) { /* Right-left needs to have priority. */ $ratio = $intMaxWidth / $intWidth; } else { /* Up-down needs to have priority. */ $ratio = $intMaxHeight / $intHeight; } $intNewWidth = $intWidth * $ratio; $intNewHeight = $intHeight * $ratio; $imgNew = @ImageCreateTrueColor($intNewWidth, $intNewHeight); if (!@ImageCopyResized($imgNew, $img, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight)) { return "image_noresize"; } $intWidth = $intNewWidth; $intHeight = $intNewHeight; ImageDestroy($img); $img = $imgNew; } /* This has to be done before setImage() because setImage() needs data from the album. */ $objPicture->set('album_id', $objAlbum->get('id')); $result = $objPicture->setImage($img); ImageDestroy($img); if ($result) { return $result; } $objPicture->set('width', $intWidth); $objPicture->set('height', $intHeight); $objPicture->save(); return $objPicture; }
$objTemplate->setText('ERROR', "You are not allowed to post pictures in that category."); } $strSubAction = 'preview'; } } if ($strSubAction == 'delete') { $user_id = $objUser ? $objUser->get('id') : 0; $objPicture = new clsPicture(); $objPicture->getFromRequest(); $objPicture->load(); if ($objPicture->get('user_id') != $user_id) { throw new Exception('exception_accessdenied'); } /* Make sure that users can only edit their own pictures. */ $objPicture->delete(); $objPicture->save(); header("Location: index.php?action=upload&subaction=preview"); } if ($strSubAction == 'preview') { $objTemplate->setText('PAGETITLE', "Pending Pictures"); $objBreadcrumbs->add('Upload', 'index.php?action=upload'); $objBreadcrumbs->add('Pending', 'index.php?action=upload&subaction=preview'); $arrPictures = clsPicture::getPending($objUser); print "You have <strong>" . sizeof($arrPictures) . "</strong> pictures waiting for attention" . ($objUser ? "" : " (note: unsaved images from all guests will appear here)") . ":<br><br>"; foreach ($arrPictures as $objPicture) { $objPicture = new clsPicture($objPicture->get('id')); $objAlbum = new clsAlbum($objPicture->get('album_id')); $objTemplate = new clsTemplate('preview'); $objTemplate->setText('HIDDEN', $objPicture->getHiddenField('id')); $objTemplate->setText('ALBUM', $objPicture->getCombo('album_id', clsDB::getOptionsFromList($objAlbum->getPostableAlbums($objUser), 'name', 'id', "Select an album"))); $objTemplate->setText('ID', $objPicture->get('id'));