chore: add prettierrc and dir=auto to form inputs

This commit is contained in:
Diego Najar 2024-06-22 16:22:05 +02:00
parent 16cd57029b
commit 6248ea0a62
28 changed files with 1388 additions and 1359 deletions

7
.prettierrc Normal file
View File

@ -0,0 +1,7 @@
{
"semi": true,
"singleQuote": true,
"useTabs": false,
"tabWidth": 2,
"printWidth": 100
}

View File

@ -55,4 +55,4 @@ a.text-danger:hover {
.table thead th { .table thead th {
font-size: 0.8em; font-size: 0.8em;
text-transform: uppercase!important; text-transform: uppercase!important;
} }

View File

@ -1,8 +1,10 @@
<?php <?php
class Bootstrap { class Bootstrap
{
public static function modal($args) { public static function modal($args)
{
$buttonSecondary = $args['buttonSecondary']; $buttonSecondary = $args['buttonSecondary'];
$buttonSecondaryClass = $args['buttonSecondaryClass']; $buttonSecondaryClass = $args['buttonSecondaryClass'];
@ -15,7 +17,7 @@ class Bootstrap {
$modalId = $args['modalId']; $modalId = $args['modalId'];
return <<<EOF return <<<EOF
<div id="$modalId" class="modal fade" tabindex="-1" role="dialog"> <div id="$modalId" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
@ -35,26 +37,26 @@ EOF;
public static function link($args) public static function link($args)
{ {
$options = 'href="'.$args['href'].'"'; $options = 'href="' . $args['href'] . '"';
if (isset($args['class'])) { if (isset($args['class'])) {
$options .= ' class="'.$args['class'].'"'; $options .= ' class="' . $args['class'] . '"';
} }
if (isset($args['target'])) { if (isset($args['target'])) {
$options .= ' target="'.$args['target'].'"'; $options .= ' target="' . $args['target'] . '"';
} }
if (isset($args['icon'])) { if (isset($args['icon'])) {
return '<a '.$options.'><span class="fa fa-'.$args['icon'].'"></span>'.$args['title'].'</a>'; return '<a ' . $options . '><span class="fa fa-' . $args['icon'] . '"></span>' . $args['title'] . '</a>';
} }
return '<a '.$options.'>'.$args['title'].'</a>'; return '<a ' . $options . '>' . $args['title'] . '</a>';
} }
public static function pageTitle($args) public static function pageTitle($args)
{ {
$icon = $args['icon']; $icon = $args['icon'];
$title = $args['title']; $title = $args['title'];
return <<<EOF return <<<EOF
<h2 class="mt-0 mb-3"> <h2 class="mt-0 mb-3">
<span class="fa fa-$icon" style="font-size: 0.9em;"></span><span>$title</span> <span class="fa fa-$icon" style="font-size: 0.9em;"></span><span>$title</span>
</h2> </h2>
@ -63,21 +65,21 @@ 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'] . '"';
$id = empty($args['id'])?'':'id="'.$args['id'].'"'; $id = empty($args['id']) ? '' : 'id="' . $args['id'] . '"';
$enctype = empty($args['enctype'])?'':'enctype="'.$args['enctype'].'"'; $enctype = empty($args['enctype']) ? '' : 'enctype="' . $args['enctype'] . '"';
$action = empty($args['action'])?'action=""':'action="'.$args['action'].'"'; $action = empty($args['action']) ? 'action=""' : 'action="' . $args['action'] . '"';
$method = empty($args['method'])?'method="post"':'method="'.$args['method'].'"'; $method = empty($args['method']) ? 'method="post"' : 'method="' . $args['method'] . '"';
$style = empty($args['style'])?'':'style="'.$args['style'].'"'; $style = empty($args['style']) ? '' : 'style="' . $args['style'] . '"';
return <<<EOF return <<<EOF
<form $class $enctype $id $method $action $style autocomplete="off"> <form $class $enctype $id $method $action $style autocomplete="off">
EOF; EOF;
} }
public static function formClose() public static function formClose()
{ {
return <<<EOF return <<<EOF
</form> </form>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
@ -95,7 +97,7 @@ EOF;
public static function formTitle($args) public static function formTitle($args)
{ {
$title = $args['title']; $title = $args['title'];
return <<<EOF return <<<EOF
<h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">$title</h6> <h6 class="mt-4 mb-2 pb-2 border-bottom text-uppercase">$title</h6>
EOF; EOF;
} }
@ -103,18 +105,18 @@ EOF;
public static function formInputTextBlock($args) public static function formInputTextBlock($args)
{ {
$name = $args['name']; $name = $args['name'];
$disabled = empty($args['disabled'])?'':'disabled'; $disabled = empty($args['disabled']) ? '' : 'disabled';
$placeholder = isset($args['placeholder'])?$args['placeholder']:''; $placeholder = isset($args['placeholder']) ? $args['placeholder'] : '';
$value = isset($args['value'])?$args['value']:''; $value = isset($args['value']) ? $args['value'] : '';
$id = 'js'.$name; $id = 'js' . $name;
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$tip = ''; $tip = '';
if (!empty($args['tip'])) { if (!empty($args['tip'])) {
$tip = '<small class="form-text text-muted">'.$args['tip'].'</small>'; $tip = '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$class = 'form-group m-0'; $class = 'form-group m-0';
@ -129,7 +131,7 @@ EOF;
$label = ''; $label = '';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$label = '<label class="'.$labelClass.'" for="'.$id.'">'.$args['label'].'</label>'; $label = '<label class="' . $labelClass . '" for="' . $id . '">' . $args['label'] . '</label>';
} }
$type = 'text'; $type = 'text';
@ -137,10 +139,10 @@ EOF;
$type = $args['type']; $type = $args['type'];
} }
return <<<EOF return <<<EOF
<div class="$class"> <div class="$class">
$label $label
<input type="text" value="$value" class="form-control" id="$id" name="$name" placeholder="$placeholder" $disabled> <input type="text" dir="auto" value="$value" class="form-control" id="$id" name="$name" placeholder="$placeholder" $disabled>
$tip $tip
</div> </div>
EOF; EOF;
@ -148,19 +150,19 @@ EOF;
public static function formInputFile($args) public static function formInputFile($args)
{ {
$id = 'js'.$args['name']; $id = 'js' . $args['name'];
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$class = 'custom-file'; $class = 'custom-file';
if (isset($args['class'])) { if (isset($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$html = '<div class="'.$class.'">'; $html = '<div class="' . $class . '">';
$html .= '<input type="file" class="custom-file-input" id="'.$id.'">'; $html .= '<input type="file" class="custom-file-input" id="' . $id . '">';
$html .= '<label class="custom-file-label" for="'.$id.'">'.$args['label'].'</label>'; $html .= '<label class="custom-file-label" for="' . $id . '">' . $args['label'] . '</label>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -168,26 +170,26 @@ EOF;
public static function formTextarea($args) public static function formTextarea($args)
{ {
$id = 'js'.$args['name']; $id = 'js' . $args['name'];
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$class = 'form-control'; $class = 'form-control';
if (isset($args['class'])) { if (isset($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$html = '<div class="form-group row">'; $html = '<div class="form-group 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 .= '<textarea class="'.$class.'" id="'.$id.'" name="'.$args['name'].'" rows="'.$args['rows'].'" placeholder="'.$args['placeholder'].'">'.$args['value'].'</textarea>'; $html .= '<textarea class="' . $class . '" id="' . $id . '" name="' . $args['name'] . '" rows="' . $args['rows'] . '" placeholder="' . $args['placeholder'] . '">' . $args['value'] . '</textarea>';
if (isset($args['tip'])) { if (isset($args['tip'])) {
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>'; $html .= '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
@ -197,24 +199,24 @@ EOF;
public static function formTextareaBlock($args) public static function formTextareaBlock($args)
{ {
$id = 'js'.$args['name']; $id = 'js' . $args['name'];
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$class = 'form-control'; $class = 'form-control';
if (!empty($args['class'])) { if (!empty($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$html = '<div class="form-group m-0">'; $html = '<div class="form-group m-0">';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>'; $html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="' . $id . '">' . $args['label'] . '</label>';
} }
$html .= '<textarea class="'.$class.'" id="'.$id.'" name="'.$args['name'].'" rows="'.$args['rows'].'" placeholder="'.$args['placeholder'].'">'.$args['value'].'</textarea>'; $html .= '<textarea class="' . $class . '" id="' . $id . '" name="' . $args['name'] . '" rows="' . $args['rows'] . '" placeholder="' . $args['placeholder'] . '">' . $args['value'] . '</textarea>';
if (!empty($args['tip'])) { if (!empty($args['tip'])) {
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>'; $html .= '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$html .= '</div>'; $html .= '</div>';
@ -224,29 +226,29 @@ EOF;
public static function formInputText($args) public static function formInputText($args)
{ {
$name = $args['name']; $name = $args['name'];
$disabled = empty($args['disabled'])?'':'disabled'; $disabled = empty($args['disabled']) ? '' : 'disabled';
$readonly = empty($args['readonly'])?'':'readonly'; $readonly = empty($args['readonly']) ? '' : 'readonly';
$placeholder = isset($args['placeholder'])?$args['placeholder']:''; $placeholder = isset($args['placeholder']) ? $args['placeholder'] : '';
$value = isset($args['value'])?$args['value']:''; $value = isset($args['value']) ? $args['value'] : '';
$id = 'js'.$name; $id = 'js' . $name;
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$tip = ''; $tip = '';
if (isset($args['tip'])) { if (isset($args['tip'])) {
$tip = '<small class="form-text text-muted">'.$args['tip'].'</small>'; $tip = '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$label = ''; $label = '';
if (isset($args['label'])) { if (isset($args['label'])) {
$label = '<label for="'.$id.'" class="col-sm-2 col-form-label">'.$args['label'].'</label>'; $label = '<label for="' . $id . '" class="col-sm-2 col-form-label">' . $args['label'] . '</label>';
} }
$class = 'form-control'; $class = 'form-control';
if (isset($args['class'])) { if (isset($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$type = 'text'; $type = 'text';
@ -254,11 +256,11 @@ EOF;
$type = $args['type']; $type = $args['type'];
} }
return <<<EOF return <<<EOF
<div class="form-group row"> <div class="form-group 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" id="$id" name="$name" value="$value" placeholder="$placeholder" type="$type" dir="auto" $disabled $readonly>
$tip $tip
</div> </div>
</div> </div>
@ -267,16 +269,16 @@ EOF;
public static function formCheckbox($args) public static function formCheckbox($args)
{ {
$labelForCheckbox = isset($args['labelForCheckbox'])?$args['labelForCheckbox']:''; $labelForCheckbox = isset($args['labelForCheckbox']) ? $args['labelForCheckbox'] : '';
$placeholder = isset($args['placeholder'])?$args['placeholder']:''; $placeholder = isset($args['placeholder']) ? $args['placeholder'] : '';
$tip = isset($args['tip'])?'<small class="form-text text-muted">'.$args['tip'].'</small>':''; $tip = isset($args['tip']) ? '<small class="form-text text-muted">' . $args['tip'] . '</small>' : '';
$value = isset($args['value'])?$args['value']:''; $value = isset($args['value']) ? $args['value'] : '';
$name = $args['name']; $name = $args['name'];
$id = 'js'.$name; $id = 'js' . $name;
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$disabled = isset($args['disabled'])?'disabled':''; $disabled = isset($args['disabled']) ? 'disabled' : '';
$class = 'form-group m-0'; $class = 'form-group m-0';
if (isset($args['class'])) { if (isset($args['class'])) {
@ -295,13 +297,13 @@ EOF;
$label = ''; $label = '';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$label = '<label class="'.$labelClass.'">'.$args['label'].'</label>'; $label = '<label class="' . $labelClass . '">' . $args['label'] . '</label>';
} }
$checked = $args['checked']?'checked':''; $checked = $args['checked'] ? 'checked' : '';
$value = $checked?'1':'0'; $value = $checked ? '1' : '0';
return <<<EOF return <<<EOF
<div class="$class"> <div class="$class">
$label $label
<div class="form-check"> <div class="form-check">
@ -315,30 +317,30 @@ EOF;
public static function formSelect($args) public static function formSelect($args)
{ {
$id = 'js'.$args['name']; $id = 'js' . $args['name'];
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$class = 'custom-select'; $class = 'custom-select';
if (isset($args['class'])) { if (isset($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$html = '<div class="form-group row">'; $html = '<div class="form-group row">';
if (isset($args['label'])) { if (isset($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="'.$args['name'].'" class="'.$class.'">'; $html .= '<select id="' . $id . '" name="' . $args['name'] . '" class="' . $class . '">';
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>';
} }
$html .= '</select>'; $html .= '</select>';
if (isset($args['tip'])) { if (isset($args['tip'])) {
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>'; $html .= '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
@ -348,32 +350,32 @@ EOF;
public static function formSelectBlock($args) public static function formSelectBlock($args)
{ {
$id = 'js'.$args['name']; $id = 'js' . $args['name'];
if (isset($args['id'])) { if (isset($args['id'])) {
$id = $args['id']; $id = $args['id'];
} }
$class = 'custom-select'; $class = 'custom-select';
if (!empty($args['class'])) { if (!empty($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$html = '<div class="form-group m-0">'; $html = '<div class="form-group m-0">';
if (!empty($args['label'])) { if (!empty($args['label'])) {
$html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="'.$id.'">'.$args['label'].'</label>'; $html .= '<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100" for="' . $id . '">' . $args['label'] . '</label>';
} }
$html .= '<select id="'.$id.'" name="'.$args['name'].'" class="'.$class.'">'; $html .= '<select id="' . $id . '" name="' . $args['name'] . '" class="' . $class . '">';
if (!empty($args['emptyOption'])) { if (!empty($args['emptyOption'])) {
$html .= '<option value="">'.$args['emptyOption'].'</option>'; $html .= '<option value="">' . $args['emptyOption'] . '</option>';
} }
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>';
} }
$html .= '</select>'; $html .= '</select>';
if (!empty($args['tip'])) { if (!empty($args['tip'])) {
$html .= '<small class="form-text text-muted">'.$args['tip'].'</small>'; $html .= '<small class="form-text text-muted">' . $args['tip'] . '</small>';
} }
$html .= '</div>'; $html .= '</div>';
@ -382,19 +384,19 @@ EOF;
public static function formInputHidden($args) public static function formInputHidden($args)
{ {
return '<input type="hidden" id="js'.$args['name'].'" name="'.$args['name'].'" value="'.$args['value'].'">'; return '<input type="hidden" id="js' . $args['name'] . '" name="' . $args['name'] . '" value="' . $args['value'] . '">';
} }
public static function alert($args) public static function alert($args)
{ {
$class = 'alert'; $class = 'alert';
if (!empty($args['class'])) { if (!empty($args['class'])) {
$class = $class.' '.$args['class']; $class = $class . ' ' . $args['class'];
} }
$text = $args['text']; $text = $args['text'];
return <<<EOF return <<<EOF
<div class="$class" role="alert">$text</div> <div class="$class" role="alert">$text</div>
EOF; EOF;
} }

View File

@ -4,46 +4,46 @@
// FORM START // FORM START
echo Bootstrap::formOpen(array( echo Bootstrap::formOpen(array(
'id'=>'jsform', 'id' => 'jsform',
'class'=>'d-flex flex-column h-100' 'class' => 'd-flex flex-column h-100'
)); ));
// Token CSRF // Token CSRF
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF', 'name' => 'tokenCSRF',
'value'=>$security->getTokenCSRF() 'value' => $security->getTokenCSRF()
)); ));
// UUID // UUID
// The UUID is generated in the controller // The UUID is generated in the controller
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'uuid', 'name' => 'uuid',
'value'=>$page->uuid() 'value' => $page->uuid()
)); ));
// Type = published, draft, sticky, static // Type = published, draft, sticky, static
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'type', 'name' => 'type',
'value'=>$page->type() 'value' => $page->type()
)); ));
// Cover image // Cover image
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'coverImage', 'name' => 'coverImage',
'value'=>$page->coverImage(false) 'value' => $page->coverImage(false)
)); ));
// Content // Content
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'content', 'name' => 'content',
'value'=>'' 'value' => ''
)); ));
// Current page key // Current page key
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'key', 'name' => 'key',
'value'=>$page->key() 'value' => $page->key()
)); ));
?> ?>
<!-- TOOLBAR --> <!-- TOOLBAR -->
@ -56,11 +56,11 @@ echo Bootstrap::formOpen(array(
<div id="jseditorToolbarLeft"> <div id="jseditorToolbarLeft">
<button type="button" class="btn btn-sm btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button> <button type="button" class="btn btn-sm btn-primary" id="jsbuttonSave"><?php echo $L->g('Save') ?></button>
<button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button> <button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button>
<span id="jsswitchButton" data-switch="<?php echo ($page->draft()?'draft':'publish') ?>" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-<?php echo ($page->draft()?'draft':'publish') ?>"></i> <?php echo ($page->draft()?$L->g('Draft'):$L->g('Publish')) ?></span> <span id="jsswitchButton" data-switch="<?php echo ($page->draft() ? 'draft' : 'publish') ?>" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-<?php echo ($page->draft() ? 'draft' : 'publish') ?>"></i> <?php echo ($page->draft() ? $L->g('Draft') : $L->g('Publish')) ?></span>
</div> </div>
<?php if($page->scheduled()): ?> <?php if ($page->scheduled()) : ?>
<div class="alert alert-warning p-1 mt-1 mb-0"><?php $L->p('scheduled') ?>: <?php echo $page->date(SCHEDULED_DATE_FORMAT) ?></div> <div class="alert alert-warning p-1 mt-1 mb-0"><?php $L->p('scheduled') ?>: <?php echo $page->date(SCHEDULED_DATE_FORMAT) ?></div>
<?php endif; ?> <?php endif; ?>
</div> </div>
<script> <script>
@ -81,10 +81,10 @@ echo Bootstrap::formOpen(array(
<div id="jseditorSidebar"> <div id="jseditorSidebar">
<nav> <nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist"> <div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a> <a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a>
<a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a> <a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a>
<?php if (!empty($site->customFields())): ?> <?php if (!empty($site->customFields())) : ?>
<a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a> <a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a>
<?php endif ?> <?php endif ?>
<a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a> <a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a>
</div> </div>
@ -93,40 +93,40 @@ echo Bootstrap::formOpen(array(
<div class="tab-content pr-3 pl-3 pb-3"> <div class="tab-content pr-3 pl-3 pb-3">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab"> <div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php <?php
// Category // Category
echo Bootstrap::formSelectBlock(array( echo Bootstrap::formSelectBlock(array(
'name'=>'category', 'name' => 'category',
'label'=>$L->g('Category'), 'label' => $L->g('Category'),
'selected'=>$page->categoryKey(), 'selected' => $page->categoryKey(),
'class'=>'', 'class' => '',
'emptyOption'=>'- '.$L->g('Uncategorized').' -', 'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options'=>$categories->getKeyNameArray() 'options' => $categories->getKeyNameArray()
)); ));
// Description // Description
echo Bootstrap::formTextareaBlock(array( echo Bootstrap::formTextareaBlock(array(
'name'=>'description', 'name' => 'description',
'label'=>$L->g('Description'), 'label' => $L->g('Description'),
'selected'=>'', 'selected' => '',
'class'=>'', 'class' => '',
'value'=>$page->description(), 'value' => $page->description(),
'rows'=>5, 'rows' => 5,
'placeholder'=>$L->get('this-field-can-help-describe-the-content') 'placeholder' => $L->get('this-field-can-help-describe-the-content')
)); ));
?> ?>
<!-- Cover Image --> <!-- Cover Image -->
<?php <?php
$coverImage = $page->coverImage(false); $coverImage = $page->coverImage(false);
$externalCoverImage = ''; $externalCoverImage = '';
if (filter_var($coverImage, FILTER_VALIDATE_URL)) { if (filter_var($coverImage, FILTER_VALIDATE_URL)) {
$coverImage = ''; $coverImage = '';
$externalCoverImage = $page->coverImage(false); $externalCoverImage = $page->coverImage(false);
} }
?> ?>
<label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100"><?php $L->p('Cover Image') ?></label> <label class="mt-4 mb-2 pb-2 border-bottom text-uppercase w-100"><?php $L->p('Cover Image') ?></label>
<div> <div>
<img id="jscoverImagePreview" class="mx-auto d-block w-100" alt="Cover image preview" src="<?php echo (empty($coverImage) ? HTML_PATH_CORE_IMG.'default.svg' : $page->coverImage() ) ?>" /> <img id="jscoverImagePreview" class="mx-auto d-block w-100" alt="Cover image preview" src="<?php echo (empty($coverImage) ? HTML_PATH_CORE_IMG . 'default.svg' : $page->coverImage()) ?>" />
</div> </div>
<div class="mt-2 text-center"> <div class="mt-2 text-center">
<button type="button" id="jsbuttonSelectCoverImage" class="btn btn-primary btn-sm"><?php echo $L->g('Select cover image') ?></button> <button type="button" id="jsbuttonSelectCoverImage" class="btn btn-primary btn-sm"><?php echo $L->g('Select cover image') ?></button>
@ -144,220 +144,222 @@ echo Bootstrap::formOpen(array(
$("#jsbuttonRemoveCoverImage").on("click", function() { $("#jsbuttonRemoveCoverImage").on("click", function() {
$("#jscoverImage").val(''); $("#jscoverImage").val('');
$("#jscoverImagePreview").attr('src', HTML_PATH_CORE_IMG+'default.svg'); $("#jscoverImagePreview").attr('src', HTML_PATH_CORE_IMG + 'default.svg');
}); });
}); });
</script> </script>
</div> </div>
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab"> <div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
<?php <?php
// Date // Date
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'date', 'name' => 'date',
'label'=>$L->g('Date'), 'label' => $L->g('Date'),
'placeholder'=>'', 'placeholder' => '',
'value'=>$page->dateRaw(), 'value' => $page->dateRaw(),
'tip'=>$L->g('date-format-format') 'tip' => $L->g('date-format-format')
)); ));
// Type // Type
echo Bootstrap::formSelectBlock(array( echo Bootstrap::formSelectBlock(array(
'name'=>'typeSelector', 'name' => 'typeSelector',
'label'=>$L->g('Type'), 'label' => $L->g('Type'),
'selected'=>$page->type(), 'selected' => $page->type(),
'options'=>array( 'options' => array(
'published'=>'- '.$L->g('Default').' -', 'published' => '- ' . $L->g('Default') . ' -',
'sticky'=>$L->g('Sticky'), 'sticky' => $L->g('Sticky'),
'static'=>$L->g('Static') 'static' => $L->g('Static')
), ),
'tip'=>'' 'tip' => ''
)); ));
// Position // Position
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'position', 'name' => 'position',
'label'=>$L->g('Position'), 'label' => $L->g('Position'),
'tip'=>$L->g('Field used when ordering content by position'), 'tip' => $L->g('Field used when ordering content by position'),
'value'=>$page->position() 'value' => $page->position()
)); ));
// Tags // Tags
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'tags', 'name' => 'tags',
'label'=>$L->g('Tags'), 'label' => $L->g('Tags'),
'placeholder'=>'', 'placeholder' => '',
'tip'=>$L->g('Write the tags separated by comma'), 'tip' => $L->g('Write the tags separated by comma'),
'value'=>$page->tags() 'value' => $page->tags()
)); ));
// Parent // Parent
try { try {
$options = array(); $options = array();
$parentKey = $page->parent(); $parentKey = $page->parent();
if (!empty($parentKey)) { if (!empty($parentKey)) {
$parent = new Page($parentKey); $parent = new Page($parentKey);
$options = array($parentKey=>$parent->title()); $options = array($parentKey => $parent->title());
}
} catch (Exception $e) {
// continue
} }
echo Bootstrap::formSelectBlock(array( } catch (Exception $e) {
'name'=>'parent', // continue
'label'=>$L->g('Parent'), }
'options'=>$options, echo Bootstrap::formSelectBlock(array(
'selected'=>false, 'name' => 'parent',
'class'=>'', 'label' => $L->g('Parent'),
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'), 'options' => $options,
)); 'selected' => false,
'class' => '',
'tip' => $L->g('Start typing a page title to see a list of suggestions.'),
));
?> ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
var parent = $("#jsparent").select2({ var parent = $("#jsparent").select2({
placeholder: "", placeholder: "",
allowClear: true, allowClear: true,
theme: "bootstrap4", theme: "bootstrap4",
minimumInputLength: 2, minimumInputLength: 2,
ajax: { ajax: {
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published", url: HTML_PATH_ADMIN_ROOT + "ajax/get-published",
data: function (params) { data: function(params) {
var query = { var query = {
checkIsParent: true, checkIsParent: true,
query: params.term query: params.term
}
return query;
},
processResults: function(data) {
return data;
} }
return query;
}, },
processResults: function (data) { escapeMarkup: function(markup) {
return data; return markup;
},
templateResult: function(data) {
var html = data.text
if (data.type == "static") {
html += '<span class="badge badge-pill badge-light">' + data.type + '</span>';
}
return html;
} }
}, });
escapeMarkup: function(markup) {
return markup;
},
templateResult: function(data) {
var html = data.text
if (data.type=="static") {
html += '<span class="badge badge-pill badge-light">'+data.type+'</span>';
}
return html;
}
}); });
});
</script> </script>
<?php <?php
// Template // Template
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'template', 'name' => 'template',
'label'=>$L->g('Template'), 'label' => $L->g('Template'),
'placeholder'=>'', 'placeholder' => '',
'value'=>$page->template(), 'value' => $page->template(),
'tip'=>$L->g('Write a template name to filter the page in the theme and change the style of the page.') 'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.')
)); ));
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'externalCoverImage', 'name' => 'externalCoverImage',
'label'=>$L->g('External cover image'), 'label' => $L->g('External cover image'),
'placeholder'=>"https://", 'placeholder' => "https://",
'value'=>$externalCoverImage, 'value' => $externalCoverImage,
'tip'=>$L->g('Set a cover image from external URL, such as a CDN or some server dedicated for images.') 'tip' => $L->g('Set a cover image from external URL, such as a CDN or some server dedicated for images.')
)); ));
// Username // Username
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'', 'name' => '',
'label'=>$L->g('Author'), 'label' => $L->g('Author'),
'placeholder'=>'', 'placeholder' => '',
'value'=>$page->username(), 'value' => $page->username(),
'tip'=>'', 'tip' => '',
'disabled'=>true 'disabled' => true
)); ));
?> ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Changes in External cover image input // Changes in External cover image input
$("#jsexternalCoverImage").change(function() { $("#jsexternalCoverImage").change(function() {
$("#jscoverImage").val( $(this).val() ); $("#jscoverImage").val($(this).val());
}); });
// Datepicker // Datepicker
$("#jsdate").datetimepicker({format:DB_DATE_FORMAT}); $("#jsdate").datetimepicker({
}); format: DB_DATE_FORMAT
});
});
</script> </script>
</div> </div>
<?php if (!empty($site->customFields())): ?> <?php if (!empty($site->customFields())) : ?>
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab"> <div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( !isset($options['position']) ) { if (!isset($options['position'])) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'value'=>(isset($options['default'])?$options['default']:''), 'value' => (isset($options['default']) ? $options['default'] : ''),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'value'=>$page->custom($field) 'value' => $page->custom($field)
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>$page->custom($field), 'checked' => $page->custom($field),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'') 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : '')
)); ));
}
} }
} }
} ?>
?> </div>
</div>
<?php endif ?> <?php endif ?>
<div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab"> <div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab">
<?php <?php
// Friendly URL // Friendly URL
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'slug', 'name' => 'slug',
'tip'=>$L->g('URL associated with the content'), 'tip' => $L->g('URL associated with the content'),
'label'=>$L->g('Friendly URL'), 'label' => $L->g('Friendly URL'),
'placeholder'=>$L->g('Leave empty for autocomplete by Bludit.'), 'placeholder' => $L->g('Leave empty for autocomplete by Bludit.'),
'value'=>$page->slug() 'value' => $page->slug()
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'noindex', 'name' => 'noindex',
'label'=>'Robots', 'label' => 'Robots',
'labelForCheckbox'=>$L->g('apply-code-noindex-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>$page->noindex(), 'checked' => $page->noindex(),
'tip'=>$L->g('This tells search engines not to show this page in their search results.') 'tip' => $L->g('This tells search engines not to show this page in their search results.')
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'nofollow', 'name' => 'nofollow',
'label'=>'', 'label' => '',
'labelForCheckbox'=>$L->g('apply-code-nofollow-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>$page->nofollow(), 'checked' => $page->nofollow(),
'tip'=>$L->g('This tells search engines not to follow links on this page.') 'tip' => $L->g('This tells search engines not to follow links on this page.')
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'noarchive', 'name' => 'noarchive',
'label'=>'', 'label' => '',
'labelForCheckbox'=>$L->g('apply-code-noarchive-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>$page->noarchive(), 'checked' => $page->noarchive(),
'tip'=>$L->g('This tells search engines not to save a cached copy of this page.') 'tip' => $L->g('This tells search engines not to save a cached copy of this page.')
)); ));
?> ?>
</div> </div>
</div> </div>
@ -365,38 +367,38 @@ echo Bootstrap::formOpen(array(
<!-- Custom fields: TOP --> <!-- Custom fields: TOP -->
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( isset($options['position']) && ($options['position']=='top') ) { if (isset($options['position']) && ($options['position'] == 'top')) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'value'=>$page->custom($field), 'value' => $page->custom($field),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'class'=>'mb-2', 'class' => 'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>$page->custom($field), 'checked' => $page->custom($field),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : ''),
'class'=>'mb-2', 'class' => 'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
}
} }
} }
}
?> ?>
<!-- Title --> <!-- Title -->
<div class="form-group mb-1"> <div class="form-group mb-1">
<input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="<?php echo $page->title() ?>" placeholder="<?php $L->p('Enter title') ?>"> <input id="jstitle" name="title" type="text" dir="auto" class="form-control form-control-lg rounded-0" value="<?php echo $page->title() ?>" placeholder="<?php $L->p('Enter title') ?>">
</div> </div>
<!-- Editor --> <!-- Editor -->
@ -404,33 +406,33 @@ echo Bootstrap::formOpen(array(
<!-- Custom fields: BOTTOM --> <!-- Custom fields: BOTTOM -->
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( isset($options['position']) && ($options['position']=='bottom') ) { if (isset($options['position']) && ($options['position'] == 'bottom')) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'value'=>$page->custom($field), 'value' => $page->custom($field),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'class'=>'mt-2', 'class' => 'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>$page->custom($field), 'checked' => $page->custom($field),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : ''),
'class'=>'mt-2', 'class' => 'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
}
} }
} }
}
?> ?>
</form> </form>
@ -450,112 +452,112 @@ echo Bootstrap::formOpen(array(
</div> </div>
</div> </div>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$("#jsbuttonDeleteAccept").on("click", function() { $("#jsbuttonDeleteAccept").on("click", function() {
$("#jstype").val("delete"); $("#jstype").val("delete");
$("#jscontent").val(""); $("#jscontent").val("");
$("#jsform").submit(); $("#jsform").submit();
});
}); });
});
</script> </script>
</div> </div>
<!-- Modal for Media Manager --> <!-- Modal for Media Manager -->
<?php include(PATH_ADMIN_THEMES.'booty/html/media.php'); ?> <?php include(PATH_ADMIN_THEMES . 'booty/html/media.php'); ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Define function if they doesn't exist // Define function if they doesn't exist
// This helps if the user doesn't activate any plugin as editor // This helps if the user doesn't activate any plugin as editor
if (typeof editorGetContent != "function") { if (typeof editorGetContent != "function") {
window.editorGetContent = function(){ window.editorGetContent = function() {
return $("#jseditor").val(); return $("#jseditor").val();
}; };
} }
if (typeof editorInsertMedia != "function") { if (typeof editorInsertMedia != "function") {
window.editorInsertMedia = function(filename){ window.editorInsertMedia = function(filename) {
$("#jseditor").val($('#jseditor').val()+'<img src="'+filename+'" alt="">'); $("#jseditor").val($('#jseditor').val() + '<img src="' + filename + '" alt="">');
}; };
} }
if (typeof editorInsertLinkedMedia != "function") { if (typeof editorInsertLinkedMedia != "function") {
window.editorInsertLinkedMedia = function(filename, link){ window.editorInsertLinkedMedia = function(filename, link) {
$("#jseditor").val($('#jseditor').val()+'<a href="'+link+'"><img src="'+filename+'" alt=""></a>'); $("#jseditor").val($('#jseditor').val() + '<a href="' + link + '"><img src="' + filename + '" alt=""></a>');
}; };
}
// Button switch
$("#jsswitchButton").on("click", function() {
if ($(this).data("switch")=="publish") {
$(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>');
$(this).data("switch", "draft");
} else {
$(this).html('<i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?>');
$(this).data("switch", "publish");
} }
});
// Button preview // Button switch
$("#jsbuttonPreview").on("click", function() { $("#jsswitchButton").on("click", function() {
var uuid = $("#jsuuid").val(); if ($(this).data("switch") == "publish") {
var title = $("#jstitle").val(); $(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>');
var content = editorGetContent(); $(this).data("switch", "draft");
var ajax = new bluditAjax(); } else {
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) { $(this).html('<i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?>');
var preview = window.open("<?php echo DOMAIN_PAGES.'autosave-'.$page->uuid().'?preview='.md5('autosave-'.$page->uuid()) ?>", "bludit-preview"); $(this).data("switch", "publish");
preview.focus(); }
}); });
});
// Button Save // Button preview
$("#jsbuttonSave").on("click", function() { $("#jsbuttonPreview").on("click", function() {
// If the switch is setted to "published", get the value from the selector var uuid = $("#jsuuid").val();
if ($("#jsswitchButton").data("switch")=="publish") { var title = $("#jstitle").val();
var value = $("#jstypeSelector option:selected").val(); var content = editorGetContent();
$("#jstype").val(value); var ajax = new bluditAjax();
} else { bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $page->uuid() . '?preview=' . md5('autosave-' . $page->uuid()) ?>", "bludit-preview");
preview.focus();
});
});
// Button Save
$("#jsbuttonSave").on("click", function() {
// If the switch is setted to "published", get the value from the selector
if ($("#jsswitchButton").data("switch") == "publish") {
var value = $("#jstypeSelector option:selected").val();
$("#jstype").val(value);
} else {
$("#jstype").val("draft");
}
// Get the content
$("#jscontent").val(editorGetContent());
// Submit the form
$("#jsform").submit();
});
// Button Save as draft
$("#jsbuttonDraft").on("click", function() {
// Set the type as draft
$("#jstype").val("draft"); $("#jstype").val("draft");
}
// Get the content // Get the content
$("#jscontent").val( editorGetContent() ); $("#jscontent").val(editorGetContent());
// Submit the form // Submit the form
$("#jsform").submit(); $("#jsform").submit();
}); });
// Button Save as draft // Autosave
$("#jsbuttonDraft").on("click", function() { var currentContent = editorGetContent();
// Set the type as draft setInterval(function() {
$("#jstype").val("draft");
// Get the content
$("#jscontent").val( editorGetContent() );
// Submit the form
$("#jsform").submit();
});
// Autosave
var currentContent = editorGetContent();
setInterval(function() {
var uuid = $("#jsuuid").val(); var uuid = $("#jsuuid").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]"; var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var content = editorGetContent(); var content = editorGetContent();
// Autosave when content has at least 100 characters // Autosave when content has at least 100 characters
if (content.length<100) { if (content.length < 100) {
return false; return false;
} }
// Autosave only when the user change the content // Autosave only when the user change the content
if (currentContent!=content) { if (currentContent != content) {
currentContent = content; currentContent = content;
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) { bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
if (data.status==0) { if (data.status == 0) {
showAlert("<?php $L->p('Autosave') ?>"); showAlert("<?php $L->p('Autosave') ?>");
} }
}); });
} }
},1000*60*AUTOSAVE_INTERVAL); }, 1000 * 60 * AUTOSAVE_INTERVAL);
}); });
</script> </script>

