Working smf.discussbot mod in joomla

Started by johnnydement, October 15, 2005, 11:06:40 PM

Previous topic - Next topic

johnnydement

I dunno if this has been already resloved, I tweaked a bit the discussbot with bridge to work with joomla, based in joomlahacks working version. I'ts working for me, hope works for you too.

mmm... can't uplñoad files... ok, copy-paste :D


<?php/*** @Add forum link to content mosbot* @package Mambo Open Source* @Copyright (C) 2000 - 2003 Miro International Pty Ltd* @ All rights reserved* @ Mambo Open Source is Free Software* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html* @version $Revision: 3.02 $* @Inspired by the SimpleBoard mosbot by Jick - [email protected]* @AdaptedBy TSMF - http://tsmf.jigsnet.com* @Adapted for SMF by Theodore Hildebrandt**///This version is for joomla 1.0.2! - Original work,Jan de Graaff, moded by Johnny Dement, based in www.mambohacks.com discussbot//releasedefined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );$_MAMBOTS->registerFunction( 'onPrepareContent', 'MOSBOT_add_smfforumlink' );  global $database,$mosConfig_absolute_path,$mosConfig_live_site, $smf_path, $discuss_image, $default_discuss, $num_chars, $quote_images, $begin_end, $title_prefix, $link_text, $link_back_text;  global $show_topic, $quick_reply, $context, $txt, $options, $myurl, $scripturl,$context, $sc, $showlink, $db_name,  $db_prefix, $db_name, $mosConfig_db, $mosConfig_dbprefix;  require($mosConfig_absolute_path."/administrator/components/com_smf/config.smf.php");mysql_select_db($mosConfig_db);$result = mysql_query ("SELECT id FROM ".$mosConfig_dbprefix."menu WHERE link='index.php?option=com_smf'");if (isset($result)){$smfurl = mysql_fetch_array($result);}$myurl = $mosConfig_live_site ."/". basename($_SERVER['PHP_SELF'])."?option=com_smf&Itemid=" . $smfurl[0]."&";$scripturl = $myurl;  require_once($mosConfig_absolute_path."/administrator/components/com_smf/config.smf.php");$database->setQuery ("SELECT params FROM #__mambots WHERE element='smf.discussbot' AND folder = 'content'");$paramlist = $database->loadResult();$paramsmain = mosParseParams($paramlist);  $num_chars = $paramsmain->num_chars;  $discuss_image = $paramsmain->discuss_image;  $quote_images = $paramsmain->quote_images;  $begin_end = $paramsmain->begin_end;  $link_text = $paramsmain->link_text;  $default_discuss = $paramsmain->default_discuss;  $title_prefix = $paramsmain->title_prefix;  $show_topic = $paramsmain->show_topic;  $quick_reply = $paramsmain->quick_reply;  $db_name = $paramsmain->db_name;  $db_prefix = $paramsmain->db_prefix;  $link_back_text = $paramsmain->link_back_text;if ( (!strpos($row->text,"{mos_smf_discuss:") && $default_discuss == "")) {   // No - just leave   return;} else {   function MOSBOT_add_smfforumlink( &$published, &$row ) {     global $database, $mainframe, $my, $default_discuss, $scripturl, $myurl, $db_prefix, $db_name;     if (empty($_REQUEST['id']) || $_REQUEST['id']==$row->id){    if (!strpos($row->text,"{mos_smf_discuss:")){      mysql_select_db($db_name);      $title = str_replace("'","`",$row->title);      $title = $title_prefix . $title;      $database->setQuery("SELECT ID_BOARD FROM {$db_prefix}messages WHERE subject = '".$title."' LIMIT 1;");         $board_num = $database->loadResult(); $database->setQuery("SELECT name FROM {$db_prefix}boards WHERE ID_BOARD = '".$board_num."';"); $board = $database->loadResult();       $add_bot = $row->text."{mos_smf_discuss:".(!empty($board) ? $board : $default_discuss)."}";         $row->text = $add_bot;        } }      $mos_smf_discuss_entrytext = $row->text;      $mos_smf_discuss_matches = array();      if (preg_match_all("/{mos_smf_discuss:.+?}/", $mos_smf_discuss_entrytext, $mos_smf_discuss_matches, PREG_PATTERN_ORDER) > 0) { foreach ($mos_smf_discuss_matches[0] as $mos_smf_discuss_match) {            $showbottext = "";            $mos_smf_discuss_match = str_replace("{mos_smf_discuss:", "", $mos_smf_discuss_match);            $mos_smf_discuss_match = str_replace("}", "", $mos_smf_discuss_match);            if ($mos_smf_discuss_match == "no_discuss"){            $showbottext = "";            } else {                $showbottext = make_smfforumlink( $mos_smf_discuss_match, $row);            }            $mos_smf_discuss_entrytext = str_replace("{mos_smf_discuss:".$mos_smf_discuss_match."}", $showbottext, $mos_smf_discuss_entrytext);         }         $row->text = $mos_smf_discuss_entrytext; mysql_select_db($mosConfig_db);      }   }   }   function make_smfforumlink($catid, &$row){      global $database, $mainframe, $my, $mosConfig_absolute_path, $discuss_image, $num_chars, $quote_images, $begin_end, $title_prefix, $link_text, $cat_id, $link_back_text;         global $showlink, $sc, $scripturl, $myurl, $context, $smf_path, $settings, $txt, $context, $options, $db_name, $db_prefix, $mosConfig_db, $mosConfig_dbprefix,$mosConfig_live_site,$themedir, $show_topic, $quick_reply;mysql_select_db($mosConfig_db);   $query = "select id from {$mosConfig_dbprefix}menu where link='index.php?option=com_smf'";   $array = mysql_query ($query);   $Itemid=$array[0];mysql_select_db($db_name);   // Check if the subject as content title exists in the messages table $title = str_replace("'","`",$row->title); $title = $title_prefix . $title;    $database->setQuery("SELECT ID_BOARD FROM {$db_prefix}boards WHERE name='".$catid."';");    $boardid=$database->loadResult();   $database->setQuery("SELECT ID_TOPIC"      . "\nFROM {$db_prefix}messages"      . "\nWHERE ID_BOARD = '".$boardid."' AND subject = '".$title."';");      $resultid = $database->loadResult();   $showlink = "";   // Is there already a topic for this?  If not, make a new topic    if ($resultid == ""){    $message = '[quote]'.substr($row->text,0,$num_chars).'. . .'.'[/quote]';           $message = "[url=http://".$mosConfig_live_site."/index.php?option=com_content&task=view&id=".$row->id."&Itemid=".$row->sectionid."]".$link_back_text."[/url]".$message;        $search =  array(                     "/\</",                     "/\>/", "/\\\"/", "/\[p([^\]]*)\]{1}/", "/\[\/p\]/", "/\[font([^\]]*)\]{1}/", "/\[\/font\]/", "/\[img.*src\=http/", "/\[img.*src\=/", "/jpg([^\]http://]*)\]{1}/", "/gif([^\]]*)\]{1}/", "/png([^\]]*)\]{1}/", "/jpeg([^\]]*)\]{1}/", "/\[a.+?(href=\"?http){1}/", "/\[a.+?(href=\"?){1}/", "/target\=([^\]]*)\]{1}/", "/\[\/a\]/", "/\[table([^\]]*)\]{1}/", "/\[tbody\]/", "/\[\/tbody\]/", "/\[td([^\]]*)\]{1}/", "/\[strike\]/", "/\[em\]/", "/\[strong\]/", "/\[ol\]/", "/\[ul\]/", "/\[\/em\]/", "/\[\/strong\]/", "/{mos_smf_discuss:.+?}/"                            );      $replace = array(                     "[", "]", "", "[br][br]", "", "", "", ($quote_images=="1" ? "[img]http" : ""), ($quote_images=="1" ? "[img]".$mosConfig_live_site."/" : ""), ($quote_images=="1" ? "jpg[/img]" : ""), ($quote_images=="1" ? "gif[/img]" : ""), ($quote_images=="1" ? "png[/img]" : ""), ($quote_images=="1" ? "jpeg[/img]" : ""), "[url=http://http", "[url=".$mosConfig_live_site."/", "]", "[/url]", "[table][tr][td]", "", "", "[table][tr][td]", "[s]", "[i]", "[b]", "[list]", "[list]", "[/i]", "[/b]", "" );                               $message = preg_replace($search, $replace,$message); //--modified by Nicao [email protected]        print '<form id='.$row->id.' action="'.$myurl.'" method ="post">';           print '<input type=hidden name="board" value="'.$boardid.'">';    print '<input type=hidden name="icon" value="xx">';           print '<input type=hidden name="action" value="post2">';           print '<input type=hidden name="subject" value="'.$title.'">';           print '<input type=hidden name="message" value="'.$message.'">';           print '<input type=hidden name="option" value="com_smf">';           print '<input type=hidden name="goback" value="true">';          print '<input type="hidden" name="sc" value="' . $GLOBALS['sc'] . '" />';           print '</form>';    $showlink = '<a class="link_pos" href="javascript:send_form('.$row->id.')"><img border="0" src="'.$discuss_image.'"> (0) '.$link_text.'</a>'; } //old form button: .'<input type=submit class="sub_bttn" value="">'   // There must already be a topic, so let's make a link to reply else{     $showlink = "";     //Do we want to show the topic under the article?     if ($show_topic=="1" && $_REQUEST['option']=='com_content'){           $post_query=mysql_query("SELECT posterName, subject, body FROM {$db_prefix}messages WHERE ID_TOPIC = '$resultid';");    if (mysql_num_rows($post_query)>0){      while ($posts = mysql_fetch_assoc($post_query)){    $showlink .="<table><tr><td class=\"contentheading\">".$posts['posterName']."</td></tr>";    $showlink .="<td><strong>".$posts['subject']."</strong></td></tr>";    $showlink .="<td>".$posts['body']."</td></table>"; }           }        }      $database->setQuery("SELECT numReplies"         . "\nFROM {$db_prefix}topics"             . "\nWHERE ID_TOPIC = '".$resultid."';");         $replies = $database->loadResult();    $replies++;        //Do we want a quick reply box? //Check instructions for using Quick Reply :)        if ($quick_reply == "1" && $_REQUEST['option']=='com_content'){            $showlink.= '<table><tr><td class="windowbg" width="75%" align="center">              <form id='.$row->id.' action="'.$scripturl.'action=post2" method="post" name="postmodify" onsubmit="submitonce(this);">              <input type="hidden" name="topic" value="' . $resultid . '" /> <input type="hidden" name="board" value="'.$boardid.'" />              <input type="hidden" name="subject" value="' . $title . '" /> <!-- <input type="hidden" name="action" value="post2" /> -->              <input type="hidden" name="icon" value="xx" /> <input type="hidden" name="goback" value="true" />              <input type="hidden" name="num_replies" value="'. $replies. '" />              <textarea cols="75" rows="7" style="width: 400px; height: 100px;" name="message" tabindex="1"></textarea><br />              <input type="submit" name="post" value="Reply" onclick="return submitThisOnce(this);" accesskey="s" tabindex="2" />                      <input type="hidden" name="sc" value="' . $GLOBALS['sc'] . '" /></form></td></tr></table>'; }  else { //Let's just show the link to the topic instead    if ($begin_end==1){$smf_location = "0";} else {$smf_location="new";}    $showlink .= '<a class="link_pos" href="'.$myurl . 'topic=' . $resultid . '.' . $smf_location . '"><img border="0" src="'.$discuss_image.'"> ('.$replies.') '.$link_text.'</a>';    //uncomment following line for default action of "reply"    //$showlink = '<a class="link_pos" href="'.$scripturl . '?option=com_smf&Itemid='.$Itemid.'&?action=view;topic=' . $resultid . '.0"><img border="0" src="'.$smf_path.'/Themes/default/images/topic/my_veryhot_post.gif"> ('.$replies.') Comments</a>';           } //modified by Nicao--   }   mysql_select_db($mosConfig_db);   return $showlink;   }?>
<script language="JavaScript">
var smf_formSubmitted;
function submitonce(theform)
{
smf_formSubmitted = true;
}

