Passed
Push — develop ( a5e1bf...c22bc5 )
by Jens
02:34
created
src/templates/documents/function.renderDocument.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -31,26 +31,26 @@
 block discarded – undo
31 31
   <div class="documentActions grid-box-2">
32 32
       <? if ($document->state == 'unpublished' || $document->unpublishedChanges) : ?>
33 33
           <? renderAction('Publish',
34
-              'publish',
35
-              $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
36
-              'check'); ?>
34
+			  'publish',
35
+			  $request::$subfolders . $cmsPrefix . '/documents/publish-document?slug=' . $slugPrefix . $document->slug,
36
+			  'check'); ?>
37 37
       <? endif ?>
38 38
       <? if ($document->state == 'published') : ?>
39 39
           <? renderAction('Unpublish',
40
-              'unpublish',
41
-              $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
42
-              'times'); ?>
40
+			  'unpublish',
41
+			  $request::$subfolders . $cmsPrefix . '/documents/unpublish-document?slug=' . $slugPrefix . $document->slug,
42
+			  'times'); ?>
43 43
       <? endif ?>
44 44
       <? renderAction('Edit',
45
-          '',
46
-          $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
47
-          'pencil'); ?>
45
+		  '',
46
+		  $request::$subfolders . $cmsPrefix . '/documents/edit-document?slug=' . $slugPrefix . $document->slug,
47
+		  'pencil'); ?>
48 48
       <? if ($document->state == 'unpublished') : ?>
49 49
           <? renderAction('Delete',
50
-              'error',
51
-              $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
52
-              'trash',
53
-              'return confirm(\'Are you sure you want to delete this document?\');'); ?>
50
+			  'error',
51
+			  $request::$subfolders . $cmsPrefix . '/documents/delete-document?slug=' . $slugPrefix . $document->slug,
52
+			  'trash',
53
+			  'return confirm(\'Are you sure you want to delete this document?\');'); ?>
54 54
       <? endif ?>
55 55
   </div>
56 56
 <? } ?>
Please login to merge, or discard this patch.
src/templates/documents/brick.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 </div>
5 5
 <label><?= $brick->title ?></label>
6 6
 <? if ($static == true) {
7
-    $fieldPrefix = 'bricks[' . $myBrickSlug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . '][fields]';
7
+	$fieldPrefix = 'bricks[' . $myBrickSlug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . '][fields]';
8 8
 } else {
9
-    $fieldPrefix = 'dynamicBricks[' . $brick->slug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . ']';
9
+	$fieldPrefix = 'dynamicBricks[' . $brick->slug . '][' . str_replace('.', '', str_replace(' ', '', microtime())) . ']';
10 10
 } ?>
11 11
 <? foreach ($brick->fields as $field) : ?>
12 12
 			<div class="form-element">
Please login to merge, or discard this patch.
src/templates/documents/fieldTypes/Rich-Text.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?
2 2
 if (isset($summernoteInstances)) {
3
-    $summernoteInstances += 1;
3
+	$summernoteInstances += 1;
4 4
 } else {
5
-    $summernoteInstances = 1;
5
+	$summernoteInstances = 1;
6 6
 }
7 7
 ?>
8 8
 <div class="rte">
@@ -26,6 +26,6 @@  discard block
 block discarded – undo
26 26
 </script>
27 27
 <?
28 28
 if (!isset($GLOBALS['rteList'])) {
29
-    $GLOBALS['rteList'] = array();
29
+	$GLOBALS['rteList'] = array();
30 30
 }
31 31
 $GLOBALS['rteList'][] = 'summernote_' . str_replace(']', '-', str_replace('[', '-', $fieldPrefix)) . $field->slug . '_rte_' . $summernoteInstances ?>
Please login to merge, or discard this patch.
src/templates/documents/function.renderFolder.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,14 +17,14 @@
 block discarded – undo
17 17
   </div>
18 18
   <div class="documentActions grid-box-4">
