// First find out whether to fetch a file or accept an upload
if ($serendipity['POST']['imageurl'] != '' && $serendipity['POST']['imageurl'] != 'http://') {
- if (!empty($serendipity['POST']['target_filename'][1])) {
+ if (!empty($serendipity['POST']['target_filename'][2])) {
+ // Faked hidden form 2 when submitting with JavaScript
+ $tfile = $serendipity['POST']['target_filename'][2];
+ $tindex = 2;
+ } elseif (!empty($serendipity['POST']['target_filename'][1])) {
+ // Fallback key when not using JavaScript
$tfile = $serendipity['POST']['target_filename'][1];
+ $tindex = 1;
} else {
$tfile = basename($serendipity['POST']['imageurl']);
+ $tindex = 1;
}
if ($serendipity['serendipityUserlevel'] < USERLEVEL_ADMIN && preg_match('@\.(php[34]?|[ps]html?)$@i', $tfile)) {
}
$tfile = serendipity_uploadSecure($tfile);
- $serendipity['POST']['target_directory'][1] = serendipity_uploadSecure($serendipity['POST']['target_directory'][1], true);
- $target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][1] . $tfile;
+ $serendipity['POST']['target_directory'][$tindex] = serendipity_uploadSecure($serendipity['POST']['target_directory'][$tindex], true);
+ $target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$tindex] . $tfile;
if (file_exists($target)) {
echo '(' . $target . ') ' . ERROR_FILE_EXISTS_ALREADY;
printf(FILE_FETCHED . '<br />', $serendipity['POST']['imageurl'], $tfile);
// Create thumbnail
- if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][1]) ) {
+ if ( $created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$tindex]) ) {
echo THUMB_CREATED_DONE . '<br />';
}
// Insert into database
- $image_id = serendipity_insertImageInDatabase($tfile, $serendipity['POST']['target_directory'][1], $authorid);
+ $image_id = serendipity_insertImageInDatabase($tfile, $serendipity['POST']['target_directory'][$tindex], $authorid);
}
}
}
return value.replace(re, "$1");
}
+ isFileUpload = true;
function hideForeign() {
document.getElementById('foreign_upload').style.display = 'none';
document.getElementById('imageurl').value = '';
+ isFileUpload = false;
}
var fieldcount = 1;
fillInput(i, i);
}
}
+
+ }
+
+ function debugFields() {
+ for (i = 1; i <= fieldcount; i++) {
+ debugField('target_filename_' + i);
+ debugField('userfile_' + i);
+ }
}
- // TODO: This does not yet work as expected and if an imageurl is entered it will overwrite the custom name again
+ function debugField(id) {
+ alert(id + ': ' + document.getElementById(id).value);
+ }
+
function fillInput(source, target) {
+ useDuplicate = false;
+
// First field is a special value for foreign URLs instead of uploaded files
- if (source == 1) {
+ if (source == 1 && document.getElementById('imageurl').value != "") {
sourceval = getfilename(document.getElementById('imageurl').value);
+ useDuplicate = true;
} else {
sourceval = getfilename(document.getElementById('userfile_' + source).value);
}
if (sourceval.length > 0) {
document.getElementById('target_filename_' + target).value = sourceval;
- inputStorage[target] = document.getElementById('target_filename_' + target).value;
+ inputStorage[target] = sourceval;
}
- // Display filename in duplicte form as well!
- if (source == 1 && target == 1) {
- fillInput(1, 2);
+ // Display filename in duplicate form as well!
+ if (useDuplicate) {
+ tkey = target + 1;
+
+ if (!inputStorage[tkey] || inputStorage[tkey] == document.getElementById('target_filename_' + tkey).value) {
+ document.getElementById('target_filename_' + (target+1)).value = sourceval;
+ inputStorage[target + 1] = '~~~';
+ }
}
}
</script>