123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- <?php
- /**
- * Filter iAssign
- *
- * Release Notes:
- * - v 1.2 2014/01/10
- * + Remove comment unread function of filter module.
- *
- * - v 1.1 2013/10/31
- * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
- *
- * @author Patricia Alves Rodrigues
- * @author Leônidas O. Brandão
- * @author Luciano Oliveira Borges
- * @version v 1.2 2014/01/10
- * @package iassign_filter
- * @since 2010/09/27
- * @copyright iMatica (<a href="http://www.matematica.br">iMath</a>) - 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>", "<br/>", $text);
- $text = str_replace("<ia", "<br/>", $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 = "<strong>" . get_string('filenotfound', 'filter_iassign_filter') . "</strong>";
- }
-
- $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 = "<strong>" . $extension . ": " . get_string('extensionnotfound', 'filter_iassign_filter') . "</strong>";
- } 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 .= "
- <applet name='iLM' code='$file_class' archive='".implode(",", $file_url)."' width='$width' height='$height' vspace=10 hspace=10>
- ";
- if ($toolbar == "disable")
- $output .="<param name='SOH_ADD' value='ADD'>";
- $output .="
-
- <param name='MA_PARAM_PropositionURL' value='true'/>
- <param name='MA_PARAM_notSEND' value='false'/>
- <param name='lang' value='$lang'/>
- <param name='MA_PARAM_addresPOST' value='$enderecoPOST'> <!-- 2 -->
- <param name='MA_PARAM_Proposition' value='" . $end_file . "'>
- </applet> ";
- }
- return $output;
- }
- }
|