View File

@ -1,38 +1,37 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
echo '<h1 class="text-center mb-3 mt-3 font-weight-normal" style="color: #555;">'.$site->title().'</h1>'; echo '<h1 class="text-center mb-3 mt-3 font-weight-normal" style="color: #555;">' . $site->title() . '</h1>';
echo Bootstrap::formOpen(array()); echo Bootstrap::formOpen(array());
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF', 'name' => 'tokenCSRF',
'value'=>$security->getTokenCSRF() 'value' => $security->getTokenCSRF()
)); ));
echo ' echo '
<div class="form-group"> <div class="form-group">
<input type="text" value="'.(isset($_POST['username'])?Sanitize::html($_POST['username']):'').'" class="form-control form-control-lg" id="jsusername" name="username" placeholder="'.$L->g('Username').'" autofocus> <input type="text" dir="auto" value="' . (isset($_POST['username']) ? Sanitize::html($_POST['username']) : '') . '" class="form-control form-control-lg" id="jsusername" name="username" placeholder="' . $L->g('Username') . '" autofocus>
</div> </div>
'; ';
echo ' echo '
<div class="form-group"> <div class="form-group">
<input type="password" class="form-control form-control-lg" id="jspassword" name="password" placeholder="'.$L->g('Password').'"> <input type="password" class="form-control form-control-lg" id="jspassword" name="password" placeholder="' . $L->g('Password') . '">
</div> </div>
'; ';
echo ' echo '
<div class="form-check"> <div class="form-check">
<input class="form-check-input" type="checkbox" value="true" id="jsremember" name="remember"> <input class="form-check-input" type="checkbox" value="true" id="jsremember" name="remember">
<label class="form-check-label" for="jsremember">'.$L->g('Remember me').'</label> <label class="form-check-label" for="jsremember">' . $L->g('Remember me') . '</label>
</div> </div>
<div class="form-group mt-3"> <div class="form-group mt-3">
<button type="submit" class="btn btn-primary btn-lg mr-2 w-100" name="save">'.$L->g('Login').'</button> <button type="submit" class="btn btn-primary btn-lg mr-2 w-100" name="save">' . $L->g('Login') . '</button>
</div> </div>
'; ';
echo '</form>'; echo '</form>';
echo '<p class="mt-3 text-right">'.$L->g('Powered by Bludit').((defined('BLUDIT_PRO'))?' PRO':'').'</p>' echo '<p class="mt-3 text-right">' . $L->g('Powered by Bludit') . ((defined('BLUDIT_PRO')) ? ' PRO' : '') . '</p>'
?>

View File

