Browse Source

Fixed images fields

pull/3/head
MadD3n 2 years ago
parent
commit
e30344ca6f
  1. 4
      README.md
  2. 4
      admin/templates/browser/browser.tpl
  3. 43
      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 сервера: * ПО WEB сервера:
* Apache >= 1.3 * Apache >= 1.3
* Nginx >= 1.6.2 * Nginx >= 1.6.2
* PHP >= 5.6.x (zlib, cURL, mbString, JSON) * PHP >= 5.6.x (!!!Не поддерживается!!!)
* PHP >= 7.x ... <= 7.4.x * PHP >= 7.x ... <= 7.4.x (zlib, cURL, mbString, JSON)
* MySQL >= 5.6.x ... <= 5.7.x * MySQL >= 5.6.x ... <= 5.7.x
## Установка ## Установка

4
admin/templates/browser/browser.tpl

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

43
admin/templates/browser/browser_2frames.tpl

@ -31,11 +31,12 @@
<!-- JS Scripts --> <!-- JS Scripts -->
<script type="text/javascript"> <script type="text/javascript">
var ave_path = "{$ABS_PATH}"; let ave_path = "{$ABS_PATH}";
var ave_theme = "{$smarty.const.DEFAULT_THEME_FOLDER}"; let ave_theme = "{$smarty.const.DEFAULT_THEME_FOLDER}";
var ave_admintpl = "{$tpl_dir}"; let ave_admintpl = "{$tpl_dir}";
let th_folder = "{$smarty.const.THUMBNAIL_DIR}";
var sess = '{$sess}'; let sess = '{$sess}';
$(document).ready(function(){ldelim} $(document).ready(function(){ldelim}
@ -46,8 +47,8 @@
); );
{literal} {literal}
var mainframe = $('#mainframe'); let mainframe = $('#mainframe');
var height = $("body").height(); let height = $("body").height();
mainframe.css({"height": height-280}); mainframe.css({"height": height-280});
$(window).bind( $(window).bind(
@ -55,8 +56,8 @@
function() function()
{ {
$(window).resize(function() { $(window).resize(function() {
var mainframe = $('#mainframe'); let mainframe = $('#mainframe');
var height = $("body").height(); let height = $("body").height();
mainframe.css({"height": height-280}); mainframe.css({"height": height-280});
}); });
} }
@ -130,12 +131,25 @@
function getUrlParam(paramName) function getUrlParam(paramName)
{ldelim} {ldelim}
var reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ; let reParam = new RegExp('(?:[\?&]|&amp;)' + paramName + '=([^&]+)', 'i') ;
var match = window.location.search.match(reParam) ; let match = window.location.search.match(reParam) ;
return (match && match.length > 1) ? match[1] : '' ; return (match && match.length > 1) ? match[1] : '' ;
{rdelim} {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} function submitTheForm() {ldelim}
if (document.bForm.bFileName.value == '' && ('{$target}' != 'dir' && '{$target}' != 'directory' && '{$target}' != 'cascad')) {ldelim} if (document.bForm.bFileName.value == '' && ('{$target}' != 'dir' && '{$target}' != 'directory' && '{$target}' != 'cascad')) {ldelim}
alert('{#MAIN_MP_PLEASE_SELECT#}'); 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; 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'} {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}').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.document.getElementById('_img_feld__{$target_id}').src = getImgPreview(imgSource);
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.$('.preview__{$target_id}').attr("href", getImgPreview(imgSource));
{elseif $target!='' && $target_id!='' && $target_id!=null} {elseif $target!='' && $target_id!='' && $target_id!=null}
{if $target=='image'} {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.$('.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); window.opener.$('#{$target}__{$target_id}').val('/{$mediapath}' + document.bForm.bDirName.value + document.bForm.bFileName.value);
{/if} {/if}

2
admin/templates/browser/browser_upload.tpl

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

45
fields/image_mega/field.php

@ -64,16 +64,12 @@
$image[$k]['url'] = $image_item[0]; $image[$k]['url'] = $image_item[0];
$image[$k]['thumb'] = ($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; : $img_pixel;
$image[$k]['title'] = (isset($image_item[1])) $image[$k]['title'] = $image_item[1] ?? '';
? $image_item[1]
: '';
$image[$k]['description'] = (isset($image_item[2])) $image[$k]['description'] = $image_item[2] ?? '';
? $image_item[2]
: '';
$image[$k]['link'] = (isset($image_item[3])) $image[$k]['link'] = (isset($image_item[3]))
? htmlspecialchars($image_item[3], ENT_QUOTES) ? htmlspecialchars($image_item[3], ENT_QUOTES)
@ -148,9 +144,9 @@
$items = (isset($field_value)) $items = (isset($field_value))
? unserialize($field_value) ? unserialize($field_value)
: array(); : [];
$res = array(); $res = [];
if ($items != false) if ($items != false)
{ {
@ -252,7 +248,7 @@
{ {
$image_item = preg_replace_callback( $image_item = preg_replace_callback(
'/\[tag:parametr:(\d+)\]/i', '/\[tag:parametr:(\d+)\]/i',
function($data) use($field_data) static function($data) use($field_data)
{ {
return $field_data[(int)$data[1]]; return $field_data[(int)$data[1]];
}, },
@ -354,10 +350,10 @@
case 'upload': case 'upload':
$error = false; $error = false;
$search = array(); $search = [];
$replace = array(); $replace = [];
$files_unput = 'mega_files' . '_' . $_REQUEST['field_id'] . '_' . $_REQUEST['doc_id']; $files_input = 'mega_files' . '_' . $_REQUEST['field_id'] . '_' . $_REQUEST['doc_id'];
$search[] = '%d'; $search[] = '%d';
$replace[] = date('d'); $replace[] = date('d');
@ -401,15 +397,16 @@
$dir_abs = BASE_DIR . $dir; $dir_abs = BASE_DIR . $dir;
if (! is_dir($dir_abs)) if (!is_dir($dir_abs) && !mkdir($dir_abs, 0777, true) && !is_dir($dir_abs)) {
mkdir($dir_abs, 0777, true); throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir_abs));
}
$new_files = array(); $new_files = [];
$thumbs = array(); $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 = getExtension($filename);
$ext = strtolower($ext); $ext = strtolower($ext);
@ -421,11 +418,11 @@
$filename = rand(1000, 9999) . '_' . $filename; $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; $new_files[] = $filename;
$thumbs[] = make_thumbnail(array('link' => $dir . $filename, 'size' => 'f128x128')); $thumbs[] = make_thumbnail(array('link' => $dir . $filename, 'size' => 't128x128'));
if ((bool)$watermark) if ((bool)$watermark)
{ {
@ -445,7 +442,7 @@
else else
{ {
$error = true; $error = true;
@unlink($_FILES[$files_unput]['tmp_name'][$name]); @unlink($_FILES[$files_input]['tmp_name'][$name]);
} }
} }
@ -455,7 +452,7 @@
'files' => $new_files, 'files' => $new_files,
'thumbs' => $thumbs, 'thumbs' => $thumbs,
'dir' => $dir, 'dir' => $dir,
'respons' => 'succes', 'respons' => 'success',
'message' => $AVE_Template->get_config_vars('resp_s_m'), 'message' => $AVE_Template->get_config_vars('resp_s_m'),
'header' => $AVE_Template->get_config_vars('resp_s_h'), 'header' => $AVE_Template->get_config_vars('resp_s_h'),
'theme' => 'accept' 'theme' => 'accept'
@ -476,6 +473,6 @@
exit; 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, init: false,
@ -27,17 +27,19 @@ var Mega = {
}, },
mega_maxid: function(id, doc) { mega_maxid: function(id, doc) {
var maxid = 1; let maxid = 1;
$('#mega_' + doc + '_' + id).children('.mega_sortable').children('.mega_item').each(function() { $('#mega_' + doc + '_' + id).children('.mega_sortable').children('.mega_item').each(function() {
maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1); maxid = Math.max(maxid, parseInt($(this).attr("data-id")) + 1);
}); });
return maxid; return maxid;
}, },
mega_del_item: function() { mega_del_item: function() {
$('.mega_item .delete').on('click', function(event) { $('.mega_item .delete').on('click', function(event) {
event.preventDefault(); event.preventDefault();
var id = $(this).attr('data-id'); let id = $(this).attr('data-id');
jConfirm( jConfirm(
mega_del_conf, mega_del_conf,
mega_del_head, mega_del_head,
@ -53,8 +55,11 @@ var Mega = {
mega_del_all_item: function() { mega_del_all_item: function() {
$('.mega_del_all').on('click', function(event) { $('.mega_del_all').on('click', function(event) {
event.preventDefault(); event.preventDefault();
var c_id = $(this).parent().parent().parent('.mega').attr("data-id"); let c_id = $(this).parent().parent().parent('.mega').attr("data-id");
var d_id = $(this).parent().parent().parent('.mega').attr("data-doc"); 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( jConfirm(
mega_del_all_c, mega_del_all_c,
mega_del_all_h, mega_del_all_h,
@ -63,6 +68,7 @@ var Mega = {
$('#mega_' + d_id + '_' + c_id).children('.mega_sortable').children('.mega_item').each(function() { $('#mega_' + d_id + '_' + c_id).children('.mega_sortable').children('.mega_item').each(function() {
$(this).remove(); $(this).remove();
}); });
$('#mega_' + d_id + '_' + c_id).append(empty_input);
} }
} }
); );
@ -72,7 +78,9 @@ var Mega = {
megae_upload_files: function() { megae_upload_files: function() {
$('.mega_upload').on('change', function(event) { $('.mega_upload').on('change', function(event) {
var mega_input = $(this); let mega_input = $(this);
let iid;
event.preventDefault(); event.preventDefault();
@ -80,8 +88,8 @@ var Mega = {
return false; return false;
} }
var files_input = this.files.length; let files_input = this.files.length;
var max_files = mega_input.attr("data-max-files"); let max_files = mega_input.attr("data-max-files");
if (files_input > max_files) { if (files_input > max_files) {
$.jGrowl(mega_max_f_t, { $.jGrowl(mega_max_f_t, {
@ -94,9 +102,9 @@ var Mega = {
return false; return false;
} }
var c_id = $(this).parent('.mega').attr("data-id"); let c_id = $(this).parent('.mega').attr("data-id");
var d_id = $(this).parent('.mega').attr("data-doc"); let d_id = $(this).parent('.mega').attr("data-doc");
var r_id = $(this).parent('.mega').attr("data-rubric"); let r_id = $(this).parent('.mega').attr("data-rubric");
$('#formDoc').ajaxSubmit({ $('#formDoc').ajaxSubmit({
url: 'index.php?do=fields', url: 'index.php?do=fields',
@ -112,14 +120,14 @@ var Mega = {
}, },
dataType: "JSON", dataType: "JSON",
success: function(data) { success: function(data) {
if (data['respons'] == 'succes') { if (data['respons'] == 'success') {
for (var p = 0, max = data.files.length; p < max; p++) { for (let p = 0, max = data.files.length; p < max; p++) {
iid = Mega.mega_maxid(c_id, d_id); iid = Mega.mega_maxid(c_id, d_id);
var field_value = data['dir'] + data.files[p]; let field_value = data['dir'] + data.files[p];
var img_path = data.thumbs[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="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>' + '<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>' + '<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>' '</div>'
); );
$('#empty' + d_id + '_' + c_id ).remove();
$.alerts._overlay('hide'); $.alerts._overlay('hide');
Mega.mega_update(); Mega.mega_update();
} }
} }
$.jGrowl(data['message'], { $.jGrowl(data['message'], {
header: data['header'], header: data['header'],
theme: data['theme'] theme: data['theme']
@ -166,8 +177,10 @@ var Mega = {
mega_click_upload: function() { mega_click_upload: function() {
$('.mega_upload_local').on('click', function(event) { $('.mega_upload_local').on('click', function(event) {
event.preventDefault(); 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'); $('.mega_upload_field_' + c_id + '_' + d_id).trigger('click');
}); });
}, },
@ -176,9 +189,9 @@ var Mega = {
$('.mega_add_single').on('click', function(event) { $('.mega_add_single').on('click', function(event) {
event.preventDefault(); event.preventDefault();
var c_id = $(this).parent().parent().parent('.mega').attr("data-id"); let c_id = $(this).parent().parent().parent('.mega').attr("data-id");
var d_id = $(this).parent().parent().parent('.mega').attr("data-doc"); let d_id = $(this).parent().parent().parent('.mega').attr("data-doc");
var iid = Mega.mega_maxid(c_id, d_id); let iid = Mega.mega_maxid(c_id, d_id);
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').prepend( $('#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 + '">' + '<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 + ''); browse_uploads('image__' + c_id + '_' + d_id + '_' + iid + '');
$('#empty' + d_id + '_' + c_id ).remove();
Mega.mega_update(); Mega.mega_update();
}); });
}, },
@ -244,10 +259,10 @@ $(document).ready(function() {
dataType: "JSON", dataType: "JSON",
success: function(data) { success: function(data) {
$.alerts._overlay('hide'); $.alerts._overlay('hide');
for (var p = 0, max = data.respons.length; p < max; p++) { for (let p = 0, max = data.respons.length; p < max; p++) {
var iid = Mega.mega_maxid(c_id, d_id); let iid = Mega.mega_maxid(c_id, d_id);
var field_value = dir + data.respons[p]; let field_value = dir + data.respons[p];
var img_path = '../index.php?thumb=' + field_value + '&mode=f&width=128&height=128'; let img_path = '../index.php?thumb=' + field_value + '&mode=f&width=128&height=128';
$('#mega_' + d_id + '_' + c_id + ' > .mega_sortable:last').prepend( $('#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 + '">' + '<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