PDA

View Full Version : BB Code Font Size: Limit to max size=5


julius
01-12-2004, 04:29 PM
I changed the Available Sizes of the Toolbar Menu Options to

1 2 3 4 5

but in standard mode when you post, you can manually change [SIZE=5] to [SIZE=7].

How can I fix it so users cannot change [SIZE=5] to [SIZE=7] or, even if they change it, the parse is no more than size=5?

Andreas
01-12-2004, 04:54 PM
Try this hack (it's for RC2, might also work for earlier versions)

File functions_newpost.php

Before
if ($post['preview'] OR sizeof($errors) > 0)

Insert

// PostSizeHack
// Make sure user does not user too large fonts
$pattern = "/\[size=[6-9]\].*\[\/size\]/si"; // Check for SIZE=6-9
$pattern2 = "/\[size=\+[5-9]\].*\[\/size\]/si"; // Check for SIZE=+5-9
$pattern3 = "/\[size=\+*[1-9][0-9]+\].*\[\/size\]/si"; // Check for SIZE=[+]10-xxxxx
if (preg_match($pattern, $post['message']) or
preg_match($pattern2, $post['message']) or
preg_match($pattern3, $post['message'])) {
$post['preview'] = 1;
eval('$errors[] = "Font size too large - max is 5";');
}
// PostSizeHack


Colud be also made configurable via CP & phrased, but would make the hack a bit more "difficult" ;)

julius
01-12-2004, 06:15 PM
Thanks.

It works, but if I put [size=07] or 08, 09, 10, 11 until [size=99] it always parses as [size=7] instead of [size=5].

Andreas
01-12-2004, 06:50 PM
Hmm ... ok. Haven't thought of leading zeros.
Give it another try then:


// PostSizeHack
// Make sure user does not user too large fonts
$pattern = "/\[size=0*[6-9]\].*\[\/size\]/si"; // Check for SIZE=[0]6-9
$pattern2 = "/\[size=\+0*[5-9]\].*\[\/size\]/si"; // Check for SIZE=+[0]5-9
$pattern3 = "/\[size=\+*0*[1-9][0-9]+\].*\[\/size\]/si"; // Check for SIZE=[+][0]10-xxxxx
if (preg_match($pattern, $post['message']) or
preg_match($pattern2, $post['message']) or
preg_match($pattern3, $post['message'])) {
$post['preview'] = 1;
eval('$errors[] = "Font size too large - max is 5";');
}
// PostSizeHack

Link14716
01-12-2004, 07:05 PM
I think you should post that up in the Mini-Mods subforum. :)

julius
01-12-2004, 07:10 PM
Link14716, it works fine now when you enter a new post, but if after you have posted you edit the post, you can still change the size to a bigger size.

Andreas
01-12-2004, 07:32 PM
For edit it's almost the same:

File editpost.php

Before
if (sizeof($errors) > 0)

Add

// PostSizeHack
// Make sure user does not user too large fonts
$pattern = "/\[size=0*[6-9]\].*\[\/size\]/si"; // Check for SIZE=[0]6-9
$pattern2 = "/\[size=\+0*[5-9]\].*\[\/size\]/si"; // Check for SIZE=+[0]5-9
$pattern3 = "/\[size=\+*0*[1-9][0-9]+\].*\[\/size\]/si"; // Check for SIZE=[+][0]10-xxxxx
if (preg_match($pattern, $edit['message']) or
preg_match($pattern2, $edit['message']) or
preg_match($pattern3, $edit['message'])) {
$post['preview'] = 1;
eval('$errors[] = "Font size too large - max is 5";');
}
// PostSizeHack


@Link14716: I think i'll make a more "advanced" version with CP-configurable size (instead of hard-coded) and then post it there maybe ;)

Link14716
01-12-2004, 09:00 PM
Go for it. :)

julius
01-13-2004, 09:01 AM
Thanks, it works now.:)

MickDoneDee
11-27-2004, 02:00 PM
How can I fix it so users cannot change [SIZE=5] to [SIZE=7] or, even if they change it, the parse is no more than size=5?On my forum I wanted size 4,5,6,&7 to parse as size 2 so I used Replacement Variables as follows:

variable string: <font size="7"> or [size=7] etc
replacement string: <font size="2"> or [size=2] etc

Admin CP > Styles & Templates > Replacement Variable Manager > Add New Replacement Variable > Search for Text: [size=7]
Replace with Text: [size=2]

Repeat the above with:
Search for Text: [size=6]; [size=5]; [size=4]; <font size="7">; <font size="6">; <font size="5">; <font size="4"> in turn.
Replace with Text: [size=2] or <font size="2"> for vbcode or html.

Works a treat for signatures and posts. Of course, a persistent and clever user can edit the size tag to size=100 and size 7 will be parsed but that should rarely happen.

yoyoyoyo
07-08-2005, 01:46 PM
cool idea, but what would I need to edit to make the wysiwyg editor only show options of font size 1-5, and omit 6 and 7? Also- how can we modify the code to allow size 7 to be the biggest, instead of 5?