add possibility to manage tags like categories

This commit is contained in:
Manuel Kammermann 2019-01-26 22:43:25 +01:00
parent ec63c0ac22
commit 16a055cf03
13 changed files with 385 additions and 1 deletions

View File

@ -0,0 +1,44 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
checkRole(array('admin'));
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['action']=='delete') {
deleteTag($_POST);
} elseif ($_POST['action']=='edit') {
editTag($_POST);
}
Redirect::page('tags');
}
// ============================================================================
// Main after POST
// ============================================================================
$tagKey = $layout['parameters'];
if (!$tags->exists($tagKey)) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the tag: '.$tagKey);
Redirect::page('tags');
}
$tagMap = $tags->getMap($tagKey);
// Title of the page
$layout['title'] .= ' - '.$L->g('Edit Tag').' [ '.$tagMap['name'] . ' ] ';

View File

@ -0,0 +1,32 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
checkRole(array('admin'));
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (createTag($_POST)) {
Redirect::page('tags');
}
}
// ============================================================================
// Main after POST
// ============================================================================
// Title of the page
$layout['title'] .= ' - '.$L->g('New tag');

View File

@ -0,0 +1,26 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
checkRole(array('admin'));
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
// Title of the page
$layout['title'] .= ' - '.$L->g('Tags');

View File

@ -28,6 +28,10 @@
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>"> <a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>">
<?php $L->p('Categories') ?></a> <?php $L->p('Categories') ?></a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'tags' ?>">
<?php $L->p('Tags') ?></a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>"> <a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>">
<?php $L->p('Users') ?></a> <?php $L->p('Users') ?></a>

View File

@ -38,6 +38,9 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>"><?php $L->p('Categories') ?></a> <a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>"><?php $L->p('Categories') ?></a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'tags' ?>"><?php $L->p('Tags') ?></a>
</li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>"><?php $L->p('Users') ?></a> <a class="nav-link" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>"><?php $L->p('Users') ?></a>
</li> </li>

View File

@ -385,6 +385,32 @@ EOF;
return <<<EOF return <<<EOF
<div class="$class" role="alert">$text</div> <div class="$class" role="alert">$text</div>
EOF;
}
public static function linkedPagesTable($pagesArray){
global $pages;
global $L;
$rows = array();
$headingTemplate = '<tr><th>%s</th><th>%s</th><th>%s</th></tr>';
$heading = sprintf($headingTemplate, $L->g('Page'), $L->g('Url'), $L->g('Type'));
$elemTemplate = '<tr><td><a href="%s" title="%s" target="_blank">%s</a></td><td><a href="%s" title="%s" target="_blank">%s</a></td><td>%s</td></tr>';
foreach($pagesArray as $pageKey){
$tmpPage = new Page($pageKey);
if($tmpPage){
$rows[] = sprintf($elemTemplate, $tmpPage->slug(), $tmpPage->title(), $tmpPage->title(), $tmpPage->slug(), $tmpPage->slug(), $tmpPage->slug(), $tmpPage->type());
}
}
$rows = implode('', $rows);
return <<<EOF
<table class="table table-striped mt-3">
$heading
$rows
</table>
EOF; EOF;
} }
} }

View File

