Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-07-2007, 10:17 AM
AnAlienHolakres3's Avatar
Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 118
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Userīs TagCloud module

Hello people, I have created a new addon to my site and I think it should be veeery useful for you.I think this improving social effect on your site.
Just like all my add-ons this is not absolutely clean code, but for this time no database modification is required.

Letīs look at the result:
Click on it to give a bigger picture:



1)Main Features:
- new tab in your user profile
- tagcloud for every single user
- highlighting of common tags, if is user logged in and has any own tags (in the picture there is a blue color in users Test&AnAlienHolakres3 common tags).
- computing and diplaying how much % of tags have users in common

2)Requirements:
- Pligg v.9.7 (but it is highly probable it can be implemented to a lower version of Pligg)
- Notepad++,PHP Designer,PHPED or whatever good enough for you to edit php files in it
- 2 hours of freetime

3)Steps to do:
3a) Make backup of these files (just in case):
- lang.conf in your /libs/ folder
- user.php in your main folder
- user_center.tpl in your /templates/*your_template*/ folder (mine is yget)

3b) Open lang.conf file and do following:
Find your users profile section and add this code with language customization:
Code:
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud = "TagCloud"
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_WithUser = "With user"
//<SECTION>USER PROFILEE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_Common= "you have common"
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_OfYourTags= "of all your tags."
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_ThisYour= "This is your TagCloud which displays your most used tags by size"
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_UsersView="However from the userīs point of view you have common"
//<SECTION>USER PROFILE</SECTION><ADDED>0.97</ADDED>
PLIGG_Visual_User_TagCloud_UsersViewOfTags="of all his tags".
Save it and close it,thatīs all.

3c) Open your user.php in main folder
If you use URL method 2, addd this code to "url method 2" section. If you use default URL method, i suppose you can skip this step.
3c1)
PHP Code:
setup the URL method 2 links
    $main_smarty
->assign('user_url_personal_data'getmyurl('user2'$login'profile'));
    
$main_smarty->assign('user_url_news_sent'getmyurl('user2'$login'history'));
    
$main_smarty->assign('user_url_news_published'getmyurl('user2'$login'published'));
    
$main_smarty->assign('user_url_news_unpublished'getmyurl('user2'$login'shaken'));
    
$main_smarty->assign('user_url_news_voted'getmyurl('user2'$login'voted'));
    
$main_smarty->assign('user_url_commented'getmyurl('user2'$login'commented'));
    
$main_smarty->assign('user_url_saved'getmyurl('user2'$login'saved'));
    
$main_smarty->assign('user_url_friends'getmyurl('user_friends'$login'viewfriends'));
    
$main_smarty->assign('user_url_friends2'getmyurl('user_friends'$login'viewfriends2'));
    
$main_smarty->assign('user_url_add'getmyurl('user_add_remove'$login'addfriend'));
    
$main_smarty->assign('user_url_remove'getmyurl('user_add_remove'$login'removefriend'));
    
$main_smarty->assign('user_rss'getmyurl('rssuser'$login));
    
$main_smarty->assign('URL_Profile'getmyurl('profile'));
  
//******************************************************************************************
//User TagCloud Addon for user.php in main folder
    
$main_smarty->assign('user_url_tagcloud'getmyurl('user2'$login'tagcloud'));                
//****************************************************************************************** 
[IN NEXT POST]

Last edited by AnAlienHolakres3; 11-23-2008 at 04:41 AM.. Reason: better structure
Reply With Quote
The Following User Says Thank You to AnAlienHolakres3 For This Useful Post:
  #2 (permalink)  
Old 09-07-2007, 10:26 AM
AnAlienHolakres3's Avatar
Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 118
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Userīs TagCloud Part 2

3c2) Find if ($view == 'voted') { and before this condition add this long piece of code:


PHP Code:
//******************************************************************************************
//User TagCloud Addon for user.php in main folder
//By AnlienHolakres3 for Pligg comunity,FREE to modify, NO WARRANTY
//********************************************************************************************
    
if ($view == 'tagcloud') {
        
$page_header .= ' / ' $main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud');
        
$navwhere['text3'] = $main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud');
        
$post_title .= " / " $main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud');
        
$main_smarty->assign('view_href''tagcloud');
       
       
        
$word_limit NULL// limit to cloud to this many words
       
$smarty_variable '';
       
$filterTo 'all'// published, queued or ALL (does not include discarded)
       
$filterCategory 0// a specific category
       
$range_values NULL// only used on the tagcloud page where there is a list of time ranges to filter to.
       
$min_points NULL// the size of the smallest tag
       
$max_points NULL// the size of the largest tag
    
   
            
        
global $db$dblang$URLMethod$tags_words_limit$tags_min_pts$tags_max_pts,$current_user$rows$user$offset$page_size;
            
$user_logged_in $current_user->user_id;
            
$selected_user=$user->id//user we want to see his own tag
            
$range_values = array(0172800604800259200031536000);   
        
        
// if we didnt set a word limit, use the default set in the config.php
            
if ($word_limit == NULL) {$word_limit $tags_words_limit;}

        
// if we didnt set the minimum font points, use the default set in the config.php
            
if ($min_points == NULL) {$min_points $tags_min_pts;}

        
// if we didnt set the maximum font points, use the default set in the config.php
            
if ($max_points == NULL) {$max_points $tags_max_pts;}

            
        
// see if we clicked on a link to filter to a specific time range
        
if(($from check_integer('range')) >= && $from count($range_values) && $range_values[$from] > ) {
            
$from_time time() - $range_values[$from];
            
$from_where "FROM " table_tags " INNER JOIN "table_links " ON "table_tags ".tag_link_id="table_links ".link_id  
            WHERE tag_date > FROM_UNIXTIME($from_time) and link_author =$selected_user  "
;
            
            
$time_query "&amp;from=$from_time";
            $
$main_smarty->assign('time_query'$time_query);
            
        } else {
            
$from_where "FROM " table_tags " INNER JOIN "table_links " ON "table_tags ".tag_link_id="table_links ".link_id  
            WHERE link_author =$selected_user  "
;
        }

        
$from_where .= " GROUP BY tag_words";
              

        
$max max($db->get_var("select count(*) as words $from_where order by words desc limit 1"), 2);
        
$coef = ($max_points $min_points)/($max-1);

        
$sql "select tag_words, count(*) as count $from_where order by count desc limit $word_limit";
      
//   echo $sql;
        
$res $db->get_results($sql);
        
        if (
$res) {
            foreach (
$res as $item) {
                
                
$words[$item->tag_words] = $item->count;
            }     
            
ksort($words);
             

            
$tag_number = array();
            
$tag_name = array();
            
$tag_count = array();
            
$tag_size = array();
            
$tag_url = array();
            
            
$tagnumber 0;
            foreach (
array_keys($words) as $theword) {
                
                
$tag_number[$tagnumber] = $tagnumber;
                
$tag_name[$tagnumber] = $theword;
                
$tag_count[$tagnumber] = $words[$theword];
                
$tag_size[$tagnumber] = $tags_min_pts + ($tag_count[$tagnumber] - 1) * $coef;
                
                if(isset(
$time_query)){
                    
$tag_url[$tagnumber] = getmyurl('tag2'urlencode($tag_name[$tagnumber]), $from_time);
                } else {
                    
$tag_url[$tagnumber] = getmyurl('tag'urlencode($tag_name[$tagnumber]));
                }
                
                
$tagnumber $tagnumber 1;
            }
        }
        
        
// Set the smarty variables for matched tags
            
if(isset($words)){$main_smarty->assign('words'$words);}
            if(isset(
$tag_number)){$main_smarty->assign('tag_number'$tag_number);}else{$main_smarty->assign('tag_number'0);}
            if(isset(
$tag_name)){$main_smarty->assign('tag_name'$tag_name);}
            if(isset(
$tag_count)){$main_smarty->assign('tag_count'$tag_count);}
            if(isset(
$tag_size)){$main_smarty->assign('tag_size'$tag_size);}
            
$tag_url str_replace("+""-"$tag_url); // Steef 2k7-07 tag search fix
            
if(isset($tag_url)){$main_smarty->assign('tag_url'$tag_url);}

           
$main_smarty->assign('tags_words_limit'$word_limit);
           
$main_smarty->assign('tags_min_pts'$min_points);
           
$main_smarty->assign('tags_max_pts'$max_points);
           
$main_smarty->assign('tags_largest_tag'$max);
           
$main_smarty->assign('tags_coef'$coef);        
        
    
//FOR LOGGED-IN USER
                //if is user logged in we will do some comparison with user selected tags
            
$sql "select tag_words FROM " table_tags " INNER JOIN " table_links " ON " table_tags".tag_link_id=" .table_links ".link_id
             WHERE link_author=" 
$user_logged_in ." AND tag_words IN (SELECT tag_words FROM "table_tags " INNER JOIN " table_links " ON "
              
table_tags".tag_link_id=" .table_links ".link_id WHERE link_author=" $user->id .")";
            
         
$res $db->get_results($sql);      
         
          if (
$res) {
            foreach (
$res as $item) {
                
                
$words_new[$item->tag_words] = $item->count;
            }     
            
ksort($words);
             

            
$tag_number = array();
            
$tag_name = array();
            
$tag_count = array();
            
$tag_size = array();
            
$tag_url = array();
            
            
$tagnumber 0;
            foreach (
array_keys($words_new) as $theword_new) {
                
                
$tag_number_match[$tagnumber] = $tagnumber;
                
$tag_name_match[$tagnumber] = $theword_new;
                
$tag_count_match[$tagnumber] = $words_new[$theword];
               
                
                
$tagnumber $tagnumber 1;
            }
        }    
           
// Set the smarty variables for matched tags
            
if(isset($words)){$main_smarty->assign('tag_number_match'$tag_number_match);}
           if(isset(
$tag_name)){$main_smarty->assign('tag_name_match'$tag_name_match);}  
                                                                   
            
        
$main_smarty->assign('nav_tc'4);
     } else {
        
$main_smarty->assign('nav_tc'3);    
     } 
   
//****************************************************************************************** 
3c3) Find following code in this file:
PHP Code:
// display the template
    
$main_smarty->assign('tpl_center'$the_template '/user_center');
    
$main_smarty->display($the_template '/pligg.tpl'); 
And BEFORE that add this function:
PHP Code:
//*******************************************************************************************
//**TagCloud Addon
//this function returns value for adding tags into tagcloud - 1 =true,0 = false
//it is used in user_center.tpl 

 
function nextTag($value) {
            global 
$main_smarty;  
       
$main_smarty->assign('next_tag',$value);     
 }

//******************************************************************************************** 

[IN NEXT PART OF TUTORIAL]

Last edited by AnAlienHolakres3; 09-07-2007 at 12:04 PM..
Reply With Quote
The Following User Says Thank You to AnAlienHolakres3 For This Useful Post:
  #3 (permalink)  
Old 09-07-2007, 10:40 AM
AnAlienHolakres3's Avatar
Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 118
Thanks: 7
Thanked 112 Times in 40 Posts
Send a message via ICQ to AnAlienHolakres3
Userīs TagCloud module Part III

3c4) Last thing to do in this file, to add following function AFTER // display the template code.

So there is the function:

PHP Code:
//********************************************************************************************
//TagCloud AddOn - % results 
//
    
function do_tagcloud_compare () { 
        global 
$current_user,$user,$main_smarty,$db;
        
$user_logged_in=$current_user->user_id;
    
        
            if (
$user_logged_in!=null){
 
           
$sql  "SELECT count(tag_words) FROM (SELECT DISTINCT tag_words FROM " table_tags " INNER JOIN " table_links " ON " table_tags".tag_link_id=" .table_links ".link_id
             WHERE link_author=" 
$user_logged_in ." AND tag_words IN (SELECT tag_words FROM "table_tags " INNER JOIN " table_links " ON "
              
table_tags".tag_link_id=" .table_links ".link_id WHERE link_author=" $user->id .")) AS matched_tags";
             
             
$sql2  "SELECT count(tag_words) FROM (SELECT DISTINCT tag_words FROM " table_tags " INNER JOIN " table_links " ON " table_tags".tag_link_id=" .table_links ".link_id
             WHERE link_author=" 
$user_logged_in .") AS matched_tags";             
           
//BUGFIX02 START
           
$sql3 "SELECT count(distinct tag_words) FROM "table_tags " INNER JOIN " table_links " ON "table_tags".tag_link_id=" .table_links ".link_id WHERE link_author=" $user->id;
         
//BUGFIX02 END  
           
$matched_count $db->get_var($sql);
           
$user_logged_tags_count $db->get_var($sql2);
           
$selected_user_tags_count=$db->get_var($sql3);
          
//START OF BUGFIX01
          
if ($user_logged_tags_count>0){
            
$percent round($matched_count $user_logged_tags_count,3)*100;  }
          if (
$selected_user_tags_count>0) {
            
$percent_his_view round($matched_count $selected_user_tags_count,3)*100  ;
           }
         
//END OF BUGFIX01
          
if ($user_logged_in != $user->id) {
               
           echo 
"<div style='text-align: center; background-color: #EAF4FF; border: 1px double #000099';>" 
           
$main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_WithUser') .
           
" <b> ".$user->username ." </b> "$main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_Common') . " <b> " 
           
.$percent "% </b> " $main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_OfYourTags'). ".<BR>".$main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_UsersView').
           
" <b>".$percent_his_view ."%</b> "$main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_UsersViewOfTags')."</div>" ;
                    
                    }else {
            echo 
"<div style='text-align: center; background-color: #EAF4FF; border: 1px double #000099';>" 
           
$main_smarty->get_config_vars('PLIGG_Visual_User_TagCloud_ThisYour') . "</div>" ;
                    
                    
                    
                    }  
          
             }       
            }       
              
   
//******************************************************************************************** 
Ok, that´s all in this file. You can save it and close it.

3d) open your user_center.tpl in your templates/yget/ folder
3d1) Find folloving code, just scroll down (it is somewhere in the end)
Code:
{php}
Global $db, $main_smarty, $view, $user, $rows, $page_size, $offset;
Now add following code into this:
PHP Code:
    case 'tagcloud':
        
do_tagcloud_compare();    
   &n