|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
|
4
|
|
|
use Illuminate\Support\Str; |
|
5
|
|
|
use Pratiksh\Adminetic\Models\Admin\Setting; |
|
6
|
|
|
|
|
7
|
|
|
if (!function_exists('spa')) { |
|
8
|
|
|
function spa() |
|
9
|
|
|
{ |
|
10
|
|
|
return setting('spa', config('adminetic.spa', true)); |
|
11
|
|
|
} |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
if (!function_exists('getClassesList')) { |
|
15
|
|
|
function getClassesList($dir) |
|
16
|
|
|
{ |
|
17
|
|
|
$classes = \File::allFiles($dir); |
|
18
|
|
|
foreach ($classes as $class) { |
|
19
|
|
|
$class->classname = str_replace( |
|
|
|
|
|
|
20
|
|
|
[app_path(), '/', '.php'], |
|
21
|
|
|
['App', '\\', ''], |
|
22
|
|
|
$class->getRealPath() |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
return $classes; |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
if (!function_exists('getAllModelNames')) { |
|
30
|
|
|
function getAllModelNames($dir) |
|
31
|
|
|
{ |
|
32
|
|
|
$modelNames = []; |
|
33
|
|
|
$models = getClassesList($dir); |
|
34
|
|
|
foreach ($models as $model) { |
|
35
|
|
|
$model_name = explode('\\', $model->classname); |
|
|
|
|
|
|
36
|
|
|
$modelNames[] = end($model_name); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
return $modelNames; |
|
40
|
|
|
} |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (!function_exists('validImageFolder')) { |
|
44
|
|
|
function validImageFolder($name, $default = 'default') |
|
45
|
|
|
{ |
|
46
|
|
|
return strtolower(str_replace([' ', '-', '$', '<', '>', '&', '{', $closing_token, '*', '\\', '/', ':', '.', ';', ',', "'", '"'], '_', $name ?? trim($default))); |
|
|
|
|
|
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if (!function_exists('getImagePlaceholder')) { |
|
51
|
|
|
function getImagePlaceholder() |
|
52
|
|
|
{ |
|
53
|
|
|
return asset('adminetic/static/placeholder.png'); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
if (!function_exists('getVerticalImagePlaceholder')) { |
|
58
|
|
|
function getVerticalImagePlaceholder() |
|
59
|
|
|
{ |
|
60
|
|
|
return asset('adminetic/static/vertical_placeholder.jpg'); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if (!function_exists('getSliderPlaceholder')) { |
|
65
|
|
|
function getSliderPlaceholder() |
|
66
|
|
|
{ |
|
67
|
|
|
return asset('adminetic/static/slider.jpg'); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if (!function_exists('getFoodImagePlaceholder')) { |
|
72
|
|
|
function getFoodImagePlaceholder() |
|
73
|
|
|
{ |
|
74
|
|
|
return asset('adminetic/static/food_placeholder.jpg'); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!function_exists('getProfilePlaceholder')) { |
|
79
|
|
|
function getProfilePlaceholder($p = null) |
|
80
|
|
|
{ |
|
81
|
|
|
$profile = $p ?? Auth::user()->profile ?? Auth::user()->profile()->create(); |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
return isset($profile->profile_pic) ? (Illuminate\Support\Str::contains($profile->profile_pic, ['https://', 'http://']) ? $profile->profile_pic : asset('storage/' . $profile->profile_pic)) : asset('adminetic/static/profile.gif'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
if (!function_exists('title')) { |
|
88
|
|
|
function title() |
|
89
|
|
|
{ |
|
90
|
|
|
return setting('title', config('adminetic.name', 'Adminetic')); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
if (!function_exists('description')) { |
|
95
|
|
|
function description($default = null) |
|
96
|
|
|
{ |
|
97
|
|
|
return setting('description', config('adminetic.description', $default ?? 'Adminetic Admin Panel')); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
if (!function_exists('keywords')) { |
|
102
|
|
|
function keywords() |
|
103
|
|
|
{ |
|
104
|
|
|
return setting('keywords', config('adminetic.keywords', 'adminetic admin panel, adminetic, pratik shrestha, doctype innovations')); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (!function_exists('loader_enabled')) { |
|
109
|
|
|
function loader_enabled() |
|
110
|
|
|
{ |
|
111
|
|
|
return setting('loader_enabled', config('adminetic.loader_enabled', true)); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
if (!function_exists('favicon')) { |
|
116
|
|
|
function favicon() |
|
117
|
|
|
{ |
|
118
|
|
|
return getImg(!is_null(setting('favicon')) ? setting('favicon') : 'adminetic/static/favicon.png', 'adminetic/static/favicon.png'); |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
if (!function_exists('logo')) { |
|
123
|
|
|
function logo() |
|
124
|
|
|
{ |
|
125
|
|
|
return getImg(!is_null(setting('logo')) ? setting('logo') : 'adminetic/static/logo.png', 'adminetic/static/logo.png'); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
if (!function_exists('dark_logo')) { |
|
130
|
|
|
function dark_logo() |
|
131
|
|
|
{ |
|
132
|
|
|
return getImg(!is_null(setting('dark_logo')) ? setting('dark_logo') : 'adminetic/static/dark_logo.png', 'adminetic/static/dark_logo.png'); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
if (!function_exists('logoBanner')) { |
|
137
|
|
|
function logoBanner() |
|
138
|
|
|
{ |
|
139
|
|
|
return getImg(!is_null(setting('logo_banner')) ? setting('logo_banner') : 'adminetic/static/logo_banner.png', 'adminetic/static/logo_banner.png'); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
if (!function_exists('login_register_bg_image')) { |
|
144
|
|
|
function login_register_bg_image() |
|
145
|
|
|
{ |
|
146
|
|
|
return getImg(!is_null(setting('login_register_bg_image')) ? setting('login_register_bg_image') : 'adminetic/static/login_register_bg_img.jpg', 'adminetic/static/login_register_bg_img.jpg'); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
if (!function_exists('getLazyLoadImg')) { |
|
151
|
|
|
function getLazyLoadImg() |
|
152
|
|
|
{ |
|
153
|
|
|
return asset('adminetic/static/loader.svg'); |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
if (!function_exists('random_color_part')) { |
|
158
|
|
|
function random_color_part() |
|
159
|
|
|
{ |
|
160
|
|
|
return str_pad(dechex(mt_rand(0, 255)), 2, '0', STR_PAD_LEFT); |
|
161
|
|
|
} |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
if (!function_exists('random_color')) { |
|
165
|
|
|
function random_color() |
|
166
|
|
|
{ |
|
167
|
|
|
return random_color_part() . random_color_part() . random_color_part(); |
|
168
|
|
|
} |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
if (!function_exists('setting')) { |
|
172
|
|
|
function setting($setting_name, $default = null) |
|
173
|
|
|
{ |
|
174
|
|
|
$valid_setting_name = strtolower(str_replace(' ', '_', $setting_name)); |
|
175
|
|
|
$setting = Setting::where('setting_name', $valid_setting_name)->first(); |
|
176
|
|
|
|
|
177
|
|
|
return isset($setting->value) ? $setting->value : ($default ?? null); |
|
178
|
|
|
} |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (!function_exists('preference')) { |
|
182
|
|
|
function preference($preference_name, bool $default = null) |
|
183
|
|
|
{ |
|
184
|
|
|
$valid_preference_name = strtolower(str_replace(' ', '_', $preference_name)); |
|
185
|
|
|
if (auth()->check()) { |
|
186
|
|
|
$preference = auth()->user()->preferences()->where('preference', $valid_preference_name)->first(); |
|
187
|
|
|
|
|
188
|
|
|
return isset($preference) ? $preference->pivot->enabled : ($default ?? null); |
|
189
|
|
|
} else { |
|
190
|
|
|
return null; |
|
191
|
|
|
} |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
if (!function_exists('deleteImage')) { |
|
196
|
|
|
function deleteImage($image) |
|
197
|
|
|
{ |
|
198
|
|
|
$image ? (\Illuminate\Support\Facades\File::exists(public_path('storage/' . $image)) ? \Illuminate\Support\Facades\File::delete(public_path('storage/' . $image)) : '') : ''; |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
if (!function_exists('api_paginate_limit')) { |
|
203
|
|
|
function api_paginate_limit($default = null) |
|
204
|
|
|
{ |
|
205
|
|
|
return setting('api_paginate_limit', $default ?? config('adminetic.api_paginate_limit', 10)); |
|
206
|
|
|
} |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
if (!function_exists('api_collection_return_paginate')) { |
|
210
|
|
|
function api_collection_return_paginate() |
|
211
|
|
|
{ |
|
212
|
|
|
return setting('api_collection_return_paginate', config('adminetic.api_collection_return_paginate', true)); |
|
213
|
|
|
} |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
if (!function_exists('darkMode')) { |
|
217
|
|
|
function darkMode() |
|
218
|
|
|
{ |
|
219
|
|
|
return setting('dark_mode', config('adminetic.dark_mode', false)); |
|
220
|
|
|
} |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
if (!function_exists('getCondition')) { |
|
224
|
|
|
function getCondition($conditions) |
|
225
|
|
|
{ |
|
226
|
|
|
$result = null; |
|
227
|
|
|
if (!isset($conditions)) { |
|
228
|
|
|
return false; |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
if (count($conditions) > 0) { |
|
232
|
|
|
if (count($conditions) == 1) { |
|
233
|
|
|
return $conditions[0]['condition']; |
|
234
|
|
|
} else { |
|
235
|
|
|
foreach ($conditions as $condition) { |
|
236
|
|
|
if (isset($condition['type']) && isset($condition['condition'])) { |
|
237
|
|
|
if ($condition['type'] == 'or' || $condition['type'] == 'Or' || $condition['type'] == 'OR' || $condition['type'] == '||') { |
|
238
|
|
|
$result = $result || $condition['condition']; |
|
239
|
|
|
} elseif ($condition['type'] == 'and' || $condition['type'] == 'And' || $condition['type'] == 'AND' || $condition['type'] == '&&') { |
|
240
|
|
|
$result = $result && $condition['condition']; |
|
|
|
|
|
|
241
|
|
|
} |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
return $result; |
|
247
|
|
|
} else { |
|
248
|
|
|
return false; |
|
249
|
|
|
} |
|
250
|
|
|
} |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
if (!function_exists('getImg')) { |
|
254
|
|
|
function getImg($img, $default) |
|
255
|
|
|
{ |
|
256
|
|
|
if (isset($img)) { |
|
257
|
|
|
if (file_exists(public_path('storage/' . $img))) { |
|
258
|
|
|
return asset('storage/' . $img); |
|
259
|
|
|
} elseif (file_exists(public_path($img))) { |
|
260
|
|
|
return asset($img); |
|
261
|
|
|
} else { |
|
262
|
|
|
return asset($default); |
|
263
|
|
|
} |
|
264
|
|
|
} else { |
|
265
|
|
|
return asset($default); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
} |
|
269
|
|
|
|
|
270
|
|
|
if (!function_exists('putContentToClassFunction')) { |
|
271
|
|
|
function putContentToClassFunction($file, $function_name, $data, $closing_token = '}') |
|
272
|
|
|
{ |
|
273
|
|
|
$data = $data . "\n"; |
|
274
|
|
|
// Read the contents of the file into a string |
|
275
|
|
|
$contents = file_get_contents($file); |
|
276
|
|
|
|
|
277
|
|
|
// Find the position of the function definition within the class |
|
278
|
|
|
$start_pos = strpos($contents, "$function_name"); |
|
279
|
|
|
if ($start_pos === false) { |
|
280
|
|
|
exit('Function not found'); |
|
|
|
|
|
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
// Find the position of the closing brace of the function |
|
284
|
|
|
$end_pos = strpos($contents, $closing_token, $start_pos); |
|
285
|
|
|
if ($end_pos === false) { |
|
286
|
|
|
exit('Function not properly defined'); |
|
|
|
|
|
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
// Extract the function definition from the class |
|
290
|
|
|
$function_definition = substr($contents, $start_pos, $end_pos - $start_pos + 1); |
|
291
|
|
|
|
|
292
|
|
|
// Append the new content to the function definition |
|
293
|
|
|
$modified_function_definition = rtrim($function_definition, $closing_token) . $data . $closing_token; |
|
294
|
|
|
|
|
295
|
|
|
// Replace the original function definition with the modified one in the class definition |
|
296
|
|
|
$modified_contents = substr_replace($contents, $modified_function_definition, $start_pos, $end_pos - $start_pos + 1); |
|
297
|
|
|
|
|
298
|
|
|
// Write the modified string back to the file |
|
299
|
|
|
file_put_contents($file, $modified_contents); |
|
300
|
|
|
|
|
301
|
|
|
return true; |
|
302
|
|
|
} |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
if (!function_exists('checkIfFieldIsRequired')) { |
|
306
|
|
|
function checkIfFieldIsRequired($table_name, $field) |
|
307
|
|
|
{ |
|
308
|
|
|
$isNullable = null; |
|
309
|
|
|
$table = Schema::getConnection()->getDoctrineSchemaManager()->listTableDetails($table_name); |
|
|
|
|
|
|
310
|
|
|
|
|
311
|
|
|
foreach ($table->getColumns() as $column) { |
|
312
|
|
|
if ($column->getName() === $field) { |
|
313
|
|
|
$isNullable = $column->getNotnull() === false; |
|
314
|
|
|
break; |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
return $isNullable; |
|
319
|
|
|
} |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
if (!function_exists('label')) { |
|
323
|
|
|
function label($table, $field, $default_label = null) |
|
324
|
|
|
{ |
|
325
|
|
|
$display_name = $default_label ?? Str::ucfirst(str_replace('_', ' ', $field)); |
|
326
|
|
|
if (!checkIfFieldIsRequired($table, $field)) { |
|
327
|
|
|
// do something if phone_number is nullable |
|
328
|
|
|
echo "{$display_name} <span class='text-danger'>*</span>"; |
|
329
|
|
|
} else { |
|
330
|
|
|
echo $display_name; |
|
331
|
|
|
} |
|
332
|
|
|
} |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
if (!function_exists('role_theme')) { |
|
336
|
|
|
function role_theme() |
|
337
|
|
|
{ |
|
338
|
|
|
$role = auth()->check() ? auth()->user()->roles->first()->name : null; |
|
339
|
|
|
$role_theme = config('adminetic.role_theme', null); |
|
340
|
|
|
if (!is_null($role_theme)) { |
|
341
|
|
|
return isset($role_theme[$role]) ? $role_theme[$role] : 'compact-sidebar'; |
|
342
|
|
|
} |
|
343
|
|
|
return 'compact-sidebar'; |
|
344
|
|
|
} |
|
345
|
|
|
} |
|
346
|
|
|
|
|
347
|
|
|
if (!function_exists('setEnvValue')) { |
|
348
|
|
|
function setEnvValue(array $values) |
|
349
|
|
|
{ |
|
350
|
|
|
$envFile = app()->environmentFilePath(); |
|
|
|
|
|
|
351
|
|
|
$str = file_get_contents($envFile); |
|
352
|
|
|
|
|
353
|
|
|
if (count($values) > 0) { |
|
354
|
|
|
foreach ($values as $envKey => $envValue) { |
|
355
|
|
|
$str .= "\n"; // In case the searched variable is in the last line without \n |
|
356
|
|
|
$keyPosition = strpos($str, "{$envKey}="); |
|
357
|
|
|
$endOfLinePosition = strpos($str, "\n", $keyPosition); |
|
358
|
|
|
$oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition); |
|
359
|
|
|
|
|
360
|
|
|
// If key does not exist, add it |
|
361
|
|
|
if (!$keyPosition || !$endOfLinePosition || !$oldLine) { |
|
362
|
|
|
$str .= "{$envKey}={$envValue}\n"; |
|
363
|
|
|
} else { |
|
364
|
|
|
$str = str_replace($oldLine, "{$envKey}={$envValue}", $str); |
|
365
|
|
|
} |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
$str = substr($str, 0, -1); |
|
370
|
|
|
if (!file_put_contents($envFile, $str)) { |
|
371
|
|
|
return false; |
|
372
|
|
|
} |
|
373
|
|
|
|
|
374
|
|
|
return true; |
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
|