Adding in a BBC box to my pages ..

Started by sangwe11, November 14, 2009, 12:05:43 PM

Previous topic - Next topic

sangwe11

I have two mods, not far from completion that need this.

Basically, I want to add whats shown below to my page creation page.



I understand I have to use a SMF function to generate the form ect, and not make my own, so I need to adjust my code accordingly, but what I am not getting is how on earth I get it to generate the form / bbc's ect ..

Any and all help is appreciated.

Arantor

You would be advised to start off looking at the code in Post.php, specifically the code concerning:

// Needed for the editor and message icons.
require_once($sourcedir . '/Subs-Editor.php');

// Now create the editor.
$editorOptions = array(
'id' => 'message',
'value' => $context['message'],
'labels' => array(
'post_button' => $context['submit_label'],
),
// We do XML preview here.
'preview_type' => 2,
);
create_control_richedit($editorOptions);

sangwe11

Mind explaining what each variable in the array does :D ?

I get the basic'ist of it, but I still can't get it to show.

Arantor

Do you get any errors? I haven't really used this myself though...

id -> the <div id> of the box
value -> the content the box should have
labels -> for the buttons that should be there
preview_type -> types of preview, I think 0 is for none, 2 for XML but I don't know about any others

sangwe11

Hmm now I'm confused haha  :o

I'm just taking a guess at these, so correct me if I'm wrong (if you know, seems this is the unknown lawl :D)

Also, are we talking this for each input box ? Or for all of them ?

id -> id of the div where I want it
value -> value to show (such as Page Name)
labels -> no idea on this
preview -> again, no idea

Arantor

Yeah, it's the div id where you want the form to be added. You'd specify that in the template.

value -> is the content the box has, for example for a post, it's blank on a new message, it has the existing message if you're editing, and has the quote if you're quoting someone.

labels -> for the buttons

preview -> depends if you a) want to have the inline preview like you normally get on posting, and b) want to have previewing anyway. Not so important if users can have WYSIWYG.

sangwe11

Ahh, 2 things I am stuck on, then I *should* be a go :D

the labels, is for the buttons right, so if I want to display the BBC buttons, what value do I have to specify ?

And is this for a single input ? or multiple ?

If it only adds a single, do I do my form like normal, and then just leave a blank div for it to put the bbc and message box in ?

Arantor

This is for a single postbox only.

The thing to do is to have a look at what the Post.template.php itself actually has in it. I have a feeling the create_ function sets it up for Post.template.php to display it, but it's something I've never gotten that far into, to be honest.

Perhaps I can come up with a mod where I find a need to create one :)

sangwe11

I can think of a few :D

I'll pm them you sometime xD

And i'll have a look and a mess around, and run back here screaming like a lil girl when it dont work haha !!!

Arantor

None of my current to-do list entries have any such need for it, to be honest.

Maybe when I get that lot cleared, though...

sangwe11

Success !!!

I've got it showing a box !! HAHA !

Still no show on the bbc though ..

I have this in my Source file ..

// Needed for the editor and message icons.
require_once($sourcedir . '/Subs-Editor.php');

// Now create the editor.
$editorOptions = array(
'id' => 'page_content_box',
'value' => '',
'labels' => array(
),
// We do XML preview here.
'preview_type' => 2,
);
create_control_richedit($editorOptions);


And this in my template file ..

<div id="page_content_box">', template_control_richedit('page_content_box', 'bbc') ,'</div>

I think its something to do with labels, but I'm not sure what I put in there :/

Arantor


sangwe11



The big box is what I get ..

I want the BBC's to be above it, like normal.

Arantor

Ah, you mean the buttons... hmm. Not sure off hand how that's done.

sangwe11

Ahh okk ..

