source: trunk/admin/site_reader_local.php @ 1717

Last change on this file since 1717 was 1717, checked in by rvelices, 17 years ago
  • bug 471: apostrophe lors de l'ajout d'un tag (different behavior depending on

magic_quotes_gpc)

  • metadata synchronization correction: iptc keywords were MySql escaped 2

times when synchronizing from site manager, but only once when synchronizing
one image

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: site_reader_local.php 1717 2007-01-11 23:56:36Z rvelices $
9// | last update   : $Date: 2007-01-11 23:56:36 +0000 (Thu, 11 Jan 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1717 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28// provides data for site synchronization from the local file system
29class LocalSiteReader
30{
31
32var $site_url;
33
34function LocalSiteReader($url)
35{
36  $this->site_url = $url;
37}
38
39/**
40 * Is this local site ok ?
41 *
42 * @return true on success, false otherwise
43 */
44function open()
45{
46  global $errors;
47
48  if (!is_dir($this->site_url))
49  {
50    array_push(
51      $errors,
52      array(
53        'path' => $this->site_url,
54        'type' => 'PWG-ERROR-NO-FS'
55        )
56      );
57
58    return false;
59  }
60
61  return true;
62}
63
64// retrieve file system sub-directories fulldirs
65function get_full_directories($basedir)
66{
67  $fs_fulldirs = get_fs_directories($basedir);
68  return $fs_fulldirs;
69}
70
71/**
72 * Returns an array with all file system files according to $conf['file_ext']
73 * and $conf['picture_ext']
74 * @param string $path recurse in this directory
75 * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
76 */
77function get_elements($path)
78{
79  global $conf;
80  if (!isset($conf['flip_file_ext']))
81  {
82    $conf['flip_file_ext'] = array_flip($conf['file_ext']);
83  }
84
85  $subdirs = array();
86  $fs = array();
87  if (is_dir($path) && $contents = opendir($path) )
88  {
89    while (($node = readdir($contents)) !== false)
90    {
91      if (is_file($path.'/'.$node))
92      {
93        $extension = get_extension($node);
94        $filename_wo_ext = get_filename_wo_extension($node);
95
96        if ( isset($conf['flip_file_ext'][$extension]) )
97        {
98          $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
99          $fs[ $path.'/'.$node ] = array(
100            'tn_ext' => $tn_ext,
101            );
102        }
103      }
104      elseif (is_dir($path.'/'.$node)
105               and $node != '.'
106               and $node != '..'
107               and $node != 'pwg_high'
108               and $node != 'pwg_representative'
109               and $node != 'thumbnail' )
110      {
111        array_push($subdirs, $node);
112      }
113    } //end while readdir
114    closedir($contents);
115
116    foreach ($subdirs as $subdir)
117    {
118      $tmp_fs = $this->get_elements($path.'/'.$subdir);
119      $fs = array_merge($fs, $tmp_fs);
120    }
121  } //end if is_dir
122  return $fs;
123}
124
125// returns the name of the attributes that are supported for
126// files update/synchronization
127function get_update_attributes()
128{
129  return array('tn_ext', 'has_high', 'representative_ext');
130}
131
132function get_element_update_attributes($file)
133{
134  global $conf;
135  $data = array();
136
137  $filename = basename($file);
138  $dirname = dirname($file);
139  $filename_wo_ext = get_filename_wo_extension($filename);
140  $extension = get_extension($filename);
141
142  $data['tn_ext'] = $this->get_tn_ext($dirname, $filename_wo_ext);
143  $data['has_high'] = $this->get_has_high($dirname, $filename);
144
145  if ( !isset($conf['flip_picture_ext'][$extension]) )
146  {
147    $data['representative_ext'] = $this->get_representative_ext(
148        $dirname, $filename_wo_ext
149      );
150  }
151  return $data;
152}
153
154// returns the name of the attributes that are supported for
155// metadata update/synchronization according to configuration
156function get_metadata_attributes()
157{
158  global $conf;
159
160  $update_fields = array('filesize', 'width', 'height');
161
162  if ($conf['use_exif'])
163  {
164    $update_fields =
165      array_merge(
166        $update_fields,
167        array_keys($conf['use_exif_mapping'])
168        );
169  }
170
171  if ($conf['use_iptc'])
172  {
173    $update_fields =
174      array_merge(
175        $update_fields,
176        array_keys($conf['use_iptc_mapping'])
177        );
178  }
179
180  return $update_fields;
181}
182
183// returns a hash of attributes (metadata+filesize+width,...) for file
184function get_element_metadata($file)
185{
186  global $conf;
187  if (!is_file($file))
188  {
189    return null;
190  }
191
192  $data = array();
193
194  $data['filesize'] = floor(filesize($file)/1024);
195
196  if ($image_size = @getimagesize($file))
197  {
198    $data['width'] = $image_size[0];
199    $data['height'] = $image_size[1];
200  }
201
202  if ($conf['use_exif'])
203  {
204    $data = array_merge($data, get_sync_exif_data($file) );
205  }
206
207  if ($conf['use_iptc'])
208  {
209    $data = array_merge($data, get_sync_iptc_data($file) );
210  }
211
212  return $data;
213}
214
215
216//-------------------------------------------------- private functions --------
217function get_representative_ext($path, $filename_wo_ext)
218{
219  global $conf;
220  $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.';
221  foreach ($conf['picture_ext'] as $ext)
222  {
223    $test = $base_test.$ext;
224    if (is_file($test))
225    {
226      return $ext;
227    }
228  }
229  return null;
230}
231
232function get_tn_ext($path, $filename_wo_ext)
233{
234  global $conf;
235
236  $base_test =
237    $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';
238
239  foreach ($conf['picture_ext'] as $ext)
240  {
241    $test = $base_test.$ext;
242    if (is_file($test))
243    {
244      return $ext;
245    }
246  }
247
248  return null;
249}
250
251function get_has_high($path, $filename)
252{
253  if (is_file($path.'/pwg_high/'.$filename))
254  {
255    return 'true';
256  }
257
258  return null;
259}
260
261}
262?>
Note: See TracBrowser for help on using the repository browser.