iMath) - Computer Science Dep. of IME-USP (Brazil)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @see moodle_text_filter
*/
/**
* Moodle core defines constant MOODLE_INTERNAL which shall be used to make sure that the script is included and not called directly.
*/
defined('MOODLE_INTERNAL') || die();
/**
* This class looks for email addresses in Moodle text and
* hides them using the Moodle obfuscate_text function.
* @see moodle_text_filter
*/
class filter_iassign_filter extends moodle_text_filter {
/**
* This takes the HTML to be filtered as an argument
* @param string $text The text for filter
* @param array $options An array for option in the filter
* @return string Return the text with filter
*/
function filter($text, array $options = array()) {
global $CFG, $DB, $USER, $COURSE;
if(file_exists($CFG->dirroot . '/mod/iassign/version.php')){
$strs = explode("</ia>", $text); // < (<) - >(>)
if (count($strs) > 1) {
$expressions = array();
foreach ($strs as $str) {
$tmp = explode("<ia", $str); // < (<) - / (⁄) >(>)
if (count($tmp) > 1)
$expressions[] = trim($tmp[1]);
} //foreach($strs as $str)
$text = str_replace("</ia>", "
", $text);
$text = str_replace("<ia", "
", $text);
foreach ($expressions as $expression) {
// default
$toolbar = 'disable'; // enable (habilita a barra de botões) disable (desabilita a barra de botões)
$width = 800;
$height = 600;
$tmp = explode(">", $expression); // >(>)
$params = trim($tmp[0]);
$fileid = trim($tmp[1]);
$params = str_replace("'", "", $params);
$params = str_replace(""", "", $params);
$params = explode(" ", $params);
foreach ($params as $param) {
$tmp1 = explode("=", $param);
if ($tmp1[0] == "toolbar")
$toolbar = $tmp1[1];
if ($tmp1[0] == "width")
$width = $tmp1[1];
if ($tmp1[0] == "height")
$height = $tmp1[1];
} //foreach($params as $param)
$fs = get_file_storage();
$file = $fs->get_file_by_id($fileid);
$ia_content = '';
$filename = '';
$output = '';
if ($file) {
$filename = $file->get_filename();
$ia_content = $file->get_content();
$file_string = utf8_encode($ia_content);
$output = $this->convert_applet($filename, $width, $height, $toolbar, $file_string, $fileid);
} else {
$output = "" . get_string('filenotfound', 'filter_iassign_filter') . "";
}
$text = str_replace($expression, $output, $text);
} // foreach($expressions as $expression)
} // if (count($strs)>1)
//TODO Retirar quando atualizar todo os iassign que estão com a tag <ia_uc>
$strs = explode("<ia_uc>", $text);
if (count($strs) > 1) {
$tmp = explode("</ia_uc>", $strs[1]);
$expression = trim($tmp[0]);
$text = $strs[0];
}
}
return $text;
}
/**
* Convert paramms to html tag for applet
* @param string $file Filename of applet
* @param string $width Width of applet in html page
* @param string $height Height of applet in html page
* @param string $toolbar Enable toolbar of applet
* @param string $file_string The content for applet load
* @param string $fileid Id for identify of applet
* @return string Return html tag with a string
*/
function convert_applet($file, $width, $height, $toolbar, $file_string, $fileid) {
global $CFG, $DB;
$tmp = explode(".", $file);
$extension = $tmp[1];
$iassign_ilms = $DB->get_records("iassign_ilm", array('enable' => 1, 'parent' => 0));
foreach($iassign_ilms as $value) {
$extensions = explode(",", $value->extension);
if(in_array($extension, $extensions))
$iassign_ilm = $value;
}
$output = '';
if (empty($iassign_ilm)) {
$output = "" . $extension . ": " . get_string('extensionnotfound', 'filter_iassign_filter') . "";
} else {
$lang = substr(current_language(), 0, 2);
$file_class = $iassign_ilm->file_class;
$notSEND = true;
$file_url = array();
$fs = get_file_storage();
$files_jar = explode(",", $iassign_ilm->file_jar);
foreach($files_jar as $fj) {
$file = $fs->get_file_by_id($fj);
if (!$file)
die($OUTPUT->notification ( get_string ( 'error_confirms_jar', 'iassign' ), 'notifyproblem' ));
$url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
array_push($file_url, $url);
}
$enderecoPOST = "";
$iassignid = 0;
$view = -1;
$token = '';
$end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view;
$output .= "
";
}
return $output;
}
}