19 19
       <? renderAction('Edit',
20
-          '',
21
-          $request::$subfolders . $cmsPrefix . '/documents/edit-folder?slug=' . $slugPrefix . $document->slug,
22
-          'pencil'); ?>
20
+		  '',
21
+		  $request::$subfolders . $cmsPrefix . '/documents/edit-folder?slug=' . $slugPrefix . $document->slug,
22
+		  'pencil'); ?>
23 23
       <? renderAction('Delete',
24
-          'error',
25
-          $request::$subfolders . $cmsPrefix . '/documents/delete-folder?slug=' . $slugPrefix . $document->slug,
26
-          'trash',
27
-          'return confirm(\'Are you sure you want to delete this document?\');'); ?>
24
+		  'error',
25
+		  $request::$subfolders . $cmsPrefix . '/documents/delete-folder?slug=' . $slugPrefix . $document->slug,
26
+		  'trash',
27
+		  'return confirm(\'Are you sure you want to delete this document?\');'); ?>
28 28
   </div>
29 29
   <ul class="documents grid-wrapper nested<?= $root ? ' root' : '' ?>">
30 30
       <? foreach ($document->getContent() as $subDocument) : ?>
Please login to merge, or discard this patch.
src/CloudControl.php 1 patch
Indentation   +126 added lines, -126 removed lines patch added patch discarded remove patch
@@ -11,131 +11,131 @@
 block discarded – undo
11 11
 
12 12
 class CloudControl
