source: trunk/admin/site_reader_local.php @ 1900

Last change on this file since 1900 was 1900, checked in by rub, 17 years ago

Apply property svn:eol-style Value: LF

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 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 1900 2007-03-12 22:33:53Z rub $
9// | last update   : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1900 $
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', 'high_filesize');
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, $has_high = false)
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 ($has_high)
203  {
204    $high_file = dirname($file).'/pwg_high/'.basename($file);
205   
206    $data['high_filesize'] = floor(filesize($high_file)/1024);
207  }
208 
209  if ($conf['use_exif'])
210  {
211    $data = array_merge($data, get_sync_exif_data($file) );
212  }
213
214  if ($conf['use_iptc'])
215  {
216    $data = array_merge($data, get_sync_iptc_data($file) );
217  }
218
219  return $data;
220}
221
222
223//-------------------------------------------------- private functions --------
224function get_representative_ext($path, $filename_wo_ext)
225{
226  global $conf;
227  $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.';
228  foreach ($conf['picture_ext'] as $ext)
229  {
230    $test = $base_test.$ext;
231    if (is_file($test))
232    {
233      return $ext;
234    }
235  }
236  return null;
237}
238
239function get_tn_ext($path, $filename_wo_ext)
240{
241  global $conf;
242
243  $base_test =
244    $path.'/thumbnail/'.$conf['prefix_thumbnail'].$filename_wo_ext.'.';
245
246  foreach ($conf['picture_ext'] as $ext)
247  {
248    $test = $base_test.$ext;
249    if (is_file($test))
250    {
251      return $ext;
252    }
253  }
254
255  return null;
256}
257
258function get_has_high($path, $filename)
259{
260  if (is_file($path.'/pwg_high/'.$filename))
261  {
262    return 'true';
263  }
264
265  return null;
266}
267
268}
269?>
Note: See TracBrowser for help on using the repository browser.