Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-02-2007, 06:47 PM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
Counting Clicks instead of Votes

I have modified my version of Pligg to count Clicks instead of Votes. It only records a click for a story once per IP address. The click is recorded when the user clicks on either the title, the url, or the click box(formerly vote box). Try it and see what you think:

favester.com

It is hard to show a lot of votes when you are just starting out. I noticed a lot of people coming to the site and clicking the links, but not voting. This was a way to show that activity.

Also, I have a php routine that compares votes to clicks for each link. If anyone wants it I can post it. The results are interesting.

Post #7 below details changes I made for this mod.

Last edited by kahunabear; 02-04-2007 at 02:11 AM..
Reply With Quote
The Following 3 Users Say Thank You to kahunabear For This Useful Post:
  #2 (permalink)  
Old 02-02-2007, 07:36 PM
chuckroast's Avatar
Coder/Designer
Pligg Version: 1.0
Pligg Template: ExpertVision
 
Join Date: Jun 2006
Location: PA
Posts: 2,399
Thanks: 171
Thanked 439 Times in 278 Posts
kahunabear, great job on that!

Care to share how you did this?
__________________
Visit PliggPro the official Pligg Mods & Template Shop!


Last edited by chuckroast; 02-02-2007 at 07:42 PM..
Reply With Quote
  #3 (permalink)  
Old 02-02-2007, 07:57 PM
kbeeveer46's Avatar
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,547
Thanks: 254
Thanked 649 Times in 513 Posts
Glad that you got that working. If you are willing to share, this could be something we can integrate into Pligg (with your permission)
__________________
I accept donations for my time helping users like you on the forum and IRC.
Reply With Quote
  #4 (permalink)  
Old 02-02-2007, 08:45 PM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
Sure, I don't mind sharing it a bit. I kinda did a hack job on it, though. It would need to be cleaned up.

I also have a php/sql routine that generates clicks from the page views table to convert past clicks.

I will work on getting it all written up.

Thanks
Reply With Quote
  #5 (permalink)  
Old 02-02-2007, 10:42 PM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
php/sql to compare Clicks and Votes

Below, is a php routine to compare clicks to votes for each link in your system. It can be saved into a file uploaded and run from a browser. The database information has to be changed to connect to your database. Also, the string "tableprefix" has to be changed to match the prefix of your database tables.
This doesn't change anything. It just gives you an idea of what using the click method would look like compared to the voting method. Also, it would make sense to delete it after running it. Not a good idea to leave username/passwords sitting around in files. Use at your own risk.

The output will look something like this:

link id: 1 How to Lose Money in Stocks
votes: 2 clicks: 11

link id: 2 10 Ways to Prepare Frog Legs
votes: 3 clicks: 14

PHP Code:
<?php
$server 
"YOUR HOST";    
$database "YOUR DATABASE";    
$db_user "YOUR USERNAME";    
$db_pass "YOUR PASSWORD";
$link mysql_connect($server$db_user$db_pass)
or die (
"Could not connect to mysql because ".mysql_error());
mysql_select_db($database)
or die (
"Could not select database because ".mysql_error());
$pvresult mysql_query("SELECT * FROM tableprefix_pageviews WHERE pv_type = 'out' ORDER BY pv_page_id, pv_user_ip");
$voteip="";
$linkid="";
while (
$pvrow mysql_fetch_row($pvresult)) {
    if (
$voteip != $pvrow[5]){
        
$clickcount++;
        
$voteip $pvrow[5];
    }
    if (
$linkid == ""){
        
$linkid $pvrow[2];
    }
    if (
$linkid != $pvrow[2]){
        
$vcresult mysql_query("SELECT COUNT(*) FROM tableprefix_votes WHERE vote_link_id = '".$linkid."'");
        
$vcrow mysql_fetch_row($vcresult);
        
$lnresult mysql_query("SELECT link_title FROM tableprefix_links WHERE link_id = '".$linkid."'");
        
$lnrow mysql_fetch_row($lnresult);    
        echo 
"link id: ".$linkid." ".$lnrow[0];
        echo 
"<br>";        
        echo 
"votes: ".$vcrow[0]."  clicks: ".$clickcount;            
        echo 
"<br>";
        echo 
"<br>";        
        
$linkid $pvrow[2];
        
$clickcount 0;
    }
}
$vcresult mysql_query("SELECT COUNT(*) FROM tableprefix_votes WHERE vote_link_id = '".$linkid."'");
$vcrow mysql_fetch_row($vcresult);
$lnresult mysql_query("SELECT link_title FROM tableprefix_links WHERE link_id = '".$linkid."'");
$lnrow mysql_fetch_row($lnresult);
echo 
"link id: ".$linkid." ".$lnrow[0];
echo 
"<br>";        
echo 
"votes: ".$vcrow[0]."  clicks: ".$clickcount;
echo 
"<br>";
echo 
"<br>";        
mysql_close($link);
?>

