1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Route Map plugin for Craft CMS |
4
|
|
|
* |
5
|
|
|
* Returns a list of public routes for elements with URLs |
6
|
|
|
* |
7
|
|
|
* @link https://nystudio107.com/ |
|
|
|
|
8
|
|
|
* @copyright Copyright (c) 2017 nystudio107 |
|
|
|
|
9
|
|
|
*/ |
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace nystudio107\routemap\controllers; |
12
|
|
|
|
13
|
|
|
use craft\base\ElementInterface; |
|
|
|
|
14
|
|
|
use craft\web\Controller; |
15
|
|
|
use nystudio107\routemap\RouteMap; |
16
|
|
|
use yii\web\Response; |
17
|
|
|
|
18
|
|
|
/** |
|
|
|
|
19
|
|
|
* @author nystudio107 |
|
|
|
|
20
|
|
|
* @package RouteMap |
|
|
|
|
21
|
|
|
* @since 1.0.0 |
|
|
|
|
22
|
|
|
*/ |
|
|
|
|
23
|
|
|
class RoutesController extends Controller |
24
|
|
|
{ |
25
|
|
|
// Protected Properties |
26
|
|
|
// ========================================================================= |
27
|
|
|
|
28
|
|
|
protected array|bool|int $allowAnonymous = [ |
29
|
|
|
'get-all-urls', |
30
|
|
|
'get-section-urls', |
31
|
|
|
'get-all-route-rules', |
32
|
|
|
'get-section-route-rules', |
33
|
|
|
'get-url-asset-urls', |
34
|
|
|
'get-element-urls', |
35
|
|
|
]; |
36
|
|
|
|
37
|
|
|
// Public Methods |
38
|
|
|
// ========================================================================= |
39
|
|
|
/** |
|
|
|
|
40
|
|
|
* Return the public URLs for all elements that have URLs |
41
|
|
|
*/ |
|
|
|
|
42
|
|
|
public function actionGetAllUrls(array $criteria = [], ?int $siteId = null): Response |
43
|
|
|
{ |
44
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getAllUrls($criteria, $siteId)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
|
|
|
|
48
|
|
|
* Return the public URLs for a section |
49
|
|
|
*/ |
|
|
|
|
50
|
|
|
public function actionGetSectionUrls(string $section, array $criteria = [], ?int $siteId = null): Response |
51
|
|
|
{ |
52
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getSectionUrls($section, $criteria, $siteId)); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
|
|
|
|
56
|
|
|
* Return the public URLs for a category |
57
|
|
|
*/ |
|
|
|
|
58
|
|
|
public function actionGetCategoryUrls(string $category, array $criteria = [], ?int $siteId = null): Response |
59
|
|
|
{ |
60
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getCategoryUrls($category, $criteria, $siteId)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Return all the section route rules |
65
|
|
|
* |
66
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
67
|
|
|
* @param ?int $siteId |
|
|
|
|
68
|
|
|
* @return Response |
|
|
|
|
69
|
|
|
*/ |
70
|
|
|
public function actionGetAllRouteRules(string $format = 'Craft', ?int $siteId = null): Response |
71
|
|
|
{ |
72
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getAllRouteRules($format, $siteId)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Return the route rules for a specific section |
77
|
|
|
* |
78
|
|
|
* @param string $section |
|
|
|
|
79
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
80
|
|
|
* @param ?int $siteId |
|
|
|
|
81
|
|
|
* @return Response |
|
|
|
|
82
|
|
|
*/ |
83
|
|
|
public function actionGetSectionRouteRules(string $section, string $format = 'Craft', ?int $siteId = null): Response |
84
|
|
|
{ |
85
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getSectionRouteRules($section, $format, $siteId)); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return the route rules for a specific category |
90
|
|
|
* |
91
|
|
|
* @param string $category |
|
|
|
|
92
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
93
|
|
|
* @param ?int $siteId |
|
|
|
|
94
|
|
|
* @return Response |
|
|
|
|
95
|
|
|
*/ |
96
|
|
|
public function actionGetCategoryRouteRules(string $category, string $format = 'Craft', ?int $siteId = null): Response |
97
|
|
|
{ |
98
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getCategoryRouteRules($category, $format, $siteId)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Return the Craft Control Panel and `routes.php` rules |
103
|
|
|
* |
104
|
|
|
* @param ?int $siteId |
|
|
|
|
105
|
|
|
* @param bool $includeGlobal |
|
|
|
|
106
|
|
|
* @return Response |
|
|
|
|
107
|
|
|
*/ |
108
|
|
|
public function actionGetRouteRules(?int $siteId = null, bool $includeGlobal = true): Response |
109
|
|
|
{ |
110
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getRouteRules($siteId, $includeGlobal)); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Get all the assets of the type $assetTypes that are used in the Entry |
115
|
|
|
* that matches the $url |
116
|
|
|
* |
117
|
|
|
* @param string $url |
|
|
|
|
118
|
|
|
* @param array $assetTypes |
|
|
|
|
119
|
|
|
* @param ?int $siteId |
|
|
|
|
120
|
|
|
* @return Response |
|
|
|
|
121
|
|
|
*/ |
122
|
|
|
public function actionGetUrlAssetUrls(string $url, array $assetTypes = ['image'], ?int $siteId = null): Response |
123
|
|
|
{ |
124
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getUrlAssetUrls($url, $assetTypes, $siteId)); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Returns all of the URLs for the given $elementType based on the passed in |
129
|
|
|
* $criteria and $siteId |
130
|
|
|
* |
131
|
|
|
* @param string|ElementInterface $elementType |
|
|
|
|
132
|
|
|
* @param array $criteria |
|
|
|
|
133
|
|
|
* @param ?int $siteId |
|
|
|
|
134
|
|
|
* @return Response |
|
|
|
|
135
|
|
|
*/ |
136
|
|
|
public function actionGetElementUrls(string|ElementInterface $elementType, array $criteria = [], ?int $siteId = null): Response |
137
|
|
|
{ |
138
|
|
|
return $this->asJson(RouteMap::$plugin->routes->getElementUrls($elementType, $criteria, $siteId)); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|