Skip to content

Commit 134fc84

Browse files
committed
Change to http POST
1 parent 95fc87a commit 134fc84

File tree

5 files changed

+48
-35
lines changed

5 files changed

+48
-35
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### v2.2.4
2+
- Change to http POST
3+
14
### v2.2.3
25
- Added preloading animation
36

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"role": "Developer"
1313
}
1414
],
15-
"version": "2.2.3",
15+
"version": "2.2.4",
1616
"repositories": [
1717
{
1818
"type": "composer",

syncmarks.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Roundcube Bookmarks Plugin
33
*
4-
* @version 2.2.2
4+
* @version 2.2.4
55
* @author Offerel
66
* @copyright Copyright (c) 2020, Offerel
77
* @license GNU General Public License, version 3
@@ -35,6 +35,11 @@ function add_url(format) {
3535
0 < t.length && (t.startsWith("http") || t.startsWith("ftp")) && rcmail.http_post("syncmarks/add_url", "_url=" + t + "&_format=" + format)
3636
}
3737

38+
function url_removed(response) {
39+
console.log(response.message);
40+
document.getElementById("bookmarkpane").style.width = "0";
41+
}
42+
3843
function urladded(t) {
3944
console.log(t.message), 0 < t.data.length && $("#bookmarkpane").html(t.data)
4045
}

syncmarks.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

syncmarks.php

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Roundcube Bookmarks Plugin
44
*
5-
* @version 2.2.3
5+
* @version 2.2.4
66
* @author Offerel
77
* @copyright Copyright (c) 2020, Offerel
88
* @license GNU General Public License, version 3
@@ -90,19 +90,19 @@ function get_notifications() {
9090
$path = $rcmail->config->get('bookmarks_path', false);
9191
$filename = $rcmail->config->get('bookmarks_filename', false);
9292

93-
$ch = curl_init();
94-
curl_setopt($ch, CURLOPT_URL, $path.$filename.'?gurls=1');
95-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
96-
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
97-
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
98-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
99-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
100-
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
101-
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
93+
$data = array(
94+
'caction' => 'gurls'
95+
);
96+
97+
$ch=curl_init();
98+
curl_setopt($ch, CURLOPT_URL, $path.$filename);
10299
curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password());
103-
$data = curl_exec($ch);
104-
$rcmail->output->command('plugin.sendNotifications', $data);
100+
curl_setopt($ch, CURLOPT_POST, true);
101+
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
102+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
103+
$response = curl_exec($ch);
105104
curl_close($ch);
105+
$rcmail->output->command('plugin.sendNotifications', $response);
106106
rcube_utils::setcookie('sycmarks_n', '1', 0);
107107
}
108108
}
@@ -112,17 +112,18 @@ function del_not() {
112112
$this->load_config();
113113
$path = $rcmail->config->get('bookmarks_path', false);
114114
$filename = $rcmail->config->get('bookmarks_filename', false);
115+
116+
$sdata = array(
117+
'caction' => 'durl',
118+
'durl' => rcube_utils::get_input_value('_nkey', rcube_utils::INPUT_GPC)
119+
);
115120

116121
$ch = curl_init();
117-
curl_setopt($ch, CURLOPT_URL, $path.$filename.'?durl='.rcube_utils::get_input_value('_nkey', rcube_utils::INPUT_GPC));
118-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
119-
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
120-
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
121-
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
122-
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
123-
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
124-
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
122+
curl_setopt($ch, CURLOPT_URL, $path.$filename);
125123
curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password());
124+
curl_setopt($ch, CURLOPT_HTTPPOST, TRUE);
125+
curl_setopt($ch, CURLOPT_POSTFIELDS, $sdata);
126+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
126127
$data = curl_exec($ch);
127128
curl_close($ch);
128129
}
@@ -136,15 +137,14 @@ function get_bookmarks() {
136137
$password = $rcmail->get_user_password();
137138
$ext = pathinfo($filename, PATHINFO_EXTENSION);
138139
$remote_url = $path."/".$filename;
139-
$opts = array('http'=>array(
140-
'method'=>"GET",
141-
'header' => "Authorization: Basic ".base64_encode("$username:$password")
142-
)
143-
);
144-
145-
$context = stream_context_create($opts);
146140

147141
if($ext === "json") {
142+
$opts = array('http'=>array(
143+
'method'=>"GET",
144+
'header' => "Authorization: Basic ".base64_encode("$username:$password")
145+
)
146+
);
147+
$context = stream_context_create($opts);
148148
$bms = file_get_contents($remote_url, false, $context);
149149
foreach ($http_response_header as &$value) {
150150
if (strpos($value, 'ast-Modified') != 0) {
@@ -162,7 +162,10 @@ function get_bookmarks() {
162162
}
163163
}
164164
elseif($ext === "php") {
165-
$sdata = array('export' => 'html');
165+
$sdata = array(
166+
'caction' => 'fexport',
167+
'type' => 'html'
168+
);
166169
$ch = curl_init();
167170
curl_setopt($ch, CURLOPT_URL, $path.$filename);
168171
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -250,7 +253,7 @@ function del_url() {
250253
$rcmail->output->command('syncmarks/urladded', array('message' => "Bookmark deleted", 'data' => $cmarks));
251254
}
252255
elseif($format == "php") {
253-
$ddata = array('mdel' => true, 'id' => $bid, 'rc' => true);
256+
$ddata = array('caction' => 'mdel', 'id' => $bid, 'rc' => true);
254257
$path = $rcmail->config->get('bookmarks_path', false);
255258
$filename = $rcmail->config->get('bookmarks_filename', false);
256259
$username = $rcmail->user->get_username();
@@ -267,13 +270,14 @@ function del_url() {
267270
curl_setopt($ch, CURLOPT_POSTFIELDS, $ddata);
268271
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
269272
$rdata = curl_exec($ch);
273+
$rcmail->output->command('syncmarks/url_removed', array('message' => "URL removed"));
270274
curl_close($ch);
271275
}
272276
}
273277

274278
function get_title($url) {
275279
$ch = curl_init();
276-
curl_setopt($ch, CURLOPT_URL, $new_url);
280+
curl_setopt($ch, CURLOPT_URL, $url);
277281
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
278282
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
279283
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
@@ -370,7 +374,7 @@ function add_url() {
370374
$rcmail->output->command('syncmarks/urladded', array('message' => 'URL is added.','data' => $cmarks));
371375
}
372376
elseif($format == 'php') {
373-
$ddata = array('madd' => true, 'url' => $new_url, 'rc' => true, 'folder' => 'unfiled_____');
377+
$ddata = array('caction' => 'madd', 'url' => $new_url, 'rc' => true, 'folder' => 'unfiled_____');
374378
$path = $rcmail->config->get('bookmarks_path', false);
375379
$filename = $rcmail->config->get('bookmarks_filename', false);
376380
$username = $rcmail->user->get_username();
@@ -387,6 +391,7 @@ function add_url() {
387391
curl_setopt($ch, CURLOPT_POSTFIELDS, $ddata);
388392
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password);
389393
$rdata = curl_exec($ch);
394+
$rcmail->output->command('syncmarks/url_removed', array('message' => "URL added"));
390395
curl_close($ch);
391396
}
392397
}

0 commit comments

Comments
 (0)