@@ -96,18 +96,18 @@ discard block |
||
96 | 96 | public function rules() |
97 | 97 | { |
98 | 98 | return [ |
99 | - ['id', 'integer'], |
|
100 | - ['siteId', 'integer'], |
|
101 | - ['siteId', 'default', 'value' => null], |
|
102 | - ['associatedElementId', 'default', 'value' => 0], |
|
103 | - ['associatedElementId', 'integer'], |
|
104 | - ['enabled', 'boolean'], |
|
105 | - ['redirectSrcMatch', 'default', 'value' => 'pathonly'], |
|
106 | - ['redirectSrcMatch', DbStringValidator::class, 'max' => 32], |
|
107 | - ['redirectSrcMatch', 'string'], |
|
108 | - ['redirectMatchType', 'default', 'value' => 'exactmatch'], |
|
109 | - ['redirectMatchType', DbStringValidator::class, 'max' => 32], |
|
110 | - ['redirectMatchType', 'string'], |
|
99 | + [ 'id', 'integer' ], |
|
100 | + [ 'siteId', 'integer' ], |
|
101 | + [ 'siteId', 'default', 'value' => null ], |
|
102 | + [ 'associatedElementId', 'default', 'value' => 0 ], |
|
103 | + [ 'associatedElementId', 'integer' ], |
|
104 | + [ 'enabled', 'boolean' ], |
|
105 | + [ 'redirectSrcMatch', 'default', 'value' => 'pathonly' ], |
|
106 | + [ 'redirectSrcMatch', DbStringValidator::class, 'max' => 32 ], |
|
107 | + [ 'redirectSrcMatch', 'string' ], |
|
108 | + [ 'redirectMatchType', 'default', 'value' => 'exactmatch' ], |
|
109 | + [ 'redirectMatchType', DbStringValidator::class, 'max' => 32 ], |
|
110 | + [ 'redirectMatchType', 'string' ], |
|
111 | 111 | [ |
112 | 112 | [ |
113 | 113 | 'redirectSrcUrl', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'default', |
118 | 118 | 'value' => '' |
119 | 119 | ], |
120 | - ['redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl'], |
|
120 | + [ 'redirectSrcUrlParsed', ParsedUriValidator::class, 'source' => 'redirectSrcUrl' ], |
|
121 | 121 | [ |
122 | 122 | [ |
123 | 123 | 'redirectSrcUrl', |
@@ -144,11 +144,11 @@ discard block |
||
144 | 144 | ], |
145 | 145 | 'string' |
146 | 146 | ], |
147 | - ['redirectHttpCode', 'integer'], |
|
148 | - ['redirectHttpCode', 'default', 'value' => 301], |
|
149 | - ['hitCount', 'default', 'value' => 0], |
|
150 | - ['hitCount', 'integer'], |
|
151 | - ['hitLastTime', 'safe'], |
|
147 | + [ 'redirectHttpCode', 'integer' ], |
|
148 | + [ 'redirectHttpCode', 'default', 'value' => 301 ], |
|
149 | + [ 'hitCount', 'default', 'value' => 0 ], |
|
150 | + [ 'hitCount', 'integer' ], |
|
151 | + [ 'hitLastTime', 'safe' ], |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | public function actionDashboard(string $range = 'day', int $siteId = 0): Response |
56 | 56 | { |
57 | 57 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
58 | - $data = []; |
|
58 | + $data = [ ]; |
|
59 | 59 | $days = 1; |
60 | 60 | switch ($range) { |
61 | 61 | case 'day': |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | 'COUNT(handledByRetour = 1 or null) as handled_cnt', |
82 | 82 | ]) |
83 | 83 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )"); |
84 | - if ((int)$siteId !== 0) { |
|
85 | - $query->andWhere(['siteId' => $siteId]); |
|
84 | + if ((int) $siteId !== 0) { |
|
85 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
86 | 86 | } |
87 | 87 | $query |
88 | 88 | ->orderBy('date_formatted ASC') |
@@ -99,8 +99,8 @@ discard block |
||
99 | 99 | "COUNT(CASE WHEN \"handledByRetour\" = true THEN 1 END) as handled_cnt", |
100 | 100 | ]) |
101 | 101 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )"); |
102 | - if ((int)$siteId !== 0) { |
|
103 | - $query->andWhere(['siteId' => $siteId]); |
|
102 | + if ((int) $siteId !== 0) { |
|
103 | + $query->andWhere([ 'siteId' => $siteId ]); |
|
104 | 104 | } |
105 | 105 | $query |
106 | 106 | ->orderBy('date_formatted ASC') |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | $stats = $query->all(); |
109 | 109 | } |
110 | 110 | if ($stats) { |
111 | - $data[] = [ |
|
111 | + $data[ ] = [ |
|
112 | 112 | 'name' => '404 hits', |
113 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'cnt')), |
|
114 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
113 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'cnt')), |
|
114 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
115 | 115 | ]; |
116 | - $data[] = [ |
|
116 | + $data[ ] = [ |
|
117 | 117 | 'name' => 'Handled 404 hits', |
118 | - 'data' => array_merge(['0'], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
119 | - 'labels' => array_merge(['-'], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
118 | + 'data' => array_merge([ '0' ], ArrayHelper::getColumn($stats, 'handled_cnt')), |
|
119 | + 'labels' => array_merge([ '-' ], ArrayHelper::getColumn($stats, 'date_formatted')), |
|
120 | 120 | ]; |
121 | 121 | } |
122 | 122 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function actionWidget($days = 1): Response |
134 | 134 | { |
135 | - $data = []; |
|
135 | + $data = [ ]; |
|
136 | 136 | // Different dbs do it different ways |
137 | 137 | $stats = null; |
138 | 138 | $handledStats = null; |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | } |
164 | 164 | if ($stats) { |
165 | 165 | $data = [ |
166 | - (int)$stats, |
|
167 | - (int)$handledStats, |
|
166 | + (int) $stats, |
|
167 | + (int) $handledStats, |
|
168 | 168 | ]; |
169 | 169 | } |
170 | 170 |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | // Protected Properties |
74 | 74 | // ========================================================================= |
75 | 75 | |
76 | - protected $allowAnonymous = []; |
|
76 | + protected $allowAnonymous = [ ]; |
|
77 | 77 | |
78 | 78 | // Public Methods |
79 | 79 | // ========================================================================= |
@@ -98,20 +98,20 @@ discard block |
||
98 | 98 | $headers = array_flip($csv->fetchOne(0)); |
99 | 99 | $csv->setOffset(1); |
100 | 100 | $columns = ArrayHelper::filterEmptyStringsFromArray($columns); |
101 | - $csv->each(function ($row) use ($headers, $columns) { |
|
101 | + $csv->each(function($row) use ($headers, $columns) { |
|
102 | 102 | $redirectConfig = [ |
103 | 103 | 'id' => 0, |
104 | 104 | ]; |
105 | 105 | $index = 0; |
106 | 106 | foreach (self::IMPORT_REDIRECTS_CSV_FIELDS as $importField) { |
107 | - if (isset($columns[$index], $headers[$columns[$index]])) { |
|
108 | - $redirectConfig[$importField] = empty($row[$headers[$columns[$index]]]) |
|
107 | + if (isset($columns[ $index ], $headers[ $columns[ $index ] ])) { |
|
108 | + $redirectConfig[ $importField ] = empty($row[ $headers[ $columns[ $index ] ] ]) |
|
109 | 109 | ? null |
110 | - : $row[$headers[$columns[$index]]]; |
|
110 | + : $row[ $headers[ $columns[ $index ] ] ]; |
|
111 | 111 | } |
112 | 112 | $index++; |
113 | 113 | } |
114 | - Craft::debug('Importing row: '.print_r($redirectConfig, true), __METHOD__); |
|
114 | + Craft::debug('Importing row: ' . print_r($redirectConfig, true), __METHOD__); |
|
115 | 115 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
116 | 116 | |
117 | 117 | return true; |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function actionImportCsv(string $siteHandle = null): Response |
135 | 135 | { |
136 | - $variables = []; |
|
136 | + $variables = [ ]; |
|
137 | 137 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
138 | 138 | // If your CSV document was created or is read on a Macintosh computer, |
139 | 139 | // add the following lines before using the library to help PHP detect line ending in Mac OS X |
@@ -151,43 +151,43 @@ discard block |
||
151 | 151 | } catch (InvalidConfigException $e) { |
152 | 152 | Craft::error($e->getMessage(), __METHOD__); |
153 | 153 | } |
154 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
154 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
155 | 155 | '@nystudio107/retour/assetbundles/retour/dist', |
156 | 156 | true |
157 | 157 | ); |
158 | 158 | // Enabled sites |
159 | 159 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
160 | - $variables['controllerHandle'] = 'file'; |
|
160 | + $variables[ 'controllerHandle' ] = 'file'; |
|
161 | 161 | |
162 | 162 | // Basic variables |
163 | - $variables['fullPageForm'] = true; |
|
164 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
165 | - $variables['pluginName'] = $pluginName; |
|
166 | - $variables['title'] = $templateTitle; |
|
167 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
168 | - $variables['crumbs'] = [ |
|
163 | + $variables[ 'fullPageForm' ] = true; |
|
164 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
165 | + $variables[ 'pluginName' ] = $pluginName; |
|
166 | + $variables[ 'title' ] = $templateTitle; |
|
167 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
168 | + $variables[ 'crumbs' ] = [ |
|
169 | 169 | [ |
170 | 170 | 'label' => $pluginName, |
171 | 171 | 'url' => UrlHelper::cpUrl('retour'), |
172 | 172 | ], |
173 | 173 | [ |
174 | 174 | 'label' => 'Redirects', |
175 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
175 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
176 | 176 | ], |
177 | 177 | ]; |
178 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
179 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
178 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
179 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
180 | 180 | |
181 | 181 | // The CSV file |
182 | 182 | $file = UploadedFile::getInstanceByName('file'); |
183 | 183 | if ($file !== null) { |
184 | - $filename = Craft::$app->getPath()->getTempPath().DIRECTORY_SEPARATOR.uniqid($file->name, true); |
|
184 | + $filename = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . uniqid($file->name, true); |
|
185 | 185 | $file->saveAs($filename, false); |
186 | 186 | $csv = Reader::createFromPath($file->tempName); |
187 | 187 | $headers = $csv->fetchOne(0); |
188 | 188 | Craft::info(print_r($headers, true), __METHOD__); |
189 | - $variables['headers'] = $headers; |
|
190 | - $variables['filename'] = $filename; |
|
189 | + $variables[ 'headers' ] = $headers; |
|
190 | + $variables[ 'filename' ] = $filename; |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // Render the template |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | } |
234 | 234 | // Query the db table |
235 | 235 | $data = (new Query()) |
236 | - ->from([$table]) |
|
236 | + ->from([ $table ]) |
|
237 | 237 | ->select(array_keys($columns)) |
238 | 238 | ->orderBy('hitCount DESC') |
239 | 239 | ->all(); |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $csv = Writer::createFromFileObject(new \SplTempFileObject()); |
242 | 242 | $csv->insertOne(array_values($columns)); |
243 | 243 | $csv->insertAll($data); |
244 | - $csv->output($filename.'.csv'); |
|
244 | + $csv->output($filename . '.csv'); |
|
245 | 245 | exit(0); |
246 | 246 | } |
247 | 247 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | /** |
100 | 100 | * @var array The URIs for the element before it was saved |
101 | 101 | */ |
102 | - public $oldElementUris = []; |
|
102 | + public $oldElementUris = [ ]; |
|
103 | 103 | |
104 | 104 | // Public Methods |
105 | 105 | // ========================================================================= |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | Craft::t( |
131 | 131 | 'retour', |
132 | 132 | '{name} plugin loaded', |
133 | - ['name' => $this->name] |
|
133 | + [ 'name' => $this->name ] |
|
134 | 134 | ), |
135 | 135 | __METHOD__ |
136 | 136 | ); |
@@ -150,18 +150,18 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function getCpNavItem() |
152 | 152 | { |
153 | - $subNavs = []; |
|
153 | + $subNavs = [ ]; |
|
154 | 154 | $navItem = parent::getCpNavItem(); |
155 | 155 | $currentUser = Craft::$app->getUser()->getIdentity(); |
156 | 156 | // Only show sub-navs the user has permission to view |
157 | 157 | if ($currentUser->can('retour:dashboard')) { |
158 | - $subNavs['dashboard'] = [ |
|
158 | + $subNavs[ 'dashboard' ] = [ |
|
159 | 159 | 'label' => 'Dashboard', |
160 | 160 | 'url' => 'retour/dashboard', |
161 | 161 | ]; |
162 | 162 | } |
163 | 163 | if ($currentUser->can('retour:redirects')) { |
164 | - $subNavs['redirects'] = [ |
|
164 | + $subNavs[ 'redirects' ] = [ |
|
165 | 165 | 'label' => 'Redirects', |
166 | 166 | 'url' => 'retour/redirects', |
167 | 167 | ]; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | $editableSettings = false; |
173 | 173 | } |
174 | 174 | if ($currentUser->can('retour:settings') && $editableSettings) { |
175 | - $subNavs['settings'] = [ |
|
175 | + $subNavs[ 'settings' ] = [ |
|
176 | 176 | 'label' => 'Settings', |
177 | 177 | 'url' => 'retour/settings', |
178 | 178 | ]; |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | Event::on( |
232 | 232 | ClearCaches::class, |
233 | 233 | ClearCaches::EVENT_REGISTER_CACHE_OPTIONS, |
234 | - function (RegisterCacheOptionsEvent $event) { |
|
234 | + function(RegisterCacheOptionsEvent $event) { |
|
235 | 235 | Craft::debug( |
236 | 236 | 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS', |
237 | 237 | __METHOD__ |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | Event::on( |
248 | 248 | Plugins::class, |
249 | 249 | Plugins::EVENT_AFTER_INSTALL_PLUGIN, |
250 | - function (PluginEvent $event) { |
|
250 | + function(PluginEvent $event) { |
|
251 | 251 | if ($event->plugin === $this) { |
252 | 252 | // Invalidate our caches after we've been installed |
253 | 253 | $this->clearAllCaches(); |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | Event::on( |
275 | 275 | CraftVariable::class, |
276 | 276 | CraftVariable::EVENT_INIT, |
277 | - function (Event $event) { |
|
277 | + function(Event $event) { |
|
278 | 278 | /** @var CraftVariable $variable */ |
279 | 279 | $variable = $event->sender; |
280 | 280 | $variable->set('retour', RetourVariable::class); |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | Event::on( |
285 | 285 | Elements::class, |
286 | 286 | Elements::EVENT_BEFORE_SAVE_ELEMENT, |
287 | - function (ElementEvent $event) { |
|
287 | + function(ElementEvent $event) { |
|
288 | 288 | Craft::debug( |
289 | 289 | 'Elements::EVENT_BEFORE_SAVE_ELEMENT', |
290 | 290 | __METHOD__ |
@@ -299,8 +299,8 @@ discard block |
||
299 | 299 | if ($oldElement !== null) { |
300 | 300 | // Stash the old URLs by element id, and do so only once, |
301 | 301 | // in case we are called more than once per request |
302 | - if (empty($this->oldElementUris[$oldElement->id])) { |
|
303 | - $this->oldElementUris[$oldElement->id] = $this->getAllElementUris($oldElement); |
|
302 | + if (empty($this->oldElementUris[ $oldElement->id ])) { |
|
303 | + $this->oldElementUris[ $oldElement->id ] = $this->getAllElementUris($oldElement); |
|
304 | 304 | } |
305 | 305 | } |
306 | 306 | } |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | Event::on( |
312 | 312 | Elements::class, |
313 | 313 | Elements::EVENT_AFTER_SAVE_ELEMENT, |
314 | - function (ElementEvent $event) { |
|
314 | + function(ElementEvent $event) { |
|
315 | 315 | Craft::debug( |
316 | 316 | 'Elements::EVENT_AFTER_SAVE_ELEMENT', |
317 | 317 | __METHOD__ |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | Event::on( |
328 | 328 | Plugins::class, |
329 | 329 | Plugins::EVENT_AFTER_LOAD_PLUGINS, |
330 | - function () { |
|
330 | + function() { |
|
331 | 331 | // Install these only after all other plugins have loaded |
332 | 332 | $request = Craft::$app->getRequest(); |
333 | 333 | // Only respond to non-console site requests |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | Event::on( |
352 | 352 | UrlManager::class, |
353 | 353 | UrlManager::EVENT_REGISTER_SITE_URL_RULES, |
354 | - function (RegisterUrlRulesEvent $event) { |
|
354 | + function(RegisterUrlRulesEvent $event) { |
|
355 | 355 | Craft::debug( |
356 | 356 | 'UrlManager::EVENT_REGISTER_SITE_URL_RULES', |
357 | 357 | __METHOD__ |
@@ -374,15 +374,15 @@ discard block |
||
374 | 374 | Event::on( |
375 | 375 | Dashboard::class, |
376 | 376 | Dashboard::EVENT_REGISTER_WIDGET_TYPES, |
377 | - function (RegisterComponentTypesEvent $event) { |
|
378 | - $event->types[] = RetourWidget::class; |
|
377 | + function(RegisterComponentTypesEvent $event) { |
|
378 | + $event->types[ ] = RetourWidget::class; |
|
379 | 379 | } |
380 | 380 | ); |
381 | 381 | // Handler: UrlManager::EVENT_REGISTER_CP_URL_RULES |
382 | 382 | Event::on( |
383 | 383 | UrlManager::class, |
384 | 384 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
385 | - function (RegisterUrlRulesEvent $event) { |
|
385 | + function(RegisterUrlRulesEvent $event) { |
|
386 | 386 | Craft::debug( |
387 | 387 | 'UrlManager::EVENT_REGISTER_CP_URL_RULES', |
388 | 388 | __METHOD__ |
@@ -398,13 +398,13 @@ discard block |
||
398 | 398 | Event::on( |
399 | 399 | UserPermissions::class, |
400 | 400 | UserPermissions::EVENT_REGISTER_PERMISSIONS, |
401 | - function (RegisterUserPermissionsEvent $event) { |
|
401 | + function(RegisterUserPermissionsEvent $event) { |
|
402 | 402 | Craft::debug( |
403 | 403 | 'UserPermissions::EVENT_REGISTER_PERMISSIONS', |
404 | 404 | __METHOD__ |
405 | 405 | ); |
406 | 406 | // Register our custom permissions |
407 | - $event->permissions[Craft::t('retour', 'Retour')] = $this->customAdminCpPermissions(); |
|
407 | + $event->permissions[ Craft::t('retour', 'Retour') ] = $this->customAdminCpPermissions(); |
|
408 | 408 | } |
409 | 409 | ); |
410 | 410 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | Event::on( |
421 | 421 | ErrorHandler::class, |
422 | 422 | ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION, |
423 | - function (ExceptionEvent $event) { |
|
423 | + function(ExceptionEvent $event) { |
|
424 | 424 | Craft::debug( |
425 | 425 | 'ErrorHandler::EVENT_BEFORE_HANDLE_EXCEPTION', |
426 | 426 | __METHOD__ |
@@ -463,16 +463,16 @@ discard block |
||
463 | 463 | protected function handleElementUriChange(Element $element) |
464 | 464 | { |
465 | 465 | $uris = $this->getAllElementUris($element); |
466 | - if (!empty($this->oldElementUris[$element->id])) { |
|
467 | - $oldElementUris = $this->oldElementUris[$element->id]; |
|
466 | + if (!empty($this->oldElementUris[ $element->id ])) { |
|
467 | + $oldElementUris = $this->oldElementUris[ $element->id ]; |
|
468 | 468 | foreach ($uris as $siteId => $newUri) { |
469 | - if (!empty($oldElementUris[$siteId])) { |
|
470 | - $oldUri = $oldElementUris[$siteId]; |
|
469 | + if (!empty($oldElementUris[ $siteId ])) { |
|
470 | + $oldUri = $oldElementUris[ $siteId ]; |
|
471 | 471 | Craft::debug( |
472 | 472 | Craft::t( |
473 | 473 | 'retour', |
474 | 474 | 'Comparing old: {oldUri} to new: {newUri}', |
475 | - ['oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true)] |
|
475 | + [ 'oldUri' => print_r($oldUri, true), 'newUri' => print_r($newUri, true) ] |
|
476 | 476 | ), |
477 | 477 | __METHOD__ |
478 | 478 | ); |
@@ -507,12 +507,12 @@ discard block |
||
507 | 507 | */ |
508 | 508 | protected function getAllElementUris(Element $element): array |
509 | 509 | { |
510 | - $uris = []; |
|
510 | + $uris = [ ]; |
|
511 | 511 | $sites = Craft::$app->getSites()->getAllSites(); |
512 | 512 | foreach ($sites as $site) { |
513 | 513 | $uri = Craft::$app->getElements()->getElementUriForSite($element->id, $site->id); |
514 | 514 | if ($uri !== null) { |
515 | - $uris[$site->id] = $uri; |
|
515 | + $uris[ $site->id ] = $uri; |
|
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | Craft::t( |
521 | 521 | 'retour', |
522 | 522 | 'Getting Element URIs: {uris}', |
523 | - ['uris' => print_r($uris, true)] |
|
523 | + [ 'uris' => print_r($uris, true) ] |
|
524 | 524 | ), |
525 | 525 | __METHOD__ |
526 | 526 | ); |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | [ |
585 | 585 | 'key' => 'retour-redirect-caches', |
586 | 586 | 'label' => Craft::t('retour', 'Retour redirect caches'), |
587 | - 'action' => [self::$plugin->redirects, 'invalidateCaches'], |
|
587 | + 'action' => [ self::$plugin->redirects, 'invalidateCaches' ], |
|
588 | 588 | ], |
589 | 589 | ]; |
590 | 590 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $siteId = 0 |
63 | 63 | ): Response { |
64 | 64 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
65 | - $data = []; |
|
65 | + $data = [ ]; |
|
66 | 66 | $sortField = 'hitCount'; |
67 | 67 | $sortType = 'DESC'; |
68 | 68 | // Figure out the sorting type |
@@ -76,42 +76,42 @@ discard block |
||
76 | 76 | // Query the db table |
77 | 77 | $offset = ($page - 1) * $per_page; |
78 | 78 | $query = (new Query()) |
79 | - ->from(['{{%retour_stats}}']) |
|
79 | + ->from([ '{{%retour_stats}}' ]) |
|
80 | 80 | ->offset($offset) |
81 | 81 | ->limit($per_page) |
82 | 82 | ->orderBy("{$sortField} {$sortType}"); |
83 | - if ((int)$siteId !== 0) { |
|
84 | - $query->where(['siteId' => $siteId]); |
|
83 | + if ((int) $siteId !== 0) { |
|
84 | + $query->where([ 'siteId' => $siteId ]); |
|
85 | 85 | } |
86 | 86 | if ($filter !== '') { |
87 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
88 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
87 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
88 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
89 | 89 | } |
90 | 90 | $stats = $query->all(); |
91 | 91 | if ($stats) { |
92 | 92 | // Add in the `addLink` field |
93 | 93 | foreach ($stats as &$stat) { |
94 | - $stat['addLink'] = ''; |
|
95 | - if (!$stat['handledByRetour']) { |
|
96 | - $encodedUrl = urlencode('/'.ltrim($stat['redirectSrcUrl'], '/')); |
|
97 | - $stat['addLink'] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
94 | + $stat[ 'addLink' ] = ''; |
|
95 | + if (!$stat[ 'handledByRetour' ]) { |
|
96 | + $encodedUrl = urlencode('/' . ltrim($stat[ 'redirectSrcUrl' ], '/')); |
|
97 | + $stat[ 'addLink' ] = UrlHelper::cpUrl('retour/add-redirect', [ |
|
98 | 98 | 'defaultUrl' => $encodedUrl |
99 | 99 | ]); |
100 | 100 | } |
101 | 101 | } |
102 | 102 | // Format the data for the API |
103 | - $data['data'] = $stats; |
|
103 | + $data[ 'data' ] = $stats; |
|
104 | 104 | $query = (new Query()) |
105 | - ->from(['{{%retour_stats}}']); |
|
106 | - if ((int)$siteId !== 0) { |
|
107 | - $query->where(['siteId' => $siteId]); |
|
105 | + ->from([ '{{%retour_stats}}' ]); |
|
106 | + if ((int) $siteId !== 0) { |
|
107 | + $query->where([ 'siteId' => $siteId ]); |
|
108 | 108 | } |
109 | 109 | if ($filter !== '') { |
110 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
111 | - $query->orWhere(['like', 'referrerUrl', $filter]); |
|
110 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
111 | + $query->orWhere([ 'like', 'referrerUrl', $filter ]); |
|
112 | 112 | } |
113 | 113 | $count = $query->count(); |
114 | - $data['links']['pagination'] = [ |
|
114 | + $data[ 'links' ][ 'pagination' ] = [ |
|
115 | 115 | 'total' => $count, |
116 | 116 | 'per_page' => $per_page, |
117 | 117 | 'current_page' => $page, |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | $siteId = 0 |
147 | 147 | ): Response { |
148 | 148 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
149 | - $data = []; |
|
149 | + $data = [ ]; |
|
150 | 150 | $sortField = 'hitCount'; |
151 | 151 | $sortType = 'DESC'; |
152 | 152 | // Figure out the sorting type |
@@ -160,43 +160,43 @@ discard block |
||
160 | 160 | // Query the db table |
161 | 161 | $offset = ($page - 1) * $per_page; |
162 | 162 | $query = (new Query()) |
163 | - ->from(['{{%retour_static_redirects}}']) |
|
163 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
164 | 164 | ->offset($offset) |
165 | 165 | ->limit($per_page) |
166 | 166 | ->orderBy("{$sortField} {$sortType}"); |
167 | - if ((int)$siteId !== 0) { |
|
168 | - $query->where(['siteId' => $siteId]); |
|
167 | + if ((int) $siteId !== 0) { |
|
168 | + $query->where([ 'siteId' => $siteId ]); |
|
169 | 169 | } |
170 | 170 | if ($filter !== '') { |
171 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
172 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
171 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
172 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
173 | 173 | } |
174 | 174 | $redirects = $query->all(); |
175 | 175 | // Add in the `deleteLink` field and clean up the redirects |
176 | 176 | foreach ($redirects as &$redirect) { |
177 | 177 | // Make sure the destination URL is not a regex |
178 | - if ($redirect['redirectMatchType'] !== 'exactmatch') { |
|
179 | - if (preg_match("/\$\d+/", $redirect['redirectDestUrl'])) { |
|
180 | - $redirect['redirectDestUrl'] = ''; |
|
178 | + if ($redirect[ 'redirectMatchType' ] !== 'exactmatch') { |
|
179 | + if (preg_match("/\$\d+/", $redirect[ 'redirectDestUrl' ])) { |
|
180 | + $redirect[ 'redirectDestUrl' ] = ''; |
|
181 | 181 | } |
182 | 182 | } |
183 | - $redirect['deleteLink'] = UrlHelper::cpUrl('retour/delete-redirect/'.$redirect['id']); |
|
184 | - $redirect['editLink'] = UrlHelper::cpUrl('retour/edit-redirect/'.$redirect['id']); |
|
183 | + $redirect[ 'deleteLink' ] = UrlHelper::cpUrl('retour/delete-redirect/' . $redirect[ 'id' ]); |
|
184 | + $redirect[ 'editLink' ] = UrlHelper::cpUrl('retour/edit-redirect/' . $redirect[ 'id' ]); |
|
185 | 185 | } |
186 | 186 | // Format the data for the API |
187 | 187 | if ($redirects) { |
188 | - $data['data'] = $redirects; |
|
188 | + $data[ 'data' ] = $redirects; |
|
189 | 189 | $query = (new Query()) |
190 | - ->from(['{{%retour_static_redirects}}']); |
|
191 | - if ((int)$siteId !== 0) { |
|
192 | - $query->where(['siteId' => $siteId]); |
|
190 | + ->from([ '{{%retour_static_redirects}}' ]); |
|
191 | + if ((int) $siteId !== 0) { |
|
192 | + $query->where([ 'siteId' => $siteId ]); |
|
193 | 193 | } |
194 | 194 | if ($filter !== '') { |
195 | - $query->where(['like', 'redirectSrcUrl', $filter]); |
|
196 | - $query->orWhere(['like', 'redirectDestUrl', $filter]); |
|
195 | + $query->where([ 'like', 'redirectSrcUrl', $filter ]); |
|
196 | + $query->orWhere([ 'like', 'redirectDestUrl', $filter ]); |
|
197 | 197 | } |
198 | 198 | $count = $query->count(); |
199 | - $data['links']['pagination'] = [ |
|
199 | + $data[ 'links' ][ 'pagination' ] = [ |
|
200 | 200 | 'total' => $count, |
201 | 201 | 'per_page' => $per_page, |
202 | 202 | 'current_page' => $page, |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | } |
59 | 59 | // Query the db table |
60 | 60 | $stats = (new Query()) |
61 | - ->from(['{{%retour_stats}}']) |
|
61 | + ->from([ '{{%retour_stats}}' ]) |
|
62 | 62 | ->orderBy('hitCount DESC') |
63 | 63 | ->limit(Retour::$settings->statsDisplayLimit) |
64 | 64 | ->all(); |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | public function getRecentStatistics($days = 1, $handled = false): array |
78 | 78 | { |
79 | 79 | // Ensure is an int |
80 | - $handledInt = (int)$handled; |
|
81 | - $stats = []; |
|
80 | + $handledInt = (int) $handled; |
|
81 | + $stats = [ ]; |
|
82 | 82 | $db = Craft::$app->getDb(); |
83 | 83 | if ($db->getIsMysql()) { |
84 | 84 | // Query the db table |
85 | 85 | $stats = (new Query()) |
86 | - ->from(['{{%retour_stats}}']) |
|
86 | + ->from([ '{{%retour_stats}}' ]) |
|
87 | 87 | ->where("hitLastTime >= ( CURDATE() - INTERVAL '{$days}' DAY )") |
88 | 88 | ->andWhere("handledByRetour = {$handledInt}") |
89 | 89 | ->orderBy('hitLastTime DESC') |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | if ($db->getIsPgsql()) { |
93 | 93 | // Query the db table |
94 | 94 | $stats = (new Query()) |
95 | - ->from(['{{%retour_stats}}']) |
|
95 | + ->from([ '{{%retour_stats}}' ]) |
|
96 | 96 | ->where("\"hitLastTime\" >= ( CURRENT_TIMESTAMP - INTERVAL '{$days} days' )") |
97 | - ->andWhere(['handledByRetour' => $handledInt]) |
|
97 | + ->andWhere([ 'handledByRetour' => $handledInt ]) |
|
98 | 98 | ->orderBy('hitLastTime DESC') |
99 | 99 | ->all(); |
100 | 100 | } |
@@ -161,16 +161,16 @@ discard block |
||
161 | 161 | $stats->validate(); |
162 | 162 | // Find any existing retour_stats record |
163 | 163 | $statsConfig = (new Query()) |
164 | - ->from(['{{%retour_stats}}']) |
|
165 | - ->where(['redirectSrcUrl' => $stats->redirectSrcUrl]) |
|
164 | + ->from([ '{{%retour_stats}}' ]) |
|
165 | + ->where([ 'redirectSrcUrl' => $stats->redirectSrcUrl ]) |
|
166 | 166 | ->one(); |
167 | 167 | // If no record is found, initialize some values |
168 | 168 | if ($statsConfig === null) { |
169 | 169 | $stats->id = 0; |
170 | 170 | $stats->hitCount = 0; |
171 | 171 | } else { |
172 | - $stats->id = $statsConfig['id']; |
|
173 | - $stats->hitCount = $statsConfig['hitCount']; |
|
172 | + $stats->id = $statsConfig[ 'id' ]; |
|
173 | + $stats->hitCount = $statsConfig[ 'hitCount' ]; |
|
174 | 174 | } |
175 | 175 | // Merge in the updated info |
176 | 176 | $stats->siteId = $siteId; |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | $stats->userAgent = $userAgent; |
180 | 180 | $stats->exceptionMessage = $exceptionMessage; |
181 | 181 | $stats->exceptionFilePath = $exceptionFilePath; |
182 | - $stats->exceptionFileLine = (int)$exceptionFileLine; |
|
182 | + $stats->exceptionFileLine = (int) $exceptionFileLine; |
|
183 | 183 | $stats->hitLastTime = Db::prepareDateForDb(new \DateTime()); |
184 | - $stats->handledByRetour = (int)$handled; |
|
184 | + $stats->handledByRetour = (int) $handled; |
|
185 | 185 | $stats->hitCount++; |
186 | 186 | $statsConfig = $stats->getAttributes(); |
187 | 187 | // Record the updated statistics |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | Craft::t( |
252 | 252 | 'retour', |
253 | 253 | 'Trimmed {rows} from retour_stats table', |
254 | - ['rows' => $affectedRows] |
|
254 | + [ 'rows' => $affectedRows ] |
|
255 | 255 | ), |
256 | 256 | __METHOD__ |
257 | 257 | ); |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | Craft::t( |
273 | 273 | 'retour', |
274 | 274 | 'Error validating statistics {id}: {errors}', |
275 | - ['id' => $stats->id, 'errors' => print_r($stats->getErrors(), true)] |
|
275 | + [ 'id' => $stats->id, 'errors' => print_r($stats->getErrors(), true) ] |
|
276 | 276 | ), |
277 | 277 | __METHOD__ |
278 | 278 | ); |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | // Get the validated model attributes and save them to the db |
283 | 283 | $statsConfig = $stats->getAttributes(); |
284 | 284 | $db = Craft::$app->getDb(); |
285 | - if ($statsConfig['id'] !== 0) { |
|
285 | + if ($statsConfig[ 'id' ] !== 0) { |
|
286 | 286 | // Update the existing record |
287 | 287 | try { |
288 | 288 | $result = $db->createCommand()->update( |
289 | 289 | '{{%retour_stats}}', |
290 | 290 | $statsConfig, |
291 | 291 | [ |
292 | - 'id' => $statsConfig['id'], |
|
292 | + 'id' => $statsConfig[ 'id' ], |
|
293 | 293 | ] |
294 | 294 | )->execute(); |
295 | 295 | } catch (Exception $e) { |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | // Craft::error($e->getMessage(), __METHOD__); |
299 | 299 | } |
300 | 300 | } else { |
301 | - unset($statsConfig['id']); |
|
301 | + unset($statsConfig[ 'id' ]); |
|
302 | 302 | // Create a new record |
303 | 303 | try { |
304 | 304 | $db->createCommand()->insert( |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public static function setSitesMenuVariables(array &$variables) |
37 | 37 | { |
38 | 38 | // Set defaults based on the section settings |
39 | - $variables['sitesMenu'] = [ |
|
39 | + $variables[ 'sitesMenu' ] = [ |
|
40 | 40 | 0 => Craft::t( |
41 | 41 | 'retour', |
42 | 42 | 'All Sites' |
@@ -49,11 +49,11 @@ discard block |
||
49 | 49 | /** @var Site $site */ |
50 | 50 | foreach ($sites->getAllGroups() as $group) { |
51 | 51 | $groupSites = $sites->getSitesByGroupId($group->id); |
52 | - $variables['sitesMenu'][$group->name] |
|
53 | - = ['optgroup' => $group->name]; |
|
52 | + $variables[ 'sitesMenu' ][ $group->name ] |
|
53 | + = [ 'optgroup' => $group->name ]; |
|
54 | 54 | foreach ($groupSites as $groupSite) { |
55 | 55 | if (in_array($groupSite->id, $editableSites, false)) { |
56 | - $variables['sitesMenu'][$groupSite->id] = $groupSite->name; |
|
56 | + $variables[ 'sitesMenu' ][ $groupSite->id ] = $groupSite->name; |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | } |
@@ -73,53 +73,53 @@ discard block |
||
73 | 73 | $sites = Craft::$app->getSites(); |
74 | 74 | if (Craft::$app->getIsMultiSite()) { |
75 | 75 | // Set defaults based on the section settings |
76 | - $variables['enabledSiteIds'] = []; |
|
77 | - $variables['siteIds'] = []; |
|
76 | + $variables[ 'enabledSiteIds' ] = [ ]; |
|
77 | + $variables[ 'siteIds' ] = [ ]; |
|
78 | 78 | |
79 | 79 | /** @var Site $site */ |
80 | 80 | foreach ($sites->getEditableSiteIds() as $editableSiteId) { |
81 | - $variables['enabledSiteIds'][] = $editableSiteId; |
|
82 | - $variables['siteIds'][] = $editableSiteId; |
|
81 | + $variables[ 'enabledSiteIds' ][ ] = $editableSiteId; |
|
82 | + $variables[ 'siteIds' ][ ] = $editableSiteId; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | // Make sure the $siteId they are trying to edit is in our array of editable sites |
86 | - if (!\in_array($siteId, $variables['enabledSiteIds'], false)) { |
|
87 | - if (!empty($variables['enabledSiteIds'])) { |
|
86 | + if (!\in_array($siteId, $variables[ 'enabledSiteIds' ], false)) { |
|
87 | + if (!empty($variables[ 'enabledSiteIds' ])) { |
|
88 | 88 | if ($siteId !== 0) { |
89 | - $siteId = reset($variables['enabledSiteIds']); |
|
89 | + $siteId = reset($variables[ 'enabledSiteIds' ]); |
|
90 | 90 | } |
91 | 91 | } else { |
92 | - self::requirePermission('editSite:'.$siteId); |
|
92 | + self::requirePermission('editSite:' . $siteId); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
96 | 96 | // Set the currentSiteId and currentSiteHandle |
97 | - $variables['currentSiteId'] = empty($siteId) ? 0 : $siteId; |
|
98 | - $variables['currentSiteHandle'] = empty($siteHandle) |
|
97 | + $variables[ 'currentSiteId' ] = empty($siteId) ? 0 : $siteId; |
|
98 | + $variables[ 'currentSiteHandle' ] = empty($siteHandle) |
|
99 | 99 | ? Craft::$app->getSites()->currentSite->handle |
100 | 100 | : $siteHandle; |
101 | 101 | |
102 | 102 | // Page title |
103 | - $variables['showSites'] = ( |
|
103 | + $variables[ 'showSites' ] = ( |
|
104 | 104 | Craft::$app->getIsMultiSite() && |
105 | - \count($variables['enabledSiteIds']) |
|
105 | + \count($variables[ 'enabledSiteIds' ]) |
|
106 | 106 | ); |
107 | 107 | |
108 | - if ($variables['showSites']) { |
|
109 | - if ($variables['currentSiteId'] === 0) { |
|
110 | - $variables['sitesMenuLabel'] = Craft::t( |
|
108 | + if ($variables[ 'showSites' ]) { |
|
109 | + if ($variables[ 'currentSiteId' ] === 0) { |
|
110 | + $variables[ 'sitesMenuLabel' ] = Craft::t( |
|
111 | 111 | 'retour', |
112 | 112 | 'All Sites' |
113 | 113 | ); |
114 | 114 | } else { |
115 | - $variables['sitesMenuLabel'] = Craft::t( |
|
115 | + $variables[ 'sitesMenuLabel' ] = Craft::t( |
|
116 | 116 | 'site', |
117 | - $sites->getSiteById((int)$variables['currentSiteId'])->name |
|
117 | + $sites->getSiteById((int) $variables[ 'currentSiteId' ])->name |
|
118 | 118 | ); |
119 | 119 | } |
120 | 120 | } else { |
121 | - $variables['currentSiteId'] = 0; |
|
122 | - $variables['sitesMenuLabel'] = ''; |
|
121 | + $variables[ 'currentSiteId' ] = 0; |
|
122 | + $variables[ 'sitesMenuLabel' ] = ''; |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | if ($siteHandle !== null) { |
138 | 138 | $site = Craft::$app->getSites()->getSiteByHandle($siteHandle); |
139 | 139 | if (!$site) { |
140 | - throw new NotFoundHttpException('Invalid site handle: '.$siteHandle); |
|
140 | + throw new NotFoundHttpException('Invalid site handle: ' . $siteHandle); |
|
141 | 141 | } |
142 | 142 | $siteId = $site->id; |
143 | 143 | } else { |
@@ -45,7 +45,7 @@ |
||
45 | 45 | // Whether the Statistics should be trimmed after each new statistic is recorded |
46 | 46 | 'automaticallyTrimStatistics' => true, |
47 | 47 | |
48 | - // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
48 | + // [Regular expressions](https://regexr.com/) to match URLs to exclude from tracking |
|
49 | 49 | 'excludePatterns' => [ |
50 | 50 | ], |
51 | 51 | ]; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | // Update retour widget type |
21 | 21 | $this->update('{{%widgets}}', [ |
22 | 22 | 'type' => RetourWidget::class |
23 | - ], ['type' => 'Retour']); |
|
23 | + ], [ 'type' => 'Retour' ]); |
|
24 | 24 | |
25 | 25 | return true; |
26 | 26 | } |