Skip to content
Snippets Groups Projects
Commit ae7870bd authored by Chris Sangwin's avatar Chris Sangwin
Browse files

Add in checks to whether the YAML functions exist on your PHP server.

parent 18b86faf
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
* Minimal functionality needed to display and grade a question in a stateless way. * Minimal functionality needed to display and grade a question in a stateless way.
*/ */
if (!function_exists(yaml_parse_file())) {
throw new Exception("To make use of the STACK API you must have support for YAML.");
}
require_once("apilib.php"); require_once("apilib.php");
require_once(__DIR__ . '/../question.php'); require_once(__DIR__ . '/../question.php');
......
...@@ -23,9 +23,11 @@ ...@@ -23,9 +23,11 @@
require_once(__DIR__.'/../../../config.php'); require_once(__DIR__.'/../../../config.php');
if (function_exists('yaml_parse_file')) {
require_once(__DIR__ . '/api/libs/yaml.php'); require_once(__DIR__ . '/api/libs/yaml.php');
require_once(__DIR__ . '/api/libs/yaml_defaults.php'); require_once(__DIR__ . '/api/libs/yaml_defaults.php');
require_once(__DIR__ . '/api/libs/export.php'); require_once(__DIR__ . '/api/libs/export.php');
}
require_once($CFG->libdir . '/questionlib.php'); require_once($CFG->libdir . '/questionlib.php');
require_once($CFG->dirroot . '/question/format/xml/format.php'); require_once($CFG->dirroot . '/question/format/xml/format.php');
...@@ -77,6 +79,10 @@ if ($exportformat == 'xml') { ...@@ -77,6 +79,10 @@ if ($exportformat == 'xml') {
// Send the xml. // Send the xml.
send_file($content, $filename, 0, 0, true, true, $qformat->mime_type()); send_file($content, $filename, 0, 0, true, true, $qformat->mime_type());
} }
if (!function_exists('yaml_parse_file')) {
throw new stack_exception("You must enable YAML support to export in YAML format.");
}
// Add in the conversion to YAML. // Add in the conversion to YAML.
$defaults = new qtype_stack_api_yaml_defaults(null); $defaults = new qtype_stack_api_yaml_defaults(null);
// We take the _site_ defaults here, not the YAML defaults. // We take the _site_ defaults here, not the YAML defaults.
......
...@@ -853,6 +853,9 @@ $string['stackDoc_404message'] = 'File not found.'; ...@@ -853,6 +853,9 @@ $string['stackDoc_404message'] = 'File not found.';
$string['stackDoc_directoryStructure'] = 'Directory structure'; $string['stackDoc_directoryStructure'] = 'Directory structure';
$string['stackDoc_version'] = 'Your site is running STACK version {$a}.'; $string['stackDoc_version'] = 'Your site is running STACK version {$a}.';
// API specific and YAML format.
$string['noyaml'] = '(YAML not supported on this server)';
// Fact sheets. // Fact sheets.
$string['greek_alphabet_name'] = 'The Greek Alphabet'; $string['greek_alphabet_name'] = 'The Greek Alphabet';
......
...@@ -417,11 +417,15 @@ echo html_writer::tag('p', html_writer::link($questionbanklink, ...@@ -417,11 +417,15 @@ echo html_writer::tag('p', html_writer::link($questionbanklink,
stack_string('seethisquestioninthequestionbank'))); stack_string('seethisquestioninthequestionbank')));
if ($canedit) { if ($canedit) {
$links = array(html_writer::link($exportquestionlink, 'XML'));
if (function_exists('yaml_parse_file')) {
$links[] = html_writer::link($yamlquestionlink, 'YAML');
} else {
$links[] = stack_string('noyaml', null);
}
echo html_writer::tag('p', echo html_writer::tag('p',
stack_string('exportthisquestion') . ' ' . stack_string('exportthisquestion') . ' ' .
html_writer::link($exportquestionlink, 'XML') . ' ' . implode($links, ' ') . ' ' . $OUTPUT->help_icon('exportthisquestion', 'qtype_stack'));
html_writer::link($yamlquestionlink, 'YAML') .
$OUTPUT->help_icon('exportthisquestion', 'qtype_stack'));
} }
echo $renderquestion; echo $renderquestion;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment