Invenzzia »

Pages: [1]   Go Down
  Print  
Author Topic: OPT: About plugins  (Read 2085 times)
Description: how i can make plugins?
0 Members and 1 Guest are viewing this topic.
turbex
User

Offline Offline

Posts: 4


View Profile
« on: August 21, 2008, 17:55:42 »

hello... i download OPT1.5  -OPT2.0 not because i only understant english so so-
well... exists any manual to make plugins for OPT....i dont understand how...

thanks...
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #1 on: August 21, 2008, 19:51:25 »

Hi,

of course - you can find everything in the manual. For OPT 1.1.5, it is all in English. The process looks much like in Smarty: you create a file with a special name, put it in the plugin directory and OPT loads it at startup. Of course, this file must contain the necessary PHP code which depends on the plugin type.

For example, if you want to add a new OPT function, you create a file function.Foo.php with the content:

Code:
<?php

  
function optFoo(optClass $tpl$someArgs)
  {
      
// some PHP code here
  
// end optFoo();

?>


Just remember that the filename must be fully correct, because there are quite strict rules, how the file name is translated into the registered item name in OPT arrays.

And BTW, here is the link: http://www.invenzzia.org/docs/opt-en/extending.html

If you have any exact questions, just ask, I'll try to help.
Logged

PozDrX, Zyx
---Invenzzia group---
turbex
User

Offline Offline

Posts: 4


View Profile
« Reply #2 on: August 22, 2008, 00:48:09 »

ok... well...

first... i set the plugin directory...
i create my plugin... file: function.include_js.php
Code:
<?php
function 
optinclude_js(optClass $tpl$someArgs)
{
return 'all its ok';
}
?>


in my template.... i insert this for test...
Code:
<html>
<head></head>
<body>
{include_js}
</body>
</html>

but... not works...i see a error...

my idea is make a thing like this:
{js_include src="my_file.js"}

and this return:
<script language='javascript' type='text/javascript' src='my_file.js'></script>

can you help me please?
« Last Edit: August 22, 2008, 00:52:39 by turbex » Logged
eXtreme
Invenzzia
Administrator
User
*****
Offline Offline

Posts: 129

Jacek Jędrzejewski


View Profile WWW
« Reply #3 on: August 22, 2008, 08:00:01 »

It is a function. And function looks like normal PHP function even in templates. So correct call looks like this:

Code:
some html

{include_js('arg')}

some html

To make your idea ({js_include src="my_file.js"}) work you have to make an Instruction, not a function.

I haven't tested this code but it should work:

make file instruction.js_include.php with content:
Code:
<?php
class 
js_include extends optInstruction
{

public function configure()
{
return array(
=> 'js_include',
'js_include' => OPT_COMMAND
);
// end configure();

public function instructionNodeProcess(ioptNode $node)
{
$block $node->getFirstBlock();
$params = array(
'src' => array(OPT_PARAM_REQUIREDOPT_PARAM_STRING),
);
$this->compiler->parametrize('js_include'$block->getAttributes(), $paramsOPT_STYLE_XML);

$this->compiler->out(' echo \'<script language="javascript" type="text/javascript" src="'.$params['src'].'"></script>\'; ');

// end instructionNodeProcess();
}

remember to delete compile.php and plugins.php in your plugins/ directory.
« Last Edit: August 22, 2008, 08:01:38 by eXtreme » Logged

turbex
User

Offline Offline

Posts: 4


View Profile
« Reply #4 on: August 22, 2008, 16:00:16 »

hi... well.... your example works... thanks!!!

but.... if i need pass a var in the param??

{js_include src="$myvar"}

what is the correct way... because this not works...

thanks for your time.
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #5 on: August 22, 2008, 18:06:35 »

Take a look at this line:

Code:
'src' => array(OPT_PARAM_REQUIRED, OPT_PARAM_STRING),

The second constant defines the requested type. Here is the full description:

http://www.invenzzia.org/docs/opt-en/extending.instructions.parameters.html

For this particular example, you have to choose between OPT_PARAM_EXPRESSION and OPT_PARAM_ASSIGN_EXPR. The first one does not allow to use the assignment operator, like $a is 5, the second one - allows.

This class is executed only during the template compilation and during the execution, the produced PHP code works, so you have to change also the following line:

Code:
$this->compiler->out(' echo \'<script language="javascript" type="text/javascript" src="'.$params['src'].'"></script>\'; ');

If you changed the parameter type and made {js_include src="$myvar"}, this will be compiled into:

Code:
echo '<script language="javascript" type="text/javascript" src="$this->data['myvar']"></script>';

Obviously, it's not even a valid PHP code! You must teach the instruction, how to enclose the expression in the quotes:

Code:
$this->compiler->out(' echo \'<script language="javascript" type="text/javascript" src="\'.'.$params['src'].'.\'"></script>\'; ');

But remember that if you have a statically defined file, you must also enclose it in the quotes in the template:

Code:
{js_include src="'some_file.js'"}

I know it's a disadvantage, but in OPT 1.x there was little I could do. The expression is expression, like in PHP - here you also can't write very long texts without quotes and OPT must know where the attribute value ends (which gives you the double quote). In OPT 2.0 and XML, this was solved with namespaces:

Code:
<opt:js_include str:src="some_file.js" /> or <opt:js_include src="$myvar" />
Of course you can always write <opt:js_include src="'some_file.js'" />
Logged

PozDrX, Zyx
---Invenzzia group---
turbex
User

Offline Offline

Posts: 4


View Profile
« Reply #6 on: August 22, 2008, 19:33:22 »

thanks...

other thing... exists a manual of opt2.0 in english... ??
Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #7 on: August 22, 2008, 19:58:13 »

This time we started with Polish version, because the library is the most popular in Poland, and some of the users have problems with English. Currently, the English version is not started yet, but I expect to begin the translation soon. I can assure you that the first stable release will arrive with fully completed text. What is more, the rest of OPL libraries will have English docs first.
Logged

PozDrX, Zyx
---Invenzzia group---
Pages: [1]   Go Up
  Print  
 
Jump to:  

Subject Started by Replies Views Last post
OPTv2: Problem z JS masterix 5 1278 Last post April 08, 2009, 19:02:18
by Zyx
New website announcement Zyx 0 809 Last post January 24, 2011, 13:45:11
by Zyx
OPTv2: TinyMCE w optv2 Zbycho 2 514 Last post January 03, 2010, 11:43:41
by Zbycho