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 {
font-size: 0.8em;
text-transform: uppercase!important;
}
}

View file

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

View file

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

View file

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

View file

@ -1,8 +1,9 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Login {
class Login
{
protected $users;
protected $site;
function __construct()
{
@ -12,11 +13,11 @@ class Login {
$this->users = new Users();
}
if (isset($GLOBALS['site'])) {
$this->site = $GLOBALS['site'];
} else {
$this->site = new Site();
}
if (isset($GLOBALS['site'])) {
$this->site = $GLOBALS['site'];
} else {
$this->site = new Site();
}
// Start the Session
if (!Session::started()) {
@ -39,18 +40,18 @@ class Login {
// Returns TRUE if the user is logged, FALSE otherwise
public function isLogged()
{
if (Session::get('fingerPrint')===$this->fingerPrint()) {
if (Session::get('fingerPrint') === $this->fingerPrint()) {
$username = Session::get('username');
if (!empty($username)) {
return true;
} 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();
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;
}
@ -62,7 +63,7 @@ class Login {
Session::set('fingerPrint', $this->fingerPrint());
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)
@ -77,7 +78,7 @@ class Login {
Cookie::set(REMEMBER_COOKIE_USERNAME, $username, 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()
@ -101,12 +102,12 @@ class Login {
$username = trim($username);
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;
}
if (Text::length($password)<PASSWORD_LENGTH) {
Log::set(__METHOD__.LOG_SEP.'Password length is shorter than required.');
if (Text::length($password) < PASSWORD_LENGTH) {
Log::set(__METHOD__ . LOG_SEP . 'Password length is shorter than required.');
return false;
}
@ -117,13 +118,13 @@ class Login {
}
$passwordHash = $this->users->generatePasswordHash($password, $user->salt());
if ($passwordHash===$user->password()) {
if ($passwordHash === $user->password()) {
$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;
}
Log::set(__METHOD__.LOG_SEP.'Password incorrect.');
Log::set(__METHOD__ . LOG_SEP . 'Password incorrect.');
return false;
}
@ -145,20 +146,20 @@ class Login {
if (empty($username) || empty($token)) {
$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;
}
if ($username !== $this->users->getByRememberToken($token)) {
$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;
}
// Get user from database and login
$user = $this->users->getUserDB($username);
$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;
}
@ -177,4 +178,4 @@ class Login {
Session::destroy();
return true;
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
<?php
class pluginSearch extends Plugin {
class pluginSearch extends Plugin
{
private $pagesFound = array();
private $numberOfItems = 0;
@ -9,10 +10,10 @@ class pluginSearch extends Plugin {
{
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label'=>'Search',
'minChars'=>3,
'wordsToCachePerPage'=>800,
'showButtonSearch'=>false
'label' => 'Search',
'minChars' => 3,
'wordsToCachePerPage' => 800,
'showButtonSearch' => false
);
}
@ -25,23 +26,23 @@ class pluginSearch extends Plugin {
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>';
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>';
$html .= '<label>' . $L->get('Label') . '</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 .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Minimum number of characters when searching').'</label>';
$html .= '<input name="minChars" type="text" value="'.$this->getValue('minChars').'">';
$html .= '<label>' . $L->get('Minimum number of characters when searching') . '</label>';
$html .= '<input name="minChars" type="text" dir="auto" value="' . $this->getValue('minChars') . '">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Show button search').'</label>';
$html .= '<select name="showButtonSearch">';
$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 .= '<div>';
$html .= '<label>' . $L->get('Show button search') . '</label>';
$html .= '<select name="showButtonSearch">';
$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 .= '</select>';
$html .= '</div>';
$html .= '</div>';
$html .= '<div>';
return $html;
@ -53,17 +54,17 @@ class pluginSearch extends Plugin {
global $L;
$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 .= '<input type="text" id="jspluginSearchText" /> ';
$html .= '<input type="text" dir="auto" id="jspluginSearchText" /> ';
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>';
$DOMAIN_BASE = DOMAIN_BASE;
$html .= <<<EOF
$html .= <<<EOF
<script>
function pluginSearch() {
var text = document.getElementById("jspluginSearchText").value;
@ -85,7 +86,7 @@ EOF;
return $html;
}
public function install($position=0)
public function install($position = 0)
{
parent::install($position);
return $this->createCache();
@ -137,8 +138,8 @@ EOF;
// The first page number is 1, so the real is 0
$realPageNumber = $url->pageNumber() - 1;
$itemsPerPage = $site->itemsPerPage();
if($itemsPerPage <= 0) {
if($realPageNumber === 0) {
if ($itemsPerPage <= 0) {
if ($realPageNumber === 0) {
$this->pagesFound = $list;
}
} else {
@ -190,7 +191,7 @@ EOF;
{
// Get all pages published
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();
foreach ($list as $pageKey) {
@ -216,7 +217,7 @@ EOF;
// Returns the absolute path of the cache file
private function cacheFile()
{
return $this->workspace().'cache.json';
return $this->workspace() . 'cache.json';
}
// Search text inside the cache
@ -229,11 +230,10 @@ EOF;
$cache = json_decode($json, true);
// Inlcude Fuzz algorithm
require_once($this->phpPath().'vendors/fuzz.php');
require_once($this->phpPath() . 'vendors/fuzz.php');
$fuzz = new Fuzz($cache, 10, 1, true);
$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
*/
class pluginSimpleStats extends Plugin {
class pluginSimpleStats extends Plugin
{
private $loadOnController = array(
'dashboard'
@ -14,10 +15,10 @@ class pluginSimpleStats extends Plugin {
// Fields and default values for the database of this plugin
$this->dbFields = array(
'label'=>$L->g('Visits'),
'numberOfDays'=>7,
'excludeAdmins'=>false,
'showContentStats'=>false
'label' => $L->g('Visits'),
'numberOfDays' => 7,
'excludeAdmins' => false,
'showContentStats' => false
);
}
@ -30,25 +31,25 @@ class pluginSimpleStats extends Plugin {
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Label').'</label>';
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
$html .= '<span class="tip">'.$L->get('This title is almost always used in the sidebar of the site').'</span>';
$html .= '<label>' . $L->get('Label') . '</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 .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Show Content Stats').'</label>';
$html .= '<label>' . $L->get('Show Content Stats') . '</label>';
$html .= '<select name="showContentStats">';
$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="true" ' . ($this->getValue('showContentStats') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" ' . ($this->getValue('showContentStats') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>';
$html .= '</div>';
if (defined('BLUDIT_PRO')) {
$html .= '<div>';
$html .= '<label>'.$L->get('Exclude administrators users').'</label>';
$html .= '<label>' . $L->get('Exclude administrators users') . '</label>';
$html .= '<select name="excludeAdmins">';
$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="true" ' . ($this->getValue('excludeAdmins') === true ? 'selected' : '') . '>' . $L->get('Enabled') . '</option>';
$html .= '<option value="false" ' . ($this->getValue('excludeAdmins') === false ? 'selected' : '') . '>' . $L->get('Disabled') . '</option>';
$html .= '</select>';
$html .= '</div>';
}
@ -80,7 +81,7 @@ class pluginSimpleStats extends Plugin {
$visitsToday = $this->visits($currentDate);
$uniqueVisitors = $this->uniqueVisitors($currentDate);
$html = <<<EOF
$html = <<<EOF
<div class="simple-stats-plugin">
<div class="my-4 pt-4 border-top">
<div class="ct-chart ct-perfect-fourth"></div>
@ -92,8 +93,8 @@ EOF;
$numberOfDays = $this->getValue('numberOfDays');
$numberOfDays = $numberOfDays - 1;
for ($i=$numberOfDays; $i >= 0 ; $i--) {
$dateWithOffset = Date::currentOffset('Y-m-d', '-'.$i.' day');
for ($i = $numberOfDays; $i >= 0; $i--) {
$dateWithOffset = Date::currentOffset('Y-m-d', '-' . $i . ' day');
$visits[$i] = $this->visits($dateWithOffset);
$unique[$i] = $this->uniqueVisitors($dateWithOffset);
$days[$i] = Date::format($dateWithOffset, 'Y-m-d', 'D');
@ -103,7 +104,7 @@ EOF;
$seriesVisits = implode(',', $visits);
$seriesUnique = implode(',', $unique);
$script = <<<EOF
$script = <<<EOF
<script>
var data = {
labels: [$labels],
@ -127,7 +128,7 @@ EOF;
/**
* Optional Content Stats Feature
*/
if ($this->getValue('showContentStats')) {
if ($this->getValue('showContentStats')) {
global $pages, $categories, $tags;
$data['title'] = $L->get('Statistics');
@ -145,7 +146,7 @@ EOF;
$this->deleteOldLogs();
return $html.PHP_EOL.$script.PHP_EOL;
return $html . PHP_EOL . $script . PHP_EOL;
}
public function siteBodyEnd()
@ -167,9 +168,9 @@ EOF;
// Returns the amount of visits by date
public function visits($date)
{
$file = $this->workspace().$date.'.log';
$file = $this->workspace() . $date . '.log';
$handle = @fopen($file, 'rb');
if ($handle===false) {
if ($handle === false) {
return 0;
}
@ -185,7 +186,7 @@ EOF;
// Returns the amount of unique visitors by date
public function uniqueVisitors($date)
{
$file = $this->workspace().$date.'.log';
$file = $this->workspace() . $date . '.log';
$lines = @file($file);
if (empty($lines)) {
return 0;
@ -207,15 +208,15 @@ EOF;
if (Cookie::get('BLUDIT-KEY') && defined('BLUDIT_PRO') && $this->getValue('excludeAdmins')) {
return false;
}
$currentTime = Date::current('Y-m-d H:i:s');
$currentTime = Date::current('Y-m-d H:i:s');
$ip = TCP::getIP();
$hashIP = md5($ip);
$line = json_encode(array($hashIP, $currentTime));
$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)
@ -230,8 +231,8 @@ EOF;
$html .= '
<nav>
<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" 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 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>
</div>
</nav>
<div class="tab-content my-2" id="nav-tabContent">
@ -271,5 +272,4 @@ EOF;
return $html;
}
}

View file

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

View file

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

View file

@ -1,6 +1,7 @@
<?php
class pluginTinymce extends Plugin {
class pluginTinymce extends Plugin
{
private $loadOnController = array(
'new-content',
@ -10,10 +11,10 @@ class pluginTinymce extends Plugin {
public function init()
{
$this->dbFields = array(
'toolbar1'=>'formatselect bold italic forecolor backcolor removeformat | bullist numlist table | blockquote alignleft aligncenter alignright | link unlink pagebreak image code',
'toolbar2'=>'',
'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'
'toolbar1' => 'formatselect bold italic forecolor backcolor removeformat | bullist numlist table | blockquote alignleft aligncenter alignright | link unlink pagebreak image code',
'toolbar2' => '',
'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'
);
}
@ -26,25 +27,25 @@ class pluginTinymce extends Plugin {
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('toolbar-top').'</label>';
$html .= '<input name="toolbar1" id="jstoolbar1" type="text" value="'.$this->getValue('toolbar1').'">';
$html .= '<label>' . $L->get('toolbar-top') . '</label>';
$html .= '<input name="toolbar1" id="jstoolbar1" type="text" dir="auto" value="' . $this->getValue('toolbar1') . '">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('toolbar-bottom').'</label>';
$html .= '<input name="toolbar2" id="jstoolbar2" type="text" value="'.$this->getValue('toolbar2').'">';
$html .= '<label>' . $L->get('toolbar-bottom') . '</label>';
$html .= '<input name="toolbar2" id="jstoolbar2" type="text" dir="auto" value="' . $this->getValue('toolbar2') . '">';
$html .= '</div>';
$html .= '<div>';
$html .= '<label>'.$L->get('Plugins').'</label>';
$html .= '<input name="plugins" id="jsplugins" type="text" value="'.$this->getValue('plugins').'">';
$html .= '<label>' . $L->get('Plugins') . '</label>';
$html .= '<input name="plugins" id="jsplugins" type="text" dir="auto" value="' . $this->getValue('plugins') . '">';
$html .= '</div>';
if (strpos($this->getValue('plugins'), 'codesample') !== false) {
$html .= '<div>';
$html .= '<label>'.$L->get('codesample-languages').'</label>';
$html .= '<input name="codesampleLanguages" id="jsCodesampleLanguages" type="text" value="'.$this->getValue('codesampleLanguages').'">';
$html .= '<span class="tip">'.$L->get('codesample-supported-laguages').'</span>';
$html .= '<label>' . $L->get('codesample-languages') . '</label>';
$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 .= '</div>';
}
@ -57,8 +58,8 @@ class pluginTinymce extends Plugin {
if (!in_array($GLOBALS['ADMIN_CONTROLLER'], $this->loadOnController)) {
return false;
}
$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 = '<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>';
return $html;
}
@ -73,32 +74,33 @@ class pluginTinymce extends Plugin {
$toolbar1 = $this->getValue('toolbar1');
$toolbar2 = $this->getValue('toolbar2');
$content_css = $this->htmlPath().'css/tinymce_content.css';
$content_css = $this->htmlPath() . 'css/tinymce_content.css';
$plugins = $this->getValue('plugins');
$version = $this->version();
if (strpos($this->getValue('plugins'), 'codesample') !== false) {
$codesampleConfig = '';
$codesampleLanguages = explode("|", $this->getValue('codesampleLanguages'));
foreach($codesampleLanguages AS $codesampleLang) {
foreach ($codesampleLanguages as $codesampleLang) {
$values = explode(" ", $codesampleLang);
$codesampleConfig .= "{ text: '" . $values[0] . "', value: '" . $values[1] . "' },";
}
}
$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();
} 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();
}
if (IMAGE_RELATIVE_TO_ABSOLUTE) {
$document_base_url = 'document_base_url: "'.DOMAIN_UPLOADS.'",';
$document_base_url = 'document_base_url: "' . DOMAIN_UPLOADS . '",';
} else {
$document_base_url = '';
}
$html = <<<EOF
$html = <<<EOF
<script>
// Insert an image in the editor at the cursor position
@ -150,5 +152,4 @@ $html = <<<EOF
EOF;
return $html;
}
}

View file

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

View file

@ -98,7 +98,7 @@ EOF;
$html = '<div class="mb-3">';
$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>';

View file

@ -650,7 +650,7 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
<input type="hidden" name="timezone" id="jstimezone" value="UTC">
<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 class="form-group mb-0">