Page 1 of 1

Editor-xtd button plugin

Posted: Thu Oct 28, 2010 11:21 am
by gubagy
Hi guys,

After several years of fascination with Joomla! I took the decision to get my hand dirty in code and programming. The last time when had written something that a computer can understand was for 8 bit computers when was teenager :D . So i made free time and got into PHP - I loved it ! and consequently I bought a book (according to the authors) Professional guide to programming Joomla!. Everything was going fine up to the moment i decided to test the provided code. It was broken !!! :eek: a real "Professional guide" !

It is a Editor-xtd button plugin and that is the PHP code:

Code: Select all

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

$mainframe->registerEvent('onCustomEditorButton', 'plgSmileyButton');

/**
 * Smiley button
 *
 * @name string Name of the editor
 * @return array Array of three elements: JavaScript action, Button name, CSS class.
 */
function plgSmileyButton($name)
{
    global $mainframe;

    // get the image base URI
    $doc =& JFactory::getDocument();
    $url = $mainframe->isAdmin() ? $mainframe->getSiteURL() : JURI::base();
    
	// get the JavaScript
    $js = "
    function insertSmiley()
    {
        jInsertEditorText(' :) ');
    }
    ";

    $css = "    .button1-left .smiley { background: url($url/plugins/editors-xtd/smiley1.gif) 100% 0 no-repeat; }";
    $css .= "\n    .button2-left .smiley { background: url($url/plugins/editors-xtd/smiley2.gif) 100% 0 no-repeat; }";
    $doc->addStyleDeclaration($css);
    $doc->addScriptDeclaration($js);
    $button = array("insertSmiley()", JText::_('Smiley'), 'smiley');

    return $button;
}

?>
Here the xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<install version="1.5.0" type="plugin" group="editors-xtd" method="upgrade">
	<name>Button - Smiley</name>
	<author>Box Office Software</author>
	<authorEmail>[email protected]</authorEmail>
	<authorUrl>www.packtpub.com</authorUrl>
	<copyright>Copyright (C) 2009 </copyright>
	<creationDate>November 14, 2009</creationDate>
	<description>This plugin adds</description>
	<license>GNU/GPL</license>
	<version>1.07.00</version>
	
	<files>
		<filename plugin="smiley">smiley.php</filename>
		<filename>smiley1.gif</filename>
		<filename>smiley2.gif</filename>
	</files>
	
	<params />

</install>
and that is the error:

Code: Select all

( ! ) Fatal error: Call to undefined method stdClass::onDisplay() in C:\wamp\www\joomla\libraries\joomla\html\editor.php on line 268
Call Stack
#	Time	Memory	Function	Location
1	0.0004	348920	{main}( )	..\index.php:0
2	0.1325	3984088	JAdministrator->dispatch( )	..\index.php:67
3	0.1397	4515696	JComponentHelper->renderComponent( )	..\application.php:136
4	0.1495	4635456	require_once( 'C:\wamp\www\joomla\administrator\components\com_content\admin.content.php' )	..\helper.php:162
5	0.1609	5698280	ContentController->editContent( )	..\admin.content.php:42
6	0.2866	6329320	ContentView->editContent( )	..\controller.php:451
7	0.3506	6829640	JEditor->display( )	..\admin.content.html.php:513
8	0.3506	6830520	JEvent->update( )	..\editor.php:152
9	0.3506	6831200	call_user_func_array ( )	..\event.php:67
10	0.3506	6831240	plgEditorTinymce->onDisplay( )	..\event.php:0
11	0.3507	6832408	plgEditorTinymce->_displayButtons( )	..\tinymce.php:627
12	0.3511	6834736	JEditor->getButtons( )	..\tinymce.php:684
How you can guess in is not about the plugin itself but it really bugs me why it breaks. According to the author that is legitimate way for writing an editor-xtd plugins -> Obviously not :)


Any help highly appreciated

Thanks in advance

Cheers,
Guby

Re: Editor-xtd button plugin

Posted: Mon Dec 06, 2010 3:07 pm
by stushev
http://tushev.org, go to Articles->Programming

Re: Editor-xtd button plugin

Posted: Mon Dec 06, 2010 4:38 pm
by gubagy
stushev wrote:http://tushev.org, go to Articles->Programming
I looked at your article and realized I will need more than 2 min.Thanks Man or should I say Болшое Спасибо ;)