13 13
 {
14
-    public static function run()
15
-    {
16
-        new Application();
17
-    }
18
-
19
-    public static function postInstall(Event $event)
20
-    {
21
-        $event->getIO()->write("Post install");
22
-        self::checkInstall($event);
23
-    }
24
-
25
-    public static function postUpdate(Event $event)
26
-    {
27
-        $event->getIO()->write("Post update");
28
-        self::checkInstall($event);
29
-    }
30
-
31
-    /**
32
-     * @param Event $event
33
-     */
34
-    private static function checkInstall(Event $event)
35
-    {
36
-        $event->getIO()->write("*** Checking installation of Cloud Control framework ***");
37
-
38
-        $vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
39
-        $rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
40
-
41
-        $baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json';
42
-        $configObject = self::getConfig($baseConfigTargetPath);
43
-
44
-        $configObject->{'vendorDir'} = realpath($vendorDir);
45
-        $configObject->{'rootDir'} = $rootDir;
46
-        $configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates');
47
-        $configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'});
48
-        $configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public');
49
-        $configObject->{'jsDir'} = self::createDir($event, $configObject->{'publicDir'}, 'js');
50
-        $configObject->{'cssDir'} = self::createDir($event, $configObject->{'publicDir'}, 'css');
51
-        $configObject->{'imagesDir'} = self::createDir($event, $configObject->{'publicDir'}, 'images');
52
-        $configObject->{'filesDir'} = self::createDir($event, $configObject->{'publicDir'}, 'files');
53
-
54
-        // TODO Fie FilesStorage to use filesDir from config, similar to ImagesStorage
55
-
56
-        $baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json';
57
-        $baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql';
58
-
59
-        self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath);
60
-        self::saveConfig($event, $baseConfigTargetPath, $configObject);
61
-        self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess');
62
-        self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess');
63
-        self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'});
64
-        self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'});
65
-        self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'});
66
-        self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'});
67
-    }
68
-
69
-    /**
70
-     * @param Event $event
71
-     * @param $baseConfigTargetPath
72
-     * @param $configObject
73
-     * @internal param $rootDir
74
-     * @internal param $vendorDir
75
-     * @internal param $templateDir
76
-     * @internal param $storageDir
77
-     * @internal param $baseConfigDefaultPath
78
-     * @internal param $baseConfigTargetPath
79
-     * @internal param $storageDir
80
-     */
81
-    private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject)
82
-    {
83
-        file_put_contents($baseConfigTargetPath, json_encode($configObject));
84
-        $event->getIO()->write("Saved config to: " . $baseConfigTargetPath);
85
-    }
86
-
87
-    private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null)
88
-    {
89
-        $sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName);
90
-
91
-        if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) {
92
-            if ($destinationFileName !== null) {
93
-                copy($sourceFilePath, realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName);
94
-            } else {
95
-                copy($sourceFilePath, realpath($destinationPath) . DIRECTORY_SEPARATOR . $sourceFileName);
96
-            }
97
-
98
-            $event->getIO()->write("Copied file: " . $sourceFileName . ' to ' . $destinationPath);
99
-        } else {
100
-            $event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath);
101
-        }
102
-    }
103
-
104
-    /**
105
-     * @param $storageDir
106
-     * @param $baseStorageDefaultPath
107
-     * @param $baseStorageSqlPath
108
-     */
109
-    private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath)
110
-    {
111
-        $repository = new Repository($storageDir);
112
-        $repository->init($baseStorageDefaultPath, $baseStorageSqlPath);
113
-    }
114
-
115
-    private static function createDir(Event $event, $rootDir, $dirName)
116
-    {
117
-        $dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR;
118
-        if (!is_dir($dir)) {
119
-            mkdir($dir);
120
-            $event->getIO()->write("Created dir: " . $dir);
121
-        }
122
-        return realpath($dir);
123
-    }
124
-
125
-    /**
126
-     * @param $configTargetPath
127
-     * @return mixed
128
-     */
129
-    private static function getConfig($configTargetPath)
130
-    {
131
-        $baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_config.json');
132
-
133
-        if (file_exists($configTargetPath)) {
134
-            $config = json_decode(file_get_contents($configTargetPath));
135
-        } else {
136
-            $config = json_decode(file_get_contents($baseConfigDefaultPath));
137
-        }
138
-        return $config;
139
-    }
14
+	public static function run()
15
+	{
16
+		new Application();
17
+	}
18
+
19
+	public static function postInstall(Event $event)
20
+	{
21
+		$event->getIO()->write("Post install");
22
+		self::checkInstall($event);
23
+	}
24
+
25
+	public static function postUpdate(Event $event)
26
+	{
27
+		$event->getIO()->write("Post update");
28
+		self::checkInstall($event);
29
+	}
30
+
31
+	/**
32
+	 * @param Event $event
33
+	 */
34
+	private static function checkInstall(Event $event)
35
+	{
36
+		$event->getIO()->write("*** Checking installation of Cloud Control framework ***");
37
+
38
+		$vendorDir = $event->getComposer()->getConfig()->get('vendor-dir');
39
+		$rootDir = realpath($vendorDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
40
+
41
+		$baseConfigTargetPath = $rootDir . DIRECTORY_SEPARATOR . 'config.json';
42
+		$configObject = self::getConfig($baseConfigTargetPath);
43
+
44
+		$configObject->{'vendorDir'} = realpath($vendorDir);
45
+		$configObject->{'rootDir'} = $rootDir;
46
+		$configObject->{'templateDir'} = self::createDir($event, $rootDir, 'templates');
47
+		$configObject->{'storageDir'} = self::createDir($event, $rootDir, $configObject->{'storageDir'});
48
+		$configObject->{'publicDir'} = self::createDir($event, $rootDir, 'public');
49
+		$configObject->{'jsDir'} = self::createDir($event, $configObject->{'publicDir'}, 'js');
50
+		$configObject->{'cssDir'} = self::createDir($event, $configObject->{'publicDir'}, 'css');
51
+		$configObject->{'imagesDir'} = self::createDir($event, $configObject->{'publicDir'}, 'images');
52
+		$configObject->{'filesDir'} = self::createDir($event, $configObject->{'publicDir'}, 'files');
53
+
54
+		// TODO Fie FilesStorage to use filesDir from config, similar to ImagesStorage
55
+
56
+		$baseStorageDefaultPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.json';
57
+		$baseStorageSqlPath = __DIR__ . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . '_storage.sql';
58
+
59
+		self::createStorage($configObject->{'storageDir'}, $baseStorageDefaultPath, $baseStorageSqlPath);
60
+		self::saveConfig($event, $baseConfigTargetPath, $configObject);
61
+		self::copyInstallFile($event, 'public.htaccess', $configObject->{'publicDir'}, '.htaccess');
62
+		self::copyInstallFile($event, 'root.htaccess', $configObject->{'rootDir'}, '.htaccess');
63
+		self::copyInstallFile($event, 'base.php', $configObject->{'templateDir'});
64
+		self::copyInstallFile($event, 'cms.css', $configObject->{'cssDir'});
65
+		self::copyInstallFile($event, 'cms.js', $configObject->{'jsDir'});
66
+		self::copyInstallFile($event, 'index.php', $configObject->{'publicDir'});
67
+	}
68
+
69
+	/**
70
+	 * @param Event $event
71
+	 * @param $baseConfigTargetPath
72
+	 * @param $configObject
73
+	 * @internal param $rootDir
74
+	 * @internal param $vendorDir
75
+	 * @internal param $templateDir
76
+	 * @internal param $storageDir
77
+	 * @internal param $baseConfigDefaultPath
78
+	 * @internal param $baseConfigTargetPath
79
+	 * @internal param $storageDir
80
+	 */
81
+	private static function saveConfig(Event $event, $baseConfigTargetPath, $configObject)
82
+	{
83
+		file_put_contents($baseConfigTargetPath, json_encode($configObject));
84
+		$event->getIO()->write("Saved config to: " . $baseConfigTargetPath);
85
+	}
86
+
87
+	private static function copyInstallFile(Event $event, $sourceFileName, $destinationPath, $destinationFileName = null)
88
+	{
89
+		$sourceFilePath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_' . $sourceFileName);
90
+
91
+		if (file_exists($sourceFilePath) && realpath($destinationPath) !== false) {
92
+			if ($destinationFileName !== null) {
93
+				copy($sourceFilePath, realpath($destinationPath) . DIRECTORY_SEPARATOR . $destinationFileName);
94
+			} else {
95
+				copy($sourceFilePath, realpath($destinationPath) . DIRECTORY_SEPARATOR . $sourceFileName);
96
+			}
97
+
98
+			$event->getIO()->write("Copied file: " . $sourceFileName . ' to ' . $destinationPath);
99
+		} else {
100
+			$event->getIO()->write("[ERROR] Couldnt copy file: " . $sourceFileName . ' to ' . $destinationPath);
101
+		}
102
+	}
103
+
104
+	/**
105
+	 * @param $storageDir
106
+	 * @param $baseStorageDefaultPath
107
+	 * @param $baseStorageSqlPath
108
+	 */
109
+	private static function createStorage($storageDir, $baseStorageDefaultPath, $baseStorageSqlPath)
110
+	{
111
+		$repository = new Repository($storageDir);
112
+		$repository->init($baseStorageDefaultPath, $baseStorageSqlPath);
113
+	}
114
+
115
+	private static function createDir(Event $event, $rootDir, $dirName)
116
+	{
117
+		$dir = $rootDir . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR;
118
+		if (!is_dir($dir)) {
119
+			mkdir($dir);
120
+			$event->getIO()->write("Created dir: " . $dir);
121
+		}
122
+		return realpath($dir);
123
+	}
124
+
125
+	/**
126
+	 * @param $configTargetPath
127
+	 * @return mixed
128
+	 */
129
+	private static function getConfig($configTargetPath)
130
+	{
131
+		$baseConfigDefaultPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . 'install/_config.json');
132
+
133
+		if (file_exists($configTargetPath)) {
134
+			$config = json_decode(file_get_contents($configTargetPath));
135
+		} else {
136
+			$config = json_decode(file_get_contents($baseConfigDefaultPath));
137
+		}
138
+		return $config;
139
+	}
140 140
 
