PluginProbe
Redirection / 4.3.3
Redirection v4.3.3
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 4.3.3, at api/api-export.php

42 lines 1.3 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 for a module in a format
5 * @apiDescription Export redirects for a module in a format
6 * @apiGroup Export
7 *
8 * @apiParam {String} module The module to export - 1, 2, 3, or 'all'
9 * @apiParam {String} format The format of the export. Either 'csv', 'apache', 'nginx', or 'json'
10 *
11 * @apiSuccess {Array} ip Array of export data
12 * @apiSuccess {Integer} total Number of items exported
13 *
14 * @apiUse 400Error
15 */
16 class Redirection_Api_Export extends Redirection_Api_Route {
17 public function __construct( $namespace ) {
18 register_rest_route( $namespace, '/export/(?P<module>1|2|3|all)/(?P<format>csv|apache|nginx|json)', array(
19 $this->get_route( WP_REST_Server::READABLE, 'route_export' ),
20 ) );
21 }
22
23 public function route_export( WP_REST_Request $request ) {
24 $module = $request['module'];
25 $format = 'json';
26
27 if ( in_array( $request['format'], array( 'csv', 'apache', 'nginx', 'json' ) ) ) {
28 $format = $request['format'];
29 }
30
31 $export = Red_FileIO::export( $module, $format );
32 if ( $export === false ) {
33 return $this->add_error_details( new WP_Error( 'redirect', 'Invalid module' ), __LINE__ );
34 }
35
36 return array(
37 'data' => $export['data'],
38 'total' => $export['total'],
39 );
40 }
41 }
42