You are here

function _advanced_help_parse_ini in Advanced Help 6

Same name and namespace in other branches
  1. 7 advanced_help.module \_advanced_help_parse_ini()

Funtion 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 696
Pluggable system to provide advanced help facilities for Drupal and modules.

Code

function _advanced_help_parse_ini() {
  static $cache = NULL;
  if (!isset($cache)) {
    $cache = array(
      'topics' => array(),
      'settings' => array(),
    );
    $help_path = drupal_get_path('module', 'advanced_help') . '/modules';
    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);
      $info = array();
      if (file_exists("{$module_path}/help/{$module}.help.ini")) {
        $path = "{$module_path}/help";
        $info = parse_ini_file("./{$module_path}/help/{$module}.help.ini", TRUE);
      }
      elseif (file_exists("{$help_path}/{$module}/{$module}.help.ini")) {
        $path = "{$help_path}/{$module}";
        $info = parse_ini_file("./{$help_path}/{$module}/{$module}.help.ini", TRUE);
      }
      elseif (!file_exists("{$module_path}/help")) {

        // Look for one or more README files (old erg).
        $files = file_scan_directory("./{$module_path}", '^(README|readme).*\\.(txt|TXT|md|MD)$', array(
          '.',
          '..',
          'CVS',
        ), 0, FALSE);
        $path = "./{$module_path}";
        foreach ($files as $name => $fileinfo) {
          $info[$fileinfo->basename] = array(
            'line break' => TRUE,
            'readme file' => TRUE,
            'file' => $fileinfo->basename,
            'title' => $fileinfo->name,
          );
        }
      }
      if (!empty($info)) {

        // Get translated titles:
        global $language;
        $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);
        }
        $cache['settings'][$module] = array();
        if (!empty($info['advanced help settings'])) {
          $cache['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'])) {
            $cache['settings']['name'] = $translation['advanced help settings']['name'];
          }
          if (isset($translation['advanced help settings']['index name'])) {
            $cache['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 the path.
          $file = !empty($topic['file']) ? $topic['file'] : $name;
          $cache['topics'][$module][$name] = array(
            'name' => $name,
            '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' => $path,
            'readme file' => isset($topic['readme file']) ? $topic['readme file'] : (isset($cache['settings'][$module]['readme file']) ? $cache['settings'][$module]['readme file'] : FALSE),
            'line break' => isset($topic['line break']) ? $topic['line break'] : (isset($cache['settings'][$module]['line break']) ? $cache['settings'][$module]['line break'] : FALSE),
            'navigation' => isset($topic['navigation']) ? $topic['navigation'] : (isset($cache['settings'][$module]['navigation']) ? $cache['settings'][$module]['navigation'] : TRUE),
            'css' => isset($topic['css']) ? $topic['css'] : (isset($cache['settings'][$module]['css']) ? $cache['settings'][$module]['css'] : NULL),
          );
        }
      }
    }
    drupal_alter('advanced_help_topic_info', $cache);
  }
  return $cache;
}