source: extensions/add_index/admin/main_page.php @ 21204

Last change on this file since 21204 was 21204, checked in by ddtddt, 11 years ago

[extensions] - add_index - change to 2.5

  • Property svn:eol-style set to LF
File size: 6.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Add Index - a Piwigo Plugin                                           |
4// | Copyright (C) 2019-2011 Piwigo team                                   |
5// +-----------------------------------------------------------------------+
6// | This program is free software; you can redistribute it and/or modify  |
7// | it under the terms of the GNU General Public License as published by  |
8// | the Free Software Foundation                                          |
9// |                                                                       |
10// | This program is distributed in the hope that it will be useful, but   |
11// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
12// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
13// | General Public License for more details.                              |
14// |                                                                       |
15// | You should have received a copy of the GNU General Public License     |
16// | along with this program; if not, write to the Free Software           |
17// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
18// | USA.                                                                  |
19// +-----------------------------------------------------------------------+
20
21if ((!defined('PHPWG_ROOT_PATH')) or (!(defined('IN_ADMIN') and IN_ADMIN)))
22{
23  die('Hacking attempt!');
24}
25
26// +-----------------------------------------------------------------------+
27// | include                                                               |
28// +-----------------------------------------------------------------------+
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
31
32// +-----------------------------------------------------------------------+
33// | Check Access and exit when user status is not ok                      |
34// +-----------------------------------------------------------------------+
35check_status(ACCESS_ADMINISTRATOR);
36
37// +-----------------------------------------------------------------------+
38// | Functions                                                             |
39// +-----------------------------------------------------------------------+
40/**
41 * returns an array containing sub-directories
42 * recursive by default
43 *
44 * directories nammed ".svn" are omitted
45 *
46 * @param string $path
47 * @param bool $recursive
48 * @return array
49 */
50function get_add_index_directories($path)
51{
52  $dirs = array($path);
53
54  if (is_dir($path))
55  {
56    if ($contents = opendir($path))
57    {
58      while (($node = readdir($contents)) !== false)
59      {
60        if (
61            is_dir($path.'/'.$node)
62            and $node != '.'
63            and $node != '..'
64            and $node != '.svn'
65           )
66        {
67          $dirs = array_merge($dirs, get_add_index_directories($path.'/'.$node));
68        }
69      }
70    }
71  }
72
73  return $dirs;
74}
75
76// +-----------------------------------------------------------------------+
77// | Main                                                                  |
78// +-----------------------------------------------------------------------+
79// Compute values
80$index_file_src=$conf['add_index_source_directory_path'].$conf['add_index_filename'];
81$overwrite_file=isset($_GET['overwrite']);
82$site_id=((isset($_GET['site_id']) and is_numeric($_GET['site_id'])) ? $_GET['site_id'] : 0);
83
84// Init values
85$add_index_results = array();
86$count_copy = 0;
87$count_skip = 0;
88$count_error = 0;
89$dir_list=array();
90
91if (@file_exists($index_file_src))
92{
93  if (empty($site_id))
94  {
95    $dir_list[] = $conf['upload_dir'];
96  }
97
98  $query = '
99select
100  galleries_url
101from
102  '.SITES_TABLE;
103  if (!empty($site_id))
104  {
105    $query .= '
106where
107  id = '.$site_id;
108  }
109    $query .= '
110order by
111 id';
112
113  $result = pwg_query($query);
114
115  if (pwg_db_num_row($result) > 0)
116  {
117    while (list($galleries_url) = pwg_db_fetch_rows($result))
118    {
119      $dir_list[] = $galleries_url;
120    }
121  }
122
123  foreach ($dir_list as $galleries_url)
124  {
125    //~ echo $galleries_url.'<BR>';
126    if (!url_is_remote($galleries_url))
127    {
128      foreach (get_add_index_directories($galleries_url) as $dir_galleries)
129      {
130        $file_dest = str_replace('//', '/', $dir_galleries.'/'.$conf['add_index_filename']);
131        if ($overwrite_file or !@file_exists($file_dest))
132        {
133          if (copy($index_file_src, $file_dest))
134          {
135            array_push($add_index_results,
136              sprintf(l10n('add_index_file_copied'), $file_dest));
137            $count_copy++;
138          }
139          else
140          {
141            array_push($page['errors'],
142              sprintf(l10n('add_index_file_not_copied'), $file_dest));
143            $count_error++;
144          }
145        }
146        else
147        {
148          $count_skip++;
149        }
150      }
151    }
152    else
153    {
154      if (!empty($site_id))
155      {
156        array_push($page['errors'],
157          sprintf(l10n('add_index_not_local_site'), 
158            $galleries_url, $site_id));
159      }
160    }
161  }
162
163  // Show always an result, defaut (0 copy, $count_copy == $count_skip == 0)
164  if (($count_copy != 0) or ($count_skip == 0))
165  {
166    array_push($add_index_results,
167      l10n_dec('add_index_nb_copied_file', 'add_index_nb_copied_files',
168        $count_copy));
169  }
170  if ($count_skip != 0)
171  {
172    array_push($add_index_results,
173      l10n_dec('add_index_nb_skipped_file', 'add_index_nb_skipped_files',
174        $count_skip));
175  }
176  if ($count_error != 0)
177  {
178    array_push($page['errors'],
179      l10n_dec('add_index_nb_not_copied_file', 'add_index_nb_not_copied_files',
180        $count_error));
181  }
182}
183else
184{
185  array_push($page['errors'],
186    sprintf(l10n('add_index_src_file_dont_exists'), $index_file_src));
187}
188
189// +-----------------------------------------------------------------------+
190// | template initialization                                               |
191// +-----------------------------------------------------------------------+
192$template->set_filenames(array('main_page' => dirname(__FILE__).'/main_page.tpl'));
193
194if (count($add_index_results) != 0)
195{
196  $template->assign('add_index_results', $add_index_results);
197}
198
199// +-----------------------------------------------------------------------+
200// | Sending html code                                                     |
201// +-----------------------------------------------------------------------+
202$template->assign_var_from_handle( 'ADMIN_CONTENT', 'main_page');
203
204?>
Note: See TracBrowser for help on using the repository browser.