feature request - view counts

Hi, first off wanted to say fantastic work on zenPhoto and congrats on the 1.0 release. I was using gallery2 and was fed up with the bloat as I don't want other users, just me, and I wanted something looking smart and simple. I found zenPhoto and realised the description is just what I was wanting to type into google!! haha.
I have moved my personal gallery over from G2 to zenPhoto (~300 pics).

My request if for some kind of view counts (per image), it may not be wanted for all but if the data was available in the db then it could be used on the templates.

Also, when will we see EXIF data available?

Again, great work, thanks!

Comments

  • trisweb Administrator
    Both of those are on the list, and probably will come in around 1.1, or a little after an "official" 1.0 release. We have a couple betas yet to release before then, and we're pressed for time by other projects, so it's hard to say exactly when, but we're on it for sure. :)
  • no worries, I understand its not on the priority list as its really just 'cosmetic' and if stats matter that much then most hosts provide something in that arena.

    However I have implemented a basic view count in the image context. (Once I'd found classes.php this was a doddle!) And yes I will be aware that my changes will be overwritten with any upgrades, after all its in beta still, so I won't be moaning that I lost anything! :o)

    http://austinandteresa.co.uk if you wanna see
  • Mania Member
    That is great. How did you implement that? I would like to display the number on photos in an album like you have and on thumbs page the "xx to xx of xx photos" part. Would you like you share your code on these?

    When I get this and later on inner albums, ZenPhoto is starting to have everything I need. :)
  • Getting the number of images was the simple part as there is already a function to return this number based on the context of the album.
    Inside /themes/<your current theme>/index.php

    find the div

    `
    `

    then after the line

    `

    <?php printAlbumDesc(); ?>

    `

    I have put (to get only number of images in this album):

    `


    <? $number = getNumImages(); if ($number != 1) $number .= " photos"; else $number .=" photo"; echo$number; ?>

    `

    Then for the album pages to get xx to xx of xx:

    Inside /themes/<your current theme>/album.php

    after the line

    `<?php printAlbumDesc(true); ?>`

    I have put:

    `


    <? echo((($_zp_page - 1) * zp_conf('images_per_page')) + 1); ?> to <? $pgtotal = ($_zp_page * zp_conf('images_per_page')); $numimg = getNumImages(); if ($pgtotal > $numimg) echo$numimg; else echo$pgtotal; ?> of <? $number = getNumImages(); if ($number > 1) $number .= " photos"; else $number .=" photo"; echo$number; ?>

    `

    This calculation looks awful and is probably not very elegant but gets there! I don't think I needed to add any extra functions for that but it was a few weeks ago now.

    To get view counts then you need to add a new field in the images table and new class functions to to read and increment this value

    Normal disclaimer of use code at own risk etc etc...
  • Mania Member
    Thank you! I will try it in action later tonight.
  • Mania Member
    Works wonderfully! :D
  • austinjreid: please, can you send code for viewing VIEW COUNT? I've been trying to do it somehow, but no succes.
  • I've done it! :) it's not as good as others, but it counts. It counts even at reloading the image page :)
    insert into image.php
    '<?
    $id = getImageID();
    query("UPDATE z_images SET hit = hit + 1 WHERE id=$id");

    $views = query_full_array("SELECT hit FROM z_images WHERE id = $id" );

    foreach ($views as $view) {
    $numviews = $view['hit'];
    echo "$numviews";
    }

    ?>'
  • I tried the code above but get an error:

    MySQL Query ( UPDATE z_images SET hit = hit + 1 WHERE id=2395 ) Failed. Error: Table 'db0006382.z_images' doesn't exist

    my mysql prefix is zen_ - using the prefix instead of z_images fails either.
    What can I do?

    Maybe somebody implemented another view counter?
  • koffee Member
    Oh, prefix z_ is in my DB. you have to put there zen_images or prefix you are using.

    And, i forgot to mention, that you have to make a new field in this DB, called HIT. In mysql it looks like this hit int(11) NOT NULL default '0'. I hope you'll do it, it is not that hard. It means name = hit, type = INT(11), NUL=no, default=0.
  • koffee, many thanks for your quick answer.
    Ok - I changed the prefix.
    Can you tell me how to make the field in the DB? It´s not my own server - it´s run by a webhost.
  • koffee Member
    You have to login to phpmyadmin (probably). It should look like this: http://img231.imageshack.us/my.php?image=phpmyadminav1.gif there you will click button "ProveÄ??" (i don't know what's there in english), under the list of fields in table. Now, you are able to add new field, with data as I have written above, NAME, TYPE, etc. Like this picture: http://img231.imageshack.us/my.php?image=phpmyadmin2gi8.gif

    Or you can make an SQL query, the code is as follows: ALTER TABLE `z_images` ADD `hit` INT( 11 ) NOT NULL ;
  • koffee Member
    And, change the prefix in the sql code again ;)
  • Thank you very much - it actually works now.
    Especially your scrennshots helped a lot. let me see how to beautifully integrate the counter ...
  • royz Member
    Thanks guys, i have now integrated the most viewed photo's along with zenpressed:

    here is my total story from begin till end, it might help people! :)

    Here it comes, but before that, you'll need a new row in table images of your gallery. Make a row that looks like: hit int(11) NOT NULL default '0'.

    Now the counting can be saved in our database, we can post the code to count the views:

    in image.php of your gallery:

    '<?
    $id = getImageID();
    query("UPDATE z_images SET hit = hit + 1 WHERE id=$id");

    $views = query_full_array("SELECT hit FROM z_images WHERE id = $id" );

    foreach ($views as $view) {
    $numviews = $view['hit'];
    }

    ?>'

    Now the counts are saved, we can custom made zenpressed:

    Add the function:

    /* shows most viewed photos */
    function zenpressed_mostviewedphotos( $album = null, $conf = null ) {
    $conf = zenpressed_conf( $conf );
    $conf["select"] = "mostviewed";
    return zenpressed_photos( $album, $conf );
    }

    Add the select:

    elseif( $conf["select"] == "mostviewed" ) $query_order = " ORDER BY images.hit DESC";

    Add the function call in your sidebar.php:

    <h4>Meest bekeken foto's</h4>

      <?php zenpressed_mostviewedphotos( ); ?>
    <?php $wpdb->select(DB_NAME); // reconnect wordpress db ?>

    And we are done! Pretty cool heh! :D

    If you need an example, you can watch it at www.royz.nl!
  • One problem is that such a method includes the admin's visits to the page. That skews the readings since at least I keep checking the images after uploading for one reason or another...I am a photographer :). Here is a version that checks for admin login and disregards page views if the admin is logged in. You can put the following code below in the <head></head> section of image.php.

    <?
    if (zp_loggedin()) {
    $id = getImageID();
    $views = query_full_array("SELECT hit FROM clientz_images WHERE id = $id" );
    foreach ($views as $view) {
    $numviews = $view['hit'];
    }
    } else {
    $id = getImageID();
    query("UPDATE clientz_images SET hit = hit + 1 WHERE id=$id");
    $views = query_full_array("SELECT hit FROM clientz_images WHERE id = $id" );
    foreach ($views as $view) {
    $numviews = $view['hit'];
    }
    }
    ?>

    Then to display your page views (depending on your theme) place

    echo "$numviews";

    where you want the count to show. For Cimi (my current favorite theme) I used:

    <div class="block light"><? echo "$numviews"; ?> views</div>

    This went somewhere below the LEFT and RIGHT arrow buttons.

    What can I say. It works. Three cheers for Tristan and his band.
Sign In or Register to comment.