Skip to content

Commit

Permalink
v0.1.1-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
rtripault committed May 1, 2013
1 parent 0ce343b commit a031d26
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 20 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Plugin Sorter

PluginSorter is a Custom Manager Page allowing you to define the execution order of your plugins, per event.
Plugin Sorter is a Custom Manager Page allowing you to define the execution order of your plugins, per event.

## Requirements

Expand All @@ -18,7 +18,7 @@ During setup, you will be offered to :
This is a required action to make Plugin Sorter work.You can skip it during the setup and perform this action from the CMP later on.
What it does is assign & increments a `priority` value to each `modPluginEvent` object.

In the CMP, you will find a button which allows you to perform this action at will (most likely after each plugin creation/creation since MODX creates all plugins with a priority of `0`, messing up the whole priority role).
In the CMP, you will find a button which allows you to perform this action at will.
If you click the button when "All events" if set in the near combo box, the sorting will be done for all system events. If you filter to a particular system event, the sorting will only be done for that event.

### Automatically refresh cache
Expand All @@ -34,5 +34,5 @@ Users must have the `save_plugin` right/flag to see the CMP menu.

## License

PluginSorter is licensed under the MIT license.
Copyright 2013 Melting Media <https://github.com/meltingmedia>
Plugin Sorter is licensed under the MIT license.
Copyright 2013 Melting Media <https://github.com/meltingmedia/PluginSorter>
37 changes: 33 additions & 4 deletions _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// define package names
define('PKG_NAME', 'PluginSorter');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));
define('PKG_VERSION', '0.1.0');
define('PKG_VERSION', '0.1.1');
define('PKG_RELEASE', 'beta');

// Define build paths
Expand All @@ -35,12 +35,15 @@
// Override with your own defines here (see build.config.sample.php)
require_once $sources['build'] . 'build.config.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
//require_once $sources['build'] . '/includes/helper.php';
require_once $sources['build'] . '/includes/helper.php';

// Instantiate modX
$modx = new modX();
$modx->initialize('mgr');
echo '<pre>'; // used for nice formatting of log messages
if (!XPDO_CLI_MODE) {
// used for nice formatting of log messages
echo '<pre>';
}
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget('ECHO');

Expand All @@ -67,6 +70,32 @@
}
unset($settings, $setting, $attributes);

// add plugins
$plugins = include $sources['data'].'transport.plugins.php';
if (!is_array($plugins)) {
$modx->log(modX::LOG_LEVEL_FATAL, 'Adding plugins failed.');
}
$attributes = array(
xPDOTransport::UNIQUE_KEY => 'name',
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
'PluginEvents' => array(
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => false,
xPDOTransport::UNIQUE_KEY => array('pluginid', 'event'),
),
),
);
foreach ($plugins as $plugin) {
$vehicle = $builder->createVehicle($plugin, $attributes);
$builder->putVehicle($vehicle);
}
$modx->log(modX::LOG_LEVEL_INFO, 'Packaged in '.count($plugins).' plugins.');
flush();
unset($plugins, $plugin, $attributes);

// Load menu
$modx->log(modX::LOG_LEVEL_INFO, 'Packaging in menu...');
$menu = include $sources['data'] . 'transport.menu.php';
Expand Down Expand Up @@ -117,5 +146,5 @@
$tend = explode(' ', microtime());
$tend = $tend[1] + $tend[0];
$totalTime = sprintf("%2.4f s", ($tend - $tstart));
$modx->log(modX::LOG_LEVEL_INFO, "\n<br />Package Built.<br />\nExecution time: {$totalTime}\n");
$modx->log(modX::LOG_LEVEL_INFO, "\n\nPackage Built. \nExecution time: {$totalTime}\n");
exit ();
23 changes: 23 additions & 0 deletions _build/data/events/pluginsorter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @var modX $modx
*/
$events = array();

$ventName = 'OnPluginEventBeforeSave';
$events[$ventName] = $modx->newObject('modPluginEvent');
$events[$ventName]->fromArray(array(
'event' => $ventName,
'priority' => 0,
'propertyset' => 0,
), '', true, true);

$ventName = 'OnPluginEventRemove';
$events[$ventName] = $modx->newObject('modPluginEvent');
$events[$ventName]->fromArray(array(
'event' => $ventName,
'priority' => 0,
'propertyset' => 0,
), '', true, true);

return $events;
29 changes: 29 additions & 0 deletions _build/data/transport.plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @var modX $modx
* @var array $sources
*/
$plugins = array();
$idx = 0;

$plugins[$idx] = $modx->newObject('modPlugin');
$plugins[$idx]->fromArray(array(
'id' => $idx + 1,
'name' => 'Plugin Sorter',
'description' => 'This plugin automatically sets (or fix) the plugins events rank.',
'plugincode' => Helper::getPHPContent($sources['elements'] . 'plugins/pluginsorter.php'),
'category' => 0,
), '', true, true);

