Rework articles handling #35

Merged
kazhnuz merged 25 commits from feat/new-formats into koblog 2025-01-25 17:02:40 +01:00
49 changed files with 967 additions and 381 deletions

View file

@ -5,6 +5,7 @@
// ============================================================================
checkRole(array('admin', 'editor', 'author'));
global $pagetypes;
// ============================================================================
// Functions
@ -35,12 +36,23 @@ function filterContentOwner($list) {
// Main after POST
// ============================================================================
$published = $pages->getList($url->pageNumber(), ITEMS_PER_PAGE_ADMIN);
$drafts = $pages->getDraftDB(true);
$scheduled = $pages->getScheduledDB(true);
$static = $pages->getStaticDB(true);
$sticky = $pages->getStickyDB(true);
$autosave = $pages->getAutosaveDB(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)) {
@ -48,12 +60,11 @@ if (checkRole(array('author'), false)) {
$drafts = filterContentOwner($drafts);
$scheduled = filterContentOwner($scheduled);
$static = filterContentOwner($static);
$sticky = filterContentOwner($sticky);
}
// Check if out of range the pageNumber
if (empty($published) && $url->pageNumber()>1) {
Redirect::page('content');
Redirect::page('content/'.$contentTypeKey);
}
// Title of the page

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
// ============================================================================
@ -38,9 +53,10 @@ if (checkRole(array('author'), false)) {
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['type']==='delete') {
if ($_POST['state']==='delete') {
if (deletePage($_POST['key'])) {
Alert::set( $L->g('The changes have been saved') );
Redirect::page('content/'.$contentTypeKey);
}
} else {
$key = editPage($_POST);

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,9 +8,8 @@ function table($type) {
global $published;
global $drafts;
global $scheduled;
global $static;
global $sticky;
global $autosave;
global $contentType;
if ($type=='published') {
$list = $published;
@ -36,22 +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=='sticky') {
$list = $sticky;
if (empty($list)) {
echo '<p class="alert alert-warning">';
echo $L->g('There are no sticky pages at this moment.');
echo '</p>';
return false;
}
} elseif ($type=='autosave') {
$list = $autosave;
}
@ -64,7 +47,7 @@ function table($type) {
<th class="border-0" scope="col">'.$L->g('Title').'</th>
';
if ($type=='published' || $type=='static' || $type=='sticky') {
if ($type=='published') {
echo '<th class="border-0 d-none d-lg-table-cell" scope="col">'.$L->g('URL').'</th>';
}
@ -74,33 +57,38 @@ 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);
if (!$page->isChild()) {
echo '<tr class="card-tablebody">
<td>
<div>
<a style="font-size: 1.1em" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$L->g('Empty title').'</span> ')
.'</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>
<div class="d-flex align-items-center">'
.($page->sticky()?'<div><span><i class="fa fa-fw fa-thumbtack text-secondary"></i></span></div> ':'')
.'<div>
<div>
<a style="font-size: 1.1em" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$L->g('Empty title').'</span> ')
.'</a>
</div>
<div>
<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' || $type=='sticky') {
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>';
}
echo '<td class="contentTools pt-3 text-end d-sm-table-cell">'.PHP_EOL;
echo '<td class="contentTools p-2 text-end d-sm-table-cell">'.PHP_EOL;
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;
if (count($page->children())==0) {
echo '<a href="#" class="ms-2 btn btn-sm btn-danger deletePageButton d-block d-sm-inline" data-toggle="modal" data-target="#jsdeletePageModal" data-key="'.$page->key().'"><i class="fa fa-trash"></i>'.$L->g('Delete').'</a>'.PHP_EOL;
echo '<a href="#" class="ms-2 btn btn-sm btn-danger deletePageButton d-block d-sm-inline" data-bs-toggle="modal" data-bs-target="#jsdeletePageModal" data-key="'.$page->key().'"><i class="fa fa-trash"></i>'.$L->g('Delete').'</a>'.PHP_EOL;
}
echo '</td>';
@ -120,17 +108,17 @@ function table($type) {
</div>
</td>';
if ($type=='published' || $type=='static' || $type=='sticky') {
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 pt-3 text-end d-sm-table-cell">'.PHP_EOL;
if ($type=='published' || $type=='static' || $type=='sticky') {
echo '<td class="contentTools p-2 text-end d-sm-table-cell">'.PHP_EOL;
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;
echo '<a class="ms-2 btn btn-sm btn-danger deletePageButton d-block d-sm-inline" href="#" data-toggle="modal" data-target="#jsdeletePageModal" data-key="'.$child->key().'"><i class="fa fa-trash"></i>'.$L->g('Delete').'</a>'.PHP_EOL;
echo '<a class="ms-2 btn btn-sm btn-danger deletePageButton d-block d-sm-inline" href="#" data-bs-toggle="modal" data-bs-target="#jsdeletePageModal" data-key="'.$child->key().'"><i class="fa fa-trash"></i>'.$L->g('Delete').'</a>'.PHP_EOL;
echo '</td>';
echo '</tr>';
@ -146,24 +134,28 @@ function table($type) {
try {
$page = new Page($pageKey);
echo '<tr class="card-tablebody">';
echo '<td class="pt-3">
<div>
<a style="font-size: 1.1em" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$L->g('Empty title').'</span> ')
.'</a>
</div>
<div>
<p style="font-size: 0.8em" class="m-0 text-uppercase text-muted">'.( ($type=='scheduled')?$L->g('Scheduled').': '.$page->date(SCHEDULED_DATE_FORMAT):$page->date(MANAGE_CONTENT_DATE_FORMAT) ).'</p>
</div>
echo '<td class="p-2">
<div class="d-flex align-items-center">'
.($page->sticky()?'<div><span><i class="fa fa-fw fa-thumbtack text-secondary"></i></span></div> ':'')
.'<div>
<div>'
.'<a style="font-size: 1.1em" href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
.($page->title()?$page->title():'<span class="label-empty-title">'.$L->g('Empty title').'</span> ')
.'</a>
</div>
<div>
<p style="font-size: 0.8em" class="m-0 text-uppercase text-muted">'.( ($type=='scheduled')?$L->g('Scheduled').': '.$page->date(SCHEDULED_DATE_FORMAT):$page->date(MANAGE_CONTENT_DATE_FORMAT) ).'</p>
</div>
</div>
</td>';
if ($type=='published' || $type=='static' || $type=='sticky') {
if ($type=='published') {
$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
echo '<td class="pt-3 d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
echo '<td class="p-2 d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
}
echo '<td class="contentTools pt-3 text-end d-sm-table-cell">'.PHP_EOL;
if ($type=='published' || $type=='static' || $type=='sticky') {
echo '<td class="contentTools p-2 text-end d-sm-table-cell">'.PHP_EOL;
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;
@ -190,23 +182,17 @@ function table($type) {
<!-- TABS -->
<ul class="nav nav-pills mb-3" role="tablist">
<li class="nav-item" role="presentation">
<li class="nav-item me-2" 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 class="nav-item me-2" 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>
<li class="nav-item" role="presentation">
<button class="nav-link" id="sticky-tab" data-bs-toggle="tab" data-bs-target="#sticky" role="tab"><?php $L->p('Sticky') ?></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-primary">'.count($scheduled).'</span>'; } ?></button>
</li>
<li class="nav-item" role="presentation">
<li class="nav-item me-2" role="presentation">
<button class="nav-link" id="draft-tab" data-bs-toggle="tab" data-bs-target="#draft" role="tab"><?php $L->p('Draft') ?></button>
</li>
<?php if (!empty($autosave)): ?>
<li class="nav-item" role="presentation">
<li class="nav-item me-2" role="presentation">
<button class="nav-link" id="autosave-tab" data-bs-toggle="tab" data-bs-target="#autosave" role="tab"><?php $L->p('Autosave') ?></button>
</li>
<?php endif; ?>
@ -247,16 +233,6 @@ function table($type) {
<?php endif; ?>
</div>
<!-- TABS STATIC -->
<div class="tab-pane" id="static" role="tabpanel">
<?php table('static'); ?>
</div>
<!-- TABS STICKY -->
<div class="tab-pane" id="sticky" role="tabpanel">
<?php table('sticky'); ?>
</div>
<!-- TABS SCHEDULED -->
<div class="tab-pane" id="scheduled" role="tabpanel">
<?php table('scheduled'); ?>
@ -313,7 +289,7 @@ $(document).ready(function() {
'value': key
}).append(jQuery('<input>', {
'type': 'hidden',
'name': 'type',
'name': 'state',
'value': 'delete'
}))));

View file

@ -21,10 +21,14 @@ echo Bootstrap::formInputHidden(array(
'value' => $page->uuid()
));
// Type = published, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name' => 'state',
'value' => $page->state()
));
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => $page->type()
'value' => $contentTypeKey
));
// Cover image
@ -44,23 +48,24 @@ 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>
<span id="jsswitchButton" data-switch="<?php echo ($page->draft() ? 'draft' : 'publish') ?>" class="ms-2 btn-outline-<?php echo ($page->draft() ? 'light' : 'success') ?> btn"><?php echo ($page->draft() ? $L->g('Draft') : $L->g('Publish')) ?></span>
<?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; ?>
<button id="jsbuttonPreview" type="button" class="btn btn-secondary"><?php $L->p('Preview') ?></button>
</div>
<div class="col-lg-6 text-end">
<button id="jsbuttonPreview" type="button" class="btn btn-secondary"><?php $L->p('Preview') ?></button>
<button type="button" class="btn btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button>
<button type="button" class="btn btn-secondary" id="jsbuttonDraft" ><?php $L->p('Draft') ?></button>
<button type="button" class="btn btn-primary" id="jsbuttonSave"><?php echo $L->g('Publish') ?></button>
</div>
</div>
@ -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(
@ -156,6 +163,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' => $page->sticky(),
'tip' => ""
));
}
?>
<!-- Cover Image -->
@ -204,19 +223,6 @@ echo Bootstrap::formInputHidden(array(
'mt'=>'mt-0'
));
// Type
echo Bootstrap::formSelectBlock(array(
'name' => 'typeSelector',
'label' => $L->g('Type'),
'selected' => $page->type(),
'options' => array(
'published' => '- ' . $L->g('Default') . ' -',
'sticky' => $L->g('Sticky'),
'static' => $L->g('Static')
),
'tip' => ''
));
// Position
echo Bootstrap::formInputTextBlock(array(
'name' => 'position',
@ -450,7 +456,7 @@ foreach ($customFields as $field => $options) {
<script>
$(document).ready(function() {
$("#jsbuttonDeleteAccept").on("click", function() {
$("#jstype").val("delete");
$("#jsstate").val("delete");
$("#jscontent").val("");
$("#jsform").submit();
});
@ -484,26 +490,14 @@ foreach ($customFields as $field => $options) {
};
}
// Button switch
$("#jsswitchButton").on("click", function() {
if ($(this).data("switch") == "publish") {
$(this).html('<?php $L->p('Draft') ?>');
$(this).data("switch", "draft");
$(this).attr('class', "ms-2 btn-outline-secondary btn");
} else {
$(this).html('<?php $L->p('Publish') ?>');
$(this).data("switch", "publish");
$(this).attr('class', "ms-2 btn-outline-success btn");
}
});
// Button preview
$("#jsbuttonPreview").on("click", function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var type = $("#jstype").val();
var content = editorGetContent();
var ajax = new koblogAjax();
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $page->uuid() . '?preview=' . md5('autosave-' . $page->uuid()) ?>", "koblog-preview");
preview.focus();
});
@ -511,13 +505,7 @@ foreach ($customFields as $field => $options) {
// Button Save
$("#jsbuttonSave").on("click", function() {
// If the switch is setted to "published", get the value from the selector
if ($("#jsswitchButton").data("switch") == "publish") {
var value = $("#jstypeSelector option:selected").val();
$("#jstype").val(value);
} else {
$("#jstype").val("draft");
}
$("#jsstate").val("published");
// Get the content
$("#jscontent").val(editorGetContent());
@ -529,7 +517,7 @@ foreach ($customFields as $field => $options) {
// Button Save as draft
$("#jsbuttonDraft").on("click", function() {
// Set the type as draft
$("#jstype").val("draft");
$("#jsstate").val("draft");
// Get the content
$("#jscontent").val(editorGetContent());
@ -544,6 +532,7 @@ foreach ($customFields as $field => $options) {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var content = editorGetContent();
var type = $("#jstype").val();
// Autosave when content has at least 100 characters
if (content.length < 100) {
return false;
@ -551,7 +540,7 @@ foreach ($customFields as $field => $options) {
// Autosave only when the user change the content
if (currentContent != content) {
currentContent = content;
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
if (data.status == 0) {
showAlert("<?php $L->p('Autosave') ?>");
}

View file

@ -11,13 +11,13 @@ echo Bootstrap::formInputHidden(array(
echo '
<div class="form-group">
<input type="text" dir="auto" value="' . (isset($_POST['username']) ? Sanitize::html($_POST['username']) : '') . '" class="form-control form-control-lg" id="jsusername" name="username" placeholder="' . $L->g('Username') . '" autofocus>
<input type="text" dir="auto" value="' . (isset($_POST['username']) ? Sanitize::html($_POST['username']) : '') . '" class="form-control form-control-lg mb-2" id="jsusername" name="username" placeholder="' . $L->g('Username') . '" autofocus>
</div>
';
echo '
<div class="form-group">
<input type="password" class="form-control form-control-lg" id="jspassword" name="password" placeholder="' . $L->g('Password') . '">
<input type="password" class="form-control form-control-lg mb-2" id="jspassword" name="password" placeholder="' . $L->g('Password') . '">
</div>
';
@ -34,4 +34,4 @@ echo '
echo '</form>';
echo '<p class="mt-3 text-right">' . $L->g('Powered by Koblog') . '</p>';
echo '<p class="mt-3 text-end">' . $L->g('Powered by Koblog') . '</p>';

View file

@ -21,10 +21,15 @@ echo Bootstrap::formInputHidden(array(
'value' => $uuid
));
// Type = published, draft, sticky, static
// Type = article, draft, sticky, static
echo Bootstrap::formInputHidden(array(
'name' => 'state',
'value' => 'published'
));
echo Bootstrap::formInputHidden(array(
'name' => 'type',
'value' => 'published'
'value' => $contentTypeKey
));
// Cover image
@ -38,17 +43,20 @@ echo Bootstrap::formInputHidden(array(
'name' => 'content',
'value' => ''
));
echo Bootstrap::pageTitle(array('title'=>$L->g("New")." (".$contentType->plural().")", 'icon'=>$contentType->icon()));
?>
<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>
<span id="jsswitchButton" data-switch="publish" class="ms-2 btn-outline-success btn"><?php $L->p('Publish') ?></span>
<button id="jsbuttonPreview" type="button" class="btn btn-secondary"><?php $L->p('Preview') ?></button>
</div>
<div class="col-lg-6 text-end">
<button id="jsbuttonPreview" type="button" class="btn btn-secondary"><?php $L->p('Preview') ?></button>
<button type="button" class="btn btn-secondary" id="jsbuttonDraft"><?php $L->p('Draft') ?></button>
<button type="button" class="btn btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button>
</div>
</div>
@ -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,19 +207,6 @@ echo Bootstrap::formInputHidden(array(
'mt' => 'mt-0'
));
// Type
echo Bootstrap::formSelectBlock(array(
'name' => 'typeSelector',
'label' => $L->g('Type'),
'selected' => '',
'options' => array(
'published' => '- ' . $L->g('Default') . ' -',
'sticky' => $L->g('Sticky'),
'static' => $L->g('Static')
),
'tip' => ''
));
// Position
echo Bootstrap::formInputTextBlock(array(
'name' => 'position',
@ -439,25 +448,13 @@ foreach ($customFields as $field => $options) {
};
}
// Button switch
$("#jsswitchButton").on("click", function() {
if ($(this).data("switch") == "publish") {
$(this).html('<?php $L->p('Draft') ?>');
$(this).data("switch", "draft");
$(this).attr('class', "ms-2 btn-outline-secondary btn");
} else {
$(this).html('<?php $L->p('Publish') ?>');
$(this).data("switch", "publish");
$(this).attr('class', "ms-2 btn-outline-success btn");
}
});
// Button preview
$("#jsbuttonPreview").on("click", function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val();
var type = $("#jstype").val();
var content = editorGetContent();
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $uuid . '?preview=' . md5('autosave-' . $uuid) ?>", "koblog-preview");
preview.focus();
});
@ -467,15 +464,24 @@ foreach ($customFields as $field => $options) {
$("#jsbuttonSave").on("click", function() {
let actionParameters = '';
// If the switch is setted to "published", get the value from the selector
if ($("#jsbuttonSwitch").data("switch") == "publish") {
var value = $("#jstypeSelector option:selected").val();
$("#jstype").val(value);
actionParameters = '#' + value;
} else {
$("#jstype").val("draft");
actionParameters = '#draft';
}
var value = "published"
$("#jsstate").val(value);
actionParameters = '#' + value;
// Get the content
$("#jscontent").val(editorGetContent());
// Submit the form
$("#jsform").attr('action', actionParameters);
$("#jsform").submit();
});
// Button Draft
$("#jsbuttonDraft").on("click", function() {
let actionParameters = '';
$("#jsstate").val("draft");
actionParameters = '#draft';
// Get the content
$("#jscontent").val(editorGetContent());
@ -490,6 +496,7 @@ foreach ($customFields as $field => $options) {
setInterval(function() {
var uuid = $("#jsuuid").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var type = $("#jstype").val();
var content = editorGetContent();
// Autosave when content has at least 100 characters
if (content.length < 100) {
@ -498,7 +505,7 @@ foreach ($customFields as $field => $options) {
// Autosave only when the user change the content
if (currentContent != content) {
currentContent = content;
koblogAjax.saveAsDraft(uuid, title, content).then(function(data) {
koblogAjax.saveAsDraft(uuid, title, type, content).then(function(data) {
if (data.status == 0) {
showAlert("<?php $L->p('Autosave') ?>");
}

View file

@ -22,7 +22,6 @@
<a class="nav-item nav-link" id="nav-social-tab" data-bs-toggle="tab" data-bs-target="#social" role="tab" aria-controls="nav-social" aria-selected="false"><?php $L->p('Social Networks') ?></a>
<a class="nav-item nav-link" id="nav-images-tab" data-bs-toggle="tab" data-bs-target="#images" role="tab" aria-controls="nav-images" aria-selected="false"><?php $L->p('Images') ?></a>
<a class="nav-item nav-link" id="nav-language-tab" data-bs-toggle="tab" data-bs-target="#language" role="tab" aria-controls="nav-language" aria-selected="false"><?php $L->p('Language') ?></a>
<a class="nav-item nav-link" id="nav-custom-fields-tab" data-bs-toggle="tab" data-bs-target="#custom-fields" role="tab" aria-controls="nav-custom-fields" aria-selected="false"><?php $L->p('Custom fields') ?></a>
<a class="nav-item nav-link" id="nav-logo-tab" data-bs-toggle="tab" data-bs-target="#logo" role="tab" aria-controls="nav-logo" aria-selected="false"><?php $L->p('Logo') ?></a>
</div>
</nav>
@ -298,6 +297,24 @@ echo Bootstrap::formInputHidden(array(
'tip' => DOMAIN_CATEGORIES
));
echo Bootstrap::formInputText(array(
'name' => 'uriArchive',
'label' => $L->g('Archive'),
'value' => $site->uriFilters('archive'),
'class' => '',
'placeholder' => '',
'tip' => DOMAIN_ARCHIVES
));
echo Bootstrap::formInputText(array(
'name' => 'uriAuthor',
'label' => $L->g('Authors'),
'value' => $site->uriFilters('author'),
'class' => '',
'placeholder' => '',
'tip' => DOMAIN_AUTHORS
));
echo Bootstrap::formInputText(array(
'name' => 'uriBlog',
'label' => $L->g('Blog'),
@ -606,26 +623,6 @@ echo Bootstrap::formInputHidden(array(
?>
</div>
<!-- Custom fields -->
<div class="tab-pane fade" id="custom-fields" role="tabpanel" aria-labelledby="custom-fields-tab">
<?php
echo Bootstrap::cardBegin($L->g('Custom fields'));
echo Bootstrap::formTextarea(array(
'name' => 'customFields',
'label' => 'JSON Format',
'value' => json_encode($site->customFields(), JSON_PRETTY_PRINT),
'class' => '',
'placeholder' => '',
'tip' => $L->g('define-custom-fields-for-the-content'),
'rows' => 15
));
echo Bootstrap::cardEnd();
?>
</div>
<!-- Site logo tab -->
<div class="tab-pane fade" id="logo" role="tabpanel" aria-labelledby="logo-tab">
<?php

View file

@ -4,23 +4,18 @@ header('Content-Type: application/json');
/*
| Search for pages that have in the title the string $query and returns the array of pages
|
| @_GET['published'] boolean True to search in published database
| @_GET['static'] boolean True to search in static database
| @_GET['sticky'] boolean True to search in sticky database
| @_GET['scheduled'] boolean True to search in scheduled database
| @_GET['draft'] boolean True to search in draft database
| @_GET['query'] string Text to search in the title
| @_GET['type'] the type to search in the database
| @_GET['state'] the state to search in the database
| @_GET['sticky'] boolean False to not search sticky post
|
| @return array
*/
// $_GET
// ----------------------------------------------------------------------------
$published = empty($_GET['published']) ? false:true;
$static = empty($_GET['static']) ? false:true;
$sticky = empty($_GET['sticky']) ? false:true;
$scheduled = empty($_GET['scheduled']) ? false:true;
$draft = empty($_GET['draft']) ? false:true;
$type = empty($GET_['type']) ? ['article'] : explode(",", $GET_['type']);
$state = empty($GET_['state']) ? ['published'] : explode(",", $GET_['state']);
$sticky = isset($_GET['sticky']) ? $_GET['sticky'] != false:true; // True by default
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
// ----------------------------------------------------------------------------
@ -30,7 +25,7 @@ if ($query===false) {
$pageNumber = 1;
$numberOfItems = -1;
$pagesKey = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
$pagesKey = $pages->getList($pageNumber, $numberOfItems, $type, $state, $sticky);
$tmp = array();
foreach ($pagesKey as $pageKey) {
try {

View file

@ -28,7 +28,7 @@ foreach ($pagesKey as $pageKey) {
$page = new Page($pageKey);
if ($page->isParent() || !$checkIsParent) {
// Check page status
if ($page->published() || $page->sticky() || $page->isStatic()) {
if ($page->published()) {
// Check if the query contains in the title
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {

View file

@ -18,7 +18,9 @@ header('Content-Type: application/json');
$title = isset($_POST['title']) ? $_POST['title'] : false;
$content = isset($_POST['content']) ? $_POST['content'] : false;
$uuid = isset($_POST['uuid']) ? $_POST['uuid'] : false;
$type = isset($_POST['type']) ? $_POST['type'] : 'draft';
$type = isset($_POST['type']) ? $_POST['type'] : 'article';
$type = isset($_POST['state']) ? $_POST['state'] : 'draft';
$type = isset($_POST['sticky']) ? $_POST['state'] : false;
// ----------------------------------------------------------------------------
// Check UUID
@ -32,7 +34,9 @@ $page = array(
'slug'=>$uuid,
'title'=>$title,
'content'=>$content,
'type'=>$type
'type'=>$type,
'state'=>$state,
'sticky'=>$sticky,
);
// Get the page key by the UUID

View file

@ -0,0 +1,49 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Archives extends dbList {
function __construct()
{
parent::__construct(DB_ARCHIVES);
}
function numberOfPages($key)
{
return $this->countItems($key);
}
public function reindex()
{
global $pages;
$db = $pages->getDB($onlyKeys=false);
$archiveIndex = array();
foreach ($db as $pageKey=>$pageFields) {
if ($pageFields['type'] == "article" && $pageFields['state'] == "published") {
$date = $pageFields['date'];
$year = mb_substr($date, 0, 4);
$month = mb_substr($date, 0, 7);
// Index by years
if (isset($archiveIndex[$year])) {
array_push($archiveIndex[$year]['list'], $pageKey);
} else {
$archiveIndex[$year]['name'] = $year;
$archiveIndex[$year]['list'] = array($pageKey);
}
// Index by month
if (isset($archiveIndex[$month])) {
array_push($archiveIndex[$month]['list'], $pageKey);
} else {
$archiveIndex[$month]['name'] = Date::prettyArchiveDate($month);
$archiveIndex[$month]['list'] = array($pageKey);
}
}
}
$this->db = $archiveIndex;
$this->sortAlphanumeric();
return $this->save();
}
}

View file

@ -0,0 +1,38 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class Authors extends dbList {
function __construct()
{
parent::__construct(DB_AUTHORS);
}
function numberOfPages($key)
{
return $this->countItems($key);
}
public function reindex()
{
global $pages;
$db = $pages->getDB($onlyKeys=false);
$authorsIndex = array();
foreach ($db as $pageKey=>$pageFields) {
if ($pageFields['type'] == "article" && $pageFields['state'] == "published") {
$authorName = $pageFields['username'];
if (isset($authorsIndex[$authorName])) {
array_push($authorsIndex[$authorName]['list'], $pageKey);
} else {
$user = new User($pageFields['username']);
$authorsIndex[$authorName]['name'] = $user->displayName();
$authorsIndex[$authorName]['list'] = array($pageKey);
}
}
}
$this->db = $authorsIndex;
$this->sortAlphanumeric();
return $this->save();
}
}

View file

@ -57,6 +57,7 @@ if ($layout['slug']==='ajax') {
else
{
// Boot rules
include(PATH_RULES.'50.updaters.php');
include(PATH_RULES.'69.pages.php');
include(PATH_RULES.'99.header.php');
include(PATH_RULES.'99.paginator.php');

View file

@ -63,9 +63,12 @@ define('DEBUG_FILE', PATH_CONTENT . 'debug.txt');
// PAGES DATABASE
define('DB_PAGES', PATH_DATABASES . 'pages.php');
define('DB_PAGE_TYPES', PATH_DATABASES . 'pagetypes.php');
define('DB_SITE', PATH_DATABASES . 'site.php');
define('DB_CATEGORIES', PATH_DATABASES . 'categories.php');
define('DB_TAGS', PATH_DATABASES . 'tags.php');
define('DB_AUTHORS', PATH_DATABASES . 'authors.php');
define('DB_ARCHIVES', PATH_DATABASES . 'archives.php');
define('DB_SYSLOG', PATH_DATABASES . 'syslog.php');
define('DB_USERS', PATH_DATABASES . 'users.php');
define('DB_SECURITY', PATH_DATABASES . 'security.php');
@ -85,13 +88,17 @@ include(PATH_ABSTRACT . 'dblist.class.php');
include(PATH_ABSTRACT . 'plugin.class.php');
// Inclde Classes
include(PATH_KERNEL . 'pagetypes.class.php');
include(PATH_KERNEL . 'pages.class.php');
include(PATH_KERNEL . 'users.class.php');
include(PATH_KERNEL . 'tags.class.php');
include(PATH_KERNEL . 'authors.class.php');
include(PATH_KERNEL . 'archives.class.php');
include(PATH_KERNEL . 'language.class.php');
include(PATH_KERNEL . 'site.class.php');
include(PATH_KERNEL . 'categories.class.php');
include(PATH_KERNEL . 'syslog.class.php');
include(PATH_KERNEL . 'pagetype.class.php');
include(PATH_KERNEL . 'pagex.class.php');
include(PATH_KERNEL . 'category.class.php');
include(PATH_KERNEL . 'tag.class.php');
@ -122,10 +129,16 @@ include(PATH_HELPERS . 'tcp.class.php');
include(PATH_HELPERS . 'dom.class.php');
include(PATH_HELPERS . 'cookie.class.php');
// Updaters
include(PATH_HELPERS . 'updater.class.php');
// Objects
$pagetypes = new PageTypes();
$pages = new Pages();
$users = new Users();
$tags = new Tags();
$authors = new Authors();
$archives = new Archives();
$categories = new Categories();
$site = new Site();
$url = new Url();
@ -191,6 +204,12 @@ define('TAG_URI_FILTER', $url->filters('tag'));
// Category URI filter
define('CATEGORY_URI_FILTER', $url->filters('category'));
// Author URI filter
define('AUTHOR_URI_FILTER', $url->filters('author'));
// Archive URI filter
define('ARCHIVE_URI_FILTER', $url->filters('archive'));
// Page URI filter
define('PAGE_URI_FILTER', $url->filters('page'));
@ -247,6 +266,8 @@ define('DOMAIN_ADMIN', DOMAIN_BASE . ADMIN_URI_FILTER . '/');
define('DOMAIN_TAGS', Text::addSlashes(DOMAIN_BASE . TAG_URI_FILTER, false, true));
define('DOMAIN_CATEGORIES', Text::addSlashes(DOMAIN_BASE . CATEGORY_URI_FILTER, false, true));
define('DOMAIN_PAGES', Text::addSlashes(DOMAIN_BASE . PAGE_URI_FILTER, false, true));
define('DOMAIN_AUTHORS', Text::addSlashes(DOMAIN_BASE . AUTHOR_URI_FILTER, false, true));
define('DOMAIN_ARCHIVES', Text::addSlashes(DOMAIN_BASE . ARCHIVE_URI_FILTER, false, true));
$ADMIN_CONTROLLER = '';
$ADMIN_VIEW = '';

View file

@ -0,0 +1,15 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
// ============================================================================
// Variables
// ============================================================================
global $site;
// ============================================================================
// Main
// ============================================================================
if ($site->databaseVersion() < 2) {
KoblogUpdater::upgradeArticlesToPageTypes();
}

View file

@ -71,6 +71,14 @@ elseif ($url->whereAmI()==='tag') {
elseif ($url->whereAmI()==='category') {
$content = buildPagesByCategory();
}
// Build content by author
elseif ($url->whereAmI()==='author') {
$content = buildPagesByAuthor();
}
// Build content by author
elseif ($url->whereAmI()==='archive') {
$content = buildPagesByArchive();
}
// Build content for the homepage
elseif ( ($url->whereAmI()==='home') || ($url->whereAmI()==='blog') ) {
$content = buildPagesForHome();

View file

@ -7,6 +7,7 @@ include(PATH_RULES.'60.plugins.php');
Theme::plugins('beforeAll');
// Load rules
include(PATH_RULES.'50.updaters.php');
include(PATH_RULES.'60.router.php');
include(PATH_RULES.'69.pages.php');
include(PATH_RULES.'99.header.php');

View file

@ -103,9 +103,6 @@ define('MEDIA_MANAGER_SORT_BY_DATE', true);
// Constant arrays using define are not allowed in PHP 5.6 or earlier
// Type of pages included in the tag database
$GLOBALS['DB_TAGS_TYPES'] = array('published','static','sticky');
// Allowed image extensions
$GLOBALS['ALLOWED_IMG_EXTENSION'] = array('gif', 'png', 'jpg', 'jpeg', 'svg', 'webp');

View file

@ -27,11 +27,7 @@ class Categories extends dbList {
if (!empty($pageFields['category'])) {
$categoryKey = $pageFields['category'];
if (isset($this->db[$categoryKey]['list'])) {
if (
($db[$pageKey]['type']=='published') ||
($db[$pageKey]['type']=='sticky') ||
($db[$pageKey]['type']=='static')
) {
if ($db[$pageKey]['state']=='published') {
array_push($this->db[$categoryKey]['list'], $pageKey);
}
}

View file

@ -16,6 +16,22 @@ function reindexTags()
return $tags->reindex();
}
// Re-index database of authors
// If you create/edit/remove a page is necessary regenerate the database of authors
function reindexAuthors()
{
global $authors;
return $authors->reindex();
}
// Re-index database of archives
// If you create/edit/remove a page is necessary regenerate the database of archives
function reindexArchives()
{
global $archives;
return $archives->reindex();
}
// Generate the page 404 Not found
function buildErrorPage()
{
@ -84,36 +100,61 @@ function buildPagesByTag()
return buildPagesFor('tag', false, $tagKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
function buildPagesByAuthor()
{
global $url;
$authorKey = $url->slug();
return buildPagesFor('author', false, false, $authorKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
function buildPagesByArchive()
{
global $url;
$archiveKey = $url->slug();
return buildPagesFor('archive', false, false, false, $archiveKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
// Generate the global variables $content / $content, defined on 69.pages.php
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
function buildPagesFor($for, $categoryKey = false, $tagKey = false)
function buildPagesFor($for, $categoryKey = false, $tagKey = false, $authorKey = false, $archiveKey = false)
{
global $pages;
global $categories;
global $tags;
global $site;
global $url;
global $authors;
global $archives;
// Get the page number from URL
$pageNumber = $url->pageNumber();
if ($for == 'home') {
$onlyPublished = true;
$numberOfItems = $site->itemsPerPage();
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
$list = $pages->getList($pageNumber, $numberOfItems, ['article'], ['published'], true, true);
// Include sticky pages only in the first page
if ($pageNumber == 1) {
$sticky = $pages->getStickyDB();
$list = array_merge($sticky, $list);
}
// if ($pageNumber == 1) {
// $sticky = $pages->getStickyDB();
// $list = array_merge($sticky, $list);
// }
} elseif ($for == 'category') {
$numberOfItems = $site->itemsPerPage();
$list = $categories->getList($categoryKey, $pageNumber, $numberOfItems);
} elseif ($for == 'tag') {
$numberOfItems = $site->itemsPerPage();
$list = $tags->getList($tagKey, $pageNumber, $numberOfItems);
} elseif ($for == 'author') {
$numberOfItems = $site->itemsPerPage();
$list = $authors->getList($authorKey, $pageNumber, $numberOfItems);
} elseif ($for == 'archive') {
$numberOfItems = $site->itemsPerPage();
$list = $archives->getList($archiveKey, $pageNumber, $numberOfItems);
}
// There are not items, invalid tag, invalid category, out of range, etc...
@ -126,7 +167,7 @@ function buildPagesFor($for, $categoryKey = false, $tagKey = false)
foreach ($list as $pageKey) {
try {
$page = new Page($pageKey);
if (($page->type() == 'published') ||
if (($page->type() == 'article') ||
($page->type() == 'sticky') ||
($page->type() == 'static')
) {
@ -341,6 +382,8 @@ function createPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(
@ -392,6 +435,8 @@ function editPage($args)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(
@ -417,6 +462,8 @@ function deletePage($key)
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
// Add to syslog
$syslog->add(array(
@ -442,6 +489,8 @@ function editUser($args)
'notes' => $args['username']
));
reindexAuthors();
return true;
}
@ -475,6 +524,8 @@ function disableUser($args)
'notes' => $username
));
reindexAuthors();
return true;
}
@ -519,6 +570,8 @@ function deleteUser($args)
'notes' => $username
));
reindexAuthors();
return true;
}

View file

@ -2,6 +2,21 @@
class Date {
private const MONTHS = [
"01" => "January",
"02" => "February",
"03" => "March",
"04" => "April",
"05" => "May",
"06" => "June",
"07" => "July",
"08" => "August",
"09" => "September",
"10" => "October",
"11" => "November",
"12" => "December"
];
// Returns string with the date translated
// Example: $date = 'Mon, 27th March' > 'Lun, 27th Marzo'
public static function translate($date)
@ -127,4 +142,22 @@ class Date {
return $tmp;
}
private static function getMonthName($month) {
return isset(self::MONTHS[$month]) ? self::MONTHS[$month] : null;
}
public static function prettyArchiveDate($date) {
global $L;
$explodedDate = explode("-", $date);
try {
if (sizeof($explodedDate) > 2) {
return $date;
} else {
return self::translate(self::getMonthName($explodedDate[1])." ".$explodedDate[0]);
}
} catch (Exception $e) {
return $L->g("Invalid Date");
}
}
}

View file

@ -91,6 +91,55 @@ class Theme
return DOMAIN_ADMIN;
}
public static function locationTitle()
{
global $url;
global $site;
global $tags;
global $archives;
global $authors;
global $categories;
global $WHERE_AM_I;
global $page;
if ($WHERE_AM_I == 'page') {
return $page->title();
} elseif ($WHERE_AM_I == 'tag') {
try {
$tagKey = $url->slug();
$tag = new Tag($tagKey);
return $tag->name();
} catch (Exception $e) {
// Tag doesn't exist
}
} elseif ($WHERE_AM_I == 'category') {
try {
$categoryKey = $url->slug();
$category = new Category($categoryKey);
return $category->name();
} catch (Exception $e) {
// Category doesn't exist
}
} elseif ($WHERE_AM_I == 'archive') {
try {
$archiveKey = $url->slug();
return Date::prettyArchiveDate($archiveKey);
} catch (Exception $e) {
// Archive doesn't exist
}
} elseif ($WHERE_AM_I == 'author') {
try {
$authorKey = $url->slug();
$user = new User($authorKey);
return $user->displayName();
} catch (Exception $e) {
// Author doesn't exist
}
}
return null;
}
public static function metaTags($tag)
{
if ($tag == 'title') {
@ -105,6 +154,8 @@ class Theme
global $url;
global $site;
global $tags;
global $archives;
global $authors;
global $categories;
global $WHERE_AM_I;
global $page;
@ -131,6 +182,23 @@ class Theme
} catch (Exception $e) {
// Category doesn't exist
}
} elseif ($WHERE_AM_I == 'archive') {
try {
$archiveKey = $url->slug();
$format = $site->titleFormatArchive();
$format = Text::replace('{{archive-name}}', Date::prettyArchiveDate($archiveKey), $format);
} catch (Exception $e) {
// Archive doesn't exist
}
} elseif ($WHERE_AM_I == 'author') {
try {
$authorKey = $url->slug();
$user = new User($authorKey);
$format = $site->titleFormatAuthor();
$format = Text::replace('{{author-name}}', $user->displayName(), $format);
} catch (Exception $e) {
// Author doesn't exist
}
} else {
$format = $site->titleFormatHomepage();
}

View file

@ -0,0 +1,55 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class KoblogUpdater {
// Special function to upgrade
public static function upgradeArticlesToPageTypes()
{
$dataHead = "<?php defined('KOBLOG') or die('Koblog CMS.'); ?>" . PHP_EOL;
global $pages;
global $L;
foreach ($pages->db as $key => $fields) {
if ($fields['type'] === "published") {
$pages->db[$key]['type'] = "article";
$pages->db[$key]['state'] = "published";
} elseif ($fields['type'] === "draft") {
$pages->db[$key]['type'] = "article";
$pages->db[$key]['state'] = "draft";
} elseif ($fields['type'] === "autosave") {
$pages->db[$key]['type'] = "article";
$pages->db[$key]['state'] = "autosave";
} elseif ($fields['type'] === "scheduled") {
$pages->db[$key]['type'] = "article";
$pages->db[$key]['state'] = "scheduled";
} elseif ($fields['type'] === "sticky") {
$pages->db[$key]['type'] = "article";
$pages->db[$key]['state'] = "published";
$pages->db[$key]['sticky'] = true;
}
// S'il n'y a toujours rien, c'est qu'il est publié
if ($pages->db[$key]['state'] === null) {
$pages->db[$key]['state'] = "published";
}
// S'il n'y a toujours pas de sticky, c'est qu'il ne l'est pas
if ($pages->db[$key]['sticky'] === null) {
$pages->db[$key]['sticky'] = false;
}
}
//
if (!file_exists(PATH_DATABASES . 'pagetypes.php')) {
$data = array(
'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'file-text'),
'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'file'),
);
file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
}
return $pages->save();
}
}

View file

@ -1,6 +1,6 @@
class koblogAjax {
static async saveAsDraft(uuid, title, content) {
static async saveAsDraft(uuid, title, type, content) {
let url = HTML_PATH_ADMIN_ROOT+"ajax/save-as-draft"
try {
const response = await fetch(url, {
@ -14,7 +14,8 @@ class koblogAjax {
'uuid': "autosave-" + uuid,
'title': title,
'content': content,
'type': 'autosave'
'type': type,
'state': 'autosave'
}),
});
const json = await response.json();

View file

@ -9,7 +9,9 @@ class Pages extends dbJSON
'description' => '',
'username' => '',
'tags' => array(),
'type' => 'published', // published, static, draft, sticky, scheduled, autosave
'type' => 'article', // article, static
'state' => 'published', // draft, scheduled, autosave
'sticky' => false,
'date' => '',
'dateModified' => '',
'position' => 0,
@ -129,8 +131,8 @@ class Pages extends dbJSON
}
// Schedule page
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'published')) {
$row['type'] = 'scheduled';
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['state'] == 'published')) {
$row['state'] = 'scheduled';
}
// Create the directory
@ -244,8 +246,8 @@ class Pages extends dbJSON
$row['dateModified'] = Date::current(DB_DATE_FORMAT);
// Schedule page
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'published')) {
$row['type'] = 'scheduled';
if (($row['date'] > Date::current(DB_DATE_FORMAT)) && ($row['type'] == 'article')) {
$row['state'] = 'scheduled';
}
// Move the directory from old key to new key only if the keys are different
@ -395,14 +397,17 @@ class Pages extends dbJSON
return $tmp;
}
// Returns a database with published pages
// $onlyKeys = true; Returns only the pages keys
// $onlyKeys = false; Returns part of the database, I do not recommend use this
public function getPublishedDB($onlyKeys = true)
public function getFilteredDB($types = [], $states = [], $sticky = false, $onlyKeys)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'published') {
if (!empty($types) && !in_array($fields['type'], $types)) {
unset($tmp[$key]);
}
if (!empty($states) && !in_array($fields['state'], $states)) {
unset($tmp[$key]);
}
if (!$sticky && $fields['sticky'] == true) {
unset($tmp[$key]);
}
}
@ -412,16 +417,37 @@ class Pages extends dbJSON
return $tmp;
}
// Returns a database with published articles
// $onlyKeys = true; Returns only the pages keys
// $onlyKeys = false; Returns part of the database, I do not recommend use this
public function getPublishedDB($types = ['article'], $onlyKeys = true)
{
return $this->getFilteredDB($types, ['published'], true, $onlyKeys);
}
// Returns an array with a list of keys/database of draft pages
public function getDraftDB($types = ['article'], $onlyKeys = true)
{
return $this->getFilteredDB($types, ['draft'], true, $onlyKeys);
}
// Returns an array with a list of keys/database of autosave pages
public function getAutosaveDB($types = ['article'], $onlyKeys = true)
{
return $this->getFilteredDB($types, ['autosave'], true, $onlyKeys);
}
// Returns an array with a list of keys/database of scheduled pages
public function getScheduledDB($types = ['article'], $onlyKeys = true)
{
return $this->getFilteredDB($types, ['scheduled'], true, $onlyKeys);
}
// Returns an array with a list of keys/database of static pages
// By default the static pages are sort by position
public function getStaticDB($onlyKeys = true)
public function getStaticDB($states = ['published'], $onlyKeys = true)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'static') {
unset($tmp[$key]);
}
}
$tmp = $this->getFilteredDB(['static'], $states, false, false);
uasort($tmp, array($this, 'sortByPositionLowToHigh'));
if ($onlyKeys) {
return array_keys($tmp);
@ -429,57 +455,12 @@ class Pages extends dbJSON
return $tmp;
}
// Returns an array with a list of keys/database of draft pages
public function getDraftDB($onlyKeys = true)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'draft') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}
// Returns an array with a list of keys/database of autosave pages
public function getAutosaveDB($onlyKeys = true)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'autosave') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}
// Returns an array with a list of keys/database of scheduled pages
public function getScheduledDB($onlyKeys = true)
{
$tmp = $this->db;
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'scheduled') {
unset($tmp[$key]);
}
}
if ($onlyKeys) {
return array_keys($tmp);
}
return $tmp;
}
// Returns an array with a list of keys of sticky pages
public function getStickyDB($onlyKeys = true)
public function getStickyDB($types = ['article'], $states = ['published'], $onlyKeys = true)
{
$tmp = $this->db;
$tmp = $this->getFilteredDB($types, $states, true, false);
foreach ($tmp as $key => $fields) {
if ($fields['type'] != 'sticky') {
if ($fields['sticky'] == false) {
unset($tmp[$key]);
}
}
@ -504,12 +485,12 @@ class Pages extends dbJSON
// Returns the next page key of the current page key
public function nextPageKey($currentKey)
{
if ($this->db[$currentKey]['type'] == 'published') {
if ($this->db[$currentKey]['state'] == 'published') {
$keys = array_keys($this->db);
$position = array_search($currentKey, $keys) - 1;
if (isset($keys[$position])) {
$nextKey = $keys[$position];
if ($this->db[$nextKey]['type'] == 'published') {
if ($this->db[$nextKey]['type'] == $this->db[$currentKey]['type']) {
return $nextKey;
}
}
@ -520,12 +501,12 @@ class Pages extends dbJSON
// Returns the previous page key of the current page key
public function previousPageKey($currentKey)
{
if ($this->db[$currentKey]['type'] == 'published') {
if ($this->db[$currentKey]['state'] == 'published') {
$keys = array_keys($this->db);
$position = array_search($currentKey, $keys) + 1;
if (isset($keys[$position])) {
$prevKey = $keys[$position];
if ($this->db[$prevKey]['type'] == 'published') {
if ($this->db[$prevKey]['type'] == $this->db[$currentKey]['type']) {
return $prevKey;
}
}
@ -538,23 +519,16 @@ class Pages extends dbJSON
// (int) $pageNumber, the page number
// (int) $numberOfItems, amount of items to return, if -1 returns all the items
// (boolean) $onlyPublished, TRUE to return only published pages
public function getList($pageNumber, $numberOfItems, $published = true, $static = false, $sticky = false, $draft = false, $scheduled = false)
public function getList($pageNumber, $numberOfItems, $types = ['article'], $states = ['published'], $sticky = true, $sortHomepage = false)
{
$list = array();
foreach ($this->db as $key => $fields) {
if ($published && $fields['type'] == 'published') {
array_push($list, $key);
} elseif ($static && $fields['type'] == 'static') {
array_push($list, $key);
} elseif ($sticky && $fields['type'] == 'sticky') {
array_push($list, $key);
} elseif ($draft && $fields['type'] == 'draft') {
array_push($list, $key);
} elseif ($scheduled && $fields['type'] == 'scheduled') {
array_push($list, $key);
}
$tmp = $this->getFilteredDB($types, $states, $sticky, false);
if ($sortHomepage) {
uasort($tmp, array($this, 'sortHomepage'));
}
$list = array_keys($tmp);
if ($numberOfItems == -1) {
return $list;
}
@ -579,7 +553,7 @@ class Pages extends dbJSON
public function count($onlyPublished = true)
{
if ($onlyPublished) {
$db = $this->getPublishedDB(false);
$db = $this->getPublishedDB(['article'], false);
return count($db);
}
@ -672,6 +646,17 @@ class Pages extends dbJSON
return $a['date'] < $b['date'];
}
private function sortHomepage($a, $b)
{
if ($a['sticky'] && !$b['sticky']) {
return false;
} elseif (!$a['sticky'] && $b['sticky']) {
return true;
} else {
return $this->sortByDateHighToLow($a, $b);
}
}
function generateUUID()
{
return md5(uniqid() . time());
@ -719,10 +704,10 @@ class Pages extends dbJSON
foreach ($this->db as $pageKey => $fields) {
if ($fields['type'] == 'scheduled') {
if ($fields['date'] <= $currentDate) {
$this->db[$pageKey]['type'] = 'published';
$this->db[$pageKey]['type'] = 'article';
$saveDatabase = true;
}
} elseif (($fields['type'] == 'published') && (ORDER_BY == 'date')) {
} elseif (($fields['type'] == 'article') && (ORDER_BY == 'date')) {
break;
}
}

View file

@ -0,0 +1,61 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class PageType
{
protected $vars;
function __construct($type)
{
global $pagetypes;
$this->vars['type'] = $type;
if (Text::isEmpty($type) || !$pagetypes->exists($type)) {
$errorMessage = 'Page Type not found in the database [' . $type . ']';
Log::set(__METHOD__ . LOG_SEP . $errorMessage);
throw new Exception($errorMessage);
}
$row = $pagetypes->getTypeDB($type);
foreach ($row as $field => $value) {
$this->setField($field, $value);
}
}
public function getValue($field)
{
if (isset($this->vars[$field])) {
return $this->vars[$field];
}
return false;
}
public function setField($field, $value)
{
$this->vars[$field] = $value;
return true;
}
public function getDB()
{
return $this->vars;
}
public function type()
{
return $this->getValue("type");
}
public function icon()
{
return $this->getValue("icon");
}
public function name()
{
return $this->getValue("name");
}
public function plural()
{
return $this->getValue("plural");
}
}

View file

@ -0,0 +1,36 @@
<?php defined('KOBLOG') or die('Koblog CMS.');
class PageTypes extends dbJSON {
protected $dbFields = array(
'name'=>'',
'plural'=>'',
'icon'=>'fa-file'
);
function __construct()
{
parent::__construct(DB_PAGE_TYPES);
}
public function getDefaultFields()
{
return $this->dbFields;
}
// Return an array with the database of the user, FALSE otherwise
public function getTypeDB($type)
{
if ($this->exists($type)) {
return $this->db[$type];
}
return false;
}
// Return TRUE if the type exists, FALSE otherwise
public function exists($type)
{
return isset($this->db[$type]);
}
}

View file

@ -360,31 +360,37 @@ class Page
// (boolean) Returns TRUE if the page is published, FALSE otherwise
public function published()
{
return ($this->getValue('type') === 'published');
return ($this->getValue('state') === 'published');
}
// (boolean) Returns TRUE if the page is an article, FALSE otherwise
public function article()
{
return ($this->getValue('type') === 'article');
}
// (boolean) Returns TRUE if the page is scheduled, FALSE otherwise
public function scheduled()
{
return ($this->getValue('type') === 'scheduled');
return ($this->getValue('state') === 'scheduled');
}
// (boolean) Returns TRUE if the page is draft, FALSE otherwise
public function draft()
{
return ($this->getValue('type') == 'draft');
return ($this->getValue('state') == 'draft');
}
// (boolean) Returns TRUE if the page is autosave, FALSE otherwise
public function autosave()
{
return ($this->getValue('type') == 'autosave');
return ($this->getValue('state') == 'autosave');
}
// (boolean) Returns TRUE if the page is sticky, FALSE otherwise
public function sticky()
{
return ($this->getValue('type') == 'sticky');
return ($this->getValue('sticky'));
}
// (boolean) Returns TRUE if the page is static, FALSE otherwise
@ -399,6 +405,12 @@ class Page
return $this->getValue('type');
}
// (string) Returns state of the page
public function state()
{
return $this->getValue('state');
}
// Returns the title field
public function title()
{

View file

@ -19,6 +19,8 @@ class Site extends dbJSON
'uriTag' => '/tag/',
'uriCategory' => '/category/',
'uriBlog' => '/blog/',
'uriAuthor' => '/author/',
'uriArchive' => '/archive/',
'url' => '',
'emailFrom' => '',
'dateFormat' => 'F j, Y',
@ -43,6 +45,8 @@ class Site extends dbJSON
'titleFormatPages' => '{{page-title}} | {{site-title}}',
'titleFormatCategory' => '{{category-name}} | {{site-title}}',
'titleFormatTag' => '{{tag-name}} | {{site-title}}',
'titleFormatAuthor' => '{{author-name}} | {{site-title}}',
'titleFormatArchive' => '{{archive-name}} | {{site-title}}',
'imageRestrict' => true,
'imageRelativeToAbsolute' => false,
'thumbnailWidth' => 400, // px
@ -99,6 +103,8 @@ class Site extends dbJSON
$filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->getField('uriTag');
$filters['category'] = $this->getField('uriCategory');
$filters['author'] = $this->getField('uriAuthor');
$filters['archive'] = $this->getField(field: 'uriArchive');
if ($this->getField('uriBlog')) {
$filters['blog'] = $this->getField('uriBlog');
@ -318,6 +324,16 @@ class Site extends dbJSON
return $this->getField('titleFormatTag');
}
public function titleFormatArchive()
{
return $this->getField('titleFormatArchive');
}
public function titleFormatAuthor()
{
return $this->getField('titleFormatAuthor');
}
// Returns the absolute URL of the site logo
// If you set $absolute=false returns only the filename
public function logo($absolute = true)
@ -461,4 +477,10 @@ class Site extends dbJSON
$customFields = Sanitize::htmlDecode($this->getField('customFields'));
return json_decode($customFields, true);
}
// Returns the custom fields as array
public function databaseVersion()
{
return 1;
}
}

View file

@ -18,7 +18,7 @@ class Tags extends dbList {
$db = $pages->getDB($onlyKeys=false);
$tagsIndex = array();
foreach ($db as $pageKey=>$pageFields) {
if (in_array($pageFields['type'], $GLOBALS['DB_TAGS_TYPES'])) {
if ($pageFields['state'] == "published") {
$tags = $pageFields['tags'];
foreach ($tags as $tagKey=>$tagName) {
if (isset($tagsIndex[$tagKey])) {

View file

@ -75,6 +75,10 @@ class User
}
}
public function authorUri() {
return DOMAIN_AUTHORS . $this->username();
}
public function displayNameMode()
{
return $this->getValue('displayNameMode');

View file

@ -77,6 +77,7 @@
"settings": "Paramètres",
"general": "Généraux",
"advanced": "Avancé",
"new": "Nouveau",
"new-content": "Nouveau contenu",
"manage-content": "Gestionnaire de contenu",
"add-new-content": "Ajouter un nouveau contenu",
@ -166,6 +167,7 @@
"current-format": "Format actuel",
"version": "Version",
"author": "Auteur",
"authors": "Auteurs",
"activate": "Activer",
"deactivate": "Désactiver",
"edit-category": "Modifier la catégorie",
@ -261,6 +263,10 @@
"type": "Type",
"draft-content": "Contenu brouillon",
"post": "Article",
"article": "Article",
"articles": "Articles",
"static-page": "Page statique",
"static-pages": "Pages statiques",
"default": "Défaut",
"latest-content": "Dernier contenu",
"default-message": "Message par défaut",

View file

@ -352,16 +352,14 @@ class pluginAPI extends Plugin
global $pages;
// Parameters and the default values
$published = (isset($args['published']) ? $args['published'] == 'true' : true);
$static = (isset($args['static']) ? $args['static'] == 'true' : false);
$draft = (isset($args['draft']) ? $args['draft'] == 'true' : false);
$sticky = (isset($args['sticky']) ? $args['sticky'] == 'true' : false);
$scheduled = (isset($args['scheduled']) ? $args['scheduled'] == 'true' : false);
$types = (isset($args['type']) ? $args['type'] : ['article']);
$state = (isset($args['state']) ? $args['state'] : ['published']);
$sticky = (isset($args['sticky']) ? $args['sticky'] == 'true' : true);
$untagged = (isset($args['untagged']) ? $args['untagged'] == 'true' : false);
$numberOfItems = (isset($args['numberOfItems']) ? $args['numberOfItems'] : 10);
$pageNumber = (isset($args['pageNumber']) ? $args['pageNumber'] : 1);
$list = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
$list = $pages->getList($pageNumber, $numberOfItems, $types, $state, $sticky);
$tmp = array(
'status' => '0',

View file

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Archives list",
"description": "Shows all archives on the sidebar."
}
}

View file

@ -0,0 +1,9 @@
{
"plugin-data":
{
"name": "Liste des archives",
"description": "Affiche tous les archives sur la barre latérale."
},
"monthly": "Mensuel",
"show-archives-by-months":"Afficher les archives par mois"
}

View file

@ -0,0 +1,11 @@
{
"author": "Koblog",
"email": "",
"website": "https://plugins.koblog.com",
"version": "kb_0.0.1",
"releaseDate": "2025-01-25",
"license": "MIT",
"compatible": "kb_0.0.1",
"notes": "",
"type": "widget"
}

View file

@ -0,0 +1,69 @@
<?php
class pluginArchives extends Plugin
{
public function init()
{
$this->dbFields = array(
'label' => 'Archives',
'monthly' => false,
);
}
public function form()
{
global $L;
$html = '<div>';
$html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>';
echo Bootstrap::formCheckbox(array(
'name' => 'monthly',
'label' => $L->g('Monthly'),
'labelForCheckbox' => $L->g('Show archives by months.'),
'placeholder' => '',
'checked' => $this->getValue('monthly'),
'tip' => ""
));
return $html;
}
public function siteSidebar()
{
global $L;
global $archives;
global $url;
$filter = $url->filters('archive');
$html = '<div class="plugin plugin-archives">';
$html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">';
$html .= '<ul>';
// By default the database of tags are alphanumeric sorted
foreach ($archives->db as $key => $fields) {
if (
($this->getValue('monthly') && strlen($key) != 4)
|| (!$this->getValue('monthly') && strlen($key) == 4)
) {
$html .= '<li class="flat-list">';
$html .= '<a href="' . DOMAIN_ARCHIVES . $key . '">';
$html .= $fields['name'];
$html .= '</a>';
$html .= '</li>';
}
}
$html .= '</ul>';
$html .= '</div>';
$html .= '</div>';
return $html;
}
}

View file

@ -62,7 +62,7 @@ class pluginDisqus extends Plugin
if ($WHERE_AM_I === 'page') {
global $page;
if ($page->published() && $this->getValue('enablePages')) {
if ($page->article() && $this->getValue('enablePages')) {
return $this->javascript();
}
if ($page->isStatic() && $this->getValue('enableStatic')) {

View file

@ -95,10 +95,9 @@ class pluginNavigation extends Plugin
// Pages order by date
else {
// List of published pages
$onlyPublished = true;
$pageNumber = 1;
$numberOfItems = $this->getValue('numberOfItems');
$publishedPages = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
$publishedPages = $pages->getList($pageNumber, $numberOfItems, ['article'], ['published']);
foreach ($publishedPages as $pageKey) {
try {

View file

@ -154,6 +154,8 @@ EOF;
Theme::plugins('afterPageCreate');
reindexCategories();
reindexTags();
reindexAuthors();
reindexArchives();
}
return true;

View file

@ -50,11 +50,9 @@ class pluginRSS extends Plugin
$list = $pages->getList(
$pageNumber = 1,
$numberOfItems,
$published = true,
$static = true,
$sticky = true,
$draft = false,
$scheduled = false
$type = ['article'],
$state = ['published'],
$sticky = true
);
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';

View file

@ -187,7 +187,7 @@ EOF;
{
// Get all pages published
global $pages;
$list = $pages->getList($pageNumber = 1, $numberOfItems = -1, $published = true, $static = true, $sticky = true, $draft = false, $scheduled = false);
$list = $pages->getList($pageNumber = 1, $numberOfItems = -1, $type = []);
$cache = array();
foreach ($list as $pageKey) {

View file

@ -53,7 +53,7 @@ class pluginSitemap extends Plugin {
$xml .= '<loc>'.$site->url().'</loc>';
$xml .= '</url>';
$list = $pages->getList($pageNumber=1, $numberOfItems=-1, $published=true, $static=true, $sticky=true, $draft=false, $scheduled=false);
$list = $pages->getList($pageNumber=1, $numberOfItems=-1, [], ['published'], true, false);
foreach ($list as $pageKey) {
try {
// Create the page object from the page key

View file

@ -47,6 +47,10 @@
<?php endif ?>
<!-- End Search input -->
<?php if (Theme::locationTitle()): ?>
<h2><?php echo Theme::locationTitle(); ?></h2>
<?php endif; ?>
<!-- Content not available -->
<?php if (empty($content)) : ?>
<div class="text-center p-4">

View file

@ -8,13 +8,13 @@
<?php if (!$page->isStatic() && !$url->notFound()) : ?>
<div class="form-text mb-2">
<!-- Page creation time -->
<span class="pr-3"><i class="bi bi-calendar"></i><?php echo $page->date() ?></span>
<span class="pe-3"><i class="bi bi-calendar"></i><?php echo $page->date() ?></span>
<!-- Page reading time -->
<span class="pr-3"><i class="bi bi-clock"></i><?php echo $page->readingTime() . ' ' . $L->get('minutes') . ' ' . $L->g('read') ?></span>
<span class="pe-3"><i class="bi bi-clock"></i><?php echo $page->readingTime() . ' ' . $L->get('minutes') . ' ' . $L->g('read') ?></span>
<!-- Page author -->
<span><i class="bi bi-person"></i><?php echo $page->user('displayName') ?></span>
<span><a href="<?php echo $page->user('authorUri'); ?>"><i class="bi bi-person"></i><?php echo $page->user('displayName') ?></a></span>
</div>
<?php endif ?>

View file

@ -334,7 +334,7 @@ function install($adminPassword, $timezone)
'description' => '',
'username' => 'admin',
'tags' => array(),
'type' => (($slug == 'example-page-4-slug') ? 'static' : 'published'),
'type' => (($slug == 'example-page-4-slug') ? 'static' : 'article'),
'date' => $nextDate,
'dateModified' => '',
'allowComments' => true,
@ -468,6 +468,12 @@ function install($adminPassword, $timezone)
);
file_put_contents(PATH_DATABASES . 'categories.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
$data = array(
'article' => array('name' => $L->g("Article"), 'plural' => $L->g("Articles"), 'icon'=>'fa-file-text'),
'static' => array('name' => $L->g("Static page"), 'plural' => $L->g("Static pages"), 'icon'=>'fa-file'),
);
file_put_contents(PATH_DATABASES . 'pagetypes.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// File tags.php
$data = array();
file_put_contents(PATH_DATABASES . 'tags.php', $dataHead . json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);