@ -0,0 +1,81 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); ?>
<?php echo Bootstrap::formOpen(array('id'=>'jsform')); ?>
<div class="align-middle">
<div class="float-right mt-1">
<button type="submit" class="btn btn-primary btn-sm" name="save"><?php $L->p('Save') ?></button>
<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#jsdeleteModal"><?php $L->p('Delete') ?></button>
<a class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT.'dashboard' ?>" role="button"><?php $L->p('Cancel') ?></a>
</div>
<?php echo Bootstrap::pageTitle(array('title'=>$L->g('Edit Tag'), 'icon'=>'cog')); ?>
</div>
<?php
// Token CSRF
echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF',
'value'=>$security->getTokenCSRF()
));
echo Bootstrap::formInputHidden(array(
'name'=>'action',
'value'=>'edit'
));
echo Bootstrap::formInputHidden(array(
'name'=>'oldKey',
'value'=>$tagMap['key']
));
echo Bootstrap::formInputText(array(
'name'=>'name',
'label'=>$L->g('Name'),
'value'=>$tagMap['name'],
'class'=>'',
'placeholder'=>'',
'tip'=>''
));
echo Bootstrap::formInputText(array(
'name'=>'newKey',
'label'=>$L->g('Friendly URL'),
'value'=>$tagMap['key'],
'class'=>'',
'placeholder'=>'',
'tip'=>DOMAIN_TAGS.$tagMap['key']
));
echo '<h5>' . $L->g('linked-pages') . '</h5>';
if(sizeof($tagMap['list']) > 0){
echo Bootstrap::linkedPagesTable($tagMap['list']);
}
else {
echo $L->g('no-linked-pages');
}
echo Bootstrap::formClose();
?>
<!-- Modal for delete tag -->
<?php
echo Bootstrap::modal(array(
'buttonPrimary'=>$L->g('Delete'),
'buttonPrimaryClass'=>'btn-danger jsbuttonDeleteAccept',
'buttonSecondary'=>$L->g('Cancel'),
'buttonSecondaryClass'=>'btn-link',
'modalTitle'=>$L->g('Delete tag'),
'modalText'=>$L->g('Are you sure you want to delete this tag?'),
'modalId'=>'jsdeleteModal'
));
?>
<script>
$(document).ready(function() {
// Delete content
$(".jsbuttonDeleteAccept").on("click", function() {
$("#jsaction").val("delete");
$("#jsform").submit();
});
});
</script>

View File

@ -0,0 +1,29 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); ?>
<?php echo Bootstrap::formOpen(array('id'=>'jsform', 'class'=>'tab-content')); ?>
<div class="align-middle">
<div class="float-right mt-1">
<button type="submit" class="btn btn-primary btn-sm" name="save"><?php $L->p('Save') ?></button>
<a class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT.'tags' ?>" role="button"><?php $L->p('Cancel') ?></a>
</div>
<?php echo Bootstrap::pageTitle(array('title'=>$L->g('New tag'), 'icon'=>'tag')); ?>
</div>
<?php
echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF',
'value'=>$security->getTokenCSRF()
));
echo Bootstrap::formInputText(array(
'name'=>'name',
'label'=>$L->g('Name'),
'value'=>isset($_POST['tag'])?$_POST['tag']:'',
'class'=>'',
'placeholder'=>'',
'tip'=>''
));
?>
<?php echo Bootstrap::formClose(); ?>

View File

@ -0,0 +1,33 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
echo Bootstrap::pageTitle(array('title'=>$L->g('Tags'), 'icon'=>'tags'));
echo Bootstrap::link(array(
'title'=>$L->g('Add a new tag'),
'href'=>HTML_PATH_ADMIN_ROOT.'new-tag',
'icon'=>'plus'
));
echo '
<table class="table table-striped mt-3">
<thead>
<tr>
<th class="border-bottom-0" scope="col">'.$L->g('Name').'</th>
<th class="border-bottom-0" scope="col">'.$L->g('URL').'</th>
</tr>
</thead>
<tbody>
';
foreach ($tags->keys() as $key) {
$tag = new Tag($key);
echo '<tr>';
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-tag/'.$key.'">'.$tag->name().'</a></td>';
echo '<td><a href="'.$tag->permalink().'">'.$url->filters('tag', false).$key.'</a></td>';
echo '</tr>';
}
echo '
</tbody>
</table>
';

View File

@ -127,6 +127,7 @@ $pages = new Pages();
$users = new Users(); $users = new Users();
$tags = new Tags(); $tags = new Tags();
$categories = new Categories(); $categories = new Categories();
$tags = new Tags();
$site = new Site(); $site = new Site();
$url = new Url(); $url = new Url();
$security = new Security(); $security = new Security();

View File

