Browse Source

Remove references to third-party Push services

spaghetti 7 years ago
parent
commit
c3a965fdee

+ 0
- 256
classes/NMA_API.php View File

@@ -1,256 +0,0 @@
1
-<?php
2
-
3
-class NMA_API
4
-{
5
-
6
-    /**
7
-     * @const LIB_ERROR_TYPE can be exception or error
8
-     */
9
-    const LIB_ERROR_TYPE = 'error';
10
-
11
-    /**
12
-     * @const holds the api key verify url
13
-     */
14
-    const LIB_NMA_VERIFY = 'https://www.notifymyandroid.com/publicapi/verify';
15
-
16
-    /**
17
-     * @const holds the notify url
18
-     */
19
-    const LIB_NMA_NOTIFY = 'https://www.notifymyandroid.com/publicapi/notify';
20
-
21
-    /**
22
-     * toggles on debugging
23
-     *
24
-     * @var bool
25
-     */
26
-    public $debug = false;
27
-
28
-    public $apiCallsRemaining = false;
29
-
30
-    public $apiLimitReset = false;
31
-
32
-    public $lastStatus = false;
33
-    /**
34
-     * @var bool|string
35
-     */
36
-    protected $apiKey = false;
37
-
38
-    /**
39
-     * @var bool|string
40
-     */
41
-    protected $devKey = false;
42
-
43
-
44
-    protected $error_codes
45
-        = array(
46
-            200     => 'Notification submitted.',
47
-            400     => 'The data supplied is in the wrong format, invalid length or null.',
48
-            401     => 'None of the API keys provided were valid.',
49
-            402     => 'Maximum number of API calls per hour exceeded.',
50
-            500     => 'Internal server error. Please contact our support if the problem persists.'
51
-        );
52
-
53
-    /**
54
-     * @param array $options
55
-     */
56
-    function __construct($options = [])
57
-    {
58
-        if (!isset($options['apikey'])) {
59
-            return $this->error('You must supply a API Key');
60
-        } else {
61
-            $this->apiKey = $options['apikey'];
62
-        }
63
-
64
-        if (isset($options['developerkey'])) {
65
-            $this->devKey = $options['developerkey'];
66
-        }
67
-
68
-        if (isset($options['debug'])) {
69
-            $this->debug = true;
70
-        }
71
-
72
-        return true; // this shuts my ide up
73
-
74
-    }
75
-
76
-
77
-    /**
78
-     * @param bool $key [optional] if not set the one used on construct is used
79
-     *
80
-     * @return bool|mixed|SimpleXMLElement|string
81
-     */
82
-    public function verify($key = false)
83
-    {
84
-
85
-        $options = [];
86
-
87
-        if ($key !== false) {
88
-            $options['apikey'] = $key;
89
-        } else {
90
-            $options['apikey'] = $this->apiKey;
91
-        }
92
-
93
-
94
-        if ($this->devKey) {
95
-            $options['developerkey'] = $this->devKey;
96
-        }
97
-
98
-        return $this->makeApiCall(self::LIB_NMA_VERIFY, $options);
99
-    }
100
-
101
-    /**
102
-     * @param string $application
103
-     * @param string $event
104
-     * @param string $description
105
-     * @param string $url
106
-     * @param int    $priority
107
-     * @param bool   $apiKeys
108
-     *
109
-     * @return bool|mixed|SimpleXMLElement|string
110
-     */
111
-    public function notify($application = '', $event = '', $description = '', $url = '', $priority = 0, $apiKeys = false)
112
-    {
113
-        if (empty($application) || empty($event) || empty($description)) {
114
-            return $this->error('you must supply a application name, event and long desc');
115
-        }
116
-
117
-        $post = array('application' => substr($application, 0, 256),
118
-                      'event'       => substr($event, 0, 1000),
119
-                      'description' => substr($description, 0, 10000),
120
-                      'priority'    => $priority
121
-        );
122
-    if (!empty($url)) {
123
-      $post['url'] = substr($url, 0, 2000);
124
-    }
125
-        if ($this->devKey) {
126
-            $post['developerkey'] = $this->devKey;
127
-        }
128
-
129
-        if ($apiKeys !== false) {
130
-            $post['apikey'] = $apiKeys;
131
-        } else {
132
-            $post['apikey'] = $this->apiKey;
133
-        }
134
-
135
-        return $this->makeApiCall(self::LIB_NMA_NOTIFY, $post, 'POST');
136
-    }
137
-
138
-
139
-    /**
140
-     * @param        $url
141
-     * @param null   $params
142
-     * @param string $verb
143
-     * @param string $format
144
-     *
145
-     * @return bool|mixed|SimpleXMLElement|string
146
-     * @throws Exception
147
-     */
148
-    protected function makeApiCall($url, $params = null, $verb = 'GET', $format = 'xml')
149
-    {
150
-        $cparams = array(
151
-            'http' => array(
152
-                'method'        => $verb,
153
-                'ignore_errors' => true
154
-            )
155
-        );
156
-        if ($params !== null && !empty($params)) {
157
-            $params = http_build_query($params);
158
-            if ($verb == 'POST') {
159
-                $cparams["http"]['header'] = 'Content-Type: application/x-www-form-urlencoded';
160
-                $cparams['http']['content'] = $params;
161
-            } else {
162
-                $url .= '?' . $params;
163
-            }
164
-        } else {
165
-            return $this->error(
166
-                'this api requires all calls to have params' . $this->debug ? ', you provided: ' . var_dump($params)
167
-                    : ''
168
-            );
169
-        }
170
-
171
-        $context = stream_context_create($cparams);
172
-        $fp = fopen($url, 'rb', false, $context);
173
-        if (!$fp) {
174
-            $res = false;
175
-        } else {
176
-
177
-            if ($this->debug) {
178
-                $meta = stream_get_meta_data($fp);
179
-                $this->error('var dump of http headers' . var_dump($meta['wrapper_data']));
180
-            }
181
-
182
-            $res = stream_get_contents($fp);
183
-        }
184
-
185
-        if ($res === false) {
186
-            return $this->error("$verb $url failed: $php_errormsg");
187
-        }
188
-
189
-        switch ($format) {
190
-            case 'json':
191
-                return $this->error('this api does not support json');
192
-            /*
193
-            * uncomment the below if json is added later
194
-            * $r = json_decode($res);
195
-           if ($r === null) {
196
-               return $this->error("failed to decode $res as json");
197
-           }
198
-           return $r;*/
199
-
200
-            case 'xml':
201
-                $r = simplexml_load_string($res);
202
-                if ($r === null) {
203
-                    return $this->error("failed to decode $res as xml");
204
-                }
205
-                return $this->process_xml_return($r);
206
-        }
207
-        return $res;
208
-    }
209
-
210
-    /**
211
-     * @param     $message
212
-     * @param int $type
213
-     *
214
-     * @return bool
215
-     * @throws Exception
216
-     */
217
-    private function error($message, $type = E_USER_NOTICE)
218
-    {
219
-        if (self::LIB_ERROR_TYPE == 'error') {
220
-            trigger_error($message, $type);
221
-            return false;
222
-        } else {
223
-            throw new Exception($message, $type);
224
-        }
225
-    }
226
-
227
-    /**
228
-     * @param SimpleXMLElement $obj
229
-     *
230
-     * @return bool
231
-     */
232
-    private function process_xml_return(SimpleXMLElement $obj)
233
-    {
234
-
235
-        if (isset($obj->success)) {
236
-            $this->lastStatus = $obj->success["@attributes"]['code'];
237
-
238
-            $this->apiCallsRemaining = $obj->success["@attributes"]['remaining'];
239
-            $this->apiLimitReset = $obj->success["@attributes"]['resettimer'];
240
-            return true;
241
-        } elseif (isset($obj->error)) {
242
-            if (isset($obj->error["@attributes"])) {
243
-                $this->lastStatus = $obj->error["@attributes"]['code'];
244
-
245
-                if (isset($obj->error["@attributes"]['resettimer'])) {
246
-                    $this->apiLimitReset = $obj->error["@attributes"]['resettimer'];
247
-                }
248
-
249
-            }
250
-            return $this->error($obj->error);
251
-        } else {
252
-            return $this->error("unkown error");
253
-        }
254
-    }
255
-
256
-}

