function advanced_help_view_topic in Advanced Help 6
Same name and namespace in other branches
- 5 advanced_help.module \advanced_help_view_topic()
- 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 - Implements hook_search().
- advanced_help_topic_page in ./
advanced_help.module - Page callback to view a help topic.
File
- ./
advanced_help.module, line 538 - Pluggable system to provide advanced help facilities for Drupal and modules.
Code
function advanced_help_view_topic($module, $topic, $popup = FALSE) {
$file_info = advanced_help_get_topic_file_info($module, $topic);
if ($file_info) {
$info = advanced_help_get_topic($module, $topic);
$file = "./{$file_info['path']}/{$file_info['file']}";
$output = file_get_contents($file);
if (isset($info['readme file']) && $info['readme file']) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ('md' == $ext && module_exists('markdown')) {
$result = module_invoke('markdown', 'filter', 'process', 0, -1, $output);
$output = '<div class="advanced-help-topic"><br/>' . filter_xss_admin($result) . '</div>';
}
else {
$output = '<p>' . t('If you install the !module module, this text below will be filtered by the module, producing rich text.', array(
'!module' => l(t('Markdown filter'), 'https://www.drupal.org/project/markdown', array(
'attributes' => array(
'title' => t('Link to project.'),
),
)),
)) . '</p>' . '<div class="advanced-help-topic"><pre class="readme">' . check_plain($output) . '</pre></div>';
}
return $output;
}
// Make some exchanges. The strtr is because url() translates $ into %24
// but we need to change it back for the regex replacement.
//
// Change 'topic:' to the URL for another help topic.
if ($popup) {
$output = preg_replace('/href="topic:([^"]+)"/', 'href="' . strtr(url('help/$1', array(
'query' => 'popup=true',
)), array(
'%24' => '$',
)) . '"', $output);
$output = preg_replace('/src="topic:([^"]+)"/', 'src="' . strtr(url('help/$1', array(
'query' => 'popup=true',
)), array(
'%24' => '$',
)) . '"', $output);
$output = preg_replace('/&topic:([^"]+)&/', strtr(url('help/$1', array(
'query' => '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);
$output = preg_replace('/&topic:([^"]+)&/', 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);
$output = str_replace('&path&', $base_path . $info['path'] . '/', $output);
// Change 'trans_path:' to the URL to the actual help directory.
$output = preg_replace('/href="trans_path:([^"]+)"/', 'href="' . $base_path . $file_info['path'] . '/$1"', $output);
$output = preg_replace('/src="trans_path:([^"]+)"/', 'src="' . $base_path . $file_info['path'] . '/$1"', $output);
$output = str_replace('&trans_path&', $base_path . $file_info['path'] . '/', $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);
$output = str_replace('&base_url&', $base_path, $output);
// 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);
}
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'];
if ($parent_topic) {
$parent = $topics[$module][$topic]['_parent'];
$up = "help/{$parent[0]}/{$parent[1]}";
}
else {
$up = "admin/advanced_help/{$module}";
}
$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 || $up || $next) {
$navigation = '<div class="help-navigation clear-block">';
if ($prev) {
$navigation .= advanced_help_l('<< ' . $topics[$prev[0]][$prev[1]]['title'], "help/{$prev[0]}/{$prev[1]}", array(
'attributes' => array(
'class' => 'help-left',
),
));
}
if ($up) {
$navigation .= advanced_help_l(t('Up'), $up, array(
'attributes' => array(
'class' => $prev ? 'help-up' : 'help-up-noleft',
),
));
}
if ($next) {
$navigation .= advanced_help_l($topics[$next[0]][$next[1]]['title'] . ' >>', "help/{$next[0]}/{$next[1]}", array(
'attributes' => array(
'class' => 'help-right',
),
));
}
$navigation .= '</div>';
$output .= $navigation;
}
}
if (!empty($info['css'])) {
drupal_add_css($info['path'] . '/' . $info['css']);
}
$output = '<div class="advanced-help-topic">' . $output . '</div>';
drupal_alter('advanced_help_topic', $output, $popup);
return $output;
}
}