function send_form(form_id)
{
document.getElementById(form_id).submit();
}

function submitThisOnce(item)
{
// Hateful, hateful fix for Safari 1.3 beta.
if (navigator.userAgent.indexOf('AppleWebKit') != -1)
return !smf_formSubmitted;

for (var i = 0; i < item.form.length; i++)
if (typeof(item.form[i]) != "undefined" && item.form[i].tagName.toLowerCase() == "textarea")
item.form[i].readOnly = true;

return !smf_formSubmitted;
}
</script>

<style> hr{ margin-top: 5px; clear: both; } .link_pos{ float: right; } .sub_bttn{ padding-left: 0px; padding-right: 0px; padding-bottom: 0px; padding-top: 0px; border-width: 0px; width: 120px; height: 18px; float: right; background-image: url(../../images/discuss.gif); background-color: #000000; } </style>
<?php    mysql_select_db($mosConfig_db); ?>


lol, some parts looks strange :P but is best I can do as I can't attach

Kindred

send it to me:  kindred at turtleshellprod dot com

I will attach it to the message. 


BTW:  Use the CODE tags, not the QUOTE tags....


THANKS!
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Orstio

Good work.   :)

This bot sure has been around.   :D

johnnydement

Ok, sorry for using quote, this sure mends the mistakes :D

