-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved query safety in bulk album methods
- Loading branch information
Showing
1 changed file
with
14 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* Zookeeper Online | ||
* | ||
* @author Jim Mason <[email protected]> | ||
* @copyright Copyright (C) 1997-2023 Jim Mason <[email protected]> | ||
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]> | ||
* @link https://zookeeper.ibinx.com/ | ||
* @license GPL-3.0 | ||
* | ||
|
@@ -416,14 +416,12 @@ private static function displayName($airname, $realname) { | |
public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) { | ||
$chain = []; | ||
$tags = []; | ||
$queryset = ""; | ||
for($i = 0; $albums != null && $i < sizeof($albums); $i++) { | ||
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0; | ||
if($tag) { | ||
if($tag && is_numeric($tag)) { | ||
if(array_key_exists($tag, $tags)) | ||
$chain[$i] = $tags[$tag]; | ||
else | ||
$queryset .= ", $tag"; | ||
|
||
$tags[$tag] = $i; | ||
} | ||
} | ||
|
@@ -433,7 +431,7 @@ public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) { | |
"$ib review FROM reviews r " . | ||
"LEFT JOIN users u ON r.user = u.name " . | ||
"LEFT JOIN airnames a ON r.airname = a.id WHERE " . | ||
"tag IN (0" . $queryset . ")"; | ||
"tag IN (" . implode(',', array_keys($tags)) . ")"; | ||
if(!$loggedIn) | ||
$query .= " AND private = 0"; | ||
$query .= " GROUP BY tag"; | ||
|
@@ -461,21 +459,19 @@ public function linkReviews(&$albums, $loggedIn = false, $includeBody = false) { | |
public function markAlbumsReviewed(&$albums, $loggedIn = 0) { | ||
$chain = []; | ||
$tags = []; | ||
$queryset = ""; | ||
for($i = 0; $albums != null && $i < sizeof($albums); $i++) { | ||
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0; | ||
if($tag) { | ||
if($tag && is_numeric($tag)) { | ||
if(array_key_exists($tag, $tags)) | ||
$chain[$i] = $tags[$tag]; | ||
else | ||
$queryset .= ", $tag"; | ||
|
||
$tags[$tag] = $i; | ||
} | ||
} | ||
$query = "SELECT tag, a.airname, realname FROM reviews r " . | ||
"LEFT JOIN users u ON r.user = u.name " . | ||
"LEFT JOIN airnames a ON r.airname = a.id WHERE " . | ||
"tag IN (0" . $queryset . ")"; | ||
"tag IN (" . implode(',', array_keys($tags)) . ")"; | ||
if(!$loggedIn) | ||
$query .= " AND private = 0"; | ||
$query .= " GROUP BY tag"; | ||
|
@@ -501,19 +497,19 @@ public function markAlbumsPlayable(&$albums) { | |
|
||
$chain = []; | ||
$tags = []; | ||
$queryset = ""; | ||
$querysetcoll = ""; | ||
$queryset = []; | ||
$querysetcoll = []; | ||
for($i = 0; $albums != null && $i < sizeof($albums); $i++) { | ||
$tag = array_key_exists("tag", $albums[$i])?$albums[$i]["tag"]:0; | ||
if($tag) { | ||
if($tag && is_numeric($tag)) { | ||
if(array_key_exists($tag, $tags)) | ||
$chain[$i] = $tags[$tag]; | ||
else { | ||
if(array_key_exists("iscoll", $albums[$i]) && | ||
$albums[$i]["iscoll"]) | ||
$querysetcoll .= ", $tag"; | ||
$querysetcoll[] = $tag; | ||
else | ||
$queryset .= ", $tag"; | ||
$queryset[] = $tag; | ||
} | ||
$tags[$tag] = $i; | ||
} | ||
|
@@ -522,11 +518,11 @@ public function markAlbumsPlayable(&$albums) { | |
$urlFilter = $enableExternalLinks ? "url <> ''" : "url RLIKE ?"; | ||
|
||
$query = "SELECT tag FROM tracknames ". | ||
"WHERE $urlFilter AND tag IN (0${queryset}) ". | ||
"WHERE $urlFilter AND tag IN (" . implode(',', $queryset) . ") ". | ||
"GROUP BY tag "; | ||
if($querysetcoll) | ||
$query .= "UNION SELECT tag FROM colltracknames ". | ||
"WHERE $urlFilter AND tag IN (0${querysetcoll}) ". | ||
"WHERE $urlFilter AND tag IN (" . implode(',', $querysetcoll) . ") ". | ||
"GROUP BY tag"; | ||
$stmt = $this->prepare($query); | ||
if(!$enableExternalLinks) { | ||
|