Skip to content

Commit c27137d

Browse files
Merge pull request #53 from whitecube/49-cookie-injection-text
Cookie injection text
2 parents e8a363b + 7709c2d commit c27137d

File tree

5 files changed

+68
-3
lines changed

5 files changed

+68
-3
lines changed

resources/lang/en/cookies.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
'less' => 'Less details',
1414
],
1515
'save' => 'Save settings',
16+
'cookie' => 'Cookie',
17+
'purpose' => 'Purpose',
18+
'duration' => 'Duration',
19+
'year' => 'Year|Years',
20+
'day' => 'Day|Days',
21+
'hour' => 'Hour|Hours',
22+
'minute' => 'Minute|Minutes',
1623

1724
'categories' => [
1825
'essentials' => [
@@ -38,4 +45,4 @@
3845
'_gid' => 'Used by Google Analytics to identify the user.',
3946
'_gat' => 'Used by Google Analytics to throttle the request rate.',
4047
],
41-
];
48+
];

resources/lang/fr/cookies.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@
1313
'less' => 'Moins d\'informations',
1414
],
1515
'save' => 'Enregistrer',
16+
'cookie' => 'Cookie',
17+
'purpose' => 'But',
18+
'duration' => 'Durée',
19+
'year' => 'Année|Années',
20+
'day' => 'Jour|Jours',
21+
'hour' => 'Heure|Heures',
22+
'minute' => 'Minute|Minutes',
1623

1724
'categories' => [
1825
'essentials' => [
@@ -38,4 +45,4 @@
3845
'_gid' => 'Utilisé par Google Analytics pour identifier un visiteur.',
3946
'_gat' => 'Utilisé par Google Analytics pour limiter le taux de demande.',
4047
],
41-
];
48+
];

resources/views/info.blade.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@foreach($cookies->getCategories() as $category)
2+
<h3>{{ $category->title }}</h3>
3+
<table>
4+
<thead>
5+
<th>@lang('cookieConsent::cookies.cookie')</th>
6+
<th>@lang('cookieConsent::cookies.purpose')</th>
7+
<th>@lang('cookieConsent::cookies.duration')</th>
8+
</thead>
9+
<tbody>
10+
@foreach($category->getCookies() as $cookie)
11+
<tr>
12+
<td>{{ $cookie->name }}</td>
13+
<td>{{ $cookie->description }}</td>
14+
<td>{{ \Carbon\CarbonInterval::minutes($cookie->duration)->cascade() }}</td>
15+
</tr>
16+
@endforeach
17+
</tbody>
18+
</table>
19+
@endforeach

src/CookiesManager.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,32 @@ public function renderButton(string $action, ?string $label = null, array $attri
266266
'basename' => $basename,
267267
])->render();
268268
}
269+
270+
/**
271+
* Output a table with all the cookies infos.
272+
*/
273+
public function renderInfo(): string
274+
{
275+
return view('cookie-consent::info', [
276+
'cookies' => $this->registrar,
277+
])->render();
278+
}
279+
280+
public function replaceInfoTag(string $wysiwyg): string
281+
{
282+
$cookieConsentInfo = view('cookie-consent::info', [
283+
'cookies' => $this->registrar,
284+
])->render();
285+
286+
$formattedString = preg_replace(
287+
[
288+
'/\<(\w)[^\>]+\>\@cookieconsentinfo\<\/\1\>/',
289+
'/\@cookieconsentinfo/',
290+
],
291+
$cookieConsentInfo,
292+
$wysiwyg,
293+
);
294+
295+
return $formattedString;
296+
}
269297
}

src/ServiceProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,9 @@ protected function registerBladeDirectives()
7474
Blade::directive('cookieconsentbutton', function (string $expression) {
7575
return '<?php echo ' . Facades\Cookies::class . '::renderButton(' . $expression . '); ?>';
7676
});
77+
78+
Blade::directive('cookieconsentinfo', function () {
79+
return '<?php echo ' . Facades\Cookies::class . '::renderInfo(); ?>';
80+
});
7781
}
78-
}
82+
}

0 commit comments

Comments
 (0)