@ -4,40 +4,40 @@
// Start form // Start form
echo Bootstrap::formOpen(array( echo Bootstrap::formOpen(array(
'id'=>'jsform', 'id' => 'jsform',
'class'=>'d-flex flex-column h-100' 'class' => 'd-flex flex-column h-100'
)); ));
// Token CSRF // Token CSRF
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'tokenCSRF', 'name' => 'tokenCSRF',
'value'=>$security->getTokenCSRF() 'value' => $security->getTokenCSRF()
)); ));
// UUID // UUID
// The UUID is generated in the controller // The UUID is generated in the controller
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'uuid', 'name' => 'uuid',
'value'=>$uuid 'value' => $uuid
)); ));
// Type = published, draft, sticky, static // Type = published, draft, sticky, static
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'type', 'name' => 'type',
'value'=>'published' 'value' => 'published'
)); ));
// Cover image // Cover image
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'coverImage', 'name' => 'coverImage',
'value'=>'' 'value' => ''
)); ));
// Content // Content
echo Bootstrap::formInputHidden(array( echo Bootstrap::formInputHidden(array(
'name'=>'content', 'name' => 'content',
'value'=>'' 'value' => ''
)); ));
?> ?>
<!-- TOOLBAR --> <!-- TOOLBAR -->
@ -48,7 +48,7 @@ echo Bootstrap::formOpen(array(
</div> </div>
<div id="jseditorToolbarLeft"> <div id="jseditorToolbarLeft">
<button id="jsbuttonSave" type="button" class="btn btn-sm btn-primary" ><?php $L->p('Save') ?></button> <button id="jsbuttonSave" type="button" class="btn btn-sm btn-primary"><?php $L->p('Save') ?></button>
<button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button> <button id="jsbuttonPreview" type="button" class="btn btn-sm btn-secondary"><?php $L->p('Preview') ?></button>
<span id="jsbuttonSwitch" data-switch="publish" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?></span> <span id="jsbuttonSwitch" data-switch="publish" class="ml-2 text-secondary switch-button"><i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?></span>
</div> </div>
@ -71,10 +71,10 @@ echo Bootstrap::formOpen(array(
<div id="jseditorSidebar"> <div id="jseditorSidebar">
<nav> <nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist"> <div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a> <a class="nav-link active show" id="nav-general-tab" data-toggle="tab" href="#nav-general" role="tab" aria-controls="general"><?php $L->p('General') ?></a>
<a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a> <a class="nav-link" id="nav-advanced-tab" data-toggle="tab" href="#nav-advanced" role="tab" aria-controls="advanced"><?php $L->p('Advanced') ?></a>
<?php if (!empty($site->customFields())): ?> <?php if (!empty($site->customFields())) : ?>
<a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a> <a class="nav-link" id="nav-custom-tab" data-toggle="tab" href="#nav-custom" role="tab" aria-controls="custom"><?php $L->p('Custom') ?></a>
<?php endif ?> <?php endif ?>
<a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a> <a class="nav-link" id="nav-seo-tab" data-toggle="tab" href="#nav-seo" role="tab" aria-controls="seo"><?php $L->p('SEO') ?></a>
</div> </div>
@ -83,26 +83,26 @@ echo Bootstrap::formOpen(array(
<div class="tab-content pr-3 pl-3 pb-3"> <div class="tab-content pr-3 pl-3 pb-3">
<div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab"> <div id="nav-general" class="tab-pane fade show active" role="tabpanel" aria-labelledby="general-tab">
<?php <?php
// Category // Category
echo Bootstrap::formSelectBlock(array( echo Bootstrap::formSelectBlock(array(
'name'=>'category', 'name' => 'category',
'label'=>$L->g('Category'), 'label' => $L->g('Category'),
'selected'=>'', 'selected' => '',
'class'=>'', 'class' => '',
'emptyOption'=>'- '.$L->g('Uncategorized').' -', 'emptyOption' => '- ' . $L->g('Uncategorized') . ' -',
'options'=>$categories->getKeyNameArray() 'options' => $categories->getKeyNameArray()
)); ));
// Description // Description
echo Bootstrap::formTextareaBlock(array( echo Bootstrap::formTextareaBlock(array(
'name'=>'description', 'name' => 'description',
'label'=>$L->g('Description'), 'label' => $L->g('Description'),
'selected'=>'', 'selected' => '',
'class'=>'', 'class' => '',
'value'=>'', 'value' => '',
'rows'=>5, 'rows' => 5,
'placeholder'=>$L->get('this-field-can-help-describe-the-content') 'placeholder' => $L->get('this-field-can-help-describe-the-content')
)); ));
?> ?>
<!-- Cover Image --> <!-- Cover Image -->
@ -126,218 +126,220 @@ echo Bootstrap::formOpen(array(
$("#jsbuttonRemoveCoverImage").on("click", function() { $("#jsbuttonRemoveCoverImage").on("click", function() {
$("#jscoverImage").val(''); $("#jscoverImage").val('');
$("#jscoverImagePreview").attr('src', HTML_PATH_CORE_IMG+'default.svg'); $("#jscoverImagePreview").attr('src', HTML_PATH_CORE_IMG + 'default.svg');
}); });
}); });
</script> </script>
</div> </div>
<div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab"> <div id="nav-advanced" class="tab-pane fade" role="tabpanel" aria-labelledby="advanced-tab">
<?php <?php
// Date // Date
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'date', 'name' => 'date',
'label'=>$L->g('Date'), 'label' => $L->g('Date'),
'placeholder'=>'', 'placeholder' => '',
'value'=>Date::current(DB_DATE_FORMAT), 'value' => Date::current(DB_DATE_FORMAT),
'tip'=>$L->g('date-format-format') 'tip' => $L->g('date-format-format')
)); ));
// Type // Type
echo Bootstrap::formSelectBlock(array( echo Bootstrap::formSelectBlock(array(
'name'=>'typeSelector', 'name' => 'typeSelector',
'label'=>$L->g('Type'), 'label' => $L->g('Type'),
'selected'=>'', 'selected' => '',
'options'=>array( 'options' => array(
'published'=>'- '.$L->g('Default').' -', 'published' => '- ' . $L->g('Default') . ' -',
'sticky'=>$L->g('Sticky'), 'sticky' => $L->g('Sticky'),
'static'=>$L->g('Static') 'static' => $L->g('Static')
), ),
'tip'=>'' 'tip' => ''
)); ));
// Position // Position
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'position', 'name' => 'position',
'label'=>$L->g('Position'), 'label' => $L->g('Position'),
'tip'=>$L->g('Field used when ordering content by position'), 'tip' => $L->g('Field used when ordering content by position'),
'value'=>$pages->nextPositionNumber() 'value' => $pages->nextPositionNumber()
)); ));
// Tags // Tags
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'tags', 'name' => 'tags',
'label'=>$L->g('Tags'), 'label' => $L->g('Tags'),
'placeholder'=>'', 'placeholder' => '',
'tip'=>$L->g('Write the tags separated by comma') 'tip' => $L->g('Write the tags separated by comma')
)); ));
// Parent // Parent
echo Bootstrap::formSelectBlock(array( echo Bootstrap::formSelectBlock(array(
'name'=>'parent', 'name' => 'parent',
'label'=>$L->g('Parent'), 'label' => $L->g('Parent'),
'options'=>array(), 'options' => array(),
'selected'=>false, 'selected' => false,
'class'=>'', 'class' => '',
'tip'=>$L->g('Start typing a page title to see a list of suggestions.'), 'tip' => $L->g('Start typing a page title to see a list of suggestions.'),
)); ));
?> ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
var parent = $("#jsparent").select2({ var parent = $("#jsparent").select2({
placeholder: "", placeholder: "",
allowClear: true, allowClear: true,
theme: "bootstrap4", theme: "bootstrap4",
minimumInputLength: 2, minimumInputLength: 2,
ajax: { ajax: {
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published", url: HTML_PATH_ADMIN_ROOT + "ajax/get-published",
data: function (params) { data: function(params) {
var query = { var query = {
checkIsParent: true, checkIsParent: true,
query: params.term query: params.term
}
return query;
},
processResults: function(data) {
return data;
} }
return query;
}, },
processResults: function (data) { escapeMarkup: function(markup) {
return data; return markup;
},
templateResult: function(data) {
var html = data.text;
if (data.type == "static") {
html += '<span class="badge badge-pill badge-light">' + data.type + '</span>';
}
return html;
} }
}, });
escapeMarkup: function(markup) {
return markup;
},
templateResult: function(data) {
var html = data.text;
if (data.type=="static") {
html += '<span class="badge badge-pill badge-light">'+data.type+'</span>';
}
return html;
}
}); });
});
</script> </script>
<?php <?php
// Template // Template
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'template', 'name' => 'template',
'label'=>$L->g('Template'), 'label' => $L->g('Template'),
'placeholder'=>'', 'placeholder' => '',
'value'=>'', 'value' => '',
'tip'=>$L->g('Write a template name to filter the page in the theme and change the style of the page.') 'tip' => $L->g('Write a template name to filter the page in the theme and change the style of the page.')
)); ));
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'externalCoverImage', 'name' => 'externalCoverImage',
'label'=>$L->g('External cover image'), 'label' => $L->g('External cover image'),
'placeholder'=>"https://", 'placeholder' => "https://",
'value'=>'', 'value' => '',
'tip'=>$L->g('Set a cover image from external URL, such as a CDN or some server dedicated for images.') 'tip' => $L->g('Set a cover image from external URL, such as a CDN or some server dedicated for images.')
)); ));
// Username // Username
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'', 'name' => '',
'label'=>$L->g('Author'), 'label' => $L->g('Author'),
'placeholder'=>'', 'placeholder' => '',
'value'=>$login->username(), 'value' => $login->username(),
'tip'=>'', 'tip' => '',
'disabled'=>true 'disabled' => true
)); ));
?> ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Changes in External cover image input
$("#jsexternalCoverImage").change(function() {
$("#jscoverImage").val($(this).val());
});
// Generate slug when the user type the title
$("#jstitle").keyup(function() {
var text = $(this).val();
var parent = $("#jsparent").val();
var currentKey = "";
var ajax = new bluditAjax();
var callBack = $("#jsslug");
ajax.generateSlug(text, parent, currentKey, callBack);
});
// Datepicker
$("#jsdate").datetimepicker({
format: DB_DATE_FORMAT
});
// Changes in External cover image input
$("#jsexternalCoverImage").change(function() {
$("#jscoverImage").val( $(this).val() );
}); });
// Generate slug when the user type the title
$("#jstitle").keyup(function() {
var text = $(this).val();
var parent = $("#jsparent").val();
var currentKey = "";
var ajax = new bluditAjax();
var callBack = $("#jsslug");
ajax.generateSlug(text, parent, currentKey, callBack);
});
// Datepicker
$("#jsdate").datetimepicker({format:DB_DATE_FORMAT});
});
</script> </script>
</div> </div>
<?php if (!empty($site->customFields())): ?> <?php if (!empty($site->customFields())) : ?>
<div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab"> <div id="nav-custom" class="tab-pane fade" role="tabpanel" aria-labelledby="custom-tab">
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( !isset($options['position']) ) { if (!isset($options['position'])) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'value'=>(isset($options['default'])?$options['default']:''), 'value' => (isset($options['default']) ? $options['default'] : ''),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:'') 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : '')
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>(isset($options['checked'])?true:false), 'checked' => (isset($options['checked']) ? true : false),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:'') 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : '')
)); ));
}
} }
} }
} ?>
?> </div>
</div>
<?php endif ?> <?php endif ?>
<div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab"> <div id="nav-seo" class="tab-pane fade" role="tabpanel" aria-labelledby="seo-tab">
<?php <?php
// Friendly URL // Friendly URL
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'slug', 'name' => 'slug',
'tip'=>$L->g('URL associated with the content'), 'tip' => $L->g('URL associated with the content'),
'label'=>$L->g('Friendly URL'), 'label' => $L->g('Friendly URL'),
'placeholder'=>$L->g('Leave empty for autocomplete by Bludit.') 'placeholder' => $L->g('Leave empty for autocomplete by Bludit.')
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'noindex', 'name' => 'noindex',
'label'=>'Robots', 'label' => 'Robots',
'labelForCheckbox'=>$L->g('apply-code-noindex-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noindex-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>false, 'checked' => false,
'tip'=>$L->g('This tells search engines not to show this page in their search results.') 'tip' => $L->g('This tells search engines not to show this page in their search results.')
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'nofollow', 'name' => 'nofollow',
'label'=>'', 'label' => '',
'labelForCheckbox'=>$L->g('apply-code-nofollow-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-nofollow-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>false, 'checked' => false,
'tip'=>$L->g('This tells search engines not to follow links on this page.') 'tip' => $L->g('This tells search engines not to follow links on this page.')
)); ));
// Robots // Robots
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'noarchive', 'name' => 'noarchive',
'label'=>'', 'label' => '',
'labelForCheckbox'=>$L->g('apply-code-noarchive-code-to-this-page'), 'labelForCheckbox' => $L->g('apply-code-noarchive-code-to-this-page'),
'placeholder'=>'', 'placeholder' => '',
'checked'=>false, 'checked' => false,
'tip'=>$L->g('This tells search engines not to save a cached copy of this page.') 'tip' => $L->g('This tells search engines not to save a cached copy of this page.')
)); ));
?> ?>
</div> </div>
</div> </div>
@ -345,39 +347,39 @@ echo Bootstrap::formOpen(array(
<!-- Custom fields: TOP --> <!-- Custom fields: TOP -->
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( isset($options['position']) && ($options['position']=='top') ) { if (isset($options['position']) && ($options['position'] == 'top')) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'value'=>(isset($options['default'])?$options['default']:''), 'value' => (isset($options['default']) ? $options['default'] : ''),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'class'=>'mb-2', 'class' => 'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>(isset($options['checked'])?true:false), 'checked' => (isset($options['checked']) ? true : false),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : ''),
'class'=>'mb-2', 'class' => 'mb-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
}
} }
} }
}
?> ?>
<!-- Title --> <!-- Title -->
<div id="jseditorTitle" class="form-group mb-1"> <div id="jseditorTitle" class="form-group mb-1">
<input id="jstitle" name="title" type="text" class="form-control form-control-lg rounded-0" value="" placeholder="<?php $L->p('Enter title') ?>"> <input id="jstitle" name="title" type="text" dir="auto" class="form-control form-control-lg rounded-0" value="" placeholder="<?php $L->p('Enter title') ?>">
</div> </div>
<!-- Editor --> <!-- Editor -->
@ -385,120 +387,120 @@ echo Bootstrap::formOpen(array(
<!-- Custom fields: BOTTOM --> <!-- Custom fields: BOTTOM -->
<?php <?php
$customFields = $site->customFields(); $customFields = $site->customFields();
foreach ($customFields as $field=>$options) { foreach ($customFields as $field => $options) {
if ( isset($options['position']) && ($options['position']=='bottom') ) { if (isset($options['position']) && ($options['position'] == 'bottom')) {
if ($options['type']=="string") { if ($options['type'] == "string") {
echo Bootstrap::formInputTextBlock(array( echo Bootstrap::formInputTextBlock(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'value'=>(isset($options['default'])?$options['default']:''), 'value' => (isset($options['default']) ? $options['default'] : ''),
'tip'=>(isset($options['tip'])?$options['tip']:''), 'tip' => (isset($options['tip']) ? $options['tip'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'class'=>'mt-2', 'class' => 'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
} elseif ($options['type']=="bool") { } elseif ($options['type'] == "bool") {
echo Bootstrap::formCheckbox(array( echo Bootstrap::formCheckbox(array(
'name'=>'custom['.$field.']', 'name' => 'custom[' . $field . ']',
'label'=>(isset($options['label'])?$options['label']:''), 'label' => (isset($options['label']) ? $options['label'] : ''),
'placeholder'=>(isset($options['placeholder'])?$options['placeholder']:''), 'placeholder' => (isset($options['placeholder']) ? $options['placeholder'] : ''),
'checked'=>(isset($options['checked'])?true:false), 'checked' => (isset($options['checked']) ? true : false),
'labelForCheckbox'=>(isset($options['tip'])?$options['tip']:''), 'labelForCheckbox' => (isset($options['tip']) ? $options['tip'] : ''),
'class'=>'mt-2', 'class' => 'mt-2',
'labelClass'=>'mb-2 pb-2 border-bottom text-uppercase w-100' 'labelClass' => 'mb-2 pb-2 border-bottom text-uppercase w-100'
)); ));
}
} }
} }
}
?> ?>
</form> </form>
<!-- Modal for Media Manager --> <!-- Modal for Media Manager -->
<?php include(PATH_ADMIN_THEMES.'booty/html/media.php'); ?> <?php include(PATH_ADMIN_THEMES . 'booty/html/media.php'); ?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
// Define function if they doesn't exist // Define function if they doesn't exist
// This helps if the user doesn't activate any plugin as editor // This helps if the user doesn't activate any plugin as editor
if (typeof editorGetContent != "function") { if (typeof editorGetContent != "function") {
window.editorGetContent = function(){ window.editorGetContent = function() {
return $("#jseditor").val(); return $("#jseditor").val();
}; };
} }
if (typeof editorInsertMedia != "function") { if (typeof editorInsertMedia != "function") {
window.editorInsertMedia = function(filename){ window.editorInsertMedia = function(filename) {
$("#jseditor").val($('#jseditor').val()+'<img src="'+filename+'" alt="">'); $("#jseditor").val($('#jseditor').val() + '<img src="' + filename + '" alt="">');
}; };
} }
if (typeof editorInsertLinkedMedia != "function") { if (typeof editorInsertLinkedMedia != "function") {
window.editorInsertLinkedMedia = function(filename, link){ window.editorInsertLinkedMedia = function(filename, link) {
$("#jseditor").val($('#jseditor').val()+'<a href="'+link+'"><img src="'+filename+'" alt=""></a>'); $("#jseditor").val($('#jseditor').val() + '<a href="' + link + '"><img src="' + filename + '" alt=""></a>');
}; };
}
// Button switch
$("#jsbuttonSwitch").on("click", function() {
if ($(this).data("switch")=="publish") {
$(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>');
$(this).data("switch", "draft");
} else {
$(this).html('<i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?>');
$(this).data("switch", "publish");
} }
});
// Button preview // Button switch
$("#jsbuttonPreview").on("click", function() { $("#jsbuttonSwitch").on("click", function() {
var uuid = $("#jsuuid").val(); if ($(this).data("switch") == "publish") {
var title = $("#jstitle").val(); $(this).html('<i class="fa fa-square switch-icon-draft"></i> <?php $L->p('Draft') ?>');
var content = editorGetContent(); $(this).data("switch", "draft");
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) { } else {
var preview = window.open("<?php echo DOMAIN_PAGES.'autosave-'.$uuid.'?preview='.md5('autosave-'.$uuid) ?>", "bludit-preview"); $(this).html('<i class="fa fa-square switch-icon-publish"></i> <?php $L->p('Publish') ?>');
preview.focus(); $(this).data("switch", "publish");
}
}); });
});
// Button Save // Button preview
$("#jsbuttonSave").on("click", function() { $("#jsbuttonPreview").on("click", function() {
// If the switch is setted to "published", get the value from the selector var uuid = $("#jsuuid").val();
if ($("#jsbuttonSwitch").data("switch")=="publish") { var title = $("#jstitle").val();
var value = $("#jstypeSelector option:selected").val(); var content = editorGetContent();
$("#jstype").val(value); bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
} else { var preview = window.open("<?php echo DOMAIN_PAGES . 'autosave-' . $uuid . '?preview=' . md5('autosave-' . $uuid) ?>", "bludit-preview");
$("#jstype").val("draft"); preview.focus();
} });
});
// Get the content // Button Save
$("#jscontent").val( editorGetContent() ); $("#jsbuttonSave").on("click", function() {
// If the switch is setted to "published", get the value from the selector
if ($("#jsbuttonSwitch").data("switch") == "publish") {
var value = $("#jstypeSelector option:selected").val();
$("#jstype").val(value);
} else {
$("#jstype").val("draft");
}
// Submit the form // Get the content
$("#jsform").submit(); $("#jscontent").val(editorGetContent());
});
// Autosave // Submit the form
var currentContent = editorGetContent(); $("#jsform").submit();
setInterval(function() { });
// Autosave
var currentContent = editorGetContent();
setInterval(function() {
var uuid = $("#jsuuid").val(); var uuid = $("#jsuuid").val();
var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]"; var title = $("#jstitle").val() + "[<?php $L->p('Autosave') ?>]";
var content = editorGetContent(); var content = editorGetContent();
// Autosave when content has at least 100 characters // Autosave when content has at least 100 characters
if (content.length<100) { if (content.length < 100) {
return false; return false;
} }
// Autosave only when the user change the content // Autosave only when the user change the content
if (currentContent!=content) { if (currentContent != content) {
currentContent = content; currentContent = content;
bluditAjax.saveAsDraft(uuid, title, content).then(function(data) { bluditAjax.saveAsDraft(uuid, title, content).then(function(data) {
if (data.status==0) { if (data.status == 0) {
showAlert("<?php $L->p('Autosave') ?>"); showAlert("<?php $L->p('Autosave') ?>");
} }
}); });
} }
},1000*60*AUTOSAVE_INTERVAL); }, 1000 * 60 * AUTOSAVE_INTERVAL);
}); });
</script> </script>

