custom PHP

kruegerson
kruegerson's picture

Joined: 2009-04-22
Posts: 6
Posted: Wed, 2009-07-08 12:52

Hi,

I have a problem: I want to customize the head of my gallery and include a simple banner rotation. I have searched the forum etc. for a possibility to insert custom php code.

This was my idea:
I know a little bit PHP and and I wrote a little script that simply chooses a random file from a certain folder to include. Every single file that is choosen contains a little piece of javascript that will bring up another banner.

But I have learned that I cannot insert custom PHP code in one of the .tpl files inside my teplates folder..
I have seen the docs about making my own Gallery module but I haven't the time right now to get through or in other words: is there an easier way to insert a few lines of custom php without writing a new module?

Any help is greatly appreciated, thank you
Markus

.. this is the gallery where I want to place this little banner rotation:

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 25961
Posted: Wed, 2009-07-08 13:28

I would just edit the template file you are wanting to place the rotation code.
like:

{php}
your php code goes here
{/php}

if you are using javascript then you have to escape smarty parsing:

{literal}
<javascript>
code here
</script>
{/literal}

stuck still? post what you are trying to add.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
kruegerson
kruegerson's picture

Joined: 2009-04-22
Posts: 6
Posted: Wed, 2009-07-08 20:49

O my .. so simple!
Thank you so much for your help!!

This is my simple little random banner generator. I just put a couple of files into a directory called 'banner' in my home directory and added the code below in my ads.tpl
If anyone is copying this, note that you have to use the physical file path on your server i.e. /usr/www/users/yourhosting/yourdir/ on some linux systems

---

{php}
$filename = array(); # initialize array
$num_files=0; # set count to 0

if($dir=@opendir ("/filepath/")) # must be local file path, not web root
{
while ($file = readdir($dir)) { # as long as files are found do the following..

# we want .php files only (excluding unix . .. files)
$dot_pos = strrpos($file,".");
$suffix = substr($file, $dot_pos);

if( $suffix == ".php")
{

$num_files++; # increase +1
$filename[] = $file; # find filename

}
}
closedir($dir);
}

srand((double)microtime()*1000000); # initialize random number
$random_file=rand(0,$num_files-1); # between 1 and total amount of files

include("/filepath/".$filename[$random_file]);

{/php}

--

Works fine for me - example

Thanks again, Dave