AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.8 KiB

7 years ago
<?php
7 years ago
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
7 years ago
7 years ago
if (! defined('ACP') || !check_permission('mediapool_int'))
{
header('Location:index.php');
exit;
}
7 years ago
7 years ago
global $AVE_DB, $AVE_Template;
7 years ago
7 years ago
ob_start();
ob_implicit_flush(0);
7 years ago
7 years ago
$_REQUEST['onlycontent'] = 1;
7 years ago
7 years ago
$max_size = 128; // максимальный размер миниатюры
$thumb_size = '-t' . $max_size . 'x' . $max_size; // формат миниатюр
$images_ext = array('jpg', 'jpeg', 'png', 'gif', 'JPG', 'JPEG', 'PNG', 'GIF');
7 years ago
7 years ago
$upload_path = BASE_DIR . '/' . UPLOAD_DIR;
7 years ago
7 years ago
$lang = empty($_SESSION['admin_language'])
? 'ru'
: $_SESSION['admin_language'];
7 years ago
7 years ago
$AVE_Template = new AVE_Template(BASE_DIR . '/admin/templates/browser');
$AVE_Template->config_load(BASE_DIR . '/admin/lang/' . $lang . '/main.txt');
$AVE_Template->assign('tpl_dir', 'templates/');
$AVE_Template->assign('ABS_PATH', '../');
7 years ago
7 years ago
if (! isset($_REQUEST['action']))
$_REQUEST['action'] = '';
7 years ago
7 years ago
switch ($_REQUEST['action'])
{
case 'list':
$dir = (empty($_REQUEST['dir'])
|| strpos($_REQUEST['dir'], '..') !== false
|| strpos($_REQUEST['dir'], '//') !== false) ? '/' : $_REQUEST['dir'];
7 years ago
7 years ago
$path = $upload_path . (is_dir($upload_path . $dir) ? $dir : '/');
7 years ago
7 years ago
$new_dir = $path . (isset($_REQUEST['newdir']) ? $_REQUEST['newdir'] : '');
$new_dir_rezult = (!is_dir($new_dir) && !mkdir($new_dir, 0777));
7 years ago
7 years ago
$skip_entry = array(THUMBNAIL_DIR, 'recycled', 'index.php');
7 years ago
7 years ago
$dirs = array();
$files = array();
7 years ago
7 years ago
$d = @dir($path);
7 years ago
7 years ago
while (false !== ($entry = @$d->read()))
7 years ago
{
7 years ago
if (in_array($entry, $skip_entry) || $entry{0} === '.')
continue;
7 years ago
7 years ago
if (is_dir($path . $entry))
7 years ago
{
7 years ago
$dirs[$entry] = 'index.php?do=browser&type=' . $_REQUEST['type']
. '&amp;action=list&amp;dir=' . $dir . $entry . '/';
7 years ago
}
else
{
7 years ago
$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;
7 years ago
}
7 years ago
}
$d->close();
ksort($dirs);
ksort($files);
7 years ago
7 years ago
$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 '<script type="text/javascript">window.close();</script>';
7 years ago
}
7 years ago
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'))
7 years ago
{
7 years ago
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))
7 years ago
{
foreach (glob($upload_path . $_REQUEST['dir'] . THUMBNAIL_DIR . '/*') as $f_name)
7 years ago
{
$base_file = basename($del_file);
$nameParts = explode('.', $base_file);
$start = strtolower(array_shift($nameParts));
$ext = strtolower(array_pop($nameParts));
$regexp = '/^(' . $start . ')*(-)(t|f|c|s).{3,}.(' . $ext . ')/';
if (preg_match_all($regexp, basename($f_name))) {
@unlink($upload_path . $_REQUEST['dir'] . THUMBNAIL_DIR . '/' . basename($f_name));
}
7 years ago
}
reportLog($_SESSION['user_name'] . ' - удалил файл ('
. UPLOAD_DIR . $_REQUEST['dir'] . $file_name . ')');
7 years ago
}
}
7 years ago
echo '<script type="text/javascript">
parent.frames[\'zf\'].location.href="index.php?do=browser&type=', $_REQUEST['type'], '&action=list&dir=', $_REQUEST['dir'], '";
</script>';
break;
7 years ago
7 years ago
default:
7 years ago
7 years ago
@list($target, $target_id) = explode('__', $_REQUEST['target']);
7 years ago
7 years ago
$tval = '/';
7 years ago
7 years ago
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)), '\\/') . '/';
}
7 years ago
7 years ago
if (is_file(BASE_DIR . '/' . $_REQUEST['tval'])) {
$tval = rtrim(dirname(substr($_REQUEST['tval'], strlen('/' . UPLOAD_DIR))), '\\/') . '/';
}
7 years ago
}
7 years ago
$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);
7 years ago
7 years ago
$AVE_Template->display('browser_2frames.tpl');
break;
}
7 years ago
7 years ago
$out = ob_get_clean();
7 years ago
7 years ago
echo $out;
7 years ago
7 years ago
?>