Already sent kindred, hope it works!

Anyway, not much done here by me, all credit should go to cowboy from mambohacks, I just applied his fix to the bridge module :)

chadness


maxdg

#5
Quote from: johnnydement on October 16, 2005, 08:25:34 PM
hope it works!

Works fine!
Thanks a lot!!!!
8)

EDIT: except for this little bug:
When you decide tu put a link in the new created topic, to return to the original article, it adds a strange: http://http//www.*
I've found on line 120 of smf.discussbot.php this line:
           $message = "[url=http://".$mosConfig_live_site."/index.php?option=com_content&task=view&id=".$row->id."&Itemid=".$row->sectionid."]".$link_back_text."[/url]".$message;
And changed with this:
           $message = "[url=".$mosConfig_live_site."/index.php?option=com_content&task=view&id=".$row->id."&Itemid=".$row->sectionid."]".$link_back_text."[/url]".$message;

For make it works.

Joomla! 1.0.3 with SMF 1.1 RC1

chadness

maxdg, was that with SEF?  I remember seeing something like that.

I have integrated a fix for this (and a few other little ones I really should have documented better) in to the versions of the Joomla SMF discussbot I have posted here:
http://www.technoadvice.com/component/option,com_docman/task,cat_view/gid,23/Itemid,53/

There's an SEF version that could use some testing.

sastrugi

Quote from: chadness on November 03, 2005, 11:33:33 PM
I have integrated a fix for this (and a few other little ones I really should have documented better) in to the versions of the Joomla SMF discussbot [nofollow] I have posted here:
http://www.technoadvice.com/component/option,com_docman/task,cat_view/gid,23/Itemid,53/ [nofollow]

There's an SEF version that could use some testing.

I must just like beating my head off a brick wall  ;)

I've just tried your new version in my set-up and its still broken for me.

Can this be a php-version thing, my server is on 4.4.0

I realise I'm probably clutching at straws and flogging a dead horse as well but I'm so frustrated as to why the Joomlahack's version [bridge and discussbot] works like a charm and Orstio's bridge works but the discussbot variants just don't want to know on my set-up? Am I taking this [too] personally?  ;)

chadness

That's so strange.  The SEF stuff I took for the newest beta version is from the joomlahacks version.  Not sure why that wouldn't work.  If the Joomlahacks version of the bridge works for you, though, you could probably stick with that.

Advertisement: