View Full Version : Counting Clicks for Thumbnails in Category listings
Mark Brookes
12-02-2006, 06:12 PM
Hi,
I have previously added thumbnails to my listings on the category pages. I use the Ocean template and ver2.0.01
I did it by adding
{if $config.thumbshot}
<td>
<div class="preview">
<a href="{$link.url}" target="_blank"><img width="111" height="87" src="http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r={$link.url}" alt="" /></a>
</div>
</td>
{/if}
below line 1.
However this does not add to the counted clicks, in the same way that clicking on the title does.
Can anyone give me details on how to make the new image count clicks in the same way as the tirle does (ie visitors can only add to clicks once (per day?))
regards
Mark
Mark Brookes
12-03-2006, 11:38 AM
Well studying the threads
http://www.esyndicat.com/forum/about6665.html
http://www.esyndicat.com/forum/showthread.php?t=6291
gave me this as an answer:
for line 5 in the mod as in the attachment above
<a href="{$link.url}" id="l{$link.id}" target="_blank"><img width="111" height="87" src="http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r={$link.url}" alt="" /></a>
Wasn't that easy :)
Of course I don't understand why it works .. but who cares?
-- if you get your thumbnails from not-MSN you will need to change that bit. ---
Dave Baker
12-03-2006, 06:54 PM
Hi Mark,
Thanks for very useful modification.
Of course I don't understand why it works .. but who cares?
Actually this works very simply:
id="l{$link.id}"
It's intended for determination of "id" link on which there is a transition. It is necessary for definition of the attitude "id" to the link in which necessary to increase quantity of clicks.
i.e
<h1><a href="{$link.url}" id="l{$link.id}" {if $config.new_window}target="_blank"{/if}>{$link.title}</a></h1>
and
<a href="{$link.url}" id="l{$link.id}" target="_blank"><img width="111" height="87" src="http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r={$link.url}" alt="" /></a>
Both codes are links. Any of them will be pass identical "id" links. Hence count of clicks will increase at the link which has this "id".
Code responsible for " interception id " you can find in "footer.tpl" file
<script type="text/javascript">
var root = '{$config.base}{$config.dir}';
var a = document.getElementsByTagName("a");
{literal}
for(i=0; i<a.length; i++)
if(a[i].id != '')
{
a[i].onclick = count_link;
}
function count_link()
{
i = new Image();
h = Math.random();
i.src= root + 'click-count.php?id='+this.id+'&h='+h;
return true;
}
{/literal}
</script>
Code responsible for renewal "count of cliks" in database, you can find in click-count.php
Bryan Ex
12-03-2006, 09:20 PM
Dave... does id="l{$link.id}" need to be contained within the template file or will a php include file that outputs html also work? I'm still trying to get the link counting working for thumbs using the thumbutilty file for Alexa paid thumb service which is called from a separate file.
Dave Baker
12-03-2006, 09:57 PM
Hello Bryan,
I understand your problem. In my opinion here only one way: to pass data through PHP file.
***Open templates/yourTemplate/view-link.tpl and find code***
{if $config.alexa_thumbs}
<td width="<strong>{$lang.$key}:</strong>">{get_thumbnail_link aUrl=$link.url aSize=Large}</td>
{/if}
***Replace with following***
{if $config.alexa_thumbs}
<td width="<strong>{$lang.$key}:</strong>">{get_thumbnail_link aUrl=$link.url aSize=Large idLink=$link.id}</td>
{/if}
We add one more parameter in function "get_thumbnail_link" for transfer "id" links. It's idLink=$link.id.
***Save file***
***Open thumbnailutility_php4.php and find function***
function get_thumbnail_link($aParams)
***In this function find code***
return get_html_snippet($url, $default_image);
***Replace with following code***
return get_html_snippet($url, $default_image, $aParams['idLink']);
***In this file find function***
function get_html_snippet($url, $image) {
$link = "";
$navigable_url = (stristr($url,"http://") == $url ) ? $url : "http://".$url;
if ($image) {
$link = "<a href='$navigable_url'><img border='0' src='$image' alt='$url'/></a>";
}
return $link;
}
***Replace with following function***
function get_html_snippet($url, $image, $idLink) {
$link = "";
$navigable_url = (stristr($url,"http://") == $url ) ? $url : "http://".$url;
if ($image) {
$link = "<a href='$navigable_url' id='l$idLink'><img border='0' src='$image' alt='$url'/></a>";
}
return $link;
}
***Save file***
Bryan Ex
12-03-2006, 10:05 PM
Will do Dave... it's good to know I was on the right track logically with only $aParams['idLink'] being the part I was messing up on for proper coding. I will update the Alexa thread once I have this working.
Bryan Ex
12-03-2006, 10:55 PM
***In this file find function***
function get_html_snippet($url, $image, $idLink)
That function in my file is originally ...
function get_html_snippet($url, $image)
... and if I add $idLink to the array so it's ($url, $image, $idLink) I receive the following error;
Missing argument 3 for get_html_snippet()
Dave Baker
12-03-2006, 11:09 PM
I'm sorry Bryan, it's my fault.
I have corrected the previous post
Bryan Ex
12-03-2006, 11:42 PM
Still the same thing Dave... missing argument 3 in the get_html_snippet function.
Here's where my file is at in case it now differs from what you may have;
<?php
/**
* Alexa Site Thumbnail Utility Package for PHP4
*
* Notes: Requires PHP4
*/
// Get a thumbnail URL from the thumbnail service. The returned image is enclosed in an achor tag (<a> <img/> </a>).
function get_thumbnail_link($aParams) {
$access_key_id = "Access key entered here";
$secret_access_key = "Secret key entered here";
$size = $aParams['aSize'];
$default_image = "http://www.mydomain.com/graphics/noimage3.gif";
$url = $aParams['aUrl'];
$idLink = $link.id;
$timestamp = generate_timestamp();
$url_enc = urlencode($url);
$timestamp_enc = urlencode($timestamp);
$signature_enc = urlencode (
calculate_RFC2104HMAC
("AlexaSiteThumbnail" . "Thumbnail" . $timestamp, $secret_access_key)
);
$request_url = "http://ast.amazonaws.com/xino/?"
. "Service=". "AlexaSiteThumbnail"
. "&Action=". "Thumbnail"
. "&AWSAccessKeyId=". $access_key_id
. "&Timestamp=" . $timestamp_enc
. "&Signature=" . $signature_enc
. "&Size=" . $size
. "&Url=" . $url;
$line = make_http_request($request_url);
$num_matches = preg_match('/<[^:]*:Thumbnail\\s*(?:Exists=\"((?:true)|(?:false))\")?[^>]*>([^<]*)<\//', $line, $matches);
if($num_matches == 1){
$exists = $matches[1];
$thumbnail = $matches[2];
}else{
$exists = NULL;
$thumbnail = NULL;
}
$has_default_image = ($default_image != NULL) && (strlen($default_image) > 0);
if ($thumbnail != NULL && ($exists || !$has_default_image)){
return get_html_snippet($url, $thumbnail);
}
return get_html_snippet($url, $default_image, $aParams['idLink']);
}
// Get an array of thumbnail URLs. The order of thumbnail URLs in the returned object is the same as that of $url_array.
// For thumbnail URLs that are missing from the service-response object, the value returned by the method is NULL.
function get_thumbnail_links($access_key_id, $secret_access_key, $size, $default_image, $url_array) {
if (!is_array($url_array)) {
echo ("url_array parameter is not an array.");
return NULL;
}
$urls_param = "";
for ($i = 0; $i < count($url_array); $i++){
$urls_param = $urls_param . "&Thumbnail." . ($i+1) . ".Url=" . urlencode($url_array[$i]);
}
$timestamp = generate_timestamp();
$timestamp_enc = urlencode($timestamp);
$signature_enc = urlencode (
calculate_RFC2104HMAC
("AlexaSiteThumbnail" . "Thumbnail" . $timestamp, $secret_access_key)
);
$request_url = "http://ast.amazonaws.com/xino/?"
. "Service=". "AlexaSiteThumbnail"
. "&Action=". "Thumbnail"
. "&AWSAccessKeyId=". $access_key_id
. "&Timestamp=" . $timestamp_enc
. "&Signature=" . $signature_enc
. "&Shared.Size=" . $size
. $urls_param;
$line = make_http_request($request_url);
$lines = explode("<aws:Response>", $line);
if(count($lines) != count($url_array) + 1){
echo "bad number of Response elements";
return NULL;
}
$has_default_image = ($default_image != NULL) && (strlen($default_image)> 0);
$return_array = array();
for ($i = 0; $i < count($url_array); $i++) {
$num_matches = preg_match('/<[^:]*:Thumbnail\\s*(?:Exists=\"((?:true)|(?:false))\")?[^>]*>([^<]*)<\//', $lines[$i + 1], $matches);
if($num_matches == 1){
$exists = $matches[1];
$thumbnail = $matches[2];
}else{
$exists = NULL;
$thumbnail = NULL;
}
if ($thumbnail != NULL && ($exists || !$has_default_image)){
$return_array[$i] = get_html_snippet($url_array[$i], $thumbnail);
}else{
$return_array[$i] = get_html_snippet($url_array[$i], $default_image);
}
}
return $return_array;
}
// Returns an HTML snippet which will display the thumbnail image url and link to the website. Returns an empty string if the image is null or empty.
function get_html_snippet($url, $image, $idLink) {
$link = "";
$navigable_url = (stristr($url,"http://") == $url ) ? $url : "http://".$url;
if ($image) {
$link = "<a href='$navigable_url' id='1$idLink'><img border='0' src='$image' alt='$url'/></a>";
}
return $link;
}
// Calculate signature using HMAC: http://www.faqs.org/rfcs/rfc2104.html
function calculate_RFC2104HMAC ($data, $key) {
return base64_encode (
pack("H*", sha1((str_pad($key, 64, chr(0x00))
^(str_repeat(chr(0x5c), 64))) .
pack("H*", sha1((str_pad($key, 64, chr(0x00))
^(str_repeat(chr(0x36), 64))) . $data))))
);
}
// Timestamp format: yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
function generate_timestamp () {
return gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
}
// Make an http request to the specified URL and return the result
function make_http_request($url){
$lines = @file($url);
return @implode("", $lines);
}
?>
Dave Baker
12-04-2006, 12:05 AM
Bryan in this code:
$access_key_id = "Access key entered here";
$secret_access_key = "Secret key entered here";
$size = $aParams['aSize'];
$default_image = "http://www.mydomain.com/graphics/noimage3.gif";
$url = $aParams['aUrl'];
$idLink = $link.id;
There is the superfluous element:
$idLink = $link.id;
Remove this code. He returns empty value.
p.s If the problem will not be solved I can attach the file
Bryan Ex
12-04-2006, 12:13 AM
Yeah... I've tried it both ways I'm afraid. I have removed it again but the same error occurs. The thumbs load and are clickable but click count does not advance in addition to the error message on screen for each return. If your version works than let me try a file compare to see what is different because I bet it is something small. :wallbash:
Dave Baker
12-04-2006, 12:22 AM
I have checked up the file on my local copy. All works excellently.
Dave Baker
12-04-2006, 12:31 AM
Bryan in this function instead of a symbol " l (L) " you've put a symbol "1"
function get_html_snippet($url, $image, $idLink) {
$link = "";
$navigable_url = (stristr($url,"http://") == $url ) ? $url : "http://".$url;
if ($image) {
$link = "<a href='$navigable_url' id='1$idLink'><img border='0' src='$image' alt='$url'/></a>";
}
return $link;
}
}
Bryan Ex
12-04-2006, 01:12 AM
Same error with your file Dave and looking at the source code to compare the thumb link and text link it seems the link ID is not being passed for some reason... so that is the missing argument I guess.
id='l' for the thumb and id="l85" for the title text link.
In my link-display.tpl I have used {get_thumbnail_link aUrl=$link.url aSize=Small idLink=$link.id} which means it's the .id part that's missing. It's so frustrating when things are this close to working... but don't. :crazy-be:
Dave Baker
12-04-2006, 01:18 AM
Can you send me PM your ftp credentials?
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.