Skip to content
GitLab
Erkunden
Anmelden
Registrieren
Primärnavigation
Suchen oder aufrufen …
Projekt
Html Snippets
Verwalten
Aktivität
Mitglieder
Labels
Planen
Tickets
1
Ticketübersichten
Meilensteine
Wiki
Code
Merge Requests
0
Repository
Branch
Commits
Tags
Repository-Diagramm
Revisionen vergleichen
Code-Schnipsel
Build
Pipelines
Aufgaben
Pipeline-Zeitpläne
Artefakte
Bereitstellung
Releases
Paket-Registry
Betreiben
Umgebungen
Terraform-Module
Überwachen
Vorfälle
Service-Desk
Analysieren
Wertschöpfungskettenanalyse
Mitwirkenden-Analyse
CI/CD-Analyse
Repository-Analysen
Hilfe
Hilfe
Support
GitLab-Dokumentation
GitLab-Pläne vergleichen
Community-Forum
Zu GitLab beitragen
Feedback geben
Tastenkürzel
?
Code-Schnipsel
Gruppen
Projekte
Show more breadcrumbs
QUIQQER
Html Snippets
Commits
c07b04a7
Commit
c07b04a7
erstellt
vor 8 Monaten
von
Jan Wennrich
Dateien durchsuchen
Optionen
Downloads
Einfaches Diff
Merge branch 'next-1.x' into '1.x'
fix: rework snippet decoding See merge request
!25
Übergeordnete
c1add9de
7d363ee0
No related branches found
Branches enthält Commit
Tags
1.1.0
Tags enthält Commit
1 Merge Request
!25
fix: rework snippet decoding
Pipeline
#9310
mit Warnungen bestanden mit Phasen
in 1 Minute und 1 Sekunde
Änderungen
3
Pipelines
1
Leerzeichenänderungen ausblenden
Inline
Nebeneinander
3 geänderte Dateien
bin/backend/Snippets.js
+2
-2
2 Ergänzungen, 2 Löschungen
bin/backend/Snippets.js
bin/frontend/gdprReader.js
+45
-30
45 Ergänzungen, 30 Löschungen
bin/frontend/gdprReader.js
src/QUI/HtmlSnippets/SnippetTemplateEvent.php
+13
-11
13 Ergänzungen, 11 Löschungen
src/QUI/HtmlSnippets/SnippetTemplateEvent.php
werden angezeigt
mit
60 Ergänzungen
und
43 Löschungen
bin/backend/Snippets.js
+
2
−
2
Zeige Datei @
c07b04a7
...
@@ -110,7 +110,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
...
@@ -110,7 +110,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
buttons
:
[
buttons
:
[
{
{
name
:
'
addSnippet
'
,
name
:
'
addSnippet
'
,
text
:
QUILocale
.
get
(
'
quiqqer/
core
'
,
'
add
'
),
text
:
QUILocale
.
get
(
'
quiqqer/
quiqqer
'
,
'
add
'
),
position
:
'
left
'
,
position
:
'
left
'
,
events
:
{
events
:
{
click
:
this
.
add
click
:
this
.
add
...
@@ -118,7 +118,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
...
@@ -118,7 +118,7 @@ define('package/quiqqer/html-snippets/bin/backend/Snippets', [
},
{
},
{
name
:
'
remove
'
,
name
:
'
remove
'
,
icon
:
'
fa fa-trash
'
,
icon
:
'
fa fa-trash
'
,
title
:
QUILocale
.
get
(
'
quiqqer/
core
'
,
'
remove
'
),
title
:
QUILocale
.
get
(
'
quiqqer/
quiqqer
'
,
'
remove
'
),
disabled
:
true
,
disabled
:
true
,
styles
:
{
styles
:
{
'
float
'
:
'
right
'
'
float
'
:
'
right
'
...
...
This diff is collapsed.
Zum Erweitern klicken.
bin/frontend/gdprReader.js
+
45
−
30
Zeige Datei @
c07b04a7
(
function
()
{
(
function
()
{
'
use strict
'
;
'
use strict
'
;
const
loadNode
=
function
(
Node
)
{
const
processSnippetNodes
=
function
(
nodes
)
{
if
(
Node
.
getAttribute
(
'
data-qui-html-snippet-gdpr-loaded
'
))
{
// Gather all HTML snippet nodes ("template" elements with a specific "data-" attribute)
return
;
const
SnippetsNodeList
=
document
.
querySelectorAll
(
'
template[data-qui-html-snippet="gdpr"]
'
);
}
Node
.
innerHTML
=
atob
(
Node
.
innerHTML
);
SnippetsNodeList
.
forEach
((
SnippetNode
)
=>
{
const
scripts
=
Array
.
from
(
Node
.
getElementsByTagName
(
'
script
'
)
);
const
gdprCategory
=
SnippetNode
.
getAttribute
(
'
data-qui-html-snippet-gdpr-category
'
);
scripts
.
forEach
((
script
)
=>
{
// Only decode (and execute) the snippet node, if the corresponding gdpr category was accepted
const
newScript
=
document
.
createElement
(
'
script
'
);
window
.
GDPR
.
waitForCookieCategoryAcceptance
(
gdprCategory
).
then
(()
=>
{
newScript
.
textContent
=
script
.
textContent
;
decodeSnippetNode
(
SnippetNode
);
});
});
};
const
decodeSnippetNode
=
function
(
SnippetNode
)
{
// The node's inner HTML is base64 encoded, turn it back to normal HTML
SnippetNode
.
innerHTML
=
atob
(
SnippetNode
.
innerHTML
);
// The snippet code is in a wrapping <template> node and thus isn't interpreted
// Therefore we have to move all nodes inside this template snippet node into the document
// We do that by iterating over all direct children of the template element and...
Array
.
from
(
SnippetNode
.
content
.
children
).
forEach
(
ChildNode
=>
{
let
NodeToInsert
=
ChildNode
;
let
i
,
len
,
attribute
;
// ...if it is a script tag it needs special treatment
if
(
ChildNode
.
tagName
===
'
SCRIPT
'
)
{
// "script" tags are not executed when moved from the snippet node to the document
// Therefore a new element has to be created instead
// The new element is executed when added to the document
NodeToInsert
=
createExecutableCopyOfScriptNode
(
ChildNode
);
for
(
i
=
0
,
len
=
script
.
attributes
.
length
;
i
<
len
;
i
++
)
{
// Remove the original script node as we are using the copy now
attribute
=
script
.
attributes
[
i
];
ChildNode
.
remove
();
newScript
.
setAttribute
(
attribute
.
name
,
attribute
.
value
);
}
}
script
.
parentNode
.
replaceChild
(
newScript
,
script
);
// ...moving the child node from inside the template snippet node in front of the snippet node
SnippetNode
.
insertAdjacentElement
(
'
beforebegin
'
,
NodeToInsert
);
});
});
Node
.
setAttribute
(
'
data-qui-html-snippet-gdpr-loaded
'
,
1
);
// ...and deleting the now empty snippet node
Node
.
style
.
display
=
''
;
SnippetNode
.
remove
()
;
};
};
const
fetchNodes
=
function
(
nodes
)
{
const
createExecutableCopyOfScriptNode
=
function
(
ScriptNode
)
{
nodes
.
forEach
((
Node
)
=>
{
const
ExecutableScriptNode
=
document
.
createElement
(
'
script
'
);
const
gdprCategory
=
Node
.
getAttribute
(
'
data-qui-html-snippet-gdpr-category
'
);
if
(
window
.
GDPR
.
isCookieCategoryAccepted
(
gdprCategory
))
{
// Copy the script's text content (the JavaScript code)
loadNode
(
Node
);
ExecutableScriptNode
.
textContent
=
ScriptNode
.
textContent
;
}
else
{
window
.
GDPR
.
waitForCookieCategoryAcceptance
(
gdprCategory
).
then
(()
=>
{
// Copy all the script's attributes
loadNode
(
Node
);
Array
.
from
(
ScriptNode
.
attributes
).
forEach
(
ScriptAttribute
=>
{
});
ExecutableScriptNode
.
setAttribute
(
ScriptAttribute
.
name
,
ScriptAttribute
.
value
);
}
});
});
return
ExecutableScriptNode
;
};
};
fetchNodes
(
document
.
querySelectorAll
(
'
[data-qui-html-snippet="gdpr"]
'
)
);
processSnippetNodes
(
);
window
.
whenQuiLoaded
().
then
(()
=>
{
window
.
whenQuiLoaded
().
then
(
processSnippetNodes
);
fetchNodes
(
document
.
querySelectorAll
(
'
[data-qui-html-snippet="gdpr"]
'
));
});
})();
})();
This diff is collapsed.
Zum Erweitern klicken.
src/QUI/HtmlSnippets/SnippetTemplateEvent.php
+
13
−
11
Zeige Datei @
c07b04a7
...
@@ -67,17 +67,19 @@ class SnippetTemplateEvent
...
@@ -67,17 +67,19 @@ class SnippetTemplateEvent
continue
;
continue
;
}
}
// consider gdpr status
$snippetGdprCategory
=
$snippet
[
'gdpr'
];
$div
=
'<script '
;
$snippetContentEncoded
=
base64_encode
(
$snippet
[
'snippet'
]);
$div
.
=
' data-qui-html-snippet="gdpr"'
;
$div
.
=
' data-qui-html-snippet-gdpr-category="'
.
$snippet
[
'gdpr'
]
.
'"'
;
$snippetHtml
=
<<<EOF
$div
.
=
' style="display: none"'
;
<template
$div
.
=
' type="text/plain"'
;
data-qui-html-snippet="gdpr"
$div
.
=
'>'
;
data-qui-html-snippet-gdpr-category="$snippetGdprCategory"
$div
.
=
base64_encode
(
$snippet
[
'snippet'
]);
>
$div
.
=
'</script>'
;
$snippetContentEncoded
</template>
$Collector
->
append
(
$div
);
EOF;
$Collector
->
append
(
$snippetHtml
);
}
}
}
}
}
}
This diff is collapsed.
Zum Erweitern klicken.
Vorschau
0%
Wiederholen
oder
Neue Datei anhängen
.
Abbrechen
You are about to add
0
people
to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Kommentar speichern
Abbrechen
Bitte
registrieren
oder
Anmelden
zum Kommentieren