Commit 05920df5 authored by Penny Leach's avatar Penny Leach
Browse files

added support for page contextual help

parent 04020afd
......@@ -133,7 +133,13 @@ function contextualHelp(formName, helpName, pluginType, pluginName, page) {
log(tooltip);
log(ctxHelp_selected);
var key = pluginType + '/' + pluginName + '/' + helpName;
var key;
if (page) {
key = pluginType + '/' + pluginName + '/' + page;
}
else {
key = pluginType + '/' + pluginName + '/' + helpName;
}
if (typeof(ctxHelp_selected) != 'undefined' && ctxHelp_selected && ctxHelp_selected != key) {
log('chose another help when one was open');
contextualHelpClose();
......@@ -147,7 +153,12 @@ function contextualHelp(formName, helpName, pluginType, pluginName, page) {
else if (ctxHelp[key]) {
log('reloaded help from cache');
ctxHelp_selected = key;
contextualHelpOpen(formName + '_' + helpName, ctxHelp[key].content);
if (page) {
contextualHelpOpen(page, ctxHelp[key].content);
}
else{
contextualHelpOpen(formName + '_' + helpName, ctxHelp[key].content);
}
return;
}
else {
......@@ -182,7 +193,12 @@ function contextualHelp(formName, helpName, pluginType, pluginName, page) {
});
}
contextualHelpOpen(formName + '_' + helpName, 'spinner');
if (page) {
contextualHelpOpen(page, 'spinner');
}
else {
contextualHelpOpen(formName + '_' + helpName, 'spinner');
}
ctxHelp[key] = {
'content': ''
};
......@@ -203,8 +219,8 @@ function contextualHelpOpen(helpName, content) {
var help = DIV({'id': 'tooltip'});
container = DIV({'class':'content'});
container.innerHTML = content;
appendChildNodes(help, container);
appendChildNodes(help, container);
appendChildNodes($(helpName + '_container'), help);
}
......
......@@ -25,6 +25,7 @@
*/
define('INTERNAL', 1);
define('JSON', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
......@@ -32,7 +33,7 @@ json_headers();
$plugintype = param_alpha('plugintype');
$pluginname = param_alpha('pluginname');
$page = param_alpha('page', null);
$page = param_variable('page', null);
$form = param_alpha('form', null);
$element = param_alpha('element', null);
......@@ -46,7 +47,8 @@ else {
$location .= 'lang/';
}
if ($page) {
$file .= $page . '.html';
$page = str_replace('-', '/', $page);
$file .= 'pages/' . $page . '.html';
}
else if (!empty($form) && !empty($element)) {
$file .= 'forms/' . $form . '.' . $element . '.html';
......@@ -55,6 +57,9 @@ else if (!empty($form) && empty($element)) {
$file .= 'forms/' . $form . '.html';
}
else {
if ($page) {
json_reply(true, get_string('nohelpfoundpage'));
}
json_reply(true, get_string('nohelpfound'));
}
......
......@@ -309,6 +309,7 @@ $string['expand'] = 'Expand';
$string['collapse'] = 'Collapse';
$string['more...'] = 'More ...';
$string['nohelpfound'] = 'There was no help found for this item';
$string['nohelpfound'] = 'There was no help found for this page';
$string['profileimage'] = 'Profile image';
// Search
......
......@@ -171,6 +171,8 @@ EOF;
$smarty->assign('THEMEURL', get_config('themeurl'));
$smarty->assign('WWWROOT', $wwwroot);
$sitename = get_config('sitename');
$smarty->assign('title', $sitename);
$smarty->assign('heading', $sitename);
......@@ -194,6 +196,11 @@ EOF;
$smarty->assign('searchform', searchform());
if ($help = has_page_help()) {
$smarty->assign('PAGEHELPNAME', $help[0]);
$smarty->assign('PAGEHELPICON', $help[1]);
}
return $smarty;
}
......@@ -804,9 +811,9 @@ function getoptions_country() {
function get_help_icon($plugintype, $pluginname, $form, $element, $page='') {
return ' <span class="help"><a href="" onclick="contextualHelp(\'' . $form . "', '"
. $element . "', '" . $plugintype . "', '"
. $pluginname . "', '" . $page . "'); return false;\">"
. '?</a></span>';
. $element . "', '" . $plugintype . "', '"
. $pluginname . "', '" . $page . "'); return false;\">"
. '?</a></span>';
}
function make_link($url) {
......@@ -1165,4 +1172,126 @@ function get_loggedin_string() {
}
/**
* Returns the name of the current script, WITH the querystring portion.
* this function is necessary because PHP_SELF and REQUEST_URI and SCRIPT_NAME
* return different things depending on a lot of things like your OS, Web
* server, and the way PHP is compiled (ie. as a CGI, module, ISAPI, etc.)
* <b>NOTE:</b> This function returns false if the global variables needed are not set.
*
* @return string
*/
function get_script_path() {
if (!empty($_SERVER['REQUEST_URI'])) {
return $_SERVER['REQUEST_URI'];
} else if (!empty($_SERVER['PHP_SELF'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['PHP_SELF'];
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['SCRIPT_NAME'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['SCRIPT_NAME'];
} else if (!empty($_SERVER['URL'])) { // May help IIS (not well tested)
if (!empty($_SERVER['QUERY_STRING'])) {
return $_SERVER['URL'] .'?'. $_SERVER['QUERY_STRING'];
}
return $_SERVER['URL'];
} else {
log_warn('Warning: Could not find any of these web server variables: $REQUEST_URI, $PHP_SELF, $SCRIPT_NAME or $URL');
return false;
}
}
/**
* Like {@link me()} but returns a full URL
* @see me()
* @return string
*/
function get_full_script_path() {
global $CFG;
if (!empty($CFG->wwwroot)) {
$url = parse_url($CFG->wwwroot);
}
if (!empty($url['host'])) {
$hostname = $url['host'];
} else if (!empty($_SERVER['SERVER_NAME'])) {
$hostname = $_SERVER['SERVER_NAME'];
} else if (!empty($_ENV['SERVER_NAME'])) {
$hostname = $_ENV['SERVER_NAME'];
} else if (!empty($_SERVER['HTTP_HOST'])) {
$hostname = $_SERVER['HTTP_HOST'];
} else if (!empty($_ENV['HTTP_HOST'])) {
$hostname = $_ENV['HTTP_HOST'];
} else {
log_warn('Warning: could not find the name of this server!');
return false;
}
if (!empty($url['port'])) {
$hostname .= ':'.$url['port'];
} else if (!empty($_SERVER['SERVER_PORT'])) {
if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) {
$hostname .= ':'.$_SERVER['SERVER_PORT'];
}
}
if (isset($_SERVER['HTTPS'])) {
$protocol = ($_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
} else if (isset($_SERVER['SERVER_PORT'])) { # Apache2 does not export $_SERVER['HTTPS']
$protocol = ($_SERVER['SERVER_PORT'] == '443') ? 'https://' : 'http://';
} else {
$protocol = 'http://';
}
$url_prefix = $protocol.$hostname;
return $url_prefix . get_script_path();
}
function has_page_help() {
// the path of the current script (used for page help)
$scriptname = substr(get_full_script_path(), strlen(get_config('wwwroot')));
if (strpos($scriptname, '.php') != (strlen($scriptname) - 4)) {
$scriptname .= 'index.php';
}
$scriptname = substr($scriptname, 0, -4);
$firstdir = $scriptname;
if (false !== ($slashpos = strpos($scriptname, '/'))) {
$firstdir = substr($scriptname, 0, $slashpos);
}
if (in_array($firstdir, plugin_types())) {
$bits = explode('/', $scriptname);
log_debug($bits);
if (count($bits) > 2) {
$plugintype = $bits[0];
$pluginname = $bits[1];
$pagehelp = get_config('docroot') . $plugintype . '/' . $pluginname . '/lang/en.utf8/help/pages/' .
substr($scriptname, strlen($plugintype . '/' . $pluginname . '/')) . '.html';
}
}
if (empty($plugintype)) {
$plugintype = 'core';
$pluginname = 'pages';
$pagehelp = get_config('docroot') . 'lang/en.utf8/help/pages/' . $scriptname . '.html';
}
if (is_readable($pagehelp)) {
$scriptname = str_replace('/', '-', $scriptname);
return array($scriptname, get_help_icon($plugintype, $pluginname, '', '', $scriptname));
}
return false;
}
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment