diff --git a/README.md b/README.md index b4a737f..b72aaae 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 +Plugin Sorter is licensed under the MIT license. +Copyright 2013 Melting Media diff --git a/_build/build.transport.php b/_build/build.transport.php index 22a6977..c970b99 100644 --- a/_build/build.transport.php +++ b/_build/build.transport.php @@ -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 @@ -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 '
'; // used for nice formatting of log messages
+if (!XPDO_CLI_MODE) {
+    // used for nice formatting of log messages
+    echo '
';
+}
 $modx->setLogLevel(modX::LOG_LEVEL_INFO);
 $modx->setLogTarget('ECHO');
 
@@ -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';
@@ -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
Package Built.
\nExecution time: {$totalTime}\n"); +$modx->log(modX::LOG_LEVEL_INFO, "\n\nPackage Built. \nExecution time: {$totalTime}\n"); exit (); diff --git a/_build/data/events/pluginsorter.php b/_build/data/events/pluginsorter.php new file mode 100644 index 0000000..1b184ab --- /dev/null +++ b/_build/data/events/pluginsorter.php @@ -0,0 +1,23 @@ +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; \ No newline at end of file diff --git a/_build/data/transport.plugins.php b/_build/data/transport.plugins.php new file mode 100644 index 0000000..3d82eba --- /dev/null +++ b/_build/data/transport.plugins.php @@ -0,0 +1,29 @@ +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; diff --git a/_build/includes/helper.php b/_build/includes/helper.php new file mode 100644 index 0000000..c6c7da6 --- /dev/null +++ b/_build/includes/helper.php @@ -0,0 +1,99 @@ +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('', '', $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; + } + +} diff --git a/_build/setup.options.php b/_build/setup.options.php index a20b3d7..a0522e6 100644 --- a/_build/setup.options.php +++ b/_build/setup.options.php @@ -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; @@ -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' => '

' ); diff --git a/core/components/pluginsorter/docs/changelog.txt b/core/components/pluginsorter/docs/changelog.txt index 39194ff..732e637 100644 --- a/core/components/pluginsorter/docs/changelog.txt +++ b/core/components/pluginsorter/docs/changelog.txt @@ -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 \ No newline at end of file diff --git a/core/components/pluginsorter/docs/readme.txt b/core/components/pluginsorter/docs/readme.txt index 4839931..7d27748 100644 --- a/core/components/pluginsorter/docs/readme.txt +++ b/core/components/pluginsorter/docs/readme.txt @@ -1,11 +1,11 @@ -------------------------------------------------------------------------------- -Extra : PluginSorter +Extra : Plugin Sorter -------------------------------------------------------------------------------- Since : April 23th, 2013 Author : Romain Tripault // Melting Media -------------------------------------------------------------------------------- -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 diff --git a/manager/components/pluginsorter/js/home/plugins.grid.js b/manager/components/pluginsorter/js/home/plugins.grid.js index 217c3be..7786609 100644 --- a/manager/components/pluginsorter/js/home/plugins.grid.js +++ b/manager/components/pluginsorter/js/home/plugins.grid.js @@ -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')