-
Hello, I'm a Bludit alert!
-
+
+
+ Hello, I'm a Bludit alert!
@@ -10,7 +9,7 @@
\ No newline at end of file
diff --git a/bl-kernel/admin/views/editor.php b/bl-kernel/admin/views/editor.php
index f890f8c6..add39f42 100644
--- a/bl-kernel/admin/views/editor.php
+++ b/bl-kernel/admin/views/editor.php
@@ -89,11 +89,11 @@
}
function disableBtnSave() {
- $('#btnSave').addClass('btn-primary-disabled').html('
p('Saved') ?>');
+ $('#btnSave').addClass('btn-primary-disabled').attr('data-current', 'saved').html('
p('Saved') ?>');
}
function enableBtnSave() {
- $('#btnSave').removeClass('btn-primary-disabled').html('
p('Save') ?>');
+ $('#btnSave').removeClass('btn-primary-disabled').attr('data-current', 'unsaved').html('
p('Save') ?>');
}
// This function is to catch all key press and provides shortcuts
@@ -117,6 +117,11 @@
return false;
}
+ // Ctrl+ or Command+ or Alt+ or Shift+ or Option+
+ if (event.ctrlKey || event.metaKey || event.altKey || event.shiftKey) {
+ return true;
+ }
+
enableBtnSave();
return true;
}
@@ -128,10 +133,21 @@
// Main interface events
// ------------------------------------------------------------------------
+
+ // Catch all keypress for shortcuts or other actions
$(this).keydown(function(event) {
keypress(event);
});
+ // Warn the user to save the changes before leave
+ $(window).bind('beforeunload', function(e) {
+ if ($('#btnSave').attr('data-current')=='unsaved') {
+ (e || window.event).returnValue = '';
+ return '';
+ }
+ return undefined; // Return undefined to continue the unload
+ });
+
$('#btnSave').on('click', function() {
var args = {
title: $('#title').val(),
@@ -505,7 +521,7 @@
-
+
g('File type is not supported. Allowed types:') . ' ' . implode(', ', $GLOBALS['ALLOWED_IMG_EXTENSION']) ?>");
diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php
index e4cdea88..0bd98ae4 100644
--- a/bl-kernel/boot/init.php
+++ b/bl-kernel/boot/init.php
@@ -211,8 +211,9 @@ define('MARKDOWN_PARSER', $site->markdownParser());
// --- PHP paths with dependency ---
// This paths are absolutes for the OS
-define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$site->theme().DS);
+define('THEME_DIR', PATH_ROOT.'bl-themes'.DS.$site->theme().DS);
define('THEME_DIR_PHP', THEME_DIR.'php'.DS);
+define('THEME_DIR_TEMPLATES', THEME_DIR.'templates'.DS);
define('THEME_DIR_CSS', THEME_DIR.'css'.DS);
define('THEME_DIR_JS', THEME_DIR.'js'.DS);
define('THEME_DIR_IMG', THEME_DIR.'img'.DS);
diff --git a/bl-kernel/boot/variables.php b/bl-kernel/boot/variables.php
index 9fa15e62..3ec91ebd 100644
--- a/bl-kernel/boot/variables.php
+++ b/bl-kernel/boot/variables.php
@@ -110,4 +110,4 @@ $GLOBALS['DB_TAGS_TYPES'] = array('published','static','sticky');
$GLOBALS['ALLOWED_IMG_EXTENSION'] = array('gif', 'png', 'jpg', 'jpeg', 'svg');
// Allowed image mime types
-$GLOBALS['ALLOWED_IMG_MIMETYPES'] = array('image/gif', 'image/png', 'image/jpeg', 'image/svg+xml');
+$GLOBALS['ALLOWED_IMG_MIMETYPES'] = array('image/gif', 'image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf');
diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php
index 495ff0f9..1c2d5d2a 100644
--- a/bl-kernel/functions.php
+++ b/bl-kernel/functions.php
@@ -1,5 +1,16 @@
(name: string, template: string, description: string)
@returns string/boolean Returns the category key if the category is successfully created, FALSE otherwise
*/
function createCategory($args) {
@@ -145,6 +156,82 @@ function createCategory($args) {
return false;
}
+/* Edit a category === Bludit v4
+
+ @args array Array => (key: string, name: string, friendlyURL: string, template: string, description: string)
+ @returns string/boolean Returns the category key if the category is successfully edited, FALSE otherwise
+*/
+function editCategory($args) {
+ global $pages;
+ global $categories;
+ global $syslog;
+
+ if (Text::isEmpty($args['key'])) {
+ Log::set(__FUNCTION__.LOG_SEP.'The category key is empty.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ if (Text::isEmpty($args['name'])) {
+ Log::set(__FUNCTION__.LOG_SEP.'The category name is empty.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ if (Text::isEmpty($args['friendlyURL'])) {
+ Log::set(__FUNCTION__.LOG_SEP.'The category friendlyURL is empty.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ $args['oldKey'] = $args['key'];
+ $args['newKey'] = $args['friendlyURL'];
+ $finalKey = $categories->edit($args);
+
+ if ($finalKey==false) {
+ Log::set(__FUNCTION__.LOG_SEP.'The category already exists.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ // Change the category key inside the pages database
+ if ($args['key']!==$finalKey) {
+ $pages->changeCategory($args['key'], $finalKey);
+ }
+
+ $syslog->add(array(
+ 'dictionaryKey'=>'category-edited',
+ 'notes'=>$finalKey
+ ));
+
+ Log::set(__FUNCTION__.LOG_SEP.'Category edited.', LOG_TYPE_INFO);
+ return $finalKey;
+}
+
+/* Delete a category === Bludit v4
+
+ @args array Array => (key: string)
+ @returns boolean Returns TRUE if the category was deleted, FALSE otherwise
+*/
+function deleteCategory($args) {
+ global $categories;
+ global $syslog;
+
+ if (Text::isEmpty($args['key'])) {
+ Log::set(__FUNCTION__.LOG_SEP.'The category key is empty.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ if ($categories->remove($args['key'])===false) {
+ Log::set(__FUNCTION__.LOG_SEP.'Something happened when you tried to delete the category.', LOG_TYPE_ERROR);
+ return false;
+ }
+
+ $syslog->add(array(
+ 'dictionaryKey'=>'category-deleted',
+ 'notes'=>$args['key']
+ ));
+
+ Log::set(__FUNCTION__.LOG_SEP.'Category deleted.', LOG_TYPE_INFO);
+ return true;
+}
+
/* Create a new user === Bludit v4
This function should check everthing, such as empty username, emtpy password, password lenght, etc
@@ -727,56 +814,9 @@ function checkRole($allowRoles, $redirect=true) {
-function editCategory($args) {
- global $L;
- global $pages;
- global $categories;
- global $syslog;
- if (Text::isEmpty($args['name']) || Text::isEmpty($args['newKey']) ) {
- Alert::set($L->g('Empty fields'));
- return false;
- }
- $newCategoryKey = $categories->edit($args);
- if ($newCategoryKey==false) {
- Alert::set($L->g('The category already exists'));
- return false;
- }
-
- // Change the category key in the pages database
- $pages->changeCategory($args['oldKey'], $newCategoryKey);
-
- // Add to syslog
- $syslog->add(array(
- 'dictionaryKey'=>'category-edited',
- 'notes'=>$newCategoryKey
- ));
-
- Alert::set($L->g('The changes have been saved'));
- return true;
-}
-
-function deleteCategory($args) {
- global $L;
- global $categories;
- global $syslog;
-
- // Remove the category by key
- $categories->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'=>'category-deleted',
- 'notes'=>$args['oldKey']
- ));
-
- Alert::set($L->g('The changes have been saved'));
- return true;
-}
// Returns an array with all the categories
// By default, the database of categories is alphanumeric sorted
diff --git a/bl-kernel/helpers/bootstrap.class.php b/bl-kernel/helpers/bootstrap.class.php
index 5d1f211d..416649c6 100644
--- a/bl-kernel/helpers/bootstrap.class.php
+++ b/bl-kernel/helpers/bootstrap.class.php
@@ -2,6 +2,15 @@
class Bootstrap {
+ public static function formInputHidden($args)
+ {
+ $name = $args['name'];
+ $id = isset($args['id'])?$args['id']:$name;
+ $value = isset($args['value'])?$args['value']:'';
+
+ return '';
+ }
+
// Floating Labels
// https://getbootstrap.com/docs/5.0/forms/floating-labels/
public static function formFloatingLabels($args)
@@ -399,10 +408,7 @@ EOF;
- public static function formInputHidden($args)
- {
- return '';
- }
+
public static function alert($args)
{
diff --git a/bl-kernel/js/api.js b/bl-kernel/js/api.js
index 9ec56e99..33f86cbb 100644
--- a/bl-kernel/js/api.js
+++ b/bl-kernel/js/api.js
@@ -194,6 +194,56 @@ class API {
}
}
+ /* Edit a category
+
+ @args array Arguments can be any of the fields from a category
+ @returns string The category key
+ */
+ async editCategory(args) {
+ var url = this.apiURL + "categories/" + args['key'];
+ var body = Object.assign({}, this.body, args);
+ try {
+ var response = await fetch(url, {
+ credentials: "same-origin",
+ method: "PUT",
+ body: JSON.stringify(body),
+ headers: new Headers({
+ "Content-Type": "application/json"
+ })
+ });
+ var json = await response.json();
+ return json.data.key;
+ } catch (err) {
+ console.log(err);
+ return true;
+ }
+ }
+
+ /* Delete a category
+
+ @args array Array => (key: string)
+ @returns string The category key deleted
+ */
+ async deleteCategory(args) {
+ var url = this.apiURL + "categories/" + args['key'];
+ var body = this.body;
+ try {
+ var response = await fetch(url, {
+ credentials: "same-origin",
+ method: "DELETE",
+ body: JSON.stringify(body),
+ headers: new Headers({
+ "Content-Type": "application/json"
+ })
+ });
+ var json = await response.json();
+ return json.data.key;
+ } catch (err) {
+ console.log(err);
+ return true;
+ }
+ }
+
/* Create a new user
@args array Arguments can be any of the fields from a user
diff --git a/bl-kernel/pages.class.php b/bl-kernel/pages.class.php
index 3f05d252..6a67f33e 100644
--- a/bl-kernel/pages.class.php
+++ b/bl-kernel/pages.class.php
@@ -785,7 +785,12 @@ class Pages extends dbJSON {
return $tmp;
}
- // Change all pages with the old category key to the new category key
+ /* Change all pages linked to the old category key to the new category key === Bludit v4
+
+ @oldCategoryKey string The old category key
+ @newCategoryKey string The new category key
+ @returns boolean Returns TRUE if the database was saved, FALSE otherwise
+ */
public function changeCategory($oldCategoryKey, $newCategoryKey)
{
foreach ($this->db as $key=>$value) {
diff --git a/bl-kernel/pagex.class.php b/bl-kernel/pagex.class.php
index 9822ad45..3423108a 100644
--- a/bl-kernel/pagex.class.php
+++ b/bl-kernel/pagex.class.php
@@ -234,9 +234,17 @@ class Page {
}
}
+ /* Returns the template for the page === Bludit v4
+
+ @returns string/boolean Returns the template for the page or FALSE if the page haven't a template assigned
+ */
public function template()
{
- return $this->getValue('template');
+ $template = $this->getValue('template');
+ if (empty($template)) {
+ return false;
+ }
+ return $template;
}
// Returns the description field
diff --git a/bl-languages/en.json b/bl-languages/en.json
index 66f7ea4f..86d4d0ec 100644
--- a/bl-languages/en.json
+++ b/bl-languages/en.json
@@ -225,7 +225,7 @@
"label": "Label",
"links": "Links",
"this-title-is-almost-always-used-in-the-sidebar-of-the-site": "This title is almost always used in the sidebar of the site.",
- "password-must-be-at-least-6-characters-long": "Password must be at least 6 characters long.",
+ "password-must-be-at-least-6-characters-long": "Password must be at least 6 characters long",
"ip-address-has-been-blocked": "IP address has been blocked",
"try-again-in-a-few-minutes": "Try again in a few minutes",
"content-published-from-scheduler": "Content published from scheduler",
@@ -240,7 +240,7 @@
"delete-the-user-and-all-his-content": "Delete the user and all of their content",
"user-disabled": "User disabled",
"user-password-changed": "User password changed",
- "the-password-and-confirmation-password-do-not-match": "The password and confirmation password do not match.",
+ "the-password-and-confirmation-password-do-not-match": "The password and confirmation password do not match",
"scheduled-content": "Scheduled content",
"there-are-no-scheduled-content": "There are no scheduled content.",
"new-content-created": "New content created",
diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php
index d5ef801b..272a4f9f 100644
--- a/bl-plugins/api/plugin.php
+++ b/bl-plugins/api/plugin.php
@@ -189,6 +189,16 @@ class pluginAPI extends Plugin {
elseif ( ($method==='POST') && ($parameters[0]==='categories') && empty($parameters[1]) && $writePermissions ) {
$data = $this->createCategory($inputs);
}
+ // (PUT) /api/categories/
+ elseif ( ($method==='PUT') && ($parameters[0]==='categories') && !empty($parameters[1]) && $writePermissions ) {
+ $inputs['key'] = $parameters[1];
+ $data = $this->editCategory($inputs);
+ }
+ // (DELETE) /api/categories/
+ elseif ( ($method==='DELETE') && ($parameters[0]==='categories') && !empty($parameters[1]) && $writePermissions ) {
+ $inputs['key'] = $parameters[1];
+ $data = $this->deleteCategory($inputs);
+ }
// (GET) /api/users
elseif ( ($method==='GET') && ($parameters[0]==='users') && empty($parameters[1]) ) {
$data = $this->getUsers();
@@ -644,9 +654,11 @@ class pluginAPI extends Plugin {
);
}
+ /* Create a new category === Bludit v4
+ Referer to the function createCategory() from functions.php
+ */
private function createCategory($args)
{
- // This function is defined on functions.php
$key = createCategory($args);
if ($key===false) {
return array(
@@ -662,6 +674,45 @@ class pluginAPI extends Plugin {
);
}
+ /* Edit a category === Bludit v4
+ Referer to the function editCategory() from functions.php
+ */
+ private function editCategory($args)
+ {
+ $key = editCategory($args);
+ if ($key===false) {
+ return array(
+ 'status'=>'1',
+ 'message'=>'An error occurred while trying to edit the category.'
+ );
+ }
+
+ return array(
+ 'status'=>'0',
+ 'message'=>'Category edited.',
+ 'data'=>array('key'=>$key)
+ );
+ }
+
+ /* Delete a category === Bludit v4
+ Referer to the function deleteCategory() from functions.php
+ */
+ private function deleteCategory($args)
+ {
+ if (deleteCategory($args)) {
+ return array(
+ 'status'=>'0',
+ 'message'=>'Category deleted.',
+ 'data'=>array('key'=>$args['key'])
+ );
+ }
+
+ return array(
+ 'status'=>'1',
+ 'message'=>'An error occurred while trying to delete the category.'
+ );
+ }
+
/*
| Returns the user profile
|
diff --git a/bl-themes/blogx/index.php b/bl-themes/blogx/index.php
index 71645914..4cd54b7d 100755
--- a/bl-themes/blogx/index.php
+++ b/bl-themes/blogx/index.php
@@ -26,7 +26,12 @@
// If the user is watching a particular page/post the variable takes the value "page"
// If the user is watching the frontpage the variable takes the value "home"
if ($WHERE_AM_I == 'page') {
- include(THEME_DIR_PHP.'page.php');
+ $template = $page->template();
+ if (($template) && file_exists(THEME_DIR_TEMPLATES.$template)) {
+ include(THEME_DIR_TEMPLATES.$template);
+ } else {
+ include(THEME_DIR_PHP.'page.php');
+ }
} else {
include(THEME_DIR_PHP.'home.php');
}