Page 1 of 1
Random stuff
Posted: Tue 17. Oct 2006, 08:33
by Stim
I use random tag for pictures {RANDOM:picture} and now I wonder if its possible to use it as background, in a table or div tag. I think I have try everything now but noting works. Is it possible?
Posted: Tue 17. Oct 2006, 19:30
by update
Should go like this:
Code: Select all
style="background-image: url({RANDOM:picture});
claus
Posted: Wed 18. Oct 2006, 05:11
by Stim
Did not work. Whole that cod shows up beside images on website.
I won’t something like this:
Code: Select all
<div style="background-image: url('http://www.site.com/picture/file.jpg')">Some cool text here</div>
But instead of 1 background picture, that (file.jpg), I won’t random that background from some pictures folder, just like that tag {RANDOM:picture} do.
Possible some how?
Posted: Wed 18. Oct 2006, 07:33
by DeXXus
Only if you can find a way to use the function as it was written!
Of course, you could rewrite it -or- replicate the function in a new tag.
That tag returns image in this format:
<img src="/myrandomimages/randomimagename.jpg" border="0" alt="" />
(SEE CODE BELOW):
Code: Select all
// -------------------------------------------------------------
function get_random_image_tag($path) {
// returns an random image 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) ? "<img src=\"".$path."/".$imageinfo["imagename"].
"\" ".$imageinfo[3]." border=\"0\" alt=\"".
$imageinfo["imagename"]."\" />"
: "";
}
// -------------------------------------------------------------
Posted: Wed 18. Oct 2006, 09:17
by update
I did some rewriting too some months ago
Code: Select all
<?php
/********************************************
titel: {GET_RANDOM_ALIAS_IMG_URL} Replacement-Tag
description: {GET_RANDOM_ALIAS_IMG_URL:image-path}
This Replacement-Tag is based on {RANDOM} tag. It started as a mixup of
tinoos adapted random code and turned on by pepes strip-prefix.php. It creates the
path info of random pictures related to your point of view in a website
(like "picture/Image/structure-aliasname/pic1.png".
This tag can be used at places like table background where no <img>-tag is required.
---------------------------------------------
example: {GET_RANDOM_ALIAS_IMG_URL:picture/Image} or
<table style="background-image: url ({GET_RANDOM_ALIAS_IMG_URL:picture/Image});"
<div style="background-image: url ({GET_RANDOM_ALIAS_IMG_URL:picture/Image});"
or even <img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}"> in an "HTML" contentpart.
or <a href="link-to-somewhere"><img src="{GET_RANDOM_ALIAS_IMG_URL:picture/Image}" border="0"></a>
---------------------------------------------
The directories "alias1" "alias2" ... are subdirectories of picture/Image
(you have to create them according to your given aliases "alias1" "alias2"...
in admin/site structure).
The complete path to the random pictures is then:
www.yourdomain.com/picture/Image/alias1/
www.yourdomain.com/picture/Image/alias2/
and so on.
The advantage of defining the alias-dirs in "picture/Image" is that this dir is used by fckeditor
and you then can upload pictures per FTP and/or per fckeditor.
It will deliver the pictures of the appropriately defined dir according to where
you are in the site.
---------------------------------------------
notice: name this file get_random_alias_img_url.php and copy it to
phpwcms_template/inc_script/frontend_render
---------------------------------------------
authors: Claus (adapting and mixing up the code)
last modified: 23.01.2006 created/mixed up
********************************************/
function get_random_image_url_based_on_alias($path)
{
// returns a random image url from the given path
// it looks for image of following type: gif, jpg, jpeg, png
$alias = $GLOBALS['content']['struct'][($GLOBALS['aktion'][0])]['acat_alias'];
$mypath = ($path."/".$alias);
$imgArray = array();
$imgpath = str_replace("//", "/", PHPWCMS_ROOT."/".$mypath."/");
$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) ? "".$mypath."/".$imageinfo["imagename"]: "";
}
$content["all"] = preg_replace('/\{GET_RANDOM_ALIAS_IMG_URL:(.*?)\}/ie', 'get_random_image_url_based_on_alias("$1");', $content["all"]);
?>
And this was working really well
claus
Posted: Wed 18. Oct 2006, 09:50
by Stim
Thanks, I will try that cod. Which file should I insert that cod to? conf.inc.php?
Posted: Wed 18. Oct 2006, 09:53
by update
notice: name this file get_random_alias_img_url.php and copy it to
phpwcms_template/inc_script/frontend_render
Posted: Wed 18. Oct 2006, 21:06
by Stim
OK, thanks claus, i will try this new stuff.
Posted: Wed 18. Oct 2006, 21:35
by frankie44
Hi, Stim - I had the same problem (generating a random image path, but no img tag) and used Tinoos {random_img_url} Works beautifully...
http://www.phpwcms.de/forum/viewtopic.p ... ndomimgurl
Greetings - Gabi