Articles: finish admin refactor, uploads hardening, and attachment sorting (0.262)

This commit is contained in:
2026-02-13 09:00:24 +01:00
parent 42e4396064
commit 5354f97baa
31 changed files with 1951 additions and 1512 deletions

View File

@@ -0,0 +1,583 @@
<?php
$article = is_array($this->article ?? null) ? $this->article : [];
$articleId = (int)($article['id'] ?? 0);
$userId = (int)($this->user['id'] ?? 0);
$imagesCount = is_array($article['images'] ?? null) ? count($article['images']) : 0;
$filesCount = is_array($article['files'] ?? null) ? count($article['files']) : 0;
$imageMaxPx = 1920;
if (isset($this->settings['image_px']) && (int)$this->settings['image_px'] > 0) {
$imageMaxPx = (int)$this->settings['image_px'];
} elseif (isset($GLOBALS['settings']['image_px']) && (int)$GLOBALS['settings']['image_px'] > 0) {
$imageMaxPx = (int)$GLOBALS['settings']['image_px'];
}
$uploadToken = bin2hex(random_bytes(24));
if (!isset($_SESSION['upload_tokens']) || !is_array($_SESSION['upload_tokens'])) {
$_SESSION['upload_tokens'] = [];
}
$_SESSION['upload_tokens'][$uploadToken] = [
'user_id' => $userId,
'expires' => time() + 60 * 20,
];
$cookiePages = [];
$cookieMenus = [];
if (!empty($_COOKIE['cookie_pages'])) {
$decoded = @unserialize($_COOKIE['cookie_pages']);
if (is_array($decoded)) {
$cookiePages = $decoded;
}
}
if (!empty($_COOKIE['cookie_menus'])) {
$decoded = @unserialize($_COOKIE['cookie_menus']);
if (is_array($decoded)) {
$cookieMenus = $decoded;
}
}
?>
<link type="text/css" rel="stylesheet" href="/libraries/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" />
<link type="text/css" rel="stylesheet" href="/libraries/grid/plugins/impromptu/jquery-impromptu.css" />
<script type="text/javascript" src="/libraries/grid/plugins/impromptu/jquery-impromptu.js"></script>
<script type="text/javascript" src="/libraries/jquery/sortable/sortable.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html4.js"></script>
<script type="text/javascript" src="/libraries/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/libraries/plupload/i18n/pl.js"></script>
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>
<style type="text/css">
.jconfirm.table-list-confirm-dialog .jconfirm-row {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.jconfirm.table-list-confirm-dialog .jconfirm-box-container {
width: 100%;
max-width: 560px;
padding-left: 12px;
padding-right: 12px;
margin: 0 auto;
}
.jconfirm.table-list-confirm-dialog .jconfirm-box {
width: 100% !important;
}
</style>
<script type="text/javascript">
var images_count = <?= (int)$imagesCount ?>;
var files_count = <?= (int)$filesCount ?>;
var article_id = <?= (int)$articleId ?>;
$(function() {
function confirmDialog(message, onConfirm, okLabel) {
if (typeof $.confirm === 'function') {
$.confirm({
title: 'Potwierdzenie',
content: String(message),
type: 'red',
boxWidth: '560px',
useBootstrap: false,
animation: 'scale',
closeAnimation: 'scale',
backgroundDismissAnimation: 'shake',
container: 'body',
theme: 'modern',
columnClass: '',
typeAnimated: true,
lazyOpen: false,
draggable: false,
closeIcon: true,
containerFluid: true,
escapeKey: true,
backgroundDismiss: true,
animationBounce: 1.1,
watchInterval: 100,
offsetTop: 0,
offsetBottom: 0,
customClass: 'table-list-confirm-dialog',
buttons: {
cancel: {
text: 'Anuluj',
btnClass: 'btn-default'
},
confirm: {
text: okLabel || 'Usun',
btnClass: 'btn-danger',
action: function() {
if (typeof onConfirm === 'function') {
onConfirm();
}
}
}
}
});
return;
}
if (window.confirm(message) && typeof onConfirm === 'function') {
onConfirm();
}
}
function ensureGalleryOrderInput() {
var $form = $('#fg-article-edit');
if (!$form.length) {
return null;
}
var $input = $form.find('input[name="gallery_order"]');
if (!$input.length) {
$input = $('<input>', {
type: 'hidden',
name: 'gallery_order',
id: 'gallery_order'
});
$form.append($input);
}
return $input;
}
function ensureFilesOrderInput() {
var $form = $('#fg-article-edit');
if (!$form.length) {
return null;
}
var $input = $form.find('input[name="files_order"]');
if (!$input.length) {
$input = $('<input>', {
type: 'hidden',
name: 'files_order',
id: 'files_order'
});
$form.append($input);
}
return $input;
}
function buildGalleryOrder() {
var order = [];
$('#images-list li').each(function() {
var imageId = $(this).find('a.article_image_delete').attr('image-id');
if (imageId) {
order.push(imageId);
}
});
return order.join(';');
}
function refreshGalleryOrderInput() {
var $input = ensureGalleryOrderInput();
if ($input) {
$input.val(buildGalleryOrder());
}
}
function buildFilesOrder() {
var order = [];
$('#files-list li').each(function() {
var fileId = $(this).find('.article_file_edit').attr('file_id');
if (fileId) {
order.push(fileId);
}
});
return order.join(';');
}
function refreshFilesOrderInput() {
var $input = ensureFilesOrderInput();
if ($input) {
$input.val(buildFilesOrder());
}
}
ensureGalleryOrderInput();
refreshGalleryOrderInput();
ensureFilesOrderInput();
refreshFilesOrderInput();
var observer = lozad();
observer.observe();
var imageList = document.getElementById('images-list');
if (imageList) {
Sortable.create(imageList, {
onEnd: function() {
var order = '';
$('#images-list li').each(function() {
if (order !== '') {
order += ';';
}
order += $(this).children('a').attr('image-id');
});
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/gallery_order_save/',
data: {
article_id: article_id,
order: order
},
beforeSend: function() {
$('#overlay').show();
},
success: function(data) {
$('#overlay').hide();
var response = jQuery.parseJSON(data);
if (response.status !== 'ok') {
create_error(response.msg);
}
}
});
refreshGalleryOrderInput();
}
});
}
var filesList = document.getElementById('files-list');
if (filesList) {
Sortable.create(filesList, {
onEnd: function() {
var order = buildFilesOrder();
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/files_order_save/',
data: {
article_id: article_id,
order: order
},
beforeSend: function() {
$('#overlay').show();
},
success: function(data) {
$('#overlay').hide();
var response = jQuery.parseJSON(data);
if (response.status !== 'ok') {
create_error(response.msg);
}
}
});
refreshFilesOrderInput();
}
});
}
$('#images-uploader').pluploadQueue({
multipart_params: {
upload_token: '<?= htmlspecialchars($uploadToken, ENT_QUOTES, 'UTF-8') ?>',
article_id: article_id
},
runtimes: 'html5,flash,html4',
init: {
Refresh: function() {
$('.plupload_buttons').css('display', 'inline');
$('.plupload_upload_status').css('display', 'inline');
$('.plupload_start').addClass('plupload_disabled');
$('.plupload_start').removeClass('plupload_disabled');
},
UploadComplete: function() {
$('.plupload_buttons').css('display', 'inline');
$('.plupload_upload_status').css('display', 'inline');
$('.plupload_start').addClass('plupload_disabled');
$('.plupload_start').removeClass('plupload_disabled');
},
FileUploaded: function(up, file, response) {
var data = jQuery.parseJSON(response.response);
$('#images-list').append(
'<li id="image-' + data.image_id + '">' +
'<img class="article-image lozad" data-src="/libraries/thumb.php?img=' + data.data_link + '&w=300&h=300">' +
'<a href="#" class="input-group-addon btn btn-danger article_image_delete" image-id="' + data.image_id + '">' +
'<i class="fa fa-trash"></i>' +
'</a>' +
'<input type="text" class="form-control image-alt" value="" image-id="' + data.image_id + '" placeholder="atrybut alt...">' +
'</li>'
);
images_count++;
observer.observe();
refreshGalleryOrderInput();
$('html, body').animate({
scrollTop: $('#images-uploader').offset().top
}, 1);
}
},
url: '/libraries/plupload/upload-articles-images.php',
chunk_size: '1mb',
max_file_size: '20mb',
unique_names: false,
resize: {
width: <?= (int)$imageMaxPx ?>,
height: <?= (int)$imageMaxPx ?>,
quality: 95
},
filters: [
{ title: 'Obrazki', extensions: 'jpg,gif,png,bmp,jpeg' }
],
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
});
$('#files-uploader').pluploadQueue({
multipart_params: {
upload_token: '<?= htmlspecialchars($uploadToken, ENT_QUOTES, 'UTF-8') ?>'
},
runtimes: 'html5,flash,html4',
init: {
Refresh: function() {
$('.plupload_buttons').css('display', 'inline');
$('.plupload_upload_status').css('display', 'inline');
$('.plupload_start').addClass('plupload_disabled');
$('.plupload_start').removeClass('plupload_disabled');
},
FileUploaded: function(up, file, response) {
var data = jQuery.parseJSON(response.response);
$('#files-list').append(
'<li id="file-' + data.file_id + '">' +
'<div class="input-group">' +
'<input type="text" class="form-control article_file_edit" file_id="' + data.file_id + '" value="' + data.file_name + '" />' +
'<a href="#" class="input-group-addon btn btn-info article_file_delete" file_id="' + data.file_id + '">' +
'<i class="fa fa-trash"></i>' +
'</a>' +
'</div>' +
'</li>'
);
files_count++;
refreshFilesOrderInput();
}
},
url: '/libraries/plupload/upload-articles-files.php',
chunk_size: '1mb',
max_file_size: '50mb',
unique_names: false,
filters: [
{ title: 'Wszystkie pliki', extensions: '*' }
],
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
});
$('ol.sortable').nestedSortable({
forcePlaceholderSize: true,
handle: 'div',
helper: 'clone',
items: 'li',
opacity: .6,
placeholder: 'placeholder',
revert: 250,
tabSize: 25,
tolerance: 'pointer',
toleranceElement: '> div',
maxLevels: 3,
isTree: true,
expandOnHover: 700,
isAllowed: function() {
return false;
}
});
$('.disclose').on('click', function() {
$(this).closest('li').toggleClass('sort-collapsed').toggleClass('sort-expanded');
});
$('.disclose').mousedown(function(e) {
if (e.which !== 1) {
return;
}
if ($(this).parent('div').hasClass('content_menu')) {
var menu_id = $(this).parent('div').parent('li').attr('menu');
$.ajax({
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data: {
a: 'cookie_menus',
menu_id: menu_id
}
});
} else {
var page_id = $(this).parent('div').parent('li').attr('id');
$.ajax({
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data: {
a: 'cookie_pages',
page_id: page_id
}
});
}
});
<?php foreach ($cookiePages as $key => $val): ?>
<?php if ($val): ?>$('.<?= htmlspecialchars((string)$key, ENT_QUOTES, 'UTF-8') ?>').children('div').children('span.disclose').click();<?php endif; ?>
<?php endforeach; ?>
<?php foreach ($cookieMenus as $key => $val): ?>
<?php if ($val): ?>$('.menu_<?= (int)$key ?>').children('div').children('span.disclose').click();<?php endif; ?>
<?php endforeach; ?>
$('body').on('change', '.image-alt', function() {
var image_alt = $(this).val();
var image_id = $(this).attr('image-id');
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/article_image_alt_change/',
data: {
image_id: image_id,
image_alt: image_alt
},
beforeSend: function() {
$('#overlay').show();
},
success: function(data) {
$('#overlay').hide();
var response = jQuery.parseJSON(data);
if (response.status !== 'ok') {
create_error(response.msg);
}
}
});
});
$('body').on('change', '.article_file_edit', function() {
var file_name = $(this).val();
var file_id = $(this).attr('file_id');
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/article_file_name_change/',
data: {
file_id: file_id,
file_name: file_name
},
beforeSend: function() {
$('#overlay').show();
},
success: function(data) {
$('#overlay').hide();
var response = jQuery.parseJSON(data);
if (response.status !== 'ok') {
create_error(response.msg);
}
}
});
});
$('body').on('click', '.article_file_delete', function() {
$(this).blur();
var file_id = $(this).attr('file_id');
confirmDialog('Na pewno chcesz usunac wybrany plik?', function() {
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/article_file_delete/',
data: {
file_id: file_id
},
beforeSend: function() {
$('#file-' + file_id).children('input').addClass('disabled');
$('#file-' + file_id).children('a').addClass('disabled');
},
success: function(data) {
var response = jQuery.parseJSON(data);
if (response.status === 'ok') {
$('#file-' + file_id).remove();
refreshFilesOrderInput();
} else {
create_error(response.msg);
}
}
});
}, 'Usun');
return false;
});
$('body').on('click', '.article_image_delete', function() {
$(this).blur();
var image_id = $(this).attr('image-id');
confirmDialog('Na pewno chcesz usunac wybrane zdjecie?', function() {
$.ajax({
type: 'POST',
cache: false,
url: '/admin/articles/article_image_delete/',
data: {
image_id: image_id
},
beforeSend: function() {
$('#overlay').show();
},
success: function(data) {
$('#overlay').hide();
var response = jQuery.parseJSON(data);
if (response.status === 'ok') {
$('#image-' + image_id).remove();
refreshGalleryOrderInput();
} else {
create_error(response.msg);
}
}
});
}, 'Usun');
return false;
});
$('body').on('click', '#g-edit-save, #g-edit-save-close', function() {
refreshGalleryOrderInput();
refreshFilesOrderInput();
});
});
function generate_seo_links(lang, title, article_id) {
if (title === '') {
return false;
}
$.ajax({
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data: {
a: 'generate_seo_link',
title: title,
article_id: article_id
},
beforeSend: function() {
$('#seo_link_' + lang).parents('.g-form-data').find('input, a').each(function() {
$(this).prop('disabled', true).addClass('disabled');
});
},
success: function(data) {
$('#seo_link_' + lang).parents('.g-form-data').find('input, a').each(function() {
$(this).prop('disabled', false).removeClass('disabled');
});
var response = jQuery.parseJSON(data);
if (response.status === 'ok') {
$('#seo_link_' + lang).val(response.seo_link);
} else {
create_error(response.msg);
}
}
});
}
</script>

