Skip to content

Commit 0ca4ea5

Browse files
committed
Improve drag and drop uploader
1 parent 1e9d970 commit 0ca4ea5

18 files changed

Lines changed: 1528 additions & 1026 deletions

dist/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vendors.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/vendors.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

easy-file-uploader.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Enhances Elementor Pro Forms and Contact Form 7 with a drag and drop uploader for seamless file uploads.
66
* Author: ZIORWeb.Dev
77
* Author URI: https://ziorweb.dev
8-
* Version: 1.1.8
8+
* Version: 1.1.9
99
* Requires at least: 6.0
1010
* Requires PHP: 8.0
1111
* License: GPL-2.0-or-later
@@ -46,27 +46,4 @@
4646

4747
// Activation and deactivation hooks.
4848
register_activation_hook( __FILE__, array( $plugin_instance, 'activate_plugin' ) );
49-
register_deactivation_hook( __FILE__, array( $plugin_instance, 'deactivate_plugin' ) );
50-
51-
52-
53-
54-
// if ( ! defined( 'ZIORWEBDEV_DRAGDROP_PLUGIN_DIR' ) ) {
55-
// define( 'ZIORWEBDEV_DRAGDROP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
56-
// }
57-
58-
// if ( ! defined( 'ZIORWEBDEV_DRAGDROP_PLUGIN_URL' ) ) {
59-
// define( 'ZIORWEBDEV_DRAGDROP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
60-
// }
61-
62-
// if ( ! defined( 'ZIORWEBDEV_DRAGDROP_PLUGIN_FILE' ) ) {
63-
// define( 'ZIORWEBDEV_DRAGDROP_PLUGIN_FILE', __FILE__ );
64-
// }
65-
66-
// require_once ZIORWEBDEV_DRAGDROP_PLUGIN_DIR . 'includes/functions.php';
67-
// require_once ZIORWEBDEV_DRAGDROP_PLUGIN_DIR . 'includes/classes/class-plugin.php';
68-
69-
// $plugin_instance = Plugin::get_instance( __FILE__ );
70-
71-
// register_activation_hook( __FILE__, array( $plugin_instance, 'activate_plugin' ) );
72-
// register_deactivation_hook( __FILE__, array( $plugin_instance, 'deactivate_plugin' ) );
49+
register_deactivation_hook( __FILE__, array( $plugin_instance, 'deactivate_plugin' ) );
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<?php
2+
/**
3+
* Base class
4+
*
5+
* @package ZIORWebDev\DragDrop\Api\Endpoints
6+
* @since 1.0.0
7+
*/
8+
namespace ZIORWebDev\DragDrop\Api\Endpoints;
9+
10+
use ZIORWebDev\DragDrop\Api\Interface;
11+
use ZIORWebDev\DragDrop\Routes;
12+
13+
// Exit if accessed directly.
14+
if ( ! defined( 'ABSPATH' ) ) {
15+
exit;
16+
}
17+
18+
/**
19+
* Base class
20+
*
21+
* @since 1.0.0
22+
* @package ZIORWebDev\DragDrop\Api\Endpoints
23+
*/
24+
abstract class Base implements Interface\Route {
25+
26+
/**
27+
* REST route path
28+
*
29+
* @var string
30+
*/
31+
protected $route_path = null;
32+
33+
/**
34+
* Check if the Nonce is valid
35+
*
36+
* @param \WP_REST_Request $request
37+
* @return boolean
38+
*/
39+
protected function is_valid_nonce( \WP_REST_Request $request ): bool {
40+
$nonce = $request->get_header( 'x-wp-nonce' );
41+
42+
return $nonce && wp_verify_nonce( $nonce, 'wp_rest' );
43+
}
44+
45+
/**
46+
* Class constructor
47+
*
48+
* @since 1.0.0
49+
*/
50+
public function __construct() {
51+
register_rest_route(
52+
Routes::get_namespace(),
53+
$this->get_rest_path(),
54+
array(
55+
'args' => $this->get_rest_args(),
56+
'methods' => $this->get_rest_method(),
57+
'callback' => array( $this, 'callback' ),
58+
'permission_callback' => array( $this, 'get_rest_permission' ),
59+
)
60+
);
61+
}
62+
63+
/**
64+
* Get Rest path and method
65+
*
66+
* @return string
67+
*/
68+
public function get_name() {
69+
$path = $this->get_rest_path();
70+
$method = strtolower( $this->get_rest_method() );
71+
72+
return "$path/$method";
73+
}
74+
75+
/**
76+
* Get REST route path
77+
*
78+
* @since 1.0.0
79+
* @return string
80+
*/
81+
public function get_rest_path() {
82+
return $this->route_path;
83+
}
84+
85+
/**
86+
* Get REST args
87+
*
88+
* @since 1.0.0
89+
* @return array
90+
*/
91+
public function get_rest_args() {
92+
return array();
93+
}
94+
95+
/**
96+
* Get RESt URL
97+
*
98+
* @since 1.0.0
99+
* @return string
100+
*/
101+
public function get_rest_url() {
102+
$blog_id = get_current_blog_id();
103+
$namespace = Routes::get_namespace();
104+
$path = $this->get_rest_path();
105+
106+
return get_rest_url( $blog_id, "{$namespace}/$path" );
107+
}
108+
109+
/**
110+
* Get REST permission
111+
*
112+
* @since 1.0.0
113+
* @return boolean|\WP_Error
114+
*/
115+
public function get_rest_permission( \WP_REST_Request $request ) {
116+
if ( $this->is_valid_nonce( $request ) ) {
117+
return true;
118+
}
119+
120+
return new \WP_Error( 'rest_forbidden', __( 'Permission denied.', 'easy-file-uploader' ), array( 'status' => 403 ) );
121+
}
122+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Upload endpoint
4+
*
5+
* @package ZIORWebDev\DragDrop\Api\Endpoints
6+
* @since 1.0.0
7+
*/
8+
namespace ZIORWebDev\DragDrop\Api\Endpoints;
9+
10+
use ZIORWebDev\DragDrop\Integrations\Uploader;
11+
12+
13+
// Exit if accessed directly.
14+
if ( ! defined( 'ABSPATH' ) ) {
15+
exit;
16+
}
17+
18+
/**
19+
* Options Value endpoint
20+
*
21+
* @package ZIORWebDev\DragDrop\Api\Endpoints
22+
* @since 1.0.0
23+
*/
24+
class Delete extends Base {
25+
26+
/**
27+
* Route path
28+
*
29+
* @var string
30+
*/
31+
protected $route_path = 'delete';
32+
33+
/**
34+
* Callback
35+
*
36+
* @param \WP_REST_Request $request The request.
37+
* @return array The response.
38+
*/
39+
public function callback( \WP_REST_Request $request ) {
40+
$uploader = new Uploader();
41+
$removed = $uploader->remove_files( $request );
42+
43+
// Failure
44+
if ( isset( $removed['success'] ) && $removed['success'] === false ) {
45+
return new \WP_REST_Response(
46+
$removed,
47+
400
48+
);
49+
}
50+
51+
// Success
52+
return new \WP_REST_Response(
53+
$removed ?? array(),
54+
200
55+
);
56+
}
57+
58+
/**
59+
* Get REST args
60+
*
61+
* @return array The REST args.
62+
*/
63+
public function get_rest_args() {
64+
return array();
65+
}
66+
67+
/**
68+
* Get REST method
69+
*
70+
* @return string The REST method.
71+
*/
72+
public function get_rest_method() {
73+
return \WP_REST_Server::DELETABLE;
74+
}
75+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Upload endpoint
4+
*
5+
* @package ZIORWebDev\DragDrop\Api\Endpoints
6+
* @since 1.0.0
7+
*/
8+
namespace ZIORWebDev\DragDrop\Api\Endpoints;
9+
10+
use ZIORWebDev\DragDrop\Integrations\Uploader;
11+
12+
13+
// Exit if accessed directly.
14+
if ( ! defined( 'ABSPATH' ) ) {
15+
exit;
16+
}
17+
18+
/**
19+
* Options Value endpoint
20+
*
21+
* @package ZIORWebDev\DragDrop\Api\Endpoints
22+
* @since 1.0.0
23+
*/
24+
class Upload extends Base {
25+
26+
/**
27+
* Route path
28+
*
29+
* @var string
30+
*/
31+
protected $route_path = 'upload';
32+
33+
/**
34+
* Callback
35+
*
36+
* @param \WP_REST_Request $request The request.
37+
* @return array The response.
38+
*/
39+
public function callback( \WP_REST_Request $request ) {
40+
$uploader = new Uploader();
41+
$uploaded = $uploader->upload_files( $request );
42+
43+
// Failure
44+
if ( isset( $uploaded['success'] ) && $uploaded['success'] === false ) {
45+
return new \WP_REST_Response(
46+
$uploaded,
47+
400
48+
);
49+
}
50+
51+
// Success
52+
return new \WP_REST_Response(
53+
$uploaded ?? array(),
54+
200
55+
);
56+
}
57+
58+
/**
59+
* Get REST args
60+
*
61+
* @return array The REST args.
62+
*/
63+
public function get_rest_args() {
64+
return array();
65+
}
66+
67+
/**
68+
* Get REST method
69+
*
70+
* @return string The REST method.
71+
*/
72+
public function get_rest_method() {
73+
return \WP_REST_Server::CREATABLE;
74+
}
75+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Route interface
4+
*
5+
* @package ZIORWebDev\DragDrop\Api\Interface
6+
* @since 1.0.0
7+
*/
8+
namespace ZIORWebDev\DragDrop\Api\Interface;
9+
10+
// Exit if accessed directly.
11+
if ( ! defined( 'ABSPATH' ) ) {
12+
exit;
13+
}
14+
15+
/**
16+
* Route interface
17+
*
18+
* @package ZIORWebDev\DragDrop\Api\Interface
19+
* @since 1.0.0
20+
*/
21+
interface Route {
22+
23+
/**
24+
* Callback
25+
*
26+
* @param \WP_REST_Request $request The request.
27+
* @return array The response.
28+
*/
29+
public function callback( \WP_REST_Request $request );
30+
31+
/**
32+
* Get name
33+
*
34+
* @return string The name.
35+
*/
36+
public function get_name();
37+
38+
/**
39+
* Get REST args
40+
*
41+
* @return array The REST args.
42+
*/
43+
public function get_rest_args();
44+
45+
/**
46+
* Get REST path
47+
*
48+
* @return string The REST path.
49+
*/
50+
public function get_rest_path();
51+
52+
/**
53+
* Get REST method
54+
*
55+
* @return string The REST method.
56+
*/
57+
public function get_rest_method();
58+
59+
/**
60+
* Get REST permission
61+
*
62+
* @return boolean The REST permission.
63+
*/
64+
public function get_rest_permission( \WP_REST_Request $request );
65+
66+
/**
67+
* Get REST URL
68+
*
69+
* @return string The REST URL.
70+
*/
71+
public function get_rest_url();
72+
}

0 commit comments

Comments
 (0)