将自定义按钮添加到Joomla的文章编辑器(TinyMCE)

时间:2012-12-06 12:22:48

标签: php tinymce joomla2.5 joomla3.0 joomla-extensions

我正在尝试在Joomla的文章编辑器中插入一个额外的按钮。它在扩展模式下使用默认的TinyMCE插件。您已经知道编辑器下面有4个按钮(文章,图像,分页和阅读更多)。我想做的是插入第5个按钮。 (我确实附上了一个图像按钮,所以说我不能发布,因为需要至少10个重复点。)

我曾尝试复制分页按钮插件并重命名等,然后将其重新安装为新插件,但所有这一切都会导致TinyMCE出现错误,并且不会显示任何按钮。

问题:如何插入按钮?

2 个答案:

答案 0 :(得分:8)

我继续进行广泛的搜索,并找到了为Joomla 1.5的文章编辑器添加额外按钮的指南。

该教程位于:http://tushev.org/articles/programming/18-how-to-create-an-editor-button-editors-xtd-plugin-for-joomla

开箱即用,这对于Joomla 2.5和Joomla 3.0无效,因为XML清单标准已经发生了如此微小的变化。与教程保持一致,改为使用此XML清单。

<?xml version="1.0" encoding="utf-8"?>
<extension version="2.5" type="plugin" method="upgrade" group="editors-xtd">
        <name>test</name>
        <author>Name</author>
        <creationDate>Month 2013</creationDate>
        <copyright>Month Name. All rights reserved.</copyright>
        <license>GPL</license>
        <authorEmail>Email</authorEmail>
        <authorUrl>Your URL</authorUrl>
        <version>1.0.0</version>
        <description>
            "adds the button 'test' to the editor"
        </description>
        <files>
            <filename plugin="test">test.php</filename>
        </files>
</extension>

教程PHP是正确的,如下所示:

<?php

 // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );

class plgButtonTest extends JPlugin {

    function plgButtonTest(& $subject, $config)
    {
        parent::__construct($subject, $config);
    }
    function onDisplay($name)
    {
        $js =  "                      
         function buttonTestClick(editor) {
                             txt = prompt('Please enter something','123');
                             if(!txt) return;
                               jInsertEditorText('{test '+txt+'}', editor);
        }";
        $css = ".button2-left .testButton {
                    background: transparent url(/plugins/editors-xtd/test.png) no-repeat 100% 0px;
                }";
        $doc = & JFactory::getDocument();
        $doc->addScriptDeclaration($js);
        $doc->addStyleDeclaration($css);
        $button = new JObject();
        $button->set('modal', false);
        $button->set('onclick', 'buttonTestClick(\''.$name.'\');return false;');
        $button->set('text', JText::_('Test'));
        $button->set('name', 'testButton');
        $button->set('link', '#');
        return $button;
    }
}
?>

谢谢大家的帮助。如果您有任何其他更好的方法,我将非常感激。

答案 1 :(得分:4)

如果您的插件安装成功,那么您必须将插件名称放入 Custom plugin插件中高级参数设置中的Custom buttontinymce。并确保您安装的插件是发表。例如,见下图。

这是我的自定义插件已设置为启用。请看这个图片: enter image description here

然后在tinymce插件中转到高级参数,最后看到有自定义字段选项。请看这张图片:

enter image description here

输入插件名称和按钮名称。在文章管理器编辑器中找到您的按钮。

相关问题