diff --git a/system/admin/views/popular-posts.html.php b/system/admin/views/popular-posts.html.php new file mode 100644 index 0000000..ed1efd4 --- /dev/null +++ b/system/admin/views/popular-posts.html.php @@ -0,0 +1,39 @@ +

+ + + + + + + + + + + + + + + + + + + + + + + +
TitlePublishedViewsAuthorTagOperations
title ?>date) ?>views ?>author ?>tag ?>Edit Delete
+ \ No newline at end of file diff --git a/system/htmly.php b/system/htmly.php index 6fa1f79..a8ea9e3 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -352,8 +352,8 @@ post('/add/image', function () { $message['error'] .= '
  • CSRF Token not correct.
  • '; } config('views.root', 'system/admin/views'); - render('add-post', array( - 'title' => 'Add post- ' . blog_title(), + render('add-image', array( + 'title' => 'Add image - ' . blog_title(), 'description' => blog_description(), 'canonical' => site_url(), 'error' => '', @@ -363,7 +363,7 @@ post('/add/image', function () { 'postUrl' => $url, 'postContent' => $content, 'bodyclass' => 'addpost', - 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add post' + 'breadcrumb' => '' . config('breadcrumb.home') . ' » Add image' )); } }); @@ -427,7 +427,7 @@ post('/add/video', function () { } config('views.root', 'system/admin/views'); render('add-video', array( - 'title' => 'Add post- ' . blog_title(), + 'title' => 'Add video - ' . blog_title(), 'description' => blog_description(), 'canonical' => site_url(), 'error' => '', @@ -792,6 +792,72 @@ get('/admin/posts', function () { } }); +// Show admin/popular +get('/admin/popular', function () { + + $user = $_SESSION[config("site.url")]['user']; + $role = user('role', $user); + if (login()) { + + config('views.root', 'system/admin/views'); + if ($role === 'admin') { + + config('views.root', 'system/admin/views'); + $page = from($_GET, 'page'); + $page = $page ? (int)$page : 1; + $perpage = 20; + + $posts = popular_posts(true,$perpage); + + $total = ''; + + if (empty($posts) || $page < 1) { + + // a non-existing page + render('no-posts', array( + 'title' => 'Popular posts - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'noposts', + )); + + die; + } + + $tl = blog_tagline(); + + if ($tl) { + $tagline = ' - ' . $tl; + } else { + $tagline = ''; + } + + render('popular-posts', array( + 'title' => 'Popular posts - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'heading' => 'Popular posts', + 'page' => $page, + 'posts' => $posts, + 'bodyclass' => 'popular-posts', + 'breadcrumb' => '', + 'pagination' => has_pagination($total, $perpage, $page) + )); + } else { + render('denied', array( + 'title' => 'Popular posts - ' . blog_title(), + 'description' => blog_description(), + 'canonical' => site_url(), + 'bodyclass' => 'denied', + 'breadcrumb' => '', + )); + } + } else { + $login = site_url() . 'login'; + header("location: $login"); + } +}); + // Show admin/mine get('/admin/mine', function () { diff --git a/system/includes/functions.php b/system/includes/functions.php index 61d54f1..00b1c83 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -138,12 +138,6 @@ 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) { @@ -776,16 +770,78 @@ function recent_posts($custom = null, $count = null) return $posts; } else { - $str = ''; + } +} + +// Return popular posts lists +function popular_posts($custom = null, $count = null) +{ + + static $_views = array(); + $tmp = array(); + + if (empty($count)) { + $count = config('popular.count'); + if (empty($count)) { + $count = 5; + } + } + if (config('views.counter') == 'true') { + if (empty($_views)) { + $filename = 'content/views.json'; + if (file_exists($filename)) { + $_views = json_decode(file_get_contents($filename), true); + if(is_array($_views)) { + arsort($_views); + foreach ($_views as $key => $val) { + if (file_exists($key)) { + if (strpos($key, 'blog') !== false) { + $tmp[] = pathinfo($key); + } + } + } + $posts = get_posts($tmp, 1, $count); + if (empty($custom)) { + echo ''; + } + else { + return $posts; + } + } else { + if(empty($custom)) { + echo ''; + } else { + echo ''; + return $tmp; + } + } + } else { + if (empty($custom)) { + echo ''; + } else { + return $tmp; + } + } + } + } else { + if (empty($custom)) { + echo ''; + } else { + return $tmp; + } } } @@ -895,6 +951,9 @@ function tag_cloud($custom = null) } else { return $tag_collection; } + } else { + if(empty($custom)) return; + return $tags; } } @@ -945,13 +1004,13 @@ function get_description($string, $char = null) } } if (strlen(strip_tags($string)) < $char) { - $string = remove_accent($string); $string = preg_replace('/[^A-Za-z0-9 !@#$%^&*(),.-]/u', ' ', strip_tags($string)); + $string = preg_replace('/\s\s+/', ' ', $string); $string = ltrim(rtrim($string)); return $string; } else { - $string = remove_accent($string); $string = preg_replace('/[^A-Za-z0-9 !@#$%^&*(),.-]/u', ' ', strip_tags($string)); + $string = preg_replace('/\s\s+/', ' ', $string); $string = ltrim(rtrim($string)); $string = substr($string, 0, $char); $string = substr($string, 0, strrpos($string, ' ')); @@ -1893,6 +1952,7 @@ EOF; echo '
  • Admin
  • '; if ($role === 'admin') { echo '
  • Posts
  • '; + echo '
  • Popular
  • '; } echo '
  • Mine
  • '; echo '
  • Draft
  • '; @@ -1950,7 +2010,7 @@ function is_csrf_proper($csrf_token) // Add page views count function add_view($page) { - $filename = "cache/count.json"; + $filename = "content/views.json"; $views = array(); if (file_exists($filename)) { $views = json_decode(file_get_contents($filename), true); @@ -1969,7 +2029,7 @@ function get_views($page) static $_views = array(); if (empty($_views)) { - $filename = "cache/count.json"; + $filename = "content/views.json"; if (file_exists($filename)) { $_views = json_decode(file_get_contents($filename), true); } @@ -2056,4 +2116,4 @@ function shorten($string = null, $char = null) return $string; } -} +} \ No newline at end of file diff --git a/themes/blog/css/styles.css b/themes/blog/css/styles.css index 88e4d3e..fbbd81f 100644 --- a/themes/blog/css/styles.css +++ b/themes/blog/css/styles.css @@ -456,6 +456,24 @@ iframe { margin-bottom: 0; } +/* popular-posts Section */ +.popular-posts .item { + margin-bottom: 20px; +} +.popular-posts .item .title { + font-size: 16px; + line-height: 1.3; +} +.popular-posts .item .title a { + color: #778492; +} +.popular-posts .item .title a:hover { + color: #5f6b77; +} +.popular-posts .item:last-child { + margin-bottom: 0; +} + /* archive Section */ ul.archivegroup { margin: 0; diff --git a/themes/blog/layout.html.php b/themes/blog/layout.html.php index 32785c2..b012b9d 100644 --- a/themes/blog/layout.html.php +++ b/themes/blog/layout.html.php @@ -115,6 +115,25 @@ + + + @@ -161,4 +179,4 @@ - + \ No newline at end of file diff --git a/themes/logs/css/style.css b/themes/logs/css/style.css index 6699b3a..a43f21b 100644 --- a/themes/logs/css/style.css +++ b/themes/logs/css/style.css @@ -608,15 +608,15 @@ ul li, ol li { margin: 0; } -.about, .social, .archive, .comments, .tagcloud, .recent { +.about, .social, .archive, .comments, .tagcloud, .recent, .popular { margin-bottom: 2em; } -#sidebar .recent ul { +#sidebar .recent ul, #sidebar .popular ul { margin: 0.25em 0 0.25em 1.3em; } -#sidebar .recent li { +#sidebar .recent li, #sidebar .popular li { list-style-type: circle; } diff --git a/themes/logs/layout.html.php b/themes/logs/layout.html.php index dab8b1c..966988c 100644 --- a/themes/logs/layout.html.php +++ b/themes/logs/layout.html.php @@ -57,6 +57,12 @@

    Recent Posts

    + + +

    Archive