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;
}
.link {
cursor: pointer;
text-decoration: underline;
color: #555;
}
.link:hover {
color: #0a58ca;
}
/*
OLD >>>>>>>>>
*/

View file

@ -72,31 +72,24 @@ function table($type)
echo '<td class="pt-3 pb-3">
<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>
<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>
<div class="mt-1">
<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>
</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">
<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 '<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>';
echo '</tr>';
@ -105,28 +98,18 @@ function table($type)
echo '<td class="ps-3 pt-3 pb-3">
<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>
<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>
<div class="mt-1">
<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>
</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">
<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 '<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>';
echo '</tr>';
}
@ -143,28 +126,18 @@ function table($type)
echo '<td class="pt-3 pb-3">
<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>
<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>
<div class="mt-1">
<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>
</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">
<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 '<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>';
echo '</tr>';
} catch (Exception $e) {

View file

@ -1,329 +1,101 @@
<?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>
// ============================================================================
// Variables for the view
// ============================================================================
// ============================================================================
// Functions for the view
// ============================================================================
function changePassword() {
var newPassword = $('#newPassword').val();
var confirmPassword = $('#confirmPassword').val();
if (newPassword.length < PASSWORD_LENGTH) {
showAlertError("<?php $L->p('Password must be at least 6 characters long') ?>");
return false;
}
if (newPassword !== confirmPassword) {
showAlertError("<?php $L->p('The password and confirmation password do not match') ?>");
return false;
}
bootbox.confirm({
message: '<?php $L->p('Are you sure you want to change the password') ?>',
buttons: {
cancel: {
label: '<i class="fa fa-times"></i><?php $L->p('Cancel') ?>',
className: 'btn-sm btn-secondary'
},
confirm: {
label: '<i class="fa fa-check"></i><?php $L->p('Confirm') ?>',
className: 'btn-sm btn-primary'
}
},
closeButton: false,
callback: function(result) {
if (result) {
// The user accepted the action to change the password
var args = {
username: $('#username').val(),
password: $('#newPassword').val()
};
api.editUser(args).then(function(response) {
if (response.status == 0) {
logs('User password changed. Username: ' + response.data.key);
showAlertInfo("<?php $L->p('The changes have been saved') ?>");
} else {
logs('An error occurred while trying to change the user password.');
showAlertError(response.message);
}
});
}
$('#newPassword').val('');
$('#confirmPassword').val('');
return true;
}
});
}
function save() {
let args = {
username: $('#username').val(),
role: $('#role').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) {
if (response.status == 0) {
logs('User edited. Username: ' + response.data.key);
showAlertInfo("<?php $L->p('The changes have been saved') ?>");
} else {
logs('An error occurred while trying to edit the user.');
showAlertError(response.message);
}
});
}
// ============================================================================
// Events for the view
// ============================================================================
$(document).ready(function() {
$('#btnSave').on('click', function() {
var username = $('#username').val();
var newPassword = $('#newPassword').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) {
showAlertError("<?php $L->p('Password must be at least 6 characters long') ?>");
return false;
}
if (newPassword !== confirmPassword) {
showAlertError("<?php $L->p('The password and confirmation password do not match') ?>");
return false;
}
bootbox.confirm({
message: '<?php $L->p('Are you sure you want to change the password') ?>',
buttons: {
cancel: {
label: '<i class="fa fa-times"></i><?php $L->p('Cancel') ?>',
className: 'btn-sm btn-secondary'
},
confirm: {
label: '<i class="fa fa-check"></i><?php $L->p('Confirm') ?>',
className: 'btn-sm btn-primary'
}
},
closeButton: false,
callback: function(result) {
if (result) {
// The user accepted the action to change the password
var args = {
username: username,
password: $('#newPassword').val()
};
api.editUser(args).then(function(response) {
if (response.status == 0) {
logs('User password changed. Username: ' + response.data.key);
showAlertInfo("<?php $L->p('The changes have been saved') ?>");
} else {
logs('An error occurred while trying to change the user password.');
showAlertError(response.message);
}
});
}
$('#newPassword').val('');
$('#confirmPassword').val('');
return true;
}
});
if ($('#newPassword').val()) {
changePassword();
} else {
// Save the edited fields
editUser();
}
// Edit the user properties
var args = {
username: username,
role: $('#role').val(),
email: $('#email').val()
};
api.editUser(args).then(function(response) {
if (response.status == 0) {
logs('User edited. Username: ' + response.data.key);
} else {
logs('An error occurred while trying to edit the user.');
showAlertError(response.message);
}
});
});
$('#inputProfilePicture').on("change", function(e) {
@ -441,4 +213,254 @@
});
});
</script>
// ============================================================================
// Initlization for the view
// ============================================================================
$(document).ready(function() {
// nothing here yet
// how do you hang your toilet paper ? over or under ?
});
</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,69 +1,108 @@
<?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>
$(document).ready(function() {
$("#search").on("keyup", function() {
var textToSearch = $(this).val().toLowerCase();
$(".searchItem").each( function() {
var item = $(this);
item.hide();
item.find(".searchText").each( function() {
var element = $(this).text().toLowerCase();
if (element.indexOf(textToSearch)!=-1) {
item.show();
}
// ============================================================================
// 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() {
var textToSearch = $(this).val().toLowerCase();
$(".searchItem").each(function() {
var item = $(this);
item.hide();
item.find(".searchText").each(function() {
var element = $(this).text().toLowerCase();
if (element.indexOf(textToSearch) != -1) {
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>
<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
echo Bootstrap::formTitle(array('title'=>$L->g('Enabled plugins')));
echo Bootstrap::formTitle(array('icon' => 'check-square', 'title' => $L->g('Enabled plugins')));
echo '
<table class="table">
<table class="table table-striped">
<tbody>
';
// Show installed plugins
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">
<div class="searchText">'.$plugin->name().'</div>
<div class="searchText">' . $plugin->name() . '</div>
<div class="mt-1">';
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 href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$plugin->className().'">'.$L->g('Deactivate').'</a>';
echo '</div>';
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 href="' . HTML_PATH_ADMIN_ROOT . 'uninstall-plugin/' . $plugin->className() . '">' . $L->g('Deactivate') . '</a>';
echo '</div>';
echo '</td>';
echo '<td class="searchText align-middle d-none d-sm-table-cell">';
echo $plugin->description();
echo $plugin->description();
echo '</td>';
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 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>';
echo '</tr>';
@ -74,35 +113,35 @@ echo '
</table>
';
echo Bootstrap::formTitle(array('title'=>$L->g('Disabled plugins')));
echo Bootstrap::formTitle(array('icon' => 'dash-square', 'title' => $L->g('Disabled plugins')));
echo '
<table class="table">
<table class="table table-striped">
<tbody>
';
// Plugins not installed
$pluginsNotInstalled = array_diff_key($plugins['all'], $pluginsInstalled);
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">
<div class="searchText">'.$plugin->name().'</div>
<div class="searchText">' . $plugin->name() . '</div>
<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>
</td>';
echo '<td class="searchText align-middle d-none d-sm-table-cell">';
echo $plugin->description();
echo $plugin->description();
echo '</td>';
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 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>';
echo '</tr>';
@ -111,4 +150,4 @@ foreach ($pluginsNotInstalled as $plugin) {
echo '
</tbody>
</table>
';
';

View file

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

View file

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

View file

@ -73,6 +73,9 @@ function editPage($args) {
return false;
}
// Call the plugins before the page is edited
execPluginsByHook('beforePageModify', array($args['key']));
$key = $pages->edit($args);
if ($key) {
// Call the plugins after page modified
@ -105,6 +108,9 @@ function deletePage($args) {
global $pages;
global $syslog;
// Call the plugins before the page is deleted
execPluginsByHook('beforePageDelete', array($args['key']));
if ($pages->delete($args['key'])) {
// Call the plugins after page deleted
execPluginsByHook('afterPageDelete', array($args['key']));
@ -497,6 +503,34 @@ function uploadPageFile($pageKey) {
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
// If you create/edit/remove a page is necessary regenerate the database of categories
function reindexCategories() {
@ -702,30 +736,7 @@ function pluginActivated($pluginClassName) {
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
// Returns TRUE if the plugin is successfully deactivated, FALSE otherwise

View file

@ -46,12 +46,21 @@ EOF;
$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">';
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.'">';
$html .= '<select id="'.$id.'" name="'.$name.'" class="'.$class.'" '.$data.'>';
foreach ($args['options'] as $key=>$value) {
$html .= '<option '.(($key==$args['selected'])?'selected':'').' value="'.$key.'">'.$value.'</option>';
}
@ -148,103 +157,46 @@ EOF;
$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
<div class="mb-3 row">
$label
<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
</div>
</div>
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)
{
$icon = $args['icon'];
$title = $args['title'];
return <<<EOF
<h2 class="m-0">
<span class="bi bi-$icon"></span><span>$title</span>
</h2>
EOF;
$title = '';
if (isset($args['icon'])) {
$title = '<span class="bi bi-'.$args['icon'].'"></span>';
}
$title .= '<span>'.$args['title'].'</span>';
return '<h2 class="m-0">'.$title.'</h2>';
}
public static function formTitle($args)
{
$title = $args['title'];
return <<<EOF
<h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">$title</h6>
EOF;
$title = '';
if (isset($args['icon'])) {
$title = '<span class="bi bi-'.$args['icon'].'"></span>';
}
$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)
{
$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');
}
public function youtube()
{
return $this->getValue('youtube');
}
public function twitter()
{
return $this->getValue('twitter');
@ -170,7 +175,8 @@ class User {
$tmp['firstName'] = $this->firstName();
$tmp['lastName'] = $this->lastName();
$tmp['nickname'] = $this->nickname();
$tmp['description'] = $this->description();
$tmp['description'] = $this->description();
$tmp['youtube'] = $this->youtube();
$tmp['twitter'] = $this->twitter();
$tmp['facebook'] = $this->facebook();
$tmp['codepen'] = $this->codepen();
@ -180,7 +186,7 @@ class User {
$tmp['linkedin'] = $this->linkedin();
$tmp['xing'] = $this->xing();
$tmp['mastodon'] = $this->mastodon();
$tmp['vk'] = $this->vk();
$tmp['vk'] = $this->vk();
$tmp['profilePicture'] = $this->profilePicture();
if ($returnsArray) {

View file

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

View file

@ -265,6 +265,11 @@ class pluginAPI extends Plugin {
$inputs['username'] = $parmB;
$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
elseif ( ($method==='GET') && ($parmA==='helper') && !empty($parmB) ) {
$name = $parmB;
@ -915,4 +920,23 @@ class pluginAPI extends Plugin {
'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.'
);
}
}