corzblog bbcode parser preview



Here it is! My [search engine fodder] bbcode to html parser, and html to bbcode parser [/search engine fodder]!

This is the actual very onsite parser that parses the bbcode of my blogs and site comments, which as well its usual tasks of, well, you know, the parsing stuff, also moonlights doing a cute wee background demo of itself, you're looking at it. it knew you wanted to do that. hit the "preview" button to see at least one half of the parser's bbcode to html/html to bbcode functionality.

The front-end (below) is built-in to the parser, you just call the function and it creates the form. The cool, super-portable JavaScript bbcode buttons and functions come in the package, too. Have fun. Oh, and by the way, output is 100% pure HTML5, or nice plain bbcode, which ever way you look at it, it's free.

button to undo the last javascript change
cbparser quick bbcode guide..
Most common bbtags are supported, and with cbparser's InfiniTags™ you can pretty much just make up tags as you go along. If cbparser can construct valid html tags out of them, it will. Experimentation is the key, and preview often.

A few bbcode examples..
[b]bold[/b], [i]italic[/i], [big]big[/big], [sm]small[/sm], [img]http://foo.com/image.png[/img], [code]code[/code],[code]teletype[/code], [url="http://foo.com" title="foo!"]foo U![/url], and more.. To post code with indentation and/or strange characters, .htaccess, etc., use [pre][/pre] tags.
download cbparser
an HTML5 compliant bbcode parser



Welcome to the comments facility!


previous comments (eighteen pages)   show all comments

cor - 15.11.08 5:25 am

Hey numstruck! Remember, cbparser is no more than a module to convert bbcode to xhtml and back.

However, cbparser also has the capability to draw funky forms and more, and that might be what is confusing you into thinking that it can do "everything". Almost, but not quite. You're right, you need a "comments.php".

Inside the distribution, is a folder called "examples", and in there, a script called "text.to.html.converter.php". Without too much messing around, that could be hacked into a simple comment facility.

Just like in cbparser.php, you'll need to adjust the preferences. I happen to keep my copy of cbparser (one copy is enough to run all the forms and tools on the site) inside /blog/inc/, though feel free to keep yours wherever you like.

Inside the example script, there's a section of code, something like..

