Browse Source

Merge pull request #2 from Kanti/viewCount+subPages

View count+sub pages
pull/74/head
Kanti 11 years ago
parent
commit
414f3a8ae7
7 changed files with 1669 additions and 1475 deletions
  1. +3
    -0
      config/config.ini.example
  2. +463
    -473
      system/admin/admin.php
  3. +2
    -1
      system/admin/views/posts-list.html.php
  4. +2
    -1
      system/admin/views/user-posts.html.php
  5. +1011
    -986
      system/htmly.php
  6. +178
    -14
      system/includes/functions.php
  7. +10
    -0
      themes/logs/static-sub.html.php

+ 3
- 0
config/config.ini.example View File

@ -80,5 +80,8 @@ lightbox = "off"
; Set the theme here
views.root = "themes/logs"
;Enable view Counter, the options is "true" and "false". If set to "true", you can see the Counts in Admin page.
views.counter = "true"
; Framework config. No need to edit.
views.layout = "layout"

+ 463
- 473
system/admin/admin.php
File diff suppressed because it is too large
View File


+ 2
- 1
system/admin/views/posts-list.html.php View File

@ -1,7 +1,7 @@
<h2 class="post-index"><?php echo $heading?></h2>
<?php if(!empty($posts)) {?>
<table class="post-list">
<tr class="head"><th>Title</th><th>Published</th><th>Author</th><th>Tag</th><th>Operations</th></tr>
<tr class="head"><th>Title</th><th>Published</th><?php if(config("views.counter") == "true"):?><th>Views</th><?php endif;?><th>Author</th><th>Tag</th><th>Operations</th></tr>
<?php $i = 0; $len = count($posts);?>
<?php foreach($posts as $p):?>
<?php
@ -19,6 +19,7 @@
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo date('d F Y', $p->date) ?></td>
<?php if(config("views.counter") == "true"):?><td><?php echo $p->views ?></td><?php endif;?>
<td><a target="_blank" href="<?php echo $p->authorurl ?>"><?php echo $p->author ?></a></td>
<td><?php echo $p->tag ?></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/posts">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/posts">Delete</a></td>


+ 2
- 1
system/admin/views/user-posts.html.php View File

@ -1,7 +1,7 @@
<h2 class="post-index"><?php echo $heading?></h2>
<?php if(!empty($posts)) {?>
<table class="post-list">
<tr class="head"><th>Title</th><th>Published</th><th>Tag</th><th>Operations</th></tr>
<tr class="head"><th>Title</th><th>Published</th><th>Views</th><th>Tag</th><th>Operations</th></tr>
<?php $i = 0; $len = count($posts);?>
<?php foreach($posts as $p):?>
<?php
@ -19,6 +19,7 @@
<tr class="<?php echo $class ?>">
<td><a target="_blank" href="<?php echo $p->url ?>"><?php echo $p->title ?></a></td>
<td><?php echo date('d F Y', $p->date) ?></td>
<td><?php echo $p->views ?></td>
<td><?php echo $p->tag ?></td>
<td><a href="<?php echo $p->url ?>/edit?destination=admin/mine">Edit</a> <a href="<?php echo $p->url ?>/delete?destination=admin/mine">Delete</a></td>
</tr>


+ 1011
- 986
system/htmly.php
File diff suppressed because it is too large
View File


+ 178
- 14
system/includes/functions.php View File

@ -54,6 +54,33 @@ function get_static_pages() {
return $_page;
}
// Get static page path. Unsorted.
function get_static_sub_pages($static = null) {
static $_sub_page = array();
if (empty($_sub_page)) {
$url = 'cache/index/index-sub-page.txt';
if(! file_exists($url)) {
rebuilt_cache('all');
}
$_sub_page = unserialize(file_get_contents($url));
}
if($static != null)
{
$stringLen = strlen($static);
return array_filter($_sub_page, function($sub_page)use($static,$stringLen){
$x = explode("/",$sub_page);
if($x[count($x)-2] == $static)
{
return true;
}
return false;
});
}
return $_sub_page;
}
// Get author bio path. Unsorted.
function get_author_names() {
@ -130,6 +157,11 @@ function rebuilt_cache($type) {
$page_cache = glob('content/static/*.md', GLOB_NOSORT);
$string = serialize($page_cache);
file_put_contents('cache/index/index-page.txt', print_r($string, true));
} elseif ($type === 'subpage') {
$page_cache = glob('content/static/*/*.md', GLOB_NOSORT);
$string = serialize($page_cache);
file_put_contents('cache/index/index-sub-page.txt', print_r($string, true));
} elseif ($type === 'author') {
$author_cache = glob('content/*/author.md', GLOB_NOSORT);
@ -138,6 +170,7 @@ function rebuilt_cache($type) {
} elseif ($type === 'all') {
rebuilt_cache('posts');
rebuilt_cache('page');
rebuilt_cache('subpage');
rebuilt_cache('author');
}
}
@ -223,6 +256,11 @@ function get_posts($posts, $page = 1, $perpage = 0) {
$post->body = $arr[0];
}
if(config("views.counter"))
{
$post->views = get_views($post->file);
}
$tmp[] = $post;
}
@ -454,6 +492,58 @@ function get_static_post($static) {
$post->title = $static;
$post->body = $arr[0];
}
if(config("views.counter"))
{
$post->views = get_views($post->file);
}
$tmp[] = $post;
}
}
}
return $tmp;
}
// Return static page.
function get_static_sub_post($static,$sub_static) {
$posts = get_static_sub_pages($static);
$tmp = array();
if (!empty($posts)) {
foreach ($posts as $index => $v) {
if (strpos($v, $sub_static . '.md') !== false) {
$post = new stdClass;
// Replaced string
$replaced = substr($v, 0, strrpos($v, '/')) . '/';
// The static page URL
$url = str_replace($replaced, '', $v);
$post->url = site_url() . $static . "/" . str_replace('.md', '', $url);
$post->file = $v;
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
$post->title = $title;
$post->body = $arr[1];
} else {
$post->title = $sub_static;
$post->body = $arr[0];
}
$post->views = get_views($post->file);
$tmp[] = $post;
}
@ -992,6 +1082,22 @@ function menu() {
}
}
function get_title_from_file($v)
{
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
} else {
$title = str_replace('-', ' ', str_replace('.md', '', $base));
}
return $title;
}
// Auto generate menu from static page
function get_menu() {
@ -1026,23 +1132,43 @@ function get_menu() {
$base = str_replace($replaced, '', $v);
$url = site_url() . str_replace('.md', '', $base);
// Get the contents and convert it to HTML
$content = MarkdownExtra::defaultTransform(file_get_contents($v));
// Extract the title and body
$arr = explode('t-->', $content);
if (isset($arr[1])) {
$title = str_replace('<!--t', '', $arr[0]);
$title = rtrim(ltrim($title, ' '), ' ');
} else {
$title = str_replace('-', ' ', str_replace('.md', '', $base));
}
$title = get_title_from_file($v);
if (strpos($req, str_replace('.md', '', $base)) !== false) {
echo '<li class="' . $class . ' active"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
$active = ' active';
} else {
echo '<li class="' . $class . '"><a href="' . $url . '">' . ucwords($title) . '</a></li>';
$active = '';
}
echo '<li class="' . $class . '"' . $active . '>';
$subPages = get_static_sub_pages(str_replace('.md', '', $base));
echo '<a href="' . $url . '">' . ucwords($title) . '</a><br/>';
if(!empty($subPages))
{
echo '<ul>';
$iSub = 0;
$countSub = count($subPages);
foreach($subPages as $index => $sp)
{
$classSub = "item";
if($iSub == 0)
{
$classSub .= " first";
}
if($iSub == $countSub -1)
{
$classSub .= " last";
}
$replacedSub = substr($sp, 0, strrpos($sp, '/')) . '/';
$baseSub = str_replace($replacedSub, '', $sp);
$urlSub = $url . "/" . str_replace('.md', '', $baseSub);
echo '<li class="' . $classSub . '"><a href="' . $urlSub . '">&raquo; ' . get_title_from_file($sp) . '</a></li>';
$iSub++;
}
echo '</ul>';
}
echo '</li>';
}
echo '</ul>';
} else {
@ -1548,3 +1674,41 @@ function is_csrf_proper($csrf_token) {
}
return false;
}
function add_view($page)
{
$filename = "cache/count.json";
$views = array();
if(file_exists($filename))
{
$views = json_decode(file_get_contents($filename),true);
}
if(isset($views[$page]))
{
$views[$page]++;
}
else
{
$views[$page] = 1;
}
file_put_contents($filename,json_encode($views));
}
function get_views($page)
{
static $_views = array();
if(empty($_views))
{
$filename = "cache/count.json";
if(file_exists($filename))
{
$_views = json_decode(file_get_contents($filename),true);
}
}
if(isset($_views[$page]))
{
return $_views[$page];
}
return -1;
}

+ 10
- 0
themes/logs/static-sub.html.php View File

@ -0,0 +1,10 @@
<?php if (!empty($breadcrumb)):?><div class="breadcrumb" xmlns:v="http://rdf.data-vocabulary.org/#"><?php echo $breadcrumb ?></div><?php endif;?>
<?php if(login()) { echo tab($p);} ?>
<div class="post" itemprop="blogPost" itemscope="itemscope" itemtype="http://schema.org/BlogPosting">
<div class="main">
<h1 class="title-post" itemprop="name"><?php echo $p->title ?></h1>
<div class="post-body" itemprop="articleBody">
<?php echo $p->body; ?>
</div>
</div>
</div>

Loading…
Cancel
Save