Project

General

Profile

« Previous | Next » 

Revision 1819

Added by Dietmar almost 12 years ago

  1. bugfix media, Undefined index /admin/media/upload.php on line 108
    - removed obselete resize_img.php

View differences:

branches/2.8.x/CHANGELOG
13 13

  
14 14

  
15 15

  
16
16 Nov-2012 Build 1819 Dietmar Woellbrink (Luisehahne)
17
# bugfix media, Undefined index /admin/media/upload.php on line 108
18
- removed obselete resize_img.php
16 19
16 Nov-2012 Build 1818 Dietmar Woellbrink (Luisehahne)
17 20
# bugfix Ticket 10 usergroup show homefolder in media
18 21
! update users, create username homefolder in media/homefolders
branches/2.8.x/wb/admin/media/resize_img.php
1
<?php
2
/**
3
 *
4
 * @category        admin
5
 * @package         admintools
6
 * @author          WebsiteBaker Project
7
 * @copyright       2004-2009, Ryan Djurovich
8
 * @copyright       2009-2011, Website Baker Org. e.V.
9
 * @link			http://www.websitebaker2.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.x
12
 * @requirements    PHP 5.2.2 and higher
13
 * @version         $Id$
14
 * @filesource		$HeadURL:  $
15
 * @lastmodified    $Date:  $
16
 *
17
 */
18

  
19
	/**
20
	 * Image Resizer. 
21
	 * @author : Harish Chauhan
22
	 * @copyright : Freeware
23
	 * About :This PHP script will resize the given image and can show on the fly or save as image file.
24
	 *
25
	 */
26
	
27

  
28
	define("HAR_AUTO_NAME",1);	
29
	Class RESIZEIMAGE
