Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Random Image Scripts

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-23-2003, 12:10 PM
 
mf2kart mf2kart is offline
 

Newbie
  
Join Date: Jun 2003
Location: San Francisco
Posts: 5
 

Default Random Image Scripts

I am trying to apply a random image ont he front of a store. does it need special tags inorder to work? I posted teh script here.

http://www.rinju.com/getRandomImage.zip

thanks

-mikey
Reply With Quote
  #2  
Old 06-23-2003, 08:43 PM
 
snorocket snorocket is offline
 

X-Adept
  
Join Date: Dec 2002
Posts: 403
 

Default did you rap

did you rap the include script with smarty tags like this

{php}
include("http://www.yourwebsite.com/path/to/randomscript.php");
{/php}

it works great on my site, i just put this in the welcome template, works awesome, i also put multiple randomizing scripts in head.tpl & copyright.tpl so that everything changes when refreshed except the navigation menus at top remain the same, totally cool.
Reply With Quote
  #3  
Old 06-24-2003, 03:24 AM
 
barabbas barabbas is offline
 

Advanced Member
  
Join Date: Feb 2003
Posts: 52
 

Default

heres a random image script that i cant get working but you may find useful:

save as sig1.php
Quote:
<?

preg_match("/^(http:\/\/)?([^\/]+)/i", "$HTTP_REFERER", $matches);
$host = $matches[2];
preg_match_all("/\.([^\.\/]+)/",$host,$matches);
$matches[0][0] = $matches[1][0];
$domain = implode('',$matches[0]);

function getRandomImage($dir,$type='random')
{
global $errors;
if (is_dir($dir)) {
$fd = opendir($dir);
$images = array();
while (($part = @readdir($fd)) == true) {
clearstatcache();
if ( eregi("(gif|jpg|png|jpeg)$",$part) ) {
$images[] = $part;
}
}
if ($type == 'all') { return $images; }
srand ((double) microtime() * 1000000);
$key = rand (0,sizeof($images)-1);
return "http://qmass.ausgamers.com/ausnetwork_sig/" . $dir . $images[$key];
} else {
$errors[] = $dir.' is not a directory';
return false;
}
}