Last edited by kbeeveer46; 02-03-2007 at 12:20 AM.. Reason: added php tags
Reply With Quote
The Following 4 Users Say Thank You to kahunabear For This Useful Post:
  #6 (permalink)  
Old 02-03-2007, 12:13 AM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
Here is how I did this. I really took the quick and dirty approach. I use the current voting system to record clicks instead of votes. There is no option to do voting also. To make the change better would require a separate table and separate click scripts.

I changed the system to update the vote table when the user clicks a link. To do this, I call the voting script from the template when the title or link is clicked. I also changed the script that calls the voting script to open the link after voting. The main files I changed were:

link.php (assigns call info to a variable used in template)
link_summary.tpl (template)
xmlhttp.php (calls voting script)

I also made various cosmetic changes and wrote a php routine to convert the old data.

I will try to post the specific changes this weekend.

kb
favester.com
Reply With Quote
  #7 (permalink)  
Old 02-04-2007, 02:04 AM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
Smile Here it is!

*****WARNING*****
This change is a total hack(but it works). Don't attempt these changes unless you have a programming background. These changes make you lose all previous votes(but you pick up lots of new click counts from past clicks). This change is not supported and will make implementing any future versions of Pligg very difficult. Make these changes to a test version of the system before implementing it live. Backup all live systems before implementing and after thorough testing. Finally, I probably have forgotten something. Proceed at your own risk.
****WARNING****


In the file /libs/link.php the following code creates a variable, called "link_shakebox_javascript_vote", that is used in the template(link_summary.tpl) to call a javascript function called "menealo" when the user clicks the vote box.

Before:

Code:
$jslink = "menealo($current_user->user_id, $this->id, $link_index, " . "'" . md5($current_user->user_id.$this->randkey) . "', 10)";
$smarty->assign('link_shakebox_javascript_vote', $jslink);
The "menealo" function handles the voting logic. To register clicks, I call "menealo" when a link is clicked. But, I also need to open the link in a window. So, I pass "menealo" the link as an extra parameter. I created a new variable to be used in my template called "link_shakebox_javascript_votelink". It works just like "link_shakebox_javascript_vote" except I have stripped off the closing paren at the end of the string. I do this so when the "menealo" function gets called, I can pass it the extra parameter.

After:

Code:
$jslink = "menealo($current_user->user_id, $this->id, $link_index, " . "'" . md5($current_user->user_id.$this->randkey) . "', 10)";
$smarty->assign('link_shakebox_javascript_vote', $jslink);
$smarty->assign('link_shakebox_javascript_votelink', rtrim ($jslink ,")" )); 
The parameter I pass it is the link URL to open after menealo does its voting thing. I pass this parameter directly in the template(link_summary.tpl) by appending it to the javascript call. Here is what the new call looks like:

javascript:{$link_shakebox_javascript_votelink},'{ $url}')

I place this code in 4 places within the link_summary.tpl file. These are the 4 places a user can click to open the link window. There are two for the voting boxes, one for the title and one for the URL. The specific code changes are as follows:

For the voting boxes I change this:

