Passed
Push — develop ( 02ffeb...d59462 )
by Jens
02:18
created
cloudcontrol/library/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 = 'cms/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 = 'cms/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.
cloudcontrol/library/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.
cloudcontrol/library/storage/storage/RedirectsStorage.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -10,91 +10,91 @@
 block discarded – undo
10 10
 
11 11
 class RedirectsStorage extends AbstractStorage
12 12
 {
13
-    /**
14
-     * Get all redirects
15
-     *
16
-     * @return mixed
17
-     */
18
-    public function getRedirects()
19
-    {
20
-        $redirects = $this->repository->redirects;
21
-        usort($redirects, array($this, 'cmp'));
22
-        return $redirects;
23
-    }
13
+	/**
14
+	 * Get all redirects
15
+	 *
16
+	 * @return mixed
17
+	 */
18
+	public function getRedirects()
19
+	{
20
+		$redirects = $this->repository->redirects;
21
+		usort($redirects, array($this, 'cmp'));
22
+		return $redirects;
23
+	}
24 24
 
25
-    /**
26
-     * Add a new redirect
27
-     * @param $postValues
28
-     */
29
-    public function addRedirect($postValues) {
30
-        $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
31
-        $redirects = $this->repository->redirects;
32
-        $redirects[] = $redirectObject;
33
-        $this->repository->redirects = $redirects;
34
-        $this->save();
35
-    }
25
+	/**
26
+	 * Add a new redirect
27
+	 * @param $postValues
28
+	 */
29
+	public function addRedirect($postValues) {
30
+		$redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
31
+		$redirects = $this->repository->redirects;
32
+		$redirects[] = $redirectObject;
33
+		$this->repository->redirects = $redirects;
34
+		$this->save();
35
+	}
36 36
 
37
-    /**
38
-     * Get a redirect by it's slug
39
-     *
40
-     * @param $slug
41
-     * @return \stdClass|null
42
-     */
43
-    public function getRedirectBySlug($slug)
44
-    {
45
-        $redirects = $this->repository->redirects;
46
-        foreach ($redirects as $redirect) {
47
-            if ($redirect->slug == $slug) {
48
-                return $redirect;
49
-            }
50
-        }
37
+	/**
38
+	 * Get a redirect by it's slug
39
+	 *
40
+	 * @param $slug
41
+	 * @return \stdClass|null
42
+	 */
43
+	public function getRedirectBySlug($slug)
44
+	{
45
+		$redirects = $this->repository->redirects;
46
+		foreach ($redirects as $redirect) {
47
+			if ($redirect->slug == $slug) {
48
+				return $redirect;
49
+			}
50
+		}
51 51
 
52
-        return null;
53
-    }
52
+		return null;
53
+	}
54 54
 
55
-    /**
56
-     * Save a redirect by it's slug
57
-     * @param $slug
58
-     * @param $postValues
59
-     */
60
-    public function saveRedirect($slug, $postValues)
61
-    {
62
-        $redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
55
+	/**
56
+	 * Save a redirect by it's slug
57
+	 * @param $slug
58
+	 * @param $postValues
59
+	 */
60
+	public function saveRedirect($slug, $postValues)
61
+	{
62
+		$redirectObject = RedirectsFactory::createRedirectFromPostValues($postValues);
63 63
 
64
-        $redirects = $this->repository->redirects;
65
-        foreach ($redirects as $key => $redirect) {
66
-            if ($redirect->slug == $slug) {
67
-                $redirects[$key] = $redirectObject;
68
-            }
69
-        }
70
-        $this->repository->redirects = $redirects;
71
-        $this->save();
72
-    }
64
+		$redirects = $this->repository->redirects;
65
+		foreach ($redirects as $key => $redirect) {
66
+			if ($redirect->slug == $slug) {
67
+				$redirects[$key] = $redirectObject;
68
+			}
69
+		}
70
+		$this->repository->redirects = $redirects;
71
+		$this->save();
72
+	}
73 73
 
74
-    /**
75
-     * Delete a redirect by it's slug
76
-     * @param $slug
77
-     */
78
-    public function deleteRedirectBySlug($slug)
79
-    {
80
-        $redirects = $this->repository->redirects;
81
-        foreach ($redirects as $key => $redirect) {
82
-            if ($redirect->slug == $slug) {
83
-                unset($redirects[$key]);
84
-            }
85
-        }
86
-        $redirects = array_values($redirects);
87
-        $this->repository->redirects = $redirects;
88
-        $this->save();
89
-    }
74
+	/**
75
+	 * Delete a redirect by it's slug
76
+	 * @param $slug
77
+	 */
78
+	public function deleteRedirectBySlug($slug)
79
+	{
80
+		$redirects = $this->repository->redirects;
81
+		foreach ($redirects as $key => $redirect) {
82
+			if ($redirect->slug == $slug) {
83
+				unset($redirects[$key]);
84
+			}
85
+		}
86
+		$redirects = array_values($redirects);
87
+		$this->repository->redirects = $redirects;
88
+		$this->save();
89
+	}
90 90
 
91
-    /**
92
-     * Compare a redirect by it's title
93
-     * @param $a
94
-     * @param $b
95
-     * @return int
96
-     */
97
-    public static function cmp($a, $b) {
98
-        return strcmp($a->title, $b->title);
99
-    }
91
+	/**
92
+	 * Compare a redirect by it's title
93
+	 * @param $a
94
+	 * @param $b
95
+	 * @return int
96
+	 */
97
+	public static function cmp($a, $b) {
98
+		return strcmp($a->title, $b->title);
99
+	}
100 100
 }
101 101
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/storage/factories/RedirectsFactory.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -10,26 +10,26 @@
 block discarded – undo
10 10
 
11 11
 class RedirectsFactory
12 12
 {
13
-    /**
14
-     * Create a new redirect object from postvalues
15
-     *
16
-     * @param $postValues
17
-     * @return \stdClass
18
-     * @throws \Exception
19
-     */
20
-    public static function createRedirectFromPostValues($postValues)
21
-    {
22
-        if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) {
23
-            $redirectObject = new \stdClass();
24
-            $redirectObject->title = $postValues['title'];
25
-            $redirectObject->slug = StringUtil::slugify($postValues['title']);
26
-            $redirectObject->fromUrl = $postValues['fromUrl'];
27
-            $redirectObject->toUrl = $postValues['toUrl'];
28
-            $redirectObject->type = $postValues['type'];
13
+	/**
14
+	 * Create a new redirect object from postvalues
15
+	 *
16
+	 * @param $postValues
17
+	 * @return \stdClass
18
+	 * @throws \Exception
19
+	 */
20
+	public static function createRedirectFromPostValues($postValues)
21
+	{
22
+		if (isset($postValues['title'], $postValues['fromUrl'], $postValues['toUrl'])) {
23
+			$redirectObject = new \stdClass();
24
+			$redirectObject->title = $postValues['title'];
25
+			$redirectObject->slug = StringUtil::slugify($postValues['title']);
26
+			$redirectObject->fromUrl = $postValues['fromUrl'];
27
+			$redirectObject->toUrl = $postValues['toUrl'];
28
+			$redirectObject->type = $postValues['type'];
29 29
 
30
-            return $redirectObject;
31
-        } else {
32
-            throw new \Exception('Trying to create valuelist with invalid data.');
33
-        }
34
-    }
30
+			return $redirectObject;
31
+		} else {
32
+			throw new \Exception('Trying to create valuelist with invalid data.');
33
+		}
34
+	}
35 35
 }
36 36
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/storage/Repository.php 1 patch
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -24,141 +24,141 @@  discard block
 block discarded – undo
24 24
  */
25 25
 class Repository
