Browse code

Contao 4 compatibility

Benjamin Roth authored on06/06/2017 16:22:01
Showing1 changed files
... ...
@@ -28,6 +28,7 @@ if(!$_SERVER['HTTP_X_REQUESTED_WITH'] || strtolower($_SERVER['HTTP_X_REQUESTED_W
28 28
  * Initialize the system
29 29
  */
30 30
 
31
+define('TL_SCRIPT', 'system/modules/eSM_cookiepolicy/ajax/Ajax.php');
31 32
 define('TL_MODE', 'FE');
32 33
 require '../../../initialize.php';
33 34
 
Browse code

Remove User authentication in Ajax since we don't need it.

Benjamin Roth authored on24/09/2015 09:48:16
Showing1 changed files
... ...
@@ -38,18 +38,11 @@ class CookiePolicyAsync extends \Frontend
38 38
 		\Controller::setStaticUrls();
39 39
 		\Controller::loadLanguageFile('default');
40 40
 
41
-		$this->import('FrontendUser', 'User');
42 41
 		parent::__construct();
43
-
44
-		// Check whether a user is logged in
45
-		define('BE_USER_LOGGED_IN', $this->getLoginStatus('BE_USER_AUTH'));
46
-		define('FE_USER_LOGGED_IN', $this->getLoginStatus('FE_USER_AUTH'));
47 42
 	}
48 43
 
49 44
 	public function run()
50 45
 	{
51
-		$this->User->authenticate();
52
-
53 46
 		$strBuffer = '';
54 47
 		switch(\Input::get('do'))
55 48
 		{
... ...
@@ -72,15 +65,6 @@ class CookiePolicyAsync extends \Frontend
72 65
 		exit;
73 66
 	}
74 67
 
75
-	protected function authorizedOrDie()
76
-	{
77
-		if (!FE_USER_LOGGED_IN)
78
-		{
79
-			header('HTTP/1.1 403 Forbidden');
80
-			die('Community: User not logged in');
81
-		}
82
-	}
83
-
84 68
 	protected function preconditionFailed()
85 69
 	{
86 70
 		header('HTTP/1.1 412 Precondition Failed');
Browse code

Initial commit

Benjamin Roth authored on26/03/2015 15:51:42
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,93 @@
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
+ * AJAX check
19
+ */
20
+
21
+if(!$_SERVER['HTTP_X_REQUESTED_WITH'] || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
22
+	header('HTTP/1.1 403 Forbidden');
23
+	die("File cannot be executed directly");
24
+}
25
+
26
+
27
+/**
28
+ * Initialize the system
29
+ */
30
+
31
+define('TL_MODE', 'FE');
32
+require '../../../initialize.php';
33
+
34
+class CookiePolicyAsync extends \Frontend
35
+{
36
+	public function __construct()
37
+	{
38
+		\Controller::setStaticUrls();
39
+		\Controller::loadLanguageFile('default');
40
+
41
+		$this->import('FrontendUser', 'User');
42
+		parent::__construct();
43
+
44
+		// Check whether a user is logged in
45
+		define('BE_USER_LOGGED_IN', $this->getLoginStatus('BE_USER_AUTH'));
46
+		define('FE_USER_LOGGED_IN', $this->getLoginStatus('FE_USER_AUTH'));
47
+	}
48
+
49
+	public function run()
50
+	{
51
+		$this->User->authenticate();
52
+
53
+		$strBuffer = '';
54
+		switch(\Input::get('do'))
55
+		{
56
+			case 'cookiepolicy_authentication':
57
+				if (!is_null(\Input::get('cookiepolicy_commit')))
58
+				{
59
+					$strBuffer = json_encode(array('status'=>(CookiePolicy::ajaxPassCookiePolicy() ? 'OK' : 'FAILED')));
60
+				} else {
61
+					$this->preconditionFailed();
62
+				}
63
+				break;
64
+
65
+			default:
66
+				$this->preconditionFailed();
67
+				break;
68
+		}
69
+
70
+		header('Content-Type: application/json; charset=utf-8');
71
+		echo $strBuffer;
72
+		exit;
73
+	}
74
+
75
+	protected function authorizedOrDie()
76
+	{
77
+		if (!FE_USER_LOGGED_IN)
78
+		{
79
+			header('HTTP/1.1 403 Forbidden');
80
+			die('Community: User not logged in');
81
+		}
82
+	}
83
+
84
+	protected function preconditionFailed()
85
+	{
86
+		header('HTTP/1.1 412 Precondition Failed');
87
+		echo 'Community: Precondition failed';
88
+		exit();
89
+	}
90
+}
91
+
92
+$Ajax = new CookiePolicyAsync();
93
+$Ajax->run();
0 94
\ No newline at end of file