diff --git a/system/htmly.php b/system/htmly.php
index 92f7aa7..8405dab 100644
--- a/system/htmly.php
+++ b/system/htmly.php
@@ -1,17 +1,16 @@
'Profile for: ' . $bio->title . ' - ' . blog_title(),
+ 'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.',
+ 'canonical' => site_url() . 'author/' . $profile,
+ 'page' => $page,
+ 'posts' => null,
+ 'bio' => $bio->body,
+ 'name' => $bio->title,
+ 'bodyclass' => 'inprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
+ die;
+ }
- render('edit-page', array(
- 'title' => 'Edit page - ' . blog_title(),
+ render('profile', array(
+ 'title' => 'Profile for: ' . $bio->title . ' - ' . blog_title(),
+ 'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.',
+ 'canonical' => site_url() . 'author/' . $profile,
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bio' => $bio->body,
+ 'name' => $bio->title,
+ 'bodyclass' => 'inprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
+});
+
+// Edit the profile
+get('/edit/profile', function () {
+
+ if (login()) {
+
+ config('views.root', 'system/admin/views');
+ render('edit-profile', array(
+ 'title' => 'Edit profile - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'editpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ',
- 'p' => $page,
- 'type' => 'staticpage',
+ 'bodyclass' => 'editprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile',
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
-post("/:static/:sub/edit", function ($static, $sub) {
+
+// Get submitted data from edit profile page
+post('/edit/profile', function () {
+
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if (!login()) {
+ $user = $_SESSION[config("site.url")]['user'];
+ $title = from($_REQUEST, 'title');
+ $content = from($_REQUEST, 'content');
+ if ($proper && !empty($title) && !empty($content)) {
+ edit_profile($title, $content, $user);
+ } else {
+ $message['error'] = '';
+ if (empty($title)) {
+ $message['error'] .= '
Title field is required.';
+ }
+ if (empty($content)) {
+ $message['error'] .= 'Content field is required.';
+ }
+ if (!$proper) {
+ $message['error'] .= 'CSRF Token not correct.';
+ }
+ config('views.root', 'system/admin/views');
+
+ render('edit-profile', array(
+ 'title' => 'Edit profile - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'error' => '' . $message['error'] . '
',
+ 'postTitle' => $title,
+ 'postContent' => $content,
+ 'bodyclass' => 'editprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile'
+ ));
+ }
+});
+
+// Show the "Add post" page
+get('/add/post', function () {
+
+ if (login()) {
+
+ config('views.root', 'system/admin/views');
+
+ render('add-post', array(
+ 'title' => 'Add post - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'addpost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post'
+ ));
+ } else {
$login = site_url() . 'login';
header("location: $login");
}
+});
+
+// Submitted add post data
+post('/add/post', function () {
+
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
+ $img = from($_REQUEST, 'img');
+ $vid = from($_REQUEST, 'vid');
+ $tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
- $oldfile = from($_REQUEST, 'oldfile');
- $destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
- if ($destination === null) {
- $destination = $static . "/" . $sub;
- }
- if ($proper && !empty($title) && !empty($content)) {
+ $user = $_SESSION[config("site.url")]['user'];
+ if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
if (!empty($url)) {
- edit_page($title, $url, $content, $oldfile, $destination, $description);
+ add_post($title, $tag, $url, $content, $user, $description, $img, $vid);
} else {
$url = $title;
- edit_page($title, $url, $content, $oldfile, $destination, $description);
+ add_post($title, $tag, $url, $content, $user, $description, $img, $vid);
}
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= 'Title field is required.';
}
+ if (empty($tag)) {
+ $message['error'] .= 'Tag field is required.';
+ }
if (empty($content)) {
$message['error'] .= 'Content field is required.';
}
@@ -186,516 +277,568 @@ post("/:static/:sub/edit", function ($static, $sub) {
$message['error'] .= 'CSRF Token not correct.';
}
config('views.root', 'system/admin/views');
-
- render('edit-page', array(
- 'title' => 'Edit page - ' . blog_title(),
+ render('add-post', array(
+ 'title' => 'Add post- ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '' . $message['error'] . '
',
- 'oldfile' => $oldfile,
'postTitle' => $title,
+ 'postImg' => $img,
+ 'postVid' => $vid,
+ 'postTag' => $tag,
'postUrl' => $url,
'postContent' => $content,
- 'bodyclass' => 'editpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page'
+ 'bodyclass' => 'addpost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post'
));
}
});
-get("/:static/:sub/delete", function ($static, $sub) {
+// Show the static add page
+get('/add/page', function () {
if (login()) {
config('views.root', 'system/admin/views');
- $post = get_static_post($static);
- if (!$post) {
- not_found();
- }
-
- $post = $post[0];
-
- $page = get_static_sub_post($static, $sub);
-
- if (!$page) {
- not_found();
- }
-
- $page = $page[0];
-
- render('delete-page', array(
- 'title' => 'Delete page - ' . blog_title(),
+ render('add-page', array(
+ 'title' => 'Add page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'deletepage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . '' . $page->title,
- 'p' => $page,
- 'type' => 'staticpage',
+ 'bodyclass' => 'addpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page'
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
-post("/:static/:sub/delete", function () {
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if ($proper && login()) {
- $file = from($_REQUEST, 'file');
- $destination = from($_GET, 'destination');
- delete_page($file, $destination);
- }
-});
+// Submitted static add page data
+post('/add/page', function () {
-// The blog post page
-get('/:year/:month/:name', function ($year, $month, $name) {
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if (config("views.counter") != "true") {
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
+ $title = from($_REQUEST, 'title');
+ $url = from($_REQUEST, 'url');
+ $content = from($_REQUEST, 'content');
+ $description = from($_REQUEST, 'description');
+ if ($proper && !empty($title) && !empty($content) && login()) {
+ if (!empty($url)) {
+ add_page($title, $url, $content, $description);
+ } else {
+ $url = $title;
+ add_page($title, $url, $content, $description);
+ }
+ } else {
+ $message['error'] = '';
+ if (empty($title)) {
+ $message['error'] .= 'Title field is required.';
+ }
+ if (empty($content)) {
+ $message['error'] .= 'Content field is required.';
+ }
+ if (!$proper) {
+ $message['error'] .= 'CSRF Token not correct.';
}
+ config('views.root', 'system/admin/views');
+ render('add-page', array(
+ 'title' => 'Add page - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'error' => '' . $message['error'] . '
',
+ 'postTitle' => $title,
+ 'postUrl' => $url,
+ 'postContent' => $content,
+ 'bodyclass' => 'addpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page'
+ ));
}
+});
- $post = find_post($year, $month, $name);
+// Show admin/posts
+get('/admin/posts', function () {
- $current = $post['current'];
+ $user = $_SESSION[config("site.url")]['user'];
+ $role = user('role', $user);
+ if (login()) {
- if (!$current) {
- not_found();
- }
+ config('views.root', 'system/admin/views');
+ if ($role === 'admin') {
- if (config("views.counter") == "true") {
- add_view($current->file);
+ config('views.root', 'system/admin/views');
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = 20;
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
- }
- }
+ $posts = get_posts(null, $page, $perpage);
- $bio = get_bio($current->author);
+ $total = '';
- if (isset($bio[0])) {
- $bio = $bio[0];
- } else {
- $bio = default_profile($current->author);
- }
+ if (empty($posts) || $page < 1) {
- if (array_key_exists('prev', $post)) {
- $prev = $post['prev'];
- } else {
- $prev = array();
- }
+ // a non-existing page
+ render('no-posts', array(
+ 'title' => 'All blog posts - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'noposts',
+ ));
- if (array_key_exists('next', $post)) {
- $next = $post['next'];
+ die;
+ }
+
+ $tl = blog_tagline();
+
+ if ($tl) {
+ $tagline = ' - ' . $tl;
+ } else {
+ $tagline = '';
+ }
+
+ render('posts-list', array(
+ 'title' => 'All blog posts - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'heading' => 'All blog posts',
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bodyclass' => 'all-posts',
+ 'breadcrumb' => '',
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
+ } else {
+ render('denied', array(
+ 'title' => 'All blog posts - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'denied',
+ 'breadcrumb' => '',
+ ));
+ }
} else {
- $next = array();
+ $login = site_url() . 'login';
+ header("location: $login");
}
-
- render('post', array(
- 'title' => $current->title . ' - ' . blog_title(),
- 'description' => $current->description,
- 'canonical' => $current->url,
- 'p' => $current,
- 'authorinfo' => authorinfo($bio->title, $bio->body),
- 'bodyclass' => 'inpost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title,
- 'prev' => has_prev($prev),
- 'next' => has_next($next),
- 'type' => 'blogpost',
- ));
});
-// Edit blog post
-get('/:year/:month/:name/edit', function ($year, $month, $name) {
+// Show admin/mine
+get('/admin/mine', function () {
if (login()) {
- $user = $_SESSION[config("site.url")]['user'];
- $role = user('role', $user);
-
config('views.root', 'system/admin/views');
- $post = find_post($year, $month, $name);
- if (!$post) {
- not_found();
- }
+ $profile = $_SESSION[config("site.url")]['user'];
- $current = $post['current'];
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = config('profile.perpage');
- if ($user === $current->author || $role === 'admin') {
- render('edit-post', array(
- 'title' => 'Edit post - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'p' => $current,
- 'bodyclass' => 'editpost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
- ));
+ $posts = get_profile($profile, $page, $perpage);
+
+ $total = get_count($profile, 'dirname');
+
+ $bio = get_bio($profile);
+
+ if (isset($bio[0])) {
+ $bio = $bio[0];
} else {
- render('denied', array(
- 'title' => 'Edit post - ' . blog_title(),
+ $bio = default_profile($profile);
+ }
+
+ if (empty($posts) || $page < 1) {
+ render('user-posts', array(
+ 'title' => 'My blog posts - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'p' => $current,
- 'bodyclass' => 'denied',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
+ 'page' => $page,
+ 'heading' => 'My posts',
+ 'posts' => null,
+ 'bio' => $bio->body,
+ 'name' => $bio->title,
+ 'bodyclass' => 'userposts',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
+ 'pagination' => has_pagination($total, $perpage, $page)
));
+ die;
}
+
+ render('user-posts', array(
+ 'title' => 'My blog posts - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'heading' => 'My posts',
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bio' => $bio->body,
+ 'name' => $bio->title,
+ 'bodyclass' => 'userposts',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
-// Get edited data for blog post
-post('/:year/:month/:name/edit', function () {
+// Show import page
+get('/admin/import', function () {
+ if (login()) {
+ config('views.root', 'system/admin/views');
+ render('import', array(
+ 'title' => 'Import feed - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'importfeed',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed'
+ ));
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
+ }
+ die;
+});
+
+// Submitted import page data
+post('/admin/import', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- $title = from($_REQUEST, 'title');
- $img = from($_REQUEST, 'img');
- $vid = from($_REQUEST, 'vid');
- $tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
- $content = from($_REQUEST, 'content');
- $oldfile = from($_REQUEST, 'oldfile');
- $destination = from($_GET, 'destination');
- $description = from($_REQUEST, 'description');
- $date = from($_REQUEST, 'date');
- $time = from($_REQUEST, 'time');
- $dateTime = null;
- if ($date !== null && $time !== null) {
- $dateTime = $date . ' ' . $time;
- }
+ $credit = from($_REQUEST, 'credit');
+ if (login() && !empty($url) && $proper) {
- if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
- if (empty($url)) {
- $url = $title;
+ get_feed($url, $credit);
+ $log = get_feed($url, $credit);
+
+ if (!empty($log)) {
+
+ config('views.root', 'system/admin/views');
+
+ render('import', array(
+ 'title' => 'Import feed - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'error' => '',
+ 'bodyclass' => 'editprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed'
+ ));
}
- edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $img, $vid);
} else {
$message['error'] = '';
- if (empty($title)) {
- $message['error'] .= 'Title field is required.';
- }
- if (empty($tag)) {
- $message['error'] .= 'Tag field is required.';
- }
- if (empty($content)) {
- $message['error'] .= 'Content field is required.';
+ if (empty($url)) {
+ $message['error'] .= 'You need to specify the feed url.';
}
if (!$proper) {
$message['error'] .= 'CSRF Token not correct.';
}
+
config('views.root', 'system/admin/views');
- render('edit-post', array(
- 'title' => 'Edit post - ' . blog_title(),
+ render('import', array(
+ 'title' => 'Import feed - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '' . $message['error'] . '
',
- 'oldfile' => $oldfile,
- 'postTitle' => $title,
- 'postImg' => $img,
- 'postVid' => $vid,
- 'postTag' => $tag,
- 'postUrl' => $url,
- 'postContent' => $content,
- 'bodyclass' => 'editpost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit post'
+ 'url' => $url,
+ 'bodyclass' => 'editprofile',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login'
));
}
});
-// Delete blog post
-get('/:year/:month/:name/delete', function ($year, $month, $name) {
-
+// Show Config page
+get('/admin/config', function () {
if (login()) {
-
- $user = $_SESSION[config("site.url")]['user'];
- $role = user('role', $user);
-
config('views.root', 'system/admin/views');
- $post = find_post($year, $month, $name);
-
- if (!$post) {
- not_found();
- }
-
- $current = $post['current'];
-
- if ($user === $current->author || $role === 'admin') {
- render('delete-post', array(
- 'title' => 'Delete post - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'p' => $current,
- 'bodyclass' => 'deletepost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
- ));
- } else {
- render('denied', array(
- 'title' => 'Delete post - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'p' => $current,
- 'bodyclass' => 'deletepost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
- ));
- }
+ render('config', array(
+ 'title' => 'Config - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'config',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Config'
+ ));
} else {
$login = site_url() . 'login';
header("location: $login");
}
+ die;
});
-// Get deleted data for blog post
-post('/:year/:month/:name/delete', function () {
+// Submitted Config page data
+post('/admin/config', function () {
+ error_reporting(E_ALL);
+ ini_set("display_errors", 1);
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if ($proper && login()) {
- $file = from($_REQUEST, 'file');
- $destination = from($_GET, 'destination');
- delete_post($file, $destination);
+ if (login() && $proper) {
+ $newKey = from($_REQUEST, 'newKey');
+ $newValue = from($_REQUEST, 'newValue');
+
+ $new_config = array();
+ $new_Keys = array();
+ if (!empty($newKey)) {
+ $new_Keys[$newKey] = $newValue;
+ }
+ foreach ($_POST as $name => $value) {
+ if (substr($name, 0, 8) == "-config-") {
+ $name = str_replace("_", ".", substr($name, 8));
+ $new_config[$name] = $value;
+ }
+ }
+ save_config($new_config, $new_Keys);
+ $login = site_url() . 'admin/config';
+ header("location: $login");
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
+ die;
});
-// The author page
-get('/author/:profile', function ($profile) {
-
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
+// Show Backup page
+get('/admin/backup', function () {
+ if (login()) {
+ config('views.root', 'system/admin/views');
+ render('backup', array(
+ 'title' => 'Backup content - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'backup',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup'
+ ));
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
+ die;
+});
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('profile.perpage');
-
- $posts = get_profile($profile, $page, $perpage);
-
- $total = get_count($profile, 'dirname');
-
- $bio = get_bio($profile);
-
- if (isset($bio[0])) {
- $bio = $bio[0];
+// Show Create backup page
+get('/admin/backup-start', function () {
+ if (login()) {
+ config('views.root', 'system/admin/views');
+ render('backup-start', array(
+ 'title' => 'Backup content started - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'startbackup',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup started'
+ ));
} else {
- $bio = default_profile($profile);
+ $login = site_url() . 'login';
+ header("location: $login");
}
+ die;
+});
- if (empty($posts) || $page < 1) {
- render('profile', array(
- 'title' => 'Profile for: ' . $bio->title . ' - ' . blog_title(),
- 'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.',
- 'canonical' => site_url() . 'author/' . $profile,
- 'page' => $page,
- 'posts' => null,
- 'bio' => $bio->body,
- 'name' => $bio->title,
- 'bodyclass' => 'inprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
- 'pagination' => has_pagination($total, $perpage, $page)
+// Show clear cache page
+get('/admin/clear-cache', function () {
+ if (login()) {
+ config('views.root', 'system/admin/views');
+ render('clear-cache', array(
+ 'title' => 'Clearing cache started - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'clearcache',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Clearing cache started'
));
- die;
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
-
- render('profile', array(
- 'title' => 'Profile for: ' . $bio->title . ' - ' . blog_title(),
- 'description' => 'Profile page and all posts by ' . $bio->title . ' on ' . blog_title() . '.',
- 'canonical' => site_url() . 'author/' . $profile,
- 'page' => $page,
- 'posts' => $posts,
- 'bio' => $bio->body,
- 'name' => $bio->title,
- 'bodyclass' => 'inprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
+ die;
});
-// Edit the profile
-get('/edit/profile', function () {
-
+// Show Update page
+get('/admin/update', function () {
if (login()) {
-
config('views.root', 'system/admin/views');
- render('edit-profile', array(
- 'title' => 'Edit profile - ' . blog_title(),
+ render('update', array(
+ 'title' => 'Check for Update - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'editprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile',
+ 'bodyclass' => 'updatepage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Update HTMLy'
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
+ die;
});
-// Get edited data for static page
-post('/edit/profile', function () {
-
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
+// Show the update now link
+get('/admin/update/now/:csrf', function ($CSRF) {
- $user = $_SESSION[config("site.url")]['user'];
- $title = from($_REQUEST, 'title');
- $content = from($_REQUEST, 'content');
- if ($proper && !empty($title) && !empty($content)) {
- edit_profile($title, $content, $user);
- } else {
- $message['error'] = '';
- if (empty($title)) {
- $message['error'] .= 'Title field is required.';
- }
- if (empty($content)) {
- $message['error'] .= 'Content field is required.';
- }
- if (!$proper) {
- $message['error'] .= 'CSRF Token not correct.';
- }
+ $proper = is_csrf_proper($CSRF);
+ $updater = new \Kanti\HubUpdater(array(
+ 'name' => 'danpros/htmly',
+ 'prerelease' => !!config("prerelease"),
+ ));
+ if (login() && $proper && $updater->able()) {
+ $updater->update();
config('views.root', 'system/admin/views');
-
- render('edit-profile', array(
- 'title' => 'Edit profile - ' . blog_title(),
+ render('updated-to', array(
+ 'title' => 'Updated - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'error' => '' . $message['error'] . '
',
- 'postTitle' => $title,
- 'postContent' => $content,
- 'bodyclass' => 'editprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit profile'
+ 'info' => $updater->getCurrentInfo(),
+ 'bodyclass' => 'updatepage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Update HTMLy'
));
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
});
-get('/admin/posts', function () {
+// Show the tag page
+get('/tag/:tag', function ($tag) {
- $user = $_SESSION[config("site.url")]['user'];
- $role = user('role', $user);
- if (login()) {
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
- config('views.root', 'system/admin/views');
- if ($role === 'admin') {
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = config('tag.perpage');
- config('views.root', 'system/admin/views');
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = 20;
+ $posts = get_tag($tag, $page, $perpage, false);
- $posts = get_posts(null, $page, $perpage);
+ $total = get_count($tag, 'filename');
- $total = '';
+ if (empty($posts) || $page < 1) {
+ // a non-existing page
+ not_found();
+ }
- if (empty($posts) || $page < 1) {
+ render('main', array(
+ 'title' => 'Posts tagged: ' . $tag . ' - ' . blog_title(),
+ 'description' => 'All posts tagged: ' . $tag . ' on ' . blog_title() . '.',
+ 'canonical' => site_url() . 'tag/' . $tag,
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bodyclass' => 'intag',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Posts tagged: ' . $tag,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
+});
- // a non-existing page
- render('no-posts', array(
- 'title' => 'All blog posts - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'noposts',
- ));
+// Show the archive page
+get('/archive/:req', function ($req) {
- die;
- }
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
- $tl = blog_tagline();
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = config('archive.perpage');
- if ($tl) {
- $tagline = ' - ' . $tl;
- } else {
- $tagline = '';
- }
+ $posts = get_archive($req, $page, $perpage);
- render('posts-list', array(
- 'title' => 'All blog posts - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'heading' => 'All blog posts',
- 'page' => $page,
- 'posts' => $posts,
- 'bodyclass' => 'all-posts',
- 'breadcrumb' => '',
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
- } else {
- render('denied', array(
- 'title' => 'All blog posts - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'denied',
- 'breadcrumb' => '',
- ));
- }
+ $total = get_count($req, 'filename');
+
+ if (empty($posts) || $page < 1) {
+ // a non-existing page
+ not_found();
+ }
+
+ $time = explode('-', $req);
+ $date = strtotime($req);
+
+ if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
+ $timestamp = date('d F Y', $date);
+ } elseif (isset($time[0]) && isset($time[1])) {
+ $timestamp = date('F Y', $date);
} else {
- $login = site_url() . 'login';
- header("location: $login");
+ $timestamp = $req;
}
+
+ if (!$date) {
+ // a non-existing page
+ not_found();
+ }
+
+ render('main', array(
+ 'title' => 'Archive for: ' . $timestamp . ' - ' . blog_title(),
+ 'description' => 'Archive page for: ' . $timestamp . ' on ' . blog_title() . '.',
+ 'canonical' => site_url() . 'archive/' . $req,
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bodyclass' => 'inarchive',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Archive for: ' . $timestamp,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
});
-// The author page
-get('/admin/mine', function () {
+// Show the search page
+get('/search/:keyword', function ($keyword) {
- if (login()) {
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
- config('views.root', 'system/admin/views');
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = config('search.perpage');
- $profile = $_SESSION[config("site.url")]['user'];
+ $posts = get_keyword($keyword, $page, $perpage);
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('profile.perpage');
+ $total = keyword_count($keyword);
- $posts = get_profile($profile, $page, $perpage);
+ if (empty($posts) || $page < 1) {
+ // a non-existing page
+ render('404-search', null, false);
+ die;
+ }
- $total = get_count($profile, 'dirname');
+ render('main', array(
+ 'title' => 'Search results for: ' . $keyword . ' - ' . blog_title(),
+ 'description' => 'Search results for: ' . $keyword . ' on ' . blog_title() . '.',
+ 'canonical' => site_url() . 'search/' . $keyword,
+ 'page' => $page,
+ 'posts' => $posts,
+ 'bodyclass' => 'insearch',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Search results for: ' . $keyword,
+ 'pagination' => has_pagination($total, $perpage, $page)
+ ));
+});
- $bio = get_bio($profile);
+// The JSON API
+get('/api/json', function () {
- if (isset($bio[0])) {
- $bio = $bio[0];
- } else {
- $bio = default_profile($profile);
- }
+ header('Content-type: application/json');
- if (empty($posts) || $page < 1) {
- render('user-posts', array(
- 'title' => 'My blog posts - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'page' => $page,
- 'heading' => 'My posts',
- 'posts' => null,
- 'bio' => $bio->body,
- 'name' => $bio->title,
- 'bodyclass' => 'userposts',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
- die;
- }
+ $page = from($_GET, 'page');
+ $page = $page ? (int)$page : 1;
+ $perpage = config('json.count');
- render('user-posts', array(
- 'title' => 'My blog posts - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'heading' => 'My posts',
- 'page' => $page,
- 'posts' => $posts,
- 'bio' => $bio->body,
- 'name' => $bio->title,
- 'bodyclass' => 'userposts',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
+ echo generate_json(get_posts(null, $page, $perpage));
});
-// The static page
+// Show the RSS feed
+get('/feed/rss', function () {
+
+ header('Content-Type: application/rss+xml');
+
+ // Show an RSS feed with the 30 latest posts
+ echo generate_rss(get_posts(null, 1, config('rss.count')));
+});
+
+// Generate OPML file
+get('/feed/opml', function () {
+
+ header('Content-Type: text/xml');
+
+ // Generate OPML file for the RSS
+ echo generate_opml();
+});
+
+// Show various page (top-level), admin, login, sitemap, static page.
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') {
@@ -764,121 +907,9 @@ get('/:static', function ($static) {
if (config("views.counter") != "true") {
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
- }
- }
-
- $post = get_static_post($static);
-
- if (!$post) {
- not_found();
- }
-
- $post = $post[0];
-
- if (config("views.counter") == "true") {
- add_view($post->file);
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
- }
- }
-
- render('static', array(
- 'title' => $post->title . ' - ' . blog_title(),
- 'description' => $post->description,
- 'canonical' => $post->url,
- 'bodyclass' => 'inpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title,
- 'p' => $post,
- 'type' => 'staticpage',
- ));
- }
-});
-
-// Edit the static page
-get('/:static/edit', function ($static) {
-
- if (login()) {
-
- config('views.root', 'system/admin/views');
- $post = get_static_post($static);
-
- if (!$post) {
- not_found();
- }
-
- $post = $post[0];
-
- render('edit-page', array(
- 'title' => 'Edit page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'editpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title,
- 'p' => $post,
- 'type' => 'staticpage',
- ));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
-});
-
-// Get edited data for static page
-post('/:static/edit', function () {
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
-
- if (!login()) {
- $login = site_url() . 'login';
- header("location: $login");
- }
-
- $title = from($_REQUEST, 'title');
- $url = from($_REQUEST, 'url');
- $content = from($_REQUEST, 'content');
- $oldfile = from($_REQUEST, 'oldfile');
- $destination = from($_GET, 'destination');
- $description = from($_REQUEST, 'description');
- if ($proper && !empty($title) && !empty($content)) {
- if (!empty($url)) {
- edit_page($title, $url, $content, $oldfile, $destination, $description);
- } else {
- $url = $title;
- edit_page($title, $url, $content, $oldfile, $destination, $description);
- }
- } else {
- $message['error'] = '';
- if (empty($title)) {
- $message['error'] .= 'Title field is required.';
- }
- if (empty($content)) {
- $message['error'] .= 'Content field is required.';
- }
- if (!$proper) {
- $message['error'] .= 'CSRF Token not correct.';
- }
- config('views.root', 'system/admin/views');
-
- render('edit-page', array(
- 'title' => 'Edit page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'error' => '' . $message['error'] . '
',
- 'oldfile' => $oldfile,
- 'postTitle' => $title,
- 'postUrl' => $url,
- 'postContent' => $content,
- 'bodyclass' => 'editpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page'
- ));
- }
-});
-
-// Deleted the static page
-get('/:static/delete', function ($static) {
-
- if (login()) {
+ }
+ }
- config('views.root', 'system/admin/views');
$post = get_static_post($static);
if (!$post) {
@@ -887,45 +918,46 @@ get('/:static/delete', function ($static) {
$post = $post[0];
- render('delete-page', array(
- 'title' => 'Delete page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'deletepage',
+ if (config("views.counter") == "true") {
+ add_view($post->file);
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
+ }
+
+ render('static', array(
+ 'title' => $post->title . ' - ' . blog_title(),
+ 'description' => $post->description,
+ 'canonical' => $post->url,
+ 'bodyclass' => 'inpage',
'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title,
'p' => $post,
'type' => 'staticpage',
));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
-});
-
-// Get deleted data for static page
-post('/:static/delete', function () {
-
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if ($proper && login()) {
- $file = from($_REQUEST, 'file');
- $destination = from($_GET, 'destination');
- delete_page($file, $destination);
}
});
-// Add blog post
-get('/add/post', function () {
+// Show the add sub static page
+get('/:static/add', function ($static) {
if (login()) {
config('views.root', 'system/admin/views');
- render('add-post', array(
- 'title' => 'Add post - ' . blog_title(),
+ $post = get_static_post($static);
+
+ if (!$post) {
+ not_found();
+ }
+
+ $post = $post[0];
+
+ render('add-page', array(
+ 'title' => 'Add page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'addpost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post'
+ 'bodyclass' => 'addpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page'
));
} else {
$login = site_url() . 'login';
@@ -933,34 +965,27 @@ get('/add/post', function () {
}
});
-// Get submitted blog post data
-post('/add/post', function () {
+// Submitted data from add sub static page
+post('/:static/add', function ($static) {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
- $img = from($_REQUEST, 'img');
- $vid = from($_REQUEST, 'vid');
- $tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
$description = from($_REQUEST, 'description');
- $user = $_SESSION[config("site.url")]['user'];
- if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
+ if ($proper && !empty($title) && !empty($content) && login()) {
if (!empty($url)) {
- add_post($title, $tag, $url, $content, $user, $description, $img, $vid);
+ add_sub_page($title, $url, $content, $static, $description);
} else {
$url = $title;
- add_post($title, $tag, $url, $content, $user, $description, $img, $vid);
+ add_sub_page($title, $url, $content, $static, $description);
}
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= 'Title field is required.';
}
- if (empty($tag)) {
- $message['error'] .= 'Tag field is required.';
- }
if (empty($content)) {
$message['error'] .= 'Content field is required.';
}
@@ -968,36 +993,42 @@ post('/add/post', function () {
$message['error'] .= 'CSRF Token not correct.';
}
config('views.root', 'system/admin/views');
- render('add-post', array(
- 'title' => 'Add post- ' . blog_title(),
+ render('add-page', array(
+ 'title' => 'Add page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '' . $message['error'] . '
',
'postTitle' => $title,
- 'postImg' => $img,
- 'postVid' => $vid,
- 'postTag' => $tag,
'postUrl' => $url,
'postContent' => $content,
- 'bodyclass' => 'addpost',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post'
+ 'bodyclass' => 'addpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page'
));
}
});
-// Add the static page
-get('/add/page', function () {
+// Show edit the static page
+get('/:static/edit', function ($static) {
if (login()) {
config('views.root', 'system/admin/views');
+ $post = get_static_post($static);
- render('add-page', array(
- 'title' => 'Add page - ' . blog_title(),
+ if (!$post) {
+ not_found();
+ }
+
+ $post = $post[0];
+
+ render('edit-page', array(
+ 'title' => 'Edit page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'addpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page'
+ 'bodyclass' => 'editpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title,
+ 'p' => $post,
+ 'type' => 'staticpage',
));
} else {
$login = site_url() . 'login';
@@ -1005,41 +1036,27 @@ get('/add/page', function () {
}
});
-// Add the static page
-get('/add/page', function () {
-
- if (login()) {
-
- config('views.root', 'system/admin/views');
+// Get edited data from static page
+post('/:static/edit', function () {
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- render('add-page', array(
- 'title' => 'Add page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'addpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page'
- ));
- } else {
+ if (!login()) {
$login = site_url() . 'login';
header("location: $login");
}
-});
-
-// Get submitted static page data
-post('/add/page', function () {
-
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
+ $oldfile = from($_REQUEST, 'oldfile');
+ $destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
- if ($proper && !empty($title) && !empty($content) && login()) {
+ if ($proper && !empty($title) && !empty($content)) {
if (!empty($url)) {
- add_page($title, $url, $content, $description);
+ edit_page($title, $url, $content, $oldfile, $destination, $description);
} else {
$url = $title;
- add_page($title, $url, $content, $description);
+ edit_page($title, $url, $content, $oldfile, $destination, $description);
}
} else {
$message['error'] = '';
@@ -1051,424 +1068,369 @@ post('/add/page', function () {
}
if (!$proper) {
$message['error'] .= 'CSRF Token not correct.';
- }
- config('views.root', 'system/admin/views');
- render('add-page', array(
- 'title' => 'Add page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'error' => '' . $message['error'] . '
',
- 'postTitle' => $title,
- 'postUrl' => $url,
- 'postContent' => $content,
- 'bodyclass' => 'addpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add page'
- ));
- }
-});
-
-// Import page
-get('/admin/import', function () {
- if (login()) {
- config('views.root', 'system/admin/views');
- render('import', array(
- 'title' => 'Import feed - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'importfeed',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed'
- ));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
- die;
-});
-
-// Get import post
-post('/admin/import', function () {
-
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
-
- $url = from($_REQUEST, 'url');
- $credit = from($_REQUEST, 'credit');
- if (login() && !empty($url) && $proper) {
-
- get_feed($url, $credit);
- $log = get_feed($url, $credit);
-
- if (!empty($log)) {
-
- config('views.root', 'system/admin/views');
-
- render('import', array(
- 'title' => 'Import feed - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'error' => '',
- 'bodyclass' => 'editprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Import feed'
- ));
- }
- } else {
- $message['error'] = '';
- if (empty($url)) {
- $message['error'] .= 'You need to specify the feed url.';
- }
- if (!$proper) {
- $message['error'] .= 'CSRF Token not correct.';
- }
-
- config('views.root', 'system/admin/views');
-
- render('import', array(
- 'title' => 'Import feed - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'error' => '' . $message['error'] . '
',
- 'url' => $url,
- 'bodyclass' => 'editprofile',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Login'
- ));
- }
-});
-
-// Config page
-get('/admin/config', function () {
- if (login()) {
- config('views.root', 'system/admin/views');
- render('config', array(
- 'title' => 'Config - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'config',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Config'
- ));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
- die;
-});
-
-
-// Config page
-post('/admin/config', function () {
- error_reporting(E_ALL);
- ini_set("display_errors", 1);
-
- $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if (login() && $proper) {
- $newKey = from($_REQUEST, 'newKey');
- $newValue = from($_REQUEST, 'newValue');
-
- $new_config = array();
- $new_Keys = array();
- if (!empty($newKey)) {
- $new_Keys[$newKey] = $newValue;
- }
- foreach ($_POST as $name => $value) {
- if (substr($name, 0, 8) == "-config-") {
- $name = str_replace("_", ".", substr($name, 8));
- $new_config[$name] = $value;
- }
- }
- save_config($new_config, $new_Keys);
- $login = site_url() . 'admin/config';
- header("location: $login");
- } else {
- $login = site_url() . 'login';
- header("location: $login");
- }
- die;
-});
-
-// Backup page
-get('/admin/backup', function () {
- if (login()) {
+ }
config('views.root', 'system/admin/views');
- render('backup', array(
- 'title' => 'Backup content - ' . blog_title(),
+
+ render('edit-page', array(
+ 'title' => 'Edit page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'backup',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup'
+ 'error' => '' . $message['error'] . '
',
+ 'oldfile' => $oldfile,
+ 'postTitle' => $title,
+ 'postUrl' => $url,
+ 'postContent' => $content,
+ 'bodyclass' => 'editpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page'
));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
}
- die;
});
-// Create Zip file
-get('/admin/backup-start', function () {
+// Deleted the static page
+get('/:static/delete', function ($static) {
+
if (login()) {
+
config('views.root', 'system/admin/views');
- render('backup-start', array(
- 'title' => 'Backup content started - ' . blog_title(),
+ $post = get_static_post($static);
+
+ if (!$post) {
+ not_found();
+ }
+
+ $post = $post[0];
+
+ render('delete-page', array(
+ 'title' => 'Delete page - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
- 'bodyclass' => 'startbackup',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Backup started'
+ 'bodyclass' => 'deletepage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title,
+ 'p' => $post,
+ 'type' => 'staticpage',
));
} else {
$login = site_url() . 'login';
header("location: $login");
}
- die;
});
-// Delete all cache
-get('/admin/clear-cache', function () {
- if (login()) {
- config('views.root', 'system/admin/views');
- render('clear-cache', array(
- 'title' => 'Clearing cache started - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'clearcache',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Clearing cache started'
- ));
- } else {
- $login = site_url() . 'login';
- header("location: $login");
+// Get deleted data for static page
+post('/:static/delete', function () {
+
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
+ if ($proper && login()) {
+ $file = from($_REQUEST, 'file');
+ $destination = from($_GET, 'destination');
+ delete_page($file, $destination);
}
- die;
});
+// Show the sb static page
+get('/:static/:sub', function ($static, $sub) {
-// The tag page
-get('/tag/:tag', function ($tag) {
+ $father_post = get_static_post($static);
+ if (!$father_post) {
+ not_found();
+ }
+ $post = get_static_sub_post($static, $sub);
+ if (!$post) {
+ not_found();
+ }
+ $post = $post[0];
+
+ if (config("views.counter") == "true") {
+ add_view($post->file);
+ }
if (!login()) {
file_cache($_SERVER['REQUEST_URI']);
}
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('tag.perpage');
-
- $posts = get_tag($tag, $page, $perpage, false);
+ render('static', array(
+ 'title' => $post->title . ' - ' . blog_title(),
+ 'description' => $post->description,
+ 'canonical' => $post->url,
+ 'bodyclass' => 'inpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title,
+ 'p' => $post,
+ 'type' => 'staticpage',
+ ));
+});
- $total = get_count($tag, 'filename');
+// Edit the sub static page
+get('/:static/:sub/edit', function ($static, $sub) {
- if (empty($posts) || $page < 1) {
- // a non-existing page
- not_found();
- }
+ if (login()) {
- render('main', array(
- 'title' => 'Posts tagged: ' . $tag . ' - ' . blog_title(),
- 'description' => 'All posts tagged: ' . $tag . ' on ' . blog_title() . '.',
- 'canonical' => site_url() . 'tag/' . $tag,
- 'page' => $page,
- 'posts' => $posts,
- 'bodyclass' => 'intag',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Posts tagged: ' . $tag,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
-});
+ config('views.root', 'system/admin/views');
+ $post = get_static_post($static);
-// The archive page
-get('/archive/:req', function ($req) {
+ if (!$post) {
+ not_found();
+ }
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
- }
+ $post = $post[0];
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('archive.perpage');
+ $page = get_static_sub_post($static, $sub);
- $posts = get_archive($req, $page, $perpage);
+ if (!$page) {
+ not_found();
+ }
- $total = get_count($req, 'filename');
+ $page = $page[0];
- if (empty($posts) || $page < 1) {
- // a non-existing page
- not_found();
+ render('edit-page', array(
+ 'title' => 'Edit page - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'editpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' » ',
+ 'p' => $page,
+ 'type' => 'staticpage',
+ ));
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
+});
- $time = explode('-', $req);
- $date = strtotime($req);
+// Submitted data from edit sub static page
+post('/:static/:sub/edit', function ($static, $sub) {
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
- if (isset($time[0]) && isset($time[1]) && isset($time[2])) {
- $timestamp = date('d F Y', $date);
- } elseif (isset($time[0]) && isset($time[1])) {
- $timestamp = date('F Y', $date);
- } else {
- $timestamp = $req;
+ if (!login()) {
+ $login = site_url() . 'login';
+ header("location: $login");
}
- if (!$date) {
- // a non-existing page
- not_found();
+ $title = from($_REQUEST, 'title');
+ $url = from($_REQUEST, 'url');
+ $content = from($_REQUEST, 'content');
+ $oldfile = from($_REQUEST, 'oldfile');
+ $destination = from($_GET, 'destination');
+ $description = from($_REQUEST, 'description');
+ if ($destination === null) {
+ $destination = $static . "/" . $sub;
}
+ if ($proper && !empty($title) && !empty($content)) {
+ if (!empty($url)) {
+ edit_page($title, $url, $content, $oldfile, $destination, $description);
+ } else {
+ $url = $title;
+ edit_page($title, $url, $content, $oldfile, $destination, $description);
+ }
+ } else {
+ $message['error'] = '';
+ if (empty($title)) {
+ $message['error'] .= 'Title field is required.';
+ }
+ if (empty($content)) {
+ $message['error'] .= 'Content field is required.';
+ }
+ if (!$proper) {
+ $message['error'] .= 'CSRF Token not correct.';
+ }
+ config('views.root', 'system/admin/views');
- render('main', array(
- 'title' => 'Archive for: ' . $timestamp . ' - ' . blog_title(),
- 'description' => 'Archive page for: ' . $timestamp . ' on ' . blog_title() . '.',
- 'canonical' => site_url() . 'archive/' . $req,
- 'page' => $page,
- 'posts' => $posts,
- 'bodyclass' => 'inarchive',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Archive for: ' . $timestamp,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
+ render('edit-page', array(
+ 'title' => 'Edit page - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'error' => '' . $message['error'] . '
',
+ 'oldfile' => $oldfile,
+ 'postTitle' => $title,
+ 'postUrl' => $url,
+ 'postContent' => $content,
+ 'bodyclass' => 'editpage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit page'
+ ));
+ }
});
-// The search page
-get('/search/:keyword', function ($keyword) {
+// Delete sub static page
+get('/:static/:sub/delete', function ($static, $sub) {
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
- }
+ if (login()) {
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('search.perpage');
+ config('views.root', 'system/admin/views');
+ $post = get_static_post($static);
- $posts = get_keyword($keyword, $page, $perpage);
+ if (!$post) {
+ not_found();
+ }
- $total = keyword_count($keyword);
+ $post = $post[0];
- if (empty($posts) || $page < 1) {
- // a non-existing page
- render('404-search', null, false);
- die;
- }
+ $page = get_static_sub_post($static, $sub);
- render('main', array(
- 'title' => 'Search results for: ' . $keyword . ' - ' . blog_title(),
- 'description' => 'Search results for: ' . $keyword . ' on ' . blog_title() . '.',
- 'canonical' => site_url() . 'search/' . $keyword,
- 'page' => $page,
- 'posts' => $posts,
- 'bodyclass' => 'insearch',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Search results for: ' . $keyword,
- 'pagination' => has_pagination($total, $perpage, $page)
- ));
+ if (!$page) {
+ not_found();
+ }
+
+ $page = $page[0];
+
+ render('delete-page', array(
+ 'title' => 'Delete page - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'bodyclass' => 'deletepage',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . '' . $page->title,
+ 'p' => $page,
+ 'type' => 'staticpage',
+ ));
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
+ }
});
-// The JSON API
-get('/api/json', function () {
+// Submitted data from delete sub static page
+post('/:static/:sub/delete', function () {
- header('Content-type: application/json');
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
+ if ($proper && login()) {
+ $file = from($_REQUEST, 'file');
+ $destination = from($_GET, 'destination');
+ delete_page($file, $destination);
+ }
+});
- $page = from($_GET, 'page');
- $page = $page ? (int)$page : 1;
- $perpage = config('json.count');
+// Show blog post page
+get('/:year/:month/:name', function ($year, $month, $name) {
- echo generate_json(get_posts(null, $page, $perpage));
-});
+ if (config("views.counter") != "true") {
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
+ }
-// Show the RSS feed
-get('/feed/rss', function () {
+ $post = find_post($year, $month, $name);
- header('Content-Type: application/rss+xml');
+ $current = $post['current'];
- // Show an RSS feed with the 30 latest posts
- echo generate_rss(get_posts(null, 1, config('rss.count')));
-});
+ if (!$current) {
+ not_found();
+ }
-// Generate OPML file
-get('/feed/opml', function () {
+ if (config("views.counter") == "true") {
+ add_view($current->file);
- header('Content-Type: text/xml');
+ if (!login()) {
+ file_cache($_SERVER['REQUEST_URI']);
+ }
+ }
- // Generate OPML file for the RSS
- echo generate_opml();
-});
+ $bio = get_bio($current->author);
-// Update page
-get('/admin/update', function () {
- if (login()) {
- config('views.root', 'system/admin/views');
- render('update', array(
- 'title' => 'Check for Update - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'updatepage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Update HTMLy'
- ));
+ if (isset($bio[0])) {
+ $bio = $bio[0];
} else {
- $login = site_url() . 'login';
- header("location: $login");
+ $bio = default_profile($current->author);
}
- die;
-});
-get('/admin/update/now/:csrf', function ($CSRF) {
+ if (array_key_exists('prev', $post)) {
+ $prev = $post['prev'];
+ } else {
+ $prev = array();
+ }
- $proper = is_csrf_proper($CSRF);
- $updater = new \Kanti\HubUpdater(array(
- 'name' => 'danpros/htmly',
- 'prerelease' => !!config("prerelease"),
- ));
- if (login() && $proper && $updater->able()) {
- $updater->update();
- config('views.root', 'system/admin/views');
- render('updated-to', array(
- 'title' => 'Updated - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'info' => $updater->getCurrentInfo(),
- 'bodyclass' => 'updatepage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » Update HTMLy'
- ));
+ if (array_key_exists('next', $post)) {
+ $next = $post['next'];
} else {
- $login = site_url() . 'login';
- header("location: $login");
+ $next = array();
}
+
+ render('post', array(
+ 'title' => $current->title . ' - ' . blog_title(),
+ 'description' => $current->description,
+ 'canonical' => $current->url,
+ 'p' => $current,
+ 'authorinfo' => authorinfo($bio->title, $bio->body),
+ 'bodyclass' => 'inpost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title,
+ 'prev' => has_prev($prev),
+ 'next' => has_next($next),
+ 'type' => 'blogpost',
+ ));
});
-get('/:static/add', function ($static) {
+// Edit blog post
+get('/:year/:month/:name/edit', function ($year, $month, $name) {
if (login()) {
- config('views.root', 'system/admin/views');
+ $user = $_SESSION[config("site.url")]['user'];
+ $role = user('role', $user);
- $post = get_static_post($static);
+ config('views.root', 'system/admin/views');
+ $post = find_post($year, $month, $name);
if (!$post) {
not_found();
}
- $post = $post[0];
+ $current = $post['current'];
- render('add-page', array(
- 'title' => 'Add page - ' . blog_title(),
- 'description' => blog_description(),
- 'canonical' => site_url(),
- 'bodyclass' => 'addpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page'
- ));
+ if ($user === $current->author || $role === 'admin') {
+ render('edit-post', array(
+ 'title' => 'Edit post - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'p' => $current,
+ 'bodyclass' => 'editpost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
+ ));
+ } else {
+ render('denied', array(
+ 'title' => 'Edit post - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'p' => $current,
+ 'bodyclass' => 'denied',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
+ ));
+ }
} else {
$login = site_url() . 'login';
header("location: $login");
}
});
-post('/:static/add', function ($static) {
+
+// Get edited data from blog post
+post('/:year/:month/:name/edit', function () {
$proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
$title = from($_REQUEST, 'title');
+ $img = from($_REQUEST, 'img');
+ $vid = from($_REQUEST, 'vid');
+ $tag = from($_REQUEST, 'tag');
$url = from($_REQUEST, 'url');
$content = from($_REQUEST, 'content');
+ $oldfile = from($_REQUEST, 'oldfile');
+ $destination = from($_GET, 'destination');
$description = from($_REQUEST, 'description');
- if ($proper && !empty($title) && !empty($content) && login()) {
- if (!empty($url)) {
- add_sub_page($title, $url, $content, $static, $description);
- } else {
+ $date = from($_REQUEST, 'date');
+ $time = from($_REQUEST, 'time');
+ $dateTime = null;
+ if ($date !== null && $time !== null) {
+ $dateTime = $date . ' ' . $time;
+ }
+
+ if ($proper && !empty($title) && !empty($tag) && !empty($content)) {
+ if (empty($url)) {
$url = $title;
- add_sub_page($title, $url, $content, $static, $description);
}
+ edit_post($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $img, $vid);
} else {
$message['error'] = '';
if (empty($title)) {
$message['error'] .= 'Title field is required.';
}
+ if (empty($tag)) {
+ $message['error'] .= 'Tag field is required.';
+ }
if (empty($content)) {
$message['error'] .= 'Content field is required.';
}
@@ -1476,54 +1438,80 @@ post('/:static/add', function ($static) {
$message['error'] .= 'CSRF Token not correct.';
}
config('views.root', 'system/admin/views');
- render('add-page', array(
- 'title' => 'Add page - ' . blog_title(),
+
+ render('edit-post', array(
+ 'title' => 'Edit post - ' . blog_title(),
'description' => blog_description(),
'canonical' => site_url(),
'error' => '' . $message['error'] . '
',
+ 'oldfile' => $oldfile,
'postTitle' => $title,
+ 'postImg' => $img,
+ 'postVid' => $vid,
+ 'postTag' => $tag,
'postUrl' => $url,
'postContent' => $content,
- 'bodyclass' => 'addpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title . ' Add page'
+ 'bodyclass' => 'editpost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » Edit post'
));
}
});
-get('/:static/:sub', function ($static, $sub) {
+// Delete blog post
+get('/:year/:month/:name/delete', function ($year, $month, $name) {
- $father_post = get_static_post($static);
- if (!$father_post) {
- not_found();
- }
- $post = get_static_sub_post($static, $sub);
- if (!$post) {
- not_found();
- }
- $post = $post[0];
+ if (login()) {
- if (config("views.counter") == "true") {
- add_view($post->file);
- }
+ $user = $_SESSION[config("site.url")]['user'];
+ $role = user('role', $user);
- if (!login()) {
- file_cache($_SERVER['REQUEST_URI']);
+ config('views.root', 'system/admin/views');
+ $post = find_post($year, $month, $name);
+
+ if (!$post) {
+ not_found();
+ }
+
+ $current = $post['current'];
+
+ if ($user === $current->author || $role === 'admin') {
+ render('delete-post', array(
+ 'title' => 'Delete post - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'p' => $current,
+ 'bodyclass' => 'deletepost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
+ ));
+ } else {
+ render('denied', array(
+ 'title' => 'Delete post - ' . blog_title(),
+ 'description' => blog_description(),
+ 'canonical' => site_url(),
+ 'p' => $current,
+ 'bodyclass' => 'deletepost',
+ 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title
+ ));
+ }
+ } else {
+ $login = site_url() . 'login';
+ header("location: $login");
}
+});
- render('static', array(
- 'title' => $post->title . ' - ' . blog_title(),
- 'description' => $post->description,
- 'canonical' => $post->url,
- 'bodyclass' => 'inpage',
- 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title,
- 'p' => $post,
- 'type' => 'staticpage',
- ));
+// Get deleted data from blog post
+post('/:year/:month/:name/delete', function () {
+
+ $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
+ if ($proper && login()) {
+ $file = from($_REQUEST, 'file');
+ $destination = from($_GET, 'destination');
+ delete_post($file, $destination);
+ }
});
// If we get here, it means that
// nothing has been matched above
-
get('.*', function () {
not_found();
});