function _advanced_help_parse_ini in Advanced Help 7
Same name and namespace in other branches
- 6 advanced_help.module \_advanced_help_parse_ini()
Function to parse ini / txt files.
2 calls to _advanced_help_parse_ini()
- advanced_help_get_settings in ./
advanced_help.module - Returns advanced help settings.
- advanced_help_get_topics in ./
advanced_help.module - Search the system for all available help topics.
File
- ./
advanced_help.module, line 875 - Pluggable system to provide advanced help facilities for Drupal and modules.
Code
function _advanced_help_parse_ini() {
global $language;
static $ini = NULL;
if (!isset($ini)) {
$cache = cache_get('advanced_help_ini:' . $language->language);
if ($cache) {
$ini = $cache->data;
}
}
if (!isset($ini)) {
// No cached list of topics - create it.
$ini = array(
'topics' => array(),
'settings' => array(),
);
foreach (array_merge(module_list(), list_themes()) as $plugin) {
$module = is_string($plugin) ? $plugin : $plugin->name;
$module_path = drupal_get_path(is_string($plugin) ? 'module' : 'theme', $module);
// Parse ini-file if it exists
if (file_exists("{$module_path}/help/{$module}.help.ini")) {
$path_html = "{$module_path}/help";
$info = parse_ini_file("./{$module_path}/help/{$module}.help.ini", TRUE);
if (!$info) {
drupal_set_message(t('There is a syntax error in the default .ini-file. Unable to display topics.'), 'error');
}
}
else {
$info = array();
}
if (empty($info) || !empty($info['advanced help settings']['show readme'])) {
// Look for one or more README files.
$files = file_scan_directory("./{$module_path}", '/^(readme).*\\.(txt|md)$/i', array(
'recurse' => FALSE,
));
$path_readme = "{$module_path}";
foreach ($files as $name => $fileinfo) {
$info[$fileinfo->filename] = array(
'line break' => TRUE,
'readme file' => TRUE,
'file' => $fileinfo->filename,
'title' => $fileinfo->name,
'weight' => -99,
);
}
}
if (!empty($info)) {
// Get translated titles:
$translation = array();
if (file_exists("{$module_path}/translations/help/{$language->language}/{$module}.help.ini")) {
$translation = parse_ini_file("{$module_path}/translations/help/{$language->language}/{$module}.help.ini", TRUE);
if (!$translation) {
drupal_set_message(t('There is a syntax error in the translated .ini-file.'), 'error');
}
}
$ini['settings'][$module] = array();
if (!empty($info['advanced help settings'])) {
$ini['settings'][$module] = $info['advanced help settings'];
unset($info['advanced help settings']);
// Check translated strings for translatable global settings.
if (isset($translation['advanced help settings']['name'])) {
$ini['settings']['name'] = $translation['advanced help settings']['name'];
}
if (isset($translation['advanced help settings']['index name'])) {
$ini['settings']['index name'] = $translation['advanced help settings']['index name'];
}
}
foreach ($info as $name => $topic) {
// Each topic should have a name, a title, a file and path.
$file = !empty($topic['file']) ? $topic['file'] : $name;
$ini['topics'][$module][$name] = array(
'name' => $name,
'module' => $module,
'ini' => $topic,
'title' => !empty($translation[$name]['title']) ? $translation[$name]['title'] : $topic['title'],
'weight' => isset($topic['weight']) ? $topic['weight'] : 0,
'parent' => isset($topic['parent']) ? $topic['parent'] : 0,
'popup width' => isset($topic['popup width']) ? $topic['popup width'] : 500,
'popup height' => isset($topic['popup height']) ? $topic['popup height'] : 500,
// Require extension.
'file' => isset($topic['readme file']) ? $file : $file . '.html',
// Not in .ini file.
'path' => isset($topic['readme file']) ? $path_readme : $path_html,
'line break' => isset($topic['line break']) ? $topic['line break'] : (isset($ini['settings'][$module]['line break']) ? $ini['settings'][$module]['line break'] : FALSE),
'navigation' => isset($topic['navigation']) ? $topic['navigation'] : (isset($ini['settings'][$module]['navigation']) ? $ini['settings'][$module]['navigation'] : TRUE),
'show readme' => isset($topic['show readme']) ? $topic['show readme'] : (isset($ini['settings'][$module]['show readme']) ? $ini['settings'][$module]['show readme'] : FALSE),
'css' => isset($topic['css']) ? $topic['css'] : (isset($ini['settings'][$module]['css']) ? $ini['settings'][$module]['css'] : NULL),
'readme file' => isset($topic['readme file']) ? $topic['readme file'] : FALSE,
);
}
}
}
drupal_alter('advanced_help_topic_info', $ini);
cache_set('advanced_help_ini:' . $language->language, $ini);
}
return $ini;
}