Author Topic: inserting new variable in a skin  (Read 7158 times)

Offline flash

  • Jr. Member
  • **
  • Posts: 49
inserting new variable in a skin
« 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?

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: inserting new variable in a skin
« Reply #1 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 ;)
 
  

Offline flash

  • Jr. Member
  • **
  • Posts: 49
not sure I am any closer
« Reply #2 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.

Offline flash

  • Jr. Member
  • **
  • Posts: 49
getting closer
« Reply #3 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.

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: inserting new variable in a skin
« Reply #4 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.
 
  

Offline flash

  • Jr. Member
  • **
  • Posts: 49
Re: inserting new variable in a skin
« Reply #5 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

Offline flash

  • Jr. Member
  • **
  • Posts: 49
done
« Reply #6 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.

Offline flash

  • Jr. Member
  • **
  • Posts: 49
I went ahead and did it
« Reply #7 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

Offline flash

  • Jr. Member
  • **
  • Posts: 49
<?
« Reply #8 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.

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: inserting new variable in a skin
« Reply #9 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 ;)
 
  

Offline flash

  • Jr. Member
  • **
  • Posts: 49
Re: inserting new variable in a skin
« Reply #10 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.

Offline flash

  • Jr. Member
  • **
  • Posts: 49
Re: inserting new variable in a skin
« Reply #11 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.

Offline flash

  • Jr. Member
  • **
  • Posts: 49
Re: inserting new variable in a skin
« Reply #12 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 . . .

Offline bpat1434

  • Administrator
  • Hero Member
  • *****
  • Posts: 673
Re: inserting new variable in a skin
« Reply #13 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
 
  

Offline flash

  • Jr. Member
  • **
  • Posts: 49
lower case
« Reply #14 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 :-[