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