Kunena 6.3.5 released

The Kunena team has announce the arrival of Kunena 6.3.5 [K 6.3.5] in stable which is now available for download as a native Joomla extension for J! 4.4.x/5.0.x/5.1.x. This version addresses most of the issues that were discovered in K 6.2 / K 6.3 and issues discovered during the last development stages of K 6.3
Note: Please go to the Kunena Dashboard after an upgrade so that the Kunena database tables are also updated.

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

Question Add Button to BBCode Editor

More
5 years 4 months 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
5 years 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.

More
5 years 3 weeks ago - 5 years 3 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();
$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: 5 years 3 weeks ago by rich. Reason: Advertising removed

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

Time to create page: 0.435 seconds