diff -r 2b826f2640e9 -r 94214ec0871c plugins/admin/PluginManager.php
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/plugins/admin/PluginManager.php Sun Apr 06 15:30:39 2008 -0400
@@ -0,0 +1,261 @@
+
+ /**!blocktype( param1 = "value1" [ param2 = "value2" ... ] )**
+
+ ... block content ...
+
+ **!* / (remove that last space)
+
+ * The format inside blocks varies. Metadata and language strings will be in JSON; installation and upgrade schemas will be in
+ * SQL. You can include an external file into a block using the following syntax inside of a block:
+
+ !include "path/to/file"
+
+ * The file will always be relative to the Enano root. So if your plugin has a language file in ENANO_ROOT/plugins/fooplugin/,
+ * you would use "plugins/fooplugin/language.json".
+ *
+ * The format for plugin metadata is as follows:
+
+ /**!info**
+ {
+ "Plugin Name" : "Foo plugin",
+ "Plugin URI" : "http://fooplugin.enanocms.org/",
+ "Description" : "Some short descriptive text",
+ "Author" : "John Doe",
+ "Version" : "0.1",
+ "Author URI" : "http://yourdomain.com/",
+ "Version list" : [ "0.1-alpha1", "0.1-alpha2", "0.1-beta1", "0.1" ]
+ }
+ **!* /
+
+ * This is the format for language data:
+
+ /**!language**
+ {
+ eng: {
+ categories: [ 'meta', 'foo', 'bar' ],
+ strings: {
+ meta: {
+ foo: "Foo strings",
+ bar: "Bar strings"
+ },
+ foo: {
+ string_name: "string value",
+ string_name_2: "string value 2"
+ }
+ }
+ }
+ }
+ **!* / (once more, remove the space in there)
+
+ * Here is the format for installation schemas:
+
+ /**!install**
+
+ CREATE TABLE {{TABLE_PREFIX}}foo_table(
+ ...
+ )
+
+ **!* /
+
+ * And finally, the format for upgrade schemas:
+
+ /**!upgrade from = "0.1-alpha1" to = "0.1-alpha2" **
+
+ **!* /
+
+ * Remember that upgrades will always be done incrementally, so if the user is upgrading 0.1-alpha2 to 0.1, Enano's plugin
+ * engine will run the 0.1-alpha2 to 0.1-beta1 upgrader, then the 0.1-beta1 to 0.1 upgrader, going by the versions listed in
+ * the example metadata block above.
+ *
+ * All of this information is effective as of Enano 1.1.4.
+ */
+
+// Plugin manager "2.0"
+
+function page_Admin_PluginManager()
+{
+ global $db, $session, $paths, $template, $plugins; // Common objects
+ global $lang;
+ if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
+ {
+ $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
+ echo '
' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '
'; + return; + } + + // Are we processing an AJAX request from the smartform? + if ( $paths->getParam(0) == 'action.json' ) + { + // Set to application/json to discourage advertisement scripts + header('Content-Type: application/json'); + + // Init return data + $return = array('mode' => 'error', 'error' => 'undefined'); + + // Start parsing process + try + { + // Is the request properly sent on POST? + if ( isset($_POST['r']) ) + { + // Try to decode the request + $request = enano_json_decode($_POST['r']); + // Is the action to perform specified? + if ( isset($request['mode']) ) + { + switch ( $request['mode'] ) + { + default: + // The requested action isn't something this script knows how to do + $return = array( + 'mode' => 'error', + 'error' => 'Unknown mode "' . $request['mode'] . '" sent in request' + ); + break; + } + } + else + { + // Didn't specify action + $return = array( + 'mode' => 'error', + 'error' => 'Missing key "mode" in request' + ); + } + } + else + { + // Didn't send a request + $return = array( + 'mode' => 'error', + 'error' => 'No request specified' + ); + } + } + catch ( Exception $e ) + { + // Sent a request but it's not valid JSON + $return = array( + 'mode' => 'error', + 'error' => 'Invalid request - JSON parsing failed' + ); + } + + echo enano_json_encode($return); + + return true; + } + + // + // Not a JSON request, output normal HTML interface + // + + // Scan all plugins + $plugin_list = array(); + + if ( $dirh = @opendir( ENANO_ROOT . '/plugins' ) ) + { + while ( $dh = @readdir($dirh) ) + { + if ( !preg_match('/\.php$/i', $dh) ) + continue; + $fullpath = ENANO_ROOT . "/plugins/$dh"; + // it's a PHP file, attempt to read metadata + // pass 1: try to read a !info block + $blockdata = $plugins->parse_plugin_blocks($fullpath, 'info'); + if ( empty($blockdata) ) + { + // no !info block, check for old header + $fh = @fopen($fullpath, 'r'); + if ( !$fh ) + // can't read, bail out + continue; + $plugin_data = array(); + for ( $i = 0; $i < 8; $i++ ) + { + $plugin_data[] = @fgets($fh, 8096); + } + // close our file handle + fclose($fh); + // is the header correct? + if ( trim($plugin_data[0]) != ' $value ) + { + $plugin_meta[ strtolower($key) ] = $value; + } + } + if ( !isset($plugin_meta) || !is_array(@$plugin_meta) ) + { + // parsing didn't work. + continue; + } + // check for required keys + $required_keys = array('plugin name', 'plugin uri', 'description', 'author', 'version', 'author uri'); + foreach ( $required_keys as $key ) + { + if ( !isset($plugin_meta[$key]) ) + // not set, skip this plugin + continue 2; + } + // all checks passed + $plugin_list[$dh] = $plugin_meta; + } + } + echo '' . print_r($plugin_list, true) . ''; +}