🚸 (content): separate the page to edit/create/view content

This commit is contained in:
Kazhnuz 2025-01-25 15:39:34 +01:00
parent cbb141d2a5
commit 25c194fac6
8 changed files with 160 additions and 115 deletions

View file

@ -5,6 +5,7 @@
// ============================================================================
checkRole(array('admin', 'editor', 'author'));
global $pagetypes;
// ============================================================================
// Functions
@ -35,11 +36,23 @@ function filterContentOwner($list) {
// Main after POST
// ============================================================================
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN, ['article'], ['published'], true, true);
$drafts = $pages->getDraftDB(['article'], true);
$scheduled = $pages->getScheduledDB(['article'],true);
$static = $pages->getStaticDB(['published'],true);
$autosave = $pages->getAutosaveDB(['article'],true);
$contentTypeKey = $layout['parameters'];
if (!$pagetypes->exists($contentTypeKey)) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
try {
$contentType = new PageType($contentTypeKey);
} catch (Exception $e) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN, [$contentTypeKey], ['published'], true, true);
$drafts = $pages->getDraftDB([$contentTypeKey], true);
$scheduled = $pages->getScheduledDB([$contentTypeKey],true);
$autosave = $pages->getAutosaveDB([$contentTypeKey],true);
// If the user is an Author filter the content he/she can edit
if (checkRole(array('author'), false)) {

View file

@ -25,6 +25,21 @@ if (checkRole(array('author'), false)) {
}
}
$pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters'];
$page = new Page($pageKey);
$contentTypeKey = $page->type();
if (!$pagetypes->exists($contentTypeKey)) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
try {
$contentType = new PageType($contentTypeKey);
} catch (Exception $e) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
// ============================================================================
// Functions
// ============================================================================

View file

@ -1,5 +1,7 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
$contentTypeKey = $layout['parameters'];
// ============================================================================
// Check role
// ============================================================================
@ -20,7 +22,7 @@ checkRole(array('admin', 'editor', 'author'));
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
createPage($_POST);
Redirect::page('content');
Redirect::page('content/'.$contentTypeKey);
}
// ============================================================================
@ -30,6 +32,19 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// UUID of the page is need it for autosave and media manager
$uuid = $pages->generateUUID();
if (!$pagetypes->exists($contentTypeKey)) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
try {
$contentType = new PageType($contentTypeKey);
} catch (Exception $e) {
Alert::set($L->g('Content type do not exists'));
Redirect::page('dashboard');
}
// Images prefix directory
define('PAGE_IMAGES_KEY', $uuid);

View file

@ -69,14 +69,14 @@
<ul class="navbar-nav mb-2 mb-lg-0 align-items-center d-none d-lg-flex">
<li class="nav-item mx-1">
<div class="btn-group dropdown">
<a class="btn btn-sm btn-outline-primary" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content' ?>"><span class="fa fa-plus-circle"></span><?php $L->p('New') ?></a>
<a class="btn btn-sm btn-outline-primary" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content/article' ?>"><span class="fa fa-plus-circle"></span><?php $L->p('New') ?></a>
<button type="button" class="btn btn-sm btn-outline-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-expanded="false">
<span class="visually-hidden">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu dropdown-menu-end">
<li>
<a class="dropdown-item" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content' ?>">
<?php $L->p('New content') ?></a>
<a class="dropdown-item" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content/static' ?>">
<?php $L->p('New') ?> (<?php $L->p(string: 'Static page') ?>)</a>
</li>
<li>
<a class="dropdown-item" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-category' ?>">

View file

