Sidebar Experts Module Tutorial

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-2007, 04:18 AM
AnAlienHolakres3's Avatar
Pligg Donor/Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 116
Send a message via ICQ to AnAlienHolakres3
Hello guys, I got a little experience with social bookmarking sites and I think at least one more thing is good to implement into pligg - Experts. The Idea is simple - when user search for something (regardless it is or it is not tag searching), in the sidebar will appear users the most interested in specific area (which is defined by search term).

This tutorial can be considered as Unofficial module, if you implement it in your Pligg, there is no problem with upgrading to a newer version of Pligg. For developers it could be quite easy to make an official module (when Pligg 1.0 comes I suppose).

The result looks like this:

As you can see, the search term (in english "programming") has two Experts. The first one (me:P) has 6 links where is search term used, the second one has one link.

Requirements
- Pligg 9.X version,personally I have v9.7, implementation into 9.8 possible
- yget template (default,blue)
- Notepad++,PhpEd or PHPdesigner...whatever good for PHP work

File requirements:
Just this little size image for background:
http://vselink.org/downloads/expert_backg.png

This image is supposed to be in your templates/yget/images folder

Steps to do:
1.1 Open your sidebar.tpl file and add this code, I preffer to be first of sidebar modules but do what you want:

Code:
{if $result neq false}{if $search_term neq false}
{assign var=sidebar_module value="sidebar_experts"}{include file=$the_template_sidebar_modules."/wrapper.tpl"}
{/if}{/if}
1.2 Create new file in your ../templates/yget/sidebar_modules folder and name it sidebar_experts.tpl. Then add this piece of code:
Code:
{* ----- show the sidebar experts box ----- *}
    {php}include('sidebar_experts.php');{/php}
{* ---------------------------------------- *}
1.3 Create new file in your main/root folder and name it sidebar_experts.php
Add following code:
PHP Code:
<?php
//==========================================================================
//  SIDEBAR EXPERTS MODULE
// This module shows in sidebar 5 people who are the most interested in 
// specific area which is defined by a search term
//
//@created by AnAlienHolakres3 for Pligg community. Free for use,no warranty
//==========================================================================
 
include_once('Smarty.class.php');
$main_smarty = new Smarty;


include_once(
'config.php');
include_once(
mnminclude.'html1.php');
include_once(
mnminclude.'link.php');
include_once(
mnminclude.'tags.php');
include_once(
mnminclude.'search.php');
include_once(
mnminclude.'smartyvariables.php');
include_once(
mnminclude.'friend.php');
include_once(
mnminclude.'user.php');


 
$search_term trim($_REQUEST['search']);    
                     
  
//if $search_term exists, we want to show  experts in sidebar
if ($search_term!=null){
 
showExperts(); 
 }



// -------------------------------------------------------------------------------------
// function showExperts() search best users for specific search term:
// 1) names + count of users who have the most tags of searched term
// --------------------------------------------------------------------------------------
                                        
