+
+
Test push
View wiki guide
diff --git a/classes/pushserver.class.php b/classes/pushserver.class.php
index 3faf2bf1..9c7eca97 100644
--- a/classes/pushserver.class.php
+++ b/classes/pushserver.class.php
@@ -52,6 +52,16 @@ private function parse_data($Data) {
case 'pushover':
$this->push_pushover($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
break;
+ case 'pushbullet':
+ $this->push_pushbullet(
+ $JSON['user']['key'],
+ $JSON['user']['device'],//
+ $JSON['user']['userid'],
+ $JSON['user']['email'],//
+ $JSON['message']['title'],
+ $JSON['message']['body'],
+ $JSON['message']['url']
+ );
default:
break;
}
@@ -134,6 +144,44 @@ private function push_pushover($UserKey, $Title, $Message, $URL) {
curl_close($ch);
echo "Push sent to Pushover";
}
+
+ /**
+ * Notify via pushbullet
+ *
+ * @param $UserKey User API key
+ * @param $DeviceID device to push to
+ * @param $UserID UserID to check IP for
+ * @param $Email Last email gotten from pushbullet API. Used for anti-cheat.
+ * @param $Title Notification title
+ * @param $Message Notification message
+ * @param $URL For compatibility with other command. Just gets appended.
+ */
+ private function push_pushbullet($UserKey, $DeviceID,
+ $Title, $Message, $URL) {
+ if (!empty($URL)) {
+ $Message .= ' ' . $URL;
+ }
+
+ curl_setopt_array($Curl = curl_init(), array(
+ CURLOPT_URL => 'https://api.pushbullet.com/api/pushes',
+ CURLOPT_POSTFIELDS => array(
+ 'type' => 'note',
+ 'title' => $Title,
+ 'body' => $Message,
+ 'device_iden' => $DeviceID
+ ),
+ CURLOPT_USERPWD => $UserKey . ':',
+ CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
+ CURLOPT_RETURNTRANSFER => True
+ ));
+
+ $Result = curl_exec($Curl);
+ echo "Push sent to Pushbullet";
+ curl_close($Curl);
+
+
+
+ }
}
$PushServer = new PushServer();
diff --git a/sections/ajax/index.php b/sections/ajax/index.php
index b7d8242b..6753f05b 100644
--- a/sections/ajax/index.php
+++ b/sections/ajax/index.php
@@ -157,6 +157,9 @@
case 'clear_user_notification':
require(SERVER_ROOT . '/sections/ajax/clear_user_notification.php');
break;
+ case 'pushbullet_devices':
+ require(SERVER_ROOT . '/sections/ajax/pushbullet_devices.php');
+ break;
default:
// If they're screwing around with the query string
json_die("failure");
diff --git a/sections/ajax/pushbullet_devices.php b/sections/ajax/pushbullet_devices.php
new file mode 100644
index 00000000..c9233d60
--- /dev/null
+++ b/sections/ajax/pushbullet_devices.php
@@ -0,0 +1,21 @@
+ 'https://api.pushbullet.com/api/devices',
+ CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
+ CURLOPT_RETURNTRANSFER => true,
+ CURLOPT_USERPWD => $ApiKey . ':'
+));
+
+$Result = curl_exec($Ch);
+curl_close($Ch);
+echo json_encode($Result);
diff --git a/static/functions/user_settings.js b/static/functions/user_settings.js
index ab0d6171..b8acfc39 100644
--- a/static/functions/user_settings.js
+++ b/static/functions/user_settings.js
@@ -1,5 +1,6 @@
var PUSHOVER = 5;
var TOASTY = 4;
+var PUSHBULLET = 6;
$(document).ready(function() {
var top = $('#settings_sections').offset().top - parseFloat($('#settings_sections').css('marginTop').replace(/auto/, 0));
@@ -59,8 +60,14 @@ $(document).ready(function() {
});
if ($("#pushservice").val() > 0) {
+ $('.pushdeviceid').hide();
$('#pushsettings').show();
+ if ($('#pushservice').val() == PUSHBULLET) {
+ fetchPushbulletDevices($('#pushkey').val());
+ $('.pushdeviceid').show();
+ }
}
+
$("#pushservice").change(function() {
if ($(this).val() > 0) {
$('#pushsettings').show(500);
@@ -75,6 +82,19 @@ $(document).ready(function() {
} else {
$('#pushsettings').hide(500);
}
+
+ if ($(this).val() == PUSHBULLET) {
+ fetchPushbulletDevices($('#pushkey').val());
+ $('.pushdeviceid').show(500);
+ } else {
+ $('.pushdeviceid').hide(500);
+ }
+ });
+
+ $("#pushkey").blur(function() {
+ if($("#pushservice").val() == PUSHBULLET) {
+ fetchPushbulletDevices($(this).val());
+ }
});
});
@@ -82,3 +102,47 @@ function fuzzyMatch(str, pattern){
pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; });
return new RegExp(pattern).test(str);
};
+
+/**
+ * Gets device IDs from the pushbullet API
+ *
+ * @return array of dictionaries with devices
+ */
+function fetchPushbulletDevices(apikey) {
+ $.ajax({
+ url: 'ajax.php',
+ data: {
+ "action": 'pushbullet_devices',
+ "apikey": apikey
+ },
+ type: 'GET',
+ success: function(data, textStatus, xhr) {
+ var data = jQuery.parseJSON(data);
+ var field = $('#pushdevice');
+ var value = field.val();
+ if (data.error || textStatus !== 'success' ) {
+ if (data.error) {
+ field.html('
');
+ } else {
+ $('#pushdevice').html('
');
+ }
+ } else {
+ if(data['devices'].length > 0) {
+ field.html('');
+ }
+ for (var i = 0; i < data['devices'].length; i++) {
+ var model = data['devices'][i]['extras']['model'];
+ var nickname = data['devices'][i]['extras']['nickname'];
+ var name = nickname !== undefined ? nickname : model;
+ var option = new Option(name, data['devices'][i]['iden']);
+
+ option.selected = (option.value == value);
+ field[0].add(option);
+ }
+ }
+ },
+ error: function(data,textStatus,xhr) {
+ $('#pushdevice').html('
');
+ }
+ });
+}
\ No newline at end of file