Browse code

Make the cookie policy text customizable

Benjamin Roth authored on08/06/2015 15:45:39
Showing8 changed files
... ...
@@ -27,6 +27,8 @@ class CookiePolicy extends \Frontend
27 27
 	 */
28 28
 	protected $strTemplate = 'cookiepolicy_dialog';
29 29
 
30
+	protected $objRootPage;
31
+
30 32
 
31 33
 	/**
32 34
 	 * Cookie policy check
... ...
@@ -40,23 +42,20 @@ class CookiePolicy extends \Frontend
40 42
 		}
41 43
 
42 44
 		// Get root page
43
-		$objRootPage = $this->getRootPageFromUrl();
45
+		$this->objRootPage = $this->getRootPageFromUrl();
44 46
 
45 47
 		// Don't check if cookie policy is disabled
46
-		if (!$objRootPage->esm_cookiepolicy_check)
48
+		if (!$this->objRootPage->esm_cookiepolicy_check)
47 49
 		{
48 50
 			return;
49 51
 		}
50 52
 
51
-		// Get cookie policy page
52
-		$objPolicyPage = \PageModel::findByPk($objRootPage->esm_cookiepolicy_jumpTo);
53
-
54 53
 		// Load dialog template
55 54
 		$objTemplate = new \FrontendTemplate($this->strTemplate);
56 55
 		
57 56
 		// Set template vars
58 57
 		$objTemplate->title = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['title'];
59
-		$objTemplate->text = sprintf($GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'], $this->generateFrontendUrl($objPolicyPage->row()));
58
+		$objTemplate->text = $this->replacePlaceholders($this->objRootPage->esm_cookiepolicy_text);
60 59
 		$objTemplate->btn_confirm = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm'];
61 60
 		$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken();
62 61
 
... ...
@@ -97,4 +96,30 @@ class CookiePolicy extends \Frontend
97 96
 		}
98 97
 		return $_SESSION['eSM_cookiepolicy_token'];
99 98
 	}
99
+
100
+	protected function replacePlaceholders($strString)
101
+	{
102
+		$strReturn = '';
103
+
104
+		// Get cookie policy page
105
+		$objPolicyPage = \PageModel::findByPk($this->objRootPage->esm_cookiepolicy_jumpTo);
106
+
107
+		// Remove any unwanted tags (especially PHP tags)
108
+		$strString = strip_tags($strString, \Config::get('allowedTags'));
109
+
110
+		// Split placeholders
111
+		$arrPlaceholders = preg_split('/(%%[^%]+%%)/', $strString, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
112
+
113
+		// Replace placeholders
114
+		foreach ($arrPlaceholders as $placeholder)
115
+		{
116
+			switch (strtolower($placeholder))
117
+			{
118
+				case '%%url%%':
119
+					$strString = preg_replace('/'.$placeholder.'/i',$this->generateFrontendUrl($objPolicyPage->row()),$strString);
120
+			}
121
+		}
122
+
123
+		return $strString;
124
+	}
100 125
 }
101 126
\ No newline at end of file
102 127
new file mode 100644
... ...
@@ -0,0 +1,35 @@
1
+<?php
2
+
3
+/**
4
+ * eSales Media Cookie Policy
5
+ *
6
+ * Copyright (C) 2013-2015 eSalesMedia
7
+ *
8
+ * @package    eSM_cookiepolicy
9
+ * @link       http://www.esales-media.de
10
+ * @license    commercial
11
+ *
12
+ * @author     Benjamin Roth <benjamin@esales-media.de>
13
+ */
14
+
15
+namespace eSM_cookiepolicy;
16
+
17
+class tl_page extends \Backend
18
+{
19
+	/**
20
+	 * Return default text if value is empty
21
+	 *
22
+	 * @param $varValue
23
+	 * @param \DataContainer $dc
24
+	 * @return String
25
+	 */
26
+	public function setDefaultCookieText($varValue, \DataContainer $dc)
27
+	{
28
+		if (!$varValue)
29
+		{
30
+			return $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'];
31
+		}
32
+
33
+		return $varValue;
34
+	}
35
+}
0 36
\ No newline at end of file
... ...
@@ -25,6 +25,7 @@ ClassLoader::addClasses(array
25 25
 (
26 26
 	// Classes
27 27
 	'eSM_cookiepolicy\CookiePolicy' => 'system/modules/eSM_cookiepolicy/classes/CookiePolicy.php',
28
+	'eSM_cookiepolicy\tl_page'      => 'system/modules/eSM_cookiepolicy/classes/tl_page.php',
28 29
 ));
29 30
 
30 31
 
