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.

425 lines
9.6 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
*/
// Изображение (Каскад)
function get_field_image_multi($field_value, $action, $field_id=0, $tpl='', $tpl_empty=0, &$maxlength=null, $document_fields=array(), $rubric_id=0, $default=null, $_tpl=null)
{
7 years ago
7 years ago
global $AVE_Template, $img_pixel;
7 years ago
7 years ago
$fld_dir = dirname(__FILE__) . '/';
$tpl_dir = $fld_dir . 'tpl/';
$fld_name = basename($fld_dir);
7 years ago
7 years ago
$lang_file = $fld_dir . 'lang/' . (defined('ACP')
? $_SESSION['admin_language']
: $_SESSION['user_language']) . '.txt';
7 years ago
7 years ago
$AVE_Template->config_load($lang_file, 'lang');
$AVE_Template->assign('config_vars', $AVE_Template->get_config_vars());
$AVE_Template->config_load($lang_file, 'admin');
7 years ago
7 years ago
$res = 0;
7 years ago
7 years ago
$iniset_count = ini_get('max_file_uploads');
7 years ago
7 years ago
switch ($action)
{
case 'edit':
7 years ago
7 years ago
$items = array();
$image_items = array();
7 years ago
7 years ago
if ($_REQUEST['action'] != 'new')
7 years ago
{
7 years ago
$items = unserialize($field_value);
if($items != false)
7 years ago
{
7 years ago
foreach($items as $k => $v)
{
$image_item = explode('|', $v);
7 years ago
7 years ago
$img = $image_item[0];
unset($image_item[0]);
$image_item = array($img, implode('|', $image_item));
7 years ago
7 years ago
$image[$k]['url'] = $image_item[0];
$image[$k]['thumb'] = ($image_item[0] != '')
? make_thumbnail(array('size' => 'f100x100', 'link' => $image_item[0]))
: $img_pixel;
7 years ago
7 years ago
$image[$k]['desc'] = (isset($image_item[1]))
? htmlspecialchars($image_item[1], ENT_QUOTES)
: '';
}
7 years ago
7 years ago
if (! empty($image))
{
$image_items = $image;
}
7 years ago
}
}
7 years ago
$show_upload = true;
7 years ago
7 years ago
$default = explode('|', $default);
7 years ago
7 years ago
list($path, $watermark, $position, $transparency) = $default;
7 years ago
7 years ago
if(preg_match("/%id/i", $path))
7 years ago
{
7 years ago
if ($_REQUEST['action'] != 'new')
{
$path_upload = trim(@str_replace('%id', $_REQUEST['Id'], $path), '/');
$show_upload = true;
}
else
{
$path_upload = (! empty($path))
? trim($path, '/')
: '';
$show_upload = false;
}
7 years ago
}
else
{
$path_upload = (! empty($path))
7 years ago
? $path
7 years ago
: '';
7 years ago
$show_upload = true;
7 years ago
}
7 years ago
$dir_upload = '/' . UPLOAD_DIR . '/' . ((!empty($path_upload))
? $path_upload . '/'
: '');
7 years ago
7 years ago
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'admin', $_tpl);
7 years ago
7 years ago
$AVE_Template->assign('max_files', $AVE_Template->get_config_vars('max_f_f') . $iniset_count);
$AVE_Template->assign('dir_upload', $AVE_Template->get_config_vars('upl_dir') . $dir_upload);
$AVE_Template->assign('show_upload', $show_upload);
7 years ago
7 years ago
$AVE_Template->assign('field_dir', $fld_name);
$AVE_Template->assign('images', $image_items);
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('doc_id', (isset($_REQUEST['Id']) ? (int)$_REQUEST['Id'] : 0));
return $AVE_Template->fetch($tpl_file);
break;
7 years ago
7 years ago
case 'doc':
7 years ago
7 years ago
$items = (isset($field_value))
? unserialize($field_value)
: array();
7 years ago
7 years ago
$res = array();
7 years ago
7 years ago
if ($items != false)
7 years ago
{
7 years ago
foreach ($items as $image_item)
7 years ago
{
7 years ago
$image_item = clean_php($image_item);
$field_param = explode('|', $image_item);
if ($image_item)
7 years ago
{
7 years ago
if ($tpl_empty)
7 years ago
{
7 years ago
$image_item = $field_param;
7 years ago
}
7 years ago
else
{
$image_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
$image_item = preg_replace_callback(
'/\[tag:watermark:(.+?):([a-zA-Z]+):([0-9]+)\]/',
create_function(
'$m',
'return watermarks(\'$m[1]\', \'$m[2]\', $m[3]);'
),
$image_item
);
$image_item = preg_replace_callback('/\[tag:([r|c|f|t|s]\d+x\d+r*):(.+?)]/', 'callback_make_thumbnail', $image_item);
}
}
7 years ago
7 years ago
$res[] = $image_item;
}
7 years ago
}
7 years ago
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'doc', $_tpl);
7 years ago
7 years ago
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('rubric_id', $rubric_id);
$AVE_Template->assign('default', $default);
7 years ago
7 years ago
return $AVE_Template->fetch($tpl_file);
}
7 years ago
7 years ago
return (! empty($res))
? implode(PHP_EOL, $res)
: $tpl;
7 years ago
7 years ago
break;
7 years ago
7 years ago
case 'req':
$items = unserialize($field_value);
7 years ago
7 years ago
$res = array();
7 years ago
7 years ago
if ($items != false)
7 years ago
{
7 years ago
foreach ($items as $image_item)
7 years ago
{
7 years ago
$image_item = clean_php($image_item);
$field_param = explode('|', $image_item);
if ($image_item)
7 years ago
{
7 years ago
if ($tpl_empty)
7 years ago
{
7 years ago
$image_item = $field_param;
7 years ago
}
7 years ago
else
{
$image_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_param)
{
return $field_param[(int)$data[1]];
},
$tpl
);
$image_item = preg_replace_callback(
'/\[tag:watermark:(.+?):([a-zA-Z]+):([0-9]+)\]/',
create_function(
'$m',
'return watermarks(\'$m[1]\', \'$m[2]\', $m[3]);'
),
$image_item
);
$image_item = preg_replace_callback('/\[tag:([r|c|f]\d+x\d+r*):(.+?)]/', 'callback_make_thumbnail', $image_item);
}
}
7 years ago
7 years ago
$res[] = $image_item;
}
7 years ago
}
7 years ago
$tpl_file = get_field_tpl($tpl_dir, $field_id, 'req', $_tpl);
7 years ago
7 years ago
if ($tpl_empty && $tpl_file)
{
$AVE_Template->assign('field_id', $field_id);
$AVE_Template->assign('field_value', $res);
$AVE_Template->assign('field_count', count($res));
$AVE_Template->assign('rubric_id', $rubric_id);
$AVE_Template->assign('default', $default);
7 years ago
7 years ago
return $AVE_Template->fetch($tpl_file);
}
7 years ago
7 years ago
return (! empty($res))
? implode(PHP_EOL, $res)
: $tpl;
7 years ago
7 years ago
break;
7 years ago
7 years ago
case 'save':
foreach ($field_value as $v)
7 years ago
{
7 years ago
if (! empty($v['url']))
{
$field_value_new[] = $v['url'] . ($v['descr'] ? '|' . $v['descr'] : '');
}
7 years ago
}
7 years ago
if (isset($field_value_new))
7 years ago
{
7 years ago
return @serialize($field_value_new);
7 years ago
}
7 years ago
else
{
return $field_value_new = '';
}
7 years ago
7 years ago
break;
7 years ago
4 years ago
case 'api':
if (empty($field_value))
return $field_value;
$items = [];
if (! empty($field_value))
{
$images = unserialize($field_value);
if (! $images)
return false;
foreach ($images AS $k => $v)
{
$_item = explode('|', $v);
$items[$k] = [
'url' => $_item[0],
'descr' => (isset($_item[1]) ? $_item[2] : ''),
];
}
}
return $items;
break;
7 years ago
case 'name' :
return $AVE_Template->get_config_vars('name');
break;
7 years ago
7 years ago
case 'upload':
$error = false;
7 years ago
7 years ago
$search = array();
$replace = array();
7 years ago
7 years ago
$files_unput = 'cascade_files'.'_'.$_REQUEST['field_id'].'_'.$_REQUEST['doc_id'];
7 years ago
7 years ago
$search[] = '%d';
$replace[] = date('d');
$search[] = '%m';
$replace[] = date('m');
$search[] = '%Y';
$replace[] = date('Y');
7 years ago
7 years ago
$default = explode('|', $default);
7 years ago
7 years ago
list($path_upload, $watermark, $position, $transparency) = $default;
7 years ago
7 years ago
if (! empty($path_upload))
$path_upload = str_replace($search, $replace, $path_upload);
7 years ago
7 years ago
if(preg_match("/%id/i", $path_upload))
7 years ago
{
7 years ago
$path = trim(@str_replace('%id', $_REQUEST['doc_id'], $path_upload), '/');
7 years ago
}
7 years ago
else
{
$path = (! empty($path_upload))
? $path_upload
: '';
}
7 years ago
4 years ago
if (! function_exists('getExtension')) {
function getExtension($file)
{
$file = pathinfo($file);
return $file['extension'];
}
7 years ago
}
7 years ago
7 years ago
$valid_formats = array("jpg", "png", "gif", "bmp","jpeg");
7 years ago
7 years ago
$dir = '/' . UPLOAD_DIR . '/' . ((! empty($path))
? trim($path, '/') . '/'
: '');
7 years ago
7 years ago
$dir_abs = BASE_DIR . $dir;
7 years ago
7 years ago
if (! is_dir($dir_abs))
@mkdir($dir_abs, 0777, true);
7 years ago
7 years ago
foreach ($_FILES[$files_unput]['name'] as $name => $value)
7 years ago
{
7 years ago
$filename = strtolower(stripslashes(prepare_url($_FILES[$files_unput]['name'][$name])));
$ext = getExtension($filename);
$ext = strtolower($ext);
7 years ago
7 years ago
if(in_array($ext, $valid_formats))
7 years ago
{
7 years ago
if (file_exists($dir_abs . $filename))
{
$filename = rand(1000, 9999) . '_' . $filename;
}
7 years ago
7 years ago
if (@move_uploaded_file($_FILES[$files_unput]['tmp_name'][$name], $dir_abs . $filename))
7 years ago
{
7 years ago
$new_files[] = $filename;
$error = false;
7 years ago
7 years ago
if ((bool)$watermark)
{
$position = ($position != '') ? $position : 'center';
$transparency = ($transparency != '') ? $transparency : '100';
watermarks($dir . $filename, $position, $transparency);
}
7 years ago
}
7 years ago
else
{
$error = true;
}
7 years ago
}
else
{
$error = true;
7 years ago
@unlink($_FILES[$files_unput]['tmp_name'][$name]);
7 years ago
}
}
7 years ago
if ($error !== true)
7 years ago
{
echo json_encode(array(
7 years ago
'files' => $new_files,
'dir' => $dir,
'respons' => 'succes',
'message' => $AVE_Template->get_config_vars('resp_s_m'),
'header' => $AVE_Template->get_config_vars('resp_s_h'),
'theme' => 'accept'
7 years ago
)
);
}
7 years ago
else
{
echo json_encode(array(
'respons' => 'error',
'message' => $AVE_Template->get_config_vars('resp_e_m'),
'header' => $AVE_Template->get_config_vars('resp_e_h'),
'theme' => 'error'
)
);
}
7 years ago
7 years ago
exit;
}
7 years ago
7 years ago
return ($res ? $res : $field_value);
}
?>