mirror of
https://github.com/danpros/htmly.git
synced 2026-04-17 19:26:08 +05:30
PSR-2 conform
This commit is contained in:
parent
2fa0745956
commit
0237e04a0e
8 changed files with 366 additions and 298 deletions
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
// Return username.ini value
|
||||
function user($key, $user = null) {
|
||||
function user($key, $user = null)
|
||||
{
|
||||
$value = 'config/users/' . $user . '.ini';
|
||||
static $_config = array();
|
||||
if (file_exists($value)) {
|
||||
|
|
@ -13,7 +14,8 @@ function user($key, $user = null) {
|
|||
}
|
||||
|
||||
// Create a session
|
||||
function session($user, $pass, $str = null) {
|
||||
function session($user, $pass, $str = null)
|
||||
{
|
||||
$user_file = 'config/users/' . $user . '.ini';
|
||||
$user_enc = user('encryption', $user);
|
||||
$user_pass = user('password', $user);
|
||||
|
|
@ -32,21 +34,22 @@ function session($user, $pass, $str = null) {
|
|||
}
|
||||
|
||||
// Clean URLs
|
||||
function remove_accent($str) {
|
||||
function remove_accent($str)
|
||||
{
|
||||
$a = array('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'ß', 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'Ā', 'ā', 'Ă', 'ă', 'Ą', 'ą', 'Ć', 'ć', 'Ĉ', 'ĉ', 'Ċ', 'ċ', 'Č', 'č', 'Ď', 'ď', 'Đ', 'đ', 'Ē', 'ē', 'Ĕ', 'ĕ', 'Ė', 'ė', 'Ę', 'ę', 'Ě', 'ě', 'Ĝ', 'ĝ', 'Ğ', 'ğ', 'Ġ', 'ġ', 'Ģ', 'ģ', 'Ĥ', 'ĥ', 'Ħ', 'ħ', 'Ĩ', 'ĩ', 'Ī', 'ī', 'Ĭ', 'ĭ', 'Į', 'į', 'İ', 'ı', 'IJ', 'ij', 'Ĵ', 'ĵ', 'Ķ', 'ķ', 'Ĺ', 'ĺ', 'Ļ', 'ļ', 'Ľ', 'ľ', 'Ŀ', 'ŀ', 'Ł', 'ł', 'Ń', 'ń', 'Ņ', 'ņ', 'Ň', 'ň', 'ʼn', 'Ō', 'ō', 'Ŏ', 'ŏ', 'Ő', 'ő', 'Œ', 'œ', 'Ŕ', 'ŕ', 'Ŗ', 'ŗ', 'Ř', 'ř', 'Ś', 'ś', 'Ŝ', 'ŝ', 'Ş', 'ş', 'Š', 'š', 'Ţ', 'ţ', 'Ť', 'ť', 'Ŧ', 'ŧ', 'Ũ', 'ũ', 'Ū', 'ū', 'Ŭ', 'ŭ', 'Ů', 'ů', 'Ű', 'ű', 'Ų', 'ų', 'Ŵ', 'ŵ', 'Ŷ', 'ŷ', 'Ÿ', 'Ź', 'ź', 'Ż', 'ż', 'Ž', 'ž', 'ſ', 'ƒ', 'Ơ', 'ơ', 'Ư', 'ư', 'Ǎ', 'ǎ', 'Ǐ', 'ǐ', 'Ǒ', 'ǒ', 'Ǔ', 'ǔ', 'Ǖ', 'ǖ', 'Ǘ', 'ǘ', 'Ǚ', 'ǚ', 'Ǜ', 'ǜ', 'Ǻ', 'ǻ', 'Ǽ', 'ǽ', 'Ǿ', 'ǿ');
|
||||
$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', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ъ', 'ь', 'я', 'Ж', 'Ч', 'Щ', 'Ш', 'Ю', 'А', 'Б', 'В', 'Г', 'Д', 'Е', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ъ', 'Ь', 'Я');
|
||||
$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);
|
||||
$b = array_merge($b,$lat);
|
||||
$a = array_merge($a, $cyr);
|
||||
$b = array_merge($b, $lat);
|
||||
return str_replace($a, $b, $str);
|
||||
}
|
||||
|
||||
// Edit blog posts
|
||||
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);
|
||||
if($date !== null)
|
||||
{
|
||||
if($date !== null) {
|
||||
$oldurl[0] = substr($oldurl[0], 0, strrpos($oldurl[0], '/')) . '/' . date('Y-m-d-h-i-s',strtotime($date));
|
||||
}
|
||||
|
||||
|
|
@ -97,7 +100,8 @@ function edit_post($title, $tag, $url, $content, $oldfile, $destination = null,
|
|||
}
|
||||
|
||||
// Edit static page
|
||||
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null) {
|
||||
function edit_page($title, $url, $content, $oldfile, $destination = null, $description = null)
|
||||
{
|
||||
$dir = substr($oldfile, 0, strrpos($oldfile, '/'));
|
||||
|
||||
$post_title = $title;
|
||||
|
|
@ -135,7 +139,8 @@ function edit_page($title, $url, $content, $oldfile, $destination = null, $descr
|
|||
}
|
||||
|
||||
// Add blog post
|
||||
function add_post($title, $tag, $url, $content, $user, $description = null) {
|
||||
function add_post($title, $tag, $url, $content, $user, $description = null)
|
||||
{
|
||||
|
||||
$post_date = date('Y-m-d-H-i-s');
|
||||
$post_title = $title;
|
||||
|
|
@ -169,7 +174,8 @@ function add_post($title, $tag, $url, $content, $user, $description = null) {
|
|||
}
|
||||
|
||||
// Add static page
|
||||
function add_page($title, $url, $content, $description = null) {
|
||||
function add_page($title, $url, $content, $description = null)
|
||||
{
|
||||
|
||||
$post_title = $title;
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
|
|
@ -201,7 +207,8 @@ function add_page($title, $url, $content, $description = null) {
|
|||
}
|
||||
|
||||
// Add static sub page
|
||||
function add_sub_page($title, $url, $content, $static, $description = null) {
|
||||
function add_sub_page($title, $url, $content, $static, $description = null)
|
||||
{
|
||||
|
||||
$post_title = $title;
|
||||
$post_url = strtolower(preg_replace(array('/[^a-zA-Z0-9 \-\p{L}]/u', '/[ -]+/', '/^-|-$/'), array('', '-', ''), remove_accent($url)));
|
||||
|
|
@ -233,7 +240,8 @@ function add_sub_page($title, $url, $content, $static, $description = null) {
|
|||
}
|
||||
|
||||
// Delete blog post
|
||||
function delete_post($file, $destination) {
|
||||
function delete_post($file, $destination)
|
||||
{
|
||||
if (!login())
|
||||
return null;
|
||||
$deleted_content = $file;
|
||||
|
|
@ -258,7 +266,8 @@ function delete_post($file, $destination) {
|
|||
}
|
||||
|
||||
// Delete static page
|
||||
function delete_page($file, $destination) {
|
||||
function delete_page($file, $destination)
|
||||
{
|
||||
if (!login())
|
||||
return null;
|
||||
$deleted_content = $file;
|
||||
|
|
@ -287,8 +296,8 @@ function delete_page($file, $destination) {
|
|||
}
|
||||
|
||||
// Edit user profile
|
||||
function edit_profile($title, $content, $user) {
|
||||
|
||||
function edit_profile($title, $content, $user)
|
||||
{
|
||||
$user_title = $title;
|
||||
$user_content = '<!--t ' . $user_title . ' t-->' . "\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('#<br\s*/?>#i', "\n", $descriptionB);
|
||||
} else {
|
||||
return $str = '<li>Can not read the feed content.</li>';
|
||||
|
|
@ -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)) {
|
||||
|
|
|
|||
100
system/htmly.php
100
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();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -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}");
|
||||
}
|
||||
?>
|
||||
|
|
@ -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 = '<ul>';
|
||||
$posts = get_posts(null, 1, 5);
|
||||
foreach($posts as $post)
|
||||
{
|
||||
foreach($posts as $post) {
|
||||
$str .= '<li><a href="' . $post->url . '">' . $post->title . '</a></li>';
|
||||
}
|
||||
if(empty($posts))
|
||||
{
|
||||
if(empty($posts)) {
|
||||
$str .= '<li>No Posts Found</li>';
|
||||
}
|
||||
$str .= '</ul>';
|
||||
|
|
@ -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 <a href="http://www.htmly.com" target="_blank">HTMLy</a>.';
|
||||
|
||||
|
|
@ -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 = <<<EOF
|
||||
|
|
@ -918,7 +926,7 @@ function disqus($title = null, $url = null) {
|
|||
var disqus_shortname = '{$disqus}';
|
||||
var disqus_title = '{$title}';
|
||||
var disqus_url = '{$url}';
|
||||
(function() {
|
||||
(function () {
|
||||
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
|
||||
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
|
||||
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
|
||||
|
|
@ -931,13 +939,14 @@ EOF;
|
|||
}
|
||||
|
||||
// Disqus comment count on teaser
|
||||
function disqus_count() {
|
||||
function disqus_count()
|
||||
{
|
||||
$comment = config('comment.system');
|
||||
$disqus = config('disqus.shortname');
|
||||
$script = <<<EOF
|
||||
<script type="text/javascript">
|
||||
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 = <<<EOF
|
||||
|
|
@ -966,12 +976,13 @@ EOF;
|
|||
}
|
||||
}
|
||||
|
||||
function facebook() {
|
||||
function facebook()
|
||||
{
|
||||
$comment = config('comment.system');
|
||||
$appid = config('fb.appid');
|
||||
$script = <<<EOF
|
||||
<div id="fb-root"></div>
|
||||
<script>(function(d, s, id) {
|
||||
<script>(function (d, s, id) {
|
||||
var js, fjs = d.getElementsByTagName(s)[0];
|
||||
if (d.getElementById(id)) return;
|
||||
js = d.createElement(s); js.id = id;
|
||||
|
|
@ -987,7 +998,8 @@ EOF;
|
|||
}
|
||||
|
||||
// Google Publisher (Google+ page).
|
||||
function publisher() {
|
||||
function publisher()
|
||||
{
|
||||
$publisher = config('google.publisher');
|
||||
if (!empty($publisher)) {
|
||||
return $publisher;
|
||||
|
|
@ -995,19 +1007,17 @@ function publisher() {
|
|||
}
|
||||
|
||||
// Google Analytics
|
||||
function analytics($analyticsDir = null) {
|
||||
function analytics($analyticsDir = null)
|
||||
{
|
||||
$analytics = config('google.analytics.id');
|
||||
if($analyticsDir === null)
|
||||
{
|
||||
if($analyticsDir === null) {
|
||||
$analyticsDir = '//www.google-analytics.com/analytics.js';
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$analyticsDir = site_url() . 'themes/' . $analyticsDir . 'analytics.js';
|
||||
}
|
||||
$script = <<<EOF
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(function (i,s,o,g,r,a,m) {i['GoogleAnalyticsObject']=r;i[r]=i[r]||function () {
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','{$analyticsDir}','ga');
|
||||
|
|
@ -1022,7 +1032,8 @@ EOF;
|
|||
}
|
||||
|
||||
// Menu
|
||||
function menu() {
|
||||
function menu()
|
||||
{
|
||||
$menu = config('blog.menu');
|
||||
$req = $_SERVER['REQUEST_URI'];
|
||||
|
||||
|
|
@ -1081,7 +1092,8 @@ function menu() {
|
|||
}
|
||||
}
|
||||
|
||||
function get_title_from_file($v) {
|
||||
function get_title_from_file($v)
|
||||
{
|
||||
// Get the contents and convert it to HTML
|
||||
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
|
||||
|
||||
|
|
@ -1178,7 +1190,8 @@ function get_menu() {//aktive Link for Sub Pages ::TODO
|
|||
}
|
||||
|
||||
// Search form
|
||||
function search() {
|
||||
function search()
|
||||
{
|
||||
echo <<<EOF
|
||||
<form id="search-form" method="get">
|
||||
<input type="text" class="search-input" name="search" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}">
|
||||
|
|
@ -1192,15 +1205,16 @@ EOF;
|
|||
}
|
||||
|
||||
// The not found error
|
||||
function not_found() {
|
||||
function not_found()
|
||||
{
|
||||
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
|
||||
render('404', null, false);
|
||||
die();
|
||||
}
|
||||
|
||||
// Turn an array of posts into an RSS feed
|
||||
function generate_rss($posts) {
|
||||
|
||||
function generate_rss($posts)
|
||||
{
|
||||
$feed = new Feed();
|
||||
$channel = new Channel();
|
||||
$rssLength = config('rss.char');
|
||||
|
|
@ -1245,8 +1259,8 @@ function generate_rss($posts) {
|
|||
}
|
||||
|
||||
// Return post, archive url for sitemap
|
||||
function get_path() {
|
||||
|
||||
function get_path()
|
||||
{
|
||||
$posts = get_post_sorted();
|
||||
|
||||
$tmp = array();
|
||||
|
|
@ -1296,8 +1310,8 @@ function get_path() {
|
|||
}
|
||||
|
||||
// Return static page path for sitemap
|
||||
function get_static_path() {
|
||||
|
||||
function get_static_path()
|
||||
{
|
||||
$posts = get_static_pages();
|
||||
|
||||
$tmp = array();
|
||||
|
|
@ -1323,8 +1337,8 @@ function get_static_path() {
|
|||
}
|
||||
|
||||
// Generate sitemap.xml.
|
||||
function generate_sitemap($str) {
|
||||
|
||||
function generate_sitemap($str)
|
||||
{
|
||||
header('X-Robots-Tag: noindex');
|
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?>';
|
||||
|
|
@ -1457,8 +1471,8 @@ function generate_sitemap($str) {
|
|||
}
|
||||
|
||||
// Function to generate OPML file
|
||||
function generate_opml() {
|
||||
|
||||
function generate_opml()
|
||||
{
|
||||
$opml_data = array(
|
||||
'head' => array(
|
||||
'title' => blog_title() . ' OPML File',
|
||||
|
|
@ -1484,13 +1498,14 @@ function generate_opml() {
|
|||
}
|
||||
|
||||
// Turn an array of posts into a JSON
|
||||
function generate_json($posts) {
|
||||
function generate_json($posts)
|
||||
{
|
||||
return json_encode($posts);
|
||||
}
|
||||
|
||||
// Create Zip files
|
||||
function Zip($source, $destination, $include_dir = false) {
|
||||
|
||||
function Zip($source, $destination, $include_dir = false)
|
||||
{
|
||||
if (!extension_loaded('zip') || !file_exists($source)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1518,11 +1533,11 @@ function Zip($source, $destination, $include_dir = false) {
|
|||
|
||||
if (is_dir($file) === true) {
|
||||
$zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
|
||||
} else if (is_file($file) === true) {
|
||||
} elseif (is_file($file) === true) {
|
||||
$zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
|
||||
}
|
||||
}
|
||||
} else if (is_file($source) === true) {
|
||||
} elseif (is_file($source) === true) {
|
||||
$zip->addFromString(basename($source), file_get_contents($source));
|
||||
}
|
||||
|
||||
|
|
@ -1530,7 +1545,8 @@ function Zip($source, $destination, $include_dir = false) {
|
|||
}
|
||||
|
||||
// TRUE if the current page is the front page.
|
||||
function is_front() {
|
||||
function is_front()
|
||||
{
|
||||
$req = $_SERVER['REQUEST_URI'];
|
||||
if ($req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false) {
|
||||
return true;
|
||||
|
|
@ -1540,7 +1556,8 @@ function is_front() {
|
|||
}
|
||||
|
||||
// TRUE if the current page is an index page like frontpage, tag index, archive index and search index.
|
||||
function is_index() {
|
||||
function is_index()
|
||||
{
|
||||
$req = $_SERVER['REQUEST_URI'];
|
||||
if (strpos($req, '/archive/') !== false || strpos($req, '/tag/') !== false || strpos($req, '/search/') !== false || $req == site_path() . '/' || strpos($req, site_path() . '/?page') !== false) {
|
||||
return true;
|
||||
|
|
@ -1550,33 +1567,39 @@ function is_index() {
|
|||
}
|
||||
|
||||
// Return blog title
|
||||
function blog_title() {
|
||||
function blog_title()
|
||||
{
|
||||
return config('blog.title');
|
||||
}
|
||||
|
||||
// Return blog tagline
|
||||
function blog_tagline() {
|
||||
function blog_tagline()
|
||||
{
|
||||
return config('blog.tagline');
|
||||
}
|
||||
|
||||
// Return blog description
|
||||
function blog_description() {
|
||||
function blog_description()
|
||||
{
|
||||
return config('blog.description');
|
||||
}
|
||||
|
||||
// Return blog copyright
|
||||
function blog_copyright() {
|
||||
function blog_copyright()
|
||||
{
|
||||
return config('blog.copyright');
|
||||
}
|
||||
|
||||
// Return author info
|
||||
function authorinfo($title = null, $body = null) {
|
||||
function authorinfo($title = null, $body = null)
|
||||
{
|
||||
if (config('author.info') == 'true') {
|
||||
return '<div class="author-info"><h4>by <strong>' . $title . '</strong></h4>' . $body . '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
function head_contents($title, $description, $canonical) {
|
||||
function head_contents($title, $description, $canonical)
|
||||
{
|
||||
$styleImage = config('lightbox');
|
||||
$jq = config('jquery');
|
||||
$output = '';
|
||||
|
|
@ -1597,8 +1620,7 @@ function head_contents($title, $description, $canonical) {
|
|||
$lightbox = '<script src="' . site_url() . 'system/plugins/lightbox/js/lightbox-2.6.min.js"></script>';
|
||||
$corejs = '<script src="' . site_url() . 'system/resources/htmly.js"></script>';
|
||||
$webmasterTools = '';
|
||||
if(!empty($wmt_id))
|
||||
{
|
||||
if(!empty($wmt_id)) {
|
||||
$webmasterTools = '<meta name="google-site-verification" content="' . $wmt_id . '" />';
|
||||
}
|
||||
|
||||
|
|
@ -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 '</ul></div>';
|
||||
}
|
||||
|
||||
// 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 = '/\<!--' . $tag . '(.+)' . $tag . '--\>/';
|
||||
$ary = array();
|
||||
if (preg_match($reg, $string, $ary)) {
|
||||
if (isset($ary[1])) {
|
||||
$result = trim($ary[1]);
|
||||
if(!empty($result))
|
||||
{
|
||||
if(!empty($result)) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
@ -1728,6 +1756,7 @@ function get_content_tag($tag, $string, $alt = null) {
|
|||
return $alt;
|
||||
}
|
||||
|
||||
function remove_html_comments($content) {
|
||||
function remove_html_comments($content)
|
||||
{
|
||||
return trim(preg_replace('/(\s|)<!--(.*)-->(\s|)/', '', $content));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
<?php
|
||||
class OPML
|
||||
class opml
|
||||
{
|
||||
private $data;
|
||||
private $writer;
|
||||
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
<?php
|
||||
|
||||
class CacheOneFile {
|
||||
|
||||
class CacheOneFile
|
||||
{
|
||||
protected $fileName = "";
|
||||
protected $holdTime = 43200; //12h
|
||||
|
||||
public function __construct($fileName, $holdTime = 43200) {
|
||||
public function __construct($fileName, $holdTime = 43200)
|
||||
{
|
||||
$this->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 = "<h3>Updated to<h3>";
|
||||
$string .= "<h2>[" . $releases[0]['tag_name'] . "] " . $releases[0]['name'] . "</h2>\n";
|
||||
|
|
@ -4055,7 +4067,8 @@ kI26oQ==
|
|||
return $string;
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
public function getName()
|
||||
{
|
||||
return $this->infos[0]['tag_name'];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,4 +7,4 @@
|
|||
});
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
})(jQuery);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue