mirror of
https://github.com/WhatCD/Gazelle.git
synced 2025-01-18 04:01:35 +00:00
Empty commit
This commit is contained in:
parent
92416668b2
commit
043144bb96
256
classes/NMA_API.php
Normal file
256
classes/NMA_API.php
Normal file
@ -0,0 +1,256 @@
|
||||
<?php
|
||||
|
||||
class NMA_API
|
||||
{
|
||||
|
||||
/**
|
||||
* @const LIB_ERROR_TYPE can be exception or error
|
||||
*/
|
||||
const LIB_ERROR_TYPE = 'error';
|
||||
|
||||
/**
|
||||
* @const holds the api key verify url
|
||||
*/
|
||||
const LIB_NMA_VERIFY = 'https://www.notifymyandroid.com/publicapi/verify';
|
||||
|
||||
/**
|
||||
* @const holds the notify url
|
||||
*/
|
||||
const LIB_NMA_NOTIFY = 'https://www.notifymyandroid.com/publicapi/notify';
|
||||
|
||||
/**
|
||||
* toggles on debugging
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $debug = false;
|
||||
|
||||
public $apiCallsRemaining = false;
|
||||
|
||||
public $apiLimitReset = false;
|
||||
|
||||
public $lastStatus = false;
|
||||
/**
|
||||
* @var bool|string
|
||||
*/
|
||||
protected $apiKey = false;
|
||||
|
||||
/**
|
||||
* @var bool|string
|
||||
*/
|
||||
protected $devKey = false;
|
||||
|
||||
|
||||
protected $error_codes
|
||||
= array(
|
||||
200 => 'Notification submitted.',
|
||||
400 => 'The data supplied is in the wrong format, invalid length or null.',
|
||||
401 => 'None of the API keys provided were valid.',
|
||||
402 => 'Maximum number of API calls per hour exceeded.',
|
||||
500 => 'Internal server error. Please contact our support if the problem persists.'
|
||||
);
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*/
|
||||
function __construct($options = array())
|
||||
{
|
||||
if (!isset($options['apikey'])) {
|
||||
return $this->error('You must supply a API Key');
|
||||
} else {
|
||||
$this->apiKey = $options['apikey'];
|
||||
}
|
||||
|
||||
if (isset($options['developerkey'])) {
|
||||
$this->devKey = $options['developerkey'];
|
||||
}
|
||||
|
||||
if (isset($options['debug'])) {
|
||||
$this->debug = true;
|
||||
}
|
||||
|
||||
return true; // this shuts my ide up
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param bool $key [optional] if not set the one used on construct is used
|
||||
*
|
||||
* @return bool|mixed|SimpleXMLElement|string
|
||||
*/
|
||||
public function verify($key = false)
|
||||
{
|
||||
|
||||
$options = array();
|
||||
|
||||
if ($key !== false) {
|
||||
$options['apikey'] = $key;
|
||||
} else {
|
||||
$options['apikey'] = $this->apiKey;
|
||||
}
|
||||
|
||||
|
||||
if ($this->devKey) {
|
||||
$options['developerkey'] = $this->devKey;
|
||||
}
|
||||
|
||||
return $this->makeApiCall(self::LIB_NMA_VERIFY, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $application
|
||||
* @param string $event
|
||||
* @param string $description
|
||||
* @param string $url
|
||||
* @param int $priority
|
||||
* @param bool $apiKeys
|
||||
*
|
||||
* @return bool|mixed|SimpleXMLElement|string
|
||||
*/
|
||||
public function notify($application = '', $event = '', $description = '', $url = '', $priority = 0, $apiKeys = false)
|
||||
{
|
||||
if (empty($application) || empty($event) || empty($description)) {
|
||||
return $this->error('you must supply a application name, event and long desc');
|
||||
}
|
||||
|
||||
$post = array('application' => substr($application, 0, 256),
|
||||
'event' => substr($event, 0, 1000),
|
||||
'description' => substr($description, 0, 10000),
|
||||
'priority' => $priority
|
||||
);
|
||||
if (!empty($url)) {
|
||||
$post['url'] = substr($url, 0, 2000);
|
||||
}
|
||||
if ($this->devKey) {
|
||||
$post['developerkey'] = $this->devKey;
|
||||
}
|
||||
|
||||
if ($apiKeys !== false) {
|
||||
$post['apikey'] = $apiKeys;
|
||||
} else {
|
||||
$post['apikey'] = $this->apiKey;
|
||||
}
|
||||
|
||||
return $this->makeApiCall(self::LIB_NMA_NOTIFY, $post, 'POST');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $url
|
||||
* @param null $params
|
||||
* @param string $verb
|
||||
* @param string $format
|
||||
*
|
||||
* @return bool|mixed|SimpleXMLElement|string
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function makeApiCall($url, $params = null, $verb = 'GET', $format = 'xml')
|
||||
{
|
||||
$cparams = array(
|
||||
'http' => array(
|
||||
'method' => $verb,
|
||||
'ignore_errors' => true
|
||||
)
|
||||
);
|
||||
if ($params !== null && !empty($params)) {
|
||||
$params = http_build_query($params);
|
||||
if ($verb == 'POST') {
|
||||
$cparams["http"]['header'] = 'Content-Type: application/x-www-form-urlencoded';
|
||||
$cparams['http']['content'] = $params;
|
||||
} else {
|
||||
$url .= '?' . $params;
|
||||
}
|
||||
} else {
|
||||
return $this->error(
|
||||
'this api requires all calls to have params' . $this->debug ? ', you provided: ' . var_dump($params)
|
||||
: ''
|
||||
);
|
||||
}
|
||||
|
||||
$context = stream_context_create($cparams);
|
||||
$fp = fopen($url, 'rb', false, $context);
|
||||
if (!$fp) {
|
||||
$res = false;
|
||||
} else {
|
||||
|
||||
if ($this->debug) {
|
||||
$meta = stream_get_meta_data($fp);
|
||||
$this->error('var dump of http headers' . var_dump($meta['wrapper_data']));
|
||||
}
|
||||
|
||||
$res = stream_get_contents($fp);
|
||||
}
|
||||
|
||||
if ($res === false) {
|
||||
return $this->error("$verb $url failed: $php_errormsg");
|
||||
}
|
||||
|
||||
switch ($format) {
|
||||
case 'json':
|
||||
return $this->error('this api does not support json');
|
||||
/*
|
||||
* uncomment the below if json is added later
|
||||
* $r = json_decode($res);
|
||||
if ($r === null) {
|
||||
return $this->error("failed to decode $res as json");
|
||||
}
|
||||
return $r;*/
|
||||
|
||||
case 'xml':
|
||||
$r = simplexml_load_string($res);
|
||||
if ($r === null) {
|
||||
return $this->error("failed to decode $res as xml");
|
||||
}
|
||||
return $this->process_xml_return($r);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @param int $type
|
||||
*
|
||||
* @return bool
|
||||
* @throws Exception
|
||||
*/
|
||||
private function error($message, $type = E_USER_NOTICE)
|
||||
{
|
||||
if (self::LIB_ERROR_TYPE == 'error') {
|
||||
trigger_error($message, $type);
|
||||
return false;
|
||||
} else {
|
||||
throw new Exception($message, $type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SimpleXMLElement $obj
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function process_xml_return(SimpleXMLElement $obj)
|
||||
{
|
||||
|
||||
if (isset($obj->success)) {
|
||||
$this->lastStatus = $obj->success["@attributes"]['code'];
|
||||
|
||||
$this->apiCallsRemaining = $obj->success["@attributes"]['remaining'];
|
||||
$this->apiLimitReset = $obj->success["@attributes"]['resettimer'];
|
||||
return true;
|
||||
} elseif (isset($obj->error)) {
|
||||
if (isset($obj->error["@attributes"])) {
|
||||
$this->lastStatus = $obj->error["@attributes"]['code'];
|
||||
|
||||
if (isset($obj->error["@attributes"]['resettimer'])) {
|
||||
$this->apiLimitReset = $obj->error["@attributes"]['resettimer'];
|
||||
}
|
||||
|
||||
}
|
||||
return $this->error($obj->error);
|
||||
} else {
|
||||
return $this->error("unkown error");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -44,6 +44,8 @@ public static function file_string($EscapeStr) {
|
||||
*/
|
||||
public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '') {
|
||||
global $Time;
|
||||
$UnescapedSubject = $Subject;
|
||||
$UnescapedBody = $Body;
|
||||
$Subject = db_string($Subject);
|
||||
$Body = db_string($Body);
|
||||
if ($ToID == 0 || $ToID == $FromID) {
|
||||
@ -126,6 +128,7 @@ public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '') {
|
||||
list($UnRead) = G::$DB->next_record();
|
||||
G::$Cache->cache_value('inbox_new_'.$ID, $UnRead);
|
||||
|
||||
NotificationsManager::send_push($ID, "Message from $SenderName, Subject: $UnescapedSubject", $UnescapedBody, site_url() . 'inbox.php', NotificationsManager::INBOX);
|
||||
}
|
||||
|
||||
G::$DB->set_query_id($QueryID);
|
||||
@ -133,7 +136,6 @@ public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '') {
|
||||
return $ConvID;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create thread function, things should already be escaped when sent here.
|
||||
*
|
||||
|
@ -5,6 +5,9 @@ class NotificationsManager {
|
||||
const OPT_DISABLED = 0;
|
||||
const OPT_POPUP = 1;
|
||||
const OPT_TRADITIONAL = 2;
|
||||
const OPT_PUSH = 3;
|
||||
const OPT_POPUP_PUSH = 4;
|
||||
const OPT_TRADITIONAL_PUSH = 5;
|
||||
|
||||
// Importances
|
||||
const IMPORTANT = 'information';
|
||||
@ -225,7 +228,7 @@ public static function clear_global_notification() {
|
||||
if ($GlobalNotification) {
|
||||
// This is some trickery
|
||||
// since we can't know which users have the read cache key set
|
||||
// wet set the expiration time of their cache key to that of the length of the notification
|
||||
// we set the expiration time of their cache key to that of the length of the notification
|
||||
// this gaurantees that their cache key will expire after the notification expires
|
||||
G::$Cache->cache_value('user_read_global_' . G::$LoggedUser['ID'], true, $GlobalNotification['Expiration']);
|
||||
}
|
||||
@ -624,9 +627,11 @@ public static function get_settings($UserID) {
|
||||
$QueryID = G::$DB->get_query_id();
|
||||
G::$DB->query("
|
||||
SELECT *
|
||||
FROM users_notifications_settings
|
||||
WHERE UserID = '$UserID'");
|
||||
$Results = G::$DB->next_record(MYSQLI_ASSOC);
|
||||
FROM users_notifications_settings AS n
|
||||
LEFT JOIN users_push_notifications AS p
|
||||
ON p.UserID = n.UserID
|
||||
WHERE n.UserID = '$UserID'");
|
||||
$Results = G::$DB->next_record(MYSQLI_ASSOC, false);
|
||||
G::$DB->set_query_id($QueryID);
|
||||
G::$Cache->cache_value("users_notifications_settings_$UserID", $Results, 0);
|
||||
}
|
||||
@ -642,12 +647,23 @@ public static function save_settings($UserID, $Settings) {
|
||||
foreach (self::$Types as $Type) {
|
||||
$Popup = array_key_exists("notifications_$Type" . '_popup', $Settings);
|
||||
$Traditional = array_key_exists("notifications_$Type" . '_traditional', $Settings);
|
||||
$Push = array_key_exists("notifications_$Type" . '_push', $Settings);
|
||||
$Result = self::OPT_DISABLED;
|
||||
if ($Popup) {
|
||||
$Result = self::OPT_POPUP;
|
||||
} elseif ($Traditional) {
|
||||
}
|
||||
if ($Traditional) {
|
||||
$Result = self::OPT_TRADITIONAL;
|
||||
}
|
||||
if ($Push) {
|
||||
$Result = self::OPT_POPUP;
|
||||
}
|
||||
if ($Popup && $Push) {
|
||||
$Result = self::OPT_POPUP_PUSH;
|
||||
}
|
||||
if ($Traditional && $Push) {
|
||||
$Result = self::OPT_TRADITIONAL_PUSH;
|
||||
}
|
||||
$Update[] = "$Type = $Result";
|
||||
}
|
||||
$Update = implode(',', $Update);
|
||||
@ -657,6 +673,23 @@ public static function save_settings($UserID, $Settings) {
|
||||
UPDATE users_notifications_settings
|
||||
SET $Update
|
||||
WHERE UserID = '$UserID'");
|
||||
|
||||
$PushService = (int) $_POST['pushservice'];
|
||||
$PushOptions = db_string(serialize(array("PushKey" => $_POST['pushkey'])));
|
||||
|
||||
if ($PushService != 0) {
|
||||
G::$DB->query("
|
||||
INSERT INTO users_push_notifications
|
||||
(UserID, PushService, PushOptions)
|
||||
VALUES
|
||||
('$UserID', '$PushService', '$PushOptions')
|
||||
ON DUPLICATE KEY UPDATE
|
||||
PushService = '$PushService',
|
||||
PushOptions = '$PushOptions'");
|
||||
} else {
|
||||
G::$DB->query("UPDATE users_push_notifications SET PushService = 0 WHERE UserID = '$UserID'");
|
||||
}
|
||||
|
||||
G::$DB->set_query_id($QueryID);
|
||||
G::$Cache->delete_value("users_notifications_settings_$UserID");
|
||||
}
|
||||
@ -672,4 +705,90 @@ public function is_skipped($Type) {
|
||||
public function use_noty() {
|
||||
return in_array(self::OPT_POPUP, $this->Settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a push notification to a user
|
||||
*
|
||||
* @param array $UserIDs integer or array of integers of UserIDs to push
|
||||
* @param string $Title the title to be displayed in the push
|
||||
* @param string $Body the body of the push
|
||||
* @param string $URL url for the push notification to contain
|
||||
* @param string $Type what sort of push is it? PM, Rippy, News, etc
|
||||
*/
|
||||
public static function send_push($UserIDs, $Title, $Body, $URL = '', $Type = 'Global') {
|
||||
if (!is_array($UserIDs)) {
|
||||
$UserIDs = array($UserIDs);
|
||||
}
|
||||
foreach($UserIDs as $UserID) {
|
||||
$UserID = (int) $UserID;
|
||||
$QueryID = G::$DB->get_query_id();
|
||||
$SQL = "
|
||||
SELECT
|
||||
p.PushService, p.PushOptions
|
||||
FROM users_notifications_settings AS n
|
||||
JOIN users_push_notifications AS p
|
||||
ON n.UserID = p.UserID
|
||||
WHERE n.UserID = '$UserID'
|
||||
AND p.PushService != 0";
|
||||
if ($Type != self::GLOBALNOTICE) {
|
||||
$SQL .= " AND n.$Type IN (" . self::OPT_PUSH . "," . self::OPT_POPUP_PUSH . "," . self::OPT_TRADITIONAL_PUSH . ")";
|
||||
}
|
||||
G::$DB->query($SQL);
|
||||
|
||||
if (G::$DB->has_results()) {
|
||||
list($PushService, $PushOptions) = G::$DB->next_record(MYSQLI_NUM, false);
|
||||
$PushOptions = unserialize($PushOptions);
|
||||
switch ($PushService) {
|
||||
case '1':
|
||||
$Service = "NMA";
|
||||
break;
|
||||
case '2':
|
||||
$Service = "Prowl";
|
||||
break;
|
||||
// Case 3 is missing because notifo is dead.
|
||||
case '4':
|
||||
$Service = "Toasty";
|
||||
break;
|
||||
case '5':
|
||||
$Service = "Pushover";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (!empty($Service) && !empty($PushOptions['PushKey'])) {
|
||||
$JSON = json_encode(array("service" => strtolower($Service),
|
||||
"user" => array("key" => $PushOptions['PushKey']),
|
||||
"message" => array("title" => $Title, "body" => $Body, "url" => $URL)));
|
||||
G::$DB->query("
|
||||
INSERT INTO push_notifications_usage
|
||||
(PushService, TimesUsed)
|
||||
VALUES
|
||||
('$Service', 1)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
TimesUsed = TimesUsed + 1");
|
||||
|
||||
$PushServerSocket = fsockopen("127.0.0.1", 6789);
|
||||
fwrite($PushServerSocket, $JSON);
|
||||
fclose($PushServerSocket);
|
||||
}
|
||||
}
|
||||
G::$DB->set_query_id($QueryID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets users who have push notifications enabled
|
||||
*
|
||||
*/
|
||||
public static function get_push_enabled_users() {
|
||||
$QueryID = G::$DB->get_query_id();
|
||||
G::$DB->query("
|
||||
SELECT UserID
|
||||
FROM users_push_notifications
|
||||
WHERE PushService != 0
|
||||
AND UserID != '$LoggedUser[ID]'");
|
||||
$PushUsers = G::$DB->collect("UserID");
|
||||
G::$DB->set_query_id($QueryID);
|
||||
return $PushUsers;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,37 @@ public static function load_js() {
|
||||
}
|
||||
}
|
||||
|
||||
private static function render_push_settings() {
|
||||
$PushService = self::$Settings['PushService'];
|
||||
$PushOptions = unserialize(self::$Settings['PushOptions']);
|
||||
?>
|
||||
<tr>
|
||||
<td class="label"><strong>Push notifications</strong></td>
|
||||
<td>
|
||||
<select name="pushservice" id="pushservice">
|
||||
<option value="0"<? if (empty($PushService)) { ?> selected="selected"<? } ?>>Disable push notifications</option>
|
||||
<option value="1"<? if ($PushService == 1) { ?> selected="selected"<? } ?>>Notify My Android</option>
|
||||
<option value="2"<? if ($PushService == 2) { ?> selected="selected"<? } ?>>Prowl</option>
|
||||
<!-- 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>
|
||||
</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'])?>" />
|
||||
<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>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<? }
|
||||
|
||||
public static function render_settings($Settings) {
|
||||
self::$Settings = $Settings;
|
||||
if (check_perms("users_mod") || G::$LoggedUser['ExtraClasses'][DELTA_TEAM]) {
|
||||
self::render_push_settings();
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<td class="label">
|
||||
@ -49,7 +78,7 @@ public static function render_settings($Settings) {
|
||||
<strong>Staff messages</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::STAFFPM); ?>
|
||||
<? self::render_checkbox(NotificationsManager::STAFFPM, false, false); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -57,7 +86,7 @@ public static function render_settings($Settings) {
|
||||
<strong>Thread subscriptions</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::SUBSCRIPTIONS); ?>
|
||||
<? self::render_checkbox(NotificationsManager::SUBSCRIPTIONS, false, false); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -74,83 +103,48 @@ public static function render_settings($Settings) {
|
||||
<strong>Torrent notifications</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::TORRENTS, true); ?>
|
||||
<? self::render_checkbox(NotificationsManager::TORRENTS, true, false); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<? } ?>
|
||||
|
||||
<tr>
|
||||
<td class="label tooltip" title="Enabling this will give you a notification when a torrent is added to a collage you are subscribed to.">
|
||||
<strong>Collage subscriptions</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::COLLAGES); ?>
|
||||
<? self::render_checkbox(NotificationsManager::COLLAGES. false, false); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<? /**
|
||||
<tr>
|
||||
<td class="label tooltip" title="">
|
||||
<strong>Site alerts</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::SITEALERTS); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label tooltip" title="">
|
||||
<strong>Forum alerts</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::FORUMALERTS); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label tooltip" title="">
|
||||
<strong>Request alerts</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::REQUESTALERTS); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label tooltip" title="">
|
||||
<strong>Collage alerts</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::COLLAGEALERTS); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label tooltip" title="">
|
||||
<strong>Torrent alerts</strong>
|
||||
</td>
|
||||
<td>
|
||||
<? self::render_checkbox(NotificationsManager::TORRENTALERTS); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<? **/
|
||||
}
|
||||
<? }
|
||||
|
||||
private static function render_checkbox($Name, $Both = false) {
|
||||
private static function render_checkbox($Name, $Traditional = false, $Push = true) {
|
||||
$Checked = self::$Settings[$Name];
|
||||
if ($Both) {
|
||||
$IsChecked = $Checked == NotificationsManager::OPT_TRADITIONAL ? ' checked="checked"' : '';
|
||||
$PopupChecked = $Checked == NotificationsManager::OPT_POPUP || $Checked == NotificationsManager::OPT_POPUP_PUSH || !isset($Checked) ? ' checked="checked"' : '';
|
||||
$TraditionalChecked = $Checked == NotificationsManager::OPT_TRADITIONAL || $Checked == NotificationsManager::OPT_TRADITIONAL_PUSH ? ' checked="checked"' : '';
|
||||
$PushChecked = $Checked == NotificationsManager::OPT_TRADITIONAL_PUSH || $Checked == NotificationsManager::OPT_POPUP_PUSH || $Checked == NotificationsManager::OPT_PUSH ? ' checked="checked"' : '';
|
||||
|
||||
?>
|
||||
<label>
|
||||
<input type="checkbox" value="1" name="notifications_<?=$Name?>_traditional" id="notifications_<?=$Name?>_traditional"<?=$IsChecked?> />
|
||||
Traditional
|
||||
</label>
|
||||
<?
|
||||
}
|
||||
$IsChecked = $Checked == NotificationsManager::OPT_POPUP || !isset($Checked) ? ' checked="checked"' : '';
|
||||
?>
|
||||
<label>
|
||||
<input type="checkbox" name="notifications_<?=$Name?>_popup" id="notifications_<?=$Name?>_popup"<?=$IsChecked?> />
|
||||
Pop-up
|
||||
</label>
|
||||
<?
|
||||
<label>
|
||||
<input type="checkbox" name="notifications_<?=$Name?>_popup" id="notifications_<?=$Name?>_popup"<?=$PopupChecked?> />
|
||||
Pop-up
|
||||
</label>
|
||||
<? if ($Traditional) { ?>
|
||||
<label>
|
||||
<input type="checkbox" name="notifications_<?=$Name?>_traditional" id="notifications_<?=$Name?>_traditional"<?=$TraditionalChecked?> />
|
||||
Traditional
|
||||
</label>
|
||||
<? }
|
||||
if ($Push && (check_perms("users_mod") || G::$LoggedUser['ExtraClasses'][DELTA_TEAM])) { ?>
|
||||
<label>
|
||||
<input type="checkbox" name="notifications_<?=$Name?>_push" id="notifications_<?=$Name?>_push"<?=$PushChecked?> />
|
||||
Push
|
||||
</label>
|
||||
<? }
|
||||
}
|
||||
|
||||
public static function format_traditional($Contents) {
|
||||
return "<a href=\"$Contents[url]\">$Contents[message]</a>";
|
||||
}
|
||||
|
||||
}
|
||||
|
140
classes/pushserver.class.php
Normal file
140
classes/pushserver.class.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
define("PUSH_SOCKET_LISTEN_ADDRESS", "127.0.0.1");
|
||||
define("PUSH_SOCKET_LISTEN_PORT", 6789);
|
||||
|
||||
require 'NMA_API.php';
|
||||
require 'config.php';
|
||||
class PushServer {
|
||||
private $ListenSocket = false;
|
||||
private $State = 1;
|
||||
private $Listened = false;
|
||||
|
||||
public function __construct() {
|
||||
// restore_error_handler(); //Avoid PHP error logging
|
||||
set_time_limit(0);
|
||||
$this->init();
|
||||
$this->listen();
|
||||
}
|
||||
|
||||
private function init() {
|
||||
$this->ListenSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
|
||||
socket_set_option($this->ListenSocket, SOL_SOCKET, SO_REUSEADDR, 1);
|
||||
socket_bind($this->ListenSocket, PUSH_SOCKET_LISTEN_ADDRESS, PUSH_SOCKET_LISTEN_PORT);
|
||||
socket_listen($this->ListenSocket);
|
||||
socket_set_nonblock($this->ListenSocket);
|
||||
echo "\nInitialized\n";
|
||||
}
|
||||
|
||||
private function listen() {
|
||||
echo "\nListening...\n";
|
||||
while ( ($this->State) == 1 ) {
|
||||
if ($this->Listened = @socket_accept($this->ListenSocket)) {
|
||||
$Data = socket_read($this->Listened, 512);
|
||||
$this->parse_data($Data);
|
||||
}
|
||||
usleep(5000);
|
||||
}
|
||||
}
|
||||
|
||||
private function parse_data($Data) {
|
||||
$JSON = json_decode($Data, true);
|
||||
$Service = strtolower($JSON['service']);
|
||||
switch ($Service) {
|
||||
case 'nma':
|
||||
$this->push_nma($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
|
||||
break;
|
||||
case 'prowl':
|
||||
$this->push_prowl($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
|
||||
break;
|
||||
case 'toasty':
|
||||
$this->push_toasty($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
|
||||
break;
|
||||
case 'pushover':
|
||||
$this->push_pushover($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function push_prowl($Key, $Title, $Message, $URL) {
|
||||
$API = "https://api.prowlapp.com/publicapi/add";
|
||||
$Fields = array(
|
||||
'apikey' => urlencode($Key),
|
||||
'application' => urlencode(SITE_NAME),
|
||||
'event' => urlencode($Title),
|
||||
'description' => urlencode($Message)
|
||||
);
|
||||
if (!empty($URL)) {
|
||||
$Fields['url'] = $URL;
|
||||
}
|
||||
$FieldsString = "";
|
||||
foreach ($Fields as $key => $value) {
|
||||
$FieldsString .= $key . '=' . $value . '&';
|
||||
}
|
||||
rtrim($FieldsString, '&');
|
||||
|
||||
$Curl = curl_init();
|
||||
curl_setopt($Curl, CURLOPT_URL, $API);
|
||||
curl_setopt($Curl, CURLOPT_POST, count($Fields));
|
||||
curl_setopt($Curl, CURLOPT_POSTFIELDS, $FieldsString);
|
||||
curl_exec($Curl);
|
||||
curl_close($Curl);
|
||||
echo "Push sent to Prowl";
|
||||
}
|
||||
|
||||
private function push_toasty($Key, $Title, $Message, $URL) {
|
||||
$API = "http://api.supertoasty.com/notify/" . urlencode($Key) . "?";
|
||||
if (!empty($URL)) {
|
||||
$Message = $Message . " " . $URL;
|
||||
}
|
||||
$Fields = array(
|
||||
'title' => urlencode($Title),
|
||||
'text' => urlencode($Message),
|
||||
'sender' => urlencode(SITE_NAME)
|
||||
);
|
||||
$FieldsString = "";
|
||||
foreach ($Fields as $key => $value) {
|
||||
$FieldsString .= $key . '=' . $value . '&';
|
||||
}
|
||||
rtrim($FieldsString, '&');
|
||||
|
||||
$Curl = curl_init();
|
||||
curl_setopt($Curl, CURLOPT_URL, $API);
|
||||
curl_setopt($Curl, CURLOPT_POST, count($Fields));
|
||||
curl_setopt($Curl, CURLOPT_POSTFIELDS, $FieldsString);
|
||||
curl_exec($Curl);
|
||||
curl_close($Curl);
|
||||
echo "Push sent to Toasty";
|
||||
}
|
||||
|
||||
private function push_nma($Key, $Title, $Message, $URL) {
|
||||
$NMA = new NMA_API(array(
|
||||
'apikey' => $Key
|
||||
));
|
||||
if ($NMA->verify()) {
|
||||
if ($NMA->notify(SITE_NAME, $Title, $Message, $URL)) {
|
||||
echo "Push sent to NMA";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function push_pushover($UserKey, $Title, $Message, $URL) {
|
||||
curl_setopt_array($ch = curl_init(), array(
|
||||
CURLOPT_URL => "https://api.pushover.net/1/messages.json",
|
||||
CURLOPT_POSTFIELDS => array(
|
||||
"token" => PUSHOVER_KEY,
|
||||
"user" => $UserKey,
|
||||
"title" => $Title,
|
||||
"message" => $Message,
|
||||
"url" => $URL
|
||||
)
|
||||
));
|
||||
curl_exec($ch);
|
||||
curl_close($ch);
|
||||
echo "Push sent to Pushover";
|
||||
}
|
||||
}
|
||||
|
||||
$PushServer = new PushServer();
|
||||
?>
|
@ -37,7 +37,6 @@ public static function quote_notify($Body, $PostID, $Page, $PageID) {
|
||||
// remove any dupes in the array (the fast way)
|
||||
$Usernames = array_flip(array_flip($Usernames));
|
||||
|
||||
|
||||
G::$DB->query("
|
||||
SELECT m.ID
|
||||
FROM users_main AS m
|
||||
@ -46,7 +45,6 @@ public static function quote_notify($Body, $PostID, $Page, $PageID) {
|
||||
AND i.NotifyOnQuote = '1'
|
||||
AND i.UserID != " . G::$LoggedUser['ID']);
|
||||
|
||||
|
||||
$Results = G::$DB->to_array();
|
||||
foreach ($Results as $Result) {
|
||||
$UserID = db_string($Result['ID']);
|
||||
@ -61,7 +59,13 @@ public static function quote_notify($Body, $PostID, $Page, $PageID) {
|
||||
VALUES
|
||||
('$UserID', '$QuoterID', '$Page', '$PageID', '$PostID', '" . sqltime() . "')");
|
||||
G::$Cache->delete_value("notify_quoted_$UserID");
|
||||
|
||||
$URL = 'https://'.SSL_SITE_URL.'/';
|
||||
if ($Page == 'forums') {
|
||||
$URL .= "forums.php?action=viewthread&postid=$PostID";
|
||||
} else {
|
||||
$URL .= "comments.php?action=jump&postid=$PostID";
|
||||
}
|
||||
NotificationsManager::send_push($UserID, 'New Quote!', 'Quoted by ' . G::$LoggedUser['Username'] . " $URL", $URL, NotificationsManager::QUOTES);
|
||||
}
|
||||
G::$DB->set_query_id($QueryID);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ public static function render_linkbox($Selected) {
|
||||
?>
|
||||
<div class="linkbox">
|
||||
<a href="top10.php?type=torrents" class="brackets"><?=self::get_selected_link("Torrents", $Selected == "torrents")?></a>
|
||||
<a href="top10.php?type=lastfm" class="brackets"><?=self::get_selected_link("Last.fm", $Selected == "lastfm")?></a>
|
||||
<a href="top10.php?type=lastfm" class="brackets"><?=self::get_selected_link("Last.FM", $Selected == "lastfm")?></a>
|
||||
<a href="top10.php?type=users" class="brackets"><?=self::get_selected_link("Users", $Selected == "users")?></a>
|
||||
<a href="top10.php?type=tags" class="brackets"><?=self::get_selected_link("Tags", $Selected == "tags")?></a>
|
||||
<a href="top10.php?type=votes" class="brackets"><?=self::get_selected_link("Favorites", $Selected == "votes")?></a>
|
||||
@ -18,8 +18,8 @@ public static function render_linkbox($Selected) {
|
||||
public static function render_artist_links($Selected, $View) {
|
||||
?>
|
||||
<div class="center">
|
||||
<a href="top10.php?type=lastfm&category=weekly&view=<?=$View?>" class="brackets tooltip" title="These are the artists with the most Last.fm listeners this week"><?=self::get_selected_link("Weekly Artists", $Selected == "weekly")?></a>
|
||||
<a href="top10.php?type=lastfm&category=hyped&view=<?=$View?>" class="brackets tooltip" title="These are the the fastest rising artists on Last.fm this week"><?=self::get_selected_link("Hyped Artists", $Selected == "hyped")?></a>
|
||||
<a href="top10.php?type=lastfm&category=weekly&view=<?=$View?>" class="brackets tooltip" title="These are the artists with the most Last.FM listeners this week"><?=self::get_selected_link("Weekly Artists", $Selected == "weekly")?></a>
|
||||
<a href="top10.php?type=lastfm&category=hyped&view=<?=$View?>" class="brackets tooltip" title="These are the the fastest rising artists on Last.FM this week"><?=self::get_selected_link("Hyped Artists", $Selected == "hyped")?></a>
|
||||
|
||||
</div>
|
||||
<?
|
||||
|
@ -99,6 +99,8 @@
|
||||
VALUES ('$LoggedUser[ID]', $ThreadID)");
|
||||
$Cache->delete_value('subscriptions_user_'.$LoggedUser['ID']);
|
||||
}
|
||||
NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::BLOG);
|
||||
|
||||
header('Location: blog.php');
|
||||
break;
|
||||
}
|
||||
|
@ -77,9 +77,9 @@
|
||||
}
|
||||
if (in_array($Short, array('comment', 'post', 'thread'))) {
|
||||
$Channels[] = '#forumreports';
|
||||
|
||||
}
|
||||
|
||||
|
||||
foreach ($Channels as $Channel) {
|
||||
send_irc("PRIVMSG $Channel :$ReportID - ".$LoggedUser['Username']." just reported a $Short: ".site_url()."$Link : ".strtr($Reason, "\n", ' '));
|
||||
}
|
||||
|
@ -171,6 +171,8 @@
|
||||
|
||||
|
||||
|
||||
NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::NEWS);
|
||||
|
||||
$Cache->delete_value('news_latest_id');
|
||||
$Cache->delete_value('news_latest_title');
|
||||
$Cache->delete_value('news');
|
||||
|
@ -22,11 +22,11 @@
|
||||
break;
|
||||
}
|
||||
|
||||
View::show_header("Last.fm", "jquery.imagesloaded,jquery.wookmark,top10", "tiles");
|
||||
View::show_header("Last.FM", "jquery.imagesloaded,jquery.wookmark,top10", "tiles");
|
||||
?>
|
||||
<div class="thin">
|
||||
<div class="header">
|
||||
<h2>Last.fm</h2>
|
||||
<h2>Last.FM</h2>
|
||||
<? Top10View::render_linkbox("lastfm"); ?>
|
||||
</div>
|
||||
<? Top10View::render_artist_links($Category, $View); ?>
|
||||
|
@ -56,8 +56,7 @@ function checked($Checked) {
|
||||
$SiteOptions = array();
|
||||
}
|
||||
|
||||
View::show_header("$Username > Settings", 'user,jquery-ui,release_sort,password_validate,validate,push_settings,cssgallery,preview_paranoia,bbcode,user_settings,donor_titles');
|
||||
|
||||
View::show_header("$Username > Settings", 'user,jquery-ui,release_sort,password_validate,validate,cssgallery,preview_paranoia,bbcode,user_settings,donor_titles');
|
||||
|
||||
|
||||
|
||||
|
@ -261,7 +261,6 @@
|
||||
$UnseededAlerts = isset($_POST['unseededalerts']) ? 1 : 0;
|
||||
|
||||
|
||||
|
||||
$LastFMUsername = db_string($_POST['lastfm_username']);
|
||||
$OldLastFMUsername = '';
|
||||
$DB->query("
|
||||
|
11
sections/user/take_push.php
Normal file
11
sections/user/take_push.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?
|
||||
authorize();
|
||||
if (!check_perms('users_mod') && $_GET['userid'] != $LoggedUser['ID']) {
|
||||
error(403);
|
||||
}
|
||||
|
||||
$UserID = db_string($_GET['userid']);
|
||||
NotificationsManager::send_push($UserID, 'Push!', 'You\'ve been pushed by ' . $LoggedUser['Username']);
|
||||
|
||||
header('Location: user.php?action=edit&userid=' . $UserID . "");
|
||||
?>
|
@ -1,24 +0,0 @@
|
||||
(function() {
|
||||
var PUSHOVER = 5;
|
||||
var TOASTY = 4;
|
||||
$(document).ready(function() {
|
||||
if ($("#pushservice").val() > 0) {
|
||||
$('#pushsettings').show();
|
||||
}
|
||||
$("#pushservice").change(function() {
|
||||
if ($(this).val() > 0) {
|
||||
$('#pushsettings').show(500);
|
||||
|
||||
if ($(this).val() == TOASTY) {
|
||||
$('#pushservice_title').text("Device ID");
|
||||
} else if ($(this).val() == PUSHOVER) {
|
||||
$('#pushservice_title').text("User Key");
|
||||
} else {
|
||||
$('#pushservice_title').text("API Key");
|
||||
}
|
||||
} else {
|
||||
$('#pushsettings').hide(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
@ -1,3 +1,6 @@
|
||||
var PUSHOVER = 5;
|
||||
var TOASTY = 4;
|
||||
|
||||
$(document).ready(function() {
|
||||
var top = $('#settings_sections').offset().top - parseFloat($('#settings_sections').css('marginTop').replace(/auto/, 0));
|
||||
$(window).scroll(function (event) {
|
||||
@ -54,6 +57,25 @@ $(document).ready(function() {
|
||||
$("#notifications_Torrents_popup").click(function() {
|
||||
$("#notifications_Torrents_traditional").prop('checked', false);
|
||||
});
|
||||
|
||||
if ($("#pushservice").val() > 0) {
|
||||
$('#pushsettings').show();
|
||||
}
|
||||
$("#pushservice").change(function() {
|
||||
if ($(this).val() > 0) {
|
||||
$('#pushsettings').show(500);
|
||||
|
||||
if ($(this).val() == TOASTY) {
|
||||
$('#pushservice_title').text("Device ID");
|
||||
} else if ($(this).val() == PUSHOVER) {
|
||||
$('#pushservice_title').text("User Key");
|
||||
} else {
|
||||
$('#pushservice_title').text("API Key");
|
||||
}
|
||||
} else {
|
||||
$('#pushsettings').hide(500);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function fuzzyMatch(str, pattern){
|
||||
|
Loading…
Reference in New Issue
Block a user