source: trunk/admin/create_listing_file.php @ 61

Last change on this file since 61 was 57, checked in by z0rglub, 21 years ago

improve the header of each file

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