PluginProbe
Redirection / 4.4
Redirection v4.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-log.php

api-log.php in Redirection 4.4, at api/api-log.php

71 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @api {get} /redirection/v1/log Get log logs
4 * @apiDescription Get log logs
5 * @apiGroup Log
6 *
7 * @apiParam {string} groupBy Group by 'ip' or 'url'
8 * @apiParam {string} orderby
9 * @apiParam {string} direction
10 * @apiParam {string} filterBy
11 * @apiParam {string} per_page
12 * @apiParam {string} page
13 */
14
15 /**
16 * @api {post} /redirection/v1/log Delete log logs
17 * @apiDescription Delete log logs either by ID or filter or group
18 * @apiGroup Log
19 *
20 * @apiParam {string} items Array of log IDs
21 * @apiParam {string} filterBy
22 * @apiParam {string} groupBy Group by 'ip' or 'url'
23 */
24
25 /**
26 * @api {post} /redirection/v1/bulk/log/delete Bulk actions on logs
27 * @apiDescription Delete log logs either by ID
28 * @apiGroup Log
29 */
30 class Redirection_Api_Log extends Redirection_Api_Filter_Route {
31 public function __construct( $namespace ) {
32 $orders = [ 'url', 'ip' ];
33 $filters = [ 'ip', 'url-exact', 'referrer', 'agent', 'url', 'target' ];
34
35 register_rest_route( $namespace, '/log', array(
36 'args' => $this->get_filter_args( $orders, $filters ),
37 $this->get_route( WP_REST_Server::READABLE, 'route_log' ),
38 $this->get_route( WP_REST_Server::EDITABLE, 'route_delete_all' ),
39 ) );
40
41 $this->register_bulk( $namespace, '/bulk/log/(?P<bulk>delete)', $orders, 'route_bulk' );
42 }
43
44 public function route_log( WP_REST_Request $request ) {
45 return $this->get_logs( $request->get_params() );
46 }
47
48 public function route_bulk( WP_REST_Request $request ) {
49 $items = explode( ',', $request['items'] );
50
51 if ( is_array( $items ) ) {
52 $items = array_map( 'intval', $items );
53 array_map( array( 'RE_Log', 'delete' ), $items );
54 return $this->route_log( $request );
55 }
56
57 return $this->add_error_details( new WP_Error( 'redirect', 'Invalid array of items' ), __LINE__ );
58 }
59
60 public function route_delete_all( WP_REST_Request $request ) {
61 $params = $request->get_params();
62
63 RE_Log::delete_all( isset( $params['filterBy'] ) ? $params['filterBy'] : [] );
64 return $this->route_log( $request );
65 }
66
67 private function get_logs( array $params ) {
68 return RE_Filter_Log::get( 'redirection_logs', 'RE_Log', $params );
69 }
70 }
71