aboutsummaryrefslogtreecommitdiffstats
path: root/admin/create_listing_file.php
blob: 9b94486ef48ee63bf85b3daa99f419caf2cf5031 (plain)
1
2
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
<?php
	$prefixe_thumbnail = "TN-";
	
	
	$tab_ext = array ( 'jpg', 'JPG','gif','GIF','png','PNG' );

	$listing = "";
	
	$local_folder = substr( $PHP_SELF, 0, strrpos( $PHP_SELF, "/" ) + 1 );
	$url = "http://".$HTTP_HOST.$local_folder;
	$listing.= "<url>$url</url>";
	
	// get_dirs retourne un tableau contenant tous les sous-r�pertoires d'un r�pertoire
	function get_dirs( $rep, $indent, $level )
	{
		$sub_rep = array();
		$i = 0;
		$dirs = "";
		if ( $opendir = opendir ( $rep ) )
		{
			while ( $file = readdir ( $opendir ) )
			{
				if ( $file != "." && $file != ".." && is_dir ( $rep."/".$file ) && $file != "thumbnail" )
				{
					$sub_rep[$i++] = $file;
				}
			}
		}
		// write of the dirs
		for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
		{
			$dirs.= "\n".$indent."<dir".$level.">";
			$dirs.= "\n".$indent."\t<name>".$sub_rep[$i]."</name>";
			$dirs.= get_pictures( $rep."/".$sub_rep[$i], $indent."\t" );
			$dirs.= get_dirs( $rep."/".$sub_rep[$i], $indent."\t", $level + 1 );
			$dirs.= "\n".$indent."</dir".$level.">";
		}
		return $dirs;		
	}
	
	function is_image ( $filename )
	{
		global $tab_ext;
		if ( in_array ( substr ( strrchr($filename,"."), 1, strlen ( $filename ) ), $tab_ext ) )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function TN_exist ( $dir, $file )
	{
		global $tab_ext, $prefixe_thumbnail;
		
		$titre = substr ( $file, 0, -4 );
		for ( $i = 0; $i < sizeof ( $tab_ext ); $i++ )
		{
			$test = $dir."/thumbnail/".$prefixe_thumbnail.$titre.".".$tab_ext[$i];
			if ( is_file ( $test ) )
			{
				return $tab_ext[$i];
			}
		}
		return false;
	}

	function get_pictures( $rep, $indent )
	{
		$pictures = array();		
		$i = 0;
		$tn_ext = "";
		$root = "";
		if ( $opendir = opendir ( $rep ) )
		{
			while ( $file = readdir ( $opendir ) )
			{
				if ( is_image( $file ) && $tn_ext = TN_exist( $rep, $file ) )
				{
					$pictures[$i] = array();
					$pictures[$i]['file'] = $file;
					$pictures[$i]['tn_ext'] = $tn_ext;
					$pictures[$i]['date'] = date( "Y-m-d", filemtime ( $rep."/".$file ) );
					$pictures[$i]['filesize'] = floor ( filesize( $rep."/".$file ) / 1024 );
					$image_size = @getimagesize( $rep."/".$file );
					$pictures[$i]['width'] = $image_size[0];
					$pictures[$i]['height'] = $image_size[1];
					$i++;
				}
			}
		}
		// write of the node <root> with all the pictures at the root of the directory
		$root.= "\n".$indent."<root>";
		if ( sizeof( $pictures ) > 0 )
		{
			for( $i = 0; $i < sizeof( $pictures ); $i++ )
			{
				$root.= "\n".$indent."\t<picture>";
				$root.= "\n".$indent."\t\t<file>".$pictures[$i]['file']."</file>";
				$root.= "\n".$indent."\t\t<tn_ext>".$pictures[$i]['tn_ext']."</tn_ext>";
				$root.= "\n".$indent."\t\t<date>".$pictures[$i]['date']."</date>";
				$root.= "\n".$indent."\t\t<filesize>".$pictures[$i]['filesize']."</filesize>";
				$root.= "\n".$indent."\t\t<width>".$pictures[$i]['width']."</width>";
				$root.= "\n".$indent."\t\t<height>".$pictures[$i]['height']."</height>";
				$root.= "\n".$indent."\t</picture>";
			}
		}
		$root.= "\n".$indent."</root>";
		return $root;
	}

	$listing.= get_dirs( ".", "", 0 );

	if ( $fp = @fopen("./listing.xml","w") )
	{
		fwrite( $fp, $listing );
		fclose( $fp );
	}
	else
	{
		echo "impossible de cr�er ou d'�crire dans le fichier listing.xml";
	}

	//echo str_replace( "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", nl2br( htmlspecialchars( $listing, ENT_QUOTES ) ) );
	echo "listing.xml created";
?>