Page 1 of 1

PHPBB 3.0 Similar Post / Topic Mod

PostPosted: April 3rd, 2009, 8:41 am
by Liv
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 -->

Re: test

PostPosted: April 3rd, 2009, 9:00 am
by SouthernFriedInfidel
Yep -- stimulating conversation. :lol:

Re: test

PostPosted: April 3rd, 2009, 9:19 am
by Liv
LOL ROFL!!!

Re: test

PostPosted: April 3rd, 2009, 9:26 am
by Serendipitous
Psssttt! Liv!!!

Whatcha testin'?

Re: test

PostPosted: April 3rd, 2009, 8:39 pm
by BecauseHeLives
Abortion sucks!

Re: test

PostPosted: April 3rd, 2009, 8:48 pm
by A Person
Only if vacuum aspiration is used.