Slideshow and view count Slideshow and view count
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Slideshow and view count

Started by gregik, August 24, 2004, 12:30:57 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

gregik

Is it a feature or is a bug but slaidshow does not count as picture view.




edit: sorry, I think this post is in wrong category

Joachim Müller

neither feature nor bug: using the slideshow a JavaScript is being used to pull the images - the images are being pre-loaded, but actually the server doesn't "know" what images have been viewed (the user might have stopped the slideshow without having viewed all files in the album). That's why the images are not counted. It's a limitation by design. You're welcome to look into it and post modifications if you find a way to overcome this.

GauGau

jerx

I also want the slideshow to be counted as views.

Do you mean by limitation that you cannot use Javascript to write into the database or do you mean that the pic counts would be unreliable, because the user might have stopped the slideshow already?

I think even though the pic counts are not accurate, it is still better to count the pre-loaded pictures. There should only be a few pictures which haven' t been displayed but counted as views. If you don' t count the slideshow your stats are even more inaccurate, because usually you have much more displayed pictures than pre-loaded images which haven' t been displayed.

Does anybody know how to modify the code to count the slideshow? Do you have to use php instead of javascript?

Stramm

the workaround you're asking for is something I wouldn't even think about. Mainly cause I have a lot of pictures in my albums and I know that when viewing a slidshow in most cases only a handful images get served. So eg view count for 1000 images get raised while only 5 pictures got viewed. Here I don't agree with you. Therefore you'd have to rewrite the entire slideshow function.... hmm, maybe when I'm bored. But if you really need it ask on the freelancers board.

Abbas Ali

Ok, here is the solution using XML HTTP Request.

Edit include/slideshow.inc.php

Add


var x1;

x1 = createRequestObject();

function createRequestObject() {
  var x = false;

  try {
    x = new ActiveXObject("Msxml2.XMLHTTP");
  } catch (e) {
    try {
      x = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (E) {
      x = false;
    }
  }

  if (!x && typeof XMLHttpRequest != "undefined") {
    x = new XMLHttpRequest();
  }

  return x;
}

function addHit(pid) {
  x1.open('get','addHit.php?pid='+pid);
  x1.onreadystatechange = function() {
    if (x1.readyState == 4) {
      return (x1.responseText);
    }
  }
  x1.send(null);
}


just after


<script language="JavaScript" type="text/JavaScript">


then Add

var Pid = new Array()


just After

var Pic = new Array() // don't touch this


Add

echo "Pid[$i] = '" . $picture['pid'] . "'\n";


just after

echo "Pic[$i] = '" . $picture_url . "'\n";


then Replace

        if (xIE4Up){
           document.images.SlideShow.filters.blendTrans.Play()
        }


with

        if (xIE4Up){
           document.images.SlideShow.filters.blendTrans.Play()
        }
        addHit(Pid[j])


Then create a new file addHit.php having the following code. Place this file in your coppermine folder.


<?php
define
('IN_COPPERMINE'true);

require(
'include/init.inc.php');

if (isset(
$_GET['pid'])) {
  
// Add 1 to hit counter
  
$pid = (int)$_GET['pid'];
  if (!
in_array($pid$USER['liv']) && isset($HTTP_COOKIE_VARS[$CONFIG['cookie_name'] . '_data'])) {
      
add_hit($pid);
      if (
count($USER['liv']) > 4array_shift($USER['liv']);
      
array_push($USER['liv'], $pid);
      
user_save_profile();
  }  
}
?>



This should work.

Note: The hit will be counted for only those images which have been served.

Abbas
Chief Geek at Ranium Systems

jerx

#5
Stramm, I didn' t know that all pictures get pre-loaded at the same time. I thought it only pre-loads a couple of pictures. If it is like this, I agree with you.

Abbas Ali,

Thank you very much for the quick modification!

Unfortunately views are not counted. I don' t get any error message. I double checked my modifications and they are as instructed (3 additions and 1 replacement). The file is named addHit.php and I copied it to the coppermine root directory. Any ideas what could be wrong?

Edit: Sorry, the code works perfect. The pictures I compared have already been viewed by me, so the slideshow view wasn' t counted. I tested it on another album which I haven' t viewed today and there all picture counts have been raised by 1. Thanks again for your help!!!

Stramm

no it doesn't preload the pictures... it preloads a list with all URLs to the pictures in that album. Means it only has to connect once to the db when the slideshow's started.

Wow, nice hack ;)
I'd written something that uses a meta refresh and connects to the db with each pic

jerx

Yes, it is a really great hack! You should implement it in future releases of coppermine!

Abbas Ali

@devs - What you all say? Not necessarily this mod but we should do something to count the slideshow views in future versions.
Chief Geek at Ranium Systems

Joachim Müller

yes, I agree - preferably as an admin option ("increase view counter during slideshow").

artistsinhawaii

Quote from: Abbas Ali on October 12, 2005, 07:36:23 PM
@devs - What you all say? Not necessarily this mod but we should do something to count the slideshow views in future versions.

Good job, Abbas.  I like it.  I vote "yes", as well. Agreeing with Gaugau, that it should be as an admin option.

Dennis
Learn and live ... In January of 2011, after a botched stent attempt, the doctors told me I needed a multiple bypass surgery or I could die.  I told them I needed new doctors.

Tranz

Ditto... that it be an admin option.

Stramm

When already adding new features to the slideshow wouldn't it be great to optimize it for huge albums too ?

Joachim Müller

Added feature to devel branch. 

Devs, please review my check in addHit.php - I have replacedif (isset($_GET['pid'])) {from Abbas' original code withif (isset($_GET['pid']) && !GALLERY_ADMIN_MODE && $CONFIG['slideshow_hits'] != 0) {

Abbas Ali

Working as expected in Mozilla and FF.

@Joachim: Did you tested it in IE? I have ie4linux and it is not working in it. Maybe it will work on windoz.
Chief Geek at Ranium Systems

Nibbler

We're not using $HTTP_COOKIE_VARS any more remember.

Joachim Müller

Quote from: Abbas Ali on September 07, 2006, 02:03:06 PM
I have ie4linux and it is not working in it.
There is IE on Linux :o? Never heard of that.
No, I haven't tested thoroughly, just added the code last night at work while I was doing a file server maintenance job that left me with some time to waste while robocopy did it's job. I'll test it with all browsers I can get hold of (which is IE, FF, Opera on Windows and Konqueror, Trillian and Firefox on Linux).

Quote from: Nibbler on September 07, 2006, 02:19:12 PM
We're not using $HTTP_COOKIE_VARS any more remember.
k, so this needs testing and modifications. I'd love to see you look into it. I confess that I was lazy and just added the code to devel without looking much into it, sorry.

Abbas Ali

Chief Geek at Ranium Systems