26 26
 {
27
-    protected $storagePath;
28
-
29
-    protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects');
30
-
31
-    protected $sitemap;
32
-    protected $sitemapChanges = false;
33
-
34
-    protected $applicationComponents;
35
-    protected $applicationComponentsChanges = false;
36
-
37
-    protected $documentTypes;
38
-    protected $documentTypesChanges = false;
39
-
40
-    protected $bricks;
41
-    protected $bricksChanges = false;
42
-
43
-    protected $imageSet;
44
-    protected $imageSetChanges = false;
45
-
46
-    protected $images;
47
-    protected $imagesChanges = false;
48
-
49
-    protected $files;
50
-    protected $filesChanges = false;
51
-
52
-    protected $users;
53
-    protected $usersChanges = false;
54
-
55
-    protected $valuelists;
56
-    protected $valuelistsChanges = false;
57
-
58
-    protected $redirects;
59
-    protected $redirectsChanges = false;
60
-
61
-    protected $contentDbHandle;
62
-
63
-
64
-    /**
65
-     * Repository constructor.
66
-     * @param $storagePath
67
-     * @throws \Exception
68
-     */
69
-    public function __construct($storagePath)
70
-    {
71
-        $storagePath = realpath($storagePath);
72
-        if (is_dir($storagePath) && $storagePath !== false) {
73
-            $this->storagePath = $storagePath;
74
-        } else {
75
-            throw new \Exception('Repository not yet initialized.');
76
-        }
77
-    }
78
-
79
-    /**
80
-     * Creates the folder in which to create all storage related files
81
-     *
82
-     * @param $storagePath
83
-     * @return bool
84
-     */
85
-    public static function create($storagePath)
86
-    {
87
-        return mkdir($storagePath);
88
-    }
89
-
90
-    /**
91
-     * Initiates default storage
92
-     * @throws \Exception
93
-     */
94
-    public function init()
95
-    {
96
-        $storageDefaultPath = realpath('../library/cc/install/_storage.json');
97
-        $contentSqlPath = realpath('../library/cc/install/content.sql');
98
-
99
-        $this->initConfigStorage($storageDefaultPath);
100
-        $this->initContentDb($contentSqlPath);
101
-
102
-        $this->save();
103
-    }
104
-
105
-    /**
106
-     * Load filebased subset and return it's contents
107
-     *
108
-     * @param $name
109
-     * @return mixed|string
110
-     * @throws \Exception
111
-     */
112
-    public function __get($name)
113
-    {
114
-        if (isset($this->$name)) {
115
-            if (in_array($name, $this->fileBasedSubsets)) {
116
-                return $this->$name;
117
-            } else {
118
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
119
-            }
120
-        } else {
121
-            if (in_array($name, $this->fileBasedSubsets)) {
122
-                return $this->loadSubset($name);
123
-            } else {
124
-                throw new \Exception('Trying to get undefined property from Repository: ' . $name);
125
-            }
126
-        }
127
-    }
128
-
129
-    /**
130
-     * Set filebased subset contents
131
-     * @param $name
132
-     * @param $value
133
-     * @throws \Exception
134
-     */
135
-    public function __set($name, $value)
136
-    {
137
-        if (in_array($name, $this->fileBasedSubsets)) {
138
-            $this->$name = $value;
139
-            $changes = $name . 'Changes';
140
-            $this->$changes = true;
141
-        } else {
142
-            throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
143
-        }
144
-    }
145
-
146
-    /**
147
-     * Persist all subsets
148
-     */
149
-    public function save()
150
-    {
151
-        array_map(function ($value) {
152
-        	$this->saveSubset($value);
27
+	protected $storagePath;
28
+
29
+	protected $fileBasedSubsets = array('sitemap', 'applicationComponents', 'documentTypes', 'bricks', 'imageSet', 'images', 'files', 'users', 'valuelists', 'redirects');
30
+
31
+	protected $sitemap;
32
+	protected $sitemapChanges = false;
33
+
34
+	protected $applicationComponents;
35
+	protected $applicationComponentsChanges = false;
36
+
37
+	protected $documentTypes;
38
+	protected $documentTypesChanges = false;
39
+
40
+	protected $bricks;
41
+	protected $bricksChanges = false;
42
+
43
+	protected $imageSet;
44
+	protected $imageSetChanges = false;
45
+
46
+	protected $images;
47
+	protected $imagesChanges = false;
48
+
49
+	protected $files;
50
+	protected $filesChanges = false;
51
+
52
+	protected $users;
53
+	protected $usersChanges = false;
54
+
55
+	protected $valuelists;
56
+	protected $valuelistsChanges = false;
57
+
58
+	protected $redirects;
59
+	protected $redirectsChanges = false;
60
+
61
+	protected $contentDbHandle;
62
+
63
+
64
+	/**
65
+	 * Repository constructor.
66
+	 * @param $storagePath
67
+	 * @throws \Exception
68
+	 */
69
+	public function __construct($storagePath)
70
+	{
71
+		$storagePath = realpath($storagePath);
72
+		if (is_dir($storagePath) && $storagePath !== false) {
73
+			$this->storagePath = $storagePath;
74
+		} else {
75
+			throw new \Exception('Repository not yet initialized.');
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * Creates the folder in which to create all storage related files
81
+	 *
82
+	 * @param $storagePath
83
+	 * @return bool
84
+	 */
85
+	public static function create($storagePath)
86
+	{
87
+		return mkdir($storagePath);
88
+	}
89
+
90
+	/**
91
+	 * Initiates default storage
92
+	 * @throws \Exception
93
+	 */
94
+	public function init()
95
+	{
96
+		$storageDefaultPath = realpath('../library/cc/install/_storage.json');
97
+		$contentSqlPath = realpath('../library/cc/install/content.sql');
98
+
99
+		$this->initConfigStorage($storageDefaultPath);
100
+		$this->initContentDb($contentSqlPath);
101
+
102
+		$this->save();
103
+	}
104
+
105
+	/**
106
+	 * Load filebased subset and return it's contents
107
+	 *
108
+	 * @param $name
109
+	 * @return mixed|string
110
+	 * @throws \Exception
111
+	 */
112
+	public function __get($name)
113
+	{
114
+		if (isset($this->$name)) {
115
+			if (in_array($name, $this->fileBasedSubsets)) {
116
+				return $this->$name;
117
+			} else {
118
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
119
+			}
120
+		} else {
121
+			if (in_array($name, $this->fileBasedSubsets)) {
122
+				return $this->loadSubset($name);
123
+			} else {
124
+				throw new \Exception('Trying to get undefined property from Repository: ' . $name);
125
+			}
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * Set filebased subset contents
131
+	 * @param $name
132
+	 * @param $value
133
+	 * @throws \Exception
134
+	 */
135
+	public function __set($name, $value)
136
+	{
137
+		if (in_array($name, $this->fileBasedSubsets)) {
138
+			$this->$name = $value;
139
+			$changes = $name . 'Changes';
140
+			$this->$changes = true;
141
+		} else {
142
+			throw new \Exception('Trying to persist unknown subset in repository: ' . $name . ' <br /><pre>' . print_r($value, true) . '</pre>');
143
+		}
144
+	}
145
+
146
+	/**
147
+	 * Persist all subsets
148
+	 */
149
+	public function save()
150
+	{
151
+		array_map(function ($value) {
152
+			$this->saveSubset($value);
153 153
 		}, $this->fileBasedSubsets);
154
-    }
155
-
156
-    /**
157
-     * Persist subset to disk
158
-     * @param $subset
159
-     */
160
-    protected function saveSubset($subset)
161
-    {
154
+	}
155
+
156
+	/**
157
+	 * Persist subset to disk
158
+	 * @param $subset
159
+	 */
160
+	protected function saveSubset($subset)
161
+	{
162 162
 		$changes = $subset . 'Changes';
163 163
 		if ($this->$changes === true) {
164 164
 			$json = json_encode($this->$subset, JSON_PRETTY_PRINT);
@@ -167,69 +167,69 @@  discard block
 block discarded – undo
167 167
 
168 168
 			$this->$changes = false;
169 169
 		}
170
-    }
171
-
172
-    /**
173
-     * Load subset from disk
174
-     * @param $subset
175
-     * @return mixed|string
176
-     */
177
-    protected function loadSubset($subset)
178
-    {
179
-        $subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
180
-        $json = file_get_contents($subsetStoragePath);
181
-        $json = json_decode($json);
182
-        $this->$subset = $json;
183
-        return $json;
184
-    }
185
-
186
-    /**
187
-     * @param $contentSqlPath
188
-     */
189
-    protected function initContentDb($contentSqlPath)
190
-    {
191
-        $db = $this->getContentDbHandle();
192
-        $sql = file_get_contents($contentSqlPath);
193
-        $db->exec($sql);
194
-    }
195
-
196
-    /**
197
-     * @param $storageDefaultPath
198
-     */
199
-    protected function initConfigStorage($storageDefaultPath)
200
-    {
201
-        $json = file_get_contents($storageDefaultPath);
202
-        $json = json_decode($json);
203
-        $this->sitemap = $json->sitemap;
204
-        $this->sitemapChanges = true;
205
-        $this->applicationComponents = $json->applicationComponents;
206
-        $this->applicationComponentsChanges = true;
207
-        $this->documentTypes = $json->documentTypes;
208
-        $this->documentTypesChanges = true;
209
-        $this->bricks = $json->bricks;
210
-        $this->bricksChanges = true;
211
-        $this->imageSet = $json->imageSet;
212
-        $this->imageSetChanges = true;
213
-        $this->images = $json->images;
214
-        $this->imagesChanges = true;
215
-        $this->files = $json->files;
216
-        $this->filesChanges = true;
217
-        $this->users = $json->users;
218
-        $this->usersChanges = true;
219
-        $this->valuelists = $json->valuelists;
220
-        $this->valuelistsChanges = true;
221
-    }
222
-
223
-    /**
224
-     * @return \PDO
225
-     */
226
-    public function getContentDbHandle()
227
-    {
228
-        if ($this->contentDbHandle === null) {
229
-            $this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
230
-        }
231
-        return $this->contentDbHandle;
232
-    }
170
+	}
171
+
172
+	/**
173
+	 * Load subset from disk
174
+	 * @param $subset
175
+	 * @return mixed|string
176
+	 */
177
+	protected function loadSubset($subset)
178
+	{
179
+		$subsetStoragePath = $this->storagePath . DIRECTORY_SEPARATOR . $subset . '.json';
180
+		$json = file_get_contents($subsetStoragePath);
181
+		$json = json_decode($json);
182
+		$this->$subset = $json;
183
+		return $json;
184
+	}
185
+
186
+	/**
187
+	 * @param $contentSqlPath
188
+	 */
189
+	protected function initContentDb($contentSqlPath)
190
+	{
191
+		$db = $this->getContentDbHandle();
192
+		$sql = file_get_contents($contentSqlPath);
193
+		$db->exec($sql);
194
+	}
195
+
196
+	/**
197
+	 * @param $storageDefaultPath
198
+	 */
199
+	protected function initConfigStorage($storageDefaultPath)
200
+	{
201
+		$json = file_get_contents($storageDefaultPath);
202
+		$json = json_decode($json);
203
+		$this->sitemap = $json->sitemap;
204
+		$this->sitemapChanges = true;
205
+		$this->applicationComponents = $json->applicationComponents;
206
+		$this->applicationComponentsChanges = true;
207
+		$this->documentTypes = $json->documentTypes;
208
+		$this->documentTypesChanges = true;
209
+		$this->bricks = $json->bricks;
210
+		$this->bricksChanges = true;
211
+		$this->imageSet = $json->imageSet;
212
+		$this->imageSetChanges = true;
213
+		$this->images = $json->images;
214
+		$this->imagesChanges = true;
215
+		$this->files = $json->files;
216
+		$this->filesChanges = true;
217
+		$this->users = $json->users;
218
+		$this->usersChanges = true;
219
+		$this->valuelists = $json->valuelists;
220
+		$this->valuelistsChanges = true;
221
+	}
222
+
223
+	/**
224
+	 * @return \PDO
225
+	 */
226
+	public function getContentDbHandle()
227
+	{
228
+		if ($this->contentDbHandle === null) {
229
+			$this->contentDbHandle = new \PDO('sqlite:' . $this->storagePath . DIRECTORY_SEPARATOR . 'content.db');
230
+		}
231
+		return $this->contentDbHandle;
232
+	}
233 233
 
234 234
 	/**
235 235
 	 * Get all documents
@@ -239,13 +239,13 @@  discard block
 block discarded – undo
239 239
 	 * @return array
240 240
 	 * @throws \Exception
241 241
 	 */
242
-    public function getDocuments($state = 'published')
243
-    {
242
+	public function getDocuments($state = 'published')
243
+	{
244 244
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
245 245
 			throw new \Exception('Unsupported document state: ' . $state);
246 246
 		}
247
-        return $this->getDocumentsByPath('/', $state);
248
-    }
247
+		return $this->getDocumentsByPath('/', $state);
248
+	}
249 249
 
250 250
 	public function getDocumentsWithState($folderPath = '/')
251 251
 	{
@@ -292,51 +292,51 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 * @throws \Exception
294 294
 	 */
295
-    public function getDocumentsByPath($folderPath, $state = 'published')
296
-    {
297
-    	if (!in_array($state, Document::$DOCUMENT_STATES)) {
298
-    		throw new \Exception('Unsupported document state: ' . $state);
295
+	public function getDocumentsByPath($folderPath, $state = 'published')
296
+	{
297
+		if (!in_array($state, Document::$DOCUMENT_STATES)) {
298
+			throw new \Exception('Unsupported document state: ' . $state);
299 299
 		}
300
-        $db = $this->getContentDbHandle();
301
-        $folderPathWithWildcard = $folderPath . '%';
300
+		$db = $this->getContentDbHandle();
301
+		$folderPathWithWildcard = $folderPath . '%';
302 302
 
303
-        $sql = 'SELECT *
303
+		$sql = 'SELECT *
304 304
               FROM documents_' . $state . '
305 305
              WHERE `path` LIKE ' . $db->quote($folderPathWithWildcard) . '
306 306
                AND substr(`path`, ' . (strlen($folderPath) + 1) . ') NOT LIKE "%/%"
307 307
                AND path != ' . $db->quote($folderPath) . '
308 308
           ORDER BY `type` DESC, `path` ASC';
309
-        $stmt = $this->getDbStatement($sql);
309
+		$stmt = $this->getDbStatement($sql);
310 310
 
311
-        $documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
312
-        foreach ($documents as $key => $document) {
311
+		$documents = $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
312
+		foreach ($documents as $key => $document) {
313 313
 			$documents = $this->setAssetsToDocumentFolders($document, $db, $documents, $key);
314
-        }
315
-        return $documents;
316
-    }
317
-
318
-
319
-    /**
320
-     * @param $path
321
-     * @return bool|Document
322
-     */
323
-    public function getDocumentContainerByPath($path)
324
-    {
325
-        $document = $this->getDocumentByPath($path, 'unpublished');
326
-        if ($document === false) {
327
-            return false;
328
-        }
329
-        $slugLength = strlen($document->slug);
330
-        $containerPath = substr($path, 0, -$slugLength);
331
-        if ($containerPath === '/') {
332
-            return $this->getRootFolder();
333
-        }
334
-        if (substr($containerPath, -1) === '/'){
314
+		}
315
+		return $documents;
316
+	}
317
+
318
+
319
+	/**
320
+	 * @param $path
321
+	 * @return bool|Document
322
+	 */
323
+	public function getDocumentContainerByPath($path)
324
+	{
325
+		$document = $this->getDocumentByPath($path, 'unpublished');
326
+		if ($document === false) {
327
+			return false;
328
+		}
329
+		$slugLength = strlen($document->slug);
330
+		$containerPath = substr($path, 0, -$slugLength);
331
+		if ($containerPath === '/') {
332
+			return $this->getRootFolder();
333
+		}
334
+		if (substr($containerPath, -1) === '/'){
335 335
 			$containerPath = substr($containerPath, 0, -1);
336 336
 		}
337
-        $containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
338
-        return $containerFolder;
339
-    }
337
+		$containerFolder = $this->getDocumentByPath($containerPath, 'unpublished');
338
+		return $containerFolder;
339
+	}
340 340
 
341 341
 	/**
342 342
 	 * @param        $path
@@ -345,23 +345,23 @@  discard block
 block discarded – undo
345 345
 	 * @return bool|\library\storage\Document
346 346
 	 * @throws \Exception
347 347
 	 */
348
-    public function getDocumentByPath($path, $state = 'published')
349
-    {
348
+	public function getDocumentByPath($path, $state = 'published')
349
+	{
350 350
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
351 351
 			throw new \Exception('Unsupported document state: ' . $state);
352 352
 		}
353
-        $db = $this->getContentDbHandle();
354
-        $document = $this->fetchDocument('
353
+		$db = $this->getContentDbHandle();
354
+		$document = $this->fetchDocument('
355 355
             SELECT *
356 356
               FROM documents_' .  $state . '
357 357
              WHERE path = ' . $db->quote($path) . '
358 358
         ');
359
-        if ($document instanceof Document && $document->type === 'folder') {
360
-            $document->dbHandle = $db;
361
-            $document->documentStorage = new DocumentStorage($this);
362
-        }
363
-        return $document;
364
-    }
359
+		if ($document instanceof Document && $document->type === 'folder') {
360
+			$document->dbHandle = $db;
361
+			$document->documentStorage = new DocumentStorage($this);
362
+		}
363
+		return $document;
364
+	}
365 365
 
366 366
 	/**
367 367
 	 * Returns the count of all documents stored in the db
@@ -456,58 +456,58 @@  discard block
 block discarded – undo
456 456
 	}
457 457
 
458 458
 	/**
459
-     * Return the results of the query as array of Documents
460
-     * @param $sql
461
-     * @return array
462
-     * @throws \Exception
463
-     */
464
-    protected function fetchAllDocuments($sql)
465
-    {
466
-        $stmt = $this->getDbStatement($sql);
467
-        return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
468
-    }
469
-
470
-    /**
471
-     * Return the result of the query as Document
472
-     * @param $sql
473
-     * @return mixed
474
-     * @throws \Exception
475
-     */
476
-    protected function fetchDocument($sql)
477
-    {
478
-        $stmt = $this->getDbStatement($sql);
479
-        return $stmt->fetchObject('\library\storage\Document');
480
-    }
481
-
482
-    /**
483
-     * Prepare the sql statement
484
-     * @param $sql
485
-     * @return \PDOStatement
486
-     * @throws \Exception
487
-     */
488
-    protected function getDbStatement($sql)
489
-    {
490
-        $db = $this->getContentDbHandle();
491
-        $stmt = $db->query($sql);
492
-        if ($stmt === false) {
493
-            $errorInfo = $db->errorInfo();
494
-            $errorMsg = $errorInfo[2];
495
-            throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
496
-        }
497
-        return $stmt;
498
-    }
499
-
500
-    /**
501
-     * Create a (non-existent) root folder Document and return it
502
-     * @return Document
503
-     */
504
-    protected function getRootFolder()
505
-    {
506
-        $rootFolder = new Document();
507
-        $rootFolder->path = '/';
508
-        $rootFolder->type = 'folder';
509
-        return $rootFolder;
510
-    }
459
+	 * Return the results of the query as array of Documents
460
+	 * @param $sql
461
+	 * @return array
462
+	 * @throws \Exception
463
+	 */
464
+	protected function fetchAllDocuments($sql)
465
+	{
466
+		$stmt = $this->getDbStatement($sql);
467
+		return $stmt->fetchAll(\PDO::FETCH_CLASS, '\library\storage\Document');
468
+	}
469
+
470
+	/**
471
+	 * Return the result of the query as Document
472
+	 * @param $sql
473
+	 * @return mixed
474
+	 * @throws \Exception
475
+	 */
476
+	protected function fetchDocument($sql)
477
+	{
478
+		$stmt = $this->getDbStatement($sql);
479
+		return $stmt->fetchObject('\library\storage\Document');
480
+	}
481
+
482
+	/**
483
+	 * Prepare the sql statement
484
+	 * @param $sql
485
+	 * @return \PDOStatement
486
+	 * @throws \Exception
487
+	 */
488
+	protected function getDbStatement($sql)
489
+	{
490
+		$db = $this->getContentDbHandle();
491
+		$stmt = $db->query($sql);
492
+		if ($stmt === false) {
493
+			$errorInfo = $db->errorInfo();
494
+			$errorMsg = $errorInfo[2];
495
+			throw new \Exception('SQLite Exception: ' . $errorMsg . ' in SQL: <br /><pre>' . $sql . '</pre>');
496
+		}
497
+		return $stmt;
498
+	}
499
+
500
+	/**
501
+	 * Create a (non-existent) root folder Document and return it
502
+	 * @return Document
503
+	 */
504
+	protected function getRootFolder()
505
+	{
506
+		$rootFolder = new Document();
507
+		$rootFolder->path = '/';
508
+		$rootFolder->type = 'folder';
509
+		return $rootFolder;
510
+	}
511 511
 
512 512
 	/**
513 513
 	 * Save the document to the database
@@ -519,13 +519,13 @@  discard block
 block discarded – undo
519 519
 	 * @throws \Exception
520 520
 	 * @internal param $path
521 521
 	 */
522
-    public function saveDocument($documentObject, $state = 'published')
523
-    {
522
+	public function saveDocument($documentObject, $state = 'published')
523
+	{
524 524
 		if (!in_array($state, Document::$DOCUMENT_STATES)) {
525 525
 			throw new \Exception('Unsupported document state: ' . $state);
526 526
 		}
527
-        $db = $this->getContentDbHandle();
528
-        $stmt = $this->getDbStatement('
527
+		$db = $this->getContentDbHandle();
528
+		$stmt = $this->getDbStatement('
529 529
             INSERT OR REPLACE INTO documents_' . $state . ' (`path`,`title`,`slug`,`type`,`documentType`,`documentTypeSlug`,`state`,`lastModificationDate`,`creationDate`,`lastModifiedBy`,`fields`,`bricks`,`dynamicBricks`)
530 530
             VALUES(
531 531
               ' . $db->quote($documentObject->path) . ',
@@ -543,9 +543,9 @@  discard block
 block discarded – undo
543 543
               ' . $db->quote(json_encode($documentObject->dynamicBricks)) . '
544 544
             )
545 545
         ');
546
-        $result = $stmt->execute();
547
-        return $result;
548
-    }
546
+		$result = $stmt->execute();
547
+		return $result;
548
+	}
549 549
 
550 550
 	/**
551 551
 	 * Delete the document from the database
@@ -556,29 +556,29 @@  discard block
 block discarded – undo
556 556
 	 * @internal param string $state
557 557
 	 *
558 558
 	 */
559
-    public function deleteDocumentByPath($path)
560
-    {
561
-        $db = $this->getContentDbHandle();
562
-        $documentToDelete = $this->getDocumentByPath($path, 'unpublished');
563
-        if ($documentToDelete instanceof Document) {
564
-            if ($documentToDelete->type == 'document') {
565
-                $stmt = $this->getDbStatement('
559
+	public function deleteDocumentByPath($path)
560
+	{
561
+		$db = $this->getContentDbHandle();
562
+		$documentToDelete = $this->getDocumentByPath($path, 'unpublished');
563
+		if ($documentToDelete instanceof Document) {
564
+			if ($documentToDelete->type == 'document') {
565
+				$stmt = $this->getDbStatement('
566 566
                     DELETE FROM documents_unpublished
567 567
                           WHERE path = ' . $db->quote($path) . '
568 568
                 ');
569
-                $stmt->execute();
570
-            } elseif ($documentToDelete->type == 'folder') {
571
-                $folderPathWithWildcard = $path . '%';
572
-                $stmt = $this->getDbStatement('
569
+				$stmt->execute();
570
+			} elseif ($documentToDelete->type == 'folder') {
571
+				$folderPathWithWildcard = $path . '%';
572
+				$stmt = $this->getDbStatement('
573 573
                     DELETE FROM documents_unpublished
574 574
                           WHERE (path LIKE ' . $db->quote($folderPathWithWildcard) . '
575 575
                             AND substr(`path`, ' . (strlen($path) + 1) . ', 1) = "/")
576 576
                             OR path = ' . $db->quote($path) . '
577 577
                 ');
578
-                $stmt->execute();
579
-            }
580
-        }
581
-    }
578
+				$stmt->execute();
579
+			}
580
+		}
581
+	}
582 582
 
583 583
 	/**
584 584
 	 * @param $document
Please login to merge, or discard this patch.
cloudcontrol/library/storage/Storage.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace library\storage {
3 3
 
4
-    use library\storage\factories\DocumentFolderFactory;
5
-    use library\storage\storage\ApplicationComponentsStorage;
6
-    use library\storage\storage\BricksStorage;
7
-    use library\storage\storage\DocumentStorage;
8
-    use library\storage\storage\DocumentTypesStorage;
9
-    use library\storage\storage\FilesStorage;
10
-    use library\storage\storage\ImageSetStorage;
11
-    use library\storage\storage\ImagesStorage;
12
-    use library\storage\storage\RedirectsStorage;
13
-    use library\storage\storage\SitemapStorage;
14
-    use library\storage\storage\UsersStorage;
15
-    use library\storage\storage\ValuelistsStorage;
4
+	use library\storage\factories\DocumentFolderFactory;
5
+	use library\storage\storage\ApplicationComponentsStorage;
6
+	use library\storage\storage\BricksStorage;
7
+	use library\storage\storage\DocumentStorage;
8
+	use library\storage\storage\DocumentTypesStorage;
9
+	use library\storage\storage\FilesStorage;
10
+	use library\storage\storage\ImageSetStorage;
11
+	use library\storage\storage\ImagesStorage;
12
+	use library\storage\storage\RedirectsStorage;
13
+	use library\storage\storage\SitemapStorage;
14
+	use library\storage\storage\UsersStorage;
15
+	use library\storage\storage\ValuelistsStorage;
16 16
 
17
-    /**
17
+	/**
18 18
 	 * Class JsonStorage
19
-     * @package library\storage
19
+	 * @package library\storage
20 20
 	 */
21 21
 	class Storage
22 22
 	{
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
 		 * @var DocumentStorage
62 62
 		 */
63 63
 		protected $documents;
64
-        /**
65
-         * @var RedirectsStorage
66
-         */
67
-        protected $redirects;
64
+		/**
65
+		 * @var RedirectsStorage
66
+		 */
67
+		protected $redirects;
68 68
 
69 69
 		/**
70 70
 		 * @var String
@@ -325,16 +325,16 @@  discard block
 block discarded – undo
325 325
 			return $this->valuelists;
326 326
 		}
327 327
 
328
-        /**
329
-         * @return RedirectsStorage
330
-         */
331
-        public function getRedirects()
332
-        {
333
-            if (!$this->redirects instanceof RedirectsStorage) {
334
-                $this->redirects = new RedirectsStorage($this->repository);
335
-            }
336
-            return $this->redirects;
337
-        }
328
+		/**
329
+		 * @return RedirectsStorage
330
+		 */
331
+		public function getRedirects()
332
+		{
333
+			if (!$this->redirects instanceof RedirectsStorage) {
334
+				$this->redirects = new RedirectsStorage($this->repository);
335
+			}
336
+			return $this->redirects;
337
+		}
338 338
 
339 339
 	}
340 340
 }
341 341
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/components/cms/SitemapRouting.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -14,26 +14,26 @@  discard block
 block discarded – undo
14 14
 class SitemapRouting implements CmsRouting
15 15
 {
16 16
 
17
-    /**
18
-     * SitemapRouting constructor.
19
-     * @param \library\cc\Request $request
20
-     * @param mixed|string $relativeCmsUri
21
-     * @param CmsComponent $cmsComponent
22
-     */
23
-    public function __construct($request, $relativeCmsUri, $cmsComponent)
24
-    {
25
-        if ($relativeCmsUri == '/sitemap') {
17
+	/**
18
+	 * SitemapRouting constructor.
19
+	 * @param \library\cc\Request $request
20
+	 * @param mixed|string $relativeCmsUri
21
+	 * @param CmsComponent $cmsComponent
22
+	 */
23
+	public function __construct($request, $relativeCmsUri, $cmsComponent)
24
+	{
25
+		if ($relativeCmsUri == '/sitemap') {
26 26
 			$this->overviewRoute($request, $cmsComponent);
27
-        } elseif ($relativeCmsUri == '/sitemap/new') {
27
+		} elseif ($relativeCmsUri == '/sitemap/new') {
28 28
 			$this->newRoute($request, $cmsComponent);
29
-        } elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
29
+		} elseif ($relativeCmsUri == '/sitemap/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
30 30
 			$this->editRoute($request, $cmsComponent);
31
-        } elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
31
+		} elseif ($relativeCmsUri == '/sitemap/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
32 32
 			$this->deleteRoute($request, $cmsComponent);
33
-        } else {
34
-            $this->redirectRoutes($relativeCmsUri, $request, $cmsComponent);
35
-        }
36
-    }
33
+		} else {
34
+			$this->redirectRoutes($relativeCmsUri, $request, $cmsComponent);
35
+		}
36
+	}
37 37
 
38 38
 	/**
39 39
 	 * @param $request
@@ -92,54 +92,54 @@  discard block
 block discarded – undo
92 92
 		exit;
93 93
 	}
94 94
 
95
-    private function redirectRoutes($relativeCmsUri, $request, $cmsComponent)
96
-    {
97
-        if ($relativeCmsUri == '/sitemap/redirects') {
98
-            $this->redirectsOverviewRoute($cmsComponent);
99
-        } elseif ($relativeCmsUri == '/sitemap/redirects/new') {
100
-            $this->redirectsNewRoute($request, $cmsComponent);
101
-        } elseif ($relativeCmsUri == '/sitemap/redirects/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
102
-            $this->redirectEditRoute($request, $cmsComponent);
103
-        } elseif ($relativeCmsUri == '/sitemap/redirects/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
104
-            $this->redirectDeleteRoute($request, $cmsComponent);
105
-        }
106
-    }
95
+	private function redirectRoutes($relativeCmsUri, $request, $cmsComponent)
96
+	{
97
+		if ($relativeCmsUri == '/sitemap/redirects') {
98
+			$this->redirectsOverviewRoute($cmsComponent);
99
+		} elseif ($relativeCmsUri == '/sitemap/redirects/new') {
100
+			$this->redirectsNewRoute($request, $cmsComponent);
101
+		} elseif ($relativeCmsUri == '/sitemap/redirects/edit' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
102
+			$this->redirectEditRoute($request, $cmsComponent);
103
+		} elseif ($relativeCmsUri == '/sitemap/redirects/delete' && isset($request::$get[CmsComponent::GET_PARAMETER_SLUG])) {
104
+			$this->redirectDeleteRoute($request, $cmsComponent);
105
+		}
106
+	}
107 107
 
108
-    private function redirectsOverviewRoute($cmsComponent)
109
-    {
110
-        $cmsComponent->subTemplate = 'cms/sitemap/redirects';
111
-        $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
112
-        $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECTS, $cmsComponent->storage->getRedirects()->getRedirects());
113
-    }
108
+	private function redirectsOverviewRoute($cmsComponent)
109
+	{
110
+		$cmsComponent->subTemplate = 'cms/sitemap/redirects';
111
+		$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
112
+		$cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECTS, $cmsComponent->storage->getRedirects()->getRedirects());
113
+	}
114 114
 
115
-    private function redirectsNewRoute($request, $cmsComponent)
116
-    {
117
-        $cmsComponent->subTemplate = 'cms/sitemap/redirects-form';
118
-        $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
119
-        if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) {
120
-            $cmsComponent->storage->getRedirects()->addRedirect($request::$post);
121
-            header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
122
-            exit;
123
-        }
124
-    }
115
+	private function redirectsNewRoute($request, $cmsComponent)
116
+	{
117
+		$cmsComponent->subTemplate = 'cms/sitemap/redirects-form';
118
+		$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
119
+		if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) {
120
+			$cmsComponent->storage->getRedirects()->addRedirect($request::$post);
121
+			header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
122
+			exit;
123
+		}
124
+	}
125 125
 
126
-    private function redirectEditRoute($request, $cmsComponent)
127
-    {
128
-        $cmsComponent->subTemplate = 'cms/sitemap/redirects-form';
129
-        $cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
130
-        $redirect = $cmsComponent->storage->getRedirects()->getRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
131
-        if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) {
132
-            $cmsComponent->storage->getRedirects()->saveRedirect($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post);
133
-            header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
134
-            exit;
135
-        }
136
-        $cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECT, $redirect);
137
-    }
126
+	private function redirectEditRoute($request, $cmsComponent)
127
+	{
128
+		$cmsComponent->subTemplate = 'cms/sitemap/redirects-form';
129
+		$cmsComponent->setParameter(CmsComponent::PARAMETER_MAIN_NAV_CLASS, CmsComponent::PARAMETER_SITEMAP);
130
+		$redirect = $cmsComponent->storage->getRedirects()->getRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
131
+		if (isset($request::$post[CmsComponent::POST_PARAMETER_TITLE], $request::$post[CmsComponent::POST_PARAMETER_FROM_URL], $request::$post[CmsComponent::POST_PARAMETER_TO_URL])) {
132
+			$cmsComponent->storage->getRedirects()->saveRedirect($request::$get[CmsComponent::GET_PARAMETER_SLUG], $request::$post);
133
+			header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
134
+			exit;
135
+		}
136
+		$cmsComponent->setParameter(CmsComponent::PARAMETER_REDIRECT, $redirect);
137
+	}
138 138
 
139
-    private function redirectDeleteRoute($request, $cmsComponent)
140
-    {
141
-        $cmsComponent->storage->getRedirects()->deleteRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
142
-        header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
143
-        exit;
144
-    }
139
+	private function redirectDeleteRoute($request, $cmsComponent)
140
+	{
141
+		$cmsComponent->storage->getRedirects()->deleteRedirectBySlug($request::$get[CmsComponent::GET_PARAMETER_SLUG]);
142
+		header('Location: ' . $request::$subfolders . $cmsComponent->getParameter(CmsComponent::PARAMETER_CMS_PREFIX) . '/sitemap/redirects');
143
+		exit;
144
+	}
145 145
 }
146 146
\ No newline at end of file
Please login to merge, or discard this patch.
cloudcontrol/library/components/CmsComponent.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 
13 13
 	class CmsComponent extends BaseComponent
14 14
 	{
15
-        /**
15
+		/**
16 16
 		 * @var \library\storage\Storage
17 17
 		 */
18 18
 		public $storage;
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 		const PARAMETER_IMAGE_SET = 'imageSet';
42 42
 		const PARAMETER_MAIN_NAV_CLASS = 'mainNavClass';
43 43
 		const PARAMETER_MY_BRICK_SLUG = 'myBrickSlug';
44
-        const PARAMETER_REDIRECT = 'redirect';
45
-        const PARAMETER_REDIRECTS = 'redirects';
44
+		const PARAMETER_REDIRECT = 'redirect';
45
+		const PARAMETER_REDIRECTS = 'redirects';
46 46
 		const PARAMETER_SEARCH = 'search';
47 47
 		const PARAMETER_SEARCH_LOG = "searchLog";
48 48
 		const PARAMETER_SEARCH_NEEDS_UPDATE = "searchNeedsUpdate";
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 		const PARAMETER_VALUELISTS = "valuelists";
58 58
 		const PARAMETER_WHITELIST_IPS = 'whitelistIps';
59 59
 
60
-        const POST_PARAMETER_COMPONENT = 'component';
61
-        const POST_PARAMETER_FROM_URL = "fromUrl";
62
-        const POST_PARAMETER_PASSWORD = 'password';
63
-        const POST_PARAMETER_SAVE = 'save';
64
-        const POST_PARAMETER_TEMPLATE = 'template';
65
-        const POST_PARAMETER_TITLE = 'title';
66
-        const POST_PARAMETER_TO_URL = "toUrl";
67
-        const POST_PARAMETER_USERNAME = 'username';
60
+		const POST_PARAMETER_COMPONENT = 'component';
61
+		const POST_PARAMETER_FROM_URL = "fromUrl";
62
+		const POST_PARAMETER_PASSWORD = 'password';
63
+		const POST_PARAMETER_SAVE = 'save';
64
+		const POST_PARAMETER_TEMPLATE = 'template';
65
+		const POST_PARAMETER_TITLE = 'title';
66
+		const POST_PARAMETER_TO_URL = "toUrl";
67
+		const POST_PARAMETER_USERNAME = 'username';
68 68
 
69 69
 		const GET_PARAMETER_PATH = 'path';
70 70
 		const GET_PARAMETER_SLUG = 'slug';
Please login to merge, or discard this patch.
cloudcontrol/library/cc/Application.php 1 patch
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -2,271 +2,271 @@
 block discarded – undo
2 2
 
3 3
 namespace library\cc {
4 4
 
5
-    use library\components\Component;
6
-    use library\storage\Storage;
7
-
8
-    /**
9
-     * Class Application
10
-     * @package library\cc
11
-     */
12
-    class Application
13
-    {
14
-        /**
15
-         * @var \stdClass
16
-         */
17
-        private $config;
18
-        /**
19
-         * @var \library\storage\Storage $config
20
-         */
21
-        private $storage;
22
-
23
-        /**
24
-         * @var Request
25
-         */
26
-        private $request;
27
-
28
-        /**
29
-         * @var array
30
-         */
31
-        private $matchedSitemapItems = array();
32
-
33
-        /**
34
-         * @var array
35
-         */
36
-        private $applicationComponents = array();
37
-
38
-        /**
39
-         * Application constructor.
40
-         */
41
-        public function __construct()
42
-        {
43
-            $this->config();
44
-            $this->storage();
45
-
46
-            $this->request = new Request();
47
-
48
-            $this->redirectMatching($this->request);
49
-            $this->sitemapMatching($this->request);
50
-
51
-            $this->getApplicationComponents();
52
-
53
-            $this->runApplicationComponents();
54
-            $this->runSitemapComponents();
55
-
56
-            $this->renderApplicationComponents();
57
-            $this->renderSitemapComponents();
58
-        }
59
-
60
-        /**
61
-         * Initialize the config
62
-         *
63
-         * @throws \Exception
64
-         */
65
-        private function config()
66
-        {
67
-            $configPath = __DIR__ . '/../../config.json';
68
-            if (realpath($configPath) !== false) {
69
-                $json = file_get_contents($configPath);
70
-                $this->config = json_decode($json);
71
-            } else {
72
-                initFramework();
73
-                $this->config();
74
-            }
75
-        }
76
-
77
-        /**
78
-         * Initialize the storage
79
-         */
80
-        private function storage()
81
-        {
82
-            $this->storage = new Storage($this->getStorageDir());
83
-        }
84
-
85
-        private function redirectMatching($request)
86
-        {
87
-            $redirects = $this->storage->getRedirects()->getRedirects();
88
-            $relativeUri = '/' . $request::$relativeUri;
89
-
90
-            foreach ($redirects as $redirect) {
91
-                if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
92
-                    $toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
93
-                    if (substr($toUrl, 0, 1) == '/') {
94
-                        $toUrl = substr($toUrl, 1);
95
-                    }
96
-                    if ($redirect->type == '301') {
97
-                        header('HTTP/1.1 301 Moved Permanently');
98
-                        header('Location: ' . $request::$subfolders . $toUrl);
99
-                        exit;
100
-                    } elseif ($redirect->type == '302') {
101
-                        header('Location: ' . $request::$subfolders . $toUrl, true, 302);
102
-                        exit;
103
-                    } else {
104
-                        throw new \Exception('Invalid redirect type.');
105
-                    }
106
-                }
107
-            }
108
-        }
109
-
110
-        /**
111
-         * Loop through sitemap items and see if one matches the requestUri.
112
-         * If it does, add it tot the matchedSitemapItems array
113
-         *
114
-         * @param $request
115
-         */
116
-        private function sitemapMatching($request)
117
-        {
118
-            $sitemap = $this->storage->getSitemap()->getSitemap();
119
-            $relativeUri = '/' . $request::$relativeUri;
120
-
121
-            foreach ($sitemap as $sitemapItem) {
122
-                if ($sitemapItem->regex) {
123
-                    $matches = array();
124
-                    if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
125
-                        // Make a clone, so it doesnt add the matches to the original
126
-                        $matchedClone = clone $sitemapItem;
127
-                        $matchedClone->matches = $matches;
128
-                        $this->matchedSitemapItems[] = $matchedClone;
129
-                        return;
130
-                    }
131
-                } else {
132
-                    if ($sitemapItem->url == $relativeUri) {
133
-                        $this->matchedSitemapItems[] = $sitemapItem;
134
-                        return;
135
-                    }
136
-                }
137
-            }
138
-        }
139
-
140
-        /**
141
-         * Loop through all application components and run them
142
-         *
143
-         * @throws \Exception
144
-         */
145
-        private function runApplicationComponents()
146
-        {
147
-            foreach ($this->applicationComponents as $key => $applicationComponent) {
148
-                $class = $applicationComponent->component;
149
-                $parameters = $applicationComponent->parameters;
150
-                $this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
151
-                $this->applicationComponents[$key]->{'object'}->run($this->storage);
152
-            }
153
-        }
154
-
155
-        /**
156
-         * Loop through all (matched) sitemap components and run them
157
-         *
158
-         * @throws \Exception
159
-         */
160
-        private function runSitemapComponents()
161
-        {
162
-            foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
163
-                $class = $sitemapItem->component;
164
-                $template = $sitemapItem->template;
165
-                $parameters = $sitemapItem->parameters;
166
-
167
-                $this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
168
-
169
-                $this->matchedSitemapItems[$key]->object->run($this->storage);
170
-            }
171
-        }
172
-
173
-        /**
174
-         * @param string $class
175
-         * @param string $template
176
-         * @param array $parameters
177
-         * @param \stdClass|null $matchedSitemapItem
178
-         *
179
-         * @return mixed
180
-         * @throws \Exception
181
-         */
182
-        private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
183
-        {
184
-            $libraryComponentName = '\\library\\components\\' . $class;
185
-            $userComponentName = '\\components\\' . $class;
186
-
187
-            if (AutoloadUtil::autoLoad($libraryComponentName, false)) {
188
-                $component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
189
-            } elseif (AutoloadUtil::autoLoad($userComponentName, false)) {
190
-                $component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
191
-            } else {
192
-                throw new \Exception('Could not load component ' . $class);
193
-            }
194
-
195
-            if (!$component instanceof Component) {
196
-                throw new \Exception('Component not of type Component. Must inherit \library\components\Component');
197
-            }
198
-
199
-            return $component;
200
-        }
201
-
202
-        /**
203
-         * Loop through all application components and render them
204
-         */
205
-        private function renderApplicationComponents()
206
-        {
207
-            foreach ($this->applicationComponents as $applicationComponent) {
208
-                $applicationComponent->{'object'}->render();
209
-            }
210
-        }
211
-
212
-        /**
213
-         * Loop through all (matched) sitemap components and render them
214
-         */
215
-        private function renderSitemapComponents()
216
-        {
217
-            foreach ($this->matchedSitemapItems as $sitemapItem) {
218
-                $this->setCachingHeaders();
219
-                $sitemapItem->object->render($this);
220
-                ob_clean();
221
-                echo $sitemapItem->object->get();
222
-                ob_end_flush();
223
-                exit;
224
-            }
225
-        }
226
-
227
-        public function getAllApplicationComponentParameters()
228
-        {
229
-            $allParameters = array();
230
-            foreach ($this->applicationComponents as $applicationComponent) {
231
-                $parameters = $applicationComponent->{'object'}->getParameters();
232
-                $allParameters[] = $parameters;
233
-            }
234
-            return $allParameters;
235
-        }
236
-
237
-        public function unlockApplicationComponentParameters()
238
-        {
239
-            foreach ($this->applicationComponents as $applicationComponent) {
240
-                $parameters = $applicationComponent->{'object'}->getParameters();
241
-                extract($parameters);
242
-            }
243
-        }
244
-
245
-        /**
246
-         * Set the default caching of pages to 2 days
247
-         */
248
-        public function setCachingHeaders()
249
-        {
250
-            header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
251
-            header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
252
-        }
253
-
254
-        /**
255
-         * @return string
256
-         */
257
-        public function getStoragePath()
258
-        {
259
-            return $this->config->storagePath;
260
-        }
261
-
262
-        public function getStorageDir()
263
-        {
264
-            return $this->config->storageDir;
265
-        }
266
-
267
-        public function getApplicationComponents()
268
-        {
269
-            $this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
270
-        }
271
-    }
5
+	use library\components\Component;
6
+	use library\storage\Storage;
7
+
8
+	/**
9
+	 * Class Application
10
+	 * @package library\cc
11
+	 */
12
+	class Application
13
+	{
14
+		/**
15
+		 * @var \stdClass
16
+		 */
17
+		private $config;
18
+		/**
19
+		 * @var \library\storage\Storage $config
20
+		 */
21
+		private $storage;
22
+
23
+		/**
24
+		 * @var Request
25
+		 */
26
+		private $request;
27
+
28
+		/**
29
+		 * @var array
30
+		 */
31
+		private $matchedSitemapItems = array();
32
+
33
+		/**
34
+		 * @var array
35
+		 */
36
+		private $applicationComponents = array();
37
+
38
+		/**
39
+		 * Application constructor.
40
+		 */
41
+		public function __construct()
42
+		{
43
+			$this->config();
44
+			$this->storage();
45
+
46
+			$this->request = new Request();
47
+
48
+			$this->redirectMatching($this->request);
49
+			$this->sitemapMatching($this->request);
50
+
51
+			$this->getApplicationComponents();
52
+
53
+			$this->runApplicationComponents();
54
+			$this->runSitemapComponents();
55
+
56
+			$this->renderApplicationComponents();
57
+			$this->renderSitemapComponents();
58
+		}
59
+
60
+		/**
61
+		 * Initialize the config
62
+		 *
63
+		 * @throws \Exception
64
+		 */
65
+		private function config()
66
+		{
67
+			$configPath = __DIR__ . '/../../config.json';
68
+			if (realpath($configPath) !== false) {
69
+				$json = file_get_contents($configPath);
70
+				$this->config = json_decode($json);
71
+			} else {
72
+				initFramework();
73
+				$this->config();
74
+			}
75
+		}
76
+
77
+		/**
78
+		 * Initialize the storage
79
+		 */
80
+		private function storage()
81
+		{
82
+			$this->storage = new Storage($this->getStorageDir());
83
+		}
84
+
85
+		private function redirectMatching($request)
86
+		{
87
+			$redirects = $this->storage->getRedirects()->getRedirects();
88
+			$relativeUri = '/' . $request::$relativeUri;
89
+
90
+			foreach ($redirects as $redirect) {
91
+				if (preg_match_all($redirect->fromUrl, $relativeUri, $matches)) {
92
+					$toUrl = preg_replace($redirect->fromUrl, $redirect->toUrl, $relativeUri);
93
+					if (substr($toUrl, 0, 1) == '/') {
94
+						$toUrl = substr($toUrl, 1);
95
+					}
96
+					if ($redirect->type == '301') {
97
+						header('HTTP/1.1 301 Moved Permanently');
98
+						header('Location: ' . $request::$subfolders . $toUrl);
99
+						exit;
100
+					} elseif ($redirect->type == '302') {
101
+						header('Location: ' . $request::$subfolders . $toUrl, true, 302);
102
+						exit;
103
+					} else {
104
+						throw new \Exception('Invalid redirect type.');
105
+					}
106
+				}
107
+			}
108
+		}
109
+
110
+		/**
111
+		 * Loop through sitemap items and see if one matches the requestUri.
112
+		 * If it does, add it tot the matchedSitemapItems array
113
+		 *
114
+		 * @param $request
115
+		 */
116
+		private function sitemapMatching($request)
117
+		{
118
+			$sitemap = $this->storage->getSitemap()->getSitemap();
119
+			$relativeUri = '/' . $request::$relativeUri;
120
+
121
+			foreach ($sitemap as $sitemapItem) {
122
+				if ($sitemapItem->regex) {
123
+					$matches = array();
124
+					if (preg_match_all($sitemapItem->url, $relativeUri, $matches)) {
125
+						// Make a clone, so it doesnt add the matches to the original
126
+						$matchedClone = clone $sitemapItem;
127
+						$matchedClone->matches = $matches;
128
+						$this->matchedSitemapItems[] = $matchedClone;
129
+						return;
130
+					}
131
+				} else {
132
+					if ($sitemapItem->url == $relativeUri) {
133
+						$this->matchedSitemapItems[] = $sitemapItem;
134
+						return;
135
+					}
136
+				}
137
+			}
138
+		}
139
+
140
+		/**
141
+		 * Loop through all application components and run them
142
+		 *
143
+		 * @throws \Exception
144
+		 */
145
+		private function runApplicationComponents()
146
+		{
147
+			foreach ($this->applicationComponents as $key => $applicationComponent) {
148
+				$class = $applicationComponent->component;
149
+				$parameters = $applicationComponent->parameters;
150
+				$this->applicationComponents[$key]->{'object'} = $this->getComponentObject($class, null, $parameters, null);
151
+				$this->applicationComponents[$key]->{'object'}->run($this->storage);
152
+			}
153
+		}
154
+
155
+		/**
156
+		 * Loop through all (matched) sitemap components and run them
157
+		 *
158
+		 * @throws \Exception
159
+		 */
160
+		private function runSitemapComponents()
161
+		{
162
+			foreach ($this->matchedSitemapItems as $key => $sitemapItem) {
163
+				$class = $sitemapItem->component;
164
+				$template = $sitemapItem->template;
165
+				$parameters = $sitemapItem->parameters;
166
+
167
+				$this->matchedSitemapItems[$key]->object = $this->getComponentObject($class, $template, $parameters, $sitemapItem);
168
+
169
+				$this->matchedSitemapItems[$key]->object->run($this->storage);
170
+			}
171
+		}
172
+
173
+		/**
174
+		 * @param string $class
175
+		 * @param string $template
176
+		 * @param array $parameters
177
+		 * @param \stdClass|null $matchedSitemapItem
178
+		 *
179
+		 * @return mixed
180
+		 * @throws \Exception
181
+		 */
182
+		private function getComponentObject($class = '', $template = '', $parameters = array(), $matchedSitemapItem)
183
+		{
184
+			$libraryComponentName = '\\library\\components\\' . $class;
185
+			$userComponentName = '\\components\\' . $class;
186
+
187
+			if (AutoloadUtil::autoLoad($libraryComponentName, false)) {
188
+				$component = new $libraryComponentName($template, $this->request, $parameters, $matchedSitemapItem);
189
+			} elseif (AutoloadUtil::autoLoad($userComponentName, false)) {
190
+				$component = new $userComponentName($template, $this->request, $parameters, $matchedSitemapItem);
191
+			} else {
192
+				throw new \Exception('Could not load component ' . $class);
193
+			}
194
+
195
+			if (!$component instanceof Component) {
196
+				throw new \Exception('Component not of type Component. Must inherit \library\components\Component');
197
+			}
198
+
199
+			return $component;
200
+		}
201
+
202
+		/**
203
+		 * Loop through all application components and render them
204
+		 */
205
+		private function renderApplicationComponents()
206
+		{
207
+			foreach ($this->applicationComponents as $applicationComponent) {
208
+				$applicationComponent->{'object'}->render();
209
+			}
210
+		}
211
+
212
+		/**
213
+		 * Loop through all (matched) sitemap components and render them
214
+		 */
215
+		private function renderSitemapComponents()
216
+		{
217
+			foreach ($this->matchedSitemapItems as $sitemapItem) {
218
+				$this->setCachingHeaders();
219
+				$sitemapItem->object->render($this);
220
+				ob_clean();
221
+				echo $sitemapItem->object->get();
222
+				ob_end_flush();
223
+				exit;
224
+			}
225
+		}
226
+
227
+		public function getAllApplicationComponentParameters()
228
+		{
229
+			$allParameters = array();
230
+			foreach ($this->applicationComponents as $applicationComponent) {
231
+				$parameters = $applicationComponent->{'object'}->getParameters();
232
+				$allParameters[] = $parameters;
233
+			}
234
+			return $allParameters;
235
+		}
236
+
237
+		public function unlockApplicationComponentParameters()
238
+		{
239
+			foreach ($this->applicationComponents as $applicationComponent) {
240
+				$parameters = $applicationComponent->{'object'}->getParameters();
241
+				extract($parameters);
242
+			}
243
+		}
244
+
245
+		/**
246
+		 * Set the default caching of pages to 2 days
247
+		 */
248
+		public function setCachingHeaders()
249
+		{
250
+			header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + (60 * 60 * 24 * 2))); // 2 days
251
+			header("Cache-Control: max-age=" . (60 * 60 * 24 * 2));
252
+		}
253
+
254
+		/**
255
+		 * @return string
256
+		 */
257
+		public function getStoragePath()
258
+		{
259
+			return $this->config->storagePath;
260
+		}
261
+
262
+		public function getStorageDir()
263
+		{
264
+			return $this->config->storageDir;
265
+		}
266
+
267
+		public function getApplicationComponents()
268
+		{
269
+			$this->applicationComponents = $this->storage->getApplicationComponents()->getApplicationComponents();
270
+		}
271
+	}
272 272
 }
273 273
\ No newline at end of file
Please login to merge, or discard this patch.