1 (edited by 2012-02-06 18:16:36)

Topic: [HACK] Counter

Name: Counter
Author: Eyece, liketobemad added a small modification
CuteNews Compatibility: 1.3.6 - * (no incompatibility reported yet)
Description: Keep statistics on your articles.
Discussion Topic:  here
Instructions:
first put this in a file named counter.php in the cutenews core folder:

<?php

if(!$cn_do)die;

$file_path = $cutepath.'/data/counter.txt';
$online_timeout = 120; // seconds
$ip = $_SERVER['REMOTE_ADDR'];
$time = time();

// load current stats into array
$counter = array();
foreach(file($file_path) as $line_num => $line){
    $line = explode("|",$line);
    $counter[$line[0]] = array("views"=>0,"unique views"=>0,"online"=>0);
    if($line[1]!="")
        foreach(explode(" ",$line[1]) as $part_num => $part){
            $part = explode(":",$part);
            if($part[3]>=($time-$online_timeout))$counter[$line[0]]["online"] += 1;
            $counter[$line[0]]["views"] += $part[1];
            $counter[$line[0]][$part[0]] = array($part[1],$part[2],$part[3]);
            $counter[$line[0]]["unique views"] += 1;
        }
}

if($cn_do=="update"){
    // update or write this users stats
    if(is_array($counter[$id])){
        if(is_array($counter[$id][$ip])){
            $counter[$id][$ip][0] += 1;
            $counter[$id]["views"] += 1;
            $counter[$id][$ip][2] = $time;
        }
        else{
            $counter[$id][$ip] = array(1,$time,$time);
            $counter[$id]["unique views"] += 1;
        }
    }
    elseif(is_numeric($id))$counter[$id] = array("views"=>1,"unique views"=>1,"online"=>0,$ip=>array(1,$time,$time));
    
    // re-write counter stats
    $fp = fopen($file_path,"w");
    $write = $counter;
    foreach($write as $item_id => $item_logs){
        foreach($item_logs as $log_ip => $log_values)
            if(is_array($log_values)){
                $write[$item_id][$log_ip] = $log_ip.":".implode(":",$log_values);
            }
            else unset($write[$item_id][$log_ip]);
        $write[$item_id] = $item_id."|".implode(" ",$write[$item_id])."|";
    }
    fwrite($fp,implode("\n",$write));
    fclose($fp);
}

?>


then create a blank file named counter.txt in the data folder (chmod 777)

shows.inc.php
find:

$output = str_replace("{title}", $news_arr[2], $template_full);

add under:

    $cn_do = "update";
        include($cutepath.'/counter.php');
        $output = str_replace("{page-views}", $counter[$news_arr[0]]["views"], $output);
        $output = str_replace("{unique-views}", $counter[$news_arr[0]]["unique views"], $output);
        $output = str_replace("{your-views}", $counter[$news_arr[0]][$ip][0], $output);
        $output = str_replace("{online}", $counter[$news_arr[0]]["online"], $output);
        $output = str_replace("{first-view}", date($config_timestamp_active,$counter[$news_arr[0]][$ip][1]), $output);


find:

$output = $template_active;

add under:

    $cn_do = "get";
        include($cutepath.'/counter.php');
        $output = str_replace("{page-views}", $counter[$news_arr[0]]["views"], $output);
        $output = str_replace("{unique-views}", $counter[$news_arr[0]]["unique views"], $output);
        $output = str_replace("{your-views}", $counter[$news_arr[0]][$ip][0], $output);
        $output = str_replace("{online}", $counter[$news_arr[0]]["online"], $output);
        $output = str_replace("{first-view}", date($config_timestamp_active,$counter[$news_arr[0]][$ip][1]), $output);

you can now use the following in the full-story & short-story templates:
{page-views} - total page loads from all unique visitors to current news
{unique-views} - count of all ip's logged in log file that are listed under the current news id
{your-views} - times viewer has loaded the page/news
{online} - count of all viewers that have been active within the timeout limit
{first-view} - time viewer first viewed news

Re: [HACK] Counter

Josef Bailey from Ontario was looking for essays on warren buffett

Norman Carter found the answer to a search query essays on warren buffett



essays on warren buffett



http://essayerudite.com/images/banner/500x500.jpg


























essay solutions overpopulation
essay imperialism world war 1
greek mythology thesis
exercises on how to write in cursive
essay on david hockney
find help for depression
essays on accidents
essay on employee access
format new resume
example of comparing an essay
ethical dilemma res
essay about jobs written by chrisann brennan
foreign commonwealth office customer cover letter
essays examples love
free cost accounting research paper
essay cover page template word
essay on racial discrimination prevalent in today scenario
essay contest afghanistan
example essay for job application
essay best friend free
essays that explains the second new deal
essays writers websites us
gre essay writing tips
example of resume for taxi driver
form to write a resume
example intern resume
example business plan web design company
example of compare and contrast essay 4th grade
essay thomas jefferson negroes
free blank resume printout
expo business plan
giving homework over the summer
freelance interpreter resume examples
functional resume mom example
free iwork pages resume templates
essay exam rubric
free resume for sales manager
essays written by baldwin
essays competitive forces
essay about playing online game
free download of resume builder software
essay for virginia tech application
free essays on george w bush
essay joker
essay writing competitions in nigeria
free essay on neural plasticity
essay on a friendly cricket match
fitzwilliam college essay competitions
goes appendices business plan
free basic business plan