×
Kunena 5.1.14 Released - Security release (13 Aug 2019)

The Kunena team is proud to announce the arrival of Kunena 5.1.14 [K5.1.14] which is now available for download as a native Joomla extension for Joomla 3.9.x. This version addresses most of the issues that were discovered in K 5.1 and issues discovered during the development stages of K 5.1.14. This update fixed 1 security issue.

× Please note: The Kunena project team takes NO responsibility for maintaining nor supporting anything in this category.

Question Add Button to BBCode Editor

More
3 months 3 weeks ago #1 by cgwarder
Hi. I am using Kunena 5.1.12.1. I would like to add a button to the Kunena BBCode Editor. Any information would be appreciated, what files to change, etc. I am using the default template Crypsis template.
The following user(s) said Thank You: raquell_vazquez

Please Log in or Create an account to join the conversation.

More
3 months 1 week ago #2 by JPike
Replied by JPike on topic Add Button to BBCode Editor
I am also interested in doing something similar like putting a button to call out to an api service

Please Log in or Create an account to join the conversation.

More
1 day 16 hours ago - 1 day 14 hours ago #3 by hertavein
look near the top of the edit.php file we copied to our template, we'll find these two lines of code:

$editor = KunenaBbcodeEditor::getInstance();
$editor->initialize('id');
It's in the initialize method where the xml file is read and the buttons rendered. So why not create our own override of the KunenaBbcodeEditor class so we can use our own custom xml file?

First copy the xml file into the same folder as the earlier mentioned edit.php file:

/libraries/kunena/bbcode/editor.xml => /templates/<YOURTEMPLATE>/html/com_kunena/topic/cuseditor.xml

Then, create a new php file in this directory named cuseditor.php.

The cuseditor.php file is where we'll create our own version of the editor class, like so:

defined('_JEXEC') or die();
class CusBbcodeEditor extends KunenaBbcodeEditor {}

There are two methods we need to change for our purposes. First the ::getInstance() method. Copy the code from the original class using our new class name for the instance:


public static function getInstance($config = array()) {
static $instance = false;
if (!$instance) {
$instance = new CusBbcodeEditor($config);
}
return $instance;
}
Note the only change we're making is to return our new CusBbcodeEditor class object.

The method we really care about is the initialize method that reads in the xml button definitions. Again copy the code from the original and make one small change to load our copied version:

{codecitation width="650px"} public function initialize($identifier='class') { $js = "window.addEvent('domready', function() { kbbcode = new kbbcode('kbbcode-message', 'kbbcode-toolbar', { dispatchChangeEvent: true, changeEventDelay: 1000, interceptTab: true });\n"; $xml_file = simplexml_load_file(dirname(__FILE__).'/cuseditor.xml'); $this->editor_elements = self::parseXML($xml_file); //Hook to manipulate the Editor XML like adding buttons $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('kunena'); $dispatcher->trigger( 'onKunenaBbcodeEditorInit', array ( $this ) ); foreach ($this->editor_elements as $item) { $js .= $item->generateJs($identifier); } $js .= "});\n"; $template = KunenaTemplate::getInstance(); $template->addScript('js/editor.js'); JFactory::getDocument()->addScriptDeclaration( "// "); } {/codecitation}

Note again only one small change to read the renamed xml file from the same directory as our new cuseditor.php.

Our next to final step is to have the template override use our new class. In the edit.php template override, replace this line:

$editor = KunenaBbcodeEditor::getInstance();
With these two lines:

require_once __DIR__ . '/cuseditor.php';
$editor = CusBbcodeEditor::getInstance();
You are now using your own customized version of Kunena's BBCode editor with minimal changes and no core edits
Last edit: 1 day 14 hours ago by rich. Reason: Advertising removed

Please Log in or Create an account to join the conversation.

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to edit your message.
Time to create page: 0.065 seconds