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