Random stuff

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Random stuff

Post 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?
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

Should go like this:

Code: Select all

style="background-image: url({RANDOM:picture});
claus
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post 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?
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post 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. :wink:

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"]."\" />"
							: "";	
}

// -------------------------------------------------------------
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

I did some rewriting too some months ago :wink:

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
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

Thanks, I will try that cod. Which file should I insert that cod to? conf.inc.php?
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

notice: name this file get_random_alias_img_url.php and copy it to
phpwcms_template/inc_script/frontend_render
Stim
Posts: 587
Joined: Mon 6. Jun 2005, 13:13

Post by Stim »

OK, thanks claus, i will try this new stuff.
frankie44
Posts: 13
Joined: Thu 13. Apr 2006, 19:28

Post 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
Post Reply