-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDropToPTPPrefs.php
executable file
·168 lines (137 loc) · 4.68 KB
/
DropToPTPPrefs.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?
// DropToPTPPrefs
function testKey($key) {
$data = array("api_key" => $key);
$url = "https://ptpimg.me/upload.php";
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$result = @file_get_contents($url, false, $context);
if (gettype($result) == "string") {
return 1;
} else {
return 0;
}
}
function makeWindowString($p, $strings) {
$conf = "
# Set window title
*.title = Preferences
*.floating = 1
# PTPimg Key
key.type = textfield
key.mandatory = 1
key.label = PTPImg key
key.default = ".$p['key']."
key.placeholder = xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
key.width = 400
key.tooltip = Your PTPImg key can be found by checking the source code on PTPimg while logged in
# Allowed Filetypes
allowed.type = textfield
allowed.mandatory = 1
allowed.label = Allowed filetypes
allowed.default = ".implode(", ",$p['allowed'])."
allowed.width = 400
allowed.tooltip = These are the types of files DropToPTP will attempt to upload to PTPimg
# Limit
limit.type = textfield
limit.label = Max images to upload without warning
limit.default = ".$p['limit']."
limit.tooltip = DropToPTP will display a warning if more than x images are dropped
limit.width = 80
# Resize images?
max_enable.type = popup
max_enable.label = Resize images?
max_enable.width = 400
max_enable.option = ".$strings[3][0]."
max_enable.option = ".$strings[3][1]."
max_enable.option = ".$strings[3][2]."
max_enable.default = ".$strings[3][$p['max_enable']]."
max_size.type = textfield
max_size.label = Max image dimension
max_size.default = ".$p['max_size']."
max_size.tooltip = DropToPTP will attempt to resize any image with a width or height greater than this value
max_size.width = 80
# Add tags
add_tags.type = popup
add_tags.label = Add [img] tags to URLs?
add_tags.width = 400
add_tags.option = ".$strings[0][0]."
add_tags.option = ".$strings[0][1]."
add_tags.option = ".$strings[0][2]."
add_tags.default = ".$strings[0][$p['add_tags']]."
# Subtitle
subtitle.type = textfield
subtitle.label = Image subtitle
subtitle.default = ".$p['subtitle']."
subtitle.width = 400
subtitle.tooltip = This text will be added on a new line after each image URL
# No files action
no_files_action.type = popup
no_files_action.label = If no files are dragged
no_files_action.width = 400
no_files_action.option = ".$strings[1][0]."
no_files_action.option = ".$strings[1][1]."
no_files_action.default = ".$strings[1][$p['no_files_action']]."
# After upload
after_upload.type = popup
after_upload.label = After successful upload
after_upload.width = 400
after_upload.option = ".$strings[2][0]."
after_upload.option = ".$strings[2][1]."
after_upload.option = ".$strings[2][2]."
after_upload.default = ".$strings[2][$p['after_upload']]."
# Stay open?
stay_open.type = checkbox
stay_open.label = Stay open after successful upload
stay_open.default = ".$p['stay_open']."
# Buttons
#gb.type = button
#gb.label = Detect Key...
cb.type = cancelbutton
db.type = defaultbutton
db.label = Save
";
return $conf;
}
// Read Prefs
$prefs_file = "/Users/".get_current_user()."/Library/Preferences/org.anatidae.DropToPTP.php";
$p = unserialize(file_get_contents($prefs_file));
// Load strings
$strings[] = array("Never","Only if 2 or more files are uploaded","Always");
$strings[] = array("Do nothing","Capture screenshot");
$strings[] = array("Copy to clipboard","Open gallery","Do nothing");
$strings[] = array("Do not resize images","Resize all images","Only resize JPEGs");
// Launch Pashua and parse results
$path = __DIR__."/bin/Pashua.app/Contents/MacOS/Pashua";
$raw = shell_exec("echo ".escapeshellarg(makeWindowString($p, $strings))." | ".escapeshellarg($path)." - ");
$result = array();
foreach (explode("\n", $raw) as $line) {
preg_match('/^(\w+)=(.*)$/', $line, $matches);
if (empty($matches) or empty($matches[1])) {
continue;
}
$result[$matches[1]] = $matches[2];
}
// User cancelled
if (@$result['cb']) { echo 1; die; }
// Fix strings
$result['allowed'] = explode(", ",$result['allowed']);
$result['add_tags'] = array_search($result['add_tags'],$strings[0]);
$result['no_files_action'] = array_search($result['no_files_action'],$strings[1]);
$result['after_upload'] = array_search($result['after_upload'],$strings[2]);
$result['max_enable'] = array_search($result['max_enable'],$strings[3]);
// Write Prefs
file_put_contents($prefs_file,serialize($result));
// Test API Key
if (@$result['key'] && ($result['key'] != $p['key'])) {
echo testKey($result['key']);
} else {
echo 1;
}
?>