[2] | 1 | <?php |
---|
[19] | 2 | $prefix_thumbnail = 'TN-'; |
---|
[2] | 3 | |
---|
[10] | 4 | $conf['picture_ext'] = array ( 'jpg', 'gif', 'png', 'JPG', 'GIF', 'PNG' ); |
---|
[2] | 5 | |
---|
[10] | 6 | $listing = ''; |
---|
| 7 | |
---|
| 8 | $end = strrpos( $_SERVER['PHP_SELF'], '/' ) + 1; |
---|
| 9 | $local_folder = substr( $_SERVER['PHP_SELF'], 0, $end ); |
---|
| 10 | $url = 'http://'.$_SERVER['HTTP_HOST'].$local_folder; |
---|
| 11 | |
---|
| 12 | $listing.= "<url>$url</url>"; |
---|
[2] | 13 | |
---|
[10] | 14 | // get_dirs retourne un tableau contenant tous les sous-répertoires d'un |
---|
| 15 | // répertoire |
---|
| 16 | function get_dirs( $rep, $indent, $level ) |
---|
| 17 | { |
---|
| 18 | $sub_rep = array(); |
---|
| 19 | $i = 0; |
---|
| 20 | $dirs = ""; |
---|
| 21 | if ( $opendir = opendir ( $rep ) ) |
---|
| 22 | { |
---|
| 23 | while ( $file = readdir ( $opendir ) ) |
---|
| 24 | { |
---|
| 25 | if ( $file != "." |
---|
| 26 | and $file != ".." |
---|
| 27 | and is_dir ( $rep."/".$file ) |
---|
| 28 | and $file != "thumbnail" ) |
---|
| 29 | { |
---|
| 30 | $sub_rep[$i++] = $file; |
---|
| 31 | } |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | // write of the dirs |
---|
| 35 | for ( $i = 0; $i < sizeof( $sub_rep ); $i++ ) |
---|
| 36 | { |
---|
| 37 | $dirs.= "\n".$indent.'<dir'.$level.' name="'.$sub_rep[$i].'">'; |
---|
| 38 | $dirs.= get_pictures( $rep.'/'.$sub_rep[$i], $indent.' ' ); |
---|
| 39 | $dirs.= get_dirs( $rep.'/'.$sub_rep[$i], $indent.' ', $level + 1 ); |
---|
| 40 | $dirs.= "\n".$indent.'</dir'.$level.'>'; |
---|
| 41 | } |
---|
| 42 | return $dirs; |
---|
| 43 | } |
---|
[2] | 44 | |
---|
[10] | 45 | // get_extension returns the part of the string after the last "." |
---|
| 46 | function get_extension( $filename ) |
---|
| 47 | { |
---|
| 48 | return substr( strrchr( $filename, '.' ), 1, strlen ( $filename ) ); |
---|
| 49 | } |
---|
[2] | 50 | |
---|
[10] | 51 | // get_filename_wo_extension returns the part of the string before the last |
---|
| 52 | // ".". |
---|
| 53 | // get_filename_wo_extension( 'test.tar.gz' ) -> 'test.tar' |
---|
| 54 | function get_filename_wo_extension( $filename ) |
---|
| 55 | { |
---|
| 56 | return substr( $filename, 0, strrpos( $filename, '.' ) ); |
---|
| 57 | } |
---|
[2] | 58 | |
---|
[10] | 59 | function is_image( $filename ) |
---|
| 60 | { |
---|
| 61 | global $conf; |
---|
[2] | 62 | |
---|
[10] | 63 | if ( !is_dir( $filename ) |
---|
| 64 | and in_array( get_extension( $filename ), $conf['picture_ext'] ) ) |
---|
| 65 | { |
---|
| 66 | return true; |
---|
| 67 | } |
---|
| 68 | return false; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function TN_exists( $dir, $file ) |
---|
| 72 | { |
---|
[19] | 73 | global $conf, $prefix_thumbnail; |
---|
[10] | 74 | |
---|
| 75 | $titre = get_filename_wo_extension( $file ); |
---|
| 76 | |
---|
| 77 | for ( $i = 0; $i < sizeof ( $conf['picture_ext'] ); $i++ ) |
---|
| 78 | { |
---|
[19] | 79 | $base_tn_name = $dir.'/thumbnail/'.$prefix_thumbnail.$titre.'.'; |
---|
[10] | 80 | $ext = $conf['picture_ext'][$i]; |
---|
| 81 | if ( is_file( $base_tn_name.$ext ) ) |
---|
| 82 | { |
---|
| 83 | return $ext; |
---|
| 84 | } |
---|
| 85 | } |
---|
| 86 | echo 'The thumbnail is missing for '.$dir.'/'.$file; |
---|
[19] | 87 | echo '-> '.$dir.'/thumbnail/'.$prefix_thumbnail.$titre.'.xxx'; |
---|
[10] | 88 | echo ' ("xxx" can be : '; |
---|
| 89 | for ( $i = 0; $i < sizeof ( $conf['picture_ext'] ); $i++ ) |
---|
| 90 | { |
---|
| 91 | if ( $i > 0 ) |
---|
| 92 | { |
---|
| 93 | echo ', '; |
---|
| 94 | } |
---|
| 95 | echo '"'.$conf['picture_ext'][$i].'"'; |
---|
| 96 | } |
---|
| 97 | echo ')<br />'; |
---|
| 98 | return false; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | function get_pictures( $rep, $indent ) |
---|
| 102 | { |
---|
| 103 | $pictures = array(); |
---|
| 104 | |
---|
| 105 | $tn_ext = ''; |
---|
| 106 | $root = ''; |
---|
| 107 | if ( $opendir = opendir ( $rep ) ) |
---|
| 108 | { |
---|
| 109 | while ( $file = readdir ( $opendir ) ) |
---|
| 110 | { |
---|
| 111 | if ( is_image( $file ) and $tn_ext = TN_exists( $rep, $file ) ) |
---|
| 112 | { |
---|
| 113 | $picture = array(); |
---|
| 114 | |
---|
| 115 | $picture['file'] = $file; |
---|
| 116 | $picture['tn_ext'] = $tn_ext; |
---|
| 117 | $picture['date'] = date('Y-m-d',filemtime( $rep.'/'.$file ) ); |
---|
| 118 | $picture['filesize'] = floor( filesize( $rep."/".$file ) / 1024 ); |
---|
| 119 | $image_size = @getimagesize( $rep."/".$file ); |
---|
| 120 | $picture['width'] = $image_size[0]; |
---|
| 121 | $picture['height'] = $image_size[1]; |
---|
| 122 | |
---|
| 123 | array_push( $pictures, $picture ); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | // write of the node <root> with all the pictures at the root of the |
---|
| 128 | // directory |
---|
| 129 | $root.= "\n".$indent."<root>"; |
---|
| 130 | if ( sizeof( $pictures ) > 0 ) |
---|
| 131 | { |
---|
| 132 | for( $i = 0; $i < sizeof( $pictures ); $i++ ) |
---|
| 133 | { |
---|
| 134 | $root.= "\n".$indent.' '; |
---|
| 135 | $root.= '<picture'; |
---|
| 136 | $root.= ' file="'. $pictures[$i]['file']. '"'; |
---|
| 137 | $root.= ' tn_ext="'. $pictures[$i]['tn_ext']. '"'; |
---|
| 138 | $root.= ' date="'. $pictures[$i]['date']. '"'; |
---|
| 139 | $root.= ' filesize="'. $pictures[$i]['filesize']. '"'; |
---|
| 140 | $root.= ' width="'. $pictures[$i]['width']. '"'; |
---|
| 141 | $root.= ' height="'. $pictures[$i]['height']. '"'; |
---|
| 142 | $root.= ' />'; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | $root.= "\n".$indent.'</root>'; |
---|
| 146 | return $root; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | $listing.= get_dirs( '.', '', 0 ); |
---|
| 150 | |
---|
| 151 | if ( $fp = @fopen("./listing.xml","w") ) |
---|
| 152 | { |
---|
| 153 | fwrite( $fp, $listing ); |
---|
| 154 | fclose( $fp ); |
---|
| 155 | } |
---|
| 156 | else |
---|
| 157 | { |
---|
| 158 | echo "I can't write the file listing.xml"; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | echo "listing.xml created"; |
---|
[2] | 162 | ?> |
---|