| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 
 | <?php
 
class PHPDiapo {
	var $relPath;
	var $images;
	var $id;
	var $className;
	var $transition_time=3;
	var $transition_pause;
 
	function PHPDiapo ($path,$id,$className="",$timeout=3, $attrs=array()) {
        $this->attrs = $attrs;
		$this->relPath = $path;
		$this->id = $id;
		$this->className = $className;
		if ($timeout) $this->transition_pause = $timeout;
		$this->init();
		$this->write();
		}
 
    function init() {
 
 
		$this->images=array();
		$dir = $_SERVER["PATH_TRANSLATED"];
		$dir = substr($dir,0,strrpos($dir,"/")+1);
		$dir .= $this->relPath;
      	$hdl = opendir($dir);
 
		while (false !== ($file = readdir($hdl))) {
		       if($file!="." && $file!="..") {
			   // check file extension
			   $pattern = '/\.(gif|png|jpg|jpeg)$/i';
			   if (!preg_match($pattern, $file, $matches)) continue;
			   if(is_file($dir."/".$file))
			       $this->images[]="$this->relPath/$file";
                 //$test2=$test[0];
				//$this->test = $test2;
 
		//	   $this->images[]="$this->test/1200_1.jpg";
				}
		}
	}
 
	function write() {
		$this->write_func();
		$first=$this->images[0];
		$this->write_JS_init();
		echo $this->img($first,$id=$this->id,$className=$this->className);
		$this->write_JS_launch();
	} 
 
	function write_JS_init() {
		echo  "images['".$this->id."']=new Array();\r";
		for ($i=0;$i<sizeof($this->images);$i++) {
			echo  "images['".$this->id."'][$i]=new Image();\r";
			echo  "images['".$this->id."'][$i].src=\"http://doubsoccase.free.fr/ebay/".$this->images[$i]."\";\r";
			echo  "images['".$this->id."'][$i].alt=\"".$this->get_alt($this->images[$i])."\";\r";
		}
		echo "</script>\r\r";
	}
 
 
	function write_func(){
                echo "\r<script type=\"text/javascript\">\r";
 
		static $already_write = false;
		if ($already_write) {
 
                }
                else {
 
            echo "
var FRAME_PER_SEC = 20;
function set_opacity(el, op) {
    el.style.opacity = op;
    el.style.MozOpacity = op;
    el.style.KhtmlOpacity = op;
    el.style.filter = 'alpha(opacity=' + op*100 + ')';
    el.opacity = op;
}
 
function fade_in(imageId) {
    var img = document.getElementById(imageId);
    var incr = 1/((img.transition_time/3)*FRAME_PER_SEC);
    var newOp = img.opacity+incr;
    newOp = (newOp > 1) ? 1.0 : newOp;
    set_opacity(img, newOp);
    if (newOp < 1) setTimeout('fade_in(\"'+imageId+'\")',1000/FRAME_PER_SEC);
}
 
var images = new Array();
function run_diapo(diapoId) {
    obj = document.getElementById(diapoId);
    obj.src = images[diapoId][obj.index].src;
    obj.alt = images[diapoId][obj.index].alt;
    obj.title = images[diapoId][obj.index].alt;
    obj.opacity = 0.0;
 
    fade_in(diapoId);
    obj.index+=1;
    if (obj.index >= obj.length_diapo) obj.index=0;
    obj.timeout = setTimeout('run_diapo(\"'+diapoId+'\")', obj.transition_pause * 1000);
}\r";
			$already_write = true;
		}
	}
 
	function write_JS_launch() {
		$diapoID=$this->id;
		echo "\r<script type=\"text/javascript\">\r";
		echo "obj = document.getElementById('".$diapoID."');\r";
		echo "obj.transition_time=".$this->transition_time.";\r";
		echo "obj.transition_pause=".$this->transition_pause.";\r";
		echo "obj.index=0;\r";
		echo "obj.length_diapo=images['".$diapoID."'].length;\r";
		echo "obj.timeout;\r";
 
		echo "if (obj.length_diapo > 0) run_diapo('".$diapoID."');\r";
		echo "</script>\r\r";
	}
 
	function get_alt($src) {
		#  strip path
		$txt=substr($src,strrpos($src,"/")+1);
		# strip extension
		$txt=substr($txt,0,strrpos($txt,"."));
		# strip special chars
		$tostrip=array("_",",","-");
		for ($i=0;$i<sizeof($tostrip);$i++) $txt=str_replace($tostrip[$i]," ",$txt);
		return $txt;
	}
 
	function img($src,$id="",$class="") {
        $has_link = false;
		$alt=$this->get_alt($src);
        $img = "<img id='$id'  name='$id' class='$class' alt='$alt' title='$alt' src='$src'";
        foreach($this->attrs as $key=>$value)
        {
            if ($key=="href" && !$has_link) {
                $has_link = true;
                $img = "<a href=$value>$img";
            }
            else {
                $img .= " $key='$value' ";
            }
        }
        $img .= "/>\r";
        if ($has_link) $img .= "</a>";
		return $img;
	}
 }
 
?> | 
Partager