4 if (file_exists('install.php')
5 or file_exists('update.php')
6 or file_exists('update_content.php'))
8 header("location: ".$settings['forum_address']."service.php");
9 die("<a href=\"service.php\">further...</a>");
12 if ($settings['upload_images']!=1) die('This feature is not activated.');
14 $uploaded_images_path = 'img/uploaded/';
15 $images_per_page = 30;
17 function resize($uploaded_file, $file, $new_width, $new_height, $compression=80) {
19 if (file_exists($file))
25 $image_info = getimagesize($uploaded_file);
27 if (!is_array($image_info) ||
$image_info[2] != 1 && $image_info[2] != 2 && $image_info[2] != 3) $error = true;
30 if($image_info[2]==1) // GIF
32 $current_image = @ImageCreateFromGIF
($uploaded_file) or $error = true;
33 if (empty($error)) $new_image = @ImageCreate
($new_width,$new_height) or $error = true;
34 if (empty($error)) @ImageCopyResampled
($new_image,$current_image,0,0,0,0,$new_width,$new_height,$image_info[0],$image_info[1]) or $error=true;
35 if (empty($error)) @ImageGIF
($new_image, $file) or $error = true;
37 else if ($image_info[2]==2) // JPG
39 $current_image = @ImageCreateFromJPEG
($uploaded_file) or $error = true;
40 if (empty($error)) $new_image=@imagecreatetruecolor
($new_width,$new_height) or $error = true;
41 if (empty($error)) @ImageCopyResampled
($new_image,$current_image,0,0,0,0,$new_width,$new_height,$image_info[0],$image_info[1]) or $error = true;
42 if (empty($error)) @ImageJPEG
($new_image, $file, $compression) or $error = true;
44 else if($image_info[2]==3) // PNG
46 $current_image=ImageCreateFromPNG($uploaded_file) or $error = true;
47 if (empty($error)) $new_image=imagecreatetruecolor($new_width,$new_height) or $error = true;
48 if (empty($error)) ImageCopyResampled($new_image,$current_image,0,0,0,0,$new_width,$new_height,$image_info[0],$image_info[1]) or $error = true;
49 if (empty($error)) ImagePNG($new_image, $file) or $error = $true;
53 if (empty($error)) return true;
57 $action = (isset($_GET['action'])) ?
$_GET['action'] : 'upload';
59 $lang['upload_exp'] = str_replace("[width]", $settings['upload_max_img_width'], $lang['upload_exp']);
60 $lang['upload_exp'] = str_replace("[height]", $settings['upload_max_img_height'], $lang['upload_exp']);
61 $lang['upload_exp'] = str_replace("[size]", $settings['upload_max_img_size'], $lang['upload_exp']);
63 if (isset($_FILES['probe']) && $_FILES['probe']['size'] != 0 && !$_FILES['probe']['error'])
66 $image_info = getimagesize($_FILES['probe']['tmp_name']);
67 if (!is_array($image_info)
68 ||
($image_info[2] != 1
69 && $image_info[2] != 2
70 && $image_info[2] != 3))
72 $errors[] = $lang['invalid_file_format'];
76 if ($_FILES['probe']['size'] > $settings['upload_max_img_size']*1000
77 ||
$image_info[0] > $settings['upload_max_img_width']
78 ||
$image_info[1] > $settings['upload_max_img_height'])
81 $width=$image_info[0];
82 $height=$image_info[1];
83 if ($width >= $height)
85 $new_width = $settings['upload_max_img_width'];
86 $new_height = intval($height*$new_width/$width);
90 $new_height = $settings['upload_max_img_height'];
91 $new_width = intval($width*$new_height/$height);
93 $img_tmp_name = uniqid(rand()).'.tmp';
95 for ($compression = 100; $compression>9; $compression=$compression-10)
97 if (!resize($_FILES['probe']['tmp_name'], $uploaded_images_path.$img_tmp_name, $new_width, $new_height, $compression))
99 $file_size = @filesize
($uploaded_images_path.$img_tmp_name);
102 $file_size = @filesize
($uploaded_images_path.$img_tmp_name);
103 if ($image_info[2]!=2 && $file_size > $settings['upload_max_img_size']*1000) break;
104 if ($file_size <= $settings['upload_max_img_size']*1000) break;
106 if ($file_size > $settings['upload_max_img_size']*1000)
108 $file_too_large_dump = str_replace("[width]",$image_info[0],$lang['file_too_large']);
109 $file_too_large_dump = str_replace("[height]",$image_info[1],$file_too_large_dump);
110 $file_too_large_dump = str_replace("[size]",number_format($_FILES['probe']['size']/1000,0,",",""),$file_too_large_dump);
111 $errors[] = $file_too_large_dump;
115 if (file_exists($uploaded_images_path.$img_tmp_name))
117 @chmod
($uploaded_images_path.$img_tmp_name, 0777);
118 @unlink
($uploaded_images_path.$img_tmp_name);
127 switch($image_info[2])
130 for(;;) { $nr++
; if (!file_exists($uploaded_images_path."image".$nr.".gif")) break; }
131 $filename = "image".$nr.".gif";
134 for(;;) { $nr++
; if (!file_exists($uploaded_images_path."image".$nr.".jpg")) break; }
135 $filename = "image".$nr.".jpg";
138 for(;;) { $nr++
; if (!file_exists($uploaded_images_path."image".$nr.".png")) break; }
139 $filename = "image".$nr.".png";
142 if (isset($img_tmp_name))
144 @rename
($uploaded_images_path.$img_tmp_name, $uploaded_images_path.$filename) or $errors[] = $lang['upload_error'];
145 $image_manipulated = str_replace('[width]',$new_width,$lang['image_manipulated']);
146 $image_manipulated = str_replace('[height]',$new_height,$image_manipulated);
147 $image_manipulated = str_replace("[size]",number_format($file_size/1000,0,",",""),$image_manipulated);
151 @move_uploaded_file
($_FILES['probe']['tmp_name'], $uploaded_images_path.$filename) or $errors[] = $lang['upload_error'];
156 @chmod
($uploaded_images_path.$filename, 0644);
157 $action = 'uploaded';
159 else $action = 'upload';
164 if (isset($_FILES['probe']['error']))
166 $errors[] = str_replace('[maximum_file_size]',ini_get('upload_max_filesize'),$lang['upload_error_2']);
170 if(isset($_GET['uploaded_image_selected']))
172 $filename = $_GET['uploaded_image_selected'];
173 $action = 'uploaded';
176 ?
><!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
179 <meta http
-equiv
="content-type" content
="text/html; charset=UTF-8" />
180 <title
><?php
echo strip_tags($lang['upload_image_title']); ?
></title
>
181 <style type
="text/css">
184 font
-family
:Verdana
,Helvetica
,sans
-serif
;
202 text
-decoration
:none
;
206 text
-decoration
:none
;
210 text
-decoration
:underline
;
214 <script type
="text/javascript">/* <![CDATA[ */
216 function insertCode(code
) {
218 if (!code
) code
= "";
221 // get the textarea of the main document and focus the element
222 var input
= opener
.document
.getElementById("text");
224 var txtLen
= input
.value
.length
;
226 if (typeof document
.selection
!= 'undefined')
229 the following code for MSIE is adapted from http://the-stickman.com/web-development/javascript/finding-selection-cursor-position-in-a-textarea-in-internet-explorer/
231 it is licensed unter the terms of the MIT-license
232 see: http://www.opensource.org/licenses/mit-license.php
233 Copyright (c) <year> <copyright holders>
235 Permission is hereby granted, free of charge, to any person obtaining
236 a copy of this software and associated documentation files (the "Software"),
237 to deal in the Software without restriction, including without limitation
238 the rights to use, copy, modify, merge, publish, distribute, sublicense,
239 and/or sell copies of the Software, and to permit persons to whom
240 the Software is furnished to do so, subject to the following conditions:
242 The above copyright notice and this permission notice shall be included
243 in all copies or substantial portions of the Software.
245 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
246 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
247 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
248 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
249 OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
250 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
251 OR OTHER DEALINGS IN THE SOFTWARE.
253 // The current selection
254 var range
= opener
.document
.selection
.createRange();
255 // We'll use this as a 'dummy'
256 var stored_range
= range
.duplicate();
258 stored_range
.moveToElementText(input
);
259 // Now move 'dummy' end point to end point of original range
260 stored_range
.setEndPoint( 'EndToEnd', range
);
261 // Now we can calculate start and end points
262 var position
= input
.selectionStart
= stored_range
.text
.length
- range
.text
.length
;
263 // input.selectionEnd = input.selectionStart + range.text.length;
265 var txtbefore
= input
.value
.substring(0,position
);
266 var txtafter
= input
.value
.substring(position
, txtLen
);
267 input
.value
= txtbefore + code + txtafter
;
270 else if ((typeof input
.selectionStart
) != 'undefined')
272 var selEnd
= input
.selectionEnd
;
273 var txtbefore
= input
.value
.substring(0,selEnd
);
274 var txtafter
= input
.value
.substring(selEnd
, txtLen
);
275 var oldScrollTop
= input
.scrollTop
;
276 input
.value
= txtbefore + code + txtafter
;
277 input
.selectionStart
= txtbefore
.length + code
.length
;
278 input
.selectionEnd
= txtbefore
.length + code
.length
;
279 input
.scrollTop
= oldScrollTop
;
294 <h1
><?php
$lang['upload_image_title']; ?
></h1
>
301 echo errorMessages($errors);
303 echo '<p>'.$lang['upload_exp'].'</p>'."\n";
304 echo '<form action="'.$_SERVER['SCRIPT_NAME'].'" method="post" '."\n";
305 echo 'enctype="multipart/form-data"><input type="file" name="probe" />'."\n";
306 echo '<input type="submit" value="'.outputLangDebugInAttributes($lang['upload_subm_button']).'">'."\n";
308 echo '<p>[ <a href="'.$_SERVER['PHP_SELF'].'?action=show_uploaded_images">';
309 echo $lang['available_images'].'</a> ]</p>'."\n";
312 if (isset($_FILES['probe']))
314 if(isset($image_manipulated))
316 echo '<p>'.$image_manipulated.'</p>'."\n";
320 echo '<p>'.$lang['upload_successful'].'</p>'."\n";
323 echo '<img src="img/uploaded/'.$filename.'" alt="" height="100" border="1">'."\n";
324 echo '<p>'.$lang['paste_image'].'</p>'."\n";
325 echo '<p><button style="width:25px; height:25px;" title="'.outputLangDebugInAttributes($lang['insert_image_normal']);
326 echo '" onclick="insertCode(\'[img]'.$uploaded_images_path.$filename.'[/img]\');';
327 echo '"><img src="img/img_normal.png" alt="'.outputLangDebugInAttributes($lang['insert_image_normal']);
328 echo '" width="11" height="11" /></button> <button style="width:25px; height:25px;"';
329 echo ' title="'.outputLangDebugInAttributes($lang['insert_image_left']).'" onclick="insertCode(\'[img|left]';
330 echo $uploaded_images_path.$filename.'[/img]\');"><img';
331 echo ' src="img/img_left.png" alt="'.outputLangDebugInAttributes($lang['insert_image_left']).'" width="11" height="11"';
332 echo ' /></button> <button style="width:25px; height:25px;" title="';
333 echo outputLangDebugInAttributes($lang['insert_image_right']).'" onclick="insertCode(\'[img|right]';
334 echo $uploaded_images_path.$filename.'[/img]\');"><img';
335 echo ' src="img/img_right.png" alt="'.outputLangDebugInAttributes($lang['insert_image_right']).'" width="11"';
336 echo ' height="11" /></button></p>'."\n";
338 case 'show_uploaded_images':
339 $p = isset($_GET['p']) ?
intval($_GET['p']) : 1;
341 $handle = opendir($uploaded_images_path);
342 while ($file = readdir($handle))
344 if (preg_match('/\.jpg$/i', $file)
345 ||
preg_match('/\.png$/i', $file)
346 ||
preg_match('/\.gif$/i', $file))
354 $images_count = count($images);
355 $show_images_from = $p * $images_per_page - $images_per_page;
356 $show_images_to = $p * $images_per_page;
357 if ($show_images_to>$images_count) $show_images_to = $images_count;
367 echo '[ <a href="'.$_SERVER['SCRIPT_NAME'].'?action=show_uploaded_images';
368 echo '&p='.$pageDown.'">«</a> ] ';
370 if ($p*$images_per_page < $images_count)
373 echo '[ <a href="'.$_SERVER['SCRIPT_NAME'].'?action=show_uploaded_images';
374 echo '&p='.$pageUp.'">»</a> ] ';
377 if ($images_count > 0)
379 for ($i=$show_images_from; $i<$show_images_to; $i++
)
381 echo '<a href="'.$_SERVER['SCRIPT_NAME'].'?uploaded_image_selected=';
382 echo $images[$i].'"><img style="margin: 0px 15px 15px 0px;" src="';
383 echo $uploaded_images_path.$images[$i].'" alt="'.$images[$i];
384 echo '" height="100" border="0"></a>'."\n";
389 echo '<i>'.$lang['no_images'].'</i>';