You are here

function advanced_help_view_topic in Advanced Help 5

Same name and namespace in other branches
  1. 6 advanced_help.module \advanced_help_view_topic()
  2. 7 advanced_help.module \advanced_help_view_topic()

Load and render a help topic.

2 calls to advanced_help_view_topic()
advanced_help_search in ./advanced_help.module
Implementation of hook_search()
advanced_help_topic_page in ./advanced_help.module
Page callback to view a help topic.

File

./advanced_help.module, line 456
advanced_help.module

Code

function advanced_help_view_topic($module, $topic, $popup = FALSE) {
  $file = advanced_help_get_topic_filename($module, $topic);
  $info = advanced_help_get_topic($module, $topic);
  if ($file) {

    // @todo is this trusted output?
    $output = file_get_contents($file);

    // Make some exchanges. The strtr is because url() translates $ into %24
    // but we need to change it back for the regex replacement.
    // Run the line break filter if requested
    if (!empty($info['line break'])) {

      // Remove the header since it adds an extra <br /> to the filter.
      $output = preg_replace('/^<!--[^\\n]*-->\\n/', '', $output);
      $output = _filter_autop($output);
    }

    // Change 'topic:' to the URL for another help topic.
    if ($popup) {
      $output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1', 'popup=true'), array(
        '%24' => '$',
      )) . '"', $output);
      $output = preg_replace('/src="topic:([^"]+)"/', 'src="' . strtr(url('help/$1', 'popup=true'), array(
        '%24' => '$',
      )) . '"', $output);
    }
    else {
      $output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1'), array(
        '%24' => '$',
      )) . '"', $output);
      $output = preg_replace('/src="topic:([^"]+)"/', 'src="' . strtr(url('help/$1'), array(
        '%24' => '$',
      )) . '"', $output);
    }
    global $base_path;

    // Change 'path:' to the URL to the base help directory.
    $output = preg_replace('/href="path:([^"]+)"/', 'href="' . $base_path . $info['path'] . '/$1"', $output);
    $output = preg_replace('/src="path:([^"]+)"/', 'src="' . $base_path . $info['path'] . '/$1"', $output);

    // Change 'base_url:' to the URL to the site.
    $output = preg_replace('/href="base_url:([^"]+)"/', 'href="' . strtr(url('$1'), array(
      '%24' => '$',
    )) . '"', $output);
    $output = preg_replace('/src="base_url:([^"]+)"/', 'src="' . strtr(url('$1'), array(
      '%24' => '$',
    )) . '"', $output);
    if (!empty($info['navigation'])) {
      $topics = advanced_help_get_topics();
      advanced_help_get_topic_hierarchy($topics);
      if (!empty($topics[$module][$topic]['children'])) {
        $items = advanced_help_get_tree($topics, $topics[$module][$topic]['children']);
        $output .= theme('item_list', $items);
      }
      list($parent_module, $parent_topic) = $topics[$module][$topic]['_parent'];
      $siblings = $topics[$parent_module][$parent_topic]['children'];
      uasort($siblings, 'advanced_help_uasort');
      $prev = $next = NULL;
      $found = FALSE;
      foreach ($siblings as $sibling) {
        list($sibling_module, $sibling_topic) = $sibling;
        if ($found) {
          $next = $sibling;
          break;
        }
        if ($sibling_module == $module && $sibling_topic == $topic) {
          $found = TRUE;
          continue;
        }
        $prev = $sibling;
      }
      if ($prev || $next) {
        $navigation = '<div class="help-navigation clear-block">';
        $navigation .= '<div class="help-previous">';
        if ($prev) {
          $navigation .= advanced_help_l('<< ' . $topics[$prev[0]][$prev[1]]['title'], "help/{$prev[0]}/{$prev[1]}");
        }
        $navigation .= '</div>';
        $navigation .= '<div class="help-next">';
        if ($next) {
          $navigation .= advanced_help_l($topics[$next[0]][$next[1]]['title'] . ' >>', "help/{$next[0]}/{$next[1]}");
        }
        $navigation .= '</div>';
        $navigation .= '</div>';
        $output .= $navigation;
      }
    }
    if (!empty($info['css'])) {
      drupal_add_css($info['path'] . '/' . $info['css']);
    }
    return '<div class="advanced-help-topic">' . $output . '</div>';
  }
}