141 141
 }
142 142
\ No newline at end of file
Please login to merge, or discard this patch.
src/util/functions.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 		}
18 18
 	} else {
19 19
 		ob_clean();
20
-        echo <<<END
20
+		echo <<<END
21 21
 <!DOCTYPE html>
22 22
 <html>
23 23
 <head>
Please login to merge, or discard this patch.
src/components/NotFoundComponent.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
 
13 13
 class NotFoundComponent extends BaseComponent
14 14
 {
15
-    public function run(Storage $storage)
16
-    {
17
-        parent::run($storage);
18
-        header("HTTP/1.0 404 Not Found");
19
-    }
15
+	public function run(Storage $storage)
16
+	{
17
+		parent::run($storage);
18
+		header("HTTP/1.0 404 Not Found");
19
+	}
20 20
 
21 21
 }
22 22
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/LanguageComponent.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -6,124 +6,124 @@
 block discarded – undo
6 6
 
7 7
 class LanguageComponent implements Component
8 8
 {
9
-    protected $request;
10
-    protected $parameters;
11
-
12
-    protected $defaultLanguage = 'en';
13
-    protected $acceptedLanguages = null;
14
-    protected $languageParameterName = 'language';
15
-    protected $forceRedirect = false;
16
-    protected $sessionValues;
17
-
18
-    /**
19
-     * Component constructor.
20
-     *
21
-     * @param                     $template
22
-     * @param Request $request
23
-     * @param                     $parameters
24
-     * @param                     $matchedSitemapItem
25
-     */
26
-    public function __construct($template, Request $request, $parameters, $matchedSitemapItem)
27
-    {
28
-        $this->parameters = (array) $parameters;
29
-        $this->checkParameters();
30
-
31
-        $lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2);
32
-        $_SESSION['LanguageComponent']['detectedLanguage'] = $lang;
33
-
34
-        $this->checkLanguageSwitch($request);
35
-
36
-        if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) {
37
-            $this->detectLanguage($lang, $request);
38
-        } else {
39
-            if ($this->forceRedirect === true) {
40
-                $this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request);
41
-            }
42
-        }
43
-
44
-        $this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName];
45
-    }
46
-
47
-    /**
48
-     * Checks to see if any parameters are given from the configuration in the CMS
49
-     */
50
-    private function checkParameters()
51
-    {
52
-        if (isset($this->parameters['defaultLanguage'])) {
53
-            $this->defaultLanguage = $this->parameters['defaultLanguage'];
54
-            unset($this->parameters['defaultLanguage']);
55
-        }
56
-        if (isset($this->parameters['acceptedLanguages'])) {
57
-            $this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']);
58
-            unset($this->parameters['acceptedLanguages']);
59
-        }
60
-        if (isset($this->parameters['languageParameterName'])) {
61
-            $this->languageParameterName = $this->parameters['languageParameterName'];
62
-            unset($this->parameters['languageParameterName']);
63
-        }
64
-        if (isset($this->parameters['forceRedirect'])) {
65
-            $this->forceRedirect = (bool) $this->parameters['forceRedirect'];
66
-            unset($this->parameters['forceRedirect']);
67
-        }
68
-    }
69
-
70
-    /**
71
-     * @return array
72
-     */
73
-    public function getParameters()
74
-    {
75
-        return $this->parameters;
76
-    }
77
-
78
-
79
-    /**
80
-     * Check if the found language is allowed and
81
-     * if an action is to be taken.
82
-     *
83
-     * @param $lang
84
-     * @param $request
85
-     */
86
-    private function detectLanguage($lang, $request)
87
-    {
88
-        $_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage;
89
-
90
-        if ($this->acceptedLanguages === null) {
91
-            $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang;
92
-        } else if (in_array($lang, $this->acceptedLanguages)) {
93
-            $_SESSION['LanguageComponent'][$this->languageParameterName] = $lang;
94
-        } else {
95
-            $lang = $this->defaultLanguage;
96
-        }
97
-
98
-        $this->sessionValues = $_SESSION['LanguageComponent'];
99
-
100
-        if ($this->forceRedirect === true) {
101
-            if (substr($request::$relativeUri, 0, 2) !== $lang ) {
102
-                if ($lang !== $this->defaultLanguage) {
103
-                    header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri);
104
-                    exit;
105
-                }
106
-            }
107
-        }
108
-    }
109
-
110
-    /**
111
-     * Detect if the language is switched manually
112
-     *
113
-     * @param $request
114
-     */
115
-    private function checkLanguageSwitch($request)
116
-    {
117
-        if (isset($request::$get['langSwitch'])) {
118
-            $this->forceRedirect = true;
119
-            $this->detectLanguage($request::$get['langSwitch'], $request);
120
-        }
121
-    }
122
-
123
-    /*
9
+	protected $request;
10
+	protected $parameters;
11
+
12
+	protected $defaultLanguage = 'en';
13
+	protected $acceptedLanguages = null;
14
+	protected $languageParameterName = 'language';
15
+	protected $forceRedirect = false;
16
+	protected $sessionValues;
17
+
18
+	/**
19
+	 * Component constructor.
20
+	 *
21
+	 * @param                     $template
22
+	 * @param Request $request
23
+	 * @param                     $parameters
24
+	 * @param                     $matchedSitemapItem
25
+	 */
26
+	public function __construct($template, Request $request, $parameters, $matchedSitemapItem)
27
+	{
28
+		$this->parameters = (array) $parameters;
29
+		$this->checkParameters();
30
+
31
+		$lang = substr(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : $this->defaultLanguage, 0, 2);
32
+		$_SESSION['LanguageComponent']['detectedLanguage'] = $lang;
33
+
34
+		$this->checkLanguageSwitch($request);
35
+
36
+		if (!isset($_SESSION['LanguageComponent'][$this->languageParameterName])) {
37
+			$this->detectLanguage($lang, $request);
38
+		} else {
39
+			if ($this->forceRedirect === true) {
40
+				$this->detectLanguage($_SESSION['LanguageComponent'][$this->languageParameterName], $request);
41
+			}
42
+		}
43
+
44
+		$this->parameters[$this->languageParameterName] = $_SESSION['LanguageComponent'][$this->languageParameterName];
45
+	}
46
+
47
+	/**
48
+	 * Checks to see if any parameters are given from the configuration in the CMS
49
+	 */
50
+	private function checkParameters()
51
+	{
52
+		if (isset($this->parameters['defaultLanguage'])) {
53
+			$this->defaultLanguage = $this->parameters['defaultLanguage'];
54
+			unset($this->parameters['defaultLanguage']);
55
+		}
56
+		if (isset($this->parameters['acceptedLanguages'])) {
57
+			$this->acceptedLanguages = explode(',', $this->parameters['acceptedLanguages']);
58
+			unset($this->parameters['acceptedLanguages']);
59
+		}
60
+		if (isset($this->parameters['languageParameterName'])) {
61
+			$this->languageParameterName = $this->parameters['languageParameterName'];
62
+			unset($this->parameters['languageParameterName']);
63
+		}
64
+		if (isset($this->parameters['forceRedirect'])) {
65
+			$this->forceRedirect = (bool) $this->parameters['forceRedirect'];
66
+			unset($this->parameters['forceRedirect']);
67
+		}
68
+	}
69
+
70
+	/**
71
+	 * @return array
72
+	 */
73
+	public function getParameters()
74
+	{
75
+		return $this->parameters;
76
+	}
77
+
78
+
79
+	/**
80
+	 * Check if the found language is allowed and
81
+	 * if an action is to be taken.
82
+	 *
83
+	 * @param $lang
84
+	 * @param $request
85
+	 */
86
+	private function detectLanguage($lang, $request)
87
+	{
88
+		$_SESSION['LanguageComponent'][$this->languageParameterName] = $this->defaultLanguage;
89
+
90
+		if ($this->acceptedLanguages === null) {
91
+			$_SESSION['LanguageComponent'][$this->languageParameterName] = $lang;
92
+		} else if (in_array($lang, $this->acceptedLanguages)) {
93
+			$_SESSION['LanguageComponent'][$this->languageParameterName] = $lang;
94
+		} else {
95
+			$lang = $this->defaultLanguage;
96
+		}
97
+
98
+		$this->sessionValues = $_SESSION['LanguageComponent'];
99
+
100
+		if ($this->forceRedirect === true) {
101
+			if (substr($request::$relativeUri, 0, 2) !== $lang ) {
102
+				if ($lang !== $this->defaultLanguage) {
103
+					header('Location: ' . $request::$subfolders . $lang . '/' . $request::$relativeUri);
104
+					exit;
105
+				}
106
+			}
107
+		}
108
+	}
109
+
110
+	/**
111
+	 * Detect if the language is switched manually
112
+	 *
113
+	 * @param $request
114
+	 */
115
+	private function checkLanguageSwitch($request)
116
+	{
117
+		if (isset($request::$get['langSwitch'])) {
118
+			$this->forceRedirect = true;
119
+			$this->detectLanguage($request::$get['langSwitch'], $request);
120
+		}
121
+	}
122
+
123
+	/*
124 124
      * These functions are required by the interface, but not for the functionality
125 125
      */
