Skip to content
Snippets Groups Projects
Commit 1c177659 authored by DELARUELLE Myriam's avatar DELARUELLE Myriam
Browse files

filtering now works correctly with activities

parent 6f6191e3
Branches
No related tags found
No related merge requests found
......@@ -120,6 +120,30 @@ public function filter_iena_add_delimiters($pieces)
return $pieces;
}
/**
* add $start and $end on each ressource link
* @param array $pieces
*
* @return array $pieces
*/
public function filter_iena_add_delimiters_new($pieces, $flagiframe)
{
global $CFG;
// If the link is in iframe then it is not tranformed
$pieces= $this->start . $pieces . $this->end;
//$pieces[$i] = substr_replace($pieces[$i], $nb_temp . $this->end, strpos($pieces[$i], "id=") + 3, strlen($nb_temp));
$pieces = str_replace('&iframe=true', '', $pieces);
$pieces = str_replace('&iframe=false', '', $pieces);
$pieces = str_replace('&iframe=true', '', $pieces);
$pieces = str_replace('&iframe=false', '', $pieces);
return $pieces;
}
/**
* @param $text
* @param array $options
......@@ -127,7 +151,8 @@ public function filter_iena_add_delimiters($pieces)
*/
function filter($text, array $options = array())
{
//Solution intermédiaire : on met un flag s'il y a déjà une iframe dans le code
global $CFG;
global $PAGE;
......@@ -137,129 +162,158 @@ function filter($text, array $options = array())
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');
//$PAGE->requires->js('/filter/iena/js/iframe_true.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;
}
error_log(isset($_GET['iframe']));
error_log("boum ?");
if (isset($_GET['iframe']) && $this->iena_filter_iframe == true) {
if ($_GET['iframe'] == 'true') {
$PAGE->requires->js('/filter/iena/js/iframe_true.js');
}
}
$flagiframe=false;
if(isset($_GET['ienaiframe']) && $this->iena_filter_iframe == true){
$flagiframe=true;
}
//À quoi ça sert ??
//On récupère tous les liens de la page
preg_match_all('/<a href="(.*?)">(.*?)<\/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);
}
}
/*if ((strpos($text, '</iframe>') !== false)) {
$flagiframe=true;
}*/
$test=str_replace('/', "\/", $CFG->wwwroot);
//On veut une regex qui ne capture que les première balises, pas celles d'avant ou d'après
preg_match_all('/(<[\w|\s| |"|;|:|=|-]*>[\w|\s| ]*'.$test.'\/mod\/.*[\r|\n| ]*<\/[a-z]*>)/', $text, $pieces);
$pieces = explode($CFG->wwwroot . '/mod', $text);
$pieces = $this->filter_iena_add_delimiters($pieces);
for ($i = 0; $i < count($pieces[0]); $i++) {
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);
$piecesToExamine=$pieces[0][$i];
if(isset($piecesToExamine) && strpos($piecesToExamine, '/mod/')){
if ($flagiframe==true) {
continue;
}
//Quoi faire de ça ? capturer toutes les balises ?
if ((strpos($piecesToExamine, '</a>') !== false)) {
continue;
}
$newElem=trim(strip_tags($piecesToExamine));
$newElem = $this->filter_iena_add_delimiters_new($newElem, $flagiframe);
//$newElem = ' ' . $newElem;
$ini = strpos($newElem, $this->start);
/* 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($ini !==false){
$ini += strlen($this->start);
if (strlen($newElem) <= $ini) {
continue;
}
$len = strpos($newElem, $this->end, $ini) - $ini;
$parsed = substr($newElem, $ini, $len);
if (isset($id_btn[0])) {
$this->filter_iena_get_info($id_btn);
}
/* 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]+)*/', $newElem, $module_id);
$module_type = "";
preg_match('/\/mod\/([^\/]+)\//', $newElem, $module_type);
if (isset($module_id[1]) && isset($module_id[1])) {
$modal_id = $module_type[1] . $module_id[1];
}
preg_match_all('/id=[\d]*/', $newElem, $matches);
if ($matches[0]) {
preg_match_all('/[\d]+/', $matches[0][0], $id_btn);
}
// $PAGE->requires->js('/filter/iena/js/iena-filter-accessibility.js');
if (isset($id_btn[0])) {
$this->filter_iena_get_info($id_btn);
}
// $pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", "<a class=\"sr-only\" target=\"_blank\" href=\"$parsed\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button id=\"iena-modal-btn-" . $i . "\" type=\"button\" " . $this->disabled . " "
// . "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $i . "\" style=\"background-color : " . $this->color_btn . "; "
// . "color : $this->color_btn_txt;border-radius:0.15rem;\">"
// . "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
// . "" . $this->btn_name . " </button>"
// . "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $i . "\" tabindex=\"-1\" "
// . "role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $i . "\" aria-hidden=\"true\">"
// . "<div class=\"modal-dialog\" role=\"document\">"
// . "<button type=\"button\" class=\"close\" data-dismiss=\"modal\" onclick=\"$('#iena-modal-" . $i . "').modal('hide');\"><span class=\"sr-only\">Fermer la modale</span><span aria-hidden=\"true\">&times;</span></button>"
// . "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
// . "</div>"
// . "</div>"
// , $pieces[$i]);
$newElem="<div>"
. "<a class=\"sr-only\" target=\"_blank\" href=\"".$parsed."\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button data-iframe=\"" .$parsed. "&ienaiframe=true&iframe=true\" type=\"button\" " . $this->disabled . " "
. "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $modal_id . "\" style=\"background-color : " . $this->color_btn . "; "
. "color : $this->color_btn_txt;border-radius:0.15rem;\">"
. "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
. "" . $this->btn_name . " </button>"
$pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/",
"<div>"
. "<a class=\"sr-only\" target=\"_blank\" href=\"$parsed\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button data-iframe=\"" .$parsed. "&iframe=true\" type=\"button\" " . $this->disabled . " "
. "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $modal_id . "\" style=\"background-color : " . $this->color_btn . "; "
. "color : $this->color_btn_txt;border-radius:0.15rem;\">"
. "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
. "" . $this->btn_name . " </button>"
. "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $modal_id . "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $modal_id . "\" aria-hidden=\"true\">"
. "<div class=\"modal-dialog\" role=\"document\">"
. '<div class="modal-content">'
. '<div class="modal-header">'
. '<h5 class="modal-title" id="iena-modal-btn-'.$modal_id.'">'.$this->btn_name.'</h5>'
. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>'
. "</div>"
. '<div class="modal-body">'
. "<iframe id=\"iframe-".$modal_id."-".$i."\" class='iena-iframe' src=\"\" frameborder=\"0\" allowfullscreen></iframe>"
. "</div>"
. "</div>"
. "</div>"
. "</div>"
. "</div>";
/*$pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/",
"<div>"
. "<a class=\"sr-only\" target=\"_blank\" href=\"$parsed\">Ouvrir dans un nouvel onglet au lieu d'utiliser la modale : $this->btn_name.</a><button data-iframe=\"" .$parsed. "&iframe=true\" type=\"button\" " . $this->disabled . " "
. "class=\"btn iena-filter-modal-btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $modal_id . "\" style=\"background-color : " . $this->color_btn . "; "
. "color : $this->color_btn_txt;border-radius:0.15rem;\">"
. "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
. "" . $this->btn_name . " </button>"
. "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $modal_id . "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $modal_id . "\" aria-hidden=\"true\">"
. "<div class=\"modal-dialog\" role=\"document\">"
. '<div class="modal-content">'
. '<div class="modal-header">'
. '<h5 class="modal-title" id="iena-modal-btn-'.$modal_id.'">'.$this->btn_name.'</h5>'
. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>'
. "</div>"
. '<div class="modal-body">'
// . "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
. "<iframe src=\"\" frameborder=\"0\" allowfullscreen></iframe>"
. "</div>"
. "</div>"
. "</div>"
. "</div>"
. "</div>"
. "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $modal_id . "\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $modal_id . "\" aria-hidden=\"true\">"
. "<div class=\"modal-dialog\" role=\"document\">"
. '<div class="modal-content">'
. '<div class="modal-header">'
. '<h5 class="modal-title" id="iena-modal-btn-'.$modal_id.'">'.$this->btn_name.'</h5>'
. '<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>'
. "</div>"
. '<div class="modal-body">'
// . "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
. "<iframe class='iena-iframe' src=\"\" frameborder=\"0\" allowfullscreen></iframe>"
. "</div>"
. "</div>"
. "</div>"
. "</div>"
. "</div>"
, $pieces[$i]);
, $pieces[$i]);*/
//$text = str_replace('{{$'.$pieces[$i][0].'}}', $newElem, $text);
$text = str_replace($piecesToExamine, $newElem, $text);
}
}
}
return implode($pieces);
}
//return implode($pieces);
return $text;
}
// $pieces[$i] = preg_replace("/(\\S+)\\[\/IENA\\]/", "<button id=\"iena-modal-btn-" . $i . "\" type=\"button\" " . $this->disabled . " "
// . "class=\"btn \" data-toggle=\"modal\" data-target=\"#iena-modal-" . $i . "\" style=\"background-color : " . $this->color_btn . "; "
// . "color : $this->color_btn_txt;border-radius:0.15rem;\">"
// . "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">"
// . "" . $this->btn_name . " </button>"
// . "<div class=\"modal fade iena-filter-modal\" id=\"iena-modal-" . $i . "\" tabindex=\"-1\" "
// . "role=\"dialog\" aria-labelledby=\"#iena-modal-btn-" . $i . "\" aria-hidden=\"true\">"
// . "<div role=\"document\" class=\"modal-dialog modal-lg\">"
// . "<div class=\"modal-content\" id=\"iena-modal-content\" >"
// . "<div class=\"modal-header\">"
// . "<button type=\"button\" class=\"close\" data-dismiss=\"modal\">&times;</button>"
// . "<h4 class=\"modal-title\">"
// . "<img class=\"icon icon\" alt=\"\" src=\"" . $CFG->wwwroot . "/theme/image.php/boost/" . $this->btn_type . "/1/icon\">" . $this->btn_name . "</h4>"
// . "</div>"
// . "<div class=\"modal-body\" id=\"iena-modal-body\">"
// . "<iframe width=\"100%\" height=\"85vh\" src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
// . "</div>"
// . "</div>"
// . "</div>"
// . "</div>"
// , $pieces[$i]);
\ No newline at end of file
}
;(function ($) {
var btns = document.querySelectorAll('.iena-filter-modal-btn');
for (var i = 0; i < btns.length; i++) {
btns[i].onclick = function (e) {
document.querySelector(e.target.dataset.target + " .modal-body").style.opacity = 0;
......@@ -7,6 +8,36 @@
document.querySelector(e.target.dataset.target + " .modal-body").style.opacity = 1;
}
document.querySelector(e.target.dataset.target + " iframe").setAttribute('src', e.target.dataset.iframe);
var to_hide = [
"#page-header",
"#page-wrapper > nav",
"#page-footer",
"#nav-drawer"
];
iframes=document.getElementsByClassName('iena-iframe');
for(var j=0; j<iframes.length; j++){
iframes[j].addEventListener("load", function(e) {
var iframe=this.contentDocument || this.contentWindow.document;
for (var i = 0; i < to_hide.length; i++) {
iframe.querySelector(to_hide[i]).setAttribute('class', 'none-hidden');
}
iframe.querySelector('#page').setAttribute('class', '');
iframe.querySelector('#page').style.margin = 0;
iframe.querySelector('#page-wrapper').setAttribute('class', 'no-after');
iframe.querySelector('#page-content').setAttribute('class', 'no-margin-l-r');
iframe.querySelector('#region-main-box').style.padding = 0;
iframe.querySelector('#region-main').style.border = "none";
iframe.body.style.marginLeft = 0;
});
}
}
}
/* iframe kill after modale closing doesn't work... */
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment