Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iena-modale-activity-filter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iena
iena-modale-activity-filter
Commits
1c177659
Commit
1c177659
authored
Apr 19, 2022
by
DELARUELLE Myriam
Browse files
Options
Downloads
Patches
Plain Diff
filtering now works correctly with activities
parent
6f6191e3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
filter.php
+149
-95
149 additions, 95 deletions
filter.php
js/iena.js
+31
-0
31 additions, 0 deletions
js/iena.js
js/jquery-3.3.1.min.js
+1
-1
1 addition, 1 deletion
js/jquery-3.3.1.min.js
with
181 additions
and
96 deletions
filter.php
+
149
−
95
View file @
1c177659
...
...
@@ -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,6 +151,7 @@ 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,51 +162,85 @@ 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
);
}
}
$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
);
/*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
);
for
(
$i
=
0
;
$i
<
count
(
$pieces
[
0
]);
$i
++
)
{
$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
);
if
(
$ini
!==
false
){
$ini
+=
strlen
(
$this
->
start
);
if
(
strlen
(
$
pieces
[
$i
]
)
<=
$ini
)
{
if
(
strlen
(
$
newElem
)
<=
$ini
)
{
continue
;
}
$len
=
strpos
(
$
pieces
[
$i
]
,
$this
->
end
,
$ini
)
-
$ini
;
$parsed
=
substr
(
$
pieces
[
$i
]
,
$ini
,
$len
);
$len
=
strpos
(
$
newElem
,
$this
->
end
,
$ini
)
-
$ini
;
$parsed
=
substr
(
$
newElem
,
$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
);
preg_match
(
'/id=([\d]+)*/'
,
$
newElem
,
$module_id
);
$module_type
=
""
;
preg_match
(
'/\/mod\/([^\/]+)\//'
,
$
pieces
[
$i
]
,
$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]*/'
,
$
parsed
,
$matches
);
preg_match_all
(
'/id=[\d]*/'
,
$
newElem
,
$matches
);
if
(
$matches
[
0
])
{
preg_match_all
(
'/[\d]+/'
,
$matches
[
0
][
0
],
$id_btn
);
}
...
...
@@ -190,23 +249,32 @@ function filter($text, array $options = array())
$this
->
filter_iena_get_info
(
$id_btn
);
}
// $PAGE->requires->js('/filter/iena/js/iena-filter-accessibility.js');
// $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\">×</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 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">×</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 . "; "
...
...
@@ -225,7 +293,7 @@ function filter($text, array $options = array())
. "</div>"
. '<div class="modal-body">'
// . "<iframe src=\"" . $parsed . "&iframe=true\" frameborder=\"0\" allowfullscreen></iframe>"
.
"<iframe src=
\"\"
frameborder=
\"
0
\"
allowfullscreen></iframe>"
. "<iframe
class='iena-iframe'
src=\"\" frameborder=\"0\" allowfullscreen></iframe>"
. "</div>"
. "</div>"
. "</div>"
...
...
@@ -233,33 +301,19 @@ function filter($text, array $options = array())
. "</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\">×</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
}
This diff is collapsed.
Click to expand it.
js/iena.js
+
31
−
0
View file @
1c177659
;(
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.
Click to expand it.
js/jquery-3.3.1.min.js
+
1
−
1
View file @
1c177659
File changed. Contains only whitespace changes.
Show whitespace changes.
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment