Roundcube Community Forum

Miscellaneous => Roundcube Discussion => Topic started by: flash on August 09, 2006, 12:18:02 PM

Title: inserting new variable in a skin
Post by: flash on August 09, 2006, 12:18:02 PM
I would like to take a $variable that I have set in a mod to index.php and insert that $variable value in a html skin file. What is the syntax to do the variable insertion in the skins. For example, in a normal php file you could use in the html:

What do you insert in the skin files in roundcube to display the php variable?
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 10, 2006, 10:14:23 AM
I'm gonna look into the templating system today. If I find out, I'll let you know ;)
Title: not sure I am any closer
Post by: flash on August 10, 2006, 07:38:13 PM
It appears that the $variable needs to be converted to


I can see, for example
$rcmail_config['product_name']
in the config file becomes


I have found the object handlers in main.inc (and have found the example above), but the process is very confusing. Documentation would be good.
Title: getting closer
Post by: flash on August 10, 2006, 08:07:45 PM
I am posting this as I get through it so there will be some documentation for others.

This function in main.inc does the replacement

function parse_rcube_xml($input)
 {
 $output = preg_replace('/]+)>/Uie', "rcube_xml_command('\\1', '\\2')", $input);
 return $output;
 }

Then you have to make your way though this function, also in main.inc

function rcube_xml_command($command, $str_attrib, $add_attrib=array())

to go through each command type (of which object is one). now I just have to figure out how to load one.

This seems quite complex for such a simple task.

It would be easy at this point just to code a translation for the object to my $variable in that function, but I am trying to fit into the RC structure and not make any mods in main.inc. So I need to figure out where to load $variable, or to say it clearer, what array to load it into. At least I think that is how to make it work with the structure.
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 10, 2006, 08:10:39 PM
Well... it's not as complex as you think....

Basically, it's a template parsing script that takes tags and their items and creates HTML code out of it. If you just take your time, and follow some of the ones already laid out in the template (like include or script) you'll soon find yourself learning the parsing script.
Title: Re: inserting new variable in a skin
Post by: flash on August 10, 2006, 08:18:19 PM
I think you posted while I was editing mine above.

If it is not as complex as I think . . . then someone would have been able to demonstrate how to do it with a simple example ;D
Title: done
Post by: flash on August 10, 2006, 08:32:27 PM
OK, my conclusion is that you cannot take a variable set on entry into index.php and ONLY edit a skin .html file and have the value be in that skin. It appears to me that all object translation relationships are in fact coded, and that this simple task would require an additional mod to main.inc to make this work.

I don't want to keep changing more and more of these scripts. Adding values like that is not worth the hassle of constant changes to scripts just to add the value and then again with future upgrades.

If someone thinks my analysis is wrong, please post.

For others who want to add values in the skins, you now have the documentation to do that in this thread.
Title: I went ahead and did it
Post by: flash on August 13, 2006, 01:55:43 PM
I went ahead and did this. One trick, don't forget the global. Here is the line I added to main.inc to make it work.

if ($object == "returnlink") { global $returnLink; return $returnLink; }  // this line is a customization

Also note that the code will make the $object lower case (took a while to find that one). So in my case above the object is returnlink and the variable is $returnLink

There are several tricks to doing this. But, like everything else, once you know how . . .

So just to recap:

1) You set a variable in index.php to what you want
2) You put a roundcube include in the skin
3) You add a translation line in main.inc for the variable
Title: <?
Post by: flash on August 13, 2006, 06:16:48 PM
You can specify short tags in the php.ini file. Every host I have seen so far let's you control a custom php.ini file if you wish to use one. I always do. But that is a moot point here, as that method does not work with the RC skins.

php.net just says that because the default php.ini file they ship with the distribution has that feature turned off. There is nothing wrong with using it. I suspect it is turned on with almost every server out there (every one I have seen). Obviously yours is an exception. Use a custom php.ini file. There are many settings you should consider changing anyway just for security reasons.

But . . . that is not the topic of this thread. So let's not wander off to unrelated topics.
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 13, 2006, 07:05:13 PM
Quote
php.net just says that because the default php.ini file they ship with the distribution has that feature turned off.
That's not true... when working with XML, the XML start string is similar to PHP "
While this isn't on topic, it should be discussed here because you brought up a more unacceptable code technique. Specifically, with Roundcube, I don't see short-tags, and thus when developing mods/skins/plug-ins for it, you should follow the coding standards and not use short tags as well. This will ensure that any customization you make will work, not matter what, on any PHP enabled server without any chance of XML interference.

Anywho... glad to hear you got the variable addition sorted... But there is an easier way ;) Just thought of it too ;) Gonna submit it as a Patch.

[tutorial=Inserting Variables]
[step=1]Open /program/includes/main.inc[/step]
[step=2]Inside the function rcube_xml_command look for the large switch() statement.[/step]
[step=3]After the case 'object': statement, add the following:
case 'variable':
global ${$attrib['name']};
return ${$attrib['name']};
break;[/step]
[step=4]Open /index.php[/step]
[step=5]Add your variables...[/step]
[step=6]Open /skins/default/*.html
Whatever files you want the vars in[/step]
[step=7]Add it in the following manner:
Code: [Select]
<roundcube:variable name=&quot;myVariableName&quot; />[/step]
[step=8]Save all files and upload[/step][/tutorial]

Hope that helps you.... and it's much cleaner than hacking away ;)
Title: Re: inserting new variable in a skin
Post by: flash on August 13, 2006, 08:01:37 PM
That is prertty much what I did. Glad I could show you the way ;D

Yes, what you coded is more generic ;)

But . . . remember the name must be lower case to match. Your example would not work.
Title: Re: inserting new variable in a skin
Post by: flash on August 13, 2006, 08:16:16 PM
Just tested it. Works great as long as the name is all lower case. Good thinking to make this more generic Brett. Now you don't have to code each one if you use more than one.
Title: Re: inserting new variable in a skin
Post by: flash on August 13, 2006, 09:21:56 PM
Quote from: Brett
While this isn't on topic, it should be discussed here because you brought up a more unacceptable code technique. . . . Most servers I work with have been secured and PHP.ini uncustomizable.
I suppose we could debate the value of webhosts that do not let you secure your site by making improvements to the php.ini file (like directing to your own sessions and upload directories). Yes you could so stupid things. But I would not use a host that forces me to use THEIR stupid things.

As for the acceptability of coding techniques . . .
But the point has already been made that standard php variable insertion does not work with RC skins anyway. So the rant that has started here is of no value to anyone. But since you kept is going . . .
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 13, 2006, 10:35:04 PM
Quote
But . . . remember the name must be lower case to match. Your example would not work.
The variable name doesn't have to be lowercase. The command name "variable" doesn't have to be lower case. It works fine with mixed case.

So in your case, your code would look like:
Code: [Select]
<roundcube:variable name=&quot;returnLink&quot; />
For further clarification....

Here's how the template works:

Quote
command attribute="value" />

When interpreted, the command and attribute array is sent to rcube_xml_command. In rcube_xml_command the command is lowercased:
$command = strtolower($command);
and then a switch occurs based upon that command. So if you used any of the following, you'd still get the same command firing:
Code: [Select]



this way numerous "skinners" can create their own skin and not have to cater directly to the coding standards we have in case they're more comfortable with a specific coding practice.

Once the command is fired, my command interpreter just takes the variable name, and sees if it's there as is. So "myVar" is different from "myvar" is different from "MYVAR" etc. What could be added (although I won't as it shouldn't be necessary) is the ability to look for the variable in upper and lower cases.

I hope that clears up the issue of being case-sensitive.

_________________________________________________
Quote
As for the acceptability of coding techniques . . .
The XML issue was just one off of the top of my head. But typically, those that will use roundcube will not know PHP or even how to change things. So as guaranteed to be working in all installations of PHP where
Title: lower case
Post by: flash on August 14, 2006, 11:45:33 AM
Here is the first section of the routine from main.inc:

function rcube_xml_command($command, $str_attrib, $add_attrib=array())
 {
 global $IMAP, $CONFIG, $OUTPUT;
 $command = strtolower($command);
.... continues

as you can see, the first thing it does is convert the command name to lower case. so it is only the command in the code in main.inc that is used for the test needs to be lower case. and your code has that (variable in this case).

sorry for the confusion. I remembered when I was testing that something had to be lower case, I just got confused as to what it was. sorry :-[
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 14, 2006, 11:53:57 PM
Quote
as you can see, the first thing it does is convert the command name to lower case. so it is only the command in the code in main.inc that is used for the test needs to be lower case. and your code has that (variable in this case).
You and I were talking about two different things. You were saying in main.inc while I was speaking of inside the template files. So to clear this up...

Inside of main.inc the command MUST be lowercased in the switch statement. Inside of the template files you can use any case you choose and the command will be fired, as long as it's spelled correctly ;)
Title: Re: inserting new variable in a skin
Post by: tuney on August 22, 2006, 06:21:10 PM
Is there a way to add php into a template ?
Title: Re: inserting new variable in a skin
Post by: bpat1434 on August 22, 2006, 07:15:04 PM
No. Each template is parsed in PHP but only for
Title: Re: lower case
Post by: davido on December 06, 2007, 12:54:34 AM
Quote from: flash
Here is the first section of the routine from main.inc:

function rcube_xml_command($command, $str_attrib, $add_attrib=array())
 {
 global $IMAP, $CONFIG, $OUTPUT;
 $command = strtolower($command);
.... continues

as you can see, the first thing it does is convert the command name to lower case. so it is only the command in the code in main.inc that is used for the test needs to be lower case. and your code has that (variable in this case).

sorry for the confusion. I remembered when I was testing that something had to be lower case, I just got confused as to what it was. sorry :-[

The new RC2 has no function rcube_xml_command($command, $str_attrib, $add_attrib=array()). So how can you do it on the new RC2. What i want is to add a new menu on the task bar.

i have added $MAIN_TASKS = array('mail','sometest','settings','addressbook','logout');

Some test displays with out an icon.

How can i add menu to the task bar.

Thanks
Title: Re: inserting new variable in a skin
Post by: bpat1434 on December 06, 2007, 09:11:38 AM
It's in program/includes/rcmail_template.inc on line 440. That's the same function except it's in a class instead of procedural style code.