Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
da35260b2b
5 changed files with 1493 additions and 1435 deletions
  1. 861
    857
      classes/text.class.php
  2. 177
    162
      classes/textarea_preview.class.php
  3. 148
    131
      classes/time.class.php
  4. 248
    229
      classes/tools.class.php
  5. 59
    56
      classes/top10view.class.php

+ 861
- 857
classes/text.class.php
File diff suppressed because it is too large
View File


+ 177
- 162
classes/textarea_preview.class.php View File

3
  * This super class is used to manage the ammount of textareas there are and to
3
  * This super class is used to manage the ammount of textareas there are and to
4
  * generate the required JavaScript that enables the previews to work.
4
  * generate the required JavaScript that enables the previews to work.
5
  */
5
  */
6
-class TEXTAREA_PREVIEW_SUPER {
7
-  /**
8
-   * @static
9
-   * @var int $Textareas Total number of textareas created
10
-   */
11
-  protected static $Textareas = 0;
12
-
13
-  /**
14
-   * @static
15
-   * @var array $_ID Array of textarea IDs
16
-   */
17
-  protected static $_ID = [];
18
-
19
-  /**
20
-   * @static
21
-   * @var bool For use in JavaScript method
22
-   */
23
-  private static $Exectuted = false;
24
-
25
-  /**
26
-   * This method should only run once with $all as true and should be placed
27
-   * in the header or footer.
28
-   *
29
-   * If $all is true, it includes TextareaPreview and jQuery
30
-   *
31
-   * jQuery is required for this to work, include it in the headers.
32
-   *
33
-   * @static
34
-   * @param bool $all Output all required scripts, otherwise just do iterator()
35
-   * @example <pre><?php TEXT_PREVIEW::JavaScript(); ?></pre>
36
-   * @return void
37
-   */
38
-  public static function JavaScript ($all = true) {
39
-    if (self::$Textareas === 0) {
40
-      return;
41
-    }
42
-    if (self::$Exectuted === false && $all) {
43
-      View::parse('generic/textarea/script.phtml');
6
+class TEXTAREA_PREVIEW_SUPER
7
+{
8
+    /**
9
+     * @static
10
+     * @var int $Textareas Total number of textareas created
11
+     */
12
+    protected static $Textareas = 0;
13
+
14
+    /**
15
+     * @static
16
+     * @var array $_ID Array of textarea IDs
17
+     */
18
+    protected static $_ID = [];
19
+
20
+    /**
21
+     * @static
22
+     * @var bool For use in JavaScript method
23
+     */
24
+    private static $Exectuted = false;
25
+
26
+    /**
27
+     * This method should only run once with $all as true and should be placed
28
+     * in the header or footer.
29
+     *
30
+     * If $all is true, it includes TextareaPreview and jQuery
31
+     *
32
+     * jQuery is required for this to work, include it in the headers.
33
+     *
34
+     * @static
35
+     * @param bool $all Output all required scripts, otherwise just do iterator()
36
+     * @example <pre><?php TEXT_PREVIEW::JavaScript(); ?></pre>
37
+     * @return void
38
+     */
39
+    public static function JavaScript($all = true)
40
+    {
41
+        if (self::$Textareas === 0) {
42
+            return;
43
+        }
44
+        if (self::$Exectuted === false && $all) {
45
+            View::parse('generic/textarea/script.phtml');
46
+        }
47
+
48
+        self::$Exectuted = true;
49
+        self::iterator();
44
     }
50
     }
45
 
51
 
46
-    self::$Exectuted = true;
47
-    self::iterator();
48
-  }
49
-
50
-  /**
51
-   * This iterator generates JavaScript to initialize each JavaScript
52
-   * TextareaPreview object.
53
-   *
54
-   * It will generate a numeric or custom ID related to the textarea.
55
-   * @static
56
-   * @return void
57
-   */
58
-  private static function iterator() {
59
-    $script = [];
60
-    for ($i = 0; $i < self::$Textareas; $i++) {
61
-      if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) {
62
-        $a = sprintf('%d, "%s"', $i, self::$_ID[$i]);
63
-      } else {
64
-        $a = $i;
65
-      }
66
-      $script[] = sprintf('[%s]', $a);
67
-    }
68
-    if (!empty($script)) {
69
-      View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
52
+    /**
53
+     * This iterator generates JavaScript to initialize each JavaScript
54
+     * TextareaPreview object.
55
+     *
56
+     * It will generate a numeric or custom ID related to the textarea.
57
+     * @static
58
+     * @return void
59
+     */
60
+    private static function iterator()
61
+    {
62
+        $script = [];
63
+        for ($i = 0; $i < self::$Textareas; $i++) {
64
+            if (isset(self::$_ID[$i]) && is_string(self::$_ID[$i])) {
65
+                $a = sprintf('%d, "%s"', $i, self::$_ID[$i]);
66
+            } else {
67
+                $a = $i;
68
+            }
69
+            $script[] = sprintf('[%s]', $a);
70
+        }
71
+        if (!empty($script)) {
72
+            View::parse('generic/textarea/script_factory.phtml', array('script' => join(', ', $script)));
73
+        }
70
     }
74
     }
71
-  }
72
 }
75
 }
73
 
76
 
74
 /**
77
 /**
110
  * </div>
113
  * </div>
111
  * </pre>
114
  * </pre>
112
  */
115
  */
