Browse Source

Added viewCount Feature #66

pull/69/head
Kanti 11 years ago
parent
commit
8ea2611323
5 changed files with 996 additions and 1002 deletions
  1. +4
    -2
      system/admin/admin.php
  2. +2
    -1
      system/admin/views/posts-list.html.php
  3. +2
    -1
      system/admin/views/user-posts.html.php
  4. +946
    -998
      system/htmly.php
  5. +42
    -0
      system/includes/functions.php

+ 4
- 2
system/admin/admin.php View File

@ -347,7 +347,7 @@ function get_recent_posts() {
$posts = get_profile($_SESSION[config("site.url")]['user'], 1, 5);
if(!empty($posts)) {
echo '<table class="post-list">';
echo '<tr class="head"><th>Title</th><th>Published</th><th>Tag</th><th>Operations</th></tr>';
echo '<tr class="head"><th>Title</th><th>Published</th><th>Views</th><th>Tag</th><th>Operations</th></tr>';
$i = 0; $len = count($posts);
foreach($posts as $p) {
if ($i == 0) {
@ -363,6 +363,7 @@ function get_recent_posts() {
echo '<tr class="' . $class . '">';
echo '<td><a target="_blank" href="' . $p->url . '">' . $p->title . '</a></td>';
echo '<td>' . date('d F Y', $p->date) . '</td>';
echo '<td>' . $p->views . '</td>';
echo '<td>' . $p->tag . '</td>';
echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>';
echo '</tr>';
@ -379,7 +380,7 @@ function get_recent_pages() {
if(!empty($posts)) {
krsort($posts);
echo '<table class="post-list">';
echo '<tr class="head"><th>Title</th><th>Operations</th></tr>';
echo '<tr class="head"><th>Title</th><th>Views</th><th>Operations</th></tr>';
$i = 0; $len = count($posts);
foreach($posts as $p) {
if ($i == 0) {
@ -394,6 +395,7 @@ function get_recent_pages() {
$i++;
echo '<tr class="' . $class . '">';
echo '<td><a target="_blank" href="' . $p->url . '">' . $p->title . '</a></td>';
echo '<td>' . $p->views . '</td>';
echo '<td><a href="' . $p->url . '/edit?destination=admin">Edit</a> <a href="' . $p->url . '/delete?destination=admin">Delete</a></td>';
echo '</tr>';
}


+ 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><th>Views</th><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>
<td><?php echo $p->views ?></td>
<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>


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


+ 42
- 0
system/includes/functions.php View File

@ -223,6 +223,8 @@ function get_posts($posts, $page = 1, $perpage = 0) {
$post->body = $arr[0];
}
$post->views = get_views($post->file);
$tmp[] = $post;
}
@ -454,6 +456,8 @@ function get_static_post($static) {
$post->title = $static;
$post->body = $arr[0];
}
$post->views = get_views($post->file);
$tmp[] = $post;
}
@ -1548,3 +1552,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;
}

Loading…
Cancel
Save