Coder Social home page Coder Social logo

Comments (6)

dignajar avatar dignajar commented on May 18, 2024 1

Hi, yes is in my todoList, thanks.

from bludit.

nickbe avatar nickbe commented on May 18, 2024

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?

from bludit.

metaskop avatar metaskop commented on May 18, 2024

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.

from bludit.

CydGoblin avatar CydGoblin commented on May 18, 2024

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

from bludit.

metaskop avatar metaskop commented on May 18, 2024

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

from bludit.

dignajar avatar dignajar commented on May 18, 2024

This request is implemented

from bludit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.