Including the Posting editor in custom page

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Autumn Shade
Registered User
Posts: 29
Joined: Thu May 30, 2019 12:38 pm

Including the Posting editor in custom page

Post by Autumn Shade » Thu Jun 20, 2019 11:41 am

Greetings, what I want to do is include the bbcode editor in my own custom page, created in extension, for replies. How can I include the editor, without breaking the whole phpbb?

User avatar
david63
Registered User
Posts: 16172
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Including the Posting editor in custom page

Post by david63 » Thu Jun 20, 2019 1:35 pm

You can probably <!-- INCLUDE posting_editor.html --> to get the template on your page and use that in conjunction with includes/functions_posting.

You should look at how it is done within the core for some guidance posting.php and posting_layout.html
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
Autumn Shade
Registered User
Posts: 29
Joined: Thu May 30, 2019 12:38 pm

Re: Including the Posting editor in custom page

Post by Autumn Shade » Fri Jun 21, 2019 6:13 am

I've tried including it, though something is missing. Anyways, will go through the posting functions. I was going to do this since the beginning, though just wanted to ask if somebody already has encountered the problem

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1047
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Including the Posting editor in custom page

Post by mrgoldy » Fri Jun 21, 2019 6:47 pm

If it's on your custom page, depending if you altered the header aswell, you might to include a few more things.
Core.js and editor.js (editor.js is included from posting_buttons.html automatically) should be included, and ajax.js if you want to automatically resize a textarea.
For the posting buttons to show up properly you have to define a couple of template variables aswell as a PHP function.
Same for smilies, you need to define a few template variables and run a PHP function.

Code: Select all

include_once $this->root_path . 'includes/functions_display.' . $this->php_ext;
include_once $this->root_path . 'includes/functions_posting.' . $this->php_ext;

$this->language->add_lang('posting');

display_custom_bbcodes();
generate_smilies('inline', 0);

$this->template->assign_vars([
	'S_BBCODE_ALLOWED'	=> true,
	'S_BBCODE_IMG'		=> true,
	'S_BBCODE_QUOTE'	=> true,
	'S_BBCODE_FLASH'	=> true,
	'S_LINKS_ALLOWED'	=> true,

	'S_SMILIES_ALLOWED'	=> true,
]);

Code: Select all

<script>
{# Used by editor.js #}
let form_name = 'your_form',
	text_name = 'your_textarea';
</script>

<form id="your_form" name="your_form">
	<textarea id="your_textarea" name="your_textarea"></texteara>
</form>
I believe the js variables should be the name attributes of your form and textarea. But what I usually do is give them the same id attribute anyway.
phpBB Studio / ''Proud member of the Studio"

User avatar
Autumn Shade
Registered User
Posts: 29
Joined: Thu May 30, 2019 12:38 pm

Re: Including the Posting editor in custom page

Post by Autumn Shade » Tue Jun 25, 2019 6:58 am

Alright, so I got this working with the help from goldy and 3Di, although the only thing it does is visualize only and not function. Like, if I use any of the bbcode and post it, then it will just show up with the bbcode in the post. Let me give you an example:

Image
https://github.com/stfkolev/PHPBB-Requests

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1047
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Including the Posting editor in custom page

Post by mrgoldy » Tue Jun 25, 2019 8:16 am

Yes. I would really suggest looking at other extensions that already stuff like this. Usually that's the easiest way to solve your issues..

You need to use phpBB's s9e TextFormatter. When submitting the post, request the message and put it through \phpbb\textformatter\s9e\parser::parse($message). Save it in the database, as xml.
Then when displaying the post, get the xml and put it through \phpbb\textformatter\s9e\renderer::render($xml). This will give you the HTML display. If you want to show the message for edit, you put it through \phpbb\textformatter\s9e\utils::unparse($xml).

The formatter classes can be injected as services, with - '@text_formatter.parser', - '@text_formatter.renderer' and - '@text_formatter.utils'

https://s9etextformatter.readthedocs.io/
phpBB Studio / ''Proud member of the Studio"

User avatar
Autumn Shade
Registered User
Posts: 29
Joined: Thu May 30, 2019 12:38 pm

Re: Including the Posting editor in custom page

Post by Autumn Shade » Tue Jun 25, 2019 9:08 am

I see. You're awesome. Greets! Thank you for the help

Post Reply

Return to “Extension Writers Discussion”