source: trunk/admin/site_reader_local.php @ 26942

Last change on this file since 26942 was 26461, checked in by mistic100, 10 years ago

Update headers to 2014. Happy new year!!

  • Property svn:eol-style set to LF
File size: 5.3 KB
RevLine 
[1058]1<?php
2// +-----------------------------------------------------------------------+
[8728]3// | Piwigo - a PHP based photo gallery                                    |
[2297]4// +-----------------------------------------------------------------------+
[26461]5// | Copyright(C) 2008-2014 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[1058]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;
[12831]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  }
[1058]42}
43
44/**
45 * Is this local site ok ?
46 *
47 * @return true on success, false otherwise
48 */
49function open()
50{
51  global $errors;
[1204]52
[1058]53  if (!is_dir($this->site_url))
54  {
[25018]55    $errors[] = array(
56      'path' => $this->site_url,
57      'type' => 'PWG-ERROR-NO-FS'
[1064]58      );
[1204]59
[1058]60    return false;
61  }
[1204]62
[1058]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
[12831]77 * @return array like "pic.jpg"=>array('representative_ext'=>'jpg' ... )
[1058]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    {
[12642]89      if ($node == '.' or $node == '..') continue;
90
[1058]91      if (is_file($path.'/'.$node))
92      {
93        $extension = get_extension($node);
94        $filename_wo_ext = get_filename_wo_extension($node);
95
[1204]96        if ( isset($conf['flip_file_ext'][$extension]) )
[1058]97        {
[12831]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          }
[1058]103          $fs[ $path.'/'.$node ] = array(
[12831]104            'representative_ext' => $representative_ext,
[1058]105            );
106        }
107      }
[25018]108      else if (is_dir($path.'/'.$node)
[1058]109               and $node != 'pwg_high'
110               and $node != 'pwg_representative'
111               and $node != 'thumbnail' )
112      {
[25018]113        $subdirs[] = $node;
[1058]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    }
[5176]123    ksort($fs);
[1058]124  } //end if is_dir
125  return $fs;
126}
127
128// returns the name of the attributes that are supported for
[1204]129// files update/synchronization
[1058]130function get_update_attributes()
131{
[12831]132  return array('representative_ext');
[1204]133}
134
135function get_element_update_attributes($file)
136{
[1058]137  global $conf;
[1204]138  $data = array();
139
140  $filename = basename($file);
141  $extension = get_extension($filename);
142
[12831]143  $representative_ext = null;
144  if (! isset($conf['flip_picture_ext'][$extension]) )
[1204]145  {
[12831]146    $dirname = dirname($file);
147    $filename_wo_ext = get_filename_wo_extension($filename);
148    $representative_ext = $this->get_representative_ext($dirname, $filename_wo_ext);
[1204]149  }
[12831]150
151  $data['representative_ext'] = $representative_ext;
[1204]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{
[12831]159  return get_sync_metadata_attributes();
[1058]160}
161
162// returns a hash of attributes (metadata+filesize+width,...) for file
[12831]163function get_element_metadata($infos)
[1058]164{
[12831]165  return get_sync_metadata($infos);
[1058]166}
167
168
169//-------------------------------------------------- private functions --------
170function get_representative_ext($path, $filename_wo_ext)
171{
172  global $conf;
[1064]173  $base_test = $path.'/pwg_representative/'.$filename_wo_ext.'.';
[1058]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
[1204]185
[1058]186}
[1029]187?>
Note: See TracBrowser for help on using the repository browser.