Skip to content

Commit 5d8639d

Browse files
committed
Moved get_bookmarks
* moved the get_bookmarks function from init to click to speed up inital loading
1 parent 33f333b commit 5d8639d

4 files changed

Lines changed: 65 additions & 49 deletions

File tree

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.1.0",
15+
"version": "2.1.1",
1616
"repositories": [
1717
{
1818
"type": "composer",

plugin.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Roundcube Bookmarks Plugin
33
*
4-
* @version 2.1.0
4+
* @version 2.1.1
55
* @author Offerel
66
* @copyright Copyright (c) 2019, Offerel
77
* @license GNU General Public License, version 3
@@ -26,7 +26,7 @@ function j_del(t, o) {
2626

2727
function bookmarks_cmd() {
2828
if(document.getElementById("bookmarkpane").clientWidth != "300") {
29-
document.getElementById("bookmarkpane").style.width = "300px";
29+
rcmail.http_post("syncmarks/get_bookmarks", "_url=2")
3030
}
3131
else {
3232
document.getElementById("bookmarkpane").style.width = "0";
@@ -46,12 +46,21 @@ function jadd_url() {
4646
function urladded(t) {
4747
console.log(t.message), 0 < t.data.length && $("#bookmarkpane").html(t.data)
4848
}
49-
window.rcmail && rcmail.addEventListener("init", function(t) {}), $(document).ready(function() {
50-
/*
51-
if(document.getElementById("phppane")) {
52-
alert(rcmail.get_user_email());
49+
50+
function get_bookmarks(response) {
51+
bookmarks = JSON.parse(response.data);
52+
53+
if(response.message == 'php') {
54+
$('#bmframe').attr('srcdoc',bookmarks);
55+
document.getElementById("bookmarkpane").style.width = "300px";
5356
}
54-
*/
57+
else {
58+
$('#bookmarkpane').html(bookmarks);
59+
document.getElementById("bookmarkpane").style.width = "300px";
60+
}
61+
}
62+
63+
window.rcmail && rcmail.addEventListener("init", function(t) {}), $(document).ready(function() {
5564
$("#7f3f3c06-5b85-4e7f-b527-d061478e9446").on("click", bookmarks_cmd), document.getElementById("bookmarkpane").addEventListener("click", function(t) {
5665
"A" == t.target.tagName && bookmarks_cmd()
5766
})

plugin.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

syncmarks.php

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/**
33
* Roundcube Bookmarks Plugin
44
*
5-
* @version 2.1.0
5+
* @version 2.1.1
66
* @author Offerel
77
* @copyright Copyright (c) 2018, Offerel
88
* @license GNU General Public License, version 3
@@ -17,7 +17,8 @@ public function init() {
1717
$this->add_texts('localization/', true);
1818
$this->register_task('syncmarks');
1919
$this->include_stylesheet($this->local_skin_path().'/plugin.min.css');
20-
$this->include_script('plugin.min.js');
20+
//$this->include_script('plugin.min.js');
21+
$this->include_script('plugin.js');
2122

2223
$this->add_button(array(
2324
'label' => 'syncmarks.bookmarks',
@@ -32,6 +33,45 @@ public function init() {
3233
$this->add_hook('render_page', array($this, 'add_bookmarks'));
3334
$this->register_action('add_url', array($this, 'add_url'));
3435
$this->register_action('del_url', array($this, 'del_url'));
36+
$this->register_action('get_bookmarks', array($this, 'get_bookmarks'));
37+
}
38+
39+
function get_bookmarks() {
40+
$rcmail = rcmail::get_instance();
41+
$this->load_config();
42+
$path = $rcmail->config->get('bookmarks_path', false);
43+
$filename = $rcmail->config->get('bookmarks_filename', false);
44+
$username = $rcmail->user->get_username();
45+
$password = $rcmail->get_user_password();
46+
$ext = pathinfo($filename, PATHINFO_EXTENSION);
47+
$remote_url = $path."/".$filename;
48+
$opts = array('http'=>array(
49+
'method'=>"GET",
50+
'header' => "Authorization: Basic ".base64_encode("$username:$password")
51+
)
52+
);
53+
$context = stream_context_create($opts);
54+
$bms = file_get_contents($remote_url, false, $context);
55+
56+
if($ext === "json") {
57+
foreach ($http_response_header as &$value) {
58+
if (strpos($value, 'ast-Modified') != 0) {
59+
$modified = strtotime(substr($value, 15));
60+
break;
61+
}
62+
}
63+
$bms = parseJSONMarks($bms,$modified, $this->gettext('bookmarks_new'));
64+
}
65+
elseif($ext === "html") {
66+
$bmfile = str_replace("%u", $username, $path."/".$filename);
67+
if(file_exists($bmfile)) {
68+
$bms = file_get_contents($bmfile);
69+
$bms = parseHTMLMarks($bms, filemtime($bmfile), $this->gettext('bookmarks_new'));
70+
}
71+
}
72+
73+
$rcmail->output->command('syncmarks/get_bookmarks', array('message' => $ext, 'data' => json_encode($bms)));
74+
3575
}
3676

3777
function del_url() {
@@ -198,54 +238,21 @@ function add_url() {
198238
function add_bookmarks($args) {
199239
$rcmail = rcmail::get_instance();
200240
$this->load_config();
201-
$path = $rcmail->config->get('bookmarks_path', false);
202241
$filename = $rcmail->config->get('bookmarks_filename', false);
203-
$username = $rcmail->user->get_username();
204-
$password = $rcmail->get_user_password();
205242
$ext = pathinfo($filename, PATHINFO_EXTENSION);
206243

207-
if($ext === "json") {
208-
$url = $path."/".$filename;
209-
$context = stream_context_create(array ('http' => array ('header' => 'Authorization: Basic ' . base64_encode("$username:$password"))));
210-
$bookmarks = file_get_contents($url, false, $context);
211-
foreach ($http_response_header as &$value) {
212-
if (strpos($value, 'ast-Modified') != 0) {
213-
$modified = strtotime(substr($value, 15));
214-
break;
215-
}
216-
}
217-
$bookmarks = parseJSONMarks($bookmarks,$modified, $this->gettext('bookmarks_new'));
218-
$rcmail->output->add_footer("<div id=\"bookmarkpane\">".$bookmarks."</div>");
244+
if($ext === "php") {
245+
$rcmail->output->add_footer("<div id=\"bookmarkpane\"><iframe id='bmframe' srcdoc=\"\"></iframe></div>");
219246
return $args;
220247
}
221-
elseif($ext === "html") {
222-
$bmfile = str_replace("%u", $username, $path.$filename);
223-
if(file_exists($bmfile)) {
224-
$bookmarks = file_get_contents($bmfile);
225-
$bookmarks = parseHTMLMarks($bookmarks, filemtime($bmfile), $this->gettext('bookmarks_new'));
226-
$rcmail->output->add_footer("<div id=\"bookmarkpane\">".$bookmarks."</div>");
227-
return $args;
228-
}
229-
else {
230-
return false;
231-
}
232-
}
233-
elseif($ext === "php") {
234-
$remote_url = $path.$filename;
235-
$opts = array('http'=>array(
236-
'method'=>"GET",
237-
'header' => "Authorization: Basic ".base64_encode("$username:$password")
238-
)
239-
);
240-
$context = stream_context_create($opts);
241-
$bms = htmlspecialchars(file_get_contents($remote_url, false, $context));
242-
$rcmail->output->add_footer("<div id=\"bookmarkpane\"><iframe id='bmframe' srcdoc=\"$bms\"></iframe>");
248+
else {
249+
$rcmail->output->add_footer("<div id=\"bookmarkpane\"></div>");
243250
return $args;
244251
}
245252
}
246253

247254
function bookmarks_cmd() {
248-
$this->include_script('plugin.min.js');
255+
$this->include_script('plugin.js');
249256
}
250257
}
251258

0 commit comments

Comments
 (0)