source: branches/2.4/admin/site_reader_local.php @ 17101

Last change on this file since 17101 was 12922, checked in by mistic100, 13 years ago

update Piwigo headers to 2012, last change before the expected (or not) apocalypse

  • Property svn:eol-style set to LF
File size: 5.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24// provides data for site synchronization from the local file system
25class LocalSiteReader
26{
27
28var $site_url;
29
30function LocalSiteReader($url)
31{
32  $this->site_url = $url;
33  global $conf;
34  if (!isset($conf['flip_file_ext']))
35  {
36    $conf['flip_file_ext'] = array_flip($conf['file_ext']);
37  }
38  if (!isset($conf['flip_picture_ext']))
39  {
40    $conf['flip_picture_ext'] = array_flip($conf['picture_ext']);
41  }
42}
43
44/**
45 * Is this local site ok ?
46 *
47 * @return true on success, false otherwise
48 */
49function open()
50{
51  global $errors;
52
53  if (!is_dir($this->site_url))
54  {
55    array_push(
56      $errors,
57      array(
58        'path' => $this->site_url,
59        'type' => 'PWG-ERROR-NO-FS'
60        )
61      );
62
63    return false;
64  }
65
66  return true;
67}
68
69// retrieve file system sub-directories fulldirs
70function get_full_directories($basedir)
71{
72  $fs_fulldirs = get_fs_directories($basedir);
73  return $fs_fulldirs;
74}
75
76/**
77 * Returns an array with all file system files according to $conf['file_ext']
78 * and $conf['picture_ext']
79 * @param string $path recurse in this directory
80 * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... )
81 */
82function get_elements($path)
83{
84  global $conf;
85
86  $subdirs = array();
87  $fs = array();
88  if (is_dir($path) && $contents = opendir($path) )
89  {
90    while (($node = readdir($contents)) !== false)
91    {
92      if ($node == '.' or $node == '..') continue;
93
94      if (is_file($path.'/'.$node))
95      {
96        $extension = get_extension($node);
97        $filename_wo_ext = get_filename_wo_extension($node);
98
99        if ( isset($conf['flip_file_ext'][$extension]) )
100        {
101          $representative_ext = null;
102          if (! isset($conf['flip_picture_ext'][$extension]) )
103          {
104            $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
105          }
106          $fs[ $path.'/'.$node ] = array(
107            'representative_ext' => $representative_ext,
108            );
109        }
110      }
111      elseif (is_dir($path.'/'.$node)
112               and $node != 'pwg_high'
113               and $node != 'pwg_representative'
114               and $node != 'thumbnail' )
115      {
116        array_push($subdirs, $node);
117      }
118    } //end while readdir
119    closedir($contents);
120
121    foreach ($subdirs as $subdir)
122    {
123      $tmp_fs = $this->get_elements($path.'/'.$subdir);
124      $fs = array_merge($fs, $tmp_fs);
125    }
126    ksort($fs);
127  } //end if is_dir
128  return $fs;
129}
130
131// returns the name of the attributes that are supported for
132// files update/synchronization
133function get_update_attributes()
134{
135  return array('representative_ext');
136}
137
138function get_element_update_attributes($file)
139{
140  global $conf;
141  $data = array();
142
143  $filename = basename($file);
144  $extension = get_extension($filename);
145
146  $representative_ext = null;
147  if (! isset($conf['flip_picture_ext'][$extension]) )
148  {
149    $dirname = dirname($file);
150    $filename_wo_ext = get_filename_wo_extension($filename);
151    $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
152  }
153
154  $data['representative_ext'] = $representative_ext;
155  return $data;
156}
157
158// returns the name of the attributes that are supported for
159// metadata update/synchronization according to configuration
160function get_metadata_attributes()
161{
162  return get_sync_metadata_attributes();
163}
164
165// returns a hash of attributes (metadata+filesize+width,...) for file
166function get_element_metadata($infos)
167{
168  return get_sync_metadata($infos);
169}
170
171
172//-------------------------------------------------- private functions --------
173function get_representative_ext($path, $filename_wo_ext)
174{
175  global $conf;
176  $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.';
177  foreach ($conf['picture_ext'] as $ext)
178  {
179    $test = $base_test.$ext;
180    if (is_file($test))
181    {
182      return $ext;
183    }
184  }
185  return null;
186}
187
188
189}
190?>
Note: See TracBrowser for help on using the repository browser.