View File

@ -12,7 +12,7 @@ echo Bootstrap::formTitle(array('title' => $L->g('Search plugins')));
?> ?>
<input type="text" class="form-control" id="search" placeholder="<?php $L->p('Search') ?>"> <input type="text" dir="auto" class="form-control" id="search" placeholder="<?php $L->p('Search') ?>">
<script> <script>
$(document).ready(function() { $(document).ready(function() {
$("#search").on("keyup", function() { $("#search").on("keyup", function() {

View File

@ -1,8 +1,9 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
class Login { class Login
{
protected $users; protected $users;
protected $site;
function __construct() function __construct()
{ {
@ -12,11 +13,11 @@ class Login {
$this->users = new Users(); $this->users = new Users();
} }
if (isset($GLOBALS['site'])) { if (isset($GLOBALS['site'])) {
$this->site = $GLOBALS['site']; $this->site = $GLOBALS['site'];
} else { } else {
$this->site = new Site(); $this->site = new Site();
} }
// Start the Session // Start the Session
if (!Session::started()) { if (!Session::started()) {
@ -39,18 +40,18 @@ class Login {
// Returns TRUE if the user is logged, FALSE otherwise // Returns TRUE if the user is logged, FALSE otherwise
public function isLogged() public function isLogged()
{ {
if (Session::get('fingerPrint')===$this->fingerPrint()) { if (Session::get('fingerPrint') === $this->fingerPrint()) {
$username = Session::get('username'); $username = Session::get('username');
if (!empty($username)) { if (!empty($username)) {
return true; return true;
} else { } else {
Log::set(__METHOD__.LOG_SEP.'Session username empty, destroying the session.'); Log::set(__METHOD__ . LOG_SEP . 'Session username empty, destroying the session.');
Session::destroy(); Session::destroy();
return false; return false;
} }
} }
Log::set(__METHOD__.LOG_SEP.'FingerPrints are different. ['.Session::get('fingerPrint').'] != ['.$this->fingerPrint().']'); Log::set(__METHOD__ . LOG_SEP . 'FingerPrints are different. [' . Session::get('fingerPrint') . '] != [' . $this->fingerPrint() . ']');
return false; return false;
} }
@ -62,7 +63,7 @@ class Login {
Session::set('fingerPrint', $this->fingerPrint()); Session::set('fingerPrint', $this->fingerPrint());
Session::set('sessionTime', time()); Session::set('sessionTime', time());
Log::set(__METHOD__.LOG_SEP.'User logged, fingerprint ['.$this->fingerPrint().']'); Log::set(__METHOD__ . LOG_SEP . 'User logged, fingerprint [' . $this->fingerPrint() . ']');
} }
public function setRememberMe($username) public function setRememberMe($username)
@ -77,7 +78,7 @@ class Login {
Cookie::set(REMEMBER_COOKIE_USERNAME, $username, REMEMBER_COOKIE_EXPIRE_IN_DAYS); Cookie::set(REMEMBER_COOKIE_USERNAME, $username, REMEMBER_COOKIE_EXPIRE_IN_DAYS);
Cookie::set(REMEMBER_COOKIE_TOKEN, $token, REMEMBER_COOKIE_EXPIRE_IN_DAYS); Cookie::set(REMEMBER_COOKIE_TOKEN, $token, REMEMBER_COOKIE_EXPIRE_IN_DAYS);
Log::set(__METHOD__.LOG_SEP.'Cookies set for Remember Me.'); Log::set(__METHOD__ . LOG_SEP . 'Cookies set for Remember Me.');
} }
public function invalidateRememberMe() public function invalidateRememberMe()
@ -101,12 +102,12 @@ class Login {
$username = trim($username); $username = trim($username);
if (empty($username) || empty($password)) { if (empty($username) || empty($password)) {
Log::set(__METHOD__.LOG_SEP.'Username or password empty. Username: '.$username); Log::set(__METHOD__ . LOG_SEP . 'Username or password empty. Username: ' . $username);
return false; return false;
} }
if (Text::length($password)<PASSWORD_LENGTH) { if (Text::length($password) < PASSWORD_LENGTH) {
Log::set(__METHOD__.LOG_SEP.'Password length is shorter than required.'); Log::set(__METHOD__ . LOG_SEP . 'Password length is shorter than required.');
return false; return false;
} }
@ -117,13 +118,13 @@ class Login {
} }
$passwordHash = $this->users->generatePasswordHash($password, $user->salt()); $passwordHash = $this->users->generatePasswordHash($password, $user->salt());
if ($passwordHash===$user->password()) { if ($passwordHash === $user->password()) {
$this->setLogin($username, $user->role()); $this->setLogin($username, $user->role());
Log::set(__METHOD__.LOG_SEP.'Successful user login by username and password - Username ['.$username.']'); Log::set(__METHOD__ . LOG_SEP . 'Successful user login by username and password - Username [' . $username . ']');
return true; return true;
} }
Log::set(__METHOD__.LOG_SEP.'Password incorrect.'); Log::set(__METHOD__ . LOG_SEP . 'Password incorrect.');
return false; return false;
} }
@ -145,20 +146,20 @@ class Login {
if (empty($username) || empty($token)) { if (empty($username) || empty($token)) {
$this->invalidateRememberMe(); $this->invalidateRememberMe();
Log::set(__METHOD__.LOG_SEP.'Username or Token empty. Username: '.$username.' - Token: '.$token); Log::set(__METHOD__ . LOG_SEP . 'Username or Token empty. Username: ' . $username . ' - Token: ' . $token);
return false; return false;
} }
if ($username !== $this->users->getByRememberToken($token)) { if ($username !== $this->users->getByRememberToken($token)) {
$this->invalidateRememberMe(); $this->invalidateRememberMe();
Log::set(__METHOD__.LOG_SEP.'The user has different token or the token doesn\'t exist.'); Log::set(__METHOD__ . LOG_SEP . 'The user has different token or the token doesn\'t exist.');
return false; return false;
} }
// Get user from database and login // Get user from database and login
$user = $this->users->getUserDB($username); $user = $this->users->getUserDB($username);
$this->setLogin($username, $user['role']); $this->setLogin($username, $user['role']);
Log::set(__METHOD__.LOG_SEP.'User authenticated via Remember Me.'); Log::set(__METHOD__ . LOG_SEP . 'User authenticated via Remember Me.');
return true; return true;
} }
@ -177,4 +178,4 @@ class Login {
Session::destroy(); Session::destroy();
return true; return true;
} }
} }

View File

@ -1,12 +1,13 @@
<?php <?php
class pluginAbout extends Plugin { class pluginAbout extends Plugin
{
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'label'=>'About', 'label' => 'About',
'text'=>'' 'text' => ''
); );
} }
@ -19,14 +20,14 @@ class pluginAbout extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('About').'</label>'; $html .= '<label>' . $L->get('About') . '</label>';
$html .= '<textarea name="text" id="jstext">'.$this->getValue('text').'</textarea>'; $html .= '<textarea name="text" id="jstext">' . $this->getValue('text') . '</textarea>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -35,12 +36,12 @@ class pluginAbout extends Plugin {
public function siteSidebar() public function siteSidebar()
{ {
$html = '<div class="plugin plugin-about">'; $html = '<div class="plugin plugin-about">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= html_entity_decode(nl2br($this->getValue('text'))); $html .= html_entity_decode(nl2br($this->getValue('text')));
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,17 +1,18 @@
<?php <?php
class pluginAPI extends Plugin { class pluginAPI extends Plugin
{
private $method; private $method;
public function init() public function init()
{ {
// Generate the API Token // Generate the API Token
$token = md5( uniqid().time().DOMAIN ); $token = md5(uniqid() . time() . DOMAIN);
$this->dbFields = array( $this->dbFields = array(
'token'=>$token, // API Token 'token' => $token, // API Token
'numberOfItems'=>15 // Amount of items to return 'numberOfItems' => 15 // Amount of items to return
); );
} }
@ -29,28 +30,28 @@ class pluginAPI extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('URL').'</label>'; $html .= '<label>' . $L->get('URL') . '</label>';
$html .= '<p class="text-muted">'.DOMAIN_BASE.'api/{endpoint}</p>'; $html .= '<p class="text-muted">' . DOMAIN_BASE . 'api/{endpoint}</p>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('API Token').'</label>'; $html .= '<label>' . $L->get('API Token') . '</label>';
$html .= '<input name="token" type="text" value="'.$this->getValue('token').'">'; $html .= '<input name="token" type="text" dir="auto" value="' . $this->getValue('token') . '">';
$html .= '<span class="tip">'.$L->get('This token is for read only and is regenerated every time you install the plugin').'</span>'; $html .= '<span class="tip">' . $L->get('This token is for read only and is regenerated every time you install the plugin') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of pages').'</label>'; $html .= '<label>' . $L->get('Amount of pages') . '</label>';
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" dir="auto" value="' . $this->getValue('numberOfItems') . '">';
$html .= '<span class="tip">'.$L->get('This is the maximum of pages to return when you call to').'</span>'; $html .= '<span class="tip">' . $L->get('This is the maximum of pages to return when you call to') . '</span>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
// API HOOKS // API HOOKS
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
public function beforeAll() public function beforeAll()
{ {
@ -60,8 +61,8 @@ class pluginAPI extends Plugin {
// CHECK URL // CHECK URL
// ------------------------------------------------------------ // ------------------------------------------------------------
$URI = $this->webhook('api', $returnsAfterURI=true, $fixed=false); $URI = $this->webhook('api', $returnsAfterURI = true, $fixed = false);
if ($URI===false) { if ($URI === false) {
return false; return false;
} }
@ -73,14 +74,14 @@ class pluginAPI extends Plugin {
// ------------------------------------------------------------ // ------------------------------------------------------------
$inputs = $this->getMethodInputs(); $inputs = $this->getMethodInputs();
if (empty($inputs)) { if (empty($inputs)) {
$this->response(400, 'Bad Request', array('message'=>'Missing method inputs.')); $this->response(400, 'Bad Request', array('message' => 'Missing method inputs.'));
} }
// ENDPOINT PARAMETERS // ENDPOINT PARAMETERS
// ------------------------------------------------------------ // ------------------------------------------------------------
$parameters = $this->getEndpointParameters($URI); $parameters = $this->getEndpointParameters($URI);
if (empty($parameters)) { if (empty($parameters)) {
$this->response(400, 'Bad Request', array('message'=>'Missing endpoint parameters.')); $this->response(400, 'Bad Request', array('message' => 'Missing endpoint parameters.'));
} }
// API TOKEN // API TOKEN
@ -90,12 +91,12 @@ class pluginAPI extends Plugin {
// Check empty token // Check empty token
if (empty($inputs['token'])) { if (empty($inputs['token'])) {
$this->response(400, 'Bad Request', array('message'=>'Missing API token.')); $this->response(400, 'Bad Request', array('message' => 'Missing API token.'));
} }
// Check if the token is valid // Check if the token is valid
if ($inputs['token']!==$tokenAPI) { if ($inputs['token'] !== $tokenAPI) {
$this->response(401, 'Unauthorized', array('message'=>'Invalid API token.')); $this->response(401, 'Unauthorized', array('message' => 'Invalid API token.'));
} }
// AUTHENTICATION TOKEN // AUTHENTICATION TOKEN
@ -105,10 +106,10 @@ class pluginAPI extends Plugin {
// Get the user with the authentication token, FALSE if doesn't exit // Get the user with the authentication token, FALSE if doesn't exit
$username = $users->getByAuthToken($inputs['authentication']); $username = $users->getByAuthToken($inputs['authentication']);
if ($username!==false) { if ($username !== false) {
try { try {
$user = new User($username); $user = new User($username);
if (($user->role()=='admin') && ($user->enabled())) { if (($user->role() == 'admin') && ($user->enabled())) {
// Loggin the user to create the session // Loggin the user to create the session
$login = new Login(); $login = new Login();
$login->setLogin($username, 'admin'); $login->setLogin($username, 'admin');
@ -130,89 +131,88 @@ class pluginAPI extends Plugin {
// ------------------------------------------------------------ // ------------------------------------------------------------
// (GET) /api/pages // (GET) /api/pages
if ( ($method==='GET') && ($parameters[0]==='pages') && empty($parameters[1]) ) { if (($method === 'GET') && ($parameters[0] === 'pages') && empty($parameters[1])) {
$data = $this->getPages($inputs); $data = $this->getPages($inputs);
} }
// (GET) /api/pages/<key> // (GET) /api/pages/<key>
elseif ( ($method==='GET') && ($parameters[0]==='pages') && !empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'pages') && !empty($parameters[1])) {
$pageKey = $parameters[1]; $pageKey = $parameters[1];
if (isset($parameters[2])) { if (isset($parameters[2])) {
$pageKey = $parameters[1].'/'.$parameters[2]; $pageKey = $parameters[1] . '/' . $parameters[2];
} }
$data = $this->getPage($pageKey); $data = $this->getPage($pageKey);
} }
// (PUT) /api/pages/<key> // (PUT) /api/pages/<key>
elseif ( ($method==='PUT') && ($parameters[0]==='pages') && !empty($parameters[1]) && $writePermissions ) { elseif (($method === 'PUT') && ($parameters[0] === 'pages') && !empty($parameters[1]) && $writePermissions) {
$pageKey = $parameters[1]; $pageKey = $parameters[1];
$data = $this->editPage($pageKey, $inputs); $data = $this->editPage($pageKey, $inputs);
} }
// (DELETE) /api/pages/<key> // (DELETE) /api/pages/<key>
elseif ( ($method==='DELETE') && ($parameters[0]==='pages') && !empty($parameters[1]) && $writePermissions ) { elseif (($method === 'DELETE') && ($parameters[0] === 'pages') && !empty($parameters[1]) && $writePermissions) {
$pageKey = $parameters[1]; $pageKey = $parameters[1];
$data = $this->deletePage($pageKey); $data = $this->deletePage($pageKey);
} }
// (POST) /api/pages // (POST) /api/pages
elseif ( ($method==='POST') && ($parameters[0]==='pages') && empty($parameters[1]) && $writePermissions ) { elseif (($method === 'POST') && ($parameters[0] === 'pages') && empty($parameters[1]) && $writePermissions) {
$data = $this->createPage($inputs); $data = $this->createPage($inputs);
} }
// (GET) /api/settings // (GET) /api/settings
elseif ( ($method==='GET') && ($parameters[0]==='settings') && empty($parameters[1]) && $writePermissions ) { elseif (($method === 'GET') && ($parameters[0] === 'settings') && empty($parameters[1]) && $writePermissions) {
$data = $this->getSettings(); $data = $this->getSettings();
} }
// (PUT) /api/settings // (PUT) /api/settings
elseif ( ($method==='PUT') && ($parameters[0]==='settings') && empty($parameters[1]) && $writePermissions ) { elseif (($method === 'PUT') && ($parameters[0] === 'settings') && empty($parameters[1]) && $writePermissions) {
$data = $this->editSettings($inputs); $data = $this->editSettings($inputs);
} }
// (POST) /api/images // (POST) /api/images
elseif ( ($method==='POST') && ($parameters[0]==='images') && $writePermissions ) { elseif (($method === 'POST') && ($parameters[0] === 'images') && $writePermissions) {
$data = $this->uploadImage($inputs); $data = $this->uploadImage($inputs);
} }
// (GET) /api/tags // (GET) /api/tags
elseif ( ($method==='GET') && ($parameters[0]==='tags') && empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'tags') && empty($parameters[1])) {
$data = $this->getTags(); $data = $this->getTags();
} }
// (GET) /api/tags/<key> // (GET) /api/tags/<key>
elseif ( ($method==='GET') && ($parameters[0]==='tags') && !empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'tags') && !empty($parameters[1])) {
$tagKey = $parameters[1]; $tagKey = $parameters[1];
$data = $this->getTag($tagKey); $data = $this->getTag($tagKey);
} }
// (GET) /api/categories // (GET) /api/categories
elseif ( ($method==='GET') && ($parameters[0]==='categories') && empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'categories') && empty($parameters[1])) {
$data = $this->getCategories(); $data = $this->getCategories();
} }
// (GET) /api/categories/<key> // (GET) /api/categories/<key>
elseif ( ($method==='GET') && ($parameters[0]==='categories') && !empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'categories') && !empty($parameters[1])) {
$categoryKey = $parameters[1]; $categoryKey = $parameters[1];
$data = $this->getCategory($categoryKey); $data = $this->getCategory($categoryKey);
} }
// (GET) /api/users // (GET) /api/users
elseif ( ($method==='GET') && ($parameters[0]==='users') && empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'users') && empty($parameters[1])) {
$data = $this->getUsers(); $data = $this->getUsers();
} }
// (GET) /api/users/<username> // (GET) /api/users/<username>
elseif ( ($method==='GET') && ($parameters[0]==='users') && !empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'users') && !empty($parameters[1])) {
$username = $parameters[1]; $username = $parameters[1];
$data = $this->getUser($username); $data = $this->getUser($username);
} }
// (GET) /api/files/<page-key> // (GET) /api/files/<page-key>
elseif ( ($method==='GET') && ($parameters[0]==='files') && !empty($parameters[1]) ) { elseif (($method === 'GET') && ($parameters[0] === 'files') && !empty($parameters[1])) {
$pageKey = $parameters[1]; $pageKey = $parameters[1];
$data = $this->getFiles($pageKey); $data = $this->getFiles($pageKey);
} }
// (POST) /api/files/<page-key> // (POST) /api/files/<page-key>
elseif ( ($method==='POST') && ($parameters[0]==='files') && !empty($parameters[1]) ) { elseif (($method === 'POST') && ($parameters[0] === 'files') && !empty($parameters[1])) {
$pageKey = $parameters[1]; $pageKey = $parameters[1];
$data = $this->uploadFile($pageKey); $data = $this->uploadFile($pageKey);
} } else {
else { $this->response(401, 'Unauthorized', array('message' => 'Access denied or invalid endpoint.'));
$this->response(401, 'Unauthorized', array('message'=>'Access denied or invalid endpoint.'));
} }
$this->response(200, 'OK', $data); $this->response(200, 'OK', $data);
} }
// PRIVATE METHODS // PRIVATE METHODS
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
private function getMethod() private function getMethod()
{ {
@ -229,7 +229,7 @@ class pluginAPI extends Plugin {
private function getMethodInputs() private function getMethodInputs()
{ {
switch($this->method) { switch ($this->method) {
case "POST": case "POST":
$inputs = $_POST; $inputs = $_POST;
break; break;
@ -259,12 +259,12 @@ class pluginAPI extends Plugin {
{ {
$tmp = array(); $tmp = array();
if (is_array($inputs)) { if (is_array($inputs)) {
foreach ($inputs as $key=>$value) { foreach ($inputs as $key => $value) {
$tmp[$key] = Sanitize::html($value); $tmp[$key] = Sanitize::html($value);
} }
} elseif (is_string($inputs)) { } elseif (is_string($inputs)) {
$tmp = json_decode($inputs, true); $tmp = json_decode($inputs, true);
if (json_last_error()!==JSON_ERROR_NONE) { if (json_last_error() !== JSON_ERROR_NONE) {
$tmp = array(); $tmp = array();
} }
} }
@ -284,16 +284,16 @@ class pluginAPI extends Plugin {
$parameters = explode('/', $URI); $parameters = explode('/', $URI);
// Sanitize parameters // Sanitize parameters
foreach ($parameters as $key=>$value) { foreach ($parameters as $key => $value) {
$parameters[$key] = Sanitize::html($value); $parameters[$key] = Sanitize::html($value);
} }
return $parameters; return $parameters;
} }
private function response($code=200, $message='OK', $data=array()) private function response($code = 200, $message = 'OK', $data = array())
{ {
header('HTTP/1.1 '.$code.' '.$message); header('HTTP/1.1 ' . $code . ' ' . $message);
header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json'); header('Content-Type: application/json');
$json = json_encode($data); $json = json_encode($data);
@ -304,9 +304,9 @@ class pluginAPI extends Plugin {
{ {
global $tags; global $tags;
$tmp = array( $tmp = array(
'status'=>'0', 'status' => '0',
'message'=>'List of tags.', 'message' => 'List of tags.',
'data'=>array() 'data' => array()
); );
foreach ($tags->keys() as $key) { foreach ($tags->keys() as $key) {
$tag = $tags->getMap($key); $tag = $tags->getMap($key);
@ -323,8 +323,8 @@ class pluginAPI extends Plugin {
$tag = new Tag($key); $tag = new Tag($key);
} catch (Exception $e) { } catch (Exception $e) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Tag not found by the key: '.$key 'message' => 'Tag not found by the key: ' . $key
); );
} }
@ -332,17 +332,18 @@ class pluginAPI extends Plugin {
foreach ($tag->pages() as $pageKey) { foreach ($tag->pages() as $pageKey) {
try { try {
$page = new Page($pageKey); $page = new Page($pageKey);
array_push($list, $page->json($returnsArray=true)); array_push($list, $page->json($returnsArray = true));
} catch (Exception $e){} } catch (Exception $e) {
}
} }
$data = $tag->json($returnsArray=true); $data = $tag->json($returnsArray = true);
$data['pages'] = $list; $data['pages'] = $list;
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Information about the tag and pages related.', 'message' => 'Information about the tag and pages related.',
'data'=>$data 'data' => $data
); );
} }
@ -351,22 +352,22 @@ class pluginAPI extends Plugin {
global $pages; global $pages;
// Parameters and the default values // Parameters and the default values
$published = (isset($args['published'])?$args['published']=='true':true); $published = (isset($args['published']) ? $args['published'] == 'true' : true);
$static = (isset($args['static'])?$args['static']=='true':false); $static = (isset($args['static']) ? $args['static'] == 'true' : false);
$draft = (isset($args['draft'])?$args['draft']=='true':false); $draft = (isset($args['draft']) ? $args['draft'] == 'true' : false);
$sticky = (isset($args['sticky'])?$args['sticky']=='true':false); $sticky = (isset($args['sticky']) ? $args['sticky'] == 'true' : false);
$scheduled = (isset($args['scheduled'])?$args['scheduled']=='true':false); $scheduled = (isset($args['scheduled']) ? $args['scheduled'] == 'true' : false);
$untagged = (isset($args['untagged'])?$args['untagged']=='true':false); $untagged = (isset($args['untagged']) ? $args['untagged'] == 'true' : false);
$numberOfItems = (isset($args['numberOfItems'])?$args['numberOfItems']:10); $numberOfItems = (isset($args['numberOfItems']) ? $args['numberOfItems'] : 10);
$pageNumber = (isset($args['pageNumber'])?$args['pageNumber']:1); $pageNumber = (isset($args['pageNumber']) ? $args['pageNumber'] : 1);
$list = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled); $list = $pages->getList($pageNumber, $numberOfItems, $published, $static, $sticky, $draft, $scheduled);
$tmp = array( $tmp = array(
'status'=>'0', 'status' => '0',
'message'=>'List of pages', 'message' => 'List of pages',
'numberOfItems'=>$numberOfItems, 'numberOfItems' => $numberOfItems,
'data'=>array() 'data' => array()
); );
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
@ -374,12 +375,12 @@ class pluginAPI extends Plugin {
// Create the page object from the page key // Create the page object from the page key
$page = new Page($pageKey); $page = new Page($pageKey);
if ($untagged) { if ($untagged) {
if (empty($page->tags())) { if (empty($page->tags())) {
// Push the page to the data array for the response // Push the page to the data array for the response
array_push($tmp['data'], $page->json($returnsArray=true)); array_push($tmp['data'], $page->json($returnsArray = true));
} }
} else{ } else {
array_push($tmp['data'], $page->json($returnsArray=true)); array_push($tmp['data'], $page->json($returnsArray = true));
} }
} catch (Exception $e) { } catch (Exception $e) {
// Continue // Continue
@ -394,14 +395,14 @@ class pluginAPI extends Plugin {
try { try {
$page = new Page($key); $page = new Page($key);
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Page filtered by key: '.$key, 'message' => 'Page filtered by key: ' . $key,
'data'=>$page->json( $returnsArray=true ) 'data' => $page->json($returnsArray = true)
); );
} catch (Exception $e) { } catch (Exception $e) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Page not found.' 'message' => 'Page not found.'
); );
} }
} }
@ -415,17 +416,17 @@ class pluginAPI extends Plugin {
// This function is defined on functions.php // This function is defined on functions.php
$key = createPage($args); $key = createPage($args);
if ($key===false) { if ($key === false) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error trying to create the new page.' 'message' => 'Error trying to create the new page.'
); );
} }
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Page created.', 'message' => 'Page created.',
'data'=>array('key'=>$key) 'data' => array('key' => $key)
); );
} }
@ -439,17 +440,17 @@ class pluginAPI extends Plugin {
$args['key'] = $key; $args['key'] = $key;
$newKey = editPage($args); $newKey = editPage($args);
if ($newKey===false) { if ($newKey === false) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error trying to edit the page.' 'message' => 'Error trying to edit the page.'
); );
} }
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Page edited.', 'message' => 'Page edited.',
'data'=>array('key'=>$newKey) 'data' => array('key' => $newKey)
); );
} }
@ -457,14 +458,14 @@ class pluginAPI extends Plugin {
{ {
if (deletePage($key)) { if (deletePage($key)) {
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Page deleted.' 'message' => 'Page deleted.'
); );
} }
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error trying to delete the page.' 'message' => 'Error trying to delete the page.'
); );
} }
@ -482,10 +483,10 @@ class pluginAPI extends Plugin {
{ {
// Set upload directory // Set upload directory
if (isset($inputs['uuid']) && IMAGE_RESTRICT) { if (isset($inputs['uuid']) && IMAGE_RESTRICT) {
$imageDirectory = PATH_UPLOADS_PAGES.$inputs['uuid'].DS; $imageDirectory = PATH_UPLOADS_PAGES . $inputs['uuid'] . DS;
$thumbnailDirectory = $imageDirectory.'thumbnails'.DS; $thumbnailDirectory = $imageDirectory . 'thumbnails' . DS;
$imageEndpoint = DOMAIN_UPLOADS_PAGES.$inputs['uuid'].'/'; $imageEndpoint = DOMAIN_UPLOADS_PAGES . $inputs['uuid'] . '/';
$thumbnailEndpoint = $imageEndpoint.'thumbnails'.'/'; $thumbnailEndpoint = $imageEndpoint . 'thumbnails' . '/';
if (!Filesystem::directoryExists($thumbnailDirectory)) { if (!Filesystem::directoryExists($thumbnailDirectory)) {
Filesystem::mkdir($thumbnailDirectory, true); Filesystem::mkdir($thumbnailDirectory, true);
} }
@ -498,36 +499,36 @@ class pluginAPI extends Plugin {
if (!isset($_FILES['image'])) { if (!isset($_FILES['image'])) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'No image sent.' 'message' => 'No image sent.'
); );
} }
if ($_FILES['image']['error'] != 0) { if ($_FILES['image']['error'] != 0) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error uploading the image, maximum load file size allowed: '.ini_get('upload_max_filesize') 'message' => 'Error uploading the image, maximum load file size allowed: ' . ini_get('upload_max_filesize')
); );
} }
// Move from PHP tmp file to Bludit tmp directory // Move from PHP tmp file to Bludit tmp directory
Filesystem::mv($_FILES['image']['tmp_name'], PATH_TMP.$_FILES['image']['name']); Filesystem::mv($_FILES['image']['tmp_name'], PATH_TMP . $_FILES['image']['name']);
// Transform image and create thumbnails // Transform image and create thumbnails
$image = transformImage(PATH_TMP.$_FILES['image']['name'], $imageDirectory, $thumbnailDirectory); $image = transformImage(PATH_TMP . $_FILES['image']['name'], $imageDirectory, $thumbnailDirectory);
if ($image) { if ($image) {
$filename = Filesystem::filename($image); $filename = Filesystem::filename($image);
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Image uploaded.', 'message' => 'Image uploaded.',
'image'=>$imageEndpoint.$filename, 'image' => $imageEndpoint . $filename,
'thumbnail'=>$thumbnailEndpoint.$filename 'thumbnail' => $thumbnailEndpoint . $filename
); );
} }
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Image extension not allowed.' 'message' => 'Image extension not allowed.'
); );
} }
@ -542,9 +543,9 @@ class pluginAPI extends Plugin {
{ {
global $site; global $site;
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Settings.', 'message' => 'Settings.',
'data'=>$site->get() 'data' => $site->get()
); );
} }
@ -560,13 +561,13 @@ class pluginAPI extends Plugin {
{ {
if (editSettings($args)) { if (editSettings($args)) {
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Settings edited.' 'message' => 'Settings edited.'
); );
} }
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error trying to edit the settings.' 'message' => 'Error trying to edit the settings.'
); );
} }
@ -581,9 +582,9 @@ class pluginAPI extends Plugin {
{ {
global $categories; global $categories;
$tmp = array( $tmp = array(
'status'=>'0', 'status' => '0',
'message'=>'List of categories.', 'message' => 'List of categories.',
'data'=>array() 'data' => array()
); );
foreach ($categories->keys() as $key) { foreach ($categories->keys() as $key) {
$category = $categories->getMap($key); $category = $categories->getMap($key);
@ -607,8 +608,8 @@ class pluginAPI extends Plugin {
$category = new Category($key); $category = new Category($key);
} catch (Exception $e) { } catch (Exception $e) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Category not found by the key: '.$key 'message' => 'Category not found by the key: ' . $key
); );
} }
@ -616,17 +617,18 @@ class pluginAPI extends Plugin {
foreach ($category->pages() as $pageKey) { foreach ($category->pages() as $pageKey) {
try { try {
$page = new Page($pageKey); $page = new Page($pageKey);
array_push($list, $page->json($returnsArray=true)); array_push($list, $page->json($returnsArray = true));
} catch (Exception $e){} } catch (Exception $e) {
}
} }
$data = $category->json($returnsArray=true); $data = $category->json($returnsArray = true);
$data['pages'] = $list; $data['pages'] = $list;
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Information about the category and pages related.', 'message' => 'Information about the category and pages related.',
'data'=>$data 'data' => $data
); );
} }
@ -643,16 +645,16 @@ class pluginAPI extends Plugin {
$user = new User($username); $user = new User($username);
} catch (Exception $e) { } catch (Exception $e) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'User not found by username: '.$username 'message' => 'User not found by username: ' . $username
); );
} }
$data = $user->json($returnsArray=true); $data = $user->json($returnsArray = true);
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'User profile.', 'message' => 'User profile.',
'data'=>$data 'data' => $data
); );
} }
@ -665,19 +667,19 @@ class pluginAPI extends Plugin {
{ {
global $users; global $users;
$data = array(); $data = array();
foreach ($users->db as $username=>$profile) { foreach ($users->db as $username => $profile) {
try { try {
$user = new User($username); $user = new User($username);
$data[$username] = $user->json($returnsArray=true); $data[$username] = $user->json($returnsArray = true);
} catch (Exception $e) { } catch (Exception $e) {
continue; continue;
} }
} }
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Users profiles.', 'message' => 'Users profiles.',
'data'=>$data 'data' => $data
); );
} }
@ -690,19 +692,19 @@ class pluginAPI extends Plugin {
{ {
$chunk = false; $chunk = false;
$sortByDate = true; $sortByDate = true;
$path = PATH_UPLOADS_PAGES.$pageKey.DS; $path = PATH_UPLOADS_PAGES . $pageKey . DS;
$listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk); $listFiles = Filesystem::listFiles($path, '*', '*', $sortByDate, $chunk);
$files = array(); $files = array();
foreach ($listFiles as $file) { foreach ($listFiles as $file) {
$info = array('thumbnail'=>''); $info = array('thumbnail' => '');
$info['file'] = $file; $info['file'] = $file;
$info['filename'] = basename($file); $info['filename'] = basename($file);
$info['mime'] = Filesystem::mimeType($file); $info['mime'] = Filesystem::mimeType($file);
$info['size'] = Filesystem::getSize($file); $info['size'] = Filesystem::getSize($file);
// Check if thumbnail exists for the file // Check if thumbnail exists for the file
$thumbnail = $path.'thumbnails'.DS.$info['filename']; $thumbnail = $path . 'thumbnails' . DS . $info['filename'];
if (Filesystem::fileExists($thumbnail)) { if (Filesystem::fileExists($thumbnail)) {
$info['thumbnail'] = $thumbnail; $info['thumbnail'] = $thumbnail;
} }
@ -711,9 +713,9 @@ class pluginAPI extends Plugin {
} }
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'Files for the page key: '.$pageKey, 'message' => 'Files for the page key: ' . $pageKey,
'data'=>$files 'data' => $files
); );
} }
@ -731,34 +733,34 @@ class pluginAPI extends Plugin {
{ {
if (!isset($_FILES['file'])) { if (!isset($_FILES['file'])) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'File not sent.' 'message' => 'File not sent.'
); );
} }
if ($_FILES['file']['error'] != 0) { if ($_FILES['file']['error'] != 0) {
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error uploading the file.' 'message' => 'Error uploading the file.'
); );
} }
$filename = $_FILES['file']['name']; $filename = $_FILES['file']['name'];
$absoluteURL = DOMAIN_UPLOADS_PAGES.$pageKey.DS.$filename; $absoluteURL = DOMAIN_UPLOADS_PAGES . $pageKey . DS . $filename;
$absolutePath = PATH_UPLOADS_PAGES.$pageKey.DS.$filename; $absolutePath = PATH_UPLOADS_PAGES . $pageKey . DS . $filename;
if (Filesystem::mv($_FILES['file']['tmp_name'], $absolutePath)) { if (Filesystem::mv($_FILES['file']['tmp_name'], $absolutePath)) {
return array( return array(
'status'=>'0', 'status' => '0',
'message'=>'File uploaded.', 'message' => 'File uploaded.',
'filename'=>$filename, 'filename' => $filename,
'absolutePath'=>$absolutePath, 'absolutePath' => $absolutePath,
'absoluteURL'=>$absoluteURL 'absoluteURL' => $absoluteURL
); );
} }
return array( return array(
'status'=>'1', 'status' => '1',
'message'=>'Error moving the file to the final path.' 'message' => 'Error moving the file to the final path.'
); );
} }
} }

