Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

passing an argument in includes

Quote Reply
passing an argument in includes
As I continue to write my mods...

I want to write an include mod something like this:

<%virtual /path/to/script/php/or/perl/%> (read my previous post and you'll see why)

My goal is to get the script to print the script being included...



I came across a problem. I'm not sure how to bring in an argument.

<%virtual whatever_variable%>

In globals.txt I have something like this...

'php' => 'sub {
#Execute a perl or php file...
my $php, $path;
$path = whatever_variable;
the rest of the code yada yada dada....
return $php;
}',

My argument in this case will be the path to the php or perl file...

Any suggestions or help is appreciated,

- Jonathan

Last edited by:

jdgamble: Jul 29, 2004, 8:14 PM
Quote Reply
Re: [jdgamble] passing an argument in includes In reply to
Hi. Give this a go :)

Code:
sub {
my $url = $_[0];
if ($url =~ /^http/i) {
require LWP::Simple;
return LWP::Simple::get($url || return;
} else {
return system($url);
}
}

.. and then call with: <%global_name('http://www.url.com/cgi-bin/script_to_run')%> (it can be *any* URL you want), or;

<%global_name('perl /full/path/to/script/on/yourserver.cgi')%>

The above global, basically gives you the option to use either a URL, or command to run on your server Smile

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!

Last edited by:

Andy: Jul 30, 2004, 12:56 AM
Quote Reply
Re: [Andy] passing an argument in includes In reply to
Okay Thanks... you solved my first problem... passing the argument.

Now my second problem is getting the script to display a php file without loading http...

It does not seem to want to load my simple php file LWP. Can LWP load locally instead of through http? (a php file that is)

My second question is what does perl in the following statement do? Is this an LWP command?

<%global_name('perl /full/path/to/script/on/yourserver.cgi')%>

Pretty much my main focus is loading php files inside perl files LOCALLY...!

Thank You once again Andy...,

- Jonathan
Quote Reply
Re: [jdgamble] passing an argument in includes In reply to
No problem :)

You could try;

<%global_name('/usr/bin/php /full/path/to/script/on/yourserver.php')%>

You will need to find out the path to PHP on your server though, as it probably won't be the same as my example :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] passing an argument in includes In reply to
My php path is the same as yours, however, all you have to put is "php"... you don't need the "/usr/bin/php"...

Also you cannot return a system command... That is what the `` are for...

So I changed it to

Quote:


'php' => 'sub {
my $url = $_[0];
my $script = `php $url -1`;
return $script;
}',


Thats all I need apparantly... I plan on editing it when I get the time use ssi for html pages or even php for php pages (like on my banner scirpt)... and I am going to add your if statements back to use lwp.

But for the simplest purposes... thats how you include php in perl... you call it by

<%php('path to your php file')%>

Thanks for the suggestions and help,
I will probably post the final script once I complete it.

- Jonathan
Quote Reply
Re: [jdgamble] passing an argument in includes In reply to
Although these could be combined into one sub routine, two works best for me:

Code:

'php' => 'sub {
my $url = $_[0];
my $script;
my $path = "your full httpdocs path without a trailing slash";
if ($ENV{SCRIPT_NAME} =~ /nph-build/) {
$script = \'<!--#include virtual="\' . $url .\'" -->\';
}
else {
$script = `php $path/$url`;
$script =~ s,Content-type:\stext/html,,;
}
return $script;
}',
'perl' => 'sub {
my $url = $_[0];
my $script;
my $path = "your full root path before httpdocs and cgi-bin without trailing slash";
if ($ENV{SCRIPT_NAME} =~ /nph-build/) {
$script = \'<!--#exec cgi="\' . $url .\'" -->\';
}
else {
$script = `$path/$url`;
$script =~ s,Content-type:\stext/html,,;
}
return $script;
}',


if you use php instead of shtml to include your banner, you could use

<? inlcude("$url") ?> or something like it...

ASP's inlcude is <!-- #include virtual="/includes/header.asp" --> ASP's inlcude

I suppose you could write a script that checks for all of it and automatically creates all the paths, but that would be too much for me...

Maybe you would check if ($build_extension =~ /.shml||php/) { do something } - just a thought


Once again off track, I am using the codes above. To include it on both shtml and perl scripts simply call it by <%php(/path to script)%> or <%perl(path to script)%>

Once again I hope this helps some people... I know it would have helped me,

- Jonathan
Quote Reply
Re: [jdgamble] passing an argument in includes In reply to
How excatly does this work?

I am trying to pass argument to the script, which is parsed by separate php script.

How do I do that?

What global template needed?
What does the url looks like, which has argument being passed?

What do I put on my results template?