30
	{
31
		var $imgFile="";
32
		var $imgWidth=0;
33
		var $imgHeight=0;
34
		var $imgType="";
35
		var $imgAttr="";
36
		var $type=NULL;
37
		var $_img=NULL;
38
		var $_error="";
39
		
40
		/**
41
		 * Constructor
42
		 *
43
		 * @param [String $imgFile] Image File Name
44
		 * @return RESIZEIMAGE (Class Object)
45
		 */
46
		
47
		function RESIZEIMAGE($imgFile="")
48
		{
49
			if (!function_exists("imagecreate"))
50
			{
51
				$this->_error="Error: GD Library is not available.";
52
				return false;
53
			}
54

  
55
			$this->type=Array(1 => 'GIF', 2 => 'JPG', 3 => 'PNG', 4 => 'SWF', 5 => 'PSD', 6 => 'BMP', 7 => 'TIFF', 8 => 'TIFF', 9 => 'JPC', 10 => 'JP2', 11 => 'JPX', 12 => 'JB2', 13 => 'SWC', 14 => 'IFF', 15 => 'WBMP', 16 => 'XBM');
56
			if(!empty($imgFile))
57
				$this->setImage($imgFile);
58
		}
59
		/**
60
		 * Error occured while resizing the image.
61
		 *
62
		 * @return String 
63
		 */
64
		function error()
65
		{
66
			return $this->_error;
67
		}
68
		
69
		/**
70
		 * Set image file name
71
		 *
72
		 * @param String $imgFile
73
		 * @return void
74
		 */
75
		function setImage($imgFile)
76
		{
77
			$this->imgFile=$imgFile;
78
			return $this->_createImage();
79
		}
80
		/**
81
		 * 
82
		 * @return void
83
		 */
84
		function close()
85
		{
86
			return @imagedestroy($this->_img);
87
		}
88
		/**
89
		 * Resize a image to given width and height and keep it's current width and height ratio
90
		 * 
91
		 * @param Number $imgwidth
92
		 * @param Numnber $imgheight
93
		 * @param String $newfile
94
		 */
95
		function resize_limitwh($imgwidth,$imgheight,$newfile=NULL)
96
		{
97
			$image_per = 100;
98
			list($width, $height, $type, $attr) = @getimagesize($this->imgFile);
99
			if($width > $imgwidth && $imgwidth > 0)
100
				$image_per = (double)(($imgwidth * 100) / $width);
101

  
102
			if(floor(($height * $image_per)/100)>$imgheight && $imgheight > 0)
103
				$image_per = (double)(($imgheight * 100) / $height);
104

  
105
			$this->resize_percentage($image_per,$newfile);
106

  
107
		}
108
		/**
109
		 * Resize an image to given percentage.
110
		 *
111
		 * @param Number $percent
112
		 * @param String $newfile
113
		 * @return Boolean
114
		 */
115
		function resize_percentage($percent=100,$newfile=NULL)
116
		{
117
			$newWidth=($this->imgWidth*$percent)/100;
118
			$newHeight=($this->imgHeight*$percent)/100;
119
			return $this->resize($newWidth,$newHeight,$newfile);
120
		}
121
		/**
122
		 * Resize an image to given X and Y percentage.
123
		 *
124
		 * @param Number $xpercent
125
		 * @param Number $ypercent
126
		 * @param String $newfile
127
		 * @return Boolean
128
		 */
129
		function resize_xypercentage($xpercent=100,$ypercent=100,$newfile=NULL)
130
		{
131
			$newWidth=($this->imgWidth*$xpercent)/100;
132
			$newHeight=($this->imgHeight*$ypercent)/100;
133
			return $this->resize($newWidth,$newHeight,$newfile);
134
		}
135
		
136
		/**
137
		 * Resize an image to given width and height
138
		 *
139
		 * @param Number $width
140
		 * @param Number $height
141
		 * @param String $newfile
142
		 * @return Boolean
143
		 */
144
		function resize($width,$height,$newfile=NULL)
145
		{
146
			if(empty($this->imgFile))
147
			{
148
				$this->_error="File name is not initialised.";
149
				return false;
150
			}
151
			if($this->imgWidth<=0 || $this->imgHeight<=0)
152
			{
153
				$this->_error="Could not resize given image";
154
				return false;
155
			}
156
			if($width<=0)
157
				$width=$this->imgWidth;
158
			if($height<=0)
159
				$height=$this->imgHeight;
160
				
161
			return $this->_resize($width,$height,$newfile);
162
		}
163
		
164
		/**
165
		 * Get the image attributes
166
		 * @access Private
167
		 * 		
168
		 */
169
		function _getImageInfo()
170
		{
171
			@list($this->imgWidth,$this->imgHeight,$type,$this->imgAttr)=@getimagesize($this->imgFile);
172
			$this->imgType=$this->type[$type];
173
		}
174
		
175
		/**
176
		 * Create the image resource 
177
		 * @access Private
178
		 * @return Boolean
179
		 */
180
		function _createImage()
181
		{
182
			$this->_getImageInfo($this->imgFile);
183
			if($this->imgType=='GIF')
184
			{
185
				$this->_img=@imagecreatefromgif($this->imgFile);
186
			}
187
			elseif($this->imgType=='JPG')
188
			{
189
				$this->_img=@imagecreatefromjpeg($this->imgFile);
190
			}
191
			elseif($this->imgType=='PNG')
192
			{
193
				$this->_img=@imagecreatefrompng($this->imgFile);
194
			}			
195
			if(!$this->_img || !@is_resource($this->_img))
196
			{
197
				$this->_error="Error loading ".$this->imgFile;
198
				return false;
199
			}
200
			return true;
201
		}
202
		
203
		/**
204
		 * Function is used to resize the image
205
		 * 
206
		 * @access Private
207
		 * @param Number $width
208
		 * @param Number $height
209
		 * @param String $newfile
210
		 * @return Boolean
211
		 */
212
		function _resize($width,$height,$newfile=NULL)
213
		{
214
			if (!function_exists("imagecreate"))
215
			{
216
				$this->_error="Error: GD Library is not available.";
217
				return false;
218
			}
219

  
220
			$newimg=@imagecreatetruecolor($width,$height);
221
			//imagecolortransparent( $newimg, imagecolorat( $newimg, 0, 0 ) );
222
			
223
			if($this->imgType=='GIF' || $this->imgType=='PNG')
224
			{
225
				/** Code to keep transparency of image **/
226
				$colorcount = imagecolorstotal($this->_img);
227
				if ($colorcount == 0) $colorcount = 256;
228
				imagetruecolortopalette($newimg,true,$colorcount);
229
				imagepalettecopy($newimg,$this->_img);
230
				$transparentcolor = imagecolortransparent($this->_img);
231
				imagefill($newimg,0,0,$transparentcolor);
232
				imagecolortransparent($newimg,$transparentcolor); 
233
			}
234

  
235
			@imagecopyresampled ( $newimg, $this->_img, 0,0,0,0, $width, $height, $this->imgWidth,$this->imgHeight);
236
			
237

  
238

  
239
			if($newfile===HAR_AUTO_NAME)
240
			{
241
				if(@preg_match("/\..*+$/",@basename($this->imgFile),$matches))
242
			   		$newfile=@substr_replace($this->imgFile,"_har",-@strlen($matches[0]),0);			
243
			}
244
			elseif(!empty($newfile))
245
			{
246
				if(!@preg_match("/\..*+$/",@basename($newfile)))
247
				{
248
					if(@preg_match("/\..*+$/",@basename($this->imgFile),$matches))
249
					   $newfile=$newfile.$matches[0];
250
				}
251
			}
252

  
253
			if($this->imgType=='GIF')
254
			{
255
				if(!empty($newfile))
256
					@imagegif($newimg,$newfile);
257
				else
258
				{
259
					@header("Content-type: image/gif");
260
					@imagegif($newimg);
261
				}
262
			}
263
			elseif($this->imgType=='JPG')
264
			{
265
				if(!empty($newfile))
266
					@imagejpeg($newimg,$newfile,85);
267
				else
268
				{
269
					@header("Content-type: image/jpeg");
270
					@imagejpeg($newimg);
271
				}
272
			}
273
			elseif($this->imgType=='PNG')
274
			{
275
				if(!empty($newfile))
276
					@imagepng($newimg,$newfile);
277
				else
278
				{
279
					@header("Content-type: image/png");
280
					@imagepng($newimg);
281
				}
282
			}
283
			@imagedestroy($newimg);
284
		}
285
	}
