Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Change order of plugins #198

Closed
HarleyDavidson86 opened this issue Jan 20, 2016 · 6 comments
Closed

Feature request: Change order of plugins #198

HarleyDavidson86 opened this issue Jan 20, 2016 · 6 comments
Labels

Comments

@HarleyDavidson86
Copy link
Contributor

It would be nice to change the order of loaded plugins like I can do it with pages.

@dignajar
Copy link
Member

Hi, yes is in my todoList, thanks.

@nickbe
Copy link

nickbe commented Jan 30, 2016

A much better way would be to simply switch between a plugin view where you can see/edit all plugins, and then viewing only the plugins with a usable function, like 'creating backups', 'maintenance switch' and some others.

This should be easy to do don't you think?

@dignajar dignajar added Idea and removed enhancement labels Jan 30, 2016
@metaskop
Copy link
Contributor

metaskop commented Apr 9, 2017

Coming from https://forum.bludit.com/viewtopic.php?f=6&t=786 I wrote an "extension" to sort the plugins in the sidebar. No guarantee that it's the best way, neither that it's bug free or secure. So: use at your own risk.

First of all I relied on jQueryUI Sortable to find at http://jqueryui.com/download/ (Toggle off everything and then click on "Sortable" in "Interactions". Everything else needed will automatically be selected.)
Put jquery-ui.min.js in /bl-kernel/admin/themes/default/js

  1. Create /bl-kernel/dbsidebar.class.php
<?php
class dbSidebar extends dbJSON {

  function __construct() {
    parent::__construct(PATH_DATABASES.'sidebar-positions.php');
  }

  public function getDB() {
    return $this->db;
  }

  public function get($dirName) {
    if (isset($this->db[$dirName])) {
      return $this->db[$dirName];
    }
    return 1;
  }

  public function set($args)
  {
    $i = 1;
    foreach($args as $field=>$value)
    {
      $this->db[Sanitize::html($field)] = $i++;
    }

    if( $this->save() === false ) {
      Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
      return false;
    }

    return true;
  }
}
?>
  1. /bl-kernel/init.php: add
    $dbSidebar = new dbSidebar();
    somewhere around //Objects (line 184 in my file)

  2. /bl-kernel/helpers/theme.class.php: add

  public static function sidebarSort($obj1, $obj2) {
    global $dbSidebar;
    if ($dbSidebar->get($obj1->directoryName) == $dbSidebar->get($obj2->directoryName)) {
      return 0;
    }
    return ($dbSidebar->get($obj1->directoryName) < $dbSidebar->get($obj2->directoryName))? -1 : 1;
  }

and change

public static function plugins($type)
	{
		global $plugins;

		foreach($plugins[$type] as $plugin)
		{
			echo call_user_func(array($plugin, $type));
		}
	}

to

public static function plugins($type)
	{
		global $plugins;

		if ($type == 'siteSidebar') {
			usort($plugins['siteSidebar'], "Theme::sidebarSort");
		}

		foreach($plugins[$type] as $plugin)
		{
			echo call_user_func(array($plugin, $type));
		}
	}
  1. /bl-languages/en_US.json
    add
    "sidebar-position": "Sidebar Positions",
    somewhere (line 80 in my file)

  2. Create /bl-kernel/admin/controllers/plugins-sidebar.php

<?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 $dbSidebar;
	global $Language;

	if($dbSidebar->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
// ============================================================================
  1. Create /bl-kernel/admin/views/plugins-sidebar.php
<?php
$dbSidebar = new dbSidebar();

HTML::title(array('title'=>$L->g('Sidebar Position'), 'icon'=>'puzzle-piece'));
HTML::formOpen(array('class'=>'uk-form-horizontal'));

    HTML::formInputHidden(array(
        'name'=>'tokenCSRF',
        'value'=>$Security->getTokenCSRF()
    ));

usort($plugins['siteSidebar'], "Theme::sidebarSort");
echo "\n".'<table class="uk-table">'."\n";
echo '<tbody id="sortable">'."\n";
foreach($plugins['siteSidebar'] as $Plugin) {
  echo '  <tr class="uk-width-1-4"><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 '<div class="uk-form-row">
        <div class="uk-form-controls">
        <button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>
        </div>
    </div>';

HTML::formClose();
?>
<script src="<?php echo HTML_PATH_ADMIN_THEME_JS.'jquery-ui.min.js'; ?>"></script>
<script>
$(function() {
  jQuery("#sortable").sortable({ handle: ".handle" });
});
</script>
  1. /bl-kernel/admin/themes/default/index.php:
  • add
<li><a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins-sidebar' ?>"><?php $L->p('Sidebar Position') ?></a></li>

somewhere around <!-- Offcanvas for Mobile --> (line 70 in my file)

  • add
			<li <?php echo ($layout['view']=='plugins-sidebar')?'class="uk-active"':'' ?>>
				<a href="<?php echo HTML_PATH_ADMIN_ROOT.'plugins-sidebar' ?>"><?php $L->p('Sidebar Position') ?></a>
			</li>

(line 136-138 in my file)

  1. /bl-kernel/admin/themes/default/css/default.css
    append
/* ----------- SIDEBAR SORT ----------- */

#sortable .handle {
  margin-right: 0.75em;
  font-size: 1.3em;
  cursor: grab;
}

Finished.

@CydGoblin
Copy link
Contributor

@metaskop you can make a pull request and add the plugin

@metaskop
Copy link
Contributor

@Turqueso Done. Now you can sort all activated plugins.

@dignajar
Copy link
Member

This request is implemented

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants