|
parseubb() question
|
| skpacman |
Posted on 21-03-2012 15:05
|

Member

Posts: 103
Joined: 23/04/2009
|
I was wondering if there was a way to parse all bbcodes excluding a single one instead of listing all of the ones to parse.
The article at Next doesn't cover it completely.
My code is:
Code$description = nl2br(parseubb(parsesmileys($snippet['description']), "b|i|u|url|left|center|justify|right|code|quote|olist|ulist|color|size|hide|fpnotice|fieldset"));
But I'm wondering if there's a way to exclude bbcodes from parse instead of listing the ones to include.
Is this possible or am I forced to do it the long way?
|
| |
|
|
| Tyler |
Posted on 21-03-2012 15:11
|

Member

Posts: 161
Joined: 30/11/2011
|
I think it is the one's you wish to include... You could store the list in a variable... you'd have to do it at least once but if its something you repeat or often use its nice. |
| |
|
|
| skpacman |
Posted on 21-03-2012 15:43
|

Member

Posts: 103
Joined: 23/04/2009
|
Thanks for your suggestion Mittens Returns.
I found a solution. My overall goal for this was to remove the GeSHi bbcode but leave all else because it conflicted with some of my other code.
I used a custom function and a few variables and tricks later, I have exactly what I wanted :D see below
Codefunction remove_element($arr, $val){
foreach ($arr as $key => $value){
if ($arr[$key] == $val){
unset($arr[$key]);
}
}
return $arr = array_values($arr);
}
$bbcode_cache = remove_element($bbcode_cache, 'geshi');
$csp_bb = implode('|', $bbcode_cache);
echo $csp_bb;
Bascially what the function does is search the $bbcode_cache array set by php-fusion's bbcode_include.php for the value 'geshi' then unsets that key, implodes it into a string, and returns it as a variable you can plug into the parseubb
so then my parseubb code is severely simplified to:
Code$description = nl2br(parseubb(parsesmileys($snippet['description']), $csp_bb));
Again, thanks for your reply, it made me realize that a custom function would be required to do what I wanted. I was just hoping for a simpler solution built into the parseubb function.
|
| |
|
|
| Tyler |
Posted on 21-03-2012 16:50
|

Member

Posts: 161
Joined: 30/11/2011
|
good job. found your answer and did it yourself. there's nothing wrong with what you did and there isn't anything special about this other than one less function to call. its the core parseubb function changed. to use it call parseubb($text, false, $list_to_avoid)
the list must be separated by | as the include. if you stick with what you have its cool. if you do use it, overwrite parseubb function in maincore.php
Tyler attached the following file:
|
| |
|
|
| skpacman |
Posted on 21-03-2012 16:54
|

Member

Posts: 103
Joined: 23/04/2009
|
Thanks again. I'm trying to make this portable though (an infusion I'm building) so I don't want people to have to edit the maincore just to get this working.
I think I'll stick with my solution. I like your modification though, I'll keep it in mind.
Merged on Mar 21 2012 at 10:59:13:
Yet another case of "Seek and ye shall find."
I found an even easier way to do it without modifying core files and no need for special functions.
Codeif (!$bbcode_cache) { cache_bbcode(); }
if (in_array("geshi", $bbcode_cache)){
$csp_bb = implode('|', $bbcode_cache);
$csp_bb = str_replace("|geshi", "", $csp_bb);
} else {
$csp_bb = implode('|', $bbcode_cache);
}
then just use $csp_bb (or whatever you want to name it) as your pipe " | " separated list
For your own purposes, you can replace "geshi" with any kind of bbcode name you want. This is useful if you want to show all available bbcodes excluding a single one. It could also be expanded to get rid if several others just by removing the if in_array and doing multiple str_replace calls.
Edited by skpacman on 21-03-2012 17:59
|
| |
|
|
| Tyler |
Posted on 21-03-2012 18:40
|

Member

Posts: 161
Joined: 30/11/2011
|
That's nice. I guess if this was implemented in fusion core as I did you wouldn't need any extra coding at all.
BTW: What exactly are you working on? |
| |
|
|
| skpacman |
Posted on 21-03-2012 18:49
|

Member

Posts: 103
Joined: 23/04/2009
|
I'm making an infusion by special request from Lenoox (on my site)
Details on my forum.
The infusion is nearly complete and will be released as soon as I'm done correcting a few errors and updating the security and version of geshi i'm using.
|
| |
|