Web Design Forum: bb code problem - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

bb code problem Rate Topic: -----

#1 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 04:11 PM

Hello, So on my CMS ive got a bb code so the client can change font colour and size etc

the function works like this

client clicks color red so, it will appear
[color=red]text[/color]
to them but when it gets displayed on their site it will change
[color=red]
to
<span style="color:red;">
etc

thats a problem because, if there is a size set on the text already on the css then it wont work because its then inside the span aswel, so then the client does
[color=red][size=12px]text[/size][/color]
so when outputted it will be
<span style="color:red;"><span style="font-size:12px;">text</span></span>
in the html

and obviously because the text is in another span then the colour wont be shown only the font will

how can i fix this?

Any help would be appreciated

Gary

This post has been edited by web-itec: 09 January 2012 - 04:13 PM

0

#2 User is online   Spitfire 

  • Mighty Pirate™
  • PipPipPipPip
  • Group: Members
  • Posts: 891
  • Joined: 05-February 11
  • Reputation: 189
  • Gender:Male
  • Location:Berkshire
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 05:11 PM

Did you write the BBcode conversion script yourself? If so, post the code that converts.

Otherwise, maybe try something like TinyMCE instead of BBcode for text editing.
0

#3 User is offline   webdesigner93 

  • Web Guru
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,976
  • Joined: 22-September 09
  • Reputation: 222
  • Gender:Male
  • Experience:Web Guru
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 05:48 PM

View Postweb-itec, on 09 January 2012 - 04:11 PM, said:

Hello, So on my CMS ive got a bb code so the client can change font colour and size etc

the function works like this

client clicks color red so, it will appear
[color=red]text[/color]
to them but when it gets displayed on their site it will change
[color=red]
to
<span style="color:red;">
etc

thats a problem because, if there is a size set on the text already on the css then it wont work because its then inside the span aswel, so then the client does
[color=red][size=12px]text[/size][/color]
so when outputted it will be
<span style="color:red;"><span style="font-size:12px;">text</span></span>
in the html

and obviously because the text is in another span then the colour wont be shown only the font will

how can i fix this?

Any help would be appreciated

Gary


idk if this will help but heres a class i wrote to parse bbcode for my blog software odviously some of it u wont need such as the adsense bit but you can change it as needed

class bbcode{
	
private $search;
private $replace;


/**
 * bbcode::parse()
 * 
 * @param mixed $string
 * @return void
 */
public function parse($string){
global $post,$page,$adsense_enabled_in_post;

/**
 *Adsence unit 
 */
 if($page || $post && $adsense_enabled_in_post === true){
 global $width_of_unit,$height_of_unit,$publisher_id,$ad_slot_id;
 $adsense = '
 <span class="adUnit"><script type="text/javascript"><!--
google_ad_client = "'.$publisher_id.'";
google_ad_slot = "'.$ad_slot_id.'";
google_ad_width = '.$width_of_unit.';
google_ad_height = '.$height_of_unit.';
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span>
 ';
 }else{
    $adsense = '';
 }
/**
*Replace everything except  our you tube code
**/
$string = str_replace('http://www.youtube.com/watch?v=','',$string);
    /**Search**/
$this->search = array(
'/\[bold\](.*?)\[\/bold\]/is',
'/\[italic\](.*?)\[\/italic\]/is',
'/\[h1\](.*?)\[\/h1\]/is',
'/\[h2\](.*?)\[\/h2\]/is',
'/\[h3\](.*?)\[\/h3\]/is',
'/\[h4\](.*?)\[\/h4\]/is',
'/\[h5\](.*?)\[\/h5\]/is',
'/\[h6\](.*?)\[\/h6\]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[right\](.*?)\[\/right\]/is',
'/\[left\](.*?)\[\/left\]/is',
'/\[allcaps\](.*?)\[\/allcaps\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[color fcolor=(.*?)\](.*?)\[\/color\]/is',
'/\[url=(.*?)\](.*?)\[\/url\]/is',
'/\[image\](.*?)\[\/image\]/is',
'/\[youtube\](.*?)\[\/youtube\]/is',
'/\[adsense\]/',
'/\[code\](.*?)\[\/code\]/is',
'/:\)/',
'/:\(/',
'/\:p/',
'/\:wink/',
'/\:unsure/',
'/\:roll/',
'/\:o/',
'/\:mellow/',
'/\:mad/',
'/\:laugh/',
'/\:huh/',
'/\:blink/',
'/\:cool/',
'/\:shy/',
'/\:sick/',
'/\:sweat/',
'/\:stamp/',
'/\:tears/',
'/\:bleh/',
'/\:bop/',
'/\:bouncy/',
'/\:chin/',
'/\:chap/',
'/\:biggrin/',
'/\:angel/',
'/\:bye/',
'/\:drool/',
'/\:dirol/',
'/\:hi/',
'/\:good/',
'/\:flm/',
'/\:plea/',
'/\:santa_cool/',
'/\:santa_grin/',
'/\:santa_smiley/',
'/\:rudolph/'
);
    /**Replace**/
$this->replace = array(
'<b>$1</b>',
'<i>$1</i>',
'</p><h1>$1</h1><p>',
'</p><h2>$1</h2><p>',
'</p><h3>$1</h3><p>',
'</p><h4>$1</h4><p>',
'</p><h5>$1</h5><p>',
'</p><h6>$1</h6><p>',
'<span style="text-align:center; display:block;">$1</span>',
'<span style="text-align:right; display:block;">$1</span>',
'<span style="text-align:left; display:block;">$1</span>',
'<span style="text-transform:uppercase;">$1</span>',
'<u>$1</u>',
'<span style="color:$1;">$2</span>',
'<a href="$1">$2</a>',
'<img src="$1" alt="" onmouseover="image_hover_expand(this)" onmouseout="image_hover_collapse(this)" width="220"  height="220" />',
'<iframe width="300" height="300" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
'
'.$adsense.'
',
'</p><div class="code"><code><span class="code_snipplet_head">Code Snipplet</span><br />$1</code></div><p>',
'<img src="smilies/smile.gif" alt="" />',
'<img src="smilies/sad.gif" alt="" />',
'<img src="smilies/tongue.gif" alt="" />',
'<img src="smilies/wink.gif" alt="" />',
'<img src="smilies/unsure.gif" alt="" />',
'<img src="smilies/rolleyes.gif" alt="" />',
'<img src="smilies/ohmy.gif" alt="" />',
'<img src="smilies/mellow.gif" alt="" />',
'<img src="smilies/mad.gif" alt="" />',
'<img src="smilies/laugh.gif" alt="" />',
'<img src="smilies/huh.gif" alt="" />',
'<img src="smilies/blink.gif" alt="" />',
'<img src="smilies/cool.gif" alt="" />',
'<img src="smilies/shy.gif" alt="" />',
'<img src="smilies/sick.gif" alt="" />',
'<img src="smilies/sweat.gif" alt="" />',
'<img src="smilies/stamp.gif" alt="" />',
'<img src="smilies/tears.gif" alt="" />',
'<img src="smilies/bleh.gif" alt="" />',
'<img src="smilies/bop.gif" alt="" />',
'<img src="smilies/bouncy.gif" alt="" />',
'<img src="smilies/chin.gif" alt="" />',
'<img src="smilies/chap.gif" alt="" />',
'<img src="smilies/biggrin.gif" alt="" />',
'<img src="smilies/angel.gif" alt="" />',
'<img src="smilies/bye.gif" alt="" />',
'<img src="smilies/drool.gif" alt="" />',
'<img src="smilies/dirol.gif" alt="" />',
'<img src="smilies/hi.gif" alt="" />',
'<img src="smilies/good.gif" alt="" />',
'<img src="smilies/flm.gif" alt="" />',
'<img src="smilies/plea.gif" alt="" />',
'<img src="smilies/santa_cool.gif" alt="" />',
'<img src="smilies/santa_grin.gif" alt="" />',
'<img src="smilies/santa_smiley.gif" alt="" />',
'<img src="smilies/rudolph.gif" alt="" />'
);

return preg_replace($this->search,$this->replace,$string);
	
}
}
$bbcode = new bbcode;