113
-class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER {
114
-  /**
115
-   * @var int Unique ID
116
-   */
117
-  private $id;
118
-
119
-  /**
120
-   * Flag for preview output
121
-   * @var bool $preview
122
-   */
123
-  private $preview = false;
124
-
125
-  /**
126
-   * String table
127
-   * @var string Buffer
128
-   */
129
-  private $buffer = null;
130
-
131
-  /**
132
-   * This method creates a textarea
133
-   *
134
-   * @param string $Name     name attribute
135
-   * @param string $ID       id attribute
136
-   * @param string $Value    default text attribute
137
-   * @param string $Cols     cols attribute
138
-   * @param string $Rows     rows attribute
139
-   * @param bool   $Preview  add the preview divs near the textarea
140
-   * @param bool   $Buttons  add the edit/preview buttons near the textarea
141
-   * @param bool   $Buffer   doesn't output the textarea, use getBuffer()
142
-   * @param array  $ExtraAttributes  array of attribute="value"
143
-   *
144
-   * If false for $Preview, $Buttons, or $Buffer, use the appropriate
145
-   * methods to add the those elements manually. Alternatively, use getID
146
-   * to create your own.
147
-   *
148
-   * It's important to have the right IDs as they make the JS function properly.
149
-   */
150
-  public function __construct($Name, $ID = '', $Value = '', $Cols = 50, $Rows = 10,
151
-    $Preview = true, $Buttons = true, $Buffer = false,
152
-    array $ExtraAttributes = []
153
-  ) {
154
-    $this->id = parent::$Textareas;
155
-    parent::$Textareas += 1;
156
-    array_push(parent::$_ID, $ID);
157
-
158
-    if (empty($ID)) {
159
-      $ID = 'quickpost_' . $this->id;
116
+class TEXTAREA_PREVIEW extends TEXTAREA_PREVIEW_SUPER
117
+{
118
+    /**
119
+     * @var int Unique ID
120
+     */
121
+    private $id;
122
+
123
+    /**
124
+     * Flag for preview output
125
+     * @var bool $preview
126
+     */
127
+    private $preview = false;
128
+
129
+    /**
130
+     * String table
131
+     * @var string Buffer
132
+     */
133
+    private $buffer = null;
134
+
135
+    /**
136
+     * This method creates a textarea
137
+     *
138
+     * @param string $Name     name attribute
139
+     * @param string $ID       id attribute
140
+     * @param string $Value    default text attribute
141
+     * @param string $Cols     cols attribute
142
+     * @param string $Rows     rows attribute
143
+     * @param bool   $Preview  add the preview divs near the textarea
144
+     * @param bool   $Buttons  add the edit/preview buttons near the textarea
145
+     * @param bool   $Buffer   doesn't output the textarea, use getBuffer()
146
+     * @param array  $ExtraAttributes  array of attribute="value"
147
+     *
148
+     * If false for $Preview, $Buttons, or $Buffer, use the appropriate
149
+     * methods to add the those elements manually. Alternatively, use getID
150
+     * to create your own.
151
+     *
152
+     * It's important to have the right IDs as they make the JS function properly.
153
+     */
154
+    public function __construct(
155
+        $Name,
156
+        $ID = '',
157
+        $Value = '',
158
+        $Cols = 50,
159
+        $Rows = 10,
160
+        $Preview = true,
161
+        $Buttons = true,
162
+        $Buffer = false,
163
+        array $ExtraAttributes = []
164
+    ) {
165
+        $this->id = parent::$Textareas;
166
+        parent::$Textareas += 1;
167
+        array_push(parent::$_ID, $ID);
168
+
169
+        if (empty($ID)) {
170
+            $ID = 'quickpost_' . $this->id;
171
+        }
172
+
173
+        if (!empty($ExtraAttributes)) {
174
+            $Attributes = ' ' . implode(' ', $ExtraAttributes);
175
+        } else {
176
+            $Attributes = '';
177
+        }
178
+
179
+        if ($Preview === true) {
180
+            $this->preview();
181
+        }
182
+
183
+        $this->buffer = View::parse('generic/textarea/textarea.phtml', array(
184
+        'ID' => $ID,
185
+        'NID' => $this->id,
186
+        'Name' => &$Name,
187
+        'Value' => &$Value,
188
+        'Cols' => &$Cols,
189
+        'Rows' => &$Rows,
190
+        'Attributes' => &$Attributes
191
+        ), $Buffer);
192
+
193
+        if ($Buttons === true) {
194
+            $this->buttons();
195
+        }
160
     }
196
     }
161
 
197
 
162
-    if (!empty($ExtraAttributes)) {
163
-      $Attributes = ' ' . implode(' ', $ExtraAttributes);
164
-    } else {
165
-      $Attributes = '';
198
+    /**
199
+     * Outputs the divs required for previewing the AJAX content
200
+     * Will only output once
201
+     */
202
+    public function preview()
203
+    {
204
+        if (!$this->preview) {
205
+            View::parse('generic/textarea/preview.phtml', array('ID' => $this->id));
206
+        }
207
+        $this->preview = true;
166
     }
208
     }
167
 
209
 
168
-    if ($Preview === true) {
169
-      $this->preview();
210
+    /**
211
+     * Outputs the preview and edit buttons
212
+     * Can be called many times to place buttons in different areas
213
+     */
214
+    public function buttons()
215
+    {
216
+        View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id));
170
     }
217
     }
171
 
218
 
172
-    $this->buffer = View::parse('generic/textarea/textarea.phtml', array(
173
-      'ID' => $ID,
174
-      'NID' => $this->id,
175
-      'Name' => &$Name,
176
-      'Value' => &$Value,
177
-      'Cols' => &$Cols,
178
-      'Rows' => &$Rows,
179
-      'Attributes' => &$Attributes
180
-    ), $Buffer);
181
-
182
-    if ($Buttons === true) {
183
-      $this->buttons();
219
+    /**
220
+     * Returns the textarea's numeric ID.
221
+     */
222
+    public function getID()
223
+    {
224
+        return $this->id;
184
     }
225
     }
185
-  }
186
-
187
-  /**
188
-   * Outputs the divs required for previewing the AJAX content
189
-   * Will only output once
190
-   */
191
-  public function preview() {
192
-    if (!$this->preview) {
193
-      View::parse('generic/textarea/preview.phtml', array('ID' => $this->id));
226
+
227
+    /**
228
+     * Returns textarea string when buffer is enabled in the constructor
229
+     * @return string
230
+     */
231
+    public function getBuffer()
232
+    {
233
+        return $this->buffer;
194
     }
234
     }
195
-    $this->preview = true;
196
-  }
197
-
198
-  /**
199
-   * Outputs the preview and edit buttons
200
-   * Can be called many times to place buttons in different areas
201
-   */
202
-  public function buttons() {
203
-    View::parse('generic/textarea/buttons.phtml', array('ID' => $this->id));
204
-  }
205
-
206
-  /**
207
-   * Returns the textarea's numeric ID.
208
-   */
209
-  public function getID() {
210
-    return $this->id;
211
-  }
212
-
213
-  /**
214
-   * Returns textarea string when buffer is enabled in the constructor
215
-   * @return string
216
-   */
217
-  public function getBuffer() {
218
-    return $this->buffer;
219
-  }
220
 }
235
 }

+ 148
- 131
classes/time.class.php View File

1
-<?
1
+<?php
2
 if (!extension_loaded('date')) {
2
 if (!extension_loaded('date')) {
3
-  error('Date extension not loaded.');
3
+    error('Date extension not loaded.');
4
 }
4
 }
5
 
5
 
6
-function time_ago($TimeStamp) {
7
-  if (!$TimeStamp) { return false; }
8
-  if (!is_number($TimeStamp)) { // Assume that $TimeStamp is SQL timestamp
9
-    $TimeStamp = strtotime($TimeStamp);
10
-  }
11
-  return time() - $TimeStamp;
6
+function time_ago($TimeStamp)
7
+{
8
+    if (!$TimeStamp) {
9
+        return false;
10
+    }
11
+    if (!is_number($TimeStamp)) { // Assume that $TimeStamp is SQL timestamp
12
+        $TimeStamp = strtotime($TimeStamp);
13
+    }
14
+    return time() - $TimeStamp;
12
 }
15
 }
13
 
16
 
14
 /*
17
 /*
15
  * Returns a <span> by default but can optionally return the raw time
18
  * Returns a <span> by default but can optionally return the raw time
16
  * difference in text (e.g. "16 hours and 28 minutes", "1 day, 18 hours").
19
  * difference in text (e.g. "16 hours and 28 minutes", "1 day, 18 hours").
17
  */
20
  */
