Browse Source

Upload files to 'classes'

Stortebeker 6 years ago
parent
commit
def939fedc
5 changed files with 841 additions and 781 deletions
  1. 281
    262
      classes/subscriptions.class.php
  2. 251
    236
      classes/tags.class.php
  3. 62
    62
      classes/templates.class.php
  4. 142
    130
      classes/testing.class.php
  5. 105
    91
      classes/testingview.class.php

+ 281
- 262
classes/subscriptions.class.php View File

@@ -1,43 +1,45 @@
1
-<?
2
-class Subscriptions {
3
-  /**
4
-   * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
5
-   * @param string $Body
6
-   * @param int $PostID
7
-   * @param string $Page
8
-   * @param int $PageID
9
-   */
10
-  public static function quote_notify($Body, $PostID, $Page, $PageID) {
11
-    $QueryID = G::$DB->get_query_id();
12
-    /*
13
-     * Explanation of the parameters PageID and Page: Page contains where
14
-     * this quote comes from and can be forums, artist, collages, requests
15
-     * or torrents. The PageID contains the additional value that is
16
-     * necessary for the users_notify_quoted table. The PageIDs for the
17
-     * different Page are: forums: TopicID artist: ArtistID collages:
18
-     * CollageID requests: RequestID torrents: GroupID
1
+<?php
2
+class Subscriptions
3
+{
4
+    /**
5
+     * Parse a post/comment body for quotes and notify all quoted users that have quote notifications enabled.
6
+     * @param string $Body
7
+     * @param int $PostID
8
+     * @param string $Page
9
+     * @param int $PageID
19 10
      */
20
-    $Matches = [];
21
-    preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
11
+    public static function quote_notify($Body, $PostID, $Page, $PageID)
12
+    {
13
+        $QueryID = G::$DB->get_query_id();
14
+        /*
15
+         * Explanation of the parameters PageID and Page: Page contains where
16
+         * this quote comes from and can be forums, artist, collages, requests
17
+         * or torrents. The PageID contains the additional value that is
18
+         * necessary for the users_notify_quoted table. The PageIDs for the
19
+         * different Page are: forums: TopicID artist: ArtistID collages:
20
+         * CollageID requests: RequestID torrents: GroupID
21
+         */
22
+        $Matches = [];
23
+        preg_match_all('/\[quote(?:=(.*)(?:\|.*)?)?]|\[\/quote]/iU', $Body, $Matches, PREG_SET_ORDER);
22 24
 
23
-    if (count($Matches)) {
24
-      $Usernames = [];
25
-      $Level = 0;
26
-      foreach ($Matches as $M) {
27
-        if ($M[0] != '[/quote]') {
28
-          if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
29
-            $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
30
-          }
31
-          ++$Level;
32
-        } else {
33
-          --$Level;
25
+        if (count($Matches)) {
26
+            $Usernames = [];
27
+            $Level = 0;
28
+            foreach ($Matches as $M) {
29
+                if ($M[0] != '[/quote]') {
30
+                    if ($Level == 0 && isset($M[1]) && strlen($M[1]) > 0 && preg_match(USERNAME_REGEX, $M[1])) {
31
+                        $Usernames[] = preg_replace('/(^[.,]*)|([.,]*$)/', '', $M[1]); // wut?
32
+                    }
33
+                    ++$Level;
34
+                } else {
35
+                    --$Level;
36
+                }
37
+            }
34 38
         }
35
-      }
36
-    }
37
-    // remove any dupes in the array (the fast way)
38
-    $Usernames = array_flip(array_flip($Usernames));
39
+        // remove any dupes in the array (the fast way)
40
+        $Usernames = array_flip(array_flip($Usernames));
39 41
 
40
-    G::$DB->query("
42
+        G::$DB->query("
41 43
       SELECT m.ID
42 44
       FROM users_main AS m
43 45
         LEFT JOIN users_info AS i ON i.UserID = m.ID
@@ -45,152 +47,163 @@ class Subscriptions {
45 47
         AND i.NotifyOnQuote = '1'
46 48
         AND i.UserID != " . G::$LoggedUser['ID']);
47 49
 
48
-    $Results = G::$DB->to_array();
49
-    foreach ($Results as $Result) {
50
-      $UserID = db_string($Result['ID']);
51
-      $QuoterID = db_string(G::$LoggedUser['ID']);
52
-      $Page = db_string($Page);
53
-      $PageID = db_string($PageID);
54
-      $PostID = db_string($PostID);
50
+        $Results = G::$DB->to_array();
51
+        foreach ($Results as $Result) {
52
+            $UserID = db_string($Result['ID']);
53
+            $QuoterID = db_string(G::$LoggedUser['ID']);
54
+            $Page = db_string($Page);
55
+            $PageID = db_string($PageID);
56
+            $PostID = db_string($PostID);
55 57
 
56
-      G::$DB->query("
58
+            G::$DB->query(
59
+                "
57 60
         INSERT IGNORE INTO users_notify_quoted
58 61
           (UserID, QuoterID, Page, PageID, PostID, Date)
59 62
         VALUES
60 63
           (    ?,               ?,               ?,      ?,       ?,   NOW())",
61
-          $Result['ID'], G::$LoggedUser['ID'], $Page, $PageID, $PostID);
62
-      G::$Cache->delete_value("notify_quoted_$UserID");
63
-      if ($Page == 'forums') {
64
-        $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
65
-      } else {
66
-        $URL = site_url() . "comments.php?action=jump&postid=$PostID";
67
-      }
64
+                $Result['ID'],
65
+                G::$LoggedUser['ID'],
66
+                $Page,
67
+                $PageID,
68
+                $PostID
69
+            );
70
+            G::$Cache->delete_value("notify_quoted_$UserID");
71
+            if ($Page == 'forums') {
72
+                $URL = site_url() . "forums.php?action=viewthread&postid=$PostID";
73
+            } else {
74
+                $URL = site_url() . "comments.php?action=jump&postid=$PostID";
75
+            }
76
+        }
77
+        G::$DB->set_query_id($QueryID);
68 78
     }
69
-    G::$DB->set_query_id($QueryID);
70
-  }
71 79
 
72
-  /**
73
-   * (Un)subscribe from a forum thread.
74
-   * If UserID == 0, G::$LoggedUser[ID] is used
75
-   * @param int $TopicID
76
-   * @param int $UserID
77
-   */
78
-  public static function subscribe($TopicID, $UserID = 0) {
79
-    if ($UserID == 0) {
80
-      $UserID = G::$LoggedUser['ID'];
81
-    }
82
-    $QueryID = G::$DB->get_query_id();
83
-    $UserSubscriptions = self::get_subscriptions();
84
-    $Key = self::has_subscribed($TopicID);
85
-    if ($Key !== false) {
86
-      G::$DB->query('
80
+    /**
81
+     * (Un)subscribe from a forum thread.
82
+     * If UserID == 0, G::$LoggedUser[ID] is used
83
+     * @param int $TopicID
84
+     * @param int $UserID
85
+     */
86
+    public static function subscribe($TopicID, $UserID = 0)
87
+    {
88
+        if ($UserID == 0) {
89
+            $UserID = G::$LoggedUser['ID'];
90
+        }
91
+        $QueryID = G::$DB->get_query_id();
92
+        $UserSubscriptions = self::get_subscriptions();
93
+        $Key = self::has_subscribed($TopicID);
94
+        if ($Key !== false) {
95
+            G::$DB->query('
87 96
         DELETE FROM users_subscriptions
88 97
         WHERE UserID = ' . db_string($UserID) . '
89 98
           AND TopicID = ' . db_string($TopicID));
90
-      unset($UserSubscriptions[$Key]);
91
-    } else {
92
-      G::$DB->query("
99
+            unset($UserSubscriptions[$Key]);
100
+        } else {
101
+            G::$DB->query("
93 102
         INSERT IGNORE INTO users_subscriptions (UserID, TopicID)
94 103
         VALUES ($UserID, " . db_string($TopicID) . ")");
95
-      array_push($UserSubscriptions, $TopicID);
104
+            array_push($UserSubscriptions, $TopicID);
105
+        }
106
+        G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
107
+        G::$Cache->delete_value("subscriptions_user_new_$UserID");
108
+        G::$DB->set_query_id($QueryID);
96 109
     }
97
-    G::$Cache->replace_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
98
-    G::$Cache->delete_value("subscriptions_user_new_$UserID");
99
-    G::$DB->set_query_id($QueryID);
100
-  }
101 110
 
102
-  /**
103
-   * (Un)subscribe from comments.
104
-   * If UserID == 0, G::$LoggedUser[ID] is used
105
-   * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
106
-   * @param int $PageID ArtistID, CollageID, RequestID or GroupID
107
-   * @param int $UserID
108
-   */
109
-  public static function subscribe_comments($Page, $PageID, $UserID = 0) {
110
-    if ($UserID == 0) {
111
-      $UserID = G::$LoggedUser['ID'];
112
-    }
113
-    $QueryID = G::$DB->get_query_id();
114
-    $UserCommentSubscriptions = self::get_comment_subscriptions();
115
-    $Key = self::has_subscribed_comments($Page, $PageID);
116
-    if ($Key !== false) {
117
-      G::$DB->query("
111
+    /**
112
+     * (Un)subscribe from comments.
113
+     * If UserID == 0, G::$LoggedUser[ID] is used
114
+     * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
115
+     * @param int $PageID ArtistID, CollageID, RequestID or GroupID
116
+     * @param int $UserID
117
+     */
118
+    public static function subscribe_comments($Page, $PageID, $UserID = 0)
119
+    {
120
+        if ($UserID == 0) {
121
+            $UserID = G::$LoggedUser['ID'];
122
+        }
123
+        $QueryID = G::$DB->get_query_id();
124
+        $UserCommentSubscriptions = self::get_comment_subscriptions();
125
+        $Key = self::has_subscribed_comments($Page, $PageID);
126
+        if ($Key !== false) {
127
+            G::$DB->query("
118 128
         DELETE FROM users_subscriptions_comments
119 129
         WHERE UserID = " . db_string($UserID) . "
120 130
           AND Page = '" . db_string($Page) . "'
121 131
           AND PageID = " . db_string($PageID));
122
-      unset($UserCommentSubscriptions[$Key]);
123
-    } else {
124
-      G::$DB->query("
132
+            unset($UserCommentSubscriptions[$Key]);
133
+        } else {
134
+            G::$DB->query("
125 135
         INSERT IGNORE INTO users_subscriptions_comments
126 136
           (UserID, Page, PageID)
127 137
         VALUES
128 138
           ($UserID, '" . db_string($Page) . "', " . db_string($PageID) . ")");
129
-      array_push($UserCommentSubscriptions, array($Page, $PageID));
139
+            array_push($UserCommentSubscriptions, array($Page, $PageID));
140
+        }
141
+        G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
142
+        G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
143
+        G::$DB->set_query_id($QueryID);
130 144
     }
131
-    G::$Cache->replace_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
132
-    G::$Cache->delete_value("subscriptions_comments_user_new_$UserID");
133
-    G::$DB->set_query_id($QueryID);
134
-  }
135 145
 
136
-  /**
137
-   * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
138
-   * If UserID == 0, G::$LoggedUser[ID] is used
139
-   * @param int $UserID
140
-   * @return array Array of TopicIDs
141
-   */
142
-  public static function get_subscriptions($UserID = 0) {
143
-    if ($UserID == 0) {
144
-      $UserID = G::$LoggedUser['ID'];
145
-    }
146
-    $QueryID = G::$DB->get_query_id();
147
-    $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
148
-    if ($UserSubscriptions === false) {
149
-      G::$DB->query('
146
+    /**
147
+     * Read $UserID's subscriptions. If the cache key isn't set, it gets filled.
148
+     * If UserID == 0, G::$LoggedUser[ID] is used
149
+     * @param int $UserID
150
+     * @return array Array of TopicIDs
151
+     */
152
+    public static function get_subscriptions($UserID = 0)
153
+    {
154
+        if ($UserID == 0) {
155
+            $UserID = G::$LoggedUser['ID'];
156
+        }
157
+        $QueryID = G::$DB->get_query_id();
158
+        $UserSubscriptions = G::$Cache->get_value("subscriptions_user_$UserID");
159
+        if ($UserSubscriptions === false) {
160
+            G::$DB->query('
150 161
         SELECT TopicID
151 162
         FROM users_subscriptions
152 163
         WHERE UserID = ' . db_string($UserID));
153
-      $UserSubscriptions = G::$DB->collect(0);
154
-      G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
164
+            $UserSubscriptions = G::$DB->collect(0);
165
+            G::$Cache->cache_value("subscriptions_user_$UserID", $UserSubscriptions, 0);
166
+        }
167
+        G::$DB->set_query_id($QueryID);
168
+        return $UserSubscriptions;
155 169
     }
156
-    G::$DB->set_query_id($QueryID);
157
-    return $UserSubscriptions;
158
-  }
159 170
 
160
-  /**
161
-   * Same as self::get_subscriptions, but for comment subscriptions
162
-   * @param int $UserID
163
-   * @return array Array of ($Page, $PageID)
164
-   */
165
-  public static function get_comment_subscriptions($UserID = 0) {
166
-    if ($UserID == 0) {
167
-      $UserID = G::$LoggedUser['ID'];
168
-    }
169
-    $QueryID = G::$DB->get_query_id();
170
-    $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
171
-    if ($UserCommentSubscriptions === false) {
172
-      G::$DB->query('
171
+    /**
172
+     * Same as self::get_subscriptions, but for comment subscriptions
173
+     * @param int $UserID
174
+     * @return array Array of ($Page, $PageID)
175
+     */
176
+    public static function get_comment_subscriptions($UserID = 0)
177
+    {
178
+        if ($UserID == 0) {
179
+            $UserID = G::$LoggedUser['ID'];
180
+        }
181
+        $QueryID = G::$DB->get_query_id();
182
+        $UserCommentSubscriptions = G::$Cache->get_value("subscriptions_comments_user_$UserID");
183
+        if ($UserCommentSubscriptions === false) {
184
+            G::$DB->query('
173 185
         SELECT Page, PageID
174 186
         FROM users_subscriptions_comments
175 187
         WHERE UserID = ' . db_string($UserID));
176
-      $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
177
-      G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
188
+            $UserCommentSubscriptions = G::$DB->to_array(false, MYSQLI_NUM);
189
+            G::$Cache->cache_value("subscriptions_comments_user_$UserID", $UserCommentSubscriptions, 0);
190
+        }
191
+        G::$DB->set_query_id($QueryID);
192
+        return $UserCommentSubscriptions;
178 193
     }
179
-    G::$DB->set_query_id($QueryID);
180
-    return $UserCommentSubscriptions;
181
-  }
182 194
 
183
-  /**
184
-   * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
185
-   * @return int Number of unread subscribed threads/comments
186
-   */
187
-  public static function has_new_subscriptions() {
188
-    $QueryID = G::$DB->get_query_id();
195
+    /**
196
+     * Returns whether or not the current user has new subscriptions. This handles both forum and comment subscriptions.
197
+     * @return int Number of unread subscribed threads/comments
198
+     */
199
+    public static function has_new_subscriptions()
200
+    {
201
+        $QueryID = G::$DB->get_query_id();
189 202
 
190
-    $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
191
-    if ($NewSubscriptions === false) {
192
-      // forum subscriptions
193
-      G::$DB->query("
203
+        $NewSubscriptions = G::$Cache->get_value('subscriptions_user_new_' . G::$LoggedUser['ID']);
204
+        if ($NewSubscriptions === false) {
205
+            // forum subscriptions
206
+            G::$DB->query("
194 207
           SELECT COUNT(1)
195 208
           FROM users_subscriptions AS s
196 209
             LEFT JOIN forums_last_read_topics AS l ON l.UserID = s.UserID AND l.TopicID = s.TopicID
@@ -199,10 +212,10 @@ class Subscriptions {
199 212
           WHERE " . Forums::user_forums_sql() . "
200 213
             AND IF(t.IsLocked = '1' AND t.IsSticky = '0'" . ", t.LastPostID, IF(l.PostID IS NULL, 0, l.PostID)) < t.LastPostID
201 214
             AND s.UserID = " . G::$LoggedUser['ID']);
202
-      list($NewForumSubscriptions) = G::$DB->next_record();
215
+            list($NewForumSubscriptions) = G::$DB->next_record();
203 216
 
204
-      // comment subscriptions
205
-      G::$DB->query("
217
+            // comment subscriptions
218
+            G::$DB->query("
206 219
           SELECT COUNT(1)
207 220
           FROM users_subscriptions_comments AS s
208 221
             LEFT JOIN users_comments_last_read AS lr ON lr.UserID = s.UserID AND lr.Page = s.Page AND lr.PageID = s.PageID
@@ -211,23 +224,24 @@ class Subscriptions {
211 224
           WHERE s.UserID = " . G::$LoggedUser['ID'] . "
212 225
             AND (s.Page != 'collages' OR co.Deleted = '0')
213 226
             AND IF(lr.PostID IS NULL, 0, lr.PostID) < c.ID");
214
-      list($NewCommentSubscriptions) = G::$DB->next_record();
227
+            list($NewCommentSubscriptions) = G::$DB->next_record();
215 228
 
216
-      $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
217
-      G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
229
+            $NewSubscriptions = $NewForumSubscriptions + $NewCommentSubscriptions;
230
+            G::$Cache->cache_value('subscriptions_user_new_' . G::$LoggedUser['ID'], $NewSubscriptions, 0);
231
+        }
232
+        G::$DB->set_query_id($QueryID);
233
+        return (int)$NewSubscriptions;
218 234
     }
219
-    G::$DB->set_query_id($QueryID);
220
-    return (int)$NewSubscriptions;
221
-  }
222 235
 
223
-  /**
224
-   * Returns whether or not the current user has new quote notifications.
225
-   * @return int Number of unread quote notifications
226
-   */
227
-  public static function has_new_quote_notifications() {
228
-    $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
229
-    if ($QuoteNotificationsCount === false) {
230
-      $sql = "
236
+    /**
237
+     * Returns whether or not the current user has new quote notifications.
238
+     * @return int Number of unread quote notifications
239
+     */
240
+    public static function has_new_quote_notifications()
241
+    {
242
+        $QuoteNotificationsCount = G::$Cache->get_value('notify_quoted_' . G::$LoggedUser['ID']);
243
+        if ($QuoteNotificationsCount === false) {
244
+            $sql = "
231 245
         SELECT COUNT(1)
232 246
         FROM users_notify_quoted AS q
233 247
           LEFT JOIN forums_topics AS t ON t.ID = q.PageID
@@ -237,166 +251,171 @@ class Subscriptions {
237 251
           AND q.UnRead
238 252
           AND (q.Page != 'forums' OR " . Forums::user_forums_sql() . ")
239 253
           AND (q.Page != 'collages' OR c.Deleted = '0')";
240
-      $QueryID = G::$DB->get_query_id();
241
-      G::$DB->query($sql);
242
-      list($QuoteNotificationsCount) = G::$DB->next_record();
243
-      G::$DB->set_query_id($QueryID);
244
-      G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
254
+            $QueryID = G::$DB->get_query_id();
255
+            G::$DB->query($sql);
256
+            list($QuoteNotificationsCount) = G::$DB->next_record();
257
+            G::$DB->set_query_id($QueryID);
258
+            G::$Cache->cache_value('notify_quoted_' . G::$LoggedUser['ID'], $QuoteNotificationsCount, 0);
259
+        }
260
+        return (int)$QuoteNotificationsCount;
245 261
     }
246
-    return (int)$QuoteNotificationsCount;
247
-  }
248 262
 
249
-  /**
250
-   * Returns the key which holds this $TopicID in the subscription array.
251
-   * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
252
-   * @param int $TopicID
253
-   * @return bool|int
254
-   */
255
-  public static function has_subscribed($TopicID) {
256
-    $UserSubscriptions = self::get_subscriptions();
257
-    return array_search($TopicID, $UserSubscriptions);
258
-  }
263
+    /**
264
+     * Returns the key which holds this $TopicID in the subscription array.
265
+     * Use type-aware comparison operators with this! (ie. if (self::has_subscribed($TopicID) !== false) { ... })
266
+     * @param int $TopicID
267
+     * @return bool|int
268
+     */
269
+    public static function has_subscribed($TopicID)
270
+    {
271
+        $UserSubscriptions = self::get_subscriptions();
272
+        return array_search($TopicID, $UserSubscriptions);
273
+    }
259 274
 
260
-  /**
261
-   * Same as has_subscribed, but for comment subscriptions.
262
-   * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
263
-   * @param int $PageID
264
-   * @return bool|int
265
-   */
266
-  public static function has_subscribed_comments($Page, $PageID) {
267
-    $UserCommentSubscriptions = self::get_comment_subscriptions();
268
-    return array_search(array($Page, $PageID), $UserCommentSubscriptions);
269
-  }
275
+    /**
276
+     * Same as has_subscribed, but for comment subscriptions.
277
+     * @param string $Page 'artist', 'collages', 'requests' or 'torrents'
278
+     * @param int $PageID
279
+     * @return bool|int
280
+     */
281
+    public static function has_subscribed_comments($Page, $PageID)
282
+    {
283
+        $UserCommentSubscriptions = self::get_comment_subscriptions();
284
+        return array_search(array($Page, $PageID), $UserCommentSubscriptions);
285
+    }
270 286
 
271
-  /**
272
-   * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
273
-   * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
274
-   * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
275
-   */
276
-  public static function flush_subscriptions($Page, $PageID) {
277
-    $QueryID = G::$DB->get_query_id();
278
-    if ($Page == 'forums') {
279
-      G::$DB->query("
287
+    /**
288
+     * Clear the subscription cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
289
+     * @param type $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
290
+     * @param type $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
291
+     */
292
+    public static function flush_subscriptions($Page, $PageID)
293
+    {
294
+        $QueryID = G::$DB->get_query_id();
295
+        if ($Page == 'forums') {
296
+            G::$DB->query("
280 297
         SELECT UserID
281 298
         FROM users_subscriptions
282 299
         WHERE TopicID = '$PageID'");
283
-    } else {
284
-      G::$DB->query("
300
+        } else {
301
+            G::$DB->query("
285 302
         SELECT UserID
286 303
         FROM users_subscriptions_comments
287 304
         WHERE Page = '$Page'
288 305
           AND PageID = '$PageID'");
306
+        }
307
+        $Subscribers = G::$DB->collect('UserID');
308
+        foreach ($Subscribers as $Subscriber) {
309
+            G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
310
+        }
311
+        G::$DB->set_query_id($QueryID);
289 312
     }
290
-    $Subscribers = G::$DB->collect('UserID');
291
-    foreach ($Subscribers as $Subscriber) {
292
-      G::$Cache->delete_value("subscriptions_user_new_$Subscriber");
293
-    }
294
-    G::$DB->set_query_id($QueryID);
295
-  }
296 313
 
297
-  /**
298
-   * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
299
-   * Passing $NewPageID = null will delete the subscriptions.
300
-   * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
301
-   * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
302
-   * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
303
-   */
304
-  public static function move_subscriptions($Page, $OldPageID, $NewPageID) {
305
-    self::flush_subscriptions($Page, $OldPageID);
306
-    $QueryID = G::$DB->get_query_id();
307
-    if ($Page == 'forums') {
308
-      if ($NewPageID !== null) {
309
-        G::$DB->query("
314
+    /**
315
+     * Move all $Page subscriptions from $OldPageID to $NewPageID (for example when merging torrent groups).
316
+     * Passing $NewPageID = null will delete the subscriptions.
317
+     * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
318
+     * @param int $OldPageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
319
+     * @param int|null $NewPageID As $OldPageID, or null to delete the subscriptions
320
+     */
321
+    public static function move_subscriptions($Page, $OldPageID, $NewPageID)
322
+    {
323
+        self::flush_subscriptions($Page, $OldPageID);
324
+        $QueryID = G::$DB->get_query_id();
325
+        if ($Page == 'forums') {
326
+            if ($NewPageID !== null) {
327
+                G::$DB->query("
310 328
           UPDATE IGNORE users_subscriptions
311 329
           SET TopicID = '$NewPageID'
312 330
           WHERE TopicID = '$OldPageID'");
313
-        // explanation see below
314
-        G::$DB->query("
331
+                // explanation see below
332
+                G::$DB->query("
315 333
           UPDATE IGNORE forums_last_read_topics
316 334
           SET TopicID = $NewPageID
317 335
           WHERE TopicID = $OldPageID");
318
-        G::$DB->query("
336
+                G::$DB->query("
319 337
           SELECT UserID, MIN(PostID)
320 338
           FROM forums_last_read_topics
321 339
           WHERE TopicID IN ($OldPageID, $NewPageID)
322 340
           GROUP BY UserID
323 341
           HAVING COUNT(1) = 2");
324
-        $Results = G::$DB->to_array(false, MYSQLI_NUM);
325
-        foreach ($Results as $Result) {
326
-          G::$DB->query("
342
+                $Results = G::$DB->to_array(false, MYSQLI_NUM);
343
+                foreach ($Results as $Result) {
344
+                    G::$DB->query("
327 345
             UPDATE forums_last_read_topics
328 346
             SET PostID = $Result[1]
329 347
             WHERE TopicID = $NewPageID
330 348
               AND UserID = $Result[0]");
331
-        }
332
-      }
333
-      G::$DB->query("
349
+                }
350
+            }
351
+            G::$DB->query("
334 352
         DELETE FROM users_subscriptions
335 353
         WHERE TopicID = '$OldPageID'");
336
-      G::$DB->query("
354
+            G::$DB->query("
337 355
         DELETE FROM forums_last_read_topics
338 356
         WHERE TopicID = $OldPageID");
339
-    } else {
340
-      if ($NewPageID !== null) {
341
-        G::$DB->query("
357
+        } else {
358
+            if ($NewPageID !== null) {
359
+                G::$DB->query("
342 360
           UPDATE IGNORE users_subscriptions_comments
343 361
           SET PageID = '$NewPageID'
344 362
           WHERE Page = '$Page'
345 363
             AND PageID = '$OldPageID'");
346
-        // last read handling
347
-        // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
348
-        G::$DB->query("
364
+                // last read handling
365
+                // 1) update all rows that have no key collisions (i.e. users that haven't previously read both pages or if there are only comments on one page)
366
+                G::$DB->query("
349 367
           UPDATE IGNORE users_comments_last_read
350 368
           SET PageID = '$NewPageID'
351 369
           WHERE Page = '$Page'
352 370
             AND PageID = $OldPageID");
353
-        // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
354
-        G::$DB->query("
371
+                // 2) get all last read records with key collisions (i.e. there are records for one user for both PageIDs)
372
+                G::$DB->query("
355 373
           SELECT UserID, MIN(PostID)
356 374
           FROM users_comments_last_read
357 375
           WHERE Page = '$Page'
358 376
             AND PageID IN ($OldPageID, $NewPageID)
359 377
           GROUP BY UserID
360 378
           HAVING COUNT(1) = 2");
361
-        $Results = G::$DB->to_array(false, MYSQLI_NUM);
362
-        // 3) update rows for those people found in 2) to the earlier post
363
-        foreach ($Results as $Result) {
364
-          G::$DB->query("
379
+                $Results = G::$DB->to_array(false, MYSQLI_NUM);
380
+                // 3) update rows for those people found in 2) to the earlier post
381
+                foreach ($Results as $Result) {
382
+                    G::$DB->query("
365 383
             UPDATE users_comments_last_read
366 384
             SET PostID = $Result[1]
367 385
             WHERE Page = '$Page'
368 386
               AND PageID = $NewPageID
369 387
               AND UserID = $Result[0]");
370
-        }
371
-      }
372
-      G::$DB->query("
388
+                }
389
+            }
390
+            G::$DB->query("
373 391
         DELETE FROM users_subscriptions_comments
374 392
         WHERE Page = '$Page'
375 393
           AND PageID = '$OldPageID'");
376
-      G::$DB->query("
394
+            G::$DB->query("
377 395
         DELETE FROM users_comments_last_read
378 396
         WHERE Page = '$Page'
379 397
           AND PageID = '$OldPageID'");
398
+        }
399
+        G::$DB->set_query_id($QueryID);
380 400
     }
381
-    G::$DB->set_query_id($QueryID);
382
-  }
383 401
 
384
-  /**
385
-   * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
386
-   * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
387
-   * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
388
-   */
389
-  public static function flush_quote_notifications($Page, $PageID) {
390
-    $QueryID = G::$DB->get_query_id();
391
-    G::$DB->query("
402
+    /**
403
+     * Clear the quote notification cache for all subscribers of a forum thread or artist/collage/request/torrent comments.
404
+     * @param string $Page 'forums', 'artist', 'collages', 'requests' or 'torrents'
405
+     * @param int $PageID TopicID, ArtistID, CollageID, RequestID or GroupID, respectively
406
+     */
407
+    public static function flush_quote_notifications($Page, $PageID)
408
+    {
409
+        $QueryID = G::$DB->get_query_id();
410
+        G::$DB->query("
392 411
       SELECT UserID
393 412
       FROM users_notify_quoted
394 413
       WHERE Page = '$Page'
395 414
         AND PageID = $PageID");
396
-    $Subscribers = G::$DB->collect('UserID');
397
-    foreach ($Subscribers as $Subscriber) {
398
-      G::$Cache->delete_value("notify_quoted_$Subscriber");
415
+        $Subscribers = G::$DB->collect('UserID');
416
+        foreach ($Subscribers as $Subscriber) {
417
+            G::$Cache->delete_value("notify_quoted_$Subscriber");
418
+        }
419
+        G::$DB->set_query_id($QueryID);
399 420
     }
400
-    G::$DB->set_query_id($QueryID);
401
-  }
402 421
 }

+ 251
- 236
classes/tags.class.php View File

@@ -24,278 +24,293 @@
24 24
  * Each time a new Tags object is instantiated, the tag list is merged with the
25 25
  * overall total amount of tags to provide a Top Tags list. Merging is optional.
26 26
  */
27
-class Tags {
28
-  /**
29
-   * Collects all tags processed by the Tags Class
30
-   * @static
31
-   * @var array $All Class Tags
32
-   */
33
-  private static $All = [];
27
+class Tags
28
+{
29
+    /**
30
+     * Collects all tags processed by the Tags Class
31
+     * @static
32
+     * @var array $All Class Tags
33
+     */
34
+    private static $All = [];
34 35
 
35
-  /**
36
-   * All tags in the current instance
37
-   * @var array $Tags Instance Tags
38
-   */
39
-  private $Tags = null;
36
+    /**
37
+     * All tags in the current instance
38
+     * @var array $Tags Instance Tags
39
+     */
40
+    private $Tags = null;
40 41
 
41
-  /**
42
-   * @var array $TagLink Tag link list
43
-   */
44
-  private $TagLink = [];
42
+    /**
43
+     * @var array $TagLink Tag link list
44
+     */
45
+    private $TagLink = [];
45 46
 
46
-  /**
47
-   * @var string $Primary The primary tag
48
-   */
49
-  private $Primary = '';
47
+    /**
48
+     * @var string $Primary The primary tag
49
+     */
50
+    private $Primary = '';
50 51
 
51
-  /**
52
-   * Filter tags array to remove empty spaces.
53
-   *
54
-   * @param string $TagList A string of tags separated by a space
55
-   * @param boolean $Merge Merge the tag list with the Class' tags
56
-   *        E.g., compilations and soundtracks are skipped, so false
57
-   */
58
-  public function __construct($TagList, $Merge = true) {
59
-    if ($TagList) {
60
-      $this->Tags = array_filter(explode(' ', str_replace('_', '.', $TagList)));
52
+    /**
53
+     * Filter tags array to remove empty spaces.
54
+     *
55
+     * @param string $TagList A string of tags separated by a space
56
+     * @param boolean $Merge Merge the tag list with the Class' tags
57
+     *        E.g., compilations and soundtracks are skipped, so false
58
+     */
59
+    public function __construct($TagList, $Merge = true)
60
+    {
61
+        if ($TagList) {
62
+            $this->Tags = array_filter(explode(' ', str_replace('_', '.', $TagList)));
61 63
 
62
-      if ($Merge) {
63
-        self::$All = array_merge(self::$All, $this->Tags);
64
-      }
64
+            if ($Merge) {
65
+                self::$All = array_merge(self::$All, $this->Tags);
66
+            }
65 67
 
66
-      $this->Primary = $this->Tags[0];
67
-      sort($this->Tags);
68
-    } else {
69
-      $this->Tags = [];
68
+            $this->Primary = $this->Tags[0];
69
+            sort($this->Tags);
70
+        } else {
71
+            $this->Tags = [];
72
+        }
70 73
     }
71
-  }
72
-
73
-  /**
74
-   * @return string Primary Tag
75
-   */
76
-  public function get_primary() {
77
-    return $this->Primary;
78
-  }
79 74
 
80
-  /**
81
-   * Set the primary tag
82
-   * @param string $Primary
83
-   */
84
-  public function set_primary($Primary) {
85
-    $this->Primary = (string)$Primary;
86
-  }
75
+    /**
76
+     * @return string Primary Tag
77
+     */
78
+    public function get_primary()
79
+    {
80
+        return $this->Primary;
81
+    }
87 82
 
88
-  /**
89
-   * Formats primary tag as a title
90
-   * @return string Title
91
-   */
92
-  public function title() {
93
-    return ucwords(str_replace('.', ' ', $this->Primary));
94
-  }
83
+    /**
84
+     * Set the primary tag
85
+     * @param string $Primary
86
+     */
87
+    public function set_primary($Primary)
88
+    {
89
+        $this->Primary = (string)$Primary;
90
+    }
95 91
 
96
-  /**
97
-   * Formats primary tag as a CSS class
98
-   * @return string CSS Class Name
99
-   */
100
-  public function css_name() {
101
-    return 'tags_' . str_replace('.', '_', $this->Primary);
102
-  }
92
+    /**
93
+     * Formats primary tag as a title
94
+     * @return string Title
95
+     */
96
+    public function title()
97
+    {
98
+        return ucwords(str_replace('.', ' ', $this->Primary));
99
+    }
103 100
 
104
-  /**
105
-   * @return array Tags
106
-   */
107
-  public function get_tags() {
108
-    return $this->Tags;
109
-  }
101
+    /**
102
+     * Formats primary tag as a CSS class
103
+     * @return string CSS Class Name
104
+     */
105
+    public function css_name()
106
+    {
107
+        return 'tags_' . str_replace('.', '_', $this->Primary);
108
+    }
110 109
 
111
-  /**
112
-   * @return array All tags
113
-   */
114
-  public static function all() {
115
-    return self::$All;
116
-  }
110
+    /**
111
+     * @return array Tags
112
+     */
113
+    public function get_tags()
114
+    {
115
+        return $this->Tags;
116
+    }
117 117
 
118
-  /**
119
-   * Counts and sorts All tags
120
-   * @return array All tags sorted
121
-   */
122
-  public static function sorted() {
123
-    $Sorted = array_count_values(self::$All);
124
-    arsort($Sorted);
125
-    return $Sorted;
126
-  }
118
+    /**
119
+     * @return array All tags
120
+     */
121
+    public static function all()
122
+    {
123
+        return self::$All;
124
+    }
127 125
 
128
-  /**
129
-   * Formats tags
130
-   * @param string $Link Link to a taglist page
131
-   * @param string $ArtistName Restrict tag search by this artist
132
-   * @return string List of tag links
133
-   */
134
-  public function format($Link = 'torrents.php?taglist=', $ArtistName = '') {
135
-    if (!empty($ArtistName)) {
136
-      $ArtistName = "&amp;artistname=" . urlencode($ArtistName) . "&amp;action=advanced&amp;searchsubmit=1";
126
+    /**
127
+     * Counts and sorts All tags
128
+     * @return array All tags sorted
129
+     */
130
+    public static function sorted()
131
+    {
132
+        $Sorted = array_count_values(self::$All);
133
+        arsort($Sorted);
134
+        return $Sorted;
137 135
     }
138
-    foreach ($this->Tags as $Tag) {
139
-      $Split = self::get_name_and_class($Tag);
140
-      $Name = $Split['name'];
141
-      $Class = $Split['class'];
142
-      if (empty($this->TagLink[$Tag])) {
143
-        $this->TagLink[$Tag] = '<a class="' . $Class . '" href="' . $Link . $Tag . $ArtistName . '">' . $Name . '</a>';
144
-      }
136
+
137
+    /**
138
+     * Formats tags
139
+     * @param string $Link Link to a taglist page
140
+     * @param string $ArtistName Restrict tag search by this artist
141
+     * @return string List of tag links
142
+     */
143
+    public function format($Link = 'torrents.php?taglist=', $ArtistName = '')
144
+    {
145
+        if (!empty($ArtistName)) {
146
+            $ArtistName = "&amp;artistname=" . urlencode($ArtistName) . "&amp;action=advanced&amp;searchsubmit=1";
147
+        }
148
+        foreach ($this->Tags as $Tag) {
149
+            $Split = self::get_name_and_class($Tag);
150
+            $Name = $Split['name'];
151
+            $Class = $Split['class'];
152
+            if (empty($this->TagLink[$Tag])) {
153
+                $this->TagLink[$Tag] = '<a class="' . $Class . '" href="' . $Link . $Tag . $ArtistName . '">' . $Name . '</a>';
154
+            }
155
+        }
156
+        return implode(', ', $this->TagLink);
145 157
     }
146
-    return implode(', ', $this->TagLink);
147
-  }
148 158
 
149
-  /**
150
-   * Format a list of top tags
151
-   * @param int $Max Max number of items to get
152
-   * @param string $Link  Page query where more items of this tag type can be found
153
-   * @param string $ArtistName Optional artist
154
-   */
155
-  public static function format_top($Max = 5, $Link = 'torrents.php?taglist=', $ArtistName = '') {
156
-    if (empty(self::$All)) { ?>
159
+    /**
160
+     * Format a list of top tags
161
+     * @param int $Max Max number of items to get
162
+     * @param string $Link  Page query where more items of this tag type can be found
163
+     * @param string $ArtistName Optional artist
164
+     */
165
+    public static function format_top($Max = 5, $Link = 'torrents.php?taglist=', $ArtistName = '')
166
+    {
167
+        if (empty(self::$All)) { ?>
157 168
       <li>No torrent tags</li>
158
-<?
159
-      return;
160
-    }
161
-    if (!empty($ArtistName)) {
162
-      $ArtistName = '&amp;artistname=' . urlencode($ArtistName) . '&amp;action=advanced&amp;searchsubmit=1';
163
-    }
164
-    foreach (array_slice(self::sorted(), 0, $Max) as $Tag => $Total) {
165
-      $Split = self::get_name_and_class($Tag);
166
-      $Name = $Split['name'];
167
-      $Class = $Split['class'];
168
-    ?>
169
+            <?php
170
+            return;
171
+        }
172
+        if (!empty($ArtistName)) {
173
+            $ArtistName = '&amp;artistname=' . urlencode($ArtistName) . '&amp;action=advanced&amp;searchsubmit=1';
174
+        }
175
+        foreach (array_slice(self::sorted(), 0, $Max) as $Tag => $Total) {
176
+            $Split = self::get_name_and_class($Tag);
177
+            $Name = $Split['name'];
178
+            $Class = $Split['class']; ?>
169 179
       <li><a class="<?=$Class?>" href="<?=$Link . display_str($Name) . $ArtistName?>"><?=display_str($Name)?></a> (<?=$Total?>)</li>
170
-<?    }
171
-  }
180
+            <?php
181
+        }
182
+    }
172 183
 
173
-  /**
174
-   * General purpose method to get all tag aliases from the DB
175
-   * @return array
176
-   */
177
-  public static function get_aliases() {
178
-    $TagAliases = G::$Cache->get_value('tag_aliases_search');
179
-    if ($TagAliases === false) {
180
-      G::$DB->query('
184
+    /**
185
+     * General purpose method to get all tag aliases from the DB
186
+     * @return array
187
+     */
188
+    public static function get_aliases()
189
+    {
190
+        $TagAliases = G::$Cache->get_value('tag_aliases_search');
191
+        if ($TagAliases === false) {
192
+            G::$DB->query('
181 193
       SELECT ID, BadTag, AliasTag
182 194
       FROM tag_aliases
183 195
       ORDER BY BadTag');
184
-      $TagAliases = G::$DB->to_array(false, MYSQLI_ASSOC, false);
185
-      // Unify tag aliases to be in_this_format as tags not in.this.format
186
-      array_walk_recursive($TagAliases, function(&$val) {
187
-        $val = preg_replace("/\./","_", $val);
188
-      });
189
-      // Clean up the array for smaller cache size
190
-      foreach ($TagAliases as &$TagAlias) {
191
-        foreach (array_keys($TagAlias) as $Key) {
192
-          if (is_numeric($Key)) {
193
-            unset($TagAlias[$Key]);
194
-          }
196
+            $TagAliases = G::$DB->to_array(false, MYSQLI_ASSOC, false);
197
+            // Unify tag aliases to be in_this_format as tags not in.this.format
198
+            array_walk_recursive($TagAliases, function (&$val) {
199
+                $val = preg_replace("/\./", "_", $val);
200
+            });
201
+            // Clean up the array for smaller cache size
202
+            foreach ($TagAliases as &$TagAlias) {
203
+                foreach (array_keys($TagAlias) as $Key) {
204
+                    if (is_numeric($Key)) {
205
+                        unset($TagAlias[$Key]);
206
+                    }
207
+                }
208
+            }
209
+            G::$Cache->cache_value('tag_aliases_search', $TagAliases, 3600 * 24 * 7); // cache for 7 days
195 210
         }
196
-      }
197
-      G::$Cache->cache_value('tag_aliases_search', $TagAliases, 3600 * 24 * 7); // cache for 7 days
211
+        return $TagAliases;
198 212
     }
199
-    return $TagAliases;
200
-  }
201 213
 
202
-  /**
203
-   * Replace bad tags with tag aliases
204
-   * @param array $Tags Array with sub-arrays 'include' and 'exclude'
205
-   * @return array
206
-   */
207
-  public static function remove_aliases($Tags) {
208
-    $TagAliases = self::get_aliases();
214
+    /**
215
+     * Replace bad tags with tag aliases
216
+     * @param array $Tags Array with sub-arrays 'include' and 'exclude'
217
+     * @return array
218
+     */
219
+    public static function remove_aliases($Tags)
220
+    {
221
+        $TagAliases = self::get_aliases();
209 222
 
210
-    if (isset($Tags['include'])) {
211
-      $End = count($Tags['include']);
212
-      for ($i = 0; $i < $End; $i++) {
213
-        foreach ($TagAliases as $TagAlias) {
214
-          if ($Tags['include'][$i] === $TagAlias['BadTag']) {
215
-            $Tags['include'][$i] = $TagAlias['AliasTag'];
216
-            break;
217
-          }
223
+        if (isset($Tags['include'])) {
224
+            $End = count($Tags['include']);
225
+            for ($i = 0; $i < $End; $i++) {
226
+                foreach ($TagAliases as $TagAlias) {
227
+                    if ($Tags['include'][$i] === $TagAlias['BadTag']) {
228
+                        $Tags['include'][$i] = $TagAlias['AliasTag'];
229
+                        break;
230
+                    }
231
+                }
232
+            }
233
+            // Only keep unique entries after unifying tag standard
234
+            $Tags['include'] = array_unique($Tags['include']);
218 235
         }
219
-      }
220
-      // Only keep unique entries after unifying tag standard
221
-      $Tags['include'] = array_unique($Tags['include']);
222
-    }
223 236
 
224
-    if (isset($Tags['exclude'])) {
225
-      $End = count($Tags['exclude']);
226
-      for ($i = 0; $i < $End; $i++) {
227
-        foreach ($TagAliases as $TagAlias) {
228
-          if (substr($Tags['exclude'][$i], 1) === $TagAlias['BadTag']) {
229
-            $Tags['exclude'][$i] = '!'.$TagAlias['AliasTag'];
230
-            break;
231
-          }
237
+        if (isset($Tags['exclude'])) {
238
+            $End = count($Tags['exclude']);
239
+            for ($i = 0; $i < $End; $i++) {
240
+                foreach ($TagAliases as $TagAlias) {
241
+                    if (substr($Tags['exclude'][$i], 1) === $TagAlias['BadTag']) {
242
+                        $Tags['exclude'][$i] = '!'.$TagAlias['AliasTag'];
243
+                        break;
244
+                    }
245
+                }
246
+            }
247
+            // Only keep unique entries after unifying tag standard
248
+            $Tags['exclude'] = array_unique($Tags['exclude']);
232 249
         }
233
-      }
234
-      // Only keep unique entries after unifying tag standard
235
-      $Tags['exclude'] = array_unique($Tags['exclude']);
250
+
251
+        return $Tags;
236 252
     }
237 253
 
238
-    return $Tags;
239
-  }
254
+    /**
255
+     * Filters a list of include and exclude tags to be used in a Sphinx search
256
+     * @param array $Tags An array of tags with sub-arrays 'include' and 'exclude'
257
+     * @param integer $TagType Search for Any or All of these tags.
258
+     * @return array Array keys predicate and input
259
+     *               Predicate for a Sphinx 'taglist' query
260
+     *               Input contains clean, aliased tags. Use it in a form instead of the user submitted string
261
+     */
262
+    public static function tag_filter_sph($Tags, $TagType)
263
+    {
264
+        $QueryParts = [];
265
+        $Tags = Tags::remove_aliases($Tags);
266
+        $TagList = str_replace('_', '.', implode(', ', array_merge($Tags['include'], $Tags['exclude'])));
240 267
 
241
-  /**
242
-   * Filters a list of include and exclude tags to be used in a Sphinx search
243
-   * @param array $Tags An array of tags with sub-arrays 'include' and 'exclude'
244
-   * @param integer $TagType Search for Any or All of these tags.
245
-   * @return array Array keys predicate and input
246
-   *               Predicate for a Sphinx 'taglist' query
247
-   *               Input contains clean, aliased tags. Use it in a form instead of the user submitted string
248
-   */
249
-  public static function tag_filter_sph($Tags, $TagType) {
250
-    $QueryParts = [];
251
-    $Tags = Tags::remove_aliases($Tags);
252
-    $TagList = str_replace('_', '.', implode(', ', array_merge($Tags['include'], $Tags['exclude'])));
268
+        foreach ($Tags['include'] as &$Tag) {
269
+            $Tag = Sphinxql::sph_escape_string($Tag);
270
+        }
253 271
 
254
-    foreach ($Tags['include'] as &$Tag) {
255
-      $Tag = Sphinxql::sph_escape_string($Tag);
256
-    }
272
+        if (!empty($Tags['exclude'])) {
273
+            foreach ($Tags['exclude'] as &$Tag) {
274
+                $Tag = '!' . Sphinxql::sph_escape_string(substr($Tag, 1));
275
+            }
276
+        }
257 277
 
258
-    if (!empty($Tags['exclude'])) {
259
-      foreach ($Tags['exclude'] as &$Tag) {
260
-        $Tag = '!' . Sphinxql::sph_escape_string(substr($Tag, 1));
261
-      }
262
-    }
278
+        // 'All' tags
279
+        if (!isset($TagType) || $TagType == 1) {
280
+            $SearchWords = array_merge($Tags['include'], $Tags['exclude']);
281
+            if (!empty($Tags)) {
282
+                $QueryParts[] = implode(' ', $SearchWords);
283
+            }
284
+        }
285
+        // 'Any' tags
286
+        else {
287
+            if (!empty($Tags['include'])) {
288
+                $QueryParts[] = '( ' . implode(' | ', $Tags['include']) . ' )';
289
+            }
290
+            if (!empty($Tags['exclude'])) {
291
+                $QueryParts[] = implode(' ', $Tags['exclude']);
292
+            }
293
+        }
263 294
 
264
-    // 'All' tags
265
-    if (!isset($TagType) || $TagType == 1) {
266
-      $SearchWords = array_merge($Tags['include'], $Tags['exclude']);
267
-      if (!empty($Tags)) {
268
-        $QueryParts[] = implode(' ', $SearchWords);
269
-      }
270
-    }
271
-    // 'Any' tags
272
-    else {
273
-      if (!empty($Tags['include'])) {
274
-        $QueryParts[] = '( ' . implode(' | ', $Tags['include']) . ' )';
275
-      }
276
-      if (!empty($Tags['exclude'])) {
277
-        $QueryParts[] = implode(' ', $Tags['exclude']);
278
-      }
295
+        return ['input' => $TagList, 'predicate' => implode(' ', $QueryParts)];
279 296
     }
280 297
 
281
-    return ['input' => $TagList, 'predicate' => implode(' ', $QueryParts)];
282
-  }
283
-
284
-  /**
285
-   * Breaks a tag down into name and namespace class
286
-   * @param string $Tag Tag of the form 'tag' or 'tag:namespace'
287
-   * @return array Array keys name and class
288
-   *               name is the name of the tag without a namespace
289
-   *               class is the HTML class that should be applied to the tag, empty string if the tag has no namespace
290
-   */
291
-   public static function get_name_and_class($Tag) {
292
-			$Name = $Tag;
293
-			$Class = "";
294
-			$Split = explode(':', $Tag);
295
-			if (count($Split) > 1 && in_array($Split[1], TAG_NAMESPACES)) {
296
-				$Name = $Split[0];
297
-				$Class = "tag_" . $Split[1];
298
-			}
299
-      return array("name" => display_str($Name), "class" => display_str($Class));
300
-   }
298
+    /**
299
+     * Breaks a tag down into name and namespace class
300
+     * @param string $Tag Tag of the form 'tag' or 'tag:namespace'
301
+     * @return array Array keys name and class
302
+     *               name is the name of the tag without a namespace
303
+     *               class is the HTML class that should be applied to the tag, empty string if the tag has no namespace
304
+     */
305
+    public static function get_name_and_class($Tag)
306
+    {
307
+        $Name = $Tag;
308
+        $Class = "";
309
+        $Split = explode(':', $Tag);
310
+        if (count($Split) > 1 && in_array($Split[1], TAG_NAMESPACES)) {
311
+            $Name = $Split[0];
312
+            $Class = "tag_" . $Split[1];
313
+        }
314
+        return array("name" => display_str($Name), "class" => display_str($Class));
315
+    }
301 316
 }

+ 62
- 62
classes/templates.class.php View File

@@ -1,82 +1,82 @@
1
-<?
1
+<?php
2 2
 // Example :
3 3
 // $TPL = new TEMPLATE;
4 4
 // $TPL->open('inv.tpl');
5 5
 // $TPL->set('ADDRESS1', $TPL->str_align(57, $UADDRESS1, 'l', ' '));
6 6
 // $TPL->get();
7 7
 
8
-class TEMPLATE {
9
-  var $file = '';
10
-  var $vars = [];
8
+class TEMPLATE
9
+{
10
+    public $file = '';
11
+    public $vars = [];
11 12
 
12
-  function open($file) {
13
-    $this->file = file($file);
14
-  }
15
-
16
-  function set($name, $var, $ifnone = '<span style="font-style: italic;">-None-</span>') {
17
-    if ($name != '') {
18
-      $this->vars[$name][0] = $var;
19
-      $this->vars[$name][1] = $ifnone;
13
+    public function open($file)
14
+    {
15
+        $this->file = file($file);
20 16
     }
21
-  }
22 17
 
23
-  function show() {
24
-    $TMPVAR = '';
25
-    for ($i = 0; $i < sizeof($this->file); $i++) {
26
-      $TMPVAR = $this->file[$i];
27
-      foreach ($this->vars as $k=>$v) {
28
-        if ($v[1] != '' && $v[0] == '') {
29
-          $v[0] = $v[1];
18
+    public function set($name, $var, $ifnone = '<span style="font-style: italic;">-None-</span>')
19
+    {
20
+        if ($name != '') {
21
+            $this->vars[$name][0] = $var;
22
+            $this->vars[$name][1] = $ifnone;
30 23
         }
31
-        $TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
32
-      }
33
-      print $TMPVAR;
34 24
     }
35
-  }
36 25
 
37
-  function get() {
38
-    $RESULT = '';
39
-    $TMPVAR = '';
40
-    for ($i = 0; $i < sizeof($this->file); $i++) {
41
-      $TMPVAR = $this->file[$i];
42
-      foreach ($this->vars as $k=>$v) {
43
-        if ($v[1] != '' && $v[0] == '') {
44
-          $v[0] = $v[1];
26
+    public function show()
27
+    {
28
+        $TMPVAR = '';
29
+        for ($i = 0; $i < sizeof($this->file); $i++) {
30
+            $TMPVAR = $this->file[$i];
31
+            foreach ($this->vars as $k => $v) {
32
+                if ($v[1] != '' && $v[0] == '') {
33
+                    $v[0] = $v[1];
34
+                }
35
+                $TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
36
+            }
37
+            print $TMPVAR;
45 38
         }
46
-        $TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
47
-      }
48
-      $RESULT.= $TMPVAR;
49 39
     }
50
-    return $RESULT;
51
-  }
52
-
53
-  function str_align($len, $str, $align, $fill) {
54
-    $strlen = strlen($str);
55
-    if ($strlen > $len) {
56
-      return substr($str, 0, $len);
57
-
58
-    } elseif (($strlen == 0) || ($len == 0)) {
59
-      return '';
60
-
61
-    } else {
62
-      if (($align == 'l') || ($align == 'left')) {
63
-        $result = $str.str_repeat($fill, ($len - $strlen));
64 40
 
65
-      } elseif (($align == 'r') || ($align == 'right')) {
66
-        $result = str_repeat($fill, ($len - $strlen)).$str;
67
-
68
-      } elseif (($align == 'c') || ($align == 'center')) {
69
-        $snm = intval(($len - $strlen) / 2);
70
-        if (($strlen + ($snm * 2)) == $len) {
71
-          $result = str_repeat($fill, $snm).$str;
41
+    public function get()
42
+    {
43
+        $RESULT = '';
44
+        $TMPVAR = '';
45
+        for ($i = 0; $i < sizeof($this->file); $i++) {
46
+            $TMPVAR = $this->file[$i];
47
+            foreach ($this->vars as $k => $v) {
48
+                if ($v[1] != '' && $v[0] == '') {
49
+                    $v[0] = $v[1];
50
+                }
51
+                $TMPVAR = str_replace('{{'.$k.'}}', $v[0], $TMPVAR);
52
+            }
53
+            $RESULT.= $TMPVAR;
54
+        }
55
+        return $RESULT;
56
+    }
72 57
 
58
+    public function str_align($len, $str, $align, $fill)
59
+    {
60
+        $strlen = strlen($str);
61
+        if ($strlen > $len) {
62
+            return substr($str, 0, $len);
63
+        } elseif (($strlen == 0) || ($len == 0)) {
64
+            return '';
73 65
         } else {
74
-          $result = str_repeat($fill, $snm + 1).$str;
66
+            if (($align == 'l') || ($align == 'left')) {
67
+                $result = $str.str_repeat($fill, ($len - $strlen));
68
+            } elseif (($align == 'r') || ($align == 'right')) {
69
+                $result = str_repeat($fill, ($len - $strlen)).$str;
70
+            } elseif (($align == 'c') || ($align == 'center')) {
71
+                $snm = intval(($len - $strlen) / 2);
72
+                if (($strlen + ($snm * 2)) == $len) {
73
+                    $result = str_repeat($fill, $snm).$str;
74
+                } else {
75
+                    $result = str_repeat($fill, $snm + 1).$str;
76
+                }
77
+                $result.= str_repeat($fill, $snm);
78
+            }
79
+            return $result;
75 80
         }
76
-        $result.= str_repeat($fill, $snm);
77
-      }
78
-      return $result;
79 81
     }
80
-  }
81 82
 }
82
-?>

+ 142
- 130
classes/testing.class.php View File

@@ -1,150 +1,162 @@
1
-<?
1
+<?php
2
+
3
+class Testing
4
+{
5
+    private static $ClassDirectories = array("classes");
6
+    private static $Classes = [];
7
+
8
+    /**
9
+     * Initialize the testasble classes into a map keyed by class name
10
+     */
11
+    public static function init()
12
+    {
13
+        self::load_classes();
14
+    }
2 15
 
3
-class Testing {
4
-  private static $ClassDirectories = array("classes");
5
-  private static $Classes = [];
16
+    /**
17
+     * Gets the class
18
+     */
19
+    public static function get_classes()
20
+    {
21
+        return self::$Classes;
22
+    }
6 23
 
7
-  /**
8
-   * Initialize the testasble classes into a map keyed by class name
9
-   */
10
-  public static function init() {
11
-    self::load_classes();
12
-  }
24
+    /**
25
+     * Loads all the classes within given directories
26
+     */
27
+    private static function load_classes()
28
+    {
29
+        foreach (self::$ClassDirectories as $Directory) {
30
+            $Directory = SERVER_ROOT . "/" . $Directory . "/";
31
+            foreach (glob($Directory . "*.php") as $FileName) {
32
+                self::get_class_name($FileName);
33
+            }
34
+        }
35
+    }
13 36
 
14
-  /**
15
-   * Gets the class
16
-   */
17
-  public static function get_classes() {
18
-    return self::$Classes;
19
-  }
37
+    /**
38
+     * Gets the class and adds into the map
39
+     */
40
+    private static function get_class_name($FileName)
41
+    {
42
+        $Tokens = token_get_all(file_get_contents($FileName));
43
+        $IsTestable = false;
44
+        $IsClass = false;
45
+
46
+        foreach ($Tokens as $Token) {
47
+            if (is_array($Token)) {
48
+                if (!$IsTestable && $Token[0] == T_DOC_COMMENT && strpos($Token[1], "@TestClass")) {
49
+                    $IsTestable = true;
50
+                }
51
+                if ($IsTestable && $Token[0] == T_CLASS) {
52
+                    $IsClass = true;
53
+                } elseif ($IsClass && $Token[0] == T_STRING) {
54
+                    $ReflectionClass = new ReflectionClass($Token[1]);
55
+                    if (count(self::get_testable_methods($ReflectionClass))) {
56
+                        self::$Classes[$Token[1]] = new ReflectionClass($Token[1]);
57
+                    }
58
+                    $IsTestable = false;
59
+                    $IsClass = false;
60
+                }
61
+            }
62
+        }
63
+    }
20 64
 
21
-  /**
22
-   * Loads all the classes within given directories
23
-   */
24
-  private static function load_classes() {
25
-    foreach (self::$ClassDirectories as $Directory)  {
26
-      $Directory = SERVER_ROOT . "/" . $Directory . "/";
27
-      foreach (glob($Directory . "*.php") as $FileName) {
28
-        self::get_class_name($FileName);
29
-      }
65
+    /**
66
+     * Checks if class exists in the map
67
+     */
68
+    public static function has_class($Class)
69
+    {
70
+        return array_key_exists($Class, self::$Classes);
30 71
     }
31
-  }
32 72
 
33
-  /**
34
-   * Gets the class and adds into the map
35
-   */
36
-  private static function get_class_name($FileName) {
37
-    $Tokens = token_get_all(file_get_contents($FileName));
38
-    $IsTestable = false;
39
-    $IsClass = false;
73
+    /**
74
+     * Checks if class has a given testable methood
75
+     */
76
+    public static function has_testable_method($Class, $Method)
77
+    {
78
+        $TestableMethods = self::get_testable_methods($Class);
79
+        foreach ($TestableMethods as $TestMethod) {
80
+            if ($TestMethod->getName() === $Method) {
81
+                return true;
82
+            }
83
+        }
84
+        return false;
85
+    }
40 86
 
41
-    foreach ($Tokens as $Token) {
42
-      if (is_array($Token)) {
43
-        if (!$IsTestable && $Token[0] == T_DOC_COMMENT && strpos($Token[1], "@TestClass")) {
44
-          $IsTestable = true;
87
+    /**
88
+     * Get testable methods in a class, a testable method has a @Test
89
+     */
90
+    public static function get_testable_methods($Class)
91
+    {
92
+        if (is_string($Class)) {
93
+            $ReflectionClass = self::$Classes[$Class];
94
+        } else {
95
+            $ReflectionClass = $Class;
45 96
         }
46
-        if ($IsTestable && $Token[0] == T_CLASS) {
47
-          $IsClass = true;
48
-        } else if ($IsClass && $Token[0] == T_STRING) {
49
-          $ReflectionClass = new ReflectionClass($Token[1]);
50
-          if (count(self::get_testable_methods($ReflectionClass))) {
51
-            self::$Classes[$Token[1]] = new ReflectionClass($Token[1]);
52
-          }
53
-          $IsTestable = false;
54
-          $IsClass = false;
97
+        $ReflectionMethods = $ReflectionClass->getMethods();
98
+        $TestableMethods = [];
99
+        foreach ($ReflectionMethods as $Method) {
100
+            if ($Method->isPublic() && $Method->isStatic() && strpos($Method->getDocComment(), "@Test")) {
101
+                $TestableMethods[] = $Method;
102
+            }
55 103
         }
56
-      }
104
+        return $TestableMethods;
57 105
     }
58
-  }
59 106
 
60
-  /**
61
-   * Checks if class exists in the map
62
-   */
63
-  public static function has_class($Class) {
64
-    return array_key_exists($Class, self::$Classes);
65
-  }
66 107
 
67
-  /**
68
-   * Checks if class has a given testable methood
69
-   */
70
-  public static function has_testable_method($Class, $Method) {
71
-    $TestableMethods = self::get_testable_methods($Class);
72
-    foreach($TestableMethods as $TestMethod) {
73
-      if ($TestMethod->getName() === $Method) {
74
-        return true;
75
-      }
108
+    /**
109
+     * Get the class comment
110
+     */
111
+    public static function get_class_comment($Class)
112
+    {
113
+        $ReflectionClass = self::$Classes[$Class];
114
+        return trim(str_replace(array("@TestClass", "*", "/"), "", $ReflectionClass->getDocComment()));
76 115
     }
77
-    return false;
78
-  }
79 116
 
80
-  /**
81
-   * Get testable methods in a class, a testable method has a @Test
82
-   */
83
-  public static function get_testable_methods($Class) {
84
-    if (is_string($Class)) {
85
-      $ReflectionClass = self::$Classes[$Class];
86
-    } else {
87
-      $ReflectionClass = $Class;
88
-    }
89
-    $ReflectionMethods = $ReflectionClass->getMethods();
90
-    $TestableMethods = [];
91
-    foreach($ReflectionMethods as $Method) {
92
-      if ($Method->isPublic() && $Method->isStatic() && strpos($Method->getDocComment(), "@Test")) {
93
-        $TestableMethods[] = $Method;
94
-      }
117
+    /**
118
+     * Get the undocumented methods in a class
119
+     */
120
+    public static function get_undocumented_methods($Class)
121
+    {
122
+        $ReflectionClass = self::$Classes[$Class];
123
+        $Methods = [];
124
+        foreach ($ReflectionClass->getMethods() as $Method) {
125
+            if (!$Method->getDocComment()) {
126
+                $Methods[] = $Method;
127
+            }
128
+        }
129
+        return $Methods;
95 130
     }
96
-    return $TestableMethods;
97
-  }
98
-
99
-
100
-  /**
101
-   * Get the class comment
102
-   */
103
-  public static function get_class_comment($Class) {
104
-    $ReflectionClass = self::$Classes[$Class];
105
-    return trim(str_replace(array("@TestClass", "*", "/"), "", $ReflectionClass->getDocComment()));
106
-  }
107 131
 
108
-  /**
109
-   * Get the undocumented methods in a class
110
-   */
111
-  public static function get_undocumented_methods($Class) {
112
-    $ReflectionClass = self::$Classes[$Class];
113
-    $Methods = [];
114
-    foreach($ReflectionClass->getMethods() as $Method) {
115
-      if (!$Method->getDocComment()) {
116
-        $Methods[] = $Method;
117
-      }
132
+    /**
133
+     * Get the documented methods
134
+     */
135
+    public static function get_documented_methods($Class)
136
+    {
137
+        $ReflectionClass = self::$Classes[$Class];
138
+        $Methods = [];
139
+        foreach ($ReflectionClass->getMethods() as $Method) {
140
+            if ($Method->getDocComment()) {
141
+                $Methods[] = $Method;
142
+            }
143
+        }
144
+        return $Methods;
118 145
     }
119
-    return $Methods;
120
-  }
121 146
 
122
-  /**
123
-   * Get the documented methods
124
-   */
125
-  public static function get_documented_methods($Class)  {
126
-    $ReflectionClass = self::$Classes[$Class];
127
-    $Methods = [];
128
-    foreach($ReflectionClass->getMethods() as $Method) {
129
-      if ($Method->getDocComment()) {
130
-        $Methods[] = $Method;
131
-      }
147
+    /**
148
+     * Get all methods in a class
149
+     */
150
+    public static function get_methods($Class)
151
+    {
152
+        return self::$Classes[$Class]->getMethods();
132 153
     }
133
-    return $Methods;
134
-  }
135
-
136
-  /**
137
-   * Get all methods in a class
138
-   */
139
-  public static function get_methods($Class) {
140
-    return self::$Classes[$Class]->getMethods();
141
-  }
142 154
 
143
-  /**
144
-   * Get a method  comment
145
-   */
146
-  public static function get_method_comment($Method) {
147
-    return trim(str_replace(array("*", "/"), "", $Method->getDocComment()));
148
-  }
149
-
150
-}
155
+    /**
156
+     * Get a method  comment
157
+     */
158
+    public static function get_method_comment($Method)
159
+    {
160
+        return trim(str_replace(array("*", "/"), "", $Method->getDocComment()));
161
+    }
162
+}

+ 105
- 91
classes/testingview.class.php View File

@@ -1,24 +1,30 @@
1
-<?
1
+<?php
2 2
 
3
-class TestingView {
4
-  /**
5
-   * Render the linkbox
6
-   */
7
-  public static function render_linkbox($Page) { ?>
3
+class TestingView
4
+{
5
+    /**
6
+     * Render the linkbox
7
+     */
8
+    public static function render_linkbox($Page)
9
+    {
10
+        ?>
8 11
     <div class="linkbox">
9
-<?      if ($Page != "classes") { ?>
12
+        <?php      if ($Page != "classes") { ?>
10 13
         <a href="testing.php" class="brackets">Classes</a>
11
-<?      }
12
-      if ($Page != "comments") { ?>
14
+        <?php      }
15
+        if ($Page != "comments") { ?>
13 16
         <a href="testing.php?action=comments" class="brackets">Comments</a>
14
-<?      } ?>
17
+        <?php      } ?>
15 18
     </div>
16
-<?  }
19
+        <?php
20
+    }
17 21
 
18
-  /**
19
-   * Render a list of classes
20
-   */
21
-  public static function render_classes($Classes) { ?>
22
+    /**
23
+     * Render a list of classes
24
+     */
25
+    public static function render_classes($Classes)
26
+    {
27
+        ?>
22 28
     <table>
23 29
       <tr class="colhead">
24 30
         <td>
@@ -28,10 +34,9 @@ class TestingView {
28 34
           Testable functions
29 35
         </td>
30 36
       </tr>
31
-<?      foreach($Classes as $Key => $Value) {
32
-        $Doc = Testing::get_class_comment($Key);
33
-        $Methods = count(Testing::get_testable_methods($Key));
34
-?>
37
+        <?php      foreach ($Classes as $Key => $Value) {
38
+            $Doc = Testing::get_class_comment($Key);
39
+            $Methods = count(Testing::get_testable_methods($Key)); ?>
35 40
         <tr>
36 41
           <td>
37 42
             <a href="testing.php?action=class&amp;name=<?=$Key?>" class="tooltip" title="<?=$Doc?>"><?=$Key?></a>
@@ -40,18 +45,20 @@ class TestingView {
40 45
             <?=$Methods?>
41 46
           </td>
42 47
         </tr>
43
-<?      } ?>
48
+            <?php
49
+        } ?>
44 50
     </table>
45
-<?  }
51
+        <?php
52
+    }
46 53
 
47
-  /**
48
-   * Render functions in a class
49
-   */
50
-  public static function render_functions($Methods) {
51
-    foreach($Methods as $Index => $Method) {
52
-      $ClassName = $Method->getDeclaringClass()->getName();
53
-      $MethodName = $Method->getName();
54
-?>
54
+    /**
55
+     * Render functions in a class
56
+     */
57
+    public static function render_functions($Methods)
58
+    {
59
+        foreach ($Methods as $Index => $Method) {
60
+            $ClassName = $Method->getDeclaringClass()->getName();
61
+            $MethodName = $Method->getName(); ?>
55 62
       <div class="box box2">
56 63
         <div class="head">
57 64
           <span><?=self::render_method_definition($Method)?></span>
@@ -61,62 +68,68 @@ class TestingView {
61 68
           </span>
62 69
         </div>
63 70
         <div class="pad hidden" id="method_params_<?=$Index?>">
64
-          <?self::render_method_params($Method);?>
71
+            <?php self::render_method_params($Method); ?>
65 72
         </div>
66 73
         <div class="pad hidden" id="method_results_<?=$Index?>">
67 74
         </div>
68 75
       </div>
69
-<?    }
70
-  }
76
+            <?php
77
+        }
78
+    }
71 79
 
72
-  /**
73
-   * Render method parameters
74
-   */
75
-  private static function render_method_params($Method) { ?>
80
+    /**
81
+     * Render method parameters
82
+     */
83
+    private static function render_method_params($Method)
84
+    {
85
+        ?>
76 86
     <table>
77
-<?    foreach($Method->getParameters() as $Parameter) {
78
-      $DefaultValue = $Parameter->isDefaultValueAvailable() ? $Parameter->getDefaultValue() : "";
79
-?>
87
+        <?php    foreach ($Method->getParameters() as $Parameter) {
88
+            $DefaultValue = $Parameter->isDefaultValueAvailable() ? $Parameter->getDefaultValue() : ""; ?>
80 89
       <tr>
81 90
         <td class="label">
82
-          <?=$Parameter->getName()?>
91
+            <?=$Parameter->getName()?>
83 92
         </td>
84 93
         <td>
85 94
           <input type="text" name="<?=$Parameter->getName()?>" value="<?=$DefaultValue?>"/>
86 95
         </td>
87 96
       </tr>
88
-<?    } ?>
97
+            <?php
98
+        } ?>
89 99
     </table>
90
-<?  }
91
-
92
-  /**
93
-   * Render the method definition
94
-   */
95
-  private static function render_method_definition($Method) {
96
-    $Title = "<span class='tooltip' title='" . Testing::get_method_comment($Method) . "'>" . $Method->getName() . "</span> (";
97
-    foreach($Method->getParameters() as $Parameter) {
98
-      $Color = "red";
99
-      if ($Parameter->isDefaultValueAvailable()) {
100
-        $Color = "green";
101
-      }
102
-      $Title .= "<span style='color: $Color'>";
103
-      $Title .= "$" . $Parameter->getName();
104
-      if ($Parameter->isDefaultValueAvailable()) {
105
-        $Title .= " = " . $Parameter->getDefaultValue();
106
-      }
107
-      $Title .= "</span>";
108
-      $Title .= ", ";
100
+        <?php
101
+    }
109 102
 
103
+    /**
104
+     * Render the method definition
105
+     */
106
+    private static function render_method_definition($Method)
107
+    {
108
+        $Title = "<span class='tooltip' title='" . Testing::get_method_comment($Method) . "'>" . $Method->getName() . "</span> (";
109
+        foreach ($Method->getParameters() as $Parameter) {
110
+            $Color = "red";
111
+            if ($Parameter->isDefaultValueAvailable()) {
112
+                $Color = "green";
113
+            }
114
+            $Title .= "<span style='color: $Color'>";
115
+            $Title .= "$" . $Parameter->getName();
116
+            if ($Parameter->isDefaultValueAvailable()) {
117
+                $Title .= " = " . $Parameter->getDefaultValue();
118
+            }
119
+            $Title .= "</span>";
120
+            $Title .= ", ";
121
+        }
122
+        $Title = rtrim($Title, ", ");
123
+        $Title .= ")";
124
+        return $Title;
110 125
     }
111
-    $Title = rtrim($Title, ", ");
112
-    $Title .= ")";
113
-    return $Title;
114
-  }
115 126
 
116
-  /**
117
-   * Renders class documentation stats
118
-   */
119
-  public static function render_missing_documentation($Classes) { ?>
127
+    /**
128
+     * Renders class documentation stats
129
+     */
130
+    public static function render_missing_documentation($Classes)
131
+    {
132
+        ?>
120 133
     <table>
121 134
       <tr class="colhead">
122 135
         <td>
@@ -132,9 +145,8 @@ class TestingView {
132 145
           Documented functions
133 146
         </td>
134 147
       </tr>
135
-<?      foreach($Classes as $Key => $Value) {
136
-        $ClassComment = Testing::get_class_comment($Key);
137
-?>
148
+        <?php      foreach ($Classes as $Key => $Value) {
149
+            $ClassComment = Testing::get_class_comment($Key); ?>
138 150
         <tr>
139 151
           <td>
140 152
             <?=$Key?>
@@ -148,28 +160,30 @@ class TestingView {
148 160
             <?=count(Testing::get_documented_methods($Key))?>
149 161
           </td>
150 162
         </tr>
151
-<?      } ?>
163
+            <?php
164
+        } ?>
152 165
     </table>
153
-<?  }
166
+        <?php
167
+    }
154 168
 
155
-  /**
156
-   * Pretty print any data
157
-   */
158
-  public static function render_results($Data) {
159
-    $Results = '<pre><ul style="list-style-type: none">';
160
-    if (is_array($Data)) {
161
-      foreach ($Data as $Key => $Value){
162
-        if (is_array($Value)){
163
-          $Results .= '<li>' . $Key . ' => ' . self::render_results($Value) . '</li>';
164
-        } else{
165
-          $Results .= '<li>' . $Key . ' => ' . $Value . '</li>';
169
+    /**
170
+     * Pretty print any data
171
+     */
172
+    public static function render_results($Data)
173
+    {
174
+        $Results = '<pre><ul style="list-style-type: none">';
175
+        if (is_array($Data)) {
176
+            foreach ($Data as $Key => $Value) {
177
+                if (is_array($Value)) {
178
+                    $Results .= '<li>' . $Key . ' => ' . self::render_results($Value) . '</li>';
179
+                } else {
180
+                    $Results .= '<li>' . $Key . ' => ' . $Value . '</li>';
181
+                }
182
+            }
183
+        } else {
184
+            $Results .= '<li>' . $Data . '</li>';
166 185
         }
167
-      }
168
-    } else {
169
-      $Results .= '<li>' . $Data . '</li>';
186
+        $Results .= '</ul></pre>';
187
+        echo $Results;
170 188
     }
171
-    $Results .= '</ul></pre>';
172
-    echo $Results;
173
-  }
174
-
175 189
 }

Loading…
Cancel
Save