alhatali
05-28-2001, 02:07 AM
I wrote before a question on how to disable line breaks in posts. However, I didn't get a working answer for it. You can look at the discussion through the following thread:
http://www.vbulletin.com/forum/showthread.php?s=&threadid=16605
So, I decided to do some hacking, though I don't know anything about PHP. Luckily, I was able to get it working correctly. I admit that what I did could be not the right way to do it. This is why I ask everyone to give comments about it and enhance it, if they wish. You will not be able to add this feature unless you enabled HTML in your forums.
The solution:
[list=1]
Adding a new column to the POST table:
Since, I don't know how to add a column to a table, I decided to stick the following statement somewhere in any of the PHP files that get executed frequently such as index.php or global.php. You can remove the line once you know it got executed for at least one time. If you know some other way to do it, then don't add the following line.
$DB_site->query("ALTER TABLE post ADD preformatted SMALLINT DEFAULT '0' not null");
In editpost, newreply, and newthread templates, add the code in red in the the following lines:
<tr>
<td bgcolor="#F1F1F1" valign="top"><normalfont><b>Options:</b></normalfont></td>
<td bgcolor="#F1F1F1" valign="top"><smallfont>
<input type="checkbox" name="preformatted" value="yes" $preformattedchecked> <b>Pre-Formatted Post:</b> (Don't add any extra formatting code).<br>
<input type="checkbox" name="parseurl" value="yes" $parseurlchecked> <b>Automatically parse URLs:</b> automatically adds and around internet addresses.
In admin/functions.php, add the code in red in the the following lines:
function bbcodeparse2($bbcode,$dohtml,$dobbimagecode,$dosmi lies,$dobbcode)
{ // parses text for vB code, smilies and censoring
global $DB_site,$wordwrap, $bbuserinfo,$preformatted;
static $smilies,$bbcodes;
global $regexcreated,$searcharray,$replacearray,$phpversi onnum;
if($wordwrap!=0) {
$bbcode=dowordwrap($bbcode);
}
if(!$dohtml) { // kill any rogue html code
// $bbcode=str_replace("&","&",$bbcode);
$bbcode=str_replace("<","&lt;",$bbcode);
$bbcode=str_replace(">","&gt;",$bbcode);
$bbcode=str_replace("<","<",$bbcode);
$bbcode=str_replace(">",">",$bbcode);
}
if (!$preformatted) { // if message is preformatted using HTML, do nothing. Otherwise, change newlines to <br>
$bbcode=nl2br($bbcode);
}
//smilies
if($dosmilies) {
$bbcode=str_replace(">)", "> )", $bbcode);
$bbcode=str_replace("<)", "< )", $bbcode);
if(!isset($smilies)) {
$smilies=$DB_site->query("SELECT smilietext,smiliepath FROM smilie");
} else {
$DB_site->data_seek(0,$smilies);
}
while ($smilie=$DB_site->fetch_array($smilies)) {
if(trim($smilie[smilietext])!="") {
$bbcode=str_replace(trim($smilie[smilietext]),"<img src=\"$smilie[smiliepath]\" border=\"0\" alt=\"$smilie[smilietext]\">",$bbcode);
}
}
}
In editpost.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
$parseurlchecked="CHECKED";
$preformattedchecked=iif($postinfo[preformatted],"CHECKED","");
$disablesmilieschecked=iif($postinfo[allowsmilie],"","CHECKED");
$signaturechecked=iif($postinfo[showsignature],"CHECKED","");
========
// ############################### start update post ###############################
if ($action=="updatepost") {
// check for message
if ($message=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif($parseurl=="yes",1,0);
$email=iif($email=="yes",1,0);
$allowsmilie=iif($disablesmilies=="yes",0,1);
$signature=iif($signature=="yes",1,0);
=======
$DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid'$editedbysql$attachmentsql WHERE postid='$postid'");
In newreply.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
// ############################### start post reply ###############################
if ($action=="postreply") {
// check for subject and message
if ($message=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif(trim($parseurl)=="yes",1,0);
$email=iif(trim($email)=="yes",1,0);
$allowsmilie=iif(trim($disablesmilies)=="yes",0,1);
$signature=iif(trim($signature)=="yes",1,0);
$preview=iif(trim($preview)!="",1,0);
============
eval("\$postpreview=\"".gettemplate("newpost_postpreview")."\";");
$preformattedchecked=iif($preformatted,"checked","");
$parseurlchecked=iif($parseurl,"checked","");
$emailchecked=iif($email,"checked","");
$disablesmilieschecked=iif(!$allowsmilie,"checked","");
$signaturechecked=iif($signature,"checked","");
$previewchecked=0;
$title = htmlspecialchars($title);
====================
$DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$postid'");
================
$DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,at tachmentid,pagetext,preformatted[/color],allowsmilie,showsignature,ipaddress,iconid,visibl e) VALUES (NULL,'$threadid','".addslashes(htmlspecialchars($title))."','".addslashes(htmlspecialchars($postusername))."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ip address','$iconid','$visible')");
===================
$posts=$DB_site->query("
SELECT IF(post.userid=0,post.username,user.username) AS username,
post.pagetext,post.preformatted,post.allowsmilie FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.visible=1 AND post.threadid='$threadid' $ignoreusers
ORDER BY dateline DESC");
if (($bbuserinfo[maxposts] != -1) and ($bbuserinfo[maxposts] != 0)) {
$maxposts = $bbuserinfo[maxposts];
}
while ($post=$DB_site->fetch_array($posts)) {
if ($postcounter++ < $maxposts) {
if ($postcounter%2 == 0) {
$backcolor = "#F1F1F1";
} else {
$backcolor = "#DFDFDF";
}
$preformatted=$post[preformatted];
$username=$post[username];
In newthread.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
// ############################### start post thread ###############################
if ($action=="postthread") {
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif(trim($parseurl)=="yes",1,0);
$email=iif(trim($email)=="yes",1,0);
$allowsmilie=iif(trim($disablesmilies)=="yes",0,1);
$signature=iif(trim($signature)=="yes",1,0);
$preview=iif(trim($preview)!="",1,0);
$postpoll=iif(trim($postpoll)=="yes",1,0);
==============
eval("\$postpreview=\"".gettemplate("newpost_postpreview")."\";");
$preformattedchecked=iif($preformatted,"checked","");
$parseurlchecked=iif($parseurl,"checked","");
$emailchecked=iif($email,"checked","");
$disablesmilieschecked=iif(!$allowsmilie,"checked","");
$signaturechecked=iif($signature,"checked","");
$previewchecked=0;
================
$DB_site->query("UPDATE post SET pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$posts[minpost]'");
===============
// create first post
$DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,at tachmentid,pagetext,preformatted,allowsmilie,shows ignature,ipaddress,iconid,visible) VALUES (NULL,'$threadid','','".addslashes($postusername)."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ip address','$iconid','1')");
In showthread.php, add the code in red in the the following lines:
$preformatted = $post[preformatted];
$post[message]=bbcodeparse($post[pagetext],$forum[forumid],$post[allowsmilie]);
//highlight words for search engine
[/list=1]
http://www.vbulletin.com/forum/showthread.php?s=&threadid=16605
So, I decided to do some hacking, though I don't know anything about PHP. Luckily, I was able to get it working correctly. I admit that what I did could be not the right way to do it. This is why I ask everyone to give comments about it and enhance it, if they wish. You will not be able to add this feature unless you enabled HTML in your forums.
The solution:
[list=1]
Adding a new column to the POST table:
Since, I don't know how to add a column to a table, I decided to stick the following statement somewhere in any of the PHP files that get executed frequently such as index.php or global.php. You can remove the line once you know it got executed for at least one time. If you know some other way to do it, then don't add the following line.
$DB_site->query("ALTER TABLE post ADD preformatted SMALLINT DEFAULT '0' not null");
In editpost, newreply, and newthread templates, add the code in red in the the following lines:
<tr>
<td bgcolor="#F1F1F1" valign="top"><normalfont><b>Options:</b></normalfont></td>
<td bgcolor="#F1F1F1" valign="top"><smallfont>
<input type="checkbox" name="preformatted" value="yes" $preformattedchecked> <b>Pre-Formatted Post:</b> (Don't add any extra formatting code).<br>
<input type="checkbox" name="parseurl" value="yes" $parseurlchecked> <b>Automatically parse URLs:</b> automatically adds and around internet addresses.
In admin/functions.php, add the code in red in the the following lines:
function bbcodeparse2($bbcode,$dohtml,$dobbimagecode,$dosmi lies,$dobbcode)
{ // parses text for vB code, smilies and censoring
global $DB_site,$wordwrap, $bbuserinfo,$preformatted;
static $smilies,$bbcodes;
global $regexcreated,$searcharray,$replacearray,$phpversi onnum;
if($wordwrap!=0) {
$bbcode=dowordwrap($bbcode);
}
if(!$dohtml) { // kill any rogue html code
// $bbcode=str_replace("&","&",$bbcode);
$bbcode=str_replace("<","&lt;",$bbcode);
$bbcode=str_replace(">","&gt;",$bbcode);
$bbcode=str_replace("<","<",$bbcode);
$bbcode=str_replace(">",">",$bbcode);
}
if (!$preformatted) { // if message is preformatted using HTML, do nothing. Otherwise, change newlines to <br>
$bbcode=nl2br($bbcode);
}
//smilies
if($dosmilies) {
$bbcode=str_replace(">)", "> )", $bbcode);
$bbcode=str_replace("<)", "< )", $bbcode);
if(!isset($smilies)) {
$smilies=$DB_site->query("SELECT smilietext,smiliepath FROM smilie");
} else {
$DB_site->data_seek(0,$smilies);
}
while ($smilie=$DB_site->fetch_array($smilies)) {
if(trim($smilie[smilietext])!="") {
$bbcode=str_replace(trim($smilie[smilietext]),"<img src=\"$smilie[smiliepath]\" border=\"0\" alt=\"$smilie[smilietext]\">",$bbcode);
}
}
}
In editpost.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
$parseurlchecked="CHECKED";
$preformattedchecked=iif($postinfo[preformatted],"CHECKED","");
$disablesmilieschecked=iif($postinfo[allowsmilie],"","CHECKED");
$signaturechecked=iif($postinfo[showsignature],"CHECKED","");
========
// ############################### start update post ###############################
if ($action=="updatepost") {
// check for message
if ($message=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif($parseurl=="yes",1,0);
$email=iif($email=="yes",1,0);
$allowsmilie=iif($disablesmilies=="yes",0,1);
$signature=iif($signature=="yes",1,0);
=======
$DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid'$editedbysql$attachmentsql WHERE postid='$postid'");
In newreply.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
// ############################### start post reply ###############################
if ($action=="postreply") {
// check for subject and message
if ($message=="") {
eval("standarderror(\"".gettemplate("error_nosubject")."\");");
exit;
}
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif(trim($parseurl)=="yes",1,0);
$email=iif(trim($email)=="yes",1,0);
$allowsmilie=iif(trim($disablesmilies)=="yes",0,1);
$signature=iif(trim($signature)=="yes",1,0);
$preview=iif(trim($preview)!="",1,0);
============
eval("\$postpreview=\"".gettemplate("newpost_postpreview")."\";");
$preformattedchecked=iif($preformatted,"checked","");
$parseurlchecked=iif($parseurl,"checked","");
$emailchecked=iif($email,"checked","");
$disablesmilieschecked=iif(!$allowsmilie,"checked","");
$signaturechecked=iif($signature,"checked","");
$previewchecked=0;
$title = htmlspecialchars($title);
====================
$DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$postid'");
================
$DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,at tachmentid,pagetext,preformatted[/color],allowsmilie,showsignature,ipaddress,iconid,visibl e) VALUES (NULL,'$threadid','".addslashes(htmlspecialchars($title))."','".addslashes(htmlspecialchars($postusername))."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ip address','$iconid','$visible')");
===================
$posts=$DB_site->query("
SELECT IF(post.userid=0,post.username,user.username) AS username,
post.pagetext,post.preformatted,post.allowsmilie FROM post
LEFT JOIN user ON user.userid=post.userid
WHERE post.visible=1 AND post.threadid='$threadid' $ignoreusers
ORDER BY dateline DESC");
if (($bbuserinfo[maxposts] != -1) and ($bbuserinfo[maxposts] != 0)) {
$maxposts = $bbuserinfo[maxposts];
}
while ($post=$DB_site->fetch_array($posts)) {
if ($postcounter++ < $maxposts) {
if ($postcounter%2 == 0) {
$backcolor = "#F1F1F1";
} else {
$backcolor = "#DFDFDF";
}
$preformatted=$post[preformatted];
$username=$post[username];
In newthread.php, add the code in red in the the following lines (please, notice the extra [/ color] that I added because vB one end tag was not enough to end the red color):
// ############################### start post thread ###############################
if ($action=="postthread") {
// decode check boxes
$preformatted=iif(trim($preformatted)=="yes",1,0);
$parseurl=iif(trim($parseurl)=="yes",1,0);
$email=iif(trim($email)=="yes",1,0);
$allowsmilie=iif(trim($disablesmilies)=="yes",0,1);
$signature=iif(trim($signature)=="yes",1,0);
$preview=iif(trim($preview)!="",1,0);
$postpoll=iif(trim($postpoll)=="yes",1,0);
==============
eval("\$postpreview=\"".gettemplate("newpost_postpreview")."\";");
$preformattedchecked=iif($preformatted,"checked","");
$parseurlchecked=iif($parseurl,"checked","");
$emailchecked=iif($email,"checked","");
$disablesmilieschecked=iif(!$allowsmilie,"checked","");
$signaturechecked=iif($signature,"checked","");
$previewchecked=0;
================
$DB_site->query("UPDATE post SET pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signat ure',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$posts[minpost]'");
===============
// create first post
$DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,at tachmentid,pagetext,preformatted,allowsmilie,shows ignature,ipaddress,iconid,visible) VALUES (NULL,'$threadid','','".addslashes($postusername)."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ip address','$iconid','1')");
In showthread.php, add the code in red in the the following lines:
$preformatted = $post[preformatted];
$post[message]=bbcodeparse($post[pagetext],$forum[forumid],$post[allowsmilie]);
//highlight words for search engine
[/list=1]