Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
0df93b4834

+ 61
- 53
classes/mass_user_bookmarks_editor.class.php View File

8
  * It can later be used for other bookmark tables.
8
  * It can later be used for other bookmark tables.
9
  *
9
  *
10
  */
10
  */
11
-class MASS_USER_BOOKMARKS_EDITOR extends MASS_USER_TORRENTS_EDITOR {
12
-  public function __construct($Table = 'bookmarks_torrents') {
13
-    $this->set_table($Table);
14
-  }
15
-
16
-  /**
17
-   * Runs a SQL query and clears the Cache key
18
-   *
19
-   * G::$Cache->delete_value didn't always work, but setting the key to null, did. (?)
20
-   *
21
-   * @param string $sql
22
-   */
23
-  protected function query_and_clear_cache($sql) {
24
-    $QueryID = G::$DB->get_query_id();
25
-    if (is_string($sql) && G::$DB->query($sql)) {
26
-      G::$Cache->delete_value('bookmarks_group_ids_' . G::$LoggedUser['ID']);
11
+class MASS_USER_BOOKMARKS_EDITOR extends MASS_USER_TORRENTS_EDITOR
12
+{
13
+    public function __construct($Table = 'bookmarks_torrents')
14
+    {
15
+        $this->set_table($Table);
27
     }
16
     }
28
-    G::$DB->set_query_id($QueryID);
29
-  }
30
 
17
 
31
-  /**
32
-   * Uses (checkboxes) $_POST['remove'] to delete entries.
33
-   *
34
-   * Uses an IN() to match multiple items in one query.
35
-   */
36
-  public function mass_remove() {
37
-    $SQL = [];
38
-    foreach ($_POST['remove'] as $GroupID => $K) {
39
-      if (is_number($GroupID)) {
40
-        $SQL[] = sprintf('%d', $GroupID);
41
-      }
18
+    /**
19
+     * Runs a SQL query and clears the Cache key
20
+     *
21
+     * G::$Cache->delete_value didn't always work, but setting the key to null, did. (?)
22
+     *
23
+     * @param string $sql
24
+     */
25
+    protected function query_and_clear_cache($sql)
26
+    {
27
+        $QueryID = G::$DB->get_query_id();
28
+        if (is_string($sql) && G::$DB->query($sql)) {
29
+            G::$Cache->delete_value('bookmarks_group_ids_' . G::$LoggedUser['ID']);
30
+        }
31
+        G::$DB->set_query_id($QueryID);
42
     }
32
     }
43
 
33
 
44
-    if (!empty($SQL)) {
45
-      $SQL = sprintf('
34
+    /**
35
+     * Uses (checkboxes) $_POST['remove'] to delete entries.
36
+     *
37
+     * Uses an IN() to match multiple items in one query.
38
+     */
39
+    public function mass_remove()
40
+    {
41
+        $SQL = [];
42
+        foreach ($_POST['remove'] as $GroupID => $K) {
43
+            if (is_number($GroupID)) {
44
+                $SQL[] = sprintf('%d', $GroupID);
45
+            }
46
+        }
47
+
48
+        if (!empty($SQL)) {
49
+            $SQL = sprintf(
50
+                '
46
           DELETE FROM %s
51
           DELETE FROM %s
47
           WHERE UserID = %d
52
           WHERE UserID = %d
48
             AND GroupID IN (%s)',
53
             AND GroupID IN (%s)',
49
-        $this->Table,
50
-        G::$LoggedUser['ID'],
51
-        implode(', ', $SQL)
52
-      );
53
-      $this->query_and_clear_cache($SQL);
54
+                $this->Table,
55
+                G::$LoggedUser['ID'],
56
+                implode(', ', $SQL)
57
+            );
58
+            $this->query_and_clear_cache($SQL);
59
+        }
54
     }
60
     }
55
-  }
56
 
61
 
57
-  /**
58
-   * Uses $_POST['sort'] values to update the DB.
59
-   */
60
-  public function mass_update() {
61
-    $SQL = [];
62
-    foreach ($_POST['sort'] as $GroupID => $Sort) {
63
-      if (is_number($Sort) && is_number($GroupID)) {
64
-        $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']);
65
-      }
66
-    }
62
+    /**
63
+     * Uses $_POST['sort'] values to update the DB.
64
+     */
65
+    public function mass_update()
66
+    {
67
+        $SQL = [];
68
+        foreach ($_POST['sort'] as $GroupID => $Sort) {
69
+            if (is_number($Sort) && is_number($GroupID)) {
70
+                $SQL[] = sprintf('(%d, %d, %d)', $GroupID, $Sort, G::$LoggedUser['ID']);
71
+            }
72
+        }
67
 
73
 
68
-    if (!empty($SQL)) {
69
-      $SQL = sprintf('
74
+        if (!empty($SQL)) {
75
+            $SQL = sprintf(
76
+                '
70
           INSERT INTO %s
77
           INSERT INTO %s
71
             (GroupID, Sort, UserID)
78
             (GroupID, Sort, UserID)
72
           VALUES
79
           VALUES
73
             %s
80
             %s
74
           ON DUPLICATE KEY UPDATE
81
           ON DUPLICATE KEY UPDATE
75
             Sort = VALUES (Sort)',
82
             Sort = VALUES (Sort)',
76
-        $this->Table,
77
-        implode(', ', $SQL));
78
-      $this->query_and_clear_cache($SQL);
83
+                $this->Table,
84
+                implode(', ', $SQL)
85
+            );
86
+            $this->query_and_clear_cache($SQL);
87
+        }
79
     }
88
     }
80
-  }
81
 }
89
 }

+ 45
- 40
classes/mass_user_torrents_editor.class.php View File

13
  *
13
  *
14
  * It could also be used for other types like collages.
14
  * It could also be used for other types like collages.
15
  */
15
  */
16
-abstract class MASS_USER_TORRENTS_EDITOR {
17
-  /**
18
-   * The affected DB table
19
-   * @var string $Table
20
-   */
21
-  protected $Table;
16
+abstract class MASS_USER_TORRENTS_EDITOR
17
+{
18
+    /**
19
+     * The affected DB table
20
+     * @var string $Table
21
+     */
22
+    protected $Table;
22
 
23
 
23
-  /**
24
-   * Set the Table
25
-   * @param string $Table
26
-   */
27
-  final public function set_table($Table) {
28
-    $this->Table = db_string($Table);
29
-  }
24
+    /**
25
+     * Set the Table
26
+     * @param string $Table
27
+     */
28
+    final public function set_table($Table)
29
+    {
30
+        $this->Table = db_string($Table);
31
+    }
30
 
32
 
31
-  /**
32
-   * Get the Table
33
-   * @return string $Table
34
-   */
35
-  final public function get_table() {
36
-    return $this->Table;
37
-  }
33
+    /**
34
+     * Get the Table
35
+     * @return string $Table
36
+     */
37
+    final public function get_table()
38
+    {
39
+        return $this->Table;
40
+    }
38
 
41
 
39
-  /**
40
-   * The extending class must provide a method to send a query and clear the cache
41
-   */
42
-  abstract protected function query_and_clear_cache($sql);
42
+    /**
43
+     * The extending class must provide a method to send a query and clear the cache
44
+     */
45
+    abstract protected function query_and_clear_cache($sql);
43
 
46
 
44
-  /**
45
-   * A method to insert many rows into a single table
46
-   * Not required in subsequent classes
47
-   */
48
-  public function mass_add() {}
47
+    /**
48
+     * A method to insert many rows into a single table
49
+     * Not required in subsequent classes
50
+     */
51
+    public function mass_add()
52
+    {
53
+    }
49
 
54
 
50
-  /**
51
-   * A method to remove many rows from a table
52
-   * The extending class must have a mass_remove method
53
-   */
54
-  abstract public function mass_remove();
55
+    /**
56
+     * A method to remove many rows from a table
57
+     * The extending class must have a mass_remove method
58
+     */
59
+    abstract public function mass_remove();
55
 
60
 
56
-  /**
57
-   * A method to update many rows in a table
58
-   * The extending class must have a mass_update method
59
-   */
60
-  abstract public function mass_update();
61
-}
61
+    /**
62
+     * A method to update many rows in a table
63
+     * The extending class must have a mass_update method
64
+     */
65
+    abstract public function mass_update();
66
+}

+ 186
- 173
classes/mass_user_torrents_table_view.class.php View File

10
  *
10
  *
11
  * It can be used for Bookmarks, Collages, or anywhere where torrents are managed.
11
  * It can be used for Bookmarks, Collages, or anywhere where torrents are managed.
12
  */
12
  */
