1 <?php
2
3 /**
4 * Utility class to generate relative URLs.
5 *
6 * @author gharlan
7 *
8 * @package redaxo\core
9 */
10 class rex_url
11 {
12 protected static $pathprovider;
13
14 /**
15 * Initializes the class.
16 *
17 * @param mixed $pathprovider A path provider
18 */
19 public static function init($pathprovider)
20 {
21 self::$pathprovider = $pathprovider;
22 }
23
24 /**
25 * Returns a base url.
26 *
27 * @param string $file File
28 *
29 * @return string
30 */
31 public static function base($file = '')
32 {
33 return self::$pathprovider->base($file);
34 }
35
36 /**
37 * Returns the url to the frontend.
38 *
39 * @param string $file File
40 *
41 * @return string
42 */
43 public static function frontend($file = '')
44 {
45 return self::$pathprovider->frontend($file);
46 }
47
48 /**
49 * Returns the url to the frontend-controller (index.php from frontend).
50 *
51 * @param array $params Params
52 * @param bool $escape Flag whether the argument separator "&" should be escaped (&)
53 *
54 * @return string
55 */
56 public static function frontendController(array $params = [], $escape = true)
57 {
58 $query = rex_string::buildQuery($params, $escape ? '&' : '&');
59 $query = $query ? '?' . $query : '';
60 return self::$pathprovider->frontendController() . $query;
61 }
62
63 /**
64 * Returns the url to the backend.
65 *
66 * @param string $file File
67 *
68 * @return string
69 */
70 public static function backend($file = '')
71 {
72 return self::$pathprovider->backend($file);
73 }
74
75 /**
76 * Returns the url to the backend-controller (index.php from backend).
77 *
78 * @param array $params Params
79 * @param bool $escape Flag whether the argument separator "&" should be escaped (&)
80 *
81 * @return string
82 */
83 public static function backendController(array $params = [], $escape = true)
84 {
85 $query = rex_string::buildQuery($params, $escape ? '&' : '&');
86 $query = $query ? '?' . $query : '';
87 return self::$pathprovider->backendController() . $query;
88 }
89
90 /**
91 * Returns the url to a backend page.
92 *
93 * @param string $page Page
94 * @param array $params Params
95 * @param bool $escape Flag whether the argument separator "&" should be escaped (&)
96 *
97 * @return string
98 */
99 public static function backendPage($page, array $params = [], $escape = true)
100 {
101 return self::backendController(array_merge(['page' => $page], $params), $escape);
102 }
103
104 /**
105 * Returns the url to the current backend page.
106 *
107 * @param array $params Params
108 * @param bool $escape Flag whether the argument separator "&" should be escaped (&)
109 *
110 * @return string
111 */
112 public static function currentBackendPage(array $params = [], $escape = true)
113 {
114 return self::backendPage(rex_be_controller::getCurrentPage(), $params, $escape);
115 }
116
117 /**
118 * Returns the url to the media-folder.
119 *
120 * @param string $file File
121 *
122 * @return string
123 */
124 public static function media($file = '')
125 {
126 return self::$pathprovider->media($file);
127 }
128
129 /**
130 * Returns the url to the assets folder.
131 *
132 * @param string $file File
133 *
134 * @return string
135 */
136 public static function assets($file = '')
137 {
138 return self::$pathprovider->assets($file);
139 }
140
141 /**
142 * Returns the url to the assets folder of the core, which contains all assets required by the core to work properly.
143 *
144 * @param string $file File
145 *
146 * @return string
147 */
148 public static function coreAssets($file = '')
149 {
150 return self::$pathprovider->coreAssets($file);
151 }
152
153 /**
154 * Returns the url to the assets folder of the given addon, which contains all assets required by the addon to work properly.
155 *
156 * @param string $addon Addon
157 * @param string $file File
158 *
159 * @return string
160 *
161 * @see assets()
162 */
163 public static function addonAssets($addon, $file = '')
164 {
165 return self::$pathprovider->addonAssets($addon, $file);
166 }
167
168 /**
169 * Returns the url to the assets folder of the given plugin of the given addon.
170 *
171 * @param string $addon Addon
172 * @param string $plugin Plugin
173 * @param string $file File
174 *
175 * @return string
176 *
177 * @see assets()
178 */
179 public static function pluginAssets($addon, $plugin, $file = '')
180 {
181 return self::$pathprovider->pluginAssets($addon, $plugin, $file);
182 }
183 }
184