... | ... |
@@ -92,7 +92,7 @@ class CookiePolicy extends \Frontend |
92 | 92 |
|
93 | 93 |
if (\Input::get('cookiepolicy_commit') == $_SESSION['eSM_cookiepolicy_token']) |
94 | 94 |
{ |
95 |
- preg_match('/(?P<subdomain>[a-z0-9][a-z0-9\-]{1,63}|)\.(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', \Environment::get('host'), $regs); |
|
95 |
+ preg_match('/((?P<subdomain>[a-z0-9][a-z0-9\-]{1,63}|)\.|^)(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', \Environment::get('host'), $regs); |
|
96 | 96 |
|
97 | 97 |
setcookie('eSM_cookiepolicy_passed', true, time()+31536000, '/',$regs['subdomain'].'.'.$regs['domain']); |
98 | 98 |
unset($_SESSION['eSM_cookiepolicy_token']); |
... | ... |
@@ -92,9 +92,9 @@ class CookiePolicy extends \Frontend |
92 | 92 |
|
93 | 93 |
if (\Input::get('cookiepolicy_commit') == $_SESSION['eSM_cookiepolicy_token']) |
94 | 94 |
{ |
95 |
- preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', \Environment::get('host'), $regs); |
|
95 |
+ preg_match('/(?P<subdomain>[a-z0-9][a-z0-9\-]{1,63}|)\.(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', \Environment::get('host'), $regs); |
|
96 | 96 |
|
97 |
- setcookie('eSM_cookiepolicy_passed', true, time()+31536000, '/','.'.$regs['domain']); |
|
97 |
+ setcookie('eSM_cookiepolicy_passed', true, time()+31536000, '/',$regs['subdomain'].'.'.$regs['domain']); |
|
98 | 98 |
unset($_SESSION['eSM_cookiepolicy_token']); |
99 | 99 |
|
100 | 100 |
return true; |
... | ... |
@@ -68,10 +68,14 @@ class CookiePolicy extends \Frontend |
68 | 68 |
$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
69 | 69 |
|
70 | 70 |
// Add dialog css to page |
71 |
- array_unshift($GLOBALS['TL_CSS'], 'system/modules/eSM_cookiepolicy/assets/css/cp_theme.css||static'); |
|
71 |
+ $GLOBALS['TL_CSS'][] = 'system/modules/eSM_cookiepolicy/assets/css/cp_theme.css||static'; |
|
72 | 72 |
|
73 | 73 |
// Add dialog code to page |
74 |
- $GLOBALS['TL_BODY'][] = $this->replaceInsertTags($objTemplate->parse(),false); |
|
74 |
+ if (!is_array($GLOBALS['TL_BODY'])) |
|
75 |
+ { |
|
76 |
+ $GLOBALS['TL_BODY'] = array(); |
|
77 |
+ } |
|
78 |
+ array_unshift($GLOBALS['TL_BODY'],$this->replaceInsertTags($objTemplate->parse(),false)); |
|
75 | 79 |
} |
76 | 80 |
|
77 | 81 |
/** |
... | ... |
@@ -67,8 +67,11 @@ class CookiePolicy extends \Frontend |
67 | 67 |
$objTemplate->btn_confirm = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm']; |
68 | 68 |
$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
69 | 69 |
|
70 |
+ // Add dialog css to page |
|
71 |
+ array_unshift($GLOBALS['TL_CSS'], 'system/modules/eSM_cookiepolicy/assets/css/cp_theme.css||static'); |
|
72 |
+ |
|
70 | 73 |
// Add dialog code to page |
71 |
- $GLOBALS['TL_JQUERY'][] = $this->replaceInsertTags($objTemplate->parse(),false); |
|
74 |
+ $GLOBALS['TL_BODY'][] = $this->replaceInsertTags($objTemplate->parse(),false); |
|
72 | 75 |
} |
73 | 76 |
|
74 | 77 |
/** |
... | ... |
@@ -68,7 +68,7 @@ class CookiePolicy extends \Frontend |
68 | 68 |
$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
69 | 69 |
|
70 | 70 |
// Add dialog code to page |
71 |
- $GLOBALS['TL_JQUERY'][] = $this->replaceInsertTags($objTemplate->parse()); |
|
71 |
+ $GLOBALS['TL_JQUERY'][] = $this->replaceInsertTags($objTemplate->parse(),false); |
|
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
/** |
... | ... |
@@ -63,7 +63,7 @@ class CookiePolicy extends \Frontend |
63 | 63 |
|
64 | 64 |
// Set template vars |
65 | 65 |
$objTemplate->title = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['title']; |
66 |
- $objTemplate->text = $this->replacePlaceholders($this->objRootPage->esm_cookiepolicy_text); |
|
66 |
+ $objTemplate->text = preg_replace('/(\\n|\\r)/',' ',$this->replacePlaceholders($this->objRootPage->esm_cookiepolicy_text)); |
|
67 | 67 |
$objTemplate->btn_confirm = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm']; |
68 | 68 |
$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
69 | 69 |
|
... | ... |
@@ -68,7 +68,7 @@ class CookiePolicy extends \Frontend |
68 | 68 |
$objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
69 | 69 |
|
70 | 70 |
// Add dialog code to page |
71 |
- $GLOBALS['TL_JQUERY'][] = $objTemplate->parse(); |
|
71 |
+ $GLOBALS['TL_JQUERY'][] = $this->replaceInsertTags($objTemplate->parse()); |
|
72 | 72 |
} |
73 | 73 |
|
74 | 74 |
/** |
... | ... |
@@ -79,7 +79,9 @@ class CookiePolicy extends \Frontend |
79 | 79 |
public static function ajaxPassCookiePolicy() |
80 | 80 |
{ |
81 | 81 |
if (!\Input::get('cookiepolicy_commit')) |
82 |
+ { |
|
82 | 83 |
return false; |
84 |
+ } |
|
83 | 85 |
|
84 | 86 |
if (\Input::get('cookiepolicy_commit') == $_SESSION['eSM_cookiepolicy_token']) |
85 | 87 |
{ |
... | ... |
@@ -90,6 +92,8 @@ class CookiePolicy extends \Frontend |
90 | 92 |
|
91 | 93 |
return true; |
92 | 94 |
} |
95 |
+ |
|
96 |
+ return false; |
|
93 | 97 |
} |
94 | 98 |
|
95 | 99 |
/** |
... | ... |
@@ -27,11 +27,19 @@ class CookiePolicy extends \Frontend |
27 | 27 |
*/ |
28 | 28 |
protected $strTemplate = 'cookiepolicy_dialog'; |
29 | 29 |
|
30 |
+ /** |
|
31 |
+ * Root page object |
|
32 |
+ * @var \PageModel|null |
|
33 |
+ */ |
|
30 | 34 |
protected $objRootPage; |
31 | 35 |
|
32 | 36 |
|
33 | 37 |
/** |
34 | 38 |
* Cookie policy check |
39 |
+ * |
|
40 |
+ * @param \PageModel $objPage |
|
41 |
+ * @param \LayoutModel $objLayout |
|
42 |
+ * @param \PageRegular $objPageRegular |
|
35 | 43 |
*/ |
36 | 44 |
public function cookiePolicyCheck(\PageModel $objPage, \LayoutModel $objLayout, \PageRegular $objPageRegular) |
37 | 45 |
{ |
... | ... |
@@ -61,10 +69,13 @@ class CookiePolicy extends \Frontend |
61 | 69 |
|
62 | 70 |
// Add dialog code to page |
63 | 71 |
$GLOBALS['TL_JQUERY'][] = $objTemplate->parse(); |
64 |
- |
|
65 |
- |
|
66 | 72 |
} |
67 | 73 |
|
74 |
+ /** |
|
75 |
+ * Is policy token correct |
|
76 |
+ * |
|
77 |
+ * @return bool |
|
78 |
+ */ |
|
68 | 79 |
public static function ajaxPassCookiePolicy() |
69 | 80 |
{ |
70 | 81 |
if (!\Input::get('cookiepolicy_commit')) |
... | ... |
@@ -80,7 +91,12 @@ class CookiePolicy extends \Frontend |
80 | 91 |
return true; |
81 | 92 |
} |
82 | 93 |
} |
83 |
- |
|
94 |
+ |
|
95 |
+ /** |
|
96 |
+ * Create and return a 32 char token |
|
97 |
+ * |
|
98 |
+ * @return string |
|
99 |
+ */ |
|
84 | 100 |
protected function createToken() |
85 | 101 |
{ |
86 | 102 |
if (!$_SESSION['eSM_cookiepolicy_token']) |
... | ... |
@@ -97,6 +113,12 @@ class CookiePolicy extends \Frontend |
97 | 113 |
return $_SESSION['eSM_cookiepolicy_token']; |
98 | 114 |
} |
99 | 115 |
|
116 |
+ /** |
|
117 |
+ * Replace placeholders |
|
118 |
+ * |
|
119 |
+ * @param $strString |
|
120 |
+ * @return string |
|
121 |
+ */ |
|
100 | 122 |
protected function replacePlaceholders($strString) |
101 | 123 |
{ |
102 | 124 |
$strReturn = ''; |
... | ... |
@@ -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 |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,100 @@ |
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 |
+ |
|
18 |
+/** |
|
19 |
+ * Class CookiePolicy |
|
20 |
+ */ |
|
21 |
+class CookiePolicy extends \Frontend |
|
22 |
+{ |
|
23 |
+ |
|
24 |
+ /** |
|
25 |
+ * Template |
|
26 |
+ * @var string |
|
27 |
+ */ |
|
28 |
+ protected $strTemplate = 'cookiepolicy_dialog'; |
|
29 |
+ |
|
30 |
+ |
|
31 |
+ /** |
|
32 |
+ * Cookie policy check |
|
33 |
+ */ |
|
34 |
+ public function cookiePolicyCheck(\PageModel $objPage, \LayoutModel $objLayout, \PageRegular $objPageRegular) |
|
35 |
+ { |
|
36 |
+ // Skip cookie policy if passed before |
|
37 |
+ if ($this->Input->cookie('eSM_cookiepolicy_passed') || $objPage->esm_cookiepolicy_ignore) |
|
38 |
+ { |
|
39 |
+ return; |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ // Get root page |
|
43 |
+ $objRootPage = $this->getRootPageFromUrl(); |
|
44 |
+ |
|
45 |
+ // Don't check if cookie policy is disabled |
|
46 |
+ if (!$objRootPage->esm_cookiepolicy_check) |
|
47 |
+ { |
|
48 |
+ return; |
|
49 |
+ } |
|
50 |
+ |
|
51 |
+ // Get cookie policy page |
|
52 |
+ $objPolicyPage = \PageModel::findByPk($objRootPage->esm_cookiepolicy_jumpTo); |
|
53 |
+ |
|
54 |
+ // Load dialog template |
|
55 |
+ $objTemplate = new \FrontendTemplate($this->strTemplate); |
|
56 |
+ |
|
57 |
+ // Set template vars |
|
58 |
+ $objTemplate->title = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['title']; |
|
59 |
+ $objTemplate->text = sprintf($GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['text'], $this->generateFrontendUrl($objPolicyPage->row())); |
|
60 |
+ $objTemplate->btn_confirm = $GLOBALS['TL_LANG']['MSC']['esm_cookiepolicy']['btn_confirm']; |
|
61 |
+ $objTemplate->commitURL = 'system/modules/eSM_cookiepolicy/ajax/Ajax.php?do=cookiepolicy_authentication&cookiepolicy_commit='.$this->createToken(); |
|
62 |
+ |
|
63 |
+ // Add dialog code to page |
|
64 |
+ $GLOBALS['TL_JQUERY'][] = $objTemplate->parse(); |
|
65 |
+ |
|
66 |
+ |
|
67 |
+ } |
|
68 |
+ |
|
69 |
+ public static function ajaxPassCookiePolicy() |
|
70 |
+ { |
|
71 |
+ if (!\Input::get('cookiepolicy_commit')) |
|
72 |
+ return false; |
|
73 |
+ |
|
74 |
+ if (\Input::get('cookiepolicy_commit') == $_SESSION['eSM_cookiepolicy_token']) |
|
75 |
+ { |
|
76 |
+ preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', \Environment::get('host'), $regs); |
|
77 |
+ |
|
78 |
+ setcookie('eSM_cookiepolicy_passed', true, time()+31536000, '/','.'.$regs['domain']); |
|
79 |
+ unset($_SESSION['eSM_cookiepolicy_token']); |
|
80 |
+ |
|
81 |
+ return true; |
|
82 |
+ } |
|
83 |
+ } |
|
84 |
+ |
|
85 |
+ protected function createToken() |
|
86 |
+ { |
|
87 |
+ if (!$_SESSION['eSM_cookiepolicy_token']) |
|
88 |
+ { |
|
89 |
+ $length = 32; |
|
90 |
+ $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
91 |
+ $random_string = ""; |
|
92 |
+ for ($p = 0; $p < $length; $p++) |
|
93 |
+ { |
|
94 |
+ $random_string .= $characters[mt_rand(0, strlen($characters))]; |
|
95 |
+ } |
|
96 |
+ $_SESSION['eSM_cookiepolicy_token'] = $random_string; |
|
97 |
+ } |
|
98 |
+ return $_SESSION['eSM_cookiepolicy_token']; |
|
99 |
+ } |
|
100 |
+} |
|
0 | 101 |
\ No newline at end of file |