$events = include $sources['data'].'events/pluginsorter.php';
if (is_array($events) && !empty($events)) {
$plugins[$idx]->addMany($events);
$modx->log(xPDO::LOG_LEVEL_INFO, 'Packaged in '.count($events).' Plugin Events for Plugin Sorter.');
flush();
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find plugin events for Plugin Sorter!');
}
unset($events);
$idx += 1;

return $plugins;
99 changes: 99 additions & 0 deletions _build/includes/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

class Helper
{
/** @var \modX $modx An instance of the modX object */
public $modx;
/** @var array $bench An array of running benches */
protected $bench = array();
/** @var array $providers An array of available transport package providers */
protected $providers = array();

/**
* Construct the object
*
* @param modX $modx A modX instance
* @param array $options
*/
public function __construct(modX &$modx, array $options = array())
{
$this->modx =& $modx;
}

/**
* Formats the given file to be used as snippet/plugin content
*
* @param string $filename The path the to snippet file
*
* @return string The PHP content
*/
public static function getPHPContent($filename)
{
$o = file_get_contents($filename);
$o = str_replace('<?php', '', $o);
$o = str_replace('?>', '', $o);
$o = trim($o);

return $o;
}

/**
* Recursively unlink/rmdir the given folder
*
* @param string $dir The folder to empty
*
* @return void
*/
public static function recursiveRmDir($dir)
{
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir."/".$entry) === true){
self::recursiveRmDir($dir."/".$entry);
} else {
unlink($dir."/".$entry);
}
}
}
closedir($handle);
rmdir($dir);
}
}

/**
* Copy the appropriate license model to the right place
*
* @param array $sources An array of options defined in the build script
* @param string $type The license type
*
* @return void
*/
public static function setLicense($sources, $type)
{
$source = $sources['build'] . 'license/'. strtolower($type) .'.txt';
$destination = $sources['docs'] . 'license.txt';
copy($source, $destination);
}

/**
* Format the given array of modAccessPolicy
*
* @param array $permissions
*
* @return string JSON encoded
*/
public function buildPolicyFormatData(array $permissions)
{
$data = array();
/** @var modAccessPolicy $permission */
foreach ($permissions as $permission) {
$data[$permission->get('name')] = true;
}

$data = json_encode($data);

return $data;
}

}
11 changes: 6 additions & 5 deletions _build/setup.options.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function loadSetupStrings($modx, $options)
$lang = $modx->getOption('manager_language', null, $modx->getOption('cultureKey', null, 'en'));
$file = 'setup.inc.php';

$search = $options['package_name'] . '/lexicon';
$search = strtolower(str_replace(' ', '', $options['package_name'])) . '/lexicon';
$length = strlen($search);
$lexicon = false;

Expand Down Expand Up @@ -50,13 +50,14 @@ function loadSetupStrings($modx, $options)
}
}
// Load lexicons
$lexicon = loadSetupStrings($modx, $options);
/** @var array $_lang */
$lexicons = loadSetupStrings($modx, $options);

// Build the setup form
$output = array(
'intro' => $lexicon['pluginsorter.o_intro'],
'auto_sort' => $lexicon['pluginsorter.o_auto_sort'],
'auto_refresh' => $lexicon['pluginsorter.o_auto_refresh'],
'intro' => $lexicons['pluginsorter.o_intro'],
'auto_sort' => $lexicons['pluginsorter.o_auto_sort'],
'auto_refresh' => $lexicons['pluginsorter.o_auto_refresh'],
'end' => '<br /><br />'
);

Expand Down
11 changes: 9 additions & 2 deletions core/components/pluginsorter/docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
--------------------------------------------------------------------------------
Changelog file for PluginSorter
Changelog file for Plugin Sorter
--------------------------------------------------------------------------------

2013/04/23 : PluginSorter 0.1.0-beta
2013/05/01 : v0.1.1-beta
==============================================================================
- Added a plugin to automatically set ranks when an event is attached/removed
from a plugin
- The setup options now make use of lexicons
- The menu/CMP is now only available to users with save_plugin right

2013/04/23 : v0.1.0-beta
==============================================================================
- First release
4 changes: 2 additions & 2 deletions core/components/pluginsorter/docs/readme.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
--------------------------------------------------------------------------------
Extra : PluginSorter
Extra : Plugin Sorter
--------------------------------------------------------------------------------
Since : April 23th, 2013
Author : Romain Tripault // Melting Media <[email protected]>
--------------------------------------------------------------------------------

PluginSorter allows you to define the execution order of your plugins, per event.
Plugin Sorter allows you to define the execution order of your plugins, per event.

Feel free to suggest ideas/improvements/submit bug reports on GitHub:
https://github.com/MeltingMedia/PluginSorter/issues
6 changes: 3 additions & 3 deletions manager/components/pluginsorter/js/home/plugins.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ PluginSorter.PluginsGrid = function(config) {
header: _('plugin')
,dataIndex: 'plugin_name'
,sortable: false
,renderer: function(value, meta, record) {
return this.pluginTpl.apply(record.data);
}
// ,renderer: function(value, meta, record) {
// return this.pluginTpl.apply(record.data);
// }
,scope: this
},{
header: _('event')
Expand Down

0 comments on commit a031d26

Please sign in to comment.