*****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:
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