X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Random Image Scripts (https://forum.x-cart.com/showthread.php?t=3314)

mf2kart 06-23-2003 12:10 PM

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

snorocket 06-23-2003 08:43 PM

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.

barabbas 06-24-2003 03:24 AM

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;}


snorocket 06-24-2003 02:06 PM

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

funkydunk 06-24-2003 10:25 PM

this one's evene shorter :wink:

http://forum.x-cart.com/viewtopic.php?t=2481&highlight=random

jgkiefer 07-03-2003 10:17 AM

Wouldn't be just as easy to use a random javascript?

funkydunk 07-03-2003 10:50 AM

but then everyone could see (read: steal) your code :wink:

dennx 07-31-2003 08:45 PM

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

Thanks

TelaFirma 08-01-2003 11:00 AM

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]

shan 08-01-2003 11:32 AM

Nice mod,

MOved to Custom templates :wink:


All times are GMT -8. The time now is 06:26 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.