source: tags/version_1_3/admin/create_listing_file.php @ 5647

Last change on this file since 5647 was 2, checked in by z0rglub, 21 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1<?php
2        $prefixe_thumbnail = "TN-";
3       
4       
5        $tab_ext = array ( 'jpg', 'JPG','gif','GIF','png','PNG' );
6
7        $listing = "";
8       
9        $local_folder = substr( $PHP_SELF, 0, strrpos( $PHP_SELF, "/" ) + 1 );
10        $url = "http://".$HTTP_HOST.$local_folder;
11        $listing.= "<url>$url</url>";
12       
13        // get_dirs retourne un tableau contenant tous les sous-répertoires d'un répertoire
14        function get_dirs( $rep, $indent, $level )
15        {
16                $sub_rep = array();
17                $i = 0;
18                $dirs = "";
19                if ( $opendir = opendir ( $rep ) )
20                {
21                        while ( $file = readdir ( $opendir ) )
22                        {
23                                if ( $file != "." && $file != ".." && is_dir ( $rep."/".$file ) && $file != "thumbnail" )
24                                {
25                                        $sub_rep[$i++] = $file;
26                                }
27                        }
28                }
29                // write of the dirs
30                for ( $i = 0; $i < sizeof( $sub_rep ); $i++ )
31                {
32                        $dirs.= "\n".$indent."<dir".$level.">";
33                        $dirs.= "\n".$indent."\t<name>".$sub_rep[$i]."</name>";
34                        $dirs.= get_pictures( $rep."/".$sub_rep[$i], $indent."\t" );
35                        $dirs.= get_dirs( $rep."/".$sub_rep[$i], $indent."\t", $level + 1 );
36                        $dirs.= "\n".$indent."</dir".$level.">";
37                }
38                return $dirs;           
39        }
40       
41        function is_image ( $filename )
42        {
43                global $tab_ext;
44                if ( in_array ( substr ( strrchr($filename,"."), 1, strlen ( $filename ) ), $tab_ext ) )
45                {
46                        return true;
47                }
48                else
49                {
50                        return false;
51                }
52        }
53       
54        function TN_exist ( $dir, $file )
55        {
56                global $tab_ext, $prefixe_thumbnail;
57               
58                $titre = substr ( $file, 0, -4 );
59                for ( $i = 0; $i < sizeof ( $tab_ext ); $i++ )
60                {
61                        $test = $dir."/thumbnail/".$prefixe_thumbnail.$titre.".".$tab_ext[$i];
62                        if ( is_file ( $test ) )
63                        {
64                                return $tab_ext[$i];
65                        }
66                }
67                return false;
68        }
69
70        function get_pictures( $rep, $indent )
71        {
72                $pictures = array();           
73                $i = 0;
74                $tn_ext = "";
75                $root = "";
76                if ( $opendir = opendir ( $rep ) )
77                {
78                        while ( $file = readdir ( $opendir ) )
79                        {
80                                if ( is_image( $file ) && $tn_ext = TN_exist( $rep, $file ) )
81                                {
82                                        $pictures[$i] = array();
83                                        $pictures[$i]['file'] = $file;
84                                        $pictures[$i]['tn_ext'] = $tn_ext;
85                                        $pictures[$i]['date'] = date( "Y-m-d", filemtime ( $rep."/".$file ) );
86                                        $pictures[$i]['filesize'] = floor ( filesize( $rep."/".$file ) / 1024 );
87                                        $image_size = @getimagesize( $rep."/".$file );
88                                        $pictures[$i]['width'] = $image_size[0];
89                                        $pictures[$i]['height'] = $image_size[1];
90                                        $i++;
91                                }
92                        }
93                }
94                // write of the node <root> with all the pictures at the root of the directory
95                $root.= "\n".$indent."<root>";
96                if ( sizeof( $pictures ) > 0 )
97                {
98                        for( $i = 0; $i < sizeof( $pictures ); $i++ )
99                        {
100                                $root.= "\n".$indent."\t<picture>";
101                                $root.= "\n".$indent."\t\t<file>".$pictures[$i]['file']."</file>";
102                                $root.= "\n".$indent."\t\t<tn_ext>".$pictures[$i]['tn_ext']."</tn_ext>";
103                                $root.= "\n".$indent."\t\t<date>".$pictures[$i]['date']."</date>";
104                                $root.= "\n".$indent."\t\t<filesize>".$pictures[$i]['filesize']."</filesize>";
105                                $root.= "\n".$indent."\t\t<width>".$pictures[$i]['width']."</width>";
106                                $root.= "\n".$indent."\t\t<height>".$pictures[$i]['height']."</height>";
107                                $root.= "\n".$indent."\t</picture>";
108                        }
109                }
110                $root.= "\n".$indent."</root>";
111                return $root;
112        }
113
114        $listing.= get_dirs( ".", "", 0 );
115
116        if ( $fp = @fopen("./listing.xml","w") )
117        {
118                fwrite( $fp, $listing );
119                fclose( $fp );
120        }
121        else
122        {
123                echo "impossible de créer ou d'écrire dans le fichier listing.xml";
124        }
125
126        //echo str_replace( "\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", nl2br( htmlspecialchars( $listing, ENT_QUOTES ) ) );
127        echo "listing.xml created";
128?>
Note: See TracBrowser for help on using the repository browser.