@ -1,4 +1,5 @@
<!-- Use .flex-column to set a vertical direction -->
<?php global $pagetypes; ?>
<ul class="nav flex-column pt-4">
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'dashboard' ?>"><span class="fa fa-globe fa-fw"></span><?php $L->p('Dashboard') ?></a>
@ -8,9 +9,14 @@
<li class="nav-item mt-3">
<h4><?php $L->p('Content') ?></h4>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'content' ?>"><span class="fa fa-archive fa-fw"></span><?php $L->p('Articles and pages') ?></a>
</li>
<?php foreach ($pagetypes->getDB() as $contentPageKey => $fields) {
$pageType = new PageType($contentPageKey);
?>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'content/'.$pageType->type() ?>"><span class="fa fa-<?php echo $pageType->icon(); ?> fa-fw"></span><?php echo $pageType->plural(); ?></a>
</li>
<?php
} ?>
<?php endif; ?>
<?php if (checkRole(array('admin'),false)): ?>
@ -18,9 +24,14 @@
<li class="nav-item mt-3">
<h4><?php $L->p('Content') ?></h4>
</li>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'content' ?>"><span class="fa fa-archive fa-fw"></span><?php $L->p('Articles and pages') ?></a>
</li>
<?php foreach ($pagetypes->getDB() as $contentPageKey => $fields) {
$pageType = new PageType($contentPageKey);
?>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'content/'.$pageType->type() ?>"><span class="fa fa-<?php echo $pageType->icon(); ?> fa-fw"></span><?php echo $pageType->plural(); ?></a>
</li>
<?php
} ?>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>"><span class="fa fa-tags fa-fw"></span><?php $L->p('Categories') ?></a>

View file