... ...
@@ -19,7 +19,7 @@
19 19
 $GLOBALS['TL_DCA']['tl_page']['palettes']['root'] = str_replace('{meta_legend}', '{cookiepolicy_legend:hide},esm_cookiepolicy_check;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['root']);
20 20
 $GLOBALS['TL_DCA']['tl_page']['palettes']['regular'] = str_replace('{meta_legend}', '{cookiepolicy_legend:hide},esm_cookiepolicy_ignore;{meta_legend}',$GLOBALS['TL_DCA']['tl_page']['palettes']['regular']);
21 21
 $GLOBALS['TL_DCA']['tl_page']['palettes']['__selector__'][] = 'esm_cookiepolicy_check';
22
-$GLOBALS['TL_DCA']['tl_page']['subpalettes']['esm_cookiepolicy_check'] = 'esm_cookiepolicy_jumpTo';
22
+$GLOBALS['TL_DCA']['tl_page']['subpalettes']['esm_cookiepolicy_check'] = 'esm_cookiepolicy_jumpTo,esm_cookiepolicy_text';
23 23
 
24 24
 /**
25 25
  * Fields
... ...
@@ -50,4 +50,21 @@ $GLOBALS['TL_DCA']['tl_page']['fields']['esm_cookiepolicy_ignore'] = array
50 50
 	'exclude'                 => true,
51 51
 	'inputType'               => 'checkbox',
52 52
 	'sql'                     => "char(1) NOT NULL default ''"
53
+);
54
+
55
+$GLOBALS['TL_DCA']['tl_page']['fields']['esm_cookiepolicy_text'] = array
56
+(
57
+	'label'                   => &$GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_text'],
58
+	'exclude'                 => true,
59
+	'inputType'               => 'textarea',
60
+	'load_callback'            => array
61
+	(
62
+		array('\eSM_cookiepolicy\tl_page', 'setDefaultCookieText')
63
+	),
64
+	'save_callback'            => array
65
+	(
66
+		array('\eSM_cookiepolicy\tl_page', 'setDefaultCookieText')
67
+	),
68
+	'eval'                    => array('rte'=>'tinyMCE', 'minlen'=>1, 'allowHtml'=>true),
69
+	'sql'                     => "text NULL"
53 70
 );
54 71
\ No newline at end of file
... ...
@@ -17,5 +17,5 @@
17 17
  * Miscellaneous
18 18
  */
19 19
 $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['title'] = 'Cookies auf dieser Seite';
20
-$GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'] = 'Diese Webseite verwendet Cookies gemäß unseren <a href="%s" target="_blank">Datenschutzbestimmungen</a>. Durch die Nutzung unserer Webseite und dem abrufen von Inhalten, erklärst Du Dich mit der Verwendung von Cookies einverstanden.';
20
+$GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'] = 'Diese Webseite verwendet Cookies gemäß unseren <a href="%%url%%" target="_blank">Datenschutzbestimmungen</a>. Durch die Nutzung unserer Webseite und dem abrufen von Inhalten, erklärst Du Dich mit der Verwendung von Cookies einverstanden.';
21 21
 $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm'] = 'Hinweis schließen';
... ...
@@ -19,6 +19,7 @@
19 19
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_check'] = array('Cookie-Hinweis anzeigen', 'Es erscheint eine Dialogbox mit dem Hinweis, dass diese Seite Cookies verwendet.');
20 20
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_jumpTo'] = array('Seite mit Datenschutzhinweisen', 'Die Seite, auf welcher sich die Datenschutzhinweise befinden.');
21 21
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_ignore'] = array('Cookie-Hinweis ignorieren', 'Auf dieser Seite wird der Cookie-Hinweis nicht dargestellt.');
22
+$GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_text'] = array('Cookie-Hinweis Text', 'Dieser Text wird als Hinweis ausgegeben. Ist das Feld leer, wird der Standardtext vorbelegt. Platzhalter: <em>%%url%%</em> = URL der Datenschutzhinweisseite.');
22 23
 
23 24
 
24 25
 /**
... ...
@@ -29,7 +30,4 @@ $GLOBALS['TL_LANG']['tl_page'][''] = '';
29 30
 /**
30 31
  * Legends
31 32
  */
32
-$GLOBALS['TL_LANG']['tl_page']['cookiepolicy_legend'] = 'Cookie-Hinweis';
33
-
34
-
35
-?>
36 33
\ No newline at end of file
34
+$GLOBALS['TL_LANG']['tl_page']['cookiepolicy_legend'] = 'Cookie-Hinweis';
37 35
\ No newline at end of file
... ...
@@ -17,5 +17,5 @@
17 17
  * Miscellaneous
18 18
  */
19 19
 $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['title'] = 'Cookies on this page';
20
-$GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'] = 'This website is using cookies according to our <a href="%s" target="_blank">Privacy Policy</a>. By using this site and accessing provided informations, you accept the usage of cookies.';
20
+$GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'] = 'This website is using cookies according to our <a href="%%url%%" target="_blank">Privacy Policy</a>. By using this site and accessing provided informations, you accept the usage of cookies.';
21 21
 $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm'] = 'Close notification';
... ...
@@ -19,6 +19,7 @@
19 19
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_check'] = array('Show cookie policy', 'Will show a dialog with the information that this site is using cookies.');
20 20
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_jumpTo'] = array('Privacy Policy Page', 'The page containing the Privacy Policy.');
21 21
 $GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_ignore'] = array('Ignore cookie policy', 'The page will not show the cookie policy dialog.');
22
+$GLOBALS['TL_LANG']['tl_page']['esm_cookiepolicy_text'] = array('Cookie policy text', 'Text which is displayed to the user. Default text will be used if field is empy. Placeholder: <em>%%url%%</em> = Privacy policy page URL.');
22 23
 
23 24
 
24 25
 /**