View File

@ -1,13 +1,14 @@
<?php <?php
class pluginCategories extends Plugin { class pluginCategories extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'Categories', 'label' => 'Categories',
'hideCero'=>true 'hideCero' => true
); );
} }
@ -21,16 +22,16 @@ class pluginCategories extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Hide Categories without content').'</label>'; $html .= '<label>' . $L->get('Hide Categories without content') . '</label>';
$html .= '<select name="hideCero">'; $html .= '<select name="hideCero">';
$html .= '<option value="true" '.($this->getValue('hideCero')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('hideCero') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('hideCero')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('hideCero') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
@ -45,27 +46,27 @@ class pluginCategories extends Plugin {
// HTML for sidebar // HTML for sidebar
$html = '<div class="plugin plugin-categories">'; $html = '<div class="plugin plugin-categories">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= '<ul>'; $html .= '<ul>';
// By default the database of categories are alphanumeric sorted // By default the database of categories are alphanumeric sorted
foreach ($categories->db as $key=>$fields) { foreach ($categories->db as $key => $fields) {
$count = count($fields['list']); $count = count($fields['list']);
if (!$this->getValue('hideCero') || $count>0) { if (!$this->getValue('hideCero') || $count > 0) {
$html .= '<li>'; $html .= '<li>';
$html .= '<a href="'.DOMAIN_CATEGORIES.$key.'">'; $html .= '<a href="' . DOMAIN_CATEGORIES . $key . '">';
$html .= $fields['name']; $html .= $fields['name'];
$html .= ' ('.count($fields['list']).')'; $html .= ' (' . count($fields['list']) . ')';
$html .= '</a>'; $html .= '</a>';
$html .= '</li>'; $html .= '</li>';
} }
} }
$html .= '</ul>'; $html .= '</ul>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,14 +1,15 @@
<?php <?php
class pluginDisqus extends Plugin { class pluginDisqus extends Plugin
{
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'shortname'=>'', 'shortname' => '',
'enablePages'=>true, 'enablePages' => true,
'enableStatic'=>true, 'enableStatic' => true,
'enableSticky'=>true 'enableSticky' => true
); );
} }
@ -21,34 +22,34 @@ class pluginDisqus extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('disqus-shortname').'</label>'; $html .= '<label>' . $L->get('disqus-shortname') . '</label>';
$html .= '<input name="shortname" id="jsshortname" type="text" value="'.$this->getValue('shortname').'">'; $html .= '<input name="shortname" id="jsshortname" type="text" dir="auto" value="' . $this->getValue('shortname') . '">';
$html .= '<span class="tip">'.$L->get('Get the shortname from the Disqus general settings').'</span>'; $html .= '<span class="tip">' . $L->get('Get the shortname from the Disqus general settings') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('enable-disqus-on-pages').'</label>'; $html .= '<label>' . $L->get('enable-disqus-on-pages') . '</label>';
$html .= '<select name="enablePages">'; $html .= '<select name="enablePages">';
$html .= '<option value="true" '.($this->getValue('enablePages')===true?'selected':'').'>'.$L->get('enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('enablePages') === true ? 'selected' : '') . '>' . $L->get('enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('enablePages')===false?'selected':'').'>'.$L->get('disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('enablePages') === false ? 'selected' : '') . '>' . $L->get('disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('enable-disqus-on-static-pages').'</label>'; $html .= '<label>' . $L->get('enable-disqus-on-static-pages') . '</label>';
$html .= '<select name="enableStatic">'; $html .= '<select name="enableStatic">';
$html .= '<option value="true" '.($this->getValue('enableStatic')===true?'selected':'').'>'.$L->get('enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('enableStatic') === true ? 'selected' : '') . '>' . $L->get('enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('enableStatic')===false?'selected':'').'>'.$L->get('disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('enableStatic') === false ? 'selected' : '') . '>' . $L->get('disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('enable-disqus-on-sticky-pages').'</label>'; $html .= '<label>' . $L->get('enable-disqus-on-sticky-pages') . '</label>';
$html .= '<select name="enableSticky">'; $html .= '<select name="enableSticky">';
$html .= '<option value="true" '.($this->getValue('enableSticky')===true?'selected':'').'>'.$L->get('enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('enableSticky') === true ? 'selected' : '') . '>' . $L->get('enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('enableSticky')===false?'selected':'').'>'.$L->get('disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('enableSticky') === false ? 'selected' : '') . '>' . $L->get('disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
@ -63,7 +64,7 @@ class pluginDisqus extends Plugin {
return false; return false;
} }
if ($WHERE_AM_I==='page') { if ($WHERE_AM_I === 'page') {
global $page; global $page;
if ($page->published() && $this->getValue('enablePages')) { if ($page->published() && $this->getValue('enablePages')) {
return $this->javascript(); return $this->javascript();
@ -86,7 +87,7 @@ class pluginDisqus extends Plugin {
$pageID = $page->uuid(); $pageID = $page->uuid();
$shortname = $this->getValue('shortname'); $shortname = $this->getValue('shortname');
$code = <<<EOF $code = <<<EOF
<!-- Disqus plugin --> <!-- Disqus plugin -->
<div id="disqus_thread"></div> <div id="disqus_thread"></div>
<script> <script>
@ -108,5 +109,4 @@ $code = <<<EOF
EOF; EOF;
return $code; return $code;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
class plugineasyMDE extends Plugin { class plugineasyMDE extends Plugin
{
// The plugin is going to be loaded in this views // The plugin is going to be loaded in this views
private $loadOnViews = array( private $loadOnViews = array(
@ -11,9 +12,9 @@ class plugineasyMDE extends Plugin {
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'tabSize'=>'2', 'tabSize' => '2',
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen"', 'toolbar' => '"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen"',
'spellChecker'=>true 'spellChecker' => true
); );
} }
@ -22,20 +23,20 @@ class plugineasyMDE extends Plugin {
global $L; global $L;
$html = '<div>'; $html = '<div>';
$html .= '<label>'.$L->get('toolbar').'</label>'; $html .= '<label>' . $L->get('toolbar') . '</label>';
$html .= '<input name="toolbar" id="jstoolbar" type="text" value="'.$this->getValue('toolbar').'">'; $html .= '<input name="toolbar" id="jstoolbar" type="text" dir="auto" value="' . $this->getValue('toolbar') . '">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('tab-size').'</label>'; $html .= '<label>' . $L->get('tab-size') . '</label>';
$html .= '<input name="tabSize" id="jstabSize" type="text" value="'.$this->getValue('tabSize').'">'; $html .= '<input name="tabSize" id="jstabSize" type="text" dir="auto" value="' . $this->getValue('tabSize') . '">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('spell-checker').'</label>'; $html .= '<label>' . $L->get('spell-checker') . '</label>';
$html .= '<select name="spellChecker">'; $html .= '<select name="spellChecker">';
$html .= '<option value="true" '.($this->getValue('spellChecker')===true?'selected':'').'>'.$L->get('enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('spellChecker') === true ? 'selected' : '') . '>' . $L->get('enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('spellChecker')===false?'selected':'').'>'.$L->get('disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('spellChecker') === false ? 'selected' : '') . '>' . $L->get('disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
@ -64,15 +65,15 @@ class plugineasyMDE extends Plugin {
global $L; global $L;
$langImage = $L->g('Image description'); $langImage = $L->g('Image description');
$spellCheckerEnable = $this->getValue('spellChecker')?'true':'false'; $spellCheckerEnable = $this->getValue('spellChecker') ? 'true' : 'false';
$tabSize = $this->getValue('tabSize'); $tabSize = $this->getValue('tabSize');
$toolbar = Sanitize::htmlDecode($this->getValue('toolbar')); $toolbar = Sanitize::htmlDecode($this->getValue('toolbar'));
$pageBreak = PAGE_BREAK; $pageBreak = PAGE_BREAK;
// Javascript path and file // Javascript path and file
$jsEasyMDE = $this->domainPath().'js/easymde.min.js?version='.BLUDIT_VERSION; $jsEasyMDE = $this->domainPath() . 'js/easymde.min.js?version=' . BLUDIT_VERSION;
return <<<EOF return <<<EOF
<script charset="utf-8" src="$jsEasyMDE"></script> <script charset="utf-8" src="$jsEasyMDE"></script>
<script> <script>
var easymde = null; var easymde = null;
@ -120,4 +121,4 @@ return <<<EOF
</script> </script>
EOF; EOF;
} }
} }

View File

@ -1,12 +1,13 @@
<?php <?php
class pluginHitCounter extends Plugin { class pluginHitCounter extends Plugin
{
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'label'=>'Hit Counter', 'label' => 'Hit Counter',
'showUniqueVisitors'=>false 'showUniqueVisitors' => false
); );
} }
@ -34,17 +35,17 @@ class pluginHitCounter extends Plugin {
// Label of the plugin to show in the sidebar // Label of the plugin to show in the sidebar
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
// Form "select" element for enable or disable Unique visitors properties // Form "select" element for enable or disable Unique visitors properties
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Show unique visitors').'</label>'; $html .= '<label>' . $L->get('Show unique visitors') . '</label>';
$html .= '<select name="showUniqueVisitors">'; $html .= '<select name="showUniqueVisitors">';
$html .= '<option value="true" '.($this->getValue('showUniqueVisitors')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('showUniqueVisitors') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('showUniqueVisitors')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('showUniqueVisitors') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
@ -74,12 +75,12 @@ class pluginHitCounter extends Plugin {
// Show in the sidebar the number of visitors // Show in the sidebar the number of visitors
$html = '<div class="plugin plugin-hit-counter">'; $html = '<div class="plugin plugin-hit-counter">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= '<div class="counter">'.$counter.'</div>'; $html .= '<div class="counter">' . $counter . '</div>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,19 +1,20 @@
<?php <?php
class pluginLinks extends Plugin { class pluginLinks extends Plugin
{
public function init() public function init()
{ {
// JSON database // JSON database
$jsondb = json_encode(array( $jsondb = json_encode(array(
'Bludit'=>'https://www.bludit.com', 'Bludit' => 'https://www.bludit.com',
'Bludit PRO'=>'https://pro.bludit.com' 'Bludit PRO' => 'https://pro.bludit.com'
)); ));
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'Links', 'label' => 'Links',
'jsondb'=>$jsondb 'jsondb' => $jsondb
); );
// Disable default Save and Cancel button // Disable default Save and Cancel button
@ -32,20 +33,21 @@ class pluginLinks extends Plugin {
$links = json_decode($jsondb, true); $links = json_decode($jsondb, true);
// Check if the user click on the button delete or add // Check if the user click on the button delete or add
if( isset($_POST['deleteLink']) ) { if (isset($_POST['deleteLink'])) {
// Values from $_POST // Values from $_POST
$name = $_POST['deleteLink']; $name = $_POST['deleteLink'];
// Delete the link from the array // Delete the link from the array
unset($links[$name]); unset($links[$name]);
} } elseif (isset($_POST['addLink'])) {
elseif( isset($_POST['addLink']) ) {
// Values from $_POST // Values from $_POST
$name = $_POST['linkName']; $name = $_POST['linkName'];
$url = $_POST['linkURL']; $url = $_POST['linkURL'];
// Check empty string // Check empty string
if( empty($name) ) { return false; } if (empty($name)) {
return false;
}
// Add the link // Add the link
$links[$name] = $url; $links[$name] = $url;
@ -69,52 +71,52 @@ class pluginLinks extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" class="form-control" type="text" value="'.$this->getValue('label').'">'; $html .= '<input name="label" class="form-control" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<button name="save" class="btn btn-primary my-2" type="submit">'.$L->get('Save').'</button>'; $html .= '<button name="save" class="btn btn-primary my-2" type="submit">' . $L->get('Save') . '</button>';
$html .= '</div>'; $html .= '</div>';
// New link, when the user click on save button this call the method post() // New link, when the user click on save button this call the method post()
// and the new link is added to the database // and the new link is added to the database
$html .= '<h4 class="mt-3">'.$L->get('Add a new link').'</h4>'; $html .= '<h4 class="mt-3">' . $L->get('Add a new link') . '</h4>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Name').'</label>'; $html .= '<label>' . $L->get('Name') . '</label>';
$html .= '<input name="linkName" type="text" class="form-control" value="" placeholder="Bludit">'; $html .= '<input name="linkName" type="text" dir="auto" class="form-control" value="" placeholder="Bludit">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Url').'</label>'; $html .= '<label>' . $L->get('Url') . '</label>';
$html .= '<input name="linkURL" type="text" class="form-control" value="" placeholder="https://www.bludit.com/">'; $html .= '<input name="linkURL" type="text" dir="auto" class="form-control" value="" placeholder="https://www.bludit.com/">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<button name="addLink" class="btn btn-primary my-2" type="submit">'.$L->get('Add').'</button>'; $html .= '<button name="addLink" class="btn btn-primary my-2" type="submit">' . $L->get('Add') . '</button>';
$html .= '</div>'; $html .= '</div>';
// Get the JSON DB, getValue() with the option unsanitized HTML code // Get the JSON DB, getValue() with the option unsanitized HTML code
$jsondb = $this->getValue('jsondb', $unsanitized=false); $jsondb = $this->getValue('jsondb', $unsanitized = false);
$links = json_decode($jsondb, true); $links = json_decode($jsondb, true);
$html .= !empty($links) ? '<h4 class="mt-3">'.$L->get('Links').'</h4>' : ''; $html .= !empty($links) ? '<h4 class="mt-3">' . $L->get('Links') . '</h4>' : '';
foreach($links as $name=>$url) { foreach ($links as $name => $url) {
$html .= '<div class="my-2">'; $html .= '<div class="my-2">';
$html .= '<label>'.$L->get('Name').'</label>'; $html .= '<label>' . $L->get('Name') . '</label>';
$html .= '<input type="text" class="form-control" value="'.$name.'" disabled>'; $html .= '<input type="text" dir="auto" class="form-control" value="' . $name . '" disabled>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Url').'</label>'; $html .= '<label>' . $L->get('Url') . '</label>';
$html .= '<input type="text" class="form-control" value="'.$url.'" disabled>'; $html .= '<input type="text" dir="auto" class="form-control" value="' . $url . '" disabled>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<button name="deleteLink" class="btn btn-secondary my-2" type="submit" value="'.$name.'">'.$L->get('Delete').'</button>'; $html .= '<button name="deleteLink" class="btn btn-secondary my-2" type="submit" value="' . $name . '">' . $L->get('Delete') . '</button>';
$html .= '</div>'; $html .= '</div>';
} }
@ -129,7 +131,7 @@ class pluginLinks extends Plugin {
// HTML for sidebar // HTML for sidebar
$html = '<div class="plugin plugin-pages">'; $html = '<div class="plugin plugin-pages">';
if ($this->getValue('label')) { if ($this->getValue('label')) {
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
} }
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= '<ul>'; $html .= '<ul>';
@ -139,17 +141,17 @@ class pluginLinks extends Plugin {
$links = json_decode($jsondb); $links = json_decode($jsondb);
// By default the database of categories are alphanumeric sorted // By default the database of categories are alphanumeric sorted
foreach( $links as $name=>$url ) { foreach ($links as $name => $url) {
$html .= '<li>'; $html .= '<li>';
$html .= '<a href="'.$url.'">'; $html .= '<a href="' . $url . '">';
$html .= $name; $html .= $name;
$html .= '</a>'; $html .= '</a>';
$html .= '</li>'; $html .= '</li>';
} }
$html .= '</ul>'; $html .= '</ul>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }

View File

@ -1,12 +1,13 @@
<?php <?php
class pluginMaintenanceMode extends Plugin { class pluginMaintenanceMode extends Plugin
{
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'enable'=>false, 'enable' => false,
'message'=>'Temporarily down for maintenance.' 'message' => 'Temporarily down for maintenance.'
); );
} }
@ -19,16 +20,16 @@ class pluginMaintenanceMode extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Enable maintenance mode').'</label>'; $html .= '<label>' . $L->get('Enable maintenance mode') . '</label>';
$html .= '<select name="enable">'; $html .= '<select name="enable">';
$html .= '<option value="true" '.($this->getValue('enable')===true?'selected':'').'>Enabled</option>'; $html .= '<option value="true" ' . ($this->getValue('enable') === true ? 'selected' : '') . '>Enabled</option>';
$html .= '<option value="false" '.($this->getValue('enable')===false?'selected':'').'>Disabled</option>'; $html .= '<option value="false" ' . ($this->getValue('enable') === false ? 'selected' : '') . '>Disabled</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Message').'</label>'; $html .= '<label>' . $L->get('Message') . '</label>';
$html .= '<input name="message" id="jsmessage" type="text" value="'.$this->getValue('message').'">'; $html .= '<input name="message" id="jsmessage" type="text" dir="auto" value="' . $this->getValue('message') . '">';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -37,7 +38,7 @@ class pluginMaintenanceMode extends Plugin {
public function beforeAll() public function beforeAll()
{ {
if ($this->getValue('enable')) { if ($this->getValue('enable')) {
exit( $this->getValue('message') ); exit($this->getValue('message'));
} }
} }
} }

View File

@ -1,14 +1,15 @@
<?php <?php
class pluginNavigation extends Plugin { class pluginNavigation extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'Navigation', 'label' => 'Navigation',
'homeLink'=>true, 'homeLink' => true,
'numberOfItems'=>5 'numberOfItems' => 5
); );
} }
@ -22,24 +23,24 @@ class pluginNavigation extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Home link').'</label>'; $html .= '<label>' . $L->get('Home link') . '</label>';
$html .= '<select name="homeLink">'; $html .= '<select name="homeLink">';
$html .= '<option value="true" '.($this->getValue('homeLink')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('homeLink') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('homeLink')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('homeLink') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '<span class="tip">'.$L->get('Show the home link on the sidebar').'</span>'; $html .= '<span class="tip">' . $L->get('Show the home link on the sidebar') . '</span>';
$html .= '</div>'; $html .= '</div>';
if (ORDER_BY=='date') { if (ORDER_BY == 'date') {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of items').'</label>'; $html .= '<label>' . $L->get('Amount of items') . '</label>';
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" dir="auto" value="' . $this->getValue('numberOfItems') . '">';
$html .= '</div>'; $html .= '</div>';
} }
@ -60,7 +61,7 @@ class pluginNavigation extends Plugin {
// Print the label if not empty // Print the label if not empty
$label = $this->getValue('label'); $label = $this->getValue('label');
if (!empty($label)) { if (!empty($label)) {
$html .= '<h2 class="plugin-label">'.$label.'</h2>'; $html .= '<h2 class="plugin-label">' . $label . '</h2>';
} }
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
@ -74,7 +75,7 @@ class pluginNavigation extends Plugin {
} }
// Pages order by position // Pages order by position
if (ORDER_BY=='position') { if (ORDER_BY == 'position') {
// Get parents // Get parents
$parents = buildParentPages(); $parents = buildParentPages();
foreach ($parents as $parent) { foreach ($parents as $parent) {
@ -116,9 +117,9 @@ class pluginNavigation extends Plugin {
} }
$html .= '</ul>'; $html .= '</ul>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,13 +1,14 @@
<?php <?php
class pluginOpenGraph extends Plugin { class pluginOpenGraph extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'defaultImage'=>'', 'defaultImage' => '',
'fbAppId'=>'' 'fbAppId' => ''
); );
} }
@ -20,15 +21,15 @@ class pluginOpenGraph extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Default image').'</label>'; $html .= '<label>' . $L->get('Default image') . '</label>';
$html .= '<input id="jsdefaultImage" name="defaultImage" type="text" value="'.$this->getValue('defaultImage').'" placeholder="https://">'; $html .= '<input id="jsdefaultImage" name="defaultImage" type="text" dir="auto" value="' . $this->getValue('defaultImage') . '" placeholder="https://">';
$html .= '<span class="tip">'.$L->g('set-a-default-image-for-content').'</span>'; $html .= '<span class="tip">' . $L->g('set-a-default-image-for-content') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Facebook App ID').'</label>'; $html .= '<label>' . $L->get('Facebook App ID') . '</label>';
$html .= '<input name="fbAppId" type="text" value="'.$this->getValue('fbAppId').'" placeholder="App ID">'; $html .= '<input name="fbAppId" type="text" dir="auto" value="' . $this->getValue('fbAppId') . '" placeholder="App ID">';
$html .= '<span class="tip">'.$L->g('set-your-facebook-app-id').'</span>'; $html .= '<span class="tip">' . $L->g('set-your-facebook-app-id') . '</span>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -43,53 +44,52 @@ class pluginOpenGraph extends Plugin {
global $content; global $content;
$og = array( $og = array(
'locale' =>$site->locale(), 'locale' => $site->locale(),
'type' =>'website', 'type' => 'website',
'title' =>$site->title(), 'title' => $site->title(),
'description' =>$site->description(), 'description' => $site->description(),
'url' =>$site->url(), 'url' => $site->url(),
'image' =>'', 'image' => '',
'siteName' =>$site->title() 'siteName' => $site->title()
); );
switch ($WHERE_AM_I) { switch ($WHERE_AM_I) {
// The user filter by page // The user filter by page
case 'page': case 'page':
$og['type'] = 'article'; $og['type'] = 'article';
$og['title'] = $page->title(); $og['title'] = $page->title();
$og['description'] = $page->description(); $og['description'] = $page->description();
$og['url'] = $page->permalink($absolute=true); $og['url'] = $page->permalink($absolute = true);
$og['image'] = $page->coverImage($absolute=true); $og['image'] = $page->coverImage($absolute = true);
$pageContent = $page->content(); $pageContent = $page->content();
break; break;
// The user is in the homepage // The user is in the homepage
default: default:
$pageContent = ''; $pageContent = '';
if (Text::isNotEmpty($this->getValue('defaultImage'))) { if (Text::isNotEmpty($this->getValue('defaultImage'))) {
$og['image'] = $this->getValue('defaultImage'); $og['image'] = $this->getValue('defaultImage');
} } elseif (isset($content[0])) {
elseif (isset($content[0]) ) { $og['image'] = $content[0]->coverImage($absolute = true);
$og['image'] = $content[0]->coverImage($absolute=true);
$pageContent = $content[0]->content(); $pageContent = $content[0]->content();
} }
break; break;
} }
$html = PHP_EOL.'<!-- Open Graph -->'.PHP_EOL; $html = PHP_EOL . '<!-- Open Graph -->' . PHP_EOL;
$html .= '<meta property="og:locale" content="'.$og['locale'].'">'.PHP_EOL; $html .= '<meta property="og:locale" content="' . $og['locale'] . '">' . PHP_EOL;
$html .= '<meta property="og:type" content="'.$og['type'].'">'.PHP_EOL; $html .= '<meta property="og:type" content="' . $og['type'] . '">' . PHP_EOL;
$html .= '<meta property="og:title" content="'.$og['title'].'">'.PHP_EOL; $html .= '<meta property="og:title" content="' . $og['title'] . '">' . PHP_EOL;
$html .= '<meta property="og:description" content="'.$og['description'].'">'.PHP_EOL; $html .= '<meta property="og:description" content="' . $og['description'] . '">' . PHP_EOL;
$html .= '<meta property="og:url" content="'.$og['url'].'">'.PHP_EOL; $html .= '<meta property="og:url" content="' . $og['url'] . '">' . PHP_EOL;
$html .= '<meta property="og:site_name" content="'.$og['siteName'].'">'.PHP_EOL; $html .= '<meta property="og:site_name" content="' . $og['siteName'] . '">' . PHP_EOL;
// If the page doesn't have a coverImage try to get an image from the HTML content // If the page doesn't have a coverImage try to get an image from the HTML content
if (empty($og['image'])) { if (empty($og['image'])) {
// Get the image from the content // Get the image from the content
$src = DOM::getFirstImage($pageContent); $src = DOM::getFirstImage($pageContent);
if ($src!==false) { if ($src !== false) {
$og['image'] = $src; $og['image'] = $src;
} else { } else {
if (Text::isNotEmpty($this->getValue('defaultImage'))) { if (Text::isNotEmpty($this->getValue('defaultImage'))) {
@ -98,11 +98,10 @@ class pluginOpenGraph extends Plugin {
} }
} }
$html .= '<meta property="og:image" content="'.$og['image'].'">'.PHP_EOL; $html .= '<meta property="og:image" content="' . $og['image'] . '">' . PHP_EOL;
if (Text::isNotEmpty($this->getValue('fbAppId'))) { if (Text::isNotEmpty($this->getValue('fbAppId'))) {
$html .= '<meta property="fb:app_id" content="'. $this->getValue('fbAppId').'">'.PHP_EOL; $html .= '<meta property="fb:app_id" content="' . $this->getValue('fbAppId') . '">' . PHP_EOL;
} }
return $html; return $html;
} }
}
}

View File

@ -1,6 +1,7 @@
<?php <?php
class pluginRemoteContent extends Plugin { class pluginRemoteContent extends Plugin
{
public function init() public function init()
{ {
@ -9,8 +10,8 @@ class pluginRemoteContent extends Plugin {
// Key and value for the database of the plugin // Key and value for the database of the plugin
$this->dbFields = array( $this->dbFields = array(
'webhook'=>$randomWebhook, 'webhook' => $randomWebhook,
'source'=>'' 'source' => ''
); );
} }
@ -18,9 +19,9 @@ class pluginRemoteContent extends Plugin {
{ {
global $language; global $language;
if (extension_loaded('zip')===false) { if (extension_loaded('zip') === false) {
$this->formButtons = false; $this->formButtons = false;
return '<div class="alert alert-success">'.$language->get('the-extension-zip-is-not-installed').'</div>'; return '<div class="alert alert-success">' . $language->get('the-extension-zip-is-not-installed') . '</div>';
} }
$html = '<div class="alert alert-primary" role="alert">'; $html = '<div class="alert alert-primary" role="alert">';
@ -28,21 +29,21 @@ class pluginRemoteContent extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$language->get('Webhook').'</label>'; $html .= '<label>' . $language->get('Webhook') . '</label>';
$html .= '<input id="jswebhook" name="webhook" type="text" value="'.$this->getValue('webhook').'">'; $html .= '<input id="jswebhook" name="webhook" type="text" dir="auto" value="' . $this->getValue('webhook') . '">';
$html .= '<span class="tip">'.DOMAIN_BASE.$this->getValue('webhook').'</span>'; $html .= '<span class="tip">' . DOMAIN_BASE . $this->getValue('webhook') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$language->get('Source').'</label>'; $html .= '<label>' . $language->get('Source') . '</label>';
$html .= '<input id="jssource" name="source" type="text" value="'.$this->getValue('source').'" placeholder="https://">'; $html .= '<input id="jssource" name="source" type="text" dir="auto" value="' . $this->getValue('source') . '" placeholder="https://">';
$html .= '<span class="tip">'.$language->get('Complete URL of the zip file').'</span>'; $html .= '<span class="tip">' . $language->get('Complete URL of the zip file') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<hr>'; $html .= '<hr>';
$html .= '<div>'; $html .= '<div>';
$html .= '<button type="button" id="jstryWebhook" class="btn btn-primary" onclick="tryWebhook()">'.$language->get('Try webhook').'</button>'; $html .= '<button type="button" id="jstryWebhook" class="btn btn-primary" onclick="tryWebhook()">' . $language->get('Try webhook') . '</button>';
$html .= <<<EOF $html .= <<<EOF
<script> <script>
function tryWebhook() { function tryWebhook() {
var webhook = document.getElementById("jswebhook").value; var webhook = document.getElementById("jswebhook").value;
@ -72,23 +73,23 @@ EOF;
$this->generateContent(); $this->generateContent();
// End request // End request
$this->response(array('status'=>'0')); $this->response(array('status' => '0'));
} }
} }
private function downloadFiles() private function downloadFiles()
{ {
// Download the zip file // Download the zip file
Log::set('Plugin Remote Content'.LOG_SEP.'Downloading the zip file.'); Log::set('Plugin Remote Content' . LOG_SEP . 'Downloading the zip file.');
$source = $this->getValue('source'); $source = $this->getValue('source');
$destinationPath = $this->workspace(); $destinationPath = $this->workspace();
$destinationFile = $destinationPath.'content.zip'; $destinationFile = $destinationPath . 'content.zip';
TCP::download($source, $destinationFile); TCP::download($source, $destinationFile);
// Uncompress the zip file // Uncompress the zip file
Log::set('Plugin Remote Content'.LOG_SEP.'Uncompress the zip file.'); Log::set('Plugin Remote Content' . LOG_SEP . 'Uncompress the zip file.');
$zip = new ZipArchive; $zip = new ZipArchive;
if ($zip->open($destinationFile)===true) { if ($zip->open($destinationFile) === true) {
$zip->extractTo($destinationPath); $zip->extractTo($destinationPath);
$zip->close(); $zip->close();
} }
@ -118,7 +119,7 @@ EOF;
private function cleanUp() private function cleanUp()
{ {
$workspace = $this->workspace(); $workspace = $this->workspace();
Filesystem::deleteRecursive($workspace.DS); Filesystem::deleteRecursive($workspace . DS);
mkdir($workspace, DIR_PERMISSIONS, true); mkdir($workspace, DIR_PERMISSIONS, true);
return true; return true;
} }
@ -132,21 +133,21 @@ EOF;
// For each page inside the pages directory // For each page inside the pages directory
// Parse the page and add to the database // Parse the page and add to the database
if (Filesystem::directoryExists($root.DS.'pages')) { if (Filesystem::directoryExists($root . DS . 'pages')) {
$parentList = Filesystem::listDirectories($root.DS.'pages'.DS); $parentList = Filesystem::listDirectories($root . DS . 'pages' . DS);
foreach ($parentList as $parentDirectory) { foreach ($parentList as $parentDirectory) {
$parentKey = basename($parentDirectory); $parentKey = basename($parentDirectory);
if (Filesystem::fileExists($parentDirectory.DS.'index.md')) { if (Filesystem::fileExists($parentDirectory . DS . 'index.md')) {
$row = $this->parsePage($parentDirectory.DS.'index.md'); $row = $this->parsePage($parentDirectory . DS . 'index.md');
$row['slug'] = $parentKey; $row['slug'] = $parentKey;
$pages->add($row); $pages->add($row);
} }
$childList = Filesystem::listDirectories($parentDirectory.DS); $childList = Filesystem::listDirectories($parentDirectory . DS);
foreach ($childList as $childDirectory) { foreach ($childList as $childDirectory) {
$childKey = basename($childDirectory); $childKey = basename($childDirectory);
if (Filesystem::fileExists($childDirectory.DS.'index.md')) { if (Filesystem::fileExists($childDirectory . DS . 'index.md')) {
$row = $this->parsePage($childDirectory.DS.'index.md'); $row = $this->parsePage($childDirectory . DS . 'index.md');
$row['slug'] = $childKey; $row['slug'] = $childKey;
$row['parent'] = $parentKey; $row['parent'] = $parentKey;
$pages->add($row); $pages->add($row);
@ -162,7 +163,7 @@ EOF;
return true; return true;
} }
private function response($data=array()) private function response($data = array())
{ {
$json = json_encode($data); $json = json_encode($data);
header('Content-Type: application/json'); header('Content-Type: application/json');
@ -180,7 +181,7 @@ EOF;
unset($lines[0]); unset($lines[0]);
$row['title'] = $title; $row['title'] = $title;
foreach ($lines as $key=>$line) { foreach ($lines as $key => $line) {
if (Text::startsWith($line, '<!--')) { if (Text::startsWith($line, '<!--')) {
$line = preg_replace('/<!\-\-/', '', $line); $line = preg_replace('/<!\-\-/', '', $line);
$line = preg_replace('/\-\->/', '', $line); $line = preg_replace('/\-\->/', '', $line);
@ -205,5 +206,4 @@ EOF;
return $row; return $row;
} }
}
}

View File

@ -1,12 +1,13 @@
<?php <?php
class pluginRSS extends Plugin { class pluginRSS extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'numberOfItems'=>5 'numberOfItems' => 5
); );
} }
@ -20,23 +21,25 @@ class pluginRSS extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('RSS URL').'</label>'; $html .= '<label>' . $L->get('RSS URL') . '</label>';
$html .= '<a href="'.Theme::rssUrl().'">'.Theme::rssUrl().'</a>'; $html .= '<a href="' . Theme::rssUrl() . '">' . Theme::rssUrl() . '</a>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Amount of items').'</label>'; $html .= '<label>' . $L->get('Amount of items') . '</label>';
$html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" value="'.$this->getValue('numberOfItems').'">'; $html .= '<input id="jsnumberOfItems" name="numberOfItems" type="text" dir="auto" value="' . $this->getValue('numberOfItems') . '">';
$html .= '<span class="tip">'.$L->get('Amount of items to show on the feed').'</span>'; $html .= '<span class="tip">' . $L->get('Amount of items to show on the feed') . '</span>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
private function encodeURL($url) private function encodeURL($url)
{ {
return preg_replace_callback('/[^\x20-\x7f]/', function($match) { return urlencode($match[0]); }, $url); return preg_replace_callback('/[^\x20-\x7f]/', function ($match) {
} return urlencode($match[0]);
}, $url);
}
private function createXML() private function createXML()
{ {
@ -49,23 +52,23 @@ class pluginRSS extends Plugin {
// Get the list of public pages (sticky and static included) // Get the list of public pages (sticky and static included)
$list = $pages->getList( $list = $pages->getList(
$pageNumber=1, $pageNumber = 1,
$numberOfItems, $numberOfItems,
$published=true, $published = true,
$static=true, $static = true,
$sticky=true, $sticky = true,
$draft=false, $draft = false,
$scheduled=false $scheduled = false
); );
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'; $xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'; $xml .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
$xml .= '<channel>'; $xml .= '<channel>';
$xml .= '<atom:link href="'.DOMAIN_BASE.'rss.xml" rel="self" type="application/rss+xml" />'; $xml .= '<atom:link href="' . DOMAIN_BASE . 'rss.xml" rel="self" type="application/rss+xml" />';
$xml .= '<title>'.$site->title().'</title>'; $xml .= '<title>' . $site->title() . '</title>';
$xml .= '<link>'.$this->encodeURL($site->url()).'</link>'; $xml .= '<link>' . $this->encodeURL($site->url()) . '</link>';
$xml .= '<description>'.$site->description().'</description>'; $xml .= '<description>' . $site->description() . '</description>';
$xml .= '<lastBuildDate>'.date(DATE_RSS).'</lastBuildDate>'; $xml .= '<lastBuildDate>' . date(DATE_RSS) . '</lastBuildDate>';
// Get keys of pages // Get keys of pages
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
@ -73,12 +76,12 @@ class pluginRSS extends Plugin {
// Create the page object from the page key // Create the page object from the page key
$page = new Page($pageKey); $page = new Page($pageKey);
$xml .= '<item>'; $xml .= '<item>';
$xml .= '<title>'.$page->title().'</title>'; $xml .= '<title>' . $page->title() . '</title>';
$xml .= '<link>'.$this->encodeURL($page->permalink()).'</link>'; $xml .= '<link>' . $this->encodeURL($page->permalink()) . '</link>';
$xml .= '<image>'.$page->coverImage(true).'</image>'; $xml .= '<image>' . $page->coverImage(true) . '</image>';
$xml .= '<description>'.Sanitize::html($page->contentBreak()).'</description>'; $xml .= '<description>' . Sanitize::html($page->contentBreak()) . '</description>';
$xml .= '<pubDate>'.date(DATE_RSS,strtotime($page->getValue('dateRaw'))).'</pubDate>'; $xml .= '<pubDate>' . date(DATE_RSS, strtotime($page->getValue('dateRaw'))) . '</pubDate>';
$xml .= '<guid isPermaLink="false">'.$page->uuid().'</guid>'; $xml .= '<guid isPermaLink="false">' . $page->uuid() . '</guid>';
$xml .= '</item>'; $xml .= '</item>';
} catch (Exception $e) { } catch (Exception $e) {
// Continue // Continue
@ -91,10 +94,10 @@ class pluginRSS extends Plugin {
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->formatOutput = true; $doc->formatOutput = true;
$doc->loadXML($xml); $doc->loadXML($xml);
return $doc->save($this->workspace().'rss.xml'); return $doc->save($this->workspace() . 'rss.xml');
} }
public function install($position=0) public function install($position = 0)
{ {
parent::install($position); parent::install($position);
return $this->createXML(); return $this->createXML();
@ -123,7 +126,7 @@ class pluginRSS extends Plugin {
public function siteHead() public function siteHead()
{ {
return '<link rel="alternate" type="application/rss+xml" href="'.DOMAIN_BASE.'rss.xml" title="RSS Feed">'.PHP_EOL; return '<link rel="alternate" type="application/rss+xml" href="' . DOMAIN_BASE . 'rss.xml" title="RSS Feed">' . PHP_EOL;
} }
public function beforeAll() public function beforeAll()
@ -136,7 +139,7 @@ class pluginRSS extends Plugin {
// Load XML // Load XML
libxml_disable_entity_loader(false); libxml_disable_entity_loader(false);
$doc->load($this->workspace().'rss.xml'); $doc->load($this->workspace() . 'rss.xml');
libxml_disable_entity_loader(true); libxml_disable_entity_loader(true);
// Print the XML // Print the XML

View File

@ -1,6 +1,7 @@
<?php <?php
class pluginSearch extends Plugin { class pluginSearch extends Plugin
{
private $pagesFound = array(); private $pagesFound = array();
private $numberOfItems = 0; private $numberOfItems = 0;
@ -9,10 +10,10 @@ class pluginSearch extends Plugin {
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'Search', 'label' => 'Search',
'minChars'=>3, 'minChars' => 3,
'wordsToCachePerPage'=>800, 'wordsToCachePerPage' => 800,
'showButtonSearch'=>false 'showButtonSearch' => false
); );
} }
@ -25,23 +26,23 @@ class pluginSearch extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Minimum number of characters when searching').'</label>'; $html .= '<label>' . $L->get('Minimum number of characters when searching') . '</label>';
$html .= '<input name="minChars" type="text" value="'.$this->getValue('minChars').'">'; $html .= '<input name="minChars" type="text" dir="auto" value="' . $this->getValue('minChars') . '">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Show button search').'</label>'; $html .= '<label>' . $L->get('Show button search') . '</label>';
$html .= '<select name="showButtonSearch">'; $html .= '<select name="showButtonSearch">';
$html .= '<option value="true" '.($this->getValue('showButtonSearch')===true?'selected':'').'>'.$L->get('enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('showButtonSearch') === true ? 'selected' : '') . '>' . $L->get('enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('showButtonSearch')===false?'selected':'').'>'.$L->get('disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('showButtonSearch') === false ? 'selected' : '') . '>' . $L->get('disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
return $html; return $html;
@ -53,17 +54,17 @@ class pluginSearch extends Plugin {
global $L; global $L;
$html = '<div class="plugin plugin-search">'; $html = '<div class="plugin plugin-search">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= '<input type="text" id="jspluginSearchText" /> '; $html .= '<input type="text" dir="auto" id="jspluginSearchText" /> ';
if ($this->getValue('showButtonSearch')) { if ($this->getValue('showButtonSearch')) {
$html .= '<input type="button" value="'.$L->get('Search').'" onClick="pluginSearch()" />'; $html .= '<input type="button" value="' . $L->get('Search') . '" onClick="pluginSearch()" />';
} }
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
$DOMAIN_BASE = DOMAIN_BASE; $DOMAIN_BASE = DOMAIN_BASE;
$html .= <<<EOF $html .= <<<EOF
<script> <script>
function pluginSearch() { function pluginSearch() {
var text = document.getElementById("jspluginSearchText").value; var text = document.getElementById("jspluginSearchText").value;
@ -85,7 +86,7 @@ EOF;
return $html; return $html;
} }
public function install($position=0) public function install($position = 0)
{ {
parent::install($position); parent::install($position);
return $this->createCache(); return $this->createCache();
@ -137,8 +138,8 @@ EOF;
// The first page number is 1, so the real is 0 // The first page number is 1, so the real is 0
$realPageNumber = $url->pageNumber() - 1; $realPageNumber = $url->pageNumber() - 1;
$itemsPerPage = $site->itemsPerPage(); $itemsPerPage = $site->itemsPerPage();
if($itemsPerPage <= 0) { if ($itemsPerPage <= 0) {
if($realPageNumber === 0) { if ($realPageNumber === 0) {
$this->pagesFound = $list; $this->pagesFound = $list;
} }
} else { } else {
@ -190,7 +191,7 @@ EOF;
{ {
// Get all pages published // Get all pages published
global $pages; global $pages;
$list = $pages->getList($pageNumber=1, $numberOfItems=-1, $published=true, $static=true, $sticky=true, $draft=false, $scheduled=false); $list = $pages->getList($pageNumber = 1, $numberOfItems = -1, $published = true, $static = true, $sticky = true, $draft = false, $scheduled = false);
$cache = array(); $cache = array();
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
@ -216,7 +217,7 @@ EOF;
// Returns the absolute path of the cache file // Returns the absolute path of the cache file
private function cacheFile() private function cacheFile()
{ {
return $this->workspace().'cache.json'; return $this->workspace() . 'cache.json';
} }
// Search text inside the cache // Search text inside the cache
@ -229,11 +230,10 @@ EOF;
$cache = json_decode($json, true); $cache = json_decode($json, true);
// Inlcude Fuzz algorithm // Inlcude Fuzz algorithm
require_once($this->phpPath().'vendors/fuzz.php'); require_once($this->phpPath() . 'vendors/fuzz.php');
$fuzz = new Fuzz($cache, 10, 1, true); $fuzz = new Fuzz($cache, 10, 1, true);
$results = $fuzz->search($text, $this->getValue('minChars')); $results = $fuzz->search($text, $this->getValue('minChars'));
return(array_keys($results)); return (array_keys($results));
} }
} }

View File

@ -2,7 +2,8 @@
/* /*
This plugin uses the javascript library https://github.com/gionkunz/chartist-js This plugin uses the javascript library https://github.com/gionkunz/chartist-js
*/ */
class pluginSimpleStats extends Plugin { class pluginSimpleStats extends Plugin
{
private $loadOnController = array( private $loadOnController = array(
'dashboard' 'dashboard'
@ -14,10 +15,10 @@ class pluginSimpleStats extends Plugin {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>$L->g('Visits'), 'label' => $L->g('Visits'),
'numberOfDays'=>7, 'numberOfDays' => 7,
'excludeAdmins'=>false, 'excludeAdmins' => false,
'showContentStats'=>false 'showContentStats' => false
); );
} }
@ -30,25 +31,25 @@ class pluginSimpleStats extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Show Content Stats').'</label>'; $html .= '<label>' . $L->get('Show Content Stats') . '</label>';
$html .= '<select name="showContentStats">'; $html .= '<select name="showContentStats">';
$html .= '<option value="true" '.($this->getValue('showContentStats')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('showContentStats') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('showContentStats')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('showContentStats') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
if (defined('BLUDIT_PRO')) { if (defined('BLUDIT_PRO')) {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Exclude administrators users').'</label>'; $html .= '<label>' . $L->get('Exclude administrators users') . '</label>';
$html .= '<select name="excludeAdmins">'; $html .= '<select name="excludeAdmins">';
$html .= '<option value="true" '.($this->getValue('excludeAdmins')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('excludeAdmins') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('excludeAdmins')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('excludeAdmins') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '</div>'; $html .= '</div>';
} }
@ -80,7 +81,7 @@ class pluginSimpleStats extends Plugin {
$visitsToday = $this->visits($currentDate); $visitsToday = $this->visits($currentDate);
$uniqueVisitors = $this->uniqueVisitors($currentDate); $uniqueVisitors = $this->uniqueVisitors($currentDate);
$html = <<<EOF $html = <<<EOF
<div class="simple-stats-plugin"> <div class="simple-stats-plugin">
<div class="my-4 pt-4 border-top"> <div class="my-4 pt-4 border-top">
<div class="ct-chart ct-perfect-fourth"></div> <div class="ct-chart ct-perfect-fourth"></div>
@ -92,8 +93,8 @@ EOF;
$numberOfDays = $this->getValue('numberOfDays'); $numberOfDays = $this->getValue('numberOfDays');
$numberOfDays = $numberOfDays - 1; $numberOfDays = $numberOfDays - 1;
for ($i=$numberOfDays; $i >= 0 ; $i--) { for ($i = $numberOfDays; $i >= 0; $i--) {
$dateWithOffset = Date::currentOffset('Y-m-d', '-'.$i.' day'); $dateWithOffset = Date::currentOffset('Y-m-d', '-' . $i . ' day');
$visits[$i] = $this->visits($dateWithOffset); $visits[$i] = $this->visits($dateWithOffset);
$unique[$i] = $this->uniqueVisitors($dateWithOffset); $unique[$i] = $this->uniqueVisitors($dateWithOffset);
$days[$i] = Date::format($dateWithOffset, 'Y-m-d', 'D'); $days[$i] = Date::format($dateWithOffset, 'Y-m-d', 'D');
@ -103,7 +104,7 @@ EOF;
$seriesVisits = implode(',', $visits); $seriesVisits = implode(',', $visits);
$seriesUnique = implode(',', $unique); $seriesUnique = implode(',', $unique);
$script = <<<EOF $script = <<<EOF
<script> <script>
var data = { var data = {
labels: [$labels], labels: [$labels],
@ -127,7 +128,7 @@ EOF;
/** /**
* Optional Content Stats Feature * Optional Content Stats Feature
*/ */
if ($this->getValue('showContentStats')) { if ($this->getValue('showContentStats')) {
global $pages, $categories, $tags; global $pages, $categories, $tags;
$data['title'] = $L->get('Statistics'); $data['title'] = $L->get('Statistics');
@ -145,7 +146,7 @@ EOF;
$this->deleteOldLogs(); $this->deleteOldLogs();
return $html.PHP_EOL.$script.PHP_EOL; return $html . PHP_EOL . $script . PHP_EOL;
} }
public function siteBodyEnd() public function siteBodyEnd()
@ -167,9 +168,9 @@ EOF;
// Returns the amount of visits by date // Returns the amount of visits by date
public function visits($date) public function visits($date)
{ {
$file = $this->workspace().$date.'.log'; $file = $this->workspace() . $date . '.log';
$handle = @fopen($file, 'rb'); $handle = @fopen($file, 'rb');
if ($handle===false) { if ($handle === false) {
return 0; return 0;
} }
@ -185,7 +186,7 @@ EOF;
// Returns the amount of unique visitors by date // Returns the amount of unique visitors by date
public function uniqueVisitors($date) public function uniqueVisitors($date)
{ {
$file = $this->workspace().$date.'.log'; $file = $this->workspace() . $date . '.log';
$lines = @file($file); $lines = @file($file);
if (empty($lines)) { if (empty($lines)) {
return 0; return 0;
@ -207,15 +208,15 @@ EOF;
if (Cookie::get('BLUDIT-KEY') && defined('BLUDIT_PRO') && $this->getValue('excludeAdmins')) { if (Cookie::get('BLUDIT-KEY') && defined('BLUDIT_PRO') && $this->getValue('excludeAdmins')) {
return false; return false;
} }
$currentTime = Date::current('Y-m-d H:i:s'); $currentTime = Date::current('Y-m-d H:i:s');
$ip = TCP::getIP(); $ip = TCP::getIP();
$hashIP = md5($ip); $hashIP = md5($ip);
$line = json_encode(array($hashIP, $currentTime)); $line = json_encode(array($hashIP, $currentTime));
$currentDate = Date::current('Y-m-d'); $currentDate = Date::current('Y-m-d');
$logFile = $this->workspace().$currentDate.'.log'; $logFile = $this->workspace() . $currentDate . '.log';
return file_put_contents($logFile, $line.PHP_EOL, FILE_APPEND | LOCK_EX)!==false; return file_put_contents($logFile, $line . PHP_EOL, FILE_APPEND | LOCK_EX) !== false;
} }
public function renderContentStatistics($data) public function renderContentStatistics($data)
@ -230,8 +231,8 @@ EOF;
$html .= ' $html .= '
<nav> <nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist"> <div class="nav nav-tabs" id="nav-tab" role="tablist">
<a class="nav-item nav-link active" id="nav-stats-chart-tab" data-toggle="tab" href="#nav-stats-chart" role="tab" aria-controls="nav-stats-chart" aria-selected="true">' . $data['tabTitleChart'] .'</a> <a class="nav-item nav-link active" id="nav-stats-chart-tab" data-toggle="tab" href="#nav-stats-chart" role="tab" aria-controls="nav-stats-chart" aria-selected="true">' . $data['tabTitleChart'] . '</a>
<a class="nav-item nav-link" id="nav-stats-table-tab" data-toggle="tab" href="#nav-stats-table" role="tab" aria-controls="nav-stats-table" aria-selected="false">' . $data['tabTitleTable'] .'</a> <a class="nav-item nav-link" id="nav-stats-table-tab" data-toggle="tab" href="#nav-stats-table" role="tab" aria-controls="nav-stats-table" aria-selected="false">' . $data['tabTitleTable'] . '</a>
</div> </div>
</nav> </nav>
<div class="tab-content my-2" id="nav-tabContent"> <div class="tab-content my-2" id="nav-tabContent">
@ -271,5 +272,4 @@ EOF;
return $html; return $html;
} }
} }

View File

@ -1,13 +1,14 @@
<?php <?php
class pluginStaticPages extends Plugin { class pluginStaticPages extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'label'=>'Static Pages', 'label' => 'Static Pages',
'homeLink'=>true 'homeLink' => true
); );
} }
@ -21,18 +22,18 @@ class pluginStaticPages extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Home link').'</label>'; $html .= '<label>' . $L->get('Home link') . '</label>';
$html .= '<select name="homeLink">'; $html .= '<select name="homeLink">';
$html .= '<option value="true" '.($this->getValue('homeLink')===true?'selected':'').'>'.$L->get('Enabled').'</option>'; $html .= '<option value="true" ' . ($this->getValue('homeLink') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" '.($this->getValue('homeLink')===false?'selected':'').'>'.$L->get('Disabled').'</option>'; $html .= '<option value="false" ' . ($this->getValue('homeLink') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>'; $html .= '</select>';
$html .= '<span class="tip">'.$L->get('show-the-home-link-on-the-sidebar').'</span>'; $html .= '<span class="tip">' . $L->get('show-the-home-link-on-the-sidebar') . '</span>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -52,7 +53,7 @@ class pluginStaticPages extends Plugin {
// Print the label if not empty // Print the label if not empty
$label = $this->getValue('label'); $label = $this->getValue('label');
if (!empty($label)) { if (!empty($label)) {
$html .= '<h2 class="plugin-label">'.$label.'</h2>'; $html .= '<h2 class="plugin-label">' . $label . '</h2>';
} }
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
@ -78,9 +79,9 @@ class pluginStaticPages extends Plugin {
} }
$html .= '</ul>'; $html .= '</ul>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,11 +1,12 @@
<?php <?php
class pluginTags extends Plugin { class pluginTags extends Plugin
{
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'label'=>'Tags' 'label' => 'Tags'
); );
} }
@ -18,9 +19,9 @@ class pluginTags extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>'; $html .= '<label>' . $L->get('Label') . '</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">'; $html .= '<input id="jslabel" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>'; $html .= '<span class="tip">' . $L->get('This title is almost always used in the sidebar of the site') . '</span>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -35,23 +36,23 @@ class pluginTags extends Plugin {
$filter = $url->filters('tag'); $filter = $url->filters('tag');
$html = '<div class="plugin plugin-tags">'; $html = '<div class="plugin plugin-tags">';
$html .= '<h2 class="plugin-label">'.$this->getValue('label').'</h2>'; $html .= '<h2 class="plugin-label">' . $this->getValue('label') . '</h2>';
$html .= '<div class="plugin-content">'; $html .= '<div class="plugin-content">';
$html .= '<ul>'; $html .= '<ul>';
// By default the database of tags are alphanumeric sorted // By default the database of tags are alphanumeric sorted
foreach( $tags->db as $key=>$fields ) { foreach ($tags->db as $key => $fields) {
$html .= '<li>'; $html .= '<li>';
$html .= '<a href="'.DOMAIN_TAGS.$key.'">'; $html .= '<a href="' . DOMAIN_TAGS . $key . '">';
$html .= $fields['name']; $html .= $fields['name'];
$html .= '</a>'; $html .= '</a>';
$html .= '</li>'; $html .= '</li>';
} }
$html .= '</ul>'; $html .= '</ul>';
$html .= '</div>'; $html .= '</div>';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
} }
} }

View File

@ -1,6 +1,7 @@
<?php <?php
class pluginTinymce extends Plugin { class pluginTinymce extends Plugin
{
private $loadOnController = array( private $loadOnController = array(
'new-content', 'new-content',
@ -10,10 +11,10 @@ class pluginTinymce extends Plugin {
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'toolbar1'=>'formatselect bold italic forecolor backcolor removeformat | bullist numlist table | blockquote alignleft aligncenter alignright | link unlink pagebreak image code', 'toolbar1' => 'formatselect bold italic forecolor backcolor removeformat | bullist numlist table | blockquote alignleft aligncenter alignright | link unlink pagebreak image code',
'toolbar2'=>'', 'toolbar2' => '',
'plugins'=>'code autolink image link pagebreak advlist lists textpattern table', 'plugins' => 'code autolink image link pagebreak advlist lists textpattern table',
'codesampleLanguages'=>'HTML/XML markup|JavaScript javascript|CSS css|PHP php|Ruby ruby|Python python|Java java|C c|C# sharp|C++ cpp' 'codesampleLanguages' => 'HTML/XML markup|JavaScript javascript|CSS css|PHP php|Ruby ruby|Python python|Java java|C c|C# sharp|C++ cpp'
); );
} }
@ -26,25 +27,25 @@ class pluginTinymce extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('toolbar-top').'</label>'; $html .= '<label>' . $L->get('toolbar-top') . '</label>';
$html .= '<input name="toolbar1" id="jstoolbar1" type="text" value="'.$this->getValue('toolbar1').'">'; $html .= '<input name="toolbar1" id="jstoolbar1" type="text" dir="auto" value="' . $this->getValue('toolbar1') . '">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('toolbar-bottom').'</label>'; $html .= '<label>' . $L->get('toolbar-bottom') . '</label>';
$html .= '<input name="toolbar2" id="jstoolbar2" type="text" value="'.$this->getValue('toolbar2').'">'; $html .= '<input name="toolbar2" id="jstoolbar2" type="text" dir="auto" value="' . $this->getValue('toolbar2') . '">';
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Plugins').'</label>'; $html .= '<label>' . $L->get('Plugins') . '</label>';
$html .= '<input name="plugins" id="jsplugins" type="text" value="'.$this->getValue('plugins').'">'; $html .= '<input name="plugins" id="jsplugins" type="text" dir="auto" value="' . $this->getValue('plugins') . '">';
$html .= '</div>'; $html .= '</div>';
if (strpos($this->getValue('plugins'), 'codesample') !== false) { if (strpos($this->getValue('plugins'), 'codesample') !== false) {
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('codesample-languages').'</label>'; $html .= '<label>' . $L->get('codesample-languages') . '</label>';
$html .= '<input name="codesampleLanguages" id="jsCodesampleLanguages" type="text" value="'.$this->getValue('codesampleLanguages').'">'; $html .= '<input name="codesampleLanguages" id="jsCodesampleLanguages" type="text" dir="auto" value="' . $this->getValue('codesampleLanguages') . '">';
$html .= '<span class="tip">'.$L->get('codesample-supported-laguages').'</span>'; $html .= '<span class="tip">' . $L->get('codesample-supported-laguages') . '</span>';
$html .= '</div>'; $html .= '</div>';
} }
@ -57,8 +58,8 @@ class pluginTinymce extends Plugin {
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) { if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
return false; return false;
} }
$html = '<link rel="stylesheet" type="text/css" href="'.$this->htmlPath().'css/tinymce_toolbar.css">'.PHP_EOL; $html = '<link rel="stylesheet" type="text/css" href="' . $this->htmlPath() . 'css/tinymce_toolbar.css">' . PHP_EOL;
$html .= '<script src="'.$this->htmlPath().'tinymce/tinymce.min.js?version='.$this->version().'"></script>'; $html .= '<script src="' . $this->htmlPath() . 'tinymce/tinymce.min.js?version=' . $this->version() . '"></script>';
return $html; return $html;
} }
@ -73,32 +74,33 @@ class pluginTinymce extends Plugin {
$toolbar1 = $this->getValue('toolbar1'); $toolbar1 = $this->getValue('toolbar1');
$toolbar2 = $this->getValue('toolbar2'); $toolbar2 = $this->getValue('toolbar2');
$content_css = $this->htmlPath().'css/tinymce_content.css'; $content_css = $this->htmlPath() . 'css/tinymce_content.css';
$plugins = $this->getValue('plugins'); $plugins = $this->getValue('plugins');
$version = $this->version(); $version = $this->version();
if (strpos($this->getValue('plugins'), 'codesample') !== false) { if (strpos($this->getValue('plugins'), 'codesample') !== false) {
$codesampleConfig = '';
$codesampleLanguages = explode("|", $this->getValue('codesampleLanguages')); $codesampleLanguages = explode("|", $this->getValue('codesampleLanguages'));
foreach($codesampleLanguages AS $codesampleLang) { foreach ($codesampleLanguages as $codesampleLang) {
$values = explode(" ", $codesampleLang); $values = explode(" ", $codesampleLang);
$codesampleConfig .= "{ text: '" . $values[0] . "', value: '" . $values[1] . "' },"; $codesampleConfig .= "{ text: '" . $values[0] . "', value: '" . $values[1] . "' },";
} }
} }
$lang = 'en'; $lang = 'en';
if (file_exists($this->phpPath().'tinymce'.DS.'langs'.DS.$L->currentLanguage().'.js')) { if (file_exists($this->phpPath() . 'tinymce' . DS . 'langs' . DS . $L->currentLanguage() . '.js')) {
$lang = $L->currentLanguage(); $lang = $L->currentLanguage();
} elseif (file_exists($this->phpPath().'tinymce'.DS.'langs'.DS.$L->currentLanguageShortVersion().'.js')) { } elseif (file_exists($this->phpPath() . 'tinymce' . DS . 'langs' . DS . $L->currentLanguageShortVersion() . '.js')) {
$lang = $L->currentLanguageShortVersion(); $lang = $L->currentLanguageShortVersion();
} }
if (IMAGE_RELATIVE_TO_ABSOLUTE) { if (IMAGE_RELATIVE_TO_ABSOLUTE) {
$document_base_url = 'document_base_url: "'.DOMAIN_UPLOADS.'",'; $document_base_url = 'document_base_url: "' . DOMAIN_UPLOADS . '",';
} else { } else {
$document_base_url = ''; $document_base_url = '';
} }
$html = <<<EOF $html = <<<EOF
<script> <script>
// Insert an image in the editor at the cursor position // Insert an image in the editor at the cursor position
@ -150,5 +152,4 @@ $html = <<<EOF
EOF; EOF;
return $html; return $html;
} }
} }

View File

@ -1,12 +1,13 @@
<?php <?php
class pluginTwitterCards extends Plugin { class pluginTwitterCards extends Plugin
{
public function init() public function init()
{ {
// Fields and default values for the database of this plugin // Fields and default values for the database of this plugin
$this->dbFields = array( $this->dbFields = array(
'defaultImage'=>'' 'defaultImage' => ''
); );
} }
@ -19,8 +20,8 @@ class pluginTwitterCards extends Plugin {
$html .= '</div>'; $html .= '</div>';
$html .= '<div>'; $html .= '<div>';
$html .= '<label>'.$L->get('Default image').'</label>'; $html .= '<label>' . $L->get('Default image') . '</label>';
$html .= '<input id="jsdefaultImage" name="defaultImage" type="text" value="'.$this->getValue('defaultImage').'" placeholder="https://">'; $html .= '<input id="jsdefaultImage" name="defaultImage" type="text" dir="auto" value="' . $this->getValue('defaultImage') . '" placeholder="https://">';
$html .= '</div>'; $html .= '</div>';
return $html; return $html;
@ -35,45 +36,45 @@ class pluginTwitterCards extends Plugin {
global $page; global $page;
$data = array( $data = array(
'card' =>'summary', 'card' => 'summary',
'site' =>'', 'site' => '',
'title' =>$site->title(), 'title' => $site->title(),
'description' =>$site->description(), 'description' => $site->description(),
'image' =>'' 'image' => ''
); );
switch($WHERE_AM_I) { switch ($WHERE_AM_I) {
// The user filter by page // The user filter by page
case 'page': case 'page':
$data['title'] = $page->title(); $data['title'] = $page->title();
$data['description'] = $page->description(); $data['description'] = $page->description();
$data['image'] = $page->coverImage($absolute=true); $data['image'] = $page->coverImage($absolute = true);
$pageContent = $page->content(); $pageContent = $page->content();
break; break;
// The user is in the homepage // The user is in the homepage
default: default:
$pageContent = ''; $pageContent = '';
// The image it's from the first page // The image it's from the first page
if(isset($content[0]) ) { if (isset($content[0])) {
$data['image'] = $content[0]->coverImage($absolute=true); $data['image'] = $content[0]->coverImage($absolute = true);
$pageContent = $content[0]->content(); $pageContent = $content[0]->content();
} }
break; break;
} }
$html = PHP_EOL.'<!-- Twitter Cards -->'.PHP_EOL; $html = PHP_EOL . '<!-- Twitter Cards -->' . PHP_EOL;
$html .= '<meta property="twitter:card" content="'.$data['card'].'">'.PHP_EOL; $html .= '<meta property="twitter:card" content="' . $data['card'] . '">' . PHP_EOL;
$html .= '<meta property="twitter:site" content="'.$data['site'].'">'.PHP_EOL; $html .= '<meta property="twitter:site" content="' . $data['site'] . '">' . PHP_EOL;
$html .= '<meta property="twitter:title" content="'.$data['title'].'">'.PHP_EOL; $html .= '<meta property="twitter:title" content="' . $data['title'] . '">' . PHP_EOL;
$html .= '<meta property="twitter:description" content="'.$data['description'].'">'.PHP_EOL; $html .= '<meta property="twitter:description" content="' . $data['description'] . '">' . PHP_EOL;
// If the page doesn't have a coverImage try to get an image from the HTML content // If the page doesn't have a coverImage try to get an image from the HTML content
if( empty($data['image']) ) { if (empty($data['image'])) {
// Get the image from the content // Get the image from the content
$src = DOM::getFirstImage($pageContent); $src = DOM::getFirstImage($pageContent);
if ($src!==false) { if ($src !== false) {
$data['image'] = $src; $data['image'] = $src;
} else { } else {
if (Text::isNotEmpty($this->getValue('defaultImage'))) { if (Text::isNotEmpty($this->getValue('defaultImage'))) {
@ -82,7 +83,7 @@ class pluginTwitterCards extends Plugin {
} }
} }
$html .= '<meta property="twitter:image" content="'.$data['image'].'">'.PHP_EOL; $html .= '<meta property="twitter:image" content="' . $data['image'] . '">' . PHP_EOL;
return $html; return $html;
} }
} }

View File

@ -98,7 +98,7 @@ EOF;
$html = '<div class="mb-3">'; $html = '<div class="mb-3">';
$html .= '<label class="form-label" for="label">' . $L->get('Label') . '</label>'; $html .= '<label class="form-label" for="label">' . $L->get('Label') . '</label>';
$html .= '<input class="form-control" id="label" name="label" type="text" value="' . $this->getValue('label') . '">'; $html .= '<input class="form-control" id="label" name="label" type="text" dir="auto" value="' . $this->getValue('label') . '">';
$html .= '<div class="form-text">' . $L->get('This title is almost always used in the sidebar of the site') . '</div>'; $html .= '<div class="form-text">' . $L->get('This title is almost always used in the sidebar of the site') . '</div>';
$html .= '</div>'; $html .= '</div>';

View File

@ -650,7 +650,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
<input type="hidden" name="timezone" id="jstimezone" value="UTC"> <input type="hidden" name="timezone" id="jstimezone" value="UTC">
<div class="form-group"> <div class="form-group">
<input type="text" value="admin" class="form-control form-control-lg" id="jsusername" name="username" placeholder="Username" disabled> <input type="text" dir="auto" value="admin" class="form-control form-control-lg" id="jsusername" name="username" placeholder="Username" disabled>
</div> </div>
<div class="form-group mb-0"> <div class="form-group mb-0">