/* **************************************************************************
* webimage.php
***************************************************************************/
/* **************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
/**
* This add-on handle displayable images (JPEG, GIF, PNG...) and show thumbnails when
* possible.
*
* If image format is supported, the GD library resize it to create a thumbnail in
* thumbnails folder.
* To increase speed, if a thumbnail already exists and have same size than wanted size (see (@link
* config.php}), it's not created again.
* A click on the reduced image open a popup with full size image.
* If image size is lower than limits you configure, it'll be simply displayed.
*
* The limits are image height, width and filesize.
*
* If image format isn't supported or you set {@link $IMG_displayThumbnail} to false,
* an icon will allow you to see image in a popup.
*
* In {@link config.php}, look at all these variables :
* - {@link $ADDON_allowDirectPreview}
* - {@link $IMG_displayThumbnail}
* - {@link $IMG_maxHeight}
* - {@link $IMG_maxWidth}
* - {@link $IMG_maxSize}
*
* The thumbnails are created if a thumbnails exist in custom folder or in main engine folder
* (see {@link index.php}). Under linux, check folder permissions. If thumbnails is unwriteable,
* they are not generated !
*
* @author Sylvain Machefert
* @copyright Copyright (C) 2004, Sylvain Machefert
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @package Add-Ons-File
*
* @todo Thumbnails : manage PNG transparency when no 100% transparent. Seems to be very hard with GD.
*/
if (PHPmyBrowser!="ok")
{
echo 'Hacking attempt!
Qu\'est-ce que tu fous ici ?';
exit;
}
// && in_array($tabIcon[$d], array('gif','jpg','jpe','jpeg','jif','jfif','png','bmp'))
$thumbsDir = '';
if (is_dir($PHPmyBrowserCustom.'thumbnails/')
&& is_writeable($PHPmyBrowserCustom.'thumbnails/'))
$thumbsDir = $PHPmyBrowserCustom.'thumbnails/';
else
$thumbsDir = $PHPmyBrowserFolder.'thumbnails/';
/**
* handle image, resize or display or add javascript code to open full-size image in popup.
* @param int Index
* @return string
* @access private
*/
function addon_webimage_display($idx)
{
global $ADDON_allowDirectPreview, $tabSize, $tabName, $PHPmyBrowserCustom, $PHPmyBrowserFolder,
$IMG_displayThumbnail, $IMG_maxHeight, $IMG_maxWidth, $IMG_maxSize,
$curr, $currRelatif, $lang, $thumbsDir;
if ($ADDON_allowDirectPreview)
{
$wThumb = false;
$a = '';
$DoNotDisplayImage = false;
if ($tabSize[$idx] > ($IMG_maxSize * 1024))
{
$DoNotDisplayImage = true;
}
$imgsize = @getimagesize($curr.$tabName[$idx]);
if (($imgsize[IMG_HEIGHT] > $IMG_maxHeight) || ($imgsize[IMG_WIDTH] > $IMG_maxWidth))
{
$DoNotDisplayImage = true;
}
if (!$DoNotDisplayImage)
{
$img = $currRelatif.str_replace('%2F','/', str_replace('+','%20',
urlencode($tabName[$idx]) ));
return '';
}
else
{
if ($IMG_displayThumbnail
&& isGDSupported($tabName[$idx])
&& is_writeable($thumbsDir)
&& ($IMG_maxHeight > 0)
&& ($IMG_maxWidth > 0)
&& ($IMG_maxSize > 0)
)
{//Create thumbnails
//If not loaded GD disable thumbnails
$wThumb = (extension_loaded('gd') || extension_loaded('gd2'));
}
if ($wThumb) //Si c'est possible de faire des miniatures, if thumbnail is possible
$a = webimage_redim($tabName[$idx]);
else
//Si pas de miniature, if no thumbnail
$a .= 'src="'.choose_right_file('images/view_image.gif').'"';
return "";
}
}
}
/**
* Resize an image...
* @access private
*/
function webimage_redim($filename)
{
global $curr, $IMG_maxWidth, $IMG_maxHeight, $thumbsDir;
$img_dest_file = str_replace(array('/',' ','\'','"','(',')','@','{','}','[',']','&','$','!','§',
',','%','~','#','`',':','\\')
,'_', $curr.$filename);
$size = getimagesize(imageresize($curr.$filename,
$thumbsDir.$img_dest_file,
$IMG_maxWidth, $IMG_maxHeight));
$img_dest = $thumbsDir . str_replace('+','%20', urlencode($img_dest_file));
return ((isIE() && (extension($img_dest)=='png'))
?'src="'.choose_right_file('images/blank.gif').'" style="filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''.$img_dest.'\', sizingMethod=\'scale\');'
:'src="'.$img_dest.'"')
.' width="'.$size[IMG_WIDTH].'" height="'.$size[IMG_HEIGHT].'" ';
}
/**
* @access private
*/
function isIE()
{
global $_SERVER;
$agt = strtolower($_SERVER['HTTP_USER_AGENT']);
return (
ereg('msie', $agt)
&& !ereg('opera', $agt)
&& !ereg('webtv', $agt)
&& !ereg('mac', $agt)
);
}
?>