diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/common.inc | 111 | ||||
-rw-r--r-- | includes/install.inc | 3 | ||||
-rw-r--r-- | includes/module.inc | 69 | ||||
-rw-r--r-- | includes/theme.inc | 10 |
4 files changed, 134 insertions, 59 deletions
diff --git a/includes/common.inc b/includes/common.inc index ebbb75c14..f9c401f39 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2482,3 +2482,114 @@ function drupal_common_themes() { ), ); } + +/** + * Parse Drupal info file format. + * + * Files should use an ini-like format to specify values. + * White-space generally doesn't matter, except inside values. + * e.g. + * key = value + * key = "value" + * key = 'value' + * key = "multi-line + * + * value" + * key = 'multi-line + * + * value' + * + * Arrays are created using a GET-like syntax: + * + * key[] = "numeric array" + * key[index] = "associative array" + * key[index][] = "nested numeric array" + * key[index][index] = "nested associative array" + * + * PHP constants are substituted in, but only when used as the entire value. + * + * Comments should start with a semi-colon at the beginning of a line. + * + * This function is NOT for placing arbitrary module-specific settings. Use + * variable_get() and variable_set() for that. + * + * Information stored in the module.info file: + * name - The real name of the module for display purposes. + * description - A brief description of the module. + * dependencies - An array of short names (shortname) of other modules this + * module depends on. + * package - The name of the package of modules this module belongs to. + * + * Example of .info file: + * name = Forum + * description = Enables threaded discussions about general topics. + * dependencies[] = taxonomy + * dependencies[] = comment + * package = Core - optional + * version = VERSION + * + * @param $filename + * The file we are parsing. Accepts file with relative or absolute path. + * @return + * The info array. + */ +function drupal_parse_info_file($filename) { + $info = array(); + + if (!file_exists($filename)) { + return $info; + } + + $data = file_get_contents($filename); + if (preg_match_all(' + @^\s* # Start at the beginning of a line, ignoring leading whitespace + ((?: + [^=;\[\]]| # Key names cannot contain equal signs, semi-colons or square brackets, + \[[^\[\]]*\] # unless they are balanced and not nested + )+?) + \s*=\s* # Key/value pairs are separated by equal signs (ignoring white-space) + (?: + ("(?:[^"]|(?<=\\\\)")*")| # Double-quoted string, which may contain slash-escaped quotes/slashes + (\'(?:[^\']|(?<=\\\\)\')*\')| # Single-quoted string, which may contain slash-escaped quotes/slashes + ([^\r\n]*?) # Non-quoted string + )\s*$ # Stop at the next end of a line, ignoring trailing whitespace + @msx', $data, $matches, PREG_SET_ORDER)) { + foreach ($matches as $match) { + // Fetch the key and value string + $i = 0; + foreach (array('key', 'value1', 'value2', 'value3') as $var) { + $$var = isset($match[++$i]) ? $match[$i] : ''; + } + $value = stripslashes(substr($value1, 1, -1)) . stripslashes(substr($value2, 1, -1)) . $value3; + + // Parse array syntax + $keys = preg_split('/\]?\[/', rtrim($key, ']')); + $last = array_pop($keys); + $parent = &$info; + + // Create nested arrays + foreach ($keys as $key) { + if ($key == '') { + $key = count($parent); + } + if (!isset($parent[$key]) || !is_array($parent[$key])) { + $parent[$key] = array(); + } + $parent = &$parent[$key]; + } + + // Handle PHP constants + if (defined($value)) { + $value = constant($value); + } + + // Insert actual value + if ($last == '') { + $last = count($parent); + } + $parent[$last] = $value; + } + } + + return $info; +} diff --git a/includes/install.inc b/includes/install.inc index e08196996..a5d362f5f 100644 --- a/includes/install.inc +++ b/includes/install.inc @@ -311,8 +311,7 @@ function drupal_install_profile($profile, $module_list) { module_invoke('system', 'install'); $system_versions = drupal_get_schema_versions('system'); $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED; - db_query("INSERT INTO {system} (filename, name, type, description, status, throttle, bootstrap, schema_version) VALUES('%s', '%s', 'module', '', 1, 0, 0, %d)", $system_path .'/system.module', 'system', $system_version); - + db_query("INSERT INTO {system} (filename, name, type, owner, status, throttle, bootstrap, schema_version) VALUES('%s', '%s', 'module', '', 1, 0, 0, %d)", $system_path .'/system.module', 'system', $system_version); // Now that we've installed things properly, bootstrap the full Drupal environment drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); diff --git a/includes/module.inc b/includes/module.inc index 99b10043a..619bf3370 100644 --- a/includes/module.inc +++ b/includes/module.inc @@ -102,16 +102,27 @@ function module_rebuild_cache() { ksort($files); + // Set defaults for module info + $defaults = array( + 'dependencies' => array(), + 'dependents' => array(), + 'description' => '', + 'version' => NULL + ); + foreach ($files as $filename => $file) { - $file->info = _module_parse_info_file(dirname($file->filename) .'/'. $file->name .'.info'); + // Look for the info file. + $file->info = drupal_parse_info_file(dirname($file->filename) .'/'. $file->name .'.info'); + // Skip modules that don't provide info. if (empty($file->info)) { unset($files[$filename]); continue; } - $files[$filename]->info = $file->info; + // Merge in defaults and save. + $files[$filename]->info = $file->info + $defaults; - // log the critical hooks implemented by this module + // Log the critical hooks implemented by this module. $bootstrap = 0; foreach (bootstrap_hooks() as $hook) { if (module_hook($file->name, $hook)) { @@ -121,15 +132,14 @@ function module_rebuild_cache() { } // Update the contents of the system table: - // TODO: We shouldn't actually need this description field anymore. Remove me next release. if (isset($file->status) || (isset($file->old_filename) && $file->old_filename != $file->filename)) { - db_query("UPDATE {system} SET description = '%s', name = '%s', filename = '%s', bootstrap = %d WHERE filename = '%s'", $file->info['description'], $file->name, $file->filename, $bootstrap, $file->old_filename); + db_query("UPDATE {system} SET info = '%s', name = '%s', filename = '%s', bootstrap = %d WHERE filename = '%s'", serialize($file->info), $file->name, $file->filename, $bootstrap, $file->old_filename); } else { // This is a new module. $files[$filename]->status = 0; $files[$filename]->throttle = 0; - db_query("INSERT INTO {system} (name, description, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, $file->info['description'], 'module', $file->filename, 0, 0, $bootstrap); + db_query("INSERT INTO {system} (name, info, type, filename, status, throttle, bootstrap) VALUES ('%s', '%s', '%s', '%s', %d, %d, %d)", $file->name, serialize($file->info), 'module', $file->filename, 0, 0, $bootstrap); } } $files = _module_build_dependents($files); @@ -160,53 +170,6 @@ function _module_build_dependents($files) { } /** - * Parse Drupal info file format. - * Uses ini parser provided by php's parse_ini_file(). - * - * Files should use the ini format to specify values. - * e.g. - * key = "value" - * key2 = value2 - * - * Some things to be aware of: - * - This function is NOT for placing arbitrary module-specific settings. Use variable_get() - * and variable_set() for that. - * - You may not use double-quotes in a value. - * - * Information stored in the module.info file: - * name - The real name of the module for display purposes. - * description - A brief description of the module. - * dependencies - A space delimited list of the short names (shortname) of other modules this module depends on. - * package - The name of the package of modules this module belongs to. - * - * Example of .info file: - * name = Forum - * description = Enables threaded discussions about general topics. - * dependencies = taxonomy comment - * package = Core - optional - * - * @param $filename - * The file we are parsing. Accepts file with relative or absolute path. - * @return - * The info array. - */ -function _module_parse_info_file($filename) { - $info = array(); - - if (file_exists($filename)) { - $info = parse_ini_file($filename); - - if (isset($info['dependencies'])) { - $info['dependencies'] = explode(" ", $info['dependencies']); - } - else { - $info['dependencies'] = NULL; - } - } - return $info; -} - -/** * Determine whether a given module exists. * * @param $module diff --git a/includes/theme.inc b/includes/theme.inc index 8db547614..f35a64e0e 100644 --- a/includes/theme.inc +++ b/includes/theme.inc @@ -59,7 +59,7 @@ function init_theme() { // File is a style; loads its CSS. // Set theme to its template/theme drupal_add_css($themes[$theme]->filename, 'theme'); - $theme = basename(dirname($themes[$theme]->description)); + $theme = basename(dirname($themes[$theme]->owner)); } else { // File is a template/theme @@ -74,10 +74,10 @@ function init_theme() { include_once './'. $themes[$theme]->filename; _theme_load_registry($theme); } - elseif (strpos($themes[$theme]->description, '.engine')) { + elseif (strpos($themes[$theme]->owner, '.engine')) { // file is a template; include its engine - include_once './'. $themes[$theme]->description; - $theme_engine = basename($themes[$theme]->description, '.engine'); + include_once './'. $themes[$theme]->owner; + $theme_engine = basename($themes[$theme]->owner, '.engine'); if (function_exists($theme_engine .'_init')) { call_user_func($theme_engine .'_init', $themes[$theme]); } @@ -210,6 +210,7 @@ function list_themes($refresh = FALSE) { $result = db_query("SELECT * FROM {system} WHERE type = 'theme'"); while ($theme = db_fetch_object($result)) { if (file_exists($theme->filename)) { + $theme->info = unserialize($theme->info); $list[$theme->name] = $theme; } } @@ -238,6 +239,7 @@ function list_theme_engines($refresh = FALSE) { $result = db_query("SELECT * FROM {system} WHERE type = 'theme_engine' AND status = '1' ORDER BY name"); while ($engine = db_fetch_object($result)) { if (file_exists($engine->filename)) { + $engine->info = unserialize($engine->info); $list[$engine->name] = $engine; } } |