Kunena 5.2 Beta 1 Released (24 Sep 2020)

The Kunena team is thrilled to announce the first public beta release of Kunena 5.2, a native Joomla extension for Joomla 3.9. This is a development release and should be only be used for testing; this version is not recommended for live websites at this stage.

The purpose of this release is to encourage testing by downloading, installing and identifying any problems or shortcomings that people may discover. K 5.2.0 B1 is stable and we are aware that people will discover defects. We encourage you to use the forum to report defects, as soon as they are discovered, so that the development team can work through the problems before the release of K 5.1 as a stable product. Reporting defects does not mean that the problems can or will be fixed. The Kunena team is looking forward to hearing your feedback on how well we have achieved our design goals.

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

Question Add Button to BBCode Editor

1 year 4 months ago #1 by cgwarder
Hi. I am using Kunena 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.

1 year 4 months 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.

1 year 4 weeks ago - 1 year 4 weeks 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();
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 year 4 weeks 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.092 seconds