diff --git a/system/admin/admin.php b/system/admin/admin.php index fe17acd..21c9319 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -1,7 +1,8 @@ ' . "\n\n" . $content; @@ -311,8 +320,8 @@ function edit_profile($title, $content, $user) { } // Import RSS feed -function migrate($title, $time, $tags, $content, $url, $user, $source) { - +function migrate($title, $time, $tags, $content, $url, $user, $source) +{ $post_date = date('Y-m-d-H-i-s', $time); $post_title = $title; $post_tag = preg_replace(array('/[^a-zA-Z0-9,.\-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($tags)); @@ -341,7 +350,8 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) { } // Fetch RSS feed -function get_feed($feed_url, $credit, $message = null) { +function get_feed($feed_url, $credit, $message = null) +{ $source = file_get_contents($feed_url); $feed = new SimpleXmlElement($source); if (!empty($feed->channel->item)) { @@ -350,7 +360,7 @@ function get_feed($feed_url, $credit, $message = null) { $descriptionB = $entry->description; if (!empty($descriptionA)) { $content = $descriptionA; - } else if (!empty($descriptionB)) { + } elseif (!empty($descriptionB)) { $content = preg_replace('##i', "\n", $descriptionB); } else { return $str = '
  • Can not read the feed content.
  • '; @@ -376,7 +386,8 @@ function get_feed($feed_url, $credit, $message = null) { } // Get recent posts by user -function get_recent_posts() { +function get_recent_posts() +{ if (isset($_SESSION[config("site.url")]['user'])) { $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); if (!empty($posts)) { @@ -411,7 +422,8 @@ function get_recent_posts() { } // Get all static pages -function get_recent_pages() { +function get_recent_pages() +{ if (isset($_SESSION[config("site.url")]['user'])) { $posts = get_static_post(null); if (!empty($posts)) { @@ -458,7 +470,8 @@ function get_recent_pages() { } // Get all available zip files -function get_backup_files() { +function get_backup_files() +{ if (isset($_SESSION[config("site.url")]['user'])) { $files = get_zip_files(); if (!empty($files)) { @@ -505,8 +518,8 @@ function get_backup_files() { } } -function clear_post_cache($post_date, $post_tag, $post_url, $filename) { - +function clear_post_cache($post_date, $post_tag, $post_url, $filename) +{ $b = str_replace('/', '#', site_path() . '/'); $t = explode('-', $post_date); $c = explode(',', $post_tag); @@ -585,7 +598,8 @@ function clear_post_cache($post_date, $post_tag, $post_url, $filename) { } } -function clear_page_cache($url) { +function clear_page_cache($url) +{ $b = str_replace('/', '#', site_path() . '/'); $p = 'cache/page/' . $b . $url . '.cache'; if (file_exists($p)) { diff --git a/system/htmly.php b/system/htmly.php index 884a4b6..abb68e6 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -13,8 +13,7 @@ include 'system/includes/opml.php'; // Load the configuration file config('source', 'config/config.ini'); -if(config('timezone')) -{ +if(config('timezone')) { date_default_timezone_set(config('timezone')); } @@ -64,7 +63,7 @@ get('/index', function () { }); // Get submitted login data -post('/login', function() { +post('/login', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -111,7 +110,7 @@ post('/login', function() { } }); -get("/:static/:sub/edit", function($static, $sub) { +get("/:static/:sub/edit", function ($static, $sub) { if (login()) { @@ -144,7 +143,7 @@ get("/:static/:sub/edit", function($static, $sub) { header("location: $login"); } }); -post("/:static/:sub/edit", function($static, $sub) { +post("/:static/:sub/edit", function ($static, $sub) { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if (!login()) { @@ -194,7 +193,7 @@ post("/:static/:sub/edit", function($static, $sub) { } }); -get("/:static/:sub/delete", function($static, $sub) { +get("/:static/:sub/delete", function ($static, $sub) { if (login()) { @@ -227,7 +226,7 @@ get("/:static/:sub/delete", function($static, $sub) { header("location: $login"); } }); -post("/:static/:sub/delete", function() { +post("/:static/:sub/delete", function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if ($proper && login()) { @@ -238,7 +237,7 @@ post("/:static/:sub/delete", function() { }); // The blog post page -get('/:year/:month/:name', function($year, $month, $name) { +get('/:year/:month/:name', function ($year, $month, $name) { if (config("views.counter") != "true") { if (!login()) { @@ -295,7 +294,7 @@ get('/:year/:month/:name', function($year, $month, $name) { }); // Edit blog post -get('/:year/:month/:name/edit', function($year, $month, $name) { +get('/:year/:month/:name/edit', function ($year, $month, $name) { if (login()) { @@ -333,7 +332,7 @@ get('/:year/:month/:name/edit', function($year, $month, $name) { }); // Get edited data for blog post -post('/:year/:month/:name/edit', function() { +post('/:year/:month/:name/edit', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -347,11 +346,10 @@ post('/:year/:month/:name/edit', function() { $date = from($_REQUEST, 'date'); $time = from($_REQUEST, 'time'); $dateTime = null; - if($date !== null && $time !== null) - { + if($date !== null && $time !== null) { $dateTime = $date . ' ' . $time; } - + if ($proper && !empty($title) && !empty($tag) && !empty($content)) { if(empty($url)) { $url = $title; @@ -388,7 +386,7 @@ post('/:year/:month/:name/edit', function() { }); // Delete blog post -get('/:year/:month/:name/delete', function($year, $month, $name) { +get('/:year/:month/:name/delete', function ($year, $month, $name) { if (login()) { @@ -426,7 +424,7 @@ get('/:year/:month/:name/delete', function($year, $month, $name) { }); // Get deleted data for blog post -post('/:year/:month/:name/delete', function() { +post('/:year/:month/:name/delete', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if ($proper && login()) { @@ -437,7 +435,7 @@ post('/:year/:month/:name/delete', function() { }); // The author page -get('/author/:profile', function($profile) { +get('/author/:profile', function ($profile) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); @@ -486,7 +484,7 @@ get('/author/:profile', function($profile) { }); // Edit the profile -get('/edit/profile', function() { +get('/edit/profile', function () { if (login()) { @@ -503,7 +501,7 @@ get('/edit/profile', function() { }); // Get edited data for static page -post('/edit/profile', function() { +post('/edit/profile', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -596,7 +594,7 @@ get('/admin/posts', function () { }); // The author page -get('/admin/mine', function() { +get('/admin/mine', function () { if (login()) { @@ -653,7 +651,7 @@ get('/admin/mine', function() { }); // The static page -get('/:static', function($static) { +get('/:static', function ($static) { if ($static === 'sitemap.xml' || $static === 'sitemap.base.xml' || $static === 'sitemap.post.xml' || $static === 'sitemap.static.xml' || $static === 'sitemap.tag.xml' || $static === 'sitemap.archive.xml' || $static === 'sitemap.author.xml') { @@ -661,17 +659,17 @@ get('/:static', function($static) { if ($static === 'sitemap.xml') { generate_sitemap('index'); - } else if ($static === 'sitemap.base.xml') { + } elseif ($static === 'sitemap.base.xml') { generate_sitemap('base'); - } else if ($static === 'sitemap.post.xml') { + } elseif ($static === 'sitemap.post.xml') { generate_sitemap('post'); - } else if ($static === 'sitemap.static.xml') { + } elseif ($static === 'sitemap.static.xml') { generate_sitemap('static'); - } else if ($static === 'sitemap.tag.xml') { + } elseif ($static === 'sitemap.tag.xml') { generate_sitemap('tag'); - } else if ($static === 'sitemap.archive.xml') { + } elseif ($static === 'sitemap.archive.xml') { generate_sitemap('archive'); - } else if ($static === 'sitemap.author.xml') { + } elseif ($static === 'sitemap.author.xml') { generate_sitemap('author'); } @@ -744,7 +742,7 @@ get('/:static', function($static) { }); // Edit the static page -get('/:static/edit', function($static) { +get('/:static/edit', function ($static) { if (login()) { @@ -771,7 +769,7 @@ get('/:static/edit', function($static) { }); // Get edited data for static page -post('/:static/edit', function() { +post('/:static/edit', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if (!login()) { @@ -819,7 +817,7 @@ post('/:static/edit', function() { }); // Deleted the static page -get('/:static/delete', function($static) { +get('/:static/delete', function ($static) { if (login()) { @@ -846,7 +844,7 @@ get('/:static/delete', function($static) { }); // Get deleted data for static page -post('/:static/delete', function() { +post('/:static/delete', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); if ($proper && login()) { @@ -857,7 +855,7 @@ post('/:static/delete', function() { }); // Add blog post -get('/add/post', function() { +get('/add/post', function () { if (login()) { @@ -875,7 +873,7 @@ get('/add/post', function() { }); // Get submitted blog post data -post('/add/post', function() { +post('/add/post', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -921,7 +919,7 @@ post('/add/post', function() { }); // Add the static page -get('/add/page', function() { +get('/add/page', function () { if (login()) { @@ -939,7 +937,7 @@ get('/add/page', function() { }); // Get submitted static page data -post('/add/page', function() { +post('/add/page', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -979,7 +977,7 @@ post('/add/page', function() { }); // Import page -get('/admin/import', function() { +get('/admin/import', function () { if (login()) { config('views.root', 'system/admin/views'); render('import', array( @@ -995,7 +993,7 @@ get('/admin/import', function() { }); // Get import post -post('/admin/import', function() { +post('/admin/import', function () { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -1039,7 +1037,7 @@ post('/admin/import', function() { }); // Backup page -get('/admin/backup', function() { +get('/admin/backup', function () { if (login()) { config('views.root', 'system/admin/views'); render('backup', array( @@ -1055,7 +1053,7 @@ get('/admin/backup', function() { }); // Create Zip file -get('/admin/backup-start', function() { +get('/admin/backup-start', function () { if (login()) { config('views.root', 'system/admin/views'); render('backup-start', array( @@ -1071,7 +1069,7 @@ get('/admin/backup-start', function() { }); // Delete all cache -get('/admin/clear-cache', function() { +get('/admin/clear-cache', function () { if (login()) { config('views.root', 'system/admin/views'); render('clear-cache', array( @@ -1088,7 +1086,7 @@ get('/admin/clear-cache', function() { // The tag page -get('/tag/:tag', function($tag) { +get('/tag/:tag', function ($tag) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); @@ -1118,7 +1116,7 @@ get('/tag/:tag', function($tag) { }); // The archive page -get('/archive/:req', function($req) { +get('/archive/:req', function ($req) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); @@ -1142,7 +1140,7 @@ get('/archive/:req', function($req) { if (isset($time[0]) && isset($time[1]) && isset($time[2])) { $timestamp = date('d F Y', $date); - } else if (isset($time[0]) && isset($time[1])) { + } elseif (isset($time[0]) && isset($time[1])) { $timestamp = date('F Y', $date); } else { $timestamp = $req; @@ -1164,7 +1162,7 @@ get('/archive/:req', function($req) { }); // The search page -get('/search/:keyword', function($keyword) { +get('/search/:keyword', function ($keyword) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); @@ -1195,7 +1193,7 @@ get('/search/:keyword', function($keyword) { }); // The JSON API -get('/api/json', function() { +get('/api/json', function () { header('Content-type: application/json'); @@ -1207,7 +1205,7 @@ get('/api/json', function() { }); // Show the RSS feed -get('/feed/rss', function() { +get('/feed/rss', function () { header('Content-Type: application/rss+xml'); @@ -1216,7 +1214,7 @@ get('/feed/rss', function() { }); // Generate OPML file -get('/feed/opml', function() { +get('/feed/opml', function () { header('Content-Type: text/xml'); @@ -1224,7 +1222,7 @@ get('/feed/opml', function() { echo generate_opml(); }); -get('/admin/update/now/:csrf', function($CSRF) { +get('/admin/update/now/:csrf', function ($CSRF) { $proper = is_csrf_proper($CSRF); $updater = new \Kanti\HubUpdater(array( @@ -1244,7 +1242,7 @@ get('/admin/update/now/:csrf', function($CSRF) { } }); -get('/:static/add', function($static) { +get('/:static/add', function ($static) { if (login()) { @@ -1268,7 +1266,7 @@ get('/:static/add', function($static) { header("location: $login"); } }); -post('/:static/add', function($static) { +post('/:static/add', function ($static) { $proper = is_csrf_proper(from($_REQUEST, 'csrf_token')); @@ -1307,7 +1305,7 @@ post('/:static/add', function($static) { } }); -get('/:static/:sub', function($static, $sub) { +get('/:static/:sub', function ($static, $sub) { $father_post = get_static_post($static); if (!$father_post) { @@ -1339,7 +1337,7 @@ get('/:static/:sub', function($static, $sub) { // If we get here, it means that // nothing has been matched above -get('.*', function() { +get('.*', function () { not_found(); }); diff --git a/system/includes/dispatch.php b/system/includes/dispatch.php index 2789c14..f3d5b02 100644 --- a/system/includes/dispatch.php +++ b/system/includes/dispatch.php @@ -3,7 +3,8 @@ if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { 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; @@ -11,8 +12,8 @@ function _log($message) { } } -function site_url(){ - +function site_url() +{ if (config('site.url') == null) error(500, '[site.url] is not set'); @@ -20,36 +21,39 @@ function site_url(){ return rtrim(config('site.url'),'/').'/'; } -function site_path(){ +function site_path() +{ static $_path; if (config('site.url') == null) error(500, '[site.url] is not set'); - + if (!$_path) $_path = rtrim(parse_url(config('site.url'), PHP_URL_PATH),'/'); - + return $_path; } -function error($code, $message) { +function error($code, $message) +{ @header("HTTP/1.0 {$code} {$message}", true, $code); die($message); } -function config($key, $value = null) { - +function config($key, $value = null) +{ static $_config = array(); if ($key === 'source' && file_exists($value)) $_config = parse_ini_file($value, true); - else if ($value == null) + 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); @@ -57,7 +61,8 @@ function to_b64($str) { return trim($str, '-'); } -function from_b64($str) { +function from_b64($str) +{ $str = preg_replace('/\_/', '/', $str); $str = preg_replace('/\./', '+', $str); $str = preg_replace('/\-/', '=', $str); @@ -67,8 +72,8 @@ function from_b64($str) { if (extension_loaded('mcrypt')) { - function encrypt($decoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC) { - + function encrypt($decoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC) + { if (($secret = config('cookies.secret')) == null) error(500, '[cookies.secret] is not set'); @@ -80,8 +85,8 @@ if (extension_loaded('mcrypt')) { return sprintf('%s|%s', $encrypted, to_b64($iv_code)); } - function decrypt($encoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC) { - + function decrypt($encoded, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC) + { if (($secret = config('cookies.secret')) == null) error(500, '[cookies.secret] is not set'); @@ -96,13 +101,14 @@ if (extension_loaded('mcrypt')) { } -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); } -function get_cookie($name) { - +function get_cookie($name) +{ $value = from($_COOKIE, $name); if ($value) @@ -111,7 +117,8 @@ function get_cookie($name) { return $value; } -function delete_cookie() { +function delete_cookie() +{ $cookies = func_get_args(); foreach ($cookies as $ck) setcookie($ck, '', -10, '/'); @@ -120,7 +127,8 @@ function delete_cookie() { // if we have APC loaded, enable cache functions if (extension_loaded('apc')) { - function cache($key, $func, $ttl = 0) { + function cache($key, $func, $ttl = 0) + { if (($data = apc_fetch($key)) === false) { $data = call_user_func($func); if ($data !== null) { @@ -130,7 +138,8 @@ if (extension_loaded('apc')) { return $data; } - function cache_invalidate() { + function cache_invalidate() + { foreach (func_get_args() as $key) { apc_delete($key); } @@ -138,8 +147,8 @@ if (extension_loaded('apc')) { } -function warn($name = null, $message = null) { - +function warn($name = null, $message = null) +{ static $warnings = array(); if ($name == '*') @@ -154,15 +163,18 @@ function warn($name = null, $message = null) { $warnings[$name] = $message; } -function _u($str) { +function _u($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); } -function from($source, $name) { +function from($source, $name) +{ if (is_array($name)) { $data = array(); foreach ($name as $k) @@ -172,8 +184,8 @@ function from($source, $name) { return isset($source[$name]) ? $source[$name] : null ; } -function stash($name, $value = null) { - +function stash($name, $value = null) +{ static $_stash = array(); if ($value === null) @@ -184,26 +196,26 @@ function stash($name, $value = null) { return $value; } -function method($verb = null) { - +function method($verb = null) +{ if ($verb == null || (strtoupper($verb) == strtoupper($_SERVER['REQUEST_METHOD']))) return strtoupper($_SERVER['REQUEST_METHOD']); error(400, 'bad request'); } -function client_ip() { - +function client_ip() +{ if (isset($_SERVER['HTTP_CLIENT_IP'])) return $_SERVER['HTTP_CLIENT_IP']; - else if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) + elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) return $_SERVER['HTTP_X_FORWARDED_FOR']; 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); @@ -243,8 +255,8 @@ function redirect(/* $code_or_path, $path_or_cond, $cond */) { exit; } -function partial($view, $locals = null) { - +function partial($view, $locals = null) +{ if (is_array($locals) && count($locals)) { extract($locals, EXTR_SKIP); } @@ -267,11 +279,13 @@ function partial($view, $locals = null) { return ''; } -function content($value = null) { +function content($value = null) +{ 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'])); @@ -319,14 +333,15 @@ function render($view, $locals = null, $layout = null) { } } -function json($obj, $code = 200) { +function json($obj, $code = 200) +{ header('Content-type: application/json', true, $code); echo json_encode($obj); exit; } -function condition() { - +function condition() +{ static $cb_map = array(); $argv = func_get_args(); @@ -350,8 +365,8 @@ function condition() { error(500, 'condition ['.$name.'] is undefined'); } -function middleware($cb_or_path = null) { - +function middleware($cb_or_path = null) +{ static $cb_map = array(); if ($cb_or_path == null || is_string($cb_or_path)) { @@ -363,8 +378,8 @@ function middleware($cb_or_path = null) { } } -function filter($sym, $cb_or_val = null) { - +function filter($sym, $cb_or_val = null) +{ static $cb_map = array(); if (is_callable($cb_or_val)) { @@ -384,7 +399,8 @@ function filter($sym, $cb_or_val = null) { 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-\.]+)'; @@ -392,8 +408,8 @@ function route_to_regex($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(), @@ -458,16 +474,18 @@ function route($method, $pattern, $callback = null) { } -function get($path, $cb) { +function get($path, $cb) +{ route('GET', $path, $cb); } -function post($path, $cb) { +function 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; @@ -497,10 +515,10 @@ function flash($key, $msg = null, $now = false) { $x[$key] = $msg; } -function dispatch() { - +function dispatch() +{ $path = urldecode($_SERVER['REQUEST_URI']); - + if (config('site.url') !== null) $path = preg_replace('@^'.preg_quote(site_path()).'@', '', $path); @@ -511,4 +529,3 @@ function dispatch() { route(method(), "/{$uri}"); } -?> \ No newline at end of file diff --git a/system/includes/functions.php b/system/includes/functions.php index d8e5e57..0f265c1 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -10,8 +10,8 @@ use \Suin\RSSWriter\Item; use \Kanti\HubUpdater; // Get blog post path. Unsorted. Mostly used on widget. -function get_post_unsorted() { - +function get_post_unsorted() +{ static $_unsorted = array(); if (empty($_unsorted)) { @@ -26,8 +26,8 @@ function get_post_unsorted() { } // Get blog post with more info about the path. Sorted by filename. -function get_post_sorted() { - +function get_post_sorted() +{ static $_sorted = array(); if (empty($_sorted)) { @@ -40,9 +40,9 @@ function get_post_sorted() { return $_sorted; } -// Get static page path. Unsorted. -function get_static_pages() { - +// Get static page path. Unsorted. +function get_static_pages() +{ static $_page = array(); if (empty($_page)) { @@ -55,9 +55,9 @@ function get_static_pages() { return $_page; } -// Get static page path. Unsorted. -function get_static_sub_pages($static = null) { - +// Get static page path. Unsorted. +function get_static_sub_pages($static = null) +{ static $_sub_page = array(); if (empty($_sub_page)) { @@ -69,7 +69,7 @@ function get_static_sub_pages($static = null) { } if ($static != null) { $stringLen = strlen($static); - return array_filter($_sub_page, function($sub_page)use($static, $stringLen) { + return array_filter($_sub_page, function ($sub_page) use ($static, $stringLen) { $x = explode("/", $sub_page); if ($x[count($x) - 2] == $static) { return true; @@ -80,9 +80,9 @@ function get_static_sub_pages($static = null) { return $_sub_page; } -// Get author bio path. Unsorted. -function get_author_names() { - +// Get author bio path. Unsorted. +function get_author_names() +{ static $_author = array(); if (empty($_author)) { @@ -96,9 +96,9 @@ function get_author_names() { return $_author; } -// Get backup file. -function get_zip_files() { - +// Get backup file. +function get_zip_files() +{ static $_zip = array(); if (empty($_zip)) { @@ -113,18 +113,20 @@ function get_zip_files() { } // usort function. Sort by filename. -function sortfile($a, $b) { +function sortfile($a, $b) +{ return $a['filename'] == $b['filename'] ? 0 : ( $a['filename'] < $b['filename'] ) ? 1 : -1; } // usort function. Sort by date. -function sortdate($a, $b) { +function sortdate($a, $b) +{ return $a->date == $b->date ? 0 : ( $a->date < $b->date ) ? 1 : -1; } // Rebuilt cache index -function rebuilt_cache($type) { - +function rebuilt_cache($type) +{ $dir = 'cache/index'; $posts_cache_sorted = array(); $posts_cache_unsorted = array(); @@ -174,9 +176,9 @@ function rebuilt_cache($type) { } } -// Return blog posts. -function get_posts($posts, $page = 1, $perpage = 0) { - +// Return blog posts. +function get_posts($posts, $page = 1, $perpage = 0) +{ if (empty($posts)) { $posts = get_post_sorted(); } @@ -239,7 +241,7 @@ function get_posts($posts, $page = 1, $perpage = 0) { $post->tagb = implode(' » ', $bc); $post->file = $filepath; - + $content = file_get_contents($filepath); // Extract the title and body @@ -261,8 +263,8 @@ function get_posts($posts, $page = 1, $perpage = 0) { } // Find post by year, month and name, previous, and next. -function find_post($year, $month, $name) { - +function find_post($year, $month, $name) +{ $posts = get_post_sorted(); foreach ($posts as $index => $v) { @@ -305,8 +307,8 @@ function find_post($year, $month, $name) { } // Return tag page. -function get_tag($tag, $page, $perpage, $random) { - +function get_tag($tag, $page, $perpage, $random) +{ $posts = get_post_sorted(); if ($random === true) { @@ -340,8 +342,8 @@ function get_tag($tag, $page, $perpage, $random) { } // Return archive page. -function get_archive($req, $page, $perpage) { - +function get_archive($req, $page, $perpage) +{ $posts = get_post_sorted(); $tmp = array(); @@ -362,8 +364,8 @@ function get_archive($req, $page, $perpage) { } // Return posts list on profile. -function get_profile($profile, $page, $perpage) { - +function get_profile($profile, $page, $perpage) +{ $posts = get_post_sorted(); $tmp = array(); @@ -385,8 +387,8 @@ function get_profile($profile, $page, $perpage) { } // Return author bio. -function get_bio($author) { - +function get_bio($author) +{ $names = get_author_names(); $username = 'config/users/' . $author . '.ini'; @@ -431,8 +433,8 @@ function get_bio($author) { } } -function default_profile($author) { - +function default_profile($author) +{ $tmp = array(); $profile = new stdClass; @@ -445,8 +447,8 @@ function default_profile($author) { } // Return static page. -function get_static_post($static) { - +function get_static_post($static) +{ $posts = get_static_pages(); $tmp = array(); @@ -489,8 +491,8 @@ function get_static_post($static) { } // Return static page. -function get_static_sub_post($static, $sub_static) { - +function get_static_sub_post($static, $sub_static) +{ $posts = get_static_sub_pages($static); $tmp = array(); @@ -531,8 +533,8 @@ function get_static_sub_post($static, $sub_static) { } // Return search page. -function get_keyword($keyword, $page, $perpage) { - +function get_keyword($keyword, $page, $perpage) +{ $posts = get_post_sorted(); $tmp = array(); @@ -559,7 +561,8 @@ function get_keyword($keyword, $page, $perpage) { } // Get related posts base on post tag. -function get_related($tag) { +function get_related($tag) +{ $perpage = config('related.count'); $posts = get_tag(strip_tags($tag), 1, $perpage + 1, true); $tmp = array(); @@ -588,8 +591,8 @@ function get_related($tag) { } // Return post count. Matching $var and $str provided. -function get_count($var, $str) { - +function get_count($var, $str) +{ $posts = get_post_sorted(); $tmp = array(); @@ -605,8 +608,8 @@ function get_count($var, $str) { } // Return seaarch result count -function keyword_count($keyword) { - +function keyword_count($keyword) +{ $posts = get_post_sorted(); $tmp = array(); @@ -628,15 +631,14 @@ function keyword_count($keyword) { return count($tmp); } -function recent() { +function recent() +{ $str = ''; @@ -644,8 +646,8 @@ function recent() { } // Return an archive list, categorized by year and month. -function archive_list() { - +function archive_list() +{ $posts = get_post_unsorted(); $by_year = array(); $col = array(); @@ -715,8 +717,8 @@ EOF; } // Return tag cloud. -function tag_cloud() { - +function tag_cloud() +{ $posts = get_post_unsorted(); $tags = array(); @@ -747,7 +749,8 @@ function tag_cloud() { // Helper function to determine whether // to show the previous buttons -function has_prev($prev) { +function has_prev($prev) +{ if (!empty($prev)) { return array( 'url' => $prev->url, @@ -758,7 +761,8 @@ function has_prev($prev) { // Helper function to determine whether // to show the next buttons -function has_next($next) { +function has_next($next) +{ if (!empty($next)) { return array( 'url' => $next->url, @@ -769,7 +773,8 @@ function has_next($next) { // Helper function to determine whether // to show the pagination buttons -function has_pagination($total, $perpage, $page = 1) { +function has_pagination($total, $perpage, $page = 1) +{ if (!$total) { $total = count(get_post_unsorted()); } @@ -780,8 +785,8 @@ function has_pagination($total, $perpage, $page = 1) { } // Get the meta description -function get_description($string) { - +function get_description($string) +{ $string = remove_accent($string); $string = preg_replace('/[^A-Za-z0-9 !@#$%^&*(),.-]/u', ' ', strip_tags($string)); $string = ltrim($string); @@ -790,8 +795,8 @@ function get_description($string) { } // Get the teaser -function get_teaser($text, $url) { - +function get_teaser($text, $url) +{ $teaserType = config('teaser.type'); if (strlen(strip_tags($text)) < config('teaser.char') || $teaserType === 'full') { @@ -806,8 +811,8 @@ function get_teaser($text, $url) { } // Get thumbnail from image and Youtube. -function get_thumbnail($text) { - +function get_thumbnail($text) +{ if (config('img.thumbnail') == 'true') { $teaserType = config('teaser.type'); @@ -838,13 +843,14 @@ function get_thumbnail($text) { } } } else { - + } } } // Return edit tab on post -function tab($p) { +function tab($p) +{ $user = $_SESSION[config("site.url")]['user']; $role = user('role', $user); if (isset($p->author)) { @@ -857,7 +863,8 @@ function tab($p) { } // Use base64 encode image to speed up page load time. -function base64_encode_image($filename = string, $filetype = string) { +function base64_encode_image($filename = string, $filetype = string) +{ if ($filename) { $imgbinary = fread(fopen($filename, "r"), filesize($filename)); return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary); @@ -865,8 +872,8 @@ function base64_encode_image($filename = string, $filetype = string) { } // Social links -function social($imgDir = null) { - +function social($imgDir = null) +{ $twitter = config('social.twitter'); $facebook = config('social.facebook'); $google = config('social.google'); @@ -897,8 +904,8 @@ function social($imgDir = null) { } // Copyright -function copyright() { - +function copyright() +{ $blogcp = blog_copyright(); $credit = 'Proudly powered by HTMLy.'; @@ -910,7 +917,8 @@ function copyright() { } // Disqus on post. -function disqus($title = null, $url = null) { +function disqus($title = null, $url = null) +{ $comment = config('comment.system'); $disqus = config('disqus.shortname'); $script = << var disqus_shortname = '{$disqus}'; - (function() { + (function () { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/count.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); @@ -950,7 +959,8 @@ EOF; } // Disqus recent comments -function recent_comments() { +function recent_comments() +{ $comment = config('comment.system'); $disqus = config('disqus.shortname'); $script = << - '; $corejs = ''; $webmasterTools = ''; - if(!empty($wmt_id)) - { + if(!empty($wmt_id)) { $webmasterTools = ''; } @@ -1616,7 +1638,8 @@ function head_contents($title, $description, $canonical) { } // Return toolbar -function toolbar() { +function toolbar() +{ $user = $_SESSION[config("site.url")]['user']; $role = user('role', $user); $base = site_url(); @@ -1651,9 +1674,9 @@ EOF; echo ''; } -// File cache -function file_cache($request) { - +// File cache +function file_cache($request) +{ if(config('cache.off')) return; $c = str_replace('/', '#', str_replace('?', '~', $request)); @@ -1666,25 +1689,29 @@ function file_cache($request) { } } -function generate_csrf_token() { +function generate_csrf_token() +{ $_SESSION[config("site.url")]['csrf_token'] = sha1(microtime(true) . mt_rand(10000, 90000)); } -function get_csrf() { +function get_csrf() +{ if (!isset($_SESSION[config("site.url")]['csrf_token']) || empty($_SESSION[config("site.url")]['csrf_token'])) { generate_csrf_token(); } return $_SESSION[config("site.url")]['csrf_token']; } -function is_csrf_proper($csrf_token) { +function is_csrf_proper($csrf_token) +{ if ($csrf_token == get_csrf()) { return true; } return false; } -function add_view($page) { +function add_view($page) +{ $filename = "cache/count.json"; $views = array(); if (file_exists($filename)) { @@ -1698,7 +1725,8 @@ function add_view($page) { file_put_contents($filename, json_encode($views)); } -function get_views($page) { +function get_views($page) +{ static $_views = array(); if (empty($_views)) { @@ -1713,14 +1741,14 @@ function get_views($page) { return -1; } -function get_content_tag($tag, $string, $alt = null) { +function get_content_tag($tag, $string, $alt = null) +{ $reg = '/\(\s|)/', '', $content)); } diff --git a/system/includes/opml.php b/system/includes/opml.php index fba9289..8cb57a8 100644 --- a/system/includes/opml.php +++ b/system/includes/opml.php @@ -1,22 +1,22 @@ data = $data; $this->writer = new XMLWriter(); $this->writer->openMemory(); } - + public function render() { $this->writer->startDocument('1.0', 'UTF-8'); $this->writer->startElement('opml'); $this->writer->writeAttribute('version', '2.0'); - + // Header $this->writer->startElement('head'); foreach ($this->data['head'] as $key => $value) { @@ -24,7 +24,7 @@ class OPML } $this->writer->writeElement('dateModified', date("D, d M Y H:i:s T")); $this->writer->endElement(); - + // Body $this->writer->startElement('body'); foreach ($this->data['body'] as $outlines) { @@ -35,11 +35,9 @@ class OPML $this->writer->endElement(); } $this->writer->endElement(); - + $this->writer->endElement(); $this->writer->endDocument(); return $this->writer->outputMemory(); } } - -?> \ No newline at end of file diff --git a/system/includes/session.php b/system/includes/session.php index e498bdc..a6795ca 100644 --- a/system/includes/session.php +++ b/system/includes/session.php @@ -2,13 +2,12 @@ session_start(); -function login() { - +function login() +{ if(isset($_SESSION[config("site.url")]['user']) && !empty($_SESSION[config("site.url")]['user'])) { return true; - } - else { + } else { return false; } -} \ No newline at end of file +} diff --git a/system/includes/updater.php b/system/includes/updater.php index 243f280..f3e7c7e 100644 --- a/system/includes/updater.php +++ b/system/includes/updater.php @@ -1,16 +1,18 @@ fileName = $fileName; $this->holdTime = $holdTime; } - public function is() { + public function is() + { if (!file_exists($this->fileName)) return false; if (filemtime($this->fileName) < ( time() - $this->holdTime )) { @@ -20,25 +22,28 @@ class CacheOneFile { return true; } - public function get() { + public function get() + { return file_get_contents($this->fileName); } - public function set($content) { + public function set($content) + { file_put_contents($this->fileName, $content); } } -class Updater { - +class Updater +{ protected $cachedInfo = "cache/downloadInfo.json"; protected $versionFile = "cache/installedVersion.json"; protected $zipFile = "cache/tmpZipFile.zip"; protected $infos = array(); protected $context = null; - - protected function genCaFile(){ + + protected function genCaFile() + { if(file_exists("cache/ca_bundle.crt")) return 1; //https://github.com/bagder/ca-bundle @@ -3938,13 +3943,14 @@ kI26oQ== -----END CERTIFICATE-----"); } - public function __construct() { + public function __construct() + { if (!file_exists("cache/")) { mkdir("cache/"); } $this->genCaFile(); $this->cachedInfo = new CacheOneFile($this->cachedInfo); - + $this->context = stream_context_create( array( 'http' => array( @@ -3959,7 +3965,8 @@ kI26oQ== $this->infos = $this->getInfos(); } - protected function getInfos() { + protected function getInfos() + { $path = "https://api.github.com/repos/danpros/htmly/releases"; if ($this->cachedInfo->is()) { $fileContent = $this->cachedInfo->get(); @@ -3980,7 +3987,8 @@ kI26oQ== return json_decode($fileContent, true); } - public function updateAble() { + public function updateAble() + { if (!in_array('https', stream_get_wrappers())) return false; if (empty($this->infos)) @@ -3998,7 +4006,8 @@ kI26oQ== return true; } - public function update() { + public function update() + { if ($this->updateAble()) { if ($this->download("https://github.com/danpros/htmly/archive/" . $this->infos[0]['tag_name'] . ".zip")) { if ($this->unZip()) { @@ -4014,7 +4023,8 @@ kI26oQ== return false; } - protected function download($url) { + protected function download($url) + { $file = @fopen($url, 'r', false , $this->context); if ($file == false) return false; @@ -4022,7 +4032,8 @@ kI26oQ== return true; } - protected function unZip() { + protected function unZip() + { $path = dirname($_SERVER['SCRIPT_FILENAME']) . "/" . $this->zipFile; $zip = new ZipArchive; @@ -4047,7 +4058,8 @@ kI26oQ== } } - public function printOne() { + public function printOne() + { $releases = $this->infos; $string = "

    Updated to

    "; $string .= "

    [" . $releases[0]['tag_name'] . "] " . $releases[0]['name'] . "

    \n"; @@ -4055,7 +4067,8 @@ kI26oQ== return $string; } - public function getName() { + public function getName() + { return $this->infos[0]['tag_name']; } diff --git a/system/resources/htmly.js b/system/resources/htmly.js index 17be35e..d1d8c6a 100644 --- a/system/resources/htmly.js +++ b/system/resources/htmly.js @@ -7,4 +7,4 @@ }); }); -})(jQuery); \ No newline at end of file +})(jQuery);