I couldn't see anything different in the post / .template as to what I was doing, so I'm taking a look at the Enhanced Quick Reply (quick reply with bbc's basically) to see if I can gain any knowledge from that.

sangwe11

Well I have them there, but its not using any of the methods I was trying.

I basically used the code from the mod I was looking at (yes, i'll ask for permission before releasing, if I don't find another way, or rewrite it, which I probably will IMHO) to manually echo all the bbc's ..

All I need to know, is that is there a array in $context with all the bbc's and smileys stored in ? ATM i'm redefining them, but it wouldn't work for custom bbc's

Arantor

All the BBcodes for the editor are declared in Subs-Editor.php. Smileys loaded too, I think.

sangwe11

Ok, and the context variables for them are ?

$context['bbc'] and $context['smiley'] ?

Arantor

$context['bbc_tags'] for the first, but it's populated in Subs-Editor.php in the very function you should be calling.

$context['smileys'] for the second, but again is populated in Subs-Editor.php in create_control_richedit. It might be worth you looking through that function.

sangwe11

Well until someone finds a way on how to do it properly, I'm going to use my method.

It now gets the BBC array from the subs-editor, along with the smiley array, and looks like the original bbc editor, and works the same :D


Marcus Forsberg

Quote from: sangwe11 on November 14, 2009, 01:12:15 PM
<div id="page_content_box">', template_control_richedit('page_content_box', 'bbc') ,'</div>

What happens if you use this:

<div id="page_content_box">', template_control_richedit_buttons('page_content_box', 'smileyBox_message', 'bbcBox_message');</div>

Then add a div with id "smileyBox_message" and one with id "bbcBox_message". Should display smileys and BBCs properly, if I understood it right.

sangwe11

ohhh !

was I suppose to be adding divs for them too ?

haha !

that might be why it wouldn't work !!

sangwe11

hmm, now all I get is the submit and preview boxes .. now message, bbc or smiley box.

edit:

fixed by removing the _buttons part at the end ..

now to add in the buttons again, as removing the _buttons removes the buttons lawl.

also, none of the buttons actually do anything, they just show.

Marcus Forsberg

Oh well, it was quite a while ago I worked on this. Will look at it when time allows and get back here.

sangwe11

Quote from: Nas on November 14, 2009, 03:55:24 PM
Oh well, it was quite a while ago I worked on this. Will look at it when time allows and get back here.

Which mod was it ?

I *could* (with permission :D) look through the source code, and see how you did it.

Marcus Forsberg

Actually, it wasn't a mod. I just looked at it without ever doing anything with it, for whatever reason. :P

sangwe11

Quote from: Nas on November 14, 2009, 03:59:30 PM
Actually, it wasn't a mod. I just looked at it without ever doing anything with it, for whatever reason. :P

Oh ok ...

Well I do have a working version, so I'll go with that for now (will keep the code you suggested that almost works in a separate file for later use)

And if / when I or you figure out whats missing, I'll swap the code over, seeing as the proper way is under 1/8 of the size of the "hackish" way.

Marcus Forsberg

I figured the basics out, but not the preview function. Plus, it doesn't do a thing when you hit "Submit" :P

Source file:

// Needed for the editor and message icons.
require_once($sourcedir . '/Subs-Editor.php');

// Now create the editor.
$editorOptions = array(
'id' => 'page_content_box',
'value' => '',
'labels' => array(
'post_button' => 'Save/Submit/Whatever/',
),
// We do XML preview here.
'preview_type' => 2,
);
create_control_richedit($editorOptions);

// Store the ID.
$context['post_box_name'] = $editorOptions['id'];


Template file:

echo'<div id="bbcBox_message"></div>';
echo'<div id="smileyBox_message"></div>';

echo template_control_richedit($context['post_box_name'], 'smileyBox_message', 'bbcBox_message');

echo'
<span class="smalltext"><br />', $context['browser']['is_firefox'] ? $txt['shortcuts_firefox'] : $txt['shortcuts'], '</span><br />
', template_control_richedit_buttons($context['post_box_name']);


I'll be back.

Marcus Forsberg

Oh, stupid me. You don't have to do anything special to make it post, except adding a <form> tag with action="bla" .. :P
* Nas slaps self

sangwe11

Quote from: Nas on November 15, 2009, 09:56:52 AM
Oh, stupid me. You don't have to do anything special to make it post, except adding a <form> tag with action="bla" .. :P
* Nas slaps self

Rofl !!! :D

Generally helps.

Btw, are the bbc buttons working ?

I got them to show before, but they didn't do anything when clicked.

Marcus Forsberg


sangwe11

Quote from: Nas on November 15, 2009, 10:00:25 AM
Yes, works fine for me. Try the code ;)

Will do :D

And as for the preview, do we have to add another function or something ?

Marcus Forsberg

Not sure how it works. Looking at it now.
You might want to look at Post.php and Post.template.php yourself too, to see if you find it.

Arantor

Might need to make sure $settings['default_theme_url'] . '/scripts/editor.js' is loaded.


EDIT: Or not.

To make the preview work you need to add a bunch more stuff, like a new subaction, ensure that it spits out XML... basically, see what the post action and preview does.

sangwe11

Any luck with the preview yet ?

I haven't had a chance to look, been busy with expressions and making my parsing function simpler.

Arantor

See above: it's not just a simple thing. You need to have an action or subaction whose job it is to make the preview and output it via XML, plus some JS to actually send the data to the action/subaction in the first place, then some more JS to display it.

In short, what the post code does...

sangwe11

#36
Just tried your code Nas, and couldn't get it to display any BBC buttons.

Not sure what I've done wrong, I'll try to figure it out.

Nevermind .. silly mistake. . was require_once'ing the file twice >.<

Advertisement: