function process_essay($xml, &$questions) { if (isset($xml["POOL"]["#"]["QUESTION_ESSAY"])) { $essayquestions = $xml["POOL"]["#"]["QUESTION_ESSAY"]; } else { return; } foreach ($essayquestions as $essayquestion) { $question = $this->defaultquestion(); $question->qtype = ESSAY; // determine if the question is already escaped html $ishtml = $essayquestion["#"]["BODY"][0]["#"]["FLAGS"][0]["#"]["ISHTML"][0]["@"]["value"]; // put questiontext in question object if ($ishtml) { $question->questiontext = html_entity_decode_php4(trim($essayquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"])); } // put name in question object $question->name = substr($question->questiontext, 0, 254); $question->answer = ''; $question->feedback = ''; $question->fraction = 0; $questions[] = $question; } }
/** * Reverse function for htmlentities. * Convert entities in UTF-8. * @param $text_to_convert Text to convert. * @return string converted */ function unhtmlentities($text_to_convert) { if (!$this->isunicode) { return html_entity_decode($text_to_convert); } return html_entity_decode_php4($text_to_convert); }
function process_matching($xml, &$questions) { if (isset($xml["POOL"]["#"]["QUESTION_MATCH"])) { $matchquestions = $xml["POOL"]["#"]["QUESTION_MATCH"]; } else { return; } for ($i = 0; $i < sizeof($matchquestions); $i++) { $question = $this->defaultquestion(); $question->qtype = MATCH; $thisquestion = $matchquestions[$i]; // determine if the question is already escaped html $ishtml = $thisquestion["#"]["BODY"][0]["#"]["FLAGS"][0]["#"]["ISHTML"][0]["@"]["value"]; // put questiontext in question object if ($ishtml) { $question->questiontext = html_entity_decode_php4(trim($thisquestion["#"]["BODY"][0]["#"]["TEXT"][0]["#"])); } $question->questiontext = addslashes($question->questiontext); // put name of question in question object $question->name = substr($question->questiontext, 0, 254); $choices = $thisquestion["#"]["CHOICE"]; for ($j = 0; $j < sizeof($choices); $j++) { $subquestion = NULL; $choice = $choices[$j]["#"]["TEXT"][0]["#"]; $choice_id = $choices[$j]["@"]["id"]; $question->subanswers[] = addslashes(trim($choice)); $correctanswers = $thisquestion["#"]["GRADABLE"][0]["#"]["CORRECTANSWER"]; for ($k = 0; $k < sizeof($correctanswers); $k++) { if (strcmp($choice_id, $correctanswers[$k]["@"]["choice_id"]) == 0) { $answer_id = $correctanswers[$k]["@"]["answer_id"]; $answers = $thisquestion["#"]["ANSWER"]; for ($m = 0; $m < sizeof($answers); $m++) { $answer = $answers[$m]; $current_ans_id = $answer["@"]["id"]; if (strcmp($current_ans_id, $answer_id) == 0) { $answer = $answer["#"]["TEXT"][0]["#"]; $question->subquestions[] = addslashes(trim($answer)); break; } } break; } } } $questions[] = $question; } }
/** * Reverse function for htmlentities. * Convert entities in UTF-8. * @param $text_to_convert Text to convert. * @return string converted * @access public */ function unhtmlentities($text_to_convert) { require_once dirname(__FILE__) . '/html_entity_decode_php4.php'; if (!$this->isunicode) { return html_entity_decode($text_to_convert); } return html_entity_decode_php4($text_to_convert); }
/** * Reverse function for htmlentities. * Convert entities in UTF-8. * * @param $text_to_convert Text to convert. * @return string converted */ function unhtmlentities($text_to_convert) { require_once dirname(__FILE__) . '/html_entity_decode_php4.php'; return html_entity_decode_php4($text_to_convert); }
function CleanText($text) { // remove any javascript - OLLY // http://forum.joomla.org/index.php?topic=194800.msg1036857 $regex = "'<script[^>]*?>.*?</script>'si"; $text = preg_replace($regex, " ", $text); $regex = "'<noscript[^>]*?>.*?</noscript>'si"; $text = preg_replace($regex, " ", $text); // convert html entities to chars // this doesnt remove but converts it to ascii 160 // we handle that further down changing chr(160) to a space //$text = html_entity_decode($text,ENT_QUOTES,'UTF-8'); if (version_compare(phpversion(), '5.0') < 0) { require_once JPATH_SITE . DS . 'libraries' . DS . 'tcpdf' . DS . 'html_entity_decode_php4.php'; $text = html_entity_decode_php4($text, ENT_QUOTES, 'UTF-8'); } else { $text = html_entity_decode($text, ENT_QUOTES, 'UTF-8'); } // strip any remaining html tags $text = strip_tags($text); // remove any mambot codes $regex = '(\\{.*?\\})'; $text = preg_replace($regex, " ", $text); // remove any extra spaces while (strchr($text, " ")) { $text = str_replace(" ", " ", $text); } // general sentence tidyup for ($cnt = 1; $cnt < strlen($text); $cnt++) { // add a space after any full stops or comma's for readability // added as strip_tags was often leaving no spaces if ($text[$cnt] == '.' || $text[$cnt] == ',') { if ($text[$cnt + 1] != ' ') { $text = substr_replace($text, ' ', $cnt + 1, 0); } } } // remove quotes $text = str_replace("\"", "", $text); return trim($text); }