Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: request: randomize head image in ChaoticSoul theme  (Read 3162 times)

0 Members and 1 Guest are viewing this topic.

technozeus

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
    • ilfra.it
request: randomize head image in ChaoticSoul theme
« on: December 27, 2007, 05:51:57 pm »

Hi to all.
I would like to change randomly (at any reload of the page) the image in the head of Chaoticsoul theme (image_left.jpg and image_right.jpg). I have the code to randomly those images but the problem is that the images are set in the css file.
Is there the possibility to set the path in the php files (theme.php for example)?
Thanks a lot.
« Last Edit: January 02, 2008, 07:53:54 am by Joachim Müller »
Logged

technozeus

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
    • ilfra.it
Re: request: randomize head image in ChaoticSoul theme
« Reply #1 on: December 28, 2007, 01:53:39 am »

ok, I'm implementing it by javascript code but I would prefer to use php code :(
Logged

just_some_guy

  • Supporter
  • Coppermine addict
  • ****
  • Offline Offline
  • Posts: 539
  • I am currently on holiday, back in a few weeks. :D
Re: request: randomize head image in ChaoticSoul theme
« Reply #2 on: December 28, 2007, 07:33:56 pm »

SELECT * FROM cpg1411_pictures ORDER BY RAND() LIMIT 1;

Will get info about a random image.
Logged
Tambien, Hablo Español      PHP - Achieve Anything
"The Internet is becoming the town square for the global village of tomorrow. " - Bill Gates
Windows 7 Forums

technozeus

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
    • ilfra.it
Re: request: randomize head image in ChaoticSoul theme
« Reply #3 on: December 31, 2007, 10:52:30 am »

mmmhhh, but the image that the template use for "head" is not an image in the db, is an image in the folder of template (421x149px).
Well, I solved whit a javascript, is not what I prefer, but works.
I post the mod for anyone else interest:

In the file "template.html" add before "</head>":
Code: [Select]
<script language="javascript" type="text/JavaScript">
function rndImage() {
numImg = 11;
numRet = Math.floor(Math.random() * (numImg++));
if (numRet==0){
numRet = 1
}
return numRet;
};
</script>

then, replace

Code: [Select]
<div class="image_header bkgleft"> </div>
<div class="image_header bkgright">

with

Code: [Select]
<script language="javascript" type="text/JavaScript">
var img = rndImage();
document.write('<div style="background-image: url(yourimagepath/image_left_'+img+'.jpg); float: left; border: 1px solid #363430; height: 149px; width: 421px;"></div>'+
'<div style="background-image: url(yourimagepath/image_right_'+img+'.jpg); float: right; border: 1px solid #363430; height: 149px; width: 421px;"></div>');
</script>

Now:
1) replace "yourimagepath" with the folder path of your images.
2) create how many couple of images you want (who know the template know that in the head there is 2 image) and call they image_left_x and image_right_x
3) replace numImg in the function rndImage() with the number of your images couple
4) sorry for my english ;D
5) any suggested is apreciate ;D
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: request: randomize head image in ChaoticSoul theme
« Reply #4 on: December 31, 2007, 01:04:37 pm »

Thanks for posting your solution. You're right that JavaScript should be avoided if possible. To do the random stuff server-sided (using PHP), you'll have to come up with some tweaks. I suggest using the custom_header feature for that purpose, since that's what it has been disgned for in the first place. The PHP script that should reside in the file that the custom_header patrh is pointing to should be a simple if/then toggle similar to the one you came up with in JavaScript. Something like this should do the trick:
Code: [Select]
<?php
$random_number 
rand(0,3); // the first parameter is the minimum, the second the maximum
if ($random_number == 0) {
print '<img src="path/to/your/first/image.jpg" border="0" alt="" />';
} elseif (
$random_number == 1) {
print '<img src="path/to/your/second/image.jpg" border="0" alt="" />';
} else {
print '<img src="path/to/your/third/image.jpg" border="0" alt="" />';
}
?>
(This is of course pretty crude code that is meant as a proof of concept. You get the idea)
Logged

technozeus

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
    • ilfra.it
Re: request: randomize head image in ChaoticSoul theme
« Reply #5 on: January 01, 2008, 06:26:57 pm »

using custom_header...good idea, but I don't know about the layout of the page of this theme. I will try and i will tell you.
I'd prefer php code also because I could scan the directory with the images and do all dinamic...
I do immediately some test ;)
Thanks!
Logged

technozeus

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 29
    • ilfra.it
Re: request: randomize head image in ChaoticSoul theme
« Reply #6 on: January 01, 2008, 10:42:25 pm »

Ok, thanks to joachim for his suggestion, I solved with the custom header:
- create a new files in coppermine base dir (ex custom_header.php) and add it in the config menu as header
- add this code:
Code: [Select]
<?php
$path_img 
"yourpathofimages";
$total_images = (count(glob("$path_img{*.gif,*.jpg,*.png}"GLOB_BRACE)))/2;
$num_img rand(1,$total_images);
print 
"<div style=\"background-image: url($path_img/image_left_$num_img.jpg); float: left; border: 1px solid #363430; height: 149px; width: 421px;\"></div>
<div style=\"background-image: url(
$path_img/image_right_$num_img.jpg); float: right; border: 1px solid #363430; height: 149px; width: 421px;\"></div>";
?>

- modify the file template.html in the theme Chaoticsoul like this:
find
Code: [Select]
<div id="page">
{CUSTOM_HEADER}
remove {CUSTOM_HEADER}
find
Code: [Select]
<div id="headerimg" class="clearfix">
<div class="image_header bkgleft"> </div>
<div class="image_header bkgright"> </div>
</div>
replace with
Code: [Select]
<div id="headerimg" class="clearfix">
{CUSTOM_HEADER}
</div>

Thanks for this beautifull tamplate, I like it very much ;D
Logged
Pages: [1]   Go Up
 

Page created in 0.023 seconds with 20 queries.