| Server IP : 185.11.201.71 / Your IP : 192.168.7.18 Web Server : Apache/2.4.29 (Ubuntu) System : Linux tech-virtual-machine 4.15.0-213-generic #224-Ubuntu SMP Mon Jun 19 13:30:12 UTC 2023 x86_64 User : tech ( 1000) PHP Version : 7.4.28 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/enaireretos/wp-content/plugins/enable-media-replace/views/ |
Upload File : |
<?php
namespace EnableMediaReplace;
use EnableMediaReplace\ShortPixelLogger\ShortPixelLogger as Log;
use EnableMediaReplace\Notices\NoticeController as Notices;
//use \EnableMediaReplace\Replacer as Replacer;
use \EnableMediaReplace\Controller\ReplaceController as ReplaceController;
if (! defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
$key = isset($_POST['key']) ? sanitize_text_field($_POST['key']) : null;
if (is_null($key) || strlen($key) == 0)
{
wp_die(esc_html__('Error while sending form (no key). Please try again.', 'enable-media-replace'));
}
$post_id = isset($_POST['ID']) ? intval($_POST['ID']) : null; // sanitize, post_id.
if (is_null($post_id)) {
wp_die(esc_html__('Error in request. Please try again', 'enable-media-replace'));
}
$attachment = get_post($post_id);
if (! emr()->checkImagePermission($attachment)) {
wp_die(esc_html__('You do not have permission to upload files for this author.', 'enable-media-replace'));
}
$uiHelper = emr()->uiHelper();
$replaceController = new ReplaceController($post_id);
//$replacer->setMode(\EnableMediaReplace\Replacer::MODE_REPLACE);
//$datetime = current_time('mysql');
//$replacer->setTimeMode( \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED, $datetime);
$api = new Api();
$result = $api->handleDownload($key);
if (! $result->success)
{
die($result->message);
}
// When are 1-1 replacing.
$source = $replacer->getSourceFile();
$redirect_error = $uiHelper->getFailedRedirect($post_id);
$redirect_success = $uiHelper->getSuccesRedirect($post_id);
if (! file_exists($result->image))
{
Log::addError('Download File not here', $result->image);
exit(__('Temp file does not exist', 'enable-media-replace'));
}
$params = array(
'replace_type' => \EnableMediaReplace\Replacer::MODE_REPLACE,
'timestamp_replace' => \EnableMediaReplace\Replacer::TIME_UPDATEMODIFIED,
'new_date' => current_time('mysql'),
'updateFile' => $result->image,
);
$replaceController->setupParams($params);
try {
$result = $replaceController->run();
} catch (\RunTimeException $e) {
print_r($e->getMessage());
Log::addError($e->getMessage());
die;
}
if (is_null($result)) {
wp_safe_redirect($redirect_error);
exit();
}
$noticeController = Notices::getInstance();
$notice = Notices::addSuccess('<p>' . __('File successfully replaced', 'enable-media-replace') . '</p>');
$notice->is_removable = false;
$noticeController->update();
wp_redirect($redirect_success);
exit();