Hello people. This is tutorial for Link Clicks Add-on which is independent on votes and it is not its replacement. The idea is pretty simple - if user clicks on link, then click value for this specific link is increased.
Where is clicks value shown? It depends on you but i did to be above of votes count so result looks like this:
You can also see demo (version 0.98) on:
Version 098
And version 0.97 (which is highly customized) on
Version 097 (Customized)
Requirements
- Pligg v 9.7 or 9.8
- Basic PHP,css knowledge
- voting option:1 (default ->NO star voting)
- title as link
-yget template
It is neccesary to use story title as link and open story title in new window. To do that, go to your admin panel-configure Pligg-Story and set both "use story titles as link" and "open story title in new window" to true.
Files:
Place to your templates/yget/images folder
![]()
Steps to do:
AA) Go to your phpMyAdmin and run following sql:
A)open link.php in your libs folder and do following:Code:ALTER TABLE your_site_links ADD COLUMN clicks bigint default 1
1)add var clicks:
var $clicks=0;
2) after function store_basic add following function:
3) find function read($usecache = TRUE) and if ($link) statement. After that add this:PHP Code://***************************************
//function storeClicks() save click value
//***************************************
function store_clicks(){
global $db;
$clicks=$this->clicks+1;
$sql = "UPDATE " . table_links . " set `clicks`=$clicks WHERE link_id=".$this->id;
$db->query($sql);
}
PHP Code:$this->clicks=$link->clicks; //clicks addon
4) find function read_basic() and update query:
So dont forget to add clicks column. After that add this into condition:¨PHP Code:if(($link = $db->get_row("SELECT link_comments, link_author, link_status, link_randkey, link_category, link_date, link_votes, link_karma, link_published_date,clicks FROM " . table_links . " WHERE link_id = $id")))
5) find function fill_smarty($smarty, $type='full') and in this function find "viewtype". After this line add:PHP Code:$this->clicks=$link->clicks; //clicks addon
Thats all in this file.PHP Code:$smarty->assign('link_clicks',$this->clicks);//link clicks addon
B) create a new file in your main folder and name it click_link_count.php. Add following code:
You can save it.PHP Code:<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// [url=http://www.affero.org/oagpl.html]affero.org: affero general public license[/url]
// @author AnAlienHolakres3
if($_POST['link_id']){
include_once('Smarty.class.php');
$main_smarty = new Smarty;
include('config.php');
include(mnminclude.'link.php');
include(mnminclude.'html1.php');
include(mnminclude.'smartyvariables.php');
$link = new Link;
//initialize Link and set ID
$link->id=$_POST['link_id'];
//read Link information
$link->read_basic();
$value = $_POST['value'];
//save new clicks value
$link->store_clicks();
}
?>
C)Open xmlhttp.php in your js folder. We need to add some javascript function,so before vote function add this:
Ok you can save itCode:function sendClickedValue(link_id,htmlid) { var value; if(document.all){ value=parseInt(document.getElementById('click_count-'+link_id).innerText)+1; document.getElementById('click_count-'+link_id).innerText=value; } else { value=parseInt(document.getElementById('click_count-'+link_id).textContent)+1; document.getElementById('click_count-'+link_id).textContent=value; } url = "<?php echo $my_base_url.$my_pligg_base; ?>/click_link_count.php"; mycontent = "link_id=" + link_id; mnmxmlhttp[htmlid] = new myXMLHttpRequest (); if (mnmxmlhttp) { mnmxmlhttp[htmlid].open ("POST", url, true); mnmxmlhttp[htmlid].setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded'); mnmxmlhttp[htmlid].send (mycontent); } }
D)Open link_summary.tpl in your templates/template/ folder.
1)after {if $Voting_Method eq 1} in the beginning add this code:
2)find {if $use_title_as_link eq true} and after {if $url_short neq "http://" && $url_short neq "://"} add into <a > element this code:PHP Code:<div class="click_count" id="click_count-{$link_id}" >{$link_clicks}</div>
Save.PHP Code:onclick="sendClickedValue({$link_id},{$link_shakebox_index});"
E) open your main.css in your templates/template/css folder
Please note that this you should customize to your own needs.Add this class:
F) Final stepCode:.click_count{font-size:7pt;width:54px;text-align:center;color:white;font-weight:bold;position:relative;z-index:1}
We made some customization in link_summary.tpl,remember? The little problem is that javascript used when voting replace our code and in some browsers (for example Opera) votebox is completely distorted. To avoid this we need to make one more customization:
open xmlhttp.php in your js folder and find function changemnmvalues (id, value, error).
Then, replace original code:
with:Code:target1.innerHTML = b[0];
You can save it.Code:if(document.all){ value=parseInt(document.getElementById('xvotes-' + id).innerText)+1; document.getElementById('xvotes-' + id).innerText=value; } else { value=parseInt(document.getElementById('xvotes-' + id).textContent)+1; document.getElementById('xvotes-' + id).textContent=value; }
G) The core of this is done but current votebox image is not suitable for our purposes.
Open main.css in your templates/yget folder and do following:
1) find .news-upcoming and change vote.png to vote2.png
2) add following class:
3)find .vote-publish a andCode:.click_count{font-size:7pt;width:54px;text-align:center;color:white;font-weight:bold;position:relative;z-index:1}
change line-height to 55px
4) add class:
Now we are going to handle "upcoming" section:Code:.vote { margin-top:-7px }
1) find .news-upcoming2 and change vote-l.png to vote-l2.png
This is not absolutely clean so feel free to customize it
Thats all. Hope it works for you![]()







Reply With Quote




