1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2010 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 | if ((!defined('PHPWG_ROOT_PATH')) or (!(defined('IN_ADMIN') and IN_ADMIN))) |
---|
25 | { |
---|
26 | die('Hacking attempt!'); |
---|
27 | } |
---|
28 | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | // | include | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | Check Access and exit when user status is not ok | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | check_status(ACCESS_ADMINISTRATOR); |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | Functions | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | /** |
---|
44 | * returns an array containing sub-directories |
---|
45 | * recursive by default |
---|
46 | * |
---|
47 | * directories nammed ".svn" are omitted |
---|
48 | * |
---|
49 | * @param string $path |
---|
50 | * @param bool $recursive |
---|
51 | * @return array |
---|
52 | */ |
---|
53 | function get_add_index_directories($path, $recursive = true) |
---|
54 | { |
---|
55 | $dirs = array(); |
---|
56 | |
---|
57 | if (is_dir($path)) |
---|
58 | { |
---|
59 | if ($contents = opendir($path)) |
---|
60 | { |
---|
61 | while (($node = readdir($contents)) !== false) |
---|
62 | { |
---|
63 | if ( |
---|
64 | is_dir($path.'/'.$node) |
---|
65 | and $node != '.' |
---|
66 | and $node != '..' |
---|
67 | and $node != '.svn' |
---|
68 | ) |
---|
69 | { |
---|
70 | array_push($dirs, $path.'/'.$node); |
---|
71 | if ($recursive) |
---|
72 | { |
---|
73 | $dirs = array_merge($dirs, get_add_index_directories($path.'/'.$node)); |
---|
74 | } |
---|
75 | } |
---|
76 | } |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | return $dirs; |
---|
81 | } |
---|
82 | |
---|
83 | // +-----------------------------------------------------------------------+ |
---|
84 | // | Main | |
---|
85 | // +-----------------------------------------------------------------------+ |
---|
86 | // Compute values |
---|
87 | $index_file_src=$conf['add_index_source_directory_path'].$conf['add_index_filename']; |
---|
88 | $overwrite_file=isset($_GET['overwrite']); |
---|
89 | $site_id = (isset($_GET['site_id']) and is_numeric($_GET['site_id']) |
---|
90 | ? $_GET['site_id'] |
---|
91 | : 0); |
---|
92 | |
---|
93 | // Init values |
---|
94 | $add_index_results = array(); |
---|
95 | $count_copy = 0; |
---|
96 | $count_skip = 0; |
---|
97 | $count_error = 0; |
---|
98 | |
---|
99 | if (@file_exists($index_file_src)) |
---|
100 | { |
---|
101 | $query = ' |
---|
102 | select |
---|
103 | galleries_url |
---|
104 | from |
---|
105 | '.SITES_TABLE; |
---|
106 | if (!empty($site_id)) |
---|
107 | { |
---|
108 | $query .= ' |
---|
109 | where |
---|
110 | id = '.$site_id; |
---|
111 | } |
---|
112 | $query .= ' |
---|
113 | order by |
---|
114 | id'; |
---|
115 | |
---|
116 | $result = pwg_query($query); |
---|
117 | |
---|
118 | if (mysql_num_rows($result) > 0) |
---|
119 | { |
---|
120 | while (list($galleries_url) = mysql_fetch_row($result)) |
---|
121 | { |
---|
122 | if (!url_is_remote($galleries_url)) |
---|
123 | { |
---|
124 | //echo $galleries_url.'<BR>'; |
---|
125 | foreach (get_add_index_directories($galleries_url) as $dir_galleries) |
---|
126 | { |
---|
127 | $file_dest = str_replace('//', '/', $dir_galleries.'/'.$conf['add_index_filename']); |
---|
128 | if ($overwrite_file or !@file_exists($file_dest)) |
---|
129 | { |
---|
130 | if (copy($index_file_src, $file_dest)) |
---|
131 | { |
---|
132 | array_push($add_index_results, |
---|
133 | sprintf(l10n('add_index_file_copied'), $file_dest)); |
---|
134 | $count_copy++; |
---|
135 | } |
---|
136 | else |
---|
137 | { |
---|
138 | array_push($page['errors'], |
---|
139 | sprintf(l10n('add_index_file_not_copied'), $file_dest)); |
---|
140 | $count_error++; |
---|
141 | } |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | $count_skip++; |
---|
146 | } |
---|
147 | } |
---|
148 | } |
---|
149 | else |
---|
150 | { |
---|
151 | if (!empty($site_id)) |
---|
152 | { |
---|
153 | array_push($page['errors'], |
---|
154 | sprintf(l10n('add_index_not_local_site'), |
---|
155 | $galleries_url, $site_id)); |
---|
156 | } |
---|
157 | } |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | // Show always an result, defaut (0 copy, $count_copy == $count_skip == 0) |
---|
162 | if (($count_copy != 0) or ($count_skip == 0)) |
---|
163 | { |
---|
164 | array_push($add_index_results, |
---|
165 | l10n_dec('add_index_nb_copied_file', 'add_index_nb_copied_files', |
---|
166 | $count_copy)); |
---|
167 | } |
---|
168 | if ($count_skip != 0) |
---|
169 | { |
---|
170 | array_push($add_index_results, |
---|
171 | l10n_dec('add_index_nb_skipped_file', 'add_index_nb_skipped_files', |
---|
172 | $count_skip)); |
---|
173 | } |
---|
174 | if ($count_error != 0) |
---|
175 | { |
---|
176 | array_push($page['errors'], |
---|
177 | l10n_dec('add_index_nb_not_copied_file', 'add_index_nb_not_copied_files', |
---|
178 | $count_error)); |
---|
179 | } |
---|
180 | } |
---|
181 | else |
---|
182 | { |
---|
183 | array_push($page['errors'], |
---|
184 | sprintf(l10n('add_index_src_file_dont_exists'), $index_file_src)); |
---|
185 | } |
---|
186 | |
---|
187 | // +-----------------------------------------------------------------------+ |
---|
188 | // | template initialization | |
---|
189 | // +-----------------------------------------------------------------------+ |
---|
190 | $template->set_filenames(array('main_page' => dirname(__FILE__).'/main_page.tpl')); |
---|
191 | |
---|
192 | if (count($add_index_results) != 0) |
---|
193 | { |
---|
194 | $template->assign('add_index_results', $add_index_results); |
---|
195 | } |
---|
196 | |
---|
197 | // +-----------------------------------------------------------------------+ |
---|
198 | // | Sending html code | |
---|
199 | // +-----------------------------------------------------------------------+ |
---|
200 | $template->assign_var_from_handle( 'ADMIN_CONTENT', 'main_page'); |
---|
201 | |
---|
202 | ?> |
---|