Display random image from filemanager

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
caramello
Posts: 70
Joined: Thu 23. Sep 2004, 21:43

Display random image from filemanager

Post by caramello »

Does anybody have any tips on how to display a single random image from ONE the filebrowser's directories ?

I figure the RT {RANDOM will not do that as it needs a full pathe to a directory on the server and then will display a random image from all the image.

(r307)
A website is a concept not a digital brochure ! Vectrus Internet Solution
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Display random image from filemanager

Post by juergen »

Hi

this is not part of core code, needs to be coded

:)
breitsch
Posts: 473
Joined: Sun 6. Mar 2005, 23:12
Location: bern switzerland

Re: Display random image from filemanager

Post by breitsch »

The following solution is not really a random image from a filemanager directory, but a random image from a contentpart 'pictures'
so you can set up a contentpart with a list of all your desired images and then tell the script to use only one random image of this list each time the contentpart is shown in frontend.

It's especially handy for header images when you want to give the user the possibility to change the header pictures easily - add a {SHOW_CONTENT:CP:#} to your template where the image should appear.

The bad news is: you need to hack the core code, but it's really just a few lines in three files:

include\inc_lib\content\cnt2.readform.inc.php

find (row 50):

Code: Select all

$content['tmp_images']		= array();
add before (row 49):

Code: Select all

$content["randomimage"] 		= empty($_POST["cimage_randomimage"]) ? 0 : 1;
find (row 126)

Code: Select all

$content['image_list']['crop']		= empty($_POST["cimage_crop"]) ? 0 : 1;
add after (row 127):

Code: Select all

$content['image_list']['randomimage']		= $content["randomimage"];

include\inc_tmpl\content\cnt2.inc.php

add in row 241:

Code: Select all

<tr>
	<td align="right" class="chatlist">Random Image:&nbsp;</td>
	<td valign="top"><table border="0" cellpadding="0" cellspacing="0" summary="">
			<tr>
				<td><input name="cimage_randomimage" type="checkbox" id="cimage_randomimage" value="1" <?php is_checked(1, $content['image_list']['randomimage']); ?> /></td>
				<td class="v10"><label for="cimage_randomimage" class="checkbox">random image from the list</label></td>
			</tr>
		</table>
	</td>
</tr>
note that 'Random Image:' and 'random image from the list' is hardcoded


include\inc_front\img.func.inc.php

find (row 370):

Code: Select all

foreach($imagelist['images'] as $key => $value) {
insert after:

Code: Select all

      if ($imagelist['randomimage']){
          $key = rand(0, $count_images-1);
      }
find (now row 536):

Code: Select all

		$capt_row 	.= $xct;
		$x++;
	}
insert after (row 539):

Code: Select all

      if ($imagelist['randomimage']){
        break;
      }

This will give you a new option in the images contentpart
Image
http://www.youtube.com/watch?v=jqxENMKaeCU
because it's important!
breitsch
User avatar
Oliver Georgi
Site Admin
Posts: 9889
Joined: Fri 3. Oct 2003, 22:22
Contact:

Re: Display random image from filemanager

Post by Oliver Georgi »

OK, Breitsch war wieder fleißig :)

Ich habs übernommen und entsprechend adaptiert (na klar Ego sei Dank ;-) etwas anders). Macht aber das gleiche.
http://code.google.com/p/phpwcms/source/detail?r=310

Gruß
Oliver
Oliver Georgi | phpwcms Developer | GitHub | LinkedIn | Систрон
User avatar
juergen
Moderator
Posts: 4556
Joined: Mon 10. Jan 2005, 18:10
Location: Weinheim
Contact:

Re: Display random image from filemanager

Post by juergen »

310 -> ist auf der docu Seite ;)
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Re: Display random image from filemanager

Post by flip-flop »

Inspired of the contribution of breitsch here is an other general solution using the template for "image <div>" or "image special".

It is very pretty and more flexible:
- list of images from CP
- width/heigth parameters from CP
- lightbox (zoom only don´t run!!!).
- alt/title from CP
- bulid your own classes/IDs

