Browse Source

Fixed images fields

master
MadD3n 2 years ago
parent
commit
e30344ca6f
  1. 4
      README.md
  2. 4
      admin/templates/browser/browser.tpl
  3. 107
      admin/templates/browser/browser_2frames.tpl
  4. 2
      admin/templates/browser/browser_upload.tpl
  5. 45
      fields/image_mega/field.php
  6. 65
      fields/image_mega/js/field.js

4
README.md

@ -19,8 +19,8 @@
* ПО WEB сервера:
* Apache >= 1.3
* Nginx >= 1.6.2
* PHP >= 5.6.x (zlib, cURL, mbString, JSON)
* PHP >= 7.x ... <= 7.4.x
* PHP >= 5.6.x (!!!Не поддерживается!!!)
* PHP >= 7.x ... <= 7.4.x (zlib, cURL, mbString, JSON)
* MySQL >= 5.6.x ... <= 5.7.x
## Установка

4
admin/templates/browser/browser.tpl

@ -163,8 +163,8 @@
{rdelim});
function ConfirmDelete(fName) {ldelim}
var title = "{#MAIN_MP_FILE_DELETE#}";
var confirm = "{#MAIN_MP_DELETE_CONFIRM#}";
let title = "{#MAIN_MP_FILE_DELETE#}";
let confirm = "{#MAIN_MP_DELETE_CONFIRM#}";
jConfirm(
confirm,
title,

107
admin/templates/browser/browser_2frames.tpl

@ -31,11 +31,12 @@
<!-- JS Scripts -->
<script type="text/javascript">
var ave_path = "{$ABS_PATH}";
var ave_theme = "{$smarty.const.DEFAULT_THEME_FOLDER}";
var ave_admintpl = "{$tpl_dir}";
let ave_path = "{$ABS_PATH}";
let ave_theme = "{$smarty.const.DEFAULT_THEME_FOLDER}";
let ave_admintpl = "{$tpl_dir}";
let th_folder = "{$smarty.const.THUMBNAIL_DIR}";
var sess = '{$sess}';
let sess = '{$sess}';
$(document).ready(function(){ldelim}
@ -46,8 +47,8 @@
);
{literal}
var mainframe = $('#mainframe');
var height = $("body").height();
let mainframe = $('#mainframe');
let height = $("body").height();
mainframe.css({"height": height-280});
$(window).bind(
@ -55,8 +56,8 @@
function()
{
$(window).resize(function() {
var mainframe = $('#mainframe');
var height = $("body").height();
let mainframe = $('#mainframe');
let height = $("body").height();
mainframe.css({"height": height-280});
});
}
@ -84,42 +85,42 @@
</div>
<div class="widget first">
<form style="display:inline;" name="bForm" onSubmit="return false;" class="mainForm">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<tr>
<td>
<div class="pr12"><input type="text" name="bDirName" id="DirName" size="20" style="width:100%;" readonly="readonly" /></div>
</td>
<td width="5%" nowrap="nowrap">
<input type="button" class="basicBtn" onClick="NewFolder();" value="{#MAIN_MP_CREATE_FOLDER#}" />&nbsp;
</td>
{if check_permission('mediapool_add')}
<td width="5%" nowrap="nowrap">
<a class="button basicBtn openDialog" data-modal="true" data-height="455" href="index.php?do=browser&type={$smarty.request.type|escape}&target={$smarty.request.target|escape}&action=upload&dir=" data-title="{#MAIN_MP_UPLOAD_FILE#}">{#MAIN_MP_UPLOAD_FILE#}</a>
</td>
{/if}
</tr>
<tr valign="top">
<td{if check_permission('mediapool_add')} colspan="3"{else} colspan="2"{/if}>
<div style="border:1px solid #d4d4d4; overflow:hidden; height:100%; width:100%">
<iframe id="mainframe" frameborder="0" name="zf" id="zf" width="100%" height="100%" scrolling="Yes" src="index.php?onlycontent=1&do=browser&type={$smarty.request.type|escape}&action=list&dir={$dir}&target={$smarty.request.target|escape}"></iframe>
</div>
</td>
</tr>
{if $smarty.request.type!=''}
<form style="display:inline;" name="bForm" onSubmit="return false;" class="mainForm">
<table cellpadding="0" cellspacing="0" width="100%" class="tableStatic">
<tr>
<td{if check_permission('mediapool_add')} colspan="2"{/if}>
<div class="pr12"><input type="text" name="bFileName" size="20" style="width:100%;" readonly="readonly" /></div>
</td>
<td>
<input type="button" class="basicBtn" onClick="submitTheForm();" value="{if $smarty.request.type != 'directory'}{#MAIN_MP_FILE_INSERT#}{else}{#MAIN_MP_DIR_INSERT#}{/if}" />
<div class="pr12"><input type="text" name="bDirName" id="DirName" size="20" style="width:100%;" readonly="readonly" /></div>
</td>
<td width="5%" nowrap="nowrap">
<input type="button" class="basicBtn" onClick="NewFolder();" value="{#MAIN_MP_CREATE_FOLDER#}" />&nbsp;
</td>
{if check_permission('mediapool_add')}
<td width="5%" nowrap="nowrap">
<a class="button basicBtn openDialog" data-modal="true" data-height="455" href="index.php?do=browser&type={$smarty.request.type|escape}&target={$smarty.request.target|escape}&action=upload&dir=" data-title="{#MAIN_MP_UPLOAD_FILE#}">{#MAIN_MP_UPLOAD_FILE#}</a>
</td>
{/if}
</tr>
<tr valign="top">
<td{if check_permission('mediapool_add')} colspan="3"{else} colspan="2"{/if}>
<div style="border:1px solid #d4d4d4; overflow:hidden; height:100%; width:100%">
<iframe id="mainframe" frameborder="0" name="zf" id="zf" width="100%" height="100%" scrolling="Yes" src="index.php?onlycontent=1&do=browser&type={$smarty.request.type|escape}&action=list&dir={$dir}&target={$smarty.request.target|escape}"></iframe>
</div>
</td>
</tr>
{/if}
</table>
</form>
{if $smarty.request.type!=''}
<tr>
<td{if check_permission('mediapool_add')} colspan="2"{/if}>
<div class="pr12"><input type="text" name="bFileName" size="20" style="width:100%;" readonly="readonly" /></div>
</td>
<td>
<input type="button" class="basicBtn" onClick="submitTheForm();" value="{if $smarty.request.type != 'directory'}{#MAIN_MP_FILE_INSERT#}{else}{#MAIN_MP_DIR_INSERT#}{/if}" />
</td>
</tr>
{/if}
</table>
</form>
</div>
</div>
@ -130,12 +131,25 @@
function getUrlParam(paramName)
{ldelim}
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
var match = window.location.search.match(reParam) ;
let reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
let match = window.location.search.match(reParam) ;
return (match && match.length > 1) ? match[1] : '' ;
{rdelim}
function getImgPreview (url)
{ldelim}
let parts = url.split('/');
let fileName = parts.pop();
let fileExt = fileName.split('.').pop();
let thumb = th_folder + '/' + fileName.substr(0, fileName.lastIndexOf(".")) + '-t128x128.' + fileExt;
parts.push(thumb);
return parts.join('/');
{rdelim}
function submitTheForm() {ldelim}
if (document.bForm.bFileName.value == '' && ('{$target}' != 'dir' && '{$target}' != 'directory' && '{$target}' != 'cascad')) {ldelim}
alert('{#MAIN_MP_PLEASE_SELECT#}');
@ -159,14 +173,15 @@
window.opener.document.getElementById('{$smarty.request.id|escape}').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
{elseif $target=='img_feld' || $target_img=='img_feld'}
let imgSource = '/' + '{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
window.opener.document.getElementById('img_feld__{$target_id}').value = '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
window.opener.document.getElementById('_img_feld__{$target_id}').src = '../index.php?mode=f&width=128&height=128&thumb=/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
window.opener.$('.preview__{$target_id}').attr("href", '../index.php?mode=f&width=128&height=128&thumb=/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
window.opener.document.getElementById('_img_feld__{$target_id}').src = getImgPreview(imgSource);
window.opener.$('.preview__{$target_id}').attr("href", getImgPreview(imgSource));
{elseif $target!='' && $target_id!='' && $target_id!=null}
{if $target=='image'}
window.opener.$('#preview__{$target_id}').attr('src', '../index.php?mode=f&width=128&height=128&thumb=/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
let imgSource = '/' + '{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value;
window.opener.$('#preview__{$target_id}').attr('src', getImgPreview(imgSource));
window.opener.$('.preview__{$target_id}').attr('href', '/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
window.opener.$('#{$target}__{$target_id}').val('/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
{/if}

2
admin/templates/browser/browser_upload.tpl

@ -1,5 +1,5 @@
<script>
var path_upload = "{$smarty.request.dir|escape}";
let path_upload = "{$smarty.request.dir|escape}";
</script>
<!-- Wrapper -->

45
fields/image_mega/field.php

@ -64,16 +64,12 @@
$image[$k]['url'] = $image_item[0];
$image[$k]['thumb'] = ($image_item[0] != '')
? make_thumbnail(array('size' => 'f128x128', 'link' => $image_item[0]))
? make_thumbnail(['size' => 't128x128', 'link' => $image_item[0]])
: $img_pixel;
$image[$k]['title'] = (isset($image_item[1]))
? $image_item[1]
: '';
$image[$k]['title'] = $image_item[1] ?? '';
$image[$k]['description'] = (isset($image_item[2]))
? $image_item[2]
: '';
$image[$k]['description'] = $image_item[2] ?? '';
$image[$k]['link'] = (isset($image_item[3]))
? htmlspecialchars($image_item[3], ENT_QUOTES)
@ -148,9 +144,9 @@
$items = (isset($field_value))
? unserialize($field_value)
: array();
: [];
$res = array();
$res = [];
if ($items != false)
{
@ -252,7 +248,7 @@
{
$image_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i',
function($data) use($field_data)
static function($data) use($field_data)
{
return $field_data[(int)$data[1]];
},
@ -354,10 +350,10 @@
case 'upload':
$error = false;
$search = array();
$replace = array();
$search = [];
$replace = [];
$files_unput = 'mega_files' . '_' . $_REQUEST['field_id'] . '_' . $_REQUEST['doc_id'];
$files_input = 'mega_files' . '_' . $_REQUEST['field_id'] . '_' . $_REQUEST['doc_id'];
$search[] = '%d';
$replace[] = date('d');
@ -401,15 +397,16 @@
$dir_abs = BASE_DIR . $dir;
if (! is_dir($dir_abs))
mkdir($dir_abs, 0777, true);
if (!is_dir($dir_abs) && !mkdir($dir_abs, 0777, true) && !is_dir($dir_abs)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir_abs));
}
$new_files = array();
$thumbs = array();
$new_files = [];
$thumbs = [];
foreach ($_FILES[$files_unput]['name'] as $name => $value)
foreach ($_FILES[$files_input]['name'] as $name => $value)
{
$filename = strtolower(stripslashes(prepare_url($_FILES[$files_unput]['name'][$name])));
$filename = strtolower(stripslashes(prepare_url($_FILES[$files_input]['name'][$name])));
$ext = getExtension($filename);
$ext = strtolower($ext);
@ -421,11 +418,11 @@
$filename = rand(1000, 9999) . '_' . $filename;
}
if (@move_uploaded_file($_FILES[$files_unput]['tmp_name'][$name], $dir_abs . $filename))
if (@move_uploaded_file($_FILES[$files_input]['tmp_name'][$name], $dir_abs . $filename))
{
$new_files[] = $filename;
$thumbs[] = make_thumbnail(array('link' => $dir . $filename, 'size' => 'f128x128'));
$thumbs[] = make_thumbnail(array('link' => $dir . $filename, 'size' => 't128x128'));
if ((bool)$watermark)
{
@ -445,7 +442,7 @@
else
{
$error = true;
@unlink($_FILES[$files_unput]['tmp_name'][$name]);
@unlink($_FILES[$files_input]['tmp_name'][$name]);
}
}
@ -455,7 +452,7 @@
'files' => $new_files,
'thumbs' => $thumbs,
'dir' => $dir,
'respons' => 'succes',
'respons' => 'success',
'message' => $AVE_Template->get_config_vars('resp_s_m'),
'header' => $AVE_Template->get_config_vars('resp_s_h'),
'theme' => 'accept'
@ -476,6 +473,6 @@
exit;
}
return ($res ? $res : $field_value);
return $res ?: $field_value;
}
?>

65
fields/image_mega/js/field.js

@ -1,4 +1,4 @@
var Mega = {
let Mega = {
init: false,
@ -27,17 +27,19 @@ var Mega = {
},
mega_maxid: function(id, doc) {
var maxid = 1;
let maxid = 1;
$('#mega_' + doc + '_' + id).children('.mega_sortable').children('.mega_item').each(function() {
maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1);
});
return maxid;
},
mega_del_item: function() {
$('.mega_item .delete').on('click', function(event) {
event.preventDefault();
var id = $(this).attr('data-id');
let id = $(this).attr('data-id');
jConfirm(
mega_del_conf,
mega_del_head,
@ -53,8 +55,11 @@ var Mega = {
mega_del_all_item: function() {
$('.mega_del_all').on('click', function(event) {
event.preventDefault();
var c_id = $(this).parent().parent().parent('.mega').attr("data-id");
var d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
let c_id = $(this).parent().parent().parent('.mega').attr("data-id");
let d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
let empty_input = '<input id="empty' + d_id + '_' + c_id + '" type="hidden" value="" name="feld[' + c_id + ']">';
jConfirm(
mega_del_all_c,
mega_del_all_h,
@ -63,6 +68,7 @@ var Mega = {
$('#mega_' + d_id + '_' + c_id).children('.mega_sortable').children('.mega_item').each(function() {
$(this).remove();
});
$('#mega_' + d_id + '_' + c_id).append(empty_input);
}
}
);
@ -72,7 +78,9 @@ var Mega = {
megae_upload_files: function() {
$('.mega_upload').on('change', function(event) {
var mega_input = $(this);
let mega_input = $(this);
let iid;
event.preventDefault();
@ -80,8 +88,8 @@ var Mega = {
return false;
}
var files_input = this.files.length;
var max_files = mega_input.attr("data-max-files");
let files_input = this.files.length;
let max_files = mega_input.attr("data-max-files");
if (files_input > max_files) {
$.jGrowl(mega_max_f_t, {
@ -94,9 +102,9 @@ var Mega = {
return false;
}
var c_id = $(this).parent('.mega').attr("data-id");
var d_id = $(this).parent('.mega').attr("data-doc");
var r_id = $(this).parent('.mega').attr("data-rubric");
let c_id = $(this).parent('.mega').attr("data-id");
let d_id = $(this).parent('.mega').attr("data-doc");
let r_id = $(this).parent('.mega').attr("data-rubric");
$('#formDoc').ajaxSubmit({
url: 'index.php?do=fields',
@ -112,14 +120,14 @@ var Mega = {
},
dataType: "JSON",
success: function(data) {
if (data['respons'] == 'succes') {
for (var p = 0, max = data.files.length; p < max; p++) {
if (data['respons'] == 'success') {
for (let p = 0, max = data.files.length; p < max; p++) {
iid = Mega.mega_maxid(c_id, d_id);
var field_value = data['dir'] + data.files[p];
var img_path = data.thumbs[p];
let field_value = data['dir'] + data.files[p];
let img_path = data.thumbs[p];
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').prepend(
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').append(
'<div class="mega_item ui-state-default" id="mega_image_' + c_id + '_' + d_id + '_' + iid + '" data-id="' + iid + '" data-doc="' + d_id + '">' +
'<div class="header grey_bg"></div>' +
'<a class="topDir icon_sprite ico_photo view fancy preview__' + c_id + '_' + d_id + '_' + iid + '" href="' + field_value + '" title="' + mega_look + '"></a>' +
@ -145,11 +153,14 @@ var Mega = {
'</div>'
);
$('#empty' + d_id + '_' + c_id ).remove();
$.alerts._overlay('hide');
Mega.mega_update();
}
}
$.jGrowl(data['message'], {
header: data['header'],
theme: data['theme']
@ -166,8 +177,10 @@ var Mega = {
mega_click_upload: function() {
$('.mega_upload_local').on('click', function(event) {
event.preventDefault();
var c_id = $(this).parent().parent().parent('.mega').attr("data-id");
var d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
let c_id = $(this).parent().parent().parent('.mega').attr("data-id");
let d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
$('.mega_upload_field_' + c_id + '_' + d_id).trigger('click');
});
},
@ -176,9 +189,9 @@ var Mega = {
$('.mega_add_single').on('click', function(event) {
event.preventDefault();
var c_id = $(this).parent().parent().parent('.mega').attr("data-id");
var d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
var iid = Mega.mega_maxid(c_id, d_id);
let c_id = $(this).parent().parent().parent('.mega').attr("data-id");
let d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
let iid = Mega.mega_maxid(c_id, d_id);
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').prepend(
'<div class="mega_item ui-state-default" id="mega_image_' + c_id + '_' + d_id + '_' + iid + '" data-id="' + iid + '" data-doc="' + d_id + '">' +
@ -207,6 +220,8 @@ var Mega = {
browse_uploads('image__' + c_id + '_' + d_id + '_' + iid + '');
$('#empty' + d_id + '_' + c_id ).remove();
Mega.mega_update();
});
},
@ -244,10 +259,10 @@ $(document).ready(function() {
dataType: "JSON",
success: function(data) {
$.alerts._overlay('hide');
for (var p = 0, max = data.respons.length; p < max; p++) {
var iid = Mega.mega_maxid(c_id, d_id);
var field_value = dir + data.respons[p];
var img_path = '../index.php?thumb=' + field_value + '&mode=f&width=128&height=128';
for (let p = 0, max = data.respons.length; p < max; p++) {
let iid = Mega.mega_maxid(c_id, d_id);
let field_value = dir + data.respons[p];
let img_path = '../index.php?thumb=' + field_value + '&mode=f&width=128&height=128';
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').prepend(
'<div class="mega_item ui-state-default" id="mega_image_' + c_id + '_' + d_id + '_' + iid + '" data-id="' + iid + '" data-doc="' + d_id + '">' +

Loading…
Cancel
Save