126
-    public function run(JsonStorage $storage) {}
127
-    public function render() {}
128
-    public function get() {}
126
+	public function run(JsonStorage $storage) {}
127
+	public function render() {}
128
+	public function get() {}
129 129
 }
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
src/components/cms/DocumentRouting.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -12,33 +12,33 @@  discard block
 block discarded – undo
12 12
 
13 13
 class DocumentRouting implements CmsRouting
14 14
 {
15
-    /**
16
-     * DocumentRouting constructor.
17
-     * @param $request
18
-     * @param $relativeCmsUri
19
-     * @param CmsComponent $cmsComponent
20
-     */
21
-    public function __construct($request, $relativeCmsUri, $cmsComponent)
22
-    {
23
-        if ($relativeCmsUri == '/documents') {
24
-            $cmsComponent->subTemplate = 'documents';
25
-            $cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState());
26
-            $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS);
27
-        }
28
-        $this->documentRouting($request, $relativeCmsUri, $cmsComponent);
29
-        $this->folderRouting($request, $relativeCmsUri, $cmsComponent);
15
+	/**
16
+	 * DocumentRouting constructor.
17
+	 * @param $request
18
+	 * @param $relativeCmsUri
19
+	 * @param CmsComponent $cmsComponent
20
+	 */
21
+	public function __construct($request, $relativeCmsUri, $cmsComponent)
22
+	{
23
+		if ($relativeCmsUri == '/documents') {
24
+			$cmsComponent->subTemplate = 'documents';
25
+			$cmsComponent->setParameter(CmsComponent::PARAMETER_DOCUMENTS, $cmsComponent->storage->getDocuments()->getDocumentsWithState());
26
+			$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_DOCUMENTS);
27
+		}
28
+		$this->documentRouting($request, $relativeCmsUri, $cmsComponent);
29
+		$this->folderRouting($request, $relativeCmsUri, $cmsComponent);
30 30
 		$this->valuelistsRouting($request, $relativeCmsUri, $cmsComponent);
