Skip to content

Commit 8172645

Browse files
authored
Merge pull request #57 from RRZE-Webteam/dev
Dev
2 parents fe0ef59 + c93fd3e commit 8172645

File tree

5 files changed

+99
-3
lines changed

5 files changed

+99
-3
lines changed

includes/Consent/Cookies.php

+48
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
defined('ABSPATH') || exit;
66

7+
use function RRZE\Legal\{consent, consentCookies};
8+
79
class Cookies
810
{
911
const CONSENT_COOKIE_NAME = 'rrze-legal-consent';
@@ -32,4 +34,50 @@ public static function checkConsent($cookieId)
3234

3335
return $consent;
3436
}
37+
38+
public static function setEssentialCookie()
39+
{
40+
if (!empty($_COOKIE[self::CONSENT_COOKIE_NAME])) {
41+
return;
42+
}
43+
44+
$categories = consentCookies()->getAllCookieCategories();
45+
if (empty($categories)) {
46+
return;
47+
}
48+
49+
$consents = [];
50+
foreach ($categories as $category) {
51+
if (empty($category['cookies'])) {
52+
continue;
53+
}
54+
55+
foreach (array_keys($category['cookies']) as $key) {
56+
$consents[$category['id']][$category['id']][] = $key;
57+
}
58+
}
59+
60+
$expires = strtotime('+6 months');
61+
$siteUrl = trailingslashit(site_url());
62+
$parseUrl = parse_url($siteUrl);
63+
$host = $parseUrl['host'];
64+
$path = $parseUrl['path'];
65+
$content = [
66+
'consents' => $consents['essential'],
67+
'domainPath' => $host . $path,
68+
// e.g. Tue, 21 Mar 2023 14:50:55 GMT
69+
'expires' => date('D, j M Y H:i:s \G\M\T', $expires),
70+
'uid' => 'anonymous',
71+
'version' => consent()->getCookieVersion()
72+
];
73+
$content = json_encode($content);
74+
75+
setcookie(
76+
self::CONSENT_COOKIE_NAME,
77+
$content,
78+
$expires,
79+
$path,
80+
$host
81+
);
82+
}
3583
}

includes/Consent/Frontend.php

+48
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ public static function loaded()
2525
*/
2626
public static function init()
2727
{
28+
if (self::rrzeAccessControlPlugin()) {
29+
Cookies::setEssentialCookie();
30+
return;
31+
} elseif (self::rrzePrivateSitePlugin()) {
32+
return;
33+
}
34+
2835
if (consent()->isBannerActive() || consent()->isTestModeActive()) {
2936
// Add scripts and styles
3037
add_action('wp_enqueue_scripts', [__CLASS__, 'enqueueScripts']);
@@ -137,4 +144,45 @@ public static function handleCookiesForIpAddresses()
137144
echo json_encode(['check' => $check]);
138145
wp_die();
139146
}
147+
148+
public static function rrzeAccessControlPlugin()
149+
{
150+
if (
151+
!Utils::isPluginActive('rrze-ac/rrze-ac.php')
152+
&& !Utils::isPluginActiveForNetwork('rrze-ac/rrze-ac.php')
153+
154+
) {
155+
return false;
156+
}
157+
158+
$currentURL = '//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
159+
$postId = url_to_postid($currentURL);
160+
$post = $postId ? get_post($postId) : 0;
161+
if (
162+
!($post instanceof \WP_Post)
163+
|| !in_array($post->post_type, ['page', 'attachment'])
164+
) {
165+
return false;
166+
}
167+
168+
$meta = get_post_meta($postId, '_access_permission');
169+
if (empty($meta) || $meta == 'all') {
170+
return false;
171+
}
172+
173+
return true;
174+
}
175+
176+
public static function rrzePrivateSitePlugin()
177+
{
178+
if (
179+
!Utils::isPluginActive('rrze-private-site/rrze-private-site.php')
180+
&& !Utils::isPluginActiveForNetwork('rrze-private-site/rrze-private-site.php')
181+
182+
) {
183+
return false;
184+
}
185+
186+
return true;
187+
}
140188
}

includes/Consent/JavaScript.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public function registerFooter()
140140
'settings' => [
141141
'blockCookiesBeforeConsent' => false,
142142
'prioritize' => false,
143-
'asyncOptOutCode' => (bool) $cookieData['async_opt_out_code'],
143+
'asyncOptOutCode' => (bool) $cookieData['async_opt_out_code'] ?? 0,
144144
],
145145
];
146146

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rrze-legal",
3-
"version": "2.4.1",
3+
"version": "2.5.0",
44
"main": "rrze-legal.php",
55
"scripts": {
66
"start": "webpack --mode=development --watch",

rrze-legal.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Plugin Name: RRZE Legal
55
Plugin URI: https://gitlab.rrze.fau.de/rrze-webteam/rrze-legal
66
Description: Legal Mandatory Information & GDPR.
7-
Version: 2.4.1
7+
Version: 2.5.0
88
Author: RRZE Webteam
99
Author URI: https://blogs.fau.de/webworking/
1010
License: GNU General Public License Version 3

0 commit comments

Comments
 (0)