0

#4 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 09:33 PM

@spitfire tinyMCE is under a license which says i cant share it (aka so my client cant then have the coding given by me because then i would be "sharing"), i dont particularly like premade stuff like that anyway like stuff like wordpress and all that stuff

function bb($r) {
$r = trim($r);
$r = htmlentities($r);
$r = str_replace("\r\n","<br />",$r);
$r = str_replace("[b]","<b>",$r);
$r = str_replace("[/b]","</b>",$r);
$r = str_replace("[i]","<i>",$r);
$r = str_replace("[/i]","</i>",$r);
$r = str_replace("[u]","<u>",$r);
$r = str_replace("[/u]","</u>",$r);
$r = str_replace("[strike]","<strike>",$r);
$r = str_replace("[/strike]","</strike>",$r);
$r = str_replace("[marquee]","<marquee>",$r);
$r = str_replace("[/marquee]","</marquee>",$r);

$search = array(   
                '/\[font\=(.*?)\](.*?)\[\/font\]/is',   
                '/\[color\=(.*?)\](.*?)\[\/color\]/is',
                '/\[size\=(.*?)\](.*?)\[\/size\]/is'
                );  

$replace = array(    
                '<span style="font-family: $1;">$2</span>',    
                '<span style="color: $1;">$2</span>',
                '<span style="font-size: $1;">$2</span>'
                );
$r = preg_replace ($search, $replace, $r);


$search = '/\[h(.*?)\](.*?)\[\/h(.*?)\]/is';
$replace = '<h$1>$2</h$3>';  
$r = preg_replace ($search, $replace, $r);

$r = html_entity_decode(stripslashes(trim($r)));
return $r;
}


as you can see the function would simply replace something like
[size=6px][color=#ff3232]Company Profile[/color][/size]

with
<span style="font-size: 6px;"><span style="color: #ff3232;">Text</span></span>


so the text only turns red it doesnt go to font size 6px aswel

any ideas?
0

#5 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 09 January 2012 - 09:49 PM

hmm, it appears just <span style="font-size: 10px;"><span style="color: #ff3232;">Text</span></span> in a text document seems to work, ill see if i must close other tags first :s

i just tried it closing the tags but didnt work

the site is

http://web-itecsolut.../nonindexed/fm/

and the text is between <h2></h2> on the home page, so by default the text is blue and fairly big, but i want the client to be able to edit it if he wants (he edits text thats saved on the database thats shown on his screen where he can put [color=red] etc) then the text with the bb code added is shown BETWEEN the <h2></h2>

if anyone can tell me what the problem is definatly deserves +1 :good:

This post has been edited by web-itec: 09 January 2012 - 09:56 PM

0

#6 User is offline   web-itec 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 533
  • Joined: 23-March 11
  • Reputation: 53
  • Gender:Male
  • Location:United Kingdom
  • Experience:Advanced
  • Area of Expertise:Web Developer

Posted 11 January 2012 - 01:10 PM

anyone?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users