config_load(BASE_DIR . '/admin/lang/' . $lang . '/main.txt');
$AVE_Template->assign('tpl_dir', 'templates/');
$AVE_Template->assign('ABS_PATH', '../');
if (! isset($_REQUEST['action']))
$_REQUEST['action'] = '';
switch ($_REQUEST['action'])
{
case 'list':
$dir = (empty($_REQUEST['dir'])
|| strpos($_REQUEST['dir'], '..') !== false
|| strpos($_REQUEST['dir'], '//') !== false) ? '/' : $_REQUEST['dir'];
$path = $upload_path . (is_dir($upload_path . $dir) ? $dir : '/');
$new_dir = $path . (isset($_REQUEST['newdir']) ? $_REQUEST['newdir'] : '');
$new_dir_rezult = (!is_dir($new_dir) && !mkdir($new_dir, 0777));
$skip_entry = array(THUMBNAIL_DIR, 'recycled', 'index.php');
$dirs = array();
$files = array();
$d = @dir($path);
while (false !== ($entry = @$d->read()))
{
if (in_array($entry, $skip_entry) || $entry{0} === '.')
continue;
if (is_dir($path . $entry))
{
$dirs[$entry] = 'index.php?do=browser&type=' . $_REQUEST['type']
. '&action=list&dir=' . $dir . $entry . '/';
}
else
{
$nameParts = explode('.', $entry);
$ext = strtolower(end($nameParts));
$file['icon'] = file_exists("templates/images/mediapool/{$ext}.gif") ? $ext : 'attach';
$file['filesize'] = @round(@filesize($path . $entry)/1024, 2);
$file['moddate'] = date("d.m.y, H:i", @filemtime($path . $entry));
if (in_array($ext, $images_ext))
{
$nameParts[count($nameParts)-2] .= $thumb_size;
$file['bild'] = '/' . UPLOAD_DIR . $dir . THUMBNAIL_DIR . '/' . implode('.', $nameParts);
}
else
{
$file['bild'] = 'templates/images/file.gif';
}
$files[$entry] = $file;
}
}
$d->close();
ksort($dirs);
ksort($files);
$AVE_Template->assign('new_dir_rezult', $new_dir_rezult);
$AVE_Template->assign('recycled', strpos($dir, '/recycled/') === 0);
$AVE_Template->assign('dirs', $dirs);
$AVE_Template->assign('files', $files);
$AVE_Template->assign('max_size', $max_size);
$AVE_Template->assign('dir', $dir);
$AVE_Template->assign('dirup', rtrim(dirname($dir), '\\/') . '/');
$AVE_Template->assign('mediapath', UPLOAD_DIR);
$AVE_Template->display('browser.tpl');
break;
case 'upload':
if (check_permission('mediapool_add'))
{
$AVE_Template->display('browser_upload.tpl');
}
else
{
echo '';
}
break;
case 'upload2':
header('Location:index.php?do=browser&type=image&target=' . $_REQUEST['target'] . '&tval=/' . UPLOAD_DIR . $_REQUEST['tval']);
break;
case 'delfile':
if (check_permission('mediapool_del'))
{
if (empty($_REQUEST['file']) || empty($_REQUEST['dir']))
exit(0);
$file_name = basename($_REQUEST['file']);
$del_file = $upload_path . $_REQUEST['dir'] . $file_name;
if (strpos($del_file, '..') !== false || !is_file($del_file)) exit(0);
$recycled_path = $upload_path . '/recycled/';
if (!is_dir($recycled_path) && !mkdir($recycled_path)) exit(0);
do {$nameParts = explode('.', $file_name);
$nameParts[count($nameParts)-2] .= '-' . uniqid(rand());
$recycled_file_name = implode('.', $nameParts);
} while (file_exists($recycled_path . $recycled_file_name));
@copy($del_file, $recycled_path . $recycled_file_name);
if (@unlink($del_file))
{
$nameParts = explode('.', $file_name);
$ext = strtolower(end($nameParts));
if (in_array($ext, $images_ext))
{
$nameParts[count($nameParts)-2] .= $thumb_size;
@unlink($upload_path . $_REQUEST['dir'] . THUMBNAIL_DIR . '/' . implode('.', $nameParts));
}
reportLog($_SESSION['user_name'] . ' - удалил файл ('
. UPLOAD_DIR . $_REQUEST['dir'] . $file_name . ')');
}
}
echo '';
break;
default:
@list($target, $target_id) = explode('__', $_REQUEST['target']);
$tval = '/';
if (!empty($_REQUEST['tval']) && 0 === strpos($_REQUEST['tval'], '/' . UPLOAD_DIR . '/'))
{
if (is_dir(BASE_DIR . '/' . $_REQUEST['tval'])) {
$tval = rtrim(substr($_REQUEST['tval'], strlen('/' . UPLOAD_DIR)), '\\/') . '/';
}
if (is_file(BASE_DIR . '/' . $_REQUEST['tval'])) {
$tval = rtrim(dirname(substr($_REQUEST['tval'], strlen('/' . UPLOAD_DIR))), '\\/') . '/';
}
}
$AVE_Template->assign('dir', $tval);
$AVE_Template->assign('target', $target);
$AVE_Template->assign('target_id', $target_id);
$AVE_Template->assign('cppath', substr($_SERVER['PHP_SELF'], 0, -18));
$AVE_Template->assign('mediapath', UPLOAD_DIR);
$AVE_Template->display('browser_2frames.tpl');
break;
}
$out = ob_get_clean();
echo $out;
?>