1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718:
<?php
$__ENV = [];
function pre($arr,$them=1){
switch ($them) {
case 1: $color='#2295bc'; $background='#e4e7e7'; break;
case 2: $color='#e4e7e7'; $background='#2295bc'; break;
case 3: $color='#064439'; $background='#51bba8'; break;
case 4: $color='#efc75e'; $background='#324d5b'; break;
case 5: $color='#000000'; $background='#b1eea1'; break;
case 6: $color='#fff'; $background='#e2574c'; break;
default: $color='#2295bc'; $background='#e4e7e7'; break;
}?>
<pre style="direction: ltr;background:<?= $background;?>;color:<?= $color;?>;
max-width: 90%;margin: 30px auto;overflow:auto;
font-family: Monaco,Consolas, 'Lucida Console',monospace;font-size: 16px;padding: 20px;"><?php print_r($arr); echo "</pre>";
}
function dd(...$logArr){
echo "<script> dd(".Array1::toJSON($logArr).") </script>";
Page1::$FLAG_SHOW_LOAD_TIME = true;
Page1::start();
foreach ($logArr as $data) {
Util1::var_dump($data);
}
Page1::end([], false);
die('');
}
function d(...$logArr){ foreach ($logArr as $data) Util1::var_dump($data); }
function app($c = null) {
$app = RouteApp::instance();
if ($c) return $app->$c;
return $app;
}
function app_class_paths(){
global $__ENV;
if(!empty($__ENV['app_class_paths'])) return $__ENV['app_class_paths'];
$all_path = $__ENV['app_class_paths'] = array_merge(
[PATH_APP],
FileManager1::getDirectoriesFolders([rtrim(PATH_LAYOUTS, DS), rtrim(PATH_PLUGINS, DS)], '', 'inc/'),
Config1::ENABLE_INCLUDES_SHARED ?
array_merge(
[PATH_SHARED_APP],
FileManager1::getDirectoriesFolders([PATH_SHARED_RESOURCE.'views/layouts', PATH_SHARED_RESOURCE.'plugins'], '', 'inc/')
): []
);
return ($all_path);
}
function app_class_list($typeList = [AuthModel1::class, Model1::class, Controller1::class, Api1::class]){
global $__ENV;
$key = implode('_', $typeList);
if(!empty($__ENV['app_class_with_interface'][$key])) return $__ENV['app_class_with_interface'][$key];
$model = [];
foreach (FileManager1::getDirectoriesFiles(app_class_paths(), ['php'], [], -1, true) as $modelFile){
$name = FileManager1::getFileName($modelFile);
$name = str_replace( '.php', '', str_replace( '.class.php', '', $name ));
if( in_array(get_parent_class($name), Array1::toArray($typeList))) $model[] = $name;
}
$model = array_diff($model, Config1::EXCLUDE_CLASS);
return $__ENV['app_class_with_interface'][$key] = $model;
}
function app_class_with_interface($interfaceName = Model1ActionInterface::class, $classTypeList = [AuthModel1::class, Model1::class]){
global $__ENV;
if(!empty($__ENV['app_class_with_interface'][$interfaceName])) return $__ENV['app_class_with_interface'][$interfaceName];
$app_dashboard = [];
foreach (app_class_list($classTypeList) as $key) if(Class1::isInterfaceImplementExistIn($key, $interfaceName)) $app_dashboard[] = $key;
return $__ENV['app_class_with_interface'][$interfaceName] = $app_dashboard;
}
function app_controller_list(){ return app_class_list([Controller1::class]); }
function app_api_list(){ return app_class_list([Api1::class]); }
function app_page_list(){ return app_class_with_interface(Model1PageInterface::class); }
function app_dashboard_list(){ return app_class_with_interface(Model1ActionInterface::class); }
function app_model_list($remove_page = true){ return array_diff(app_class_list([Model1::class, AuthModel1::class]), $remove_page? array_merge(app_page_list(), ['Dashboard']): []); }
function app_db_table_list(){ return Db1::getExistingTables(true); }
function app_db_model_list(){ return Db1::getExistingModels(); }
function now($pretty = false){ return DateManager1::now($pretty); }
function now_date($pretty = false){ return DateManager1::nowDate($pretty); }
function now_time($pretty = false){ return DateManager1::nowTime($pretty); }
if(($_SERVER['REQUEST_METHOD'] == 'POST')){
$request = $_REQUEST;
unset($request['password']);
Session1::set('__old', array_merge(isset($_SESSION['__old'])? $_SESSION['__old']:[], $request));
Page1::$FLAG_KEEP_OLD_REQUEST = true;
}
function old($inputName = '', $defaultValueOnFailed = ''){ return String1::is_empty($inputName)? Object1::toArrayObject(true, Session1::get('__old')) : String1::isset_or(Session1::get('__old')[$inputName], String1::isset_or($_REQUEST[$inputName], $defaultValueOnFailed));}
function request(array $insertOrReplaceKeyValue = [], array $filterCheckBoxNameList = [], array $filterFileUploadNameList = []){
$request = Object1::toArrayObject(true, array_merge($_REQUEST, $_FILES, $insertOrReplaceKeyValue));
if($filterCheckBoxNameList) foreach ($filterCheckBoxNameList as $value) $request[$value] = String1::toBoolean($request->{$value}, true, false);
if($filterFileUploadNameList) foreach ($filterFileUploadNameList as $value) $request[$value] = Array1::normalizeLinearRequestList($_FILES[$value]);
return $request;
}
function token(){
if(!empty($_SESSION['token'])) return $_SESSION['token'];
else{
$_SESSION['token'] = bin2hex(openssl_random_pseudo_bytes(32)).'____'.String1::encodeStringToNumber(Url1::backUrl());
$_SESSION['token_time'] = time();
return $_SESSION['token'];
}
}
function is_token_valid($token = null, $moreValidation = true){
$token = $token? $token: String1::isset_or($_POST['token'], '');
$is_match = hash_equals(token(), $token);
if($is_match){
if(is_ajax_request() || !$moreValidation) return true;
else{
if(explode('____', token())[1] != String1::encodeStringToNumber(Url1::backUrl())) return false;
unset($_SESSION['token'], $_SESSION['token_time']);
return true;
}
}
unset($_SESSION['token'], $_SESSION['token_time']);
return false;
}
function csrf_token(){ return token(); }
function form_token(){ return HtmlForm1::addHidden('token', token()); }
function form_call_controller($classStaticFunction = 'className::function(param1, param2)'){ return Form1::callController($classStaticFunction); }
function form_call_api($classStaticFunction = 'className::function(param1, param2)'){ return Form1::callApi($classStaticFunction); }
function is_ajax_request() {
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest';
}
function routes($except = [], $listAsMenu = false, $renameLinkName_oldName_equals_newName = []) {
$routeKeyValueList = Array1::removeKeys(array_merge( Array1::wrap( array_merge(['index'=> '/', 'home'=>'/'], app('route')->getAllRoutes()), path_main_url('/')), ['current'=>@explode('?', Url1::getPageFullUrl())[0] ]), $except);
$routeKeyValueList = Array1::replaceKeyNames($routeKeyValueList, $renameLinkName_oldName_equals_newName);
if($listAsMenu) { $menuLink = []; foreach ($routeKeyValueList as $item => $value) $menuLink[ucwords(String1::convertToCamelCase(String1::replace($item, '.', ' '), ' '))] = $value; return $menuLink; }
else return Object1::toArrayObject(true, $routeKeyValueList);
}
function route($name = null, array $args = []) {
if($name) return url(app('route')->getRoute($name, $args));
global $route; return $route;
}
function url($path = null) { return path_main_url().'/'.trim($path, '/'); }
function redirect_to_view($viewPageName, array $param = [], $actionResult = false, $trueMessage = [], $falseMessage = []){
global $FORM_ACTION_SHOULD_REDIRECT;
$FORM_ACTION_SHOULD_REDIRECT = false;
if(!empty($trueMessage) || !empty($trueMessage)) Session1::setStatusFrom(($actionResult)? $trueMessage: $falseMessage );
return view($viewPageName, $param);
}
function redirect($routeUrl = '/', $status = [], $param = []){
if(String1::startsWith($routeUrl, '/') || !String1::startsWith(strtolower($routeUrl), 'http')) return Url1::redirect(url($routeUrl), $status, $param);
else return Url1::redirect($routeUrl, $status, $param);
}
function redirect_failed($status = ['Request Failed', 'Could not retrieve necessary data', 'error']){
Session1::setStatusFrom($status? $status: ['Request Failed']);
$backUrl = Url1::backUrl();
$returnUrl = url('/error404');
if($backUrl !== Url1::getPageFullUrl()) $returnUrl = $backUrl;
Url1::redirect($returnUrl);
return Console1::println($status, true);
}
function redirect_back($status = [], $param = []){
Url1::redirect(Url1::backUrl(), $status, $param);
return '';
}
function layout_asset($file_path_name = '', $assets_folder_name = 'assets', $layout_name= null, $isInSharedLayout = false){
$path = exBlade1::$CURRENT_LAYOUT_PATH ? exBlade1::$CURRENT_LAYOUT_PATH: (resources_path_view_layout($isInSharedLayout).DS.$layout_name);
$path = $path.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
$path = normalizeSharedPath($path, '/shared/resources/views/', 'layout_list');
return Url1::pathToUrl($path);
}
function plugin_asset($file_path_name = '', $assets_folder_name = 'assets', $plugin_name = null, $isInSharedLayout = false){
$path = resources_path_plugin($isInSharedLayout).DS.$plugin_name;
$path = $path.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
$path = normalizeSharedPath($path, '/shared/resources/plugins/', 'plugin_list');
return Url1::pathToUrl($path);
}
function normalizeSharedPath($file_system_path = '', $shared_path_delimiter = '/shared/resources/', $destination_asset_folder_name = 'shared_asset_list'){
if(String1::contains($shared_path_delimiter, $file_system_path) && String1::startsWith(Config1::INCLUDES_PATH, '../') ){
$name = String1::replace(explode($shared_path_delimiter, $file_system_path)[1], DS, '_');
$layout_asset = path_asset()."/shared/$destination_asset_folder_name/$name";
if(!is_link($layout_asset)){
@unlink($layout_asset);
@mkdir(path_asset()."/shared/$destination_asset_folder_name", 0777, true);
Session1::setStatus('Shared Resources Linked', ["Resources ('".String1::convertToCamelCase($name, ' ')."') Linked to app!", Url1::createSymLinks($file_system_path, $layout_asset)]);
}
$file_system_path = $layout_asset;
}
return $file_system_path;
}
function current_resources_asset_path($file_path_name = '', $assets_folder_name = 'assets', $app_path_delimiter = '/resources/views/layouts/', $shared_path_delimiter = '/shared/resources/', $destination_asset_folder_name = 'shared_asset_list', $debug_backtrace = 0){
$current_file_full_path = debug_backtrace(null, 2)[$debug_backtrace]['file'];
if(!String1::contains($app_path_delimiter, $current_file_full_path)) throw new Exception(Console1::println('Current Layout Assets function Can only be run in Layout Folder, to retrieve assets of the layout. E.g Can be use to retrieve assets/css for plugin instead of using layout_asset("layout-name")'));
$slitter = explode($app_path_delimiter, $current_file_full_path);
$full_layout = $slitter[0].$app_path_delimiter.explode(DS, $slitter[1])[0];
$path = $full_layout.DS.$assets_folder_name.(!empty($file_path_name)? DS.$file_path_name: '');
$path = normalizeSharedPath($path, $shared_path_delimiter, $destination_asset_folder_name);
return Url1::pathToUrl($path);
}
function current_plugin_asset($file_path_name = '', $assets_folder_name = 'assets'){
return current_resources_asset_path($file_path_name, $assets_folder_name, '/resources/plugins/', '/shared/resources/plugins/', 'plugin_list', 1);
}
function current_layout_asset($file_path_name = '', $assets_folder_name = 'assets'){
return current_resources_asset_path($file_path_name, $assets_folder_name, '/resources/views/layouts/', '/shared/resources/views/', 'layout_list', 1);
}
function register_path_for_layout_asset($optional_layoutViewPath_or_layoutFullPath = null, $backtrace_index = 0){
if($optional_layoutViewPath_or_layoutFullPath) return exBlade1::$CURRENT_LAYOUT_PATH = dirname(String1::contains( DS, $optional_layoutViewPath_or_layoutFullPath)? $optional_layoutViewPath_or_layoutFullPath: viewpath_to_path($optional_layoutViewPath_or_layoutFullPath) );
$allData = array_flip(exBlade1::$LOADED_VIEW_AND_CACHE_LIST);
$cachePath = debug_backtrace(null, 2)[$backtrace_index]['file'];
if($allData[$cachePath]) return exBlade1::$CURRENT_LAYOUT_PATH = dirname($allData[$cachePath]);
else return die('Error in register_path_for_layout_asset(), Assets Path Not Found');
}
function path_main_url($path = ''){
if(!String1::is_empty($path)) $path = '/'.ltrim($path, '/');
return rtrim(Url1::getSiteMainAddress().str_replace('index.php', '', $_SERVER['PHP_SELF']), '/').$path;
}
function path_main($path = ''){ return rtrim(BASE_PATH.'/'.ltrim($path, '/'), '/'); }
function asset($path = '', $findInSharedAssets = false){ return path_asset_url($path, $findInSharedAssets); }
function path_asset_url($path = '', $findInSharedAssets = false){
if($findInSharedAssets) return path_shared_asset_url($path);
return path_main_url().'/resources/assets'.((!empty($path))? '/'.trim($path, '/'): '');
}
function path_asset($path = '') { return rtrim(str_replace('index.php', '', $_SERVER['SCRIPT_FILENAME']), '/').'/resources/assets'.((!empty($path))? '/'.trim($path, '/'): ''); }
function path_app($path = ''){ return rtrim(PATH_APP.ltrim($path, '/'), '/'); }
function path_shared($path = '', $directory = ''){ return (!empty($path))? PATH_SHARED.$directory.'/'.ltrim($path, '/'): PATH_SHARED.$directory; }
function path_shared_resources($path = ''){ return path_shared($path, 'resources'); }
function path_shared_app($path = ''){ return path_shared($path, 'app'); }
function path_shared_asset($path = ''){ return path_shared($path, 'resources/assets'); }
function path_shared_asset_url($path = ''){
if(String1::startsWith(Config1::INCLUDES_PATH, '../')){
$shared_link_path = path_asset()."/shared/assets";
if(!is_link($shared_link_path)){ Session1::setStatus('Shared Assets Linked', ['Link Successfully Created', Url1::createSymLinks(path_shared_asset(), $shared_link_path)]); }
}else{
$shared_link_path = PATH_SHARED_RESOURCE.'/assets';
}
return Url1::pathToUrl($shared_link_path).( (empty($path)? '': '/'.trim($path, '/')));
}
function shared_asset($path = ''){ return (path_shared_asset_url($path)); }
function path_clear_cache(){
$all_link_path = [ path_asset()."/shared", resources_path_view_cache()];
@session_destroy();
foreach(array_merge($all_link_path) as $path) {
@unlink(FileManager1::normalizeFilePathSeparator($path));
@rmdir(FileManager1::normalizeFilePathSeparator($path));
}
@mkdir(resources_path_view_cache());
Session1::setStatus('Session and All Path File Deleted', array_merge($all_link_path));
}