/* GAME ARENA SIG */
if ($host=="games.telstra.com" || $host=="cogs.games.telstra.com"){
echo <<<END
document.write("<img src='
END;
echo getRandomImage('gamearena/');
echo <<<END
' width='545' height='85' border='0'></td>");
END;
exit;}

/* QGL */
else if ($host=="qgl.ausforums.com"){
echo <<<END
document.write("<img src='
END;
echo getRandomImage('qgl/');
echo <<<END
' width='450' height='47' border='0'></td>");
END;
exit;}

/* AUS NS SIG */
else if ($host=="ausns.ausforums.com"){
echo <<<END
document.write("<img src='
END;
echo getRandomImage('gamearena/');
echo <<<END
' width='545' height='85' border='0'></td>");
END;
exit;}

/* AusAnime */
else if ($host=="ausanime.ausforums.com"){
echo <<<END
document.write("<img src='
END;
echo getRandomImage('qgl/');
echo <<<END
' width='450' height='47' border='0'></td>");
END;
}

else {exit;}
Reply With Quote
  #4  
Old 06-24-2003, 02:06 PM
 
snorocket snorocket is offline
 

X-Adept
  
Join Date: Dec 2002
Posts: 403
 

Default rinjuanimation & barabbas try this script

this scipt is much easier and simple, just save it as randomscript.php or whatever you want, change the paths to your images and upload the script to your website, then in your welcome template put this include function

{php}
include("http://www.yourwebsite.com/path/to/randomscript.php");
{/php}

and change the paths to where you uploaded the file, let me know if it works, this is a great script and you can change the paths to an html file or another website, whatever you want really


Quote:
<?php

srand((double)microtime()*1000000);
$randomtopic = rand(0,11);

if ($randomtopic == "0") {
header('Location: http://www.yourwebsite.com/path/to/image01.jpg');

} else if ($randomtopic == "1") {
header('Location: http://www.yourwebsite.com/path/to/image02.jpg');

} else if ($randomtopic == "2") {
header('Location: http://www.yourwebsite.com/path/to/image03.jpg');

} else if ($randomtopic == "3") {
header('Location: http://www.yourwebsite.com/path/to/image04.jpg');

} else if ($randomtopic == "4") {
header('Location: http://www.yourwebsite.com/path/to/image05.jpg');

} else if ($randomtopic == "5") {
header('Location: http://www.yourwebsite.com/path/to/image06.jpg');

} else if ($randomtopic == "6") {
header('Location: http://www.yourwebsite.com/path/to/image07.jpg');

} else if ($randomtopic == "7") {
header('Location: http://www.yourwebsite.com/path/to/image08.jpg');

} else if ($randomtopic == "8") {
header('Location: http://www.yourwebsite.com/path/to/image09.jpg');

} else if ($randomtopic == "9") {
header('Location: http://www.yourwebsite.com/path/to/image10.jpg');

} else if ($randomtopic == "10") {
header('Location: http://www.yourwebsite.com/path/to/image11.jpg');

} else if ($randomtopic == "11") {
header('Location: http://www.yourwebsite.com/path/to/image12.jpg');

} else {
echo ( "ERROR: There was a problem running the script. ");
}
?>

just PM if you want to see this script in action
Reply With Quote
  #5  
Old 06-24-2003, 10:25 PM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

this one's evene shorter

http://forum.x-cart.com/viewtopic.php?t=2481&highlight=random
__________________
ex x-cart guru
Reply With Quote
  #6  
Old 07-03-2003, 10:17 AM
 
jgkiefer jgkiefer is offline
 

Advanced Member
  
Join Date: Apr 2003
Posts: 85
 

Default

Wouldn't be just as easy to use a random javascript?
Reply With Quote
  #7  
Old 07-03-2003, 10:50 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

but then everyone could see (read: steal) your code
__________________
ex x-cart guru
Reply With Quote
  #8  
Old 07-31-2003, 08:45 PM
 
dennx dennx is offline
 

Member
  
Join Date: Jul 2003
Posts: 10
 

Default

Can the above script be made to make the images 'clickable' to a specified page/url?

Thanks
Reply With Quote
  #9  
Old 08-01-2003, 11:00 AM
  TelaFirma's Avatar 
TelaFirma TelaFirma is offline
 

X-Adept
  
Join Date: Nov 2002
Location: North Carolina USA
Posts: 930
 

Default

Here is one for you... It is a little more work, but is is nice Make a new file in /skin1/customer/main/ named randoms.tpl. In this file put:

Code:
<a href=product.php?productid={$images[0].productid}> {if $images[image].tmbn_url} [img]{$images[0].tmbn_url}[/img] {else} [img]../product_image.php?imageid={$images[0].imageid}[/img] {/if} </a>

Create a new file in /customer/ named random.php. In this file put:

Code:
<? // give it all available products to work with // $image_id = func_query("SELECT imageid FROM $sql_tbl[images] WHERE avail='Y'"); // set the variables // $str = ""; // $numberRandoms=1; // set this to how many you want to show // srand((double)microtime()*1000000); // $rnd = rand(0, count($image_id)-1); $images = func_query("select * from $sql_tbl[images] ORDER BY RAND() limit 1"); if ($current_area != "C" && is_array($images)) { foreach($images as $k=>$v) { $images[$k]["type"] = (eregi("gif",$v["image_type"])?"GIF":(eregi("png",$v["image_type"])?"PNG":"JPG")); } } # # Get thumbnail's URL (uses only if images stored in FS) # if ($config["Images"]["det_images_location"] == "FS") if ($current_area == "C" && is_array($images)) { foreach($images as $k=>$v) if (eregi("^(http|ftp)://", $v["image_path"])) # image_path is an URL $images[$k]["tmbn_url"] = $v["image_path"]; elseif (eregi($xcart_dir, $v["image_path"])) { # image_path is an locally placed image $images[$k]["tmbn_url"] = $http_location.ereg_replace($xcart_dir, "", $v["image_path"]); } } $smarty->assign("images",$images); ?>

Next, insert this into your welcome.tpl file:

Code:
{include file="customer/main/randoms.tpl"}

Next, in the customer/home.php file look for
Code:
require "../include/categories.php";

and insert this line under it:
Code:
include "./random.php";
What this does is ger a list of all the Detail Images used for all your products. It then choses one at random and displays it, also linking it to the respective product page that it belongs to.

*This is for version 3.4.x and will work with inages stored in a File System or in the Database.[/code]
Reply With Quote
  #10  
Old 08-01-2003, 11:32 AM
  shan's Avatar 
shan shan is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Birmingham, UK
Posts: 6,163
 

Default

Nice mod,

MOved to Custom templates
__________________
Looking for a reliable X-cart host ?
You wont go wrong with either of these.

EWD Hosting
Hands On Hosting
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:02 PM.

   

 
X-Cart forums © 2001-2020