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:
<?php
function ddie($var = NULL) {
echo '<pre>';
var_dump($var);
die();
}
function ppie($var = NULL) {
print_r($var);
die();
}
function php($php, $return = FALSE) {
if (!$return) {
echo '<?php ' . $php . ' ?>';
} else {
return '<?php ' . $php . ' ?>';
}
}
register_shutdown_function(function() {
require_once __ROOT__ . '/app/Kernel/Dispatch/Logger.php';
$error = error_get_last();
if($error !== NULL) {
\Kernel\Dispatch\Logger::error($error);
}
});
spl_autoload_register(function($className) {
$exploded = explode('\\', $className);
if(count($exploded) == 1) {
$namespace = "";
$name = $exploded[0];
} else {
list($namespace, $name) = $exploded;
}
$root = __ROOT__;
if ($namespace) {
if (file_exists($req = $root . '/app/Kernel/' . $name . '.php')) {
} elseif (file_exists($req = $root . '/app/controllers/' . $name . '.php')) {
} elseif (file_exists($req = $root . '/app/models/' . $name . '.php')) {
} else {
return false;
}
} else {
if (file_exists($req = $root . '/src/controllers/' . $name . '.php')) {
} elseif (file_exists($req = $root . '/src/models/' . $name . '.php')) {
} else {
return false;
}
}
require_once $req;
return TRUE;
});
function email_png($text, $size = array(175, 20), $color = array(50, 50, 50)) {
header('Content-type: image/png');
$im = imagecreate($size[0], $size[1]);
$white = imagecolorallocate($im, 255, 255, 255);
$color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
imagestring($im, 5, 0, 0, $text, $color);
imagepng($im);
imagedestroy($im);
}
function clock_start($key = 'main') {
$time = explode(' ', microtime());
$start = (float)$time[0] + (float)$time[1];
$GLOBALS['_clock_'][$key]['start'] = $start;
return $start;
}
function clock_end($key = 'main') {
if (!$GLOBALS['_clock_'][$key]) {
return 0;
}
$time = explode(' ', microtime());
$end = (float)$time[0] + (float)$time[1];
$GLOBALS['_clock_'][$key]['end'] = $end;
return $end;
}
function clock_time($key = 'main', $all = false) {
if (!empty($GLOBALS['_clock_'][$key]['end'])) {
return -1;
}
$GLOBALS['_clock_'][$key]['diff'] = $GLOBALS['_clock_'][$key]['end'] - $GLOBALS['_clock_'][$key]['start'];
if (!$all) {
return $GLOBALS['_clock_'][$key]['diff'];
} else {
return [
'start' => $GLOBALS['_clock_'][$key]['start'],
'end' => $GLOBALS['_clock_'][$key]['end'],
'diff' => $GLOBALS['_clock_'][$key]['diff']
];
}
}
function save_ini_file($assoc_arr, $has_sections=FALSE, $path) {
if (empty($assoc_arr) || !count($assoc_arr)) {
return ['success' => 0, 'reason' => "Array is empty. You might not have any active plugins"];
}
$content = "";
if ($has_sections) {
foreach ($assoc_arr as $key => $elem) {
$content .= "[" . $key . "]\n";
foreach ($elem as $key2 => $elem2) {
if(is_array($elem2)) {
for( $i = 0; $i < count($elem2); ++$i) {
$content .= $key2 . "[] = \"" . $elem2[$i]."\"\n";
}
}
elseif ($elem2=="") {
$content .= $key2." = \"\"\n";
} else {
$content .= $key2." = \"".$elem2."\"\n";
}
}
$content .= "\n";
}
} else {
foreach ($assoc_arr as $key2 => $elem2) {
if(is_array($elem2)) {
for( $i = 0; $i < count($elem2); ++$i) {
$content .= " " . $key2 . "[] = \"" . $elem2[$i]."\"\n";
}
}
elseif ($elem2=="") {
$content .= $key2." = \"\"\n";
} else {
$content .= $key2." = \"".$elem2."\"\n";
}
$content .= "\n";
}
}
$handle = NULL;
if (!$handle = fopen($path, 'w')) {
return ['success' => 0, 'reason' => 'Cannot open handle "' . $path . '"'];
}
if (!fwrite($handle, $content)) {
return ['success' => 0, 'reason' => 'Cannot write $content into "' . $path . '"'];
}
fclose($handle);
if (function_exists('shell_exec')) {
shell_exec('chmod 666 ' . $path);
}
return ['success' => 1];
}
function getClientIP() {
if (isset($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
else if (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
return $_SERVER['HTTP_X_FORWARDED_FOR'];
return $_SERVER['REMOTE_ADDR'];
}
function getClientUserAgent() {
if (isset($_SERVER['HTTP_USER_AGENT'])) {
return $_SERVER['HTTP_USER_AGENT'];
} else {
return "";
}
}
function nocache() {
header('Expires: Tue, 13 Mar 1979 18:00:00 GMT');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
}
function folder_recurse($src,$dst, $action = 'copy') {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
folder_recurse($src . '/' . $file,$dst . '/' . $file, $action);
}
else {
$action($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
function deleteDir($dirPath) {
if (! is_dir($dirPath)) {
throw new InvalidArgumentException("$dirPath must be a directory");
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
}