18
-function time_diff($TimeStamp, $Levels = 2, $Span = true, $Lowercase = false) {
19
-  if (!$TimeStamp) { return 'Never'; }
20
-  if (!is_number($TimeStamp)) { // Assume that $TimeStamp is SQL timestamp
21
-    $TimeStamp = strtotime($TimeStamp);
22
-  }
23
-  $Time = time() - $TimeStamp;
24
-
25
-  // If the time is negative, then it expires in the future.
26
-  if ($Time < 0) {
27
-    $Time = -$Time;
28
-    $HideAgo = true;
29
-  }
30
-
31
-  $Years = floor($Time / 31556926); // seconds in one year
32
-  $Remain = $Time - $Years * 31556926;
33
-
34
-  $Months = floor($Remain / 2629744); // seconds in one month
35
-  $Remain = $Remain - $Months * 2629744;
36
-
37
-  $Weeks = floor($Remain / 604800); // seconds in one week
38
-  $Remain = $Remain - $Weeks * 604800;
39
-
40
-  $Days = floor($Remain / 86400); // seconds in one day
41
-  $Remain = $Remain - $Days * 86400;
42
-
43
-  $Hours=floor($Remain / 3600); // seconds in one hour
44
-  $Remain = $Remain - $Hours * 3600;
45
-
46
-  $Minutes = floor($Remain / 60); // seconds in one minute
47
-  $Remain = $Remain - $Minutes * 60;
48
-
49
-  $Seconds = $Remain;
50
-
51
-  $Return = '';
52
-
53
-  if ($Years > 0 && $Levels > 0) {
54
-    $Return .= "$Years year".(($Years > 1) ? 's' : '' );
55
-    $Levels--;
56
-  }
57
-
58
-  if ($Months > 0 && $Levels > 0) {
59
-    $Return .= ($Return != '') ? ', ' : '';
60
-    $Return .= "$Months month".(($Months > 1) ? 's' : '');
61
-    $Levels--;
62
-  }
63
-
64
-  if ($Weeks > 0 && $Levels > 0) {
65
-    $Return .= ($Return != '') ? ', ' : '';
66
-    $Return .= "$Weeks week".(($Weeks > 1) ? 's' : '');
67
-    $Levels--;
68
-  }
69
-
70
-  if ($Days > 0 && $Levels > 0) {
71
-    $Return .= ($Return != '') ? ', ' : '';
72
-    $Return .= "$Days day".(($Days > 1) ? 's' : '');
73
-    $Levels--;
74
-  }
75
-
76
-  if ($Hours > 0 && $Levels > 0) {
77
-    $Return .= ($Return != '') ? ', ' : '';
78
-    $Return .= "$Hours hour".(($Hours > 1) ? 's' : '');
79
-    $Levels--;
80
-  }
81
-
82
-  if ($Minutes > 0 && $Levels > 0) {
83
-    $Return .= ($Return != '') ? ' and ' : '';
84
-    $Return .= "$Minutes min".(($Minutes > 1) ? 's' : '');
85
-  }
86
-
87
-  if ($Return == '') {
88
-    $Return = 'Just now';
89
-  } elseif (!isset($HideAgo)) {
90
-    $Return .= ' ago';
91
-  }
92
-
93
-  if ($Lowercase) {
94
-    $Return = strtolower($Return);
95
-  }
96
-
97
-  if ($Span) {
98
-    return '<span class="time tooltip" title="'.date('M d Y, H:i', $TimeStamp).'">'.$Return.'</span>';
99
-  } else {
100
-    return $Return;
101
-  }
21
+function time_diff($TimeStamp, $Levels = 2, $Span = true, $Lowercase = false)
22
+{
23
+    if (!$TimeStamp) {
24
+        return 'Never';
25
+    }
26
+    if (!is_number($TimeStamp)) { // Assume that $TimeStamp is SQL timestamp
27
+        $TimeStamp = strtotime($TimeStamp);
28
+    }
29
+    $Time = time() - $TimeStamp;
30
+
31
+    // If the time is negative, then it expires in the future.
32
+    if ($Time < 0) {
33
+        $Time = -$Time;
34
+        $HideAgo = true;
35
+    }
36
+
37
+    $Years = floor($Time / 31556926); // seconds in one year
38
+    $Remain = $Time - $Years * 31556926;
39
+
40
+    $Months = floor($Remain / 2629744); // seconds in one month
41
+    $Remain = $Remain - $Months * 2629744;
42
+
43
+    $Weeks = floor($Remain / 604800); // seconds in one week
44
+    $Remain = $Remain - $Weeks * 604800;
45
+
46
+    $Days = floor($Remain / 86400); // seconds in one day
47
+    $Remain = $Remain - $Days * 86400;
48
+
49
+    $Hours=floor($Remain / 3600); // seconds in one hour
50
+    $Remain = $Remain - $Hours * 3600;
51
+
52
+    $Minutes = floor($Remain / 60); // seconds in one minute
53
+    $Remain = $Remain - $Minutes * 60;
54
+
55
+    $Seconds = $Remain;
56
+
57
+    $Return = '';
58
+
59
+    if ($Years > 0 && $Levels > 0) {
60
+        $Return .= "$Years year".(($Years > 1) ? 's' : '');
61
+        $Levels--;
62
+    }
63
+
64
+    if ($Months > 0 && $Levels > 0) {
65
+        $Return .= ($Return != '') ? ', ' : '';
66
+        $Return .= "$Months month".(($Months > 1) ? 's' : '');
67
+        $Levels--;
68
+    }
69
+
70
+    if ($Weeks > 0 && $Levels > 0) {
71
+        $Return .= ($Return != '') ? ', ' : '';
72
+        $Return .= "$Weeks week".(($Weeks > 1) ? 's' : '');
73
+        $Levels--;
74
+    }
75
+
76
+    if ($Days > 0 && $Levels > 0) {
77
+        $Return .= ($Return != '') ? ', ' : '';
78
+        $Return .= "$Days day".(($Days > 1) ? 's' : '');
79
+        $Levels--;
80
+    }
81
+
82
+    if ($Hours > 0 && $Levels > 0) {
83
+        $Return .= ($Return != '') ? ', ' : '';
84
+        $Return .= "$Hours hour".(($Hours > 1) ? 's' : '');
85
+        $Levels--;
86
+    }
87
+
88
+    if ($Minutes > 0 && $Levels > 0) {
89
+        $Return .= ($Return != '') ? ' and ' : '';
90
+        $Return .= "$Minutes min".(($Minutes > 1) ? 's' : '');
91
+    }
92
+
93
+    if ($Return == '') {
94
+        $Return = 'Just now';
95
+    } elseif (!isset($HideAgo)) {
96
+        $Return .= ' ago';
97
+    }
98
+
99
+    if ($Lowercase) {
100
+        $Return = strtolower($Return);
101
+    }
102
+
103
+    if ($Span) {
104
+        return '<span class="time tooltip" title="'.date('M d Y, H:i', $TimeStamp).'">'.$Return.'</span>';
105
+    } else {
106
+        return $Return;
107
+    }
102
 }
108
 }
103
 
109
 
104
 /* SQL utility functions */
110
 /* SQL utility functions */
105
 
111
 
106
-function time_plus($Offset) {
107
-  return date('Y-m-d H:i:s', time() + $Offset);
112
+function time_plus($Offset)
113
+{
114
+    return date('Y-m-d H:i:s', time() + $Offset);
108
 }
115
 }
109
 
116
 
110
-function time_minus($Offset, $Fuzzy = false) {
111
-  if ($Fuzzy) {
112
-    return date('Y-m-d 00:00:00', time() - $Offset);
113
-  } else {
114
-    return date('Y-m-d H:i:s', time() - $Offset);
115
-  }
117
+function time_minus($Offset, $Fuzzy = false)
118
+{
119
+    if ($Fuzzy) {
120
+        return date('Y-m-d 00:00:00', time() - $Offset);
121
+    } else {
122
+        return date('Y-m-d H:i:s', time() - $Offset);
123
+    }
116
 }
124
 }
