|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Ramsey\Uuid\Uuid; |
|
4
|
|
|
|
|
5
|
|
|
if (! function_exists('is_domain')) { |
|
6
|
|
|
/** |
|
7
|
|
|
* Determines the current domain equals to the given domain identifier. |
|
8
|
|
|
* |
|
9
|
|
|
* @param string $identifier |
|
10
|
|
|
* @return bool |
|
11
|
|
|
*/ |
|
12
|
|
|
function is_domain($identifier) |
|
13
|
|
|
{ |
|
14
|
|
|
return app('request')->getHost() === config('app.domains.'.$identifier); |
|
15
|
|
|
} |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
if (! function_exists('app_url')) { |
|
19
|
|
|
/** |
|
20
|
|
|
* Generate an URL for the application. |
|
21
|
|
|
* |
|
22
|
|
|
* @param string $path |
|
23
|
|
|
* @param mixed $parameters |
|
24
|
|
|
* @param string $identifier |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
function app_url($path = '', $parameters = null, $identifier = 'site') |
|
28
|
|
|
{ |
|
29
|
|
|
$path = trim($path, '/'); |
|
30
|
|
|
if (! empty($path) && ! starts_with($path, ['?', '&', '#'])) { |
|
31
|
|
|
$path = '/'.$path; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (! is_null($parameters)) { |
|
35
|
|
|
$query = http_build_query($parameters); |
|
36
|
|
|
if (! empty($query)) { |
|
37
|
|
|
$path .= (str_contains($path, ['?', '&', '#']) ? '&' : '?').$query; |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
if ($identifier && ($root = config('support.url.'.$identifier))) { |
|
42
|
|
|
return $root.$path; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return url($path); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (! function_exists('revision')) { |
|
50
|
|
|
/** |
|
51
|
|
|
* Get the revisioned asset path. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $path |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
function revision($path) |
|
57
|
|
|
{ |
|
58
|
|
|
if ($rev = array_get(config('assets-version'), trim($path, DIRECTORY_SEPARATOR))) { |
|
59
|
|
|
return $path.'?'.$rev; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
return $path; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (! function_exists('asset_url')) { |
|
67
|
|
|
/** |
|
68
|
|
|
* Generate an asset URL. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $path |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
|
|
function asset_url($path, $identifier = 'asset') |
|
74
|
|
|
{ |
|
75
|
|
|
if (filter_var($path, FILTER_VALIDATE_URL) !== false) { |
|
76
|
|
|
return $path; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return config('support.url.'.$identifier).'/'.revision(trim($path, '/')); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
if (! function_exists('cdn_url')) { |
|
84
|
|
|
/** |
|
85
|
|
|
* Generate an asset CDN URL. |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $path |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
function cdn_url($path) |
|
91
|
|
|
{ |
|
92
|
|
|
return asset_url($path, 'cdn'); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (! function_exists('gravatar')) { |
|
97
|
|
|
/** |
|
98
|
|
|
* Generate a Gravatar url. |
|
99
|
|
|
* |
|
100
|
|
|
* @see http://cn.gravatar.com/site/implement/images/ |
|
101
|
|
|
* |
|
102
|
|
|
* @param string $email |
|
103
|
|
|
* @param int $size |
|
104
|
|
|
* @param string $default |
|
105
|
|
|
* @param string $rating |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
function gravatar($email, $size = 100, $default = null, $rating = null) |
|
109
|
|
|
{ |
|
110
|
|
|
if (is_null($default)) { |
|
111
|
|
|
$default = config('support.gravatar.default'); |
|
112
|
|
|
} |
|
113
|
|
|
if (is_null($rating)) { |
|
114
|
|
|
$rating = config('support.gravatar.rating'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$query = http_build_query(array_filter(compact('size', 'default', 'rating'))); |
|
118
|
|
|
|
|
119
|
|
|
return app('url')->assetFrom( |
|
120
|
|
|
config('support.gravatar.host', 'http://gravatar.com/avatar'), |
|
121
|
|
|
md5(strtolower(trim($email))).'?'.$query |
|
122
|
|
|
); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if (! function_exists('random_uuid')) { |
|
127
|
|
|
/** |
|
128
|
|
|
* Generate a version 4 (random) UUID. |
|
129
|
|
|
* |
|
130
|
|
|
* @param bool $hex |
|
131
|
|
|
* @return string |
|
132
|
|
|
*/ |
|
133
|
|
|
function random_uuid($hex = false) |
|
134
|
|
|
{ |
|
135
|
|
|
$uuid = Uuid::uuid4(); |
|
136
|
|
|
|
|
137
|
|
|
return $hex ? $uuid->getHex() : $uuid->toString(); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|