forum.coppermine-gallery.net
No Support => Modifications/Add-Ons/Hacks => Mods: Statistics => Topic started by: jaspervd on April 13, 2008, 08:09:38 pm
-
I just started my own gallery but hated how all of my pictures had 0 views, so I decided to create a little script that will update all pictures in the database with a random amount of views, looks much better in my opinion :)
How to install:
1) Open activity.php and edit line 20:
$views = mt_rand(300,1000);
the first number(300) is the minimum amount of views you want, the last number (1000) is the max amount of views you want. The script will then randomly pick a number between these values.
2) Upload this script to the root of your gallery
3) point your browser to the file to run it once and your done :)
4) delete the file or chmod/rename it so other people cant use it
Source code:
<?php
//needed to acces the database
define('IN_COPPERMINE', true);
define('ADMIN_PHP', true);
define('CONFIG_PHP', true);
require('include/init.inc.php');
require('include/sql_parse.php');
$query="select * from cpg14x_pictures";
$result=mysql_query($query);
$i=1;
//repeat for all pictures
while ($email=mysql_fetch_row($result)) {
//generate random ammount of views between 300 and 1000 (you can edit these values)
$views = mt_rand(300,1000);
//do not edit below
//update the database
$email_mysql_query = ("UPDATE cpg14x_pictures SET hits = $views WHERE pid = $i");
$email_mysql_query_result = mysql_query($email_mysql_query);
echo $i;
$i = $i+1;
}
?>
I have also attached my file :)
-
For what it's worth (for anyone reading this who may not realize), the view count stats can simply be disabled in the admin config panel. Not sure what the real point of having a 'fake' count is. Probably better to disable the display of the view count, and renable it some time later when you have some gallery usage stats built up.
Thanks for sharing the contribution though.
-Tim
-
@jaspervd: thanks for sharing your solution, although I agree with tfischer: I can't see a reason why you want to fake the number of views. That's cheating imo that will cause a misproportion/disbalance of your actual stats, nothing else.
-
Here's an improved version that works for all galleries:
<?php
define('IN_COPPERMINE', true);
require('include/init.inc.php');
if (!GALLERY_ADMIN_MODE) {
cpg_die(ERROR, $lang_errors['access_denied'], __FILE__, __LINE__);
}
$min = 300;
$max = 1000;
cpg_db_query("UPDATE {$CONFIG['TABLE_PICTURES']} SET hits = FLOOR(RAND() * ".($max - $min + 1).") + ".$min);
pageheader();
echo $lang_common['done'];
pagefooter();
?>