source: trunk/admin/site_reader_local.php @ 1029

Last change on this file since 1029 was 1029, checked in by rvelices, 18 years ago
  • remake of Remote sites and Synchronize:
    • synchronization for remote and local sites are done by the same code
    • remote sites can update metadata now (not before) - bug 279
    • fixes bug 82: has_high column
  • improve feature 280: user sort by filename
  • fix path to template mimetypes icons
  • bug 284: session cookie lifetime, deletion on logout and corrected issue

when db upgrades were missing

File size: 7.0 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-2006 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-12-03 17:03:58 -0500 (Sat, 03 Dec 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 967 $
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  if (!is_dir($this->site_url))
48  {
49    array_push($errors, array('path' => $this->site_url, 'type' => 'PWG-ERROR-NODIR'));
50    return false;
51  }
52  return true;
53}
54
55// retrieve file system sub-directories fulldirs
56function get_full_directories($basedir)
57{
58  $fs_fulldirs = get_fs_directories($basedir);
59  return $fs_fulldirs;
60}
61
62/**
63 * Returns an array with all file system files according to $conf['file_ext']
64 * and $conf['picture_ext']
65 * @param string $path recurse in this directory
66 * @return array like "pic.jpg"=>array('tn_ext'=>'jpg' ... )
67 */
68function get_elements($path)
69{
70  global $conf;
71  if (!isset($conf['flip_picture_ext']))
72  {
73    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
74  }
75  if (!isset($conf['flip_file_ext']))
76  {
77    $conf['flip_file_ext'] = array_flip($conf['file_ext']);
78  }
79
80  $subdirs = array();
81  $fs = array();
82  if (is_dir($path) && $contents = opendir($path) )
83  {
84    while (($node = readdir($contents)) !== false)
85    {
86      if (is_file($path.'/'.$node))
87      {
88        $extension = get_extension($node);
89        $filename_wo_ext = get_filename_wo_extension($node);
90
91        // searching the thumbnail
92        $tn_ext = $this->get_tn_ext($path, $filename_wo_ext);
93
94        if (isset($conf['flip_picture_ext'][$extension]))
95        {
96          $fs[ $path.'/'.$node ] = array(
97            'tn_ext' => $tn_ext,
98            'has_high' => $this->get_has_high($path, $node)
99            );
100        }
101        else if (isset($conf['flip_file_ext'][$extension]))
102        { // file not a picture
103          $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
104
105          $fs[ $path.'/'.$node ] = array(
106            'tn_ext' => $tn_ext,
107            'representative_ext' => $representative_ext
108            );
109        }
110
111      }
112      elseif (is_dir($path.'/'.$node)
113               and $node != '.'
114               and $node != '..'
115               and $node != 'pwg_high'
116               and $node != 'pwg_representative'
117               and $node != 'thumbnail' )
118      {
119        array_push($subdirs, $node);
120      }
121    } //end while readdir
122    closedir($contents);
123
124    foreach ($subdirs as $subdir)
125    {
126      $tmp_fs = $this->get_elements($path.'/'.$subdir);
127      $fs = array_merge($fs, $tmp_fs);
128    }
129  } //end if is_dir
130  return $fs;
131}
132
133// returns the name of the attributes that are supported for
134// update/synchronization according to configuration
135function get_update_attributes()
136{
137  global $conf;
138  $update_fields = array( 'has_high', 'representative_ext', 
139      'filesize', 'width', 'height' );
140  if ($conf['use_exif'])
141  {
142    $update_fields =
143      array_merge(
144        $update_fields,
145        array_keys($conf['use_exif_mapping'])
146        );
147  }
148
149  if ($conf['use_iptc'])
150  {
151    $update_fields =
152      array_merge(
153        $update_fields,
154        array_keys($conf['use_iptc_mapping'])
155        );
156  }
157  return $update_fields;
158}
159
160// returns a hash of attributes (metadata+filesize+width,...) for file
161function get_element_update_attributes($file)
162{
163  global $conf;
164  if (!is_file($file))
165  {
166    return null;
167  }
168 
169  $data = array();
170 
171  $filename = basename($file);
172  $data['has_high'] = $this->get_has_high( dirname($file), $filename );
173  $data['representative_ext'] = $this->get_representative_ext( dirname($file), 
174                                        get_filename_wo_extension($filename) );
175 
176  $data['filesize'] = floor(filesize($file)/1024);
177  if ($image_size = @getimagesize($file))
178  {
179    $data['width'] = $image_size[0];
180    $data['height'] = $image_size[1];
181  }
182
183  if ($conf['use_exif'])
184  {
185    $exif = get_sync_exif_data($file);
186
187    if (count($exif) > 0)
188    {
189      foreach (array_keys($exif) as $key)
190      {
191        $data[$key] = addslashes($exif[$key]);
192      }
193    }
194  }
195
196  if ($conf['use_iptc'])
197  {
198    $iptc = get_sync_iptc_data($file);
199    if (count($iptc) > 0)
200    {
201      foreach (array_keys($iptc) as $key)
202      {
203        $data[$key] = addslashes($iptc[$key]);
204      }
205    }
206  }
207  return $data;
208}
209
210
211//-------------------------------------------------- private functions --------
212function get_representative_ext($path, $filename_wo_ext)
213{
214  global $conf;
215  $base_test = $path.'/pwg_representative/';
216  $base_test.= $filename_wo_ext.'.';
217  foreach ($conf['picture_ext'] as $ext)
218  {
219    $test = $base_test.$ext;
220    if (is_file($test))
221    {
222      return $ext;
223    }
224  }
225  return null;
226}
227
228function get_tn_ext($path, $filename_wo_ext)
229{
230  global $conf;
231  $base_test = $path.'/thumbnail/';
232  $base_test.= $conf['prefix_thumbnail'].$filename_wo_ext.'.';
233  foreach ($conf['picture_ext'] as $ext)
234  {
235    $test = $base_test.$ext;
236    if (is_file($test))
237    {
238      return $ext;
239    }
240  }
241  return null;
242}
243
244function get_has_high($path, $filename)
245{
246  if (is_file($path.'/pwg_high/'.$filename))
247  {
248    return 'true';
249  }
250  return null;
251}
252
253}
254?>
Note: See TracBrowser for help on using the repository browser.