mirror of
https://github.com/WhatCD/Gazelle.git
synced 2024-12-12 18:36:29 +00:00
Empty commit
This commit is contained in:
parent
8cd5c4e1fe
commit
e5b57d8c27
@ -675,7 +675,12 @@ public static function save_settings($UserID, $Settings) {
|
||||
WHERE UserID = '$UserID'");
|
||||
|
||||
$PushService = (int) $_POST['pushservice'];
|
||||
$PushOptions = db_string(serialize(array("PushKey" => $_POST['pushkey'])));
|
||||
$PushOptionsArray = array("PushKey" => $_POST['pushkey']);
|
||||
if ($PushService === 6) { //pushbullet
|
||||
$PushOptionsArray['PushDevice'] = $_POST['pushdevice'];
|
||||
|
||||
}
|
||||
$PushOptions = db_string(serialize($PushOptionsArray));
|
||||
|
||||
if ($PushService != 0) {
|
||||
G::$DB->query("
|
||||
@ -752,13 +757,23 @@ public static function send_push($UserIDs, $Title, $Body, $URL = '', $Type = 'Gl
|
||||
case '5':
|
||||
$Service = "Pushover";
|
||||
break;
|
||||
case '6':
|
||||
$Service = "PushBullet";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!empty($Service) && !empty($PushOptions['PushKey'])) {
|
||||
$JSON = json_encode(array("service" => strtolower($Service),
|
||||
$Options = array("service" => strtolower($Service),
|
||||
"user" => array("key" => $PushOptions['PushKey']),
|
||||
"message" => array("title" => $Title, "body" => $Body, "url" => $URL)));
|
||||
"message" => array("title" => $Title, "body" => $Body, "url" => $URL));
|
||||
|
||||
if ($Service === 'PushBullet') {
|
||||
$Options["user"]["device"] = $PushOptions['PushDevice'];
|
||||
|
||||
}
|
||||
|
||||
$JSON = json_encode($Options);
|
||||
G::$DB->query("
|
||||
INSERT INTO push_notifications_usage
|
||||
(PushService, TimesUsed)
|
||||
|
@ -20,6 +20,9 @@ public static function load_js() {
|
||||
private static function render_push_settings() {
|
||||
$PushService = self::$Settings['PushService'];
|
||||
$PushOptions = unserialize(self::$Settings['PushOptions']);
|
||||
if (empty($PushOptions['PushDevice'])) {
|
||||
$PushOptions['PushDevice'] = '';
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td class="label"><strong>Push notifications</strong></td>
|
||||
@ -31,10 +34,15 @@ private static function render_push_settings() {
|
||||
<!-- No option 3, notifo died. -->
|
||||
<option value="4"<? if ($PushService == 4) { ?> selected="selected"<? } ?>>Super Toasty</option>
|
||||
<option value="5"<? if ($PushService == 5) { ?> selected="selected"<? } ?>>Pushover</option>
|
||||
<option value="6"<? if ($PushService == 6) { ?> selected="selected"<? } ?>>PushBullet</option>
|
||||
</select>
|
||||
<div id="pushsettings" style="display: none;">
|
||||
<label id="pushservice_title" for="pushkey">API key</label>
|
||||
<input type="text" size="50" name="pushkey" id="pushkey" value="<?=display_str($PushOptions['PushKey'])?>" />
|
||||
<label class="pushdeviceid" id="pushservice_device" for="pushdevice">Device ID</label>
|
||||
<select class="pushdeviceid" name="pushdevice" id="pushdevice">
|
||||
<option value="<?= display_str($PushOptions['PushDevice'])?>" selected="selected"><?= display_str($PushOptions['PushDevice'])?></option>
|
||||
</select>
|
||||
<br />
|
||||
<a href="user.php?action=take_push&push=1&userid=<?=G::$LoggedUser['ID']?>&auth=<?=G::$LoggedUser['AuthKey']?>" class="brackets">Test push</a>
|
||||
<a href="wiki.php?action=article&id=1017" class="brackets">View wiki guide</a>
|
||||
|
@ -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'],// <strip>
|
||||
$JSON['user']['userid'],
|
||||
$JSON['user']['email'],//</strip>
|
||||
$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 <strip>
|
||||
* @param $UserID UserID to check IP for
|
||||
* @param $Email Last email gotten from pushbullet API. Used for anti-cheat.</strip>
|
||||
* @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();
|
||||
|
@ -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");
|
||||
|
21
sections/ajax/pushbullet_devices.php
Normal file
21
sections/ajax/pushbullet_devices.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
|
||||
if (!isset($_GET['apikey']) || empty($_GET['apikey'])) {
|
||||
echo '{"error": { "message": "No API Key specified" }}';
|
||||
die();
|
||||
}
|
||||
|
||||
$ApiKey = $_GET['apikey'];
|
||||
|
||||
|
||||
curl_setopt_array($Ch = curl_init(), array(
|
||||
CURLOPT_URL => '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);
|
@ -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('<option>' + data.error.message + '</option>');
|
||||
} else {
|
||||
$('#pushdevice').html('<option>No devices fetched</option>');
|
||||
}
|
||||
} 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('<option>' + textStatus + '</option>');
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user