Changeset 10 for trunk/admin/create_listing_file.php
- Timestamp:
- May 17, 2003, 12:49:14 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/create_listing_file.php
r2 r10 1 1 <?php 2 $prefixe_thumbnail = "TN-";2 $prefixe_thumbnail = 'TN-'; 3 3 4 $conf['picture_ext'] = array ( 'jpg', 'gif', 'png', 'JPG', 'GIF', 'PNG' ); 5 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>"; 4 13 5 $tab_ext = array ( 'jpg', 'JPG','gif','GIF','png','PNG' ); 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 } 6 44 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 } 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 } 69 50 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 } 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 } 113 58 114 $listing.= get_dirs( ".", "", 0 ); 59 function is_image( $filename ) 60 { 61 global $conf; 115 62 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 } 63 if ( !is_dir( $filename ) 64 and in_array( get_extension( $filename ), $conf['picture_ext'] ) ) 65 { 66 return true; 67 } 68 return false; 69 } 125 70 126 //echo str_replace( "\t", " ", nl2br( htmlspecialchars( $listing, ENT_QUOTES ) ) ); 127 echo "listing.xml created"; 71 function TN_exists( $dir, $file ) 72 { 73 global $conf, $prefixe_thumbnail; 74 75 $titre = get_filename_wo_extension( $file ); 76 77 for ( $i = 0; $i < sizeof ( $conf['picture_ext'] ); $i++ ) 78 { 79 $base_tn_name = $dir.'/thumbnail/'.$prefixe_thumbnail.$titre.'.'; 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; 87 echo '-> '.$dir.'/thumbnail/'.$prefixe_thumbnail.$titre.'.xxx'; 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"; 128 162 ?>
Note: See TracChangeset
for help on using the changeset viewer.