286
?>
287 0

  
branches/2.8.x/wb/admin/media/setparameter.php
123 123
	if (isset($pathsettings[$safepath]['height'])){ $cur_height = $pathsettings[$safepath]['height'];}
124 124
	$cur_width = ($cur_width ? (int)$cur_width : '');
125 125
	$cur_height = ($cur_height ? (int)$cur_height : '');
126
//
126
// check for user homefolder
127 127
    $bPathCanEdit = (preg_match('/'.$currentHome.'/i', $safepath)) ? true : false;
128 128

  
129 129
//	if($row_bg_color == 'DEDEDE') $row_bg_color = 'EEEEEE';
......
132 132

  
133 133
	$template->set_var(array(
134 134
					'ADMIN_URL' => ADMIN_URL,
135
					'THEME_URL' => THEME_URL,
135 136
					'PATH_NAME' => $relative,
136 137
					'WIDTH' => $TEXT['WIDTH'],
137 138
					'HEIGHT' => $TEXT['HEIGHT'],
138 139
					'FIELD_NAME_W' => $safepath.'-w',
139 140
					'FIELD_NAME_H' => $safepath.'-h',
140 141
					'CAN_EDIT_CLASS' => ($bPathCanEdit==false) ? '' : 'bold',
142
					'SHOW_EDIT_CLASS' => ($bPathCanEdit==false) ? 'hide' : '',
141 143
					'READ_ONLY_DIR' => ($bPathCanEdit==false) ? ' readonly="readonly"' : '',
142 144
					'CUR_HEIGHT' => $cur_height,
143 145
					'CUR_WIDTH' => $cur_width,
branches/2.8.x/wb/admin/media/thumbs.php
15 15
 *
16 16
 */
17 17

  
18
require('../../config.php');
18
if(!defined('WB_URL'))
19
{
20
    $config_file = realpath('../../config.php');
21
    if(file_exists($config_file) && !defined('WB_URL'))
22
    {
23
    	require($config_file);
24
    }
25
}
26
//if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
19 27
$modulePath = dirname(__FILE__);
20 28

  
21 29
/*
......
35 43
	$thumb = PhpThumbFactory::create(WB_PATH.MEDIA_DIRECTORY.'/'.$image);
36 44

  
37 45
	if ($type == 1) {
46
        $thumb->adaptiveResize(20,20);
47
//        $thumb->resize(30,30);
38 48
//		$thumb->cropFromCenter(80,50);
39
        $thumb->resize(30,30);
40 49
// 		$thumb->resizePercent(40);
41 50
	} else {
42
    	$thumb->resize(250,250);
43
// 		$thumb->resizePercent(50);
51
//    	$thumb->adaptiveResize(250,250);
52
 		$thumb->resizePercent(30);
44 53
//		$thumb->cropFromCenter(80,50);
45 54
	}
46 55
	$thumb->show();
branches/2.8.x/wb/admin/media/parameters.php
3 3
 *
4 4
 * @category        admin
5 5
 * @package         media
6
 * @author          Ryan Djurovich, WebsiteBaker Project
7
 * @copyright       2009-2011, Website Baker Org. e.V.
6
 * @author          Ryan Djurovich (2004-2009), WebsiteBaker Project
7
 * @copyright       2009-2012, WebsiteBaker Org. e.V.
8 8
 * @link			http://www.websitebaker2.org/
9 9
 * @license         http://www.gnu.org/licenses/gpl.html
10 10
 * @platform        WebsiteBaker 2.8.x
......
34 34
		$database->query ( "INSERT INTO ".TABLE_PREFIX."settings (`name`,`value`) VALUES ('mediasettings','')" );
35 35
	}
36 36
}
37

  
branches/2.8.x/wb/admin/media/upload.php
15 15
 *
16 16
 */
17 17

  
18
// Print admin header
19
require('../../config.php');
20
include_once('resize_img.php');
21
include_once('parameters.php');
18
if(!defined('WB_URL'))
19
{
20
    $config_file = realpath('../../config.php');
21
    if(file_exists($config_file) && !defined('WB_URL'))
22
    {
23
    	require($config_file);
24
    }
25
}
26
if(!class_exists('admin', false)){ include(WB_PATH.'/framework/class.admin.php'); }
22 27

  
23
require_once(WB_PATH.'/framework/class.admin.php');
24
// require_once(WB_PATH.'/include/pclzip/pclzip.lib.php');	// Required to unzip file.
28
$modulePath = dirname(__FILE__);
29

  
30
//include_once('resize_img.php');
31
include_once($modulePath.'/parameters.php');
32

  
25 33
// suppress to print the header, so no new FTAN will be set
26 34
$admin = new admin('Media', 'media_upload', false);
27 35

  
......
57 65
// Find out whether we should replace files or give an error
58 66
$overwrite = ($admin->get_post('overwrite') != '') ? true : false;
59 67

  
68
$file_extension_string = '';
60 69
// Get list of file types to which we're supposed to append 'txt'
61
$get_result=$database->query("SELECT value FROM ".TABLE_PREFIX."settings WHERE name='rename_files_on_upload' LIMIT 1");
62
$file_extension_string='';
63
if ($get_result->numRows()>0) {
64
	$fetch_result=$get_result->fetchRow();
65
	$file_extension_string=$fetch_result['value'];
70
$sql = 'SELECT ´value´ FROM ´'.TABLE_PREFIX. 'settings´ '.
71
       'WHERE ´name´=\'rename_files_on_upload\'';
72

  
73
if($oRes = $database->query($sql)) {
74
    $aResult = $oRes->fetchRow(MYSQL_ASSOC);
75
    $file_extension_string = $aResult['value'];
66 76
}
67 77

  
68 78
$file_extensions=explode(",",$file_extension_string);
......
104 114
				}
105 115
			}
106 116

  
117

  
107 118
			if(file_exists($relative.$filename)) {
108
				if ($pathsettings[$resizepath]['width'] || $pathsettings[$resizepath]['height'] ) {
109
					$rimg=new RESIZEIMAGE($relative.$filename);
110
					$rimg->resize_limitwh($pathsettings[$resizepath]['width'],$pathsettings[$resizepath]['height'],$relative.$filename);
111
					$rimg->close();
119

  
120
                $ImgWidth  = isset($pathsettings[$resizepath]['width'])  ? intval($pathsettings[$resizepath]['width'])  : null;
121
                $ImgHeigth = isset($pathsettings[$resizepath]['height']) ? intval($pathsettings[$resizepath]['height']) : null;
122

  
123
				if ($ImgWidth!=null || $ImgHeigth!=null ) {
124
                    if(!class_exists('PhpThumbFactory', false)){ include($modulePath.'/inc/ThumbLib.inc.php'); }
125
                	$oImage = PhpThumbFactory::create($relative.$filename);
126
                    $aOldSize = $oImage->getCurrentDimensions();
127
                    $ImgPercent = 50;
128

  
129
    				if ($ImgWidth!=null && $ImgHeigth==null ) {
130
                        $ImgPercent =  $ImgWidth*100/$aOldSize['width'];
131
                        $ImgHeigth = $ImgWidth;
132
                    } elseif( $ImgWidth==null && $ImgHeigth!=null ) {
133
                        $ImgPercent =  $ImgHeigth*100/$aOldSize['height'];
134
                        $ImgWidth = $ImgHeigth;
135
                    } else {
136
                        $ImgPercent = $ImgWidth*100/$aOldSize['width'];
137
                    }
138
                    $oImage->resize($ImgWidth,$ImgHeigth)->save($relative.$filename);
139
//                    $oImage->resizePercent($ImgPercent)->save($relative.$filename);
140
//                    $oImage->adaptiveResize($ImgWidth,$ImgHeigth)->save($relative.$filename);
141
//                    $oImage->save($relative.$filename);
112 142
				}
143

  
113 144
			}
114 145

  
115 146
			// store file name of first file for possible unzip action
branches/2.8.x/wb/admin/media/index.php
41 41
// Include the WB functions file
42 42
require_once(WB_PATH.'/framework/functions.php');
43 43

  
44
// Target location
45
$requestMethod = '_'.strtoupper($_SERVER['REQUEST_METHOD']);
46
$directory = (isset(${$requestMethod}['dir'])) ? ${$requestMethod}['dir'] : '';
47

  
48
$directory = ($directory == '/') ?  '' : $directory;
49
$dirlink = 'index.php?dir='.$directory;
50
$rootlink = 'index.php?dir=';
51

  
44 52
// Get home folder not to show
45 53
$home_folders = get_home_folders();
46 54

  
......
90 98
$template->set_var(array(
91 99
					'HEADING_BROWSE_MEDIA' => $HEADING['BROWSE_MEDIA'],
92 100
					'HOME_DIRECTORY' => $currentHome,
101
//					'HOME_DIRECTORY' => ( $currentHome!='') ? $currentHome : $directory,
93 102
					'DISPLAY_UP_ARROW' => $display_up_arrow, // **!
94 103
					'HEADING_CREATE_FOLDER' => $HEADING['CREATE_FOLDER'],
95 104
					'HEADING_UPLOAD_FILES' => $HEADING['UPLOAD_FILES']
branches/2.8.x/wb/admin/skel/themes/htt/setparameter.htt
33 33
.bold { color: #2C50A3; }
34 34
.path-name { width: 65%;}
35 35
tbody.path-option tr th  { font-weight: normal;}
36
.show-img { width: 30px; text-align: center;}
36 37

  
37 38
</style>
38 39
</head>
......
64 65
        {HEIGHT}
65 66
        <input size="5" type="text" name="{FIELD_NAME_H}" value="{CUR_HEIGHT}"{READ_ONLY_DIR} />
66 67
        </td>
68
		<td class="show-img" >
69
            <img class="{SHOW_EDIT_CLASS}" height="16" width="16" alt="" src="{THEME_URL}/images/resize_16.png" />
70
        </td>
67 71
	</tr>
68 72
<!-- END list_block -->
69 73
	<tr>
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1818');
54
if(!defined('REVISION')) define('REVISION', '1819');
55 55
if(!defined('SP')) define('SP', '');

Also available in: Unified diff