Code:
<ul class="news-shakeit">
	<li class="mnm-published" id="cat{$category_id}"><a id="mnms-{$link_shakebox_index}" href="javascript:{$link_shakebox_javascript_vote}">{$link_shakebox_votes}</a></li>
	<li class="menealo" id="mnmlink-{$link_shakebox_index}">
		{if $link_shakebox_currentuser_votes eq 0}
			<a href="javascript:{$link_shakebox_javascript_vote}">{#PLIGG_Visual_Vote_For_It#}</a>
		{else}
			<span>{#PLIGG_Visual_Vote_Cast#}</span>
		{/if}
	</li>
</ul>
To this:

Code:
<ul class="news-shakeit">
	<li class="mnm-published" id="cat{$category_id}"><a id="mnms-{$link_shakebox_index}" href="javascript:{$link_shakebox_javascript_votelink},'{$url}')">{$link_shakebox_votes}</a></li>
	<li class="menealo" id="mnmlink-{$link_shakebox_index}">
		{if $link_shakebox_currentuser_votes eq 0}
			<a href="javascript:{$link_shakebox_javascript_votelink},'{$url}')">{#PLIGG_Visual_Vote_For_It#}</a>
		{else}
			<span>{#PLIGG_Visual_Vote_Cast#}</span>
		{/if}
	</li>
</ul>
For the title I change:

Code:
{if $use_title_as_link eq true}
	{if $url_short neq "http://" && $url_short neq "://"}
		<a href="{$url}" {if $open_in_new_window eq true} target="_blank"{/if}>{$title_short}</a>
	{else}
		<a href="{$story_url}">{$title_short}</a>
	{/if}
{else}
	<a href="{$story_url}">{$title_short}</a>
{/if}
To this:

Code:
{if $use_title_as_link eq true}
	{if $url_short neq "http://" && $url_short neq "://"}
		<a href="javascript:{$link_shakebox_javascript_votelink},'{$url}')">{$title_short}</a>
	{else}
		<a href="{$story_url}">{$title_short}</a>
	{/if}
{else}
	<a href="{$story_url}">{$title_short}</a>
{/if}
For the URL I change:

Code:
<span id="ls_story_link-{$link_shakebox_index}">
	{if $url_short neq "http://" && $url_short neq "://"}
		<a href="{$url}" {if $open_in_new_window eq true} target="_blank"{/if} class="screen">{$url_short}{if $use_thumbnails eq true}<b><img src="http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r={$url_short}"></b>{/if}</a>
	{else}
		{$No_URL_Name}
	{/if}
</span>
To this:

Code:
<span id="ls_story_link-{$link_shakebox_index}">
	{if $url_short neq "http://" && $url_short neq "://"}
		<a href="javascript:{$link_shakebox_javascript_votelink},'{$url}')" class="screen">{$url_short}{if $use_thumbnails eq true}<b><img src="http://msnsearch.srv.girafa.com/srv/i?s=MSNSEARCH&r={$url_short}"></b>{/if}</a>
	{else}
		{$No_URL_Name}
	{/if}
</span>
So, now that I am passing the URL to the javascript function "menealo", I had to change that function to accept this extra parameter and use it to open a window for the link. The function is found in the file /js/xmlhttp.php. Here are the two changes.

The function call before:

Code:
function menealo (user, id, htmlid, md5, value)
The function call after:

Code:
function menealo (user, id, htmlid, md5, value, linkurl)
The bottom part of the function before:

Code:
    					}
    				}
    			}
    		}
    	}
	}
}
The bottom of the function after:

Code:
    					}
    				}
    			}
    		}
    	}
	if (linkurl){window.open(linkurl)};
	}
}
Other configuration and cosmetic changes:

I changed all language files that used to say "vote" or "votes" to "click" or "clicks". Some labels are still in the code.

Also, I changed my system configuration as follows:

1.No vote when a link is submitted.
2.Set the publish threshold at 0 votes.

This causes links to immediately show up on my published list with a click count of 0. Each click from then on is recorded as a vote. BTW, I also changed my system to not even show unpublished links since I have none.

Before I implemented the above changes I made the following database changes:

1. I deleted all of the rows in the tableprefix_votes table. This destroys all past votes. Do a backup!

2. Then I ran the following php script to generate votes from past clicks. It reads through the tableprefix_pageviews table looking for all rows where the user clicked a link or title(pv_type = 'out'). For each unique click by an ip address, I insert a row into the tableprefix_votes table. For each link, I update the tableprefix_links table with the total number of clicks/votes for that link.

***** WARNING - The script below changes your database! *****

