Go Back   Pligg CMS Forum > Pligg Development > Modification Tutorials

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-27-2008, 12:30 PM
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
Related links

Hello everyone. As you well know there are related links to each link on story page. In some cases (i.e. when title on published or upcoming page is used directly as a link to destination page) related links are not shown.

In that case we have two choices:
1) forget related links
2) implement related links to same area as Bury or Save button.



The idea is pretty simple, when user clicks on specific "Related links"(Související) button, related links are shown right below specific link.




Ways of implementation:
- Easy synchronous solution
- Asynchronous solution (using AJAX)

Necessary icons and files are as an attachment.

Comparation of these solutions:
- Easy synchronous solution is easy to implement and it works smoothly
- Asynchronous solution is far better for performance. Necessary data are loaded when user desires to do so,not in advance like when synchronous solution is used.
- Asynchronous solution keeps information updated, you do not have to refresh the whole page to reload related links info.
- Asynchronous solution is a little more difficult to implement

Easy synchronous solution implementation
We need to modify 2 files:
- link.php in libs folder
- link_summary.tpl in templates/template folder

Link.php:

find function fill_smarty() and at the end of these function add following code:
PHP Code:
         //=============================================
         // Related links in link     
      
        
$rel_stor=related_stories($this->id$this->tags$this->category);     
        
$smarty->assign('rs_exist',count($rel_stor));        
         
$smarty->assign('related_story',$rel_stor);       
        
//============================================= 
Link_summary.tpl
Find {if $link_shakebox_currentuser_reports eq 0 AND $user_logged_in neq ""} and after this section (which is ended by {/if}) add following code:
Code:
{if $rs_exist neq 0}
     &nbsp;<span>
     <img src="{$my_pligg_base}/templates/{$the_template}/images/similar.gif" 
style="width:16px;height:16px;margin-bottom:-3px" /> 
<a href="javascript://" 
onclick="new Effect.toggle('rel_links-{$link_shakebox_index}','blind', {queue: 'end'});">{#PLIGG_Visual_Story_RelatedStory#}</a></span>
     <div id="rel_links-{$link_shakebox_index}" 
     style="border:4px solid {if $pagename eq "upcoming"}#AEF1FF{else}#AED7FF{/if};padding-left:5px;margin-top:10px;background:white;display:none">              
    {section name=nr loop=$related_story}
      - <a href = "{$related_title_url}{$related_story[nr].link_title_url}">{$related_story[nr].link_title}</a><br/></li>
    {/section}                                                                
    </div>    
{/if}
Feel free to customize this code. Highlihted code should work with Prototype Javascript library but personally I use JQuery and in that case you would need edit this code also.

Find {if $Enable_Recommend eq 1} and before this section add following code:
Code:
            <span id="related_load-{$link_shakebox_index}" style="display:none">
            </span>
Asynchronous solution implementation (ajax)
We need to modify 3 files and create new 2 files:
- link.php in libs folder
- link_summary.tpl in templates/template folder
- xmlhttp in js folder
- create relatedlink_request.php in root folder (attachment)
- create related_link.tpl in /templates/template folder (attachment)

Link.php
Customization of this file is really short. Position of new added code is the same as in synchronous way of implementation, at the end of fill_smarty() function:
PHP Code:
        //=============================================
        // Related links in link ADDON
            
$smarty->assign('tags_str',$this->tags);       
        
//============================================= 

Link_Summary.tpl
Exactly the same position as in synchronous way of implementation. Code:
Code:
     &nbsp;<span>
     <img src="{$my_pligg_base}/templates/{$the_template}/images/similar.gif"  style="width:16px;height:16px;margin-bottom:-3px" />
      <a href="javascript://" onclick="relatedlink_request('related_load-{$link_shakebox_index}',{$link_id},'<br />{#PLIGG_Visual_Loading_Wait#}<img src=\'{$my_pligg_base}/templates/{$the_template}/images/load.gif\'  style=\'width:16px;height:16px\' />','{$tags_str}','{$pagename}')">{#PLIGG_Visual_Story_RelatedStory#}</a></span>
      <div id="rel_links-{$link_shakebox_index}" style="border:4px solid {if $pagename eq "upcoming"}#AEF1FF{else}#AED7FF{/if};padding-left:5px;margin-top:10px;background:white;display:none">
     </div>
Find {if $Enable_Recommend eq 1} and before this section add following code (yes, the same code and the same position as in sync. way):
Code:
            <span id="related_load-{$link_shakebox_index}" style="display:none">
            </span>
xmlhttp.php
We need do some javascript,add following 2 functions:
Code:
function EL(id){
 return document.getElementById(id);
}

function relatedlink_request(target_id,link_id,input_html,tags,pagename) 
{ 
    new Effect.toggle(target_id,'blind', {queue: 'end'})   
            
    if (EL(target_id).style.display=="") {
        EL(target_id).innerHTML = input_html;
          
    
        url = "/relatedlink_request.php";
        
    
            mycontent = "link_id=" + link_id + "&"+"tags="+tags+ "&"+"pagename="+pagename;                
        
         mnmxmlhttp = new myXMLHttpRequest ();
         
         if (mnmxmlhttp) {   
          mnmxmlhttp.open ("POST", url, true);
           mnmxmlhttp.setRequestHeader ('Content-Type', 'application/x-www-form-urlencoded');    
            mnmxmlhttp.send (mycontent);
                        
          }
        mnmxmlhttp.onreadystatechange = function () {
                    if (mnmxmlhttp.readyState == 4) {
                        response = mnmxmlhttp.responseText;
                        EL(target_id).style.display='none';
                        new Effect.toggle(target_id,'blind', {queue: 'end'});
                        EL(target_id).innerHTML= response;
                                                                            
                }
            
            }    
          }    
          
    
}
New file relatedlink_request.php is a php file which implements functions of html1.php which are necessary. This file displays smarty file related_link.tpl.
New file related_link.tpl is smarty file for related links. You should edit this file to change text if no related link is found.
Attached Images
  
Attached Files
File Type: tpl related_link.tpl (667 Bytes, 53 views)
File Type: php relatedlink_request.php (1.7 KB, 53 views)
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.cz
Reply With Quote
The Following 8 Users Say Thank You to AnAlienHolakres3 For This Useful Post:
  #2 (permalink)  
Old 05-27-2008, 04:08 PM
graphicsguru's Avatar
Pligg Donor
Pligg Version: 9.9.5
 
Join Date: Aug 2006
Location: USA
Posts: 416
Thanks: 75
Thanked 48 Times in 36 Posts
This is fantastic great mod thank you very much

not sure what to do yet
mine is not 100% its works great on all my old categories on old post
maybe the same on your site ?

i.e. if I go to your last page last story and click Související

I get 10 related stories

VĹ*Elink / SchválenĂ© záloĹľky

on your site when I click I see this not sure what it says
K této záložce neexistují žádné související linky

can you translate this to English K této záložce neexistují žádné související linky
Reply With Quote
  #3 (permalink)  
Old 05-27-2008, 05:06 PM
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
Quote:
Originally Posted by graphicsguru View Post
can you translate this to English K této záložce neexistují žádné související linky

Of course I must forgot to translate it in English - it means "For this link there are no related links"
__________________
=Everything that has a beginnig has an end=
=Nevere stop fighting=

Site: http://www.vselink.cz
Reply With Quote
  #4 (permalink)  
Old 05-27-2008, 06:10 PM
graphicsguru's Avatar
Pligg Donor
Pligg Version: 9.9.5
 
Join Date: Aug 2006
Location: USA
Posts: 416
Thanks: 75
Thanked 48 Times in 36 Posts
OK thank you my friend
Reply With Quote
  #5 (permalink)  
Old 05-28-2008, 11:01 AM
Banned
Pligg Version: 9.9.5
 
Join Date: Oct 2007
Location: Canada
Posts: 914
Thanks: 169
Thanked 17 Times in 17 Posts
wow this is amazing, PROPS to you for helping our free open source community!

I will try and install this tonight!
Reply With Quote
  #6 (permalink)  
Old 06-06-2008, 09:34 AM
New Pligger
Pligg Version: 9.9
Pligg Template: Custom
 
Join Date: Dec 2007
Posts: 21
Thanks: 4
Thanked 0 Times in 0 Posts
sweet to this work on version 9.9.0????? el try it anyways props for the contribution.
Reply With Quote
  #7 (permalink)  
Old 06-07-2008, 12:55 AM
davemackey's Avatar
Pligg Donor
Pligg Version: 9.9.
Pligg Template: siChunkBlue
 
Join Date: Aug 2007
Location: Langhorne, PA
Posts: 286
Thanks: 33
Thanked 18 Times in 14 Posts
Great mod. Looking forward to implementing. Thanks!
David.
Reply With Quote
  #8 (permalink)  
Old 06-07-2008, 05:14 AM
Casual Pligger
 
Join Date: Apr 2008
Posts: 49
Thanks: 2
Thanked 1 Time in 1 Post
Very great mod, thanks!
Reply With Quote
  #9 (permalink)  
Old 08-21-2008, 09:28 AM
New Pligger
 
Join Date: Apr 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Have you noticed the URLs for the related stories ?

I have something like this http://www.domain.com/story/title/bl...la-story-title when it should be http://www.domain.com/category/bla-bla-bla-story-title

This is a big problem, do you have a fix for it ?
Reply With Quote
  #10 (permalink)  
Old 08-24-2008, 01:29 AM
New Pligger
Pligg Version: 9.9.5
 
Join Date: Aug 2008
Location: India
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I get forums.pligg login page when I click related links.
I am using Asynchronous solution implementation (ajax) method
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
Related links in a frame clems365 General Help 0 07-01-2008 11:55 AM
Related Links - URL method 1 - Please help micxuy General Help 0 06-25-2008 05:38 PM
ShakeBox Related Links tommy818 General Help 2 05-14-2008 11:40 AM
Removing 'tags' and 'related links' Pligga General Help 2 11-04-2007 12:11 AM
Related Links mollyfud General Help 6 07-06-2007 07:42 PM


Search Engine Friendly URLs by vBSEO 3.2.0