openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 324a0aed3ffd2335408e74b26a9d7ee255c64a29
parent 13006307badcaaba4879b30afcbf75f2ac56112e
Author: dankert <devnull@localhost>
Date:   Sun, 28 Nov 2004 22:28:20 +0100

Bildbearbeitung erweitert

Diffstat:
actionClasses/FileAction.class.php | 68+++++++++++++++++++++++++++++++-------------------------------------
objectClasses/File.class.php | 93++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
themes/default/pages/html/file/edit.tpl.php | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 217 insertions(+), 57 deletions(-)

diff --git a/actionClasses/FileAction.class.php b/actionClasses/FileAction.class.php @@ -20,7 +20,10 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------------------------------------------- // $Log$ -// Revision 1.7 2004-11-27 13:05:59 dankert +// Revision 1.8 2004-11-28 21:27:21 dankert +// Bildbearbeitung erweitert +// +// Revision 1.7 2004/11/27 13:05:59 dankert // Einzelne Funktionen verlagert // // Revision 1.6 2004/09/26 12:12:31 dankert @@ -81,8 +84,9 @@ class FileAction extends ObjectAction $this->file->saveValue(); //$setTemplateVar('tree_refresh',true); + $this->addNotice($this->file->getType(),$this->file->name,'VALUE_SAVED','ok'); - $this->callSubAction('show'); + $this->callSubAction('edit'); } @@ -91,7 +95,8 @@ class FileAction extends ObjectAction $this->file->value = $this->getRequestVar('value'); $this->file->saveValue(); - $this->callSubAction('show'); + $this->addNotice($this->file->getType(),$this->file->name,'VALUE_SAVED','ok'); + $this->callSubAction('edit'); } @@ -99,12 +104,13 @@ class FileAction extends ObjectAction { global $SESS; - // Wenn Dateiname gef?llt, dann Datenbank-Update + // Wenn Dateiname gefuellt, dann Datenbank-Update if ( $this->getRequestVar('delete') != '' ) { - // Datei l?schen + // Datei loeschen $this->file->delete(); + $this->addNotice($this->file->getType(),$this->file->name,'DELETED','ok'); unset( $SESS['objectid'] ); } else @@ -115,11 +121,12 @@ class FileAction extends ObjectAction $this->file->extension = $this->getRequestVar('extension'); $this->file->desc = $this->getRequestVar('desc' ); + $this->addNotice($this->file->getType(),$this->file->name,'PROP_SAVED','ok'); $this->file->save(); } $this->setTemplateVar('tree_refresh',true); - $this->callSubAction('show'); + $this->callSubAction('prop'); } @@ -156,29 +163,27 @@ class FileAction extends ObjectAction */ function resize() { - $width = $this->getRequestVar('width' ); - $height = $this->getRequestVar('height'); + $width = intval($this->getRequestVar('width' )); + $height = intval($this->getRequestVar('height' )); + $jpegcompression = $this->getRequestVar('jpeg_compression') ; + $format = $this->getRequestVar('format' ) ; - if ( $width != '' || $height != '' ) - - $this->file->imageResize( intval($width),intval($height) ); + $this->file->imageResize( intval($width),intval($height),$format,$jpegcompression ); $this->file->save(); $this->file->saveValue(); - $this->callSubAction('show'); + $this->addNotice($this->file->getType(),$this->file->name,'IMAGE_RESIZED','ok'); + $this->callSubAction('edit'); } function prop() { - // MIME-Types aus Datei lesen + // Eigenschaften der Datei uebertragen $this->setTemplateVars( $this->file->getProperties() ); $this->setTemplateVar('full_filename',$this->file->full_filename()); - if ( substr($this->file->mimetype(),0,5) == 'text/' ) - $var['src_url'] = Html::url(array('fileaction'=>'src')); - if ( is_numeric($this->file->lastchange_userid) ) { $user = new User( $this->file->lastchange_userid ); @@ -205,23 +210,6 @@ class FileAction extends ObjectAction $this->setTemplateVar('create_user',array('name'=>lang('UNKNOWN'))); } - // Alle Ordner ermitteln - $this->setTemplateVar('act_folderobjectid',$this->file->parentid); - $list = array(); - - $f = new Folder( $this->file->parentid ); - - foreach( $f->getOtherFolders() as $oid ) - { - $folder = new Folder( $oid ); - $folder->load(); - $list[$oid] = implode(' &raquo; ',$folder->parentObjectNames(true,true) ); - } - asort( $list ); - $this->setTemplateVar('folderobject',$list); - - - // Alle Seiten mit dieser Datei ermitteln $pages = $this->file->getDependentObjectIds(); @@ -239,16 +227,22 @@ class FileAction extends ObjectAction $this->forward( 'file_prop' ); } - + /** * Anzeigen des Inhaltes */ - function src() + function edit() { + global $conf; + // MIME-Types aus Datei lesen + $this->setTemplateVars( $this->file->getProperties() ); $this->setTemplateVar('value',$this->file->loadValue()); - - $this->forward('file_src'); + $formats = array(); + foreach( explode(',',$conf['gd']['extension']) as $f ) + $formats[$f] = $f; + $this->setTemplateVar('formats',$formats); + $this->forward('file_edit'); } diff --git a/objectClasses/File.class.php b/objectClasses/File.class.php @@ -20,7 +20,10 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // --------------------------------------------------------------------------- // $Log$ -// Revision 1.3 2004-11-10 22:45:24 dankert +// Revision 1.4 2004-11-28 21:28:05 dankert +// Bildbearbeitung erweitert +// +// Revision 1.3 2004/11/10 22:45:24 dankert // *** empty log message *** // // Revision 1.2 2004/05/02 14:41:31 dankert @@ -178,7 +181,7 @@ class File extends Object } - function imageResize( $newWidth,$newHeight ) + function imageResize( $newWidth,$newHeight,$format,$jpegquality ) { global $conf; @@ -195,6 +198,18 @@ class File extends Object $oldHeight = $size[1]; $aspectRatio = $oldHeight / $oldWidth; // Seitenverhaeltnis + // Wenn Breite und Hoehe fehlen, dann Bildgroesse beibehalten + if ( $newWidth == 0 && $newHeight == 0) + { + $newWidth = $oldWidth; + $newHeight = $oldHeight; + $resizing = false; + } + else + { + $resizing = true; + } + // Wenn nur Breite oder Hoehe angegeben ist, dann // das Seitenverhaeltnis beibehalten if ( $newWidth == 0 ) @@ -203,24 +218,58 @@ class File extends Object if ( $newHeight == 0 ) $newHeight = $newWidth * $aspectRatio; - switch( $size[2] ) + + switch( strtolower($this->extension) ) { - case '1': // GIF + case 'gif': // GIF $oldImage = ImageCreateFromGIF( $this->tmpfile ); - $newImage = ImageCreate($newWidth,$newHeight); - ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, - $newHeight,$oldWidth,$oldHeight); - ImageGIF($newImage, $this->tmpfile() ); + break; + + case 'jpg': + case 'jpeg': // JPEG + + $oldImage = ImageCreateFromJPEG($this->tmpfile); + break; + + case 'png': // PNG + + $oldImage = imagecreatefrompng($this->tmpfile); + break; + + default: + die('unsupported image format "'.$this->extension.'", cannot load image. resize failed'); + } + + + switch( $format ) + { + case 'gif': // GIF + + if ( $resizing ) + { + $newImage = ImageCreate($newWidth,$newHeight); + ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, + $newHeight,$oldWidth,$oldHeight); + } + else + { + $newImage = $oldImage; + } + + ImageGIF($newImage, $this->tmpfile() ); $this->extension = 'gif'; break; - case '2': // JPEG + case 'jpg': + case 'jpeg': // JPEG - $oldImage = ImageCreateFromJPEG($this->tmpfile); - - if ( $gd2 ) + if ( !$resizing ) + { + $newImage = $oldImage; + } + elseif ( $gd2 ) { // Verwende TrueColor $newImage = imageCreateTrueColor( $newWidth,$newHeight ); @@ -230,22 +279,25 @@ class File extends Object } else { - // GD Version 1.x unterst?tzt kein TrueColor + // GD Version 1.x unterstuetzt kein TrueColor $newImage = ImageCreate($newWidth,$newHeight); ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, $newHeight,$oldWidth,$oldHeight); } - ImageJPEG($newImage, $this->tmpfile ); + ImageJPEG($newImage, $this->tmpfile,$jpegquality ); $this->extension = 'jpeg'; break; - case '3': // PNG + case 'png': // PNG - $oldImage = imagecreatefrompng($this->tmpfile); - if ( $gd2 ) + if ( !$resizing ) + { + $newImage = $oldImage; + } + elseif ( $gd2 ) { // Verwende TrueColor $newImage = imageCreateTrueColor( $newWidth,$newHeight ); @@ -255,7 +307,7 @@ class File extends Object } else { - // GD Version 1.x unterst?tzt kein TrueColor + // GD Version 1.x unterstuetzt kein TrueColor $newImage = ImageCreate($newWidth,$newHeight); ImageCopyResized($newImage,$oldImage,0,0,0,0,$newWidth, @@ -268,7 +320,7 @@ class File extends Object break; default: - die('unsupported type for resizing'); + die('unsupported image format "'.$format.'", cannot resize'); } $f = fopen( $this->tmpfile(), "r" ); @@ -316,7 +368,8 @@ class File extends Object */ function isImage() { - return eregi('jpe?g|png|gif',$this->extension); + //return eregi('jpe?g|png|gif',$this->extension); + return substring($this->mimeType(),0,6)=='image/'; } diff --git a/themes/default/pages/html/file/edit.tpl.php b/themes/default/pages/html/file/edit.tpl.php @@ -0,0 +1,112 @@ +<?php include( $tpl_dir.'header.tpl.php') ?> + +<!-- $Id$ --> +<center> + +<table class="main" width="90%" cellspacing="0" cellpadding="4"> + +<tr> + <th colspan="2"><?php echo lang('FILE_REPLACE') ?></th> +</tr> +<tr> + <td colspan="2" class="help"><?php echo lang('FILE_REPLACE_DESC') ?></td> +</tr> + +<tr> +<td colspan="2" class="act"> + <form action="<?php echo $self ?>" method="post" enctype="multipart/form-data"> + <input type="hidden" name="action" value="file"> + <input type="hidden" name="subaction" value="replace"> + <input type="file" name="file"> <input type="submit" class="submit" value="<?php echo lang('GLOBAL_UPLOAD') ?>"> + </form> + +</td> +</tr> + +</table> + +<?php if ( substr($mimetype,0,6) == 'image/' ) + { ?> +<form action="<?php echo $self ?>" method="post" target="_self"> + +<input type="hidden" name="action" value="file"> +<input type="hidden" name="subaction" value="resize"> + +<table class="main" width="90%" cellspacing="0" cellpadding="4"> + +<tr> + <th colspan="2"><?php echo lang('FILE_IMAGE_RESIZE') ?></th> +</tr> +<tr> + <td colspan="2" class="help"><?php echo lang('FILE_IMAGE_RESIZE_DESC') ?></td> +</tr> + +<tr> +<td width="50%" class="f2"><?php echo lang('FILE_IMAGE_NEW_WIDTH') ?></td> +<td width="50%" class="f2"><input type="text" name="width" value=""></td> +</tr> +<tr> +<td width="50%" class="f2"><?php echo lang('FILE_IMAGE_NEW_HEIGHT') ?></td> +<td width="50%" class="f2"><input type="text" name="height" value=""></td> +</tr> +<tr> +<td width="50%" class="f2"><?php echo lang('FILE_IMAGE_FORMAT') ?></td> +<td width="50%" class="f2"><?php echo Html::selectBox('format',$formats,$extension) ?></td> +</tr> +<tr> +<td width="50%" class="f2"><?php echo lang('FILE_IMAGE_JPEG_COMPRESSION') ?></td> +<?php + $jpeglist = array(); + for ($i=10; $i<=95; $i+=5) + $jpeglist[$i]=$i.'%'; +?> +<td width="50%" class="f2"><?php echo Html::selectBox('jpeg_compression',$jpeglist,'70') ?></td> +</tr> + +<tr> +<td class="act" colspan="2"><input type="submit" class="submit" value="<?php echo lang('FILE_IMAGE_RESIZE') ?>"></td> +</tr> + +</table> + +</form> +<?php } ?> + + + + + +<?php if ( substr($mimetype,0,5) == 'text/' ) + { ?> + +<form action="<?php echo $self ?>" method="post" target="_self"> + +<input type="hidden" name="action" value="file"> +<input type="hidden" name="subaction" value="savevalue"> + +<table class="main" width="90%" cellspacing="0" cellpadding="4"> + +<tr> + <th colspan="2"><?php echo lang('GLOBAL_VALUE') ?></th> +</tr> + +<tr> +<td class="f2"><?php echo lang('GLOBAL_VALUE') ?></a></td> +<td class="f2"><textarea cols="60" rows="35" name="value"><?php echo htmlentities($value) ?></textarea></td> +</tr> +<tr> +<td class="act" colspan="2"><input type="submit" class="submit" value="<?php echo lang('GLOBAL_SAVE') ?>"></td> +</tr> + +</table> + +</form> +<?php } ?> + + + +</center> + +<?php Html::focusField('name') ?> + +<?php include( $tpl_dir.'footer.tpl.php') ?>+ \ No newline at end of file