@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | // Protected Properties |
40 | 40 | // ========================================================================= |
41 | 41 | |
42 | - protected $allowAnonymous = []; |
|
42 | + protected $allowAnonymous = [ ]; |
|
43 | 43 | |
44 | 44 | // Public Methods |
45 | 45 | // ========================================================================= |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | */ |
55 | 55 | public function actionPluginSettings($settings = null): Response |
56 | 56 | { |
57 | - $variables = []; |
|
57 | + $variables = [ ]; |
|
58 | 58 | PermissionHelper::controllerPermissionCheck('retour:settings'); |
59 | 59 | if ($settings === null) { |
60 | 60 | $settings = Retour::$settings; |
@@ -69,16 +69,16 @@ discard block |
||
69 | 69 | } catch (InvalidConfigException $e) { |
70 | 70 | Craft::error($e->getMessage(), __METHOD__); |
71 | 71 | } |
72 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
72 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
73 | 73 | '@nystudio107/retour/web/assets/dist', |
74 | 74 | true |
75 | 75 | ); |
76 | 76 | // Basic variables |
77 | - $variables['fullPageForm'] = true; |
|
78 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
79 | - $variables['pluginName'] = $pluginName; |
|
80 | - $variables['title'] = $templateTitle; |
|
81 | - $variables['crumbs'] = [ |
|
77 | + $variables[ 'fullPageForm' ] = true; |
|
78 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
79 | + $variables[ 'pluginName' ] = $pluginName; |
|
80 | + $variables[ 'title' ] = $templateTitle; |
|
81 | + $variables[ 'crumbs' ] = [ |
|
82 | 82 | [ |
83 | 83 | 'label' => $pluginName, |
84 | 84 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -88,9 +88,9 @@ discard block |
||
88 | 88 | 'url' => UrlHelper::cpUrl('retour/settings'), |
89 | 89 | ], |
90 | 90 | ]; |
91 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
92 | - $variables['selectedSubnavItem'] = 'settings'; |
|
93 | - $variables['settings'] = $settings; |
|
91 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
92 | + $variables[ 'selectedSubnavItem' ] = 'settings'; |
|
93 | + $variables[ 'settings' ] = $settings; |
|
94 | 94 | |
95 | 95 | // Render the template |
96 | 96 | return $this->renderTemplate('retour/settings', $variables); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | PermissionHelper::controllerPermissionCheck('retour:settings'); |
111 | 111 | $this->requirePostRequest(); |
112 | 112 | $pluginHandle = Craft::$app->getRequest()->getRequiredBodyParam('pluginHandle'); |
113 | - $settings = Craft::$app->getRequest()->getBodyParam('settings', []); |
|
113 | + $settings = Craft::$app->getRequest()->getBodyParam('settings', [ ]); |
|
114 | 114 | $plugin = Craft::$app->getPlugins()->getPlugin($pluginHandle); |
115 | 115 | |
116 | 116 | if ($plugin === null) { |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | // Protected Properties |
42 | 42 | // ========================================================================= |
43 | 43 | |
44 | - protected $allowAnonymous = []; |
|
44 | + protected $allowAnonymous = [ ]; |
|
45 | 45 | |
46 | 46 | // Public Methods |
47 | 47 | // ========================================================================= |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function actionRedirects(string $siteHandle = null): Response |
59 | 59 | { |
60 | - $variables = []; |
|
60 | + $variables = [ ]; |
|
61 | 61 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
62 | 62 | // Get the site to edit |
63 | 63 | $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle); |
@@ -70,32 +70,32 @@ discard block |
||
70 | 70 | } catch (InvalidConfigException $e) { |
71 | 71 | Craft::error($e->getMessage(), __METHOD__); |
72 | 72 | } |
73 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
73 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
74 | 74 | '@nystudio107/retour/web/assets/dist', |
75 | 75 | true |
76 | 76 | ); |
77 | 77 | // Enabled sites |
78 | 78 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
79 | - $variables['controllerHandle'] = 'redirects'; |
|
79 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
80 | 80 | |
81 | 81 | // Basic variables |
82 | - $variables['fullPageForm'] = false; |
|
83 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
84 | - $variables['pluginName'] = $pluginName; |
|
85 | - $variables['title'] = $templateTitle; |
|
86 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
87 | - $variables['crumbs'] = [ |
|
82 | + $variables[ 'fullPageForm' ] = false; |
|
83 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
84 | + $variables[ 'pluginName' ] = $pluginName; |
|
85 | + $variables[ 'title' ] = $templateTitle; |
|
86 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
87 | + $variables[ 'crumbs' ] = [ |
|
88 | 88 | [ |
89 | 89 | 'label' => $pluginName, |
90 | 90 | 'url' => UrlHelper::cpUrl('retour'), |
91 | 91 | ], |
92 | 92 | [ |
93 | 93 | 'label' => $templateTitle, |
94 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
94 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
95 | 95 | ], |
96 | 96 | ]; |
97 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
98 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
97 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
98 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
99 | 99 | |
100 | 100 | // Render the template |
101 | 101 | return $this->renderTemplate('retour/redirects/index', $variables); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | int $siteId = 0, |
120 | 120 | StaticRedirectsModel $redirect = null |
121 | 121 | ): Response { |
122 | - $variables = []; |
|
122 | + $variables = [ ]; |
|
123 | 123 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
124 | 124 | |
125 | 125 | // Load in the redirect |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | if ($redirect === null) { |
134 | 134 | $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId); |
135 | 135 | if ($redirectConfig === null) { |
136 | - $redirectConfig = []; |
|
136 | + $redirectConfig = [ ]; |
|
137 | 137 | Craft::error( |
138 | 138 | Craft::t( |
139 | 139 | 'retour', |
140 | 140 | "Couldn't load redirect id {id}", |
141 | - ['id' => $redirectId] |
|
141 | + [ 'id' => $redirectId ] |
|
142 | 142 | ), |
143 | 143 | __METHOD__ |
144 | 144 | ); |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | if ($redirect->siteId) { |
152 | 152 | $site = $sites->getSiteById($redirect->siteId); |
153 | 153 | if ($site) { |
154 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
154 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | if ($siteId) { |
158 | 158 | $site = $sites->getSiteById($siteId); |
159 | 159 | if ($site) { |
160 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
160 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | $pluginName = Retour::$settings->pluginName; |
@@ -169,20 +169,20 @@ discard block |
||
169 | 169 | } catch (InvalidConfigException $e) { |
170 | 170 | Craft::error($e->getMessage(), __METHOD__); |
171 | 171 | } |
172 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
172 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
173 | 173 | '@nystudio107/retour/web/assets/dist', |
174 | 174 | true |
175 | 175 | ); |
176 | 176 | // Sites menu |
177 | 177 | MultiSiteHelper::setSitesMenuVariables($variables); |
178 | - $variables['controllerHandle'] = 'redirects'; |
|
178 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
179 | 179 | |
180 | 180 | // Basic variables |
181 | - $variables['fullPageForm'] = true; |
|
182 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
183 | - $variables['pluginName'] = $pluginName; |
|
184 | - $variables['title'] = $templateTitle; |
|
185 | - $variables['crumbs'] = [ |
|
181 | + $variables[ 'fullPageForm' ] = true; |
|
182 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
183 | + $variables[ 'pluginName' ] = $pluginName; |
|
184 | + $variables[ 'title' ] = $templateTitle; |
|
185 | + $variables[ 'crumbs' ] = [ |
|
186 | 186 | [ |
187 | 187 | 'label' => $pluginName, |
188 | 188 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | ], |
194 | 194 | [ |
195 | 195 | 'label' => $templateTitle, |
196 | - 'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId), |
|
196 | + 'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId), |
|
197 | 197 | ], |
198 | 198 | ]; |
199 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
200 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
201 | - $variables['redirect'] = $redirect; |
|
199 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
200 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
201 | + $variables[ 'redirect' ] = $redirect; |
|
202 | 202 | |
203 | 203 | // Render the template |
204 | 204 | return $this->renderTemplate('retour/redirects/_edit', $variables); |
@@ -251,17 +251,17 @@ discard block |
||
251 | 251 | if ($redirectConfig === null) { |
252 | 252 | throw new NotFoundHttpException('Redirect not found'); |
253 | 253 | } |
254 | - $redirectConfig['id'] = (int)$redirectConfig['id']; |
|
254 | + $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ]; |
|
255 | 255 | // Handle enforcing trailing slashes |
256 | 256 | $generalConfig = Craft::$app->getConfig()->getGeneral(); |
257 | - if ($generalConfig->addTrailingSlashesToUrls && $redirectConfig['redirectMatchType'] === 'exactmatch') { |
|
258 | - $destUrl = $redirectConfig['redirectDestUrl'] ?? ''; |
|
259 | - $redirectConfig['redirectDestUrl'] = $this->addSlashToSiteUrls($destUrl); |
|
257 | + if ($generalConfig->addTrailingSlashesToUrls && $redirectConfig[ 'redirectMatchType' ] === 'exactmatch') { |
|
258 | + $destUrl = $redirectConfig[ 'redirectDestUrl' ] ?? ''; |
|
259 | + $redirectConfig[ 'redirectDestUrl' ] = $this->addSlashToSiteUrls($destUrl); |
|
260 | 260 | } |
261 | 261 | // Handle URL encoded URLs by decoding them before saving them |
262 | - if ($redirectConfig['redirectMatchType'] === 'exactmatch') { |
|
263 | - $redirectConfig['redirectSrcUrl'] = urldecode($redirectConfig['redirectSrcUrl'] ?? ''); |
|
264 | - $redirectConfig['redirectSrcUrlParsed'] = urldecode($redirectConfig['redirectSrcUrlParsed'] ?? ''); |
|
262 | + if ($redirectConfig[ 'redirectMatchType' ] === 'exactmatch') { |
|
263 | + $redirectConfig[ 'redirectSrcUrl' ] = urldecode($redirectConfig[ 'redirectSrcUrl' ] ?? ''); |
|
264 | + $redirectConfig[ 'redirectSrcUrlParsed' ] = urldecode($redirectConfig[ 'redirectSrcUrlParsed' ] ?? ''); |
|
265 | 265 | } |
266 | 266 | $redirect = new StaticRedirectsModel($redirectConfig); |
267 | 267 | // Make sure the redirect validates |
@@ -279,8 +279,8 @@ discard block |
||
279 | 279 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
280 | 280 | // Handle the case where the redirect wasn't saved because it'd create a redirect loop |
281 | 281 | $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl( |
282 | - $redirectConfig['redirectSrcUrl'], |
|
283 | - $redirectConfig['siteId'] |
|
282 | + $redirectConfig[ 'redirectSrcUrl' ], |
|
283 | + $redirectConfig[ 'siteId' ] |
|
284 | 284 | ); |
285 | 285 | if ($testRedirectConfig === null) { |
286 | 286 | Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop.")); |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | // Protected Properties |
80 | 80 | // ========================================================================= |
81 | 81 | |
82 | - protected $allowAnonymous = []; |
|
82 | + protected $allowAnonymous = [ ]; |
|
83 | 83 | |
84 | 84 | // Public Methods |
85 | 85 | // ========================================================================= |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function actionImportCsv(string $siteHandle = null): Response |
158 | 158 | { |
159 | - $variables = []; |
|
159 | + $variables = [ ]; |
|
160 | 160 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
161 | 161 | // If your CSV document was created or is read on a Macintosh computer, |
162 | 162 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -174,38 +174,38 @@ discard block |
||
174 | 174 | } catch (InvalidConfigException $e) { |
175 | 175 | Craft::error($e->getMessage(), __METHOD__); |
176 | 176 | } |
177 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
177 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
178 | 178 | '@nystudio107/retour/web/assets/dist', |
179 | 179 | true |
180 | 180 | ); |
181 | 181 | // Enabled sites |
182 | 182 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
183 | - $variables['controllerHandle'] = 'file'; |
|
183 | + $variables[ 'controllerHandle' ] = 'file'; |
|
184 | 184 | |
185 | 185 | // Basic variables |
186 | - $variables['fullPageForm'] = true; |
|
187 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
188 | - $variables['pluginName'] = $pluginName; |
|
189 | - $variables['title'] = $templateTitle; |
|
190 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
191 | - $variables['crumbs'] = [ |
|
186 | + $variables[ 'fullPageForm' ] = true; |
|
187 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
188 | + $variables[ 'pluginName' ] = $pluginName; |
|
189 | + $variables[ 'title' ] = $templateTitle; |
|
190 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
191 | + $variables[ 'crumbs' ] = [ |
|
192 | 192 | [ |
193 | 193 | 'label' => $pluginName, |
194 | 194 | 'url' => UrlHelper::cpUrl('retour'), |
195 | 195 | ], |
196 | 196 | [ |
197 | 197 | 'label' => 'Redirects', |
198 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
198 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
199 | 199 | ], |
200 | 200 | ]; |
201 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
202 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
201 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
202 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
203 | 203 | |
204 | 204 | // The CSV file |
205 | 205 | $file = UploadedFile::getInstanceByName('file'); |
206 | 206 | if ($file !== null) { |
207 | 207 | $filename = uniqid($file->name, true); |
208 | - $filePath = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.$filename; |
|
208 | + $filePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . $filename; |
|
209 | 209 | $file->saveAs($filePath, false); |
210 | 210 | // Also save the file to the cache as a backup way to access it |
211 | 211 | $cache = Craft::$app->getCache(); |
@@ -226,8 +226,8 @@ discard block |
||
226 | 226 | } |
227 | 227 | $headers = $csv->fetchOne(0); |
228 | 228 | Craft::info(print_r($headers, true), __METHOD__); |
229 | - $variables['headers'] = $headers; |
|
230 | - $variables['filename'] = $filePath; |
|
229 | + $variables[ 'headers' ] = $headers; |
|
230 | + $variables[ 'filename' ] = $filePath; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Render the template |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | // Query the db table |
275 | 275 | $data = (new Query()) |
276 | - ->from([$table]) |
|
276 | + ->from([ $table ]) |
|
277 | 277 | ->select(array_keys($columns)) |
278 | 278 | ->orderBy('hitCount DESC') |
279 | 279 | ->all(); |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | } |
287 | 287 | $csv->insertOne(array_values($columns)); |
288 | 288 | $csv->insertAll($data); |
289 | - $csv->output($filename.'.csv'); |
|
289 | + $csv->output($filename . '.csv'); |
|
290 | 290 | exit(0); |
291 | 291 | } |
292 | 292 | |
@@ -299,16 +299,16 @@ discard block |
||
299 | 299 | { |
300 | 300 | $csv->setOffset(1); |
301 | 301 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
302 | - $csv->each(function ($row) use ($headers, $columns) { |
|
302 | + $csv->each(function($row) use ($headers, $columns) { |
|
303 | 303 | $redirectConfig = [ |
304 | 304 | 'id' => 0, |
305 | 305 | ]; |
306 | 306 | $index = 0; |
307 | 307 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
308 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
309 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
308 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
309 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
310 | 310 | ? null |
311 | - : $row[$headers[$columns[$index]]]; |
|
311 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
312 | 312 | } |
313 | 313 | $index++; |
314 | 314 | } |
@@ -338,10 +338,10 @@ discard block |
||
338 | 338 | ]; |
339 | 339 | $index = 0; |
340 | 340 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
341 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
342 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
341 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
342 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
343 | 343 | ? null |
344 | - : $row[$headers[$columns[$index]]]; |
|
344 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
345 | 345 | } |
346 | 346 | $index++; |
347 | 347 | } |