Browse Source

Merge pull request #132 from Kanti/master

prepare for version 2.5
pull/146/merge
Kanti 11 years ago
parent
commit
936a084a07
5 changed files with 342 additions and 341 deletions
  1. +2
    -2
      cache/installedVersion.json
  2. +9
    -8
      system/admin/admin.php
  3. +4
    -4
      system/htmly.php
  4. +316
    -316
      system/includes/dispatch.php
  5. +11
    -11
      system/upgrade/run.php

+ 2
- 2
cache/installedVersion.json View File

@ -1,4 +1,4 @@
{ {
"id": 587750,
"tag_name": "v2.4"
"id": 782014,
"tag_name": "v2.5"
} }

+ 9
- 8
system/admin/admin.php View File

@ -13,12 +13,13 @@ function user($key, $user = null)
} }
} }
function create_user($userName, $password){
function create_user($userName, $password)
{
$file = 'config/users/' . $userName . '.ini'; $file = 'config/users/' . $userName . '.ini';
if(file_exists($file)) {
if (file_exists($file)) {
return false; return false;
} else { } else {
file_put_contents($file,"password = " . hash("sha512",$password) . "\n" .
file_put_contents($file, "password = " . hash("sha512", $password) . "\n" .
"encryption = sha512\n" . "encryption = sha512\n" .
"role = user\n"); "role = user\n");
return true; return true;
@ -26,7 +27,7 @@ function create_user($userName, $password){
} }
// Create a session // Create a session
function session($user, $pass, $str = null)
function session($user, $pass)
{ {
$user_file = 'config/users/' . $user . '.ini'; $user_file = 'config/users/' . $user . '.ini';
$user_enc = user('encryption', $user); $user_enc = user('encryption', $user);
@ -50,7 +51,7 @@ function remove_accent($str)
{ {
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', '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ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
$b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o'); $b = array('A', 'A', 'A', 'A', 'A', 'A', 'AE', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'D', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'ae', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'a', 'A', 'a', 'A', 'a', 'C', 'c', 'C', 'c', 'C', 'c', 'C', 'c', 'D', 'd', 'D', 'd', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'E', 'e', 'G', 'g', 'G', 'g', 'G', 'g', 'G', 'g', 'H', 'h', 'H', 'h', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'I', 'i', 'IJ', 'ij', 'J', 'j', 'K', 'k', 'L', 'l', 'L', 'l', 'L', 'l', 'L', 'l', 'l', 'l', 'N', 'n', 'N', 'n', 'N', 'n', 'n', 'O', 'o', 'O', 'o', 'O', 'o', 'OE', 'oe', 'R', 'r', 'R', 'r', 'R', 'r', 'S', 's', 'S', 's', 'S', 's', 'S', 's', 'T', 't', 'T', 't', 'T', 't', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'W', 'w', 'Y', 'y', 'Y', 'Z', 'z', 'Z', 'z', 'Z', 'z', 's', 'f', 'O', 'o', 'U', 'u', 'A', 'a', 'I', 'i', 'O', 'o', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'U', 'u', 'A', 'a', 'AE', 'ae', 'O', 'o');
$cyr = array('ж', 'ч', 'щ', 'ш', 'ю', 'а', 'б', 'в', 'г', 'д', 'e', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я', 'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
$cyr = array('ж', 'ч', 'щ', 'ш', 'ю', 'а', 'б', 'в', 'г', 'д', 'e', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я', 'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
$lat = array('zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'y', 'x', 'q', 'Zh', 'Ch', 'Sht', 'Sh', 'Yu', 'A', 'B', 'V', 'G', 'D', 'E', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'c', 'Y', 'X', 'Q'); $lat = array('zh', 'ch', 'sht', 'sh', 'yu', 'a', 'b', 'v', 'g', 'd', 'e', 'z', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'y', 'x', 'q', 'Zh', 'Ch', 'Sht', 'Sh', 'Yu', 'A', 'B', 'V', 'G', 'D', 'E', 'Z', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'c', 'Y', 'X', 'Q');
$a = array_merge($a, $cyr); $a = array_merge($a, $cyr);
$b = array_merge($b, $lat); $b = array_merge($b, $lat);
@ -61,8 +62,8 @@ function remove_accent($str)
function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null) function edit_post($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null)
{ {
$oldurl = explode('_', $oldfile); $oldurl = explode('_', $oldfile);
if($date !== null) {
$oldurl[0] = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/' . date('Y-m-d-h-i-s',strtotime($date));
if ($date !== null) {
$oldurl[0] = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/' . date('Y-m-d-h-i-s', strtotime($date));
} }
$post_title = $title; $post_title = $title;
@ -362,7 +363,7 @@ function migrate($title, $time, $tags, $content, $url, $user, $source)
} }
// Fetch RSS feed // Fetch RSS feed
function get_feed($feed_url, $credit, $message = null)
function get_feed($feed_url, $credit)
{ {
$source = file_get_contents($feed_url); $source = file_get_contents($feed_url);
$feed = new SimpleXmlElement($source); $feed = new SimpleXmlElement($source);


+ 4
- 4
system/htmly.php View File

@ -64,8 +64,8 @@ post('/login', function () {
$pass = from($_REQUEST, 'password'); $pass = from($_REQUEST, 'password');
if ($proper && $captcha && !empty($user) && !empty($pass)) { if ($proper && $captcha && !empty($user) && !empty($pass)) {
session($user, $pass, null);
$log = session($user, $pass, null);
session($user, $pass);
$log = session($user, $pass);
if (!empty($log)) { if (!empty($log)) {
@ -997,8 +997,8 @@ post('/admin/import', function () {
$credit = from($_REQUEST, 'credit'); $credit = from($_REQUEST, 'credit');
if (!empty($url)) { if (!empty($url)) {
get_feed($url, $credit, null);
$log = get_feed($url, $credit, null);
get_feed($url, $credit);
$log = get_feed($url, $credit);
if (!empty($log)) { if (!empty($log)) {


+ 316
- 316
system/includes/dispatch.php View File

@ -1,531 +1,531 @@
<?php <?php
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
error(500, 'dispatch requires at least PHP 5.3 to run.');
error(500, 'dispatch requires at least PHP 5.3 to run.');
} }
function _log($message) function _log($message)
{ {
if (config('debug.enable') == true && php_sapi_name() !== 'cli') {
$file = config('debug.log');
$type = $file ? 3 : 0;
error_log("{$message}\n", $type, $file);
}
if (config('debug.enable') == true && php_sapi_name() !== 'cli') {
$file = config('debug.log');
$type = $file ? 3 : 0;
error_log("{$message}\n", $type, $file);
}
} }
function site_url() function site_url()
{ {
if (config('site.url') == null)
error(500, '[site.url] is not set');
if (config('site.url') == null)
error(500, '[site.url] is not set');
// Forcing the forward slash
return rtrim(config('site.url'),'/').'/';
// Forcing the forward slash
return rtrim(config('site.url'), '/') . '/';
} }
function site_path() function site_path()
{ {
static $_path;
static $_path;
if (config('site.url') == null)
error(500, '[site.url] is not set');
if (config('site.url') == null)
error(500, '[site.url] is not set');
if (!$_path)
$_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH),'/');
if (!$_path)
$_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH), '/');
return $_path;
return $_path;
} }
function error($code, $message) function error($code, $message)
{ {
@header("HTTP/1.0 {$code} {$message}", true, $code);
die($message);
@header("HTTP/1.0 {$code} {$message}", true, $code);
die($message);
} }
function config($key, $value = null) function config($key, $value = null)
{ {
static $_config = array();
static $_config = array();
if ($key === 'source' && file_exists($value))
$_config = parse_ini_file($value, true);
elseif ($value == null)
return (isset($_config[$key]) ? $_config[$key] : null);
else
$_config[$key] = $value;
if ($key === 'source' && file_exists($value))
$_config = parse_ini_file($value, true);
elseif ($value == null)
return (isset($_config[$key]) ? $_config[$key] : null);
else
$_config[$key] = $value;
} }
function to_b64($str) function to_b64($str)
{ {
$str = base64_encode($str);
$str = preg_replace('/\//', '_', $str);
$str = preg_replace('/\+/', '.', $str);
$str = preg_replace('/\=/', '-', $str);
return trim($str, '-');
$str = base64_encode($str);
$str = preg_replace('/\//', '_', $str);
$str = preg_replace('/\+/', '.', $str);
$str = preg_replace('/\=/', '-', $str);
return trim($str, '-');
} }
function from_b64($str) function from_b64($str)
{ {
$str = preg_replace('/\_/', '/', $str);
$str = preg_replace('/\./', '+', $str);
$str = preg_replace('/\-/', '=', $str);
$str = base64_decode($str);
return $str;
$str = preg_replace('/\_/', '/', $str);
$str = preg_replace('/\./', '+', $str);
$str = preg_replace('/\-/', '=', $str);
$str = base64_decode($str);
return $str;
} }
if (extension_loaded('mcrypt')) { if (extension_loaded('mcrypt')) {
function encrypt($decoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
{
if (($secret = config('cookies.secret')) == null)
error(500, '[cookies.secret] is not set');
function encrypt($decoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
{
if (($secret = config('cookies.secret')) == null)
error(500, '[cookies.secret] is not set');
$secret = mb_substr($secret, 0, mcrypt_get_key_size($algo, $mode));
$iv_size = mcrypt_get_iv_size($algo, $mode);
$iv_code = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
$encrypted = to_b64(mcrypt_encrypt($algo, $secret, $decoded, $mode, $iv_code));
$secret = mb_substr($secret, 0, mcrypt_get_key_size($algo, $mode));
$iv_size = mcrypt_get_iv_size($algo, $mode);
$iv_code = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
$encrypted = to_b64(mcrypt_encrypt($algo, $secret, $decoded, $mode, $iv_code));
return sprintf('%s|%s', $encrypted, to_b64($iv_code));
}
return sprintf('%s|%s', $encrypted, to_b64($iv_code));
}
function decrypt($encoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
{
if (($secret = config('cookies.secret')) == null)
error(500, '[cookies.secret] is not set');
function decrypt($encoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
{
if (($secret = config('cookies.secret')) == null)
error(500, '[cookies.secret] is not set');
$secret = mb_substr($secret, 0, mcrypt_get_key_size($algo, $mode));
list($enc_str, $iv_code) = explode('|', $encoded);
$enc_str = from_b64($enc_str);
$iv_code = from_b64($iv_code);
$enc_str = mcrypt_decrypt($algo, $secret, $enc_str, $mode, $iv_code);
$secret = mb_substr($secret, 0, mcrypt_get_key_size($algo, $mode));
list($enc_str, $iv_code) = explode('|', $encoded);
$enc_str = from_b64($enc_str);
$iv_code = from_b64($iv_code);
$enc_str = mcrypt_decrypt($algo, $secret, $enc_str, $mode, $iv_code);
return rtrim($enc_str, "\0");
}
return rtrim($enc_str, "\0");
}
} }
function set_cookie($name, $value, $expire = 31536000, $path = '/') function set_cookie($name, $value, $expire = 31536000, $path = '/')
{ {
$value = (function_exists('encrypt') ? encrypt($value) : $value);
setcookie($name, $value, time() + $expire, $path);
$value = (function_exists('encrypt') ? encrypt($value) : $value);
setcookie($name, $value, time() + $expire, $path);
} }
function get_cookie($name) function get_cookie($name)
{ {
$value = from($_COOKIE, $name);
$value = from($_COOKIE, $name);
if ($value)
$value = (function_exists('decrypt') ? decrypt($value) : $value);
if ($value)
$value = (function_exists('decrypt') ? decrypt($value) : $value);
return $value;
return $value;
} }
function delete_cookie() function delete_cookie()
{ {
$cookies = func_get_args();
foreach ($cookies as $ck)
setcookie($ck, '', -10, '/');
$cookies = func_get_args();
foreach ($cookies as $ck)
setcookie($ck, '', -10, '/');
} }
// if we have APC loaded, enable cache functions // if we have APC loaded, enable cache functions
if (extension_loaded('apc')) { if (extension_loaded('apc')) {
function cache($key, $func, $ttl = 0)
{
if (($data = apc_fetch($key)) === false) {
$data = call_user_func($func);
if ($data !== null) {
apc_store($key, $data, $ttl);
}
function cache($key, $func, $ttl = 0)
{
if (($data = apc_fetch($key)) === false) {
$data = call_user_func($func);
if ($data !== null) {
apc_store($key, $data, $ttl);
}
}
return $data;
} }
return $data;
}
function cache_invalidate()
{
foreach (func_get_args() as $key) {
apc_delete($key);
function cache_invalidate()
{
foreach (func_get_args() as $key) {
apc_delete($key);
}
} }
}
} }
function warn($name = null, $message = null) function warn($name = null, $message = null)
{ {
static $warnings = array();
static $warnings = array();
if ($name == '*')
return $warnings;
if ($name == '*')
return $warnings;
if (!$name)
return count(array_keys($warnings));
if (!$name)
return count(array_keys($warnings));
if (!$message)
return isset($warnings[$name]) ? $warnings[$name] : null ;
if (!$message)
return isset($warnings[$name]) ? $warnings[$name] : null;
$warnings[$name] = $message;
$warnings[$name] = $message;
} }
function _u($str) function _u($str)
{ {
return urlencode($str);
return urlencode($str);
} }
function _h($str, $enc = 'UTF-8', $flags = ENT_QUOTES) function _h($str, $enc = 'UTF-8', $flags = ENT_QUOTES)
{ {
return htmlentities($str, $flags, $enc);
return htmlentities($str, $flags, $enc);
} }
function from($source, $name) function from($source, $name)
{ {
if (is_array($name)) {
$data = array();
foreach ($name as $k)
$data[$k] = isset($source[$k]) ? $source[$k] : null ;
return $data;
}
return isset($source[$name]) ? $source[$name] : null ;
if (is_array($name)) {
$data = array();
foreach ($name as $k)
$data[$k] = isset($source[$k]) ? $source[$k] : null;
return $data;
}
return isset($source[$name]) ? $source[$name] : null;
} }
function stash($name, $value = null) function stash($name, $value = null)
{ {
static $_stash = array();
static $_stash = array();
if ($value === null)
return isset($_stash[$name]) ? $_stash[$name] : null;
if ($value === null)
return isset($_stash[$name]) ? $_stash[$name] : null;
$_stash[$name] = $value;
$_stash[$name] = $value;
return $value;
return $value;
} }
function method($verb = null) function method($verb = null)
{ {
if ($verb == null || (strtoupper($verb) == strtoupper($_SERVER['REQUEST_METHOD'])))
return strtoupper($_SERVER['REQUEST_METHOD']);
if ($verb == null || (strtoupper($verb) == strtoupper($_SERVER['REQUEST_METHOD'])))
return strtoupper($_SERVER['REQUEST_METHOD']);
error(400, 'bad request');
error(400, 'bad request');
} }
function client_ip() function client_ip()
{ {
if (isset($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
return $_SERVER['HTTP_X_FORWARDED_FOR'];
if (isset($_SERVER['HTTP_CLIENT_IP']))
return $_SERVER['HTTP_CLIENT_IP'];
elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR']))
return $_SERVER['HTTP_X_FORWARDED_FOR'];
return $_SERVER['REMOTE_ADDR'];
return $_SERVER['REMOTE_ADDR'];
} }
function redirect(/* $code_or_path, $path_or_cond, $cond */) function redirect(/* $code_or_path, $path_or_cond, $cond */)
{ {
$argv = func_get_args();
$argc = count($argv);
$path = null;
$code = 302;
$cond = true;
switch ($argc) {
case 3:
list($code, $path, $cond) = $argv;
break;
case 2:
if (is_string($argv[0]) ? $argv[0] : $argv[1]) {
$code = 302;
$path = $argv[0];
$cond = $argv[1];
} else {
$code = $argv[0];
$path = $argv[1];
}
break;
case 1:
if (!is_string($argv[0]))
error(500, 'bad call to redirect()');
$path = $argv[0];
break;
default:
error(500, 'bad call to redirect()');
}
$cond = (is_callable($cond) ? !!call_user_func($cond) : !!$cond);
if (!$cond)
return;
header('Location: '.$path, true, $code);
exit;
$argv = func_get_args();
$argc = count($argv);
$path = null;
$code = 302;
$cond = true;
switch ($argc) {
case 3:
list($code, $path, $cond) = $argv;
break;
case 2:
if (is_string($argv[0]) ? $argv[0] : $argv[1]) {
$code = 302;
$path = $argv[0];
$cond = $argv[1];
} else {
$code = $argv[0];
$path = $argv[1];
}
break;
case 1:
if (!is_string($argv[0]))
error(500, 'bad call to redirect()');
$path = $argv[0];
break;
default:
error(500, 'bad call to redirect()');
}
$cond = (is_callable($cond) ? !!call_user_func($cond) : !!$cond);
if (!$cond)
return;
header('Location: ' . $path, true, $code);
exit;
} }
function partial($view, $locals = null) function partial($view, $locals = null)
{ {
if (is_array($locals) && count($locals)) {
extract($locals, EXTR_SKIP);
}
if (is_array($locals) && count($locals)) {
extract($locals, EXTR_SKIP);
}
if (($view_root = config('views.root')) == null)
error(500, "[views.root] is not set");
if (($view_root = config('views.root')) == null)
error(500, "[views.root] is not set");
$path = basename($view);
$view = preg_replace('/'.$path.'$/', "_{$path}", $view);
$view = "{$view_root}/{$view}.html.php";
$path = basename($view);
$view = preg_replace('/' . $path . '$/', "_{$path}", $view);
$view = "{$view_root}/{$view}.html.php";
if (file_exists($view)) {
ob_start();
require $view;
return ob_get_clean();
} else {
error(500, "partial [{$view}] not found");
}
if (file_exists($view)) {
ob_start();
require $view;
return ob_get_clean();
} else {
error(500, "partial [{$view}] not found");
}
return '';
return '';
} }
function content($value = null) function content($value = null)
{ {
return stash('$content$', $value);
return stash('$content$', $value);
} }
function render($view, $locals = null, $layout = null) function render($view, $locals = null, $layout = null)
{ {
$login = login();
if(!$login) {
$c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI']));
$dir = 'cache/page';
$cachefile = $dir. '/' . $c . '.cache';
if(is_dir($dir) === false) {
mkdir($dir, 0777, true);
}
}
$login = login();
if (!$login) {
$c = str_replace('/', '#', str_replace('?', '~', $_SERVER['REQUEST_URI']));
$dir = 'cache/page';
$cachefile = $dir . '/' . $c . '.cache';
if (is_dir($dir) === false) {
mkdir($dir, 0777, true);
}
}
if (is_array($locals) && count($locals)) {
extract($locals, EXTR_SKIP);
}
if (is_array($locals) && count($locals)) {
extract($locals, EXTR_SKIP);
}
if (($view_root = config('views.root')) == null)
error(500, "[views.root] is not set");
if (($view_root = config('views.root')) == null)
error(500, "[views.root] is not set");
ob_start();
include "{$view_root}/{$view}.html.php";
content(trim(ob_get_clean()));
ob_start();
include "{$view_root}/{$view}.html.php";
content(trim(ob_get_clean()));
if ($layout !== false) {
if ($layout !== false) {
if ($layout == null) {
$layout = config('views.layout');
$layout = ($layout == null) ? 'layout' : $layout;
}
if ($layout == null) {
$layout = config('views.layout');
$layout = ($layout == null) ? 'layout' : $layout;
}
$layout = "{$view_root}/{$layout}.html.php";
$layout = "{$view_root}/{$layout}.html.php";
header('Content-type: text/html; charset=utf-8');
header('Content-type: text/html; charset=utf-8');
ob_start();
require $layout;
ob_start();
require $layout;
if(!$login) {
if (!file_exists($cachefile)) {
file_put_contents($cachefile, ob_get_contents());
}
}
if (!$login) {
if (!file_exists($cachefile)) {
file_put_contents($cachefile, ob_get_contents());
}
}
echo trim(ob_get_clean());
} else {
echo content();
}
echo trim(ob_get_clean());
} else {
echo content();
}
} }
function json($obj, $code = 200) function json($obj, $code = 200)
{ {
header('Content-type: application/json', true, $code);
echo json_encode($obj);
exit;
header('Content-type: application/json', true, $code);
echo json_encode($obj);
exit;
} }
function condition() function condition()
{ {
static $cb_map = array();
static $cb_map = array();
$argv = func_get_args();
$argc = count($argv);
$argv = func_get_args();
$argc = count($argv);
if (!$argc)
error(500, 'bad call to condition()');
if (!$argc)
error(500, 'bad call to condition()');
$name = array_shift($argv);
$argc = $argc - 1;
$name = array_shift($argv);
$argc = $argc - 1;
if (!$argc && is_callable($cb_map[$name]))
return call_user_func($cb_map[$name]);
if (!$argc && is_callable($cb_map[$name]))
return call_user_func($cb_map[$name]);
if (is_callable($argv[0]))
return ($cb_map[$name] = $argv[0]);
if (is_callable($argv[0]))
return ($cb_map[$name] = $argv[0]);
if (is_callable($cb_map[$name]))
return call_user_func_array($cb_map[$name], $argv);
if (is_callable($cb_map[$name]))
return call_user_func_array($cb_map[$name], $argv);
error(500, 'condition ['.$name.'] is undefined');
error(500, 'condition [' . $name . '] is undefined');
} }
function middleware($cb_or_path = null) function middleware($cb_or_path = null)
{ {
static $cb_map = array();
static $cb_map = array();
if ($cb_or_path == null || is_string($cb_or_path)) {
foreach ($cb_map as $cb) {
call_user_func($cb, $cb_or_path);
if ($cb_or_path == null || is_string($cb_or_path)) {
foreach ($cb_map as $cb) {
call_user_func($cb, $cb_or_path);
}
} else {
array_push($cb_map, $cb_or_path);
} }
} else {
array_push($cb_map, $cb_or_path);
}
} }
function filter($sym, $cb_or_val = null) function filter($sym, $cb_or_val = null)
{ {
static $cb_map = array();
if (is_callable($cb_or_val)) {
$cb_map[$sym] = $cb_or_val;
return;
}
if (is_array($sym) && count($sym) > 0) {
foreach ($sym as $s) {
$s = substr($s, 1);
if (isset($cb_map[$s]) && isset($cb_or_val[$s]))
call_user_func($cb_map[$s], $cb_or_val[$s]);
static $cb_map = array();
if (is_callable($cb_or_val)) {
$cb_map[$sym] = $cb_or_val;
return;
}
if (is_array($sym) && count($sym) > 0) {
foreach ($sym as $s) {
$s = substr($s, 1);
if (isset($cb_map[$s]) && isset($cb_or_val[$s]))
call_user_func($cb_map[$s], $cb_or_val[$s]);
}
return;
} }
return;
}
error(500, 'bad call to filter()');
error(500, 'bad call to filter()');
} }
function route_to_regex($route) function route_to_regex($route)
{ {
$route = preg_replace_callback('@:[\w]+@i', function ($matches) {
$token = str_replace(':', '', $matches[0]);
return '(?P<'.$token.'>[a-z0-9_\0-\.]+)';
}, $route);
return '@^'.rtrim($route, '/').'$@i';
$route = preg_replace_callback('@:[\w]+@i', function ($matches) {
$token = str_replace(':', '', $matches[0]);
return '(?P<' . $token . '>[a-z0-9_\0-\.]+)';
}, $route);
return '@^' . rtrim($route, '/') . '$@i';
} }
function route($method, $pattern, $callback = null) function route($method, $pattern, $callback = null)
{ {
// callback map by request type
static $route_map = array(
'GET' => array(),
'POST' => array()
);
// callback map by request type
static $route_map = array(
'GET' => array(),
'POST' => array()
);
$method = strtoupper($method);
$method = strtoupper($method);
if (!in_array($method, array('GET', 'POST')))
error(500, 'Only GET and POST are supported');
if (!in_array($method, array('GET', 'POST')))
error(500, 'Only GET and POST are supported');
// a callback was passed, so we create a route defiition
if ($callback !== null) {
// a callback was passed, so we create a route defiition
if ($callback !== null) {
// create a route entry for this pattern
$route_map[$method][$pattern] = array(
'xp' => route_to_regex($pattern),
'cb' => $callback
);
// create a route entry for this pattern
$route_map[$method][$pattern] = array(
'xp' => route_to_regex($pattern),
'cb' => $callback
);
} else {
} else {
// callback is null, so this is a route invokation. look up the callback.
foreach ($route_map[$method] as $pat => $obj) {
// callback is null, so this is a route invokation. look up the callback.
foreach ($route_map[$method] as $pat => $obj) {
// if the requested uri ($pat) has a matching route, let's invoke the cb
if (!preg_match($obj['xp'], $pattern, $vals))
continue;
// if the requested uri ($pat) has a matching route, let's invoke the cb
if (!preg_match($obj['xp'], $pattern, $vals))
continue;
// call middleware
middleware($pattern);
// call middleware
middleware($pattern);
// construct the params for the callback
array_shift($vals);
preg_match_all('@:([\w]+)@', $pat, $keys, PREG_PATTERN_ORDER);
$keys = array_shift($keys);
$argv = array();
// construct the params for the callback
array_shift($vals);
preg_match_all('@:([\w]+)@', $pat, $keys, PREG_PATTERN_ORDER);
$keys = array_shift($keys);
$argv = array();
foreach ($keys as $index => $id) {
$id = substr($id, 1);
if (isset($vals[$id])) {
array_push($argv, trim(urldecode($vals[$id])));
}
}
foreach ($keys as $index => $id) {
$id = substr($id, 1);
if (isset($vals[$id])) {
array_push($argv, trim(urldecode($vals[$id])));
}
}
// call filters if we have symbols
if (count($keys)) {
filter(array_values($keys), $vals);
}
// call filters if we have symbols
if (count($keys)) {
filter(array_values($keys), $vals);
}
// if cb found, invoke it
if (is_callable($obj['cb'])) {
call_user_func_array($obj['cb'], $argv);
}
// if cb found, invoke it
if (is_callable($obj['cb'])) {
call_user_func_array($obj['cb'], $argv);
}
// leave after first match
break;
// leave after first match
break;
}
} }
}
} }
function get($path, $cb) function get($path, $cb)
{ {
route('GET', $path, $cb);
route('GET', $path, $cb);
} }
function post($path, $cb) function post($path, $cb)
{ {
route('POST', $path, $cb);
route('POST', $path, $cb);
} }
function flash($key, $msg = null, $now = false) function flash($key, $msg = null, $now = false)
{ {
static $x = array(),
$f = null;
static $x = array(),
$f = null;
$f = (config('cookies.flash') ? config('cookies.flash') : '_F');
$f = (config('cookies.flash') ? config('cookies.flash') : '_F');
if ($c = get_cookie($f))
$c = json_decode($c, true);
else
$c = array();
if ($c = get_cookie($f))
$c = json_decode($c, true);
else
$c = array();
if ($msg == null) {
if ($msg == null) {
if (isset($c[$key])) {
$x[$key] = $c[$key];
unset($c[$key]);
set_cookie($f, json_encode($c));
}
if (isset($c[$key])) {
$x[$key] = $c[$key];
unset($c[$key]);
set_cookie($f, json_encode($c));
}
return (isset($x[$key]) ? $x[$key] : null);
}
return (isset($x[$key]) ? $x[$key] : null);
}
if (!$now) {
$c[$key] = $msg;
set_cookie($f, json_encode($c));
}
if (!$now) {
$c[$key] = $msg;
set_cookie($f, json_encode($c));
}
$x[$key] = $msg;
$x[$key] = $msg;
} }
function dispatch() function dispatch()
{ {
$path = urldecode($_SERVER['REQUEST_URI']);
$path = urldecode($_SERVER['REQUEST_URI']);
if (config('site.url') !== null)
$path = preg_replace('@^'.preg_quote(site_path()).'@', '', $path);
if (config('site.url') !== null)
$path = preg_replace('@^' . preg_quote(site_path()) . '@', '', $path);
$parts = preg_split('/\?/', $path, -1, PREG_SPLIT_NO_EMPTY);
$parts = preg_split('/\?/', $path, -1, PREG_SPLIT_NO_EMPTY);
$uri = trim($parts[0], '/');
$uri = strlen($uri) ? $uri : 'index';
$uri = trim($parts[0], '/');
$uri = strlen($uri) ? $uri : 'index';
route(method(), "/{$uri}");
route(method(), "/{$uri}");
} }

+ 11
- 11
system/upgrade/run.php View File

@ -2,20 +2,22 @@
$updater = new Kanti\HubUpdater("danpros/htmly"); $updater = new Kanti\HubUpdater("danpros/htmly");
$info = $updater->getCurrentInfo(); $info = $updater->getCurrentInfo();
$versionNumber = substr($info['tag_name'],1);
$versionNumber = substr($info['tag_name'], 1);
function isGraterThan($string){
function isGraterThan($string)
{
global $versionNumber; global $versionNumber;
return (version_compare($versionNumber,$string) > 0);
return (version_compare($versionNumber, $string) > 0);
} }
// http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir // http://stackoverflow.com/questions/3338123/how-do-i-recursively-delete-a-directory-and-its-entire-contents-files-sub-dir
function rrmdir($dir) {
function rrmdir($dir)
{
if (is_dir($dir)) { if (is_dir($dir)) {
$objects = scandir($dir); $objects = scandir($dir);
foreach ($objects as $object) { foreach ($objects as $object) {
if ($object != "." && $object != "..") { if ($object != "." && $object != "..") {
if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
if (filetype($dir . "/" . $object) == "dir") rrmdir($dir . "/" . $object); else unlink($dir . "/" . $object);
} }
} }
reset($objects); reset($objects);
@ -24,13 +26,11 @@ function rrmdir($dir) {
} }
//run upgrade specific stuff //run upgrade specific stuff
if(isGraterThan("2.3")) {// 2.4, 2.5, ...
if(file_exists("vendor/")){
if (isGraterThan("2.3")) {// 2.4, 2.5, ...
if (file_exists("vendor/")) {
rrmdir("vendor/"); rrmdir("vendor/");
} }
} }
if(isGraterThan("2.3")) {
file_put_contents("index.php",file_get_contents("system/upgrade/index.php"));
rrmdir("system/upgrade/");
}
file_put_contents("index.php", file_get_contents("system/upgrade/index.php"));
rrmdir("system/upgrade/");

Loading…
Cancel
Save