| 1 |
<?php |
| 2 |
|
| 3 |
class Redirection_Api_Export extends Redirection_Api_Route { |
| 4 |
public function __construct( $namespace ) { |
| 5 |
register_rest_route( $namespace, '/export/(?P<module>1|2|3|all)/(?P<format>csv|apache|nginx|json)', array( |
| 6 |
$this->get_route( WP_REST_Server::READABLE, 'route_export' ), |
| 7 |
) ); |
| 8 |
} |
| 9 |
|
| 10 |
public function route_export( WP_REST_Request $request ) { |
| 11 |
if ( ! function_exists( 'get_plugin_data' ) ) { |
| 12 |
include_once ABSPATH.'/wp-admin/includes/plugin.php'; |
| 13 |
} |
| 14 |
|
| 15 |
$module = $request['module']; |
| 16 |
$format = 'json'; |
| 17 |
|
| 18 |
if ( in_array( $request['format'], array( 'csv', 'apache', 'nginx', 'json' ) ) ) { |
| 19 |
$format = $request['format']; |
| 20 |
} |
| 21 |
|
| 22 |
$export = Red_FileIO::export( $module, $format ); |
| 23 |
if ( $export === false ) { |
| 24 |
return $this->add_error_details( new WP_Error( 'redirect', 'Invalid module' ), __LINE__ ); |
| 25 |
} |
| 26 |
|
| 27 |
return array( |
| 28 |
'data' => $export['data'], |
| 29 |
'total' => $export['total'], |
| 30 |
); |
| 31 |
} |
| 32 |
} |
| 33 |
|