Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
287e6318ce
5 changed files with 434 additions and 415 deletions
  1. 31
    24
      classes/imagetools.class.php
  2. 26
    26
      classes/inbox.class.php
  3. 185
    190
      classes/invite_tree.class.php
  4. 191
    173
      classes/irc.class.php
  5. 1
    2
      classes/lockedaccounts.class.php

+ 31
- 24
classes/imagetools.class.php View File

@@ -4,7 +4,8 @@
4 4
  * ImageTools Class
5 5
  * Thumbnail aide, mostly
6 6
  */
7
-class ImageTools {
7
+class ImageTools
8
+{
8 9
 
9 10
   /**
10 11
    * Determine the image URL. This takes care of the image proxy and thumbnailing.
@@ -12,31 +13,37 @@ class ImageTools {
12 13
    * @param string $Thumb image proxy scale profile to use
13 14
    * @return string
14 15
    */
15
-  public static function process($Url = '', $Thumb = false) {
16
-    if (!$Url) return '';
17
-    if (preg_match('/^https:\/\/('.SITE_DOMAIN.'|'.IMAGE_DOMAIN.')\//', $Url) || $Url[0]=='/') {
18
-      if (strpos($Url, '?') === false) $Url .= '?';
19
-      return $Url;
20
-    } else {
21
-      return 'https://'.IMAGE_DOMAIN.($Thumb?"/$Thumb/":'/').'?h='.rawurlencode(base64_encode(hash_hmac('sha256', $Url, IMAGE_PSK, true))).'&i='.urlencode($Url);
16
+    public static function process($Url = '', $Thumb = false)
17
+    {
18
+        if (!$Url) {
19
+            return '';
20
+        }
21
+        if (preg_match('/^https:\/\/('.SITE_DOMAIN.'|'.IMAGE_DOMAIN.')\//', $Url) || $Url[0]=='/') {
22
+            if (strpos($Url, '?') === false) {
23
+                $Url .= '?';
24
+            }
25
+            return $Url;
26
+        } else {
27
+            return 'https://'.IMAGE_DOMAIN.($Thumb?"/$Thumb/":'/').'?h='.rawurlencode(base64_encode(hash_hmac('sha256', $Url, IMAGE_PSK, true))).'&i='.urlencode($Url);
28
+        }
22 29
     }
23
-  }
24 30
 
25
-  /**
26
-   * Checks if a link's host is (not) good, otherwise displays an error.
27
-   * @param string $Url Link to an image
28
-   * @return boolean
29
-   */
30
-  public static function blacklisted($Url, $ShowError = true) {
31
-    $Blacklist = ['tinypic.com'];
32
-    foreach ($Blacklist as $Value) {
33
-      if (stripos($Url, $Value) !== false) {
34
-        if ($ShowError) {
35
-          error($Value . ' is not an allowed image host. Please use a different host.');
31
+    /**
32
+     * Checks if a link's host is (not) good, otherwise displays an error.
33
+     * @param string $Url Link to an image
34
+     * @return boolean
35
+     */
36
+    public static function blacklisted($Url, $ShowError = true)
37
+    {
38
+        $Blacklist = ['tinypic.com'];
39
+        foreach ($Blacklist as $Value) {
40
+            if (stripos($Url, $Value) !== false) {
41
+                if ($ShowError) {
42
+                    error($Value . ' is not an allowed image host. Please use a different host.');
43
+                }
44
+                return true;
45
+            }
36 46
         }
37
-        return true;
38
-      }
47
+        return false;
39 48
     }
40
-    return false;
41
-  }
42 49
 }

+ 26
- 26
classes/inbox.class.php View File

@@ -1,31 +1,31 @@
1 1
 <?php
2 2
 
3
-class Inbox {
4
-  /*
5
-   * Get the link to a user's inbox.
6
-   * This is what handles the ListUnreadPMsFirst setting
7
-   *
8
-   * @param string - whether the inbox or sentbox should be loaded
9
-   * @return string - the URL to a user's inbox
10
-   */
11
-  public static function get_inbox_link($WhichBox = 'inbox') {
3
+class Inbox
4
+{
5
+    /*
6
+     * Get the link to a user's inbox.
7
+     * This is what handles the ListUnreadPMsFirst setting
8
+     *
9
+     * @param string - whether the inbox or sentbox should be loaded
10
+     * @return string - the URL to a user's inbox
11
+     */
12
+    public static function get_inbox_link($WhichBox = 'inbox')
13
+    {
14
+        $ListFirst = isset(G::$LoggedUser['ListUnreadPMsFirst']) ? G::$LoggedUser['ListUnreadPMsFirst'] : false;
12 15
 
13
-    $ListFirst = isset(G::$LoggedUser['ListUnreadPMsFirst']) ? G::$LoggedUser['ListUnreadPMsFirst'] : false;
14
-
15
-    if ($WhichBox == 'inbox') {
16
-      if ($ListFirst) {
17
-        $InboxURL = 'inbox.php?sort=unread';
18
-      } else {
19
-        $InboxURL = 'inbox.php';
20
-      }
21
-    } else {
22
-      if ($ListFirst) {
23
-        $InboxURL = 'inbox.php?action=sentbox&amp;sort=unread';
24
-      } else {
25
-        $InboxURL = 'inbox.php?action=sentbox';
26
-      }
16
+        if ($WhichBox == 'inbox') {
17
+            if ($ListFirst) {
18
+                $InboxURL = 'inbox.php?sort=unread';
19
+            } else {
20
+                $InboxURL = 'inbox.php';
21
+            }
22
+        } else {
23
+            if ($ListFirst) {
24
+                $InboxURL = 'inbox.php?action=sentbox&amp;sort=unread';
25
+            } else {
26
+                $InboxURL = 'inbox.php?action=sentbox';
27
+            }
28
+        }
29
+        return $InboxURL;
27 30
     }
28
-    return $InboxURL;
29
-  }
30 31
 }
31
-?>

+ 185
- 190
classes/invite_tree.class.php View File

@@ -1,4 +1,4 @@
1
-<?
1
+<?php
2 2
 /**************************************************************************/
3 3
 /*-- Invite tree class -----------------------------------------------------
4 4
 
@@ -6,35 +6,37 @@
6 6
 
7 7
 ***************************************************************************/
8 8
 
9
-class INVITE_TREE {
10
-  var $UserID = 0;
11
-  var $Visible = true;
12
-
13
-  // Set things up
14
-  function INVITE_TREE($UserID, $Options = []) {
15
-    $this->UserID = $UserID;
16
-    if ($Options['visible'] === false) {
17
-      $this->Visible = false;
9
+class INVITE_TREE
10
+{
11
+    public $UserID = 0;
12
+    public $Visible = true;
13
+
14
+    // Set things up
15
+    public function INVITE_TREE($UserID, $Options = [])
16
+    {
17
+        $this->UserID = $UserID;
18
+        if ($Options['visible'] === false) {
19
+            $this->Visible = false;
20
+        }
18 21
     }
19
-  }
20 22
 
21
-  function make_tree() {
22
-    $QueryID = G::$DB->get_query_id();
23
+    public function make_tree()
24
+    {
25
+        $QueryID = G::$DB->get_query_id();
23 26
 
24
-    $UserID = $this->UserID;
25
-?>
27
+        $UserID = $this->UserID; ?>
26 28
     <div class="invitetree pad">
27
-<?
28
-    G::$DB->query("
29
+        <?php
30
+        G::$DB->query("
29 31
       SELECT TreePosition, TreeID, TreeLevel
30 32
       FROM invite_tree
31 33
       WHERE UserID = $UserID");
32
-    list($TreePosition, $TreeID, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false);
34
+        list($TreePosition, $TreeID, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false);
33 35
 
34
-    if (!$TreeID) {
35
-      return;
36
-    }
37
-    G::$DB->query("
36
+        if (!$TreeID) {
37
+            return;
38
+        }
39
+        G::$DB->query("
38 40
       SELECT TreePosition
39 41
       FROM invite_tree
40 42
       WHERE TreeID = $TreeID
@@ -42,12 +44,12 @@ class INVITE_TREE {
42 44
         AND TreePosition > $TreePosition
43 45
       ORDER BY TreePosition ASC
44 46
       LIMIT 1");
45
-    if (G::$DB->has_results()) {
46
-      list($MaxPosition) = G::$DB->next_record(MYSQLI_NUM, false);
47
-    } else {
48
-      $MaxPosition = false;
49
-    }
50
-    $TreeQuery = G::$DB->query("
47
+        if (G::$DB->has_results()) {
48
+            list($MaxPosition) = G::$DB->next_record(MYSQLI_NUM, false);
49
+        } else {
50
+            $MaxPosition = false;
51
+        }
52
+        $TreeQuery = G::$DB->query("
51 53
       SELECT
52 54
         it.UserID,
53 55
         Enabled,
@@ -67,182 +69,175 @@ class INVITE_TREE {
67 69
         AND TreeLevel > $TreeLevel
68 70
       ORDER BY TreePosition");
69 71
 
70
-    $PreviousTreeLevel = $TreeLevel;
71
-
72
-    // Stats for the summary
73
-    $MaxTreeLevel = $TreeLevel; // The deepest level (this changes)
74
-    $OriginalTreeLevel = $TreeLevel; // The level of the user we're viewing
75
-    $BaseTreeLevel = $TreeLevel + 1; // The level of users invited by our user
76
-    $Count = 0;
77
-    $Branches = 0;
78
-    $DisabledCount = 0;
79
-    $DonorCount = 0;
80
-    $ParanoidCount = 0;
81
-    $TotalUpload = 0;
82
-    $TotalDownload = 0;
83
-    $TopLevelUpload = 0;
84
-    $TopLevelDownload = 0;
85
-
86
-    $ClassSummary = [];
87
-    global $Classes;
88
-    foreach ($Classes as $ClassID => $Val) {
89
-      $ClassSummary[$ClassID] = 0;
90
-    }
91
-
92
-    // We store this in an output buffer, so we can show the summary at the top without having to loop through twice
93
-    ob_start();
94
-    while (list($ID, $Enabled, $Class, $Donor, $Uploaded, $Downloaded, $Paranoia, $TreePosition, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false)) {
95
-
96
-      // Do stats
97
-      $Count++;
98
-
99
-      if ($TreeLevel > $MaxTreeLevel) {
100
-        $MaxTreeLevel = $TreeLevel;
101
-      }
102
-
103
-      if ($TreeLevel == $BaseTreeLevel) {
104
-        $Branches++;
105
-        $TopLevelUpload += $Uploaded;
106
-        $TopLevelDownload += $Downloaded;
107
-      }
108
-
109
-      $ClassSummary[$Class]++;
110
-      if ($Enabled == 2) {
111
-        $DisabledCount++;
112
-      }
113
-      if ($Donor) {
114
-        $DonorCount++;
115
-      }
116
-
117
-      // Manage tree depth
118
-      if ($TreeLevel > $PreviousTreeLevel) {
119
-        for ($i = 0; $i < $TreeLevel - $PreviousTreeLevel; $i++) {
120
-          echo "\n\n<ul class=\"invitetree\">\n\t<li>\n";
121
-        }
122
-      } elseif ($TreeLevel < $PreviousTreeLevel) {
123
-        for ($i = 0; $i < $PreviousTreeLevel - $TreeLevel; $i++) {
124
-          echo "\t</li>\n</ul>\n";
72
+        $PreviousTreeLevel = $TreeLevel;
73
+
74
+        // Stats for the summary
75
+        $MaxTreeLevel = $TreeLevel; // The deepest level (this changes)
76
+        $OriginalTreeLevel = $TreeLevel; // The level of the user we're viewing
77
+        $BaseTreeLevel = $TreeLevel + 1; // The level of users invited by our user
78
+        $Count = 0;
79
+        $Branches = 0;
80
+        $DisabledCount = 0;
81
+        $DonorCount = 0;
82
+        $ParanoidCount = 0;
83
+        $TotalUpload = 0;
84
+        $TotalDownload = 0;
85
+        $TopLevelUpload = 0;
86
+        $TopLevelDownload = 0;
87
+
88
+        $ClassSummary = [];
89
+        global $Classes;
90
+        foreach ($Classes as $ClassID => $Val) {
91
+            $ClassSummary[$ClassID] = 0;
125 92
         }
126
-        echo "\t</li>\n\t<li>\n";
127
-      } else {
128
-        echo "\t</li>\n\t<li>\n";
129
-      }
130
-      $UserClass = $Classes[$Class]['Level'];
131
-?>
93
+
94
+        // We store this in an output buffer, so we can show the summary at the top without having to loop through twice
95
+        ob_start();
96
+        while (list($ID, $Enabled, $Class, $Donor, $Uploaded, $Downloaded, $Paranoia, $TreePosition, $TreeLevel) = G::$DB->next_record(MYSQLI_NUM, false)) {
97
+            // Do stats
98
+            $Count++;
99
+
100
+            if ($TreeLevel > $MaxTreeLevel) {
101
+                $MaxTreeLevel = $TreeLevel;
102
+            }
103
+
104
+            if ($TreeLevel == $BaseTreeLevel) {
105
+                $Branches++;
106
+                $TopLevelUpload += $Uploaded;
107
+                $TopLevelDownload += $Downloaded;
108
+            }
109
+
110
+            $ClassSummary[$Class]++;
111
+            if ($Enabled == 2) {
112
+                $DisabledCount++;
113
+            }
114
+            if ($Donor) {
115
+                $DonorCount++;
116
+            }
117
+
118
+            // Manage tree depth
119
+            if ($TreeLevel > $PreviousTreeLevel) {
120
+                for ($i = 0; $i < $TreeLevel - $PreviousTreeLevel; $i++) {
121
+                    echo "\n\n<ul class=\"invitetree\">\n\t<li>\n";
122
+                }
123
+            } elseif ($TreeLevel < $PreviousTreeLevel) {
124
+                for ($i = 0; $i < $PreviousTreeLevel - $TreeLevel; $i++) {
125
+                    echo "\t</li>\n</ul>\n";
126
+                }
127
+                echo "\t</li>\n\t<li>\n";
128
+            } else {
129
+                echo "\t</li>\n\t<li>\n";
130
+            }
131
+            $UserClass = $Classes[$Class]['Level']; ?>
132 132
     <strong><?=Users::format_username($ID, true, true, ($Enabled != 2 ? false : true), true)?></strong>
133
-<?
134
-      if (check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) {
135
-        $TotalUpload += $Uploaded;
136
-        $TotalDownload += $Downloaded;
137
-?>
133
+            <?php
134
+            if (check_paranoia(array('uploaded', 'downloaded'), $Paranoia, $UserClass)) {
135
+                $TotalUpload += $Uploaded;
136
+                $TotalDownload += $Downloaded; ?>
138 137
     &nbsp;Uploaded: <strong><?=Format::get_size($Uploaded)?></strong>
139 138
     &nbsp;Downloaded: <strong><?=Format::get_size($Downloaded)?></strong>
140 139
     &nbsp;Ratio: <strong><?=Format::get_ratio_html($Uploaded, $Downloaded)?></strong>
141
-<?
142
-      } else {
143
-        $ParanoidCount++;
144
-?>
140
+                <?php
141
+            } else {
142
+                $ParanoidCount++; ?>
145 143
     &nbsp;Hidden
146
-<?
147
-      }
148
-?>
149
-
150
-<?
151
-      $PreviousTreeLevel = $TreeLevel;
152
-      G::$DB->set_query_id($TreeQuery);
153
-    }
144
+                <?php
145
+            } ?>
154 146
 
155
-    $Tree = ob_get_clean();
156
-    for ($i = 0; $i < $PreviousTreeLevel - $OriginalTreeLevel; $i++) {
157
-      $Tree .= "\t</li>\n</ul>\n";
158
-    }
147
+            <?php
148
+              $PreviousTreeLevel = $TreeLevel;
149
+            G::$DB->set_query_id($TreeQuery);
150
+        }
159 151
 
160
-    if ($Count) {
152
+        $Tree = ob_get_clean();
153
+        for ($i = 0; $i < $PreviousTreeLevel - $OriginalTreeLevel; $i++) {
154
+            $Tree .= "\t</li>\n</ul>\n";
155
+        }
161 156
 
162
-?>
157
+        if ($Count) {
158
+            ?>
163 159
     <p style="font-weight: bold;">
164 160
       This tree has <?=number_format($Count)?> entries, <?=number_format($Branches)?> branches, and a depth of <?=number_format($MaxTreeLevel - $OriginalTreeLevel)?>.
165 161
       It has
166
-<?
167
-      $ClassStrings = [];
168
-      foreach ($ClassSummary as $ClassID => $ClassCount) {
169
-        if ($ClassCount == 0) {
170
-          continue;
171
-        }
172
-        $LastClass = Users::make_class_string($ClassID);
173
-        if ($ClassCount > 1) {
174
-          if ($LastClass == 'Torrent Celebrity') {
175
-             $LastClass = 'Torrent Celebrities';
176
-          } else {
177
-            // Prevent duplicate letterss
178
-            if (substr($LastClass, -1) != 's') {
179
-              $LastClass.='s';
162
+            <?php
163
+              $ClassStrings = [];
164
+            foreach ($ClassSummary as $ClassID => $ClassCount) {
165
+                if ($ClassCount == 0) {
166
+                    continue;
167
+                }
168
+                $LastClass = Users::make_class_string($ClassID);
169
+                if ($ClassCount > 1) {
170
+                    if ($LastClass == 'Torrent Celebrity') {
171
+                        $LastClass = 'Torrent Celebrities';
172
+                    } else {
173
+                        // Prevent duplicate letterss
174
+                        if (substr($LastClass, -1) != 's') {
175
+                            $LastClass.='s';
176
+                        }
177
+                    }
178
+                }
179
+                $LastClass = "$ClassCount $LastClass (" . number_format(($ClassCount / $Count) * 100) . '%)';
180
+
181
+                $ClassStrings[] = $LastClass;
180 182
             }
181
-          }
182
-        }
183
-        $LastClass = "$ClassCount $LastClass (" . number_format(($ClassCount / $Count) * 100) . '%)';
184
-
185
-        $ClassStrings[] = $LastClass;
186
-      }
187
-      if (count($ClassStrings) > 1) {
188
-        array_pop($ClassStrings);
189
-        echo implode(', ', $ClassStrings);
190
-        echo ' and '.$LastClass;
191
-      } else {
192
-        echo $LastClass;
193
-      }
194
-      echo '. ';
195
-      echo $DisabledCount;
196
-      echo ($DisabledCount == 1) ? ' user is' : ' users are';
197
-      echo ' disabled (';
198
-      if ($DisabledCount == 0) {
199
-        echo '0%)';
200
-      } else {
201
-        echo number_format(($DisabledCount / $Count) * 100) . '%)';
202
-      }
203
-      echo ', and ';
204
-      echo $DonorCount;
205
-      echo ($DonorCount == 1) ? ' user has' : ' users have';
206
-      echo ' donated (';
207
-      if ($DonorCount == 0) {
208
-        echo '0%)';
209
-      } else {
210
-        echo number_format(($DonorCount / $Count) * 100) . '%)';
211
-      }
212
-      echo '. </p>';
213
-
214
-      echo '<p style="font-weight: bold;">';
215
-      echo 'The total amount uploaded by the entire tree was '.Format::get_size($TotalUpload);
216
-      echo '; the total amount downloaded was '.Format::get_size($TotalDownload);
217
-      echo '; and the total ratio is '.Format::get_ratio_html($TotalUpload, $TotalDownload).'. ';
218
-      echo '</p>';
219
-
220
-      echo '<p style="font-weight: bold;">';
221
-      echo 'The total amount uploaded by direct invitees (the top level) was '.Format::get_size($TopLevelUpload);
222
-      echo '; the total amount downloaded was '.Format::get_size($TopLevelDownload);
223
-      echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. ';
224
-
225
-      echo "These numbers include the stats of paranoid users and will be factored into the invitation giving script.\n\t\t</p>\n";
226
-
227
-      if ($ParanoidCount) {
228
-        echo '<p style="font-weight: bold;">';
229
-        echo $ParanoidCount;
230
-        echo ($ParanoidCount == 1) ? ' user (' : ' users (';
231
-        echo number_format(($ParanoidCount / $Count) * 100);
232
-        echo '%) ';
233
-        echo ($ParanoidCount == 1) ? ' is' : ' are';
234
-        echo ' too paranoid to have their stats shown here, and ';
235
-        echo ($ParanoidCount == 1) ? ' was' : ' were';
236
-        echo ' not factored into the stats for the total tree.';
237
-        echo '</p>';
238
-      }
239
-    }
240
-?>
183
+            if (count($ClassStrings) > 1) {
184
+                array_pop($ClassStrings);
185
+                echo implode(', ', $ClassStrings);
186
+                echo ' and '.$LastClass;
187
+            } else {
188
+                echo $LastClass;
189
+            }
190
+            echo '. ';
191
+            echo $DisabledCount;
192
+            echo ($DisabledCount == 1) ? ' user is' : ' users are';
193
+            echo ' disabled (';
194
+            if ($DisabledCount == 0) {
195
+                echo '0%)';
196
+            } else {
197
+                echo number_format(($DisabledCount / $Count) * 100) . '%)';
198
+            }
199
+            echo ', and ';
200
+            echo $DonorCount;
201
+            echo ($DonorCount == 1) ? ' user has' : ' users have';
202
+            echo ' donated (';
203
+            if ($DonorCount == 0) {
204
+                echo '0%)';
205
+            } else {
206
+                echo number_format(($DonorCount / $Count) * 100) . '%)';
207
+            }
208
+            echo '. </p>';
209
+
210
+            echo '<p style="font-weight: bold;">';
211
+            echo 'The total amount uploaded by the entire tree was '.Format::get_size($TotalUpload);
212
+            echo '; the total amount downloaded was '.Format::get_size($TotalDownload);
213
+            echo '; and the total ratio is '.Format::get_ratio_html($TotalUpload, $TotalDownload).'. ';
214
+            echo '</p>';
215
+
216
+            echo '<p style="font-weight: bold;">';
217
+            echo 'The total amount uploaded by direct invitees (the top level) was '.Format::get_size($TopLevelUpload);
218
+            echo '; the total amount downloaded was '.Format::get_size($TopLevelDownload);
219
+            echo '; and the total ratio is '.Format::get_ratio_html($TopLevelUpload, $TopLevelDownload).'. ';
220
+
221
+            echo "These numbers include the stats of paranoid users and will be factored into the invitation giving script.\n\t\t</p>\n";
222
+
223
+            if ($ParanoidCount) {
224
+                echo '<p style="font-weight: bold;">';
225
+                echo $ParanoidCount;
226
+                echo ($ParanoidCount == 1) ? ' user (' : ' users (';
227
+                echo number_format(($ParanoidCount / $Count) * 100);
228
+                echo '%) ';
229
+                echo ($ParanoidCount == 1) ? ' is' : ' are';
230
+                echo ' too paranoid to have their stats shown here, and ';
231
+                echo ($ParanoidCount == 1) ? ' was' : ' were';
232
+                echo ' not factored into the stats for the total tree.';
233
+                echo '</p>';
234
+            }
235
+        } ?>
241 236
       <br />
242
-<?=     $Tree?>
237
+        <?=     $Tree?>
243 238
     </div>
244
-<?
245
-    G::$DB->set_query_id($QueryID);
246
-  }
239
+        <?php
240
+        G::$DB->set_query_id($QueryID);
241
+    }
247 242
 }
248 243
 ?>

+ 191
- 173
classes/irc.class.php View File

@@ -1,183 +1,201 @@
1
-<?
2
-class IRC_DB extends DB_MYSQL {
3
-  function halt($Msg) {
4
-    global $Bot;
5
-    $Bot->send_to($Bot->get_channel(), 'The database is currently unavailable; try again later.');
6
-  }
1
+<?php
2
+class IRC_DB extends DB_MYSQL
3
+{
4
+    public function halt($Msg)
5
+    {
6
+        global $Bot;
7
+        $Bot->send_to($Bot->get_channel(), 'The database is currently unavailable; try again later.');
8
+    }
7 9
 }
8 10
 
9
-abstract class IRC_BOT {
10
-  abstract protected function connect_events();
11
-  abstract protected function channel_events();
12
-  abstract protected function query_events();
13
-  abstract protected function irc_events();
14
-  abstract protected function listener_events();
15
-
16
-  protected $Debug = false;
17
-  protected $Socket = false;
18
-  protected $Data = false;
19
-  protected $Whois = false;
20
-  protected $Identified = [];
21
-  protected $Channels = [];
22
-  protected $Messages = [];
23
-  protected $LastChan = false;
24
-  protected $ListenSocket = false;
25
-  protected $Listened = false;
26
-  protected $Connecting = false;
27
-  protected $State = 1; // Drone is live
28
-  public $Restart = 0; // Die by default
29
-
30
-  public function __construct() {
31
-    if (isset($_SERVER['HOME']) && is_dir($_SERVER['HOME']) && getcwd() != $_SERVER['HOME']) {
32
-      chdir($_SERVER['HOME']);
33
-    }
34
-    ob_end_clean();
35
-    restore_error_handler(); //Avoid PHP error logging
36
-    set_time_limit(0);
37
-  }
38
-
39
-  public function connect() {
40
-    $this->connect_irc();
41
-    $this->connect_listener();
42
-    $this->post_connect();
43
-  }
44
-
45
-  private function connect_irc($Reconnect = false) {
46
-    $this->Connecting = true;
47
-    //Open a socket to the IRC server
48
-    if (defined('BOT_PORT_SSL')) {
49
-      $IrcAddress = 'tls://' . BOT_SERVER . ':' . BOT_PORT_SSL;
50
-    } else {
51
-      $IrcAddress = 'tcp://' . BOT_SERVER . ':' . BOT_PORT;
52
-    }
53
-    while (!$this->Socket = stream_socket_client($IrcAddress, $ErrNr, $ErrStr)) {
54
-      sleep(15);
55
-    }
56
-    stream_set_blocking($this->Socket, 0);
57
-    $this->Connecting = false;
58
-    if ($Reconnect) {
59
-      $this->post_connect();
60
-    }
61
-  }
62
-
63
-  private function connect_listener() {
64
-    //create a socket to listen on
65
-    $ListenAddress = 'tcp://' . SOCKET_LISTEN_ADDRESS . ':' . SOCKET_LISTEN_PORT;
66
-    if (!$this->ListenSocket = stream_socket_server($ListenAddress, $ErrNr, $ErrStr)) {
67
-      die("Cannot create listen socket: $ErrStr");
68
-    }
69
-    stream_set_blocking($this->ListenSocket, false);
70
-  }
71
-
72
-  private function post_connect() {
73
-    fwrite($this->Socket, "NICK ".BOT_NICK."Init\n");
74
-    fwrite($this->Socket, "USER ".BOT_NICK." * * :IRC Bot\n");
75
-    $this->listen();
76
-  }
77
-
78
-  public function disconnect() {
79
-    fclose($this->ListenSocket);
80
-    $this->State = 0; //Drones dead
81
-  }
82
-
83
-  public function get_channel() {
84
-    preg_match('/.+ PRIVMSG ([^:]+) :.+/', $this->Data, $Channel);
85
-    if (preg_match('/#.+/', $Channel[1])) {
86
-      return $Channel[1];
87
-    } else {
88
-      return false;
89
-    }
90
-  }
91
-
92
-  public function get_nick() {
93
-    preg_match('/:([^!:]+)!.+@[^\s]+ PRIVMSG [^:]+ :.+/', $this->Data, $Nick);
94
-    return $Nick[1];
95
-  }
96
-
97
-  protected function get_message() {
98
-    preg_match('/:.+ PRIVMSG [^:]+ :(.+)/', $this->Data, $Msg);
99
-    return trim($Msg[1]);
100
-  }
101
-
102
-  protected function get_irc_host() {
103
-    preg_match('/:[^!:]+!.+@([^\s]+) PRIVMSG [^:]+ :.+/', $this->Data, $Host);
104
-    return trim($Host[1]);
105
-  }
106
-
107
-  protected function get_word($Select = 1) {
108
-    preg_match('/:.+ PRIVMSG [^:]+ :(.+)/', $this->Data, $Word);
109
-    $Word = preg_split(' ', $Word[1]);
110
-    return trim($Word[$Select]);
111
-  }
112
-
113
-  protected function get_action() {
114
-    preg_match('/:.+ PRIVMSG [^:]+ :!(\S+)/', $this->Data, $Action);
115
-    return strtoupper($Action[1]);
116
-  }
117
-
118
-  protected function send_raw($Text) {
119
-    if (!feof($this->Socket)) {
120
-      fwrite($this->Socket, "$Text\n");
121
-    } elseif (!$this->Connecting) {
122
-      $this->Connecting = true;
123
-      sleep(120);
124
-      $this->connect_irc(true);
125
-    }
126
-  }
127
-
128
-  public function send_to($Channel, $Text) {
129
-    // split the message up into <= 460 character strings and send each individually
130
-    // this is used to prevent messages from getting truncated
131
-    $Text = wordwrap($Text, 460, "\n", true);
132
-    $TextArray = explode("\n", $Text);
133
-    foreach ($TextArray as $Text) {
134
-      $this->send_raw("PRIVMSG $Channel :$Text");
135
-    }
136
-  }
137
-
138
-  protected function whois($Nick) {
139
-    $this->Whois = $Nick;
140
-    $this->send_raw("WHOIS $Nick");
141
-  }
142
-
143
-  /*
144
-  This function uses blacklisted_ip, which is no longer in RC2.
145
-  You can probably find it in old RC1 code kicking aronud if you need it.
146
-  protected function ip_check($IP, $Gline = false, $Channel = BOT_REPORT_CHAN) {
147
-    if (blacklisted_ip($IP)) {
148
-      $this->send_to($Channel, 'TOR IP Detected: '.$IP);
149
-      if ($Gline) {
150
-        $this->send_raw('GLINE *@'.$IP.' 90d :DNSBL Proxy');
151
-      }
11
+abstract class IRC_BOT
12
+{
13
+    abstract protected function connect_events();
14
+    abstract protected function channel_events();
15
+    abstract protected function query_events();
16
+    abstract protected function irc_events();
17
+    abstract protected function listener_events();
18
+
19
+    protected $Debug = false;
20
+    protected $Socket = false;
21
+    protected $Data = false;
22
+    protected $Whois = false;
23
+    protected $Identified = [];
24
+    protected $Channels = [];
25
+    protected $Messages = [];
26
+    protected $LastChan = false;
27
+    protected $ListenSocket = false;
28
+    protected $Listened = false;
29
+    protected $Connecting = false;
30
+    protected $State = 1; // Drone is live
31
+    public $Restart = 0; // Die by default
32
+
33
+    public function __construct()
34
+    {
35
+        if (isset($_SERVER['HOME']) && is_dir($_SERVER['HOME']) && getcwd() != $_SERVER['HOME']) {
36
+            chdir($_SERVER['HOME']);
37
+        }
38
+        ob_end_clean();
39
+        restore_error_handler(); //Avoid PHP error logging
40
+        set_time_limit(0);
152 41
     }
153
-    if (Tools::site_ban_ip($IP)) {
154
-      $this->send_to($Channel, 'Site IP Ban Detected: '.$IP);
155
-      if ($Gline) {
156
-        $this->send_raw('GLINE *@'.$IP.' 90d :IP Ban');
157
-      }
42
+
43
+    public function connect()
44
+    {
45
+        $this->connect_irc();
46
+        $this->connect_listener();
47
+        $this->post_connect();
158 48
     }
159
-  }*/
160 49
 
161
-  protected function listen() {
162
-    G::$Cache->InternalCache = false;
163
-    stream_set_timeout($this->Socket, 10000000000);
164
-    while ($this->State == 1) {
165
-      $NullSock = null;
166
-      $Sockets = array($this->Socket, $this->ListenSocket);
167
-      if (stream_select($Sockets, $NullSock, $NullSock, null) === false) {
168
-        die();
169
-      }
170
-      foreach ($Sockets as $Socket) {
171
-        if ($Socket === $this->Socket) {
172
-          $this->irc_events();
50
+    private function connect_irc($Reconnect = false)
51
+    {
52
+        $this->Connecting = true;
53
+        //Open a socket to the IRC server
54
+        if (defined('BOT_PORT_SSL')) {
55
+            $IrcAddress = 'tls://' . BOT_SERVER . ':' . BOT_PORT_SSL;
56
+        } else {
57
+            $IrcAddress = 'tcp://' . BOT_SERVER . ':' . BOT_PORT;
58
+        }
59
+        while (!$this->Socket = stream_socket_client($IrcAddress, $ErrNr, $ErrStr)) {
60
+            sleep(15);
61
+        }
62
+        stream_set_blocking($this->Socket, 0);
63
+        $this->Connecting = false;
64
+        if ($Reconnect) {
65
+            $this->post_connect();
66
+        }
67
+    }
68
+
69
+    private function connect_listener()
70
+    {
71
+        //create a socket to listen on
72
+        $ListenAddress = 'tcp://' . SOCKET_LISTEN_ADDRESS . ':' . SOCKET_LISTEN_PORT;
73
+        if (!$this->ListenSocket = stream_socket_server($ListenAddress, $ErrNr, $ErrStr)) {
74
+            die("Cannot create listen socket: $ErrStr");
75
+        }
76
+        stream_set_blocking($this->ListenSocket, false);
77
+    }
78
+
79
+    private function post_connect()
80
+    {
81
+        fwrite($this->Socket, "NICK ".BOT_NICK."Init\n");
82
+        fwrite($this->Socket, "USER ".BOT_NICK." * * :IRC Bot\n");
83
+        $this->listen();
84
+    }
85
+
86
+    public function disconnect()
87
+    {
88
+        fclose($this->ListenSocket);
89
+        $this->State = 0; //Drones dead
90
+    }
91
+
92
+    public function get_channel()
93
+    {
94
+        preg_match('/.+ PRIVMSG ([^:]+) :.+/', $this->Data, $Channel);
95
+        if (preg_match('/#.+/', $Channel[1])) {
96
+            return $Channel[1];
173 97
         } else {
174
-          $this->Listened = stream_socket_accept($Socket);
175
-          $this->listener_events();
98
+            return false;
99
+        }
100
+    }
101
+
102
+    public function get_nick()
103
+    {
104
+        preg_match('/:([^!:]+)!.+@[^\s]+ PRIVMSG [^:]+ :.+/', $this->Data, $Nick);
105
+        return $Nick[1];
106
+    }
107
+
108
+    protected function get_message()
109
+    {
110
+        preg_match('/:.+ PRIVMSG [^:]+ :(.+)/', $this->Data, $Msg);
111
+        return trim($Msg[1]);
112
+    }
113
+
114
+    protected function get_irc_host()
115
+    {
116
+        preg_match('/:[^!:]+!.+@([^\s]+) PRIVMSG [^:]+ :.+/', $this->Data, $Host);
117
+        return trim($Host[1]);
118
+    }
119
+
120
+    protected function get_word($Select = 1)
121
+    {
122
+        preg_match('/:.+ PRIVMSG [^:]+ :(.+)/', $this->Data, $Word);
123
+        $Word = preg_split(' ', $Word[1]);
124
+        return trim($Word[$Select]);
125
+    }
126
+
127
+    protected function get_action()
128
+    {
129
+        preg_match('/:.+ PRIVMSG [^:]+ :!(\S+)/', $this->Data, $Action);
130
+        return strtoupper($Action[1]);
131
+    }
132
+
133
+    protected function send_raw($Text)
134
+    {
135
+        if (!feof($this->Socket)) {
136
+            fwrite($this->Socket, "$Text\n");
137
+        } elseif (!$this->Connecting) {
138
+            $this->Connecting = true;
139
+            sleep(120);
140
+            $this->connect_irc(true);
141
+        }
142
+    }
143
+
144
+    public function send_to($Channel, $Text)
145
+    {
146
+        // split the message up into <= 460 character strings and send each individually
147
+        // this is used to prevent messages from getting truncated
148
+        $Text = wordwrap($Text, 460, "\n", true);
149
+        $TextArray = explode("\n", $Text);
150
+        foreach ($TextArray as $Text) {
151
+            $this->send_raw("PRIVMSG $Channel :$Text");
152
+        }
153
+    }
154
+
155
+    protected function whois($Nick)
156
+    {
157
+        $this->Whois = $Nick;
158
+        $this->send_raw("WHOIS $Nick");
159
+    }
160
+
161
+    /*
162
+    This function uses blacklisted_ip, which is no longer in RC2.
163
+    You can probably find it in old RC1 code kicking aronud if you need it.
164
+    protected function ip_check($IP, $Gline = false, $Channel = BOT_REPORT_CHAN) {
165
+      if (blacklisted_ip($IP)) {
166
+        $this->send_to($Channel, 'TOR IP Detected: '.$IP);
167
+        if ($Gline) {
168
+          $this->send_raw('GLINE *@'.$IP.' 90d :DNSBL Proxy');
176 169
         }
177 170
       }
178
-      G::$DB->LinkID = false;
179
-      G::$DB->Queries = [];
171
+      if (Tools::site_ban_ip($IP)) {
172
+        $this->send_to($Channel, 'Site IP Ban Detected: '.$IP);
173
+        if ($Gline) {
174
+          $this->send_raw('GLINE *@'.$IP.' 90d :IP Ban');
175
+        }
176
+      }
177
+    }*/
178
+
179
+    protected function listen()
180
+    {
181
+        G::$Cache->InternalCache = false;
182
+        stream_set_timeout($this->Socket, 10000000000);
183
+        while ($this->State == 1) {
184
+            $NullSock = null;
185
+            $Sockets = array($this->Socket, $this->ListenSocket);
186
+            if (stream_select($Sockets, $NullSock, $NullSock, null) === false) {
187
+                die();
188
+            }
189
+            foreach ($Sockets as $Socket) {
190
+                if ($Socket === $this->Socket) {
191
+                    $this->irc_events();
192
+                } else {
193
+                    $this->Listened = stream_socket_accept($Socket);
194
+                    $this->listener_events();
195
+                }
196
+            }
197
+            G::$DB->LinkID = false;
198
+            G::$DB->Queries = [];
199
+        }
180 200
     }
181
-  }
182 201
 }
183
-?>

+ 1
- 2
classes/lockedaccounts.class.php View File

@@ -1,4 +1,4 @@
1
-<?
1
+<?php
2 2
 
3 3
 /**
4 4
  * Class to manage locked accounts
@@ -17,7 +17,6 @@ class LockedAccounts
17 17
      */
18 18
     public static function lock_account($UserID, $Type, $Message, $Reason, $LockedByUserID)
19 19
     {
20
-
21 20
         if ($LockedByUserID == 0) {
22 21
             $Username = "System";
23 22
         } else {

Loading…
Cancel
Save