function showExperts() {
global 
$the_template$main_smarty$db ,$user;
 
$search_term trim($_REQUEST['search']); 
 
$limit_users 5// You can customize num of users displayed by changing $limit_users value     
                                                                  
     
     //display sidebar box        
    
echo "<div class=\"tlb\" style=\"margin-top:-15px\"><span><a onclick=\"new Effect.toggle('sideexperts','blind', {queue: 'end'}); \">  <img src=\""
    
.my_base_url."/templates/" $the_template "/images/expand.png\"  width=\"30\" height=\"29\"/></a></span><b>"
    
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_For')."<font color='#0000CC'>".$search_term."</font></b></a></div>
    <div id=sideexperts>"
;
    
                                                   
     
     
//get the best people   
     
$bp $db->get_results ("SELECT distinct(user_login) AS 'user_name', count(user_login) AS 'tag_count' FROM "table_users " INNER JOIN "table_links 
     
" ON " table_users ".user_id = " table_links ".link_author INNER JOIN "table_tags ." ON  ".table_links ".link_id = "table_tags.
     
".tag_link_id WHERE tag_words LIKE '".$search_term"' GROUP BY user_login ORDER BY tag_count DESC");
     
     
        
//display table header 
                
echo "<table border='0' style='border: 1px solid #3333FF;width:235px;margin-top:12px;margin-bottom:14px;padding-bottom:3px;
                background: url("
.my_pligg_base."/templates/".$the_template."/images/expert_backg.png) repeat-y'><td style='text-align=center'><b>" 
                  
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_Username')."</b></td><td align='center'><b>"
                  
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_Num_Of_Links')."</b></td>";
     
            
//get expert names and num of tags
             
foreach($bp as $best_person) {
                 
$best_person_name $best_person->user_name;
                 
$best_person_count $best_person->tag_count;
                  
                 
                 echo 
"<tr>";
                 echo 
'<td><a href="'.getmyurl('user2'$best_person_name'profile'). '">'.$best_person_name'</a></td>';     
                 echo 
"<td style='text-align:center'><span style='background: #D9E0FF; border: 1px solid #0000CC;padding-right:5px;padding-left:5px'>" .$best_person_count"</span></td>";    
                
                 
       
             }
       
              
//table end
               
               
echo "</tr></table><div id='iefix' style='display:none;height:0px'></div></div>";
     
               
//IE fix
               
echo "<!--[if lt IE 8]>
                       
               <style type='text/css' media='screen'>
               #iefix {display:block !important}     
               </style>
               <![endif]--> "



 }

 
?>
1.4 Open your lang.conf file in your libs folder and add somewhere following code. Dont forget customize it into your language.
Code:
4) add to lang.conf in your ../libs/ folder to sidebar section:
//<SECTION>SIDEBAR</SECTION><ADDED>0.9X</ADDED>
PLIGG_Visual_Experts_For= "Experti na "
//<SECTION>SIDEBAR</SECTION><ADDED>0.9X</ADDED>
PLIGG_Visual_Experts_Username= "Uživatelské jméno"
//<SECTION>SIDEBAR</SECTION><ADDED>0.9X</ADDED>
PLIGG_Visual_Experts_Num_Of_Links= "Počet záložek"
1.5 And the final thing, open search.php in your libs folder and do following:
1.5.1: Find function new_search and add global variable $main_smarty.
1.5.2: Find if ($links) { condition. Please note there is 2x and you have to add 2 times this code :
$main_smarty->assign('result',1);
So it should be like this:
Code:
if ($links) {
            $main_smarty->assign('result',1);
            foreach($links as $link_id) {
                if(array_search($link_id->link_id, $foundlinks) === false){
Thats it. Now you can enjoy this new enhancement
Reply With Quote
  #2 (permalink)  
Old 10-18-2007, 02:53 AM
AnAlienHolakres3's Avatar
Pligg Donor/Coder
 
Join Date: Jul 2007
Location: Prague
Posts: 116
Send a message via ICQ to AnAlienHolakres3
FIXED: if tag contains two or more words and if user search only for one of this word it results in error

UPDATE: if is tag too long,it is shortened.

1)open search.php in libs folder,find
// set smarty variables
if(isset($this->searchTerm)){

and after that add this code:
PHP Code:
//expert fix - if no tags no expert sidebar 
            
            
$tag_exist $db->get_var("SELECT tag_words FROM "table_tags ." WHERE tag_words LIKE '".$this->searchTerm."'");                       
            
$main_smarty->assign('tagresult',$tag_exist);
               
//expert fix 
2) open sidebar.tpl and modify original code:
Code:
{if $result neq false}{if $search_term neq false}
{assign var=sidebar_module value="sidebar_experts"}{include file=$the_template_sidebar_modules."/wrapper.tpl"}
{/if}{/if}
to :
Code:
{if $result neq false}{if $search_term neq false}{if $tagresult neq false}
{assign var=sidebar_module value="sidebar_experts"}{include file=$the_template_sidebar_modules."/wrapper.tpl"}
{/if}{/if}{/if}
.


3) Replace ALL code in sidebar_experts.php with:
PHP Code:
<?php
//==========================================================================
//  SIDEBAR EXPERTS MODULE v 1.2
// This module shows in sidebar 5 people who are the most interested in 
// specific area which is defined by a search term
//
//@created by AnAlienHolakres3 for Pligg community. Free for use,no warranty
//==========================================================================
 
include_once('Smarty.class.php');
$main_smarty = new Smarty;


include_once(
'config.php');
include_once(
mnminclude.'html1.php');
include_once(
mnminclude.'link.php');
include_once(
mnminclude.'tags.php');
include_once(
mnminclude.'search.php');
include_once(
mnminclude.'smartyvariables.php');
include_once(
mnminclude.'friend.php');
include_once(
mnminclude.'user.php');


 
$search_term trim($_REQUEST['search']);    
 
global 
$db;  
  
if (
$search_term!=null){
 
showExperts(); 
 }



// -------------------------------------------------------------------------------------
// function showExperts() search best users for specific search term:
// 1) names + count of users who have the most tags of searched term
// --------------------------------------------------------------------------------------
                                        
function showExperts() {
global 
$the_template$main_smarty$db ,$user;

  


 
$search_term trim($_REQUEST['search']); 
 
      
//get the best people   
     
$bp $db->get_results ("SELECT distinct(user_login) AS 'user_name', count(user_login) AS 'tag_count' FROM "table_users " INNER JOIN "table_links 
     
" ON " table_users ".user_id = " table_links ".link_author INNER JOIN "table_tags ." ON  ".table_links ".link_id = "table_tags.
     
".tag_link_id WHERE tag_words LIKE '".$search_term"' GROUP BY user_login ORDER BY tag_count DESC");
     
     
 

  if (
strlen($search_term) > 15) {
       
$search_termutf8_substr($search_term,0,15)."..";
       }

 
 
$limit_users 5// You can customize num of users displayed by changing $limit_users value     
                                                                  
     
     //display sidebar box        
    
echo "<div class=\"tlb\" style=\"margin-top:-15px\"><span><a onclick=\"new Effect.toggle('sideexperts','blind', {queue: 'end'}); \">  <img src=\""
    
.my_base_url."/templates/" $the_template "/images/expand.png\"  width=\"30\" height=\"29\"/></a></span><b>"
    
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_For')."<font color='#0000CC'>".$search_term."</font></b></a></div>
    <div id=sideexperts>"
;
    
                                                   
   
   
        
//display table header 
                
echo "<table border='0' style='border: 1px solid #3333FF;width:235px;margin-top:12px;margin-bottom:14px;padding-bottom:3px;
                background: url("
.my_pligg_base."/templates/".$the_template."/images/expert_backg.png) repeat-y'><td style='text-align=center'><b>" 
                  
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_Username')."</b></td><td align='center'><b>"
                  
.$main_smarty->get_config_vars('PLIGG_Visual_Experts_Num_Of_Links')."</b></td>";
     
            
//get expert names and num of tags
             
foreach($bp as $best_person) {
                 
$best_person_name $best_person->user_name;
                 
$best_person_count $best_person->tag_count;
                  
                 
                 echo 
"<tr>";
                 echo 
'<td><a href="'.getmyurl('user2'$best_person_name'profile'). '">'.$best_person_name'</a></td>';     
                 echo 
"<td style='text-align:center'><span style='background: #D9E0FF; border: 1px solid #0000CC;padding-right:5px;padding-left:5px'>" .$best_person_count"</span></td>";    
                
                 
       
             }
       
              
//table end
               
               
echo "</tr></table><div id='iefix' style='height:0px'></div></div>";
     
               
//IE fix
               
echo "<!--[if lt IE 8]>
                       
               <style type='text/css' media='screen'>
               #iefix {display:block !important}     
               </style>
               <![endif]--> "



 }

 
?>
Thats all
Reply With Quote
  #3 (permalink)  
Old 11-02-2007, 12:32 PM
New Pligger
Pligg Version: 0.98
Pligg Template: none
 
Join Date: Nov 2007
Posts: 7
Good module, great idea!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fixes to Profile Extra Fields Module v0.2 and Extended Profile Module v0.1 redwine Questions and Comments 8 01-04-2010 07:06 PM
Help needed with code insertion into sidebar module. jemaverick Questions and Comments 3 03-27-2008 01:27 PM
Google Translate v0.1 Sidebar Pligg Module pliggedit Questions and Comments 3 03-16-2008 02:57 AM
Sidebar Friends Module with messaging and activity AnAlienHolakres3 Questions and Comments 31 02-09-2008 06:54 AM
Adding a Sidebar Module to a Pligg Template kbeeveer46 Questions and Comments 1 04-05-2007 10:01 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development