Browse Source

Use prepared queries on better, blog, and some bookmarks (add/remove artist notifications still broken)

biotorrents 3 years ago
parent
commit
8f824a4843

+ 12
- 10
sections/artist/notify.php View File

@@ -5,12 +5,12 @@ authorize();
5 5
 if (!check_perms('site_torrents_notify')) {
6 6
     error(403);
7 7
 }
8
-$ArtistID = $_GET['artistid'];
9
-if (!is_number($ArtistID)) {
10
-    error(0);
11
-}
8
+
9
+$ArtistID = (int) $_GET['artistid'];
10
+Security::checkInt($ArtistID);
11
+
12 12
 /*
13
-$DB->query("
13
+$DB->prepared_query("
14 14
   SELECT GROUP_CONCAT(Name SEPARATOR '|')
15 15
   FROM artists_alias
16 16
   WHERE ArtistID = '$ArtistID'
@@ -18,7 +18,8 @@ $DB->query("
18 18
   GROUP BY ArtistID");
19 19
 list($ArtistAliases) = $DB->next_record(MYSQLI_NUM, FALSE);
20 20
 */
21
-$DB->query("
21
+
22
+$DB->prepared_query("
22 23
   SELECT Name
23 24
   FROM artists_group
24 25
   WHERE ArtistID = '$ArtistID'");
@@ -26,7 +27,7 @@ list($ArtistAliases) = $DB->next_record(MYSQLI_NUM, false);
26 27
 
27 28
 $Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID']);
28 29
 if (empty($Notify)) {
29
-    $DB->query("
30
+    $DB->prepared_query("
30 31
     SELECT ID, Artists
31 32
     FROM users_notify_filters
32 33
     WHERE Label = 'Artist notifications'
@@ -34,13 +35,14 @@ if (empty($Notify)) {
34 35
     ORDER BY ID
35 36
     LIMIT 1");
36 37
 } else {
37
-    $DB->query("
38
+    $DB->prepared_query("
38 39
     SELECT ID, Artists
39 40
     FROM users_notify_filters
40 41
     WHERE ID = '$Notify[ID]'");
41 42
 }
43
+
42 44
 if (empty($Notify) && !$DB->has_results()) {
43
-    $DB->query("
45
+    $DB->prepared_query("
44 46
     INSERT INTO users_notify_filters
45 47
       (UserID, Label, Artists)
46 48
     VALUES
@@ -52,7 +54,7 @@ if (empty($Notify) && !$DB->has_results()) {
52 54
     list($ID, $ArtistNames) = $DB->next_record(MYSQLI_NUM, false);
53 55
     if (stripos($ArtistNames, "|$ArtistAliases|") === false) {
54 56
         $ArtistNames .= "$ArtistAliases|";
55
-        $DB->query("
57
+        $DB->prepared_query("
56 58
       UPDATE users_notify_filters
57 59
       SET Artists = '".db_string($ArtistNames)."'
58 60
       WHERE ID = '$ID'");

+ 19
- 15
sections/artist/notifyremove.php View File

@@ -1,15 +1,16 @@
1
-<?
1
+<?php
2
+#declare(strict_types=1);
3
+
2 4
 authorize();
3 5
 if (!check_perms('site_torrents_notify')) {
4
-  error(403);
5
-}
6
-$ArtistID = $_GET['artistid'];
7
-if (!is_number($ArtistID)) {
8
-  error(0);
6
+    error(403);
9 7
 }
10 8
 
9
+$ArtistID = (int) $_GET['artistid'];
10
+Security::checkInt($ArtistID);
11
+
11 12
 if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) {
12
-  $DB->query("
13
+    $DB->prepared_query("
13 14
     SELECT ID, Artists
14 15
     FROM users_notify_filters
15 16
     WHERE Label = 'Artist notifications'
@@ -17,33 +18,36 @@ if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false
17 18
     ORDER BY ID
18 19
     LIMIT 1");
19 20
 } else {
20
-  $DB->query("
21
+    $DB->prepared_query("
21 22
     SELECT ID, Artists
22 23
     FROM users_notify_filters
23 24
     WHERE ID = '$Notify[ID]'");
24 25
 }
25 26
 list($ID, $Artists) = $DB->next_record(MYSQLI_NUM, false);
26
-$DB->query("
27
+
28
+$DB->prepared_query("
27 29
   SELECT Name
28 30
   FROM artists_alias
29 31
   WHERE ArtistID = '$ArtistID'
30 32
     AND Redirect = 0");
33
+
31 34
 while (list($Alias) = $DB->next_record(MYSQLI_NUM, false)) {
32
-  while (stripos($Artists, "|$Alias|") !== false) {
33
-    $Artists = str_ireplace("|$Alias|", '|', $Artists);
34
-  }
35
+    while (stripos($Artists, "|$Alias|") !== false) {
36
+        $Artists = str_ireplace("|$Alias|", '|', $Artists);
37
+    }
35 38
 }
39
+
36 40
 if ($Artists == '|') {
37
-  $DB->query("
41
+    $DB->prepared_query("
38 42
     DELETE FROM users_notify_filters
39 43
     WHERE ID = $ID");
40 44
 } else {
41
-  $DB->query("
45
+    $DB->prepared_query("
42 46
     UPDATE users_notify_filters
43 47
     SET Artists = '".db_string($Artists)."'
44 48
     WHERE ID = '$ID'");
45 49
 }
50
+
46 51
 $Cache->delete_value('notify_filters_'.$LoggedUser['ID']);
47 52
 $Cache->delete_value('notify_artists_'.$LoggedUser['ID']);
48 53
 header('Location: '.$_SERVER['HTTP_REFERER']);
49
-?>

+ 1
- 1
sections/better/covers.php View File

@@ -31,7 +31,7 @@ LIMIT 20
31 31
 $DB->exec_prepared_query();
32 32
 
33 33
 $Groups = $DB->to_array('id', MYSQLI_ASSOC);
34
-$DB->query('SELECT FOUND_ROWS()');
34
+$DB->prepared_query('SELECT FOUND_ROWS()');
35 35
 list($NumResults) = $DB->next_record();
36 36
 $Results = Torrents::get_groups(array_keys($Groups));
37 37
 

+ 3
- 3
sections/better/folders.php View File

@@ -2,11 +2,11 @@
2 2
 #declare(strict_types=1);
3 3
 
4 4
 if (check_perms('admin_reports') && !empty($_GET['remove']) && is_number($_GET['remove'])) {
5
-    $DB->query("
5
+    $DB->prepared_query("
6 6
     DELETE FROM torrents_bad_folders
7 7
     WHERE TorrentID = ".$_GET['remove']);
8 8
 
9
-    $DB->query("
9
+    $DB->prepared_query("
10 10
     SELECT GroupID
11 11
     FROM torrents
12 12
     WHERE ID = ".$_GET['remove']);
@@ -24,7 +24,7 @@ if (!empty($_GET['filter']) && $_GET['filter'] == 'all') {
24 24
 }
25 25
 
26 26
 View::show_header('Torrents with bad folder names');
27
-$DB->query("
27
+$DB->prepared_query("
28 28
   SELECT tbf.TorrentID, t.GroupID
29 29
   FROM torrents_bad_folders AS tbf
30 30
     JOIN torrents AS t ON t.ID = tbf.TorrentID

+ 1
- 1
sections/better/literature.php View File

@@ -31,7 +31,7 @@ LIMIT 20
31 31
 ");
32 32
 
33 33
 $Groups = $DB->to_array('id', MYSQLI_ASSOC);
34
-$DB->query('SELECT FOUND_ROWS()');
34
+$DB->prepared_query('SELECT FOUND_ROWS()');
35 35
 list($NumResults) = $DB->next_record();
36 36
 $Results = Torrents::get_groups(array_keys($Groups)); ?>
37 37
 

+ 1
- 1
sections/better/single.php View File

@@ -2,7 +2,7 @@
2 2
 declare(strict_types = 1);
3 3
 
4 4
 if (($Results = $Cache->get_value('better_single_groupids')) === false) {
5
-    $DB->query("
5
+    $DB->prepared_query("
6 6
     SELECT
7 7
       t.`ID` AS `TorrentID`,
8 8
       t.`GroupID` AS `GroupID`

+ 3
- 3
sections/better/tags.php View File

@@ -2,11 +2,11 @@
2 2
 declare(strict_types=1);
3 3
 
4 4
 if (check_perms('admin_reports') && !empty($_GET['remove']) && is_number($_GET['remove'])) {
5
-    $DB->query("
5
+    $DB->prepared_query("
6 6
     DELETE FROM torrents_bad_tags
7 7
     WHERE TorrentID = ".$_GET['remove']);
8 8
 
9
-    $DB->query("
9
+    $DB->prepared_query("
10 10
     SELECT GroupID
11 11
     FROM torrents
12 12
     WHERE ID = ".$_GET['remove']);
@@ -25,7 +25,7 @@ if (!empty($_GET['filter']) && $_GET['filter'] === 'all') {
25 25
 
26 26
 View::show_header('Torrents with bad tags');
27 27
 
28
-$DB->query("
28
+$DB->prepared_query("
29 29
   SELECT tbt.TorrentID, t.GroupID
30 30
   FROM torrents_bad_tags AS tbt
31 31
     JOIN torrents AS t ON t.ID = tbt.TorrentID

+ 10
- 10
sections/blog/index.php View File

@@ -11,7 +11,7 @@ if (check_perms('admin_manage_blog')) {
11 11
         switch ($_REQUEST['action']) {
12 12
       case 'deadthread':
13 13
         if (is_number($_GET['id'])) {
14
-            $DB->query("
14
+            $DB->prepared_query("
15 15
             UPDATE blog
16 16
             SET ThreadID = NULL
17 17
             WHERE ID = ".$_GET['id']);
@@ -24,7 +24,7 @@ if (check_perms('admin_manage_blog')) {
24 24
       case 'takeeditblog':
25 25
         authorize();
26 26
         if (is_number($_POST['blogid']) && is_number($_POST['thread'])) {
27
-            $DB->query("
27
+            $DB->prepared_query("
28 28
             UPDATE blog
29 29
             SET
30 30
               Title = '".db_string($_POST['title'])."',
@@ -40,7 +40,7 @@ if (check_perms('admin_manage_blog')) {
40 40
       case 'editblog':
41 41
         if (is_number($_GET['id'])) {
42 42
             $BlogID = $_GET['id'];
43
-            $DB->query("
43
+            $DB->prepared_query("
44 44
             SELECT Title, Body, ThreadID
45 45
             FROM blog
46 46
             WHERE ID = $BlogID");
@@ -51,7 +51,7 @@ if (check_perms('admin_manage_blog')) {
51 51
       case 'deleteblog':
52 52
         if (is_number($_GET['id'])) {
53 53
             authorize();
54
-            $DB->query("
54
+            $DB->prepared_query("
55 55
             DELETE FROM blog
56 56
             WHERE ID = '".db_string($_GET['id'])."'");
57 57
             $Cache->delete_value('blog');
@@ -66,7 +66,7 @@ if (check_perms('admin_manage_blog')) {
66 66
         $Body = db_string($_POST['body']);
67 67
         $ThreadID = $_POST['thread'];
68 68
         if ($ThreadID && is_number($ThreadID)) {
69
-            $DB->query("
69
+            $DB->prepared_query("
70 70
             SELECT ForumID
71 71
             FROM forums_topics
72 72
             WHERE ID = $ThreadID");
@@ -81,7 +81,7 @@ if (check_perms('admin_manage_blog')) {
81 81
             }
82 82
         }
83 83
 
84
-        $DB->query("
84
+        $DB->prepared_query("
85 85
           INSERT INTO blog
86 86
             (UserID, Title, Body, Time, ThreadID, Important)
87 87
           VALUES
@@ -96,7 +96,7 @@ if (check_perms('admin_manage_blog')) {
96 96
             $Cache->delete_value('blog_latest_id');
97 97
         }
98 98
         if (isset($_POST['subscribe'])) {
99
-            $DB->query("
99
+            $DB->prepared_query("
100 100
             INSERT IGNORE INTO users_subscriptions
101 101
             VALUES ('$LoggedUser[ID]', $ThreadID)");
102 102
             $Cache->delete_value('subscriptions_user_'.$LoggedUser['ID']);
@@ -140,7 +140,7 @@ if (check_perms('admin_manage_blog')) {
140 140
       <label for="subscribebox">Subscribe</label>
141 141
 
142 142
       <div class="center">
143
-        <input type="submit"
143
+        <input type="submit" class="button-primary"
144 144
           value="<?=!isset($_GET['action']) ? 'Create blog post' : 'Edit blog post'; ?>" />
145 145
       </div>
146 146
     </div>
@@ -153,7 +153,7 @@ if (check_perms('admin_manage_blog')) {
153 153
 <div>
154 154
   <?php
155 155
 if (!$Blog = $Cache->get_value('blog')) {
156
-    $DB->query("
156
+    $DB->prepared_query("
157 157
     SELECT
158 158
       b.ID,
159 159
       um.Username,
@@ -174,7 +174,7 @@ if ($LoggedUser['LastReadBlog'] < $Blog[0][0]) {
174 174
     $Cache->begin_transaction('user_info_heavy_'.$LoggedUser['ID']);
175 175
     $Cache->update_row(false, array('LastReadBlog' => $Blog[0][0]));
176 176
     $Cache->commit_transaction(0);
177
-    $DB->query("
177
+    $DB->prepared_query("
178 178
     UPDATE users_info
179 179
     SET LastReadBlog = '".$Blog[0][0]."'
180 180
     WHERE UserID = ".$LoggedUser['ID']);

+ 6
- 6
sections/bookmarks/add.php View File

@@ -18,7 +18,7 @@ if (!is_number($_GET['id'])) {
18 18
 }
19 19
 
20 20
 $PageID = $_GET['id'];
21
-$DB->query("
21
+$DB->prepared_query("
22 22
 SELECT
23 23
   `UserID`
24 24
 FROM
@@ -29,7 +29,7 @@ WHERE
29 29
 
30 30
 if (!$DB->has_results()) {
31 31
     if ($Type === 'torrent') {
32
-        $DB->query("
32
+        $DB->prepared_query("
33 33
         SELECT
34 34
           MAX(`Sort`)
35 35
         FROM
@@ -44,7 +44,7 @@ if (!$DB->has_results()) {
44 44
         }
45 45
 
46 46
         $Sort += 1;
47
-        $DB->query("
47
+        $DB->prepared_query("
48 48
         INSERT IGNORE
49 49
         INTO $Table(`UserID`, $Col, `Time`, `Sort`)
50 50
         VALUES(
@@ -55,7 +55,7 @@ if (!$DB->has_results()) {
55 55
         )
56 56
         ");
57 57
     } else {
58
-        $DB->query("
58
+        $DB->prepared_query("
59 59
         INSERT IGNORE
60 60
         INTO $Table(`UserID`, $Col, `Time`)
61 61
         VALUES(
@@ -69,7 +69,7 @@ if (!$DB->has_results()) {
69 69
     $Cache->delete_value('bookmarks_'.$Type.'_'.$LoggedUser['ID']);
70 70
     if ($Type === 'torrent') {
71 71
         $Cache->delete_value("bookmarks_group_ids_$UserID");
72
-        $DB->query("
72
+        $DB->prepared_query("
73 73
         SELECT
74 74
           `title`,
75 75
           `year`,
@@ -115,7 +115,7 @@ if (!$DB->has_results()) {
115 115
             $Feed->populate('torrents_bookmarks_t_'.$LoggedUser['torrent_pass'], $Item);
116 116
         }
117 117
     } elseif ($Type === 'request') {
118
-        $DB->query("
118
+        $DB->prepared_query("
119 119
         SELECT
120 120
           `UserID`
121 121
         FROM

+ 3
- 3
sections/bookmarks/artists.php View File

@@ -13,7 +13,7 @@ if (!empty($_GET['userid'])) {
13 13
         error(404);
14 14
     }
15 15
 
16
-    $DB->query("
16
+    $DB->prepared_query("
17 17
       SELECT Username
18 18
       FROM users_main
19 19
       WHERE ID = '$UserID'");
@@ -25,7 +25,7 @@ if (!empty($_GET['userid'])) {
25 25
 $Sneaky = $UserID !== $LoggedUser['ID'];
26 26
 //$ArtistList = Bookmarks::all_bookmarks('artist', $UserID);
27 27
 
28
-$DB->query("
28
+$DB->prepared_query("
29 29
   SELECT ag.ArtistID, ag.Name
30 30
   FROM bookmarks_artists AS ba
31 31
     INNER JOIN artists_group AS ag ON ba.ArtistID = ag.ArtistID
@@ -81,7 +81,7 @@ foreach ($ArtistList as $Artist) {
81 81
         <?php
82 82
   if (check_perms('site_torrents_notify')) {
83 83
       if (($Notify = $Cache->get_value('notify_artists_'.$LoggedUser['ID'])) === false) {
84
-          $DB->query("
84
+          $DB->prepared_query("
85 85
             SELECT ID, Artists
86 86
             FROM users_notify_filters
87 87
             WHERE UserID = '$LoggedUser[ID]'

Loading…
Cancel
Save