PHP Code:
<?php
$server 
"YOUR HOST";    
$database "YOUR DATABASE";    
$db_user "YOUR USERNAME";    
$db_pass "YOUR PASSWORD";
$link mysql_connect($server$db_user$db_pass)
or die (
"Could not connect to mysql because ".mysql_error());
mysql_select_db($database)
or die (
"Could not select database because ".mysql_error());
$pvresult mysql_query("SELECT * FROM tableprefix_pageviews WHERE pv_type = 'out' ORDER BY pv_page_id, pv_user_ip");
$voteip="";
$linkid="";
while (
$pvrow mysql_fetch_row($pvresult)) {
    if (
$linkid == ""){
        
$linkid $pvrow[2];
    }
    if (
$linkid != $pvrow[2]){
        
$vcresult mysql_query("SELECT COUNT(*) FROM tableprefix_votes WHERE vote_link_id = '".$linkid."'");
        
$vcrow mysql_fetch_row($vcresult);
        
$lnresult mysql_query("SELECT link_title FROM tableprefix_links WHERE link_id = '".$linkid."'");
        
$lnrow mysql_fetch_row($lnresult);
        
$updatelink "UPDATE tableprefix_links SET link_votes = ".$clickcount." WHERE link_id = ".$linkid;
        
$ulresult mysql_query($updatelink) or die ("Could not select database because ".mysql_error());        
        echo 
"link id: ".$linkid." ".$lnrow[0];
        echo 
"<br>";        
        echo 
"votes: ".$vcrow[0]."  clicks: ".$clickcount;            
        echo 
"<br>";
        echo 
"<br>";        
        
$linkid $pvrow[2];
        
$clickcount 0;
    }
    if (
$voteip != $pvrow[5]){
        
$clickcount++;
        
$voteip $pvrow[5];
        
$insertclickvote "INSERT INTO tableprefix_votes (vote_type, vote_date, vote_link_id, vote_user_id, vote_value, vote_ip) VALUES ('links', '".$pvrow[3]."', ".$pvrow[2].", ".$pvrow[4].", '10','".$pvrow[5]."')";
        
$ivresult mysql_query($insertclickvote) or die ("Could not select database because ".mysql_error());
        echo 
$insertclickvote;
        echo 
"<br>";
    }
}
$vcresult mysql_query("SELECT COUNT(*) FROM tableprefix_votes WHERE vote_link_id = '".$linkid."'");
$vcrow mysql_fetch_row($vcresult);
$lnresult mysql_query("SELECT link_title FROM tableprefix_links WHERE link_id = '".$linkid."'");
$lnrow mysql_fetch_row($lnresult);
$updatelink "UPDATE tableprefix_links SET link_votes = ".$clickcount." WHERE link_id = ".$linkid;
$ulresult mysql_query($updatelink) or die ("Could not select database because ".mysql_error());    
echo 
"link id: ".$linkid." ".$lnrow[0];
echo 
"<br>";        
echo 
"votes: ".$vcrow[0]."  clicks: ".$clickcount;
echo 
"<br>";
echo 
"<br>";        
mysql_close($link);
?>
That is pretty much it. I think. Good Luck.

favester.com

kb

Last edited by kahunabear; 02-04-2007 at 02:16 AM..
Reply With Quote
The Following 6 Users Say Thank You to kahunabear For This Useful Post:
  #8 (permalink)  
Old 02-04-2007, 10:57 AM
Casual Pligger
 
Join Date: Nov 2006
Location: Europe
Posts: 81
Thanks: 18
Thanked 10 Times in 10 Posts
Thank you kahunabear, i will try it.
__________________
www.youdude.net | www.techbeta.org
Reply With Quote
  #9 (permalink)  
Old 02-04-2007, 11:58 AM
New Pligger
 
Join Date: Jan 2007
Posts: 17
Thanks: 1
Thanked 20 Times in 6 Posts
Googlebot,

Your Welcome. Let me know how it goes and if I can help.

kb
Reply With Quote
  #10 (permalink)  
Old 02-06-2007, 09:38 PM
fightlinker's Avatar
New Pligger
 
Join Date: Nov 2006
Posts: 27
Thanks: 9
Thanked 0 Times in 0 Posts
I'm interested in doing this, but eventually i will want to switch back to the standard way. Do the changes to the system mean that i won't simply be able to reinstall or upgrade pligg to get back to the way things used to be?
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
[mod] count clicks instead of votes abcdefgary Modification Tutorials 8 06-14-2008 11:34 PM
News based on Clicks instead of Votes mde05 Modification Tutorials 2 01-14-2008 08:32 AM
counting clicks instead of votes lumpen5 Modification Tutorials 41 01-04-2008 05:47 PM
users total votes? inggenia General Help 2 07-09-2007 07:44 AM
Registering Clicks instead of Votes kahunabear General Help 2 02-01-2007 06:50 PM


Search Engine Friendly URLs by vBSEO 3.2.0