tinker Posted December 22, 2007 Share Posted December 22, 2007 Hi, i'm doing a little bbcode editor and was wondering how others do certain things. 1) When the bbcode is entered, how would you store it, i.e. convert to html and store, or store as bbcode and convert as served. I'm thinking that converting to html and storing, if needs to be edited then convert back (because there will be more views served than edits!) 2) How to deal with code tags, I know the code shouldn't be bbcode, but i'm to filter out any threatening code. I'm thinking of either splitting the whole lot, or cutting the code sections out and dealing with separately, then putting back. Both of these sound convoluted so i'm hoping there's a better way. CHeers for any suggestions! Quote Link to comment Share on other sites More sharing options...
papaface Posted December 22, 2007 Share Posted December 22, 2007 bbcode should be interpreted on the fly and not stored in its HTML form because you may change the way things are interpreted. Quote Link to comment Share on other sites More sharing options...
tinker Posted December 22, 2007 Author Share Posted December 22, 2007 When you say 'because you may change the way things are interpreted.', do you mean it may mean something different through time, or that it may be updated. The way i'm thinking is, this post has been read 12+ times but not as such edited, admittedly theres not much content as such but if there was, every time it would need to be converted and regex is quite cpu intensive. Is this a fair tradeoff, surely it's possible to convert back to bbcode from html, (once again the code tags being the stickler). ? ? ? Quote Link to comment Share on other sites More sharing options...
Jessica Posted December 22, 2007 Share Posted December 22, 2007 Store it as bbcode. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 22, 2007 Share Posted December 22, 2007 When you say 'because you may change the way things are interpreted.', do you mean it may mean something different through time, or that it may be updated. The way i'm thinking is, this post has been read 12+ times but not as such edited, admittedly theres not much content as such but if there was, every time it would need to be converted and regex is quite cpu intensive. Is this a fair tradeoff, surely it's possible to convert back to bbcode from html, (once again the code tags being the stickler). ??? I mean what jesirose said Quote Link to comment Share on other sites More sharing options...
tinker Posted December 22, 2007 Author Share Posted December 22, 2007 This was my original thinking and definitely the easier option, even less code to preprocess when loading, however i'm just reasoning the wear and tear on the server. For 1k of post you could be talking more than 20k of cpu cycles. I've just copied the first page of this, and that comes in at about 11.4k or say 220k cycles, probably more. And that page has been viewed 127 times. I don't want to be impertinent but would you mind giving me some reasoning as to your views, they sound pretty solid. Many thanks! Quote Link to comment Share on other sites More sharing options...
papaface Posted December 22, 2007 Share Posted December 22, 2007 I'd do it like that because you can always decide to take out a particular bbcode at anytime, or add any at any given time. If the HTML is stored, that code will not be processed anymore. Therefore take this for example: You start your script with [*b][*/b] bbcode. People post comments on your script using that particular bb code. Your script turns and stores bbcode in the database in HTML form Later in your scripts life you want to remove the [*b][*/b] bbcode. All the posts that were made before this decision will have bolded text. Understand? As for server resources, well thats just one of those things lol. Quote Link to comment Share on other sites More sharing options...
tinker Posted December 22, 2007 Author Share Posted December 22, 2007 Thanks for rationalising it for me. Not that I can find that usage of the bold (but hey, thats why i'm here). However that's sort of why i'm questioning it all now, so that changes don't have to be made latter (I wish I was perfect, not, I like my imperfections)... but enough on that for the moment. Any suggestions for Q2 please? 2) How to deal with code tags, I know the code shouldn't be bbcode, but i'm to filter out any threatening code. I'm thinking of either splitting the whole lot, or cutting the code sections out and dealing with separately, then putting back. Both of these sound convoluted so i'm hoping there's a better way. Quote Link to comment Share on other sites More sharing options...
papaface Posted December 22, 2007 Share Posted December 22, 2007 Thanks for rationalising it for me. Not that I can find that usage of the bold (but hey, thats why i'm here). However that's sort of why i'm questioning it all now, so that changes don't have to be made latter (I wish I was perfect, not, I like my imperfections)... but enough on that for the moment. Any suggestions for Q2 please? 2) How to deal with code tags, I know the code shouldn't be bbcode, but i'm to filter out any threatening code. I'm thinking of either splitting the whole lot, or cutting the code sections out and dealing with separately, then putting back. Both of these sound convoluted so i'm hoping there's a better way. http://uk2.php.net/manual/en/function.strip-tags.php is that what you're looking for? Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted December 22, 2007 Share Posted December 22, 2007 As for question 2, i assume you refer to something similar to the tags like on this forum? If so, your best bet is to use the htmlentities() function. This will stop any html/javascript code being interpreted. You can then place it inside <pre > </pre > tags to preserve the look of it. Quote Link to comment Share on other sites More sharing options...
tinker Posted December 27, 2007 Author Share Posted December 27, 2007 Yes but no, they would be handled as you say, but as like this forum, if you put bbcode within a code block it stays as bbcode... 1) Split post on code delimiters and deal with code blocks differently. 2) Extract code block contents, leaving an id, dealing with, then replacing. Without hacking the code for this site, there currently my two options... Any suggestions? P.S. As for point 1, through discussion i'm deciding to store as bbcode, then disallow post updates after n time, then on first view thereafter to convert to html and re-store (db flag is required) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.