| Server IP : 188.114.97.2 / Your IP : 104.23.243.200 Web Server : Apache/2.4.59 (Debian) System : Linux EDL-STRETCH 4.19.0-27-amd64 #1 SMP Debian 4.19.316-1 (2024-06-25) x86_64 User : edlftp ( 1002) PHP Version : 7.4.33 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 : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/nicolasj/www/blog.ecoledelangues.be/wp-content/plugins/redirection/api/ |
Upload File : |
<?php
class Redirection_Api_Import extends Redirection_Api_Route {
public function __construct( $namespace ) {
register_rest_route( $namespace, '/import/file/(?P<group_id>\d+)', array(
$this->get_route( WP_REST_Server::EDITABLE, 'route_import_file' ),
) );
register_rest_route( $namespace, '/import/plugin', array(
$this->get_route( WP_REST_Server::READABLE, 'route_plugin_import_list' ),
) );
register_rest_route( $namespace, '/import/plugin/(?P<plugin>.*?)', array(
$this->get_route( WP_REST_Server::EDITABLE, 'route_plugin_import' ),
) );
}
public function route_plugin_import_list( WP_REST_Request $request ) {
include_once dirname( dirname( __FILE__ ) ) . '/models/importer.php';
return array( 'importers' => Red_Plugin_Importer::get_plugins() );
}
public function route_plugin_import( WP_REST_Request $request ) {
include_once dirname( dirname( __FILE__ ) ) . '/models/importer.php';
$groups = Red_Group::get_all();
return array( 'imported' => Red_Plugin_Importer::import( $request['plugin'], $groups[0]['id'] ) );
}
public function route_import_file( WP_REST_Request $request ) {
$upload = $request->get_file_params();
$upload = isset( $upload['file'] ) ? $upload['file'] : false;
$group_id = $request['group_id'];
if ( $upload && is_uploaded_file( $upload['tmp_name'] ) ) {
$count = Red_FileIO::import( $group_id, $upload );
if ( $count !== false ) {
return array(
'imported' => $count,
);
}
return $this->add_error_details( new WP_Error( 'redirect', 'Invalid group' ), __LINE__ );
}
return $this->add_error_details( new WP_Error( 'redirect', 'Invalid file' ), __LINE__ );
}
}