-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.php
305 lines (297 loc) · 12.9 KB
/
sync.php
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
# +--------------------------------------------------------------------+
# | phpEasyVCS |
# | The file-based version control system |
# +--------------------------------------------------------------------+
# | Copyright (c) 2011 Martin Vlcek |
# | License: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html) |
# +--------------------------------------------------------------------+
require_once('inc/basic.php');
require_once('inc/template.php');
require_once('inc/filetype.class.php');
$dir = sanitizeDir($_GET['dir']);
$vcs = new FileVCS(DATAPATH, @$_GET['tag'], getUserName(), isReadOnly());
$tag = $vcs->getTag();
$tagname = $tag && $tag->name ? $tag->name : ($tag ? $_GET['tag'] : null);
template_header();
$v = filemtime(ROOTPATH.'applet/vcsapplet.jar');
$uri = isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === "on" ? "https" : "http";
$uri .= "://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
$uri = substr($uri,0,strlen($uri)-8) . 'rest.php/current';
$currlink = 'browse.php?'.($tagname ? 'tag='.urlencode($tagname).'&' : '').'dir='.urlencode($dir);
?>
<noscript>
<div class="error">This page requires Javascript and a Java Applet!</div>
</noscript>
<ul class="actions">
<?php if (!$tagname) { ?>
<li style="display:none"><a href="#" id="open-start">Start</a></li>
<?php } ?>
<li style="display:none"><a href="#" id="refresh-all">Refresh</a></li>
<li style="display:none"><a href="#" id="open-all">Open all</a></li>
<li style="display:none"><a href="#" id="close-all">Close all</a></li>
<li style="display:none"><a href="#" id="show-identical" class="toggle">Show identical files</a></li>
<li><a href="<?php echo htmlspecialchars($currlink); ?>">Back to directory</a></li>
</ul>
<h2>
Synchronize
<a href="<?php echo htmlspecialchars($currlink); ?>">/<?php echo htmlspecialchars(substr($dir,0,-1)); ?></a>
</h2>
<p id="localrootp">
Local Directory: <span id="localroot"></span>
<button id="selectlocalroot">Select</button>
</p>
<div id="progress" class="progress" style="display:none;">
<div class="progress-bar"></div>
<div class="progress-text"></div>
</div>
<table id="entries" class="list hide-identical" style="display:none;">
<thead>
<tr><th rowspan="2">Name</th><th colspan="3" class="side">Local</th><th rowspan="2" colspan="5" class="action">Action</th><th colspan="3" class="side">Remote</th><th rowspan="2" colspan="3"></th></tr>
<tr><th class="version">Version</th><th class="size">Size</th><th class="date">Date</th><th class="version">Version</th><th class="size">Size</th><th class="date">Date</th></tr>
</thead>
<tbody>
</tbody>
</table>
<?php if (!$tagname) { ?>
<a id="dialog-background" class="dialog-background" href="<?php echo $currlink; ?>" style="display:<?php echo isset($_GET['addfolder']) || isset($_GET['addfile']) ? 'block' : 'none'; ?>"></a>
<div class="dialog-container">
<div id="start-dialog" class="dialog" style="display:<?php echo isset($_GET['addfolder']) ? 'block' : 'none';?>;">
<a href="<?php echo $currlink; ?>"><img src="images/close.png" class="close" alt="Close dialog"/></a>
<form action="add.php" method="POST">
<h2>Start Synchronisation</h2>
<p>This will start copying and deleting files as indicated.</p>
<label for="comment">Comment:</label>
<textarea name="comment" style="width:90%; height:4em;"></textarea>
<br />
<input type="submit" class="submit" id="start" name="start" value="Start"/>
</form>
</div>
</div>
<?php } ?>
<p style="text-align: center;">
<object type="application/x-java-applet;version=1.5"
width="1" height= "1" id="applet" name="SyncApplet">
<param name="archive" value="applet/vcsapplet.jar?v=<?php echo $v; ?>">
<param name="code" value="net.sf.phpeasyvcs.SynchronizerApplet">
<param name="MAYSCRIPT" value="yes">
<param name="root" value="<?php echo htmlspecialchars($uri) . ($dir ? '/'.substr($dir,0,-1) : ''); ?>">
</object>
</p>
<script type="text/javascript">
// <![CDATA[
var num = 0;
var dirIds = { };
var icons = <?php echo json_encode(Filetype::getIcons()); ?>;
function showLocalRoot(localRoot) {
$('#localroot').text(localRoot);
}
function showScanProgress(progress, total, percent) {
$('#selectlocalroot').hide();
$('#progress').show();
$('#progress .progress-text').text(progress+" directories of "+total);
$('#progress .progress-bar').css('width',percent+'%');
}
function showScanResult(dir, jsonEntries) {
var entries = $.parseJSON(jsonEntries);
displayEntries(dir, entries);
$('#progress').hide();
$('#entries').show();
$('ul.actions, ul.actions li').show();
}
function displayEntries(dir, entries) {
var id = null;
var level = 0;
var dirclasses = '';
var $prevRow = null;
if (dir) {
parentId = dirIds[dir];
if (!parentId) return;
$('#entries tbody tr.'+parentId).remove();
dirclasses = $('#'+parentId).attr('class');
dirclasses = dirclasses.replace(/[^\s]+-curr|open|closed|directory|root/g, '').replace(/\s+/g, ' ').trim();
dirclasses = dirclasses + ' ' + parentId + ' ' + parentId + '-curr';
level = dir.split("/").length;
$prevRow = $('#'+parentId);
} else {
dirclasses = 'root';
$('#entries tbody tr').remove();
}
var $tbody = $('#entries tbody');
for (var i in entries) {
var entry = entries[i];
var isdir = (entry['local'] && entry['local']['dir']) || (entry['remote'] && entry['remote']['dir']);
var dirId = null;
var dirName = null;
var entryNum = num++;
if (isdir) {
dirId = 'dir-'+entryNum;
dirName = (dir ? dir+'/' : '')+entry['name'];
dirIds[dirName] = dirId;
}
var $row = $('<tr '+(dirId ? 'id="'+dirId+'" ' : '')+'class="'+(isdir ? 'open directory' : entry['action'])+' '+dirclasses+'"/>');
var $td = $('<td class="name" style="padding-left:'+(7+16*level)+'px"></td>').text(entry['name']);
$td.append($('<input type="hidden" name="entry-'+entryNum+'" value=""/>').val((dir ? dir+'/' : '')+entry['name']));
if (isdir) {
$td.prepend('<img class="closed" src="images/folder.png" alt="Open folder" /> ');
$td.prepend('<img class="open" src="images/folder_open.png" alt="Close folder" /> ');
$td.append('<img class="refresh" src="images/refresh.png" alt="Refresh" />');
} else {
var pos = entry['name'].lastIndexOf('.');
var icon = icons[entry['name'].substring(entry['name'].lastIndexOf('.')+1)];
if (!icon) icon = 'unknown';
$td.prepend('<img src="images/'+icon+'.png" alt=""/> ');
}
$row.append($td);
if (entry['local']) {
var size = entry['local']['size'];
if (!size) size ='';
var version = entry['local']['version'];
if (version < 0) version = "";
$row.append('<td class="version">'+version+'</td>');
$row.append('<td class="size">'+size+'</td>');
$row.append('<td class="date">'+entry['local']['date']+'</td>');
} else {
$row.append('<td colspan="3"></td>');
}
if (isdir) {
$row.append('<td colspan="5"></td>');
} else {
if (entry['local']) {
$row.append('<td class="link delete DELETE_LOCAL"><a href="#" title="Delete local">X</a></td>');
} else $row.append('<td class="nolink"></td>');
if (entry['remote'] && entry['action'] != 'IDENTICAL') {
$row.append('<td class="link COPY_TO_LOCAL"><a href="#" title="Copy to local"><<</a></td>');
} else $row.append('<td class="nolink"></td>');
$row.append('<td class="link NONE"><a href="#" title="Do nothing">-</a></td>');
if (entry['local'] && entry['action'] != 'IDENTICAL') {
$row.append('<td class="link COPY_TO_REMOTE"><a href="#" title="Copy to remote">>></a></td>');
} else $row.append('<td class="nolink"></td>');
if (entry['remote']) {
$row.append('<td class="link delete DELETE_REMOTE"><a href="#" title="Delete remote">X</a></td>');
} else $row.append('<td class="nolink"></td>');
}
if (entry['remote']) {
var size = entry['remote']['size'];
if (!size) size = "";
$row.append('<td class="version">'+entry['remote']['version']+'</td>');
$row.append('<td class="size">'+size+'</td>');
$row.append('<td class="date">'+entry['remote']['date']+'</td>');
} else {
$row.append('<td colspan="3"></td>');
}
if (isdir) {
$row.append('<td colspan="3"></td>');
} else if (entry['local'] && entry['remote']) {
$row.append('<td class="link quickview"><a href="#" title="Quick view local"><Q</a></td>');
if (entry['action'] != 'IDENTICAL') {
$row.append('<td class="link merge"><a href="#" title="Compare/Merge">M</a></td>');
} else {
$row.append('<td class="nolink"></td>');
}
$row.append('<td class="link quickview"><a href="#" title="Quick view remote">Q></a></td>');
} else if (entry['local']) {
$row.append('<td class="link quickview"><a href="#" title="Quick view local"><Q</a></td>');
$row.append('<td colspan="2"></td>');
} else {
$row.append('<td colspan="2"></td>');
$row.append('<td class="link quickview"><a href="#" title="Quick view remote">Q></a></td>');
}
if ($prevRow) $prevRow.after($row); else $tbody.append($row);
$prevRow = $row;
if (isdir) {
$prevRow = displayEntries(dirName, entry['entries']);
if ($('#entries tr.'+dirId+':not(.IDENTICAL)').size() <= 0) $row.addClass('IDENTICAL');
}
}
return $prevRow;
}
$(function() {
$('#localrootp').show();
var localroot = document.SyncApplet.getLocalRoot();
$('#localroot').text(localroot);
$('#selectlocalroot').click(function(e) {
e.preventDefault();
document.SyncApplet.selectLocalRoot(true);
});
$('#synchronize').click(function(e) {
e.preventDefault();
document.SyncApplet.scan();
});
$('#entries').delegate('td.link a','click',function(e) {
e.preventDefault();
var $td = $(e.target).closest('td');
var $tr = $(e.target).closest('tr');
var cl = "";
if ($td.hasClass('DELETE_LOCAL') && $tr.hasClass('DELETE_REMOTE')) {
cl = 'DELETE_BOTH';
} else if ($td.hasClass('DELETE_REMOTE') && $tr.hasClass('DELETE_LOCAL')) {
cl = 'DELETE_BOTH';
} else if ($td.hasClass('DELETE_LOCAL')) {
cl = 'DELETE_LOCAL';
} else if ($td.hasClass('DELETE_REMOTE')) {
cl = 'DELETE_REMOTE';
} else if ($td.hasClass('COPY_TO_LOCAL')) {
cl = 'COPY_TO_LOCAL';
} else if ($td.hasClass('COPY_TO_REMOTE')) {
cl = 'COPY_TO_REMOTE';
} else if ($td.hasClass('NONE')) {
cl = 'NONE';
}
$tr.removeClass('DELETE_LOCAL COPY_TO_LOCAL NONE COPY_TO_REMOTE DELETE_REMOTE MERGE DELETE_BOTH');
$tr.addClass(cl);
});
$('#entries').delegate('tr.directory td.name img.open, tr.directory td.name img.closed','click',function(e) {
e.preventDefault();
var $tr = $(e.target).closest('tr');
var id = $tr.attr('id');
if ($tr.hasClass('open')) {
$('#entries tr.'+id).addClass('hidden');
$('#entries tr.open.'+id).removeClass('open').addClass('closed');
$tr.removeClass('open').addClass('closed');
} else {
$('#entries tr.'+id+'-curr').removeClass('hidden');
$tr.removeClass('closed').addClass('open');
}
});
$('#entries').delegate('tr.directory td.name img.refresh','click',function(e) {
e.preventDefault();
var dir = $(e.target).closest('td').find('[name^=entry-]').val();
document.SyncApplet.scan(dir);
});
$('#refresh-all').click(function(e) {
e.preventDefault();
document.SyncApplet.scan();
});
$('#show-identical').click(function(e) {
e.preventDefault();
$(e.target).toggleClass('on');
$('#entries').toggleClass('hide-identical');
});
$('#open-all').click(function(e) {
e.preventDefault();
$('#entries tbody tr').removeClass('hidden');
$('#entries tbody tr.directory').removeClass('closed').addClass('open');
});
$('#close-all').click(function(e) {
e.preventDefault();
$('#entries tbody tr:not(.root)').addClass('hidden');
$('#entries tbody tr.directory').removeClass('open').addClass('closed');
});
$('#open-start').click(function(e) {
e.preventDefault();
$('#start-dialog').dialog();
});
$('#start').click(function(e) {
e.preventDefault();
document.SyncApplet.sync();
});
$('.close').click(function(e) {
e.preventDefault();
$(e.target).closest('.dialog').dialog('close');
})
});
// ]]>
</script>
<?php
template_footer();