Counting Clicks for Thumbnails in Category listings - eSyndiCat User Forums
eSyndiCat User Forums esyndicat directory software esyndicat support

Go Back   eSyndiCat User Forums > eSyndiCat Directory Software [FREE] > Modifications

Modifications Simple to complex modifications, made by users or by our team, applied to logic or presentation, all kinds of modifications are discussed and requested here.

Reply
 
Thread Tools Display Modes
Old 12-02-2006   #1
Mark Brookes
 
Join Date: Mar 2006
Posts: 650
Mark Brookes has disabled reputation
Default Counting Clicks for Thumbnails in Category listings

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
Code:
{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
Attached Files
File Type: pdf thumbnails iin listings-Ocean.pdf (25.3 KB, 15 views)
Mark Brookes is offline   Reply With Quote
Old 12-03-2006   #2
Mark Brookes
 
Join Date: Mar 2006
Posts: 650
Mark Brookes has disabled reputation
Default

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
Code:
<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. ---
Mark Brookes is offline   Reply With Quote
Old 12-03-2006   #3
Dave Baker
 
Join Date: Jul 2006
Location: St. Petersburg
Posts: 2,567
Dave Baker is on a distinguished road
Default

Hi Mark,
Thanks for very useful modification.

Quote:
Of course I don't understand why it works .. but who cares?
Actually this works very simply:
Code:
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
Code:
<h1><a href="{$link.url}" id="l{$link.id}" {if $config.new_window}target="_blank"{/if}>{$link.title}</a></h1>
and
Code:
<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
Code:
<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+'&amp;h='+h;

		return true;
	}
	{/literal}
</script>
Code responsible for renewal "count of cliks" in database, you can find in click-count.php
Dave Baker is offline   Reply With Quote
Old 12-03-2006   #4
Bryan Ex
 
Bryan Ex's Avatar
 
Join Date: Mar 2006
Location: Ottawa, Canada
Posts: 366
Bryan Ex has disabled reputation
Default

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.
__________________
Theres no place like 127.0.0.1
Bryan Ex is offline   Reply With Quote
Old 12-03-2006   #5
Dave Baker
 
Join Date: Jul 2006
Location: St. Petersburg
Posts: 2,567
Dave Baker is on a distinguished road
Default

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***
Code:
{if $config.alexa_thumbs}
	<td width="<strong>{$lang.$key}:</strong>">{get_thumbnail_link aUrl=$link.url aSize=Large}</td>
{/if}
***Replace with following***
Code:
{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***
PHP Code:
function get_thumbnail_link($aParams
***In this function find code***
PHP Code:
return get_html_snippet($url$default_image); 
***Replace with following code***
PHP Code:
return get_html_snippet($url$default_image$aParams['idLink']); 
***In this file find function***
PHP Code:
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***
PHP Code:
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***

Last edited by Dave Baker; 12-03-2006 at 10:07 PM.
Dave Baker is offline   Reply With Quote
Old 12-03-2006   #6
Bryan Ex
 
Bryan Ex's Avatar
 
Join Date: Mar 2006
Location: Ottawa, Canada
Posts: 366
Bryan Ex has disabled reputation
Default

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.
__________________
Theres no place like 127.0.0.1
Bryan Ex is offline   Reply With Quote
Old 12-03-2006   #7
Bryan Ex
 
Bryan Ex's Avatar
 
Join Date: Mar 2006
Location: Ottawa, Canada
Posts: 366
Bryan Ex has disabled reputation
Default

Quote:
Originally Posted by Dave Baker
***In this file find function***
PHP Code:
function get_html_snippet($url$image$idLink
That function in my file is originally ...
PHP Code:
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()
__________________
Theres no place like 127.0.0.1
Bryan Ex is offline   Reply With Quote
Old 12-03-2006   #8
Dave Baker
 
Join Date: Jul 2006
Location: St. Petersburg
Posts: 2,567
Dave Baker is on a distinguished road
Default

I'm sorry Bryan, it's my fault.
I have corrected the previous post
Dave Baker is offline   Reply With Quote
Old 12-03-2006   #9
Bryan Ex
 
Bryan Ex's Avatar
 
Join Date: Mar 2006
Location: Ottawa, Canada
Posts: 366
Bryan Ex has disabled reputation
Default

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 Code:
<?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($key64chr(0x00))
        ^(
str_repeat(chr(0x5c), 64))) .
        
pack("H*"sha1((str_pad($key64chr(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);
}
?>
__________________
Theres no place like 127.0.0.1
Bryan Ex is offline   Reply With Quote
Old 12-03-2006   #10
Dave Baker
 
Join Date: Jul 2006
Location: St. Petersburg
Posts: 2,567
Dave Baker is on a distinguished road
Default

Bryan in this code:
PHP 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:
PHP Code:
$idLink $link.id
Remove this code. He returns empty value.
p.s If the problem will not be solved I can attach the file
Dave Baker is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 07:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Testimonials | Articles | Support | Documentation | Privacy Policy | License | Affiliates | Contact Us