117
 
125
 
118
 // This is never used anywhere with $timestamp set
126
 // This is never used anywhere with $timestamp set
119
 // TODO: Why don't we just use NOW() in the sql queries?
127
 // TODO: Why don't we just use NOW() in the sql queries?
120
-function sqltime($timestamp = NULL) {
121
-  return date('Y-m-d H:i:s', ($timestamp ?? time()));
128
+function sqltime($timestamp = null)
129
+{
130
+    return date('Y-m-d H:i:s', ($timestamp ?? time()));
122
 }
131
 }
123
 
132
 
124
-function validDate($DateString) {
125
-  $DateTime = explode(' ', $DateString);
126
-  if (count($DateTime) != 2) {
127
-    return false;
128
-  }
129
-  list($Date, $Time) = $DateTime;
130
-  $SplitTime = explode(':', $Time);
131
-  if (count($SplitTime) != 3) {
132
-    return false;
133
-  }
134
-  list($H, $M, $S) = $SplitTime;
135
-  if ($H != 0 && !(is_number($H) && $H < 24 && $H >= 0)) { return false; }
136
-  if ($M != 0 && !(is_number($M) && $M < 60 && $M >= 0)) { return false; }
137
-  if ($S != 0 && !(is_number($S) && $S < 60 && $S >= 0)) { return false; }
138
-  $SplitDate = explode('-', $Date);
139
-  if (count($SplitDate) != 3) {
140
-    return false;
141
-  }
142
-  list($Y, $M, $D) = $SplitDate;
143
-  return checkDate($M, $D, $Y);
133
+function validDate($DateString)
134
+{
135
+    $DateTime = explode(' ', $DateString);
136
+    if (count($DateTime) != 2) {
137
+        return false;
138
+    }
139
+    list($Date, $Time) = $DateTime;
140
+    $SplitTime = explode(':', $Time);
141
+    if (count($SplitTime) != 3) {
142
+        return false;
143
+    }
144
+    list($H, $M, $S) = $SplitTime;
145
+    if ($H != 0 && !(is_number($H) && $H < 24 && $H >= 0)) {
146
+        return false;
147
+    }
148
+    if ($M != 0 && !(is_number($M) && $M < 60 && $M >= 0)) {
149
+        return false;
150
+    }
151
+    if ($S != 0 && !(is_number($S) && $S < 60 && $S >= 0)) {
152
+        return false;
153
+    }
154
+    $SplitDate = explode('-', $Date);
155
+    if (count($SplitDate) != 3) {
156
+        return false;
157
+    }
158
+    list($Y, $M, $D) = $SplitDate;
159
+    return checkDate($M, $D, $Y);
144
 }
160
 }
145
 
161
 
146
-function is_valid_date($Date) {
147
-  return is_valid_datetime($Date, 'Y-m-d');
162
+function is_valid_date($Date)
163
+{
164
+    return is_valid_datetime($Date, 'Y-m-d');
148
 }
165
 }
149
 
166
 
150
-function is_valid_time($Time) {
151
-  return is_valid_datetime($Time, 'H:i');
167
+function is_valid_time($Time)
168
+{
169
+    return is_valid_datetime($Time, 'H:i');
152
 }
170
 }
153
 
171
 
154
-function is_valid_datetime($DateTime, $Format = 'Y-m-d H:i') {
155
-  $FormattedDateTime = DateTime::createFromFormat($Format, $DateTime);
156
-  return $FormattedDateTime && $FormattedDateTime->format($Format) == $DateTime;
172
+function is_valid_datetime($DateTime, $Format = 'Y-m-d H:i')
173
+{
174
+    $FormattedDateTime = DateTime::createFromFormat($Format, $DateTime);
175
+    return $FormattedDateTime && $FormattedDateTime->format($Format) == $DateTime;
157
 }
176
 }
158
-
159
-?>

+ 248
- 229
classes/tools.class.php View File