31
-    }
31
+	}
32 32
 
33 33
 
34
-    /**
35
-     * @param $request
36
-     * @param $relativeCmsUri
37
-     * @param CmsComponent $cmsComponent
38
-     * @throws \Exception
39
-     */
40
-    private function documentRouting($request, $relativeCmsUri, $cmsComponent)
41
-    {
34
+	/**
35
+	 * @param $request
36
+	 * @param $relativeCmsUri
37
+	 * @param CmsComponent $cmsComponent
38
+	 * @throws \Exception
39
+	 */
40
+	private function documentRouting($request, $relativeCmsUri, $cmsComponent)
41
+	{
42 42
 		if ($relativeCmsUri == '/documents/new-document' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
43 43
 			$this->documentNewRoute($request, $cmsComponent);
44 44
 		} elseif (isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])){
@@ -50,23 +50,23 @@  discard block
 block discarded – undo
50 50
 				case '/documents/unpublish-document': $this->unpublishDocumentRoute($request, $cmsComponent); break;
51 51
 			}
52 52
 		}
53
-    }
53
+	}
54 54
 
55
-    /**
56
-     * @param $request
57
-     * @param $relativeCmsUri
58
-     * @param CmsComponent $cmsComponent
59
-     */
60
-    private function folderRouting($request, $relativeCmsUri, $cmsComponent)
61
-    {
62
-        if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
55
+	/**
56
+	 * @param $request
57
+	 * @param $relativeCmsUri
58
+	 * @param CmsComponent $cmsComponent
59
+	 */
60
+	private function folderRouting($request, $relativeCmsUri, $cmsComponent)
61
+	{
62
+		if ($relativeCmsUri == '/documents/new-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_PATH])) {
63 63
 			$this->newFolderRoute($request, $cmsComponent);
64
-        } else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
64
+		} else if ($relativeCmsUri == '/documents/edit-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
65 65
 			$this->editFolderRoute($request, $cmsComponent);
66
-        } else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
66
+		} else if ($relativeCmsUri == '/documents/delete-folder' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
67 67
 			$this->deleteFolderRoute($request, $cmsComponent);
68
-        }
69
-    }
68
+		}
69
+	}
70 70
 
71 71
 	private function valuelistsRouting($request, $relativeCmsUri, $cmsComponent)
72 72
 	{
Please login to merge, or discard this patch.