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\variables; |
12
|
|
|
|
13
|
|
|
use craft\base\ElementInterface; |
|
|
|
|
14
|
|
|
use nystudio107\routemap\RouteMap; |
15
|
|
|
|
16
|
|
|
/** |
|
|
|
|
17
|
|
|
* @author nystudio107 |
|
|
|
|
18
|
|
|
* @package RouteMap |
|
|
|
|
19
|
|
|
* @since 1.0.0 |
|
|
|
|
20
|
|
|
*/ |
|
|
|
|
21
|
|
|
class RouteMapVariable |
22
|
|
|
{ |
23
|
|
|
// Public Methods |
24
|
|
|
// ========================================================================= |
25
|
|
|
/** |
26
|
|
|
* Return the public URLs for all elements that have URLs |
27
|
|
|
* |
28
|
|
|
* @param array $criteria |
|
|
|
|
29
|
|
|
* @param ?int $siteId |
|
|
|
|
30
|
|
|
* @return array |
|
|
|
|
31
|
|
|
*/ |
32
|
|
|
public function getAllUrls(array $criteria = [], ?int $siteId = null): array |
33
|
|
|
{ |
34
|
|
|
return RouteMap::$plugin->routes->getAllUrls($criteria, $siteId); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Return all the section and category route rules |
39
|
|
|
* |
40
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
41
|
|
|
* @param ?int $siteId |
|
|
|
|
42
|
|
|
* @return array |
|
|
|
|
43
|
|
|
*/ |
44
|
|
|
public function getAllRouteRules(string $format = 'Craft', ?int $siteId = null): array |
45
|
|
|
{ |
46
|
|
|
return RouteMap::$plugin->routes->getAllRouteRules($format, $siteId); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Return the public URLs for a section |
52
|
|
|
* |
53
|
|
|
* @param string $section |
|
|
|
|
54
|
|
|
* @param array $criteria |
|
|
|
|
55
|
|
|
* @param ?int $siteId |
|
|
|
|
56
|
|
|
* @return array |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function getSectionUrls(string $section, array $criteria = [], ?int $siteId = null): array |
59
|
|
|
{ |
60
|
|
|
return RouteMap::$plugin->routes->getSectionUrls($section, $criteria, $siteId); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Return all the section route rules |
66
|
|
|
* |
67
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
68
|
|
|
* @param ?int $siteId |
|
|
|
|
69
|
|
|
* @return array |
|
|
|
|
70
|
|
|
*/ |
71
|
|
|
public function getAllSectionRouteRules(string $format = 'Craft', ?int $siteId = null): array |
72
|
|
|
{ |
73
|
|
|
return RouteMap::$plugin->routes->getAllSectionRouteRules($format, $siteId); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Return the route rules for a specific section |
78
|
|
|
* |
79
|
|
|
* @param string $section |
|
|
|
|
80
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
81
|
|
|
* @param ?int $siteId |
|
|
|
|
82
|
|
|
* @return array |
|
|
|
|
83
|
|
|
*/ |
84
|
|
|
public function getSectionRouteRules(string $section, string $format = 'Craft', ?int $siteId = null): array |
85
|
|
|
{ |
86
|
|
|
return RouteMap::$plugin->routes->getSectionRouteRules($section, $format, $siteId); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Return the public URLs for a category group |
91
|
|
|
* |
92
|
|
|
* @param string $category |
|
|
|
|
93
|
|
|
* @param array $criteria |
|
|
|
|
94
|
|
|
* @param ?int $siteId |
|
|
|
|
95
|
|
|
* @return array |
|
|
|
|
96
|
|
|
*/ |
97
|
|
|
public function getCategoryUrls(string $category, array $criteria = [], ?int $siteId = null): array |
98
|
|
|
{ |
99
|
|
|
return RouteMap::$plugin->routes->getCategoryUrls($category, $criteria, $siteId); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return all the cateogry group route rules |
104
|
|
|
* |
105
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
106
|
|
|
* @param ?int $siteId |
|
|
|
|
107
|
|
|
* @return array |
|
|
|
|
108
|
|
|
*/ |
109
|
|
|
public function getAllCategoryRouteRules(string $format = 'Craft', ?int $siteId = null): array |
110
|
|
|
{ |
111
|
|
|
return RouteMap::$plugin->routes->getAllCategoryRouteRules($format, $siteId); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return the route rules for a specific category |
116
|
|
|
* |
117
|
|
|
* @param string $category |
|
|
|
|
118
|
|
|
* @param string $format 'Craft'|'React'|'Vue' |
|
|
|
|
119
|
|
|
* @param ?int $siteId |
|
|
|
|
120
|
|
|
* @return array |
|
|
|
|
121
|
|
|
*/ |
122
|
|
|
public function getCategoryRouteRules(string $category, string $format = 'Craft', ?int $siteId = null): array |
123
|
|
|
{ |
124
|
|
|
return RouteMap::$plugin->routes->getCategoryRouteRules($category, $format, $siteId); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Get all the assets of the type $assetTypes that are used in the Entry |
130
|
|
|
* that matches the $url |
131
|
|
|
* |
132
|
|
|
* @param string $url |
|
|
|
|
133
|
|
|
* @param array $assetTypes |
|
|
|
|
134
|
|
|
* @param ?int $siteId |
|
|
|
|
135
|
|
|
* @return array |
|
|
|
|
136
|
|
|
*/ |
137
|
|
|
public function getUrlAssetUrls(string $url, array $assetTypes = ['image'], ?int $siteId = null): array |
138
|
|
|
{ |
139
|
|
|
return RouteMap::$plugin->routes->getUrlAssetUrls($url, $assetTypes, $siteId); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Returns all the URLs for the given $elementType based on the passed in |
144
|
|
|
* $criteria and $siteId |
145
|
|
|
* |
146
|
|
|
* @param string|ElementInterface $elementType |
|
|
|
|
147
|
|
|
* @param array $criteria |
|
|
|
|
148
|
|
|
* @param ?int $siteId |
|
|
|
|
149
|
|
|
* @return array |
|
|
|
|
150
|
|
|
*/ |
151
|
|
|
public function getElementUrls(string|ElementInterface $elementType, array $criteria = [], ?int $siteId = null): array |
152
|
|
|
{ |
153
|
|
|
return RouteMap::$plugin->routes->getElementUrls($elementType, $criteria, $siteId); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get all routes rules defined in the config/routes.php file and CMS |
158
|
|
|
* |
159
|
|
|
* @param bool $incGlobalRules - merge global routes with the site rules |
|
|
|
|
160
|
|
|
* @param ?int $siteId |
|
|
|
|
161
|
|
|
* @return array |
|
|
|
|
162
|
|
|
*/ |
163
|
|
|
public function getRouteRules(?int $siteId = null, bool $incGlobalRules = true): array |
164
|
|
|
{ |
165
|
|
|
return RouteMap::$plugin->routes->getRouteRules($siteId, $incGlobalRules); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|