1
-<?
2
-class Tools {
3
-  /**
4
-   * Returns true if given IP is banned.
5
-   *
6
-   * @param string $IP
7
-   */
8
-  public static function site_ban_ip($IP) {
9
-    global $Debug;
10
-    $A = substr($IP, 0, strcspn($IP, '.:'));
11
-    $IPNum = Tools::ip_to_unsigned($IP);
12
-    $IPBans = G::$Cache->get_value('ip_bans_'.$A);
13
-    if (!is_array($IPBans)) {
14
-      $SQL = sprintf("
1
+<?php
2
+class Tools
3
+{
4
+    /**
5
+     * Returns true if given IP is banned.
6
+     *
7
+     * @param string $IP
8
+     */
9
+    public static function site_ban_ip($IP)
10
+    {
11
+        global $Debug;
12
+        $A = substr($IP, 0, strcspn($IP, '.:'));
13
+        $IPNum = Tools::ip_to_unsigned($IP);
14
+        $IPBans = G::$Cache->get_value('ip_bans_'.$A);
15
+        if (!is_array($IPBans)) {
16
+            $SQL = sprintf("
15
         SELECT ID, FromIP, ToIP
17
         SELECT ID, FromIP, ToIP
16
         FROM ip_bans
18
         FROM ip_bans
17
         WHERE FromIP BETWEEN %d << 24 AND (%d << 24) - 1", $A, $A + 1);
19
         WHERE FromIP BETWEEN %d << 24 AND (%d << 24) - 1", $A, $A + 1);
18
-      $QueryID = G::$DB->get_query_id();
19
-      G::$DB->query($SQL);
20
-      $IPBans = G::$DB->to_array(0, MYSQLI_NUM);
21
-      G::$DB->set_query_id($QueryID);
22
-      G::$Cache->cache_value('ip_bans_'.$A, $IPBans, 0);
23
-    }
24
-    $Debug->log_var($IPBans, 'IP bans for class '.$A);
25
-    foreach ($IPBans as $Index => $IPBan) {
26
-      list ($ID, $FromIP, $ToIP) = $IPBan;
27
-      if ($IPNum >= $FromIP && $IPNum <= $ToIP) {
28
-        return true;
29
-      }
30
-    }
31
-
32
-    return false;
33
-  }
20
+            $QueryID = G::$DB->get_query_id();
21
+            G::$DB->query($SQL);
22
+            $IPBans = G::$DB->to_array(0, MYSQLI_NUM);
23
+            G::$DB->set_query_id($QueryID);
24
+            G::$Cache->cache_value('ip_bans_'.$A, $IPBans, 0);
25
+        }
26
+        $Debug->log_var($IPBans, 'IP bans for class '.$A);
27
+        foreach ($IPBans as $Index => $IPBan) {
28
+            list($ID, $FromIP, $ToIP) = $IPBan;
29
+            if ($IPNum >= $FromIP && $IPNum <= $ToIP) {
30
+                return true;
31
+            }
32
+        }
34
 
33
 
35
-  /**
36
-   * Returns the unsigned form of an IP address.
37
-   *
38
-   * @param string $IP The IP address x.x.x.x
39
-   * @return string the long it represents.
40
-   */
41
-  public static function ip_to_unsigned($IP) {
42
-    $IPnum = sprintf('%u', ip2long($IP));
43
-    if (!$IPnum) {
44
-      // Try to encode as IPv6 (stolen from stackoverflow)
45
-      // Note that this is *wrong* and because of PHP's wankery stops being accurate after the most significant 16 digits or so
46
-      // But since this is only used for geolocation and IPv6 blocks are allocated in huge numbers, it's still fine
47
-      $IPnum = '';
48
-      foreach (unpack('C*', inet_pton($IP)) as $byte) {
49
-        $IPnum .= str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
50
-      }
51
-      $IPnum = base_convert(ltrim($IPnum, '0'), 2, 10);
34
+        return false;
52
     }
35
     }
53
-    return $IPnum;
54
-  }
55
 
36
 
56
-  /**
57
-   * Geolocate an IP address using the database
58
-   *
59
-   * @param $IP the ip to fetch the country for
60
-   * @return the country of origin
61
-   */
62
-  public static function geoip($IP) {
63
-    static $IPs = [];
64
-    if (isset($IPs[$IP])) {
65
-      return $IPs[$IP];
66
-    }
67
-    if (is_number($IP)) {
68
-      $Long = $IP;
69
-    } else {
70
-      $Long = Tools::ip_to_unsigned($IP);
71
-    }
72
-    if (!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
73
-      return false;
37
+    /**
38
+     * Returns the unsigned form of an IP address.
39
+     *
40
+     * @param string $IP The IP address x.x.x.x
41
+     * @return string the long it represents.
42
+     */
43
+    public static function ip_to_unsigned($IP)
44
+    {
45
+        $IPnum = sprintf('%u', ip2long($IP));
46
+        if (!$IPnum) {
47
+            // Try to encode as IPv6 (stolen from stackoverflow)
48
+            // Note that this is *wrong* and because of PHP's wankery stops being accurate after the most significant 16 digits or so
49
+            // But since this is only used for geolocation and IPv6 blocks are allocated in huge numbers, it's still fine
50
+            $IPnum = '';
51
+            foreach (unpack('C*', inet_pton($IP)) as $byte) {
52
+                $IPnum .= str_pad(decbin($byte), 8, "0", STR_PAD_LEFT);
53
+            }
54
+            $IPnum = base_convert(ltrim($IPnum, '0'), 2, 10);
55
+        }
56
+        return $IPnum;
74
     }
57
     }
75
-    $QueryID = G::$DB->get_query_id();
76
-    G::$DB->query("
58
+
59
+    /**
60
+     * Geolocate an IP address using the database
61
+     *
62
+     * @param $IP the ip to fetch the country for
63
+     * @return the country of origin
64
+     */
65
+    public static function geoip($IP)
66
+    {
67
+        static $IPs = [];
68
+        if (isset($IPs[$IP])) {
69
+            return $IPs[$IP];
70
+        }
71
+        if (is_number($IP)) {
72
+            $Long = $IP;
73
+        } else {
74
+            $Long = Tools::ip_to_unsigned($IP);
75
+        }
76
+        if (!$Long || $Long == 2130706433) { // No need to check cc for 127.0.0.1
77
+            return false;
78
+        }
79
+        $QueryID = G::$DB->get_query_id();
80
+        G::$DB->query("
77
       SELECT EndIP, Code
81
       SELECT EndIP, Code
78
       FROM geoip_country
82
       FROM geoip_country
79
       WHERE $Long >= StartIP
83
       WHERE $Long >= StartIP
80
       ORDER BY StartIP DESC
84
       ORDER BY StartIP DESC
81
       LIMIT 1");
85
       LIMIT 1");
82
-    if ((!list($EndIP, $Country) = G::$DB->next_record()) || $EndIP < $Long) {
83
-      $Country = '?';
86
+        if ((!list($EndIP, $Country) = G::$DB->next_record()) || $EndIP < $Long) {
87
+            $Country = '?';
88
+        }
89
+        G::$DB->set_query_id($QueryID);
90
+        $IPs[$IP] = $Country;
91
+        return $Country;
84
     }
92
     }
85
-    G::$DB->set_query_id($QueryID);
86
-    $IPs[$IP] = $Country;
87
-    return $Country;
88
-  }
89
 
93
 
90
-  /**
91
-   * Gets the hostname for an IP address
92
-   *
93
-   * @param $IP the IP to get the hostname for
94
-   * @return hostname fetched
95
-   */
96
-  public static function get_host_by_ip($IP) {
97
-    $testar = explode('.', $IP);
98
-    if (count($testar) != 4) {
99
-      return $IP;
100
-    }
101
-    for ($i = 0; $i < 4; ++$i) {
102
-      if (!is_numeric($testar[$i])) {
103
-        return $IP;
104
-      }
105
-    }
94
+    /**
95
+     * Gets the hostname for an IP address
96
+     *
97
+     * @param $IP the IP to get the hostname for
98
+     * @return hostname fetched
99
+     */
100
+    public static function get_host_by_ip($IP)
101
+    {
102
+        $testar = explode('.', $IP);
103
+        if (count($testar) != 4) {
104
+            return $IP;
105
+        }
106
+        for ($i = 0; $i < 4; ++$i) {
107
+            if (!is_numeric($testar[$i])) {
108
+                return $IP;
109
+            }
110
+        }
106
 
111
 
107
-    $host = `host -W 1 $IP`;
108
-    return ($host ? end(explode(' ', $host)) : $IP);
109
-  }
112
+        $host = `host -W 1 $IP`;
113
+        return ($host ? end(explode(' ', $host)) : $IP);
114
+    }
110
 
115
 
111
-  /**
112
-   * Gets an hostname using AJAX
113
-   *
114
-   * @param $IP the IP to fetch
115
-   * @return a span with JavaScript code
116
-   */
117
-  public static function get_host_by_ajax($IP) {
118
-    static $ID = 0;
119
-    ++$ID;
120
-    return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host) {$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>';
121
-  }
116
+    /**
117
+     * Gets an hostname using AJAX
118
+     *
119
+     * @param $IP the IP to fetch
120
+     * @return a span with JavaScript code
121
+     */
122
+    public static function get_host_by_ajax($IP)
123
+    {
124
+        static $ID = 0;
125
+        ++$ID;
126
+        return '<span id="host_'.$ID.'">Resolving host...<script type="text/javascript">ajax.get(\'tools.php?action=get_host&ip='.$IP.'\',function(host) {$(\'#host_'.$ID.'\').raw().innerHTML=host;});</script></span>';
127
+    }
122
 
128
 
123
 
129
 
124
-  /**
125
-   * Looks up the full host of an IP address, by system call.
126
-   * Used as the server-side counterpart to get_host_by_ajax.
127
-   *
128
-   * @param string $IP The IP address to look up.
129
-   * @return string the host.
130
-   */
131
-  public static function lookup_ip($IP) {
132
-    //TODO: use the G::$Cache
133
-    $Output = explode(' ',shell_exec('host -W 1 '.escapeshellarg($IP)));
134
-    if (count($Output) == 1 && empty($Output[0]))  { return ''; }
135
-    if (count($Output) != 5)                       { return false; }
136
-    if ($Output[2].' '.$Output[3] == 'not found:') { return false; }
137
-    return trim($Output[4]);
138
-  }
130
+    /**
131
+     * Looks up the full host of an IP address, by system call.
132
+     * Used as the server-side counterpart to get_host_by_ajax.
133
+     *
134
+     * @param string $IP The IP address to look up.
135
+     * @return string the host.
136
+     */
137
+    public static function lookup_ip($IP)
138
+    {
139
+        //TODO: use the G::$Cache
140
+        $Output = explode(' ', shell_exec('host -W 1 '.escapeshellarg($IP)));
141
+        if (count($Output) == 1 && empty($Output[0])) {
142
+            return '';
143
+        }
144
+        if (count($Output) != 5) {
145
+            return false;
146
+        }
147
+        if ($Output[2].' '.$Output[3] == 'not found:') {
148
+            return false;
149
+        }
150
+        return trim($Output[4]);
151
+    }
139
 
152
 
140
-  /**
141
-   * Format an IP address with links to IP history.
142
-   *
143
-   * @param string IP
144
-   * @return string The HTML
145
-   */
146
-  public static function display_ip($IP) {
147
-    $Line = display_str($IP).' ('.Tools::get_country_code_by_ajax($IP).') ';
148
-    $Line .= '<a href="user.php?action=search&amp;ip_history=on&amp;ip='.display_str($IP).'&amp;matchtype=strict" title="Search" class="brackets tooltip">S</a>';
153
+    /**
154
+     * Format an IP address with links to IP history.
155
+     *
156
+     * @param string IP
157
+     * @return string The HTML
158
+     */
159
+    public static function display_ip($IP)
160
+    {
161
+        $Line = display_str($IP).' ('.Tools::get_country_code_by_ajax($IP).') ';
162
+        $Line .= '<a href="user.php?action=search&amp;ip_history=on&amp;ip='.display_str($IP).'&amp;matchtype=strict" title="Search" class="brackets tooltip">S</a>';
149
 
163
 
150
-    return $Line;
151
-  }
164
+        return $Line;
165
+    }
152
 
166
 
153
-  public static function get_country_code_by_ajax($IP) {
154
-    static $ID = 0;
155
-    ++$ID;
156
-    return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\', function(cc) {$(\'#cc_'.$ID.'\').raw().innerHTML = cc;});</script></span>';
157
-  }
167
+    public static function get_country_code_by_ajax($IP)
168
+    {
169
+        static $ID = 0;
170
+        ++$ID;
171
+        return '<span id="cc_'.$ID.'">Resolving CC...<script type="text/javascript">ajax.get(\'tools.php?action=get_cc&ip='.$IP.'\', function(cc) {$(\'#cc_'.$ID.'\').raw().innerHTML = cc;});</script></span>';
172
+    }
158
 
173
 
159
 
174
 
160
-  /**
161
-   * Disable an array of users.
162
-   *
163
-   * @param array $UserIDs (You can also send it one ID as an int, because fuck types)
164
-   * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
165
-   */
166
-  public static function disable_users($UserIDs, $AdminComment, $BanReason = 1) {
167
-    $QueryID = G::$DB->get_query_id();
168
-    if (!is_array($UserIDs)) {
169
-      $UserIDs = array($UserIDs);
170
-    }
171
-    G::$DB->query("
175
+    /**
176
+     * Disable an array of users.
177
+     *
178
+     * @param array $UserIDs (You can also send it one ID as an int, because fuck types)
179
+     * @param BanReason 0 - Unknown, 1 - Manual, 2 - Ratio, 3 - Inactive, 4 - Unused.
180
+     */
181
+    public static function disable_users($UserIDs, $AdminComment, $BanReason = 1)
182
+    {
183
+        $QueryID = G::$DB->get_query_id();
184
+        if (!is_array($UserIDs)) {
185
+            $UserIDs = array($UserIDs);
186
+        }
187
+        G::$DB->query("
172
       UPDATE users_info AS i
188
       UPDATE users_info AS i
173
         JOIN users_main AS m ON m.ID = i.UserID
189
         JOIN users_main AS m ON m.ID = i.UserID
174
       SET m.Enabled = '2',
190
       SET m.Enabled = '2',
178
         i.BanReason = '$BanReason',
194
         i.BanReason = '$BanReason',
179
         i.RatioWatchDownload = ".($BanReason == 2 ? 'm.Downloaded' : "'0'")."
195
         i.RatioWatchDownload = ".($BanReason == 2 ? 'm.Downloaded' : "'0'")."
180
       WHERE m.ID IN(".implode(',', $UserIDs).') ');
196
       WHERE m.ID IN(".implode(',', $UserIDs).') ');
181
-    G::$Cache->decrement('stats_user_count', G::$DB->affected_rows());
182
-    foreach ($UserIDs as $UserID) {
183
-      G::$Cache->delete_value("enabled_$UserID");
184
-      G::$Cache->delete_value("user_info_$UserID");
185
-      G::$Cache->delete_value("user_info_heavy_$UserID");
186
-      G::$Cache->delete_value("user_stats_$UserID");
197
+        G::$Cache->decrement('stats_user_count', G::$DB->affected_rows());
198
+        foreach ($UserIDs as $UserID) {
199
+            G::$Cache->delete_value("enabled_$UserID");
200
+            G::$Cache->delete_value("user_info_$UserID");
201
+            G::$Cache->delete_value("user_info_heavy_$UserID");
202
+            G::$Cache->delete_value("user_stats_$UserID");
187
 
203
 
188
-      G::$DB->query("
204
+            G::$DB->query("
189
         SELECT SessionID
205
         SELECT SessionID
190
         FROM users_sessions
206
         FROM users_sessions
191
         WHERE UserID = '$UserID'
207
         WHERE UserID = '$UserID'
192
           AND Active = 1");
208
           AND Active = 1");
193
-      while (list($SessionID) = G::$DB->next_record()) {
194
-        G::$Cache->delete_value("session_$UserID"."_$SessionID");
195
-      }
196
-      G::$Cache->delete_value("users_sessions_$UserID");
209
+            while (list($SessionID) = G::$DB->next_record()) {
210
+                G::$Cache->delete_value("session_$UserID"."_$SessionID");
211
+            }
212
+            G::$Cache->delete_value("users_sessions_$UserID");
197
 
213
 
198
-      G::$DB->query("
214
+            G::$DB->query("
199
         DELETE FROM users_sessions
215
         DELETE FROM users_sessions
200
         WHERE UserID = '$UserID'");
216
         WHERE UserID = '$UserID'");
217
+        }
201
 
218
 
202
-    }
203
-
204
-    // Remove the users from the tracker.
205
-    G::$DB->query('
219
+        // Remove the users from the tracker.
220
+        G::$DB->query('
206
       SELECT torrent_pass
221
       SELECT torrent_pass
207
       FROM users_main
222
       FROM users_main
208
       WHERE ID in ('.implode(', ', $UserIDs).')');
223
       WHERE ID in ('.implode(', ', $UserIDs).')');
209
-    $PassKeys = G::$DB->collect('torrent_pass');
210
-    $Concat = '';
211
-    foreach ($PassKeys as $PassKey) {
212
-      if (strlen($Concat) > 3950) { // Ocelot's read buffer is 4 KiB and anything exceeding it is truncated
224
+        $PassKeys = G::$DB->collect('torrent_pass');
225
+        $Concat = '';
226
+        foreach ($PassKeys as $PassKey) {
227
+            if (strlen($Concat) > 3950) { // Ocelot's read buffer is 4 KiB and anything exceeding it is truncated
228
+                Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
229
+                $Concat = $PassKey;
230
+            } else {
231
+                $Concat .= $PassKey;
232
+            }
233
+        }
213
         Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
234
         Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
214
-        $Concat = $PassKey;
215
-      } else {
216
-        $Concat .= $PassKey;
217
-      }
235
+        G::$DB->set_query_id($QueryID);
218
     }
236
     }
219
-    Tracker::update_tracker('remove_users', array('passkeys' => $Concat));
220
-    G::$DB->set_query_id($QueryID);
221
-  }
222
 
237
 
223
-  /**
224
-   * Warn a user.
225
-   *
226
-   * @param int $UserID
227
-   * @param int $Duration length of warning in seconds
228
-   * @param string $reason
229
-   */
230
-  public static function warn_user($UserID, $Duration, $Reason) {
231
-    global $Time;
238
+    /**
239
+     * Warn a user.
240
+     *
241
+     * @param int $UserID
242
+     * @param int $Duration length of warning in seconds
243
+     * @param string $reason
244
+     */
245
+    public static function warn_user($UserID, $Duration, $Reason)
246
+    {
247
+        global $Time;
232
 
248
 
233
-    $QueryID = G::$DB->get_query_id();
234
-    G::$DB->query("
249
+        $QueryID = G::$DB->get_query_id();
250
+        G::$DB->query("
235
       SELECT Warned
251
       SELECT Warned
236
       FROM users_info
252
       FROM users_info
237
       WHERE UserID = $UserID
253
       WHERE UserID = $UserID
238
         AND Warned IS NOT NULL");
254
         AND Warned IS NOT NULL");
239
-    if (G::$DB->has_results()) {
240
-      //User was already warned, appending new warning to old.
241
-      list($OldDate) = G::$DB->next_record();
242
-      $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
255
+        if (G::$DB->has_results()) {
256
+            //User was already warned, appending new warning to old.
257
+            list($OldDate) = G::$DB->next_record();
258
+            $NewExpDate = date('Y-m-d H:i:s', strtotime($OldDate) + $Duration);
243
 
259
 
244
-      Misc::send_pm($UserID, 0,
245
-        'You have received multiple warnings.',
246
-        "When you received your latest warning (set to expire on ".date('Y-m-d', (time() + $Duration)).'), you already had a different warning (set to expire on '.date('Y-m-d', strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at $NewExpDate.");
260
+            Misc::send_pm(
261
+                $UserID,
262
+                0,
263
+                'You have received multiple warnings.',
264
+                "When you received your latest warning (set to expire on ".date('Y-m-d', (time() + $Duration)).'), you already had a different warning (set to expire on '.date('Y-m-d', strtotime($OldDate)).").\n\n Due to this collision, your warning status will now expire at $NewExpDate."
265
+            );
247
 
266
 
248
-      $AdminComment = date('Y-m-d')." - Warning (Clash) extended to expire at $NewExpDate by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
267
+            $AdminComment = date('Y-m-d')." - Warning (Clash) extended to expire at $NewExpDate by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
249
 
268
 
250
-      G::$DB->query('
269
+            G::$DB->query('
251
         UPDATE users_info
270
         UPDATE users_info
252
         SET
271
         SET
253
           Warned = \''.db_string($NewExpDate).'\',
272
           Warned = \''.db_string($NewExpDate).'\',
254
           WarnedTimes = WarnedTimes + 1,
273
           WarnedTimes = WarnedTimes + 1,
255
           AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
274
           AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
256
         WHERE UserID = \''.db_string($UserID).'\'');
275
         WHERE UserID = \''.db_string($UserID).'\'');
257
-    } else {
258
-      //Not changing, user was not already warned
259
-      $WarnTime = time_plus($Duration);
276
+        } else {
277
+            //Not changing, user was not already warned
278
+            $WarnTime = time_plus($Duration);
260
 
279
 
261
-      G::$Cache->begin_transaction("user_info_$UserID");
262
-      G::$Cache->update_row(false, array('Warned' => $WarnTime));
263
-      G::$Cache->commit_transaction(0);
280
+            G::$Cache->begin_transaction("user_info_$UserID");
281
+            G::$Cache->update_row(false, array('Warned' => $WarnTime));
282
+            G::$Cache->commit_transaction(0);
264
 
283
 
265
-      $AdminComment = date('Y-m-d')." - Warned until $WarnTime by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
284
+            $AdminComment = date('Y-m-d')." - Warned until $WarnTime by " . G::$LoggedUser['Username'] . "\nReason: $Reason\n\n";
266
 
285
 
267
-      G::$DB->query('
286
+            G::$DB->query('
268
         UPDATE users_info
287
         UPDATE users_info
269
         SET
288
         SET
270
           Warned = \''.db_string($WarnTime).'\',
289
           Warned = \''.db_string($WarnTime).'\',
271
           WarnedTimes = WarnedTimes + 1,
290
           WarnedTimes = WarnedTimes + 1,
272
           AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
291
           AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
273
         WHERE UserID = \''.db_string($UserID).'\'');
292
         WHERE UserID = \''.db_string($UserID).'\'');
293
+        }
294
+        G::$DB->set_query_id($QueryID);
274
     }
295
     }
275
-    G::$DB->set_query_id($QueryID);
276
-  }
277
 
296
 
278
-  /**
279
-   * Update the notes of a user
280
-   * @param unknown $UserID ID of user
281
-   * @param unknown $AdminComment Comment to update with
282
-   */
283
-  public static function update_user_notes($UserID, $AdminComment) {
284
-    $QueryID = G::$DB->get_query_id();
285
-    G::$DB->query('
297
+    /**
298
+     * Update the notes of a user
299
+     * @param unknown $UserID ID of user
300
+     * @param unknown $AdminComment Comment to update with
301
+     */
302
+    public static function update_user_notes($UserID, $AdminComment)
303
+    {
304
+        $QueryID = G::$DB->get_query_id();
305
+        G::$DB->query('
286
       UPDATE users_info
306
       UPDATE users_info
287
       SET AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
307
       SET AdminComment = CONCAT(\''.db_string($AdminComment).'\', AdminComment)
288
       WHERE UserID = \''.db_string($UserID).'\'');
308
       WHERE UserID = \''.db_string($UserID).'\'');
289
-    G::$DB->set_query_id($QueryID);
290
-  }
291
-
292
-  /**
293
-  * Check if an IP address is part of a given CIDR range.
294
-  * @param string $CheckIP the IP address to be looked up
295
-  * @param string $Subnet the CIDR subnet to be checked against
296
-  */
297
-  public static function check_cidr_range($CheckIP, $Subnet) {
298
-    $IP = ip2long($CheckIP);
299
-    $CIDR = preg_split('/', $Subnet);
300
-    $SubnetIP = ip2long($CIDR[0]);
301
-    $SubnetMaskBits = 32 - $CIDR[1];
309
+        G::$DB->set_query_id($QueryID);
310
+    }
302
 
311
 
303
-    return (($IP>>$SubnetMaskBits) == ($SubnetIP>>$SubnetMaskBits));
304
-  }
312
+    /**
313
+    * Check if an IP address is part of a given CIDR range.
314
+    * @param string $CheckIP the IP address to be looked up
315
+    * @param string $Subnet the CIDR subnet to be checked against
316
+    */
317
+    public static function check_cidr_range($CheckIP, $Subnet)
318
+    {
319
+        $IP = ip2long($CheckIP);
320
+        $CIDR = preg_split('/', $Subnet);
321
+        $SubnetIP = ip2long($CIDR[0]);
322
+        $SubnetMaskBits = 32 - $CIDR[1];
305
 
323
 
324
+        return (($IP>>$SubnetMaskBits) == ($SubnetIP>>$SubnetMaskBits));
325
+    }
306
 }
326
 }
307
-?>

+ 59
- 56
classes/top10view.class.php View File

1
-<?
1
+<?php
2
 
2
 
3
-class Top10View {
4
-
5
-  public static function render_linkbox($Selected) {
6
-?>
3
+class Top10View
4
+{
5
+    public static function render_linkbox($Selected)
6
+    {
7
+        ?>
7
     <div class="linkbox">
8
     <div class="linkbox">
8
       <a href="top10.php?type=torrents" class="brackets"><?=self::get_selected_link("Torrents", $Selected == "torrents")?></a>
9
       <a href="top10.php?type=torrents" class="brackets"><?=self::get_selected_link("Torrents", $Selected == "torrents")?></a>
9
       <a href="top10.php?type=users" class="brackets"><?=self::get_selected_link("Users", $Selected == "users")?></a>
10
       <a href="top10.php?type=users" class="brackets"><?=self::get_selected_link("Users", $Selected == "users")?></a>
10
       <a href="top10.php?type=tags" class="brackets"><?=self::get_selected_link("Tags", $Selected == "tags")?></a>
11
       <a href="top10.php?type=tags" class="brackets"><?=self::get_selected_link("Tags", $Selected == "tags")?></a>
11
-<?  if (FEATURE_DONATE) { ?>
12
+        <?php  if (FEATURE_DONATE) { ?>
12
       <a href="top10.php?type=donors" class="brackets"><?=self::get_selected_link("Donors", $Selected == "donors")?></a>
13
       <a href="top10.php?type=donors" class="brackets"><?=self::get_selected_link("Donors", $Selected == "donors")?></a>
13
-<?  } ?>
14
+        <?php  } ?>
14
     </div>
15
     </div>
15
-<?
16
-  }
16
+        <?php
17
+    }
17
 
18
 
18
-  private static function get_selected_link($String, $Selected) {
19
-    if ($Selected) {
20
-      return "<strong>$String</strong>";
21
-    } else {
22
-      return $String;
19
+    private static function get_selected_link($String, $Selected)
20
+    {
21
+        if ($Selected) {
22
+            return "<strong>$String</strong>";
23
+        } else {
24
+            return $String;
25
+        }
23
     }
26
     }
24
-  }
25
 
27
 
26
-  public static function render_artist_tile($Artist, $Category) {
27
-    if (self::is_valid_artist($Artist)) {
28
-      switch ($Category) {
29
-        case 'weekly':
30
-        case 'hyped':
31
-          self::render_tile("artist.php?artistname=", $Artist['name'], $Artist['image'][3]['#text']);
32
-          break;
33
-        default:
34
-          break;
35
-      }
28
+    public static function render_artist_tile($Artist, $Category)
29
+    {
30
+        if (self::is_valid_artist($Artist)) {
31
+            switch ($Category) {
32
+                case 'weekly':
33
+                case 'hyped':
34
+                    self::render_tile("artist.php?artistname=", $Artist['name'], $Artist['image'][3]['#text']);
35
+                    break;
36
+                default:
37
+                    break;
38
+            }
39
+        }
36
     }
40
     }
37
-  }
38
 
41
 
39
-  private static function render_tile($Url, $Name, $Image) {
40
-    if (!empty($Image)) {
41
-      $Name = display_str($Name);
42
-?>
42
+    private static function render_tile($Url, $Name, $Image)
43
+    {
44
+        if (!empty($Image)) {
45
+            $Name = display_str($Name); ?>
43
       <li>
46
       <li>
44
         <a href="<?=$Url?><?=$Name?>">
47
         <a href="<?=$Url?><?=$Name?>">
45
           <img class="tooltip large_tile" alt="<?=$Name?>" title="<?=$Name?>" src="<?=ImageTools::process($Image)?>" />
48
           <img class="tooltip large_tile" alt="<?=$Name?>" title="<?=$Name?>" src="<?=ImageTools::process($Image)?>" />
46
         </a>
49
         </a>
47
       </li>
50
       </li>
48
-<?
51
+            <?php
52
+        }
49
     }
53
     }
50
-  }
51
-
52
 
54
 
53
-  public static function render_artist_list($Artist, $Category) {
54
-    if (self::is_valid_artist($Artist)) {
55
-      switch ($Category) {
56
 
55
 
57
-        case 'weekly':
58
-        case 'hyped':
59
-          self::render_list("artist.php?artistname=", $Artist['name'], $Artist['image'][3]['#text']);
60
-          break;
61
-        default:
62
-          break;
63
-      }
56
+    public static function render_artist_list($Artist, $Category)
57
+    {
58
+        if (self::is_valid_artist($Artist)) {
59
+            switch ($Category) {
60
+                case 'weekly':
61
+                case 'hyped':
62
+                    self::render_list("artist.php?artistname=", $Artist['name'], $Artist['image'][3]['#text']);
63
+                    break;
64
+                default:
65
+                    break;
66
+            }
67
+        }
64
     }
68
     }
65
-  }
66
 
69
 
67
-  private static function render_list($Url, $Name, $Image) {
68
-    if (!empty($Image)) {
69
-      $Image = ImageTools::process($Image);
70
-      $Title = "title=\"&lt;img class=&quot;large_tile&quot; src=&quot;$Image&quot; alt=&quot;&quot; /&gt;\"";
71
-      $Name = display_str($Name);
72
-?>
70
+    private static function render_list($Url, $Name, $Image)
71
+    {
72
+        if (!empty($Image)) {
73
+            $Image = ImageTools::process($Image);
74
+            $Title = "title=\"&lt;img class=&quot;large_tile&quot; src=&quot;$Image&quot; alt=&quot;&quot; /&gt;\"";
75
+            $Name = display_str($Name); ?>
73
       <li>
76
       <li>
74
         <a class="tooltip_image" data-title-plain="<?=$Name?>" <?=$Title?> href="<?=$Url?><?=$Name?>"><?=$Name?></a>
77
         <a class="tooltip_image" data-title-plain="<?=$Name?>" <?=$Title?> href="<?=$Url?><?=$Name?>"><?=$Name?></a>
75
       </li>
78
       </li>
76
-<?
79
+            <?php
80
+        }
77
     }
81
     }
78
-  }
79
-
80
-  private static function is_valid_artist($Artist) {
81
-    return $Artist['name'] != '[unknown]';
82
-  }
83
 
82
 
83
+    private static function is_valid_artist($Artist)
84
+    {
85
+        return $Artist['name'] != '[unknown]';
86
+    }
84
 }
87
 }

Loading…
Cancel
Save