13
-class MASS_USER_TORRENTS_TABLE_VIEW {
14
-  /**
15
-   * Used to set text the page heading (h2 tag)
16
-   * @var string $Heading
17
-   */
18
-  private $Heading = 'Manage Torrents';
19
-
20
-  /**
21
-   * Sets the value of the input name="type"
22
-   * Later to be used as $_POST['type'] in a form processor
23
-   * @var string $EditType
24
-   */
25
-  private $EditType;
26
-
27
-  /**
28
-   * Flag for empty $TorrentList
29
-   * @var bool $HasTorrentList
30
-   */
31
-  private $HasTorrents;
32
-
33
-  /**
34
-   * Internal reference to the TorrentList
35
-   * @var array $TorrentList
36
-   */
37
-  private $TorrentList;
38
-
39
-  /**
40
-   * Ref. to $CollageDataList
41
-   * @var array $CollageDataList
42
-   */
43
-  private $CollageDataList;
44
-
45
-  /**
46
-   * Counter for number of groups
47
-   * @var in $NumGroups
48
-   */
49
-  private $NumGroups = 0;
50
-
51
-  /**
52
-   * When creating a new instance of this class, TorrentList and
53
-   * CollageDataList must be passed. Additionally, a heading can be added.
54
-   *
55
-   * @param array $TorrentList
56
-   * @param array $CollageDataList
57
-   * @param string $EditType
58
-   * @param string $Heading
59
-   */
60
-  public function __construct (array &$TorrentList, array &$CollageDataList, $EditType, $Heading = null) {
61
-    $this->set_heading($Heading);
62
-    $this->set_edit_type($EditType);
63
-
64
-    $this->TorrentList = $TorrentList;
65
-    $this->CollageDataList = $CollageDataList;
66
-
67
-    $this->HasTorrents = !empty($TorrentList);
68
-    if (!$this->HasTorrents) {
69
-      $this->no_torrents();
13
+class MASS_USER_TORRENTS_TABLE_VIEW
14
+{
15
+    /**
16
+     * Used to set text the page heading (h2 tag)
17
+     * @var string $Heading
18
+     */
19
+    private $Heading = 'Manage Torrents';
20
+
21
+    /**
22
+     * Sets the value of the input name="type"
23
+     * Later to be used as $_POST['type'] in a form processor
24
+     * @var string $EditType
25
+     */
26
+    private $EditType;
27
+
28
+    /**
29
+     * Flag for empty $TorrentList
30
+     * @var bool $HasTorrentList
31
+     */
32
+    private $HasTorrents;
33
+
34
+    /**
35
+     * Internal reference to the TorrentList
36
+     * @var array $TorrentList
37
+     */
38
+    private $TorrentList;
39
+
40
+    /**
41
+     * Ref. to $CollageDataList
42
+     * @var array $CollageDataList
43
+     */
44
+    private $CollageDataList;
45
+
46
+    /**
47
+     * Counter for number of groups
48
+     * @var in $NumGroups
49
+     */
50
+    private $NumGroups = 0;
51
+
52
+    /**
53
+     * When creating a new instance of this class, TorrentList and
54
+     * CollageDataList must be passed. Additionally, a heading can be added.
55
+     *
56
+     * @param array $TorrentList
57
+     * @param array $CollageDataList
58
+     * @param string $EditType
59
+     * @param string $Heading
60
+     */
61
+    public function __construct(array &$TorrentList, array &$CollageDataList, $EditType, $Heading = null)
62
+    {
63
+        $this->set_heading($Heading);
64
+        $this->set_edit_type($EditType);
65
+
66
+        $this->TorrentList = $TorrentList;
67
+        $this->CollageDataList = $CollageDataList;
68
+
69
+        $this->HasTorrents = !empty($TorrentList);
70
+        if (!$this->HasTorrents) {
71
+            $this->no_torrents();
72
+        }
70
     }
73
     }
71
-  }
72
 
74
 
73
-  private function no_torrents () {
74
-?>
75
+    private function no_torrents()
76
+    {
77
+        ?>
75
     <div class="thin">
78
     <div class="thin">
76
       <div class="header">
79
       <div class="header">
77
         <h2>No torrents found.</h2>
80
         <h2>No torrents found.</h2>
80
         <p>Add some torrents and come back later.</p>
83
         <p>Add some torrents and come back later.</p>
81
       </div>
84
       </div>
82
     </div>
85
     </div>
83
-<?
84
-  }
85
-
86
-  /**
87
-   * Renders a complete page and table
88
-   */
89
-  public function render_all () {
90
-    $this->header();
91
-    $this->body();
92
-    $this->footer();
93
-  }
94
-
95
-  /**
96
-   * Renders a comptele page/table header: div#thin, h2, scripts, notes,
97
-   * form, table, etc.
98
-   */
99
-  public function header () {
100
-    if ($this->HasTorrents) {
101
-?>
86
+        <?php
87
+    }
88
+
89
+    /**
90
+     * Renders a complete page and table
91
+     */
92
+    public function render_all()
93
+    {
94
+        $this->header();
95
+        $this->body();
96
+        $this->footer();
97
+    }
98
+
99
+    /**
100
+     * Renders a comptele page/table header: div#thin, h2, scripts, notes,
101
+     * form, table, etc.
102
+     */
103
+    public function header()
104
+    {
105
+        if ($this->HasTorrents) {
106
+            ?>
102
 
107
 
103
 <div class="thin">
108
 <div class="thin">
104
   <div class="header">
109
   <div class="header">
121
 
126
 
122
   <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
127
   <form action="bookmarks.php" method="post" id="drag_drop_collage_form">
123
 
128
 
124
-<?      $this->buttons(); ?>
129
+            <?php      $this->buttons(); ?>
125
 
130
 
126
     <table id="manage_collage_table" class="box">
131
     <table id="manage_collage_table" class="box">
127
       <thead>
132
       <thead>
136
         </tr>
141
         </tr>
137
       </thead>
142
       </thead>
138
       <tbody>
143
       <tbody>
139
-<?
144
+            <?php
145
+        }
140
     }
146
     }
141
-  }
142
 
147
 
143
-  /**
144
-   * Closes header code
145
-   */
146
-  public function footer () {
147
-    if ($this->HasTorrents) {
148
-?>
148
+    /**
149
+     * Closes header code
150
+     */
151
+    public function footer()
152
+    {
153
+        if ($this->HasTorrents) {
154
+            ?>
149
 
155
 
150
       </tbody>
156
       </tbody>
151
     </table>
157
     </table>
152
 
158
 
153
-<?      $this->buttons(); ?>
159
+            <?php      $this->buttons(); ?>
154
 
160
 
155
     <div>
161
     <div>
156
       <input type="hidden" name="action" value="mass_edit" />
162
       <input type="hidden" name="action" value="mass_edit" />
160
   </form>
166
   </form>
161
 </div>
167
 </div>
162
 
168
 
163
-<?
169
+            <?php
170
+        }
164
     }
171
     }
165
-  }
166
-
167
-  /**
168
-   * Formats data for use in row
169
-   *
170
-   */
171
-  public function body () {
172
-    if ($this->HasTorrents)
173
-      foreach ($this->TorrentList as $GroupID => $Group) {
174
-        $Artists = [];
175
-
176
-        extract($Group);
177
-        extract($this->CollageDataList[$GroupID]);
178
-
179
-        $this->NumGroups++;
180
-
181
-        $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
182
-        $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
183
-        $Year = $Year > 0 ? $Year : '';
184
-        $DateAdded = date($Time);
185
-
186
-        $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
187
-      }
188
-  }
189
-
190
-  /**
191
-   * Outputs a single row
192
-   *
193
-   * @param string|int $Sort
194
-   * @param string|int $GroupID
195
-   * @param string|int $GroupYear
196
-   * @param string $DisplayName
197
-   * @param string $TorrentLink
198
-   */
199
-  public function row ($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded) {
200
-?>
172
+
173
+    /**
174
+     * Formats data for use in row
175
+     *
176
+     */
177
+    public function body()
178
+    {
179
+        if ($this->HasTorrents) {
180
+            foreach ($this->TorrentList as $GroupID => $Group) {
181
+                $Artists = [];
182
+
183
+                extract($Group);
184
+                extract($this->CollageDataList[$GroupID]);
185
+
186
+                $this->NumGroups++;
187
+
188
+                $DisplayName = self::display_name($ExtendedArtists, $Artists, $VanityHouse);
189
+                $TorrentLink = '<a href="torrents.php?id='.$GroupID.'" class="tooltip" title="View torrent">'.$Name.'</a>';
190
+                $Year = $Year > 0 ? $Year : '';
191
+                $DateAdded = date($Time);
192
+
193
+                $this->row($Sort, $GroupID, $Year, $DisplayName, $TorrentLink, $DateAdded);
194
+            }
195
+        }
196
+    }
197
+
198
+    /**
199
+     * Outputs a single row
200
+     *
201
+     * @param string|int $Sort
202
+     * @param string|int $GroupID
203
+     * @param string|int $GroupYear
204
+     * @param string $DisplayName
205
+     * @param string $TorrentLink
206
+     */
207
+    public function row($Sort, $GroupID, $GroupYear, $DisplayName, $TorrentLink, $DateAdded)
208
+    {
209
+        ?>
201
 
210
 
202
           <tr class="drag row" id="li_<?=$GroupID?>">
211
           <tr class="drag row" id="li_<?=$GroupID?>">
203
             <td>
212
             <td>
210
             <td class="nobr tooltip" title="<?=$DateAdded?>"><?=$DateAdded ? time_diff($DateAdded) : ' '?></td>
219
             <td class="nobr tooltip" title="<?=$DateAdded?>"><?=$DateAdded ? time_diff($DateAdded) : ' '?></td>
211
             <td class="center"><input type="checkbox" name="remove[<?=$GroupID?>]" value="" /></td>
220
             <td class="center"><input type="checkbox" name="remove[<?=$GroupID?>]" value="" /></td>
212
           </tr>
221
           </tr>
213
-<?
214
-  }
215
-
216
-  /**
217
-   * Parses a simple display name
218
-   *
219
-   * @param array $ExtendedArtists
220
-   * @param array $Artists
221
-   * @param string $VanityHouse
222
-   * @return string $DisplayName
223
-   */
224
-  public static function display_name (array &$ExtendedArtists, array &$Artists, $VanityHouse) {
225
-    $DisplayName = '';
226
-    if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
227
-        || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
228
-      unset($ExtendedArtists[2], $ExtendedArtists[3]);
229
-      $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
230
-    } elseif (count($Artists) > 0) {
231
-      $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
222
+        <?php
232
     }
223
     }
233
-    if ($VanityHouse) {
234
-      $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
224
+
225
+    /**
226
+     * Parses a simple display name
227
+     *
228
+     * @param array $ExtendedArtists
229
+     * @param array $Artists
230
+     * @param string $VanityHouse
231
+     * @return string $DisplayName
232
+     */
233
+    public static function display_name(array &$ExtendedArtists, array &$Artists, $VanityHouse)
234
+    {
235
+        $DisplayName = '';
236
+        if (!empty($ExtendedArtists[1]) || !empty($ExtendedArtists[4])
237
+        || !empty($ExtendedArtists[5]) || !empty($ExtendedArtists[6])) {
238
+            unset($ExtendedArtists[2], $ExtendedArtists[3]);
239
+            $DisplayName = Artists::display_artists($ExtendedArtists, true, false);
240
+        } elseif (count($Artists) > 0) {
241
+            $DisplayName = Artists::display_artists(array('1'=>$Artists), true, false);
242
+        }
243
+        if ($VanityHouse) {
244
+            $DisplayName .= ' [<abbr class="tooltip" title="This is a Vanity House release">VH</abbr>]';
245
+        }
246
+        return $DisplayName;
235
     }
247
     }
236
-    return $DisplayName;
237
-  }
238
-
239
-  /**
240
-   * Renders buttons used at the top and bottom of the table
241
-   */
242
-  public function buttons () {
243
-?>
248
+
249
+    /**
250
+     * Renders buttons used at the top and bottom of the table
251
+     */
252
+    public function buttons()
253
+    {
254
+        ?>
244
     <div class="drag_drop_save">
255
     <div class="drag_drop_save">
245
       <input type="submit" name="update" value="Update ranking" title="Save your rank" class="tooltip save_sortable_collage" />
256
       <input type="submit" name="update" value="Update ranking" title="Save your rank" class="tooltip save_sortable_collage" />
246
       <input type="submit" name="delete" value="Delete checked" title="Remove items" class="tooltip save_sortable_collage" />
257
       <input type="submit" name="delete" value="Delete checked" title="Remove items" class="tooltip save_sortable_collage" />
247
     </div>
258
     </div>
248
-<?
249
-  }
250
-
251
-
252
-  /**
253
-   * @param string $EditType
254
-   */
255
-  public function set_edit_type ($EditType) {
256
-    $this->EditType = $EditType;
257
-  }
258
-
259
-  /**
260
-   * Set's the current page's heading
261
-   * @param string $Heading
262
-   */
263
-  public function set_heading ($Heading) {
264
-    $this->Heading = $Heading;
265
-  }
259
+        <?php
260
+    }
261
+
262
+
263
+    /**
264
+     * @param string $EditType
265
+     */
266
+    public function set_edit_type($EditType)
267
+    {
268
+        $this->EditType = $EditType;
269
+    }
270
+
271
+    /**
272
+     * Set's the current page's heading
273
+     * @param string $Heading
274
+     */
275
+    public function set_heading($Heading)
276
+    {
277
+        $this->Heading = $Heading;
278
+    }
266
 }
279
 }

+ 193
- 113
classes/mediainfo.class.php View File

1
 <?php
1
 <?php
2
-class MediaInfo {
3
-    public static function parse($string, $raw=false) {
2
+class MediaInfo
3
+{
4
+    public static function parse($string, $raw = false)
5
+    {
4
         $t = new ParseManager($string);
6
         $t = new ParseManager($string);
5
         $t->parse();
7
         $t->parse();
6
         return $raw ? $t->output_raw() : $t->output();
8
         return $raw ? $t->output_raw() : $t->output();
7
     }
9
     }
8
 }
10
 }
9
 
11
 