- fallback image (please insert your image into the snippet at the end)

And if you wan´t more features, please play around with the other parameter like {THUMB_HEIGHT} or {IMAGE_HASH} and so on.

config: $phpwcms['allow_cntPHP_rt'] = 1;

E.g. template file: random_image.tmpl

Code: Select all

<!--IMAGES_HEADER_START//-->

<div class="images" id="images{ID}">

[PHP]

	$my_images = array();
	$my_counter = -1;

<!--IMAGES_HEADER_END//-->


<!--IMAGES_ENTRY_START//-->

	$my_counter++;
	$my_images[$my_counter][0] = '{IMAGE}';  // complete html string with image
	$my_images[$my_counter][1] = '{IMGID}';  // image-id

<!--IMAGES_ENTRY_END//-->

<!--IMAGES_ENTRY_SPACER_START//--><!--IMAGES_ENTRY_SPACER_END//-->
<!--IMAGES_ROW_SPACER_START//--><!--IMAGES_ROW_SPACER_END//-->


<!--IMAGES_FOOTER_START//-->

echo '<div class="imageEntry">'.LF;

if (!empty($my_images) ) {
	echo '<div id="img'.$my_images[$my_counter][1].'">'.LF;  // ID

//	srand(microtime()*1000000); // Only for php version < 4.2
	echo $my_images[rand(0,$my_counter)][0];  // iamge output

	echo '</div>'.LF;  // End ID
} 
else 
{ // ************* Please insert your fallback image *************
	echo '<img src="content/images/my_fallback_image.jpg" width="200" height="150" alt="My alt" title="My title" border="0" />';
}
echo '</div>'.LF;

unset ($my_images);
unset ($my_counter);

[/PHP]

</div>
<!--IMAGES_FOOTER_END//-->
And have a look to this parameters......

Code: Select all

	<!-- 
		Thumbnail image: {THUMB_NAME}
		  relative:      {THUMB_REL}
		  absolute:      {THUMB_ABS}
		  height/width:  {THUMB_HEIGHT}px/{THUMB_WIDTH}px
		  image ID:      {IMAGE_ID}
		  image Hash:    {IMAGE_HASH}
		
		If you are not sure wrap zoomed image:
		[ZOOM]
		Zoomed (big) image: {IMAGE_NAME}
		  relative: {IMAGE_REL}
		  absolute: {IMAGE_ABS}
		  height/width: {IMAGE_HEIGHT}px/{IMAGE_WIDTH}px
		[/ZOOM]		
	//-->
Parameters hand over from the range

<!--IMAGES_ENTRY_START//-->
$my_images[$my_counter][2] = '{THUMB_HEIGHT}'; // image-id
$my_images[$my_counter][3] = '{THUMB_WIDTH}'; // image-id
// and so on .......
<!--IMAGES_ENTRY_END//-->

into the range

<!--IMAGES_FOOTER_START//-->
echo 'Test thumb height'.$my_images[$my_counter][2].'<br />'.LF;
echo 'Test thumb width'.$my_images[$my_counter][3].'<br />'.LF;
<!--IMAGES_FOOTER_END//-->

Knut
Last edited by flip-flop on Wed 1. Apr 2009, 23:05, edited 3 times in total.
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Re: Display random image from filemanager

Post by update »

Oliver Georgi wrote:OK, Breitsch war wieder fleißig :)

Ich habs übernommen und entsprechend adaptiert (na klar Ego sei Dank ;-) etwas anders). Macht aber das gleiche.
Good to know that this method is doing the trick ;)
Hey, there are some other contributions (similar to this really nice one done by breitsch) which will fit into this method too (the random CP for example) ;)
(not to mention some done by flip-flop and others)
Keep on tracking / truckin' :D
It's mostly all about maintaining two or three customer's sites Still supporter for the band Mykket Morton. Visit Mykket Morton on FB. Listen Mykket Morton and live videos on youtube.
Now building a venue for young artists to get wet on stage, rehearsal rooms, a studio, a guitar shop - yes I'm going to build some guitars.
Post Reply