genslideshow.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:00 2007 from genslideshow.php 2005/12/11 8.4 KB bytes.


<html>
<head>

<?php
// genslideshow.php
// AIM: To autogenerate a a JAVASCRIPT SLIDESHOW, and full table display.
// This is a combination of PHP on the server, finding the list of files,
// and GENERATING the appropriate java script, in HTML ... once generated,
// of course it would be possible to revert to just HTML+Javascript, to
// save the SERVER generating this script dynamically each time
//
// Just to show the POWER of the combination of the two scripts. ;=))
// geoff mclane - geoffair.@hotmail.com - 10 Decemebr, 2005
//
$meol = "\r\n";
$in_folder = 'temp3';
$out_folder = 'constr';
$file_count = 0;
$m_filearr = array();
// this array is made up of an array
// of the file name,
// and its image size 313x204
// it size, and date
$arr_fn = 0;
$arr_is = 1;
$arr_fs = 2;
$arr_fd = 3;
$i = 0;
get_file_arr( $in_folder, $out_folder );

function get_file_arr ( $in_folder, $out_folder )
{
   global $meol;
   global $file_count;
   $mydir = opendir($in_folder) ;
   if( !$mydir ) {
   echo "ERROR: Can not OPEN directory [$in_folder] ... aborting ... <br>$meol";
   return 0;
   }
   while($fn = readdir($mydir)) //scan through the whole directory
   {
   if( !(($fn == '.') || ($fn == '..')) ) {
   $inp_file = $in_folder . '/' . $fn;
   if( IsMYFile( $fn ) ) {
   $file_count++;
   $file_size = filesize( $inp_file );
   $file_time = filemtime( $inp_file );
   $imgSx = 0;
   $imgSy = 0;
   $src_img = imagecreatefromjpeg( $inp_file );
   if ($src_img) {
   $imgSx = imagesx($src_img);
   $imgSy = imagesy($src_img);
   }
   $arr = array();
   $arr[] = $out_folder . '/' . $fn; // $arr_fn = 0;
   $arr[] = '' . $imgSx . 'x' . $imgSy; //$arr_is = 1;
   $arr[] = $file_size; //$arr_fs = 2;
   $arr[] = $file_time; //$arr_fd = 3;
   AddFile($arr);
   }
   }
   }
   closedir($mydir);
   return $file_count;
}

function AddFile( $arr )
{
   global $m_filearr;
   $m_filearr[] = $arr;
}

function IsMYFile( $in_file )
{
   // this is a SPECIALISED filter
   $ext = strtolower(substr($in_file,-4,4));
   if ($ext == '.jpg') {
   return 1;
   }
   return 0;
}

// now GENERATE the JAVASCRIPT
print '<script LANGUAGE="JavaScript">'.$meol;
print '<!-- Begin'.$meol;
print 'var baseTit = "Construction Slideshow";'.$meol;
print 'var fileList = new Array(';
for( $i = 0; $i < $file_count; $i++ ) {
   $arr = $m_filearr[$i];
   $fn = $arr[$arr_fn];
   $inf = basename($fn) . " $arr[$arr_is]";
   print '"'. $fn . '","' . $inf . '"';
   if(($i + 1) < $file_count) {
   print ',';
   }
   print $meol;
}
// close the array generation
print '); // end of list'.$meol;
// the following will now be output within the <script ...> tag
?>

// care when changing below ... ;-))
var i;
var timerID;
var timeron = false;
var current = 0;
var rotate_delay = (8 * 1000); // delay in milliseconds, delaysec
var pixCnt = fileList.length / 2;   // count of pictures

// load the image files, at full web size, depends on
// browser http get file caching algorithms ...
var pLoad = new Array();
for( i = 0; i < pixCnt; i++ ) {
 var stg = fileList[i*2];
 pLoad[i] = new Image();
 pLoad[i].src = stg;
}

// this function is called from the body, to generate DHTML
function setSlideform() {
 for( i = 0; i < pixCnt; i++ ) {
 var stg = fileList[i*2];
 var stg2 = fileList[(i*2)+1];
 if( document.slideform.slide[i] == null )
 document.slideform.slide[i] = new Option(stg);
 document.slideform.slide[i].value = stg;
 document.slideform.slide[i].text = stg2;
 }
 first(); // establish the FIRST
}

// still maybe too early? call from body ...
// window.onload = setSlideform(); after select decoded ...

function stop() {
 if(timeron) {
 clearTimeout(timerID);
 timeron = false;
 }
 if (document.slideform.slidebutton.value == "Stop") {
 document.slideform.slidebutton.value = "Start";
 }
}

