Plugin position

This commit is contained in:
Diego Najar 2018-02-06 18:26:59 +01:00
parent a764d6f177
commit 2a0d694756
12 changed files with 157 additions and 16 deletions

View File

@ -227,7 +227,7 @@ class Plugin {
// Return TRUE if the installation success, otherwise FALSE.
public function install($position=1)
{
if($this->installed()) {
if ($this->installed()) {
return false;
}
@ -278,6 +278,17 @@ class Plugin {
return $this->save();
}
public function setField($field, $value)
{
$this->db[$field] = Sanitize::html($value);
return $this->save();
}
public function setPosition($position)
{
return $this->setField('position', $position);
}
// Returns the parameters after the URI, FALSE if the URI doesn't match with the webhook
// Example: https://www.mybludit.com/api/foo/bar
public function webhook($URI=false, $returnsAfterURI=false, $fixed=true)

View File

@ -0,0 +1,32 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
if ($Login->role()!=='admin') {
Alert::set($Language->g('You do not have sufficient permissions'));
Redirect::page('dashboard');
}
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
changePluginsPosition(explode(',',$_POST['plugin-list']));
Redirect::page('plugins-position');
}
// ============================================================================
// POST Method
// ============================================================================
// ============================================================================
// Main after POST
// ============================================================================
// Title of the page
$layout['title'] .= ' - '.$Language->g('Plugins');

View File

@ -31,8 +31,13 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// ============================================================================
$allPages = buildAllpages($publishedPages=true, $staticPages=true, $draftPages=false, $scheduledPages=false);
// Generate $pagesByParentByKey and pagesByParent
$pagesByParent = array(PARENT=>array());
$pagesByParentByKey = array(PARENT=>array());
buildPagesByParent(true, true);
// Homepage select options
$homepageOptions = array(' '=>'- '.$L->g('Latest content').' -');
$homepageOptions = array(' '=>'- '.$L->g('Default').' -');
foreach ($allPages as $key=>$page) {
$parentKey = $page->parentKey();
if ($parentKey) {

View File

@ -86,6 +86,10 @@ body {
max-width: 1800px;
}
.hint {
}
/* TOPBAR
---------------------------------------------------------------- */
@ -649,6 +653,30 @@ div.plugin-links > span.separator {
color: #ccc;
}
.plugin-position {
display: block !important;
margin: 10px 0 !important;
padding: 10px !important;
line-height: 50px !important;
height: 50px !important;
width: 30% !important;
min-width: 100px !important;
cursor: move !important;
border: 1px solid #ccc !important;
background: #fafafa;
}
.uk-sortable-item {
background: #fafafa !important;
}
.uk-sortable-placeholder {
background: #fafafa !important;
}
.plugin-position-wrap {
z-index: 200;
}
/* ----------- PAGINATOR ----------- */

View File

@ -0,0 +1,2 @@
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
.uk-sortable{position:relative}.uk-sortable>*{touch-action:none}.uk-sortable a,.uk-sortable img{-webkit-touch-callout:none}.uk-sortable>:last-child{margin-bottom:0}.uk-sortable-dragged{position:absolute;z-index:1050;pointer-events:none}.uk-sortable-placeholder{opacity:0}.uk-sortable-empty{min-height:30px}.uk-sortable-handle{touch-action:none}.uk-sortable-handle:hover{cursor:move}.uk-sortable-moving,.uk-sortable-moving *{cursor:move}.uk-sortable-moving iframe{pointer-events:none}

View File

@ -16,6 +16,7 @@
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/uikit/form-file.almost-flat.min.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/uikit/placeholder.almost-flat.min.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/uikit/progress.almost-flat.min.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/uikit/sortable.min.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/default.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_ADMIN_THEME.'css/jquery.datetimepicker.css?version='.BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="<?php echo HTML_PATH_CORE_CSS.'font-awesome/css/font-awesome.min.css?version='.BLUDIT_VERSION ?>">
@ -24,6 +25,7 @@
<script charset="utf-8" src="<?php echo HTML_PATH_CORE_JS.'jquery.min.js?version='.BLUDIT_VERSION ?>"></script>
<script charset="utf-8" src="<?php echo HTML_PATH_ADMIN_THEME.'js/uikit/uikit.min.js?version='.BLUDIT_VERSION ?>"></script>
<script charset="utf-8" src="<?php echo HTML_PATH_ADMIN_THEME.'js/uikit/upload.min.js?version='.BLUDIT_VERSION ?>"></script>
<script charset="utf-8" src="<?php echo HTML_PATH_ADMIN_THEME.'js/uikit/sortable.min.js?version='.BLUDIT_VERSION ?>"></script>
<script charset="utf-8" src="<?php echo HTML_PATH_ADMIN_THEME.'js/jquery.datetimepicker.js?version='.BLUDIT_VERSION ?>"></script>
<!-- Plugins -->

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,38 @@
<?php
HTML::title(array('title'=>$L->g('Plugins Position'), 'icon'=>'puzzle-piece'));
echo '<div class="hint">'.$L->g('drag-and-drop-to-set-the-position-of-the-plugin').'</div>';
echo '<form class="uk-form" method="post" action="" autocomplete="off">';
HTML::formInputHidden(array(
'name'=>'tokenCSRF',
'value'=>$Security->getTokenCSRF()
));
echo '<div class="uk-sortable" data-uk-sortable>';
foreach ($plugins['siteSidebar'] as $Plugin) {
echo '<div class="plugin-position" data-plugin="'.$Plugin->className().'"><i class="uk-icon-bars"></i> '.$Plugin->name().'</div>';
}
echo '</div>';
echo '<input id="plugin-list" name="plugin-list" type="text" value="" hidden/>';
echo '<button class="uk-button uk-button-primary" type="button" id="jsSave">'.$L->g('Save').'</button>';
echo '</form>';
?>
<script>
$( document ).ready(function() {
$("#jsSave").on("click", function() {
var tmp = [];
$( "div.plugin-position" ).each(function() {
tmp.push( $(this).attr("data-plugin") );
});
console.log( tmp.join(",") );
$("#plugin-list").attr("value", tmp.join(",") );
$(".uk-form").submit();
});
});
</script>

View File

@ -2,6 +2,8 @@
HTML::title(array('title'=>$L->g('Plugins'), 'icon'=>'puzzle-piece'));
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'plugins-position"><i class="uk-icon-plus"></i> '.$L->g('Change the position of the plugins').'</a>';
echo '
<table class="uk-table">
<thead>

View File

@ -42,7 +42,7 @@ $page = $Page = false;
N => Page Object),
)
*/
$pagesByParent = array(PARENT=>array());
//$pagesByParent = array(PARENT=>array()); // DEPREACTED
// Array with pages order by parent and by key
/*
@ -66,7 +66,7 @@ $pagesByParent = array(PARENT=>array());
"childKeyZ" => Page Object),
)
*/
$pagesByParentByKey = array(PARENT=>array());
//$pagesByParentByKey = array(PARENT=>array()); // DEPREACTED
// Array with static content, each item is a Page Object
// Order by position
@ -100,7 +100,7 @@ if ($dbPages->scheduler()) {
}
// Generate pages parent tree, only published pages
buildPagesByParent(true, true);
//buildPagesByParent(true, true);
// Set home page is the user defined one
if ($Site->homepage() && $Url->whereAmI()==='home') {
@ -111,25 +111,19 @@ if ($Site->homepage() && $Url->whereAmI()==='home') {
}
}
// The filter blog alway show all the content
// Change the where am i to use
if ($Url->whereAmI()==='blog') {
//$Url->setWhereAmI('home');
}
// Build specific page
if ($Url->whereAmI()==='page') {
buildThePage();
}
// Build pages by tag
// Build content by tag
elseif ($Url->whereAmI()==='tag') {
buildPagesByTag();
}
// Build pages by category
// Build content by category
elseif ($Url->whereAmI()==='category') {
buildPagesByCategory();
}
// Build pages for the homepage
// Build content for the homepage
elseif ( ($Url->whereAmI()==='home') || ($Url->whereAmI()==='blog') ) {
buildPagesForHome();
}

View File

@ -336,6 +336,27 @@ function deactivatePlugin($pluginClassName) {
return false;
}
function changePluginsPosition($pluginClassList) {
global $plugins;
global $Syslog;
global $Language;
foreach ($pluginClassList as $position=>$pluginClassName) {
if (isset($plugins['all'][$pluginClassName])) {
$plugin = $plugins['all'][$pluginClassName];
$plugin->setPosition(++$position);
}
}
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'plugins-sorted',
'notes'=>''
));
return true;
}
function createPage($args) {
global $dbPages;
global $Syslog;

View File

@ -276,5 +276,9 @@
"congratulations-you-have-successfully-installed-your-bludit": "Congratulations you have successfully installed your **Bludit**.",
"this-theme-may-not-be-supported-by-this-version-of-bludit": "This theme may not be supported by this version of Bludit",
"read-more": "Read more",
"remember-me": "Remember me"
"remember-me": "Remember me",
"plugins-position": "Plugin position",
"plugins-position-changed": "Plugin position changed",
"drag-and-drop-to-set-the-position-of-the-plugin": "Drag and Drop to set the position of the plugins",
"change-the-position-of-the-plugins": "Change the position of the plugins"
}