View File

@@ -1,804 +1,6 @@
<script type="text/javascript" src="/libraries/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/libraries/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript" src="/libraries/jquery/sortable/sortable.js"></script>
<?
global $db;
$upload_token = bin2hex( random_bytes(24) );
$_SESSION['upload_tokens'][$upload_token] = [
'user_id' => $this -> user['id'],
'expires' => time() + 60*20
];
$_SESSION['rfm_akey'] = bin2hex(random_bytes(16));
$_SESSION['rfm_akey_expires'] = time() + 20*60;
$_SESSION['can_use_rfm'] = true;
$rfmAkeyJS = $_SESSION['rfm_akey'];
ob_start();
?>
<div id="settings-tabs">
<ul class="resp-tabs-list settings-tabs">
<li><i class="fa fa-file"></i>Treść</li>
<li><i class="fa fa-wrench"></i>Ustawienia</li>
<li><i class="fa fa-globe"></i>SEO</li>
<li><i class="fa fa-share-alt"></i>Wyświetlanie</li>
<li><i class="fa fa-file-image-o"></i>Galeria</li>
<li><i class="fa fa-file-archive-o"></i>Załączniki</li>
</ul>
<div class="resp-tabs-container settings-tabs">
<div>
<div id="languages-main">
<ul class="resp-tabs-list languages-main htabs">
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
<? if ( $lg['status'] ):?>
<li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg['name'];?></a></li>
<? endif;?>
<? endforeach; endif;?>
</ul>
<div class="resp-tabs-container languages-main">
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
<?
$languages = array();
$languages[''] = '---- wersja językowa ----';
if ( is_array( $this -> languages ) ) foreach ( $this -> languages as $lg_tmp )
{
if ( $lg_tmp['id'] != $lg['id'] )
$languages[ $lg_tmp['id'] ] = $lg_tmp['name'];
}
?>
<? if ( $lg['status'] ):?>
<div>
<?= \Html::select(
array(
'label' => 'Wyświetlaj treść z wersji',
'name' => 'copy_from[' . $lg['id'] . ']',
'values' => $languages,
'value' => $this -> article['languages'][ $lg['id'] ]['copy_from'],
)
);?>
<?= \Html::input(
array(
'label' => 'Tytuł',
'name' => 'title[' . $lg['id'] . ']',
'id' => 'title_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['title'],
'inline' => true
)
);?>
<?= \Html::input_icon( [
'label' => 'Zdjęcie tytułowe',
'name' => 'main_image[' . $lg['id'] . ']',
'id' => 'main_image_' . $lg['id'],
'value' => htmlspecialchars( $this -> article['languages'][ $lg['id'] ]['main_image'] ),
'icon_content' => 'przeglądaj',
'inline' => true,
'icon_js' => "window.open ( '/libraries/filemanager-9.14.2/dialog.php?type=1&popup=1&field_id=main_image_" . $lg['id'] . "&akey=" . $rfmAkeyJS . "', 'mywindow', 'location=1,status=1,scrollbars=1, width=1100,height=700');"
] );
?>
<?= \Html::textarea(
array(
'label' => 'Wstęp',
'name' => 'entry[' . $lg['id'] . ']',
'id' => 'entry_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['entry'],
'inline' => true
)
);?>
<?= \Html::textarea(
array(
'label' => 'Treść',
'name' => 'text[' . $lg['id'] . ']',
'id' => 'text_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['text'],
'inline' => true
)
);?>
<?= \Html::textarea( [
'label' => 'Spis treści',
'name' => 'table_of_contents[' . $lg['id'] . ']',
'id' => 'table_of_contents_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['table_of_contents'],
'inline' => true
] );?>
<script type="text/javascript">
$( function() {
$( '#text_<?= $lg['id'];?>, #entry_<?= $lg['id'];?>, #table_of_contents_<?= $lg['id'];?>' ).ckeditor( {
toolbar : 'MyToolbar',
height:'250',
filebrowserBrowseUrl: '/libraries/filemanager-9.14.2/dialog.php?type=2&editor=ckeditor&akey=<?= $rfmAkeyJS;?>',
filebrowserImageBrowseUrl: '/libraries/filemanager-9.14.2/dialog.php?type=1&editor=ckeditor&akey=<?= $rfmAkeyJS;?>',
filebrowserUploadUrl: '/libraries/filemanager-9.14.2/dialog.php?type=2&editor=ckeditor&upload=1&akey=<?= $rfmAkeyJS;?>',
filebrowserImageUploadUrl: '/libraries/filemanager-9.14.2/dialog.php?type=1&editor=ckeditor&upload=1&akey=<?= $rfmAkeyJS;?>'
});
});
</script>
</div>
<? endif;?>
<? endforeach; endif;?>
</div>
<div class="clear"></div>
</div>
</div>
<div>
<?= \Html::input_switch(
array(
'label' => 'Opublikowany',
'name' => 'status',
'checked' => $this -> article['status'] == 1 or !$this -> article['id'] ? true : false
)
);?>
<?= \Html::input_switch(
array(
'label' => 'Pokaż tytuł',
'name' => 'show_title',
'checked' => $this -> article['show_title'] == 1 ? true : false
)
);?>
<?= \Html::input_switch( [
'label' => 'Pokaż spis treści',
'name' => 'show_table_of_contents',
'checked' => $this -> article['show_table_of_contents'] == 1 ? true : false
] );?>
<?= \Html::input_switch(
array(
'label' => 'Pokaż datę dodania',
'name' => 'show_date_add',
'checked' => $this -> article['show_date_add'] == 1 ? true : false
)
);?>
<?= \Html::input_switch(
array(
'label' => 'Pokaż datę modyfikacji',
'name' => 'show_date_modify',
'checked' => $this -> article['show_date_modify'] == 1 ? true : false
)
);?>
<?= \Html::input_switch(
array(
'label' => 'Powtórz wprowadzenie',
'name' => 'repeat_entry',
'checked' => $this -> article['repeat_entry'] == 1 ? true : false
)
);?>
<?= \Html::input_switch(
array(
'label' => 'Linki do portali społecznościowych',
'name' => 'social_icons',
'checked' => $this -> article['social_icons'] == 1 ? true : false
)
);?>
</div>
<div>
<div id="languages-seo">
<ul class="resp-tabs-list languages-seo htabs">
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
<? if ( $lg['status'] ):?>
<li><? if ( $lg['id'] == \front\factory\Languages::default_language() ) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> ';?><?= $lg['name'];?></a></li>
<? endif;?>
<? endforeach; endif;?>
</ul>
<div class="resp-tabs-container languages-seo">
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
<? if ( $lg['status'] ):?>
<div>
<?= \Html::input_icon(
array(
'label' => 'Link SEO',
'name' => 'seo_link[' . $lg['id'] . ']',
'id' => 'seo_link_' . $lg['id'],
'value' => $this -> article['languages' ][ $lg['id'] ]['seo_link'],
'icon_content' => 'generuj',
'icon_js' => 'generate_seo_links( "' . $lg['id'] . '", $( "#title_' . $lg['id'] . '" ).val(), ' . (int)$this -> article['id'] . ' );'
)
);?>
<?= \Html::input( [
'label' => 'Meta title',
'name' => 'meta_title[' . $lg['id'] . ']',
'id' => 'meta_title_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['meta_title']
]
);?>
<?= \Html::textarea(
array(
'label' => 'Meta description',
'name' => 'meta_description[' . $lg['id'] . ']',
'id' => 'meta_description_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['meta_description']
)
);?>
<?= \Html::textarea(
array(
'label' => 'Meta keywords',
'name' => 'meta_keywords[' . $lg['id'] . ']',
'id' => 'meta_keywords_' . $lg['id'],
'value' => $this -> article['languages'][ $lg['id'] ]['meta_keywords']
)
);?>
<?= \Html::input_switch( [
'label' => 'Blokuj indeksację',
'name' => 'noindex[' . $lg['id'] . ']',
'id' => 'noindex_' . $lg['id'],
'checked' => $this -> article['languages'][ $lg['id'] ]['noindex'] == 1 ? 1 : 0
]
);?>
<?= \Html::input_switch( [
'label' => 'Blokuj bezpośredni dostęp',
'name' => 'block_direct_access[' . $lg['id'] . ']',
'id' => 'block_direct_access_' . $lg['id'],
'checked' => $this -> article['languages'][ $lg['id'] ]['block_direct_access'] == 1 ? 1 : 0
] );?>
</div>
<? endif;?>
<? endforeach; endif;?>
</div>
<div class="clear"></div>
</div>
</div>
<div>
<?
$layouts[''] = '---- szablon domyślny ----';
if ( is_array( $this -> layouts ) ): foreach ( $this -> layouts as $layout ):
$layouts[ $layout['id'] ] = $layout['name'];
endforeach; endif;
?>
<?= \Html::select(
array(
'label' => 'Szablon',
'name' => 'layout_id',
'id' => 'layout_id',
'values' => $layouts,
'value' => $this -> article['layout_id']
)
);?>
<div class="form-group">
<label class="col-lg-4 control-label">Wyświetlaj na:</label>
<div class="col-lg-8">
<?
if ( is_array( $this -> menus ) ) foreach ( $this -> menus as $menu )
{
?>
<div class="menu_sortable">
<ol class="sortable" id="sortable_<?= $menu['id'];?>">
<li id="list_<?= $menu['id'];?>" class="menu_<?= $menu['id'];?>" menu="<?= $menu['id'];?>">
<div class="context_0 content content_menu" <? if ( !$menu['status'] ) echo 'style="color: #cc0000;"';?>>
<span class="disclose"><span></span></span>
Menu: <b><?= $menu['name'];?></b>
</div>
<?= \admin\view\Articles::subpages_list( \admin\factory\Pages::menu_pages( $menu['id'] ), $this -> article['pages'] );?>
</li>
</ol>
</div>
<?
}
?>
</div>
<div class="clear"></div>
</div>
</div>
<div>
<ul id="images-list">
<?
$images_count = 0;
if ( is_array( $this -> article['images'] ) ): foreach ( $this -> article['images'] as $img ):
?>
<li id="image-<?= $img['id'];?>">
<img class="article-image lozad" data-src="/libraries/thumb.php?img=<?= $img['src'];?>&w=300&h=300">
<a href="#" class="input-group-addon btn btn-danger article_image_delete" image-id="<?= $img['id'];?>">
<i class="fa fa-trash"></i>
</a>
<input type="text" class="form-control image-alt" value="<?= $img['alt'];?>" image-id="<?= $img['id'];?>" placeholder="atrybut alt...">
</li>
<?
$images_count++;
endforeach; endif;
?>
</ul>
<div id="images-uploader">You browser doesn't have Flash installed.</div>
</div>
<div>
<ul id="files-list">
<?
$files_count = 0;
if ( is_array( $this -> article['files'] ) ): foreach ( $this -> article['files'] as $file ):
if ( $file['name'] )
$name = $file['name'];
else
{
$name = explode( '/', $file['src'] );
$name = $name[ count( $name ) - 1 ];
}
?>
<li id="file-<?= $file['id'];?>">
<div class="input-group">
<input type="text" class="article_file_edit form-control" file_id="<?= $file['id'];?>" value="<?= $name;?>" />
<a href="#" class="input-group-addon btn btn-info article_file_delete" file_id="<?= $file['id'];?>">
<i class="fa fa-trash"></i>
</a>
</div>
</li>
<?
$files_count++;
endforeach; endif;
?>
</ul>
<div id="files-uploader">You browser doesn't have Flash installed.</div>
</div>
</div>
</div>
<?
$out = ob_get_clean();
$grid = new \gridEdit;
$grid -> id = 'article-edit';
$grid -> gdb_opt = $gdb;
$grid -> include_plugins = true;
$grid -> title = 'Edycja artykułu';
$grid -> fields = [
[
'db' => 'id',
'type' => 'hidden',
'value' => $this -> article['id']
]
];
$grid -> actions = [
'save' => [ 'url' => '/admin/articles/article_save/', 'back_url' => '/admin/articles/view_list/' ],
'cancel' => [ 'url' => '/admin/articles/view_list/' ]
];
$grid -> external_code = $out;
$grid -> persist_edit = true;
$grid -> id_param = 'id';
echo $grid -> draw();
?>
<link type="text/css" rel="stylesheet" href="/libraries/plupload/jquery.plupload.queue/css/jquery.plupload.queue.css" />
<script type="text/javascript" src="/libraries/plupload/plupload.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.flash.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html5.js"></script>
<script type="text/javascript" src="/libraries/plupload/plupload.html4.js"></script>
<script type="text/javascript" src="/libraries/plupload/jquery.plupload.queue/jquery.plupload.queue.js"></script>
<script type="text/javascript" src="/libraries/plupload/i18n/pl.js"></script>
<script type="text/javascript" src="/libraries/jquery-nested-sortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/libraries/jquery/lozad.js"></script>
<script type="text/javascript">
var images_count = <?= $images_count;?>;
var files_count = <?= $files_count;?>;
$( function()
{
const observer = lozad();
observer.observe();
disable_menu();
var el = document.getElementById( 'images-list' );
var sortable = Sortable.create(el, {
onEnd: function ( evt ) {
var order = '';
$( '#images-list li' ).each( function()
{
if ( order !== '' )
order += ';';
order += $( this ).children( 'a' ).attr( 'image-id' );
});
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/articles/gallery_order_save/',
data:
{
article_id: '<?= $this -> article['id'];?>',
order: order
},
beforeSend: function()
{
$( '#overlay' ).show();
},
success: function( data )
{
$( '#overlay' ).hide();
response = jQuery.parseJSON( data );
if ( response.status !== 'ok' )
create_error( response.msg );
}
});
}
});
$( "#images-uploader" ).pluploadQueue(
{
multipart_params: {
upload_token: '<?= $upload_token ?>',
},
runtimes: 'html5,flash,html4',
init:
{
Refresh: function(up)
{
$( ".plupload_buttons" ).css( "display", "inline" );
$( ".plupload_upload_status" ).css( "display", "inline" );
$( ".plupload_start" ).addClass( "plupload_disabled" );
$( ".plupload_start" ).removeClass( "plupload_disabled" );
},
UploadComplete: function()
{
$( ".plupload_buttons" ).css( "display", "inline" );
$( ".plupload_upload_status" ).css( "display", "inline" );
$( ".plupload_start" ).addClass( "plupload_disabled" );
$( ".plupload_start" ).removeClass( "plupload_disabled" );
},
FileUploaded: function( up, file, response )
{
data = jQuery.parseJSON( response.response );
$( '#images-list' ).append(
'<li id="image-' + data.image_id + '">' +
'<img class="article-image lozad" data-src="/libraries/thumb.php?img=' + data.data_link + '&w=300&h=300">' +
'<a href="#" class="input-group-addon btn btn-danger article_image_delete" image-id="' + data.image_id + '">' +
'<i class="fa fa-trash"></i>' +
'</a>' +
'<input type="text" class="form-control image-alt" value="" image-id="' + data.image_id + '" placeholder="atrybut alt...">' +
'</li>'
);
images_count++;
observer.observe();
$( 'html, body' ).animate({
scrollTop: $( "#images-uploader" ).offset().top
}, 1 );
}
},
url: '/libraries/plupload/upload-articles-images.php',
chunk_size: '1mb',
unique_names: false,
resize : {
width : <?= $this -> settings['image_px'] ? $this -> settings['image_px'] : '1920';?>,
height : <?= $this -> settings['image_px'] ? $this -> settings['image_px'] : '1920';?>,
quality : 95
},
filters: [
{ title: "Obrazki", extensions : "jpg, gif, png, bmp, jpeg" }
],
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
});
$( "#files-uploader" ).pluploadQueue(
{
multipart_params: {
upload_token: '<?= $upload_token ?>',
},
runtimes: 'html5,flash,html4',
init:
{
Refresh: function( up )
{
$( ".plupload_buttons" ).css( "display", "inline" );
$( ".plupload_upload_status" ).css( "display", "inline" );
$( ".plupload_start" ).addClass( "plupload_disabled" );
$( ".plupload_start" ).removeClass( "plupload_disabled" );
},
FileUploaded: function( up, file, response )
{
data = jQuery.parseJSON( response.response );
$( '#files-list' ).append(
'<li id="file-' + data.file_id + '">' +
'<div class="input-group">' +
'<input type="text" class="form-control article_file_edit" file_id="' + data.file_id + '" value="' + data.file_name + '" />' +
'<a href="#" class="input-group-addon btn btn-info article_file_delete" file_id="' + data.file_id + '">' +
'<i class="fa fa-trash"></i>' +
'</a>' +
'</div>' +
'</li>'
);
files_count++;
}
},
url: '/libraries/plupload/upload-articles-files.php',
chunk_size: '1mb',
unique_names: false,
filters: [
{ title: "Wszystkie pliki", extensions: "*" }
],
flash_swf_url: '/../libraries/plupload/plupload.flash.swf'
});
$( '#settings-tabs' ).easyResponsiveTabs({
width: 'auto',
fit: true,
tabidentify: 'settings-tabs',
type: 'vertical'
});
$( '#languages-main' ).easyResponsiveTabs({
width: 'auto',
fit: true,
tabidentify: 'languages-main'
});
$( '#languages-seo' ).easyResponsiveTabs({
width: 'auto',
fit: true,
tabidentify: 'languages-seo'
});
$('ol.sortable').nestedSortable({
forcePlaceholderSize: true,
handle: 'div',
helper: 'clone',
items: 'li',
opacity: .6,
placeholder: 'placeholder',
revert: 250,
tabSize: 25,
tolerance: 'pointer',
toleranceElement: '> div',
maxLevels: 3,
isTree: true,
expandOnHover: 700,
isAllowed: function()
{
return false;
}
});
$( '.disclose' ).on( 'click', function() {
$( this ).closest( 'li' ).toggleClass( 'sort-collapsed' ).toggleClass( 'sort-expanded' );
});
$( '.disclose' ).mousedown( function(e) {
if ( e.which === 1 ) {
if ( $( this ).parent( 'div' ).hasClass( 'content_menu' ) )
{
var menu_id = $( this ).parent( 'div' ).parent( 'li' ).attr( 'menu' );
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data: {
a: 'cookie_menus',
menu_id: menu_id
}
});
}
else
{
var page_id = $( this ).parent( 'div' ).parent( 'li' ).attr( 'id' );
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data: {
a: 'cookie_pages',
page_id: page_id
}
});
}
}
});
<?php
$array = unserialize( $_COOKIE[ 'cookie_pages' ] );
if ( is_array( $array ) ): foreach ( $array as $key => $val ):
if ( $val ):
?>$( '.<?= $key;?>' ).children( 'div' ).children( 'span.disclose' ).click();<?
endif;
endforeach; endif;
$array = unserialize( $_COOKIE[ 'cookie_menus' ] );
if ( is_array( $array ) ): foreach ( $array as $key => $val ):
if ( $val ):
?>$( '.menu_<?= $key;?>' ).children( 'div' ).children( 'span.disclose' ).click();<?
endif;
endforeach; endif;
?>
$( 'body' ).on( 'change', '.image-alt', function()
{
var image_alt = $( this ).val();
var image_id = $( this ).attr( 'image-id' );
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data:
{
a: 'article_image_alt_change',
image_id: image_id,
image_alt: image_alt
},
beforeSend: function()
{
$( '#overlay' ).show();
},
success: function( data )
{
$( '#overlay' ).hide();
response = jQuery.parseJSON( data );
if ( response.status !== 'ok' )
create_error( response.msg );
}
});
});
$( 'body' ).on( 'change', '.article_file_edit', function()
{
var file_name = $( this ).val();
var file_id = $( this ).attr( 'file_id' );
$.ajax({
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data:
{
a: 'article_file_name_change',
file_id: file_id,
file_name: file_name
},
beforeSend: function()
{
$( '#overlay' ).show();
},
success: function( data )
{
$( '#overlay' ).hide();
response = jQuery.parseJSON( data );
if ( response.status !== 'ok' )
create_error( response.msg );
}
});
});
$( 'body' ).on( 'click', '.article_file_delete', function()
{
$( this ).blur();
var file_id = $( this ).attr( 'file_id' );
$.prompt( 'Na pewno chcesz usunąć wybrany plik?', {
title: 'Potwierdź?',
submit: function(e,v,m,f)
{
if ( v === true )
{
$.ajax({
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data:
{
a: 'article_file_delete',
file_id: file_id
},
beforeSend: function()
{
$( '#file-' + file_id ).children( 'input' ).addClass( 'disabled' );
$( '#file-' + file_id ).children( 'a' ).addClass( 'disabled' );
},
success: function( data )
{
response = jQuery.parseJSON( data );
if ( response.status === 'ok' )
$( '#file-' + file_id ).remove();
else
create_error( msg );
}
});
}
},
buttons: {
'tak': true,
'nie': false
},
focus: 0
});
});
$( 'body' ).on( 'click', '.article_image_delete', function()
{
$( this ).blur();
var image_id = $( this ).attr( 'image-id' );
$.prompt( 'Na pewno chcesz usunąć wybrane zdjęcie?',
{
title: 'Potwierdź?',
submit: function(e,v,m,f)
{
if ( v === true )
{
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data:
{
a: 'article_image_delete',
image_id: image_id
},
beforeSend: function()
{
$( '#overlay' ).show();
},
success: function( data )
{
$( '#overlay' ).hide();
response = jQuery.parseJSON( data );
if ( response.status === 'ok' )
$( '#image-' + image_id ).remove();
else
create_error( msg );
}
});
}
},
buttons: {
'tak': true,
'nie': false
},
focus: 0
});
return false;
});
});
function generate_seo_links( lang, title, article_id )
{
if ( title === '' )
return false;
$.ajax(
{
type: 'POST',
cache: false,
url: '/admin/ajax.php',
data:
{
a: 'generate_seo_link',
title: title,
article_id: article_id
},
beforeSend: function()
{
$( '#seo_link_' + lang ).parents( '.g-form-data' ).find( 'input, a' ).each( function()
{
$( this ).prop( 'disabled', true ).addClass( 'disabled' );
});
},
success: function( data ) {
$( '#seo_link_' + lang ).parents( '.g-form-data' ).find( 'input, a' ).each( function() {
$( this ).prop( 'disabled', false ).removeClass( 'disabled' );
});
response = jQuery.parseJSON( data );
if ( response.status === 'ok' )
$( '#seo_link_' + lang ).val( response.seo_link );
else
create_error( response.msg );
}
});
}
</script>
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
<?= \Tpl::view('components/form-edit', ['form' => $this->form]); ?>
<?= \Tpl::view('articles/article-edit-custom-script', [
'article' => $this->article,
'user' => $this->user,
'languages' => $this->form->languages ?? []
]); ?>

View File

@@ -6,11 +6,13 @@
<span class="disclose"><span></span></span>
<input type="checkbox" class="g-checkbox" name="pages[]" value="<?= $page['id'];?>" <? if ( is_array( $this -> article_pages ) and in_array( $page['id'], $this -> article_pages ) ):?>checked="checked"<? endif;?> /><?= $page['title'];?>
</div>
<?
if ( is_array( $page['subpages'] ) )
echo \admin\view\Articles::subpages_list( $page['subpages'], $this -> article_pages, $page['id'], $this -> step + 1 );
?>
<?= \Tpl::view( 'articles/subpages-list', [
'pages' => $page['subpages'],
'article_pages' => $this->article_pages,
'parent_id' => $page['id'],
'step' => $this->step + 1,
] ); ?>
</li>
<? endforeach;?>
</ol>
<? endif;?>
<? endif;?>