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:
<?php
DEFINE ('FW_UPDATE_HOST', 'http://kupfer.es/core');
DEFINE ('FW_UPDATE_ROUTE', '/_versioncheck');
DEFINE ('FW_UPDATEGET_ROUTE', '/_versionget');
DEFINE ('FW_TOKEN', 'fwRW7w3i8aHg4N315cCGgKi5mqCc3E');
DEFINE ('FW_VERSION', getVersion());
function getVersion() {
if (!file_exists(__ROOT__ . '/app/bootload/CHANGELOG.txt')) {
return '0.0.0';
}
$changelog = file_get_contents(__ROOT__ . '/app/bootload/CHANGELOG.txt');
preg_match("/\[([\d\.]+)\]/", $changelog, $matches);
return $matches[1];
}
function write_ini($assoc_arr, $has_sections=FALSE, $file = null) {
$content = "";
$path = is_null($file) ? self::$_file : $file;
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";
}
}
}
$handle = NULL;
if (!$handle = fopen($path, 'w')) {
return false;
}
if (!fwrite($handle, $content)) {
return false;
}
fclose($handle);
return true;
}
function query($db, $query, $params = array(), $fetchAll = FALSE) {
$res = $db->prepare($query);
$res->execute($params);
if ($fetchAll) {
return $res->fetchAll(PDO::FETCH_ASSOC);
} else {
return $res;
}
}
function queryIndexed($db, $query, $params = array(), $unique = TRUE) {
$res = $db->prepare($query);
$res->execute($params);
$rows = $res->fetchAll(PDO::FETCH_GROUP|PDO::FETCH_ASSOC);
if ($unique) {
return array_map('reset', $rows);
} else {
return $rows;
}
}
function asset($path) {
$extension = [
'css' => 'text/css',
'js' => 'text/javascript',
'png' => 'image/png',
'jpg' => 'image/jpg',
'gif' => 'image/gif'
];
header('Content-type: ' . $extension[array_pop(explode('.', $path))]);
readfile('assets/' . $path);
die();
}
function versioning($path) {
header('Content-type: text/plain');
readfile($path);
die();
}
function folder_action($action, $dst, $src = '') {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
folder_action($action, $dst . '/' . $file, $src . '/' . $file);
}
else {
switch ($action) {
case 'unlink':
unlink($dst . '/' . $file);
break;
default:
$action($src . '/' . $file, $dst . '/' . $file);
chmod($dst . '/'. $file, 0777);
break;
}
}
}
}
closedir($dir);
}
function _die($var, $die = true) {
echo "<pre>", var_export($var, true), "</pre>";
if ($die) die;
}