@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script> |
4 | 4 | <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet"> |
5 | 5 | <script>var smallestImage = '<?=$smallestImage?>';</script> |
6 | -<?$copyable=''?> |
|
6 | +<?$copyable = ''?> |
|
7 | 7 | <section class="documents"> |
8 | 8 | <h2><i class="fa fa-file-text-o"></i> Documents</h2> |
9 | 9 | <nav class="actions"> |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | </div> |
24 | 24 | </li> |
25 | 25 | </ul> |
26 | - <?include('document-form-form.php');?> |
|
26 | + <?include('document-form-form.php'); ?> |
|
27 | 27 | </section> |
28 | 28 | |
29 | 29 | <script> |
@@ -14,125 +14,125 @@ |
||
14 | 14 | |
15 | 15 | class FormComponent Extends BaseComponent |
16 | 16 | { |
17 | - protected $documentType = null; |
|
18 | - protected $responseFolder = null; |
|
19 | - protected $subTemplate = 'cms/documents/document-form-form'; |
|
20 | - protected $formParameterName = 'form'; |
|
21 | - protected $thankYouMessage = 'Thank you for sending us your response.'; |
|
22 | - |
|
23 | - private $formId; |
|
24 | - private $getPathBackup = null; |
|
25 | - |
|
26 | - public function run(Storage $storage) |
|
27 | - { |
|
28 | - parent::run($storage); |
|
29 | - |
|
30 | - $this->checkParameters(); |
|
31 | - |
|
32 | - if ($this->documentType === null || $this->responseFolder === null) { |
|
33 | - throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); |
|
34 | - } |
|
35 | - |
|
36 | - $this->setFormId(); |
|
37 | - $this->initialize($storage); |
|
38 | - $this->checkSubmit($storage); |
|
39 | - } |
|
40 | - |
|
41 | - public function render($application = null) |
|
42 | - { |
|
43 | - $request = $this->request; |
|
44 | - if (isset($request::$get['path'])) { |
|
45 | - $this->getPathBackup = $request::$get['path']; |
|
46 | - } |
|
47 | - $request::$get['path'] = $this->responseFolder; |
|
48 | - $form = $this->renderTemplate($this->subTemplate); |
|
49 | - if ($this->getPathBackup !== null) { |
|
50 | - $request::$get['path'] = $this->getPathBackup; |
|
51 | - } else { |
|
52 | - unset($request::$get['path']); |
|
53 | - } |
|
54 | - if (!empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]) && $_SESSION['FormComponent'][$this->formParameterName] === $this->formId) { |
|
55 | - $this->parameters[$this->formParameterName] = $this->thankYouMessage; |
|
56 | - } else { |
|
57 | - $this->parameters[$this->formParameterName] = $form; |
|
58 | - } |
|
59 | - |
|
60 | - parent::render($application); |
|
61 | - } |
|
62 | - |
|
63 | - private function checkParameters() |
|
64 | - { |
|
65 | - if (isset($this->parameters['documentType'])) { |
|
66 | - $this->documentType = $this->parameters['documentType']; |
|
67 | - unset($this->parameters['documentType']); |
|
68 | - } |
|
69 | - |
|
70 | - if (isset($this->parameters['responseFolder'])) { |
|
71 | - $this->responseFolder = $this->parameters['responseFolder']; |
|
72 | - unset($this->parameters['responseFolder']); |
|
73 | - } |
|
74 | - |
|
75 | - if (isset($this->parameters['subTemplate'])) { |
|
76 | - $this->subTemplate = $this->parameters['subTemplate']; |
|
77 | - unset($this->parameters['subTemplate']); |
|
78 | - } |
|
79 | - |
|
80 | - if (isset($this->parameters['formParameterName'])) { |
|
81 | - $this->formParameterName = $this->parameters['formParameterName']; |
|
82 | - unset($this->parameters['formParameterName']); |
|
83 | - } |
|
84 | - |
|
85 | - if (isset($this->parameters['thankYouMessage'])) { |
|
86 | - $this->thankYouMessage = $this->parameters['thankYouMessage']; |
|
87 | - unset($this->parameters['thankYouMessage']); |
|
88 | - } |
|
89 | - } |
|
90 | - |
|
91 | - private function initialize($storage) |
|
92 | - { |
|
93 | - $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; |
|
94 | - $this->parameters['cmsPrefix'] = ''; |
|
95 | - |
|
96 | - $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); |
|
97 | - $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); |
|
98 | - $this->parameters['hideTitleAndState'] = true; |
|
99 | - $this->parameters['formId'] = $this->formId; |
|
100 | - } |
|
101 | - |
|
102 | - private function checkSubmit($storage) |
|
103 | - { |
|
104 | - $request = $this->request; |
|
105 | - if (!empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]) && $_SESSION['FormComponent'][$this->formParameterName] === $this->formId) { |
|
106 | - $postValues = $request::$post; |
|
107 | - $postValues['documentType'] = $this->documentType; |
|
108 | - $postValues['path'] = $this->responseFolder; |
|
109 | - $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
110 | - |
|
111 | - $backup = null; |
|
112 | - if (isset($_SESSION['cloudcontrol'])) { |
|
113 | - $backup = $_SESSION['cloudcontrol']; |
|
114 | - } |
|
115 | - $fakeUser = new \stdClass(); |
|
116 | - $fakeUser->username = 'FormComponent'; |
|
117 | - $_SESSION['cloudcontrol'] = $fakeUser; |
|
118 | - |
|
119 | - $storage->addDocument($postValues); |
|
120 | - |
|
121 | - if ($backup === null) { |
|
122 | - unset($_SESSION['cloudcontrol']); |
|
123 | - } else { |
|
124 | - $_SESSION['cloudcontrol'] = $backup; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - private function setFormId() |
|
130 | - { |
|
131 | - if (isset($_SESSION['FormComponent'][$this->formParameterName])) { |
|
132 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]; |
|
133 | - } else { |
|
134 | - $_SESSION['FormComponent'][$this->formParameterName] = (string) microtime(true); |
|
135 | - $this->formId = $_SESSION['FormComponent'][$this->formParameterName]; |
|
136 | - } |
|
137 | - } |
|
17 | + protected $documentType = null; |
|
18 | + protected $responseFolder = null; |
|
19 | + protected $subTemplate = 'cms/documents/document-form-form'; |
|
20 | + protected $formParameterName = 'form'; |
|
21 | + protected $thankYouMessage = 'Thank you for sending us your response.'; |
|
22 | + |
|
23 | + private $formId; |
|
24 | + private $getPathBackup = null; |
|
25 | + |
|
26 | + public function run(Storage $storage) |
|
27 | + { |
|
28 | + parent::run($storage); |
|
29 | + |
|
30 | + $this->checkParameters(); |
|
31 | + |
|
32 | + if ($this->documentType === null || $this->responseFolder === null) { |
|
33 | + throw new \Exception('Parameters `documentType` and `responseFolder` are required for usage with this form'); |
|
34 | + } |
|
35 | + |
|
36 | + $this->setFormId(); |
|
37 | + $this->initialize($storage); |
|
38 | + $this->checkSubmit($storage); |
|
39 | + } |
|
40 | + |
|
41 | + public function render($application = null) |
|
42 | + { |
|
43 | + $request = $this->request; |
|
44 | + if (isset($request::$get['path'])) { |
|
45 | + $this->getPathBackup = $request::$get['path']; |
|
46 | + } |
|
47 | + $request::$get['path'] = $this->responseFolder; |
|
48 | + $form = $this->renderTemplate($this->subTemplate); |
|
49 | + if ($this->getPathBackup !== null) { |
|
50 | + $request::$get['path'] = $this->getPathBackup; |
|
51 | + } else { |
|
52 | + unset($request::$get['path']); |
|
53 | + } |
|
54 | + if (!empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]) && $_SESSION['FormComponent'][$this->formParameterName] === $this->formId) { |
|
55 | + $this->parameters[$this->formParameterName] = $this->thankYouMessage; |
|
56 | + } else { |
|
57 | + $this->parameters[$this->formParameterName] = $form; |
|
58 | + } |
|
59 | + |
|
60 | + parent::render($application); |
|
61 | + } |
|
62 | + |
|
63 | + private function checkParameters() |
|
64 | + { |
|
65 | + if (isset($this->parameters['documentType'])) { |
|
66 | + $this->documentType = $this->parameters['documentType']; |
|
67 | + unset($this->parameters['documentType']); |
|
68 | + } |
|
69 | + |
|
70 | + if (isset($this->parameters['responseFolder'])) { |
|
71 | + $this->responseFolder = $this->parameters['responseFolder']; |
|
72 | + unset($this->parameters['responseFolder']); |
|
73 | + } |
|
74 | + |
|
75 | + if (isset($this->parameters['subTemplate'])) { |
|
76 | + $this->subTemplate = $this->parameters['subTemplate']; |
|
77 | + unset($this->parameters['subTemplate']); |
|
78 | + } |
|
79 | + |
|
80 | + if (isset($this->parameters['formParameterName'])) { |
|
81 | + $this->formParameterName = $this->parameters['formParameterName']; |
|
82 | + unset($this->parameters['formParameterName']); |
|
83 | + } |
|
84 | + |
|
85 | + if (isset($this->parameters['thankYouMessage'])) { |
|
86 | + $this->thankYouMessage = $this->parameters['thankYouMessage']; |
|
87 | + unset($this->parameters['thankYouMessage']); |
|
88 | + } |
|
89 | + } |
|
90 | + |
|
91 | + private function initialize($storage) |
|
92 | + { |
|
93 | + $this->parameters['smallestImage'] = $storage->getSmallestImageSet()->slug; |
|
94 | + $this->parameters['cmsPrefix'] = ''; |
|
95 | + |
|
96 | + $this->parameters['documentType'] = $this->storage->getDocumentTypeBySlug($this->documentType, true); |
|
97 | + $this->parameters['documentTypes'] = $this->storage->getDocumentTypes(); |
|
98 | + $this->parameters['hideTitleAndState'] = true; |
|
99 | + $this->parameters['formId'] = $this->formId; |
|
100 | + } |
|
101 | + |
|
102 | + private function checkSubmit($storage) |
|
103 | + { |
|
104 | + $request = $this->request; |
|
105 | + if (!empty($request::$post) && isset($request::$post['formId']) && $request::$post['formId'] === $this->formId && isset($_SESSION['FormComponent'][$this->formParameterName]) && $_SESSION['FormComponent'][$this->formParameterName] === $this->formId) { |
|
106 | + $postValues = $request::$post; |
|
107 | + $postValues['documentType'] = $this->documentType; |
|
108 | + $postValues['path'] = $this->responseFolder; |
|
109 | + $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
110 | + |
|
111 | + $backup = null; |
|
112 | + if (isset($_SESSION['cloudcontrol'])) { |
|
113 | + $backup = $_SESSION['cloudcontrol']; |
|
114 | + } |
|
115 | + $fakeUser = new \stdClass(); |
|
116 | + $fakeUser->username = 'FormComponent'; |
|
117 | + $_SESSION['cloudcontrol'] = $fakeUser; |
|
118 | + |
|
119 | + $storage->addDocument($postValues); |
|
120 | + |
|
121 | + if ($backup === null) { |
|
122 | + unset($_SESSION['cloudcontrol']); |
|
123 | + } else { |
|
124 | + $_SESSION['cloudcontrol'] = $backup; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + private function setFormId() |
|
130 | + { |
|
131 | + if (isset($_SESSION['FormComponent'][$this->formParameterName])) { |
|
132 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]; |
|
133 | + } else { |
|
134 | + $_SESSION['FormComponent'][$this->formParameterName] = (string) microtime(true); |
|
135 | + $this->formId = $_SESSION['FormComponent'][$this->formParameterName]; |
|
136 | + } |
|
137 | + } |
|
138 | 138 | } |
139 | 139 | \ No newline at end of file |
@@ -106,7 +106,7 @@ |
||
106 | 106 | $postValues = $request::$post; |
107 | 107 | $postValues['documentType'] = $this->documentType; |
108 | 108 | $postValues['path'] = $this->responseFolder; |
109 | - $postValues['title'] = date('r') . ' - From: ' . $request::$requestUri; |
|
109 | + $postValues['title'] = date('r').' - From: '.$request::$requestUri; |
|
110 | 110 | |
111 | 111 | $backup = null; |
112 | 112 | if (isset($_SESSION['cloudcontrol'])) { |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | } |
44 | 44 | return $returnFileNames; |
45 | 45 | } else { |
46 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
46 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @return string |
55 | 55 | * @throws \Exception |
56 | 56 | */ |
57 | - public function resize($imagePath='', $width='',$height='') |
|
57 | + public function resize($imagePath = '', $width = '', $height = '') |
|
58 | 58 | { |
59 | - $modifier = '-r' . $width . 'x' . $height; |
|
60 | - return $this->applyMethod('Resize', $imagePath, $width,$height, $modifier); |
|
59 | + $modifier = '-r'.$width.'x'.$height; |
|
60 | + return $this->applyMethod('Resize', $imagePath, $width, $height, $modifier); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -67,10 +67,10 @@ discard block |
||
67 | 67 | * @return string |
68 | 68 | * @throws \Exception |
69 | 69 | */ |
70 | - public function smartcrop($imagePath='', $width='',$height='') |
|
70 | + public function smartcrop($imagePath = '', $width = '', $height = '') |
|
71 | 71 | { |
72 | - $modifier = '-s' . $width . 'x' . $height; |
|
73 | - return $this->applyMethod('SmartCrop', $imagePath, $width,$height, $modifier); |
|
72 | + $modifier = '-s'.$width.'x'.$height; |
|
73 | + return $this->applyMethod('SmartCrop', $imagePath, $width, $height, $modifier); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -80,10 +80,10 @@ discard block |
||
80 | 80 | * @return string |
81 | 81 | * @throws \Exception |
82 | 82 | */ |
83 | - public function boxcrop($imagePath='', $width='',$height='') |
|
83 | + public function boxcrop($imagePath = '', $width = '', $height = '') |
|
84 | 84 | { |
85 | - $modifier = '-b' . $width . 'x' . $height; |
|
86 | - return $this->applyMethod('BoxCrop', $imagePath, $width,$height, $modifier); |
|
85 | + $modifier = '-b'.$width.'x'.$height; |
|
86 | + return $this->applyMethod('BoxCrop', $imagePath, $width, $height, $modifier); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return string |
94 | 94 | */ |
95 | - private function modifyName($imagePath, $modifier='') |
|
95 | + private function modifyName($imagePath, $modifier = '') |
|
96 | 96 | { |
97 | 97 | $filename = basename($imagePath); |
98 | 98 | $path = dirname($imagePath); |
@@ -102,30 +102,30 @@ discard block |
||
102 | 102 | array_pop($fileParts); |
103 | 103 | $fileNameWithoutExtension = implode('-', $fileParts); |
104 | 104 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
105 | - $filename = $fileNameWithoutExtension . $modifier . '.' . $extension; |
|
105 | + $filename = $fileNameWithoutExtension.$modifier.'.'.$extension; |
|
106 | 106 | } else { |
107 | 107 | $filename = slugify($filename); |
108 | 108 | } |
109 | 109 | |
110 | - if (file_exists($path . '/' . $filename)) { |
|
110 | + if (file_exists($path.'/'.$filename)) { |
|
111 | 111 | $fileParts = explode('.', $filename); |
112 | 112 | if (count($fileParts) > 1) { |
113 | 113 | $extension = end($fileParts); |
114 | 114 | array_pop($fileParts); |
115 | 115 | $fileNameWithoutExtension = implode('-', $fileParts); |
116 | 116 | $fileNameWithoutExtension .= '-copy'; |
117 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
117 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
118 | 118 | } else { |
119 | 119 | $filename .= '-copy'; |
120 | 120 | } |
121 | - return $this->modifyName($path . '/' . $filename); |
|
121 | + return $this->modifyName($path.'/'.$filename); |
|
122 | 122 | } |
123 | - return $path . '/' . $filename; |
|
123 | + return $path.'/'.$filename; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | private function applyMethod($method, $imagePath, $width, $height, $modifier) |
127 | 127 | { |
128 | - $method = 'library\\images\\methods\\' . $method; |
|
128 | + $method = 'library\\images\\methods\\'.$method; |
|
129 | 129 | $destination = $this->modifyName($imagePath, $modifier); |
130 | 130 | if (file_exists($imagePath)) { |
131 | 131 | $image = new Image(); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $resizedImage->SaveImage($destination, $resizedImage->GetImageMimeType($imagePath), 80); |
140 | 140 | return basename($destination); |
141 | 141 | } else { |
142 | - throw new \Exception('Image doesnt exist: ' . $imagePath); |
|
142 | + throw new \Exception('Image doesnt exist: '.$imagePath); |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | */ |
34 | 34 | private function config() |
35 | 35 | { |
36 | - $storagePath = __DIR__ . $this->storagePath; |
|
36 | + $storagePath = __DIR__.$this->storagePath; |
|
37 | 37 | if (realpath($storagePath) !== false) { |
38 | 38 | $jsonString = file_get_contents($storagePath); |
39 | 39 | $this->repository = json_decode($jsonString); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | public function getDocumentBySlug($slug) |
185 | 185 | { |
186 | - $documentContainer = $this->getDocumentContainerByPath('/' . $slug); |
|
186 | + $documentContainer = $this->getDocumentContainerByPath('/'.$slug); |
|
187 | 187 | $indices = $documentContainer['indices']; |
188 | 188 | |
189 | 189 | if ($indices === null) { |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | // Check for duplicates |
229 | 229 | foreach ($this->repository->documents as $index => $document) { |
230 | 230 | if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') { |
231 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
231 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | $this->repository->documents[end($indices)] = $documentFolderObject; |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | // Check for duplicates |
237 | 237 | foreach ($previousFolder->content as $index => $document) { |
238 | 238 | if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'document') { |
239 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
239 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
240 | 240 | } |
241 | 241 | } |
242 | - $previousFolder->content[end($indices)] = $documentFolderObject ; |
|
242 | + $previousFolder->content[end($indices)] = $documentFolderObject; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | $this->save(); |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | foreach ($this->repository->documents as $document) { |
254 | 254 | if ($document->slug == $documentFolderObject->slug && $document->type == 'document') { |
255 | 255 | // TODO make it so it doesnt throw an exception, but instead shows a warning |
256 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
256 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | $this->repository->documents[] = $documentFolderObject; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | foreach ($containerFolder->content as $document) { |
265 | 265 | if ($document->slug == $documentFolderObject->slug && $document->type == 'document') { |
266 | 266 | // TODO make it so it doesnt throw an exception, but instead shows a warning |
267 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
267 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
268 | 268 | } |
269 | 269 | } |
270 | 270 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | foreach ($this->repository->documents as $document) { |
381 | 381 | if ($document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
382 | 382 | // TODO make it so it doesnt throw an exception, but instead shows a warning |
383 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
383 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
384 | 384 | } |
385 | 385 | } |
386 | 386 | $this->repository->documents[] = $documentFolderObject; |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | foreach ($containerFolder->content as $document) { |
402 | 402 | if ($document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
403 | 403 | // TODO make it so it doesnt throw an exception, but instead shows a warning |
404 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
404 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | $folder->content[] = $documentFolderObject; |
@@ -453,12 +453,12 @@ discard block |
||
453 | 453 | */ |
454 | 454 | public function getDocumentFolderBySlug($slug) |
455 | 455 | { |
456 | - $documentContainer = $this->getDocumentContainerByPath('/' . $slug); |
|
456 | + $documentContainer = $this->getDocumentContainerByPath('/'.$slug); |
|
457 | 457 | $indices = $documentContainer['indices']; |
458 | 458 | |
459 | 459 | $folder = $this->repository->documents; |
460 | 460 | if ($indices === null) { |
461 | - throw new \Exception('Can\'t find folder with slug `' . $slug . '`'); |
|
461 | + throw new \Exception('Can\'t find folder with slug `'.$slug.'`'); |
|
462 | 462 | } |
463 | 463 | foreach ($indices as $index) { |
464 | 464 | if ($folder === $this->repository->documents) { |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | // Check for duplicates |
501 | 501 | foreach ($this->repository->documents as $index => $document) { |
502 | 502 | if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
503 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
503 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
504 | 504 | } |
505 | 505 | } |
506 | 506 | $this->repository->documents[end($indices)] = $documentFolderObject; |
@@ -508,10 +508,10 @@ discard block |
||
508 | 508 | // Check for duplicates |
509 | 509 | foreach ($previousFolder->content as $index => $document) { |
510 | 510 | if (end($indices) !== $index && $document->slug == $documentFolderObject->slug && $document->type == 'folder') { |
511 | - throw new \Exception('Duplicate slug: ' . $document->slug . ' in folder ' . $postValues['path']); |
|
511 | + throw new \Exception('Duplicate slug: '.$document->slug.' in folder '.$postValues['path']); |
|
512 | 512 | } |
513 | 513 | } |
514 | - $previousFolder->content[end($indices)] = $documentFolderObject ; |
|
514 | + $previousFolder->content[end($indices)] = $documentFolderObject; |
|
515 | 515 | } |
516 | 516 | |
517 | 517 | $this->save(); |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | 'previousDocument' => $previousDocument |
581 | 581 | ); |
582 | 582 | } else { |
583 | - throw new \Exception('Invalid path: ' . $path); |
|
583 | + throw new \Exception('Invalid path: '.$path); |
|
584 | 584 | } |
585 | 585 | } |
586 | 586 | |
@@ -765,13 +765,13 @@ discard block |
||
765 | 765 | |
766 | 766 | public function addImage($postValues) |
767 | 767 | { |
768 | - $destinationPath = realpath(__DIR__ . '/../../www/images/'); |
|
768 | + $destinationPath = realpath(__DIR__.'/../../www/images/'); |
|
769 | 769 | |
770 | 770 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
771 | - $destination = $destinationPath . '/' . $filename; |
|
771 | + $destination = $destinationPath.'/'.$filename; |
|
772 | 772 | |
773 | 773 | if ($postValues['error'] != '0') { |
774 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
774 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -793,14 +793,14 @@ discard block |
||
793 | 793 | |
794 | 794 | public function deleteImageByName($filename) |
795 | 795 | { |
796 | - $destinationPath = realpath(__DIR__ . '/../../www/images/'); |
|
796 | + $destinationPath = realpath(__DIR__.'/../../www/images/'); |
|
797 | 797 | |
798 | 798 | $images = $this->getImages(); |
799 | 799 | |
800 | 800 | foreach ($images as $key => $image) { |
801 | 801 | if ($image->file == $filename) { |
802 | 802 | foreach ($image->set as $imageSetFilename) { |
803 | - $destination = $destinationPath . '/' . $imageSetFilename; |
|
803 | + $destination = $destinationPath.'/'.$imageSetFilename; |
|
804 | 804 | if (file_exists($destination)) { |
805 | 805 | unlink($destination); |
806 | 806 | } else { |
@@ -842,7 +842,7 @@ discard block |
||
842 | 842 | */ |
843 | 843 | public function getFiles() |
844 | 844 | { |
845 | - $files = $this->repository->files; |
|
845 | + $files = $this->repository->files; |
|
846 | 846 | usort($files, array($this, 'compareFiles')); |
847 | 847 | return $files; |
848 | 848 | } |
@@ -854,13 +854,13 @@ discard block |
||
854 | 854 | |
855 | 855 | public function addFile($postValues) |
856 | 856 | { |
857 | - $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
|
857 | + $destinationPath = realpath(__DIR__.'/../../www/files/'); |
|
858 | 858 | |
859 | 859 | $filename = $this->validateFilename($postValues['name'], $destinationPath); |
860 | - $destination = $destinationPath . '/' . $filename; |
|
860 | + $destination = $destinationPath.'/'.$filename; |
|
861 | 861 | |
862 | 862 | if ($postValues['error'] != '0') { |
863 | - throw new \Exception('Error uploading file. Error code: ' . $postValues['error']); |
|
863 | + throw new \Exception('Error uploading file. Error code: '.$postValues['error']); |
|
864 | 864 | } |
865 | 865 | |
866 | 866 | if (move_uploaded_file($postValues['tmp_name'], $destination)) { |
@@ -884,23 +884,23 @@ discard block |
||
884 | 884 | array_pop($fileParts); |
885 | 885 | $fileNameWithoutExtension = implode('-', $fileParts); |
886 | 886 | $fileNameWithoutExtension = slugify($fileNameWithoutExtension); |
887 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
887 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
888 | 888 | } else { |
889 | 889 | $filename = slugify($filename); |
890 | 890 | } |
891 | 891 | |
892 | - if (file_exists($path . '/' . $filename)) { |
|
892 | + if (file_exists($path.'/'.$filename)) { |
|
893 | 893 | $fileParts = explode('.', $filename); |
894 | 894 | if (count($fileParts) > 1) { |
895 | 895 | $extension = end($fileParts); |
896 | 896 | array_pop($fileParts); |
897 | 897 | $fileNameWithoutExtension = implode('-', $fileParts); |
898 | 898 | $fileNameWithoutExtension .= '-copy'; |
899 | - $filename = $fileNameWithoutExtension . '.' . $extension; |
|
899 | + $filename = $fileNameWithoutExtension.'.'.$extension; |
|
900 | 900 | } else { |
901 | 901 | $filename .= '-copy'; |
902 | 902 | } |
903 | - return $this->validateFilename($filename,$path); |
|
903 | + return $this->validateFilename($filename, $path); |
|
904 | 904 | } |
905 | 905 | return $filename; |
906 | 906 | } |
@@ -926,8 +926,8 @@ discard block |
||
926 | 926 | */ |
927 | 927 | public function deleteFileByName($filename) |
928 | 928 | { |
929 | - $destinationPath = realpath(__DIR__ . '/../../www/files/'); |
|
930 | - $destination = $destinationPath . '/' . $filename; |
|
929 | + $destinationPath = realpath(__DIR__.'/../../www/files/'); |
|
930 | + $destination = $destinationPath.'/'.$filename; |
|
931 | 931 | |
932 | 932 | if (file_exists($destination)) { |
933 | 933 | $files = $this->getFiles(); |
@@ -1223,12 +1223,12 @@ discard block |
||
1223 | 1223 | * @throws \Exception |
1224 | 1224 | */ |
1225 | 1225 | private function save() { |
1226 | - $storagePath = __DIR__ . $this->storagePath; |
|
1226 | + $storagePath = __DIR__.$this->storagePath; |
|
1227 | 1227 | if (realpath($storagePath) !== false) { |
1228 | - copy($storagePath, $storagePath . '.bak'); |
|
1228 | + copy($storagePath, $storagePath.'.bak'); |
|
1229 | 1229 | file_put_contents($storagePath, json_encode($this->repository)); |
1230 | 1230 | } else { |
1231 | - throw new \Exception('Couldnt find storagePath ' . $storagePath); |
|
1231 | + throw new \Exception('Couldnt find storagePath '.$storagePath); |
|
1232 | 1232 | } |
1233 | 1233 | } |
1234 | 1234 |