Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit c6f7226

Browse files
authored
Merge pull request #15 from silinternational/develop
consumers wanted more sophisticated analytics data.
2 parents d74fdf0 + 913be71 commit c6f7226

File tree

7 files changed

+86
-57
lines changed

7 files changed

+86
-57
lines changed

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ services:
1919
ADMIN_EMAIL: "[email protected]"
2020
SECRET_SALT: "FcJwl0zCDc4nuzOuQL9/7WPIj3hdfusGm2ny0dcRQm0="
2121
IDP_NAME: "The Hub"
22+
ANALYTICS_ID: "UA-XXXX-Y"
2223
idp1:
2324
image: silintl/ssp-base:develop
2425
volumes:
@@ -56,3 +57,4 @@ services:
5657
ADMIN_EMAIL: "[email protected]"
5758
SECRET_SALT: "edI4GGkYfkzD6/OXFvHBHb9Meu9hdKXQpNFg4q/GGfY="
5859
IDP_NAME: "Idp 2"
60+
ANALYTICS_ID: "UA-XXXX-Y"

themes/material/common-announcement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
$announcement = $this->data['announcement'] ?? null;
2+
$announcement = htmlentities($this->data['announcement'] ?? null);
33

44
if (! empty($announcement)) {
55
?>

themes/material/common-footer.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
11
<footer class="mdl-mini-footer">
22
<?= $this->t('{material:footer:copyright}') ?>
33
</footer>
4-
5-
<?php
6-
$trackingId = $this->configuration->getValue('analytics.trackingId');
7-
8-
if (! empty($trackingId)) {
9-
?>
10-
<script>
11-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
12-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
13-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
14-
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
15-
16-
ga('create', $trackingId, 'auto');
17-
ga('send', 'pageview');
18-
</script>
19-
<?php
20-
}
21-
?>

themes/material/common-head-elements.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,30 @@
44
<meta name="viewport" content="width=device-width, initial-scale=1.0">
55

66
<?php
7-
$colors = $this->configuration->getValue('theme.color-scheme', 'indigo-purple');
7+
$trackingId = htmlentities($this->configuration->getValue('analytics.trackingId'));
8+
if (! empty($trackingId)) {
9+
?>
10+
<script>
11+
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
12+
ga('create', '<?= $trackingId ?>', 'auto');
13+
ga('send', 'pageview');
14+
</script>
15+
<script async src='https://www.google-analytics.com/analytics.js'></script>
16+
<?php
17+
} else {
18+
?>
19+
<script>
20+
window.ga = function () {
21+
// Null object pattern to avoid `if (window.ga)` wherever ga is used.
22+
}
23+
</script>
24+
<?php
25+
}
26+
?>
27+
28+
29+
<?php
30+
$colors = htmlentities($this->configuration->getValue('theme.color-scheme', 'indigo-purple'));
831
?>
932
<link rel="stylesheet" href="/module.php/material/material.<?= $colors ?>.1.2.1.min.css">
1033
<link rel="stylesheet" href="/module.php/material/styles.2.1.0.css">

themes/material/core/loginuserpass.php

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
<!DOCTYPE html>
2-
<?php
3-
$siteKey = $this->data['recaptcha.siteKey'] ?? null;
4-
$username = $this->data['username'] ?? null;
5-
$forgotPasswordUrl = $this->data['forgotPasswordUrl'] ?? null;
6-
$csrfToken = $this->data['csrfToken'] ?? null;
7-
$idpName = $this->configuration->getValue('idp_name', '');
8-
9-
$errorCode = $this->data['errorcode'] ?? null;
10-
$errorMessageKey = $this->data['errorparams'][1] ?? '{material:login:error_wronguserpass}';
11-
$errorMessageTokens = $this->data['errorparams'][2] ?? [];
12-
?>
132
<html>
143
<head>
154
<title><?= $this->t('{material:login:title}') ?></title>
165

176
<?php include __DIR__ . '/../common-head-elements.php' ?>
187

198
<?php
9+
$siteKey = htmlentities($this->data['recaptcha.siteKey'] ?? null);
2010
if (! empty($siteKey)) {
2111
?>
2212
<script src='https://www.google.com/recaptcha/api.js?onload=onRecaptchaLoad&render=explicit'
@@ -31,10 +21,12 @@ function onRecaptchaLoad() {
3121
var loginButton = document.querySelector('button');
3222

3323
grecaptcha.render(loginButton, {
34-
sitekey: '<?= htmlentities($siteKey) ?>',
24+
sitekey: '<?= $siteKey ?>',
3525
callback: submitForm
3626
});
3727
}
28+
29+
ga('send', 'event', 'reCAPTCHA', 'required');
3830
</script>
3931
<?php
4032
}
@@ -45,12 +37,19 @@ function onRecaptchaLoad() {
4537
<main class="mdl-layout__content" layout-children="column" child-spacing="center">
4638
<?php include __DIR__ . '/../common-announcement.php' ?>
4739

40+
4841
<form method="POST" action="<?= htmlentities($_SERVER['PHP_SELF']) ?>">
4942
<input type="hidden" name="AuthState"
50-
value="<?= htmlspecialchars($this->data['stateparams']['AuthState']) ?>" />
51-
<input type="hidden" name="csrf-token" value="<?= htmlentities($csrfToken); ?>" />
43+
value="<?= htmlentities($this->data['stateparams']['AuthState'] ?? null) ?>" />
44+
<?php
45+
$csrfToken = htmlentities($this->data['csrfToken'] ?? null);
46+
?>
47+
<input type="hidden" name="csrf-token" value="<?= $csrfToken ?>" />
5248

5349
<div class="mdl-card mdl-shadow--8dp">
50+
<?php
51+
$idpName = htmlentities($this->configuration->getValue('idp_name', ''));
52+
?>
5453
<div class="mdl-card__media white-bg margin" layout-children="column">
5554
<img src="/logo.png"
5655
alt="<?= $this->t('{material:login:logo}', ['{idpName}' => $idpName]) ?>">
@@ -67,8 +66,11 @@ function onRecaptchaLoad() {
6766
<label for="username" class="mdl-textfield__label">
6867
<?= $this->t('{material:login:label_username}') ?>
6968
</label>
69+
<?php
70+
$username = htmlentities($this->data['username'] ?? null);
71+
?>
7072
<input type="text" name="username" class="mdl-textfield__input"
71-
value="<?= htmlspecialchars($username) ?>"
73+
value="<?= $username ?>"
7274
<?= empty($username) ? 'autofocus' : '' ?> id="username"/>
7375
</div>
7476

@@ -82,24 +84,34 @@ function onRecaptchaLoad() {
8284
</div>
8385

8486
<?php
87+
$errorCode = htmlentities($this->data['errorcode']);
8588
if ($errorCode == 'WRONGUSERPASS') {
89+
$errorMessageKey = $this->data['errorparams'][1] ?? '{material:login:error_wronguserpass}';
90+
$errorMessageTokens = $this->data['errorparams'][2] ?? null;
91+
92+
$message = htmlentities($this->t($errorMessageKey, $errorMessageTokens));
8693
?>
87-
<p class="mdl-color-text--red error">
88-
<i class="material-icons">error</i>
94+
<p class="mdl-color-text--red error">
95+
<i class="material-icons">error</i>
96+
97+
<span class="mdl-textfield mdl-typography--caption">
98+
<?= $message ?>
99+
</span>
100+
</p>
89101

90-
<span class="mdl-textfield mdl-typography--caption">
91-
<?= $this->t($errorMessageKey, $errorMessageTokens) ?>
92-
</span>
93-
</p>
102+
<script>
103+
ga('send','event','error','<?= $errorCode ?>','<?= $username ?>','<?= $message ?>');
104+
</script>
94105
<?php
95106
}
96107
?>
97108

98109
<div class="mdl-card__actions" layout-children="row">
99110
<?php
111+
$forgotPasswordUrl = htmlentities($this->data['forgotPasswordUrl'] ?? null);
100112
if (! empty($forgotPasswordUrl)) {
101113
?>
102-
<a href="<?= htmlentities($forgotPasswordUrl) ?>" target="_blank"
114+
<a href="<?= $forgotPasswordUrl ?>" target="_blank"
103115
class="mdl-button mdl-button--colored mdl-typography--caption">
104116
<?= $this->t('{material:login:forgot}') ?>
105117
</a>

themes/material/default/error.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
</p>
2222

2323
<?php
24-
if ($this->data['showerrors']) {
24+
if ($this->data['showerrors'] ?? false) {
2525
?>
2626
<p class="mdl-typography--body-2">
27-
<?= htmlspecialchars($this->data['error']['exceptionMsg']) ?>
27+
<?= htmlentities($this->data['error']['exceptionMsg'] ?? null) ?>
2828
</p>
2929

3030
<pre class="mdl-typography--caption">
31-
<?= htmlspecialchars($this->data['error']['exceptionTrace']) ?>
31+
<?= htmlentities($this->data['error']['exceptionTrace'] ?? null) ?>
3232
</pre>
3333
<?php
3434
}

themes/material/default/selectidp-links.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ function setSelectedIdp(id) {
1414
idpInput.value = id;
1515

1616
document.querySelector('form').appendChild(idpInput);
17+
18+
ga('send', 'event', 'hub', 'choice', 'IdP', id);
19+
}
20+
21+
function clickedAnyway(idpName) {
22+
ga('send', 'event', 'hub', 'choice-disabled', 'IdP', idpName);
1723
}
1824
</script>
1925
</head>
@@ -34,11 +40,11 @@ function setSelectedIdp(id) {
3440
<form action="<?= htmlentities($_SERVER['PHP_SELF']) ?>"
3541
layout-children="row" child-spacing="space-around">
3642
<input type="hidden" name="entityID"
37-
value="<?= htmlspecialchars($this->data['entityID']) ?>" />
43+
value="<?= htmlentities($this->data['entityID'] ?? null) ?>" />
3844
<input type="hidden" name="return"
39-
value="<?= htmlspecialchars($this->data['return']) ?>" />
45+
value="<?= htmlentities($this->data['return'] ?? null) ?>" />
4046
<input type="hidden" name="returnIDParam"
41-
value="<?= htmlspecialchars($this->data['returnIDParam']) ?>" />
47+
value="<?= htmlentities($this->data['returnIDParam'] ?? null) ?>" />
4248

4349
<?php
4450
// in order to bypass some built-in simplesaml behavior, an extra idp
@@ -53,15 +59,14 @@ function setSelectedIdp(id) {
5359
}
5460

5561
foreach ($enabledIdps as $idp) {
56-
$name = htmlspecialchars($this->t($idp['name']));
57-
$idpId = htmlspecialchars($idp['entityid']);
62+
$name = htmlentities($this->t($idp['name'] ?? null));
63+
$idpId = htmlentities($idp['entityid'] ?? null);
5864
$hoverText = $this->t('{material:selectidp:enabled}', ['{idpName}' => $name]);
5965
?>
6066
<div class="mdl-card mdl-shadow--8dp row-aware" title="<?= $hoverText ?>">
6167
<div class="mdl-card__media white-bg fixed-height">
62-
<button class="mdl-button fill-parent" value="<?= $name ?>"
63-
onclick="setSelectedIdp('<?= $idpId ?>')">
64-
<img class="scale-to-parent"
68+
<button class="mdl-button fill-parent" onclick="setSelectedIdp('<?= $idpId ?>')">
69+
<img class="scale-to-parent" id="<?= $idpId ?>"
6570
src="<?= empty($idp['logoURL']) ? '/module.php/material/default-logo.png'
6671
: $idp['logoURL'] ?>">
6772
</button>
@@ -73,14 +78,15 @@ function setSelectedIdp(id) {
7378

7479
<?php
7580
foreach ($disabledIdps as $idp) {
76-
$name = htmlspecialchars($this->t($idp['name']));
81+
$name = htmlentities($this->t($idp['name'] ?? null));
82+
$idpId = htmlentities($idp['entityid'] ?? null);
7783
$hoverText = $this->t('{material:selectidp:disabled}', ['{idpName}' => $name]);
7884
?>
79-
<div class="mdl-card mdl-shadow--2dp disabled row-aware"
80-
title="<?= $hoverText ?>">
85+
<div class="mdl-card mdl-shadow--2dp disabled row-aware" title="<?= $hoverText ?>"
86+
onclick="clickedAnyway('<?= $name ?>')">
8187
<div class="mdl-card__media white-bg fixed-height" layout-children="row"
8288
child-spacing="center">
83-
<img class="scale-to-parent"
89+
<img class="scale-to-parent" id="<?= $idpId ?>"
8490
src="<?= empty($idp['logoURL']) ? '/module.php/material/default-logo.png'
8591
: $idp['logoURL'] ?>">
8692
</div>
@@ -91,6 +97,10 @@ function setSelectedIdp(id) {
9197
</form>
9298
</main>
9399

100+
<script>
101+
ga('send', 'event', 'hub', 'choices', 'enabled', <?= count($enabledIdps) ?>);
102+
ga('send', 'event', 'hub', 'choices', 'disabled', <?= count($disabledIdps) ?>);
103+
</script>
94104
<?php include __DIR__ . '/../common-footer.php' ?>
95105
</div>
96106
</body>

0 commit comments

Comments
 (0)