Select2 as search function and the new assistant for Bludit on Dashboard

This commit is contained in:
Diego Najar 2019-09-25 20:16:45 +02:00
parent e153a20417
commit 582dd26243
12 changed files with 372 additions and 125 deletions

View File

@ -1,31 +0,0 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
checkRole(array('admin'));
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
// ============================================================================
// POST Method
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
editSettings($_POST);
Redirect::page('settings-general');
}
// ============================================================================
// Main after POST
// ============================================================================
// Title of the page
$layout['title'] .= ' - '.$L->g('General Settings');

View File

@ -212,7 +212,6 @@ function table($type) {
<div class="tab-content">
<!-- TABS PAGES -->
<div class="tab-pane show active" id="pages" role="tabpanel">
<input type="text" class="form-control mt-3" id="search" placeholder="<?php $L->p('Search') ?>">
<?php table('published'); ?>
@ -245,42 +244,6 @@ function table($type) {
</nav>
<?php endif; ?>
</div>
<script>
$(document).ready(function() {
var searchXHR;
var searchArray;
$("#search").autoComplete({
minChars: 3,
source: function(term, response) {
searchXHR = $.getJSON(HTML_PATH_ADMIN_ROOT+"ajax/content-get-list",
{
published: true,
static: true,
sticky: true,
scheduled: true,
draft: true,
query: term
},
function(data) {
searchArray = data;
var matches = [];
for (var key in data) {
matches.push(key);
}
response(matches);
});
},
renderItem: function (item, search) {
var title = searchArray[item]['title'];
html = '<div class="search-suggestion">';
html += '<div class="search-suggestion-item">'+title+'</div>';
html += '<div class="search-suggestion-options"><a target="_blank" href="<?php echo DOMAIN_PAGES ?>'+item+'""><?php $L->p('View') ?></a><a class="ml-2" href="<?php echo DOMAIN_ADMIN ?>edit-content/'+item+'"><?php $L->p('Edit') ?></a></div>';
html += '</div>';
return html;
}
});
});
</script>
<!-- TABS STATIC -->
<div class="tab-pane" id="static" role="tabpanel">

View File

@ -27,28 +27,64 @@
</div>
<!-- Quick Links -->
<div class="container border-bottom pb-4">
<h4 class="pb-3"><?php $L->p('Quick links') ?></h4>
<div class="container border-bottom pb-5">
<div class="row">
<div class="col">
<a class="quick-links text-center" style="color: #4586d4" href="<?php echo HTML_PATH_ADMIN_ROOT.'new-content' ?>">
<div class="fa fa-edit quick-links-icons"></div>
<div><?php $L->p('New content') ?></div>
</a>
</div>
<div class="col border-left border-right">
<a class="quick-links text-center" href="<?php echo HTML_PATH_ADMIN_ROOT.'categories' ?>">
<div class="fa fa-tags quick-links-icons"></div>
<div><?php $L->p('Categories') ?></div>
</a>
</div>
<div class="col">
<a class="quick-links text-center" href="<?php echo HTML_PATH_ADMIN_ROOT.'users' ?>">
<div class="fa fa-users quick-links-icons"></div>
<div><?php $L->p('Users') ?></div>
</a>
<div class="form-group">
<select id="jsclippy" class="clippy" name="state"></select>
</div>
</div>
</div>
<script>
$(document).ready(function() {
var clippy = $("#jsclippy").select2({
placeholder: "<?php $L->p('Start typing to see a list of suggestions.') ?>",
allowClear: true,
width: "100%",
theme: "bootstrap4",
minimumInputLength: 2,
ajax: {
url: HTML_PATH_ADMIN_ROOT+"ajax/clippy",
data: function (params) {
var query = { query: params.term }
return query;
},
processResults: function (data) {
return data;
}
},
templateResult: function(data) {
console.log(data);
var html = '';
if (data.type=='menu') {
html += '<a href="'+data.url+'"><div class="search-suggestion">';
html += '<span class="fa fa-'+data.icon+'"></span>'+data.text+'</div></a>';
} else {
html += '<div class="search-suggestion">';
html += '<div class="search-suggestion-item">'+data.text+'</div>';
html += '<div class="search-suggestion-options">';
html += '<a target="_blank" href="http://localhost:8000/testt">View</a>';
html += '<a class="ml-2" href="http://localhost:8000/admin/edit-content/testt">Edit</a>';
html += '</div></div>';
}
return html;
},
escapeMarkup: function(markup) {
return markup;
}
}).on("select2:closing", function(e) {
e.preventDefault();
}).on("select2:closed", function(e) {
clippy.select2("open");
});
clippy.select2("open");
});
</script>
</div>
<div class="container mt-4">
<div class="row">

View File

@ -30,12 +30,6 @@
'name'=>'tokenCSRF',
'value'=>$security->getTokenCSRF()
));
// Page not found
echo Bootstrap::formInputHidden(array(
'name'=>'pageNotFound',
'value'=>$site->pageNotFound()
));
?>
<!-- General tab -->
@ -109,40 +103,95 @@
// Homepage
try {
$options = array();
$homeKey = $site->homepage();
$home = new Page($homeKey);
$homeValue = $home->title();
if (!empty($homeKey)) {
$home = new Page($homeKey);
$options = array($homeKey=>$home->title());
}
} catch (Exception $e) {
$homeValue = '';
// continue
}
echo Bootstrap::formSelect(array(
'name'=>'homepage',
'label'=>$L->g('Homepage'),
'options'=>array(''=>''),
'options'=>$options,
'selected'=>false,
'class'=>'',
'placeholder'=>$L->g('Start typing a page title to see a list of suggestions.'),
'tip'=>$L->g('Returning page for the main page')
));
?>
<script>
$(document).ready(function() {
var homepage = $("#jshomepage").select2({
placeholder: "<?php $L->p('Start typing to see a list of suggestions.') ?>",
allowClear: true,
theme: "bootstrap4",
minimumInputLength: 2,
ajax: {
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published",
data: function (params) {
var query = { query: params.term }
return query;
},
processResults: function (data) {
return data;
}
},
escapeMarkup: function(markup) {
return markup;
}
});
});
</script>
<?php
// Page not found 404
try {
$options = array();
$pageNotFoundKey = $site->pageNotFound();
$pageNotFound = new Page($pageNotFoundKey);
$pageNotFoundValue = $pageNotFound->title();
if (!empty($pageNotFoundKey)) {
$pageNotFound = new Page($pageNotFoundKey);
$options = array($pageNotFoundKey=>$pageNotFound->title());
}
} catch (Exception $e) {
$pageNotFoundValue = '';
// continue
}
echo Bootstrap::formInputText(array(
'name'=>'pageNotFoundTMP',
echo Bootstrap::formSelect(array(
'name'=>'pageNotFound',
'label'=>$L->g('Page not found'),
'value'=>$pageNotFoundValue,
'options'=>$options,
'selected'=>false,
'class'=>'',
'placeholder'=>$L->g('Start typing a page title to see a list of suggestions.'),
'tip'=>$L->g('Returning page when the page doesnt exist')
));
?>
<script>
$(document).ready(function() {
var homepage = $("#jspageNotFound").select2({
placeholder: "<?php $L->p('Start typing to see a list of suggestions.') ?>",
allowClear: true,
theme: "bootstrap4",
minimumInputLength: 2,
ajax: {
url: HTML_PATH_ADMIN_ROOT+"ajax/get-published",
data: function (params) {
var query = { query: params.term }
return query;
},
processResults: function (data) {
return data;
}
},
escapeMarkup: function(markup) {
return markup;
}
});
});
</script>
<?
echo Bootstrap::formTitle(array('title'=>$L->g('Email account settings')));
echo Bootstrap::formInputText(array(
@ -507,7 +556,6 @@
contentType: false,
processData: false
}).done(function(data) {
console.log(data);
if (data.status==0) {
$("#jssiteLogoPreview").attr('src',data.absoluteURL+"?time="+Math.random());
} else {
@ -525,7 +573,6 @@
$(function() {
$('a[data-toggle="tab"]').on('click', function(e) {
window.localStorage.setItem('activeTab', $(e.target).attr('href'));
console.log($(e.target).attr('href'));
});
var activeTab = window.localStorage.getItem('activeTab');
if (activeTab) {

68
bl-kernel/ajax/clippy.php Normal file
View File

@ -0,0 +1,68 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
// $_GET
// ----------------------------------------------------------------------------
// (string) $_GET['query']
$query = isset($_GET['query']) ? Text::lowercase($_GET['query']) : false;
// ----------------------------------------------------------------------------
if ($query===false) {
ajaxResponse(1, 'Invalid query.');
}
$result = array();
// MENU
if (Text::stringContains(Text::lowercase($L->g('New content')), $query)) {
$tmp = array('disabled'=>true, 'icon'=>'plus-circle', 'type'=>'menu');
$tmp['text'] = $L->g('New content');
$tmp['url'] = HTML_PATH_ADMIN_ROOT.'new-content';
array_push($result, $tmp);
}
if (Text::stringContains(Text::lowercase($L->g('New category')), $query)) {
$tmp = array('disabled'=>true, 'icon'=>'tag', 'type'=>'menu');
$tmp['text'] = $L->g('New category');
$tmp['url'] = HTML_PATH_ADMIN_ROOT.'new-category';
array_push($result, $tmp);
}
if (Text::stringContains(Text::lowercase($L->g('New user')), $query)) {
$tmp = array('disabled'=>true, 'icon'=>'user', 'type'=>'menu');
$tmp['text'] = $L->g('New user');
$tmp['url'] = HTML_PATH_ADMIN_ROOT.'new-user';
array_push($result, $tmp);
}
if (Text::stringContains(Text::lowercase($L->g('Categories')), $query)) {
$tmp = array('disabled'=>true, 'icon'=>'tags', 'type'=>'menu');
$tmp['text'] = $L->g('Categories');
$tmp['url'] = HTML_PATH_ADMIN_ROOT.'categories';
array_push($result, $tmp);
}
if (Text::stringContains(Text::lowercase($L->g('Users')), $query)) {
$tmp = array('disabled'=>true, 'icon'=>'users', 'type'=>'menu');
$tmp['text'] = $L->g('Users');
$tmp['url'] = HTML_PATH_ADMIN_ROOT.'users';
array_push($result, $tmp);
}
// PAGES
$pagesKey = $pages->getDB();
foreach ($pagesKey as $pageKey) {
try {
$page = new Page($pageKey);
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {
$tmp = array('disabled'=>true);
$tmp['id'] = $page->key();
$tmp['text'] = $page->title();
$tmp['type'] = $page->type();
array_push($result, $tmp);
}
} catch (Exception $e) {
// continue
}
}
exit (json_encode(array('results'=>$result)));
?>

View File

@ -1,6 +1,15 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
header('Content-Type: application/json');
/*
| Returns a list of pages and the title contains the query string
| The returned list have published, sticky and statics pages
|
| @_POST['query'] string The string to search in the title of the pages
|
| @return array
*/
// $_GET
// ----------------------------------------------------------------------------
// (string) $_GET['query']
@ -10,17 +19,21 @@ if ($query===false) {
ajaxResponse(1, 'Invalid query.');
}
$tmp = array();
$published = $pages->getPublishedDB();
$statics = $pages->getStaticDB();
$pagesKey = array_merge($published, $statics);
$result = array();
$pagesKey = $pages->getDB();
foreach ($pagesKey as $pageKey) {
try {
$page = new Page($pageKey);
if ($page->isParent()) {
// Check page status
if ($page->published() || $page->sticky() || $page->isStatic()) {
// Check if the query contains in the title
$lowerTitle = Text::lowercase($page->title());
if (Text::stringContains($lowerTitle, $query)) {
$tmp[$page->title()] = $page->key();
$tmp = array('disabled'=>false);
$tmp['id'] = $page->key();
$tmp['text'] = $page->title();
$tmp['type'] = $page->type();
array_push($result, $tmp);
}
}
} catch (Exception $e) {
@ -28,6 +41,6 @@ foreach ($pagesKey as $pageKey) {
}
}
exit (json_encode($tmp));
exit (json_encode(array('results'=>$result)));
?>

145
bl-kernel/css/select2-bootstrap4.min.css vendored Normal file
View File

@ -0,0 +1,145 @@
.select2-container--bootstrap4 .select2-selection--single {
height: calc(1.5em + 0.75rem + 2px) !important; }
.select2-container--bootstrap4 .select2-selection--single .select2-selection__placeholder {
color: #757575;
line-height: calc(1.5em + 0.75rem); }
.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow {
position: absolute;
top: 50%;
right: 3px;
width: 20px; }
.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow b {
top: 60%;
border-color: #343a40 transparent transparent transparent;
border-style: solid;
border-width: 5px 4px 0 4px;
width: 0;
height: 0;
left: 50%;
margin-left: -4px;
margin-top: -2px;
position: absolute; }
.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered {
line-height: calc(1.5em + 0.75rem); }
.select2-search--dropdown .select2-search__field {
border: 1px solid #ced4da;
border-radius: 0.25rem; }
.select2-results__message {
color: #6c757d; display: none !important; }
.select2-container--bootstrap4 .select2-selection--multiple {
min-height: calc(1.5em + 0.75rem + 2px) !important; }
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__rendered {
-webkit-box-sizing: border-box;
box-sizing: border-box;
list-style: none;
margin: 0;
padding: 0 5px;
width: 100%; }
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice {
color: #343a40;
border: 1px solid #bdc6d0;
border-radius: 0.2rem;
padding: 0;
padding-right: 5px;
cursor: pointer;
float: left;
margin-top: 0.3em;
margin-right: 5px; }
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove {
color: #bdc6d0;
font-weight: bold;
margin-left: 3px;
margin-right: 1px;
padding-right: 3px;
padding-left: 3px;
float: left; }
.select2-container--bootstrap4 .select2-selection--multiple .select2-selection__choice__remove:hover {
color: #343a40; }
.select2-container {
display: block; }
.select2-container *:focus {
outline: 0; }
.input-group .select2-container--bootstrap4 {
-webkit-box-flex: 1;
-ms-flex-positive: 1;
flex-grow: 1; }
.input-group-prepend ~ .select2-container--bootstrap4 .select2-selection {
border-top-left-radius: 0;
border-bottom-left-radius: 0; }
.select2-container--bootstrap4 .select2-selection {
border: 1px solid #ced4da;
border-radius: 0.25rem;
width: 100%; }
.select2-container--bootstrap4.select2-container--focus.select2-container--open .select2-selection {
border-bottom: none;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0; }
.select2-container--bootstrap4.select2-container--disabled .select2-selection, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-selection {
background-color: #e9ecef;
cursor: not-allowed;
border-color: #ced4da;
-webkit-box-shadow: none;
box-shadow: none; }
.select2-container--bootstrap4.select2-container--disabled .select2-search__field, .select2-container--bootstrap4.select2-container--disabled.select2-container--focus .select2-search__field {
background-color: transparent; }
select.is-invalid ~ .select2-container--bootstrap4 .select2-selection,
form.was-validated select:invalid ~ .select2-container--bootstrap4 .select2-selection {
border-color: #dc3545; }
select.is-valid ~ .select2-container--bootstrap4 .select2-selection,
form.was-validated select:valid ~ .select2-container--bootstrap4 .select2-selection {
border-color: #28a745; }
.select2-container--bootstrap4 .select2-dropdown {
border-color: #ced4da;
border-top: none;
border-top-left-radius: 0;
border-top-right-radius: 0; }
.select2-container--bootstrap4 .select2-dropdown.select2-dropdown--above {
border-top: 1px solid #ced4da;
border-top-left-radius: 0.25rem;
border-top-right-radius: 0.25rem; }
.select2-container--bootstrap4 .select2-dropdown .select2-results__option[aria-selected=true] {
background-color: #e9ecef; }
.select2-container--bootstrap4 .select2-results__option--highlighted,
.select2-container--bootstrap4 .select2-results__option--highlighted.select2-results__option[aria-selected=true] {
background-color: #f1f1f1;
}
.select2-container--bootstrap4 .select2-results__option[role=group] {
padding: 0; }
.select2-container--bootstrap4 .select2-results > .select2-results__options {
max-height: 15em;
overflow-y: auto; }
.select2-container--bootstrap4 .select2-results__group {
padding: 6px;
display: list-item;
color: #6c757d; }
.select2-container--bootstrap4 .select2-selection__clear {
width: 1.2em;
height: 1.2em;
line-height: 1.15em;
padding-left: 0.3em;
margin-top: 0.5em;
border-radius: 50%;
background-color: #F44336;
color: #f8f9fa;
float: right;
margin-right: 0.3em; }
.select2-container--bootstrap4 .select2-selection__clear:hover {
background-color: #343a40; }

1
bl-kernel/css/select2.min.css vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -553,6 +553,13 @@ function editSettings($args) {
}
}
if (empty($args['homepage'])) {
$args['homepage'] = '';
}
if (empty($args['pageNotFound'])) {
$args['pageNotFound'] = '';
}
if (isset($args['uriPage'])) {
$args['uriPage'] = Text::addSlashes($args['uriPage']);
}

View File

@ -1,5 +1,3 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); ?>
function sanitizeHTML(text) {
var map = {
'&': '&amp;',

2
bl-kernel/js/select2.full.min.js vendored Executable file

File diff suppressed because one or more lines are too long

View File

@ -82,8 +82,7 @@ class pluginSimpleStats extends Plugin {
$html = <<<EOF
<div class="simple-stats-plugin">
<div class="my-5 pt-4 border-top">
<h4 class="pb-3">{$L->get('Visits')}</h4>
<div class="my-4 pt-4 border-top">
<div class="ct-chart ct-perfect-fourth"></div>
<p class="legends visits-today">{$L->g('Visits today')}: $visitsToday</p>
<p class="legends unique-today">{$L->g('Unique visitors today')}: $uniqueVisitors</p>
@ -125,28 +124,27 @@ $script = <<<EOF
</script>
EOF;
$this->deleteOldLogs();
/**
* Optional Content Stats Feature
*/
if ($this->getValue('showContentStats')) {
global $pages, $categories, $tags;
$data['title'] = $L->get('Statistics');
$data['tabTitleChart'] = $L->get('Chart');
$data['tabTitleTable'] = $L->get('Table');
$data['data'][$L->get('published')] = count($pages->getPublishedDB());
$data['data'][$L->get('published')] = count($pages->getPublishedDB());
$data['data'][$L->get('static')] = count($pages->getStaticDB());
$data['data'][$L->get('drafts')] = count($pages->getDraftDB());
$data['data'][$L->get('scheduled')] = count($pages->getScheduledDB());
$data['data'][$L->get('scheduled')] = count($pages->getScheduledDB());
$data['data'][$L->get('sticky')] = count($pages->getStickyDB());
$data['data'][$L->get('categories')]= count($categories->keys());
$data['data'][$L->get('categories')] = count($categories->keys());
$data['data'][$L->get('tags')] = count($tags->keys());
$html .= $this->renderContentStatistics($data);
}
$this->deleteOldLogs();
return $html.PHP_EOL.$script.PHP_EOL;
}
@ -155,7 +153,7 @@ EOF;
$this->addVisitor();
}
// Keep only 7 days of logs, remove the old ones
// Keep only 7 days of logs
public function deleteOldLogs()
{
$logs = Filesystem::listFiles($this->workspace(), '*', 'log', true);