| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | require_once '../ImageManager/Classes/Files.php'; |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | class ExtendedFileManager |
|---|
| 24 | { |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | var $config; |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | var $dirs; |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | var $mode; |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | |
|---|
| 44 | function ExtendedFileManager($config, $mode = null) |
|---|
| 45 | { |
|---|
| 46 | $this->config = $config; |
|---|
| 47 | |
|---|
| 48 | $this->mode = empty($mode) ? (empty($config['insert_mode']) ? 'image' : $config['insert_mode']): $mode; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | function getImagesDir() |
|---|
| 56 | { |
|---|
| 57 | if ($this->mode == 'link' && isset($this->config['files_dir'])) |
|---|
| 58 | Return $this->config['files_dir']; |
|---|
| 59 | else Return $this->config['images_dir']; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | function getImagesURL() |
|---|
| 67 | { |
|---|
| 68 | if ($this->mode == 'link' && isset($this->config['files_url'])) |
|---|
| 69 | Return $this->config['files_url']; |
|---|
| 70 | else Return $this->config['images_url']; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | function isValidBase() |
|---|
| 74 | { |
|---|
| 75 | return is_dir($this->getImagesDir()); |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | function getTmpPrefix() |
|---|
| 83 | { |
|---|
| 84 | Return $this->config['tmp_prefix']; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | function getDirs() |
|---|
| 96 | { |
|---|
| 97 | if(is_null($this->dirs)) |
|---|
| 98 | { |
|---|
| 99 | $dirs = $this->_dirs($this->getImagesDir(),'/'); |
|---|
| 100 | ksort($dirs); |
|---|
| 101 | $this->dirs = $dirs; |
|---|
| 102 | } |
|---|
| 103 | return $this->dirs; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | |
|---|
| 113 | |
|---|
| 114 | function _dirs($base, $path) |
|---|
| 115 | { |
|---|
| 116 | $base = Files::fixPath($base); |
|---|
| 117 | $dirs = array(); |
|---|
| 118 | |
|---|
| 119 | if($this->isValidBase() == false) |
|---|
| 120 | return $dirs; |
|---|
| 121 | |
|---|
| 122 | $d = @dir($base); |
|---|
| 123 | |
|---|
| 124 | while (false !== ($entry = $d->read())) |
|---|
| 125 | { |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | if(is_dir($base.$entry) |
|---|
| 129 | && substr($entry,0,1) != '.' |
|---|
| 130 | && $this->isThumbDir($entry) == false) |
|---|
| 131 | { |
|---|
| 132 | $relative = Files::fixPath($path.$entry); |
|---|
| 133 | $fullpath = Files::fixPath($base.$entry); |
|---|
| 134 | $dirs[$relative] = $fullpath; |
|---|
| 135 | $dirs = array_merge($dirs, $this->_dirs($fullpath, $relative)); |
|---|
| 136 | } |
|---|
| 137 | } |
|---|
| 138 | $d->close(); |
|---|
| 139 | |
|---|
| 140 | Return $dirs; |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | function getFiles($path) |
|---|
| 155 | { |
|---|
| 156 | $files = array(); |
|---|
| 157 | $dirs = array(); |
|---|
| 158 | |
|---|
| 159 | $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions']; |
|---|
| 160 | |
|---|
| 161 | if($this->isValidBase() == false) |
|---|
| 162 | return array($files,$dirs); |
|---|
| 163 | |
|---|
| 164 | $path = Files::fixPath($path); |
|---|
| 165 | $base = Files::fixPath($this->getImagesDir()); |
|---|
| 166 | $fullpath = Files::makePath($base,$path); |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | $d = @dir($fullpath); |
|---|
| 170 | |
|---|
| 171 | while (false !== ($entry = $d->read())) |
|---|
| 172 | { |
|---|
| 173 | |
|---|
| 174 | if(substr($entry,0,1) != '.') |
|---|
| 175 | { |
|---|
| 176 | if(is_dir($fullpath.$entry) |
|---|
| 177 | && $this->isThumbDir($entry) == false) |
|---|
| 178 | { |
|---|
| 179 | $relative = Files::fixPath($path.$entry); |
|---|
| 180 | $full = Files::fixPath($fullpath.$entry); |
|---|
| 181 | $count = $this->countFiles($full); |
|---|
| 182 | $dirs[$relative] = array('fullpath'=>$full,'entry'=>$entry,'count'=>$count, 'stat'=>stat($fullpath.$entry)); |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | else if(is_file($fullpath.$entry) && $this->isThumb($entry)==false && $this->isTmpFile($entry) == false) |
|---|
| 186 | { |
|---|
| 187 | $afruext = strtolower(substr(strrchr($entry, "."), 1)); |
|---|
| 188 | |
|---|
| 189 | if(in_array($afruext,$valid_extensions)) |
|---|
| 190 | { |
|---|
| 191 | |
|---|
| 192 | $file['url'] = Files::makePath($this->config['base_url'],$path).$entry; |
|---|
| 193 | $file['relative'] = $path.$entry; |
|---|
| 194 | $file['fullpath'] = $fullpath.$entry; |
|---|
| 195 | $img = $this->getImageInfo($fullpath.$entry); |
|---|
| 196 | if(!is_array($img)) $img[0]=$img[1]=0; |
|---|
| 197 | $file['image'] = $img; |
|---|
| 198 | $file['stat'] = stat($fullpath.$entry); |
|---|
| 199 | $file['ext'] = $afruext; |
|---|
| 200 | $files[$entry] = $file; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | } |
|---|
| 205 | } |
|---|
| 206 | $d->close(); |
|---|
| 207 | ksort($dirs); |
|---|
| 208 | ksort($files); |
|---|
| 209 | |
|---|
| 210 | Return array($dirs, $files); |
|---|
| 211 | } |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | function countFiles($path) |
|---|
| 218 | { |
|---|
| 219 | $total = 0; |
|---|
| 220 | |
|---|
| 221 | if(is_dir($path)) |
|---|
| 222 | { |
|---|
| 223 | $d = @dir($path); |
|---|
| 224 | |
|---|
| 225 | while (false !== ($entry = $d->read())) |
|---|
| 226 | { |
|---|
| 227 | |
|---|
| 228 | if(substr($entry,0,1) != '.' |
|---|
| 229 | && $this->isThumbDir($entry) == false |
|---|
| 230 | && $this->isTmpFile($entry) == false |
|---|
| 231 | && $this->isThumb($entry) == false) |
|---|
| 232 | { |
|---|
| 233 | $total++; |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | $d->close(); |
|---|
| 237 | } |
|---|
| 238 | return $total; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | function getImageInfo($file) |
|---|
| 248 | { |
|---|
| 249 | Return @getImageSize($file); |
|---|
| 250 | } |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | function isThumb($file) |
|---|
| 258 | { |
|---|
| 259 | $len = strlen($this->config['thumbnail_prefix']); |
|---|
| 260 | if(substr($file,0,$len)==$this->config['thumbnail_prefix']) |
|---|
| 261 | Return true; |
|---|
| 262 | else |
|---|
| 263 | Return false; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | |
|---|
| 269 | |
|---|
| 270 | |
|---|
| 271 | function isThumbDir($entry) |
|---|
| 272 | { |
|---|
| 273 | if($this->config['thumbnail_dir'] == false |
|---|
| 274 | || strlen(trim($this->config['thumbnail_dir'])) == 0) |
|---|
| 275 | Return false; |
|---|
| 276 | else |
|---|
| 277 | Return ($entry == $this->config['thumbnail_dir']); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | function isTmpFile($file) |
|---|
| 286 | { |
|---|
| 287 | $len = strlen($this->config['tmp_prefix']); |
|---|
| 288 | if(substr($file,0,$len)==$this->config['tmp_prefix']) |
|---|
| 289 | Return true; |
|---|
| 290 | else |
|---|
| 291 | Return false; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | function getThumbName($fullpathfile) |
|---|
| 301 | { |
|---|
| 302 | $path_parts = pathinfo($fullpathfile); |
|---|
| 303 | |
|---|
| 304 | $thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename']; |
|---|
| 305 | |
|---|
| 306 | if($this->config['safe_mode'] == true |
|---|
| 307 | || strlen(trim($this->config['thumbnail_dir'])) == 0) |
|---|
| 308 | { |
|---|
| 309 | Return Files::makeFile($path_parts['dirname'],$thumbnail); |
|---|
| 310 | } |
|---|
| 311 | else |
|---|
| 312 | { |
|---|
| 313 | if(strlen(trim($this->config['thumbnail_dir'])) > 0) |
|---|
| 314 | { |
|---|
| 315 | $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']); |
|---|
| 316 | if(!is_dir($path)) |
|---|
| 317 | Files::createFolder($path); |
|---|
| 318 | Return Files::makeFile($path,$thumbnail); |
|---|
| 319 | } |
|---|
| 320 | else |
|---|
| 321 | { |
|---|
| 322 | |
|---|
| 323 | } |
|---|
| 324 | } |
|---|
| 325 | } |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | function getThumbURL($relative) |
|---|
| 335 | { |
|---|
| 336 | $path_parts = pathinfo($relative); |
|---|
| 337 | $thumbnail = $this->config['thumbnail_prefix'].$path_parts['basename']; |
|---|
| 338 | if($path_parts['dirname']=='\\') $path_parts['dirname']='/'; |
|---|
| 339 | |
|---|
| 340 | if($this->config['safe_mode'] == true |
|---|
| 341 | || strlen(trim($this->config['thumbnail_dir'])) == 0) |
|---|
| 342 | { |
|---|
| 343 | Return Files::makeFile($this->getImagesURL(),$thumbnail); |
|---|
| 344 | } |
|---|
| 345 | else |
|---|
| 346 | { |
|---|
| 347 | if(strlen(trim($this->config['thumbnail_dir'])) > 0) |
|---|
| 348 | { |
|---|
| 349 | $path = Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']); |
|---|
| 350 | $url_path = Files::makePath($this->getImagesURL(), $path); |
|---|
| 351 | Return Files::makeFile($url_path,$thumbnail); |
|---|
| 352 | } |
|---|
| 353 | else |
|---|
| 354 | { |
|---|
| 355 | |
|---|
| 356 | } |
|---|
| 357 | |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | function getResizedName($fullpathfile, $width, $height, $mkDir = TRUE) |
|---|
| 371 | { |
|---|
| 372 | $path_parts = pathinfo($fullpathfile); |
|---|
| 373 | |
|---|
| 374 | $thumbnail = $this->config['resized_prefix']."_{$width}x{$height}_{$path_parts['basename']}"; |
|---|
| 375 | |
|---|
| 376 | if( strlen(trim($this->config['resized_dir'])) == 0 || $this->config['safe_mode'] == true ) |
|---|
| 377 | { |
|---|
| 378 | Return Files::makeFile($path_parts['dirname'],$thumbnail); |
|---|
| 379 | } |
|---|
| 380 | else |
|---|
| 381 | { |
|---|
| 382 | $path = Files::makePath($path_parts['dirname'],$this->config['resized_dir']); |
|---|
| 383 | if($mkDir && !is_dir($path)) |
|---|
| 384 | Files::createFolder($path); |
|---|
| 385 | Return Files::makeFile($path,$thumbnail); |
|---|
| 386 | } |
|---|
| 387 | } |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | function validRelativePath($path) |
|---|
| 396 | { |
|---|
| 397 | $dirs = $this->getDirs(); |
|---|
| 398 | if($path == '/') |
|---|
| 399 | Return true; |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | for($i = 0; $i < count($dirs); $i++) |
|---|
| 403 | { |
|---|
| 404 | $key = key($dirs); |
|---|
| 405 | |
|---|
| 406 | if($key == $path) |
|---|
| 407 | Return true; |
|---|
| 408 | |
|---|
| 409 | next($dirs); |
|---|
| 410 | } |
|---|
| 411 | Return false; |
|---|
| 412 | } |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | |
|---|
| 417 | |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | function processUploads() |
|---|
| 421 | { |
|---|
| 422 | if($this->isValidBase() == false) |
|---|
| 423 | return; |
|---|
| 424 | |
|---|
| 425 | $relative = null; |
|---|
| 426 | |
|---|
| 427 | if(isset($_POST['dir'])) |
|---|
| 428 | $relative = rawurldecode($_POST['dir']); |
|---|
| 429 | else |
|---|
| 430 | return; |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | if(isset($_FILES['upload']) && $this->validRelativePath($relative)) |
|---|
| 434 | { |
|---|
| 435 | Return $this->_processFiles($relative, $_FILES['upload']); |
|---|
| 436 | } |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | function _processFiles($relative, $file) |
|---|
| 451 | { |
|---|
| 452 | |
|---|
| 453 | if($file['error']!=0) |
|---|
| 454 | { |
|---|
| 455 | Return false; |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | if(!is_file($file['tmp_name'])) |
|---|
| 459 | { |
|---|
| 460 | Return false; |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | if(!is_uploaded_file($file['tmp_name'])) |
|---|
| 464 | { |
|---|
| 465 | Files::delFile($file['tmp_name']); |
|---|
| 466 | Return false; |
|---|
| 467 | } |
|---|
| 468 | |
|---|
| 469 | $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions']; |
|---|
| 470 | $max_size = $this->mode == 'image' ? $this->config['max_filesize_kb_image'] : $this->config['max_filesize_kb_link']; |
|---|
| 471 | $afruext = strtolower(substr(strrchr($file['name'], "."), 1)); |
|---|
| 472 | |
|---|
| 473 | if(!in_array($afruext, $valid_extensions)) |
|---|
| 474 | { |
|---|
| 475 | Files::delFile($file['tmp_name']); |
|---|
| 476 | Return 'Cannot upload $extension='.$afruext.'$ Files. Permission denied.'; |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | if($file['size']>($max_size*1024)) |
|---|
| 480 | { |
|---|
| 481 | Files::delFile($file['tmp_name']); |
|---|
| 482 | Return 'Unble to upload file. Maximum file size [$max_size='.$max_size.'$ KB] exceeded.'; |
|---|
| 483 | } |
|---|
| 484 | |
|---|
| 485 | if(!empty($this->config['max_foldersize_mb']) && (Files::dirSize($this->getImagesDir()))+$file['size']> ($this->config['max_foldersize_mb']*1048576)) |
|---|
| 486 | { |
|---|
| 487 | Files::delFile($file['tmp_name']); |
|---|
| 488 | Return ("Cannot upload. Maximum folder size reached. Delete unwanted files and try again."); |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | $path = Files::makePath($this->getImagesDir(),$relative); |
|---|
| 493 | $result = Files::copyFile($file['tmp_name'], $path, $file['name']); |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | if(!is_int($result)) |
|---|
| 497 | { |
|---|
| 498 | Files::delFile($file['tmp_name']); |
|---|
| 499 | Return 'File "$file='.$file['name'].'$" successfully uploaded.'; |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | Files::delFile($file['tmp_name']); |
|---|
| 504 | Return false; |
|---|
| 505 | |
|---|
| 506 | } |
|---|
| 507 | |
|---|
| 508 | |
|---|
| 509 | function getDiskInfo() |
|---|
| 510 | { |
|---|
| 511 | if (empty($this->config['max_foldersize_mb'])) |
|---|
| 512 | return ''; |
|---|
| 513 | |
|---|
| 514 | $tmpFreeSize=($this->config['max_foldersize_mb']*1048576)-Files::dirSize($this->getImagesDir()); |
|---|
| 515 | |
|---|
| 516 | if(!is_numeric($tmpFreeSize) || $tmpFreeSize<0) $tmpFreeSize=0; |
|---|
| 517 | |
|---|
| 518 | Return 'Total Size : $max_foldersize_mb='.$this->config['max_foldersize_mb'].'$ MB, Free Space: $free_space='.Files::formatSize($tmpFreeSize).'$'; |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | |
|---|
| 523 | |
|---|
| 524 | |
|---|
| 525 | |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | |
|---|
| 530 | function getFileURL($relative) |
|---|
| 531 | { |
|---|
| 532 | Return Files::makeFile($this->getImagesURL(),$relative); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | function getFullPath($relative) |
|---|
| 541 | { |
|---|
| 542 | Return Files::makeFile($this->getImagesDir(),$relative);; |
|---|
| 543 | } |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | function getDefaultThumb() |
|---|
| 551 | { |
|---|
| 552 | if(is_file($this->config['default_thumbnail'])) |
|---|
| 553 | Return $this->config['default_thumbnail']; |
|---|
| 554 | else |
|---|
| 555 | Return ''; |
|---|
| 556 | } |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | function checkImageSize($relative) |
|---|
| 564 | { |
|---|
| 565 | $fullpath = Files::makeFile($this->getImagesDir(),$relative); |
|---|
| 566 | |
|---|
| 567 | $afruext = strtolower(substr(strrchr($relative, "."), 1)); |
|---|
| 568 | |
|---|
| 569 | if(!in_array($afruext,$this->config['thumbnail_extensions'])) |
|---|
| 570 | { |
|---|
| 571 | $imgInfo=array(0,0); |
|---|
| 572 | Return $imgInfo; |
|---|
| 573 | } |
|---|
| 574 | else |
|---|
| 575 | { |
|---|
| 576 | $imgInfo = @getImageSize($fullpath); |
|---|
| 577 | |
|---|
| 578 | if(!is_array($imgInfo)) |
|---|
| 579 | { |
|---|
| 580 | $imgInfo=array(0,0); |
|---|
| 581 | Return $imgInfo; |
|---|
| 582 | } |
|---|
| 583 | else |
|---|
| 584 | { |
|---|
| 585 | if($imgInfo[0] > $this->config['thumbnail_width']) |
|---|
| 586 | $imgInfo[0] = $this->config['thumbnail_width']; |
|---|
| 587 | |
|---|
| 588 | if($imgInfo[1] > $this->config['thumbnail_height']) |
|---|
| 589 | $imgInfo[1] = $this->config['thumbnail_height']; |
|---|
| 590 | |
|---|
| 591 | Return $imgInfo; |
|---|
| 592 | } |
|---|
| 593 | } |
|---|
| 594 | |
|---|
| 595 | } |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | |
|---|
| 609 | |
|---|
| 610 | |
|---|
| 611 | |
|---|
| 612 | |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | function getThumbnail($relative) |
|---|
| 616 | { |
|---|
| 617 | global $IMConfig; |
|---|
| 618 | |
|---|
| 619 | $fullpath = Files::makeFile($this->getImagesDir(),$relative); |
|---|
| 620 | |
|---|
| 621 | |
|---|
| 622 | if(!is_file($fullpath)) |
|---|
| 623 | Return $this->getDefaultThumb(); |
|---|
| 624 | |
|---|
| 625 | $afruext = strtolower(substr(strrchr($relative, "."), 1)); |
|---|
| 626 | |
|---|
| 627 | if(!in_array($afruext,$this->config['thumbnail_extensions'])) |
|---|
| 628 | { |
|---|
| 629 | if(is_file('icons/'.$afruext.'.gif')) |
|---|
| 630 | Return('icons/'.$afruext.'.gif'); |
|---|
| 631 | else |
|---|
| 632 | Return $this->getDefaultThumb(); |
|---|
| 633 | } |
|---|
| 634 | |
|---|
| 635 | $imgInfo = @getImageSize($fullpath); |
|---|
| 636 | |
|---|
| 637 | |
|---|
| 638 | if(!is_array($imgInfo)) |
|---|
| 639 | Return $this->getDefaultThumb(); |
|---|
| 640 | |
|---|
| 641 | |
|---|
| 642 | |
|---|
| 643 | if(!$this->config['img_library']) Return $this->getFileURL($relative); |
|---|
| 644 | |
|---|
| 645 | |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | if ($imgInfo[0] <= $this->config['thumbnail_width'] |
|---|
| 649 | && $imgInfo[1] <= $this->config['thumbnail_height']) |
|---|
| 650 | Return $this->getFileURL($relative); |
|---|
| 651 | |
|---|
| 652 | $thumbnail = $this->getThumbName($fullpath); |
|---|
| 653 | |
|---|
| 654 | |
|---|
| 655 | |
|---|
| 656 | if(is_file($thumbnail)) |
|---|
| 657 | { |
|---|
| 658 | if(filemtime($thumbnail) >= filemtime($fullpath)) |
|---|
| 659 | Return $this->getThumbURL($relative); |
|---|
| 660 | } |
|---|
| 661 | |
|---|
| 662 | |
|---|
| 663 | |
|---|
| 664 | Return $IMConfig['backend_url'] . '__function=thumbs&img='.rawurlencode($relative)."&mode=$this->mode"; |
|---|
| 665 | } |
|---|
| 666 | |
|---|
| 667 | |
|---|
| 668 | |
|---|
| 669 | |
|---|
| 670 | |
|---|
| 671 | function deleteFiles() |
|---|
| 672 | { |
|---|
| 673 | if(isset($_GET['delf'])) |
|---|
| 674 | return $this->_delFile(rawurldecode($_GET['delf'])); |
|---|
| 675 | return false; |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | |
|---|
| 679 | |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | function deleteDirs() |
|---|
| 683 | { |
|---|
| 684 | if(isset($_GET['deld'])) |
|---|
| 685 | return $this->_delDir(rawurldecode($_GET['deld'])); |
|---|
| 686 | else |
|---|
| 687 | Return false; |
|---|
| 688 | } |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | function _delFile($relative) |
|---|
| 696 | { |
|---|
| 697 | $fullpath = Files::makeFile($this->getImagesDir(),$relative); |
|---|
| 698 | |
|---|
| 699 | $afruext = strtolower(substr(strrchr($relative, "."), 1)); |
|---|
| 700 | |
|---|
| 701 | $valid_extensions = $this->mode == 'image' ? $this->config['allowed_image_extensions'] : $this->config['allowed_link_extensions']; |
|---|
| 702 | |
|---|
| 703 | if(!in_array($afruext,$valid_extensions)) |
|---|
| 704 | { |
|---|
| 705 | return false; |
|---|
| 706 | } |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | if(is_array($this->getImageInfo($fullpath))) |
|---|
| 710 | { |
|---|
| 711 | $thumbnail = $this->getThumbName($fullpath); |
|---|
| 712 | Files::delFile($thumbnail); |
|---|
| 713 | } |
|---|
| 714 | |
|---|
| 715 | Return Files::delFile($fullpath); |
|---|
| 716 | } |
|---|
| 717 | |
|---|
| 718 | |
|---|
| 719 | |
|---|
| 720 | |
|---|
| 721 | |
|---|
| 722 | |
|---|
| 723 | function _delDir($relative) |
|---|
| 724 | { |
|---|
| 725 | $fullpath = Files::makePath($this->getImagesDir(),$relative); |
|---|
| 726 | |
|---|
| 727 | return Files::delFolder($fullpath,true); |
|---|
| 728 | |
|---|
| 729 | |
|---|
| 730 | } |
|---|
| 731 | |
|---|
| 732 | |
|---|
| 733 | |
|---|
| 734 | |
|---|
| 735 | |
|---|
| 736 | |
|---|
| 737 | function processNewDir() |
|---|
| 738 | { |
|---|
| 739 | if($this->config['safe_mode'] == true) |
|---|
| 740 | Return false; |
|---|
| 741 | |
|---|
| 742 | if(isset($_GET['newDir']) && isset($_GET['dir'])) |
|---|
| 743 | { |
|---|
| 744 | $newDir = rawurldecode($_GET['newDir']); |
|---|
| 745 | $dir = rawurldecode($_GET['dir']); |
|---|
| 746 | $path = Files::makePath($this->getImagesDir(),$dir); |
|---|
| 747 | $fullpath = Files::makePath($path, Files::escape($newDir)); |
|---|
| 748 | if(is_dir($fullpath)) |
|---|
| 749 | Return false; |
|---|
| 750 | |
|---|
| 751 | Return Files::createFolder($fullpath); |
|---|
| 752 | } |
|---|
| 753 | } |
|---|
| 754 | |
|---|
| 755 | |
|---|
| 756 | |
|---|
| 757 | |
|---|
| 758 | |
|---|
| 759 | function processRenames() |
|---|
| 760 | { |
|---|
| 761 | if(!empty($_GET['rename']) && !empty($_GET['renameTo'])) |
|---|
| 762 | { |
|---|
| 763 | |
|---|
| 764 | $newName = Files::escape(rawurldecode($_GET['renameTo'])); |
|---|
| 765 | $newName = str_replace('.', '', $newName); |
|---|
| 766 | |
|---|
| 767 | |
|---|
| 768 | $oldName = rawurldecode($_GET['rename']); |
|---|
| 769 | |
|---|
| 770 | |
|---|
| 771 | $oldName = preg_replace('#\.\.#', '', $oldName); |
|---|
| 772 | |
|---|
| 773 | if (is_dir($oldPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$oldName))) |
|---|
| 774 | { |
|---|
| 775 | $newPath = Files::makeFile($this->getImagesDir(), $_GET['dir'].$newName); |
|---|
| 776 | return Files::rename($oldPath,$newPath); |
|---|
| 777 | } |
|---|
| 778 | else |
|---|
| 779 | { |
|---|
| 780 | |
|---|
| 781 | $oldPath = Files::makeFile($this->getImagesDir(), $oldName); |
|---|
| 782 | |
|---|
| 783 | $ret = Files::renameFile($oldPath, $newName); |
|---|
| 784 | if ($ret === true) { |
|---|
| 785 | |
|---|
| 786 | Files::delFile($this->getThumbname($oldPath)); |
|---|
| 787 | } |
|---|
| 788 | } |
|---|
| 789 | return $ret; |
|---|
| 790 | } |
|---|
| 791 | |
|---|
| 792 | return null; |
|---|
| 793 | } |
|---|
| 794 | |
|---|
| 795 | function processPaste() |
|---|
| 796 | { |
|---|
| 797 | switch ($_GET['paste']) |
|---|
| 798 | { |
|---|
| 799 | case 'copyFile': |
|---|
| 800 | $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']); |
|---|
| 801 | $file = $_GET['file']; |
|---|
| 802 | $dest = Files::makeFile($this->getImagesDir(), $_GET['dir']); |
|---|
| 803 | return Files::copyFile($src,$dest,$file); |
|---|
| 804 | break; |
|---|
| 805 | case 'copyDir': |
|---|
| 806 | $basePath = $this->getImagesDir(); |
|---|
| 807 | $src = $_GET['srcdir'].$_GET['file']; |
|---|
| 808 | $dest = $_GET['dir'].$_GET['file']; |
|---|
| 809 | return Files::copyDir($basePath,$src,$dest); |
|---|
| 810 | break; |
|---|
| 811 | case 'moveFile': |
|---|
| 812 | $src = Files::makePath($this->getImagesDir(), $_GET['srcdir'].$_GET['file']); |
|---|
| 813 | $dest = Files::makePath($this->getImagesDir(), $_GET['dir'].$_GET['file']); |
|---|
| 814 | return Files::rename($src,$dest); |
|---|
| 815 | break; |
|---|
| 816 | case 'moveDir': |
|---|
| 817 | $src = Files::makeFile($this->getImagesDir(), $_GET['srcdir'].$_GET['file']); |
|---|
| 818 | $dest = Files::makeFile($this->getImagesDir(), $_GET['dir'].$_GET['file']); |
|---|
| 819 | return Files::rename($src,$dest); |
|---|
| 820 | break; |
|---|
| 821 | } |
|---|
| 822 | } |
|---|
| 823 | } |
|---|
| 824 | |
|---|
| 825 | ?> |
|---|