Random image

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
holbytv
Posts: 7
Joined: Sun 6. Jun 2004, 01:34

Random image

Post by holbytv »

Hello

I am trying to use the random image replacement tag for a background image of a table, is this at all possible, it would be most useful for me.....

Thanks in advance
Pappnase

Post by Pappnase »

hello

i think this is not possible! but maybe you can find an java script wich you can implement!
cyrilo
Posts: 9
Joined: Mon 17. May 2004, 11:57

Post by cyrilo »

Hi,

You can add this code and use the new tag
Open include/inc_front/front.func.inc.php

Find function html_parser($string) {
Find in the function sholud be at line 1205

Code: Select all

// random Image Tag
$search[15]		= '/\{RANDOM:(.*?)\}/e';
$replace[15]	= 'get_random_image_tag("$1");';
Add after it

Code: Select all

// random Image Tag
$search[15]		= '/\{RANDOM_IMG_FILE:(.*?)\}/e';
$replace[15]	= 'get_random_image_file("$1");';
Then find in the same file (line 1336)
function get_random_image_tag($path) {
Replace function with

Code: Select all

// -------------------------------------------------------------
function get_random_image($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;
}

// -------------------------------------------------------------

function get_random_image_tag($path) {
	// returns an random image tag from the give path
	// it looks for image of following type:
	// gif, jpg, jpeg, png

	return (get_random_image($path)) ?	"<img src=\"".$path."/".$imageinfo["imagename"].
							"\" ".$imageinfo[3]." border=\"0\" alt=\"".
							$imageinfo["imagename"]."\" />"
							: "";	
}

// -------------------------------------------------------------

function get_random_image_file($path) {
	// returns an random image tag from the give path
	// it looks for image of following type:
	// gif, jpg, jpeg, png

	return (get_random_image($path)) ?	$path."/".$imageinfo["imagename"]: "";	
}
Then use the new tag RANDOM_IMG_FILE

Best Regards
Kiril
holbytv
Posts: 7
Joined: Sun 6. Jun 2004, 01:34

Thanks

Post by holbytv »

Thanks so much for this - but I keep getting Parse error: parse error in /usr/local/psa/home/vhosts/holby.tv/httpdocs/db/include/inc_front/front.func.inc.php on line 2189

Fatal error: Call to undefined function: get_active_categories() in /usr/local/psa/home/vhosts/holby.tv/httpdocs/db/include/inc_front/content.func.inc.php on line 85

when I try and do it.

Any ideas? Thanks
cyrilo
Posts: 9
Joined: Mon 17. May 2004, 11:57

Post by cyrilo »

Check for that function, just search for it.
Look where this function is called and where this function is defined
Check this parse error, you are missing some semicolumns or comma or some other mistake.
holbytv
Posts: 7
Joined: Sun 6. Jun 2004, 01:34

Post by holbytv »

Still having trouble mate

The image doesn't come up... no errors though. Using this HTML...

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="144">
<TBODY>
<TR>
<TD height="207" background={RANDOM_IMG_FILE:db/img/front/pres}>
</TD></TR>



Thanks
Pappnase

Post by Pappnase »

holbytv wrote:Still having trouble mate

The image doesn't come up... no errors though. Using this HTML...

<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="144">
<TBODY>
<TR>
<TD height="207" background={RANDOM_IMG_FILE:db/img/front/pres}>
</TD></TR>



Thanks
hello

never tryed this! but maybe the random path is wrong!?

Code: Select all

<TD height="207" background={RANDOM_IMG_FILE:db/img/front/pres/}
leone
Posts: 21
Joined: Tue 19. Oct 2004, 11:30
Location: Switzerland

Post by leone »

This modification can't possibly work as the variable $imageinfo is not defined in the functions that return the value, yet it is being used in the return statement. You can't possibly have tested this to work. :roll:


The correct modification would be:

Code: Select all

// ------------------------------------------------------------- 
function get_random_image($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; 
} 

// ------------------------------------------------------------- 

function get_random_image_tag($path) { 
   // returns an random image tag from the give path 
   // it looks for image of following type: 
   // gif, jpg, jpeg, png 
	$imageinfo = get_random_image($path);
	return ($imageinfo) ?   "<img src=\"".$path."/".$imageinfo["imagename"]. 
                     "\" ".$imageinfo[3]." border=\"0\" alt=\"". 
                     $imageinfo["imagename"]."\" />" 
                     : "";    
} 

// ------------------------------------------------------------- 

function get_random_image_file($path) { 
   // returns an random image tag from the give path 
   // it looks for image of following type: 
   // gif, jpg, jpeg, png 
   $imageinfo = get_random_image($path);
   return ($imageinfo) ?   $path."/".$imageinfo["imagename"]: "";    
} 
I suggest to add a new search statement anyway so not to interfere with the existing {RANDOM..} tags. (Replace xx with the next number)

Code: Select all

	// random Image File Without tag.
	$search[xx]		= '/\{RANDIMG:(.*?)\}/e';
	$replace[xx]	= 'get_random_image_file("$1");';

Hope this helps.

I came accross this post due to the fact that I also needed to have random images posted to the code without any accompanying html code, just the path and file.

regards,
Leone
Post Reply