Skip to content

Commit

Permalink
Merge pull request #2 from Offerel/dev
Browse files Browse the repository at this point in the history
Notifications for pushed links
  • Loading branch information
Offerel authored Jul 10, 2020
2 parents 5d8639d + 5563fb4 commit 281fcb9
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 54 deletions.
2 changes: 0 additions & 2 deletions .gitignore

This file was deleted.

27 changes: 27 additions & 0 deletions .vscode/sftp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "Fruchtzwerg",
"host": "192.168.188.4",
"protocol": "sftp",
"port": 22,
"username": "root",
"remotePath": "/media/stick/www/roundcube/plugins/syncmarks",
"uploadOnSave": true,
"agent": "pageant",
"downloadOnOpen": true,
"syncOption":{ "delete": true,
"skipCreate": false,
"ignoreExisting": false,
"update" : true
},
"remoteTimeOffsetInHours": 1,
"syncMode": "full",
"watcher": {
"files": "**/*",
"autoUpload": true,
"autoDelete": true
},
"ignore": [
".vscode",
".git"
]
}
46 changes: 46 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### v2.2.0
- Added notifications for pushed links

### v2.1.2
- Moved the get_bookmarks function from init to click to speed up inital loading

### v2.1.1
- Moved the get_bookmarks function from init to click to speed up inital loading

### v2.1.0
- Added support for SyncMarks
- Renamed to Roundcube Sycmarks

### v2.0.3
- Added support for Rouncube 1.4 elastic skin

### v2.0.2
- changed composer.json

### v2.0.1
- Added Chrome Extension

### v2.0.0
- The bookmarks saved with DAVMarks AddOn (https://addons.mozilla.org/en-US/firefox/addon/davmarks/) are now supported. Change $config['bookmarks_path'] to the WebDAV url (foldername) to your WebDAV share and $config['bookmarks_filename'] to "bookmarks.json". For the username and password, the Roundcube credentials are used.

### v1.2.0
- delete bookmarks with right-click
- retrieve bookmark now via curl instead file_get_contents
- bug fixes

### v1.1.0
- Add bookmarks via button
- automatically import bookmarks to Firefox file at Firefox start

### v1.0.3
- fix JavaScript for initialization error
- fix css for toolbar button

### v1.0.2
- small fix for a error message

### v1.0.1
- fixed open links in other tab

### v1.0.0
- Initial version
Binary file added bookmarks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 25 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
{
"name": "offerel/syncmarks",
"description": "Access your Firefox Bookmarks in Roundcube",
"keywords": ["bookmarks","plugin","firefox","roundcube"],
"homepage": "https://github.com/Offerel/roundcube_syncmarks",
"type": "roundcube-plugin",
"license": "AGPL-3.0",
"authors": [
{
"name": "Offerel",
"homepage": "https://github.com/Offerel",
"role": "Developer"
}
],
"version": "2.1.1",
"repositories": [
{
"type": "composer",
"url": "https://plugins.roundcube.net"
}
],
"require": {
"roundcube/plugin-installer": ">=0.1.6"
}
}
{
"name": "offerel/syncmarks",
"description": "Access your Firefox Bookmarks in Roundcube",
"keywords": ["bookmarks","plugin","firefox","roundcube"],
"homepage": "https://github.com/Offerel/roundcube_syncmarks",
"type": "roundcube-plugin",
"license": "AGPL-3.0",
"authors": [
{
"name": "Offerel",
"homepage": "https://github.com/Offerel",
"role": "Developer"
}
],
"version": "2.2.0",
"repositories": [
{
"type": "composer",
"url": "https://plugins.roundcube.net"
}
],
"require": {
"roundcube/plugin-installer": ">=0.1.6"
}
}
1 change: 0 additions & 1 deletion plugin.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion skins/classic/plugin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 29 additions & 3 deletions plugin.js → syncmarks.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
* Roundcube Bookmarks Plugin
*
* @version 2.1.1
* @version 2.2.0
* @author Offerel
* @copyright Copyright (c) 2019, Offerel
* @copyright Copyright (c) 2020, Offerel
* @license GNU General Public License, version 3
*/
function h_del(t, o) {
Expand Down Expand Up @@ -60,8 +60,34 @@ function get_bookmarks(response) {
}
}

function get_notifications(response) {
let notifications = JSON.parse(response);
notifications.forEach(function(notification){
show_noti(notification);
});
}

function show_noti(noti) {
if (Notification.permission !== 'granted')
Notification.requestPermission();
else {
let notification = new Notification(noti.title, {
body: noti.url,
icon: './plugins/syncmarks/bookmarks.png',
requireInteraction: true
});

notification.onclick = function() {
window.open(noti.url);
rcmail.http_post("syncmarks/del_not", '&_nkey=' + noti.nkey);
};
}
}

window.rcmail && rcmail.addEventListener("init", function(t) {}), $(document).ready(function() {
$("#7f3f3c06-5b85-4e7f-b527-d061478e9446").on("click", bookmarks_cmd), document.getElementById("bookmarkpane").addEventListener("click", function(t) {
"A" == t.target.tagName && bookmarks_cmd()
})
})
})

