Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-29-2007, 07:12 AM
AnAlienHolakres3's Avatar
Pligg Donor
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Link Clicks-Count Addon

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:
Code:
ALTER TABLE your_site_links ADD COLUMN clicks bigint default 1
A)open link.php in your libs folder and do following:
1)add var clicks:
var $clicks=0;

2) after function store_basic add following function:
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);
     } 
3) find function read($usecache = TRUE) and if ($link) statement. After that add this:
PHP Code:
$this->clicks=$link->clicks//clicks addon 

4) find function read_basic() and update query:
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"))) 
So dont forget to add clicks column. After that add this into condition:¨
PHP Code:
 $this->clicks=$link->clicks;               //clicks addon 
5) find function fill_smarty($smarty, $type='full') and in this function find "viewtype". After this line add:
PHP Code:
$smarty->assign('link_clicks',$this->clicks);//link clicks addon 
Thats all in this file.

B) create a new file in your main folder and name it click_link_count.php. Add following code:
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(); 
   }

    
    

?>
You can save it.

C)Open xmlhttp.php in your js folder. We need to add some javascript function,so before vote function add this:
Code:
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);
                        
          }  
  }
Ok you can save it

D)Open link_summary.tpl in your templates/template/ folder.
1)after {if $Voting_Method eq 1} in the beginning add this code:

PHP Code:
        <div class="click_count"  id="click_count-{$link_id}" >{$link_clicks}</div
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:
onclick="sendClickedValue({$link_id},{$link_shakebox_index});" 
Save.

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:
Code:
.click_count{font-size:7pt;width:54px;text-align:center;color:white;font-weight:bold;position:relative;z-index:1}
F) Final step
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:
Code:
target1.innerHTML = b[0];
with:
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;  
          }
You can save it.

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:
Code:
.click_count{font-size:7pt;width:54px;text-align:center;color:white;font-weight:bold;position:relative;z-index:1}
3)find .vote-publish a and
change line-height to 55px

4) add class:
Code:
.vote {
  margin-top:-7px
}
Now we are going to handle "upcoming" section:
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
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.org
Reply With Quote
The Following 9 Users Say Thank You to AnAlienHolakres3 For This Useful Post:
  #2 (permalink)  
Old 10-29-2007, 05:31 PM
Constant Pligger
 
Join Date: Feb 2007
Posts: 183
Thanks: 13
Thanked 24 Times in 19 Posts
Thanks for this. Is this method better than Ozo's one which is discussed on this thread:
http://forums.pligg.com/pligg-mods/6...ead-votes.html
Reply With Quote
  #3 (permalink)  
Old 10-29-2007, 09:11 PM
not2serious's Avatar
Pligg Donor
Pligg Version: v0.96 w/modifications
Pligg Template: Yget w/modifications
 
Join Date: Apr 2007
Location: East Coast, USA
Posts: 226
Thanks: 16
Thanked 16 Times in 15 Posts
I there a way to use this is voting method 2 (5 stars). Say, post the view total with the voting statistics?

Quote:
Posted by USER 11 days ago - Average Rating: 4.5 with 6 vote(s) and 25 view(s) (Art or Editorial Post)
__________________
My Pligg Site: Critique My Art
My Arts Directory: Links 2 Arts
Reply With Quote
  #4 (permalink)  
Old 10-29-2007, 09:33 PM
New Pligger
Pligg Version: 9.8.2
Pligg Template: NA
 
Join Date: Oct 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Great addon! I'll be adding this first thing in the morning, thanks!
Reply With Quote
  #5 (permalink)  
Old 10-30-2007, 04:13 AM
AnAlienHolakres3's Avatar
Pligg Donor
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Which method is better

Quote:
Originally Posted by Andtony View Post
Thanks for this. Is this method better than Ozo's one which is discussed on this thread:
http://forums.pligg.com/pligg-mods/6...ead-votes.html
Ozo´s method is great but with certain drawback - "views" value is increased after reloading page, this method increase value immediately after clicking on link.
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.org
Reply With Quote
  #6 (permalink)  
Old 10-30-2007, 04:19 AM
AnAlienHolakres3's Avatar
Pligg Donor
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Implementation with Star voting method

Quote:
Originally Posted by not2serious View Post
I there a way to use this is voting method 2 (5 stars). Say, post the view total with the voting statistics?
I think so. Of course you will have to change link_summary.tpl in a little different way but the core of this is the same. Try to customize steps D and E . If you got difficulties with implementation feel free to post the problem.
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.org
Reply With Quote
The Following User Says Thank You to AnAlienHolakres3 For This Useful Post:
  #7 (permalink)  
Old 10-30-2007, 09:08 AM
not2serious's Avatar
Pligg Donor
Pligg Version: v0.96 w/modifications
Pligg Template: Yget w/modifications
 
Join Date: Apr 2007
Location: East Coast, USA
Posts: 226
Thanks: 16
Thanked 16 Times in 15 Posts
I will give this a try the next time I upgrade.

Thanks for the add on.
__________________
My Pligg Site: Critique My Art
My Arts Directory: Links 2 Arts
Reply With Quote
  #8 (permalink)  
Old 10-30-2007, 11:15 PM
Casual Pligger
 
Join Date: Jan 2007
Posts: 60
Thanks: 22
Thanked 7 Times in 6 Posts
Quote:
Originally Posted by AnAlienHolakres3 View Post
Ozo´s method is great but with certain drawback - "views" value is increased after reloading page, this method increase value immediately after clicking on link.
Even better, after editing the post, you don't lose the click count. See my implementation here: Pandora Stations

I just finished converting from Ozo's version to this one.
Reply With Quote
  #9 (permalink)  
Old 11-02-2007, 09:45 AM
AnAlienHolakres3's Avatar
Pligg Donor
 
Join Date: Jul 2007
Location: Prague
Posts: 117
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Quote:
Originally Posted by timofsuburbia View Post
Even better, after editing the post, you don't lose the click count. See my implementation here: Pandora Stations

I just finished converting from Ozo's version to this one.
Nice site
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.org
Reply With Quote
  #10 (permalink)  
Old 11-07-2007, 10:21 PM
netwb's Avatar
Casual Pligger
Pligg Version: 9.8
Pligg Template: Yget - Convergence - GarrX
 
Join Date: Dec 2006
Location: Bruxelles
Posts: 63
Thanks: 20
Thanked 25 Times in 11 Posts
you have the zip file to Link Clicks-Count Addon? and you have the source of your placement the add gooogle pub display in you pligg.tpl
thank you very mutch "AnAlienHolakres3's Avatar
AnAlienHolakres"
__________________
Bruxello.com l Europeanpainting.eu l
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
Submit Antispam Addon v 0.1 AnAlienHolakres3 Pligg Modules 22 10-01-2008 05:08 PM
Special Advertising Add-On for banners Tutorial AnAlienHolakres3 Modification Tutorials 18 07-30-2008 09:25 AM
[mod] count clicks instead of votes abcdefgary Modification Tutorials 8 06-14-2008 11:34 PM
Pligg Team Addon Installation GUIDE & MANUAL AnAlienHolakres3 Modification Tutorials 17 04-07-2008 03:41 PM
Vote count and Title Link only on front page tommy818 General Help 1 10-25-2007 04:40 AM


Search Engine Friendly URLs by vBSEO 3.2.0