10
-class ParseManager {
12
+class ParseManager
13
+{
11
     protected $lines;
14
     protected $lines;
12
     protected $parsed_lines;
15
     protected $parsed_lines;
13
     protected $index;
16
     protected $index;
22
 
25
 
23
     const GENERIC_PARSER = 'generic_parser';
26
     const GENERIC_PARSER = 'generic_parser';
24
     const MEDIAINFO_START = 'general';
27
     const MEDIAINFO_START = 'general';
25
-    public function __construct($string='') {
28
+    public function __construct($string = '')
29
+    {
26
         $this->index = 0;
30
         $this->index = 0;
27
         $this->output = '';
31
         $this->output = '';
28
         $this->parsed_lines = [];
32
         $this->parsed_lines = [];
31
         $this->add_parser($p);
35
         $this->add_parser($p);
32
     }
36
     }
33
 
37
 
34
-    protected function set_string($string) {
38
+    protected function set_string($string)
39
+    {
35
         $string = trim($string);
40
         $string = trim($string);
36
         $string = static::strip_escaped_tags($string);
41
         $string = static::strip_escaped_tags($string);
37
         $lines = preg_split("/\r\n|\n|\r/", $string);
42
         $lines = preg_split("/\r\n|\n|\r/", $string);
38
-        array_walk($lines,function(&$l) {
43
+        array_walk($lines, function (&$l) {
39
             $l=trim($l);
44
             $l=trim($l);
40
         });
45
         });
41
         $this->lines = $lines;
46
         $this->lines = $lines;
42
     }
47
     }
43
 
48
 
44
-    protected function add_parser($p,$name='') {
45
-        $p->set_lines($this->lines,$this->index);
46
-        if (!$name) $name = static::GENERIC_PARSER;
49
+    protected function add_parser($p, $name = '')
50
+    {
51
+        $p->set_lines($this->lines, $this->index);
52
+        if (!$name) {
53
+            $name = static::GENERIC_PARSER;
54
+        }
47
         $this->parsers[$name][] = $p;
55
         $this->parsers[$name][] = $p;
48
     }
56
     }
49
 
57
 
50
-    public function parse() {
58
+    public function parse()
59
+    {
51
         // get the next section
60
         // get the next section
52
         while ($this->index < count($this->lines) &&
61
         while ($this->index < count($this->lines) &&
53
-          !($line = $this->parsers[static::GENERIC_PARSER][0]->parse_line()));
62
+          !($line = $this->parsers[static::GENERIC_PARSER][0]->parse_line())) {
63
+        }
54
         $section = SectionParser::section_name($line);
64
         $section = SectionParser::section_name($line);
55
         $this->index--; // go back to line we just read
65
         $this->index--; // go back to line we just read
56
 
66
 
58
         if ($section == self::MEDIAINFO_START && isset($this->parsers[$section])) {
68
         if ($section == self::MEDIAINFO_START && isset($this->parsers[$section])) {
59
             $this->new_mediainfo();
69
             $this->new_mediainfo();
60
         }
70
         }
61
-        if (isset($this->available_parsers[$section])){
71
+        if (isset($this->available_parsers[$section])) {
62
             $parser = new $this->available_parsers[$section];
72
             $parser = new $this->available_parsers[$section];
63
-            $this->add_parser($parser,$section);
73
+            $this->add_parser($parser, $section);
64
             // parse section using the parser
74
             // parse section using the parser
65
-            while ($line = $parser->parse_line()) $this->parsed_lines[] = $line;
75
+            while ($line = $parser->parse_line()) {
76
+                $this->parsed_lines[] = $line;
77
+            }
66
 
78
 
67
             $this->parsed_lines[] = '';
79
             $this->parsed_lines[] = '';
68
-        }
69
-        else {
80
+        } else {
70
             // skip until the next blank line or until the next general section
81
             // skip until the next blank line or until the next general section
71
-            while ($line = $this->parsers[static::GENERIC_PARSER][0]->parse_line()){
82
+            while ($line = $this->parsers[static::GENERIC_PARSER][0]->parse_line()) {
72
                 $section = SectionParser::section_name($line);
83
                 $section = SectionParser::section_name($line);
73
                 if ($section == self::MEDIAINFO_START) {
84
                 if ($section == self::MEDIAINFO_START) {
74
                     $this->index--; // go back to line we just read
85
                     $this->index--; // go back to line we just read
83
         }
94
         }
84
     }
95
     }
85
 
96
 
86
-    public function output($cummulative=true) {
87
-        $string = implode("<br />\n",$this->parsed_lines);
88
-        if (!isset($this->parsers['general'])) return $string;
97
+    public function output($cummulative = true)
98
+    {
99
+        $string = implode("<br />\n", $this->parsed_lines);
100
+        if (!isset($this->parsers['general'])) {
101
+            return $string;
102
+        }
89
 
103
 
90
         $midiv_start = '<div class="spoilerContainer hideContainer">
104
         $midiv_start = '<div class="spoilerContainer hideContainer">
91
             <input type="button" class="spoilerButton" value="Show '.
105
             <input type="button" class="spoilerButton" value="Show '.
95
 
109
 
96
         $output = '<table class="mediainfo"><tbody><tr><td>';
110
         $output = '<table class="mediainfo"><tbody><tr><td>';
97
         $output .= $this->parsers['general'][0]->output();
111
         $output .= $this->parsers['general'][0]->output();
98
-        if (isset($this->parsers['video'])){
112
+        if (isset($this->parsers['video'])) {
99
             $output .= '</td><td>';
113
             $output .= '</td><td>';
100
             $output .= $this->parsers['video'][0]->output();
114
             $output .= $this->parsers['video'][0]->output();
101
         }
115
         }
102
-        if (isset($this->parsers['audio'])){
116
+        if (isset($this->parsers['audio'])) {
103
             $output .= '</td><td>';
117
             $output .= '</td><td>';
104
             $output .= '<table><caption>Audio</caption><tbody>';
118
             $output .= '<table><caption>Audio</caption><tbody>';
105
-            foreach($this->parsers['audio'] as $index => $ap) {
106
-                $output .= sprintf('<tr><td>#%d: &nbsp;</td><td>%s</td></tr>',intval($index+1),$ap->output());
119
+            foreach ($this->parsers['audio'] as $index => $ap) {
120
+                $output .= sprintf('<tr><td>#%d: &nbsp;</td><td>%s</td></tr>', intval($index+1), $ap->output());
107
             }
121
             }
108
             $output .= '</tbody></table>';
122
             $output .= '</tbody></table>';
109
         }
123
         }
110
-        if (isset($this->parsers['text'])){
124
+        if (isset($this->parsers['text'])) {
111
             // subtitles table will be printed below the previous table
125
             // subtitles table will be printed below the previous table
112
             $output .= '<br />';
126
             $output .= '<br />';
113
             $output .= '<table><caption>Subtitles</caption><tbody>';
127
             $output .= '<table><caption>Subtitles</caption><tbody>';
114
-            foreach($this->parsers['text'] as $index => $tp) {
115
-                $output .= sprintf('<tr><td>#%d: &nbsp;</td><td>%s</td></tr>',intval($index+1),$tp->output());
128
+            foreach ($this->parsers['text'] as $index => $tp) {
129
+                $output .= sprintf('<tr><td>#%d: &nbsp;</td><td>%s</td></tr>', intval($index+1), $tp->output());
116
             }
130
             }
117
             $output .= '</tbody></table>';
131
             $output .= '</tbody></table>';
118
         }
132
         }
124
         return  $output;
138
         return  $output;
125
     }
139
     }
126
 
140
 
127
-    public function output_raw() {
141
+    public function output_raw()
142
+    {
128
         $output = [];
143
         $output = [];
129
         $sections = ['general', 'video', 'audio', 'text'];
144
         $sections = ['general', 'video', 'audio', 'text'];
130
 
145
 
131
-        foreach($sections as $section) {
146
+        foreach ($sections as $section) {
132
             if (isset($this->parsers[$section])) {
147
             if (isset($this->parsers[$section])) {
133
                 $output[$section] = [];
148
                 $output[$section] = [];
134
-                foreach($this->parsers[$section] as $index => $parser) {
149
+                foreach ($this->parsers[$section] as $index => $parser) {
135
                     $output[$section][$index] = $parser->output_raw();
150
                     $output[$section][$index] = $parser->output_raw();
136
                 }
151
                 }
137
             }
152
             }
141
 
156
 
142
     // strip escaped html tags
157
     // strip escaped html tags
143
     // this is not done for security, just to beautify things (html should already be escaped)
158
     // this is not done for security, just to beautify things (html should already be escaped)
144
-    public static function strip_escaped_tags($string) {
159
+    public static function strip_escaped_tags($string)
160
+    {
145
         // use the php function first
161
         // use the php function first
146
         $string = strip_tags($string);
162
         $string = strip_tags($string);
147
 
163
 
149
         $lt = '&lt;|&#60;|<';
165
         $lt = '&lt;|&#60;|<';
150
 
166
 
151
         // there is no opening tag, so don't go through the rest of the regexes
167
         // there is no opening tag, so don't go through the rest of the regexes
152
-        if (!preg_match("($lt)",$string))
168
+        if (!preg_match("($lt)", $string)) {
153
             return $string;
169
             return $string;
170
+        }
154
 
171
 
155
         $tag_match = "/(?:$lt)(?P<tag>(?:(?!$gt).)*)(?:$gt)/ims";
172
         $tag_match = "/(?:$lt)(?P<tag>(?:(?!$gt).)*)(?:$gt)/ims";
156
 
173
 
157
         // this should match and remove tags
174
         // this should match and remove tags
158
-        $string = preg_replace($tag_match,'',$string);
175
+        $string = preg_replace($tag_match, '', $string);
159
 
176
 
160
         return $string;
177
         return $string;
161
     }
178
     }
162
 
179
 
163
-    protected function new_mediainfo() {
180
+    protected function new_mediainfo()
181
+    {
164
         $this->output .= $this->output(false);
182
         $this->output .= $this->output(false);
165
         $this->parsed_lines = [];
183
         $this->parsed_lines = [];
166
-        foreach(array_keys($this->parsers) as $key) {
167
-            if ($key != static::GENERIC_PARSER)
184
+        foreach (array_keys($this->parsers) as $key) {
185
+            if ($key != static::GENERIC_PARSER) {
168
                 unset($this->parsers[$key]);
186
                 unset($this->parsers[$key]);
187
+            }
169
         }
188
         }
170
     }
189
     }
171
-
172
 }
190
 }
173
 
191
 
174
-class SectionParser {
192
+class SectionParser
193
+{
175
     protected $lines;
194
     protected $lines;
176
     protected $index;
195
     protected $index;
177
 
196
 
178
 
197
 
179
-    public function __construct(&$lines=[],&$i=0) {
180
-        $this->set_lines($lines,$i);
198
+    public function __construct(&$lines = [], &$i = 0)
199
+    {
200
+        $this->set_lines($lines, $i);
181
     }
201
     }
182
-    public function set_lines(&$lines=[],&$i=0){
202
+    public function set_lines(&$lines = [], &$i = 0)
203
+    {
183
         $this->lines = &$lines;
204
         $this->lines = &$lines;
184
         $this->index = &$i;
205
         $this->index = &$i;
185
     }
206
     }
186
     // should always return the read line
207
     // should always return the read line
187
-    public function parse_line(){
208
+    public function parse_line()
209
+    {
188
         if (!isset($this->lines[$this->index])) {
210
         if (!isset($this->lines[$this->index])) {
189
             return null;
211
             return null;
190
         }
212
         }
191
         $line = $this->lines[$this->index++];
213
         $line = $this->lines[$this->index++];
192
         $pair = static::property_value_pair($line);
214
         $pair = static::property_value_pair($line);
193
-        $this->handle_cases($pair['property'],$pair['value']);
215
+        $this->handle_cases($pair['property'], $pair['value']);
194
         return $line;
216
         return $line;
195
     }
217
     }
196
-    public function output() {
197
-
218
+    public function output()
219
+    {
198
     }
220
     }
199
-    protected function handle_cases($property, $value) {
200
-
221
+    protected function handle_cases($property, $value)
222
+    {
201
     }
223
     }
202
-    public static function section_name($string) {
203
-        if (!$string) return false;
224
+    public static function section_name($string)
225
+    {
226
+        if (!$string) {
227
+            return false;
228
+        }
204
         $mistart="/^(?:general$|unique id|complete name)/i";
229
         $mistart="/^(?:general$|unique id|complete name)/i";
205
-        if (preg_match($mistart, $string)) return ParseManager::MEDIAINFO_START;
206
-        $words = explode(' ',$string);
230
+        if (preg_match($mistart, $string)) {
231
+            return ParseManager::MEDIAINFO_START;
232
+        }
233
+        $words = explode(' ', $string);
207
         return strtolower($words[0]);
234
         return strtolower($words[0]);
208
     }
235
     }
209
-    public static function property_value_pair($string) {
236
+    public static function property_value_pair($string)
237
+    {
210
         $pair = explode(":", $string, 2);
238
         $pair = explode(":", $string, 2);
211
         return array('property'=>strtolower(trim($pair[0])),'value'=>trim($pair[1]??''));
239
         return array('property'=>strtolower(trim($pair[0])),'value'=>trim($pair[1]??''));
212
     }
240
     }
213
-    public static function strip_path($string) { // remove filepath
241
+    public static function strip_path($string)
242
+    {
243
+        // remove filepath
214
         $string = str_replace("\\", "/", $string);
244
         $string = str_replace("\\", "/", $string);
215
         $path_parts = pathinfo($string);
245
         $path_parts = pathinfo($string);
216
         return $path_parts['basename'];
246
         return $path_parts['basename'];
217
     }
247
     }
218
-    public static function parse_size($string) {
248
+    public static function parse_size($string)
249
+    {
219
         return str_replace(array('pixels', ' '), null, $string);
250
         return str_replace(array('pixels', ' '), null, $string);
220
     }
251
     }
221
-    protected static function table_head($caption) {
252
+    protected static function table_head($caption)
253
+    {
222
         return "<table class='nobr'><caption>$caption</caption><tbody>";
254
         return "<table class='nobr'><caption>$caption</caption><tbody>";
223
     }
255
     }
224
-    protected static function table_row($property,$value) {
225
-        if ($value)
256
+    protected static function table_row($property, $value)
257
+    {
258
+        if ($value) {
226
             return "<tr><td>$property:&nbsp;&nbsp;</td><td>$value</td></tr>";
259
             return "<tr><td>$property:&nbsp;&nbsp;</td><td>$value</td></tr>";
260
+        }
227
         return '';
261
         return '';
228
     }
262
     }
229
-    protected static function table_tail(){
263
+    protected static function table_tail()
264
+    {
230
         return '</tbody></table>';
265
         return '</tbody></table>';
231
     }
266
     }
232
-
233
 }
267
 }
234
 
268
 
235
-class AudioSectionParser extends SectionParser {
269
+class AudioSectionParser extends SectionParser
270
+{
236
     protected $audioformat;
271
     protected $audioformat;
237
     protected $audiobitrate;
272
     protected $audiobitrate;
238
     protected $audiochannels;
273
     protected $audiochannels;
243
     protected $form_audioformat;
278
     protected $form_audioformat;
244
     protected $form_audiochannels;
279
     protected $form_audiochannels;
245
 
280
 
246
-    protected function handle_cases($property,$value) {
281
+    protected function handle_cases($property, $value)
282
+    {
247
         switch ($property) {
283
         switch ($property) {
248
             case "format":
284
             case "format":
249
                 $this->audioformat = $value;
285
                 $this->audioformat = $value;
268
                 break;
304
                 break;
269
         }
305
         }
270
     }
306
     }
271
-    public function output() {
307
+    public function output()
308
+    {
272
         $this->process_vars();
309
         $this->process_vars();
273
         $output = $this->audiolang . ' ' . $this->channels() . ' ' . $this->format();
310
         $output = $this->audiolang . ' ' . $this->channels() . ' ' . $this->format();
274
         $output .= ($this->audiobitrate) ? " @ $this->audiobitrate" : '';
311
         $output .= ($this->audiobitrate) ? " @ $this->audiobitrate" : '';
275
         $output .= ($this->audiotitle) ? " ($this->audiotitle)" : '';
312
         $output .= ($this->audiotitle) ? " ($this->audiotitle)" : '';
276
         return $output;
313
         return $output;
277
     }
314
     }
278
-    public function output_raw() {
315
+    public function output_raw()
316
+    {
279
         $this->process_vars();
317
         $this->process_vars();
280
         $output = [];
318
         $output = [];
281
         $properties = [
319
         $properties = [
283
             'audiochannelpositions', 'audiotitle', 'audiolang', 'audioprofile',
321
             'audiochannelpositions', 'audiotitle', 'audiolang', 'audioprofile',
284
             'form_audioformat', 'form_audiochannels'
322
             'form_audioformat', 'form_audiochannels'
285
         ];
323
         ];
286
-        foreach($properties as $property) {
287
-            if ($this->$property) $output[$property] = $this->$property;
324
+        foreach ($properties as $property) {
325
+            if ($this->$property) {
326
+                $output[$property] = $this->$property;
327
+            }
288
         }
328
         }
289
         return $output;
329
         return $output;
290
     }
330
     }
291
-    protected function process_vars() {
331
+    protected function process_vars()
332
+    {
292
         $this->form_audioformat = $this->form_format();
333
         $this->form_audioformat = $this->form_format();
293
         $this->form_audiochannels = $this->form_channels();
334
         $this->form_audiochannels = $this->form_channels();
294
     }
335
     }
295
-    protected function format() {
336
+    protected function format()
337
+    {
296
         if (strtolower($this->audioformat) === 'mpeg audio') {
338
         if (strtolower($this->audioformat) === 'mpeg audio') {
297
             switch (strtolower($this->audioprofile)) {
339
             switch (strtolower($this->audioprofile)) {
298
                 case 'layer 3':
340
                 case 'layer 3':
305
         }
347
         }
306
         return $this->audioformat;
348
         return $this->audioformat;
307
     }
349
     }
308
-    protected function form_format() {
350
+    protected function form_format()
351
+    {
309
         // Not implemented: Real Audio, DTS-HD
352
         // Not implemented: Real Audio, DTS-HD
310
         switch (strtolower($this->format())) {
353
         switch (strtolower($this->format())) {
311
             case 'mp2':
354
             case 'mp2':
329
                     default:
372
                     default:
330
                         return 'DTS';
373
                         return 'DTS';
331
                 }
374
                 }
332
-            case 'flac':
375
+                // no break
376
+                case 'flac':
333
                 return 'FLAC';
377
                 return 'FLAC';
334
             case 'pcm':
378
             case 'pcm':
335
                 return 'PCM';
379
                 return 'PCM';
337
                 return 'WMA';
381
                 return 'WMA';
338
         }
382
         }
339
     }
383
     }
340
-    protected function channels() {
384
+    protected function channels()
385
+    {
341
         if (isset($this->audiochannels)) {
386
         if (isset($this->audiochannels)) {
342
             $chans = preg_replace('/^(\d).*$/', '$1', $this->audiochannels);
387
             $chans = preg_replace('/^(\d).*$/', '$1', $this->audiochannels);
343
 
388
 
344
-            if (isset($this->audiochannelpositions) && preg_match('/LFE/',
345
-                    $this->audiochannelpositions)) {
389
+            if (isset($this->audiochannelpositions) && preg_match(
390
+                '/LFE/',
391
+                $this->audiochannelpositions
392
+            )) {
346
                 $chans -= .9;
393
                 $chans -= .9;
347
             } else {
394
             } else {
348
                 $chans = $chans . '.0';
395
                 $chans = $chans . '.0';
351
             return $chans . 'ch';
398
             return $chans . 'ch';
352
         }
399
         }
353
     }
400
     }
354
-    protected function form_channels() {
401
+    protected function form_channels()
402
+    {
355
         return preg_replace('/ch/', '', $this->channels());
403
         return preg_replace('/ch/', '', $this->channels());
356
     }
404
     }
357
 }
405
 }
358
 
406
 
359
-class GeneralSectionParser extends SectionParser {
407
+class GeneralSectionParser extends SectionParser
408
+{
360
     public $filename;
409
     public $filename;
361
     protected $generalformat;
410
     protected $generalformat;
362
     protected $duration;
411
     protected $duration;
364
     protected $form_codec;
413
     protected $form_codec;
365
     protected $form_releasegroup;
414
     protected $form_releasegroup;
366
 
415
 
367
-    protected function handle_cases($property,$value) {
416
+    protected function handle_cases($property, $value)
417
+    {
368
         switch ($property) {
418
         switch ($property) {
369
             case "complete name":
419
             case "complete name":
370
                 // Remove autodetected urls
420
                 // Remove autodetected urls
384
                 break;
434
                 break;
385
         }
435
         }
386
     }
436
     }
387
-    public function output() {
437
+    public function output()
438
+    {
388
         $this->process_vars();
439
         $this->process_vars();
389
         $output = static::table_head('General');
440
         $output = static::table_head('General');
390
         $properties = [
441
         $properties = [
392
             'Runtime' => 'duration',
443
             'Runtime' => 'duration',
393
             'Size' => 'filesize'
444
             'Size' => 'filesize'
394
         ];
445
         ];
395
-        foreach($properties as $property => $value) {
396
-            $output .= static::table_row($property,$this->$value);
446
+        foreach ($properties as $property => $value) {
447
+            $output .= static::table_row($property, $this->$value);
397
         }
448
         }
398
         $output .= static::table_tail();
449
         $output .= static::table_tail();
399
         return  $output;
450
         return  $output;
400
     }
451
     }
401
-    public function output_raw() {
452
+    public function output_raw()
453
+    {
402
         $this->process_vars();
454
         $this->process_vars();
403
         $output = [];
455
         $output = [];
404
         $properties = [
456
         $properties = [
405
             'filename', 'generalformat', 'duration', 'filesize', 'form_codec',
457
             'filename', 'generalformat', 'duration', 'filesize', 'form_codec',
406
             'form_releasegroup'
458
             'form_releasegroup'
407
         ];
459
         ];
408
-        foreach($properties as $property) {
409
-            if ($this->$property) $output[$property] = $this->$property;
460
+        foreach ($properties as $property) {
461
+            if ($this->$property) {
462
+                $output[$property] = $this->$property;
463
+            }
410
         }
464
         }
411
         return $output;
465
         return $output;
412
     }
466
     }
413
-    protected function process_vars() {
467
+    protected function process_vars()
468
+    {
414
         switch (strtolower($this->generalformat)) {
469
         switch (strtolower($this->generalformat)) {
415
             case 'mpeg-ts':
470
             case 'mpeg-ts':
416
                 $this->form_codec = 'MPEG-TS';
471
                 $this->form_codec = 'MPEG-TS';
421
                 break;
476
                 break;
422
         }
477
         }
423
         $matches = [];
478
         $matches = [];
424
-        preg_match('/(?:^|.*\\|\/)\[(.*?)\].*$/',
425
-            $this->filename, $matches);
479
+        preg_match(
480
+            '/(?:^|.*\\|\/)\[(.*?)\].*$/',
481
+            $this->filename,
482
+            $matches
483
+        );
426
         $this->form_releasegroup = $matches ? $matches[1] : '';
484
         $this->form_releasegroup = $matches ? $matches[1] : '';
427
     }
485
     }
428
 }
486
 }
429
 
487
 
430
-class TextSectionParser extends SectionParser {
488
+class TextSectionParser extends SectionParser
489
+{
431
     protected $title;
490
     protected $title;
432
     protected $language;
491
     protected $language;
433
     protected $format;
492
     protected $format;
435
     protected $processed_language;
494
     protected $processed_language;
436
     protected $form_format;
495
     protected $form_format;
437
 
496
 
438
-    protected function handle_cases($property,$value) {
497
+    protected function handle_cases($property, $value)
498
+    {
439
         switch ($property) {
499
         switch ($property) {
440
             case 'title':
500
             case 'title':
441
                 $this->title = $value;
501
                 $this->title = $value;
451
                 break;
511
                 break;
452
         }
512
         }
453
     }
513
     }
454
-    public function output() {
514
+    public function output()
515
+    {
455
         $this->process_vars();
516
         $this->process_vars();
456
         $language = $this->processed_language;
517
         $language = $this->processed_language;
457
         $output = "$language ($this->format)";
518
         $output = "$language ($this->format)";
458
-        if ($this->title) $output .= " ($this->title)";
459
-        if ($this->default) $output .= ' (default)';
519
+        if ($this->title) {
520
+            $output .= " ($this->title)";
521
+        }
522
+        if ($this->default) {
523
+            $output .= ' (default)';
524
+        }
460
         return $output;
525
         return $output;
461
     }
526
     }
462
-    public function output_raw() {
527
+    public function output_raw()
528
+    {
463
         $this->process_vars();
529
         $this->process_vars();
464
         $output = [];
530
         $output = [];
465
         $properties = [
531
         $properties = [
466
             'title', 'language', 'format', 'default', 'processed_language',
532
             'title', 'language', 'format', 'default', 'processed_language',
467
             'form_format'
533
             'form_format'
468
         ];
534
         ];
469
-        foreach($properties as $property) {
470
-            if ($this->$property) $output[$property] = $this->$property;
535
+        foreach ($properties as $property) {
536
+            if ($this->$property) {
537
+                $output[$property] = $this->$property;
538
+            }
471
         }
539
         }
472
         return $output;
540
         return $output;
473
     }
541
     }
474
-    protected function process_vars() {
542
+    protected function process_vars()
543
+    {
475
         $this->processed_language = ($this->language) ?
544
         $this->processed_language = ($this->language) ?
476
             $this->language : 'Unknown';
545
             $this->language : 'Unknown';
477
         $this->form_format = 'Softsubbed';
546
         $this->form_format = 'Softsubbed';
478
     }
547
     }
479
 }
548
 }
480
 
549
 
481
-class VideoSectionParser extends SectionParser {
550
+class VideoSectionParser extends SectionParser
551
+{
482
     protected $videoformat;
552
     protected $videoformat;
483
     protected $videoformatversion;
553
     protected $videoformatversion;
484
     protected $codec;
554
     protected $codec;
499
     protected $form_codec;
569
     protected $form_codec;
500
     protected $form_resolution;
570
     protected $form_resolution;
501
 
571
 
502
-    protected function handle_cases($property,$value) {
572
+    protected function handle_cases($property, $value)
573
+    {
503
         switch ($property) {
574
         switch ($property) {
504
             case "format":
575
             case "format":
505
                 $this->videoformat = $value;
576
                 $this->videoformat = $value;
546
                 break;
617
                 break;
547
         }
618
         }
548
     }
619
     }
549
-    public function output() {
620
+    public function output()
621
+    {
550
         $this->process_vars();
622
         $this->process_vars();
551
         $output = static::table_head('Video');
623
         $output = static::table_head('Video');
552
         $properties = [
624
         $properties = [
558
             'Bit rate' => 'bitrate',
630
             'Bit rate' => 'bitrate',
559
             'BPP' => 'bpp'
631
             'BPP' => 'bpp'
560
         ];
632
         ];
561
-        foreach($properties as $property => $value) {
562
-            $output .= static::table_row($property,$this->$value);
633
+        foreach ($properties as $property => $value) {
634
+            $output .= static::table_row($property, $this->$value);
563
         }
635
         }
564
         $output .= static::table_tail();
636
         $output .= static::table_tail();
565
         return  $output;
637
         return  $output;
566
     }
638
     }
567
-    public function output_raw() {
639
+    public function output_raw()
640
+    {
568
         $this->process_vars();
641
         $this->process_vars();
569
         $output = [];
642
         $output = [];
570
         $properties = [
643
         $properties = [
574
             'processed_codec', 'processed_resolution', 'processed_framerate',
647
             'processed_codec', 'processed_resolution', 'processed_framerate',
575
             'form_codec', 'form_resolution'
648
             'form_codec', 'form_resolution'
576
         ];
649
         ];
577
-        foreach($properties as $property) {
578
-            if ($this->$property) $output[$property] = $this->$property;
650
+        foreach ($properties as $property) {
651
+            if ($this->$property) {
652
+                $output[$property] = $this->$property;
653
+            }
579
         }
654
         }
580
         return $output;
655
         return $output;
581
     }
656
     }
582
-    protected function process_vars() {
657
+    protected function process_vars()
658
+    {
583
         $this->processed_codec = $this->compute_codec();
659
         $this->processed_codec = $this->compute_codec();
584
         $this->processed_resolution = ($this->width) ?
660
         $this->processed_resolution = ($this->width) ?
585
             $this->width . 'x' . $this->height : '';
661
             $this->width . 'x' . $this->height : '';
589
         $this->form_codec = $this->compute_form_codec();
665
         $this->form_codec = $this->compute_form_codec();
590
         $this->form_resolution = $this->compute_form_resolution();
666
         $this->form_resolution = $this->compute_form_resolution();
591
     }
667
     }
592
-    protected function compute_codec() {
668
+    protected function compute_codec()
669
+    {
593
         switch (strtolower($this->videoformat)) {
670
         switch (strtolower($this->videoformat)) {
594
             case "mpeg video":
671
             case "mpeg video":
595
                 switch (strtolower($this->videoformatversion)) {
672
                 switch (strtolower($this->videoformatversion)) {
615
 
692
 
616
         $chk = strtolower($this->codec);
693
         $chk = strtolower($this->codec);
617
         $wl = strtolower($this->writinglibrary);
694
         $wl = strtolower($this->writinglibrary);
618
-        if (($chk === "v_mpeg4/iso/avc" || $chk === "avc1") && strpos($wl, "x264 core") === FALSE) {
695
+        if (($chk === "v_mpeg4/iso/avc" || $chk === "avc1") && strpos($wl, "x264 core") === false) {
619
             return "H264";
696
             return "H264";
620
-        } else if (($chk === "v_mpeg4/iso/avc" || $chk === "avc1") && strpos($wl, "x264 core") > -1)  {
697
+        } elseif (($chk === "v_mpeg4/iso/avc" || $chk === "avc1") && strpos($wl, "x264 core") > -1) {
621
             return "x264";
698
             return "x264";
622
-        } else if (strtolower($this->videoformat) === "avc" && strpos($wl, "x264 core") === FALSE) {
699
+        } elseif (strtolower($this->videoformat) === "avc" && strpos($wl, "x264 core") === false) {
623
             return "H264";
700
             return "H264";
624
         }
701
         }
625
 
702
 
626
-        if (($chk === 'v_mpegh/iso/hevc') || ($wl === 'hevc'))
703
+        if (($chk === 'v_mpegh/iso/hevc') || ($wl === 'hevc')) {
627
             return 'H265';
704
             return 'H265';
705
+        }
628
     }
706
     }
629
-    protected function compute_form_codec() {
707
+    protected function compute_form_codec()
708
+    {
630
         // Not implemented: DVD5, DVD9, WMV, Real Video
709
         // Not implemented: DVD5, DVD9, WMV, Real Video
631
         // MPEG-TS set as GeneralSectionParser::$form_codec if found
710
         // MPEG-TS set as GeneralSectionParser::$form_codec if found
632
         // MPEG-PS sets GeneralSectionParser::$form_codec to blank form value
711
         // MPEG-PS sets GeneralSectionParser::$form_codec to blank form value
633
         //   so DVD5 or DVD9 is selected manually.
712
         //   so DVD5 or DVD9 is selected manually.
634
         $codec = $this->compute_codec();
713
         $codec = $this->compute_codec();
635
-        switch(strtolower($codec)) {
714
+        switch (strtolower($codec)) {
636
             case 'x264':
715
             case 'x264':
637
             case 'h264':
716
             case 'h264':
638
                 return strtolower($this->bitdepth) == '10 bits' ?
717
                 return strtolower($this->bitdepth) == '10 bits' ?
649
             case 'mpeg-2':
728
             case 'mpeg-2':
650
                 return 'MPEG-2';
729
                 return 'MPEG-2';
651
         }
730
         }
652
-        switch(strtolower($this->codec)) {
731
+        switch (strtolower($this->codec)) {
653
             case 'wmv3':
732
             case 'wmv3':
654
                 return 'VC-1';
733
                 return 'VC-1';
655
             case 'mp43':
734
             case 'mp43':
656
                 return 'MPEG-4 v3';
735
                 return 'MPEG-4 v3';
657
         }
736
         }
658
-        switch(strtolower($this->videoformat)) {
737
+        switch (strtolower($this->videoformat)) {
659
             case 'vc-1':
738
             case 'vc-1':
660
                 return 'VC-1';
739
                 return 'VC-1';
661
             case 's-mpeg 4 v3':
740
             case 's-mpeg 4 v3':
662
                 return 'MPEG-4 v3';
741
                 return 'MPEG-4 v3';
663
         }
742
         }
664
     }
743
     }
665
-    protected function compute_form_resolution() {
744
+    protected function compute_form_resolution()
745
+    {
666
         global $Resolutions;
746
         global $Resolutions;
667
         $closest = null;
747
         $closest = null;
668
         if (isset($this->height)) {
748
         if (isset($this->height)) {
669
             $resolutions = $Resolutions;
749
             $resolutions = $Resolutions;
670
-            foreach($resolutions as $resolution) {
750
+            foreach ($resolutions as $resolution) {
671
                 if (!isset($closest) || abs($this->height - $resolution) <
751
                 if (!isset($closest) || abs($this->height - $resolution) <
672
                         abs($this->height - $closest)) {
752
                         abs($this->height - $closest)) {
673
                     $closest = $resolution;
753
                     $closest = $resolution;

+ 430
- 416
classes/misc.class.php View File

1
-<?
2
-class Misc {
3
-  /**
4
-   * Send an email.
5
-   *
6
-   * @param string $To the email address to send it to.
7
-   * @param string $Subject
8
-   * @param string $Body
9
-   * @param string $From The user part of the user@SITE_DOMAIN email address.
10
-   * @param string $ContentType text/plain or text/html
11
-   */
12
-  public static function send_email($To, $Subject, $Body, $From = 'noreply', $ContentType = 'text/plain') {
13
-    $Headers = 'MIME-Version: 1.0'."\r\n";
14
-    $Headers .= 'Content-type: '.$ContentType.'; charset=iso-8859-1'."\r\n";
15
-    $Headers .= 'From: '.SITE_NAME.' <'.$From.'@'.SITE_DOMAIN.'>'."\r\n";
16
-    $Headers .= 'Reply-To: '.$From.'@'.SITE_DOMAIN."\r\n";
17
-    $Headers .= 'X-Mailer: Project Gazelle'."\r\n";
18
-    $Headers .= 'Message-Id: <'.Users::make_secret().'@'.SITE_DOMAIN.">\r\n";
19
-    $Headers .= 'X-Priority: 3'."\r\n";
20
-    // check if email is enabled
21
-    if (FEATURE_SEND_EMAIL) {
22
-      mail($To, $Subject, $Body, $Headers, "-f $From@".SITE_DOMAIN);
1
+<?php
2
+class Misc
3
+{
4
+    /**
5
+     * Send an email.
6
+     *
7
+     * @param string $To the email address to send it to.
8
+     * @param string $Subject
9
+     * @param string $Body
10
+     * @param string $From The user part of the user@SITE_DOMAIN email address.
11
+     * @param string $ContentType text/plain or text/html
12
+     */
13
+    public static function send_email($To, $Subject, $Body, $From = 'noreply', $ContentType = 'text/plain')
14
+    {
15
+        $Headers = 'MIME-Version: 1.0'."\r\n";
16
+        $Headers .= 'Content-type: '.$ContentType.'; charset=iso-8859-1'."\r\n";
17
+        $Headers .= 'From: '.SITE_NAME.' <'.$From.'@'.SITE_DOMAIN.'>'."\r\n";
18
+        $Headers .= 'Reply-To: '.$From.'@'.SITE_DOMAIN."\r\n";
19
+        $Headers .= 'X-Mailer: Project Gazelle'."\r\n";
20
+        $Headers .= 'Message-Id: <'.Users::make_secret().'@'.SITE_DOMAIN.">\r\n";
21
+        $Headers .= 'X-Priority: 3'."\r\n";
22
+        // check if email is enabled
23
+        if (FEATURE_SEND_EMAIL) {
24
+            mail($To, $Subject, $Body, $Headers, "-f $From@".SITE_DOMAIN);
25
+        }
23
     }
26
     }
24
-  }
25
-
26
-
27
-  /**
28
-   * Sanitize a string to be allowed as a filename.
29
-   *
30
-   * @param string $EscapeStr the string to escape
31
-   * @return the string with all banned characters removed.
32
-   */
33
-  public static function file_string($EscapeStr) {
34
-    return str_replace(array('"', '*', '/', ':', '<', '>', '?', '\\', '|'), '', $EscapeStr);
35
-  }
36
-
37
-
38
-  /**
39
-   * Sends a PM from $FromId to $ToId.
40
-   *
41
-   * @param string $ToID ID of user to send PM to. If $ToID is an array and $ConvID is empty, a message will be sent to multiple users.
42
-   * @param string $FromID ID of user to send PM from, 0 to send from system
43
-   * @param string $Subject
44
-   * @param string $Body
45
-   * @param int $ConvID The conversation the message goes in. Leave blank to start a new conversation.
46
-   * @return
47
-   */
48
-  public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '') {
49
-    global $Time;
50
-    $UnescapedSubject = $Subject;
51
-    $UnescapedBody = $Body;
52
-    $Subject = db_string($Subject);
53
-    $Body = Crypto::encrypt(substr($Body, 0, 49135)); // 49135 -> encryption -> 65536 (max length in mysql)
54
-    if ($ToID == 0) {
55
-      // Don't allow users to send messages to the system
56
-      return;
27
+
28
+
29
+    /**
30
+     * Sanitize a string to be allowed as a filename.
31
+     *
32
+     * @param string $EscapeStr the string to escape
33
+     * @return the string with all banned characters removed.
34
+     */
35
+    public static function file_string($EscapeStr)
36
+    {
37
+        return str_replace(array('"', '*', '/', ':', '<', '>', '?', '\\', '|'), '', $EscapeStr);
57
     }
38
     }
58
 
39
 
59
-    $QueryID = G::$DB->get_query_id();
60
 
40
 
61
-    if ($ConvID == '') {
62
-      // Create a new conversation.
63
-      G::$DB->query("
41
+    /**
42
+     * Sends a PM from $FromId to $ToId.
43
+     *
44
+     * @param string $ToID ID of user to send PM to. If $ToID is an array and $ConvID is empty, a message will be sent to multiple users.
45
+     * @param string $FromID ID of user to send PM from, 0 to send from system
46
+     * @param string $Subject
47
+     * @param string $Body
48
+     * @param int $ConvID The conversation the message goes in. Leave blank to start a new conversation.
49
+     * @return
50
+     */
51
+    public static function send_pm($ToID, $FromID, $Subject, $Body, $ConvID = '')
52
+    {
53
+        global $Time;
54
+        $UnescapedSubject = $Subject;
55
+        $UnescapedBody = $Body;
56
+        $Subject = db_string($Subject);
57
+        $Body = Crypto::encrypt(substr($Body, 0, 49135)); // 49135 -> encryption -> 65536 (max length in mysql)
58
+        if ($ToID == 0) {
59
+            // Don't allow users to send messages to the system
60
+            return;
61
+        }
62
+
63
+        $QueryID = G::$DB->get_query_id();
64
+
65
+        if ($ConvID == '') {
66
+            // Create a new conversation.
67
+            G::$DB->query("
64
         INSERT INTO pm_conversations (Subject)
68
         INSERT INTO pm_conversations (Subject)
65
         VALUES ('$Subject')");
69
         VALUES ('$Subject')");
66
-      $ConvID = G::$DB->inserted_id();
67
-      G::$DB->query("
70
+            $ConvID = G::$DB->inserted_id();
71
+            G::$DB->query("
68
         INSERT INTO pm_conversations_users
72
         INSERT INTO pm_conversations_users
69
           (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)
73
           (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)
70
         VALUES
74
         VALUES
71
           ('$ToID', '$ConvID', '1','0', NOW(), NOW(), '1')");
75
           ('$ToID', '$ConvID', '1','0', NOW(), NOW(), '1')");
72
-      if ($FromID == $ToID) {
73
-        G::$DB->query("
76
+            if ($FromID == $ToID) {
77
+                G::$DB->query("
74
           UPDATE pm_conversations_users
78
           UPDATE pm_conversations_users
75
             SET InSentbox = '1'
79
             SET InSentbox = '1'
76
-            WHERE ConvID = '$ConvID'"
77
-        );
78
-      }
79
-      elseif ($FromID != 0) {
80
-        G::$DB->query("
80
+            WHERE ConvID = '$ConvID'");
81
+            } elseif ($FromID != 0) {
82
+                G::$DB->query("
81
           INSERT INTO pm_conversations_users
83
           INSERT INTO pm_conversations_users
82
             (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)
84
             (UserID, ConvID, InInbox, InSentbox, SentDate, ReceivedDate, UnRead)
83
           VALUES
85
           VALUES
84
             ('$FromID', '$ConvID', '0','1', NOW(), NOW(), '0')");
86
             ('$FromID', '$ConvID', '0','1', NOW(), NOW(), '0')");
85
-      }
86
-      $ToID = array($ToID);
87
-    } else {
88
-      // Update the pre-existing conversations.
89
-      G::$DB->query("
87
+            }
88
+            $ToID = array($ToID);
89
+        } else {
90
+            // Update the pre-existing conversations.
91
+            G::$DB->query("
90
         UPDATE pm_conversations_users
92
         UPDATE pm_conversations_users
91
         SET
93
         SET
92
           InInbox = '1',
94
           InInbox = '1',
95
         WHERE UserID IN (".implode(',', $ToID).")
97
         WHERE UserID IN (".implode(',', $ToID).")
96
           AND ConvID = '$ConvID'");
98
           AND ConvID = '$ConvID'");
97
 
99
 
98
-      G::$DB->query("
100
+            G::$DB->query("
99
         UPDATE pm_conversations_users
101
         UPDATE pm_conversations_users
100
         SET
102
         SET
101
           InSentbox = '1',
103
           InSentbox = '1',
102
           SentDate = NOW()
104
           SentDate = NOW()
103
         WHERE UserID = '$FromID'
105
         WHERE UserID = '$FromID'
104
           AND ConvID = '$ConvID'");
106
           AND ConvID = '$ConvID'");
105
-    }
107
+        }
106
 
108
 
107
-    // Now that we have a $ConvID for sure, send the message.
108
-    G::$DB->query("
109
+        // Now that we have a $ConvID for sure, send the message.
110
+        G::$DB->query("
109
       INSERT INTO pm_messages
111
       INSERT INTO pm_messages
110
         (SenderID, ConvID, SentDate, Body)
112
         (SenderID, ConvID, SentDate, Body)
111
       VALUES
113
       VALUES
112
         ('$FromID', '$ConvID', NOW(), '$Body')");
114
         ('$FromID', '$ConvID', NOW(), '$Body')");
113
 
115
 
114
-    // Update the cached new message count.
115
-    foreach ($ToID as $ID) {
116
-      G::$DB->query("
116
+        // Update the cached new message count.
117
+        foreach ($ToID as $ID) {
118
+            G::$DB->query("
117
         SELECT COUNT(ConvID)
119
         SELECT COUNT(ConvID)
118
         FROM pm_conversations_users
120
         FROM pm_conversations_users
119
         WHERE UnRead = '1'
121
         WHERE UnRead = '1'
120
           AND UserID = '$ID'
122
           AND UserID = '$ID'
121
           AND InInbox = '1'");
123
           AND InInbox = '1'");
122
-      list($UnRead) = G::$DB->next_record();
123
-      G::$Cache->cache_value("inbox_new_$ID", $UnRead);
124
-    }
124
+            list($UnRead) = G::$DB->next_record();
125
+            G::$Cache->cache_value("inbox_new_$ID", $UnRead);
126
+        }
125
 
127
 
126
-    G::$DB->query("
128
+        G::$DB->query("
127
       SELECT Username
129
       SELECT Username
128
       FROM users_main
130
       FROM users_main
129
       WHERE ID = '$FromID'");
131
       WHERE ID = '$FromID'");
130
-    list($SenderName) = G::$DB->next_record();
131
-    foreach ($ToID as $ID) {
132
-      G::$DB->query("
132
+        list($SenderName) = G::$DB->next_record();
133
+        foreach ($ToID as $ID) {
134
+            G::$DB->query("
133
         SELECT COUNT(ConvID)
135
         SELECT COUNT(ConvID)
134
         FROM pm_conversations_users
136
         FROM pm_conversations_users
135
         WHERE UnRead = '1'
137
         WHERE UnRead = '1'
136
           AND UserID = '$ID'
138
           AND UserID = '$ID'
137
           AND InInbox = '1'");
139
           AND InInbox = '1'");
138
-      list($UnRead) = G::$DB->next_record();
139
-      G::$Cache->cache_value("inbox_new_$ID", $UnRead);
140
-    }
140
+            list($UnRead) = G::$DB->next_record();
141
+            G::$Cache->cache_value("inbox_new_$ID", $UnRead);
142
+        }
143
+
144
+        G::$DB->set_query_id($QueryID);
141
 
145
 
142
-    G::$DB->set_query_id($QueryID);
143
-
144
-    return $ConvID;
145
-  }
146
-
147
-  /**
148
-   * Create thread function, things should already be escaped when sent here.
149
-   *
150
-   * @param int $ForumID
151
-   * @param int $AuthorID ID of the user creating the post.
152
-   * @param string $Title
153
-   * @param string $PostBody
154
-   * @return -1 on error, -2 on user not existing, thread id on success.
155
-   */
156
-  public static function create_thread($ForumID, $AuthorID, $Title, $PostBody) {
157
-    global $Time;
158
-    if (!$ForumID || !$AuthorID || !is_number($AuthorID) || !$Title || !$PostBody) {
159
-      return -1;
146
+        return $ConvID;
160
     }
147
     }
161
 
148
 
162
-    $QueryID = G::$DB->get_query_id();
149
+    /**
150
+     * Create thread function, things should already be escaped when sent here.
151
+     *
152
+     * @param int $ForumID
153
+     * @param int $AuthorID ID of the user creating the post.
154
+     * @param string $Title
155
+     * @param string $PostBody
156
+     * @return -1 on error, -2 on user not existing, thread id on success.
157
+     */
158
+    public static function create_thread($ForumID, $AuthorID, $Title, $PostBody)
159
+    {
160
+        global $Time;
161
+        if (!$ForumID || !$AuthorID || !is_number($AuthorID) || !$Title || !$PostBody) {
162
+            return -1;
163
+        }
164
+
165
+        $QueryID = G::$DB->get_query_id();
163
 
166
 
164
-    G::$DB->query("
167
+        G::$DB->query("
165
       SELECT Username
168
       SELECT Username
166
       FROM users_main
169
       FROM users_main
167
       WHERE ID = $AuthorID");
170
       WHERE ID = $AuthorID");
168
-    if (!G::$DB->has_results()) {
169
-      G::$DB->set_query_id($QueryID);
170
-      return -2;
171
-    }
172
-    list($AuthorName) = G::$DB->next_record();
171
+        if (!G::$DB->has_results()) {
172
+            G::$DB->set_query_id($QueryID);
173
+            return -2;
174
+        }
175
+        list($AuthorName) = G::$DB->next_record();
173
 
176
 
174
-    $ThreadInfo = [];
175
-    $ThreadInfo['IsLocked'] = 0;
176
-    $ThreadInfo['IsSticky'] = 0;
177
+        $ThreadInfo = [];
178
+        $ThreadInfo['IsLocked'] = 0;
179
+        $ThreadInfo['IsSticky'] = 0;
177
 
180
 
178
-    G::$DB->query("
181
+        G::$DB->query("
179
       INSERT INTO forums_topics
182
       INSERT INTO forums_topics
180
         (Title, AuthorID, ForumID, LastPostTime, LastPostAuthorID, CreatedTime)
183
         (Title, AuthorID, ForumID, LastPostTime, LastPostAuthorID, CreatedTime)
181
       VALUES
184
       VALUES
182
         ('$Title', '$AuthorID', '$ForumID', NOW(), '$AuthorID', NOW())");
185
         ('$Title', '$AuthorID', '$ForumID', NOW(), '$AuthorID', NOW())");
183
-    $TopicID = G::$DB->inserted_id();
184
-    $Posts = 1;
186
+        $TopicID = G::$DB->inserted_id();
187
+        $Posts = 1;
185
 
188
 
186
-    G::$DB->query("
189
+        G::$DB->query("
187
       INSERT INTO forums_posts
190
       INSERT INTO forums_posts
188
         (TopicID, AuthorID, AddedTime, Body)
191
         (TopicID, AuthorID, AddedTime, Body)
189
       VALUES
192
       VALUES
190
         ('$TopicID', '$AuthorID', NOW(), '$PostBody')");
193
         ('$TopicID', '$AuthorID', NOW(), '$PostBody')");
191
-    $PostID = G::$DB->inserted_id();
194
+        $PostID = G::$DB->inserted_id();
192
 
195
 
193
-    G::$DB->query("
196
+        G::$DB->query("
194
       UPDATE forums
197
       UPDATE forums
195
       SET
198
       SET
196
         NumPosts  = NumPosts + 1,
199
         NumPosts  = NumPosts + 1,
201
         LastPostTime = NOW()
204
         LastPostTime = NOW()
202
       WHERE ID = '$ForumID'");
205
       WHERE ID = '$ForumID'");
203
 
206
 
204
-    G::$DB->query("
207
+        G::$DB->query("
205
       UPDATE forums_topics
208
       UPDATE forums_topics
206
       SET
209
       SET
207
         NumPosts = NumPosts + 1,
210
         NumPosts = NumPosts + 1,
210
         LastPostTime = NOW()
213
         LastPostTime = NOW()
211
       WHERE ID = '$TopicID'");
214
       WHERE ID = '$TopicID'");
212
 
215
 
213
-    // Bump this topic to head of the cache
214
-    list($Forum,,, $Stickies) = G::$Cache->get_value("forums_$ForumID");
215
-    if (!empty($Forum)) {
216
-      if (count($Forum) == TOPICS_PER_PAGE && $Stickies < TOPICS_PER_PAGE) {
217
-        array_pop($Forum);
218
-      }
219
-      G::$DB->query("
216
+        // Bump this topic to head of the cache
217
+        list($Forum, , , $Stickies) = G::$Cache->get_value("forums_$ForumID");
218
+        if (!empty($Forum)) {
219
+            if (count($Forum) == TOPICS_PER_PAGE && $Stickies < TOPICS_PER_PAGE) {
220
+                array_pop($Forum);
221
+            }
222
+            G::$DB->query("
220
         SELECT IsLocked, IsSticky, NumPosts
223
         SELECT IsLocked, IsSticky, NumPosts
221
         FROM forums_topics
224
         FROM forums_topics
222
         WHERE ID ='$TopicID'");
225
         WHERE ID ='$TopicID'");
223
-      list($IsLocked, $IsSticky, $NumPosts) = G::$DB->next_record();
224
-      $Part1 = array_slice($Forum, 0, $Stickies, true); //Stickys
225
-      $Part2 = array(
226
-        $TopicID => array(
227
-          'ID' => $TopicID,
228
-          'Title' => $Title,
229
-          'AuthorID' => $AuthorID,
230
-          'IsLocked' => $IsLocked,
231
-          'IsSticky' => $IsSticky,
232
-          'NumPosts' => $NumPosts,
233
-          'LastPostID' => $PostID,
234
-          'LastPostTime' => sqltime(),
235
-          'LastPostAuthorID' => $AuthorID,
236
-          )
237
-        ); //Bumped thread
238
-      $Part3 = array_slice($Forum, $Stickies, TOPICS_PER_PAGE, true); //Rest of page
239
-      if ($Stickies > 0) {
240
-        $Part1 = array_slice($Forum, 0, $Stickies, true); //Stickies
241
-        $Part3 = array_slice($Forum, $Stickies, TOPICS_PER_PAGE - $Stickies - 1, true); //Rest of page
242
-      } else {
243
-        $Part1 = [];
244
-        $Part3 = $Forum;
245
-      }
246
-      if (is_null($Part1)) {
247
-        $Part1 = [];
248
-      }
249
-      if (is_null($Part3)) {
250
-        $Part3 = [];
251
-      }
252
-      $Forum = $Part1 + $Part2 + $Part3;
253
-      G::$Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
226
+            list($IsLocked, $IsSticky, $NumPosts) = G::$DB->next_record();
227
+            $Part1 = array_slice($Forum, 0, $Stickies, true); //Stickys
228
+            $Part2 = array(
229
+            $TopicID => array(
230
+              'ID' => $TopicID,
231
+              'Title' => $Title,
232
+              'AuthorID' => $AuthorID,
233
+              'IsLocked' => $IsLocked,
234
+              'IsSticky' => $IsSticky,
235
+              'NumPosts' => $NumPosts,
236
+              'LastPostID' => $PostID,
237
+              'LastPostTime' => sqltime(),
238
+              'LastPostAuthorID' => $AuthorID,
239
+            )
240
+            ); //Bumped thread
241
+            $Part3 = array_slice($Forum, $Stickies, TOPICS_PER_PAGE, true); //Rest of page
242
+            if ($Stickies > 0) {
243
+                $Part1 = array_slice($Forum, 0, $Stickies, true); //Stickies
244
+                $Part3 = array_slice($Forum, $Stickies, TOPICS_PER_PAGE - $Stickies - 1, true); //Rest of page
245
+            } else {
246
+                $Part1 = [];
247
+                $Part3 = $Forum;
248
+            }
249
+            if (is_null($Part1)) {
250
+                $Part1 = [];
251
+            }
252
+            if (is_null($Part3)) {
253
+                $Part3 = [];
254
+            }
255
+            $Forum = $Part1 + $Part2 + $Part3;
256
+            G::$Cache->cache_value("forums_$ForumID", array($Forum, '', 0, $Stickies), 0);
257
+        }
258
+
259
+        //Update the forum root
260
+        G::$Cache->begin_transaction('forums_list');
261
+        $UpdateArray = array(
262
+        'NumPosts' => '+1',
263
+        'NumTopics' => '+1',
264
+        'LastPostID' => $PostID,
265
+        'LastPostAuthorID' => $AuthorID,
266
+        'LastPostTopicID' => $TopicID,
267
+        'LastPostTime' => sqltime(),
268
+        'Title' => $Title,
269
+        'IsLocked' => $ThreadInfo['IsLocked'],
270
+        'IsSticky' => $ThreadInfo['IsSticky']
271
+        );
272
+
273
+        $UpdateArray['NumTopics'] = '+1';
274
+
275
+        G::$Cache->update_row($ForumID, $UpdateArray);
276
+        G::$Cache->commit_transaction(0);
277
+
278
+        $CatalogueID = floor((POSTS_PER_PAGE * ceil($Posts / POSTS_PER_PAGE) - POSTS_PER_PAGE) / THREAD_CATALOGUE);
279
+        G::$Cache->begin_transaction('thread_'.$TopicID.'_catalogue_'.$CatalogueID);
280
+        $Post = array(
281
+        'ID' => $PostID,
282
+        'AuthorID' => G::$LoggedUser['ID'],
283
+        'AddedTime' => sqltime(),
284
+        'Body' => $PostBody,
285
+        'EditedUserID' => 0,
286
+        'EditedTime' => null,
287
+        'Username' => ''
288
+        );
289
+        G::$Cache->insert('', $Post);
290
+        G::$Cache->commit_transaction(0);
291
+
292
+        G::$Cache->begin_transaction('thread_'.$TopicID.'_info');
293
+        G::$Cache->update_row(false, array('Posts' => '+1', 'LastPostAuthorID' => $AuthorID));
294
+        G::$Cache->commit_transaction(0);
295
+
296
+        G::$DB->set_query_id($QueryID);
297
+
298
+        return $TopicID;
254
     }
299
     }
255
 
300
 
256
-    //Update the forum root
257
-    G::$Cache->begin_transaction('forums_list');
258
-    $UpdateArray = array(
259
-      'NumPosts' => '+1',
260
-      'NumTopics' => '+1',
261
-      'LastPostID' => $PostID,
262
-      'LastPostAuthorID' => $AuthorID,
263
-      'LastPostTopicID' => $TopicID,
264
-      'LastPostTime' => sqltime(),
265
-      'Title' => $Title,
266
-      'IsLocked' => $ThreadInfo['IsLocked'],
267
-      'IsSticky' => $ThreadInfo['IsSticky']
268
-      );
269
-
270
-    $UpdateArray['NumTopics'] = '+1';
271
-
272
-    G::$Cache->update_row($ForumID, $UpdateArray);
273
-    G::$Cache->commit_transaction(0);
274
-
275
-    $CatalogueID = floor((POSTS_PER_PAGE * ceil($Posts / POSTS_PER_PAGE) - POSTS_PER_PAGE) / THREAD_CATALOGUE);
276
-    G::$Cache->begin_transaction('thread_'.$TopicID.'_catalogue_'.$CatalogueID);
277
-    $Post = array(
278
-      'ID' => $PostID,
279
-      'AuthorID' => G::$LoggedUser['ID'],
280
-      'AddedTime' => sqltime(),
281
-      'Body' => $PostBody,
282
-      'EditedUserID' => 0,
283
-      'EditedTime' => NULL,
284
-      'Username' => ''
285
-      );
286
-    G::$Cache->insert('', $Post);
287
-    G::$Cache->commit_transaction(0);
288
-
289
-    G::$Cache->begin_transaction('thread_'.$TopicID.'_info');
290
-    G::$Cache->update_row(false, array('Posts' => '+1', 'LastPostAuthorID' => $AuthorID));
291
-    G::$Cache->commit_transaction(0);
292
-
293
-    G::$DB->set_query_id($QueryID);
294
-
295
-    return $TopicID;
296
-  }
297
-
298
-  /**
299
-   * If the suffix of $Haystack is $Needle
300
-   *
301
-   * @param string $Haystack String to search in
302
-   * @param string $Needle String to search for
303
-   * @return boolean True if $Needle is a suffix of $Haystack
304
-   */
305
-  public static function ends_with($Haystack, $Needle) {
306
-    return substr($Haystack, strlen($Needle) * -1) == $Needle;
307
-  }
308
-
309
-
310
-  /**
311
-   * If the prefix of $Haystack is $Needle
312
-   *
313
-   * @param string $Haystack String to search in
314
-   * @param string $Needle String to search for
315
-   * @return boolean True if $Needle is a prefix of $Haystack
316
-   */
317
-  public static function starts_with($Haystack, $Needle) {
318
-    return strpos($Haystack, $Needle) === 0;
319
-  }
320
-
321
-  /**
322
-   * Variant of in_array() with trailing wildcard support
323
-   *
324
-   * @param string $Needle, array $Haystack
325
-   * @return boolean true if (substring of) $Needle exists in $Haystack
326
-   */
327
-  public static function in_array_partial($Needle, $Haystack) {
328
-    static $Searches = [];
329
-    if (array_key_exists($Needle, $Searches)) {
330
-      return $Searches[$Needle];
301
+    /**
302
+     * If the suffix of $Haystack is $Needle
303
+     *
304
+     * @param string $Haystack String to search in
305
+     * @param string $Needle String to search for
306
+     * @return boolean True if $Needle is a suffix of $Haystack
307
+     */
308
+    public static function ends_with($Haystack, $Needle)
309
+    {
310
+        return substr($Haystack, strlen($Needle) * -1) == $Needle;
331
     }
311
     }
332
-    foreach ($Haystack as $String) {
333
-      if (substr($String, -1) == '*') {
334
-        if (!strncmp($Needle, $String, strlen($String) - 1)) {
335
-          $Searches[$Needle] = true;
336
-          return true;
337
-        }
338
-      } elseif (!strcmp($Needle, $String)) {
339
-        $Searches[$Needle] = true;
340
-        return true;
341
-      }
312
+
313
+
314
+    /**
315
+     * If the prefix of $Haystack is $Needle
316
+     *
317
+     * @param string $Haystack String to search in
318
+     * @param string $Needle String to search for
319
+     * @return boolean True if $Needle is a prefix of $Haystack
320
+     */
321
+    public static function starts_with($Haystack, $Needle)
322
+    {
323
+        return strpos($Haystack, $Needle) === 0;
342
     }
324
     }
343
-    $Searches[$Needle] = false;
344
-    return false;
345
-  }
346
-
347
-  /**
348
-   * Used to check if keys in $_POST and $_GET are all set, and throws an error if not.
349
-   * This reduces 'if' statement redundancy for a lot of variables
350
-   *
351
-   * @param array $Request Either $_POST or $_GET, or whatever other array you want to check.
352
-   * @param array $Keys The keys to ensure are set.
353
-   * @param boolean $AllowEmpty If set to true, a key that is in the request but blank will not throw an error.
354
-   * @param int $Error The error code to throw if one of the keys isn't in the array.
355
-   */
356
-  public static function assert_isset_request($Request, $Keys = null, $AllowEmpty = false, $Error = 0) {
357
-    if (isset($Keys)) {
358
-      foreach ($Keys as $K) {
359
-        if (!isset($Request[$K]) || ($AllowEmpty == false && $Request[$K] == '')) {
360
-          error($Error);
361
-          break;
325
+
326
+    /**
327
+     * Variant of in_array() with trailing wildcard support
328
+     *
329
+     * @param string $Needle, array $Haystack
330
+     * @return boolean true if (substring of) $Needle exists in $Haystack
331
+     */
332
+    public static function in_array_partial($Needle, $Haystack)
333
+    {
334
+        static $Searches = [];
335
+        if (array_key_exists($Needle, $Searches)) {
336
+            return $Searches[$Needle];
362
         }
337
         }
363
-      }
364
-    } else {
365
-      foreach ($Request as $R) {
366
-        if (!isset($R) || ($AllowEmpty == false && $R == '')) {
367
-          error($Error);
368
-          break;
338
+        foreach ($Haystack as $String) {
339
+            if (substr($String, -1) == '*') {
340
+                if (!strncmp($Needle, $String, strlen($String) - 1)) {
341
+                    $Searches[$Needle] = true;
342
+                    return true;
343
+                }
344
+            } elseif (!strcmp($Needle, $String)) {
345
+                $Searches[$Needle] = true;
346
+                return true;
347
+            }
369
         }
348
         }
370
-      }
349
+        $Searches[$Needle] = false;
350
+        return false;
371
     }
351
     }
372
-  }
373
-
374
-
375
-  /**
376
-   * Given an array of tags, return an array of their IDs.
377
-   *
378
-   * @param array $TagNames
379
-   * @return array IDs
380
-   */
381
-  public static function get_tags($TagNames) {
382
-    $TagIDs = [];
383
-    foreach ($TagNames as $Index => $TagName) {
384
-      $Tag = G::$Cache->get_value("tag_id_$TagName");
385
-      if (is_array($Tag)) {
386
-        unset($TagNames[$Index]);
387
-        $TagIDs[$Tag['ID']] = $Tag['Name'];
388
-      }
352
+
353
+    /**
354
+     * Used to check if keys in $_POST and $_GET are all set, and throws an error if not.
355
+     * This reduces 'if' statement redundancy for a lot of variables
356
+     *
357
+     * @param array $Request Either $_POST or $_GET, or whatever other array you want to check.
358
+     * @param array $Keys The keys to ensure are set.
359
+     * @param boolean $AllowEmpty If set to true, a key that is in the request but blank will not throw an error.
360
+     * @param int $Error The error code to throw if one of the keys isn't in the array.
361
+     */
362
+    public static function assert_isset_request($Request, $Keys = null, $AllowEmpty = false, $Error = 0)
363
+    {
364
+        if (isset($Keys)) {
365
+            foreach ($Keys as $K) {
366
+                if (!isset($Request[$K]) || ($AllowEmpty == false && $Request[$K] == '')) {
367
+                    error($Error);
368
+                    break;
369
+                }
370
+            }
371
+        } else {
372
+            foreach ($Request as $R) {
373
+                if (!isset($R) || ($AllowEmpty == false && $R == '')) {
374
+                    error($Error);
375
+                    break;
376
+                }
377
+            }
378
+        }
389
     }
379
     }
390
-    if (count($TagNames) > 0) {
391
-      $QueryID = G::$DB->get_query_id();
392
-      G::$DB->query("
380
+
381
+
382
+    /**
383
+     * Given an array of tags, return an array of their IDs.
384
+     *
385
+     * @param array $TagNames
386
+     * @return array IDs
387
+     */
388
+    public static function get_tags($TagNames)
389
+    {
390
+        $TagIDs = [];
391
+        foreach ($TagNames as $Index => $TagName) {
392
+            $Tag = G::$Cache->get_value("tag_id_$TagName");
393
+            if (is_array($Tag)) {
394
+                unset($TagNames[$Index]);
395
+                $TagIDs[$Tag['ID']] = $Tag['Name'];
396
+            }
397
+        }
398
+        if (count($TagNames) > 0) {
399
+            $QueryID = G::$DB->get_query_id();
400
+            G::$DB->query("
393
         SELECT ID, Name
401
         SELECT ID, Name
394
         FROM tags
402
         FROM tags
395
         WHERE Name IN ('".implode("', '", $TagNames)."')");
403
         WHERE Name IN ('".implode("', '", $TagNames)."')");
396
-      $SQLTagIDs = G::$DB->to_array();
397
-      G::$DB->set_query_id($QueryID);
398
-      foreach ($SQLTagIDs as $Tag) {
399
-        $TagIDs[$Tag['ID']] = $Tag['Name'];
400
-        G::$Cache->cache_value('tag_id_'.$Tag['Name'], $Tag, 0);
401
-      }
402
-    }
404
+            $SQLTagIDs = G::$DB->to_array();
405
+            G::$DB->set_query_id($QueryID);
406
+            foreach ($SQLTagIDs as $Tag) {
407
+                $TagIDs[$Tag['ID']] = $Tag['Name'];
408
+                G::$Cache->cache_value('tag_id_'.$Tag['Name'], $Tag, 0);
409
+            }
410
+        }
403
 
411
 
404
-    return($TagIDs);
405
-  }
412
+        return($TagIDs);
413
+    }
406
 
414
 
407
 
415
 
408
-  /**
409
-   * Gets the alias of the tag; if there is no alias, silently returns the original tag.
410
-   *
411
-   * @param string $BadTag the tag we want to alias
412
-   * @return string The aliased tag.
413
-   */
414
-  public static function get_alias_tag($BadTag) {
415
-    $QueryID = G::$DB->get_query_id();
416
-    G::$DB->query("
416
+    /**
417
+     * Gets the alias of the tag; if there is no alias, silently returns the original tag.
418
+     *
419
+     * @param string $BadTag the tag we want to alias
420
+     * @return string The aliased tag.
421
+     */
422
+    public static function get_alias_tag($BadTag)
423
+    {
424
+        $QueryID = G::$DB->get_query_id();
425
+        G::$DB->query("
417
       SELECT AliasTag
426
       SELECT AliasTag
418
       FROM tag_aliases
427
       FROM tag_aliases
419
       WHERE BadTag = '$BadTag'
428
       WHERE BadTag = '$BadTag'
420
       LIMIT 1");
429
       LIMIT 1");
421
-    if (G::$DB->has_results()) {
422
-      list($AliasTag) = G::$DB->next_record();
423
-    } else {
424
-      $AliasTag = $BadTag;
430
+        if (G::$DB->has_results()) {
431
+            list($AliasTag) = G::$DB->next_record();
432
+        } else {
433
+            $AliasTag = $BadTag;
434
+        }
435
+        G::$DB->set_query_id($QueryID);
436
+        return $AliasTag;
425
     }
437
     }
426
-    G::$DB->set_query_id($QueryID);
427
-    return $AliasTag;
428
-  }
429
-
430
-
431
-  /*
432
-   * Write a message to the system log.
433
-   *
434
-   * @param string $Message the message to write.
435
-   */
436
-  public static function write_log($Message) {
437
-    global $Time;
438
-    $QueryID = G::$DB->get_query_id();
439
-    G::$DB->query("
438
+
439
+
440
+    /*
441
+     * Write a message to the system log.
442
+     *
443
+     * @param string $Message the message to write.
444
+     */
445
+    public static function write_log($Message)
446
+    {
447
+        global $Time;
448
+        $QueryID = G::$DB->get_query_id();
449
+        G::$DB->query("
440
       INSERT INTO log (Message, Time)
450
       INSERT INTO log (Message, Time)
441
       VALUES (?, NOW())", $Message);
451
       VALUES (?, NOW())", $Message);
442
-    G::$DB->set_query_id($QueryID);
443
-  }
444
-
445
-
446
-  /**
447
-   * Get a tag ready for database input and display.
448
-   *
449
-   * @param string $Str
450
-   * @return sanitized version of $Str
451
-   */
452
-  public static function sanitize_tag($Str) {
453
-    $Str = strtolower($Str);
454
-    $Str = preg_replace('/[^a-z0-9:.]/', '', $Str);
455
-    $Str = preg_replace('/(^[.,]*)|([.,]*$)/', '', $Str);
456
-    $Str = htmlspecialchars($Str);
457
-    $Str = db_string(trim($Str));
458
-    return $Str;
459
-  }
460
-
461
-  /**
462
-   * HTML escape an entire array for output.
463
-   * @param array $Array, what we want to escape
464
-   * @param boolean/array $Escape
465
-   *  if true, all keys escaped
466
-   *  if false, no escaping.
467
-   *  If array, it's a list of array keys not to escape.
468
-   * @return mutated version of $Array with values escaped.
469
-   */
470
-  public static function display_array($Array, $Escape = []) {
471
-    foreach ($Array as $Key => $Val) {
472
-      if ((!is_array($Escape) && $Escape == true) || !in_array($Key, $Escape)) {
473
-        $Array[$Key] = display_str($Val);
474
-      }
452
+        G::$DB->set_query_id($QueryID);
475
     }
453
     }
476
-    return $Array;
477
-  }
478
-
479
-  /**
480
-   * Searches for a key/value pair in an array.
481
-   *
482
-   * @return array of results
483
-   */
484
-  public static function search_array($Array, $Key, $Value) {
485
-    $Results = [];
486
-    if (is_array($Array))
454
+
455
+
456
+    /**
457
+     * Get a tag ready for database input and display.
458
+     *
459
+     * @param string $Str
460
+     * @return sanitized version of $Str
461
+     */
462
+    public static function sanitize_tag($Str)
463
+    {
464
+        $Str = strtolower($Str);
465
+        $Str = preg_replace('/[^a-z0-9:.]/', '', $Str);
466
+        $Str = preg_replace('/(^[.,]*)|([.,]*$)/', '', $Str);
467
+        $Str = htmlspecialchars($Str);
468
+        $Str = db_string(trim($Str));
469
+        return $Str;
470
+    }
471
+
472
+    /**
473
+     * HTML escape an entire array for output.
474
+     * @param array $Array, what we want to escape
475
+     * @param boolean/array $Escape
476
+     *  if true, all keys escaped
477
+     *  if false, no escaping.
478
+     *  If array, it's a list of array keys not to escape.
479
+     * @return mutated version of $Array with values escaped.
480
+     */
481
+    public static function display_array($Array, $Escape = [])
487
     {
482
     {
488
-      if (isset($Array[$Key]) && $Array[$Key] == $Value) {
489
-        $Results[] = $Array;
490
-      }
483
+        foreach ($Array as $Key => $Val) {
484
+            if ((!is_array($Escape) && $Escape == true) || !in_array($Key, $Escape)) {
485
+                $Array[$Key] = display_str($Val);
486
+            }
487
+        }
488
+        return $Array;
489
+    }
490
+
491
+    /**
492
+     * Searches for a key/value pair in an array.
493
+     *
494
+     * @return array of results
495
+     */
496
+    public static function search_array($Array, $Key, $Value)
497
+    {
498
+        $Results = [];
499
+        if (is_array($Array)) {
500
+            if (isset($Array[$Key]) && $Array[$Key] == $Value) {
501
+                $Results[] = $Array;
502
+            }
503
+
504
+            foreach ($Array as $subarray) {
505
+                $Results = array_merge($Results, self::search_array($subarray, $Key, $Value));
506
+            }
507
+        }
508
+        return $Results;
509
+    }
491
 
510
 
492
-      foreach ($Array as $subarray) {
493
-        $Results = array_merge($Results, self::search_array($subarray, $Key, $Value));
494
-      }
511
+    /**
512
+     * Search for $Needle in the string $Haystack which is a list of values separated by $Separator.
513
+     * @param string $Haystack
514
+     * @param string $Needle
515
+     * @param string $Separator
516
+     * @param boolean $Strict
517
+     * @return boolean
518
+     */
519
+    public static function search_joined_string($Haystack, $Needle, $Separator = '|', $Strict = true)
520
+    {
521
+        return (array_search($Needle, explode($Separator, $Haystack), $Strict) !== false);
495
     }
522
     }
496
-    return $Results;
497
-  }
498
-
499
-  /**
500
-   * Search for $Needle in the string $Haystack which is a list of values separated by $Separator.
501
-   * @param string $Haystack
502
-   * @param string $Needle
503
-   * @param string $Separator
504
-   * @param boolean $Strict
505
-   * @return boolean
506
-   */
507
-  public static function search_joined_string($Haystack, $Needle, $Separator = '|', $Strict = true) {
508
-    return (array_search($Needle, explode($Separator, $Haystack), $Strict) !== false);
509
-  }
510
-
511
-  /**
512
-   * Check for a ":" in the beginning of a torrent meta data string
513
-   * to see if it's stored in the old base64-encoded format
514
-   *
515
-   * @param string $Torrent the torrent data
516
-   * @return true if the torrent is stored in binary format
517
-   */
518
-  public static function is_new_torrent(&$Data) {
519
-    return strpos(substr($Data, 0, 10), ':') !== false;
520
-  }
521
-
522
-  public static function display_recommend($ID, $Type, $Hide = true) {
523
-    if ($Hide) {
524
-      $Hide = ' style="display: none;"';
523
+
524
+    /**
525
+     * Check for a ":" in the beginning of a torrent meta data string
526
+     * to see if it's stored in the old base64-encoded format
527
+     *
528
+     * @param string $Torrent the torrent data
529
+     * @return true if the torrent is stored in binary format
530
+     */
531
+    public static function is_new_torrent(&$Data)
532
+    {
533
+        return strpos(substr($Data, 0, 10), ':') !== false;
525
     }
534
     }
526
-    ?>
535
+
536
+    public static function display_recommend($ID, $Type, $Hide = true)
537
+    {
538
+        if ($Hide) {
539
+            $Hide = ' style="display: none;"';
540
+        } ?>
527
     <div id="recommendation_div" data-id="<?=$ID?>" data-type="<?=$Type?>"<?=$Hide?> class="center">
541
     <div id="recommendation_div" data-id="<?=$ID?>" data-type="<?=$Type?>"<?=$Hide?> class="center">
528
       <div style="display: inline-block;">
542
       <div style="display: inline-block;">
529
         <strong>Recommend to:</strong>
543
         <strong>Recommend to:</strong>
535
       </div>
549
       </div>
536
       <div class="new" id="recommendation_status"><br /></div>
550
       <div class="new" id="recommendation_status"><br /></div>
537
     </div>
551
     </div>
538
-<?
539
-  }
540
-
541
-  public static function is_valid_url($URL) {
542
-    return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $URL);
543
-  }
552
+        <?php
553
+    }
544
 
554
 
555
+    public static function is_valid_url($URL)
556
+    {
557
+        return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $URL);
558
+    }
545
 }
559
 }
546
 ?>
560
 ?>

Loading…
Cancel
Save