This is my first Replacement Tag. Well, it's not really my tag. It's actually
a modification of the {RANDOM}-tag... Safe this piece of code into a file
(for example reptag_random_img_url.php) and copy it to phpwcms_template\inc_script\frontend_render. Instructions are inside the
code...
Because i'm a php-noob, no support is given...
Code: Select all
<?php
/********************************************
titel: {RANDOM_IMG_URL} Replacement-Tag
description: {RANDOM_IMG_URL:image-path}
This Replacement-Tag is based on {RANDOM} tag, but creates only the
path informations of random pictures, like "picture/random-title/header2.jpg".
Use this tag at places like table background where no <img>-tag is required.
example: {RANDOM_IMG_URL:picture/random-pics} or
<table style="background-image: url({RANDOM_IMG_URL:picture/random-pics});"
The directory random-pics is a subdirectory of picture.
The complete path to the random pictures is then:
www.yourdomain.com/picture/random-pics/
notice: copy this file to phpwcms_template\inc_script\frontend_render
author: Martin Heggli
last modified: 27.07.2005 created
********************************************/
function get_random_image_url($path) {
// returns an random image url from the give path
// it looks for image of following type:
// gif, jpg, jpeg, png
$imgArray = array();
$imgpath = str_replace("//", "/", PHPWCMS_ROOT."/".$path."/");
$imageinfo = false;
if(is_dir($imgpath)) {
$handle = opendir( $imgpath );
while($file = readdir( $handle )) {
if( $file != "." && $file != ".." ) {
if( preg_match('/(\.jpg|\.jpeg|\.gif|\.png)$/', strtolower($file)) ) $imgArray[] = $file;
}
}
closedir( $handle );
}
if(sizeof($imgArray)) $imageinfo = is_random_image($imgArray, $imgpath);
//return $imageinfo;
return ($imageinfo) ? "".$path."/".$imageinfo["imagename"]: "";
}
// -------------------------------------------------------------
$content["all"] = preg_replace('/\{RANDOM_IMG_URL:(.*?)\}/e', 'get_random_image_url("$1");', $content["all"]);
// -------------------------------------------------------------
?>