Passed
Push — master ( 09ce37...db619f )
by Ferry
04:38
created

themeLayoutPageTitleAndButton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * Theme Helper
5
 */
6
if(!function_exists("themeLoginBackground")) {
7
    function themeLoginBackground() {
8
        return "crudbooster::layouts.login_background_css";
9
    }
10
}
11
if(!function_exists("themeFlashMessage")) {
12
    function themeFlashMessage() {
13
        return "crudbooster::layouts.flash_message";
14
    }
15
}
16
17
if(!function_exists("themeAlertMessage")) {
18
    function themeAlertMessage() {
19
        return "crudbooster::layouts.alert_message";
20
    }
21
}
22
23
if(!function_exists("themeLayoutPageTitleAndButton")) {
24
    function themeLayoutPageTitleAndButton() {
25
        return 'crudbooster::module.index.index_head_buttons';
26
    }
27
}
28
29
if(!function_exists("themeLayoutHead")) {
30
    function themeLayoutHead() {
31
        return "crudbooster::layouts.head";
32
    }
33
}
34
if(!function_exists("themeTitle")) {
35
    function themeTitle($page_title) {
36
        $page_title = isset($page_title)?$page_title:module()->getPageTitle();
37
        return (isset($page_title))?cb()->getAppName().': '.strip_tags($page_title):"Admin Area";
38
    }
39
}
40
41
if(!function_exists("getThemePath")) {
42
    function getThemePath($path = null) {
43
        return getSetting("theme_path", "crudbooster::themes.adminlte").(($path)?".".$path:null);
44
    }
45
}
46
47
// End Theme Helper
48
49
if(!function_exists("isConfigCached")) {
50
    function isConfigCached()
51
    {
52
        if(env("APP_NAME")=="" || env("APP_NAME")==null) return true;
53
        else return false;
54
    }
55
}
56
57
if(!function_exists("miscellanousSingleton")) {
58
    /**
59
     * @return \crocodicstudio\crudbooster\helpers\MiscellanousSingleton
60
     */
61
    function miscellanousSingleton() {
62
        return app("MiscellanousSingleton");
0 ignored issues
show
Bug Best Practice introduced by
The expression return app('MiscellanousSingleton') also could return the type Illuminate\Contracts\Foundation\Application which is incompatible with the documented return type crocodicstudio\crudboost...s\MiscellanousSingleton.
Loading history...
63
    }
64
}
65
66
if(!function_exists("makeReferalUrl")) {
67
    function makeReferalUrl($name = null) {
68
        $ref = [];
69
        $ref['url'] = request()->fullUrl();
70
        $ref['name'] = $name;
71
        $md5Hash = md5(serialize($ref));
72
73
        if($exist = \Illuminate\Support\Facades\Cache::get("refurl_".$md5Hash)) {
74
            return $exist['id'];
75
        }
76
77
        $ref['id'] = $newID = \Illuminate\Support\Str::random(7);
78
79
        \Illuminate\Support\Facades\Cache::forever("refurl_token_".$newID, $md5Hash);
80
        \Illuminate\Support\Facades\Cache::forever("refurl_".$md5Hash, $ref);
81
        return $newID;
82
    }
83
}
84
85
if(!function_exists("getReferalUrl")) {
86
    function getReferalUrl($key = null) {
87
        if(verifyReferalUrl()) {
88
            $md5hash = \Illuminate\Support\Facades\Cache::get("refurl_token_".request("ref"));
0 ignored issues
show
Bug introduced by
Are you sure request('ref') of type Illuminate\Http\Request|array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

88
            $md5hash = \Illuminate\Support\Facades\Cache::get("refurl_token_"./** @scrutinizer ignore-type */ request("ref"));
Loading history...
89
            $ref = \Illuminate\Support\Facades\Cache::get("refurl_".$md5hash);
90
            if($key) {
91
                return @$ref[$key];
92
            } else {
93
                return $ref;
94
            }
95
        }
96
        return null;
97
    }
98
}
99
100
if(!function_exists("verifyReferalUrl")) {
101
    function verifyReferalUrl()
102
    {
103
        if(request("ref")) {
104
            if($md5hash = \Illuminate\Support\Facades\Cache::get("refurl_token_".request("ref"))) {
0 ignored issues
show
Bug introduced by
Are you sure request('ref') of type Illuminate\Http\Request|array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

104
            if($md5hash = \Illuminate\Support\Facades\Cache::get("refurl_token_"./** @scrutinizer ignore-type */ request("ref"))) {
Loading history...
105
                $ref = \Illuminate\Support\Facades\Cache::get("refurl_".$md5hash);
106
                if(filter_var($ref['url'], FILTER_VALIDATE_URL)) {
107
                    return true;
108
                }
109
            }
110
        }
111
        return false;
112
    }
113
}
114
115
if(!function_exists("putHtaccess")) {
116
    function putHtaccess($stringToPut)
117
    {
118
        file_put_contents(base_path(".htaccess"), "\n".$stringToPut, FILE_APPEND);
119
        file_put_contents(public_path(".htaccess"), "\n".$stringToPut, FILE_APPEND);
120
    }
121
}
122
123
if(!function_exists("checkHtaccess")) {
124
    function checkHtaccess($stringToCheck)
125
    {
126
        if(file_exists(base_path(".htaccess")) && file_exists(public_path(".htaccess"))) {
127
            $htaccess = file_get_contents(base_path(".htaccess"));
128
            $htaccess2= file_get_contents(public_path(".htaccess"));
129
            if(\Illuminate\Support\Str::contains($htaccess, $stringToCheck) && \Illuminate\Support\Str::contains($htaccess2, $stringToCheck)) {
130
                return true;
131
            }
132
        }
133
134
        return false;
135
    }
136
}
137
138
if(!function_exists("setEnvironmentValue")) {
139
    function setEnvironmentValue(array $values)
140
    {
141
        $envFile = app()->environmentFilePath();
0 ignored issues
show
introduced by
The method environmentFilePath() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

141
        $envFile = app()->/** @scrutinizer ignore-call */ environmentFilePath();
Loading history...
142
        $str = file_get_contents($envFile);
143
144
        if (count($values) > 0) {
145
            foreach ($values as $envKey => $envValue) {
146
147
                $str .= "\n"; // In case the searched variable is in the last line without \n
148
                $keyPosition = strpos($str, "{$envKey}=");
149
                $endOfLinePosition = strpos($str, "\n", $keyPosition);
150
                $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
151
152
                // If key does not exist, add it
153
                if (!$keyPosition || !$endOfLinePosition || !$oldLine) {
154
                    $str .= "{$envKey}={$envValue}\n";
155
                } else {
156
                    $str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
157
                }
158
159
            }
160
        }
161
162
        $str = substr($str, 0, -1);
163
        if (!file_put_contents($envFile, $str)) return false;
164
        return true;
165
    }
166
}
167
168
169
if(!function_exists("cbLang")) {
170
    /**
171
     * @param string $key
172
     * @param array $replace
173
     * @return array|\Illuminate\Contracts\Translation\Translator|null|string
174
     */
175
    function cbLang($key, $replace = [])
176
    {
177
        return trans("cb::cb.".$key, $replace);
178
    }
179
}
180
181
if(!function_exists('rglob')) {
182
    function rglob($pattern, $flags = 0) {
183
        $files = glob($pattern, $flags);
184
        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
185
            $files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
0 ignored issues
show
Bug introduced by
It seems like $files can also be of type false; however, parameter $array1 of array_merge() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

185
            $files = array_merge(/** @scrutinizer ignore-type */ $files, rglob($dir.'/'.basename($pattern), $flags));
Loading history...
Bug introduced by
It seems like rglob($dir . '/' . basename($pattern), $flags) can also be of type false; however, parameter $array2 of array_merge() does only seem to accept array|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

185
            $files = array_merge($files, /** @scrutinizer ignore-type */ rglob($dir.'/'.basename($pattern), $flags));
Loading history...
186
        }
187
        return $files;
188
    }
189
}
190
191
if(!function_exists('convertPHPToMomentFormat')) {
192
    function convertPHPToMomentFormat($format)
193
    {
194
        $replacements = [
195
            'd' => 'DD',
196
            'D' => 'ddd',
197
            'j' => 'D',
198
            'l' => 'dddd',
199
            'N' => 'E',
200
            'S' => 'o',
201
            'w' => 'e',
202
            'z' => 'DDD',
203
            'W' => 'W',
204
            'F' => 'MMMM',
205
            'm' => 'MM',
206
            'M' => 'MMM',
207
            'n' => 'M',
208
            't' => '', // no equivalent
209
            'L' => '', // no equivalent
210
            'o' => 'YYYY',
211
            'Y' => 'YYYY',
212
            'y' => 'YY',
213
            'a' => 'a',
214
            'A' => 'A',
215
            'B' => '', // no equivalent
216
            'g' => 'h',
217
            'G' => 'H',
218
            'h' => 'hh',
219
            'H' => 'HH',
220
            'i' => 'mm',
221
            's' => 'ss',
222
            'u' => 'SSS',
223
            'e' => 'zz', // deprecated since version 1.6.0 of moment.js
224
            'I' => '', // no equivalent
225
            'O' => '', // no equivalent
226
            'P' => '', // no equivalent
227
            'T' => '', // no equivalent
228
            'Z' => '', // no equivalent
229
            'c' => '', // no equivalent
230
            'r' => '', // no equivalent
231
            'U' => 'X',
232
        ];
233
        $momentFormat = strtr($format, $replacements);
234
        return $momentFormat;
235
    }
236
}
237
238
if(!function_exists('slug')) {
239
    function slug($string, $separator = '-') {
240
        return \Illuminate\Support\Str::slug($string, $separator);
241
    }
242
}
243
244
if(!function_exists('columnSingleton')) {
245
    /**
246
     * @return \crocodicstudio\crudbooster\controllers\scaffolding\singletons\ColumnSingleton
247
     */
248
    function columnSingleton() {
249
        return app('ColumnSingleton');
0 ignored issues
show
Bug Best Practice introduced by
The expression return app('ColumnSingleton') also could return the type Illuminate\Contracts\Foundation\Application which is incompatible with the documented return type crocodicstudio\crudboost...gletons\ColumnSingleton.
Loading history...
250
    }
251
}
252
253
if(!function_exists('cbHook'))
254
{
255
    /**
256
     * @return crocodicstudio\crudbooster\hooks\CBHook
257
     */
258
    function cbHook()
259
    {
260
        $className = "\App\Http\CBHook";
261
        return new $className();
262
    }
263
}
264
265
if(!function_exists('getTypeHook'))
266
{
267
    /**
268
     * @param string $type
269
     * @return crocodicstudio\crudbooster\types\TypesHookInterface
270
     */
271
    function getTypeHook($type) {
272
        $className = '\crocodicstudio\crudbooster\types\\'.$type.'\Hook';
273
        $typeClass = new $className();
274
        return $typeClass;
275
    }
276
}
277
278
if(!function_exists('getPrimaryKey'))
279
{
280
    function getPrimaryKey($table_name)
281
    {
282
        return cb()->pk($table_name);
283
    }
284
}
285
286
if(!function_exists('cb'))
287
{
288
    function cb()
289
    {
290
        return new \crocodicstudio\crudbooster\helpers\CB();
291
    }
292
}
293
294
if(!function_exists('cbAsset')) {
295
    function cbAsset($path, $secure = null) {
296
        return asset("cb_asset/".$path, $secure);
297
    }
298
}
299
300
if(!function_exists("cbConfig")) {
301
    function cbConfig($name, $default = null) {
302
        return config("crudbooster.".$name, $default);
303
    }
304
}
305
306
if(!function_exists("strRandom")) {
307
    function strRandom($length = 5) {
308
        return \Illuminate\Support\Str::random($length);
309
    }
310
}
311
312
if(!function_exists('module')) {
313
    function module()
314
    {
315
        $module = new \crocodicstudio\crudbooster\helpers\Module();
316
        return $module;
317
    }
318
}
319
320
if(!function_exists('getAdminLoginURL')) {
321
    function getAdminLoginURL()
322
    {
323
        return cb()->getAdminUrl("login");
324
    }
325
}
326
327
if(!function_exists('dummyPhoto')) {
328
    function dummyPhoto()
329
    {
330
        return cbConfig("DUMMY_PHOTO");
331
    }
332
}
333
334
if(!function_exists('extract_unit')) {	
335
	/*
336
	Credits: Bit Repository
337
	URL: http://www.bitrepository.com/extract-content-between-two-delimiters-with-php.html
338
	*/
339
	function extract_unit($string, $start, $end)
340
	{
341
	$pos = stripos($string, $start);
342
	$str = substr($string, $pos);
343
	$str_two = substr($str, strlen($start));
344
	$second_pos = stripos($str_two, $end);
345
	$str_three = substr($str_two, 0, $second_pos);
346
	$unit = trim($str_three); // remove whitespaces
347
	return $unit;
348
	}
349
}
350
351
/* 
352
| --------------------------------------------------------------------------------------------------------------
353
| Get data from input post/get more simply
354
| --------------------------------------------------------------------------------------------------------------
355
| $name = name of input
356
|
357
*/
358
359
if(!function_exists('putSetting')) {
360
    function putSetting($key, $value)
361
    {
362
        if(file_exists(storage_path('.cbconfig'))) {
363
            $settings = file_get_contents(storage_path('.cbconfig'));
364
            $settings = decrypt($settings);
365
            $settings = unserialize($settings);
366
        }else{
367
            $settings = [];
368
        }
369
370
        $settings[$key] = $value;
371
372
        \Illuminate\Support\Facades\Cache::forget("setting_".$key);
373
374
        $settings = serialize($settings);
375
        $settings = encrypt($settings);
376
        file_put_contents(storage_path('.cbconfig'), $settings);
377
    }
378
}
379
380
if(!function_exists('getSetting')) {
381
    function getSetting($key, $default = null)
382
    {
383
        if($cache = \Illuminate\Support\Facades\Cache::get("setting_".$key)) {
384
            return $cache;
385
        }
386
387
        if(file_exists(storage_path('.cbconfig'))) {
388
            $settings = file_get_contents(storage_path('.cbconfig'));
389
            $settings = decrypt($settings);
390
            $settings = unserialize($settings);
391
        }else{
392
            $settings = [];
393
        }
394
395
        if(isset($settings[$key])) {
396
            \Illuminate\Support\Facades\Cache::forever("setting_".$key, $settings[$key]);
397
            return $settings[$key]?:$default;
398
        }else{
399
            return $default;
400
        }
401
    }
402
}
403
404
if(!function_exists('timeAgo')) {
405
    function timeAgo($datetime_to, $datetime_from = null, $full = false)
406
    {
407
        $datetime_from = ($datetime_from) ?: date('Y-m-d H:i:s');
408
        $now = new \DateTime;
409
        if ($datetime_from != '') {
410
            $now = new \DateTime($datetime_from);
411
        }
412
        $ago = new \DateTime($datetime_to);
413
        $diff = $now->diff($ago);
414
415
        $diff->w = floor($diff->d / 7);
0 ignored issues
show
Bug introduced by
The property w does not seem to exist on DateInterval.
Loading history...
416
        $diff->d -= $diff->w * 7;
417
418
        $string = [
419
            'y' => 'year',
420
            'm' => 'month',
421
            'w' => 'week',
422
            'd' => 'day',
423
            'h' => 'hour',
424
            'i' => 'minute',
425
            's' => 'second',
426
        ];
427
        foreach ($string as $k => &$v) {
428
            if ($diff->$k) {
429
                $v = $diff->$k.' '.$v.($diff->$k > 1 ? 's' : '');
430
            } else {
431
                unset($string[$k]);
432
            }
433
        }
434
435
        if (! $full) {
436
            $string = array_slice($string, 0, 1);
437
        }
438
439
        return $string ? implode(', ', $string).' ' : 'just now';
440
    }
441
}
442
443
if(!function_exists("array_map_r")) {
444
    function array_map_r( $func, $arr )
445
    {
446
        $newArr = array();
447
448
        foreach( $arr as $key => $value )
449
        {
450
            $key = $func($key);
451
            $newArr[ $key ] = ( is_array( $value ) ? array_map_r( $func, $value ) : ( is_array($func) ? call_user_func_array($func, $value) : $func( $value ) ) );
452
        }
453
454
        return $newArr;
455
    }
456
}
457
458
if(!function_exists("sanitizeXSS"))
459
{
460
    function sanitizeXSS($value)
461
    {
462
        $value = filter_var($value, FILTER_SANITIZE_STRING);
463
        $value = strip_tags($value);
464
        $value = htmlspecialchars($value);
465
        $value = preg_replace('~\r\n?~', "\n", $value);
466
        return $value;
467
    }
468
}
469
470
if(!function_exists("requestAll")) {
471
    function requestAll() {
472
        $all = array_map_r("sanitizeXSS", request()->all());
473
        return $all;
474
    }
475
}
476
477
478
479
if(!function_exists('getURLFormat')) {
480
    function getURLFormat($name) {
481
        $url = request($name);
482
        if(filter_var($url, FILTER_VALIDATE_URL)) {
483
            return $url;
484
        }else{
485
            return request()->url();
486
        }
487
    }
488
}
489
490
if(!function_exists('g')) {
491
    function g($name, $safe = true) {
492
        if($safe == true) {
493
            $response = request($name);
494
            if(is_string($response)) {
495
                $response = sanitizeXSS($response);
496
            }elseif (is_array($response)) {
497
                array_walk_recursive($response, function(&$response) {
498
                    $response = sanitizeXSS($response);
499
                });
500
            }
501
502
            return $response;
503
        }else{
504
            return Request::get($name);
505
        }
506
    }
507
}
508
509
if(!function_exists('min_var_export')) {
510
    function min_var_export($input) {
511
        if(is_array($input)) {
512
            $buffer = [];
513
            foreach($input as $key => $value)
514
                $buffer[] = var_export($key, true)."=>".min_var_export($value);
515
            return "[".implode(",",$buffer)."]";
516
        } else
517
            return var_export($input, true);
518
    }
519
}
520
521
if(!function_exists('rrmdir')) {
522
	/*
523
	* http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir
524
	*/
525
	function rrmdir($dir) { 
526
	   if (is_dir($dir)) { 
527
	     $objects = scandir($dir); 
528
	     foreach ($objects as $object) { 
529
	       if ($object != "." && $object != "..") { 
530
	         if (is_dir($dir."/".$object))
531
	           rrmdir($dir."/".$object);
532
	         else
533
	           unlink($dir."/".$object); 
534
	       } 
535
	     }
536
	     rmdir($dir); 
537
	   } 
538
	 }
539
}
540
541