vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Enabling HTML Formatting on Posts (https://vborg.vbsupport.ru/showthread.php?t=18415)

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/showt...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.

Code:

  $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:

Code:

<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:

Code:

function bbcodeparse2($bbcode,$dohtml,$dobbimagecode,$dosmilies,$dobbcode)
{ // parses text for vB code, smilies and censoring

  global $DB_site,$wordwrap, $bbuserinfo,$preformatted;

  static $smilies,$bbcodes;
  global $regexcreated,$searcharray,$replacearray,$phpversionnum;

  if($wordwrap!=0) {
    $bbcode=dowordwrap($bbcode);
  }

  if(!$dohtml)  { // kill any rogue html code
    // $bbcode=str_replace("&","&amp;",$bbcode);
    $bbcode=str_replace("&lt;","&amp;lt;",$bbcode);
    $bbcode=str_replace("&gt;","&amp;gt;",$bbcode);
    $bbcode=str_replace("<","&lt;",$bbcode);
    $bbcode=str_replace(">","&gt;",$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("&gt;)", "&gt; )", $bbcode);
    $bbcode=str_replace("&lt;)", "&lt; )", $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):

Code:

  $parseurlchecked="CHECKED";

  $preformattedchecked=iif($postinfo[preformatted],"CHECKED","");
  $disablesmilieschecked=iif($postinfo[allowsmilie],"","CHECKED");
  $signaturechecked=iif($postinfo[showsignature],"CHECKED","");

========

Code:

// ############################### 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);

=======

Code:

  $DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signature',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):

Code:

// ############################### 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);

============

Code:

    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);

====================

Code:

      $DB_site->query("UPDATE post SET title='".addslashes(htmlspecialchars($newtitle))."',pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signature',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$postid'");
================

Code:

      $DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,attachmentid,pagetext,preformatted[/color],allowsmilie,showsignature,ipaddress,iconid,visible) VALUES (NULL,'$threadid','".addslashes(htmlspecialchars($title))."','".addslashes(htmlspecialchars($postusername))."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ipaddress','$iconid','$visible')");
===================

Code:

  $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):

Code:

// ############################### 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);

==============

Code:

    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;

================

Code:

      $DB_site->query("UPDATE post SET pagetext='".addslashes($message)."',preformatted='$preformatted'[/color],allowsmilie='$allowsmilie',showsignature='$signature',iconid='$iconid',attachmentid='$attachmentid' WHERE postid='$posts[minpost]'");
===============

Code:

      // create first post
      $DB_site->query("INSERT INTO post (postid,threadid,title,username,userid,dateline,attachmentid,pagetext,preformatted,allowsmilie,showsignature,ipaddress,iconid,visible) VALUES (NULL,'$threadid','','".addslashes($postusername)."','$bbuserinfo[userid]','".time()."','$attachmentid','".addslashes($message)."','$preformatted','$allowsmilie','$signature','$ipaddress','$iconid','1')");

[*]In showthread.php, add the code in red in the the following lines:

Code:

  $preformatted = $post[preformatted];
  $post[message]=bbcodeparse($post[pagetext],$forum[forumid],$post[allowsmilie]);

  //highlight words for search engine

[/list=1]


All times are GMT. The time now is 09:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00999 seconds
  • Memory Usage 1,750KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (16)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete