Page 1 of 2 12 LastLast
Results 1 to 10 of 15
  1. #1
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0

    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.

  2. #2
    Pligg Developer/Coder/Designer ChuckRoast's Avatar
    Joined
    Dec 2005
    Location
    Pliggville USA
    Posts
    9,118
    Thanks
    Received:396
    Given: 73
    Version
    SVN Build
    Site
    http://Pligg.com/chuckroast
    kahunabear, great job on that!

    Care to share how you did this?
    Help Keep ChuckRoast Home
    Today's Pligg Blog Post


  3. #3
    Pligg Developer/Admin kbeeveer46's Avatar
    Joined
    Jun 2006
    Posts
    3,215
    Thanks
    Received:1
    Given: 0
    Glad that you got that working. If you are willing to share, this could be something we can integrate into Pligg (with your permission)

  4. #4
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0
    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

  5. #5
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0

    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);
    ?>

  6. #6
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0
    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

  7. #7
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0

    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

  8. #8
    Casual Pligger GoogleBot's Avatar
    Joined
    Nov 2006
    Posts
    63
    Thanks
    Received:0
    Given: 0
    Thank you kahunabear, i will try it.

  9. #9
    New Pligger kahunabear's Avatar
    Joined
    Jan 2007
    Posts
    13
    Thanks
    Received:0
    Given: 0
    Googlebot,

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

    kb

  10. #10
    New Pligger fightlinker's Avatar
    Joined
    Nov 2006
    Posts
    27
    Thanks
    Received:0
    Given: 0
    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?

Page 1 of 2 12 LastLast

Similar Threads

  1. [mod] count clicks instead of votes
    By abcdefgary in forum Questions & Comments
    Replies: 7
    Last Post: 03-15-2013, 06:47 AM
  2. Clicks instead of Votes (Again)
    By KevinChristman in forum Questions & Comments
    Replies: 4
    Last Post: 05-05-2011, 11:04 PM
  3. counting clicks instead of votes
    By lumpen5 in forum Questions & Comments
    Replies: 45
    Last Post: 01-17-2011, 05:44 AM
  4. News based on Clicks instead of Votes
    By mde05 in forum Questions & Comments
    Replies: 2
    Last Post: 01-14-2008, 05:32 AM
  5. Registering Clicks instead of Votes
    By kahunabear in forum Questions & Comments
    Replies: 2
    Last Post: 02-01-2007, 03:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Pligg Modules and Pligg Templates from Pligg Pro Web Hosting Services by Midphase Dreamhost Web Hosting Donate to Pligg