source: trunk/admin/site_reader_local.php @ 28134

Last change on this file since 28134 was 26461, checked in by mistic100, 11 years ago

Update headers to 2014. Happy new year!!

  • 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-2014 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    $errors[] = array(
56      'path' => $this->site_url,
57      'type' => 'PWG-ERROR-NO-FS'
58      );
59
60    return false;
61  }
62
63  return true;
64}
65
66// retrieve file system sub-directories fulldirs
67function get_full_directories($basedir)
68{
69  $fs_fulldirs = get_fs_directories($basedir);
70  return $fs_fulldirs;
71}
72
73/**
74 * Returns an array with all file system files according to $conf['file_ext']
75 * and $conf['picture_ext']
76 * @param string $path recurse in this directory
77 * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... )
78 */
79function get_elements($path)
80{
81  global $conf;
82
83  $subdirs = array();
84  $fs = array();
85  if (is_dir($path) && $contents = opendir($path) )
86  {
87    while (($node = readdir($contents)) !== false)
88    {
89      if ($node == '.' or $node == '..') continue;
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          $representative_ext = null;
99          if (! isset($conf['flip_picture_ext'][$extension]) )
100          {
101            $representative_ext = $this->get_representative_ext($path, $filename_wo_ext);
102          }
103          $fs[ $path.'/'.$node ] = array(
104            'representative_ext' => $representative_ext,
105            );
106        }
107      }
108      else if (is_dir($path.'/'.$node)
109               and $node != 'pwg_high'
110               and $node != 'pwg_representative'
111               and $node != 'thumbnail' )
112      {
113        $subdirs[] = $node;
114      }
115    } //end while readdir
116    closedir($contents);
117
118    foreach ($subdirs as $subdir)
119    {
120      $tmp_fs = $this->get_elements($path.'/'.$subdir);
121      $fs = array_merge($fs, $tmp_fs);
122    }
123    ksort($fs);
124  } //end if is_dir
125  return $fs;
126}
127
128// returns the name of the attributes that are supported for
129// files update/synchronization
130function get_update_attributes()
131{
132  return array('representative_ext');
133}
134
135function get_element_update_attributes($file)
136{
137  global $conf;
138  $data = array();
139
140  $filename = basename($file);
141  $extension = get_extension($filename);
142
143  $representative_ext = null;
144  if (! isset($conf['flip_picture_ext'][$extension]) )
145  {
146    $dirname = dirname($file);
147    $filename_wo_ext = get_filename_wo_extension($filename);
148    $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
149  }
150
151  $data['representative_ext'] = $representative_ext;
152  return $data;
153}
154
155// returns the name of the attributes that are supported for
156// metadata update/synchronization according to configuration
157function get_metadata_attributes()
158{
159  return get_sync_metadata_attributes();
160}
161
162// returns a hash of attributes (metadata+filesize+width,...) for file
163function get_element_metadata($infos)
164{
165  return get_sync_metadata($infos);
166}
167
168
169//-------------------------------------------------- private functions --------
170function get_representative_ext($path, $filename_wo_ext)
171{
172  global $conf;
173  $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.';
174  foreach ($conf['picture_ext'] as $ext)
175  {
176    $test = $base_test.$ext;
177    if (is_file($test))
178    {
179      return $ext;
180    }
181  }
182  return null;
183}
184
185
186}
187?>
Note: See TracBrowser for help on using the repository browser.