PluginProbe
UpStream: a Project Management Plugin for WordPress / 1.39.1
UpStream: a Project Management Plugin for WordPress v1.39.1
trunk 1.39.0 1.39.1 1.39.2 1.39.3 2.0.7 2.1.0
upstream / includes / up-filesystem.php

up-filesystem.php in UpStream: a Project Management Plugin for WordPress 1.39.1, at includes/up-filesystem.php

127 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
4
5
6
7 function upstream_upfs_get_file_url($value)
8 {
9 if (!is_string($value)) return $value;
10
11 if (substr($value, 0, 7) == '_upfs__') {
12 // upfs file
13 return add_query_arg('download', $value, get_post_type_archive_link('project'));
14 } elseif (filter_var($value, FILTER_VALIDATE_INT)) {
15 // an fid
16 return wp_get_attachment_url($value);
17 } else {
18 return $value;
19 }
20 }
21
22 function upstream_upfs_info($value)
23 {
24 global $wpdb;
25 $res = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'upfs_files WHERE upfsid=%s', $value));
26
27 if (!empty($res)) {
28 foreach ($res as $row) {
29
30 return $row;
31
32 }
33 }
34
35 return null;
36 }
37
38 function upstream_upfs_download($value)
39 {
40 global $wpdb;
41 $res = $wpdb->get_results( $wpdb->prepare('SELECT * FROM '.$wpdb->prefix.'upfs_files WHERE upfsid=%s', $value) );
42
43 if (!empty($res)) {
44 foreach ($res as $row) {
45 $path = upstream_filesystem_path() . '/' . $row->saved_filename;
46
47 if (file_exists($path)) {
48
49 header('Content-Description: File Transfer');
50 header('Content-Disposition: attachment; filename=' . $row->orig_filename);
51 header('Expires: 0');
52 header('Cache-Control: must-revalidate');
53 header('Pragma: public');
54 header('Content-Length: ' . filesize($path));
55 header("Content-Type: " . $row->mime_type);
56 readfile($path);
57 }
58
59 exit();
60 }
61 }
62
63 exit();
64 }
65
66 function upstream_upfs_upload($file)
67 {
68 $folder = upstream_filesystem_path();
69 $info = [];
70
71 if (true) {
72
73 if (!empty($file)) {
74
75 if (!empty($file['tmp_name'])) {
76
77 if (true) {
78
79 // Checks the size of the the image
80 if (filesize($file['tmp_name']) < upstream_filesystem_max_size()) {
81
82 if (is_dir($folder)) {
83
84 $upfsid = '_upfs__'. upstreamGenerateRandomString(50);
85 // Moves the image to the created file
86 if (move_uploaded_file($file['tmp_name'], $folder . '/'. $upfsid)) {
87
88 global $wpdb;
89
90 $sql = 'CREATE TABLE '.$wpdb->prefix.'upfs_files ( upfsid VARCHAR(60), orig_filename VARCHAR(255), saved_filename VARCHAR(255), mime_type VARCHAR(255), file_size INT, access_rules TEXT, PRIMARY KEY (upfsid) )';
91 $r = maybe_create_table($wpdb->prefix . 'upfs_files', $sql);
92 $r = $wpdb->insert($wpdb->prefix . 'upfs_files', array(
93 'upfsid' => $upfsid,
94 'orig_filename' => $file['name'],
95 'saved_filename' => $upfsid,
96 'mime_type' => $file['type'],
97 'file_size' => $file['size'],
98 'access_rules' => ''
99 ));
100
101 return $upfsid;
102
103 } else {
104 unlink($file['tmp_name']);
105 array_push($info, __("Unable to move file to target folder", 'upstream'));
106 }
107 } else {
108 unlink($file['tmp_name']);
109 array_push($info, __("Unable to move file. The target folder does not exist.", 'upstream'));
110 }
111 } else {
112 array_push($info, __("File exceeds the maximum file size", 'upstream'));
113 }
114 } else {
115 unlink($file['tmp_name']);
116 array_push($info, __("File is not an allowed type.", 'upstream'));
117 }
118 } else {
119 array_push($info, __("File exceeds the maximum file size", 'upstream'));
120 }
121 }
122 } else {
123
124 }
125
126 return $info;
127 }