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