·  News ·  Travel ·  Food ·  Arts ·  Science ·  Sports ·  Advice ·  Religion ·  Life ·  Greensboro · 

PHPBB 3.0 Similar Post / Topic Mod

by Liv | Published on April 3rd, 2009, 8:41 am | Advice
This Mod searches for similar or like post and topics based on the originating post title. In this latest release, I've attempted to make it work on various installs, but it is generally, just stored here for my use. Feel free to use or modify but please retain a link to this release page as a courtesy.

In Viewtopic.php find:

Code: Select all
// Replace naughty words in title
$topic_data['topic_title'] = censor_text($topic_data['topic_title']);


Below add:
Code: Select all
// SIMILAR TOPIC POST MOD FOR PHPBB 3 OLYMPUS
// COPYRIGHT, LIV JONES
// 8/10/1010

// Enable Forum Only Option
$forum_only="";
// $forum_only="AND t.forum_id = $forum_id";

// Private Forum Option
$priv_forum="AND p.forum_id <> 27 AND p.forum_id <> 28";

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

if ($topic_id &1) {$direction="DESC ";} else {$direction="";}

$sim_top=preg_replace("/[^A-Za-z ]/","",$topic_data['topic_title']);
$sim_top=strtolower($sim_top);
$sim_top_b=explode(" ",$sim_top);

$chkdups=array();

foreach ($sim_top_b as $bt) {

   $limit=2;   
   $bt2=preg_replace("!\\b\\w{1,4}\\b!", "", $bt);
   $bt=preg_replace("!\\b\\w{1,5}\\b!", "", $bt);
   if ($bt=="" && $bt2 !="") {$bt=$bt2; $limit=1;}
            else if ($bt=="") {continue;}


$sql = "SELECT * FROM ". POSTS_TABLE ." as p, ". TOPICS_TABLE ." as t WHERE p.topic_id <> $topic_id AND p.topic_id = t.topic_id ". $forum_only ." AND t.topic_first_post_id = p.post_id ". $priv_forum ." AND p.post_approved = 1 AND LOWER(p.post_subject) LIKE '%".$bt."%' ORDER BY p.topic_id ".$direction."LIMIT ".$limit;

          $result = $db->sql_query($sql);
         while ($data=mysql_fetch_array($result)) {

         if (in_array($data['topic_id'],$chkdups)) {continue;}
         array_push($chkdups, $data['topic_id']);

if ($count_links > 4) {continue;}
   else {$count_links=$count_links+1; }

$data['topic_title'] = censor_text($data['topic_title']);

$topic_top_o=$topic_top_o.'<li><a href="http://'.$_SERVER['HTTP_HOST'].'/viewtopic.'.$phpEx.'?f='.$data['forum_id'].'&t='.$data['topic_id'].'">'.$data['topic_title'].'</a>';
}
}

if ($topic_top_o != "") {   
$topic_top_o='<div style="float:left; width:600px; margin:10px;">
    <p><b>Similar Articles:</b>'.$topic_top_o.'</p><p><small><small><a href="http://greensboring.com/viewtopic.php?f=23&t=10174">PHPBB Similar Topic Mod</a></small></small></p></div>';
}
if ($_GET['start'] > 0) {$topic_top_o='';}

// END SIMILAR TOPIC POST MOD


find:

Code: Select all
'FORUM_ID'       => $forum_id,


add right after:

Code: Select all
'TOPIC_TOP' => $topic_top_o,


Open viewtopic template and add where necessary: (usually below postrow.message)

Code: Select all
<!-- IF postrow.S_FIRST_ROW -->
{TOPIC_TOP}
<!-- ENDIF -->
 
 
Yep -- stimulating conversation. :lol:
April 3rd, 2009, 9:00 am
User avatar
SouthernFriedInfidel
 
Location: 5th circle of hell -- actually not very crowded at the moment.
LOL ROFL!!!
April 3rd, 2009, 9:19 am
User avatar
Liv
I show you something fantastic and you find fault.
 
Location: Greensboro, NC
Psssttt! Liv!!!

Whatcha testin'?
When it is not in our power to follow what is true, we ought to follow what is most probable. –Rene Descartes

I may not have gone where I intended to go, but I think I have ended up where I needed to be. -Douglas Adams
April 3rd, 2009, 9:26 am
User avatar
Serendipitous
This is my world and I am the world leader...pretend.
 
Location: in the now
Abortion sucks!
All truth passes through three stages. First, it is ridiculed. Second,it is violently opposed. Third, it is accepted as being self-evident.

Ephesians 2:8-9 For by grace are ye saved through faith; and that not of yourselves: it is the gift of God: Not of works, lest any man should boast.
April 3rd, 2009, 8:39 pm
User avatar
BecauseHeLives
 
Only if vacuum aspiration is used.
All stupid ideas pass through three stages. First, it is ridiculed. Second, it is ridiculed. Third, it is ridiculed
April 3rd, 2009, 8:48 pm
User avatar
A Person
 
Location: Slightly west of the Great White North

Return to Advice