koblog/bl-kernel/admin/views/content.php

321 lines
11 KiB
PHP
Raw Normal View History

<?php defined('BLUDIT') or die('Bludit CMS.'); ?>
<script>
// ============================================================================
// Variables for the view
// ============================================================================
// ============================================================================
// Functions for the view
// ============================================================================
2021-06-07 19:49:38 +02:00
function deletePage(key) {
var args = {
key: key
};
api.deletePage(args).then(function(response) {
if (response.status == 0) {
logs('Page deleted. Key: ' + response.data.key);
showAlertInfo("<?php $L->p('Page deleted') ?>");
$('#pagekey-'+response.data.key).addClass('disabled');
} else {
logs('An error occurred while trying to delete the page.');
showAlertError(response.message);
}
});
}
// ============================================================================
// Events for the view
// ============================================================================
$(document).ready(function() {
$(".btnDeletePage").on("click", function() {
var key = $(this).data('key');
logs('Deleting page. Key: ' + key);
bootbox.confirm({
message: '<?php $L->p('Are you sure you want to delete this page') ?>',
buttons: {
cancel: {
2021-06-07 19:49:38 +02:00
label: '<i class="bi bi-x"></i><?php $L->p('Cancel') ?>',
className: 'btn-sm btn-secondary'
},
confirm: {
2021-06-07 19:49:38 +02:00
label: '<i class="bi bi-check"></i><?php $L->p('Confirm') ?>',
className: 'btn-sm btn-primary'
}
},
closeButton: false,
callback: function(result) {
if (result) {
2021-06-07 19:49:38 +02:00
deletePage(key);
}
}
});
});
});
// ============================================================================
// Initialization for the view
// ============================================================================
$(document).ready(function() {
// No initialization for the view yet
});
</script>
<div class="d-flex align-items-center mb-4">
<h2 class="m-0"><i class="bi bi-folder"></i><?php $L->p('Content') ?></h2>
<div class="ms-auto">
<a id="btnNew" class="btn btn-primary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT . 'editor' ?>" role="button"><i class="bi bi-plus-circle"></i><?php $L->p('Add a new page') ?></a>
</div>
</div>
2017-05-16 00:46:20 +02:00
<?php
2017-05-16 00:46:20 +02:00
function table($type)
{
global $L;
global $published;
global $drafts;
global $scheduled;
2017-09-20 23:00:03 +02:00
global $static;
2018-03-27 18:40:03 +02:00
global $sticky;
2021-09-12 20:57:44 +02:00
global $unlisted;
2017-08-06 17:27:30 +02:00
if ($type == 'published') {
$list = $published;
2018-05-02 19:59:45 +02:00
if (empty($list)) {
2020-11-30 22:00:54 +01:00
echo '<p class="text-muted p-4">';
echo $L->g('There are no pages at this moment.');
2018-05-02 19:59:45 +02:00
echo '</p>';
return false;
}
} elseif ($type == 'draft') {
$list = $drafts;
2018-05-02 19:59:45 +02:00
if (empty($list)) {
2020-11-30 22:00:54 +01:00
echo '<p class="text-muted p-4">';
echo $L->g('There are no draft pages at this moment.');
2018-05-02 19:59:45 +02:00
echo '</p>';
return false;
}
} elseif ($type == 'scheduled') {
$list = $scheduled;
2018-05-02 19:59:45 +02:00
if (empty($list)) {
2020-11-30 22:00:54 +01:00
echo '<p class="text-muted p-4">';
echo $L->g('There are no scheduled pages at this moment.');
2018-05-02 19:59:45 +02:00
echo '</p>';
return false;
}
} elseif ($type == 'static') {
2017-09-20 23:00:03 +02:00
$list = $static;
2018-05-02 19:59:45 +02:00
if (empty($list)) {
2020-11-30 22:00:54 +01:00
echo '<p class="text-muted p-4">';
echo $L->g('There are no static pages at this moment.');
2018-05-02 19:59:45 +02:00
echo '</p>';
return false;
}
2021-09-12 20:57:44 +02:00
} elseif ($type == 'unlisted') {
$list = $unlisted;
if (empty($list)) {
echo '<p class="text-muted p-4">';
echo $L->g('There are no unlisted pages at this moment.');
echo '</p>';
return false;
}
} elseif ($type == 'sticky') {
2018-03-27 18:40:03 +02:00
$list = $sticky;
2018-05-02 19:59:45 +02:00
if (empty($list)) {
2020-11-30 22:00:54 +01:00
echo '<p class="text-muted p-4">';
echo $L->g('There are no sticky pages at this moment.');
2018-05-02 19:59:45 +02:00
echo '</p>';
return false;
}
}
echo '<table class="table table-striped"><tbody><tr></tr>';
if ((ORDER_BY == 'position') || $type == 'static') {
2018-01-21 23:23:22 +01:00
foreach ($list as $pageKey) {
2018-07-17 23:58:01 +02:00
try {
2018-08-02 17:06:53 +02:00
$page = new Page($pageKey);
2019-09-08 10:35:21 +02:00
if (!$page->isChild()) {
2021-06-07 19:49:38 +02:00
echo '<tr id="pagekey-'.$pageKey.'">';
2018-01-22 00:21:47 +01:00
echo '<td class="pt-4 pb-4">
<div>
2021-09-05 16:18:01 +02:00
<i class="bi bi-file-text"></i><span>' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</span>
</div>
<div class="mt-1">
<a class="me-2" target="_blank" href="' . $page->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . $L->g('Edit') . '</a>
';
if (count($page->children()) == 0) {
echo '<span class="link btnDeletePage" data-key="' . $page->key() . '">Delete</span>';
2019-01-04 14:18:40 +01:00
}
echo '
</div>
</td>';
2018-05-02 19:59:45 +02:00
echo '<td class="pt-4 pb-4 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-4 text-center d-sm-table-cell">' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $page->position() : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
2018-01-22 00:21:47 +01:00
echo '</tr>';
2018-01-21 23:23:22 +01:00
2018-02-15 20:08:00 +01:00
foreach ($page->children() as $child) {
2021-06-07 19:49:38 +02:00
echo '<tr id="pagekey-'.$pageKey.'">';
2018-01-21 23:23:22 +01:00
echo '<td class="ps-3 pt-4 pb-4">
<div>
2021-09-05 16:18:01 +02:00
<i class="bi bi-file-text"></i><span>' . ($child->title() ? $child->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</span>
</div>
<div class="mt-1">
<a class="me-2" target="_blank" href="' . $child->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $child->key() . '">' . $L->g('Edit') . '</a>
<span class="link btnDeletePage" data-key="' . $child->key() . '">Delete</span>
</div>
</td>';
2018-05-02 19:59:45 +02:00
echo '<td class="pt-4 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($child->category() ? $child->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-4 text-center d-sm-table-cell">' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $child->position() : $child->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
2018-05-02 19:59:45 +02:00
2018-01-21 23:23:22 +01:00
echo '</tr>';
}
}
2018-07-17 23:58:01 +02:00
} catch (Exception $e) {
// Continue
2018-01-21 23:23:22 +01:00
}
}
} else {
foreach ($list as $pageKey) {
2018-07-17 23:58:01 +02:00
try {
2018-08-02 17:06:53 +02:00
$page = new Page($pageKey);
2021-06-07 19:49:38 +02:00
echo '<tr id="pagekey-'.$pageKey.'">';
echo '<td class="pt-4 pb-4">
2018-07-28 18:33:37 +02:00
<div>
2021-09-05 16:18:01 +02:00
<i class="bi bi-file-text"></i>' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '
2018-07-28 18:33:37 +02:00
</div>
<div class="mt-1">
<a class="me-2" target="_blank" href="' . $page->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . $L->g('Edit') . '</a>
<span class="link btnDeletePage" data-key="' . $page->key() . '">Delete</span>
2018-07-28 18:33:37 +02:00
</div>
2018-01-21 23:23:22 +01:00
</td>';
echo '<td class="pt-4 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-4 text-center d-sm-table-cell"> ' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $page->position() : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
2018-05-02 19:59:45 +02:00
2018-01-21 23:23:22 +01:00
echo '</tr>';
2018-07-17 23:58:01 +02:00
} catch (Exception $e) {
// Continue
2018-01-21 23:23:22 +01:00
}
2017-12-17 21:16:30 +01:00
}
}
2017-05-16 00:46:20 +02:00
2018-05-02 19:59:45 +02:00
echo '
</tbody>
</table>
';
}
2017-07-07 23:38:01 +02:00
?>
<!-- Tabs -->
<ul class="nav nav-tabs ps-3" role="tablist">
2018-05-02 19:59:45 +02:00
<li class="nav-item">
<a class="nav-link active" id="pages-tab" data-bs-toggle="tab" href="#pages" role="tab" aria-controls="pages" aria-selected="true"><?php $L->p('Pages') ?></a>
2018-05-02 19:59:45 +02:00
</li>
<li class="nav-item">
<a class="nav-link" id="static-tab" data-bs-toggle="tab" href="#static" role="tab" aria-controls="static" aria-selected="true"><?php $L->p('Static') ?></a>
2018-05-02 19:59:45 +02:00
</li>
<li class="nav-item">
<a class="nav-link" id="sticky-tab" data-bs-toggle="tab" href="#sticky" role="tab" aria-controls="sticky" aria-selected="true"><?php $L->p('Sticky') ?></a>
2018-05-02 19:59:45 +02:00
</li>
<li class="nav-item">
<a class="nav-link" id="scheduled-tab" data-bs-toggle="tab" href="#scheduled" role="tab" aria-controls="scheduled" aria-selected="true"><?php $L->p('Scheduled') ?>
<?php if (count($scheduled) > 0) {
echo '<span class="badge badge-danger">' . count($scheduled) . '</span>';
} ?>
</a>
2018-05-02 19:59:45 +02:00
</li>
2021-09-12 20:57:44 +02:00
<li class="nav-item">
<a class="nav-link" id="unlisted-tab" data-bs-toggle="tab" href="#unlisted" role="tab" aria-controls="unlisted" aria-selected="true"><?php $L->p('Unlisted') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="draft-tab" data-bs-toggle="tab" href="#draft" role="tab" aria-controls="draft" aria-selected="true"><?php $L->p('Draft') ?></a>
</li>
2017-07-07 23:38:01 +02:00
</ul>
<!-- End Tabs -->
<!-- Content -->
2018-05-02 19:59:45 +02:00
<div class="tab-content">
2019-05-17 19:49:35 +02:00
<!-- Tab pages -->
<div class="tab-pane show active" id="pages" role="tabpanel">
2018-07-18 23:16:30 +02:00
<?php table('published'); ?>
<!-- Paginator -->
<!-- The paginator is defined in the rule 99.paginator.php for the admin area -->
<?php if (Paginator::numberOfPages() > 1) : ?>
<nav class="mt-4 mb-4">
<ul class="pagination flex-wrap justify-content-center">
<!-- First button -->
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Paginator::firstPageUrl() ?>"><i class="bi bi-arrow-left-circle"></i><?php echo $L->get('First'); ?></a>
</li>
<!-- Previous button -->
<li class="page-item <?php if (!Paginator::showPrev()) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Paginator::previousPageUrl() ?>"><?php echo $L->get('Previous'); ?></a>
</li>
<li class="page-item"><span class="page-link text-muted"><?php echo Paginator::currentPage() ?> / <?php echo Paginator::numberOfPages() ?></span></li>
<!-- Next button -->
<li class="page-item <?php if (!Paginator::showNext()) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Paginator::nextPageUrl() ?>"><?php echo $L->get('Next'); ?></a>
</li>
<!-- Last button -->
<li class="page-item <?php if (!Paginator::showNext()) echo 'disabled' ?>">
<a class="page-link" href="<?php echo Paginator::lastPageUrl() ?>"><?php echo $L->get('Last'); ?><i class="ms-2 bi bi-arrow-right-circle"></i></a>
</li>
</ul>
</nav>
2018-07-28 18:33:37 +02:00
<?php endif; ?>
<!-- End Paginator -->
2018-05-02 19:59:45 +02:00
</div>
<!-- End Tab pages -->
2018-05-02 19:59:45 +02:00
<!-- TABS STATIC -->
<div class="tab-pane" id="static" role="tabpanel">
<?php table('static'); ?>
2018-05-02 19:59:45 +02:00
</div>
<!-- TABS STICKY -->
<div class="tab-pane" id="sticky" role="tabpanel">
<?php table('sticky'); ?>
2018-05-02 19:59:45 +02:00
</div>
<!-- TABS SCHEDULED -->
<div class="tab-pane" id="scheduled" role="tabpanel">
<?php table('scheduled'); ?>
2018-05-02 19:59:45 +02:00
</div>
2021-09-12 20:57:44 +02:00
<!-- TABS UNLISTED -->
<div class="tab-pane" id="unlisted" role="tabpanel">
<?php table('unlisted'); ?>
</div>
2018-05-02 19:59:45 +02:00
<!-- TABS DRAFT -->
<div class="tab-pane" id="draft" role="tabpanel">
<?php table('draft'); ?>
2018-05-02 19:59:45 +02:00
</div>
</div>
<!-- End Content -->