Browse code

Follow coding standards by moving the independent class in classes subfolder

Benjamin Roth authored on27/03/2015 09:57:53
Showing3 changed files
1 1
deleted file mode 100644
... ...
@@ -1,100 +0,0 @@
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
-}
101 0
\ No newline at end of file
102 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
... ...
@@ -23,7 +23,8 @@ ClassLoader::addNamespaces(array
23 23
  */
24 24
 ClassLoader::addClasses(array
25 25
 (
26
-	'eSM_cookiepolicy\CookiePolicy' => 'system/modules/eSM_cookiepolicy/CookiePolicy.php',
26
+	// Classes
27
+	'eSM_cookiepolicy\CookiePolicy' => 'system/modules/eSM_cookiepolicy/classes/CookiePolicy.php',
27 28
 ));
28 29
 
29 30