Thread: vBindex v2.1
View Single Post
  #1071  
Old 11-09-2002, 04:03 AM
kreftt's Avatar
kreftt kreftt is offline
 
Join Date: Dec 2001
Posts: 121
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

for those who have the problem with their bbcodes breaking in pieces when characterlimit is reached:

i think i found a solution, which allows the following things:

-have admins post html
-have the "read more" whether the post is over the limit or not
-have the post cut itself in front of a bbcode that would be cut in half by the character limit
-have the post cut itself in front of a html tag that would be cut in half by the character limit
-have the news post follow the "use smilies" option that you set when you post the news

YOU MUST NOT

- use [ tags in your news posts except in bbcode

- use slashes inside html arguments. means you can do
Code:
<a href="http://ww.vbulletin.org/forum">vb.org</a>
but you cannot use
Code:
<a href="http://ww.vbulletin.org/forum">http://ww.vbulletin.org/forum</a>
you can use slashes in the rest of the post

what you need to do is to is to

1) backup your vbindex.php

2) replace the whole news section
(starting with:
Code:
// news (based on code by TECK)
and ending with
Code:
// end news
)

with the code below
from how i understand it there are no additional queries, and from how i understand it it was the first time i used all these functions so there might be errors. it works for me though.

PHP Code:
// news (based on code by TECK)
// has pieces of entourage's admin html allow hack
// -------------------------
if ($newsonoff!=0) {
// $newsquery=$newsquery=$DB_site->query("SELECT thread.*,threadpost.pagetext AS pagetext FROM thread LEFT JOIN post AS threadpost ON (thread.firstpostid = threadpost.postid) WHERE forumid = '$newsforum' ORDER BY thread.dateline DESC LIMIT $newsposts");
$newsquery=$newsquery=$DB_site->query("SELECT thread.*, user.usergroupid AS usergroupid, threadpost.pagetext AS pagetext, threadpost.allowsmilie AS allowsmilie FROM thread LEFT JOIN post AS threadpost ON (thread.firstpostid = threadpost.postid) LEFT JOIN user ON (thread.postuserid = user.userid) WHERE forumid = '$newsforum' ORDER BY thread.dateline DESC LIMIT $newsposts");
while (
$news=$DB_site->fetch_array($newsquery)) {
  
$newsthreadid=$news[threadid];
  
$newstitle=$news[title];
  
$newstime=vbdate($timeformat,$news[dateline]);
  
$newsdate=vbdate($dateformat,$news[dateline]);
  
$newsusername=$news[postusername];
  
$newsusergroupid=$news[usergroupid];
  
$newsallowsmilie=$news[allowsmilie];
  
$newsuserid=$news[postuserid];
  
$comments=$news[replycount];
  
$icon=$news[iconid];
  
// uncomment out next line to remove line breaks in the news
  //$newstext=str_replace("<br />","",$newstext);

$pagetext=$news['pagetext'];

// max news chars
if (strlen($pagetext) >= $maxnewschars) { 
                
$pagetext=substr($pagetext,0,$maxnewschars); 
    
$pagetext=substr($pagetext,0,strrpos($pagetext," ")); 
    
// does this post have bbcode?
    
$pos=strrpos($pagetext,"[");
        if (
$pos === false) {
            
// if no, then do nothing
        
} else {
            
// check the distance between the last / and the last [ of the post.
            // if its +1 we are outside bbcode and safe
            
$needle1="/";
            
$pos1=strlen($pagetext) - (strpos(strrev($pagetext), strrev($needle1)) + strlen($needle1));
            
$needle2="[";
            
$pos2=strlen($pagetext) - (strpos(strrev($pagetext), strrev($needle2)) + strlen($needle2));
            
$pos3 $pos1 $pos2;
                if (
$pos3 >= 1) {
                    
// we are outside bbcode
                
} else {
                    
// we are in bbcode, so we have cut it away
                    
$pagetext=substr($pagetext,0,strrpos($pagetext,"[")); 
                }
        }
    
//does this post have html ?
    
$posh=strrpos($pagetext,"<");
        if (
$posh === false) {
            
// if no, then do nothing
        
} else {
            
// check the distance between the last / and the last < of the post.
            // if its +1 we are outside html and safe
            
$needleh1="/";
            
$posh1=strlen($pagetext) - (strpos(strrev($pagetext), strrev($needleh1)) + strlen($needleh1));
            
$needleh2="<";
            
$posh2=strlen($pagetext) - (strpos(strrev($pagetext), strrev($needleh2)) + strlen($needleh2));
            
$needleh3=">";
            
$posh3=strlen($pagetext) - (strpos(strrev($pagetext), strrev($needleh3)) + strlen($needleh3));
            
$posh4 $posh1 $posh2;
            
$posh5 $posh1 $posh3;
                if (
$posh4 == 1) {
                    
// we are outside html
                
} elseif ($posh4 1) {
                    
// we are inside a html-tag, so we cut it away
                    
$pagetext=substr($pagetext,0,strrpos($pagetext,"<")); 
                } elseif (
$posh4 1) {
                        
// we could be everywhere if there are slashes in the post
                        
if ($posh5 $posh4) {
                            
// we are inside a tag as the way from the last / to the last <
                            // is shorter than the way to the last >, so we cut
                            
$pagetext=substr($pagetext,0,strrpos($pagetext,"<")); 
                        } else { 
                            
// we are right after a html tag as someone uses slashes in posts
                            // < is farer than > away, no need to do sth
                        
}
                }
        }

    
$pagetext=$pagetext." ..."
    
$readmore="<a href=\"$bburl/showthread.php?threadid=$newsthreadid\">Read full post</a> - ";
} else {
    
$readmore="";
}
// end max newschars

if ($newsusergroupid == 6) {
$newstext=bbcodeparse2($pagetext,1,1,$newsallowsmilie,1);
} else {
$newstext=bbcodeparse($pagetext,$newsforum,$newsallowsmilie,1);
}


// get users avatar to display with news
if ($shownewsavatar!=0) {
$newsavatarurl2=getavatarurl($newsuserid);
  if (
$newsavatarurl2=='') {
    
$newsavatarurl="$bburl/https://vborg.vbsupport.ru/images/clear.gif";
  } else {
  
$newsavatarurl=''.$bburl.'/'.$newsavatarurl2.'';
  }
  eval(
"\$newsavatar = \"".gettemplate('home_avatar')."\";");
}
// end avatar
  
eval("\$newsbits .= \"".gettemplate('home_newsbit')."\";");
}
eval(
"\$news = \"".gettemplate('home_news')."\";");
}
// -------------------------
// end news 
and as this board here parses bbcode even in php-tags, you will need to replace the link $newsavatarurl with your own clear.gif, as it now leads to vbulletin.orgs clear.gif

feedback appreciated

kreftt
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01333 seconds
  • Memory Usage 1,880KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete