Settings trough API, change user password via API, refactor code

This commit is contained in:
dignajar 2021-02-07 17:19:24 +01:00
parent 71f1742c45
commit cd0446e080
14 changed files with 961 additions and 913 deletions

View file

@ -27,6 +27,16 @@ div.sidebar .nav-item h4 {
cursor: pointer; cursor: pointer;
} }
.link {
cursor: pointer;
text-decoration: underline;
color: #555;
}
.link:hover {
color: #0a58ca;
}
/* /*
OLD >>>>>>>>> OLD >>>>>>>>>
*/ */

View file

@ -72,31 +72,24 @@ function table($type)
echo '<td class="pt-3 pb-3"> echo '<td class="pt-3 pb-3">
<div> <div>
<a href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</a> <span>' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</span>
</div> </div>
<div> <div class="mt-1">
<span class="m-0 text-uppercase text-muted" style="font-size: 0.8rem"> ' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $page->position() : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</span> <a class="me-2" target="_blank" href="' . $page->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . $L->g('Edit') . '</a>
';
if (count($page->children()) == 0) {
echo '<span class="link btnDeletePage" data-key="' . $page->key() . '">Delete</span>';
}
echo '
</div> </div>
</td>'; </td>';
echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>'; echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-3 text-center d-sm-table-cell"> echo '<td class="pt-3 text-center d-sm-table-cell">' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $page->position() : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
<div class="dropdown">
<button type="button" class="btn dropdown-toggle btn-secondary btn-sm" type="button" id="dropdownOptions" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-gear"></i></span>' . $L->g('Options') . '
</button>
<div class="dropdown-menu ps-1 pe-1" aria-labelledby="dropdownOptions">
<a class="dropdown-item" target="_blank" href="' . $page->permalink() . '"><i class="bi bi-box-arrow-up-right"></i>' . $L->g('View') . '</a>
<a class="dropdown-item" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '"><i class="bi bi-pencil-square"></i>' . $L->g('Edit') . '</a>
<a><hr class="dropdown-divider"></a>
';
if (count($page->children()) == 0) {
echo '<a data-toggle="modal" data-target="#modalDeletePage" data-key="' . $page->key() . '" class="btnDeletePage dropdown-item" href="#"><i class="bi bi-trash"></i>' . $L->g('Delete') . '</a>';
}
echo '</div>
</div>
</td>';
echo '</tr>'; echo '</tr>';
@ -105,28 +98,18 @@ function table($type)
echo '<td class="ps-3 pt-3 pb-3"> echo '<td class="ps-3 pt-3 pb-3">
<div> <div>
<a href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $child->key() . '">' . ($child->title() ? $child->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</a> <span>' . ($child->title() ? $child->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</span>
</div> </div>
<div> <div class="mt-1">
<span class="m-0 text-uppercase text-muted" style="font-size: 0.8rem">' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $child->position() : $child->date(MANAGE_CONTENT_DATE_FORMAT)) . '</span> <a class="me-2" target="_blank" href="' . $child->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $child->key() . '">' . $L->g('Edit') . '</a>
<span class="link btnDeletePage" data-key="' . $child->key() . '">Delete</span>
</div> </div>
</td>'; </td>';
echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($child->category() ? $child->category() : $L->get('uncategorized')) . '</td>'; echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($child->category() ? $child->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-3 text-center d-sm-table-cell"> echo '<td class="pt-3 text-center d-sm-table-cell">' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $child->position() : $child->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
<div class="dropdown">
<button type="button" class="btn dropdown-toggle btn-secondary btn-sm" type="button" id="dropdownOptions" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-gear"></i></span>' . $L->g('Options') . '
</button>
<div class="dropdown-menu ps-1 pe-1" aria-labelledby="dropdownOptions">
<a class="dropdown-item" target="_blank" href="' . $child->permalink() . '"><i class="bi bi-box-arrow-up-right"></i>' . $L->g('View') . '</a>
<a class="dropdown-item" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $child->key() . '"><i class="bi bi-pencil-square"></i>' . $L->g('Edit') . '</a>
<a><hr class="dropdown-divider"></a>
<a data-toggle="modal" data-target="#modalDeletePage" data-key="' . $child->key() . '" class="btnDeletePage dropdown-item" href="#"><i class="bi bi-trash"></i>' . $L->g('Delete') . '</a>
</div>
</div>
</td>';
echo '</tr>'; echo '</tr>';
} }
@ -143,28 +126,18 @@ function table($type)
echo '<td class="pt-3 pb-3"> echo '<td class="pt-3 pb-3">
<div> <div>
<a href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '</a> ' . ($page->title() ? $page->title() : '<span class="text-muted">' . $L->g('Empty title') . '</span> ') . '
</div> </div>
<div> <div class="mt-1">
<span class="m-0 text-uppercase text-muted" style="font-size: 0.8rem"> ' . (($type == 'scheduled') ? $L->g('Scheduled') . ': ' . $page->date(SCHEDULED_DATE_FORMAT) : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</span> <a class="me-2" target="_blank" href="' . $page->permalink() . '">' . $L->g('View') . '</a>
<a class="me-2" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '">' . $L->g('Edit') . '</a>
<span class="link btnDeletePage" data-key="' . $page->key() . '">Delete</span>
</div> </div>
</td>'; </td>';
echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>'; echo '<td class="pt-3 pb-3 d-none d-lg-table-cell">' . $L->get('Category') . ': ' . ($page->category() ? $page->category() : $L->get('uncategorized')) . '</td>';
echo '<td class="pt-3 text-center d-sm-table-cell"> echo '<td class="pt-3 text-center d-sm-table-cell"> ' . (((ORDER_BY == 'position') || ($type != 'published')) ? $L->g('Position') . ': ' . $page->position() : $page->date(MANAGE_CONTENT_DATE_FORMAT)) . '</td>';
<div class="dropdown">
<button type="button" class="btn dropdown-toggle btn-secondary btn-sm" type="button" id="dropdownOptions" data-bs-toggle="dropdown" aria-expanded="false">
<i class="bi bi-gear"></i></span>' . $L->g('Options') . '
</button>
<div class="dropdown-menu ps-1 pe-1" aria-labelledby="dropdownOptions">
<a class="dropdown-item" target="_blank" href="' . $page->permalink() . '"><i class="bi bi-box-arrow-up-right"></i>' . $L->g('View') . '</a>
<a class="dropdown-item" href="' . HTML_PATH_ADMIN_ROOT . 'editor/' . $page->key() . '"><i class="bi bi-pencil-square"></i>' . $L->g('Edit') . '</a>
<a><hr class="dropdown-divider"></a>
<a data-toggle="modal" data-target="#modalDeletePage" data-key="' . $page->key() . '" class="btnDeletePage dropdown-item" href="#"><i class="bi bi-trash"></i>' . $L->g('Delete') . '</a>
</div>
</div>
</td>';
echo '</tr>'; echo '</tr>';
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -1,267 +1,18 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); ?> <?php defined('BLUDIT') or die('Bludit CMS.'); ?>
<div class="d-flex align-items-center mb-4">
<h2 class="m-0"><i class="bi bi-person"></i><?php $L->p('Edit user') ?></h2>
<div class="ms-auto">
<button id="btnSave" type="button" class="btn btn-primary btn-sm"><?php $L->p('Save') ?></button>
<a id="btnCancel" class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT . 'users' ?>" role="button"><?php $L->p('Cancel') ?></a>
</div>
</div>
<!-- Tabs -->
<ul class="nav nav-tabs ps-3 mb-3" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="true"><?php $L->p('Profile') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="picture-tab" data-bs-toggle="tab" href="#picture" role="tab" aria-controls="picture" aria-selected="false"><?php $L->p('Profile picture') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="security-tab" data-bs-toggle="tab" href="#security" role="tab" aria-controls="security" aria-selected="false"><?php $L->p('Security') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="social-tab" data-bs-toggle="tab" href="#social" role="tab" aria-controls="social" aria-selected="false"><?php $L->p('Social Networks') ?></a>
</li>
</ul>
<!-- End Tabs -->
<!-- Content -->
<div class="tab-content" id="tabContent">
<!-- Tab profile -->
<div class="tab-pane show active" id="profile" role="tabpanel">
<?php
echo Bootstrap::formInputText(array(
'name' => 'username',
'label' => $L->g('Username'),
'value' => $user->username(),
'disabled' => true
));
if ($login->role() === 'admin') {
echo Bootstrap::formSelect(array(
'name' => 'role',
'label' => $L->g('Role'),
'options' => array('author' => $L->g('Author'), 'editor' => $L->g('Editor'), 'admin' => $L->g('Administrator')),
'selected' => $user->role(),
'tip' => $L->g('author-can-write-and-edit-their-own-content')
));
}
echo Bootstrap::formInputText(array(
'name' => 'email',
'label' => $L->g('Email'),
'value' => $user->email()
));
echo Bootstrap::formInputText(array(
'name' => 'nickname',
'label' => $L->g('Nickname'),
'value' => $user->nickname(),
'tip' => $L->g('The nickname is almost used in the themes to display the author of the content')
));
echo Bootstrap::formInputText(array(
'name' => 'firstName',
'label' => $L->g('First Name'),
'value' => $user->firstName()
));
echo Bootstrap::formInputText(array(
'name' => 'lastName',
'label' => $L->g('Last Name'),
'value' => $user->lastName()
));
?>
</div>
<!-- End Tab profile -->
<!-- Tab profile picture -->
<div class="tab-pane" id="picture" role="tabpanel">
<div class="container">
<div class="row">
<div class="col-8">
<img id="profilePicturePreview" class="img-fluid img-thumbnail" alt="Profile picture preview" src="<?php echo ($user->profilePicture() ? $user->profilePicture() . '?version=' . time() : HTML_PATH_CORE_IMG . 'default.svg') ?>" />
</div>
<div class="col-4">
<label id="btnUploadProfilePicture" class="btn btn-primary"><i class="bi bi-upload"></i><?php $L->p('Upload image'); ?><input type="file" id="inputProfilePicture" name="inputProfilePicture" hidden></label>
<button id="btnRemoveProfilePicture" type="button" class="btn btn-secondary"><i class="bi bi-trash"></i><?php $L->p('Remove image'); ?></button>
</div>
</div>
</div>
</div>
<!-- End Tab profile picture -->
<!-- Tab security -->
<div class="tab-pane" id="security" role="tabpanel">
<?php
if (checkRole(array('admin'), false)) {
echo Bootstrap::formTitle(array('title' => $L->g('Status')));
echo Bootstrap::formInputText(array(
'name' => 'status',
'label' => $L->g('Current status'),
'value' => $user->enabled() ? $L->g('Enabled') : $L->g('Disabled'),
'disabled' => true,
'tip' => $user->enabled() ? '' : $L->g('To enable the user you must set a new password')
));
echo Bootstrap::formInputText(array(
'name' => 'registered',
'label' => $L->g('Registered'),
'value' => Date::format($user->registered(), DB_DATE_FORMAT, ADMIN_PANEL_DATE_FORMAT),
'disabled' => true
));
if ($user->enabled()) {
echo '
<div class="form-group row">
<div class="col-sm-2"></div>
<div class="col-sm-10">
<button type="button" class="btn btn-warning me-2" id="btnDisableUser"><i class="bi bi-slash-circle"></i>' . $L->g('Disable user') . '</button>
<button type="button" class="btn btn-danger me-2" id="btnDeleteUserAndKeepContent"><i class="bi bi-trash"></i>' . $L->g('Delete user and keep content') . '</button>
<button type="button" class="btn btn-danger" id="btnDeleteUserAndContent"><i class="bi bi-trash"></i>' . $L->g('Delete user and delete content') . '</button>
</div>
</div>
';
}
}
echo Bootstrap::formTitle(array('title' => $L->g('Authentication Token')));
echo Bootstrap::formInputText(array(
'name' => 'tokenAuth',
'label' => $L->g('Token'),
'value' => $user->tokenAuth(),
'class' => '',
'tip' => $L->g('this-token-is-similar-to-a-password-it-should-not-be-shared')
));
echo Bootstrap::formTitle(array('title' => $L->g('Change password')));
echo Bootstrap::formInputText(array(
'name' => 'newPassword',
'label' => $L->g('New password'),
'type' => 'password',
'value' => '',
));
echo Bootstrap::formInputText(array(
'name' => 'confirmPassword',
'label' => $L->g('Confirm password'),
'type' => 'password',
'value' => '',
));
?>
</div>
<!-- End Tab security -->
<!-- Social Networks tab -->
<div class="tab-pane" id="social" role="tabpanel">
<?php
echo Bootstrap::formInputText(array(
'name' => 'twitter',
'label' => 'Twitter',
'value' => $user->twitter(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'facebook',
'label' => 'Facebook',
'value' => $user->facebook(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'codepen',
'label' => 'CodePen',
'value' => $user->codepen(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'instagram',
'label' => 'Instagram',
'value' => $user->instagram(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'gitlab',
'label' => 'GitLab',
'value' => $user->gitlab(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'github',
'label' => 'GitHub',
'value' => $user->github(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'linkedin',
'label' => 'LinkedIn',
'value' => $user->linkedin(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'xing',
'label' => 'Xing',
'value' => $user->xing(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'mastodon',
'label' => 'Mastodon',
'value' => $user->mastodon(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'vk',
'label' => 'VK',
'value' => $user->vk(),
'class' => '',
'placeholder' => '',
'tip' => ''
));
?>
</div>
</div>
<script> <script>
$(document).ready(function() { // ============================================================================
// Variables for the view
// ============================================================================
$('#btnSave').on('click', function() { // ============================================================================
var username = $('#username').val(); // Functions for the view
// ============================================================================
function changePassword() {
var newPassword = $('#newPassword').val(); var newPassword = $('#newPassword').val();
var confirmPassword = $('#confirmPassword').val(); var confirmPassword = $('#confirmPassword').val();
// Change the password if the user write a new one in the input
if (newPassword) {
if (newPassword.length < PASSWORD_LENGTH) { if (newPassword.length < PASSWORD_LENGTH) {
showAlertError("<?php $L->p('Password must be at least 6 characters long') ?>"); showAlertError("<?php $L->p('Password must be at least 6 characters long') ?>");
return false; return false;
@ -289,7 +40,7 @@
if (result) { if (result) {
// The user accepted the action to change the password // The user accepted the action to change the password
var args = { var args = {
username: username, username: $('#username').val(),
password: $('#newPassword').val() password: $('#newPassword').val()
}; };
api.editUser(args).then(function(response) { api.editUser(args).then(function(response) {
@ -309,21 +60,42 @@
}); });
} }
// Edit the user properties function save() {
var args = { let args = {
username: username, username: $('#username').val(),
role: $('#role').val(), role: $('#role').val()
email: $('#email').val()
}; };
$('input[data-save="true"]').each(function() {
var key = $(this).attr('name');
var value = $(this).val();
args[key] = value;
})
api.editUser(args).then(function(response) { api.editUser(args).then(function(response) {
if (response.status == 0) { if (response.status == 0) {
logs('User edited. Username: ' + response.data.key); logs('User edited. Username: ' + response.data.key);
showAlertInfo("<?php $L->p('The changes have been saved') ?>");
} else { } else {
logs('An error occurred while trying to edit the user.'); logs('An error occurred while trying to edit the user.');
showAlertError(response.message); showAlertError(response.message);
} }
}); });
}
// ============================================================================
// Events for the view
// ============================================================================
$(document).ready(function() {
$('#btnSave').on('click', function() {
// Change the password if the user write a new one in the input
if ($('#newPassword').val()) {
changePassword();
} else {
// Save the edited fields
editUser();
}
}); });
$('#inputProfilePicture').on("change", function(e) { $('#inputProfilePicture').on("change", function(e) {
@ -441,4 +213,254 @@
}); });
}); });
// ============================================================================
// Initlization for the view
// ============================================================================
$(document).ready(function() {
// nothing here yet
// how do you hang your toilet paper ? over or under ?
});
</script> </script>
<div class="d-flex align-items-center mb-4">
<h2 class="m-0"><i class="bi bi-person"></i><?php $L->p('Edit user') ?></h2>
<div class="ms-auto">
<button id="btnSave" type="button" class="btn btn-primary btn-sm"><?php $L->p('Save') ?></button>
<a id="btnCancel" class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT . 'users' ?>" role="button"><?php $L->p('Cancel') ?></a>
</div>
</div>
<!-- Tabs -->
<ul class="nav nav-tabs ps-3 mb-3" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="profile-tab" data-bs-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="true"><?php $L->p('Profile') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="picture-tab" data-bs-toggle="tab" href="#picture" role="tab" aria-controls="picture" aria-selected="false"><?php $L->p('Profile picture') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="security-tab" data-bs-toggle="tab" href="#security" role="tab" aria-controls="security" aria-selected="false"><?php $L->p('Security') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="social-tab" data-bs-toggle="tab" href="#social" role="tab" aria-controls="social" aria-selected="false"><?php $L->p('Social Networks') ?></a>
</li>
</ul>
<!-- End Tabs -->
<!-- Content -->
<div class="tab-content" id="tabContent">
<!-- Tab profile -->
<div class="tab-pane show active" id="profile" role="tabpanel">
<?php
echo Bootstrap::formInputText(array(
'name' => 'username',
'label' => $L->g('Username'),
'value' => $user->username(),
'disabled' => true
));
if ($login->role() === 'admin') {
echo Bootstrap::formSelect(array(
'name' => 'role',
'label' => $L->g('Role'),
'options' => array('author' => $L->g('Author'), 'editor' => $L->g('Editor'), 'admin' => $L->g('Administrator')),
'selected' => $user->role(),
'tip' => $L->g('author-can-write-and-edit-their-own-content')
));
}
echo Bootstrap::formInputText(array(
'name' => 'email',
'label' => $L->g('Email'),
'value' => $user->email(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'nickname',
'label' => $L->g('Nickname'),
'value' => $user->nickname(),
'tip' => $L->g('The nickname is almost used in the themes to display the author of the content'),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'firstName',
'label' => $L->g('First Name'),
'value' => $user->firstName(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'lastName',
'label' => $L->g('Last Name'),
'value' => $user->lastName(),
'data' => array('save' => 'true')
));
?>
</div>
<!-- End Tab profile -->
<!-- Tab profile picture -->
<div class="tab-pane" id="picture" role="tabpanel">
<div class="container">
<div class="row">
<div class="col-8">
<img id="profilePicturePreview" class="img-fluid img-thumbnail" alt="Profile picture preview" src="<?php echo ($user->profilePicture() ? $user->profilePicture() . '?version=' . time() : HTML_PATH_CORE_IMG . 'default.svg') ?>" />
</div>
<div class="col-4">
<label id="btnUploadProfilePicture" class="btn btn-primary"><i class="bi bi-upload"></i><?php $L->p('Upload image'); ?><input type="file" id="inputProfilePicture" name="inputProfilePicture" hidden></label>
<button id="btnRemoveProfilePicture" type="button" class="btn btn-secondary"><i class="bi bi-trash"></i><?php $L->p('Remove image'); ?></button>
</div>
</div>
</div>
</div>
<!-- End Tab profile picture -->
<!-- Tab security -->
<div class="tab-pane" id="security" role="tabpanel">
<?php
if (checkRole(array('admin'), false)) {
echo Bootstrap::formTitle(array('title' => $L->g('Status')));
echo Bootstrap::formInputText(array(
'name' => 'status',
'label' => $L->g('Current status'),
'value' => $user->enabled() ? $L->g('Enabled') : $L->g('Disabled'),
'disabled' => true,
'tip' => $user->enabled() ? '' : $L->g('To enable the user you must set a new password')
));
echo Bootstrap::formInputText(array(
'name' => 'registered',
'label' => $L->g('Registered'),
'value' => Date::format($user->registered(), DB_DATE_FORMAT, ADMIN_PANEL_DATE_FORMAT),
'disabled' => true
));
if ($user->enabled()) {
echo '
<div class="form-group row">
<div class="col-sm-2"></div>
<div class="col-sm-10">
<button type="button" class="btn btn-warning me-2" id="btnDisableUser"><i class="bi bi-slash-circle"></i>' . $L->g('Disable user') . '</button>
<button type="button" class="btn btn-danger me-2" id="btnDeleteUserAndKeepContent"><i class="bi bi-trash"></i>' . $L->g('Delete user and keep content') . '</button>
<button type="button" class="btn btn-danger" id="btnDeleteUserAndContent"><i class="bi bi-trash"></i>' . $L->g('Delete user and delete content') . '</button>
</div>
</div>
';
}
}
echo Bootstrap::formTitle(array('title' => $L->g('Authentication Token')));
echo Bootstrap::formInputText(array(
'name' => 'tokenAuth',
'label' => $L->g('Token'),
'value' => $user->tokenAuth(),
'tip' => $L->g('this-token-is-similar-to-a-password-it-should-not-be-shared')
));
echo Bootstrap::formTitle(array('title' => $L->g('Change password')));
echo Bootstrap::formInputText(array(
'name' => 'newPassword',
'label' => $L->g('New password'),
'type' => 'password',
'value' => ''
));
echo Bootstrap::formInputText(array(
'name' => 'confirmPassword',
'label' => $L->g('Confirm password'),
'type' => 'password',
'value' => ''
));
?>
</div>
<!-- End Tab security -->
<!-- Social Networks tab -->
<div class="tab-pane" id="social" role="tabpanel">
<?php
echo Bootstrap::formInputText(array(
'name' => 'youtube',
'label' => 'Youtube',
'value' => $user->youtube(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'twitter',
'label' => 'Twitter',
'value' => $user->twitter(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'facebook',
'label' => 'Facebook',
'value' => $user->facebook(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'codepen',
'label' => 'CodePen',
'value' => $user->codepen(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'instagram',
'label' => 'Instagram',
'value' => $user->instagram(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'gitlab',
'label' => 'GitLab',
'value' => $user->gitlab(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'github',
'label' => 'GitHub',
'value' => $user->github(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'linkedin',
'label' => 'LinkedIn',
'value' => $user->linkedin(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'xing',
'label' => 'Xing',
'value' => $user->xing(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'mastodon',
'label' => 'Mastodon',
'value' => $user->mastodon(),
'data' => array('save' => 'true')
));
echo Bootstrap::formInputText(array(
'name' => 'vk',
'label' => 'VK',
'value' => $user->vk(),
'data' => array('save' => 'true')
));
?>
</div>
</div>

View file

@ -1,56 +1,95 @@
<?php <?php defined('BLUDIT') or die('Bludit CMS.'); ?>
echo Bootstrap::pageTitle(array('title'=>$L->g('Plugins'), 'icon'=>'puzzle-piece'));
// echo Bootstrap::link(array(
// 'title'=>$L->g('Change the position of the plugins'),
// 'href'=>HTML_PATH_ADMIN_ROOT.'plugins-position',
// 'icon'=>'arrows'
// ));
echo Bootstrap::formTitle(array('title'=>$L->g('Search plugins')));
?>
<input type="text" class="form-control" id="search" placeholder="<?php $L->p('Search') ?>">
<script> <script>
$(document).ready(function() { // ============================================================================
// Variables for the view
// ============================================================================
// ============================================================================
// Functions for the view
// ============================================================================
function activatePlugin(pluginClassName) {
var args = {
pluginClassName: pluginClassName
};
api.activatePlugin(args).then(function(response) {
if (response.status == 0) {
logs('Plugin activated: ' + response.data.key);
window.location.replace('<?php echo HTML_PATH_ADMIN_ROOT . 'plugins-settings/' ?>'+response.data.key);
} else {
logs('An error occurred while trying to activate the plugin.');
showAlertError(response.message);
}
});
}
// ============================================================================
// Events for the view
// ============================================================================
$(document).ready(function() {
$("#search").on("keyup", function() { $("#search").on("keyup", function() {
var textToSearch = $(this).val().toLowerCase(); var textToSearch = $(this).val().toLowerCase();
$(".searchItem").each( function() { $(".searchItem").each(function() {
var item = $(this); var item = $(this);
item.hide(); item.hide();
item.find(".searchText").each( function() { item.find(".searchText").each(function() {
var element = $(this).text().toLowerCase(); var element = $(this).text().toLowerCase();
if (element.indexOf(textToSearch)!=-1) { if (element.indexOf(textToSearch) != -1) {
item.show(); item.show();
} }
}); });
}); });
}); });
});
$('.activatePlugin').on('click', function() {
var pluginClassName = $(this).data('class-name');
activatePlugin(pluginClassName);
});
});
// ============================================================================
// Initlization for the view
// ============================================================================
$(document).ready(function() {
// nothing here yet
// how do you hang your toilet paper ? over or under ?
});
</script> </script>
<div class="d-flex align-items-center mb-4">
<h2 class="m-0"><i class="bi bi-node-plus"></i><?php $L->p('Plugins') ?></h2>
<div class="ms-auto">
<a id="btnNew" class="btn btn-primary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT . 'plugins-position' ?>" role="button"><i class="bi bi-plus-circle"></i><?php $L->p('Change plugins position') ?></a>
</div>
</div>
<?php echo Bootstrap::formTitle(array('icon' => 'search', 'title' => $L->g('Search plugins'))); ?>
<input type="text" class="form-control" id="search" placeholder="<?php $L->p('Search') ?>">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Enabled plugins'))); echo Bootstrap::formTitle(array('icon' => 'check-square', 'title' => $L->g('Enabled plugins')));
echo ' echo '
<table class="table"> <table class="table table-striped">
<tbody> <tbody>
'; ';
// Show installed plugins // Show installed plugins
foreach ($pluginsInstalled as $plugin) { foreach ($pluginsInstalled as $plugin) {
echo '<tr id="'.$plugin->className().'" class="bg-light searchItem">'; echo '<tr id="' . $plugin->className() . '" class="bg-light searchItem">';
echo '<td class="align-middle pt-3 pb-3 w-25"> echo '<td class="align-middle pt-3 pb-3 w-25">
<div class="searchText">'.$plugin->name().'</div> <div class="searchText">' . $plugin->name() . '</div>
<div class="mt-1">'; <div class="mt-1">';
if (method_exists($plugin, 'form')) { if (method_exists($plugin, 'form')) {
echo '<a class="me-3" href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$plugin->className().'">'.$L->g('Settings').'</a>'; echo '<a class="me-3" href="' . HTML_PATH_ADMIN_ROOT . 'configure-plugin/' . $plugin->className() . '">' . $L->g('Settings') . '</a>';
} }
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$plugin->className().'">'.$L->g('Deactivate').'</a>'; echo '<a href="' . HTML_PATH_ADMIN_ROOT . 'uninstall-plugin/' . $plugin->className() . '">' . $L->g('Deactivate') . '</a>';
echo '</div>'; echo '</div>';
echo '</td>'; echo '</td>';
@ -59,11 +98,11 @@ foreach ($pluginsInstalled as $plugin) {
echo '</td>'; echo '</td>';
echo '<td class="text-center align-middle d-none d-lg-table-cell">'; echo '<td class="text-center align-middle d-none d-lg-table-cell">';
echo '<span>'.$plugin->version().'</span>'; echo '<span>' . $plugin->version() . '</span>';
echo '</td>'; echo '</td>';
echo '<td class="text-center align-middle d-none d-lg-table-cell"> echo '<td class="text-center align-middle d-none d-lg-table-cell">
<a target="_blank" href="'.$plugin->website().'">'.$plugin->author().'</a> <a target="_blank" href="' . $plugin->website() . '">' . $plugin->author() . '</a>
</td>'; </td>';
echo '</tr>'; echo '</tr>';
@ -74,22 +113,22 @@ echo '
</table> </table>
'; ';
echo Bootstrap::formTitle(array('title'=>$L->g('Disabled plugins'))); echo Bootstrap::formTitle(array('icon' => 'dash-square', 'title' => $L->g('Disabled plugins')));
echo ' echo '
<table class="table"> <table class="table table-striped">
<tbody> <tbody>
'; ';
// Plugins not installed // Plugins not installed
$pluginsNotInstalled = array_diff_key($plugins['all'], $pluginsInstalled); $pluginsNotInstalled = array_diff_key($plugins['all'], $pluginsInstalled);
foreach ($pluginsNotInstalled as $plugin) { foreach ($pluginsNotInstalled as $plugin) {
echo '<tr id="'.$plugin->className().'" class="searchItem">'; echo '<tr id="' . $plugin->className() . '" class="searchItem">';
echo '<td class="align-middle pt-3 pb-3 w-25"> echo '<td class="align-middle pt-3 pb-3 w-25">
<div class="searchText">'.$plugin->name().'</div> <div class="searchText">' . $plugin->name() . '</div>
<div class="mt-1"> <div class="mt-1">
<a href="'.HTML_PATH_ADMIN_ROOT.'install-plugin/'.$plugin->className().'">'.$L->g('Activate').'</a> <span class="link activatePlugin" data-class-name="' . $plugin->className() . '">' . $L->g('Activate') . '</a>
</div> </div>
</td>'; </td>';
@ -98,11 +137,11 @@ foreach ($pluginsNotInstalled as $plugin) {
echo '</td>'; echo '</td>';
echo '<td class="text-center align-middle d-none d-lg-table-cell">'; echo '<td class="text-center align-middle d-none d-lg-table-cell">';
echo '<span>'.$plugin->version().'</span>'; echo '<span>' . $plugin->version() . '</span>';
echo '</td>'; echo '</td>';
echo '<td class="text-center align-middle d-none d-lg-table-cell"> echo '<td class="text-center align-middle d-none d-lg-table-cell">
<a target="_blank" href="'.$plugin->website().'">'.$plugin->author().'</a> <a target="_blank" href="' . $plugin->website() . '">' . $plugin->author() . '</a>
</td>'; </td>';
echo '</tr>'; echo '</tr>';

View file

@ -1,536 +1,516 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); ?> <?php defined('BLUDIT') or die('Bludit CMS.'); ?>
<script> <script>
// ============================================================================ // ============================================================================
// Variables for the view // Variables for the view
// ============================================================================ // ============================================================================
// ============================================================================ // ============================================================================
// Functions for the view // Functions for the view
// ============================================================================ // ============================================================================
// This function catch all key press // This function catch all key press
// Provide shortcuts for the view // Provide shortcuts for the view
function keypress(event) { function keypress(event) {
logs(event); logs(event);
// Shortcuts // Shortcuts
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Ctrl+S or Command+S // Ctrl+S or Command+S
if ((event.ctrlKey || event.metaKey) && event.which == 83) { if ((event.ctrlKey || event.metaKey) && event.which == 83) {
save();
$('#btnSave').addClass('btn-primary-disabled').html('<?php $L->p('Saved') ?>');
event.preventDefault(); event.preventDefault();
save();
return false; return false;
} }
$('#btnSave').removeClass('btn-primary-disabled').html('<?php $L->p('Save') ?>');
return true; return true;
} }
function save() { // Save the settings
function save() {
var args = {} var args = {}
// Get values from all inputs['text'] $('input[data-save="true"]').each(function() {
$('input[type=text]').each(function(){
var key = $(this).attr('name'); var key = $(this).attr('name');
var value = $(this).val(); var value = $(this).val();
args[key] = value; args[key] = value;
}); });
// Get values from all selects $('select[data-save="true"]').each(function() {
$('select').each(function() {
var key = $(this).attr('name'); var key = $(this).attr('name');
var value = $(this).val(); var value = $(this).val();
args[key] = value; args[key] = value;
}); });
logs('Saving settings');
api.saveSettings(args).then(function(response) { api.saveSettings(args).then(function(response) {
logs('Settings saved'); if (response.status == 0) {
logs('Settings saved.');
showAlertInfo("<?php $L->p('The changes have been saved') ?>");
} else {
logs('An error occurred while trying to save the settings.');
showAlertError(response.message);
}
}); });
return true; return true;
} }
// ============================================================================ // ============================================================================
// Events for the view // Events for the view
// ============================================================================ // ============================================================================
$(document).ready(function() { $(document).ready(function() {
// Main interface events $(this).keydown(function(event) {
// ------------------------------------------------------------------------
$(this).keydown(function(event){
keypress(event); keypress(event);
}); });
$('#btnSave').on('click', function() { $('#btnSave').on('click', function() {
save(); save();
$(this).addClass('btn-primary-disabled').html('<?php $L->p('Saved') ?>');
}); });
}); });
// ============================================================================ // ============================================================================
// Initlization for the view // Initlization for the view
// ============================================================================ // ============================================================================
$(document).ready(function() { $(document).ready(function() {
// nothing here yet // nothing here yet
// how do you hang your toilet paper ? over or under ? // how do you hang your toilet paper ? over or under ?
}); });
</script> </script>
<div class="align-middle"> <div class="d-flex align-items-center mb-4">
<div class="float-end mt-1"> <h2 class="m-0"><i class="bi bi-gear"></i><?php $L->p('Settings') ?></h2>
<button type="button" class="btn btn-primary btn-sm btn-primary-disabled" id="btnSave"><?php $L->p('Saved') ?></button> <div class="ms-auto">
<a class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT.'dashboard' ?>" role="button"><?php $L->p('Cancel') ?></a> <button id="btnSave" type="button" class="btn btn-primary btn-sm"><?php $L->p('Save') ?></button>
<a id="btnCancel" class="btn btn-secondary btn-sm" href="<?php echo HTML_PATH_ADMIN_ROOT . 'users' ?>" role="button"><?php $L->p('Cancel') ?></a>
</div> </div>
<?php echo Bootstrap::pageTitle(array('title'=>$L->g('Settings'), 'icon'=>'cog')); ?>
</div> </div>
<!-- Tabs --> <!-- Tabs -->
<nav> <ul class="nav nav-tabs ps-3 mb-3" role="tablist">
<div class="nav nav-tabs ps-3" id="nav-tab" role="tablist"> <li class="nav-item">
<a class="nav-item nav-link active" id="nav-general-tab" data-toggle="tab" href="#general" role="tab" aria-controls="nav-general" aria-selected="false"><?php $L->p('General') ?></a> <a class="nav-link active" id="general-tab" data-bs-toggle="tab" href="#general" role="tab" aria-controls="general" aria-selected="true"><?php $L->p('general') ?></a>
<a class="nav-item nav-link" id="nav-advanced-tab" data-toggle="tab" href="#advanced" role="tab" aria-controls="nav-advanced" aria-selected="false"><?php $L->p('Advanced') ?></a> </li>
<a class="nav-item nav-link" id="nav-seo-tab" data-toggle="tab" href="#seo" role="tab" aria-controls="nav-seo" aria-selected="false"><?php $L->p('SEO') ?></a> <li class="nav-item">
<a class="nav-item nav-link" id="nav-social-tab" data-toggle="tab" href="#social" role="tab" aria-controls="nav-social" aria-selected="false"><?php $L->p('Social Networks') ?></a> <a class="nav-link" id="advanced-tab" data-bs-toggle="tab" href="#advanced" role="tab" aria-controls="advanced" aria-selected="false"><?php $L->p('advanced') ?></a>
<a class="nav-item nav-link" id="nav-images-tab" data-toggle="tab" href="#images" role="tab" aria-controls="nav-images" aria-selected="false"><?php $L->p('Images') ?></a> </li>
<a class="nav-item nav-link" id="nav-language-tab" data-toggle="tab" href="#language" role="tab" aria-controls="nav-language" aria-selected="false"><?php $L->p('Language') ?></a> <li class="nav-item">
<a class="nav-item nav-link" id="nav-custom-fields-tab" data-toggle="tab" href="#custom-fields" role="tab" aria-controls="nav-custom-fields" aria-selected="false"><?php $L->p('Custom fields') ?></a> <a class="nav-link" id="seo-tab" data-bs-toggle="tab" href="#seo" role="tab" aria-controls="seo" aria-selected="false"><?php $L->p('seo') ?></a>
<a class="nav-item nav-link" id="nav-logo-tab" data-toggle="tab" href="#logo" role="tab" aria-controls="nav-logo" aria-selected="false"><?php $L->p('Logo') ?></a> </li>
</div> <li class="nav-item">
</nav> <a class="nav-link" id="social-tab" data-bs-toggle="tab" href="#social" role="tab" aria-controls="social" aria-selected="false"><?php $L->p('Social Networks') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="images-tab" data-bs-toggle="tab" href="#images" role="tab" aria-controls="images" aria-selected="false"><?php $L->p('images') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="language-tab" data-bs-toggle="tab" href="#language" role="tab" aria-controls="language" aria-selected="false"><?php $L->p('language') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="custom-fields-tab" data-bs-toggle="tab" href="#custom-fields" role="tab" aria-controls="custom-fields" aria-selected="false"><?php $L->p('custom-fields') ?></a>
</li>
<li class="nav-item">
<a class="nav-link" id="logo-tab" data-bs-toggle="tab" href="#logo" role="tab" aria-controls="logo" aria-selected="false"><?php $L->p('Site logo') ?></a>
</li>
</ul>
<!-- End Tabs --> <!-- End Tabs -->
<div class="tab-content" id="myTabContent"> <!-- Content -->
<div class="tab-content" id="tabContent">
<!-- General tab --> <!-- General tab -->
<div class="tab-pane show active pt-1 pb-1 ps-3 pe-3" id="general" role="tabpanel" aria-labelledby="general-tab"> <div class="tab-pane show active" id="general" role="tabpanel">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Site'))); echo Bootstrap::formTitle(array('title' => $L->g('Site')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'title', 'name' => 'title',
'label'=>$L->g('Site title'), 'label' => $L->g('Site title'),
'value'=>$site->title(), 'value' => $site->title(),
'tip'=>$L->g('use-this-field-to-name-your-site') 'tip' => $L->g('use-this-field-to-name-your-site'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'slogan', 'name' => 'slogan',
'label'=>$L->g('Site slogan'), 'label' => $L->g('Site slogan'),
'value'=>$site->slogan(), 'value' => $site->slogan(),
'tip'=>$L->g('use-this-field-to-add-a-catchy-phrase') 'tip' => $L->g('use-this-field-to-add-a-catchy-phrase'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'description', 'name' => 'description',
'label'=>$L->g('Site description'), 'label' => $L->g('Site description'),
'value'=>$site->description(), 'value' => $site->description(),
'tip'=>$L->g('you-can-add-a-site-description-to-provide') 'tip' => $L->g('you-can-add-a-site-description-to-provide'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'footer', 'name' => 'footer',
'label'=>$L->g('Footer text'), 'label' => $L->g('Footer text'),
'value'=>$site->footer(), 'value' => $site->footer(),
'tip'=>$L->g('you-can-add-a-small-text-on-the-bottom') 'tip' => $L->g('you-can-add-a-small-text-on-the-bottom'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Content'))); echo Bootstrap::formTitle(array('title' => $L->g('Autosave')));
echo Bootstrap::formInputText(array(
'name' => 'autosaveInterval',
'label' => $L->g('Interval'),
'value' => $site->autosaveInterval(),
'tip' => $L->g('Number in minutes for every execution of autosave'),
'data' => array('save' => 'true')
));
echo Bootstrap::formTitle(array('title' => $L->g('Content')));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'itemsPerPage', 'name' => 'itemsPerPage',
'label'=>$L->g('Items per page'), 'label' => $L->g('Items per page'),
'options'=>array('1'=>'1','2'=>'2','3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8', '-1'=>$L->g('All content')), 'options' => array('1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '-1' => $L->g('All content')),
'selected'=>$site->itemsPerPage(), 'selected' => $site->itemsPerPage(),
'tip'=>$L->g('Number of items to show per page') 'tip' => $L->g('Number of items to show per page'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'orderBy', 'name' => 'orderBy',
'label'=>$L->g('Order content by'), 'label' => $L->g('Order content by'),
'options'=>array('date'=>$L->g('Date'),'position'=>$L->g('Position')), 'options' => array('date' => $L->g('Date'), 'position' => $L->g('Position')),
'selected'=>$site->orderBy(), 'selected' => $site->orderBy(),
'tip'=>$L->g('order-the-content-by-date-to-build-a-blog') 'tip' => $L->g('order-the-content-by-date-to-build-a-blog'),
'data' => array('save' => 'true')
)); ));
?> ?>
</div> </div>
<!-- End General tab --> <!-- End General tab -->
<!-- Advanced tab --> <!-- Advanced tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="advanced" role="tabpanel" aria-labelledby="advanced-tab"> <div class="tab-pane" id="advanced" role="tabpanel">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Page content'))); echo Bootstrap::formTitle(array('title' => $L->g('Page content')));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'markdownParser', 'name' => 'markdownParser',
'label'=>$L->g('Markdown parser'), 'label' => $L->g('Markdown parser'),
'options'=>array('true'=>$L->g('Enabled'), 'false'=>$L->g('Disabled')), 'options' => array('true' => $L->g('Enabled'), 'false' => $L->g('Disabled')),
'selected'=>($site->markdownParser()?'true':'false'), 'selected' => ($site->markdownParser() ? 'true' : 'false'),
'tip'=>$L->g('Enable the markdown parser for the content of the page.') 'tip' => $L->g('Enable the markdown parser for the content of the page.'),
'data' => array('save' => 'true')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Predefined pages'))); echo Bootstrap::formTitle(array('title' => $L->g('Predefined pages')));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'homepage', 'name' => 'homepage',
'label'=>$L->g('Homepage'), 'label' => $L->g('Homepage'),
'options'=>$options, 'options' => array(), // Complete via Ajax
'selected'=>false, 'selected' => false,
'class'=>'', 'tip' => $L->g('Returning page for the main page'),
'tip'=>$L->g('Returning page for the main page') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'pageNotFound', 'name' => 'pageNotFound',
'label'=>$L->g('Page not found'), 'label' => $L->g('Page not found'),
'options'=>$options, 'options' => array(), // Complete via Ajax
'selected'=>false, 'selected' => false,
'class'=>'', 'tip' => $L->g('Returning page when the page doesnt exist'),
'tip'=>$L->g('Returning page when the page doesnt exist') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Email account settings'))); echo Bootstrap::formTitle(array('title' => $L->g('Email account settings')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'emailFrom', 'name' => 'emailFrom',
'label'=>$L->g('Sender email'), 'label' => $L->g('Sender email'),
'value'=>$site->emailFrom(), 'value' => $site->emailFrom(),
'class'=>'', 'tip' => $L->g('Emails will be sent from this address'),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Emails will be sent from this address')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Autosave'))); echo Bootstrap::formTitle(array('title' => $L->g('Site URL')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'autosaveInterval', 'name' => 'url',
'label'=>$L->g('Interval'), 'label' => 'URL',
'value'=>$site->autosaveInterval(), 'value' => $site->url(),
'class'=>'', 'tip' => $L->g('full-url-of-your-site'),
'placeholder'=>'', 'placeholder' => 'https://',
'tip'=>$L->g('Number in minutes for every execution of autosave') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Site URL'))); echo Bootstrap::formTitle(array('title' => $L->g('URL Filters')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'url', 'name' => 'uriPage',
'label'=>'URL', 'label' => $L->g('Pages'),
'value'=>$site->url(), 'value' => $site->uriFilters('page'),
'class'=>'', 'tip' => DOMAIN_PAGES,
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('full-url-of-your-site'),
'placeholder'=>'https://'
));
echo Bootstrap::formTitle(array('title'=>$L->g('URL Filters')));
echo Bootstrap::formInputText(array(
'name'=>'uriPage',
'label'=>$L->g('Pages'),
'value'=>$site->uriFilters('page'),
'class'=>'',
'placeholder'=>'',
'tip'=>DOMAIN_PAGES
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'uriTag', 'name' => 'uriTag',
'label'=>$L->g('Tags'), 'label' => $L->g('Tags'),
'value'=>$site->uriFilters('tag'), 'value' => $site->uriFilters('tag'),
'class'=>'', 'tip' => DOMAIN_TAGS,
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>DOMAIN_TAGS
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'uriCategory', 'name' => 'uriCategory',
'label'=>$L->g('Category'), 'label' => $L->g('Category'),
'value'=>$site->uriFilters('category'), 'value' => $site->uriFilters('category'),
'class'=>'', 'tip' => DOMAIN_CATEGORIES,
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>DOMAIN_CATEGORIES
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'uriBlog', 'name' => 'uriBlog',
'label'=>$L->g('Blog'), 'label' => $L->g('Blog'),
'value'=>$site->uriFilters('blog'), 'value' => $site->uriFilters('blog'),
'class'=>'', 'tip' => DOMAIN . $site->uriFilters('blog'),
'placeholder'=>'', 'disabled' => Text::isEmpty($site->uriFilters('blog')),
'tip'=>DOMAIN.$site->uriFilters('blog'), 'data' => array('save' => 'true')
'disabled'=>Text::isEmpty($site->uriFilters('blog'))
)); ));
?> ?>
</div> </div>
<!-- SEO tab --> <!-- SEO tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="seo" role="tabpanel" aria-labelledby="seo-tab"> <div class="tab-pane" id="seo" role="tabpanel" aria-labelledby="seo-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Extreme friendly URL'))); echo Bootstrap::formTitle(array('title' => $L->g('Extreme friendly URL')));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'extremeFriendly', 'name' => 'extremeFriendly',
'label'=>$L->g('Allow Unicode'), 'label' => $L->g('Allow Unicode'),
'options'=>array('true'=>$L->g('Enabled'), 'false'=>$L->g('Disabled')), 'options' => array('true' => $L->g('Enabled'), 'false' => $L->g('Disabled')),
'selected'=>($site->extremeFriendly()?'true':'false'), 'selected' => ($site->extremeFriendly() ? 'true' : 'false'),
'class'=>'', 'tip' => $L->g('Allow unicode characters in the URL and some part of the system.'),
'tip'=>$L->g('Allow unicode characters in the URL and some part of the system.') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Title formats'))); echo Bootstrap::formTitle(array('title' => $L->g('Title formats')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'titleFormatHomepage', 'name' => 'titleFormatHomepage',
'label'=>$L->g('Homepage'), 'label' => $L->g('Homepage'),
'value'=>$site->titleFormatHomepage(), 'value' => $site->titleFormatHomepage(),
'class'=>'', 'tip' => $L->g('Variables allowed') . ' <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Variables allowed').' <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'titleFormatPages', 'name' => 'titleFormatPages',
'label'=>$L->g('Pages'), 'label' => $L->g('Pages'),
'value'=>$site->titleFormatPages(), 'value' => $site->titleFormatPages(),
'class'=>'', 'tip' => $L->g('Variables allowed') . ' <code>{{page-title}}</code> <code>{{page-description}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Variables allowed').' <code>{{page-title}}</code> <code>{{page-description}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'titleFormatCategory', 'name' => 'titleFormatCategory',
'label'=>$L->g('Category'), 'label' => $L->g('Category'),
'value'=>$site->titleFormatCategory(), 'value' => $site->titleFormatCategory(),
'class'=>'', 'class' => '',
'placeholder'=>'', 'tip' => $L->g('Variables allowed') . ' <code>{{category-name}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'tip'=>$L->g('Variables allowed').' <code>{{category-name}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>', 'data' => array('save' => 'true')
'placeholder'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'titleFormatTag', 'name' => 'titleFormatTag',
'label'=>$L->g('Tag'), 'label' => $L->g('Tag'),
'value'=>$site->titleFormatTag(), 'value' => $site->titleFormatTag(),
'class'=>'', 'tip' => $L->g('Variables allowed') . ' <code>{{tag-name}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Variables allowed').' <code>{{tag-name}}</code> <code>{{site-title}}</code> <code>{{site-slogan}}</code> <code>{{site-description}}</code>',
'placeholder'=>''
)); ));
?> ?>
</div> </div>
<!-- Social Network tab --> <!-- Social Network tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="social" role="tabpanel" aria-labelledby="social-tab"> <div class="tab-pane" id="social" role="tabpanel" aria-labelledby="social-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Social Networks'))); echo Bootstrap::formTitle(array('title' => $L->g('Social Networks')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'twitter', 'name' => 'twitter',
'label'=>'Twitter', 'label' => 'Twitter',
'value'=>$site->twitter(), 'value' => $site->twitter(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'facebook', 'name' => 'facebook',
'label'=>'Facebook', 'label' => 'Facebook',
'value'=>$site->facebook(), 'value' => $site->facebook(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'codepen', 'name' => 'codepen',
'label'=>'CodePen', 'label' => 'CodePen',
'value'=>$site->codepen(), 'value' => $site->codepen(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'instagram', 'name' => 'instagram',
'label'=>'Instagram', 'label' => 'Instagram',
'value'=>$site->instagram(), 'value' => $site->instagram(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'gitlab', 'name' => 'gitlab',
'label'=>'GitLab', 'label' => 'GitLab',
'value'=>$site->gitlab(), 'value' => $site->gitlab(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'github', 'name' => 'github',
'label'=>'GitHub', 'label' => 'GitHub',
'value'=>$site->github(), 'value' => $site->github(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'linkedin', 'name' => 'linkedin',
'label'=>'LinkedIn', 'label' => 'LinkedIn',
'value'=>$site->linkedin(), 'value' => $site->linkedin(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'xing', 'name' => 'xing',
'label'=>'Xing', 'label' => 'Xing',
'value'=>$site->xing(), 'value' => $site->xing(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'mastodon', 'name' => 'mastodon',
'label'=>'Mastodon', 'label' => 'Mastodon',
'value'=>$site->mastodon(), 'value' => $site->mastodon(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'dribbble', 'name' => 'dribbble',
'label'=>'Dribbble', 'label' => 'Dribbble',
'value'=>$site->dribbble(), 'value' => $site->dribbble(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'vk', 'name' => 'vk',
'label'=>'VK', 'label' => 'VK',
'value'=>$site->vk(), 'value' => $site->vk(),
'class'=>'', 'data' => array('save' => 'true')
'placeholder'=>'',
'tip'=>''
)); ));
?> ?>
</div> </div>
<!-- Images tab --> <!-- Images tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="images" role="tabpanel" aria-labelledby="images-tab"> <div class="tab-pane" id="images" role="tabpanel" aria-labelledby="images-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Thumbnails'))); echo Bootstrap::formTitle(array('title' => $L->g('Thumbnails')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'thumbnailWidth', 'name' => 'thumbnailWidth',
'label'=>$L->g('Width'), 'label' => $L->g('Width'),
'value'=>$site->thumbnailWidth(), 'value' => $site->thumbnailWidth(),
'class'=>'', 'tip' => $L->g('Thumbnail width in pixels'),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Thumbnail width in pixels')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'thumbnailHeight', 'name' => 'thumbnailHeight',
'label'=>$L->g('Height'), 'label' => $L->g('Height'),
'value'=>$site->thumbnailHeight(), 'value' => $site->thumbnailHeight(),
'class'=>'', 'tip' => $L->g('Thumbnail height in pixels'),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Thumbnail height in pixels')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'thumbnailQuality', 'name' => 'thumbnailQuality',
'label'=>$L->g('Quality'), 'label' => $L->g('Quality'),
'value'=>$site->thumbnailQuality(), 'value' => $site->thumbnailQuality(),
'class'=>'', 'tip' => $L->g('Thumbnail quality in percentage'),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Thumbnail quality in percentage')
)); ));
?> ?>
</div> </div>
<!-- Timezone and language tab --> <!-- Timezone and language tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="language" role="tabpanel" aria-labelledby="language-tab"> <div class="tab-pane" id="language" role="tabpanel" aria-labelledby="language-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Language and timezone'))); echo Bootstrap::formTitle(array('title' => $L->g('Language and timezone')));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'language', 'name' => 'language',
'label'=>$L->g('Language'), 'label' => $L->g('Language'),
'options'=>$L->getLanguageList(), 'options' => $L->getLanguageList(),
'selected'=>$site->language(), 'selected' => $site->language(),
'class'=>'', 'tip' => $L->g('select-your-sites-language'),
'tip'=>$L->g('select-your-sites-language') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formSelect(array( echo Bootstrap::formSelect(array(
'name'=>'timezone', 'name' => 'timezone',
'label'=>$L->g('Timezone'), 'label' => $L->g('Timezone'),
'options'=>Date::timezoneList(), 'options' => Date::timezoneList(),
'selected'=>$site->timezone(), 'selected' => $site->timezone(),
'class'=>'', 'tip' => $L->g('select-a-timezone-for-a-correct'),
'tip'=>$L->g('select-a-timezone-for-a-correct') 'data' => array('save' => 'true')
)); ));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'locale', 'name' => 'locale',
'label'=>$L->g('Locale'), 'label' => $L->g('Locale'),
'value'=>$site->locale(), 'value' => $site->locale(),
'class'=>'', 'tip' => $L->g('with-the-locales-you-can-set-the-regional-user-interface'),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('with-the-locales-you-can-set-the-regional-user-interface')
)); ));
echo Bootstrap::formTitle(array('title'=>$L->g('Date and time formats'))); echo Bootstrap::formTitle(array('title' => $L->g('Date and time formats')));
echo Bootstrap::formInputText(array( echo Bootstrap::formInputText(array(
'name'=>'dateFormat', 'name' => 'dateFormat',
'label'=>$L->g('Date format'), 'label' => $L->g('Date format'),
'value'=>$site->dateFormat(), 'value' => $site->dateFormat(),
'class'=>'', 'tip' => $L->g('Current format') . ': ' . Date::current($site->dateFormat()),
'placeholder'=>'', 'data' => array('save' => 'true')
'tip'=>$L->g('Current format').': '.Date::current($site->dateFormat())
)); ));
?> ?>
</div> </div>
<!-- Custom fields --> <!-- Custom fields -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="custom-fields" role="tabpanel" aria-labelledby="custom-fields-tab"> <div class="tab-pane" id="custom-fields" role="tabpanel" aria-labelledby="custom-fields-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Custom fields'))); echo Bootstrap::formTitle(array('title' => $L->g('Custom fields')));
echo Bootstrap::formTextarea(array( echo Bootstrap::formTextarea(array(
'name'=>'customFields', 'name' => 'customFields',
'label'=>'JSON Format', 'label' => 'JSON Format',
'value'=>json_encode($site->customFields(), JSON_PRETTY_PRINT), 'value' => json_encode($site->customFields(), JSON_PRETTY_PRINT),
'class'=>'', 'tip' => $L->g('define-custom-fields-for-the-content'),
'placeholder'=>'', 'rows' => 15,
'tip'=>$L->g('define-custom-fields-for-the-content'), 'data' => array('save' => 'true')
'rows'=>15
)); ));
?> ?>
</div> </div>
<!-- Site logo tab --> <!-- Site logo tab -->
<div class="tab-pane pt-1 pb-1 ps-3 pe-3" id="logo" role="tabpanel" aria-labelledby="logo-tab"> <div class="tab-pane" id="logo" role="tabpanel" aria-labelledby="logo-tab">
<?php <?php
echo Bootstrap::formTitle(array('title'=>$L->g('Site logo'))); echo Bootstrap::formTitle(array('title' => $L->g('Site logo')));
?> ?>
<div class="container"> <div class="container">
@ -543,14 +523,14 @@ $(document).ready(function() {
<button id="jsbuttonRemoveLogo" type="button" class="btn btn-primary w-100 mt-4 mb-4"><i class="bi-trash"></i><?php $L->p('Remove logo') ?></button> <button id="jsbuttonRemoveLogo" type="button" class="btn btn-primary w-100 mt-4 mb-4"><i class="bi-trash"></i><?php $L->p('Remove logo') ?></button>
</div> </div>
<div class="col-lg-8 col-sm-12 p-0 text-center"> <div class="col-lg-8 col-sm-12 p-0 text-center">
<img id="jssiteLogoPreview" class="img-fluid img-thumbnail" alt="Site logo preview" src="<?php echo ($site->logo()?DOMAIN_UPLOADS.$site->logo(false).'?version='.time():HTML_PATH_CORE_IMG.'default.svg') ?>" /> <img id="jssiteLogoPreview" class="img-fluid img-thumbnail" alt="Site logo preview" src="<?php echo ($site->logo() ? DOMAIN_UPLOADS . $site->logo(false) . '?version=' . time() : HTML_PATH_CORE_IMG . 'default.svg') ?>" />
</div> </div>
</div> </div>
</div> </div>
<script> <script>
$("#jsbuttonRemoveLogo").on("click", function() { $("#jsbuttonRemoveLogo").on("click", function() {
bluditAjax.removeLogo(); bluditAjax.removeLogo();
$("#jssiteLogoPreview").attr("src", "<?php echo HTML_PATH_CORE_IMG.'default.svg' ?>"); $("#jssiteLogoPreview").attr("src", "<?php echo HTML_PATH_CORE_IMG . 'default.svg' ?>");
}); });
$("#jssiteLogoInputFile").on("change", function() { $("#jssiteLogoInputFile").on("change", function() {
@ -558,15 +538,15 @@ $(document).ready(function() {
formData.append('tokenCSRF', tokenCSRF); formData.append('tokenCSRF', tokenCSRF);
formData.append('inputFile', $(this)[0].files[0]); formData.append('inputFile', $(this)[0].files[0]);
$.ajax({ $.ajax({
url: HTML_PATH_ADMIN_ROOT+"ajax/logo-upload", url: HTML_PATH_ADMIN_ROOT + "ajax/logo-upload",
type: "POST", type: "POST",
data: formData, data: formData,
cache: false, cache: false,
contentType: false, contentType: false,
processData: false processData: false
}).done(function(data) { }).done(function(data) {
if (data.status==0) { if (data.status == 0) {
$("#jssiteLogoPreview").attr('src',data.absoluteURL+"?time="+Math.random()); $("#jssiteLogoPreview").attr('src', data.absoluteURL + "?time=" + Math.random());
} else { } else {
showAlert(data.message); showAlert(data.message);
} }
@ -575,3 +555,5 @@ $(document).ready(function() {
</script> </script>
</div> </div>
</div>
<!-- End Content -->

View file

@ -29,6 +29,9 @@ $plugins = array(
'paginator'=>array(), 'paginator'=>array(),
'beforePageModify'=>array(),
'beforePageDelete'=>array(),
'afterPageCreate'=>array(), 'afterPageCreate'=>array(),
'afterPageModify'=>array(), 'afterPageModify'=>array(),
'afterPageDelete'=>array(), 'afterPageDelete'=>array(),

View file

@ -73,6 +73,9 @@ function editPage($args) {
return false; return false;
} }
// Call the plugins before the page is edited
execPluginsByHook('beforePageModify', array($args['key']));
$key = $pages->edit($args); $key = $pages->edit($args);
if ($key) { if ($key) {
// Call the plugins after page modified // Call the plugins after page modified
@ -105,6 +108,9 @@ function deletePage($args) {
global $pages; global $pages;
global $syslog; global $syslog;
// Call the plugins before the page is deleted
execPluginsByHook('beforePageDelete', array($args['key']));
if ($pages->delete($args['key'])) { if ($pages->delete($args['key'])) {
// Call the plugins after page deleted // Call the plugins after page deleted
execPluginsByHook('afterPageDelete', array($args['key'])); execPluginsByHook('afterPageDelete', array($args['key']));
@ -497,6 +503,34 @@ function uploadPageFile($pageKey) {
return false; return false;
} }
/* Install and activate a plugin === Bludit v4
@pluginClassName string The plugin PHP class name
@return string/bool Returns TRUE on successful install, FALSE otherwise
*/
function activatePlugin($pluginClassName) {
global $plugins;
global $syslog;
if (!isset($plugins['all'][$pluginClassName])) {
Log::set(__FUNCTION__.LOG_SEP.'The plugin doesn\'t exist: '.$pluginClassName, LOG_TYPE_ERROR);
return false;
}
$plugin = $plugins['all'][$pluginClassName];
if ($plugin->install()) {
$syslog->add(array(
'dictionaryKey'=>'plugin-activated',
'notes'=>$plugin->name()
));
Log::set(__FUNCTION__.LOG_SEP.'Plugin installed.', LOG_TYPE_INFO);
return true;
}
Log::set(__FUNCTION__.LOG_SEP.'Not was possible install the plugin.', LOG_TYPE_ERROR);
return false;
}
// Re-index database of categories // Re-index database of categories
// If you create/edit/remove a page is necessary regenerate the database of categories // If you create/edit/remove a page is necessary regenerate the database of categories
function reindexCategories() { function reindexCategories() {
@ -702,30 +736,7 @@ function pluginActivated($pluginClassName) {
return false; return false;
} }
// Activate / install the plugin
// Returns TRUE if the plugin is successfully activated, FALSE otherwise
function activatePlugin($pluginClassName) {
global $plugins;
global $syslog;
global $L;
// Check if the plugin exists
if (isset($plugins['all'][$pluginClassName])) {
$plugin = $plugins['all'][$pluginClassName];
if ($plugin->install()) {
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'plugin-activated',
'notes'=>$plugin->name()
));
// Create an alert
Alert::set($L->g('plugin-activated'));
return true;
}
}
return false;
}
// Deactivate / uninstall the plugin // Deactivate / uninstall the plugin
// Returns TRUE if the plugin is successfully deactivated, FALSE otherwise // Returns TRUE if the plugin is successfully deactivated, FALSE otherwise

View file

@ -46,12 +46,21 @@ EOF;
$class = $class.' '.$args['class']; $class = $class.' '.$args['class'];
} }
$data = 'data-current-value="'.$args['selected'].'"';
if (isset($args['data'])) {
if (is_array($args['data'])) {
foreach ($args['data'] as $x => $y) {
$data .= 'data-'.$x.' = "'.$y.'"';
}
}
}
$html = '<div class="mb-3 row">'; $html = '<div class="mb-3 row">';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$html .= '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>'; $html .= '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>';
} }
$html .= '<div class="col-sm-10">'; $html .= '<div class="col-sm-10">';
$html .= '<select id="'.$id.'" name="'.$name.'" class="'.$class.'">'; $html .= '<select id="'.$id.'" name="'.$name.'" class="'.$class.'" '.$data.'>';
foreach ($args['options'] as $key=>$value) { foreach ($args['options'] as $key=>$value) {
$html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>'; $html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>';
} }
@ -148,103 +157,46 @@ EOF;
$class = $class.' '.$args['class']; $class = $class.' '.$args['class'];
} }
$data = 'data-current-value="'.$value.'"';
if (isset($args['data'])) {
if (is_array($args['data'])) {
foreach ($args['data'] as $x => $y) {
$data .= ' data-'.$x.' = "'.$y.'"';
}
}
}
return <<<EOF return <<<EOF
<div class="mb-3 row"> <div class="mb-3 row">
$label $label
<div class="col-sm-10"> <div class="col-sm-10">
<input class="$class" id="$id" name="$name" value="$value" placeholder="$placeholder" type="$type" $disabled $readonly> <input class="$class" $data id="$id" name="$name" value="$value" placeholder="$placeholder" type="$type" $disabled $readonly>
$tip $tip
</div> </div>
</div> </div>
EOF; EOF;
} }
public static function formSelectOld($args)
{
$name = $args['name'];
$id = isset($args['id'])?$args['id']:$name;
$value = isset($args['value'])?$args['value']:'';
$class = 'custom-select';
if (isset($args['class'])) {
$class = $class.' '.$args['class'];
}
$html = '<div class="mb-3 row">';
if (!empty($args['label'])) {
$html .= '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>';
}
$html .= '<div class="col-sm-10">';
$html .= '<select id="'.$id.'" name="'.$name.'" class="'.$class.'">';
foreach ($args['options'] as $key=>$value) {
$html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>';
}
$html .= '</select>';
if (!empty($args['tip'])) {
$html .= '<div class="form-text">'.$args['tip'].'</div>';
}
$html .= '</div>';
$html .= '</div>';
return $html;
}
public static function pageTitle($args) public static function pageTitle($args)
{ {
$icon = $args['icon']; $title = '';
$title = $args['title']; if (isset($args['icon'])) {
return <<<EOF $title = '<span class="bi bi-'.$args['icon'].'"></span>';
<h2 class="m-0"> }
<span class="bi bi-$icon"></span><span>$title</span> $title .= '<span>'.$args['title'].'</span>';
</h2> return '<h2 class="m-0">'.$title.'</h2>';
EOF;
} }
public static function formTitle($args) public static function formTitle($args)
{ {
$title = $args['title']; $title = '';
return <<<EOF if (isset($args['icon'])) {
<h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">$title</h6> $title = '<span class="bi bi-'.$args['icon'].'"></span>';
EOF;
} }
$title .= '<span>'.$args['title'].'</span>';
return '<h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">'.$title.'</h6>';
// -- OLD --------
public static function modal($args) {
$buttonSecondary = $args['buttonSecondary'];
$buttonSecondaryClass = $args['buttonSecondaryClass'];
$buttonPrimary = $args['buttonPrimary'];
$buttonPrimaryClass = $args['buttonPrimaryClass'];
$modalText = $args['modalText'];
$modalTitle = $args['modalTitle'];
$modalId = $args['modalId'];
return <<<EOF
<div id="$modalId" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<h3>$modalTitle</h3>
<p>$modalText</p>
</div>
<div class="modal-footer">
<button type="button" class="btn $buttonSecondaryClass" data-dismiss="modal">$buttonSecondary</button>
<button type="button" class="btn $buttonPrimaryClass">$buttonPrimary</button>
</div>
</div>
</div>
</div>
EOF;
} }
public static function formOpen($args) public static function formOpen($args)
{ {
$class = empty($args['class'])?'':'class="'.$args['class'].'"'; $class = empty($args['class'])?'':'class="'.$args['class'].'"';

View file

@ -293,4 +293,29 @@ class API {
} }
} }
/* Install and activate a plugin === Bludit v4
@args array Arguments can be any of the fields from a category
@return string New category key
*/
async activatePlugin(args) {
var url = this.apiURL + "plugins/" + args['pluginClassName'];
var body = Object.assign({}, this.body, args);
try {
var response = await fetch(url, {
credentials: "same-origin",
method: "POST",
body: JSON.stringify(body),
headers: new Headers({
"Content-Type": "application/json"
})
});
var json = await response.json();
return json;
} catch (err) {
console.log(err);
return true;
}
}
} }

View file

@ -105,6 +105,11 @@ class User {
return $this->getValue('registered'); return $this->getValue('registered');
} }
public function youtube()
{
return $this->getValue('youtube');
}
public function twitter() public function twitter()
{ {
return $this->getValue('twitter'); return $this->getValue('twitter');
@ -171,6 +176,7 @@ class User {
$tmp['lastName'] = $this->lastName(); $tmp['lastName'] = $this->lastName();
$tmp['nickname'] = $this->nickname(); $tmp['nickname'] = $this->nickname();
$tmp['description'] = $this->description(); $tmp['description'] = $this->description();
$tmp['youtube'] = $this->youtube();
$tmp['twitter'] = $this->twitter(); $tmp['twitter'] = $this->twitter();
$tmp['facebook'] = $this->facebook(); $tmp['facebook'] = $this->facebook();
$tmp['codepen'] = $this->codepen(); $tmp['codepen'] = $this->codepen();

View file

@ -23,7 +23,8 @@ class Users extends dbJSON {
'gitlab'=>'', 'gitlab'=>'',
'linkedin'=>'', 'linkedin'=>'',
'mastodon'=>'', 'mastodon'=>'',
'vk'=>'' 'vk'=>'',
'youtube'=>''
); );
function __construct() function __construct()

View file

@ -265,6 +265,11 @@ class pluginAPI extends Plugin {
$inputs['username'] = $parmB; $inputs['username'] = $parmB;
$data = $this->editUser($inputs); $data = $this->editUser($inputs);
} }
// (POST) /api/plugins/:key
elseif ( ($method==='POST') && ($parmA==='plugins') && !empty($parmB) ) {
$pluginClassName = $parmB;
$data = $this->activatePlugin($pluginClassName);
}
// (GET) /api/helper/:name // (GET) /api/helper/:name
elseif ( ($method==='GET') && ($parmA==='helper') && !empty($parmB) ) { elseif ( ($method==='GET') && ($parmA==='helper') && !empty($parmB) ) {
$name = $parmB; $name = $parmB;
@ -915,4 +920,23 @@ class pluginAPI extends Plugin {
'data'=>$files 'data'=>$files
); );
} }
/* Install and activate a plugin === Bludit v4
Referer to the function activatePlugin() from functions.php
*/
private function activatePlugin($pluginClassName)
{
if (activatePlugin($pluginClassName)) {
return array(
'status'=>'0',
'message'=>'Plugin installed and activated.',
'data'=>array('key'=>$pluginClassName)
);
}
return array(
'status'=>'1',
'message'=>'An error occurred while trying to install the plugin.'
);
}
} }