// set 1 new picture, using image file name,
// set 2 new selection in the combo box,
// set 3 title, showing (nn of max.)
// NO too much!!! set 4 picture also to background ;-))
function setsrc() {
   // Use IE Transition
 if (document.images.show.filters) { 
   document.images.show.filters[0].Stop();
 document.images.show.filters[0].Apply();
 // Use a random transition effect
 document.images.show.filters.revealTrans.transition=23;
 }
   document.images.show.src = document.slideform.slide[current].value;
   document.slideform.slide.selectedIndex = current;
   showTitle.innerText = baseTit + " (" + (current+1) + 
   " of " + pixCnt + ") - " + fileList[(current*2)+1];
 // Run the transition in IE
 if (document.images.show.filters) {
   document.images.show.filters[0].Play();
   }
   // document.body.background = fileList[(current*2)];
}

function next() {
 if (document.slideform.slide[current+1]) {
 stop();
 current++;
 setsrc();
 } else first();
}

function previous() {
 if (current-1 >= 0) {
 stop();
 current--;
 setsrc();
 } else last();
}

function first() {
 stop();
 current = 0;
 setsrc();
}

function last() {
 stop();
 current = document.slideform.slide.length-1;
 setsrc();
}

// handle click on start/stop button, current value passed ...
function ap(text) {
 var stg = document.slideform.delaysecs.value; // (user) DELAY
 var i = parseInt(stg);
 if(( i > 0 ) && ( i < 1000000 )) { // change delay period, in milli secs
 rotate_delay = (i * 1000);
 } else {
 stg = ""+(rotate_delay / 1000);
 document.slideform.delaysecs.value = stg;
 }
 // if "Start", change to "Stop" ...
 document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
 rotate(); // do first rotation, and set timer ...
}

function change() {
 stop();
 current = document.slideform.slide.selectedIndex;
 document.images.show.src = document.slideform.slide[current].value;
}

function rotate() {
 timeron = false;
 if (document.slideform.slidebutton.value == "Stop") {
 current = (current == document.slideform.slide.length-1) ? 0 : current+1;
 setsrc();
 timeron = true;
 timerID = window.setTimeout("rotate()", rotate_delay);
 }
}

// End -->
</script>

<title>Construction Slide Show</title>
</head>

<body background="cldsm.jpg">

<h1 align="center">Construction Slide Show</h1>

<center>
<form name=slideform>
<table cellspacing=1 cellpadding=4 bgcolor="#000000">
 <tr>
 <td align="center" bgcolor="white">
 <p ID="showTitle" align="center">
 <b>Construction Slideshow</b>
 </p>
 </td>
 </tr>
 <tr>
 <td align="center" bgcolor="white" width="200" height="150">
 <img name="show" src="dummy.jpg" width="600" height="400" style="filter: revealTrans(TRANSITION=23)">
 </td>
 </tr>
 <tr>
 <td align="center" bgcolor="#c0c0c0">
Select <select name="slide" onChange="change();">
 <option value="temp2/const-001.jpg" selected>temp2/const-001.jpg...
   </option> 
 </select>
Move <input type=button onClick="first();" value="|<<" title="Beginning">
<input type=button onClick="previous();" value="<<" title="Previous">
<input type=button onClick="next();" value=">>" title="Next">
<input type=button onClick="last();" value=">>|" title="End">
Run <input type=button name="slidebutton" onClick="ap(this.value);" value="Start" title="AutoPlay"> 
 <input type=text name="delaysecs" style="WIDTH: 28px; HEIGHT: 23px" size=2 onChange="stop();" value="1" title="Delay in Seconds">
 </td>
 </tr>
</table>
</form>
</center>

<script language="javascript">
<!-- begin
setSlideform(); // load image list to dropdown combo box
// End -->
</script>

<p>Full set of images ...</p>

<?php
global $file_count;
global $m_filearr;
global $meol;
global $arr_fn, $arr_is, $arr_fs, $arr_fd;
$m_wrap = 5;
print '<table border="0" width="100%">'.$meol;
for( $i = 0; $i < $file_count; $i++ )
{
   if( ($i % $m_wrap) == 0 ) {
   print '<tr>'.$meol;
   }
   $arr = $m_filearr[$i];
   $fn = $arr[$arr_fn];
   $alt = basename($fn);
   $alt .= ' image '.$arr[$arr_is];
   $alt .= ' '.$arr[$arr_fs].' bytes';
   print '<td width="20%">'.$meol;
   print '<a target="_blank" href="'.$fn.'">'.$meol;
   print '<img border="0" src="'.$fn.'" width="171" height="128" alt="'.$alt.'">'.$meol;
   print '</a>'.$meol;
   print '</td>'.$meol;
   if( (($i + 1) % $m_wrap) == 0 ) {
   print '</tr>'.$meol;
   }
}
if( ($i % $m_wrap) != 0 ) {
   while( ($i % $m_wrap) != 0 ) {
   print '<td width="20%" align="center">No image</td>'.$meol;
   $i++;
   }
   print '</tr>'.$meol;
}
print '</table>'.$meol;
?>

</body>

</html>

index

Valid HTML 4.01 Transitional