|
@@ -1,5 +1,7 @@
|
1
|
|
-<?
|
2
|
|
-class Artists {
|
|
1
|
+<?php
|
|
2
|
+class Artists
|
|
3
|
+{
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* Given an array of GroupIDs, return their associated artists.
|
5
|
7
|
*
|
|
@@ -17,27 +19,28 @@ class Artists {
|
17
|
19
|
* 5 => Conductor
|
18
|
20
|
* 6 => DJ
|
19
|
21
|
*/
|
20
|
|
- public static function get_artists($GroupIDs) {
|
21
|
|
- $Results = [];
|
22
|
|
- $DBs = [];
|
23
|
|
- foreach ($GroupIDs as $GroupID) {
|
24
|
|
- if (!is_number($GroupID)) {
|
25
|
|
- continue;
|
26
|
|
- }
|
27
|
|
- $Artists = G::$Cache->get_value('groups_artists_'.$GroupID);
|
28
|
|
- if (is_array($Artists)) {
|
29
|
|
- $Results[$GroupID] = $Artists;
|
30
|
|
- } else {
|
31
|
|
- $DBs[] = $GroupID;
|
32
|
|
- }
|
33
|
|
- }
|
34
|
|
- if (count($DBs) > 0) {
|
35
|
|
- $IDs = implode(',', $DBs);
|
36
|
|
- if (empty($IDs)) {
|
37
|
|
- $IDs = "null";
|
38
|
|
- }
|
39
|
|
- $QueryID = G::$DB->get_query_id();
|
40
|
|
- G::$DB->query("
|
|
22
|
+ public static function get_artists($GroupIDs)
|
|
23
|
+ {
|
|
24
|
+ $Results = [];
|
|
25
|
+ $DBs = [];
|
|
26
|
+ foreach ($GroupIDs as $GroupID) {
|
|
27
|
+ if (!is_number($GroupID)) {
|
|
28
|
+ continue;
|
|
29
|
+ }
|
|
30
|
+ $Artists = G::$Cache->get_value('groups_artists_'.$GroupID);
|
|
31
|
+ if (is_array($Artists)) {
|
|
32
|
+ $Results[$GroupID] = $Artists;
|
|
33
|
+ } else {
|
|
34
|
+ $DBs[] = $GroupID;
|
|
35
|
+ }
|
|
36
|
+ }
|
|
37
|
+ if (count($DBs) > 0) {
|
|
38
|
+ $IDs = implode(',', $DBs);
|
|
39
|
+ if (empty($IDs)) {
|
|
40
|
+ $IDs = "null";
|
|
41
|
+ }
|
|
42
|
+ $QueryID = G::$DB->get_query_id();
|
|
43
|
+ G::$DB->query("
|
41
|
44
|
SELECT ta.GroupID,
|
42
|
45
|
ta.ArtistID,
|
43
|
46
|
ag.Name
|
|
@@ -46,164 +49,165 @@ class Artists {
|
46
|
49
|
WHERE ta.GroupID IN ($IDs)
|
47
|
50
|
ORDER BY ta.GroupID ASC,
|
48
|
51
|
ag.Name ASC;");
|
49
|
|
- while (list($GroupID, $ArtistID, $ArtistName) = G::$DB->next_record(MYSQLI_BOTH, false)) {
|
50
|
|
- $Results[$GroupID][] = array('id' => $ArtistID, 'name' => $ArtistName);
|
51
|
|
- $New[$GroupID][] = array('id' => $ArtistID, 'name' => $ArtistName);
|
52
|
|
- }
|
53
|
|
- G::$DB->set_query_id($QueryID);
|
54
|
|
- foreach ($DBs as $GroupID) {
|
55
|
|
- if (isset($New[$GroupID])) {
|
56
|
|
- G::$Cache->cache_value('groups_artists_'.$GroupID, $New[$GroupID]);
|
57
|
|
- }
|
58
|
|
- else {
|
59
|
|
- G::$Cache->cache_value('groups_artists_'.$GroupID, []);
|
|
52
|
+ while (list($GroupID, $ArtistID, $ArtistName) = G::$DB->next_record(MYSQLI_BOTH, false)) {
|
|
53
|
+ $Results[$GroupID][] = array('id' => $ArtistID, 'name' => $ArtistName);
|
|
54
|
+ $New[$GroupID][] = array('id' => $ArtistID, 'name' => $ArtistName);
|
|
55
|
+ }
|
|
56
|
+ G::$DB->set_query_id($QueryID);
|
|
57
|
+ foreach ($DBs as $GroupID) {
|
|
58
|
+ if (isset($New[$GroupID])) {
|
|
59
|
+ G::$Cache->cache_value('groups_artists_'.$GroupID, $New[$GroupID]);
|
|
60
|
+ } else {
|
|
61
|
+ G::$Cache->cache_value('groups_artists_'.$GroupID, []);
|
|
62
|
+ }
|
|
63
|
+ }
|
|
64
|
+ $Missing = array_diff($GroupIDs, array_keys($Results));
|
|
65
|
+ if (!empty($Missing)) {
|
|
66
|
+ $Results += array_fill_keys($Missing, []);
|
|
67
|
+ }
|
60
|
68
|
}
|
61
|
|
- }
|
62
|
|
- $Missing = array_diff($GroupIDs, array_keys($Results));
|
63
|
|
- if (!empty($Missing)) {
|
64
|
|
- $Results += array_fill_keys($Missing, []);
|
65
|
|
- }
|
|
69
|
+ return $Results;
|
66
|
70
|
}
|
67
|
|
- return $Results;
|
68
|
|
- }
|
69
|
71
|
|
|
72
|
+ /**
|
|
73
|
+ * Convenience function for get_artists, when you just need one group.
|
|
74
|
+ *
|
|
75
|
+ * @param int $GroupID
|
|
76
|
+ * @return array - see get_artists
|
|
77
|
+ */
|
|
78
|
+ public static function get_artist($GroupID)
|
|
79
|
+ {
|
|
80
|
+ $Results = Artists::get_artists(array($GroupID));
|
|
81
|
+ return $Results[$GroupID];
|
|
82
|
+ }
|
70
|
83
|
|
71
|
|
- /**
|
72
|
|
- * Convenience function for get_artists, when you just need one group.
|
73
|
|
- *
|
74
|
|
- * @param int $GroupID
|
75
|
|
- * @return array - see get_artists
|
76
|
|
- */
|
77
|
|
- public static function get_artist($GroupID) {
|
78
|
|
- $Results = Artists::get_artists(array($GroupID));
|
79
|
|
- return $Results[$GroupID];
|
80
|
|
- }
|
81
|
|
-
|
82
|
|
-
|
83
|
|
- /**
|
84
|
|
- * Format an array of artists for display.
|
85
|
|
- * TODO: Revisit the logic of this, see if we can helper-function the copypasta.
|
86
|
|
- *
|
87
|
|
- * @param array Artists an array of the form output by get_artists
|
88
|
|
- * @param boolean $MakeLink if true, the artists will be links, if false, they will be text.
|
89
|
|
- * @param boolean $IncludeHyphen if true, appends " - " to the end.
|
90
|
|
- * @param $Escape if true, output will be escaped. Think carefully before setting it false.
|
91
|
|
- */
|
92
|
|
- public static function display_artists($Artists, $MakeLink = true, $IncludeHyphen = true, $Escape = true) {
|
93
|
|
- if (!empty($Artists)) {
|
94
|
|
- $ampersand = ($Escape) ? ' & ' : ' & ';
|
95
|
|
- $link = '';
|
96
|
|
-
|
97
|
|
- switch(count($Artists)) {
|
|
84
|
+ /**
|
|
85
|
+ * Format an array of artists for display.
|
|
86
|
+ * TODO: Revisit the logic of this, see if we can helper-function the copypasta.
|
|
87
|
+ *
|
|
88
|
+ * @param array Artists an array of the form output by get_artists
|
|
89
|
+ * @param boolean $MakeLink if true, the artists will be links, if false, they will be text.
|
|
90
|
+ * @param boolean $IncludeHyphen if true, appends " - " to the end.
|
|
91
|
+ * @param $Escape if true, output will be escaped. Think carefully before setting it false.
|
|
92
|
+ */
|
|
93
|
+ public static function display_artists($Artists, $MakeLink = true, $IncludeHyphen = true, $Escape = true)
|
|
94
|
+ {
|
|
95
|
+ if (!empty($Artists)) {
|
|
96
|
+ $ampersand = ($Escape) ? ' & ' : ' & ';
|
|
97
|
+ $link = '';
|
|
98
|
+
|
|
99
|
+ switch (count($Artists)) {
|
98
|
100
|
case 0:
|
99
|
101
|
break;
|
100
|
102
|
case 3:
|
101
|
103
|
$link .= Artists::display_artist($Artists[2], $MakeLink, $Escape). ", ";
|
|
104
|
+ break;
|
102
|
105
|
case 2:
|
103
|
106
|
$link .= Artists::display_artist($Artists[1], $MakeLink, $Escape). ", ";
|
|
107
|
+ break;
|
104
|
108
|
case 1:
|
105
|
109
|
$link .= Artists::display_artist($Artists[0], $MakeLink, $Escape).($IncludeHyphen?' – ':'');
|
106
|
110
|
break;
|
107
|
111
|
default:
|
108
|
|
- $link = "Various".($IncludeHyphen?' – ':'');
|
|
112
|
+ $link = Artists::display_artist($Artists[0], $MakeLink, $Escape).' et al.'.($IncludeHyphen?' – ':'');
|
109
|
113
|
}
|
110
|
114
|
|
111
|
|
- return $link;
|
112
|
|
- } else {
|
113
|
|
- return '';
|
|
115
|
+ return $link;
|
|
116
|
+ } else {
|
|
117
|
+ return '';
|
|
118
|
+ }
|
114
|
119
|
}
|
115
|
|
- }
|
116
|
|
-
|
117
|
120
|
|
118
|
|
- /**
|
119
|
|
- * Formats a single artist name.
|
120
|
|
- *
|
121
|
|
- * @param array $Artist an array of the form ('id'=>ID, 'name'=>Name)
|
122
|
|
- * @param boolean $MakeLink If true, links to the artist page.
|
123
|
|
- * @param boolean $Escape If false and $MakeLink is false, returns the unescaped, unadorned artist name.
|
124
|
|
- * @return string Formatted artist name.
|
125
|
|
- */
|
126
|
|
- public static function display_artist($Artist, $MakeLink = true, $Escape = true) {
|
127
|
|
- if ($MakeLink && !$Escape) {
|
128
|
|
- error('Invalid parameters to Artists::display_artist()');
|
129
|
|
- } elseif ($MakeLink) {
|
130
|
|
- return '<a href="artist.php?id='.$Artist['id'].'" dir="ltr">'.display_str($Artist['name']).'</a>';
|
131
|
|
- } elseif ($Escape) {
|
132
|
|
- return display_str($Artist['name']);
|
133
|
|
- } else {
|
134
|
|
- return $Artist['name'];
|
|
121
|
+ /**
|
|
122
|
+ * Formats a single artist name.
|
|
123
|
+ *
|
|
124
|
+ * @param array $Artist an array of the form ('id'=>ID, 'name'=>Name)
|
|
125
|
+ * @param boolean $MakeLink If true, links to the artist page.
|
|
126
|
+ * @param boolean $Escape If false and $MakeLink is false, returns the unescaped, unadorned artist name.
|
|
127
|
+ * @return string Formatted artist name.
|
|
128
|
+ */
|
|
129
|
+ public static function display_artist($Artist, $MakeLink = true, $Escape = true)
|
|
130
|
+ {
|
|
131
|
+ if ($MakeLink && !$Escape) {
|
|
132
|
+ error('Invalid parameters to Artists::display_artist()');
|
|
133
|
+ } elseif ($MakeLink) {
|
|
134
|
+ return '<a href="artist.php?id='.$Artist['id'].'" dir="ltr">'.display_str($Artist['name']).'</a>';
|
|
135
|
+ } elseif ($Escape) {
|
|
136
|
+ return display_str($Artist['name']);
|
|
137
|
+ } else {
|
|
138
|
+ return $Artist['name'];
|
|
139
|
+ }
|
135
|
140
|
}
|
136
|
|
- }
|
137
|
141
|
|
138
|
|
- /**
|
139
|
|
- * Deletes an artist and their requests, wiki, and tags.
|
140
|
|
- * Does NOT delete their torrents.
|
141
|
|
- *
|
142
|
|
- * @param int $ArtistID
|
143
|
|
- */
|
144
|
|
- public static function delete_artist($ArtistID) {
|
145
|
|
- $QueryID = G::$DB->get_query_id();
|
146
|
|
- G::$DB->query("
|
|
142
|
+ /**
|
|
143
|
+ * Deletes an artist and their requests, wiki, and tags.
|
|
144
|
+ * Does NOT delete their torrents.
|
|
145
|
+ *
|
|
146
|
+ * @param int $ArtistID
|
|
147
|
+ */
|
|
148
|
+ public static function delete_artist($ArtistID)
|
|
149
|
+ {
|
|
150
|
+ $QueryID = G::$DB->get_query_id();
|
|
151
|
+ G::$DB->query("
|
147
|
152
|
SELECT Name
|
148
|
153
|
FROM artists_group
|
149
|
154
|
WHERE ArtistID = ".$ArtistID);
|
150
|
|
- list($Name) = G::$DB->next_record(MYSQLI_NUM, false);
|
|
155
|
+ list($Name) = G::$DB->next_record(MYSQLI_NUM, false);
|
151
|
156
|
|
152
|
|
- // Delete requests
|
153
|
|
- G::$DB->query("
|
|
157
|
+ // Delete requests
|
|
158
|
+ G::$DB->query("
|
154
|
159
|
SELECT RequestID
|
155
|
160
|
FROM requests_artists
|
156
|
161
|
WHERE ArtistID = $ArtistID
|
157
|
162
|
AND ArtistID != 0");
|
158
|
|
- $Requests = G::$DB->to_array();
|
159
|
|
- foreach ($Requests AS $Request) {
|
160
|
|
- list($RequestID) = $Request;
|
161
|
|
- G::$DB->query('DELETE FROM requests WHERE ID='.$RequestID);
|
162
|
|
- G::$DB->query('DELETE FROM requests_votes WHERE RequestID='.$RequestID);
|
163
|
|
- G::$DB->query('DELETE FROM requests_tags WHERE RequestID='.$RequestID);
|
164
|
|
- G::$DB->query('DELETE FROM requests_artists WHERE RequestID='.$RequestID);
|
165
|
|
- }
|
|
163
|
+ $Requests = G::$DB->to_array();
|
|
164
|
+ foreach ($Requests as $Request) {
|
|
165
|
+ list($RequestID) = $Request;
|
|
166
|
+ G::$DB->query('DELETE FROM requests WHERE ID='.$RequestID);
|
|
167
|
+ G::$DB->query('DELETE FROM requests_votes WHERE RequestID='.$RequestID);
|
|
168
|
+ G::$DB->query('DELETE FROM requests_tags WHERE RequestID='.$RequestID);
|
|
169
|
+ G::$DB->query('DELETE FROM requests_artists WHERE RequestID='.$RequestID);
|
|
170
|
+ }
|
166
|
171
|
|
167
|
|
- // Delete artist
|
168
|
|
- G::$DB->query('DELETE FROM artists_group WHERE ArtistID='.$ArtistID);
|
169
|
|
- G::$Cache->decrement('stats_artist_count');
|
|
172
|
+ // Delete artist
|
|
173
|
+ G::$DB->query('DELETE FROM artists_group WHERE ArtistID='.$ArtistID);
|
|
174
|
+ G::$Cache->decrement('stats_artist_count');
|
170
|
175
|
|
171
|
|
- // Delete wiki revisions
|
172
|
|
- G::$DB->query('DELETE FROM wiki_artists WHERE PageID='.$ArtistID);
|
|
176
|
+ // Delete wiki revisions
|
|
177
|
+ G::$DB->query('DELETE FROM wiki_artists WHERE PageID='.$ArtistID);
|
173
|
178
|
|
174
|
|
- // Delete tags
|
175
|
|
- G::$DB->query('DELETE FROM artists_tags WHERE ArtistID='.$ArtistID);
|
|
179
|
+ // Delete tags
|
|
180
|
+ G::$DB->query('DELETE FROM artists_tags WHERE ArtistID='.$ArtistID);
|
176
|
181
|
|
177
|
|
- // Delete artist comments, subscriptions and quote notifications
|
178
|
|
- Comments::delete_page('artist', $ArtistID);
|
|
182
|
+ // Delete artist comments, subscriptions and quote notifications
|
|
183
|
+ Comments::delete_page('artist', $ArtistID);
|
179
|
184
|
|
180
|
|
- G::$Cache->delete_value('artist_'.$ArtistID);
|
181
|
|
- G::$Cache->delete_value('artist_groups_'.$ArtistID);
|
182
|
|
- // Record in log
|
|
185
|
+ G::$Cache->delete_value('artist_'.$ArtistID);
|
|
186
|
+ G::$Cache->delete_value('artist_groups_'.$ArtistID);
|
|
187
|
+ // Record in log
|
183
|
188
|
|
184
|
|
- if (!empty(G::$LoggedUser['Username'])) {
|
185
|
|
- $Username = G::$LoggedUser['Username'];
|
186
|
|
- } else {
|
187
|
|
- $Username = 'System';
|
|
189
|
+ if (!empty(G::$LoggedUser['Username'])) {
|
|
190
|
+ $Username = G::$LoggedUser['Username'];
|
|
191
|
+ } else {
|
|
192
|
+ $Username = 'System';
|
|
193
|
+ }
|
|
194
|
+ Misc::write_log("Artist $ArtistID ($Name) was deleted by $Username");
|
|
195
|
+ G::$DB->set_query_id($QueryID);
|
188
|
196
|
}
|
189
|
|
- Misc::write_log("Artist $ArtistID ($Name) was deleted by $Username");
|
190
|
|
- G::$DB->set_query_id($QueryID);
|
191
|
|
- }
|
192
|
|
-
|
193
|
197
|
|
194
|
|
- /**
|
195
|
|
- * Remove LRM (left-right-marker) and trims, because people copypaste carelessly.
|
196
|
|
- * If we don't do this, we get seemingly duplicate artist names.
|
197
|
|
- * TODO: make stricter, e.g. on all whitespace characters or Unicode normalisation
|
198
|
|
- *
|
199
|
|
- * @param string $ArtistName
|
200
|
|
- */
|
201
|
|
- public static function normalise_artist_name($ArtistName) {
|
202
|
|
- // \u200e is ‎
|
203
|
|
- $ArtistName = trim($ArtistName);
|
204
|
|
- $ArtistName = preg_replace('/^(\xE2\x80\x8E)+/', '', $ArtistName);
|
205
|
|
- $ArtistName = preg_replace('/(\xE2\x80\x8E)+$/', '', $ArtistName);
|
206
|
|
- return trim(preg_replace('/ +/', ' ', $ArtistName));
|
207
|
|
- }
|
|
198
|
+ /**
|
|
199
|
+ * Remove LRM (left-right-marker) and trims, because people copypaste carelessly.
|
|
200
|
+ * If we don't do this, we get seemingly duplicate artist names.
|
|
201
|
+ * TODO: make stricter, e.g. on all whitespace characters or Unicode normalisation
|
|
202
|
+ *
|
|
203
|
+ * @param string $ArtistName
|
|
204
|
+ */
|
|
205
|
+ public static function normalise_artist_name($ArtistName)
|
|
206
|
+ {
|
|
207
|
+ // \u200e is ‎
|
|
208
|
+ $ArtistName = trim($ArtistName);
|
|
209
|
+ $ArtistName = preg_replace('/^(\xE2\x80\x8E)+/', '', $ArtistName);
|
|
210
|
+ $ArtistName = preg_replace('/(\xE2\x80\x8E)+$/', '', $ArtistName);
|
|
211
|
+ return trim(preg_replace('/ +/', ' ', $ArtistName));
|
|
212
|
+ }
|
208
|
213
|
}
|
209
|
|
-?>
|