@ -1,6 +1,6 @@
<?php
echo Bootstrap::pageTitle(array('title'=>$L->g('Articles and pages'), 'icon'=>'archive'));
echo Bootstrap::pageTitle(array('title'=>$contentType->plural(), 'icon'=>$contentType->icon()));
function table($type) {
global $url;
@ -8,8 +8,8 @@ function table($type) {
global $published;
global $drafts;
global $scheduled;
global $static;
global $autosave;
global $contentType;
if ($type=='published') {
$list = $published;
@ -35,14 +35,6 @@ function table($type) {
echo '</p>';
return false;
}
} elseif ($type=='static') {
$list = $static;
if (empty($list)) {
echo '<p class="alert alert-warning">';
echo $L->g('There are no static pages at this moment.');
echo '</p>';
return false;
}
} elseif ($type=='autosave') {
$list = $autosave;
}
@ -55,7 +47,7 @@ function table($type) {
<th class="border-0" scope="col">'.$L->g('Title').'</th>
';
if ($type=='published' || $type=='static') {
if ($type=='published') {
echo '<th class="border-0 d-none d-lg-table-cell" scope="col">'.$L->g('URL').'</th>';
}
@ -65,7 +57,7 @@ function table($type) {
<tbody>
';
if ( (ORDER_BY=='position') || $type=='static' ) {
if ( (ORDER_BY=='position') || $contentType->type() == 'static') {
foreach ($list as $pageKey) {
try {
$page = new Page($pageKey);
@ -81,13 +73,13 @@ function table($type) {
.'</a>
</div>
<div>
<p style="font-size: 0.8em" class="m-0 text-uppercase text-muted">'.( ((ORDER_BY=='position') || ($type!='published'))?$L->g('Position').': '.$page->position():$page->date(MANAGE_CONTENT_DATE_FORMAT) ).'</p>
<p style="font-size: 0.8em" class="m-0 text-uppercase text-muted">'.( ((ORDER_BY=='position') || ($contentType->type()=='static'))?$L->g('Position').': '.$page->position():$page->date(MANAGE_CONTENT_DATE_FORMAT) ).'</p>
</div>
</div>
</div>
</td>';
if ($type=='published' || $type=='static') {
if ($type=='published') {
$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
echo '<td class="d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
}
@ -116,13 +108,13 @@ function table($type) {
</div>
</td>';
if ($type=='published' || $type=='static') {
if ($type=='published') {
$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$child->key() : '/'.$url->filters('page').'/'.$child->key();
echo '<td class="d-none d-lg-table-cell"><a target="_blank" href="'.$child->permalink().'">'.$friendlyURL.'</a></td>';
}
echo '<td class="contentTools p-2 text-end d-sm-table-cell">'.PHP_EOL;
if ($type=='published' || $type=='static') {
if ($type=='published') {
echo '<a class="btn btn-sm btn-secondary d-none d-md-inline" target="_blank" href="'.$child->permalink().'"><i class="fa fa-desktop"></i>'.$L->g('View').'</a>'.PHP_EOL;
}
echo '<a class="btn btn-sm btn-secondary d-none d-md-inline ms-2" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$child->key().'"><i class="fa fa-edit"></i>'.$L->g('Edit').'</a>'.PHP_EOL;
@ -157,13 +149,13 @@ function table($type) {
</div>
</td>';
if ($type=='published' || $type=='static') {
if ($type=='published') {
$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
echo '<td class="p-2 d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
}
echo '<td class="contentTools p-2 text-end d-sm-table-cell">'.PHP_EOL;
if ($type=='published' || $type=='static') {
if ($type=='published') {
echo '<a class="btn btn-sm btn-secondary d-none d-md-inline" target="_blank" href="'.$page->permalink().'"><i class="fa fa-desktop"></i>'.$L->g('View').'</a>'.PHP_EOL;
}
echo '<a class="btn btn-sm btn-secondary d-none d-md-inline ms-2" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'"><i class="fa fa-edit"></i>'.$L->g('Edit').'</a>'.PHP_EOL;
@ -193,9 +185,6 @@ function table($type) {
<li class="nav-item" role="presentation">
<button class="nav-link active" id="pages-tab" data-bs-toggle="tab" data-bs-target="#pages" role="tab"><?php $L->p('Pages') ?></button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="static-tab" data-bs-toggle="tab" data-bs-target="#static" role="tab"><?php $L->p('Static') ?></button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="scheduled-tab" data-bs-toggle="tab" data-bs-target="#scheduled" role="tab"><?php $L->p('Scheduled') ?> <?php if (count($scheduled)>0) { echo '<span class="badge bg-danger" style="position:relative;top:-2px;">'.count($scheduled).'</span>'; } ?></button>
</li>
@ -244,11 +233,6 @@ function table($type) {
<?php endif; ?>
</div>
<!-- TABS STATIC -->
<div class="tab-pane" id="static" role="tabpanel">
<?php table('static'); ?>
</div>
<!-- TABS SCHEDULED -->
<div class="tab-pane" id="scheduled" role="tabpanel">
<?php table('scheduled'); ?>

View file

@ -21,12 +21,16 @@ echo Bootstrap::formInputHidden(array(
'value' => $page->uuid()
));
// Type = article, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name' => 'state',
'value' => $page->state()
));
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => $contentTypeKey
));
// Cover image
echo Bootstrap::formInputHidden(array(
'name' => 'coverImage',
@ -44,18 +48,19 @@ echo Bootstrap::formInputHidden(array(
'name' => 'key',
'value' => $page->key()
));
echo Bootstrap::pageTitle(array('title'=>$L->g("Edit")." (".$contentType->plural().")", 'icon'=>$contentType->icon()));
?>
<?php if ($page->scheduled()) : ?>
<div class="alert alert-info"><?php $L->p('scheduled') ?>: <?php echo $page->date(SCHEDULED_DATE_FORMAT) ?></div>
<?php endif; ?>
<div class="row">
<!-- TOOLBAR -->
<div class="mb-3 col-lg-6">
<button type="button" class="btn btn-light" data-bs-toggle="modal" data-bs-target="#jsmediaManagerModal"><span class="fa fa-image"></span> <?php $L->p('Images') ?></button>
<button id="jsbuttonPreview" type="button" class="btn btn-secondary"><?php $L->p('Preview') ?></button>
<?php if ($page->scheduled()) : ?>
<div class="alert alert-warning p-1 mt-1 mb-0"><?php $L->p('scheduled') ?>: <?php echo $page->date(SCHEDULED_DATE_FORMAT) ?></div>
<?php endif; ?>
</div>
<div class="col-lg-6 text-end">
@ -126,25 +131,27 @@ echo Bootstrap::formInputHidden(array(
<div class="tab-content pr-3 pl-3 pb-3 card-body">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php
// Category
echo Bootstrap::formSelectBlock(array(
'name' => 'category',
'label' => $L->g('Category'),
'selected' => $page->categoryKey(),
'class' => '',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options' => $categories->getKeyNameArray(),
'mt'=>'mt-0'
));
// Tags
echo Bootstrap::formInputTextBlock(array(
'name' => 'tags',
'label' => $L->g('Tags'),
'placeholder' => '',
'tip' => $L->g('Write the tags separated by comma'),
'value' => $page->tags()
));
if ($contentTypeKey == "article") {
// Category
echo Bootstrap::formSelectBlock(array(
'name' => 'category',
'label' => $L->g('Category'),
'selected' => $page->categoryKey(),
'class' => '',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options' => $categories->getKeyNameArray(),
'mt'=>'mt-0'
));
// Tags
echo Bootstrap::formInputTextBlock(array(
'name' => 'tags',
'label' => $L->g('Tags'),
'placeholder' => '',
'tip' => $L->g('Write the tags separated by comma'),
'value' => $page->tags()
));
}
// Description
echo Bootstrap::formTextareaBlock(array(
@ -157,15 +164,17 @@ echo Bootstrap::formInputHidden(array(
'placeholder' => $L->get('this-field-can-help-describe-the-content')
));
// Sticky
echo Bootstrap::formCheckbox(array(
'name' => 'sticky',
'label' => $L->g('Sticky'),
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
'placeholder' => '',
'checked' => $page->sticky(),
'tip' => ""
));
if ($contentTypeKey == "article") {
// Sticky
echo Bootstrap::formCheckbox(array(
'name' => 'sticky',
'label' => $L->g('Sticky'),
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
'placeholder' => '',
'checked' => $page->sticky(),
'tip' => ""
));
}
?>
<!-- Cover Image -->
@ -214,18 +223,6 @@ echo Bootstrap::formInputHidden(array(
'mt'=>'mt-0'
));
// Type
echo Bootstrap::formSelectBlock(array(
'name' => 'type',
'label' => $L->g('Type'),
'selected' => $page->type(),
'options' => array(
'article' => '- ' . $L->g('Default') . ' -',
'static' => $L->g('Static')
),
'tip' => ''
));
// Position
echo Bootstrap::formInputTextBlock(array(
'name' => 'position',

View file

@ -27,6 +27,11 @@ echo Bootstrap::formInputHidden(array(
'value' => 'published'
));
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => $contentTypeKey
));
// Cover image
echo Bootstrap::formInputHidden(array(
'name' => 'coverImage',
@ -38,7 +43,10 @@ echo Bootstrap::formInputHidden(array(
'name' => 'content',
'value' => ''
));
echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural().")", 'icon'=>$contentType->icon()));
?>
<div class="row">
<!-- TOOLBAR -->
@ -116,24 +124,26 @@ echo Bootstrap::formInputHidden(array(
<div class="tab-content pr-3 pl-3 pb-3">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php
// Category
echo Bootstrap::formSelectBlock(array(
'name' => 'category',
'label' => $L->g('Category'),
'selected' => '',
'class' => '',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options' => $categories->getKeyNameArray(),
'mt' => 'mt-0'
));
if ($contentTypeKey == "article") {
// Category
echo Bootstrap::formSelectBlock(array(
'name' => 'category',
'label' => $L->g('Category'),
'selected' => '',
'class' => '',
'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options' => $categories->getKeyNameArray(),
'mt' => 'mt-0'
));
// Tags
echo Bootstrap::formInputTextBlock(array(
'name' => 'tags',
'label' => $L->g('Tags'),
'placeholder' => '',
'tip' => $L->g('Write the tags separated by comma')
));
// Tags
echo Bootstrap::formInputTextBlock(array(
'name' => 'tags',
'label' => $L->g('Tags'),
'placeholder' => '',
'tip' => $L->g('Write the tags separated by comma')
));
}
// Description
echo Bootstrap::formTextareaBlock(array(
@ -145,6 +155,18 @@ echo Bootstrap::formInputHidden(array(
'rows' => 5,
'placeholder' => $L->get('this-field-can-help-describe-the-content')
));
if ($contentTypeKey == "article") {
// Sticky
echo Bootstrap::formCheckbox(array(
'name' => 'sticky',
'label' => $L->g('Sticky'),
'labelForCheckbox' => $L->g('Put this article in first position in the article list.'),
'placeholder' => '',
'checked' => false,
'tip' => ""
));
}
?>
<!-- Cover Image -->
@ -185,18 +207,6 @@ echo Bootstrap::formInputHidden(array(
'mt' => 'mt-0'
));
// Type
echo Bootstrap::formSelectBlock(array(
'name' => 'type',
'label' => $L->g('Type'),
'selected' => '',
'options' => array(
'article' => '- ' . $L->g('Default') . ' -',
'static' => $L->g('Static')
),
'tip' => ''
));
// Position
echo Bootstrap::formInputTextBlock(array(
'name' => 'position',