color_btn) */ public $color_btn = "#009085"; /** @var string Hex color of button text is defined in settings ($CFG->color_btn_txt) */ public $color_btn_txt = "#ffffff"; /** @var string set empty, if the id does not exist then turn to "disabled" */ public $disabled = ""; /** @var string hide iframe nav and footer, admin setting */ public $iena_filter_iframe = true; /** * Get name and type of resource with the id * Set the $btn_name and $btn_type * Set $disabled (if $disabled is empty the button is active) * @param array $id_btn * * @return void */ public function filter_iena_get_info($id_btn) { global $DB; $this->btn_name = get_string('erreur_ressource', 'filter_iena'); $this->disabled = ""; $id_course_modules = $id_btn[0][0]; if ($id_course_modules) { $requete = $DB->get_record_sql('SELECT * FROM {course_modules} WHERE id = ?', array($id_course_modules)); $id_instance = $requete->instance; $id_module = $requete->module; if ($id_module) { $modules = $DB->get_record_sql('SELECT * FROM {modules} WHERE id = ?', array($id_module)); } if ($modules->name) { $instance = $DB->get_record_sql('SELECT * FROM {' . $modules->name . '} WHERE id = ?', array($id_instance)); } if ($instance->name) { $this->btn_name = $instance->name; } else { $this->disabled = "disabled"; } $this->btn_type = $modules->name; } } /** * add $start and $end on each ressource link * @param array $pieces * * @return array $pieces */ public function filter_iena_add_delimiters($pieces) { global $CFG; for ($i = 1; $i < count($pieces); $i++) { // If the link is in iframe then it is not tranformer if ((strpos($pieces[$i], '') !== false)) { $pieces[$i] = $CFG->wwwroot . '/mod' . $pieces[$i]; continue; } if ((strpos($pieces[$i], '') !== false)) { $pieces[$i] = $CFG->wwwroot . '/mod' . $pieces[$i]; continue; } $pieces[$i] = $this->start . $CFG->wwwroot . '/mod' . $pieces[$i]; $temp = strpos($pieces[$i], "id=") + 3; $nb_temp = ''; while (is_numeric($pieces[$i][$temp])) { $nb_temp = $nb_temp . $pieces[$i][$temp]; $temp++; } $pieces[$i] = substr_replace($pieces[$i], $nb_temp . $this->end, strpos($pieces[$i], "id=") + 3, strlen($nb_temp)); $pieces[$i] = str_replace('&iframe=true', '', $pieces[$i]); $pieces[$i] = str_replace('&iframe=false', '', $pieces[$i]); $pieces[$i] = str_replace('&iframe=true', '', $pieces[$i]); $pieces[$i] = str_replace('&iframe=false', '', $pieces[$i]); } return $pieces; } /** * @param $text * @param array $options * @return string */ function filter($text, array $options = array()) { global $CFG; global $PAGE; if ($CFG->color_btn) { $this->color_btn = $CFG->color_btn; } if ($CFG->color_btn_txt) { $this->color_btn_txt = $CFG->color_btn_txt; } $PAGE->requires->js('/filter/iena/js/jquery-3.3.1.min.js'); $PAGE->requires->js('/filter/iena/js/iena.js'); //We hide the menus and block if the iframe parameter is a true if (isset($CFG->iena_filter_iframe)) { $this->iena_filter_iframe = $CFG->iena_filter_iframe; } if (isset($_GET['iframe']) && $this->iena_filter_iframe == true) { if ($_GET['iframe'] == 'true') { $PAGE->requires->js('/filter/iena/js/iframe_true.js'); } } preg_match_all('/(.*?)<\/a>/s', $text, $matches); for ($i = 0; $i < count($matches[0]); $i++) { if (strcmp($matches[1][$i], $matches[2][$i]) == 0) { $text = str_replace($matches[0][$i], $matches[1][$i], $text); } } $pieces = explode($CFG->wwwroot . '/mod', $text); $pieces = $this->filter_iena_add_delimiters($pieces); for ($i = 0; $i < count($pieces); $i++) { $pieces[$i] = ' ' . $pieces[$i]; $ini = strpos($pieces[$i], $this->start); $ini += strlen($this->start); if (strlen($pieces[$i]) <= $ini) { continue; } $len = strpos($pieces[$i], $this->end, $ini) - $ini; $parsed = substr($pieces[$i], $ini, $len); /* calcul unique modale id for showing modale, based on module type (page, test, etc.) and module id */ $modal_id = $i; /* default */ $module_id = null; preg_match('/id=([\d]+)*/', $pieces[$i], $module_id); $module_type = ""; preg_match('/\/mod\/([^\/]+)\//', $pieces[$i], $module_type); if (isset($module_id[1]) && isset($module_id[1])) { $modal_id = $module_type[1] . $module_id[1]; } preg_match_all('/id=[\d]*/', $parsed, $matches); if ($matches[0]) { preg_match_all('/[\d]+/', $matches[0][0], $id_btn); } if (isset($id_btn[0])) { $this->filter_iena_get_info($id_btn); } // $PAGE->requires->js('/filter/iena/js/iena-filter-accessibility.js'); // $pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", "Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name." // . "
" // . "
" // . "" // . "" // . "
" // . "
" // , $pieces[$i]); $pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", "
" . "Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name." . "
" . "
" . '" . "
" . "
" . "
" , $pieces[$i]); } return implode($pieces); } } // $pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", "" // . "
" // . "
" // . "
" // . "
" // . "" // . "

" // . "\"\"wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">" . $this->btn_name . "

" // . "
" // . "
" // . "" // . "
" // . "
" // . "
" // . "
" // , $pieces[$i]);