+ 0
- 2
classes/misc.class.php View File

@@ -137,8 +137,6 @@ class Misc {
137 137
           AND InInbox = '1'");
138 138
       list($UnRead) = G::$DB->next_record();
139 139
       G::$Cache->cache_value("inbox_new_$ID", $UnRead);
140
-
141
-      NotificationsManager::send_push($ID, "Message from $SenderName, Subject: $UnescapedSubject", $UnescapedBody, site_url() . 'inbox.php', NotificationsManager::INBOX);
142 140
     }
143 141
 
144 142
     G::$DB->set_query_id($QueryID);

+ 7
- 129
classes/notificationsmanager.class.php View File

@@ -5,9 +5,6 @@ class NotificationsManager {
5 5
   const OPT_DISABLED = 0;
6 6
   const OPT_POPUP = 1;
7 7
   const OPT_TRADITIONAL = 2;
8
-  const OPT_PUSH = 3;
9
-  const OPT_POPUP_PUSH = 4;
10
-  const OPT_TRADITIONAL_PUSH = 5;
11 8
 
12 9
   // Importances
13 10
   const IMPORTANT = 'information';
@@ -628,10 +625,8 @@ class NotificationsManager {
628 625
       $QueryID = G::$DB->get_query_id();
629 626
       G::$DB->query("
630 627
         SELECT *
631
-        FROM users_notifications_settings AS n
632
-        LEFT JOIN users_push_notifications AS p
633
-        ON p.UserID = n.UserID
634
-        WHERE n.UserID = '$UserID'");
628
+        FROM users_notifications_settings
629
+        WHERE UserID = ?", $UserID);
635 630
       $Results = G::$DB->next_record(MYSQLI_ASSOC, false);
636 631
       G::$DB->set_query_id($QueryID);
637 632
       G::$Cache->cache_value("users_notifications_settings_$UserID", $Results, 0);
@@ -648,14 +643,11 @@ class NotificationsManager {
648 643
     foreach (self::$Types as $Type) {
649 644
       $Popup = array_key_exists("notifications_{$Type}_popup", $Settings);
650 645
       $Traditional = array_key_exists("notifications_{$Type}_traditional", $Settings);
651
-      $Push = array_key_exists("notifications_{$Type}_push", $Settings);
652 646
       $Result = self::OPT_DISABLED;
653 647
       if ($Popup) {
654
-        $Result = $Push ? self::OPT_POPUP_PUSH : self::OPT_POPUP;
648
+        $Result = self::OPT_POPUP;
655 649
       } elseif ($Traditional) {
656
-        $Result = $Push ? self::OPT_TRADITIONAL_PUSH : self::OPT_TRADITIONAL;
657
-      } elseif ($Push) {
658
-        $Result = self::OPT_PUSH;
650
+        $Result = self::OPT_TRADITIONAL;
659 651
       }
660 652
       $Update[] = "$Type = $Result";
661 653
     }
@@ -665,34 +657,14 @@ class NotificationsManager {
665 657
     G::$DB->query("
666 658
       UPDATE users_notifications_settings
667 659
       SET $Update
668
-      WHERE UserID = '$UserID'");
669
-
670
-    $PushService = (int) $_POST['pushservice'];
671
-    $PushOptionsArray = array("PushKey" => $_POST['pushkey']);
672
-    if ($PushService === 6) { //pushbullet
673
-      $PushOptionsArray['PushDevice'] = $_POST['pushdevice'];
674
-    }
675
-    $PushOptions = db_string(serialize($PushOptionsArray));
676
-
677
-    if ($PushService != 0) {
678
-      G::$DB->query("
679
-          INSERT INTO users_push_notifications
680
-            (UserID, PushService, PushOptions)
681
-          VALUES
682
-            ('$UserID', '$PushService', '$PushOptions')
683
-          ON DUPLICATE KEY UPDATE
684
-            PushService = '$PushService',
685
-            PushOptions = '$PushOptions'");
686
-    } else {
687
-      G::$DB->query("UPDATE users_push_notifications SET PushService = 0 WHERE UserID = '$UserID'");
688
-    }
660
+      WHERE UserID = ?", $UserID);
689 661
 
690 662
     G::$DB->set_query_id($QueryID);
691 663
     G::$Cache->delete_value("users_notifications_settings_$UserID");
692 664
   }
693 665
 
694 666
   public function is_traditional($Type) {
695
-    return $this->Settings[$Type] == self::OPT_TRADITIONAL || $this->Settings[$Type] == self::OPT_TRADITIONAL_PUSH;
667
+    return $this->Settings[$Type] == self::OPT_TRADITIONAL;
696 668
   }
697 669
 
698 670
   public function is_skipped($Type) {
@@ -700,101 +672,7 @@ class NotificationsManager {
700 672
   }
701 673
 
702 674
   public function use_noty() {
703
-    return in_array(self::OPT_POPUP, $this->Settings) || in_array(self::OPT_POPUP_PUSH, $this->Settings);
704
-  }
705
-
706
-  /**
707
-   * Send a push notification to a user
708
-   *
709
-   * @param array $UserIDs integer or array of integers of UserIDs to push
710
-   * @param string $Title the title to be displayed in the push
711
-   * @param string $Body the body of the push
712
-   * @param string $URL url for the push notification to contain
713
-   * @param string $Type what sort of push is it? PM, Rippy, News, etc
714
-   */
715
-  public static function send_push($UserIDs, $Title, $Body, $URL = '', $Type = self::GLOBALNOTICE) {
716
-    if (!is_array($UserIDs)) {
717
-      $UserIDs = array($UserIDs);
718
-    }
719
-    foreach($UserIDs as $UserID) {
720
-      $UserID = (int) $UserID;
721
-      $QueryID = G::$DB->get_query_id();
722
-      $SQL = "
723
-        SELECT
724
-          p.PushService, p.PushOptions
725
-        FROM users_notifications_settings AS n
726
-          JOIN users_push_notifications AS p ON n.UserID = p.UserID
727
-        WHERE n.UserID = '$UserID'
728
-        AND p.PushService != 0";
729
-      if ($Type != self::GLOBALNOTICE) {
730
-        $SQL .= " AND n.$Type IN (" . self::OPT_PUSH . "," . self::OPT_POPUP_PUSH . "," . self::OPT_TRADITIONAL_PUSH . ")";
731
-      }
732
-      G::$DB->query($SQL);
733
-
734
-      if (G::$DB->has_results()) {
735
-        list($PushService, $PushOptions) = G::$DB->next_record(MYSQLI_NUM, false);
736
-        $PushOptions = unserialize($PushOptions);
737
-        switch ($PushService) {
738
-          case '1':
739
-            $Service = "NMA";
740
-            break;
741
-          case '2':
742
-            $Service = "Prowl";
743
-            break;
744
-          // Case 3 is missing because notifo is dead.
745
-          case '4':
746
-            $Service = "Toasty";
747
-            break;
748
-          case '5':
749
-            $Service = "Pushover";
750
-            break;
751
-          case '6':
752
-            $Service = "PushBullet";
753
-            break;
754
-          default:
755
-            break;
756
-          }
757
-          if (!empty($Service) && !empty($PushOptions['PushKey'])) {
758
-            $Options = array("service" => strtolower($Service),
759
-                    "user" => array("key" => $PushOptions['PushKey']),
760
-                    "message" => array("title" => $Title, "body" => $Body, "url" => $URL));
761
-
762
-            if ($Service === 'PushBullet') {
763
-              $Options["user"]["device"] = $PushOptions['PushDevice'];
764
-
765
-            }
766
-
767
-            $JSON = json_encode($Options);
768
-            G::$DB->query("
769
-              INSERT INTO push_notifications_usage
770
-                (PushService, TimesUsed)
771
-              VALUES
772
-                ('$Service', 1)
773
-              ON DUPLICATE KEY UPDATE
774
-                TimesUsed = TimesUsed + 1");
775
-
776
-            $PushServerSocket = fsockopen("127.0.0.1", 6789);
777
-            fwrite($PushServerSocket, $JSON);
778
-            fclose($PushServerSocket);
779
-          }
780
-      }
781
-      G::$DB->set_query_id($QueryID);
782
-    }
675
+    return in_array(self::OPT_POPUP, $this->Settings);
783 676
   }
784 677
 
785
-  /**
786
-   * Gets users who have push notifications enabled
787
-   *
788
-   */
789
-  public static function get_push_enabled_users() {
790
-    $QueryID = G::$DB->get_query_id();
791
-    G::$DB->query("
792
-      SELECT UserID
793
-      FROM users_push_notifications
794
-      WHERE PushService != 0
795
-        AND UserID != '" . G::$LoggedUser['ID']. "'");
796
-    $PushUsers = G::$DB->collect("UserID");
797
-    G::$DB->set_query_id($QueryID);
798
-    return $PushUsers;
799
-  }
800 678
 }

+ 3
- 45
classes/notificationsmanagerview.class.php View File

@@ -17,43 +17,8 @@ class NotificationsManagerView {
17 17
     }
18 18
   }
19 19
 
20
-  private static function render_push_settings() {
21
-    $PushService = self::$Settings['PushService'];
22
-    $PushOptions = unserialize(self::$Settings['PushOptions']);
23
-    if (empty($PushOptions['PushDevice'])) {
24
-      $PushOptions['PushDevice'] = '';
25
-    }
26
-    ?>
27
-    <tr>
28
-      <td class="label"><strong>Push notifications</strong></td>
29
-      <td>
30
-        <select name="pushservice" id="pushservice">
31
-          <option value="0"<? if (empty($PushService)) { ?> selected="selected"<? } ?>>Disable push notifications</option>
32
-          <option value="1"<? if ($PushService == 1) { ?> selected="selected"<? } ?>>Notify My Android</option>
33
-          <option value="2"<? if ($PushService == 2) { ?> selected="selected"<? } ?>>Prowl</option>
34
-<!--            No option 3, notifo died. -->
35
-          <option value="4"<? if ($PushService == 4) { ?> selected="selected"<? } ?>>Super Toasty</option>
36
-          <option value="5"<? if ($PushService == 5) { ?> selected="selected"<? } ?>>Pushover</option>
37
-          <option value="6"<? if ($PushService == 6) { ?> selected="selected"<? } ?>>PushBullet</option>
38
-        </select>
39
-        <div id="pushsettings" style="display: none;">
40
-          <label id="pushservice_title" for="pushkey">API key</label>
41
-          <input type="text" size="50" name="pushkey" id="pushkey" value="<?=display_str($PushOptions['PushKey'])?>" />
42
-          <label class="pushdeviceid" id="pushservice_device" for="pushdevice">Device ID</label>
43
-          <select class="pushdeviceid" name="pushdevice" id="pushdevice">
44
-            <option value="<?= display_str($PushOptions['PushDevice'])?>" selected="selected"><?= display_str($PushOptions['PushDevice'])?></option>
45
-          </select>
46
-          <br />
47
-          <a href="user.php?action=take_push&amp;push=1&amp;userid=<?=G::$LoggedUser['ID']?>&amp;auth=<?=G::$LoggedUser['AuthKey']?>" class="brackets">Test push</a>
48
-          <a href="wiki.php?action=article&amp;id=1017" class="brackets">View wiki guide</a>
49
-        </div>
50
-      </td>
51
-    </tr>
52
-<?  }
53
-
54 20
   public static function render_settings($Settings) {
55 21
     self::$Settings = $Settings;
56
-    self::render_push_settings();
57 22
 ?>
58 23
     <tr>
59 24
       <td class="label">
@@ -124,11 +89,10 @@ class NotificationsManagerView {
124 89
     </tr>
125 90
 <?  }
126 91
 
127
-  private static function render_checkbox($Name, $Traditional = false, $Push = true) {
92
+  private static function render_checkbox($Name, $Traditional = false) {
128 93
     $Checked = self::$Settings[$Name];
129
-    $PopupChecked = $Checked == NotificationsManager::OPT_POPUP || $Checked == NotificationsManager::OPT_POPUP_PUSH || !isset($Checked) ? ' checked="checked"' : '';
130
-    $TraditionalChecked = $Checked == NotificationsManager::OPT_TRADITIONAL || $Checked == NotificationsManager::OPT_TRADITIONAL_PUSH ? ' checked="checked"' : '';
131
-    $PushChecked = $Checked == NotificationsManager::OPT_TRADITIONAL_PUSH || $Checked == NotificationsManager::OPT_POPUP_PUSH || $Checked == NotificationsManager::OPT_PUSH ? ' checked="checked"' : '';
94
+    $PopupChecked = $Checked == NotificationsManager::OPT_POPUP || !isset($Checked) ? ' checked="checked"' : '';
95
+    $TraditionalChecked = $Checked == NotificationsManager::OPT_TRADITIONAL ? ' checked="checked"' : '';
132 96
 
133 97
 ?>
134 98
     <label>
@@ -140,12 +104,6 @@ class NotificationsManagerView {
140 104
       <input type="checkbox" name="notifications_<?=$Name?>_traditional" id="notifications_<?=$Name?>_traditional"<?=$TraditionalChecked?> />
141 105
       Traditional
142 106
     </label>
143
-<?    }
144
-    if ($Push) { ?>
145
-    <label>
146
-      <input type="checkbox" name="notifications_<?=$Name?>_push" id="notifications_<?=$Name?>_push"<?=$PushChecked?> />
147
-      Push
148
-    </label>
149 107
 <?    }
150 108
   }
151 109
 

+ 0
- 184
classes/pushserver.class.php View File

@@ -1,184 +0,0 @@
1
-<?php
2
-define("PUSH_SOCKET_LISTEN_ADDRESS", "127.0.0.1");
3
-define("PUSH_SOCKET_LISTEN_PORT", 6789);
4
-
5
-require 'NMA_API.php';
6
-require 'config.php';
7
-class PushServer {
8
-  private $ListenSocket = false;
9
-  private $State = 1;
10
-  private $Listened = false;
11
-
12
-  public function __construct() {
13
-    // restore_error_handler(); //Avoid PHP error logging
14
-    set_time_limit(0);
15
-    $this->init();
16
-    $this->listen();
17
-  }
18
-
19
-  private function init() {
20
-    $this->ListenSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
21
-    socket_set_option($this->ListenSocket, SOL_SOCKET, SO_REUSEADDR, 1);
22
-    socket_bind($this->ListenSocket, PUSH_SOCKET_LISTEN_ADDRESS, PUSH_SOCKET_LISTEN_PORT);
23
-    socket_listen($this->ListenSocket);
24
-    socket_set_nonblock($this->ListenSocket);
25
-    echo "\nInitialized\n";
26
-  }
27
-
28
-  private function listen() {
29
-    echo "\nListening...\n";
30
-    while ( ($this->State) == 1 ) {
31
-      if ($this->Listened = @socket_accept($this->ListenSocket)) {
32
-        $Data = socket_read($this->Listened, 512);
33
-        $this->parse_data($Data);
34
-      }
35
-      usleep(5000);
36
-    }
37
-  }
38
-
39
-  private function parse_data($Data) {
40
-    $JSON = json_decode($Data, true);
41
-    $Service = strtolower($JSON['service']);
42
-    switch ($Service) {
43
-      case 'nma':
44
-        $this->push_nma($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
45
-        break;
46
-      case 'prowl':
47
-        $this->push_prowl($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
48
-        break;
49
-      case 'toasty':
50
-        $this->push_toasty($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
51
-        break;
52
-      case 'pushover':
53
-        $this->push_pushover($JSON['user']['key'], $JSON['message']['title'], $JSON['message']['body'], $JSON['message']['url']);
54
-        break;
55
-      case 'pushbullet':
56
-        $this->push_pushbullet(
57
-          $JSON['user']['key'],
58
-          $JSON['user']['device'],
59
-          $JSON['message']['title'],
60
-          $JSON['message']['body'],
61
-          $JSON['message']['url']
62
-        );
63
-      default:
64
-        break;
65
-    }
66
-  }
67
-
68
-  private function push_prowl($Key, $Title, $Message, $URL) {
69
-    $API = "https://api.prowlapp.com/publicapi/add";
70
-    $Fields = array(
71
-        'apikey' => urlencode($Key),
72
-        'application' => urlencode(SITE_NAME),
73
-        'event' => urlencode($Title),
74
-        'description' => urlencode($Message)
75
-    );
76
-    if (!empty($URL)) {
77
-      $Fields['url'] = $URL;
78
-    }
79
-    $FieldsString = "";
80
-    foreach ($Fields as $key => $value) {
81
-      $FieldsString .= $key . '=' . $value . '&';
82
-    }
83
-    rtrim($FieldsString, '&');
84
-
85
-    $Curl = curl_init();
86
-    curl_setopt($Curl, CURLOPT_URL, $API);
87
-    curl_setopt($Curl, CURLOPT_POST, count($Fields));
88
-    curl_setopt($Curl, CURLOPT_POSTFIELDS, $FieldsString);
89
-    curl_exec($Curl);
90
-    curl_close($Curl);
91
-    echo "Push sent to Prowl";
92
-  }
93
-
94
-  private function push_toasty($Key, $Title, $Message, $URL) {
95
-    $API = "http://api.supertoasty.com/notify/" . urlencode($Key) . "?";
96
-    if (!empty($URL)) {
97
-      $Message = $Message . " " . $URL;
98
-    }
99
-    $Fields = array(
100
-        'title' => urlencode($Title),
101
-        'text' => urlencode($Message),
102
-        'sender' => urlencode(SITE_NAME)
103
-    );
104
-    $FieldsString = "";
105
-    foreach ($Fields as $key => $value) {
106
-      $FieldsString .= $key . '=' . $value . '&';
107
-    }
108
-    rtrim($FieldsString, '&');
109
-
110
-    $Curl = curl_init();
111
-    curl_setopt($Curl, CURLOPT_URL, $API);
112
-    curl_setopt($Curl, CURLOPT_POST, count($Fields));
113
-    curl_setopt($Curl, CURLOPT_POSTFIELDS, $FieldsString);
114
-    curl_exec($Curl);
115
-    curl_close($Curl);
116
-    echo "Push sent to Toasty";
117
-  }
118
-
119
-  private function push_nma($Key, $Title, $Message, $URL) {
120
-    $NMA = new NMA_API(array(
121
-        'apikey' => $Key
122
-    ));
123
-    if ($NMA->verify()) {
124
-      if ($NMA->notify(SITE_NAME, $Title, $Message, $URL)) {
125
-        echo "Push sent to NMA";
126
-      }
127
-    }
128
-  }
129
-
130
-  private function push_pushover($UserKey, $Title, $Message, $URL) {
131
-    curl_setopt_array($ch = curl_init(), array(
132
-        CURLOPT_URL => "https://api.pushover.net/1/messages.json",
133
-        CURLOPT_POSTFIELDS => array(
134
-            "token" => PUSHOVER_KEY,
135
-            "user" => $UserKey,
136
-            "title" => $Title,
137
-            "message" => $Message,
138
-            "url" => $URL
139
-        )
140
-    ));
141
-    curl_exec($ch);
142
-    curl_close($ch);
143
-    echo "Push sent to Pushover";
144
-  }
145
-
146
-  /**
147
-   * Notify via pushbullet
148
-   *
149
-   * @param $UserKey User API key
150
-   * @param $DeviceID device to push to
151
-   * @param $Title Notification title
152
-   * @param $Message Notification message
153
-   * @param $URL For compatibility with other command. Just gets appended.
154
-   */
155
-  private function push_pushbullet($UserKey, $DeviceID,
156
-    $Title, $Message, $URL) {
157
-    if (!empty($URL)) {
158
-      $Message .= ' ' . $URL;
159
-    }
160
-
161
-    curl_setopt_array($Curl = curl_init(), array(
162
-      CURLOPT_URL => 'https://api.pushbullet.com/api/pushes',
163
-      CURLOPT_POSTFIELDS => array(
164
-        'type' => 'note',
165
-        'title' => $Title,
166
-        'body' => $Message,
167
-        'device_iden' => $DeviceID
168
-      ),
169
-      CURLOPT_USERPWD => $UserKey . ':',
170
-      CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
171
-      CURLOPT_RETURNTRANSFER => True
172
-    ));
173
-
174
-    $Result = curl_exec($Curl);
175
-    echo "Push sent to Pushbullet";
176
-    curl_close($Curl);
177
-
178
-
179
-
180
-  }
181
-}
182
-
183
-$PushServer = new PushServer();
184
-?>

+ 2
- 2
classes/subscriptions.class.php View File

@@ -57,14 +57,14 @@ class Subscriptions {
57 57
         INSERT IGNORE INTO users_notify_quoted
58 58
           (UserID, QuoterID, Page, PageID, PostID, Date)
59 59
         VALUES
60
-          ('$UserID', '$QuoterID', '$Page', '$PageID', '$PostID', NOW())");
60
+          (    ?,               ?,               ?,      ?,       ?,   NOW())",
61
+          $Result['ID'], G::$LoggedUser['ID'], $Page, $PageID, $PostID);
61 62
       G::$Cache->delete_value("notify_quoted_$UserID");
62 63
       if ($Page == 'forums') {
63 64
         $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
64 65
       } else {
65 66
         $URL = site_url() . "comments.php?action=jump&postid=$PostID";
66 67
       }
67
-      NotificationsManager::send_push($UserID, 'New Quote!', 'Quoted by ' . G::$LoggedUser['Username'] . " $URL", $URL, NotificationsManager::QUOTES);
68 68
     }
69 69
     G::$DB->set_query_id($QueryID);
70 70
   }

+ 0
- 13
gazelle.sql View File

@@ -640,12 +640,6 @@ CREATE TABLE `pm_messages` (
640 640
   KEY `ConvID` (`ConvID`)
641 641
 ) ENGINE=InnoDB CHARSET=utf8;
642 642
 
643
-CREATE TABLE `push_notifications_usage` (
644
-  `PushService` varchar(10) NOT NULL,
645
-  `TimesUsed` int(10) NOT NULL DEFAULT '0',
646
-  PRIMARY KEY (`PushService`)
647
-) ENGINE=InnoDB CHARSET=utf8;
648
-
649 643
 CREATE TABLE `reports` (
650 644
   `ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
651 645
   `UserID` int(10) unsigned NOT NULL DEFAULT '0',
@@ -1593,13 +1587,6 @@ CREATE TABLE `users_points_requests` (
1593 1587
   KEY `RequestID` (`RequestID`)
1594 1588
 ) ENGINE=InnoDB CHARSET=utf8;
1595 1589
 
1596
-CREATE TABLE `users_push_notifications` (
1597
-  `UserID` int(10) NOT NULL,
1598
-  `PushService` tinyint(1) NOT NULL DEFAULT '0',
1599
-  `PushOptions` text,
1600
-  PRIMARY KEY (`UserID`)
1601
-) ENGINE=InnoDB CHARSET=utf8;
1602
-
1603 1590
 CREATE TABLE `users_seedtime` (
1604 1591
   `UserID` int(10) unsigned NOT NULL,
1605 1592
   `TorrentID` int(10) unsigned NOT NULL,

+ 0
- 3
sections/ajax/index.php View File

@@ -153,9 +153,6 @@ switch ($_GET['action']) {
153 153
   case 'clear_user_notification':
154 154
     require(SERVER_ROOT . '/sections/ajax/clear_user_notification.php');
155 155
     break;
156
-  case 'pushbullet_devices':
157
-    require(SERVER_ROOT . '/sections/ajax/pushbullet_devices.php');
158
-    break;
159 156
   case 'anidb':
160 157
     require(SERVER_ROOT . '/sections/ajax/anidb.php');
161 158
     break;

+ 0
- 21
sections/ajax/pushbullet_devices.php View File

@@ -1,21 +0,0 @@
1
-<?php
2
-
3
-
4
-if (!isset($_GET['apikey']) || empty($_GET['apikey'])) {
5
-  echo '{"error": { "message": "No API Key specified" }}';
6
-  die();
7
-}
8
-
9
-$ApiKey = $_GET['apikey'];
10
-
11
-
12
-curl_setopt_array($Ch = curl_init(), array(
13
-  CURLOPT_URL => 'https://api.pushbullet.com/api/devices',
14
-  CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
15
-  CURLOPT_RETURNTRANSFER => true,
16
-  CURLOPT_USERPWD => $ApiKey . ':'
17
-));
18
-
19
-$Result = curl_exec($Ch);
20
-curl_close($Ch);
21
-echo json_encode($Result);

+ 0
- 1
sections/blog/index.php View File

@@ -101,7 +101,6 @@ if (check_perms('admin_manage_blog')) {
101 101
             VALUES ('$LoggedUser[ID]', $ThreadID)");
102 102
           $Cache->delete_value('subscriptions_user_'.$LoggedUser['ID']);
103 103
         }
104
-        NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::BLOG);
105 104
 
106 105
         header('Location: blog.php');
107 106
         break;

+ 0
- 2
sections/tools/index.php View File

@@ -178,8 +178,6 @@ switch ($_REQUEST['action']) {
178 178
     $Cache->delete_value('news_latest_title');
179 179
     $Cache->delete_value('news');
180 180
 
181
-    NotificationsManager::send_push(NotificationsManager::get_push_enabled_users(), $_POST['title'], $_POST['body'], site_url() . 'index.php', NotificationsManager::NEWS);
182
-
183 181
     header('Location: index.php');
184 182
     break;
185 183
 

+ 0
- 11
sections/user/take_push.php View File

@@ -1,11 +0,0 @@
1
-<?
2
-authorize();
3
-if (!check_perms('users_mod') && $_GET['userid'] != $LoggedUser['ID']) {
4
-  error(403);
5
-}
6
-
7
-$UserID = db_string($_GET['userid']);
8
-NotificationsManager::send_push($UserID, 'Push!', 'You\'ve been pushed by ' . $LoggedUser['Username']);
9
-
10
-header('Location: user.php?action=edit&userid=' . $UserID . "");
11
-?>

+ 0
- 86
static/functions/user_settings.js View File

@@ -1,7 +1,3 @@
1
-var PUSHOVER = 5;
2
-var TOASTY = 4;
3
-var PUSHBULLET = 6;
4
-
5 1
 $(document).ready(function() {
6 2
   var top = $('#settings_sections').offset().top - parseFloat($('#settings_sections').css('marginTop').replace(/auto/, 0));
7 3
   $(window).scroll(function (event) {
@@ -58,91 +54,9 @@ $(document).ready(function() {
58 54
   $("#notifications_Torrents_popup").click(function() {
59 55
     $("#notifications_Torrents_traditional").prop('checked', false);
60 56
   });
61
-
62
-  if ($("#pushservice").val() > 0) {
63
-    $('.pushdeviceid').hide();
64
-    $('#pushsettings').show();
65
-    if ($('#pushservice').val() == PUSHBULLET) {
66
-      fetchPushbulletDevices($('#pushkey').val());
67
-      $('.pushdeviceid').show();
68
-    }
69
-  }
70
-
71
-  $("#pushservice").change(function() {
72
-    if ($(this).val() > 0) {
73
-      $('#pushsettings').show(500);
74
-
75
-      if ($(this).val() == TOASTY) {
76
-        $('#pushservice_title').text("Device ID");
77
-      } else if ($(this).val() == PUSHOVER) {
78
-        $('#pushservice_title').text("User Key");
79
-      } else {
80
-        $('#pushservice_title').text("API Key");
81
-      }
82
-    } else {
83
-      $('#pushsettings').hide(500);
84
-    }
85
-
86
-    if ($(this).val() == PUSHBULLET) {
87
-      fetchPushbulletDevices($('#pushkey').val());
88
-      $('.pushdeviceid').show(500);
89
-    } else {
90
-      $('.pushdeviceid').hide(500);
91
-    }
92
-  });
93
-
94
-  $("#pushkey").blur(function() {
95
-    if($("#pushservice").val() == PUSHBULLET) {
96
-      fetchPushbulletDevices($(this).val());
97
-    }
98
-  });
99 57
 });
100 58
 
101 59
 function fuzzyMatch(str, pattern){
102 60
   pattern = pattern.split("").reduce(function(a,b){ return a+".*"+b; });
103 61
   return new RegExp(pattern).test(str);
104 62
 };
105
-
106
-/**
107
- * Gets device IDs from the pushbullet API
108
- *
109
- * @return array of dictionaries with devices
110
- */
111
-function fetchPushbulletDevices(apikey) {
112
-  $.ajax({
113
-    url: 'ajax.php',
114
-    data: {
115
-      "action": 'pushbullet_devices',
116
-      "apikey": apikey
117
-    },
118
-    type: 'GET',
119
-    success: function(data, textStatus, xhr) {
120
-      var data = jQuery.parseJSON(data);
121
-      var field = $('#pushdevice');
122
-      var value = field.val();
123
-      if (data.error || textStatus !== 'success' ) {
124
-        if (data.error) {
125
-          field.html('<option>' + data.error.message + '</option>');
126
-        } else {
127
-          $('#pushdevice').html('<option>No devices fetched</option>');
128
-        }
129
-      } else {
130
-        if(data['devices'].length > 0) {
131
-          field.html('');
132
-        }
133
-        for (var i = 0; i < data['devices'].length; i++) {
134
-          var model = data['devices'][i]['extras']['model'];
135
-          var nickname = data['devices'][i]['extras']['nickname'];
136
-          var name = nickname !== undefined ? nickname : model;
137
-          var option = new Option(name, data['devices'][i]['iden']);
138
-
139
-          option.selected = (option.value == value);
140
-          field[0].add(option);
141
-        }
142
-      }
143
-    },
144
-    error: function(data,textStatus,xhr) {
145
-      $('#pushdevice').html('<option>' + textStatus + '</option>');
146
-    }
147
-  });
148
-}

Loading…
Cancel
Save