1 | <?php |
||
2 | /** |
||
3 | * Retour plugin for Craft CMS 3.x |
||
4 | * |
||
5 | * Retour allows you to intelligently redirect legacy URLs, so that you don't |
||
6 | * lose SEO value when rebuilding & restructuring a website |
||
7 | * |
||
8 | * @link https://nystudio107.com/ |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
9 | * @copyright Copyright (c) 2018 nystudio107 |
||
0 ignored issues
–
show
|
|||
10 | */ |
||
0 ignored issues
–
show
|
|||
11 | |||
12 | namespace nystudio107\retour\controllers; |
||
13 | |||
14 | use nystudio107\retour\Retour; |
||
15 | use craft\web\Controller; |
||
16 | |||
17 | /** |
||
0 ignored issues
–
show
|
|||
18 | * @author nystudio107 |
||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
|
|||
19 | * @package Retour |
||
0 ignored issues
–
show
|
|||
20 | * @since 3.1.39 |
||
0 ignored issues
–
show
|
|||
21 | */ |
||
0 ignored issues
–
show
|
|||
22 | class ApiController extends Controller |
||
23 | { |
||
24 | // Constants |
||
25 | // ========================================================================= |
||
26 | |||
27 | // Protected Properties |
||
28 | // ========================================================================= |
||
29 | |||
30 | /** |
||
0 ignored issues
–
show
|
|||
31 | * @inheritdoc |
||
32 | */ |
||
33 | protected $allowAnonymous = [ |
||
34 | 'get-redirects', |
||
35 | ]; |
||
36 | |||
37 | // Public Methods |
||
38 | // ========================================================================= |
||
39 | |||
40 | /** |
||
0 ignored issues
–
show
|
|||
41 | * @inheritDoc |
||
42 | */ |
||
0 ignored issues
–
show
|
|||
43 | public function beforeAction($action) |
||
44 | { |
||
45 | if (!Retour::$settings->enableApiEndpoint) { |
||
46 | $this->allowAnonymous = false; |
||
47 | } |
||
48 | |||
49 | return parent::beforeAction($action); |
||
50 | } |
||
51 | |||
52 | /** |
||
0 ignored issues
–
show
|
|||
53 | * @param null $siteId |
||
0 ignored issues
–
show
|
|||
54 | * @return \yii\web\Response |
||
0 ignored issues
–
show
|
|||
55 | */ |
||
56 | public function actionGetRedirects($siteId = null) |
||
57 | { |
||
58 | $redirects = Retour::$plugin->redirects->getAllStaticRedirects(null, $siteId); |
||
59 | |||
60 | return $this->asJson($redirects ?? []); |
||
61 | } |
||
62 | } |
||
63 |