Commit 040fc917 authored by Penny Leach's avatar Penny Leach
Browse files

contextual help now calls a json page that does language parent stuff

and cleverness
parent 90c1af8f
......@@ -71,7 +71,7 @@ var ctxHelp = new Array();
var ctxHelp_selected;
var container;
function contextualHelp(formName, helpName, pluginType, pluginName, language) {
function contextualHelp(formName, helpName, pluginType, pluginName, page) {
var tooltip = $('tooltip');
log(tooltip);
log(ctxHelp_selected);
......@@ -97,12 +97,26 @@ function contextualHelp(formName, helpName, pluginType, pluginName, language) {
log('no help for this key yet, getting...');
ctxHelp[key] = new Object();
processingStart();
var d = loadJSONDoc('../lang/' + language + '/help/' + formName + '.' + helpName + '.html');
var url = '../json/help.php?plugintype=' + pluginType + '&pluginname=' + pluginName;
if (page) {
url += '&page=' + page;
}
else {
url += '&form=' + formName + '&element=' + helpName;
}
var d = loadJSONDoc(url);
d.addCallbacks(
function (data) {
ctxHelp[key].content = data;
container.innerHTML = ctxHelp[key].content;
processingStop();
if (data.error) {
ctxHelp[key].content = data.message;
container.innerHTML = ctxHelp[key].content;
processingStop();
}
else {
ctxHelp[key].content = data.content;
container.innerHTML = ctxHelp[key].content;
processingStop();
}
},
function () {
ctxHelp[key].content = '<p>Sorry, no help for this element could be found</p>';
......
<?php
/**
* This program is part of Mahara
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* @package mahara
* @subpackage core
* @author Penny Leach <penny@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', 1);
require(dirname(dirname(__FILE__)) . '/init.php');
json_headers();
$plugintype = param_alpha('plugintype');
$pluginname = param_alpha('pluginname');
$page = param_alpha('page', null);
$form = param_alpha('form', null);
$element = param_alpha('element', null);
$location = get_config('docroot') ;
$file = 'help/';
if ($plugintype != 'core') {
$location .= $plugintype . '/' . $pluginname . '/lang/';
}
else {
$location .= 'lang/';
}
if ($page) {
$file .= $page . '.html';
}
else if (!empty($form) && !empty($element)) {
$file .= 'forms/' . $form . '.' . $element . '.html';
}
else if (!empty($form) && empty($element)) {
$file .= 'forms/' . $form . '.html';
}
else {
json_reply(true, get_string('nohelpfound'));
}
// now we have to try and locate the help file
$lang = current_language();
if ($lang == 'en.utf8') {
$trieden = true;
}
else {
$trieden = false;
}
// try the current language
$langfile = $location . $lang . '/' . $file;
if (is_readable($langfile)) {
$data = file_get_contents($langfile);
}
// if it's not found, try the parent language if there is one...
if (empty($data) && empty($trieden)) {
$langfile = $location . $lang . '/langconfig.php';
if ($parentlang = get_string_from_file('parentlanguage', $langfile)) {
if ($parentlang == 'en.utf8') {
$trieden = true;
}
$langfile = $location . $parentlang . '/' . $file;
if (is_readable($langfile)) {
$data = file_get_contents($langfile);
}
}
}
// if it's STILL not found, and we haven't already tried english ...
if (empty($data) && empty($trieden)) {
$langfile = $location . 'en.utf8/' . $file;
if (is_readable($langfile)) {
$data = file_get_contents($langfile);
}
}
if (empty($data)) {
json_reply(true, get_string('nohelpfound'));
}
$json = array('error' => false, 'content' => $data);
echo json_encode($json);
exit;
?>
......@@ -208,4 +208,6 @@ $string['height'] = 'Height';
$string['widthshort'] = 'w';
$string['heightshort'] = 'h';
$string['nohelpfound'] = 'There was no help found for this item';
?>
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