<?
if (isset($_POST['preview'])) { etc... 
?>


You could add your own section, checking not for 'preview', but 'publish' (meaning someone pressed that button on the form). Your section of code would grab the string they posted, and write it to a file. You could display (include()) that file at the top of the page (a-la "previous comments"). And so on.

In fact, as you are not the first to ask for such a thing, by any means, and as it's a fine Saturday morning task, I have gone ahead and done all this, as well as a few other edits, zipped the whole thing up for your learning and amusement, and hopefully, hacking. You can grab that, here..

https://corz.org/engine?download=menu&section=beta/corzblog

Full documentation is included in the script, though if you have any comments or questions about it, feel free to drop them here.

Have fun!

;o)
(or

p.s. the "tables" aren't tables, they only look that way.


numstruck - 15.11.08 6:43 am

THANK YOU, THANK YOU, THANK YOU

That is exactly what I wanted.

I hope your weekend is filled with happiness.

an image

your
'looks-like-tables'
are perfect
for what I need.


genius, pure genius.
<?php
include 2thumbsup smilie here
*
?>


I hope I can figure out how to add a NAME field...


cor - 15.11.08 8:58 am

I'm glad you like it! All donations warmly accepted! smiley for ;)

I picked up your love-pulse a wee while back, thanks, I was in the middle of something at the time. As mentioned, you're not the first to hint that such an example would be useful. I think I was leaving it "as an exercise", or something, but that can be frustrating when you are completely unfamiliar with cbparser's comprehensive feature set. Thanks for giving me a nudge to do it. A working comments example was long overdue.

For greater insight into cbparser's auto-form capabilities, compare the do_bb_form() call in the two example scripts. I didn't make many changes, and bang! Instant comments!

I'll no doubt add it to the next cbparser distro. By the way, you can send an id via the do_bb_form() function, maybe preferable to a NAME. Or hack whatever you like directly into cbparser.php (search for <form).

May your own weekend be joyful!

;o)
(or


numstruck - 16.11.08 4:54 am

Hmmm, well I got it incorporated into my page, (never could figure out the name thing),
just one small problem, if you refresh the page after posting, it posts again, and again. smiley for :eek:

It doesn't seem logical since the text field is blank.. any suggestions how I could stop that?
(I know people will try to use it as a chatbox, and be hitting refresh ad nauseum...)

Other than that I am thoroughly impressed, it looks great with my page colors and layout too.

an image


cor - 16.11.08 6:29 pm

My mistake was in adding the capability to have the script wipe the text field after a successful comment. I should have left *everything* as an exercise! It might not seem logical, but if you refresh a page like that, you are sending the previous request, again.

As it says within the notes, the comment example script lacks all the security and finesse of a full-blown comment facility (like the one we are using here), things like refresh-protection are still left as "an exercise". For a real, live comment facility, you would need to add quite a few things. For the refresh issue, though, I can suggest a couple of possible approaches..

You could interrogate the existing comments file. I included the facility to have html automatically inserted before and after each comment, so that's two known markers you can use to split the comment file into an array of individual entries (e.g. "<div class="comment">… " add more specific markers, as required), and from there, pluck out the user's text to compare with what's being posted. If they match, ignore the new post.

Or else, if everything went okay and the comment got written, present the user with a temporary page (as these comments do) where all the request variables can be flushed, and after a few seconds, the script redirects automatically back to a clean URL of itself.

Or something else.

As for your NAME property. Firstly, check you really do need to use a NAME property, and that an id wouldn't do just as well, if not better. If it will, then note you can send the id you want to give to your form from within the do_bb_form() function, so you never have to hack cbparser itself.

If you really do need to add a NAME property to your form, simply open cbparser in a text editor, do a search for "<form", and you'll see the part where cbparser spits out the form, add your NAME="whatever", right there. It won't affect cbparser's operation, though it may affect your page's validation, which may or may not matter to you.

Pretty much anything is possible, with a little imagination, and some work.

Looking good, so far!

;o)
(or


numstruck - 16.11.08 9:26 pm

I think an id field will work fine... but I am a little confused about how to make
a the script present a temp page and then flush all the request variables.
(I can make an index page with an empty main <div>, just not sure about the rest)

I guess I really am a n00b to php. Sorry for the endless questions.

My biggest problem is using a free host, so I have to upload every test page.
Then when that doesn't work, delete them and start all over again...frustrating.

I have found plenty of other plain-jane comment scripts, but none compare to this.
Even more frustrating is knowing that someone like you could fix it in 5 minutes.smiley for :lol:

Oh well, I will keep hacking away and when I'm ready to smash my PC I'll come back
and beg and plead one more time, or give up and use some generic chat script.smiley for :erm:

At any rate, thanks for all your time, I've learned several things about php, css
and html...so you have helped me regardless if the script works eventually or not.

Cheers and Regards,


cor - 17.11.08 2:09 pm

Firstly, don't let your host get you down. If you are serious about making web sites, setup Apache on a local machine, and do all this stuff on a "development mirror". Creating back-end code on a live site isn't recommended.

If you want to know more about running a web server, check out the /serv/ part of this site.

While I'm here, one simple solution to your refresh problem, and in a lot less than five minutes..

header('Location: http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

Put that directly under the write_data(...) call, and the problem is solved; the page up to that point becomes your "temporary page" (it doesn't need to output anything!), and then php spits out a "Location" header which sends the browser to the new location (which just so happens to be the same location, except "fresh", without any user form data).

Tada!

Note: For this to work, you would need to ensure that no data has been sent to the browser before the header() is sent.

;o)
(or

p.s. I'll add this capability to the example script the next time I'm in there.


numstruck - 17.11.08 4:58 pm

Yuppers, worked perfect.
Again, (sigh), thank you so much.

Actually, I have downloaded Apache, and the latest PHP and MySQL,
but...as I have been searching for information on different things
I've read a few horror stories, so I've been putting off installing it all.

I want to understand it all enough to be sure I don't become a "server". smiley for :blank:
I've learned that I usually know just enough to be dangerous ( think regedit )
Add to that the fact that I am an alcoholic who has scrambled his brain with
45 years of a smörgåsbord drugs... well, you get the picture.

I'm sure there is some simple .htaccess trick to insure I never send any files
out into the world, but that is just one more subject that I need to learn.
So between learning html, css, php, mysql... eh, I'm sure you find this all
fascinating, but I have used up plenty of your time and ink already.

I did grab a copy of your remarkable distro machine...and copied the .htaccess tut.

Thanks again for the help, (and for suggesting EditPlus, what an awesome app)

EDIT: Just in case you want to waste more time on me, I would also like to limit
the number of comments to say 30 - 50, so only the newest ones were shown, and
any older ones would simply be deleted...if that makes any sense at all.



cor - 18.11.08 12:01 pm

Hello again.

I don't think it's a waste, not if we are learning stuff. And who knows, your site may get huge, and you may even make a donation! smiley for ;)

The .htaccess "trick" that will prevent you from sharing your server with the world goes something like this..
deny from all
allow from 127.0.0.1
replace "127.0.0.1" with whatever IP your client machine uses (127.0.0.1 is fine if it's the same machine that Apache is running on). Having said that, it's probably easier to simply not allow access through your router/gateway.

As for your "show recent comments only"; firstly, are you sure you want to delete the old comments? Why not just keep them? Plain text doesn't take up a lot of space, and you would prevent pissing people off, destroying their work. Nomatter how trivial it might seem, time spent is time spent.

As to how to achieve the effect, there are a number of ways you could approach this. Personally, I would load the entire file into a string (you never have to worry about strings being "too big" with php). Then explode() it into an array of comments. Then remove all but the most recent x number of comments, and spit out what's left. The code for that would go something like this (replacing the include() command)..

<?
//@include ($data_file);
$comment_page file_get_contents($data_file);
$comment_array explode('<div class="comment">'$comment_page);
if (
count($comment_array) > 30) {
    
$comment_array array_slice($comment_array, -30);  // show 30 most recent comments
    
$recent_comments implode('<div class="comment">'$comment_array);
    echo 
'<div class="comment">',$recent_comments;
} else {
    echo 
$comment_page;
}
?>


Some of that could be combined, made smaller, but I left it as-is because it's clearer. It basically does exactly what I just described, loading the file into a string, exploding that string into an array of posts, chopping off all but the most recent x posts, and then imploding it back into a string (using the same string of text we used to explode it in the first place). And finally, echoing the new string out as "recent comments", preceded by the string, '<div class="comment">', which was lost during the conversion.

The code will first check that the number of comments exceeds the preferred amount-per-page, and only kicks-in if that is the case. Otherwise it simply spits out the string. This will prevent validation errors with extra '<div class="comment">' strings being prepended to the comments when there was no processing done.

I'll add something like this into the example. See! While we're at it, we're making a rather good little comment script! Nothing is wasted!.

Have fun!

;o)
(or


numstruck - 18.11.08 7:20 pm

I added this, replacing the @include ($data_file); section on my page,
but now it posts everything twice and gives a (can't send headers warning)...

do I need to delete the echo $converted;, command just below it,

or would I change this...
write_data($data_file, $comment_pre.$converted.$comment_post);
to something like this...
write_data($recent_comments, $comment_pre.$converted.$comment_post);

or am I completely looking in the wrong direction?



I guess I should explain that instead of using the simple-comments.php page,
I cut out all of the code and pasted it in an empty main <div> on an index page.
(I also added most of your css to mine, so the page has all of my colors and layout)
It all works perfectly until this last change, so I am just not pasting this right,
or in the right place.

What I really like about this solution is that I could easily make an index2 page,
(without this block of code added), and add a link to "show all comments"...
as soon as they clicked any link it would default back to the index page again.

I'm beginning to see that installing apache and php is almost a necessity, I could
waste hours uploading dozens of test pages and still never find a solution.

I should just wait until you post the new examples...heck, since all of your
other apps are in the realm of perfection, (and you have already started on it)
you should just go ahead and add all the security and finesse of this one.
...or at least the bits that could be easily incorporated.

I know after days of searching dozens of scripting sites that a good comment script
is next to impossible to find, they are either a complete 'stand-alone' program,
or a bloated package of content management, neither of which can be easily added
to an existing page layout. So I think your script could be very useful and popular.

It already is better than anything else I have found...


cor - 18.11.08 7:26 pm

Interestingly, as you were posting that, I was adding all these ideas, and others, into the example script! check it out..

https://corz.org/engine?download=menu&section=beta/corzblog

while I read your post properly..

;o)
(or


next comments (2 pages)

First, confirm that you are human by entering the code you see..

(if you find the code difficult to decipher, click it for a new one!)


Enter the 5-digit code this text sounds like :

lower-case dee, Upper-Case Elle, wun, lower-case see, Upper-Case Em


 

Welcome to corz.org!

I'm always messing around with the back-end.. See a bug? Wait a minute and try again. Still see a bug? Mail Me!