| Server IP : 151.101.66.159 / Your IP : 216.73.216.66 Web Server : Flywheel/5.1.0 System : Linux wordpress 6.12.113+ #1 SMP Thu Oct 22 02:38:20 UTC 2026 x86_64 User : root ( ) PHP Version : 7.4.33.18 Disable Function : disk_free_space,diskfreespace,dl,exec,fpassthru,getmypid,getmyuid,highlight_file,link,opcache_compile_file,opcache_get_configuration,opcache_is_script_cached,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifcontinued,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,phpinfo,popen,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,show_source,socket_listen,source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wp-content/plugins/file-manager-advanced/application/assets/js/ |
Upload File : |
/**
* elFinder custom commands for File Manager Advanced
*/
(function ($) {
$(document).ready(function () {
if (typeof elFinder !== 'undefined' && elFinder.prototype && elFinder.prototype.commands) {
// AFM-989: paste.js blocks PHP via uploadMimeCheck (uploadDeny). Allow paste/copy
// of existing PHP files; real uploads still go through the upload command checks.
if (elFinder.prototype.commands.paste && !elFinder.prototype.commands.paste._afmPhpPastePatched) {
var OrigPaste = elFinder.prototype.commands.paste;
elFinder.prototype.commands.paste = function () {
OrigPaste.apply(this, arguments);
var origExec = this.exec;
this.exec = function (select, cOpts) {
var fm = this.fm;
var origCheck = fm.uploadMimeCheck;
fm.uploadMimeCheck = function (mime, target) {
if (mime && String(mime).toLowerCase().indexOf('php') !== -1) {
return true;
}
return origCheck.call(fm, mime, target);
};
var ret;
try {
ret = origExec.call(this, select, cOpts);
} catch (err) {
fm.uploadMimeCheck = origCheck;
throw err;
}
if (ret && typeof ret.always === 'function') {
ret.always(function () {
fm.uploadMimeCheck = origCheck;
});
} else {
fm.uploadMimeCheck = origCheck;
}
return ret;
};
};
elFinder.prototype.commands.paste._afmPhpPastePatched = true;
}
// Icon CSS
var pluginUrl = (typeof afm_object !== 'undefined') ? afm_object.plugin_url : '';
if (!pluginUrl) {
// Try to find it from script src
var script = $('script[src*="fma-elfinder-commands.js"]');
if (script.length) {
pluginUrl = script.attr('src').split('application/assets/js/')[0];
}
}
if (pluginUrl) {
var iconStyle = `
<style id="fma-replace-icon">
.elfinder-button-icon-replace {
background-image: url(${pluginUrl}application/assets/images/replace.png) !important;
background-size: 16px !important;
background-repeat: no-repeat !important;
background-position: center !important;
}
.elfinder-contextmenu-icon-replace {
background-image: url(${pluginUrl}application/assets/images/replace.png) !important;
background-size: 16px !important;
background-repeat: no-repeat !important;
background-position: center !important;
}
</style>
`;
if ($('#fma-replace-icon').length === 0) {
$('head').append(iconStyle);
}
}
// Translation
var i18Obj = elFinder.prototype.i18 || elFinder.prototype.i18n;
if (i18Obj) {
// Ensure English is initialized if not present
if (!i18Obj.en) {
i18Obj.en = { messages: {} };
}
for (var lang in i18Obj) {
if (i18Obj.hasOwnProperty(lang)) {
var msg = 'Replace';
// Add some common translations
if (lang === 'es') msg = 'Reemplazar';
if (lang === 'fr') msg = 'Remplacer';
if (lang === 'de') msg = 'Ersetzen';
if (lang === 'it') msg = 'Sostituisci';
if (lang === 'pt') msg = 'Substituir';
if (lang === 'ru') msg = 'Заменить';
if (lang === 'zh_CN') msg = '替换';
if (!i18Obj[lang].messages) {
i18Obj[lang].messages = {};
}
i18Obj[lang].messages.cmdreplace = msg;
i18Obj[lang].messages.replace = msg;
}
}
}
// Replace command definition
elFinder.prototype.commands.replace = function () {
this.updateOnSelect = false;
this.title = 'Replace';
this.getstate = function (hashes) {
var fm = this.fm;
var sel = this.hashes(hashes);
var cnt = sel.length;
if (cnt !== 1) {
return -1;
}
var file = fm.file(sel[0]);
if (!file || file.mime === 'directory' || file.phash === null) {
return -1;
}
// AFM-989: hide Replace for PHP (and other write:false / locked files)
// shown to non-admins and shortcode guests — overwrite must stay blocked.
if (file.write === false || file.locked) {
return -1;
}
if (file.name && /\.(php\d?|phtml)$/i.test(file.name)) {
return -1;
}
return fm.isCommandEnabled('upload', sel[0]) ? 0 : -1;
};
this.exec = function (hashes) {
var fm = this.fm;
var sel = this.hashes(hashes);
var file = fm.file(sel[0]);
var self = this;
if (!file) {
return $.Deferred().reject();
}
var input = $('<input type="file" />');
input.on('change', function () {
if (this.files && this.files.length) {
var selectedFile = this.files[0];
var formData = new FormData();
formData.append('cmd', 'upload');
formData.append('target', file.phash);
formData.append('overwrite', '1');
formData.append('hashes[' + file.name + ']', sel[0]);
formData.append('mtime[]', selectedFile.lastModified ? Math.round(selectedFile.lastModified / 1000) : 0);
formData.append('upload[]', selectedFile, file.name);
// Add custom data (nonce, action, etc. required by WordPress and the plugin)
var customData = fm.customData || fm.options.customData || {};
if (typeof customData === 'function') {
customData = customData('upload', fm);
}
for (var key in customData) {
if (customData.hasOwnProperty(key)) {
if (!formData.has(key)) { // Prevent overwriting existing formData keys like 'cmd' or 'target'
formData.append(key, customData[key]);
}
}
}
var ajaxHeaders = $.extend({}, fm.customHeaders || {});
// Use jQuery.ajax directly for upload to avoid elFinder request stripping FormData issues
$.ajax({
url: fm.options.url,
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: ajaxHeaders,
beforeSend: function () {
fm.notify({ type: 'upload', cnt: 1, hide: false });
},
success: function (data) {
// Always decrement the counter
fm.notify({ type: 'upload', cnt: -1, hide: true });
// Try to parse if it's a string
if (typeof data === 'string') {
try {
data = JSON.parse(data);
} catch (e) { }
}
if (data && data.error) {
fm.error(data.error);
} else {
fm.notify({
type: 'info',
msg: 'File replaced successfully!',
hide: 3000
});
// Refresh the UI to show the new file immediately
if (typeof fm.exec === 'function') {
fm.exec('reload');
}
if (typeof fm.sync === 'function') {
fm.sync();
}
}
},
error: function (xhr, status, error) {
fm.notify({ type: 'upload', cnt: -1, hide: true });
var response = null;
try {
response = JSON.parse(xhr.responseText);
} catch (e) { }
if (xhr.status === 403 && response && response.csrfReload && typeof fm.refreshCsrfToken === 'function') {
fm.refreshCsrfToken().done(function () {
$.ajax({
url: fm.options.url,
type: 'POST',
data: formData,
processData: false,
contentType: false,
headers: $.extend({}, fm.customHeaders || {}),
success: function (retryData) {
fm.notify({ type: 'upload', cnt: -1, hide: true });
if (typeof retryData === 'string') {
try {
retryData = JSON.parse(retryData);
} catch (e) { }
}
if (retryData && retryData.error) {
fm.error(retryData.error);
} else {
fm.notify({ type: 'info', msg: 'File replaced successfully!', hide: 3000 });
if (typeof fm.exec === 'function') {
fm.exec('reload');
}
if (typeof fm.sync === 'function') {
fm.sync();
}
}
},
error: function () {
fm.notify({ type: 'error', msg: 'Failed to replace file.', hide: 3000 });
}
});
});
return;
}
console.error('FMA Replace Error:', error, xhr.responseText);
fm.notify({
type: 'error',
msg: 'Failed to replace file. Error: ' + error,
hide: 3000
});
}
});
}
});
input.click();
return $.Deferred().resolve();
};
};
// Function to add replace to context menu
var addReplaceToContextMenu = function (opts) {
if (opts && opts.contextmenu && opts.contextmenu.files) {
var filesMenu = opts.contextmenu.files;
if (filesMenu.indexOf('replace') === -1) {
var renameIdx = filesMenu.indexOf('rename');
if (renameIdx !== -1) {
filesMenu.splice(renameIdx + 1, 0, 'replace');
} else {
filesMenu.push('replace');
}
}
}
};
// Add to context menu for ALL future instances (by modifying the prototype _options)
if (elFinder && elFinder.prototype && elFinder.prototype._options) {
addReplaceToContextMenu(elFinder.prototype._options);
}
// Also handle existing and new instances
var setupInstance = function (fm) {
if (fm && fm.options) {
addReplaceToContextMenu(fm.options);
}
// Get the translation based on current language
var msg = 'Replace';
var lang = fm.lang || (fm.options && fm.options.lang) || 'en';
if (lang === 'es') msg = 'Reemplazar';
if (lang === 'fr') msg = 'Remplacer';
if (lang === 'de') msg = 'Ersetzen';
if (lang === 'it') msg = 'Sostituisci';
if (lang === 'pt') msg = 'Substituir';
if (lang === 'ru') msg = 'Заменить';
if (lang === 'zh_CN') msg = '替换';
// Ensure instance has the translation (FORCE IT)
if (fm && fm.messages) {
fm.messages.cmdreplace = msg;
fm.messages.replace = msg;
}
// Ensure the command title is capitalized
if (fm && fm.commands && fm.commands.replace) {
fm.commands.replace.title = msg;
}
};
// Apply to any elFinder instances that might already exist
if (typeof elFinder !== 'undefined' && typeof elFinder.instances !== 'undefined') {
$.each(elFinder.instances, function (id, fm) {
setupInstance(fm);
});
}
// Hook into elFinder creation event to apply to new instances as they are created
$(document).on('elfindercreate', function (event, fm) {
setupInstance(fm);
});
}
});
})(jQuery);