diff --git a/system/admin/admin.php b/system/admin/admin.php index 26ef419..95178a1 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -519,10 +519,10 @@ function get_feed($feed_url, $credit) } // Get recent posts by user -function get_recent_posts() +function get_user_posts() { if (isset($_SESSION[config("site.url")]['user'])) { - $posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5); + $posts = get_profile_posts($_SESSION[config("site.url")]['user'], 1, 5); if (!empty($posts)) { echo '
| Title | Published | '; @@ -555,7 +555,7 @@ function get_recent_posts() } // Get all static pages -function get_recent_pages() +function get_user_pages() { if (isset($_SESSION[config("site.url")]['user'])) { $posts = get_static_post(null); diff --git a/system/admin/views/main.html.php b/system/admin/views/main.html.php index 89829fa..bf1dac0 100644 --- a/system/admin/views/main.html.php +++ b/system/admin/views/main.html.php @@ -1,5 +1,5 @@ Your recent posts'; -get_recent_posts(); +get_user_posts(); echo 'date) ?> | views ?> | -author ?> | +author ?> | tag ?> | Edit Delete | diff --git a/system/htmly.php b/system/htmly.php index e26ac64..32cac92 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -41,6 +41,7 @@ get('/index', function () { 'description' => blog_description(), 'canonical' => site_url(), 'bodyclass' => 'noposts', + 'is_front' => is_front(true), )); die; @@ -54,7 +55,8 @@ get('/index', function () { 'posts' => $posts, 'bodyclass' => 'infront', 'breadcrumb' => '', - 'pagination' => has_pagination($total, $perpage, $page) + 'pagination' => has_pagination($total, $perpage, $page), + 'is_front' => is_front(true), )); }); @@ -115,7 +117,7 @@ post('/login', function () { }); // Show the author page -get('/author/:profile', function ($profile) { +get('/author/:name', function ($name) { if (!login()) { file_cache($_SERVER['REQUEST_URI']); @@ -125,45 +127,46 @@ get('/author/:profile', function ($profile) { $page = $page ? (int)$page : 1; $perpage = config('profile.perpage'); - $posts = get_profile($profile, $page, $perpage); + $posts = get_profile_posts($name, $page, $perpage); - $total = get_count($profile, 'dirname'); + $total = get_count($name, 'dirname'); - $bio = get_bio($profile); + $author = get_author($name); - if (isset($bio[0])) { - $bio = $bio[0]; + if (isset($author[0])) { + $author = $author[0]; } else { - $bio = default_profile($profile); + $author = default_profile($name); } 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, + 'title' => 'Profile for: ' . $author->name . ' - ' . blog_title(), + 'description' => 'Profile page and all posts by ' . $author->name . ' on ' . blog_title() . '.', + 'canonical' => site_url() . 'author/' . $name, 'page' => $page, 'posts' => null, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'inprofile', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $author->name, 'pagination' => has_pagination($total, $perpage, $page) )); die; } 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, + 'title' => 'Profile for: ' . $author->name . ' - ' . blog_title(), + 'description' => 'Profile page and all posts by ' . $author->name . ' on ' . blog_title() . '.', + 'canonical' => site_url() . 'author/' . $name, 'page' => $page, 'posts' => $posts, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'inprofile', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, - 'pagination' => has_pagination($total, $perpage, $page) + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $author->name, + 'pagination' => has_pagination($total, $perpage, $page), + 'is_profile' => is_profile(true), )); }); @@ -430,22 +433,22 @@ get('/admin/mine', function () { config('views.root', 'system/admin/views'); - $profile = $_SESSION[config("site.url")]['user']; + $name = $_SESSION[config("site.url")]['user']; $page = from($_GET, 'page'); $page = $page ? (int)$page : 1; $perpage = config('profile.perpage'); - $posts = get_profile($profile, $page, $perpage); + $posts = get_profile_posts($name, $page, $perpage); - $total = get_count($profile, 'dirname'); + $total = get_count($name, 'dirname'); - $bio = get_bio($profile); + $author = get_author($name); - if (isset($bio[0])) { - $bio = $bio[0]; + if (isset($author[0])) { + $author = $author[0]; } else { - $bio = default_profile($profile); + $author = default_profile($name); } if (empty($posts) || $page < 1) { @@ -456,10 +459,10 @@ get('/admin/mine', function () { 'page' => $page, 'heading' => 'My posts', 'posts' => null, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'userposts', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $author->name, 'pagination' => has_pagination($total, $perpage, $page) )); die; @@ -472,10 +475,10 @@ get('/admin/mine', function () { 'heading' => 'My posts', 'page' => $page, 'posts' => $posts, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'userposts', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $bio->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Profile for: ' . $author->name, 'pagination' => has_pagination($total, $perpage, $page) )); } else { @@ -491,22 +494,22 @@ get('/admin/draft', function () { config('views.root', 'system/admin/views'); - $profile = $_SESSION[config("site.url")]['user']; + $name = $_SESSION[config("site.url")]['user']; $page = from($_GET, 'page'); $page = $page ? (int)$page : 1; $perpage = config('profile.perpage'); - $posts = get_draft($profile, $page, $perpage); + $posts = get_draft($name, $page, $perpage); - $total = get_count($profile, 'dirname'); + $total = get_count($name, 'dirname'); - $bio = get_bio($profile); + $author = get_author($name); - if (isset($bio[0])) { - $bio = $bio[0]; + if (isset($author[0])) { + $author = $author[0]; } else { - $bio = default_profile($profile); + $author = default_profile($name); } if (empty($posts) || $page < 1) { @@ -517,10 +520,10 @@ get('/admin/draft', function () { 'page' => $page, 'heading' => 'My draft', 'posts' => null, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'userdraft', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Draft for: ' . $bio->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Draft for: ' . $author->name, )); die; } @@ -532,10 +535,10 @@ get('/admin/draft', function () { 'heading' => 'My draft', 'page' => $page, 'posts' => $posts, - 'bio' => $bio->body, - 'name' => $bio->title, + 'about' => $author->about, + 'name' => $author->name, 'bodyclass' => 'userdraft', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Draft for: ' . $bio->title, + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Draft for: ' . $author->name, )); } else { $login = site_url() . 'login'; @@ -782,7 +785,8 @@ get('/tag/:tag', function ($tag) { 'posts' => $posts, 'bodyclass' => 'intag', 'breadcrumb' => '' . config('breadcrumb.home') . ' » Posts tagged: ' . $tag, - 'pagination' => has_pagination($total, $perpage, $page) + 'pagination' => has_pagination($total, $perpage, $page), + 'is_tag' => is_tag(true), )); }); @@ -830,7 +834,8 @@ get('/archive/:req', function ($req) { 'posts' => $posts, 'bodyclass' => 'inarchive', 'breadcrumb' => '' . config('breadcrumb.home') . ' » Archive for: ' . $timestamp, - 'pagination' => has_pagination($total, $perpage, $page) + 'pagination' => has_pagination($total, $perpage, $page), + 'is_archive' => is_archive(true), )); }); @@ -863,7 +868,8 @@ get('/search/:keyword', function ($keyword) { 'posts' => $posts, 'bodyclass' => 'insearch', 'breadcrumb' => '' . config('breadcrumb.home') . ' » Search results for: ' . $keyword, - 'pagination' => has_pagination($total, $perpage, $page) + 'pagination' => has_pagination($total, $perpage, $page), + 'is_search' => is_search(true), )); }); @@ -992,6 +998,7 @@ get('/:static', function ($static) { 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $post->title, 'p' => $post, 'type' => 'staticpage', + 'is_page' => is_page(true), )); } }); @@ -1214,6 +1221,7 @@ get('/:static/:sub', function ($static, $sub) { 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $father_post[0]->title . ' » ' . $post->title, 'p' => $post, 'type' => 'staticpage', + 'is_subpage' => is_subpage(true), )); }); @@ -1380,12 +1388,12 @@ get('/:year/:month/:name', function ($year, $month, $name) { } } - $bio = get_bio($current->author); + $author = get_author($current->author); - if (isset($bio[0])) { - $bio = $bio[0]; + if (isset($author[0])) { + $author = $author[0]; } else { - $bio = default_profile($current->author); + $author = default_profile($current->author); } if (array_key_exists('prev', $post)) { @@ -1405,13 +1413,15 @@ get('/:year/:month/:name', function ($year, $month, $name) { 'description' => $current->description, 'canonical' => $current->url, 'p' => $current, - 'authorinfo' => authorinfo($bio->title, $bio->body), + 'author' => $author, 'bodyclass' => 'inpost', 'breadcrumb' => '' . config('breadcrumb.home') . ' » ' . $current->tagb . ' » ' . $current->title, 'prev' => has_prev($prev), 'next' => has_next($next), 'type' => 'blogpost', + 'is_post' => is_post(true), )); + }); // Edit blog post diff --git a/system/includes/functions.php b/system/includes/functions.php index 281418f..f4b6876 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -76,8 +76,8 @@ function get_static_sub_pages($static = null) return $_sub_page; } -// Get author bio path. Unsorted. -function get_author_names() +// Get author name. Unsorted. +function get_author_name() { static $_author = array(); @@ -138,6 +138,12 @@ function sortdate($a, $b) return $a->date == $b->date ? 0 : ($a->date < $b->date) ? 1 : -1; } +// usort function. Sort by views. +function sortviews($a, $b) +{ + return $a[$page] == $b[$page] ? 0 : ($a[$page] < $b[$page]) ? 1 : -1; +} + // Rebuilt cache index function rebuilt_cache($type) { @@ -148,7 +154,7 @@ function rebuilt_cache($type) $author_cache = array(); if (is_dir($dir) === false) { - mkdir($dir, 0777, true); + mkdir($dir, 0775, true); } if ($type === 'posts') { @@ -220,7 +226,7 @@ function get_posts($posts, $page = 1, $perpage = 0) // The post author + author url $post->author = $author; - $post->authorurl = site_url() . 'author/' . $author; + $post->authorUrl = site_url() . 'author/' . $author; $dt = str_replace($replaced, '', $arr[0]); $t = str_replace('-', '', $dt); @@ -424,7 +430,7 @@ function get_archive($req, $page, $perpage) } // Return posts list on profile. -function get_profile($profile, $page, $perpage) +function get_profile_posts($name, $page, $perpage) { $posts = get_post_sorted(); @@ -434,7 +440,7 @@ function get_profile($profile, $page, $perpage) $url = $v['dirname']; $str = explode('/', $url); $author = $str[count($str) - 2]; - if ($profile === $author) { + if ($name === $author) { $tmp[] = $v; } } @@ -469,19 +475,20 @@ function get_draft($profile, $page, $perpage) return $tmp = get_posts($tmp, $page, $perpage); } -// Return author bio. -function get_bio($author) +// Return author info. +function get_author($name) { - $names = get_author_names(); + $names = get_author_name(); - $username = 'config/users/' . $author . '.ini'; + $username = 'config/users/' . $name . '.ini'; $tmp = array(); if (!empty($names)) { foreach ($names as $index => $v) { - $post = new stdClass; + + $author = new stdClass; // Replaced string $replaced = substr($v, 0, strrpos($v, '/')) . '/'; @@ -490,19 +497,19 @@ function get_bio($author) $str = explode('/', $replaced); $profile = $str[count($str) - 2]; - if ($author === $profile) { + if ($name === $profile) { // Profile URL $url = str_replace($replaced, '', $v); - $post->url = site_url() . 'author/' . $profile; + $author->url = site_url() . 'author/' . $profile; // Get the contents and convert it to HTML $content = file_get_contents($v); // Extract the title and body - $post->title = get_content_tag('t', $content, $author); - $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content)); + $author->name = get_content_tag('t', $content, $author); + $author->about = MarkdownExtra::defaultTransform(remove_html_comments($content)); - $tmp[] = $post; + $tmp[] = $author; } } } @@ -515,17 +522,17 @@ function get_bio($author) } // Return default profile -function default_profile($author) +function default_profile($name) { $tmp = array(); - $profile = new stdClass; + $author = new stdClass; - $profile->title = $author; - $profile->body = '
|---|