/**
  * Do the necessary processing on content that came from the user, for example
  * the question text or general feedback. The result of calling this method is
  * then passed to Moodle's {@link format_text()} function.
  * @param string $text the content to process.
  * @param qtype_stack_renderer $renderer (options) the STACK renderer, if you have one.
  * @return string the content ready to pass to format_text.
  */
 public function process_display_castext($text, $replacedollars, qtype_stack_renderer $renderer = null)
 {
     if ($replacedollars) {
         $text = $this->replace_dollars($text);
     }
     $text = str_replace('!ploturl!', moodle_url::make_file_url('/question/type/stack/plot.php', '/'), $text);
     $text = stack_fact_sheets::display($text, $renderer);
     return $text;
 }
 /**
  * Validate a CAS text field.
  * @param array $errors the errors array that validation is assembling.
  * @param string $value the submitted value validate.
  * @param string $fieldname the name of the field add any errors to.
  * @param string $savesession the array key to save the session to in $this->validationcasstrings.
  * @return array updated $errors array.
  */
 protected function validate_cas_text($errors, $value, $fieldname, $fixingdollars, $session = null)
 {
     if (!$fixingdollars && strpos($value, '$$') !== false) {
         $errors[$fieldname][] = stack_string('forbiddendoubledollars');
     }
     $castext = new stack_cas_text($value, $session, $this->seed, 't');
     if (!$castext->get_valid()) {
         $errors[$fieldname][] = $castext->get_errors();
         return $errors;
     }
     // Validate any [[facts:...]] tags.
     $unrecognisedtags = stack_fact_sheets::get_unrecognised_tags($value);
     if ($unrecognisedtags) {
         $errors[$fieldname][] = stack_string('unrecognisedfactstags', array('tags' => implode(', ', $unrecognisedtags)));
         return $errors;
     }
     if ($session) {
         $display = $castext->get_display_castext();
         if ($castext->get_errors()) {
             $errors[$fieldname][] = $castext->get_errors();
             return $errors;
         }
     }
     return $errors;
 }
 /**
  * Replace STACK 2 tags in the question text with new ones.
  * @param  string incoming question text
  * @param  array input names
  * @return string converted raw keyvals.
  */
 public function convert_questiontext($questiontext, $inputnames)
 {
     foreach ($inputnames as $name) {
         $questiontext = str_replace('#' . $name . '#', "[[input:{$name}]]", $questiontext);
         $questiontext = str_replace('<IEfeedback>' . $name . '</IEfeedback>', "[[validation:{$name}]]", $questiontext);
     }
     $questiontext = stack_fact_sheets::convert_legacy_tags($questiontext);
     return $this->fix_maths_delimiters($questiontext);
 }
Example #4
0
/**
 * @param string $page countent in Markdown format.
 * @param string $docscontent base URL for linking to images etc.
 * @return string HTML content.
 */
function stack_docs_render_markdown($page, $docscontent)
{
    // Put in links to images etc.
    $page = preg_replace('~(?<!\\\\)%CONTENT~', $docscontent, $page);
    $page = str_replace('\\%CONTENT', '%CONTENT', $page);
    $page = stack_maths::pre_process_docs_page($page);
    if (strpos($page, '[[ALL_FACTS]]') > 0) {
        $page = str_replace('[[ALL_FACTS]]', stack_fact_sheets::generate_docs(), $page);
    }
    $page = format_text($page, $format = FORMAT_MARKDOWN);
    $page = stack_maths::post_process_docs_page($page);
    return $page;
}
 public function test_legacy_convert()
 {
     $this->assertEquals("An [[facts:old_hint]] and [[facts:older_hint]].", stack_fact_sheets::convert_legacy_tags("An <hint>old_hint</hint> and <hint>older_hint</hint>."));
 }