rcmail.addEventListener('plugin.sendNotifications', get_notifications);
9 changes: 9 additions & 0 deletions syncmarks.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

97 changes: 75 additions & 22 deletions syncmarks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
/**
* Roundcube Bookmarks Plugin
*
* @version 2.1.1
* @version 2.2.0
* @author Offerel
* @copyright Copyright (c) 2018, Offerel
* @copyright Copyright (c) 2020, Offerel
* @license GNU General Public License, version 3
*/
class syncmarks extends rcube_plugin
{
public $task = '?(?!login|logout).*';

{
public function init() {
$rcmail = rcmail::get_instance();

$this->add_texts('localization/', true);
$this->register_task('syncmarks');
$this->include_stylesheet($this->local_skin_path().'/plugin.min.css');
//$this->include_script('plugin.min.js');
$this->include_script('plugin.js');
$this->include_script('syncmarks.js');

$this->add_button(array(
'label' => 'syncmarks.bookmarks',
Expand All @@ -31,11 +27,63 @@ public function init() {
), 'taskbar');

$this->add_hook('render_page', array($this, 'add_bookmarks'));
$this->add_hook('refresh', array($this, 'get_notifications'));
$this->add_hook('session_destroy', array($this, 'unset_cookie'));

$this->register_action('add_url', array($this, 'add_url'));
$this->register_action('del_url', array($this, 'del_url'));
$this->register_action('get_bookmarks', array($this, 'get_bookmarks'));
$this->register_action('del_not', array($this, 'del_not'));
}

function unset_cookie() {
rcube_utils::setcookie('sycmarks_n', '0', time() - 60);
}

function get_notifications() {
if($_COOKIE['sycmarks_n'] != '1') {
$rcmail = rcmail::get_instance();
$this->load_config();
$path = $rcmail->config->get('bookmarks_path', false);
$filename = $rcmail->config->get('bookmarks_filename', false);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path.$filename.'?gurls=1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password());
$data = curl_exec($ch);
$rcmail->output->command('plugin.sendNotifications', $data);
curl_close($ch);
rcube_utils::setcookie('sycmarks_n', '1', 0);
}
}

function del_not() {
$rcmail = rcmail::get_instance();
$this->load_config();
$path = $rcmail->config->get('bookmarks_path', false);
$filename = $rcmail->config->get('bookmarks_filename', false);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path.$filename.'?durl='.rcube_utils::get_input_value('_nkey', rcube_utils::INPUT_GPC));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password());
$data = curl_exec($ch);
curl_close($ch);
}

function get_bookmarks() {
$rcmail = rcmail::get_instance();
$this->load_config();
Expand All @@ -50,9 +98,10 @@ function get_bookmarks() {
'header' => "Authorization: Basic ".base64_encode("$username:$password")
)
);

$context = stream_context_create($opts);
$bms = file_get_contents($remote_url, false, $context);

if($ext === "json") {
foreach ($http_response_header as &$value) {
if (strpos($value, 'ast-Modified') != 0) {
Expand All @@ -69,9 +118,8 @@ function get_bookmarks() {
$bms = parseHTMLMarks($bms, filemtime($bmfile), $this->gettext('bookmarks_new'));
}
}

$rcmail->output->command('syncmarks/get_bookmarks', array('message' => $ext, 'data' => json_encode($bms)));

}

function del_url() {
Expand Down Expand Up @@ -156,6 +204,7 @@ function add_url() {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 4);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_USERPWD, $rcmail->user->get_username().":".$rcmail->get_user_password());

$data = curl_exec($ch);
curl_close($ch);
Expand Down Expand Up @@ -235,19 +284,23 @@ function add_url() {
}
}

function add_bookmarks($args) {
function add_bookmarks() {
$rcmail = rcmail::get_instance();
$this->load_config();
$filename = $rcmail->config->get('bookmarks_filename', false);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$exctasks = array("login","logout");

if(!in_array($rcmail->task,$exctasks)) {
$this->load_config();
$filename = $rcmail->config->get('bookmarks_filename', false);
$ext = pathinfo($filename, PATHINFO_EXTENSION);

if($ext === "php") {
$rcmail->output->add_footer("<div id=\"bookmarkpane\"><iframe id='bmframe' srcdoc=\"\"></iframe></div>");
return $args;
}
else {
$rcmail->output->add_footer("<div id=\"bookmarkpane\"></div>");
return $args;
if($ext === "php") {
$rcmail->output->add_footer("<div id=\"bookmarkpane\"><iframe id='bmframe'></iframe></div>");
return $args;
}
else {
$rcmail->output->add_footer("<div id=\"bookmarkpane\"></div>");
return $args;
}
}
}

Expand Down

0 comments on commit 281fcb9

Please sign in to comment.