PluginProbe
Redirection / 5.3.4
Redirection v5.3.4
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / api / api-export.php

api-export.php in Redirection 5.3.4, at api/api-export.php

55 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @api {get} /redirection/v1/export/:module/:format Export redirects
5 * @apiName Export
6 * @apiDescription Export redirects for a module to Apache, CSV, Nginx, or JSON format
7 * @apiGroup Import/Export
8 *
9 * @apiParam (URL) {String="1","2","3","all"} :module The module to export, with 1 being WordPress, 2 is Apache, and 3 is Nginx
10 * @apiParam (URL) {String="csv","apache","nginx","json"} :format The format of the export
11 *
12 * @apiSuccess {String} data Exported data
13 * @apiSuccess {Integer} total Number of items exported
14 *
15 * @apiUse 401Error
16 * @apiUse 404Error
17 * @apiError (Error 400) redirect_export_invalid_module Invalid module
18 * @apiErrorExample {json} 404 Error Response:
19 * HTTP/1.1 400 Bad Request
20 * {
21 * "code": "redirect_export_invalid_module",
22 * "message": "Invalid module"
23 * }
24 */
25 class Redirection_Api_Export extends Redirection_Api_Route {
26 public function __construct( $namespace ) {
27 register_rest_route( $namespace, '/export/(?P<module>1|2|3|all)/(?P<format>csv|apache|nginx|json)', array(
28 $this->get_route( WP_REST_Server::READABLE, 'route_export', [ $this, 'permission_callback_manage' ] ),
29 ) );
30 }
31
32 public function permission_callback_manage( WP_REST_Request $request ) {
33 return Redirection_Capabilities::has_access( Redirection_Capabilities::CAP_IO_MANAGE );
34 }
35
36 public function route_export( WP_REST_Request $request ) {
37 $module = $request['module'];
38 $format = 'json';
39
40 if ( in_array( $request['format'], [ 'csv', 'apache', 'nginx', 'json' ], true ) ) {
41 $format = $request['format'];
42 }
43
44 $export = Red_FileIO::export( $module, $format );
45 if ( $export === false ) {
46 return $this->add_error_details( new WP_Error( 'redirect_export_invalid_module', 'Invalid module' ), __LINE__ );
47 }
48
49 return array(
50 'data' => $export['data'],
51 'total' => $export['total'],
52 );
53 }
54 }
55