PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.5.84
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.5.84
5.5.84 5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 All 160 releases
wp-data-access / WPDataAccess / Drive / WPDA_Local.php

WPDA_Local.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.5.84, at WPDataAccess/Drive/WPDA_Local.php

79 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDataAccess\Drive {
4
5 use WPDataAccess\WPDA;
6
7 class WPDA_Local extends WPDA_Drive {
8
9 public function __construct( $drive = array(), $enabled = false ) {
10
11 $this->drive_type = 'local';
12
13 parent::__construct( 'local', $drive, $enabled );
14
15 }
16
17 public function authorize( $authorization, $enabled = true ) {
18
19 if ( isset( $authorization['path'] ) ) {
20 $this->drive = array(
21 'path' => $authorization['path'],
22 );
23 $this->enabled = $enabled;
24 $this->save();
25
26 return true;
27 }
28
29 return false;
30
31 }
32
33 public function refresh_token() {
34
35 return true; // N.A.
36
37 }
38
39 public function connect() {
40
41 return true; // N.A.
42
43 }
44
45 public function close() {
46
47 // N.A.
48
49 }
50
51 public function upload_file( $local_file, $remote_file ) {
52
53 copy( $local_file, $this->drive['path'] . $remote_file );
54
55 }
56
57 public function cleanup( $query, $keep ) {
58
59 $keep_counting = 0;
60 $files_sorted = array();
61
62 $path = '/' === substr( $this->drive['path'], -1 ) ? $this->drive['path'] : $this->drive['path'] . '/';
63
64 foreach ( glob( $path . $query ) as $filename ) {
65 array_push( $files_sorted, $filename );
66 }
67 rsort( $files_sorted );
68
69 foreach ( $files_sorted as $file ) {
70 $keep_counting ++;
71 if ( $keep_counting > (int) $keep ) {
72 unlink( $file ); // phpcs:ignore
73 }
74 }
75
76 }
77 }
78
79 }