setBlock('ibrowser'); //------------------------------------------------------------------------- // parameters $param = (isset($_REQUEST['param']) ? $_REQUEST['param'] : ''); if (isset($param)) { $param = explode('|', $param); } // set action $action = (isset($_REQUEST['action']) ? $_REQUEST['action'] : ''); // set image library $clib = (isset($_REQUEST['clib']) ? $_REQUEST['clib'] : (isset($_REQUEST['ilibs']) ? $_REQUEST['ilibs'] : $cfg['ilibs'][0]['value'])); // set current file $cfile = (isset($_REQUEST['cfile']) ? $_REQUEST['cfile'] : ''); // set new file $nfile = (isset($_REQUEST['nfile']) ? $_REQUEST['nfile'] : ''); // set list view $list = (isset($_REQUEST['flist']) ? $_REQUEST['flist'] : $cfg['list']); $list = false; //------------------------------------------------------------------------- // file/directory actions if ($param[0] == 'delete') { // ACTION: delete image $action = $param[0]; $cfile = $param[1]; // current filename if(!deleteImg($clib, $cfile)) { echo $l->m('er_001') . ': ' . $l->m('er_030'); }; } else if ($param[0] == 'rename') { // ACTION: rename image $action = $param[0]; $cfile = $param[1]; // current filename $nfile = $param[2]; // new filename if(!$nfile = renameImg($clib, $cfile, $nfile)) { echo $l->m('er_001') . ': ' . $l->m('er_033'); }; } else if ($param[0] == 'upload') { // ACTION: upload image $action = $param[0]; $chkT = (isset($_REQUEST['chkThumbSize']) ? $_REQUEST['chkThumbSize'] : Array() ); // thumb-sizes in Array $selR = (isset($_REQUEST['selRotate']) ? $_REQUEST['selRotate'] : ''); // auto rotate if (isset($_FILES['nfile']['name'][0])) { if (!$nfile = uploadImg($clib, $chkT, $selR)) { echo $l->m('er_001') . ': ' . $l->m('er_028'); } }; } else if ($param[0] == 'create') { // ACTION: create directory $action = $param[0]; $nfile = $param[1]; // new filename if(!createDir($clib, $nfile)) { echo $l->m('er_001') . ': ' . $l->m('er_034'); }; } else if ($param[0] == 'update') { // ACTION: update image list and select current image $action = $param[0]; $cfile = $param[1]; // current filename } else if ($param[0] == 'switch') { // ACTION: switch image list view (list or thumbnails) $action = $param[0]; $cfile = $param[1]; // current filename } ?> <?php echo $l->m('im_002'); ?> Image list
$ext) { $size = @getimagesize($path . basename($filename)); if( $size === false ) { continue; } $fsize = filesize($path . basename($filename)); $modified = date($dfmt, filemtime($path . basename($filename))); $created = date($dfmt, filectime($path . basename($filename))); $ctype = iType($size[2]); /*if ($list == true || $list == 1) {*/ $retstr .= '
  • ' . htmlentities(basename($filename), ENT_QUOTES,$l->getCharset()) . '
  • ' . "\n"; /*} else { $src = 'phpThumb/phpThumb.php?src=' . absPath(str_replace($cfg['root_dir'],'', $path)) . basename($filename) . '&w=48&h=48&far=1&bg=ffffff&f=jpg'; $retstr .= '
  • ' . '' . basename($filename) . '; ' . htmlentities($size[0], ENT_QUOTES) . ' x ' . htmlentities($size[1], ENT_QUOTES) . 'px;' . '' . '
  • ' . "\n"; }*/ } return $retstr; } echo $l->m('er_036'); return false; } // get image types function iType($type) { switch ($type) { case 1: $str = 'GIF'; break; case 2: $str = 'JPG'; break; case 3: $str = 'PNG'; break; case 4: $str = 'SWF'; break; case 5: $str = 'PSD'; break; case 6: $str = 'BMP'; break; case 7: $str = 'TIFF'; break; case 8: $str = 'TIFF'; break; case 15: $str = 'WBMP'; break; default: $str = 'n/a'; break; } return $str; } //------------------------------------------------------------------------- // Return the human readable size of a file // @param int $size a file size // @param int $dec a number of decimal places function filesize_h($size, $dec = 1) { $sizes = array('b', 'kb', 'mb', 'gb'); $count = count($sizes); $i = 0; while ($size >= 1024 && ($i < $count - 1)) { $size /= 1024; $i++; } return round($size, $dec) . '|' . $sizes[$i]; } //------------------------------------------------------------------------- // delete image function deleteImg($clib, $cfile) { global $cfg; global $l; if (!$cfg['delete']) { return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path return @unlink($path . $cfile); // returns true or false } //------------------------------------------------------------------------- // rename image function renameImg($clib, $cfile, $nfile) { global $cfg; global $l; if (!$cfg['rename']) { return false; } // check new file extension $ext = strtolower(substr($nfile,strrpos($nfile, '.')+1)); if (!in_array($ext, $cfg['valid'])) { // invalid image / file extension echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path if (file_exists($path . $cfile)) { $nfile = fixFileName($nfile); // remove invalid characters in file name $nfile = chkFileName($path, $nfile); // rename if file already exists @rename($path . $cfile, $path . $nfile); return $nfile; } return false; } //------------------------------------------------------------------------- // create directory function createDir($clib, $nfile) { global $cfg; global $l; if (!$cfg['create']) { return false; } $nfile = fixFileName($nfile); $tfile = $nfile; $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path // renaming directory if it already exists // keep looping and incrementing _i filenumber until a non-existing one is found $i = 1; while (file_exists($path . $nfile)) { $nfile = $tfile . '_' . $i; $i++; } $perm = 0777; $oumask = umask(0); umask(); if(@mkdir($path . $nfile, $perm)) { umask($oumask); return true; } umask($oumask); return false; } //------------------------------------------------------------------------- // upload image function uploadImg($clib, $chkT, $selR) { global $cfg; global $l; if (!$cfg['upload']) { return false; } foreach ($_FILES['nfile']['size'] as $key => $size) { if ($size > 0) { // get file extension and check for validity $ext = pathinfo($_FILES['nfile']['name'][$key]); $ext = strtolower($ext['extension']); if (!in_array($ext, $cfg['valid'])) { // invalid image echo $l->m('er_029'); return false; } $path = str_replace('//', '/', $cfg['root_dir'] . $clib); // remove double slash in path $nfile = fixFileName($_FILES['nfile']['name'][$key]); // remove invalid characters in filename // move file to temp directory for processing if (!move_uploaded_file($_FILES['nfile']['tmp_name'][$key], $cfg['temp'] . '/' . $nfile)) { // upload image to temp dir echo $l->m('er_028'); return false; } $size = getimagesize($cfg['temp'] . '/' . $nfile); // process (thumbnail) images $arr = $cfg['thumbs']; foreach($arr as $key => $thumb) { if (in_array($key, $chkT)) { // create new phpThumb() object require_once(dirname(__FILE__) . '/phpThumb/phpthumb.class.php'); $phpThumb = new phpThumb(); // create object // parameters $phpThumb->config_cache_disable_warning = true; // disable cache warning $phpThumb->config_output_format = $ext; // output format $phpThumb->src = $cfg['temp'] . '/' . $nfile; // destination $phpThumb->q = 95; // compression level for jpeg if ($selR != '') { // set auto rotate $phpThumb->ar = $selR; }; //------------------------------------------------------------------------- if ($thumb['size'] > 0 && ($size[0] >= $thumb['size'] || $size[1] >= $thumb['size'])) { // size value is set -> RESIZING and source image is larger than preset sizes // resize parameters if ($size[0] < $size[1]) { // portrait $phpThumb->h = $thumb['size']; // max. height } else { $phpThumb->w = $thumb['size']; // max. width } // crop parameters if($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop $phpThumb->w = $thumb['size']; // width $phpThumb->h = $thumb['size']; // height } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . $thumb['size']; // e.g. _1280 } else if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_'. $thumb['ext']; } //------------------------------------------------------------------------- } elseif ($thumb['size'] == 0 || $thumb['size'] == '*') { // size value is set to '0' -> NO RESIZING // crop parameters if ($thumb['crop'] == true) { $phpThumb->zc = 1; // set zoom crop if($size[0] < $size[1]) { // portrait $phpThumb->w = $size[0]; // getimagesize width value $phpThumb->h = $size[0]; // getimagesize width value } else { // landscape $phpThumb->w = $size[1]; // getimagesize height value $phpThumb->h = $size[1]; // getimagesize height value } } // create file suffix if ($thumb['ext'] == '*') { // image size is used $dim = '_' . (($size[0] <= $size[1]) ? $size[1] : $size[0]); // source height or width - e.g. _1280 } else if ($thumb['ext'] == '') { // no suffix is created $dim = ''; } else { // suffix is set to $thumb['ext'] $dim = '_'. $thumb['ext']; } //------------------------------------------------------------------------- } else { // default setting - images smaller than predefined sizes $dim = ''; // no file suffix is used } //------------------------------------------------------------------------- $nthumb = fixFileName(basename($nfile, '.' . $ext) . $dim . '.' . $ext); $nthumb = chkFileName($path, $nthumb); // rename if file already exists if ($phpThumb->GenerateThumbnail()) { $phpThumb->RenderToFile($path . $nthumb); @chmod($path . $nthumb, 0755) or die($l->m('er_028')); } else { // error echo $l->m('er_028'); return false; } unset($phpThumb); } } @unlink($cfg['temp'] . '/' . $nfile); // delete temporary file } } return $nthumb; } //------------------------------------------------------------------------- // escape and clean up file name (only lowercase letters, numbers and underscores are allowed) function fixFileName($file) { $file = ereg_replace("[^a-z0-9._-]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($file)))); return $file; } //------------------------------------------------------------------------- // check whether file already exists; rename file if filename already exists // keep looping and incrementing _i filenumber until a non-existing filename is found function chkFileName($path, $nfile) { $tfile = $nfile; $i = 1; while (file_exists($path . $nfile)) { $nfile = ereg_replace('(.*)(\.[a-zA-Z]+)$', '\1_' . sprintf('%02d',$i) . '\2', $tfile); $i++; } return $nfile; } // ============================================================ // = abs path - add slashes V 1.0, date: 05/10/2005 = // ============================================================ function absPath($path) { if(substr($path,-1) != '/') $path .= '/'; if(substr($path,0,1) != '/') $path = '/' . $path; return $path; } ?>