This repository has been archived by the owner on Mar 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathroute.smms.php
executable file
·86 lines (59 loc) · 2 KB
/
route.smms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
add_action('rest_api_init', 'smms_forward_route');
add_action('rest_api_init', 'smms_getlist_route');
function smms_forward_route(){
register_rest_route('smms/api/v2/', 'upload', [
'methods' => 'POST',
'callback' => 'smms_forward_callback',
]);
}
function smms_getlist_route(){
register_rest_route('smms/api/v2/', 'list', [
'methods' => 'GET',
'callback' => 'smms_getlist_callback',
]);
}
function smms_forward_callback($request){
//$paged = $request->get_param('paged');
global $wpdb;
$lastname = $_FILES['smfile']['tmp_name'];
$wp_uploads = wp_upload_dir()['path'];
//return $wp_uploads;
create_folders($wp_uploads.'/smms_imglist/');
$path = $wp_uploads.'/smms_imglist/'.$_FILES['smfile']['name'];
//return $path;
copy($lastname,$path);
unlink($lastname);
$option = get_option('SMMS_DATA');
$auth = $option['Authorization'];
$smapi = new SMApi($auth);
$result = $smapi->Upload($path);
if($result["success"]){
$data['width'] = $result['data']['width'];
$data['height'] = $result['data']['height'];
$data['size'] = $result['data']['size'];
$data['hash'] = $result['data']['hash'];
$data['url'] = $result['data']['url'];
$wpdb->insert(MY_NEW_TABLE, $data);
if($option['Nolocal']){
unlink($path);
}
}elseif($result["code"] == "image_repeated"){
$result['data']['url'] = $result["images"];
}
return $result;
}
function smms_getlist_callback($request){
global $wpdb;
$pages = $request->get_param('pages');
$pages = $pages? : 1;
$limit = 10;
$offset = ($pages - 1) * 10;
$sql = $wpdb->prepare('SELECT `url` FROM `'. MY_NEW_TABLE .'` ORDER BY `id` DESC LIMIT %d OFFSET %d', $limit, $offset);
$result = $wpdb->get_results($sql);
return $result;
}
function create_folders($dir) {
return is_dir($dir) or (create_folders(dirname($dir)) and mkdir($dir, 0777));
}
?>