@ -744,6 +744,84 @@ function deleteCategory($args) {
return true; return true;
} }
// Add a new tag to the system
// Returns TRUE is successfully added, FALSE otherwise
function createTag($args) {
global $tags;
global $L;
global $syslog;
if (Text::isEmpty($args['name'])) {
Alert::set($L->g('Tag name is empty'), ALERT_STATUS_FAIL);
return false;
}
if ($tags->add(array('name'=>$args['name'], 'description'=>$args['description']))) {
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'new-tag-created',
'notes'=>$args['name']
));
Alert::set($L->g('Tag added'), ALERT_STATUS_OK);
return true;
}
Alert::set($L->g('The tag already exists'), ALERT_STATUS_FAIL);
return false;
}
function editTag($args) {
global $L;
global $pages;
global $tags;
global $syslog;
if (Text::isEmpty($args['name']) || Text::isEmpty($args['newKey']) ) {
Alert::set($L->g('Empty fields'));
return false;
}
$newTagKey = $tags->edit($args);
if ($newTagKey==false) {
Alert::set($L->g('The category already exists'));
return false;
}
// Change the tag key in the pages database
$pages->changeTag($args['oldKey'], $newTagKey);
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'tag-edited',
'notes'=>$newTagKey
));
Alert::set($L->g('The changes have been saved'));
return true;
}
function deleteTag($args) {
global $L;
global $tags;
global $syslog;
// Remove the category by key
$tags->remove($args['oldKey']);
// Remove the category from the pages ? or keep it if the user want to recovery the category ?
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'tag-deleted',
'notes'=>$args['oldKey']
));
Alert::set($L->g('The changes have been saved'));
return true;
}
// Returns an array with all the categories // Returns an array with all the categories
// By default, the database of categories is alphanumeric sorted // By default, the database of categories is alphanumeric sorted
function getCategories() { function getCategories() {

View File

@ -54,6 +54,7 @@
"dashboard": "Dashboard", "dashboard": "Dashboard",
"manage-users": "Benutzer verwalten", "manage-users": "Benutzer verwalten",
"manage-categories": "Kategorien verwalten", "manage-categories": "Kategorien verwalten",
"manage-tags": "Schlagwörter verwalten",
"general-settings": "Allgemeine Einstellungen", "general-settings": "Allgemeine Einstellungen",
"advanced-settings": "Erweiterte Einstellungen", "advanced-settings": "Erweiterte Einstellungen",
"thanks-for-support-bludit": "Vielen Dank für die Unterstützung von Bludit!", "thanks-for-support-bludit": "Vielen Dank für die Unterstützung von Bludit!",
@ -73,6 +74,7 @@
"content": "Inhalte", "content": "Inhalte",
"category": "Kategorie", "category": "Kategorie",
"categories": "Kategorien", "categories": "Kategorien",
"tag":"Schlagwort",
"users": "Benutzer", "users": "Benutzer",
"settings": "Einstellungen", "settings": "Einstellungen",
"general": "Allgemein", "general": "Allgemein",
@ -81,6 +83,7 @@
"manage-content": "Inhalte verwalten", "manage-content": "Inhalte verwalten",
"add-new-content": "Neuen Inhalt erstellen", "add-new-content": "Neuen Inhalt erstellen",
"new-category": "Neue Kategorie", "new-category": "Neue Kategorie",
"new-tag": "Neues Schlagwort",
"you-do-not-have-sufficient-permissions": "Keine Berechtigung, die Seite aufzurufen.", "you-do-not-have-sufficient-permissions": "Keine Berechtigung, die Seite aufzurufen.",
"add-a-new-user": "Neuer Benutzer", "add-a-new-user": "Neuer Benutzer",
"url-associated-with-the-content": "Der URL kann selbst angepasst werden.", "url-associated-with-the-content": "Der URL kann selbst angepasst werden.",
@ -129,6 +132,7 @@
"friendly-url": "URL", "friendly-url": "URL",
"image-description": "Bildbeschreibung", "image-description": "Bildbeschreibung",
"add-a-new-category": "Neue Kategorie hinzufügen", "add-a-new-category": "Neue Kategorie hinzufügen",
"add-a-new-tag": "Neues Schlagwort hinzufügen",
"name": "Name", "name": "Name",
"username": "Benutzername", "username": "Benutzername",
"first-name": "Vorname", "first-name": "Vorname",
@ -164,6 +168,9 @@
"activate": "Aktivieren", "activate": "Aktivieren",
"deactivate": "Deaktivieren", "deactivate": "Deaktivieren",
"edit-category": "Kategorie bearbeiten", "edit-category": "Kategorie bearbeiten",
"edit-tag": "Schlagwort bearbeiten",
"no-linked-pages": "Keine Seiten verlinkt",
"linked-pages": "Verlinkte Seiten",
"delete": "Löschen", "delete": "Löschen",
"password": "Passwort", "password": "Passwort",
"confirm-password": "Passwort wiederholen", "confirm-password": "Passwort wiederholen",
@ -178,6 +185,8 @@
"profile-picture": "Profil-Bild", "profile-picture": "Profil-Bild",
"edit-or-delete-your-categories": "Kategorien bearbeiten oder löschen.", "edit-or-delete-your-categories": "Kategorien bearbeiten oder löschen.",
"create-a-new-category-to-organize-your-content": "Eine neue Kategorie hinzufügen.", "create-a-new-category-to-organize-your-content": "Eine neue Kategorie hinzufügen.",
"edit-or-delete-your-tags": "Schlagwörter bearbeiten oder löschen.",
"create-a-new-tag-to-organize-your-content": "Ein neues Schlagwort hinzufügen.",
"confirm-delete-this-action-cannot-be-undone": "Bestätigung der Löschung. Diese kann nicht rückgängig gemacht werden.", "confirm-delete-this-action-cannot-be-undone": "Bestätigung der Löschung. Diese kann nicht rückgängig gemacht werden.",
"do-you-want-to-disable-the-user": "Soll der Benutzer deaktiviert werden?", "do-you-want-to-disable-the-user": "Soll der Benutzer deaktiviert werden?",
"new-password": "Neues Passwort", "new-password": "Neues Passwort",
@ -214,6 +223,9 @@
"new-category-created": "Kategorie hinzugefügt", "new-category-created": "Kategorie hinzugefügt",
"category-deleted": "Kategorie gelöscht", "category-deleted": "Kategorie gelöscht",
"category-edited": "Kategorie bearbeitet", "category-edited": "Kategorie bearbeitet",
"new-tag-created": "Schlagwort hinzugefügt",
"tag-deleted": "Schlagwort gelöscht",
"tag-edited": "Schlagwort bearbeitet",
"new-user-created": "Benutzer hinzugefügt", "new-user-created": "Benutzer hinzugefügt",
"user-edited": "Benutzer bearbeitet", "user-edited": "Benutzer bearbeitet",
"user-deleted": "Benutzer gelöscht", "user-deleted": "Benutzer gelöscht",
@ -332,6 +344,8 @@
"done": "Bestätigen", "done": "Bestätigen",
"delete-category": "Kategorie löschen", "delete-category": "Kategorie löschen",
"are-you-sure-you-want-to-delete-this-category?": "Bist du sicher, dass Du diese Kategorie löschen möchtest?", "are-you-sure-you-want-to-delete-this-category?": "Bist du sicher, dass Du diese Kategorie löschen möchtest?",
"delete-tag": "Schlagwort löschen",
"are-you-sure-you-want-to-delete-this-tag?": "Bist du sicher, dass Du dieses Schlagwort löschen möchtest?",
"confirm-new-password": "Bestätige das neue Passwort", "confirm-new-password": "Bestätige das neue Passwort",
"the-nickname-is-almost-used-in-the-themes-to-display-the-author-of-the-content": "Der Nickname wird als Name des Autors von Beiträgen angezeigt.", "the-nickname-is-almost-used-in-the-themes-to-display-the-author-of-the-content": "Der Nickname wird als Name des Autors von Beiträgen angezeigt.",
"allow-unicode": "Unicode", "allow-unicode": "Unicode",

View File

@ -53,6 +53,7 @@
"dashboard": "Dashboard", "dashboard": "Dashboard",
"manage-users": "Manage users", "manage-users": "Manage users",
"manage-categories": "Manage categories", "manage-categories": "Manage categories",
"manage-tags": "Manage tags",
"general-settings": "General settings", "general-settings": "General settings",
"advanced-settings": "Advanced settings", "advanced-settings": "Advanced settings",
"thanks-for-support-bludit": "Thanks for support Bludit", "thanks-for-support-bludit": "Thanks for support Bludit",
@ -80,6 +81,7 @@
"manage-content": "Manage content", "manage-content": "Manage content",
"add-new-content": "Add new content", "add-new-content": "Add new content",
"new-category": "New category", "new-category": "New category",
"new-tag": "New tag",
"you-do-not-have-sufficient-permissions": "You do not have sufficient permissions", "you-do-not-have-sufficient-permissions": "You do not have sufficient permissions",
"add-a-new-user": "Add a new user", "add-a-new-user": "Add a new user",
"url-associated-with-the-content": "URL associated with the content.", "url-associated-with-the-content": "URL associated with the content.",
@ -128,6 +130,7 @@
"friendly-url": "Friendly URL", "friendly-url": "Friendly URL",
"image-description": "Image description", "image-description": "Image description",
"add-a-new-category": "Add a new category", "add-a-new-category": "Add a new category",
"add-a-new-tag": "Add a new tag",
"name": "Name", "name": "Name",
"username": "Username", "username": "Username",
"first-name": "First name", "first-name": "First name",
@ -163,6 +166,9 @@
"activate": "Activate", "activate": "Activate",
"deactivate": "Deactivate", "deactivate": "Deactivate",
"edit-category": "Edit category", "edit-category": "Edit category",
"edit-tag": "Edit tag",
"no-linked-pages": "No linked pages",
"linked-pages": "Linked pages",
"delete": "Delete", "delete": "Delete",
"password": "Password", "password": "Password",
"confirm-password": "Confirm Password", "confirm-password": "Confirm Password",
@ -177,6 +183,8 @@
"profile-picture": "Profile picture", "profile-picture": "Profile picture",
"edit-or-delete-your-categories": "Edit or delete your categories", "edit-or-delete-your-categories": "Edit or delete your categories",
"create-a-new-category-to-organize-your-content": "Create a new category to organize your content", "create-a-new-category-to-organize-your-content": "Create a new category to organize your content",
"edit-or-delete-your-tags": "Edit or delete your tags",
"create-a-new-tag-to-organize-your-content": "Create a new tag to organize your content",
"confirm-delete-this-action-cannot-be-undone": "Confirm delete, this action cannot be undone.", "confirm-delete-this-action-cannot-be-undone": "Confirm delete, this action cannot be undone.",
"do-you-want-to-disable-the-user": "Do you want to disable the user ?", "do-you-want-to-disable-the-user": "Do you want to disable the user ?",
"new-password": "New password", "new-password": "New password",
@ -213,6 +221,9 @@
"new-category-created": "New category created", "new-category-created": "New category created",
"category-deleted": "Category deleted", "category-deleted": "Category deleted",
"category-edited": "Category edited", "category-edited": "Category edited",
"new-tag-created": "New tag created",
"tag-deleted": "tag deleted",
"tag-edited": "tag edited",
"new-user-created": "New user created", "new-user-created": "New user created",
"user-edited": "User edited", "user-edited": "User edited",
"user-deleted": "User deleted", "user-deleted": "User deleted",
@ -331,6 +342,8 @@
"done": "Done", "done": "Done",
"delete-category": "Delete category", "delete-category": "Delete category",
"are-you-sure-you-want-to-delete-this-category?": "Are you sure you want to delete this category?", "are-you-sure-you-want-to-delete-this-category?": "Are you sure you want to delete this category?",
"delete-tag": "Delete tag",
"are-you-sure-you-want-to-delete-this-tag?": "Are you sure you want to delete this tag?",
"confirm-new-password": "Confirm new password", "confirm-new-password": "Confirm new password",
"the-nickname-is-almost-used-in-the-themes-to-display-the-author-of-the-content": "The nickname is almost used in the themes to display the author of the content", "the-nickname-is-almost-used-in-the-themes-to-display-the-author-of-the-content": "The nickname is almost used in the themes to display the author of the content",
"allow-unicode": "Allow Unicode", "allow-unicode": "Allow Unicode",
@ -377,4 +390,4 @@
"thumbnail-width-in-pixels": "Thumbnail width in pixels (px).", "thumbnail-width-in-pixels": "Thumbnail width in pixels (px).",
"thumbnail-height-in-pixels": "Thumbnail height in pixels (px).", "thumbnail-height-in-pixels": "Thumbnail height in pixels (px).",
"thumbnail-quality-in-percentage": "Thumbnail quality in percentage (%)." "thumbnail-quality-in-percentage": "Thumbnail quality in percentage (%)."
} }