Plugin Sort implementation
This commit is contained in:
parent
96d3efaa65
commit
cf584b2cc1
47
bl-kernel/admin/controllers/plugins-sort.php
Normal file
47
bl-kernel/admin/controllers/plugins-sort.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?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('admin', 'dashboard');
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Functions
|
||||
// ============================================================================
|
||||
|
||||
function setSettings($args)
|
||||
{
|
||||
global $dbPluginSort;
|
||||
global $Language;
|
||||
|
||||
if($dbPluginSort->set($args) ) {
|
||||
Alert::set($Language->g('the-changes-have-been-saved'));
|
||||
}
|
||||
else {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the settings.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main before POST
|
||||
// ============================================================================
|
||||
|
||||
// ============================================================================
|
||||
// POST Method
|
||||
// ============================================================================
|
||||
|
||||
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
{
|
||||
setSettings($_POST);
|
||||
Redirect::page('admin', $layout['controller']);
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main after POST
|
||||
// ============================================================================
|
@ -687,4 +687,12 @@ div.plugin-links > span.separator {
|
||||
|
||||
#jsformplugin p {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* ----------- PLUGIN SORT ----------- */
|
||||
|
||||
.sortable .handle {
|
||||
margin-right: 0.75em;
|
||||
font-size: 1.3em;
|
||||
cursor: grab;
|
||||
}
|
@ -67,6 +67,7 @@ $(document).ready(function() {
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'settings-advanced' ?>"><?php $L->p('Advanced settings') ?></a></li>
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'settings-regional' ?>"><?php $L->p('Language and timezone') ?></a></li>
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins' ?>"><?php $L->p('Plugins') ?></a></li>
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins-sort' ?>"><?php $L->p('Plugin Sort') ?></a></li>
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'themes' ?>"><?php $L->p('Themes') ?></a></li>
|
||||
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'about' ?>"><?php $L->p('About') ?></a></li>
|
||||
<?php } ?>
|
||||
@ -132,6 +133,9 @@ $(document).ready(function() {
|
||||
<li <?php echo ($layout['view']=='plugins')?'class="uk-active"':'' ?>>
|
||||
<a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins' ?>"><?php $L->p('Plugins') ?></a>
|
||||
</li>
|
||||
<li <?php echo ($layout['view']=='plugins-sort')?'class="uk-active"':'' ?>>
|
||||
<a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins-sort' ?>"><?php $L->p('Plugin Sort') ?></a>
|
||||
</li>
|
||||
<li <?php echo ($layout['view']=='themes')?'class="uk-active"':'' ?>>
|
||||
<a href="<?php echo HTML_PATH_ADMIN_ROOT.'themes' ?>"><?php $L->p('Themes') ?></a>
|
||||
</li>
|
||||
|
7
bl-kernel/admin/themes/default/js/jquery-ui.min.js
vendored
Normal file
7
bl-kernel/admin/themes/default/js/jquery-ui.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
35
bl-kernel/admin/views/plugins-sort.php
Normal file
35
bl-kernel/admin/views/plugins-sort.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
HTML::title(array('title'=>$L->g('Plugin Sort'), 'icon'=>'puzzle-piece'));
|
||||
|
||||
foreach(array_keys($plugins) as $key) {
|
||||
if ($key != 'all' and count($plugins[$key]) > 0) {
|
||||
sortPlugins($plugins[$key], $key);
|
||||
HTML::formOpen(array('class'=>'uk-form-horizontal'));
|
||||
HTML::formInputHidden(
|
||||
array('name'=>'tokenCSRF','value'=>$Security->getTokenCSRF())
|
||||
);
|
||||
HTML::formInputHidden(array('name'=>'pluginList','value'=>$key));
|
||||
echo '<table class="uk-table">'."\n";
|
||||
echo '<thead>'."\n";
|
||||
echo "\t".'<tr><th>'.$key.'</th></tr>'."\n";
|
||||
echo '</thead>'."\n";
|
||||
echo '<tbody class="sortable">'."\n";
|
||||
foreach($plugins[$key] as $plugin) {
|
||||
print "\t".'<tr><td><span class="handle">≡</span>';
|
||||
HTML::formInputHidden(array('name'=>$plugin->directoryName, 'value'=>''));
|
||||
echo $plugin->name().'</td></tr>'."\n";
|
||||
}
|
||||
echo '</tbody>'."\n";
|
||||
echo '</table>'."\n";
|
||||
echo '<button type="submit" class="uk-button">'.$L->g('Save').'</button>'."\n";
|
||||
HTML::formClose(false);
|
||||
}
|
||||
}
|
||||
?>
|
||||
<script src="<?php echo HTML_PATH_ADMIN_THEME_JS.'jquery-ui.min.js'; ?>"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
jQuery(".sortable").sortable({ handle: ".handle" });
|
||||
});
|
||||
</script>
|
@ -145,6 +145,7 @@ include(PATH_KERNEL.'dbtags.class.php');
|
||||
include(PATH_KERNEL.'dblanguage.class.php');
|
||||
include(PATH_KERNEL.'dbsite.class.php');
|
||||
include(PATH_KERNEL.'dbcategories.class.php');
|
||||
include(PATH_KERNEL.'dbpluginsort.class.php');
|
||||
include(PATH_KERNEL.'post.class.php');
|
||||
include(PATH_KERNEL.'page.class.php');
|
||||
include(PATH_KERNEL.'user.class.php');
|
||||
@ -185,6 +186,7 @@ $dbPages = new dbPages();
|
||||
$dbUsers = new dbUsers();
|
||||
$dbTags = new dbTags();
|
||||
$dbCategories = new dbCategories();
|
||||
$dbPluginSort = new dbPluginSort();
|
||||
$Site = new dbSite();
|
||||
$Url = new Url();
|
||||
$Parsedown = new ParsedownExtra();
|
||||
|
40
bl-kernel/dbpluginsort.class.php
Normal file
40
bl-kernel/dbpluginsort.class.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
class dbPluginSort extends dbJSON {
|
||||
|
||||
public $dbFields = array(
|
||||
'pluginList'=> array('inFile'=>false, 'value'=>array())
|
||||
);
|
||||
|
||||
function __construct() {
|
||||
parent::__construct(PATH_DATABASES.'plugin-positions.php');
|
||||
}
|
||||
|
||||
public function getDB() {
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
public function get($dir, $name) {
|
||||
if (isset($this->db[$dir][$name])) {
|
||||
return $this->db[$dir][$name];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function set($args)
|
||||
{
|
||||
$i = 1;
|
||||
array_walk($args, '&Sanitize::html');
|
||||
$pluginList = array_shift($args);
|
||||
|
||||
foreach(array_keys($args) as $plugin) {
|
||||
$this->db[$pluginList][$plugin] = $i++;
|
||||
}
|
||||
if( $this->save() === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
@ -258,4 +258,17 @@ function buildAllPages()
|
||||
}
|
||||
|
||||
return $pages;
|
||||
}
|
||||
|
||||
function sortPlugins(&$pluginList, $cat) {
|
||||
|
||||
usort($pluginList, function($p1, $p2) use ($cat) {
|
||||
global $dbPluginSort;
|
||||
if ($dbPluginSort->get($cat, $p1->directoryName) ==
|
||||
$dbPluginSort->get($cat, $p2->directoryName)) {
|
||||
return 0;
|
||||
}
|
||||
return ($dbPluginSort->get($cat, $p1->directoryName) <
|
||||
$dbPluginSort->get($cat, $p2->directoryName))? -1 : 1;
|
||||
});
|
||||
}
|
@ -160,6 +160,10 @@ class Theme {
|
||||
{
|
||||
global $plugins;
|
||||
|
||||
if ($type != 'all' and count($plugins[$type]) > 0) {
|
||||
sortPlugins($plugins[$type], $type);
|
||||
}
|
||||
|
||||
foreach($plugins[$type] as $plugin)
|
||||
{
|
||||
echo call_user_func(array($plugin, $type));
|
||||
|
@ -77,6 +77,7 @@
|
||||
"modified-date": "Modified date",
|
||||
"empty-title": "Empty title",
|
||||
"plugins": "Plugins",
|
||||
"plugin-sort": "Plugin Sort",
|
||||
"install-plugin": "Install plugin",
|
||||
"uninstall-plugin": "Uninstall plugin",
|
||||
"new-password": "New password",
|
||||
|
Loading…
x
Reference in New Issue
Block a user