@@ -76,271 +76,271 @@ discard block |
||
76 | 76 | */ |
77 | 77 | class ServicesJSON |
78 | 78 | { |
79 | - /** |
|
80 | - * constructs a new JSON instance |
|
81 | - * |
|
82 | - * @param int $use object behavior flags; combine with boolean-OR |
|
83 | - * |
|
84 | - * possible values: |
|
85 | - * - SERVICES_JSON_LOOSE_TYPE: loose typing. |
|
86 | - * "{...}" syntax creates associative arrays |
|
87 | - * instead of objects in decode(). |
|
88 | - * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
|
89 | - * Values which can't be encoded (e.g. resources) |
|
90 | - * appear as NULL instead of throwing errors. |
|
91 | - * By default, a deeply-nested resource will |
|
92 | - * bubble up with an error, so all return values |
|
93 | - * from encode() should be checked with isError() |
|
94 | - */ |
|
95 | - public function __construct($use = 0) |
|
96 | - { |
|
97 | - $this->use = $use; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * convert a string from one UTF-16 char to one UTF-8 char |
|
102 | - * |
|
103 | - * Normally should be handled by mb_convert_encoding, but |
|
104 | - * provides a slower PHP-only method for installations |
|
105 | - * that lack the multibye string extension. |
|
106 | - * |
|
107 | - * @param string $utf16 UTF-16 character |
|
108 | - * @return string UTF-8 character |
|
109 | - */ |
|
110 | - public function utf162utf8($utf16): string |
|
111 | - { |
|
112 | - // oh please oh please oh please oh please oh please |
|
113 | - if (function_exists('mb_convert_encoding')) { |
|
114 | - return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
115 | - } |
|
116 | - |
|
117 | - $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
|
118 | - |
|
119 | - switch (true) { |
|
120 | - case ((0x7F & $bytes) == $bytes): |
|
121 | - // this case should never be reached, because we are in ASCII range |
|
122 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
123 | - return chr(0x7F & $bytes); |
|
124 | - case (0x07FF & $bytes) == $bytes: |
|
125 | - // return a 2-byte UTF-8 character |
|
126 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
127 | - return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
128 | - case (0xFFFF & $bytes) == $bytes: |
|
129 | - // return a 3-byte UTF-8 character |
|
130 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
131 | - return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
132 | - } |
|
133 | - |
|
134 | - // ignoring UTF-32 for now, sorry |
|
135 | - return ''; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * convert a string from one UTF-8 char to one UTF-16 char |
|
140 | - * |
|
141 | - * Normally should be handled by mb_convert_encoding, but |
|
142 | - * provides a slower PHP-only method for installations |
|
143 | - * that lack the multibye string extension. |
|
144 | - * |
|
145 | - * @param string $utf8 UTF-8 character |
|
146 | - * @return string UTF-16 character |
|
147 | - */ |
|
148 | - public function utf82utf16($utf8): string |
|
149 | - { |
|
150 | - // oh please oh please oh please oh please oh please |
|
151 | - if (function_exists('mb_convert_encoding')) { |
|
152 | - return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
153 | - } |
|
154 | - |
|
155 | - switch (mb_strlen($utf8)) { |
|
156 | - case 1: |
|
157 | - // this case should never be reached, because we are in ASCII range |
|
158 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
159 | - return $utf8; |
|
160 | - case 2: |
|
161 | - // return a UTF-16 character from a 2-byte UTF-8 char |
|
162 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
163 | - return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
164 | - case 3: |
|
165 | - // return a UTF-16 character from a 3-byte UTF-8 char |
|
166 | - // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
167 | - return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
168 | - } |
|
169 | - |
|
170 | - // ignoring UTF-32 for now, sorry |
|
171 | - return ''; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * encodes an arbitrary variable into JSON format (and sends JSON Header) |
|
176 | - * |
|
177 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
178 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
179 | - * if var is a strng, note that encode() always expects it |
|
180 | - * to be in ASCII or UTF-8 format! |
|
181 | - * |
|
182 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
183 | - */ |
|
184 | - public function encode($var) |
|
185 | - { |
|
186 | - header('Document-type: application/json'); |
|
187 | - |
|
188 | - return $this->encodeUnsafe($var); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!) |
|
193 | - * |
|
194 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
195 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
196 | - * if var is a strng, note that encode() always expects it |
|
197 | - * to be in ASCII or UTF-8 format! |
|
198 | - * |
|
199 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
200 | - */ |
|
201 | - public function encodeUnsafe($var) |
|
202 | - { |
|
203 | - // see bug #16908 - regarding numeric locale printing |
|
204 | - $lc = setlocale(LC_NUMERIC, 0); |
|
205 | - setlocale(LC_NUMERIC, 'C'); |
|
206 | - $ret = $this->_encode($var); |
|
207 | - setlocale(LC_NUMERIC, $lc); |
|
208 | - |
|
209 | - return $ret; |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format |
|
214 | - * |
|
215 | - * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
216 | - * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
217 | - * if var is a strng, note that encode() always expects it |
|
218 | - * to be in ASCII or UTF-8 format! |
|
219 | - * |
|
220 | - * @return mixed JSON string representation of input var or an error if a problem occurs |
|
221 | - */ |
|
222 | - public function _encode($var) |
|
223 | - { |
|
224 | - switch (gettype($var)) { |
|
225 | - case 'boolean': |
|
226 | - return $var ? 'true' : 'false'; |
|
227 | - case 'NULL': |
|
228 | - return 'null'; |
|
229 | - case 'integer': |
|
230 | - return (int)$var; |
|
231 | - case 'double': |
|
232 | - case 'float': |
|
233 | - return (float)$var; |
|
234 | - case 'string': |
|
235 | - // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
236 | - $ascii = ''; |
|
237 | - $strlen_var = mb_strlen($var); |
|
238 | - |
|
239 | - /* |
|
79 | + /** |
|
80 | + * constructs a new JSON instance |
|
81 | + * |
|
82 | + * @param int $use object behavior flags; combine with boolean-OR |
|
83 | + * |
|
84 | + * possible values: |
|
85 | + * - SERVICES_JSON_LOOSE_TYPE: loose typing. |
|
86 | + * "{...}" syntax creates associative arrays |
|
87 | + * instead of objects in decode(). |
|
88 | + * - SERVICES_JSON_SUPPRESS_ERRORS: error suppression. |
|
89 | + * Values which can't be encoded (e.g. resources) |
|
90 | + * appear as NULL instead of throwing errors. |
|
91 | + * By default, a deeply-nested resource will |
|
92 | + * bubble up with an error, so all return values |
|
93 | + * from encode() should be checked with isError() |
|
94 | + */ |
|
95 | + public function __construct($use = 0) |
|
96 | + { |
|
97 | + $this->use = $use; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * convert a string from one UTF-16 char to one UTF-8 char |
|
102 | + * |
|
103 | + * Normally should be handled by mb_convert_encoding, but |
|
104 | + * provides a slower PHP-only method for installations |
|
105 | + * that lack the multibye string extension. |
|
106 | + * |
|
107 | + * @param string $utf16 UTF-16 character |
|
108 | + * @return string UTF-8 character |
|
109 | + */ |
|
110 | + public function utf162utf8($utf16): string |
|
111 | + { |
|
112 | + // oh please oh please oh please oh please oh please |
|
113 | + if (function_exists('mb_convert_encoding')) { |
|
114 | + return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
|
115 | + } |
|
116 | + |
|
117 | + $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
|
118 | + |
|
119 | + switch (true) { |
|
120 | + case ((0x7F & $bytes) == $bytes): |
|
121 | + // this case should never be reached, because we are in ASCII range |
|
122 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
123 | + return chr(0x7F & $bytes); |
|
124 | + case (0x07FF & $bytes) == $bytes: |
|
125 | + // return a 2-byte UTF-8 character |
|
126 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
127 | + return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
128 | + case (0xFFFF & $bytes) == $bytes: |
|
129 | + // return a 3-byte UTF-8 character |
|
130 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
131 | + return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
132 | + } |
|
133 | + |
|
134 | + // ignoring UTF-32 for now, sorry |
|
135 | + return ''; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * convert a string from one UTF-8 char to one UTF-16 char |
|
140 | + * |
|
141 | + * Normally should be handled by mb_convert_encoding, but |
|
142 | + * provides a slower PHP-only method for installations |
|
143 | + * that lack the multibye string extension. |
|
144 | + * |
|
145 | + * @param string $utf8 UTF-8 character |
|
146 | + * @return string UTF-16 character |
|
147 | + */ |
|
148 | + public function utf82utf16($utf8): string |
|
149 | + { |
|
150 | + // oh please oh please oh please oh please oh please |
|
151 | + if (function_exists('mb_convert_encoding')) { |
|
152 | + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); |
|
153 | + } |
|
154 | + |
|
155 | + switch (mb_strlen($utf8)) { |
|
156 | + case 1: |
|
157 | + // this case should never be reached, because we are in ASCII range |
|
158 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
159 | + return $utf8; |
|
160 | + case 2: |
|
161 | + // return a UTF-16 character from a 2-byte UTF-8 char |
|
162 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
163 | + return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
164 | + case 3: |
|
165 | + // return a UTF-16 character from a 3-byte UTF-8 char |
|
166 | + // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
167 | + return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
168 | + } |
|
169 | + |
|
170 | + // ignoring UTF-32 for now, sorry |
|
171 | + return ''; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * encodes an arbitrary variable into JSON format (and sends JSON Header) |
|
176 | + * |
|
177 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
178 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
179 | + * if var is a strng, note that encode() always expects it |
|
180 | + * to be in ASCII or UTF-8 format! |
|
181 | + * |
|
182 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
183 | + */ |
|
184 | + public function encode($var) |
|
185 | + { |
|
186 | + header('Document-type: application/json'); |
|
187 | + |
|
188 | + return $this->encodeUnsafe($var); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * encodes an arbitrary variable into JSON format without JSON Header - warning - may allow CSS!!!!) |
|
193 | + * |
|
194 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
195 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
196 | + * if var is a strng, note that encode() always expects it |
|
197 | + * to be in ASCII or UTF-8 format! |
|
198 | + * |
|
199 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
200 | + */ |
|
201 | + public function encodeUnsafe($var) |
|
202 | + { |
|
203 | + // see bug #16908 - regarding numeric locale printing |
|
204 | + $lc = setlocale(LC_NUMERIC, 0); |
|
205 | + setlocale(LC_NUMERIC, 'C'); |
|
206 | + $ret = $this->_encode($var); |
|
207 | + setlocale(LC_NUMERIC, $lc); |
|
208 | + |
|
209 | + return $ret; |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * PRIVATE CODE that does the work of encodes an arbitrary variable into JSON format |
|
214 | + * |
|
215 | + * @param mixed $var any number, boolean, string, array, or object to be encoded. |
|
216 | + * see argument 1 to ServicesJSON() above for array-parsing behavior. |
|
217 | + * if var is a strng, note that encode() always expects it |
|
218 | + * to be in ASCII or UTF-8 format! |
|
219 | + * |
|
220 | + * @return mixed JSON string representation of input var or an error if a problem occurs |
|
221 | + */ |
|
222 | + public function _encode($var) |
|
223 | + { |
|
224 | + switch (gettype($var)) { |
|
225 | + case 'boolean': |
|
226 | + return $var ? 'true' : 'false'; |
|
227 | + case 'NULL': |
|
228 | + return 'null'; |
|
229 | + case 'integer': |
|
230 | + return (int)$var; |
|
231 | + case 'double': |
|
232 | + case 'float': |
|
233 | + return (float)$var; |
|
234 | + case 'string': |
|
235 | + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
|
236 | + $ascii = ''; |
|
237 | + $strlen_var = mb_strlen($var); |
|
238 | + |
|
239 | + /* |
|
240 | 240 | * Iterate over every character in the string, |
241 | 241 | * escaping with a slash or encoding to UTF-8 where necessary |
242 | 242 | */ |
243 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
244 | - $ord_var_c = ord($var[$c]); |
|
245 | - |
|
246 | - switch (true) { |
|
247 | - case 0x08 == $ord_var_c: |
|
248 | - $ascii .= '\b'; |
|
249 | - break; |
|
250 | - case 0x09 == $ord_var_c: |
|
251 | - $ascii .= '\t'; |
|
252 | - break; |
|
253 | - case 0x0A == $ord_var_c: |
|
254 | - $ascii .= '\n'; |
|
255 | - break; |
|
256 | - case 0x0C == $ord_var_c: |
|
257 | - $ascii .= '\f'; |
|
258 | - break; |
|
259 | - case 0x0D == $ord_var_c: |
|
260 | - $ascii .= '\r'; |
|
261 | - break; |
|
262 | - case 0x22 == $ord_var_c: |
|
263 | - case 0x2F == $ord_var_c: |
|
264 | - case 0x5C == $ord_var_c: |
|
265 | - // double quote, slash, slosh |
|
266 | - $ascii .= '\\' . $var[$c]; |
|
267 | - break; |
|
268 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
269 | - // characters U-00000000 - U-0000007F (same as ASCII) |
|
270 | - $ascii .= $var[$c]; |
|
271 | - break; |
|
272 | - case (0xC0 == ($ord_var_c & 0xE0)): |
|
273 | - // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
274 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
275 | - if ($c + 1 >= $strlen_var) { |
|
276 | - ++$c; |
|
277 | - $ascii .= '?'; |
|
278 | - break; |
|
279 | - } |
|
280 | - |
|
281 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
282 | - ++$c; |
|
283 | - $utf16 = $this->utf82utf16($char); |
|
284 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
285 | - break; |
|
286 | - case (0xE0 == ($ord_var_c & 0xF0)): |
|
287 | - if ($c + 2 >= $strlen_var) { |
|
288 | - $c += 2; |
|
289 | - $ascii .= '?'; |
|
290 | - break; |
|
291 | - } |
|
292 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
293 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
294 | - $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
295 | - $c += 2; |
|
296 | - $utf16 = $this->utf82utf16($char); |
|
297 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
298 | - break; |
|
299 | - case (0xF0 == ($ord_var_c & 0xF8)): |
|
300 | - if ($c + 3 >= $strlen_var) { |
|
301 | - $c += 3; |
|
302 | - $ascii .= '?'; |
|
303 | - break; |
|
304 | - } |
|
305 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
306 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
307 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
308 | - $c += 3; |
|
309 | - $utf16 = $this->utf82utf16($char); |
|
310 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
311 | - break; |
|
312 | - case (0xF8 == ($ord_var_c & 0xFC)): |
|
313 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
314 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
315 | - if ($c + 4 >= $strlen_var) { |
|
316 | - $c += 4; |
|
317 | - $ascii .= '?'; |
|
318 | - break; |
|
319 | - } |
|
320 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
321 | - $c += 4; |
|
322 | - $utf16 = $this->utf82utf16($char); |
|
323 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
324 | - break; |
|
325 | - case (0xFC == ($ord_var_c & 0xFE)): |
|
326 | - if ($c + 5 >= $strlen_var) { |
|
327 | - $c += 5; |
|
328 | - $ascii .= '?'; |
|
329 | - break; |
|
330 | - } |
|
331 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
332 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
333 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
334 | - $c += 5; |
|
335 | - $utf16 = $this->utf82utf16($char); |
|
336 | - $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
337 | - break; |
|
338 | - } |
|
339 | - } |
|
340 | - |
|
341 | - return '"' . $ascii . '"'; |
|
342 | - case 'array': |
|
343 | - /* |
|
243 | + for ($c = 0; $c < $strlen_var; ++$c) { |
|
244 | + $ord_var_c = ord($var[$c]); |
|
245 | + |
|
246 | + switch (true) { |
|
247 | + case 0x08 == $ord_var_c: |
|
248 | + $ascii .= '\b'; |
|
249 | + break; |
|
250 | + case 0x09 == $ord_var_c: |
|
251 | + $ascii .= '\t'; |
|
252 | + break; |
|
253 | + case 0x0A == $ord_var_c: |
|
254 | + $ascii .= '\n'; |
|
255 | + break; |
|
256 | + case 0x0C == $ord_var_c: |
|
257 | + $ascii .= '\f'; |
|
258 | + break; |
|
259 | + case 0x0D == $ord_var_c: |
|
260 | + $ascii .= '\r'; |
|
261 | + break; |
|
262 | + case 0x22 == $ord_var_c: |
|
263 | + case 0x2F == $ord_var_c: |
|
264 | + case 0x5C == $ord_var_c: |
|
265 | + // double quote, slash, slosh |
|
266 | + $ascii .= '\\' . $var[$c]; |
|
267 | + break; |
|
268 | + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
269 | + // characters U-00000000 - U-0000007F (same as ASCII) |
|
270 | + $ascii .= $var[$c]; |
|
271 | + break; |
|
272 | + case (0xC0 == ($ord_var_c & 0xE0)): |
|
273 | + // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
274 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
275 | + if ($c + 1 >= $strlen_var) { |
|
276 | + ++$c; |
|
277 | + $ascii .= '?'; |
|
278 | + break; |
|
279 | + } |
|
280 | + |
|
281 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
282 | + ++$c; |
|
283 | + $utf16 = $this->utf82utf16($char); |
|
284 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
285 | + break; |
|
286 | + case (0xE0 == ($ord_var_c & 0xF0)): |
|
287 | + if ($c + 2 >= $strlen_var) { |
|
288 | + $c += 2; |
|
289 | + $ascii .= '?'; |
|
290 | + break; |
|
291 | + } |
|
292 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
293 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
294 | + $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
295 | + $c += 2; |
|
296 | + $utf16 = $this->utf82utf16($char); |
|
297 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
298 | + break; |
|
299 | + case (0xF0 == ($ord_var_c & 0xF8)): |
|
300 | + if ($c + 3 >= $strlen_var) { |
|
301 | + $c += 3; |
|
302 | + $ascii .= '?'; |
|
303 | + break; |
|
304 | + } |
|
305 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
306 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
307 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
308 | + $c += 3; |
|
309 | + $utf16 = $this->utf82utf16($char); |
|
310 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
311 | + break; |
|
312 | + case (0xF8 == ($ord_var_c & 0xFC)): |
|
313 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
314 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
315 | + if ($c + 4 >= $strlen_var) { |
|
316 | + $c += 4; |
|
317 | + $ascii .= '?'; |
|
318 | + break; |
|
319 | + } |
|
320 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
321 | + $c += 4; |
|
322 | + $utf16 = $this->utf82utf16($char); |
|
323 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
324 | + break; |
|
325 | + case (0xFC == ($ord_var_c & 0xFE)): |
|
326 | + if ($c + 5 >= $strlen_var) { |
|
327 | + $c += 5; |
|
328 | + $ascii .= '?'; |
|
329 | + break; |
|
330 | + } |
|
331 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
332 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
333 | + $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
334 | + $c += 5; |
|
335 | + $utf16 = $this->utf82utf16($char); |
|
336 | + $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
|
337 | + break; |
|
338 | + } |
|
339 | + } |
|
340 | + |
|
341 | + return '"' . $ascii . '"'; |
|
342 | + case 'array': |
|
343 | + /* |
|
344 | 344 | * As per JSON spec if any array key is not an integer |
345 | 345 | * we must treat the the whole array as an object. We |
346 | 346 | * also try to catch a sparsely populated associative |
@@ -358,422 +358,422 @@ discard block |
||
358 | 358 | * bracket notation. |
359 | 359 | */ |
360 | 360 | |
361 | - // treat as a JSON object |
|
362 | - if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
363 | - $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
|
364 | - |
|
365 | - foreach ($properties as $property) { |
|
366 | - if ($this->isError($property)) { |
|
367 | - return $property; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - return '{' . implode(',', $properties) . '}'; |
|
372 | - } |
|
373 | - |
|
374 | - // treat it like a regular array |
|
375 | - $elements = array_map([$this, '_encode'], $var); |
|
376 | - |
|
377 | - foreach ($elements as $element) { |
|
378 | - if ($this->isError($element)) { |
|
379 | - return $element; |
|
380 | - } |
|
381 | - } |
|
382 | - |
|
383 | - return '[' . implode(',', $elements) . ']'; |
|
384 | - case 'object': |
|
385 | - $vars = get_object_vars($var); |
|
386 | - |
|
387 | - $properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars)); |
|
388 | - |
|
389 | - foreach ($properties as $property) { |
|
390 | - if ($this->isError($property)) { |
|
391 | - return $property; |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - return '{' . implode(',', $properties) . '}'; |
|
396 | - default: |
|
397 | - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
398 | - } |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * array-walking function for use in generating JSON-formatted name-value pairs |
|
403 | - * |
|
404 | - * @param string $name name of key to use |
|
405 | - * @param mixed $value reference to an array element to be encoded |
|
406 | - * |
|
407 | - * @return string JSON-formatted name-value pair, like '"name":value' |
|
408 | - */ |
|
409 | - public function name_value($name, $value) |
|
410 | - { |
|
411 | - $encoded_value = $this->_encode($value); |
|
412 | - |
|
413 | - if ($this->isError($encoded_value)) { |
|
414 | - return $encoded_value; |
|
415 | - } |
|
416 | - |
|
417 | - return $this->_encode((string)$name) . ':' . $encoded_value; |
|
418 | - } |
|
419 | - |
|
420 | - /** |
|
421 | - * reduce a string by removing leading and trailing comments and whitespace |
|
422 | - * |
|
423 | - * @param string $str string value to strip of comments and whitespace |
|
424 | - * |
|
425 | - * @return string string value stripped of comments and whitespace |
|
426 | - */ |
|
427 | - public function reduce_string($str): string |
|
428 | - { |
|
429 | - $str = preg_replace( |
|
430 | - [ |
|
431 | - // eliminate single line comments in '// ...' form |
|
432 | - '#^\s*//(.+)$#m', |
|
433 | - |
|
434 | - // eliminate multi-line comments in '/* ... */' form, at start of string |
|
435 | - '#^\s*/\*(.+)\*/#Us', |
|
436 | - |
|
437 | - // eliminate multi-line comments in '/* ... */' form, at end of string |
|
438 | - '#/\*(.+)\*/\s*$#Us', |
|
439 | - ], |
|
440 | - '', |
|
441 | - $str |
|
442 | - ); |
|
443 | - |
|
444 | - // eliminate extraneous space |
|
445 | - return trim($str); |
|
446 | - } |
|
447 | - |
|
448 | - /** |
|
449 | - * decodes a JSON string into appropriate variable |
|
450 | - * |
|
451 | - * @param string $str JSON-formatted string |
|
452 | - * |
|
453 | - * @return array|bool|float|int|\stdClass|string|void|null number, boolean, string, array, or object |
|
454 | - * corresponding to given JSON input string. |
|
455 | - * See argument 1 to ServicesJSON() above for object-output behavior. |
|
456 | - * Note that decode() always returns strings |
|
457 | - * in ASCII or UTF-8 format! |
|
458 | - */ |
|
459 | - public function decode($str) |
|
460 | - { |
|
461 | - $str = $this->reduce_string($str); |
|
462 | - |
|
463 | - switch (mb_strtolower($str)) { |
|
464 | - case 'true': |
|
465 | - return true; |
|
466 | - case 'false': |
|
467 | - return false; |
|
468 | - case 'null': |
|
469 | - return null; |
|
470 | - default: |
|
471 | - $m = []; |
|
472 | - |
|
473 | - if (is_numeric($str)) { |
|
474 | - // Lookie-loo, it's a number |
|
475 | - |
|
476 | - // This would work on its own, but I'm trying to be |
|
477 | - // good about returning integers where appropriate: |
|
478 | - // return (float)$str; |
|
479 | - |
|
480 | - // Return float or int, as appropriate |
|
481 | - return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
482 | - } |
|
483 | - |
|
484 | - if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
485 | - // STRINGS RETURNED IN UTF-8 FORMAT |
|
486 | - $delim = mb_substr($str, 0, 1); |
|
487 | - $chrs = mb_substr($str, 1, -1); |
|
488 | - $utf8 = ''; |
|
489 | - $strlen_chrs = mb_strlen($chrs); |
|
490 | - |
|
491 | - for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
492 | - $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
493 | - $ord_chrs_c = ord($chrs[$c]); |
|
494 | - |
|
495 | - switch (true) { |
|
496 | - case '\b' === $substr_chrs_c_2: |
|
497 | - $utf8 .= chr(0x08); |
|
498 | - ++$c; |
|
499 | - break; |
|
500 | - case '\t' === $substr_chrs_c_2: |
|
501 | - $utf8 .= chr(0x09); |
|
502 | - ++$c; |
|
503 | - break; |
|
504 | - case '\n' === $substr_chrs_c_2: |
|
505 | - $utf8 .= chr(0x0A); |
|
506 | - ++$c; |
|
507 | - break; |
|
508 | - case '\f' === $substr_chrs_c_2: |
|
509 | - $utf8 .= chr(0x0C); |
|
510 | - ++$c; |
|
511 | - break; |
|
512 | - case '\r' === $substr_chrs_c_2: |
|
513 | - $utf8 .= chr(0x0D); |
|
514 | - ++$c; |
|
515 | - break; |
|
516 | - case '\\"' === $substr_chrs_c_2: |
|
517 | - case '\\\'' === $substr_chrs_c_2: |
|
518 | - case '\\\\' === $substr_chrs_c_2: |
|
519 | - case '\\/' === $substr_chrs_c_2: |
|
520 | - if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
521 | - || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
522 | - $utf8 .= $chrs[++$c]; |
|
523 | - } |
|
524 | - break; |
|
525 | - case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
|
526 | - // single, escaped unicode character |
|
527 | - $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
528 | - $utf8 .= $this->utf162utf8($utf16); |
|
529 | - $c += 5; |
|
530 | - break; |
|
531 | - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
532 | - $utf8 .= $chrs[$c]; |
|
533 | - break; |
|
534 | - case 0xC0 == ($ord_chrs_c & 0xE0): |
|
535 | - // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
536 | - //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
537 | - $utf8 .= mb_substr($chrs, $c, 2); |
|
538 | - ++$c; |
|
539 | - break; |
|
540 | - case 0xE0 == ($ord_chrs_c & 0xF0): |
|
541 | - // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
542 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
543 | - $utf8 .= mb_substr($chrs, $c, 3); |
|
544 | - $c += 2; |
|
545 | - break; |
|
546 | - case 0xF0 == ($ord_chrs_c & 0xF8): |
|
547 | - // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
548 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
549 | - $utf8 .= mb_substr($chrs, $c, 4); |
|
550 | - $c += 3; |
|
551 | - break; |
|
552 | - case 0xF8 == ($ord_chrs_c & 0xFC): |
|
553 | - // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
554 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
555 | - $utf8 .= mb_substr($chrs, $c, 5); |
|
556 | - $c += 4; |
|
557 | - break; |
|
558 | - case 0xFC == ($ord_chrs_c & 0xFE): |
|
559 | - // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
560 | - // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
561 | - $utf8 .= mb_substr($chrs, $c, 6); |
|
562 | - $c += 5; |
|
563 | - break; |
|
564 | - } |
|
565 | - } |
|
566 | - |
|
567 | - return $utf8; |
|
568 | - } |
|
569 | - |
|
570 | - if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
|
571 | - // array, or object notation |
|
572 | - |
|
573 | - if ('[' === $str[0]) { |
|
574 | - $stk = [SERVICES_JSON_IN_ARR]; |
|
575 | - $arr = []; |
|
576 | - } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
577 | - $stk = [SERVICES_JSON_IN_OBJ]; |
|
578 | - $obj = []; |
|
579 | - } else { |
|
580 | - $stk = [SERVICES_JSON_IN_OBJ]; |
|
581 | - $obj = new stdClass(); |
|
582 | - } |
|
583 | - |
|
584 | - array_push( |
|
585 | - $stk, |
|
586 | - [ |
|
587 | - 'what' => SERVICES_JSON_SLICE, |
|
588 | - 'where' => 0, |
|
589 | - 'delim' => false, |
|
590 | - ] |
|
591 | - ); |
|
592 | - |
|
593 | - $chrs = mb_substr($str, 1, -1); |
|
594 | - $chrs = $this->reduce_string($chrs); |
|
595 | - |
|
596 | - if ('' == $chrs) { |
|
597 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
598 | - return $arr; |
|
599 | - } |
|
600 | - |
|
601 | - return $obj; |
|
602 | - } |
|
603 | - |
|
604 | - //print("\nparsing {$chrs}\n"); |
|
605 | - |
|
606 | - $strlen_chrs = mb_strlen($chrs); |
|
607 | - |
|
608 | - for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
609 | - $top = end($stk); |
|
610 | - $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
611 | - |
|
612 | - if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
613 | - // found a comma that is not inside a string, array, etc., |
|
614 | - // OR we've reached the end of the character list |
|
615 | - $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
616 | - array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
617 | - //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
618 | - |
|
619 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
620 | - // we are in an array, so just push an element onto the stack |
|
621 | - $arr[] = $this->decode($slice); |
|
622 | - } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
623 | - // we are in an object, so figure |
|
624 | - // out the property name and set an |
|
625 | - // element in an associative array, |
|
626 | - // for now |
|
627 | - $parts = []; |
|
628 | - |
|
629 | - if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
630 | - // "name":value pair |
|
631 | - $key = $this->decode($parts[1]); |
|
632 | - $val = $this->decode($parts[2]); |
|
633 | - |
|
634 | - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
635 | - $obj[$key] = $val; |
|
636 | - } else { |
|
637 | - $obj->$key = $val; |
|
638 | - } |
|
639 | - } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
640 | - // name:value pair, where name is unquoted |
|
641 | - $key = $parts[1]; |
|
642 | - $val = $this->decode($parts[2]); |
|
643 | - |
|
644 | - if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
645 | - $obj[$key] = $val; |
|
646 | - } else { |
|
647 | - $obj->$key = $val; |
|
648 | - } |
|
649 | - } |
|
650 | - } |
|
651 | - } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
652 | - // found a quote, and we are not inside a string |
|
653 | - array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
|
654 | - //print("Found start of string at {$c}\n"); |
|
655 | - } elseif (($chrs[$c] == $top['delim']) |
|
656 | - && (SERVICES_JSON_IN_STR == $top['what']) |
|
657 | - && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
658 | - // found a quote, we're in a string, and it's not escaped |
|
659 | - // we know that it's not escaped becase there is _not_ an |
|
660 | - // odd number of backslashes at the end of the string so far |
|
661 | - array_pop($stk); |
|
662 | - //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
|
663 | - } elseif (('[' === $chrs[$c]) |
|
664 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
665 | - // found a left-bracket, and we are in an array, object, or slice |
|
666 | - array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
|
667 | - //print("Found start of array at {$c}\n"); |
|
668 | - } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
669 | - // found a right-bracket, and we're in an array |
|
670 | - array_pop($stk); |
|
671 | - //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
672 | - } elseif (('{' === $chrs[$c]) |
|
673 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
674 | - // found a left-brace, and we are in an array, object, or slice |
|
675 | - array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
|
676 | - //print("Found start of object at {$c}\n"); |
|
677 | - } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
678 | - // found a right-brace, and we're in an object |
|
679 | - array_pop($stk); |
|
680 | - //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
681 | - } elseif (('/*' === $substr_chrs_c_2) |
|
682 | - && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
683 | - // found a comment start, and we are in an array, object, or slice |
|
684 | - array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
|
685 | - ++$c; |
|
686 | - //print("Found start of comment at {$c}\n"); |
|
687 | - } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
688 | - // found a comment end, and we're in one now |
|
689 | - array_pop($stk); |
|
690 | - ++$c; |
|
691 | - |
|
692 | - for ($i = $top['where']; $i <= $c; ++$i) { |
|
693 | - $chrs = substr_replace($chrs, ' ', $i, 1); |
|
694 | - } |
|
695 | - //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
696 | - } |
|
697 | - } |
|
698 | - |
|
699 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
700 | - return $arr; |
|
701 | - } |
|
702 | - |
|
703 | - if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
704 | - return $obj; |
|
705 | - } |
|
706 | - } |
|
707 | - } |
|
708 | - } |
|
709 | - |
|
710 | - /** |
|
711 | - * @param $data |
|
712 | - * @param null $code |
|
713 | - * @return bool |
|
714 | - * @todo Ultimately, this should just call PEAR::isError() |
|
715 | - */ |
|
716 | - public function isError($data, $code = null): bool |
|
717 | - { |
|
718 | - if (class_exists('pear')) { |
|
719 | - return PEAR::isError($data, $code); |
|
720 | - } |
|
721 | - |
|
722 | - if (is_object($data) |
|
723 | - && ($data instanceof \services_json_error |
|
724 | - || $data instanceof \services_json_error)) { |
|
725 | - return true; |
|
726 | - } |
|
727 | - |
|
728 | - return false; |
|
729 | - } |
|
361 | + // treat as a JSON object |
|
362 | + if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
363 | + $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
|
364 | + |
|
365 | + foreach ($properties as $property) { |
|
366 | + if ($this->isError($property)) { |
|
367 | + return $property; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + return '{' . implode(',', $properties) . '}'; |
|
372 | + } |
|
373 | + |
|
374 | + // treat it like a regular array |
|
375 | + $elements = array_map([$this, '_encode'], $var); |
|
376 | + |
|
377 | + foreach ($elements as $element) { |
|
378 | + if ($this->isError($element)) { |
|
379 | + return $element; |
|
380 | + } |
|
381 | + } |
|
382 | + |
|
383 | + return '[' . implode(',', $elements) . ']'; |
|
384 | + case 'object': |
|
385 | + $vars = get_object_vars($var); |
|
386 | + |
|
387 | + $properties = array_map([$this, 'name_value'], array_keys($vars), array_values($vars)); |
|
388 | + |
|
389 | + foreach ($properties as $property) { |
|
390 | + if ($this->isError($property)) { |
|
391 | + return $property; |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + return '{' . implode(',', $properties) . '}'; |
|
396 | + default: |
|
397 | + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
398 | + } |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * array-walking function for use in generating JSON-formatted name-value pairs |
|
403 | + * |
|
404 | + * @param string $name name of key to use |
|
405 | + * @param mixed $value reference to an array element to be encoded |
|
406 | + * |
|
407 | + * @return string JSON-formatted name-value pair, like '"name":value' |
|
408 | + */ |
|
409 | + public function name_value($name, $value) |
|
410 | + { |
|
411 | + $encoded_value = $this->_encode($value); |
|
412 | + |
|
413 | + if ($this->isError($encoded_value)) { |
|
414 | + return $encoded_value; |
|
415 | + } |
|
416 | + |
|
417 | + return $this->_encode((string)$name) . ':' . $encoded_value; |
|
418 | + } |
|
419 | + |
|
420 | + /** |
|
421 | + * reduce a string by removing leading and trailing comments and whitespace |
|
422 | + * |
|
423 | + * @param string $str string value to strip of comments and whitespace |
|
424 | + * |
|
425 | + * @return string string value stripped of comments and whitespace |
|
426 | + */ |
|
427 | + public function reduce_string($str): string |
|
428 | + { |
|
429 | + $str = preg_replace( |
|
430 | + [ |
|
431 | + // eliminate single line comments in '// ...' form |
|
432 | + '#^\s*//(.+)$#m', |
|
433 | + |
|
434 | + // eliminate multi-line comments in '/* ... */' form, at start of string |
|
435 | + '#^\s*/\*(.+)\*/#Us', |
|
436 | + |
|
437 | + // eliminate multi-line comments in '/* ... */' form, at end of string |
|
438 | + '#/\*(.+)\*/\s*$#Us', |
|
439 | + ], |
|
440 | + '', |
|
441 | + $str |
|
442 | + ); |
|
443 | + |
|
444 | + // eliminate extraneous space |
|
445 | + return trim($str); |
|
446 | + } |
|
447 | + |
|
448 | + /** |
|
449 | + * decodes a JSON string into appropriate variable |
|
450 | + * |
|
451 | + * @param string $str JSON-formatted string |
|
452 | + * |
|
453 | + * @return array|bool|float|int|\stdClass|string|void|null number, boolean, string, array, or object |
|
454 | + * corresponding to given JSON input string. |
|
455 | + * See argument 1 to ServicesJSON() above for object-output behavior. |
|
456 | + * Note that decode() always returns strings |
|
457 | + * in ASCII or UTF-8 format! |
|
458 | + */ |
|
459 | + public function decode($str) |
|
460 | + { |
|
461 | + $str = $this->reduce_string($str); |
|
462 | + |
|
463 | + switch (mb_strtolower($str)) { |
|
464 | + case 'true': |
|
465 | + return true; |
|
466 | + case 'false': |
|
467 | + return false; |
|
468 | + case 'null': |
|
469 | + return null; |
|
470 | + default: |
|
471 | + $m = []; |
|
472 | + |
|
473 | + if (is_numeric($str)) { |
|
474 | + // Lookie-loo, it's a number |
|
475 | + |
|
476 | + // This would work on its own, but I'm trying to be |
|
477 | + // good about returning integers where appropriate: |
|
478 | + // return (float)$str; |
|
479 | + |
|
480 | + // Return float or int, as appropriate |
|
481 | + return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
482 | + } |
|
483 | + |
|
484 | + if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
485 | + // STRINGS RETURNED IN UTF-8 FORMAT |
|
486 | + $delim = mb_substr($str, 0, 1); |
|
487 | + $chrs = mb_substr($str, 1, -1); |
|
488 | + $utf8 = ''; |
|
489 | + $strlen_chrs = mb_strlen($chrs); |
|
490 | + |
|
491 | + for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
492 | + $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
493 | + $ord_chrs_c = ord($chrs[$c]); |
|
494 | + |
|
495 | + switch (true) { |
|
496 | + case '\b' === $substr_chrs_c_2: |
|
497 | + $utf8 .= chr(0x08); |
|
498 | + ++$c; |
|
499 | + break; |
|
500 | + case '\t' === $substr_chrs_c_2: |
|
501 | + $utf8 .= chr(0x09); |
|
502 | + ++$c; |
|
503 | + break; |
|
504 | + case '\n' === $substr_chrs_c_2: |
|
505 | + $utf8 .= chr(0x0A); |
|
506 | + ++$c; |
|
507 | + break; |
|
508 | + case '\f' === $substr_chrs_c_2: |
|
509 | + $utf8 .= chr(0x0C); |
|
510 | + ++$c; |
|
511 | + break; |
|
512 | + case '\r' === $substr_chrs_c_2: |
|
513 | + $utf8 .= chr(0x0D); |
|
514 | + ++$c; |
|
515 | + break; |
|
516 | + case '\\"' === $substr_chrs_c_2: |
|
517 | + case '\\\'' === $substr_chrs_c_2: |
|
518 | + case '\\\\' === $substr_chrs_c_2: |
|
519 | + case '\\/' === $substr_chrs_c_2: |
|
520 | + if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
521 | + || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
522 | + $utf8 .= $chrs[++$c]; |
|
523 | + } |
|
524 | + break; |
|
525 | + case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
|
526 | + // single, escaped unicode character |
|
527 | + $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
528 | + $utf8 .= $this->utf162utf8($utf16); |
|
529 | + $c += 5; |
|
530 | + break; |
|
531 | + case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
532 | + $utf8 .= $chrs[$c]; |
|
533 | + break; |
|
534 | + case 0xC0 == ($ord_chrs_c & 0xE0): |
|
535 | + // characters U-00000080 - U-000007FF, mask 110SONGLIST |
|
536 | + //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
537 | + $utf8 .= mb_substr($chrs, $c, 2); |
|
538 | + ++$c; |
|
539 | + break; |
|
540 | + case 0xE0 == ($ord_chrs_c & 0xF0): |
|
541 | + // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
|
542 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
543 | + $utf8 .= mb_substr($chrs, $c, 3); |
|
544 | + $c += 2; |
|
545 | + break; |
|
546 | + case 0xF0 == ($ord_chrs_c & 0xF8): |
|
547 | + // characters U-00010000 - U-001FFFFF, mask 11110XXX |
|
548 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
549 | + $utf8 .= mb_substr($chrs, $c, 4); |
|
550 | + $c += 3; |
|
551 | + break; |
|
552 | + case 0xF8 == ($ord_chrs_c & 0xFC): |
|
553 | + // characters U-00200000 - U-03FFFFFF, mask 111110XX |
|
554 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
555 | + $utf8 .= mb_substr($chrs, $c, 5); |
|
556 | + $c += 4; |
|
557 | + break; |
|
558 | + case 0xFC == ($ord_chrs_c & 0xFE): |
|
559 | + // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
|
560 | + // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
|
561 | + $utf8 .= mb_substr($chrs, $c, 6); |
|
562 | + $c += 5; |
|
563 | + break; |
|
564 | + } |
|
565 | + } |
|
566 | + |
|
567 | + return $utf8; |
|
568 | + } |
|
569 | + |
|
570 | + if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
|
571 | + // array, or object notation |
|
572 | + |
|
573 | + if ('[' === $str[0]) { |
|
574 | + $stk = [SERVICES_JSON_IN_ARR]; |
|
575 | + $arr = []; |
|
576 | + } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
577 | + $stk = [SERVICES_JSON_IN_OBJ]; |
|
578 | + $obj = []; |
|
579 | + } else { |
|
580 | + $stk = [SERVICES_JSON_IN_OBJ]; |
|
581 | + $obj = new stdClass(); |
|
582 | + } |
|
583 | + |
|
584 | + array_push( |
|
585 | + $stk, |
|
586 | + [ |
|
587 | + 'what' => SERVICES_JSON_SLICE, |
|
588 | + 'where' => 0, |
|
589 | + 'delim' => false, |
|
590 | + ] |
|
591 | + ); |
|
592 | + |
|
593 | + $chrs = mb_substr($str, 1, -1); |
|
594 | + $chrs = $this->reduce_string($chrs); |
|
595 | + |
|
596 | + if ('' == $chrs) { |
|
597 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
598 | + return $arr; |
|
599 | + } |
|
600 | + |
|
601 | + return $obj; |
|
602 | + } |
|
603 | + |
|
604 | + //print("\nparsing {$chrs}\n"); |
|
605 | + |
|
606 | + $strlen_chrs = mb_strlen($chrs); |
|
607 | + |
|
608 | + for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
609 | + $top = end($stk); |
|
610 | + $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
|
611 | + |
|
612 | + if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
613 | + // found a comma that is not inside a string, array, etc., |
|
614 | + // OR we've reached the end of the character list |
|
615 | + $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
616 | + array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
617 | + //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
618 | + |
|
619 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
620 | + // we are in an array, so just push an element onto the stack |
|
621 | + $arr[] = $this->decode($slice); |
|
622 | + } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
623 | + // we are in an object, so figure |
|
624 | + // out the property name and set an |
|
625 | + // element in an associative array, |
|
626 | + // for now |
|
627 | + $parts = []; |
|
628 | + |
|
629 | + if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
630 | + // "name":value pair |
|
631 | + $key = $this->decode($parts[1]); |
|
632 | + $val = $this->decode($parts[2]); |
|
633 | + |
|
634 | + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
635 | + $obj[$key] = $val; |
|
636 | + } else { |
|
637 | + $obj->$key = $val; |
|
638 | + } |
|
639 | + } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) { |
|
640 | + // name:value pair, where name is unquoted |
|
641 | + $key = $parts[1]; |
|
642 | + $val = $this->decode($parts[2]); |
|
643 | + |
|
644 | + if ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
|
645 | + $obj[$key] = $val; |
|
646 | + } else { |
|
647 | + $obj->$key = $val; |
|
648 | + } |
|
649 | + } |
|
650 | + } |
|
651 | + } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
652 | + // found a quote, and we are not inside a string |
|
653 | + array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
|
654 | + //print("Found start of string at {$c}\n"); |
|
655 | + } elseif (($chrs[$c] == $top['delim']) |
|
656 | + && (SERVICES_JSON_IN_STR == $top['what']) |
|
657 | + && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
658 | + // found a quote, we're in a string, and it's not escaped |
|
659 | + // we know that it's not escaped becase there is _not_ an |
|
660 | + // odd number of backslashes at the end of the string so far |
|
661 | + array_pop($stk); |
|
662 | + //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
|
663 | + } elseif (('[' === $chrs[$c]) |
|
664 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
665 | + // found a left-bracket, and we are in an array, object, or slice |
|
666 | + array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
|
667 | + //print("Found start of array at {$c}\n"); |
|
668 | + } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
669 | + // found a right-bracket, and we're in an array |
|
670 | + array_pop($stk); |
|
671 | + //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
672 | + } elseif (('{' === $chrs[$c]) |
|
673 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
674 | + // found a left-brace, and we are in an array, object, or slice |
|
675 | + array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
|
676 | + //print("Found start of object at {$c}\n"); |
|
677 | + } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
678 | + // found a right-brace, and we're in an object |
|
679 | + array_pop($stk); |
|
680 | + //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
681 | + } elseif (('/*' === $substr_chrs_c_2) |
|
682 | + && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
|
683 | + // found a comment start, and we are in an array, object, or slice |
|
684 | + array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
|
685 | + ++$c; |
|
686 | + //print("Found start of comment at {$c}\n"); |
|
687 | + } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
688 | + // found a comment end, and we're in one now |
|
689 | + array_pop($stk); |
|
690 | + ++$c; |
|
691 | + |
|
692 | + for ($i = $top['where']; $i <= $c; ++$i) { |
|
693 | + $chrs = substr_replace($chrs, ' ', $i, 1); |
|
694 | + } |
|
695 | + //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
|
696 | + } |
|
697 | + } |
|
698 | + |
|
699 | + if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
700 | + return $arr; |
|
701 | + } |
|
702 | + |
|
703 | + if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
704 | + return $obj; |
|
705 | + } |
|
706 | + } |
|
707 | + } |
|
708 | + } |
|
709 | + |
|
710 | + /** |
|
711 | + * @param $data |
|
712 | + * @param null $code |
|
713 | + * @return bool |
|
714 | + * @todo Ultimately, this should just call PEAR::isError() |
|
715 | + */ |
|
716 | + public function isError($data, $code = null): bool |
|
717 | + { |
|
718 | + if (class_exists('pear')) { |
|
719 | + return PEAR::isError($data, $code); |
|
720 | + } |
|
721 | + |
|
722 | + if (is_object($data) |
|
723 | + && ($data instanceof \services_json_error |
|
724 | + || $data instanceof \services_json_error)) { |
|
725 | + return true; |
|
726 | + } |
|
727 | + |
|
728 | + return false; |
|
729 | + } |
|
730 | 730 | } |
731 | 731 | |
732 | 732 | if (class_exists('PEAR_Error')) { |
733 | - /** |
|
734 | - * Class ServicesJSON_Error |
|
735 | - */ |
|
736 | - class ServicesJSON_Error extends PEAR_Error |
|
737 | - { |
|
738 | - /** |
|
739 | - * ServicesJSON_Error constructor. |
|
740 | - * @param string $message |
|
741 | - * @param null $code |
|
742 | - * @param null $mode |
|
743 | - * @param null $options |
|
744 | - * @param null $userinfo |
|
745 | - */ |
|
746 | - public function __construct( |
|
747 | - $message = 'unknown error', |
|
748 | - $code = null, |
|
749 | - $mode = null, |
|
750 | - $options = null, |
|
751 | - $userinfo = null |
|
752 | - ) { |
|
753 | - parent::__construct($message, $code, $mode, $options, $userinfo); |
|
754 | - } |
|
755 | - } |
|
733 | + /** |
|
734 | + * Class ServicesJSON_Error |
|
735 | + */ |
|
736 | + class ServicesJSON_Error extends PEAR_Error |
|
737 | + { |
|
738 | + /** |
|
739 | + * ServicesJSON_Error constructor. |
|
740 | + * @param string $message |
|
741 | + * @param null $code |
|
742 | + * @param null $mode |
|
743 | + * @param null $options |
|
744 | + * @param null $userinfo |
|
745 | + */ |
|
746 | + public function __construct( |
|
747 | + $message = 'unknown error', |
|
748 | + $code = null, |
|
749 | + $mode = null, |
|
750 | + $options = null, |
|
751 | + $userinfo = null |
|
752 | + ) { |
|
753 | + parent::__construct($message, $code, $mode, $options, $userinfo); |
|
754 | + } |
|
755 | + } |
|
756 | 756 | } else { |
757 | - /** |
|
758 | - * @todo Ultimately, this class shall be descended from PEAR_Error |
|
759 | - */ |
|
760 | - class ServicesJSON_Error |
|
761 | - { |
|
762 | - /** |
|
763 | - * ServicesJSON_Error constructor. |
|
764 | - * @param string $message |
|
765 | - * @param null $code |
|
766 | - * @param null $mode |
|
767 | - * @param null $options |
|
768 | - * @param null $userinfo |
|
769 | - */ |
|
770 | - public function __construct( |
|
771 | - $message = 'unknown error', |
|
772 | - $code = null, |
|
773 | - $mode = null, |
|
774 | - $options = null, |
|
775 | - $userinfo = null |
|
776 | - ) { |
|
777 | - } |
|
778 | - } |
|
757 | + /** |
|
758 | + * @todo Ultimately, this class shall be descended from PEAR_Error |
|
759 | + */ |
|
760 | + class ServicesJSON_Error |
|
761 | + { |
|
762 | + /** |
|
763 | + * ServicesJSON_Error constructor. |
|
764 | + * @param string $message |
|
765 | + * @param null $code |
|
766 | + * @param null $mode |
|
767 | + * @param null $options |
|
768 | + * @param null $userinfo |
|
769 | + */ |
|
770 | + public function __construct( |
|
771 | + $message = 'unknown error', |
|
772 | + $code = null, |
|
773 | + $mode = null, |
|
774 | + $options = null, |
|
775 | + $userinfo = null |
|
776 | + ) { |
|
777 | + } |
|
778 | + } |
|
779 | 779 | } |
@@ -117,18 +117,18 @@ discard block |
||
117 | 117 | $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
118 | 118 | |
119 | 119 | switch (true) { |
120 | - case ((0x7F & $bytes) == $bytes): |
|
120 | + case ((0x7F & $bytes)==$bytes): |
|
121 | 121 | // this case should never be reached, because we are in ASCII range |
122 | 122 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
123 | 123 | return chr(0x7F & $bytes); |
124 | - case (0x07FF & $bytes) == $bytes: |
|
124 | + case (0x07FF & $bytes)==$bytes: |
|
125 | 125 | // return a 2-byte UTF-8 character |
126 | 126 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
127 | - return chr(0xC0 | (($bytes >> 6) & 0x1F)) . chr(0x80 | ($bytes & 0x3F)); |
|
128 | - case (0xFFFF & $bytes) == $bytes: |
|
127 | + return chr(0xC0 | (($bytes >> 6) & 0x1F)).chr(0x80 | ($bytes & 0x3F)); |
|
128 | + case (0xFFFF & $bytes)==$bytes: |
|
129 | 129 | // return a 3-byte UTF-8 character |
130 | 130 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
131 | - return chr(0xE0 | (($bytes >> 12) & 0x0F)) . chr(0x80 | (($bytes >> 6) & 0x3F)) . chr(0x80 | ($bytes & 0x3F)); |
|
131 | + return chr(0xE0 | (($bytes >> 12) & 0x0F)).chr(0x80 | (($bytes >> 6) & 0x3F)).chr(0x80 | ($bytes & 0x3F)); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | // ignoring UTF-32 for now, sorry |
@@ -160,11 +160,11 @@ discard block |
||
160 | 160 | case 2: |
161 | 161 | // return a UTF-16 character from a 2-byte UTF-8 char |
162 | 162 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
163 | - return chr(0x07 & (ord($utf8[0]) >> 2)) . chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
163 | + return chr(0x07 & (ord($utf8[0]) >> 2)).chr((0xC0 & (ord($utf8[0]) << 6)) | (0x3F & ord($utf8[1]))); |
|
164 | 164 | case 3: |
165 | 165 | // return a UTF-16 character from a 3-byte UTF-8 char |
166 | 166 | // see: https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
167 | - return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))) . chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
167 | + return chr((0xF0 & (ord($utf8[0]) << 4)) | (0x0F & (ord($utf8[1]) >> 2))).chr((0xC0 & (ord($utf8[1]) << 6)) | (0x7F & ord($utf8[2]))); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // ignoring UTF-32 for now, sorry |
@@ -227,10 +227,10 @@ discard block |
||
227 | 227 | case 'NULL': |
228 | 228 | return 'null'; |
229 | 229 | case 'integer': |
230 | - return (int)$var; |
|
230 | + return (int) $var; |
|
231 | 231 | case 'double': |
232 | 232 | case 'float': |
233 | - return (float)$var; |
|
233 | + return (float) $var; |
|
234 | 234 | case 'string': |
235 | 235 | // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT |
236 | 236 | $ascii = ''; |
@@ -240,97 +240,97 @@ discard block |
||
240 | 240 | * Iterate over every character in the string, |
241 | 241 | * escaping with a slash or encoding to UTF-8 where necessary |
242 | 242 | */ |
243 | - for ($c = 0; $c < $strlen_var; ++$c) { |
|
243 | + for ($c = 0; $c<$strlen_var; ++$c) { |
|
244 | 244 | $ord_var_c = ord($var[$c]); |
245 | 245 | |
246 | 246 | switch (true) { |
247 | - case 0x08 == $ord_var_c: |
|
247 | + case 0x08==$ord_var_c: |
|
248 | 248 | $ascii .= '\b'; |
249 | 249 | break; |
250 | - case 0x09 == $ord_var_c: |
|
250 | + case 0x09==$ord_var_c: |
|
251 | 251 | $ascii .= '\t'; |
252 | 252 | break; |
253 | - case 0x0A == $ord_var_c: |
|
253 | + case 0x0A==$ord_var_c: |
|
254 | 254 | $ascii .= '\n'; |
255 | 255 | break; |
256 | - case 0x0C == $ord_var_c: |
|
256 | + case 0x0C==$ord_var_c: |
|
257 | 257 | $ascii .= '\f'; |
258 | 258 | break; |
259 | - case 0x0D == $ord_var_c: |
|
259 | + case 0x0D==$ord_var_c: |
|
260 | 260 | $ascii .= '\r'; |
261 | 261 | break; |
262 | - case 0x22 == $ord_var_c: |
|
263 | - case 0x2F == $ord_var_c: |
|
264 | - case 0x5C == $ord_var_c: |
|
262 | + case 0x22==$ord_var_c: |
|
263 | + case 0x2F==$ord_var_c: |
|
264 | + case 0x5C==$ord_var_c: |
|
265 | 265 | // double quote, slash, slosh |
266 | - $ascii .= '\\' . $var[$c]; |
|
266 | + $ascii .= '\\'.$var[$c]; |
|
267 | 267 | break; |
268 | - case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
|
268 | + case (($ord_var_c>=0x20) && ($ord_var_c<=0x7F)): |
|
269 | 269 | // characters U-00000000 - U-0000007F (same as ASCII) |
270 | 270 | $ascii .= $var[$c]; |
271 | 271 | break; |
272 | - case (0xC0 == ($ord_var_c & 0xE0)): |
|
272 | + case (0xC0==($ord_var_c & 0xE0)): |
|
273 | 273 | // characters U-00000080 - U-000007FF, mask 110SONGLIST |
274 | 274 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
275 | - if ($c + 1 >= $strlen_var) { |
|
275 | + if ($c+1>=$strlen_var) { |
|
276 | 276 | ++$c; |
277 | 277 | $ascii .= '?'; |
278 | 278 | break; |
279 | 279 | } |
280 | 280 | |
281 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
|
281 | + $char = pack('C*', $ord_var_c, ord($var[$c+1])); |
|
282 | 282 | ++$c; |
283 | 283 | $utf16 = $this->utf82utf16($char); |
284 | 284 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
285 | 285 | break; |
286 | - case (0xE0 == ($ord_var_c & 0xF0)): |
|
287 | - if ($c + 2 >= $strlen_var) { |
|
286 | + case (0xE0==($ord_var_c & 0xF0)): |
|
287 | + if ($c+2>=$strlen_var) { |
|
288 | 288 | $c += 2; |
289 | 289 | $ascii .= '?'; |
290 | 290 | break; |
291 | 291 | } |
292 | 292 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
293 | 293 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
294 | - $char = pack('C*', $ord_var_c, @ord($var[$c + 1]), @ord($var[$c + 2])); |
|
294 | + $char = pack('C*', $ord_var_c, @ord($var[$c+1]), @ord($var[$c+2])); |
|
295 | 295 | $c += 2; |
296 | 296 | $utf16 = $this->utf82utf16($char); |
297 | 297 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
298 | 298 | break; |
299 | - case (0xF0 == ($ord_var_c & 0xF8)): |
|
300 | - if ($c + 3 >= $strlen_var) { |
|
299 | + case (0xF0==($ord_var_c & 0xF8)): |
|
300 | + if ($c+3>=$strlen_var) { |
|
301 | 301 | $c += 3; |
302 | 302 | $ascii .= '?'; |
303 | 303 | break; |
304 | 304 | } |
305 | 305 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
306 | 306 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
307 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3])); |
|
307 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3])); |
|
308 | 308 | $c += 3; |
309 | 309 | $utf16 = $this->utf82utf16($char); |
310 | 310 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
311 | 311 | break; |
312 | - case (0xF8 == ($ord_var_c & 0xFC)): |
|
312 | + case (0xF8==($ord_var_c & 0xFC)): |
|
313 | 313 | // characters U-00200000 - U-03FFFFFF, mask 111110XX |
314 | 314 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
315 | - if ($c + 4 >= $strlen_var) { |
|
315 | + if ($c+4>=$strlen_var) { |
|
316 | 316 | $c += 4; |
317 | 317 | $ascii .= '?'; |
318 | 318 | break; |
319 | 319 | } |
320 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4])); |
|
320 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4])); |
|
321 | 321 | $c += 4; |
322 | 322 | $utf16 = $this->utf82utf16($char); |
323 | 323 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
324 | 324 | break; |
325 | - case (0xFC == ($ord_var_c & 0xFE)): |
|
326 | - if ($c + 5 >= $strlen_var) { |
|
325 | + case (0xFC==($ord_var_c & 0xFE)): |
|
326 | + if ($c+5>=$strlen_var) { |
|
327 | 327 | $c += 5; |
328 | 328 | $ascii .= '?'; |
329 | 329 | break; |
330 | 330 | } |
331 | 331 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
332 | 332 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
333 | - $char = pack('C*', $ord_var_c, ord($var[$c + 1]), ord($var[$c + 2]), ord($var[$c + 3]), ord($var[$c + 4]), ord($var[$c + 5])); |
|
333 | + $char = pack('C*', $ord_var_c, ord($var[$c+1]), ord($var[$c+2]), ord($var[$c+3]), ord($var[$c+4]), ord($var[$c+5])); |
|
334 | 334 | $c += 5; |
335 | 335 | $utf16 = $this->utf82utf16($char); |
336 | 336 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | } |
340 | 340 | |
341 | - return '"' . $ascii . '"'; |
|
341 | + return '"'.$ascii.'"'; |
|
342 | 342 | case 'array': |
343 | 343 | /* |
344 | 344 | * As per JSON spec if any array key is not an integer |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | */ |
360 | 360 | |
361 | 361 | // treat as a JSON object |
362 | - if (is_array($var) && count($var) && (array_keys($var) !== range(0, count($var) - 1))) { |
|
362 | + if (is_array($var) && count($var) && (array_keys($var)!==range(0, count($var)-1))) { |
|
363 | 363 | $properties = array_map([$this, 'name_value'], array_keys($var), array_values($var)); |
364 | 364 | |
365 | 365 | foreach ($properties as $property) { |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | } |
369 | 369 | } |
370 | 370 | |
371 | - return '{' . implode(',', $properties) . '}'; |
|
371 | + return '{'.implode(',', $properties).'}'; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | // treat it like a regular array |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | } |
381 | 381 | } |
382 | 382 | |
383 | - return '[' . implode(',', $elements) . ']'; |
|
383 | + return '['.implode(',', $elements).']'; |
|
384 | 384 | case 'object': |
385 | 385 | $vars = get_object_vars($var); |
386 | 386 | |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - return '{' . implode(',', $properties) . '}'; |
|
395 | + return '{'.implode(',', $properties).'}'; |
|
396 | 396 | default: |
397 | - return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var) . ' can not be encoded as JSON string'); |
|
397 | + return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS) ? 'null' : new ServicesJSON_Error(gettype($var).' can not be encoded as JSON string'); |
|
398 | 398 | } |
399 | 399 | } |
400 | 400 | |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | return $encoded_value; |
415 | 415 | } |
416 | 416 | |
417 | - return $this->_encode((string)$name) . ':' . $encoded_value; |
|
417 | + return $this->_encode((string) $name).':'.$encoded_value; |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -478,84 +478,84 @@ discard block |
||
478 | 478 | // return (float)$str; |
479 | 479 | |
480 | 480 | // Return float or int, as appropriate |
481 | - return ((float)$str == (int)$str) ? (int)$str : (float)$str; |
|
481 | + return ((float) $str==(int) $str) ? (int) $str : (float) $str; |
|
482 | 482 | } |
483 | 483 | |
484 | - if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) { |
|
484 | + if (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1]==$m[2]) { |
|
485 | 485 | // STRINGS RETURNED IN UTF-8 FORMAT |
486 | 486 | $delim = mb_substr($str, 0, 1); |
487 | 487 | $chrs = mb_substr($str, 1, -1); |
488 | 488 | $utf8 = ''; |
489 | 489 | $strlen_chrs = mb_strlen($chrs); |
490 | 490 | |
491 | - for ($c = 0; $c < $strlen_chrs; ++$c) { |
|
491 | + for ($c = 0; $c<$strlen_chrs; ++$c) { |
|
492 | 492 | $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
493 | 493 | $ord_chrs_c = ord($chrs[$c]); |
494 | 494 | |
495 | 495 | switch (true) { |
496 | - case '\b' === $substr_chrs_c_2: |
|
496 | + case '\b'===$substr_chrs_c_2: |
|
497 | 497 | $utf8 .= chr(0x08); |
498 | 498 | ++$c; |
499 | 499 | break; |
500 | - case '\t' === $substr_chrs_c_2: |
|
500 | + case '\t'===$substr_chrs_c_2: |
|
501 | 501 | $utf8 .= chr(0x09); |
502 | 502 | ++$c; |
503 | 503 | break; |
504 | - case '\n' === $substr_chrs_c_2: |
|
504 | + case '\n'===$substr_chrs_c_2: |
|
505 | 505 | $utf8 .= chr(0x0A); |
506 | 506 | ++$c; |
507 | 507 | break; |
508 | - case '\f' === $substr_chrs_c_2: |
|
508 | + case '\f'===$substr_chrs_c_2: |
|
509 | 509 | $utf8 .= chr(0x0C); |
510 | 510 | ++$c; |
511 | 511 | break; |
512 | - case '\r' === $substr_chrs_c_2: |
|
512 | + case '\r'===$substr_chrs_c_2: |
|
513 | 513 | $utf8 .= chr(0x0D); |
514 | 514 | ++$c; |
515 | 515 | break; |
516 | - case '\\"' === $substr_chrs_c_2: |
|
517 | - case '\\\'' === $substr_chrs_c_2: |
|
518 | - case '\\\\' === $substr_chrs_c_2: |
|
519 | - case '\\/' === $substr_chrs_c_2: |
|
520 | - if (('"' === $delim && '\\\'' !== $substr_chrs_c_2) |
|
521 | - || ("'" === $delim && '\\"' !== $substr_chrs_c_2)) { |
|
516 | + case '\\"'===$substr_chrs_c_2: |
|
517 | + case '\\\''===$substr_chrs_c_2: |
|
518 | + case '\\\\'===$substr_chrs_c_2: |
|
519 | + case '\\/'===$substr_chrs_c_2: |
|
520 | + if (('"'===$delim && '\\\''!==$substr_chrs_c_2) |
|
521 | + || ("'"===$delim && '\\"'!==$substr_chrs_c_2)) { |
|
522 | 522 | $utf8 .= $chrs[++$c]; |
523 | 523 | } |
524 | 524 | break; |
525 | 525 | case preg_match('/\\\u[0-9A-F]{4}/i', mb_substr($chrs, $c, 6)): |
526 | 526 | // single, escaped unicode character |
527 | - $utf16 = chr(hexdec(mb_substr($chrs, $c + 2, 2))) . chr(hexdec(mb_substr($chrs, $c + 4, 2))); |
|
527 | + $utf16 = chr(hexdec(mb_substr($chrs, $c+2, 2))).chr(hexdec(mb_substr($chrs, $c+4, 2))); |
|
528 | 528 | $utf8 .= $this->utf162utf8($utf16); |
529 | 529 | $c += 5; |
530 | 530 | break; |
531 | - case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
|
531 | + case ($ord_chrs_c>=0x20) && ($ord_chrs_c<=0x7F): |
|
532 | 532 | $utf8 .= $chrs[$c]; |
533 | 533 | break; |
534 | - case 0xC0 == ($ord_chrs_c & 0xE0): |
|
534 | + case 0xC0==($ord_chrs_c & 0xE0): |
|
535 | 535 | // characters U-00000080 - U-000007FF, mask 110SONGLIST |
536 | 536 | //see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
537 | 537 | $utf8 .= mb_substr($chrs, $c, 2); |
538 | 538 | ++$c; |
539 | 539 | break; |
540 | - case 0xE0 == ($ord_chrs_c & 0xF0): |
|
540 | + case 0xE0==($ord_chrs_c & 0xF0): |
|
541 | 541 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
542 | 542 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
543 | 543 | $utf8 .= mb_substr($chrs, $c, 3); |
544 | 544 | $c += 2; |
545 | 545 | break; |
546 | - case 0xF0 == ($ord_chrs_c & 0xF8): |
|
546 | + case 0xF0==($ord_chrs_c & 0xF8): |
|
547 | 547 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
548 | 548 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
549 | 549 | $utf8 .= mb_substr($chrs, $c, 4); |
550 | 550 | $c += 3; |
551 | 551 | break; |
552 | - case 0xF8 == ($ord_chrs_c & 0xFC): |
|
552 | + case 0xF8==($ord_chrs_c & 0xFC): |
|
553 | 553 | // characters U-00200000 - U-03FFFFFF, mask 111110XX |
554 | 554 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
555 | 555 | $utf8 .= mb_substr($chrs, $c, 5); |
556 | 556 | $c += 4; |
557 | 557 | break; |
558 | - case 0xFC == ($ord_chrs_c & 0xFE): |
|
558 | + case 0xFC==($ord_chrs_c & 0xFE): |
|
559 | 559 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
560 | 560 | // see https://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
561 | 561 | $utf8 .= mb_substr($chrs, $c, 6); |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | if (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
571 | 571 | // array, or object notation |
572 | 572 | |
573 | - if ('[' === $str[0]) { |
|
573 | + if ('['===$str[0]) { |
|
574 | 574 | $stk = [SERVICES_JSON_IN_ARR]; |
575 | 575 | $arr = []; |
576 | 576 | } elseif ($this->use & SERVICES_JSON_LOOSE_TYPE) { |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | $chrs = mb_substr($str, 1, -1); |
594 | 594 | $chrs = $this->reduce_string($chrs); |
595 | 595 | |
596 | - if ('' == $chrs) { |
|
597 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
596 | + if (''==$chrs) { |
|
597 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
598 | 598 | return $arr; |
599 | 599 | } |
600 | 600 | |
@@ -605,21 +605,21 @@ discard block |
||
605 | 605 | |
606 | 606 | $strlen_chrs = mb_strlen($chrs); |
607 | 607 | |
608 | - for ($c = 0; $c <= $strlen_chrs; ++$c) { |
|
608 | + for ($c = 0; $c<=$strlen_chrs; ++$c) { |
|
609 | 609 | $top = end($stk); |
610 | 610 | $substr_chrs_c_2 = mb_substr($chrs, $c, 2); |
611 | 611 | |
612 | - if (($c == $strlen_chrs) || ((',' === $chrs[$c]) && (SERVICES_JSON_SLICE == $top['what']))) { |
|
612 | + if (($c==$strlen_chrs) || ((','===$chrs[$c]) && (SERVICES_JSON_SLICE==$top['what']))) { |
|
613 | 613 | // found a comma that is not inside a string, array, etc., |
614 | 614 | // OR we've reached the end of the character list |
615 | - $slice = mb_substr($chrs, $top['where'], $c - $top['where']); |
|
616 | - array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c + 1, 'delim' => false]); |
|
615 | + $slice = mb_substr($chrs, $top['where'], $c-$top['where']); |
|
616 | + array_push($stk, ['what' => SERVICES_JSON_SLICE, 'where' => $c+1, 'delim' => false]); |
|
617 | 617 | //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
618 | 618 | |
619 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
619 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
620 | 620 | // we are in an array, so just push an element onto the stack |
621 | 621 | $arr[] = $this->decode($slice); |
622 | - } elseif (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
622 | + } elseif (SERVICES_JSON_IN_OBJ==reset($stk)) { |
|
623 | 623 | // we are in an object, so figure |
624 | 624 | // out the property name and set an |
625 | 625 | // element in an associative array, |
@@ -648,59 +648,59 @@ discard block |
||
648 | 648 | } |
649 | 649 | } |
650 | 650 | } |
651 | - } elseif ((('"' === $chrs[$c]) || ("'" === $chrs[$c])) && (SERVICES_JSON_IN_STR != $top['what'])) { |
|
651 | + } elseif ((('"'===$chrs[$c]) || ("'"===$chrs[$c])) && (SERVICES_JSON_IN_STR!=$top['what'])) { |
|
652 | 652 | // found a quote, and we are not inside a string |
653 | 653 | array_push($stk, ['what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c]]); |
654 | 654 | //print("Found start of string at {$c}\n"); |
655 | - } elseif (($chrs[$c] == $top['delim']) |
|
656 | - && (SERVICES_JSON_IN_STR == $top['what']) |
|
657 | - && (1 != (mb_strlen(mb_substr($chrs, 0, $c)) - mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\'))) % 2)) { |
|
655 | + } elseif (($chrs[$c]==$top['delim']) |
|
656 | + && (SERVICES_JSON_IN_STR==$top['what']) |
|
657 | + && (1!=(mb_strlen(mb_substr($chrs, 0, $c))-mb_strlen(rtrim(mb_substr($chrs, 0, $c), '\\')))%2)) { |
|
658 | 658 | // found a quote, we're in a string, and it's not escaped |
659 | 659 | // we know that it's not escaped becase there is _not_ an |
660 | 660 | // odd number of backslashes at the end of the string so far |
661 | 661 | array_pop($stk); |
662 | 662 | //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
663 | - } elseif (('[' === $chrs[$c]) |
|
663 | + } elseif (('['===$chrs[$c]) |
|
664 | 664 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
665 | 665 | // found a left-bracket, and we are in an array, object, or slice |
666 | 666 | array_push($stk, ['what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false]); |
667 | 667 | //print("Found start of array at {$c}\n"); |
668 | - } elseif ((']' === $chrs[$c]) && (SERVICES_JSON_IN_ARR == $top['what'])) { |
|
668 | + } elseif ((']'===$chrs[$c]) && (SERVICES_JSON_IN_ARR==$top['what'])) { |
|
669 | 669 | // found a right-bracket, and we're in an array |
670 | 670 | array_pop($stk); |
671 | 671 | //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
672 | - } elseif (('{' === $chrs[$c]) |
|
672 | + } elseif (('{'===$chrs[$c]) |
|
673 | 673 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
674 | 674 | // found a left-brace, and we are in an array, object, or slice |
675 | 675 | array_push($stk, ['what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false]); |
676 | 676 | //print("Found start of object at {$c}\n"); |
677 | - } elseif (('}' === $chrs[$c]) && (SERVICES_JSON_IN_OBJ == $top['what'])) { |
|
677 | + } elseif (('}'===$chrs[$c]) && (SERVICES_JSON_IN_OBJ==$top['what'])) { |
|
678 | 678 | // found a right-brace, and we're in an object |
679 | 679 | array_pop($stk); |
680 | 680 | //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
681 | - } elseif (('/*' === $substr_chrs_c_2) |
|
681 | + } elseif (('/*'===$substr_chrs_c_2) |
|
682 | 682 | && in_array($top['what'], [SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ], true)) { |
683 | 683 | // found a comment start, and we are in an array, object, or slice |
684 | 684 | array_push($stk, ['what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false]); |
685 | 685 | ++$c; |
686 | 686 | //print("Found start of comment at {$c}\n"); |
687 | - } elseif (('*/' === $substr_chrs_c_2) && (SERVICES_JSON_IN_CMT == $top['what'])) { |
|
687 | + } elseif (('*/'===$substr_chrs_c_2) && (SERVICES_JSON_IN_CMT==$top['what'])) { |
|
688 | 688 | // found a comment end, and we're in one now |
689 | 689 | array_pop($stk); |
690 | 690 | ++$c; |
691 | 691 | |
692 | - for ($i = $top['where']; $i <= $c; ++$i) { |
|
692 | + for ($i = $top['where']; $i<=$c; ++$i) { |
|
693 | 693 | $chrs = substr_replace($chrs, ' ', $i, 1); |
694 | 694 | } |
695 | 695 | //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
696 | 696 | } |
697 | 697 | } |
698 | 698 | |
699 | - if (SERVICES_JSON_IN_ARR == reset($stk)) { |
|
699 | + if (SERVICES_JSON_IN_ARR==reset($stk)) { |
|
700 | 700 | return $arr; |
701 | 701 | } |
702 | 702 | |
703 | - if (SERVICES_JSON_IN_OBJ == reset($stk)) { |
|
703 | + if (SERVICES_JSON_IN_OBJ==reset($stk)) { |
|
704 | 704 | return $obj; |
705 | 705 | } |
706 | 706 | } |
@@ -3,11 +3,11 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Form\FormController, |
|
7 | - Helper, |
|
8 | - Songs, |
|
9 | - SongsHandler, |
|
10 | - Uploader |
|
6 | + Form\FormController, |
|
7 | + Helper, |
|
8 | + Songs, |
|
9 | + SongsHandler, |
|
10 | + Uploader |
|
11 | 11 | }; |
12 | 12 | |
13 | 13 | /** @var Songs $songs */ |
@@ -27,101 +27,101 @@ discard block |
||
27 | 27 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
28 | 28 | |
29 | 29 | switch ($op) { |
30 | - default: |
|
31 | - case 'songs': |
|
32 | - switch ($fct) { |
|
33 | - default: |
|
34 | - case 'list': |
|
35 | - $adminObject = Admin::getInstance(); |
|
36 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
30 | + default: |
|
31 | + case 'songs': |
|
32 | + switch ($fct) { |
|
33 | + default: |
|
34 | + case 'list': |
|
35 | + $adminObject = Admin::getInstance(); |
|
36 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
37 | 37 | |
38 | - /** @var SongsHandler $songsHandler */ |
|
39 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
38 | + /** @var SongsHandler $songsHandler */ |
|
39 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
40 | 40 | |
41 | - $criteria = $songsHandler->getFilterCriteria($GLOBALS['filter']); |
|
42 | - $ttl = $songsHandler->getCount($criteria); |
|
43 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
41 | + $criteria = $songsHandler->getFilterCriteria($GLOBALS['filter']); |
|
42 | + $ttl = $songsHandler->getCount($criteria); |
|
43 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
44 | 44 | |
45 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
46 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
45 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
46 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
47 | 47 | |
48 | - foreach ($songsHandler->filterFields() as $id => $key) { |
|
49 | - $GLOBALS['xoopsTpl']->assign( |
|
50 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
51 | - '<a href="' |
|
52 | - . $_SERVER['SCRIPT_NAME'] |
|
53 | - . '?start=' |
|
54 | - . $GLOBALS['start'] |
|
55 | - . '&limit=' |
|
56 | - . $GLOBALS['limit'] |
|
57 | - . '&sort=' |
|
58 | - . $key |
|
59 | - . '&order=' |
|
60 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | - . '&op=' |
|
62 | - . $GLOBALS['op'] |
|
63 | - . '&filter=' |
|
64 | - . $GLOBALS['filter'] |
|
65 | - . '">' |
|
66 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | - . '</a>' |
|
68 | - ); |
|
69 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $songsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | - } |
|
48 | + foreach ($songsHandler->filterFields() as $id => $key) { |
|
49 | + $GLOBALS['xoopsTpl']->assign( |
|
50 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
51 | + '<a href="' |
|
52 | + . $_SERVER['SCRIPT_NAME'] |
|
53 | + . '?start=' |
|
54 | + . $GLOBALS['start'] |
|
55 | + . '&limit=' |
|
56 | + . $GLOBALS['limit'] |
|
57 | + . '&sort=' |
|
58 | + . $key |
|
59 | + . '&order=' |
|
60 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | + . '&op=' |
|
62 | + . $GLOBALS['op'] |
|
63 | + . '&filter=' |
|
64 | + . $GLOBALS['filter'] |
|
65 | + . '">' |
|
66 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | + . '</a>' |
|
68 | + ); |
|
69 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $songsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | + } |
|
71 | 71 | |
72 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
77 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
72 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
77 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
78 | 78 | |
79 | - $criteria->setStart($GLOBALS['start']); |
|
80 | - $criteria->setLimit($GLOBALS['limit']); |
|
81 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
82 | - $criteria->setOrder($GLOBALS['order']); |
|
79 | + $criteria->setStart($GLOBALS['start']); |
|
80 | + $criteria->setLimit($GLOBALS['limit']); |
|
81 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
82 | + $criteria->setOrder($GLOBALS['order']); |
|
83 | 83 | |
84 | - $songss = $songsHandler->getObjects($criteria, true); |
|
85 | - foreach ($songss as $cid => $songs) { |
|
86 | - if (is_object($songs)) { |
|
87 | - $GLOBALS['xoopsTpl']->append('songs', $songs->toArray()); |
|
88 | - } |
|
89 | - } |
|
90 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormSongs(false)); |
|
91 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
92 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_songs_list.tpl'); |
|
93 | - break; |
|
94 | - case 'new': |
|
95 | - case 'edit': |
|
96 | - $adminObject = Admin::getInstance(); |
|
97 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
84 | + $songss = $songsHandler->getObjects($criteria, true); |
|
85 | + foreach ($songss as $cid => $songs) { |
|
86 | + if (is_object($songs)) { |
|
87 | + $GLOBALS['xoopsTpl']->append('songs', $songs->toArray()); |
|
88 | + } |
|
89 | + } |
|
90 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormSongs(false)); |
|
91 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
92 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_songs_list.tpl'); |
|
93 | + break; |
|
94 | + case 'new': |
|
95 | + case 'edit': |
|
96 | + $adminObject = Admin::getInstance(); |
|
97 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
98 | 98 | |
99 | - require_once $GLOBALS['xoops']->path('/class/pagenav.php'); |
|
99 | + require_once $GLOBALS['xoops']->path('/class/pagenav.php'); |
|
100 | 100 | |
101 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
102 | - if (Request::hasVar('id', 'REQUEST')) { |
|
103 | - $songs = $songsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
104 | - } else { |
|
105 | - $songs = $songsHandler->create(); |
|
106 | - } |
|
101 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
102 | + if (Request::hasVar('id', 'REQUEST')) { |
|
103 | + $songs = $songsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
104 | + } else { |
|
105 | + $songs = $songsHandler->create(); |
|
106 | + } |
|
107 | 107 | |
108 | - $GLOBALS['xoopsTpl']->assign('form', $songs->getForm()); |
|
109 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
110 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_songs_edit.tpl'); |
|
111 | - break; |
|
112 | - case 'save': |
|
113 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
114 | - $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
115 | - $id = 0; |
|
116 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
117 | - if ($id) { |
|
118 | - $songs = $songsHandler->get($id); |
|
119 | - } else { |
|
120 | - $songs = $songsHandler->create(); |
|
121 | - } |
|
122 | - $songs->setVars($_POST[$id]); |
|
108 | + $GLOBALS['xoopsTpl']->assign('form', $songs->getForm()); |
|
109 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
110 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_songs_edit.tpl'); |
|
111 | + break; |
|
112 | + case 'save': |
|
113 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
114 | + $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
115 | + $id = 0; |
|
116 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
117 | + if ($id) { |
|
118 | + $songs = $songsHandler->get($id); |
|
119 | + } else { |
|
120 | + $songs = $songsHandler->create(); |
|
121 | + } |
|
122 | + $songs->setVars($_POST[$id]); |
|
123 | 123 | |
124 | - if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
124 | + if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
125 | 125 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
126 | 126 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
127 | 127 | // foreach (explode('/', $folders) as $folder) { |
@@ -134,74 +134,74 @@ discard block |
||
134 | 134 | // } |
135 | 135 | |
136 | 136 | // require_once $GLOBALS['xoops']->path('modules/songlist/include/uploader.php'); |
137 | - $uploader = new Uploader( |
|
138 | - $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
139 | - explode('|', $GLOBALS['songlistModuleConfig']['mp3_mimetype']), |
|
140 | - $GLOBALS['songlistModuleConfig']['mp3_filesize'], |
|
141 | - 0, |
|
142 | - 0, |
|
143 | - explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
|
144 | - ); |
|
145 | - try { |
|
146 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
147 | - } catch (Exception $e) { |
|
148 | - } |
|
137 | + $uploader = new Uploader( |
|
138 | + $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
139 | + explode('|', $GLOBALS['songlistModuleConfig']['mp3_mimetype']), |
|
140 | + $GLOBALS['songlistModuleConfig']['mp3_filesize'], |
|
141 | + 0, |
|
142 | + 0, |
|
143 | + explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
|
144 | + ); |
|
145 | + try { |
|
146 | + $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
147 | + } catch (Exception $e) { |
|
148 | + } |
|
149 | 149 | |
150 | - if ($uploader->fetchMedia('mp3' . $id)) { |
|
151 | - if (!$uploader->upload()) { |
|
152 | - $adminObject = Admin::getInstance(); |
|
153 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
154 | - echo $uploader->getErrors(); |
|
155 | - xoops_cp_footer(); |
|
156 | - exit(0); |
|
157 | - } |
|
158 | - if (mb_strlen($songs->getVar('mp3'))) { |
|
159 | - unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
160 | - } |
|
150 | + if ($uploader->fetchMedia('mp3' . $id)) { |
|
151 | + if (!$uploader->upload()) { |
|
152 | + $adminObject = Admin::getInstance(); |
|
153 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
154 | + echo $uploader->getErrors(); |
|
155 | + xoops_cp_footer(); |
|
156 | + exit(0); |
|
157 | + } |
|
158 | + if (mb_strlen($songs->getVar('mp3'))) { |
|
159 | + unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
160 | + } |
|
161 | 161 | |
162 | - $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
163 | - } else { |
|
164 | - $adminObject = Admin::getInstance(); |
|
165 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
166 | - echo $uploader->getErrors(); |
|
167 | - xoops_cp_footer(); |
|
168 | - exit(0); |
|
169 | - } |
|
170 | - } |
|
171 | - if (!$id = $songsHandler->insert($songs)) { |
|
172 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE); |
|
173 | - exit(0); |
|
174 | - } |
|
175 | - $extra = $extrasHandler->get($id); |
|
176 | - $extra->setVars($_POST[$id]); |
|
177 | - $extra->setVar('sid', $id); |
|
178 | - $extrasHandler->insert($extra); |
|
162 | + $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
163 | + } else { |
|
164 | + $adminObject = Admin::getInstance(); |
|
165 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
166 | + echo $uploader->getErrors(); |
|
167 | + xoops_cp_footer(); |
|
168 | + exit(0); |
|
169 | + } |
|
170 | + } |
|
171 | + if (!$id = $songsHandler->insert($songs)) { |
|
172 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE); |
|
173 | + exit(0); |
|
174 | + } |
|
175 | + $extra = $extrasHandler->get($id); |
|
176 | + $extra->setVars($_POST[$id]); |
|
177 | + $extra->setVar('sid', $id); |
|
178 | + $extrasHandler->insert($extra); |
|
179 | 179 | |
180 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
181 | - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
182 | - $tagHandler->updateByItem($_POST['tags'], $id, $GLOBALS['songlistModule']->getVar('dirname'), $songs->getVar('cid')); |
|
183 | - } |
|
180 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
181 | + $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
182 | + $tagHandler->updateByItem($_POST['tags'], $id, $GLOBALS['songlistModule']->getVar('dirname'), $songs->getVar('cid')); |
|
183 | + } |
|
184 | 184 | |
185 | - if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
186 | - redirect_header( |
|
187 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
188 | - 10, |
|
189 | - _AM_SONGLIST_MSG_SONGS_SAVEDOKEY |
|
190 | - ); |
|
191 | - } else { |
|
192 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
193 | - } |
|
194 | - exit(0); |
|
185 | + if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
186 | + redirect_header( |
|
187 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
188 | + 10, |
|
189 | + _AM_SONGLIST_MSG_SONGS_SAVEDOKEY |
|
190 | + ); |
|
191 | + } else { |
|
192 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
193 | + } |
|
194 | + exit(0); |
|
195 | 195 | |
196 | - break; |
|
197 | - case 'savelist': |
|
198 | - print_r($_FILES); |
|
199 | - exit; |
|
200 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
201 | - foreach ($_REQUEST['id'] as $id) { |
|
202 | - $songs = $songsHandler->get($id); |
|
203 | - $songs->setVars($_POST[$id]); |
|
204 | - if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
196 | + break; |
|
197 | + case 'savelist': |
|
198 | + print_r($_FILES); |
|
199 | + exit; |
|
200 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
201 | + foreach ($_REQUEST['id'] as $id) { |
|
202 | + $songs = $songsHandler->get($id); |
|
203 | + $songs->setVars($_POST[$id]); |
|
204 | + if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
205 | 205 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
206 | 206 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
207 | 207 | // foreach (explode('/', $folders) as $folder) { |
@@ -214,78 +214,78 @@ discard block |
||
214 | 214 | // } |
215 | 215 | |
216 | 216 | // require_once $GLOBALS['xoops']->path('modules/songlist/include/uploader.php'); |
217 | - $uploader = new Uploader( |
|
218 | - $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
219 | - explode('|', $GLOBALS['songlistModuleConfig']['mp3_mimetype']), |
|
220 | - $GLOBALS['songlistModuleConfig']['mp3_filesize'], |
|
221 | - 0, |
|
222 | - 0, |
|
223 | - explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
|
224 | - ); |
|
225 | - try { |
|
226 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
227 | - } catch (Exception $e) { |
|
228 | - } |
|
217 | + $uploader = new Uploader( |
|
218 | + $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
219 | + explode('|', $GLOBALS['songlistModuleConfig']['mp3_mimetype']), |
|
220 | + $GLOBALS['songlistModuleConfig']['mp3_filesize'], |
|
221 | + 0, |
|
222 | + 0, |
|
223 | + explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
|
224 | + ); |
|
225 | + try { |
|
226 | + $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
227 | + } catch (Exception $e) { |
|
228 | + } |
|
229 | 229 | |
230 | - if ($uploader->fetchMedia('mp3' . $id)) { |
|
231 | - if (!$uploader->upload()) { |
|
232 | - $adminObject = Admin::getInstance(); |
|
233 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
234 | - echo $uploader->getErrors(); |
|
235 | - xoops_cp_footer(); |
|
236 | - exit(0); |
|
237 | - } |
|
238 | - if (mb_strlen($songs->getVar('mp3'))) { |
|
239 | - unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
240 | - } |
|
230 | + if ($uploader->fetchMedia('mp3' . $id)) { |
|
231 | + if (!$uploader->upload()) { |
|
232 | + $adminObject = Admin::getInstance(); |
|
233 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
234 | + echo $uploader->getErrors(); |
|
235 | + xoops_cp_footer(); |
|
236 | + exit(0); |
|
237 | + } |
|
238 | + if (mb_strlen($songs->getVar('mp3'))) { |
|
239 | + unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
240 | + } |
|
241 | 241 | |
242 | - $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
243 | - } else { |
|
244 | - $adminObject = Admin::getInstance(); |
|
245 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
246 | - echo $uploader->getErrors(); |
|
247 | - xoops_cp_footer(); |
|
248 | - exit(0); |
|
249 | - } |
|
250 | - } |
|
251 | - if (!$songsHandler->insert($songs)) { |
|
252 | - redirect_header( |
|
253 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
254 | - 10, |
|
255 | - _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE |
|
256 | - ); |
|
257 | - exit(0); |
|
258 | - } |
|
259 | - } |
|
260 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
261 | - exit(0); |
|
262 | - break; |
|
263 | - case 'delete': |
|
264 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
265 | - $id = 0; |
|
266 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
267 | - $songs = $songsHandler->get($id); |
|
268 | - if (!$songsHandler->delete($songs)) { |
|
269 | - redirect_header( |
|
270 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
271 | - 10, |
|
272 | - _AM_SONGLIST_MSG_SONGS_FAILEDTODELETE |
|
273 | - ); |
|
274 | - exit(0); |
|
275 | - } |
|
276 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_DELETED); |
|
277 | - exit(0); |
|
278 | - } |
|
279 | - $songs = $songsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
280 | - xoops_confirm( |
|
281 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
282 | - $_SERVER['SCRIPT_NAME'], |
|
283 | - sprintf(_AM_SONGLIST_MSG_SONGS_DELETE, $songs->getVar('name')) |
|
284 | - ); |
|
242 | + $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
243 | + } else { |
|
244 | + $adminObject = Admin::getInstance(); |
|
245 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
246 | + echo $uploader->getErrors(); |
|
247 | + xoops_cp_footer(); |
|
248 | + exit(0); |
|
249 | + } |
|
250 | + } |
|
251 | + if (!$songsHandler->insert($songs)) { |
|
252 | + redirect_header( |
|
253 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
254 | + 10, |
|
255 | + _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE |
|
256 | + ); |
|
257 | + exit(0); |
|
258 | + } |
|
259 | + } |
|
260 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
261 | + exit(0); |
|
262 | + break; |
|
263 | + case 'delete': |
|
264 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
265 | + $id = 0; |
|
266 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
267 | + $songs = $songsHandler->get($id); |
|
268 | + if (!$songsHandler->delete($songs)) { |
|
269 | + redirect_header( |
|
270 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
271 | + 10, |
|
272 | + _AM_SONGLIST_MSG_SONGS_FAILEDTODELETE |
|
273 | + ); |
|
274 | + exit(0); |
|
275 | + } |
|
276 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_DELETED); |
|
277 | + exit(0); |
|
278 | + } |
|
279 | + $songs = $songsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
280 | + xoops_confirm( |
|
281 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
282 | + $_SERVER['SCRIPT_NAME'], |
|
283 | + sprintf(_AM_SONGLIST_MSG_SONGS_DELETE, $songs->getVar('name')) |
|
284 | + ); |
|
285 | 285 | |
286 | - break; |
|
287 | - } |
|
288 | - break; |
|
286 | + break; |
|
287 | + } |
|
288 | + break; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | xoops_cp_footer(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | /** @var Songs $songs */ |
14 | 14 | |
15 | -require __DIR__ . '/header.php'; |
|
15 | +require __DIR__.'/header.php'; |
|
16 | 16 | |
17 | 17 | xoops_loadLanguage('admin', 'songlist'); |
18 | 18 | |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
24 | 24 | $start = Request::getInt('start', 0, 'REQUEST'); |
25 | 25 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
26 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
27 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
26 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
27 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
28 | 28 | |
29 | 29 | switch ($op) { |
30 | 30 | default: |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | |
41 | 41 | $criteria = $songsHandler->getFilterCriteria($GLOBALS['filter']); |
42 | 42 | $ttl = $songsHandler->getCount($criteria); |
43 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
44 | 44 | |
45 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
46 | 46 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
47 | 47 | |
48 | 48 | foreach ($songsHandler->filterFields() as $id => $key) { |
49 | 49 | $GLOBALS['xoopsTpl']->assign( |
50 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
51 | 51 | '<a href="' |
52 | 52 | . $_SERVER['SCRIPT_NAME'] |
53 | 53 | . '?start=' |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | . '&sort=' |
58 | 58 | . $key |
59 | 59 | . '&order=' |
60 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | 61 | . '&op=' |
62 | 62 | . $GLOBALS['op'] |
63 | 63 | . '&filter=' |
64 | 64 | . $GLOBALS['filter'] |
65 | 65 | . '">' |
66 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | 67 | . '</a>' |
68 | 68 | ); |
69 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $songsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $songsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $criteria->setStart($GLOBALS['start']); |
80 | 80 | $criteria->setLimit($GLOBALS['limit']); |
81 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
82 | 82 | $criteria->setOrder($GLOBALS['order']); |
83 | 83 | |
84 | 84 | $songss = $songsHandler->getObjects($criteria, true); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | } |
122 | 122 | $songs->setVars($_POST[$id]); |
123 | 123 | |
124 | - if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
124 | + if (Request::hasVar('mp3'.$id, 'FILES') && !empty($_FILES['mp3'.$id]['title'])) { |
|
125 | 125 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
126 | 126 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
127 | 127 | // foreach (explode('/', $folders) as $folder) { |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
144 | 144 | ); |
145 | 145 | try { |
146 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
146 | + $uploader->setPrefix(mb_substr(md5((string) microtime(true)), random_int(0, 20), 13)); |
|
147 | 147 | } catch (Exception $e) { |
148 | 148 | } |
149 | 149 | |
150 | - if ($uploader->fetchMedia('mp3' . $id)) { |
|
150 | + if ($uploader->fetchMedia('mp3'.$id)) { |
|
151 | 151 | if (!$uploader->upload()) { |
152 | 152 | $adminObject = Admin::getInstance(); |
153 | 153 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | exit(0); |
157 | 157 | } |
158 | 158 | if (mb_strlen($songs->getVar('mp3'))) { |
159 | - unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
159 | + unlink($GLOBALS['xoops']->path($songs->getVar('path')).basename($songs->getVar('mp3'))); |
|
160 | 160 | } |
161 | 161 | |
162 | - $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
162 | + $songs->setVar('mp3', XOOPS_URL.'/'.str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']).$uploader->getSavedFileName()); |
|
163 | 163 | } else { |
164 | 164 | $adminObject = Admin::getInstance(); |
165 | 165 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | } |
170 | 170 | } |
171 | 171 | if (!$id = $songsHandler->insert($songs)) { |
172 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE); |
|
172 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE); |
|
173 | 173 | exit(0); |
174 | 174 | } |
175 | 175 | $extra = $extrasHandler->get($id); |
@@ -177,19 +177,19 @@ discard block |
||
177 | 177 | $extra->setVar('sid', $id); |
178 | 178 | $extrasHandler->insert($extra); |
179 | 179 | |
180 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
180 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH.'/modules/tag/class/tag.php')) { |
|
181 | 181 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
182 | 182 | $tagHandler->updateByItem($_POST['tags'], $id, $GLOBALS['songlistModule']->getVar('dirname'), $songs->getVar('cid')); |
183 | 183 | } |
184 | 184 | |
185 | - if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
185 | + if ('new'===isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']] : '') { |
|
186 | 186 | redirect_header( |
187 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
187 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
188 | 188 | 10, |
189 | 189 | _AM_SONGLIST_MSG_SONGS_SAVEDOKEY |
190 | 190 | ); |
191 | 191 | } else { |
192 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
192 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
193 | 193 | } |
194 | 194 | exit(0); |
195 | 195 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | foreach ($_REQUEST['id'] as $id) { |
202 | 202 | $songs = $songsHandler->get($id); |
203 | 203 | $songs->setVars($_POST[$id]); |
204 | - if (Request::hasVar('mp3' . $id, 'FILES') && !empty($_FILES['mp3' . $id]['title'])) { |
|
204 | + if (Request::hasVar('mp3'.$id, 'FILES') && !empty($_FILES['mp3'.$id]['title'])) { |
|
205 | 205 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
206 | 206 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
207 | 207 | // foreach (explode('/', $folders) as $folder) { |
@@ -223,11 +223,11 @@ discard block |
||
223 | 223 | explode('|', $GLOBALS['songlistModuleConfig']['mp3_extensions']) |
224 | 224 | ); |
225 | 225 | try { |
226 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
226 | + $uploader->setPrefix(mb_substr(md5((string) microtime(true)), random_int(0, 20), 13)); |
|
227 | 227 | } catch (Exception $e) { |
228 | 228 | } |
229 | 229 | |
230 | - if ($uploader->fetchMedia('mp3' . $id)) { |
|
230 | + if ($uploader->fetchMedia('mp3'.$id)) { |
|
231 | 231 | if (!$uploader->upload()) { |
232 | 232 | $adminObject = Admin::getInstance(); |
233 | 233 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | exit(0); |
237 | 237 | } |
238 | 238 | if (mb_strlen($songs->getVar('mp3'))) { |
239 | - unlink($GLOBALS['xoops']->path($songs->getVar('path')) . basename($songs->getVar('mp3'))); |
|
239 | + unlink($GLOBALS['xoops']->path($songs->getVar('path')).basename($songs->getVar('mp3'))); |
|
240 | 240 | } |
241 | 241 | |
242 | - $songs->setVar('mp3', XOOPS_URL . '/' . str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']) . $uploader->getSavedFileName()); |
|
242 | + $songs->setVar('mp3', XOOPS_URL.'/'.str_replace(DS, '/', $GLOBALS['songlistModuleConfig']['upload_areas']).$uploader->getSavedFileName()); |
|
243 | 243 | } else { |
244 | 244 | $adminObject = Admin::getInstance(); |
245 | 245 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -250,14 +250,14 @@ discard block |
||
250 | 250 | } |
251 | 251 | if (!$songsHandler->insert($songs)) { |
252 | 252 | redirect_header( |
253 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
253 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
254 | 254 | 10, |
255 | 255 | _AM_SONGLIST_MSG_SONGS_FAILEDTOSAVE |
256 | 256 | ); |
257 | 257 | exit(0); |
258 | 258 | } |
259 | 259 | } |
260 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
260 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_SAVEDOKEY); |
|
261 | 261 | exit(0); |
262 | 262 | break; |
263 | 263 | case 'delete': |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | $songs = $songsHandler->get($id); |
268 | 268 | if (!$songsHandler->delete($songs)) { |
269 | 269 | redirect_header( |
270 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
270 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
271 | 271 | 10, |
272 | 272 | _AM_SONGLIST_MSG_SONGS_FAILEDTODELETE |
273 | 273 | ); |
274 | 274 | exit(0); |
275 | 275 | } |
276 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_DELETED); |
|
276 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_SONGS_DELETED); |
|
277 | 277 | exit(0); |
278 | 278 | } |
279 | 279 | $songs = $songsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -3,10 +3,10 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Form\FormController, |
|
7 | - Helper, |
|
8 | - Artists, |
|
9 | - ArtistsHandler |
|
6 | + Form\FormController, |
|
7 | + Helper, |
|
8 | + Artists, |
|
9 | + ArtistsHandler |
|
10 | 10 | }; |
11 | 11 | |
12 | 12 | /** @var Artists $artist */ |
@@ -26,156 +26,156 @@ discard block |
||
26 | 26 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
27 | 27 | |
28 | 28 | switch ($op) { |
29 | - default: |
|
30 | - case 'artists': |
|
31 | - switch ($fct) { |
|
32 | - default: |
|
33 | - case 'list': |
|
34 | - $adminObject = Admin::getInstance(); |
|
35 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | - |
|
37 | - /** @var ArtistsHandler $artistsHandler */ |
|
38 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
39 | - |
|
40 | - $criteria = $artistsHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | - $ttl = $artistsHandler->getCount($criteria); |
|
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | - |
|
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | - |
|
47 | - foreach ($artistsHandler->filterFields() as $id => $key) { |
|
48 | - $GLOBALS['xoopsTpl']->assign( |
|
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | - '<a href="' |
|
51 | - . $_SERVER['SCRIPT_NAME'] |
|
52 | - . '?start=' |
|
53 | - . $GLOBALS['start'] |
|
54 | - . '&limit=' |
|
55 | - . $GLOBALS['limit'] |
|
56 | - . '&sort=' |
|
57 | - . $key |
|
58 | - . '&order=' |
|
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | - . '&op=' |
|
61 | - . $GLOBALS['op'] |
|
62 | - . '&filter=' |
|
63 | - . $GLOBALS['filter'] |
|
64 | - . '">' |
|
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | - . '</a>' |
|
67 | - ); |
|
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $artistsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | - } |
|
70 | - |
|
71 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | - |
|
78 | - $criteria->setStart($GLOBALS['start']); |
|
79 | - $criteria->setLimit($GLOBALS['limit']); |
|
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | - $criteria->setOrder($GLOBALS['order']); |
|
82 | - |
|
83 | - $artistsArray = $artistsHandler->getObjects($criteria, true); |
|
84 | - foreach ($artistsArray as $cid => $artist) { |
|
85 | - if (is_object($artist)) { |
|
86 | - $GLOBALS['xoopsTpl']->append('artists', $artist->toArray()); |
|
87 | - } |
|
88 | - } |
|
89 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormArtists(false)); |
|
90 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_artists_list.tpl'); |
|
92 | - break; |
|
93 | - case 'new': |
|
94 | - case 'edit': |
|
95 | - $adminObject = Admin::getInstance(); |
|
96 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | - |
|
98 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
99 | - if (Request::hasVar('id', 'REQUEST')) { |
|
100 | - $artist = $artistsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | - } else { |
|
102 | - $artist = $artistsHandler->create(); |
|
103 | - } |
|
104 | - |
|
105 | - $GLOBALS['xoopsTpl']->assign('form', $artist->getForm()); |
|
106 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_artists_edit.tpl'); |
|
108 | - break; |
|
109 | - case 'save': |
|
110 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
111 | - $id = 0; |
|
112 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | - if ($id) { |
|
114 | - $artist = $artistsHandler->get($id); |
|
115 | - } else { |
|
116 | - $artist = $artistsHandler->create(); |
|
117 | - } |
|
118 | - $artist->setVars($_POST[$id]); |
|
119 | - |
|
120 | - if (!$id = $artistsHandler->insert($artist)) { |
|
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE); |
|
122 | - exit(0); |
|
123 | - } |
|
124 | - if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
125 | - redirect_header( |
|
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | - 10, |
|
128 | - _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY |
|
129 | - ); |
|
130 | - } else { |
|
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
132 | - } |
|
133 | - exit(0); |
|
134 | - |
|
135 | - break; |
|
136 | - case 'savelist': |
|
137 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
138 | - foreach ($_REQUEST['id'] as $id) { |
|
139 | - $artist = $artistsHandler->get($id); |
|
140 | - $artist->setVars($_POST[$id]); |
|
141 | - if (!$artistsHandler->insert($artist)) { |
|
142 | - redirect_header( |
|
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | - 10, |
|
145 | - _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE |
|
146 | - ); |
|
147 | - exit(0); |
|
148 | - } |
|
149 | - } |
|
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
151 | - exit(0); |
|
152 | - break; |
|
153 | - case 'delete': |
|
154 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
155 | - $id = 0; |
|
156 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | - $artist = $artistsHandler->get($id); |
|
158 | - if (!$artistsHandler->delete($artist)) { |
|
159 | - redirect_header( |
|
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | - 10, |
|
162 | - _AM_SONGLIST_MSG_ARTISTS_FAILEDTODELETE |
|
163 | - ); |
|
164 | - exit(0); |
|
165 | - } |
|
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_DELETED); |
|
167 | - exit(0); |
|
168 | - } |
|
169 | - $artist = $artistsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | - xoops_confirm( |
|
171 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | - $_SERVER['SCRIPT_NAME'], |
|
173 | - sprintf(_AM_SONGLIST_MSG_ARTISTS_DELETE, $artist->getVar('name')) |
|
174 | - ); |
|
175 | - |
|
176 | - break; |
|
177 | - } |
|
178 | - break; |
|
29 | + default: |
|
30 | + case 'artists': |
|
31 | + switch ($fct) { |
|
32 | + default: |
|
33 | + case 'list': |
|
34 | + $adminObject = Admin::getInstance(); |
|
35 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | + |
|
37 | + /** @var ArtistsHandler $artistsHandler */ |
|
38 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
39 | + |
|
40 | + $criteria = $artistsHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | + $ttl = $artistsHandler->getCount($criteria); |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | + |
|
47 | + foreach ($artistsHandler->filterFields() as $id => $key) { |
|
48 | + $GLOBALS['xoopsTpl']->assign( |
|
49 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + '<a href="' |
|
51 | + . $_SERVER['SCRIPT_NAME'] |
|
52 | + . '?start=' |
|
53 | + . $GLOBALS['start'] |
|
54 | + . '&limit=' |
|
55 | + . $GLOBALS['limit'] |
|
56 | + . '&sort=' |
|
57 | + . $key |
|
58 | + . '&order=' |
|
59 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . '&op=' |
|
61 | + . $GLOBALS['op'] |
|
62 | + . '&filter=' |
|
63 | + . $GLOBALS['filter'] |
|
64 | + . '">' |
|
65 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . '</a>' |
|
67 | + ); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $artistsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + } |
|
70 | + |
|
71 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | + |
|
78 | + $criteria->setStart($GLOBALS['start']); |
|
79 | + $criteria->setLimit($GLOBALS['limit']); |
|
80 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setOrder($GLOBALS['order']); |
|
82 | + |
|
83 | + $artistsArray = $artistsHandler->getObjects($criteria, true); |
|
84 | + foreach ($artistsArray as $cid => $artist) { |
|
85 | + if (is_object($artist)) { |
|
86 | + $GLOBALS['xoopsTpl']->append('artists', $artist->toArray()); |
|
87 | + } |
|
88 | + } |
|
89 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormArtists(false)); |
|
90 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_artists_list.tpl'); |
|
92 | + break; |
|
93 | + case 'new': |
|
94 | + case 'edit': |
|
95 | + $adminObject = Admin::getInstance(); |
|
96 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | + |
|
98 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
99 | + if (Request::hasVar('id', 'REQUEST')) { |
|
100 | + $artist = $artistsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | + } else { |
|
102 | + $artist = $artistsHandler->create(); |
|
103 | + } |
|
104 | + |
|
105 | + $GLOBALS['xoopsTpl']->assign('form', $artist->getForm()); |
|
106 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_artists_edit.tpl'); |
|
108 | + break; |
|
109 | + case 'save': |
|
110 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
111 | + $id = 0; |
|
112 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | + if ($id) { |
|
114 | + $artist = $artistsHandler->get($id); |
|
115 | + } else { |
|
116 | + $artist = $artistsHandler->create(); |
|
117 | + } |
|
118 | + $artist->setVars($_POST[$id]); |
|
119 | + |
|
120 | + if (!$id = $artistsHandler->insert($artist)) { |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE); |
|
122 | + exit(0); |
|
123 | + } |
|
124 | + if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
125 | + redirect_header( |
|
126 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | + 10, |
|
128 | + _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY |
|
129 | + ); |
|
130 | + } else { |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
132 | + } |
|
133 | + exit(0); |
|
134 | + |
|
135 | + break; |
|
136 | + case 'savelist': |
|
137 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
138 | + foreach ($_REQUEST['id'] as $id) { |
|
139 | + $artist = $artistsHandler->get($id); |
|
140 | + $artist->setVars($_POST[$id]); |
|
141 | + if (!$artistsHandler->insert($artist)) { |
|
142 | + redirect_header( |
|
143 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | + 10, |
|
145 | + _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE |
|
146 | + ); |
|
147 | + exit(0); |
|
148 | + } |
|
149 | + } |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
151 | + exit(0); |
|
152 | + break; |
|
153 | + case 'delete': |
|
154 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
155 | + $id = 0; |
|
156 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | + $artist = $artistsHandler->get($id); |
|
158 | + if (!$artistsHandler->delete($artist)) { |
|
159 | + redirect_header( |
|
160 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | + 10, |
|
162 | + _AM_SONGLIST_MSG_ARTISTS_FAILEDTODELETE |
|
163 | + ); |
|
164 | + exit(0); |
|
165 | + } |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_DELETED); |
|
167 | + exit(0); |
|
168 | + } |
|
169 | + $artist = $artistsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | + xoops_confirm( |
|
171 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | + $_SERVER['SCRIPT_NAME'], |
|
173 | + sprintf(_AM_SONGLIST_MSG_ARTISTS_DELETE, $artist->getVar('name')) |
|
174 | + ); |
|
175 | + |
|
176 | + break; |
|
177 | + } |
|
178 | + break; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | xoops_cp_footer(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | /** @var Artists $artist */ |
13 | 13 | |
14 | -require __DIR__ . '/header.php'; |
|
14 | +require __DIR__.'/header.php'; |
|
15 | 15 | |
16 | 16 | xoops_loadLanguage('admin', 'songlist'); |
17 | 17 | |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
23 | 23 | $start = Request::getInt('start', 0, 'REQUEST'); |
24 | 24 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
25 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
26 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
25 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
26 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
27 | 27 | |
28 | 28 | switch ($op) { |
29 | 29 | default: |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | |
40 | 40 | $criteria = $artistsHandler->getFilterCriteria($GLOBALS['filter']); |
41 | 41 | $ttl = $artistsHandler->getCount($criteria); |
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
43 | 43 | |
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
45 | 45 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
46 | 46 | |
47 | 47 | foreach ($artistsHandler->filterFields() as $id => $key) { |
48 | 48 | $GLOBALS['xoopsTpl']->assign( |
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
49 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
50 | 50 | '<a href="' |
51 | 51 | . $_SERVER['SCRIPT_NAME'] |
52 | 52 | . '?start=' |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | . '&sort=' |
57 | 57 | . $key |
58 | 58 | . '&order=' |
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
59 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | 60 | . '&op=' |
61 | 61 | . $GLOBALS['op'] |
62 | 62 | . '&filter=' |
63 | 63 | . $GLOBALS['filter'] |
64 | 64 | . '">' |
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
65 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | 66 | . '</a>' |
67 | 67 | ); |
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $artistsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $artistsHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $criteria->setStart($GLOBALS['start']); |
79 | 79 | $criteria->setLimit($GLOBALS['limit']); |
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
80 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
81 | 81 | $criteria->setOrder($GLOBALS['order']); |
82 | 82 | |
83 | 83 | $artistsArray = $artistsHandler->getObjects($criteria, true); |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | $artist->setVars($_POST[$id]); |
119 | 119 | |
120 | 120 | if (!$id = $artistsHandler->insert($artist)) { |
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE); |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE); |
|
122 | 122 | exit(0); |
123 | 123 | } |
124 | - if ('new' === isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']]:'') { |
|
124 | + if ('new'===isset($_REQUEST['state']) ? $_REQUEST['state'][$_REQUEST['id']] : '') { |
|
125 | 125 | redirect_header( |
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
126 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
127 | 127 | 10, |
128 | 128 | _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY |
129 | 129 | ); |
130 | 130 | } else { |
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
132 | 132 | } |
133 | 133 | exit(0); |
134 | 134 | |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | $artist->setVars($_POST[$id]); |
141 | 141 | if (!$artistsHandler->insert($artist)) { |
142 | 142 | redirect_header( |
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
143 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
144 | 144 | 10, |
145 | 145 | _AM_SONGLIST_MSG_ARTISTS_FAILEDTOSAVE |
146 | 146 | ); |
147 | 147 | exit(0); |
148 | 148 | } |
149 | 149 | } |
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_SAVEDOKEY); |
|
151 | 151 | exit(0); |
152 | 152 | break; |
153 | 153 | case 'delete': |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | $artist = $artistsHandler->get($id); |
158 | 158 | if (!$artistsHandler->delete($artist)) { |
159 | 159 | redirect_header( |
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
160 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
161 | 161 | 10, |
162 | 162 | _AM_SONGLIST_MSG_ARTISTS_FAILEDTODELETE |
163 | 163 | ); |
164 | 164 | exit(0); |
165 | 165 | } |
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_DELETED); |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_ARTISTS_DELETED); |
|
167 | 167 | exit(0); |
168 | 168 | } |
169 | 169 | $artist = $artistsHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -3,10 +3,10 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Form\FormController, |
|
7 | - Helper, |
|
8 | - Utf8map, |
|
9 | - Utf8mapHandler, |
|
6 | + Form\FormController, |
|
7 | + Helper, |
|
8 | + Utf8map, |
|
9 | + Utf8mapHandler, |
|
10 | 10 | }; |
11 | 11 | |
12 | 12 | /** @var Utf8map $utf8map */ |
@@ -26,156 +26,156 @@ discard block |
||
26 | 26 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
27 | 27 | |
28 | 28 | switch ($op) { |
29 | - default: |
|
30 | - case 'utf8map': |
|
31 | - switch ($fct) { |
|
32 | - default: |
|
33 | - case 'list': |
|
34 | - $adminObject = Admin::getInstance(); |
|
35 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | - |
|
37 | - /** @var Utf8mapHandler $utf8mapHandler */ |
|
38 | - $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
39 | - |
|
40 | - $criteria = $utf8mapHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | - $ttl = $utf8mapHandler->getCount($criteria); |
|
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | - |
|
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | - |
|
47 | - foreach ($utf8mapHandler->filterFields() as $id => $key) { |
|
48 | - $GLOBALS['xoopsTpl']->assign( |
|
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | - '<a href="' |
|
51 | - . $_SERVER['SCRIPT_NAME'] |
|
52 | - . '?start=' |
|
53 | - . $GLOBALS['start'] |
|
54 | - . '&limit=' |
|
55 | - . $GLOBALS['limit'] |
|
56 | - . '&sort=' |
|
57 | - . $key |
|
58 | - . '&order=' |
|
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | - . '&op=' |
|
61 | - . $GLOBALS['op'] |
|
62 | - . '&filter=' |
|
63 | - . $GLOBALS['filter'] |
|
64 | - . '">' |
|
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | - . '</a>' |
|
67 | - ); |
|
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $utf8mapHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | - } |
|
70 | - |
|
71 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | - |
|
78 | - $criteria->setStart($GLOBALS['start']); |
|
79 | - $criteria->setLimit($GLOBALS['limit']); |
|
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | - $criteria->setOrder($GLOBALS['order']); |
|
82 | - |
|
83 | - $utf8maps = $utf8mapHandler->getObjects($criteria, true); |
|
84 | - foreach ($utf8maps as $cid => $utf8map) { |
|
85 | - if (is_object($utf8map)) { |
|
86 | - $GLOBALS['xoopsTpl']->append('utf8map', $utf8map->toArray()); |
|
87 | - } |
|
88 | - } |
|
89 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormUtf8map(false)); |
|
90 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_utf8map_list.tpl'); |
|
92 | - break; |
|
93 | - case 'new': |
|
94 | - case 'edit': |
|
95 | - $adminObject = Admin::getInstance(); |
|
96 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | - |
|
98 | - $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
99 | - if (Request::hasVar('id', 'REQUEST')) { |
|
100 | - $utf8map = $utf8mapHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | - } else { |
|
102 | - $utf8map = $utf8mapHandler->create(); |
|
103 | - } |
|
104 | - |
|
105 | - $GLOBALS['xoopsTpl']->assign('form', $utf8map->getForm()); |
|
106 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_utf8map_edit.tpl'); |
|
108 | - break; |
|
109 | - case 'save': |
|
110 | - $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
111 | - $id = 0; |
|
112 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | - if ($id) { |
|
114 | - $utf8map = $utf8mapHandler->get($id); |
|
115 | - } else { |
|
116 | - $utf8map = $utf8mapHandler->create(); |
|
117 | - } |
|
118 | - $utf8map->setVars($_POST[$id]); |
|
119 | - |
|
120 | - if (!$id = $utf8mapHandler->insert($utf8map)) { |
|
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE); |
|
122 | - exit(0); |
|
123 | - } |
|
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | - redirect_header( |
|
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | - 10, |
|
128 | - _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY |
|
129 | - ); |
|
130 | - } else { |
|
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
132 | - } |
|
133 | - exit(0); |
|
134 | - |
|
135 | - break; |
|
136 | - case 'savelist': |
|
137 | - $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
138 | - foreach ($_REQUEST['id'] as $id) { |
|
139 | - $utf8map = $utf8mapHandler->get($id); |
|
140 | - $utf8map->setVars($_POST[$id]); |
|
141 | - if (!$utf8mapHandler->insert($utf8map)) { |
|
142 | - redirect_header( |
|
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | - 10, |
|
145 | - _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE |
|
146 | - ); |
|
147 | - exit(0); |
|
148 | - } |
|
149 | - } |
|
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
151 | - exit(0); |
|
152 | - break; |
|
153 | - case 'delete': |
|
154 | - $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
155 | - $id = 0; |
|
156 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | - $utf8map = $utf8mapHandler->get($id); |
|
158 | - if (!$utf8mapHandler->delete($utf8map)) { |
|
159 | - redirect_header( |
|
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | - 10, |
|
162 | - _AM_SONGLIST_MSG_UTF8MAP_FAILEDTODELETE |
|
163 | - ); |
|
164 | - exit(0); |
|
165 | - } |
|
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_DELETED); |
|
167 | - exit(0); |
|
168 | - } |
|
169 | - $utf8map = $utf8mapHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | - xoops_confirm( |
|
171 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | - $_SERVER['SCRIPT_NAME'], |
|
173 | - sprintf(_AM_SONGLIST_MSG_UTF8MAP_DELETE, $utf8map->getVar('from'), $utf8map->getVar('to')) |
|
174 | - ); |
|
175 | - |
|
176 | - break; |
|
177 | - } |
|
178 | - break; |
|
29 | + default: |
|
30 | + case 'utf8map': |
|
31 | + switch ($fct) { |
|
32 | + default: |
|
33 | + case 'list': |
|
34 | + $adminObject = Admin::getInstance(); |
|
35 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | + |
|
37 | + /** @var Utf8mapHandler $utf8mapHandler */ |
|
38 | + $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
39 | + |
|
40 | + $criteria = $utf8mapHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | + $ttl = $utf8mapHandler->getCount($criteria); |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | + |
|
47 | + foreach ($utf8mapHandler->filterFields() as $id => $key) { |
|
48 | + $GLOBALS['xoopsTpl']->assign( |
|
49 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + '<a href="' |
|
51 | + . $_SERVER['SCRIPT_NAME'] |
|
52 | + . '?start=' |
|
53 | + . $GLOBALS['start'] |
|
54 | + . '&limit=' |
|
55 | + . $GLOBALS['limit'] |
|
56 | + . '&sort=' |
|
57 | + . $key |
|
58 | + . '&order=' |
|
59 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . '&op=' |
|
61 | + . $GLOBALS['op'] |
|
62 | + . '&filter=' |
|
63 | + . $GLOBALS['filter'] |
|
64 | + . '">' |
|
65 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . '</a>' |
|
67 | + ); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $utf8mapHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + } |
|
70 | + |
|
71 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | + |
|
78 | + $criteria->setStart($GLOBALS['start']); |
|
79 | + $criteria->setLimit($GLOBALS['limit']); |
|
80 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setOrder($GLOBALS['order']); |
|
82 | + |
|
83 | + $utf8maps = $utf8mapHandler->getObjects($criteria, true); |
|
84 | + foreach ($utf8maps as $cid => $utf8map) { |
|
85 | + if (is_object($utf8map)) { |
|
86 | + $GLOBALS['xoopsTpl']->append('utf8map', $utf8map->toArray()); |
|
87 | + } |
|
88 | + } |
|
89 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormUtf8map(false)); |
|
90 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_utf8map_list.tpl'); |
|
92 | + break; |
|
93 | + case 'new': |
|
94 | + case 'edit': |
|
95 | + $adminObject = Admin::getInstance(); |
|
96 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | + |
|
98 | + $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
99 | + if (Request::hasVar('id', 'REQUEST')) { |
|
100 | + $utf8map = $utf8mapHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | + } else { |
|
102 | + $utf8map = $utf8mapHandler->create(); |
|
103 | + } |
|
104 | + |
|
105 | + $GLOBALS['xoopsTpl']->assign('form', $utf8map->getForm()); |
|
106 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_utf8map_edit.tpl'); |
|
108 | + break; |
|
109 | + case 'save': |
|
110 | + $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
111 | + $id = 0; |
|
112 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | + if ($id) { |
|
114 | + $utf8map = $utf8mapHandler->get($id); |
|
115 | + } else { |
|
116 | + $utf8map = $utf8mapHandler->create(); |
|
117 | + } |
|
118 | + $utf8map->setVars($_POST[$id]); |
|
119 | + |
|
120 | + if (!$id = $utf8mapHandler->insert($utf8map)) { |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE); |
|
122 | + exit(0); |
|
123 | + } |
|
124 | + if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | + redirect_header( |
|
126 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | + 10, |
|
128 | + _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY |
|
129 | + ); |
|
130 | + } else { |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
132 | + } |
|
133 | + exit(0); |
|
134 | + |
|
135 | + break; |
|
136 | + case 'savelist': |
|
137 | + $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
138 | + foreach ($_REQUEST['id'] as $id) { |
|
139 | + $utf8map = $utf8mapHandler->get($id); |
|
140 | + $utf8map->setVars($_POST[$id]); |
|
141 | + if (!$utf8mapHandler->insert($utf8map)) { |
|
142 | + redirect_header( |
|
143 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | + 10, |
|
145 | + _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE |
|
146 | + ); |
|
147 | + exit(0); |
|
148 | + } |
|
149 | + } |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
151 | + exit(0); |
|
152 | + break; |
|
153 | + case 'delete': |
|
154 | + $utf8mapHandler = Helper::getInstance()->getHandler('Utf8map'); |
|
155 | + $id = 0; |
|
156 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | + $utf8map = $utf8mapHandler->get($id); |
|
158 | + if (!$utf8mapHandler->delete($utf8map)) { |
|
159 | + redirect_header( |
|
160 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | + 10, |
|
162 | + _AM_SONGLIST_MSG_UTF8MAP_FAILEDTODELETE |
|
163 | + ); |
|
164 | + exit(0); |
|
165 | + } |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_DELETED); |
|
167 | + exit(0); |
|
168 | + } |
|
169 | + $utf8map = $utf8mapHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | + xoops_confirm( |
|
171 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | + $_SERVER['SCRIPT_NAME'], |
|
173 | + sprintf(_AM_SONGLIST_MSG_UTF8MAP_DELETE, $utf8map->getVar('from'), $utf8map->getVar('to')) |
|
174 | + ); |
|
175 | + |
|
176 | + break; |
|
177 | + } |
|
178 | + break; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | xoops_cp_footer(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | /** @var Utf8map $utf8map */ |
13 | 13 | |
14 | -require __DIR__ . '/header.php'; |
|
14 | +require __DIR__.'/header.php'; |
|
15 | 15 | |
16 | 16 | xoops_loadLanguage('admin', 'songlist'); |
17 | 17 | |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
23 | 23 | $start = Request::getInt('start', 0, 'REQUEST'); |
24 | 24 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
25 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
26 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
25 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
26 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
27 | 27 | |
28 | 28 | switch ($op) { |
29 | 29 | default: |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | |
40 | 40 | $criteria = $utf8mapHandler->getFilterCriteria($GLOBALS['filter']); |
41 | 41 | $ttl = $utf8mapHandler->getCount($criteria); |
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
43 | 43 | |
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
45 | 45 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
46 | 46 | |
47 | 47 | foreach ($utf8mapHandler->filterFields() as $id => $key) { |
48 | 48 | $GLOBALS['xoopsTpl']->assign( |
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
49 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
50 | 50 | '<a href="' |
51 | 51 | . $_SERVER['SCRIPT_NAME'] |
52 | 52 | . '?start=' |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | . '&sort=' |
57 | 57 | . $key |
58 | 58 | . '&order=' |
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
59 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | 60 | . '&op=' |
61 | 61 | . $GLOBALS['op'] |
62 | 62 | . '&filter=' |
63 | 63 | . $GLOBALS['filter'] |
64 | 64 | . '">' |
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
65 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | 66 | . '</a>' |
67 | 67 | ); |
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $utf8mapHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $utf8mapHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $criteria->setStart($GLOBALS['start']); |
79 | 79 | $criteria->setLimit($GLOBALS['limit']); |
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
80 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
81 | 81 | $criteria->setOrder($GLOBALS['order']); |
82 | 82 | |
83 | 83 | $utf8maps = $utf8mapHandler->getObjects($criteria, true); |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | $utf8map->setVars($_POST[$id]); |
119 | 119 | |
120 | 120 | if (!$id = $utf8mapHandler->insert($utf8map)) { |
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE); |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE); |
|
122 | 122 | exit(0); |
123 | 123 | } |
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
124 | + if ('new'===$_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | 125 | redirect_header( |
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
126 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
127 | 127 | 10, |
128 | 128 | _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY |
129 | 129 | ); |
130 | 130 | } else { |
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
132 | 132 | } |
133 | 133 | exit(0); |
134 | 134 | |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | $utf8map->setVars($_POST[$id]); |
141 | 141 | if (!$utf8mapHandler->insert($utf8map)) { |
142 | 142 | redirect_header( |
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
143 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
144 | 144 | 10, |
145 | 145 | _AM_SONGLIST_MSG_UTF8MAP_FAILEDTOSAVE |
146 | 146 | ); |
147 | 147 | exit(0); |
148 | 148 | } |
149 | 149 | } |
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_SAVEDOKEY); |
|
151 | 151 | exit(0); |
152 | 152 | break; |
153 | 153 | case 'delete': |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | $utf8map = $utf8mapHandler->get($id); |
158 | 158 | if (!$utf8mapHandler->delete($utf8map)) { |
159 | 159 | redirect_header( |
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
160 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
161 | 161 | 10, |
162 | 162 | _AM_SONGLIST_MSG_UTF8MAP_FAILEDTODELETE |
163 | 163 | ); |
164 | 164 | exit(0); |
165 | 165 | } |
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_DELETED); |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_UTF8MAP_DELETED); |
|
167 | 167 | exit(0); |
168 | 168 | } |
169 | 169 | $utf8map = $utf8mapHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
30 | 30 | |
31 | 31 | switch ($op) { |
32 | - case 'import': |
|
33 | - switch ($fct) { |
|
34 | - default: |
|
35 | - case 'actiona': |
|
36 | - if (Request::hasVar('xmlfile', 'SESSION')) { |
|
37 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
38 | - } |
|
39 | - $adminObject = Admin::getInstance(); |
|
40 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
32 | + case 'import': |
|
33 | + switch ($fct) { |
|
34 | + default: |
|
35 | + case 'actiona': |
|
36 | + if (Request::hasVar('xmlfile', 'SESSION')) { |
|
37 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
38 | + } |
|
39 | + $adminObject = Admin::getInstance(); |
|
40 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
41 | 41 | |
42 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImport(false)); |
|
43 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
44 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actiona.tpl'); |
|
45 | - break; |
|
46 | - case 'upload': |
|
47 | - if (Request::hasVar('xmlfile', 'FILES') && !empty($_FILES['xmlfile']['title'])) { |
|
42 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImport(false)); |
|
43 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
44 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actiona.tpl'); |
|
45 | + break; |
|
46 | + case 'upload': |
|
47 | + if (Request::hasVar('xmlfile', 'FILES') && !empty($_FILES['xmlfile']['title'])) { |
|
48 | 48 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
49 | 49 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
50 | 50 | // foreach (explode('/', $folders) as $folder) { |
@@ -57,287 +57,287 @@ discard block |
||
57 | 57 | // } |
58 | 58 | |
59 | 59 | // require_once $GLOBALS['xoops']->path('modules/songlist/include/uploader.php'); |
60 | - $albums = $albumsHandler->get($id); |
|
61 | - $uploader = new Uploader( |
|
62 | - $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
63 | - ['application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
|
64 | - 1024 * 1024 * 32, |
|
65 | - 0, |
|
66 | - 0, |
|
67 | - ['xml'] |
|
68 | - ); |
|
69 | - try { |
|
70 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
71 | - } catch (Exception $e) { |
|
72 | - } |
|
60 | + $albums = $albumsHandler->get($id); |
|
61 | + $uploader = new Uploader( |
|
62 | + $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
63 | + ['application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
|
64 | + 1024 * 1024 * 32, |
|
65 | + 0, |
|
66 | + 0, |
|
67 | + ['xml'] |
|
68 | + ); |
|
69 | + try { |
|
70 | + $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
71 | + } catch (Exception $e) { |
|
72 | + } |
|
73 | 73 | |
74 | - if ($uploader->fetchMedia('xmlfile')) { |
|
75 | - if (!$uploader->upload()) { |
|
76 | - echo $uploader->getErrors(); |
|
77 | - require __DIR__ . '/admin_footer.php'; |
|
78 | - exit(0); |
|
79 | - } |
|
80 | - $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
|
81 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
82 | - } else { |
|
83 | - echo $uploader->getErrors(); |
|
84 | - require __DIR__ . '/admin_footer.php'; |
|
85 | - exit(0); |
|
86 | - } |
|
87 | - } |
|
88 | - break; |
|
89 | - case 'actionb': |
|
90 | - $adminObject = Admin::getInstance(); |
|
91 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
74 | + if ($uploader->fetchMedia('xmlfile')) { |
|
75 | + if (!$uploader->upload()) { |
|
76 | + echo $uploader->getErrors(); |
|
77 | + require __DIR__ . '/admin_footer.php'; |
|
78 | + exit(0); |
|
79 | + } |
|
80 | + $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
|
81 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
82 | + } else { |
|
83 | + echo $uploader->getErrors(); |
|
84 | + require __DIR__ . '/admin_footer.php'; |
|
85 | + exit(0); |
|
86 | + } |
|
87 | + } |
|
88 | + break; |
|
89 | + case 'actionb': |
|
90 | + $adminObject = Admin::getInstance(); |
|
91 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
92 | 92 | |
93 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImportb($_SESSION['xmlfile'])); |
|
94 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
95 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actionb.tpl'); |
|
96 | - break; |
|
97 | - case 'import': |
|
93 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImportb($_SESSION['xmlfile'])); |
|
94 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
95 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actionb.tpl'); |
|
96 | + break; |
|
97 | + case 'import': |
|
98 | 98 | |
99 | - $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
100 | - $mb = floor($filesize / 1024 / 1024); |
|
101 | - if ($mb > 32) { |
|
102 | - ini_set('memory_limit', ($mb + 128) . 'M'); |
|
103 | - } |
|
104 | - set_time_limit(3600); |
|
99 | + $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
100 | + $mb = floor($filesize / 1024 / 1024); |
|
101 | + if ($mb > 32) { |
|
102 | + ini_set('memory_limit', ($mb + 128) . 'M'); |
|
103 | + } |
|
104 | + set_time_limit(3600); |
|
105 | 105 | |
106 | - $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
106 | + $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
107 | 107 | |
108 | - if (mb_strlen($_POST['collection']) > 0) { |
|
109 | - foreach ($xmlarray[$_POST['collection']] as $id => $record) { |
|
110 | - foreach ($record as $recid => $data) { |
|
111 | - $gid = 0; |
|
112 | - if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
113 | - $criteria = new \Criteria('name', $data[$_POST['genre']]); |
|
114 | - if ($genreHandler->getCount($criteria) > 0) { |
|
115 | - $objects = $genreHandler->getObjects($criteria, false); |
|
116 | - $gid = $objects[0]->getVar('gid'); |
|
117 | - } else { |
|
118 | - $object = $genreHandler->create(); |
|
119 | - $object->setVar('name', $data[$_POST['genre']]); |
|
120 | - $gid = $genreHandler->insert($object); |
|
121 | - } |
|
122 | - } |
|
108 | + if (mb_strlen($_POST['collection']) > 0) { |
|
109 | + foreach ($xmlarray[$_POST['collection']] as $id => $record) { |
|
110 | + foreach ($record as $recid => $data) { |
|
111 | + $gid = 0; |
|
112 | + if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
113 | + $criteria = new \Criteria('name', $data[$_POST['genre']]); |
|
114 | + if ($genreHandler->getCount($criteria) > 0) { |
|
115 | + $objects = $genreHandler->getObjects($criteria, false); |
|
116 | + $gid = $objects[0]->getVar('gid'); |
|
117 | + } else { |
|
118 | + $object = $genreHandler->create(); |
|
119 | + $object->setVar('name', $data[$_POST['genre']]); |
|
120 | + $gid = $genreHandler->insert($object); |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - $vid = 0; |
|
125 | - if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
126 | - $criteria = new \Criteria('name', $data[$_POST['voice']]); |
|
127 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
128 | - $objects = $voiceHandler->getObjects($criteria, false); |
|
129 | - $gid = $objects[0]->getVar('vid'); |
|
130 | - } else { |
|
131 | - $object = $voiceHandler->create(); |
|
132 | - $object->setVar('name', $data[$_POST['voice']]); |
|
133 | - $gid = $voiceHandler->insert($object); |
|
134 | - } |
|
135 | - } |
|
124 | + $vid = 0; |
|
125 | + if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
126 | + $criteria = new \Criteria('name', $data[$_POST['voice']]); |
|
127 | + if ($voiceHandler->getCount($criteria) > 0) { |
|
128 | + $objects = $voiceHandler->getObjects($criteria, false); |
|
129 | + $gid = $objects[0]->getVar('vid'); |
|
130 | + } else { |
|
131 | + $object = $voiceHandler->create(); |
|
132 | + $object->setVar('name', $data[$_POST['voice']]); |
|
133 | + $gid = $voiceHandler->insert($object); |
|
134 | + } |
|
135 | + } |
|
136 | 136 | |
137 | - $cid = 0; |
|
138 | - if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
139 | - $criteria = new \Criteria('name', $data[$_POST['category']]); |
|
140 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
141 | - $objects = $categoryHandler->getObjects($criteria, false); |
|
142 | - $cid = $objects[0]->getVar('cid'); |
|
143 | - } else { |
|
144 | - $object = $categoryHandler->create(); |
|
145 | - $object->setVar('name', $data[$_POST['category']]); |
|
146 | - $cid = $categoryHandler->insert($object); |
|
147 | - } |
|
148 | - } |
|
149 | - $aids = []; |
|
150 | - if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
151 | - foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
|
152 | - $criteria = new \Criteria('name', $artist); |
|
153 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
154 | - $objects = $artistsHandler->getObjects($criteria, false); |
|
155 | - $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
156 | - } else { |
|
157 | - $object = $artistsHandler->create(); |
|
158 | - $object->setVar('cid', $cid); |
|
159 | - switch ($data[$_POST['singer']]) { |
|
160 | - case $_POST['duet']: |
|
161 | - $object->setVar('singer', '_ENUM_SONGLIST_DUET'); |
|
162 | - break; |
|
163 | - case $_POST['solo']: |
|
164 | - $object->setVar('singer', '_ENUM_SONGLIST_SOLO'); |
|
165 | - break; |
|
166 | - } |
|
167 | - $object->setVar('name', $data[$_POST['artist']]); |
|
168 | - $aid = $artistsHandler->insert($object); |
|
169 | - $aids[$aid] = $aid; |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - $abid = 0; |
|
174 | - if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
175 | - $criteria = new \Criteria('name', $data[$_POST['album']]); |
|
176 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
177 | - $objects = $albumsHandler->getObjects($criteria, false); |
|
178 | - $abid = $objects[0]->getVar('aid'); |
|
179 | - } else { |
|
180 | - $object = $albumsHandler->create(); |
|
181 | - $object->setVar('cid', $cid); |
|
182 | - $object->setVar('aids', $aids); |
|
183 | - $object->setVar('name', $data[$_POST['album']]); |
|
184 | - $abid = $albumsHandler->insert($object); |
|
185 | - } |
|
186 | - } |
|
187 | - $sid = 0; |
|
188 | - if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
189 | - $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
|
190 | - if ($songsHandler->getCount($criteria) > 0) { |
|
191 | - $objects = $songsHandler->getObjects($criteria, false); |
|
192 | - $object = $objects[0]->getVar('sid'); |
|
193 | - } else { |
|
194 | - $object = $songsHandler->create(); |
|
195 | - } |
|
196 | - if ($object->getVar('cid') > 0 && $cid > 0) { |
|
197 | - $object->setVar('cid', $cid); |
|
198 | - } else { |
|
199 | - $object->setVar('cid', $cid); |
|
200 | - } |
|
201 | - if ($object->getVar('gid') > 0 && $gid > 0) { |
|
202 | - $object->setVar('gid', $gid); |
|
203 | - } else { |
|
204 | - $object->setVar('gid', $gid); |
|
205 | - } |
|
206 | - if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
207 | - $object->setVar('aids', $aids); |
|
208 | - } else { |
|
209 | - $object->setVar('aids', $aids); |
|
210 | - } |
|
211 | - if ($object->getVar('abid') > 0 && $abid > 0) { |
|
212 | - $object->setVar('abid', $abid); |
|
213 | - } else { |
|
214 | - $object->setVar('abid', $abid); |
|
215 | - } |
|
216 | - $object->setVar('songid', $data[$_POST['songid']]); |
|
217 | - $object->setVar('title', $data[$_POST['title']]); |
|
218 | - $object->setVar('lyrics', str_replace("\n", "<br>\n", $data[$_POST['lyrics']])); |
|
219 | - $sid = $songsHandler->insert($object); |
|
220 | - } |
|
221 | - } |
|
222 | - } |
|
223 | - } else { |
|
224 | - foreach ($xmlarray as $recid => $data) { |
|
225 | - $gid = 0; |
|
226 | - if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
227 | - $criteria = new \Criteria('name', $data[$_POST['genre']]); |
|
228 | - if ($genreHandler->getCount($criteria) > 0) { |
|
229 | - $objects = $genreHandler->getObjects($criteria, false); |
|
230 | - $gid = $objects[0]->getVar('gid'); |
|
231 | - } else { |
|
232 | - $object = $genreHandler->create(); |
|
233 | - $object->setVar('name', $data[$_POST['genre']]); |
|
234 | - $gid = $genreHandler->insert($object); |
|
235 | - } |
|
236 | - } |
|
237 | - $vid = 0; |
|
238 | - if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
239 | - $criteria = new \Criteria('name', $data[$_POST['voice']]); |
|
240 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
241 | - $objects = $voiceHandler->getObjects($criteria, false); |
|
242 | - $gid = $objects[0]->getVar('vid'); |
|
243 | - } else { |
|
244 | - $object = $voiceHandler->create(); |
|
245 | - $object->setVar('name', $data[$_POST['voice']]); |
|
246 | - $gid = $voiceHandler->insert($object); |
|
247 | - } |
|
248 | - } |
|
249 | - $cid = 0; |
|
250 | - if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
251 | - $criteria = new \Criteria('name', $data[$_POST['category']]); |
|
252 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
253 | - $objects = $categoryHandler->getObjects($criteria, false); |
|
254 | - $cid = $objects[0]->getVar('cid'); |
|
255 | - } else { |
|
256 | - $object = $categoryHandler->create(); |
|
257 | - $object->setVar('name', $data[$_POST['category']]); |
|
258 | - $cid = $categoryHandler->insert($object); |
|
259 | - } |
|
260 | - } |
|
261 | - $aids = []; |
|
262 | - if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
263 | - foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
|
264 | - $criteria = new \Criteria('name', $artist); |
|
265 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
266 | - $objects = $artistsHandler->getObjects($criteria, false); |
|
267 | - $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
268 | - } else { |
|
269 | - $object = $artistsHandler->create(); |
|
270 | - switch ($data[$_POST['singer']]) { |
|
271 | - case $_POST['duet']: |
|
272 | - $object->setVar('singer', '_ENUM_SONGLIST_DUET'); |
|
273 | - break; |
|
274 | - case $_POST['solo']: |
|
275 | - $object->setVar('singer', '_ENUM_SONGLIST_SOLO'); |
|
276 | - break; |
|
277 | - } |
|
278 | - $object->setVar('cid', $cid); |
|
279 | - $object->setVar('name', $data[$_POST['artist']]); |
|
280 | - $aid = $artistsHandler->insert($object); |
|
281 | - $aids[$aid] = $aid; |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - $abid = 0; |
|
286 | - if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
287 | - $criteria = new \Criteria('name', $data[$_POST['album']]); |
|
288 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
289 | - $objects = $albumsHandler->getObjects($criteria, false); |
|
290 | - $abid = $objects[0]->getVar('aid'); |
|
291 | - } else { |
|
292 | - $object = $albumsHandler->create(); |
|
293 | - $object->setVar('cid', $cid); |
|
294 | - $object->setVar('aids', $aids); |
|
295 | - $object->setVar('name', $data[$_POST['album']]); |
|
296 | - $abid = $albumsHandler->insert($object); |
|
297 | - } |
|
298 | - } |
|
299 | - $sid = 0; |
|
300 | - if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
301 | - $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
|
302 | - if ($songsHandler->getCount($criteria) > 0) { |
|
303 | - $objects = $songsHandler->getObjects($criteria, false); |
|
304 | - $object = $objects[0]->getVar('sid'); |
|
305 | - } else { |
|
306 | - $object = $songsHandler->create(); |
|
307 | - } |
|
308 | - if ($object->getVar('cid') > 0 && $cid > 0) { |
|
309 | - $object->setVar('cid', $cid); |
|
310 | - } else { |
|
311 | - $object->setVar('cid', $cid); |
|
312 | - } |
|
313 | - if ($object->getVar('gid') > 0 && $gid > 0) { |
|
314 | - $object->setVar('gid', $gid); |
|
315 | - } else { |
|
316 | - $object->setVar('gid', $gid); |
|
317 | - } |
|
318 | - if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
319 | - $object->setVar('aids', $aids); |
|
320 | - } else { |
|
321 | - $object->setVar('aids', $aids); |
|
322 | - } |
|
323 | - if ($object->getVar('abid') > 0 && $abid > 0) { |
|
324 | - $object->setVar('abid', $abid); |
|
325 | - } else { |
|
326 | - $object->setVar('abid', $abid); |
|
327 | - } |
|
328 | - $object->setVar('songid', $data[$_POST['songid']]); |
|
329 | - $object->setVar('title', $data[$_POST['title']]); |
|
330 | - $object->setVar('lyrics', str_replace("\n", "<br>\n", $data[$_POST['lyrics']])); |
|
331 | - $sid = $songsHandler->insert($object); |
|
332 | - } |
|
333 | - } |
|
334 | - } |
|
335 | - unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
336 | - unset($_SESSION['xmlfile']); |
|
337 | - redirect_header($_SERVER['SCRIPT_NAME'] . '&op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
338 | - break; |
|
339 | - } |
|
340 | - break; |
|
137 | + $cid = 0; |
|
138 | + if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
139 | + $criteria = new \Criteria('name', $data[$_POST['category']]); |
|
140 | + if ($categoryHandler->getCount($criteria) > 0) { |
|
141 | + $objects = $categoryHandler->getObjects($criteria, false); |
|
142 | + $cid = $objects[0]->getVar('cid'); |
|
143 | + } else { |
|
144 | + $object = $categoryHandler->create(); |
|
145 | + $object->setVar('name', $data[$_POST['category']]); |
|
146 | + $cid = $categoryHandler->insert($object); |
|
147 | + } |
|
148 | + } |
|
149 | + $aids = []; |
|
150 | + if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
151 | + foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
|
152 | + $criteria = new \Criteria('name', $artist); |
|
153 | + if ($artistsHandler->getCount($criteria) > 0) { |
|
154 | + $objects = $artistsHandler->getObjects($criteria, false); |
|
155 | + $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
156 | + } else { |
|
157 | + $object = $artistsHandler->create(); |
|
158 | + $object->setVar('cid', $cid); |
|
159 | + switch ($data[$_POST['singer']]) { |
|
160 | + case $_POST['duet']: |
|
161 | + $object->setVar('singer', '_ENUM_SONGLIST_DUET'); |
|
162 | + break; |
|
163 | + case $_POST['solo']: |
|
164 | + $object->setVar('singer', '_ENUM_SONGLIST_SOLO'); |
|
165 | + break; |
|
166 | + } |
|
167 | + $object->setVar('name', $data[$_POST['artist']]); |
|
168 | + $aid = $artistsHandler->insert($object); |
|
169 | + $aids[$aid] = $aid; |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + $abid = 0; |
|
174 | + if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
175 | + $criteria = new \Criteria('name', $data[$_POST['album']]); |
|
176 | + if ($albumsHandler->getCount($criteria) > 0) { |
|
177 | + $objects = $albumsHandler->getObjects($criteria, false); |
|
178 | + $abid = $objects[0]->getVar('aid'); |
|
179 | + } else { |
|
180 | + $object = $albumsHandler->create(); |
|
181 | + $object->setVar('cid', $cid); |
|
182 | + $object->setVar('aids', $aids); |
|
183 | + $object->setVar('name', $data[$_POST['album']]); |
|
184 | + $abid = $albumsHandler->insert($object); |
|
185 | + } |
|
186 | + } |
|
187 | + $sid = 0; |
|
188 | + if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
189 | + $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
|
190 | + if ($songsHandler->getCount($criteria) > 0) { |
|
191 | + $objects = $songsHandler->getObjects($criteria, false); |
|
192 | + $object = $objects[0]->getVar('sid'); |
|
193 | + } else { |
|
194 | + $object = $songsHandler->create(); |
|
195 | + } |
|
196 | + if ($object->getVar('cid') > 0 && $cid > 0) { |
|
197 | + $object->setVar('cid', $cid); |
|
198 | + } else { |
|
199 | + $object->setVar('cid', $cid); |
|
200 | + } |
|
201 | + if ($object->getVar('gid') > 0 && $gid > 0) { |
|
202 | + $object->setVar('gid', $gid); |
|
203 | + } else { |
|
204 | + $object->setVar('gid', $gid); |
|
205 | + } |
|
206 | + if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
207 | + $object->setVar('aids', $aids); |
|
208 | + } else { |
|
209 | + $object->setVar('aids', $aids); |
|
210 | + } |
|
211 | + if ($object->getVar('abid') > 0 && $abid > 0) { |
|
212 | + $object->setVar('abid', $abid); |
|
213 | + } else { |
|
214 | + $object->setVar('abid', $abid); |
|
215 | + } |
|
216 | + $object->setVar('songid', $data[$_POST['songid']]); |
|
217 | + $object->setVar('title', $data[$_POST['title']]); |
|
218 | + $object->setVar('lyrics', str_replace("\n", "<br>\n", $data[$_POST['lyrics']])); |
|
219 | + $sid = $songsHandler->insert($object); |
|
220 | + } |
|
221 | + } |
|
222 | + } |
|
223 | + } else { |
|
224 | + foreach ($xmlarray as $recid => $data) { |
|
225 | + $gid = 0; |
|
226 | + if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
227 | + $criteria = new \Criteria('name', $data[$_POST['genre']]); |
|
228 | + if ($genreHandler->getCount($criteria) > 0) { |
|
229 | + $objects = $genreHandler->getObjects($criteria, false); |
|
230 | + $gid = $objects[0]->getVar('gid'); |
|
231 | + } else { |
|
232 | + $object = $genreHandler->create(); |
|
233 | + $object->setVar('name', $data[$_POST['genre']]); |
|
234 | + $gid = $genreHandler->insert($object); |
|
235 | + } |
|
236 | + } |
|
237 | + $vid = 0; |
|
238 | + if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
239 | + $criteria = new \Criteria('name', $data[$_POST['voice']]); |
|
240 | + if ($voiceHandler->getCount($criteria) > 0) { |
|
241 | + $objects = $voiceHandler->getObjects($criteria, false); |
|
242 | + $gid = $objects[0]->getVar('vid'); |
|
243 | + } else { |
|
244 | + $object = $voiceHandler->create(); |
|
245 | + $object->setVar('name', $data[$_POST['voice']]); |
|
246 | + $gid = $voiceHandler->insert($object); |
|
247 | + } |
|
248 | + } |
|
249 | + $cid = 0; |
|
250 | + if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
251 | + $criteria = new \Criteria('name', $data[$_POST['category']]); |
|
252 | + if ($categoryHandler->getCount($criteria) > 0) { |
|
253 | + $objects = $categoryHandler->getObjects($criteria, false); |
|
254 | + $cid = $objects[0]->getVar('cid'); |
|
255 | + } else { |
|
256 | + $object = $categoryHandler->create(); |
|
257 | + $object->setVar('name', $data[$_POST['category']]); |
|
258 | + $cid = $categoryHandler->insert($object); |
|
259 | + } |
|
260 | + } |
|
261 | + $aids = []; |
|
262 | + if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
263 | + foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
|
264 | + $criteria = new \Criteria('name', $artist); |
|
265 | + if ($artistsHandler->getCount($criteria) > 0) { |
|
266 | + $objects = $artistsHandler->getObjects($criteria, false); |
|
267 | + $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
268 | + } else { |
|
269 | + $object = $artistsHandler->create(); |
|
270 | + switch ($data[$_POST['singer']]) { |
|
271 | + case $_POST['duet']: |
|
272 | + $object->setVar('singer', '_ENUM_SONGLIST_DUET'); |
|
273 | + break; |
|
274 | + case $_POST['solo']: |
|
275 | + $object->setVar('singer', '_ENUM_SONGLIST_SOLO'); |
|
276 | + break; |
|
277 | + } |
|
278 | + $object->setVar('cid', $cid); |
|
279 | + $object->setVar('name', $data[$_POST['artist']]); |
|
280 | + $aid = $artistsHandler->insert($object); |
|
281 | + $aids[$aid] = $aid; |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + $abid = 0; |
|
286 | + if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
287 | + $criteria = new \Criteria('name', $data[$_POST['album']]); |
|
288 | + if ($albumsHandler->getCount($criteria) > 0) { |
|
289 | + $objects = $albumsHandler->getObjects($criteria, false); |
|
290 | + $abid = $objects[0]->getVar('aid'); |
|
291 | + } else { |
|
292 | + $object = $albumsHandler->create(); |
|
293 | + $object->setVar('cid', $cid); |
|
294 | + $object->setVar('aids', $aids); |
|
295 | + $object->setVar('name', $data[$_POST['album']]); |
|
296 | + $abid = $albumsHandler->insert($object); |
|
297 | + } |
|
298 | + } |
|
299 | + $sid = 0; |
|
300 | + if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
301 | + $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
|
302 | + if ($songsHandler->getCount($criteria) > 0) { |
|
303 | + $objects = $songsHandler->getObjects($criteria, false); |
|
304 | + $object = $objects[0]->getVar('sid'); |
|
305 | + } else { |
|
306 | + $object = $songsHandler->create(); |
|
307 | + } |
|
308 | + if ($object->getVar('cid') > 0 && $cid > 0) { |
|
309 | + $object->setVar('cid', $cid); |
|
310 | + } else { |
|
311 | + $object->setVar('cid', $cid); |
|
312 | + } |
|
313 | + if ($object->getVar('gid') > 0 && $gid > 0) { |
|
314 | + $object->setVar('gid', $gid); |
|
315 | + } else { |
|
316 | + $object->setVar('gid', $gid); |
|
317 | + } |
|
318 | + if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
319 | + $object->setVar('aids', $aids); |
|
320 | + } else { |
|
321 | + $object->setVar('aids', $aids); |
|
322 | + } |
|
323 | + if ($object->getVar('abid') > 0 && $abid > 0) { |
|
324 | + $object->setVar('abid', $abid); |
|
325 | + } else { |
|
326 | + $object->setVar('abid', $abid); |
|
327 | + } |
|
328 | + $object->setVar('songid', $data[$_POST['songid']]); |
|
329 | + $object->setVar('title', $data[$_POST['title']]); |
|
330 | + $object->setVar('lyrics', str_replace("\n", "<br>\n", $data[$_POST['lyrics']])); |
|
331 | + $sid = $songsHandler->insert($object); |
|
332 | + } |
|
333 | + } |
|
334 | + } |
|
335 | + unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
336 | + unset($_SESSION['xmlfile']); |
|
337 | + redirect_header($_SERVER['SCRIPT_NAME'] . '&op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
338 | + break; |
|
339 | + } |
|
340 | + break; |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | xoops_cp_footer(); |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use XoopsModules\Songlist\AlbumsHandler; |
8 | 8 | use XoopsModules\Songlist\Form\FormController; |
9 | 9 | |
10 | -require __DIR__ . '/header.php'; |
|
10 | +require __DIR__.'/header.php'; |
|
11 | 11 | |
12 | 12 | xoops_loadLanguage('admin', 'songlist'); |
13 | 13 | |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
19 | 19 | $start = Request::getInt('start', 0, 'REQUEST'); |
20 | 20 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
21 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
22 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
21 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
22 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
23 | 23 | |
24 | 24 | $albumsHandler = Helper::getInstance()->getHandler('Albums'); |
25 | 25 | $songsHandler = Helper::getInstance()->getHandler('Songs'); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | default: |
35 | 35 | case 'actiona': |
36 | 36 | if (Request::hasVar('xmlfile', 'SESSION')) { |
37 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
37 | + redirect_header($_SERVER['SCRIPT_NAME'].'?file='.$_SESSION['xmlfile'].'&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
38 | 38 | } |
39 | 39 | $adminObject = Admin::getInstance(); |
40 | 40 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -61,27 +61,27 @@ discard block |
||
61 | 61 | $uploader = new Uploader( |
62 | 62 | $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
63 | 63 | ['application/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
64 | - 1024 * 1024 * 32, |
|
64 | + 1024*1024*32, |
|
65 | 65 | 0, |
66 | 66 | 0, |
67 | 67 | ['xml'] |
68 | 68 | ); |
69 | 69 | try { |
70 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
70 | + $uploader->setPrefix(mb_substr(md5((string) microtime(true)), random_int(0, 20), 13)); |
|
71 | 71 | } catch (Exception $e) { |
72 | 72 | } |
73 | 73 | |
74 | 74 | if ($uploader->fetchMedia('xmlfile')) { |
75 | 75 | if (!$uploader->upload()) { |
76 | 76 | echo $uploader->getErrors(); |
77 | - require __DIR__ . '/admin_footer.php'; |
|
77 | + require __DIR__.'/admin_footer.php'; |
|
78 | 78 | exit(0); |
79 | 79 | } |
80 | 80 | $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
81 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
81 | + redirect_header($_SERVER['SCRIPT_NAME'].'?file='.$uploader->getSavedFileName().'&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
82 | 82 | } else { |
83 | 83 | echo $uploader->getErrors(); |
84 | - require __DIR__ . '/admin_footer.php'; |
|
84 | + require __DIR__.'/admin_footer.php'; |
|
85 | 85 | exit(0); |
86 | 86 | } |
87 | 87 | } |
@@ -96,22 +96,22 @@ discard block |
||
96 | 96 | break; |
97 | 97 | case 'import': |
98 | 98 | |
99 | - $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
100 | - $mb = floor($filesize / 1024 / 1024); |
|
101 | - if ($mb > 32) { |
|
102 | - ini_set('memory_limit', ($mb + 128) . 'M'); |
|
99 | + $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])); |
|
100 | + $mb = floor($filesize/1024/1024); |
|
101 | + if ($mb>32) { |
|
102 | + ini_set('memory_limit', ($mb+128).'M'); |
|
103 | 103 | } |
104 | 104 | set_time_limit(3600); |
105 | 105 | |
106 | - $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
106 | + $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])), false, 'tag'); |
|
107 | 107 | |
108 | - if (mb_strlen($_POST['collection']) > 0) { |
|
108 | + if (mb_strlen($_POST['collection'])>0) { |
|
109 | 109 | foreach ($xmlarray[$_POST['collection']] as $id => $record) { |
110 | 110 | foreach ($record as $recid => $data) { |
111 | 111 | $gid = 0; |
112 | - if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
112 | + if (mb_strlen($_POST['genre'])>0 && !empty($data[$_POST['genre']])) { |
|
113 | 113 | $criteria = new \Criteria('name', $data[$_POST['genre']]); |
114 | - if ($genreHandler->getCount($criteria) > 0) { |
|
114 | + if ($genreHandler->getCount($criteria)>0) { |
|
115 | 115 | $objects = $genreHandler->getObjects($criteria, false); |
116 | 116 | $gid = $objects[0]->getVar('gid'); |
117 | 117 | } else { |
@@ -122,9 +122,9 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | $vid = 0; |
125 | - if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
125 | + if (mb_strlen($_POST['voice'])>0 && !empty($data[$_POST['voice']])) { |
|
126 | 126 | $criteria = new \Criteria('name', $data[$_POST['voice']]); |
127 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
127 | + if ($voiceHandler->getCount($criteria)>0) { |
|
128 | 128 | $objects = $voiceHandler->getObjects($criteria, false); |
129 | 129 | $gid = $objects[0]->getVar('vid'); |
130 | 130 | } else { |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | } |
136 | 136 | |
137 | 137 | $cid = 0; |
138 | - if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
138 | + if (mb_strlen($_POST['category'])>0 && !empty($data[$_POST['category']])) { |
|
139 | 139 | $criteria = new \Criteria('name', $data[$_POST['category']]); |
140 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
140 | + if ($categoryHandler->getCount($criteria)>0) { |
|
141 | 141 | $objects = $categoryHandler->getObjects($criteria, false); |
142 | 142 | $cid = $objects[0]->getVar('cid'); |
143 | 143 | } else { |
@@ -147,10 +147,10 @@ discard block |
||
147 | 147 | } |
148 | 148 | } |
149 | 149 | $aids = []; |
150 | - if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
150 | + if (mb_strlen($_POST['artist'])>0 && !empty($data[$_POST['artist']])) { |
|
151 | 151 | foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
152 | 152 | $criteria = new \Criteria('name', $artist); |
153 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
153 | + if ($artistsHandler->getCount($criteria)>0) { |
|
154 | 154 | $objects = $artistsHandler->getObjects($criteria, false); |
155 | 155 | $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
156 | 156 | } else { |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | } |
172 | 172 | } |
173 | 173 | $abid = 0; |
174 | - if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
174 | + if (mb_strlen($_POST['album'])>0 && !empty($data[$_POST['album']])) { |
|
175 | 175 | $criteria = new \Criteria('name', $data[$_POST['album']]); |
176 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
176 | + if ($albumsHandler->getCount($criteria)>0) { |
|
177 | 177 | $objects = $albumsHandler->getObjects($criteria, false); |
178 | 178 | $abid = $objects[0]->getVar('aid'); |
179 | 179 | } else { |
@@ -185,30 +185,30 @@ discard block |
||
185 | 185 | } |
186 | 186 | } |
187 | 187 | $sid = 0; |
188 | - if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
188 | + if (mb_strlen($_POST['songid'])>0 && !empty($data[$_POST['songid']])) { |
|
189 | 189 | $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
190 | - if ($songsHandler->getCount($criteria) > 0) { |
|
190 | + if ($songsHandler->getCount($criteria)>0) { |
|
191 | 191 | $objects = $songsHandler->getObjects($criteria, false); |
192 | 192 | $object = $objects[0]->getVar('sid'); |
193 | 193 | } else { |
194 | 194 | $object = $songsHandler->create(); |
195 | 195 | } |
196 | - if ($object->getVar('cid') > 0 && $cid > 0) { |
|
196 | + if ($object->getVar('cid')>0 && $cid>0) { |
|
197 | 197 | $object->setVar('cid', $cid); |
198 | 198 | } else { |
199 | 199 | $object->setVar('cid', $cid); |
200 | 200 | } |
201 | - if ($object->getVar('gid') > 0 && $gid > 0) { |
|
201 | + if ($object->getVar('gid')>0 && $gid>0) { |
|
202 | 202 | $object->setVar('gid', $gid); |
203 | 203 | } else { |
204 | 204 | $object->setVar('gid', $gid); |
205 | 205 | } |
206 | - if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
206 | + if (count($object->getVar('aids'))>0 && count($aids)>0) { |
|
207 | 207 | $object->setVar('aids', $aids); |
208 | 208 | } else { |
209 | 209 | $object->setVar('aids', $aids); |
210 | 210 | } |
211 | - if ($object->getVar('abid') > 0 && $abid > 0) { |
|
211 | + if ($object->getVar('abid')>0 && $abid>0) { |
|
212 | 212 | $object->setVar('abid', $abid); |
213 | 213 | } else { |
214 | 214 | $object->setVar('abid', $abid); |
@@ -223,9 +223,9 @@ discard block |
||
223 | 223 | } else { |
224 | 224 | foreach ($xmlarray as $recid => $data) { |
225 | 225 | $gid = 0; |
226 | - if (mb_strlen($_POST['genre']) > 0 && !empty($data[$_POST['genre']])) { |
|
226 | + if (mb_strlen($_POST['genre'])>0 && !empty($data[$_POST['genre']])) { |
|
227 | 227 | $criteria = new \Criteria('name', $data[$_POST['genre']]); |
228 | - if ($genreHandler->getCount($criteria) > 0) { |
|
228 | + if ($genreHandler->getCount($criteria)>0) { |
|
229 | 229 | $objects = $genreHandler->getObjects($criteria, false); |
230 | 230 | $gid = $objects[0]->getVar('gid'); |
231 | 231 | } else { |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | } |
236 | 236 | } |
237 | 237 | $vid = 0; |
238 | - if (mb_strlen($_POST['voice']) > 0 && !empty($data[$_POST['voice']])) { |
|
238 | + if (mb_strlen($_POST['voice'])>0 && !empty($data[$_POST['voice']])) { |
|
239 | 239 | $criteria = new \Criteria('name', $data[$_POST['voice']]); |
240 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
240 | + if ($voiceHandler->getCount($criteria)>0) { |
|
241 | 241 | $objects = $voiceHandler->getObjects($criteria, false); |
242 | 242 | $gid = $objects[0]->getVar('vid'); |
243 | 243 | } else { |
@@ -247,9 +247,9 @@ discard block |
||
247 | 247 | } |
248 | 248 | } |
249 | 249 | $cid = 0; |
250 | - if (mb_strlen($_POST['category']) > 0 && !empty($data[$_POST['category']])) { |
|
250 | + if (mb_strlen($_POST['category'])>0 && !empty($data[$_POST['category']])) { |
|
251 | 251 | $criteria = new \Criteria('name', $data[$_POST['category']]); |
252 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
252 | + if ($categoryHandler->getCount($criteria)>0) { |
|
253 | 253 | $objects = $categoryHandler->getObjects($criteria, false); |
254 | 254 | $cid = $objects[0]->getVar('cid'); |
255 | 255 | } else { |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | } |
260 | 260 | } |
261 | 261 | $aids = []; |
262 | - if (mb_strlen($_POST['artist']) > 0 && !empty($data[$_POST['artist']])) { |
|
262 | + if (mb_strlen($_POST['artist'])>0 && !empty($data[$_POST['artist']])) { |
|
263 | 263 | foreach (explode(',', $data[$_POST['artist']]) as $artist) { |
264 | 264 | $criteria = new \Criteria('name', $artist); |
265 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
265 | + if ($artistsHandler->getCount($criteria)>0) { |
|
266 | 266 | $objects = $artistsHandler->getObjects($criteria, false); |
267 | 267 | $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
268 | 268 | } else { |
@@ -283,9 +283,9 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | $abid = 0; |
286 | - if (mb_strlen($_POST['album']) > 0 && !empty($data[$_POST['album']])) { |
|
286 | + if (mb_strlen($_POST['album'])>0 && !empty($data[$_POST['album']])) { |
|
287 | 287 | $criteria = new \Criteria('name', $data[$_POST['album']]); |
288 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
288 | + if ($albumsHandler->getCount($criteria)>0) { |
|
289 | 289 | $objects = $albumsHandler->getObjects($criteria, false); |
290 | 290 | $abid = $objects[0]->getVar('aid'); |
291 | 291 | } else { |
@@ -297,30 +297,30 @@ discard block |
||
297 | 297 | } |
298 | 298 | } |
299 | 299 | $sid = 0; |
300 | - if (mb_strlen($_POST['songid']) > 0 && !empty($data[$_POST['songid']])) { |
|
300 | + if (mb_strlen($_POST['songid'])>0 && !empty($data[$_POST['songid']])) { |
|
301 | 301 | $criteria = new \Criteria('songid', $data[$_POST['songid']]); |
302 | - if ($songsHandler->getCount($criteria) > 0) { |
|
302 | + if ($songsHandler->getCount($criteria)>0) { |
|
303 | 303 | $objects = $songsHandler->getObjects($criteria, false); |
304 | 304 | $object = $objects[0]->getVar('sid'); |
305 | 305 | } else { |
306 | 306 | $object = $songsHandler->create(); |
307 | 307 | } |
308 | - if ($object->getVar('cid') > 0 && $cid > 0) { |
|
308 | + if ($object->getVar('cid')>0 && $cid>0) { |
|
309 | 309 | $object->setVar('cid', $cid); |
310 | 310 | } else { |
311 | 311 | $object->setVar('cid', $cid); |
312 | 312 | } |
313 | - if ($object->getVar('gid') > 0 && $gid > 0) { |
|
313 | + if ($object->getVar('gid')>0 && $gid>0) { |
|
314 | 314 | $object->setVar('gid', $gid); |
315 | 315 | } else { |
316 | 316 | $object->setVar('gid', $gid); |
317 | 317 | } |
318 | - if (count($object->getVar('aids')) > 0 && count($aids) > 0) { |
|
318 | + if (count($object->getVar('aids'))>0 && count($aids)>0) { |
|
319 | 319 | $object->setVar('aids', $aids); |
320 | 320 | } else { |
321 | 321 | $object->setVar('aids', $aids); |
322 | 322 | } |
323 | - if ($object->getVar('abid') > 0 && $abid > 0) { |
|
323 | + if ($object->getVar('abid')>0 && $abid>0) { |
|
324 | 324 | $object->setVar('abid', $abid); |
325 | 325 | } else { |
326 | 326 | $object->setVar('abid', $abid); |
@@ -332,9 +332,9 @@ discard block |
||
332 | 332 | } |
333 | 333 | } |
334 | 334 | } |
335 | - unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
335 | + unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])); |
|
336 | 336 | unset($_SESSION['xmlfile']); |
337 | - redirect_header($_SERVER['SCRIPT_NAME'] . '&op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
337 | + redirect_header($_SERVER['SCRIPT_NAME'].'&op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
338 | 338 | break; |
339 | 339 | } |
340 | 340 | break; |
@@ -3,11 +3,11 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Form\FormController, |
|
7 | - Helper, |
|
8 | - Category, |
|
9 | - CategoryHandler, |
|
10 | - Uploader |
|
6 | + Form\FormController, |
|
7 | + Helper, |
|
8 | + Category, |
|
9 | + CategoryHandler, |
|
10 | + Uploader |
|
11 | 11 | }; |
12 | 12 | |
13 | 13 | /** @var Category $category */ |
@@ -27,102 +27,102 @@ discard block |
||
27 | 27 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
28 | 28 | |
29 | 29 | switch ($op) { |
30 | - default: |
|
31 | - case 'category': |
|
32 | - switch ($fct) { |
|
33 | - default: |
|
34 | - case 'list': |
|
35 | - $adminObject = Admin::getInstance(); |
|
36 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
37 | - |
|
38 | - /** @var CategoryHandler $categoryHandler */ |
|
39 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
40 | - |
|
41 | - $criteria = $categoryHandler->getFilterCriteria($GLOBALS['filter']); |
|
42 | - $ttl = $categoryHandler->getCount($criteria); |
|
43 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
44 | - |
|
45 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
46 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
47 | - |
|
48 | - foreach ($categoryHandler->filterFields() as $id => $key) { |
|
49 | - $GLOBALS['xoopsTpl']->assign( |
|
50 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
51 | - '<a href="' |
|
52 | - . $_SERVER['SCRIPT_NAME'] |
|
53 | - . '?start=' |
|
54 | - . $GLOBALS['start'] |
|
55 | - . '&limit=' |
|
56 | - . $GLOBALS['limit'] |
|
57 | - . '&sort=' |
|
58 | - . $key |
|
59 | - . '&order=' |
|
60 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | - . '&op=' |
|
62 | - . $GLOBALS['op'] |
|
63 | - . '&filter=' |
|
64 | - . $GLOBALS['filter'] |
|
65 | - . '">' |
|
66 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | - . '</a>' |
|
68 | - ); |
|
69 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $categoryHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | - } |
|
71 | - |
|
72 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
77 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
78 | - |
|
79 | - $criteria->setStart($GLOBALS['start']); |
|
80 | - $criteria->setLimit($GLOBALS['limit']); |
|
81 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
82 | - $criteria->setOrder($GLOBALS['order']); |
|
83 | - |
|
84 | - $categorys = $categoryHandler->getObjects($criteria, true); |
|
85 | - foreach ($categorys as $cid => $category) { |
|
86 | - if (is_object($category)) { |
|
87 | - $GLOBALS['xoopsTpl']->append('categories', $category->toArray()); |
|
88 | - } |
|
89 | - } |
|
90 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormCategory(false)); |
|
91 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
92 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_category_list.tpl'); |
|
93 | - break; |
|
94 | - case 'new': |
|
95 | - case 'edit': |
|
96 | - $adminObject = Admin::getInstance(); |
|
97 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
98 | - |
|
99 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
100 | - if (Request::hasVar('id', 'REQUEST')) { |
|
101 | - $category = $categoryHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
102 | - } else { |
|
103 | - $category = $categoryHandler->create(); |
|
104 | - } |
|
105 | - |
|
106 | - $GLOBALS['xoopsTpl']->assign('form', $category->getForm()); |
|
107 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
108 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_category_edit.tpl'); |
|
109 | - break; |
|
110 | - case 'save': |
|
111 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
112 | - $id = 0; |
|
113 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
114 | - if ($id) { |
|
115 | - $category = $categoryHandler->get($id); |
|
116 | - } else { |
|
117 | - $category = $categoryHandler->create(); |
|
118 | - } |
|
119 | - $category->setVars($_POST[$id]); |
|
120 | - |
|
121 | - if (!$id = $categoryHandler->insert($category)) { |
|
122 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE); |
|
123 | - exit(0); |
|
124 | - } |
|
125 | - if (Request::hasVar('image', 'FILES') && !empty($_FILES['image']['name'])) { |
|
30 | + default: |
|
31 | + case 'category': |
|
32 | + switch ($fct) { |
|
33 | + default: |
|
34 | + case 'list': |
|
35 | + $adminObject = Admin::getInstance(); |
|
36 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
37 | + |
|
38 | + /** @var CategoryHandler $categoryHandler */ |
|
39 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
40 | + |
|
41 | + $criteria = $categoryHandler->getFilterCriteria($GLOBALS['filter']); |
|
42 | + $ttl = $categoryHandler->getCount($criteria); |
|
43 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
44 | + |
|
45 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
46 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
47 | + |
|
48 | + foreach ($categoryHandler->filterFields() as $id => $key) { |
|
49 | + $GLOBALS['xoopsTpl']->assign( |
|
50 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
51 | + '<a href="' |
|
52 | + . $_SERVER['SCRIPT_NAME'] |
|
53 | + . '?start=' |
|
54 | + . $GLOBALS['start'] |
|
55 | + . '&limit=' |
|
56 | + . $GLOBALS['limit'] |
|
57 | + . '&sort=' |
|
58 | + . $key |
|
59 | + . '&order=' |
|
60 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | + . '&op=' |
|
62 | + . $GLOBALS['op'] |
|
63 | + . '&filter=' |
|
64 | + . $GLOBALS['filter'] |
|
65 | + . '">' |
|
66 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | + . '</a>' |
|
68 | + ); |
|
69 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $categoryHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | + } |
|
71 | + |
|
72 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
77 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
78 | + |
|
79 | + $criteria->setStart($GLOBALS['start']); |
|
80 | + $criteria->setLimit($GLOBALS['limit']); |
|
81 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
82 | + $criteria->setOrder($GLOBALS['order']); |
|
83 | + |
|
84 | + $categorys = $categoryHandler->getObjects($criteria, true); |
|
85 | + foreach ($categorys as $cid => $category) { |
|
86 | + if (is_object($category)) { |
|
87 | + $GLOBALS['xoopsTpl']->append('categories', $category->toArray()); |
|
88 | + } |
|
89 | + } |
|
90 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormCategory(false)); |
|
91 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
92 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_category_list.tpl'); |
|
93 | + break; |
|
94 | + case 'new': |
|
95 | + case 'edit': |
|
96 | + $adminObject = Admin::getInstance(); |
|
97 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
98 | + |
|
99 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
100 | + if (Request::hasVar('id', 'REQUEST')) { |
|
101 | + $category = $categoryHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
102 | + } else { |
|
103 | + $category = $categoryHandler->create(); |
|
104 | + } |
|
105 | + |
|
106 | + $GLOBALS['xoopsTpl']->assign('form', $category->getForm()); |
|
107 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
108 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_category_edit.tpl'); |
|
109 | + break; |
|
110 | + case 'save': |
|
111 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
112 | + $id = 0; |
|
113 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
114 | + if ($id) { |
|
115 | + $category = $categoryHandler->get($id); |
|
116 | + } else { |
|
117 | + $category = $categoryHandler->create(); |
|
118 | + } |
|
119 | + $category->setVars($_POST[$id]); |
|
120 | + |
|
121 | + if (!$id = $categoryHandler->insert($category)) { |
|
122 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE); |
|
123 | + exit(0); |
|
124 | + } |
|
125 | + if (Request::hasVar('image', 'FILES') && !empty($_FILES['image']['name'])) { |
|
126 | 126 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
127 | 127 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
128 | 128 | // foreach (explode('/', $folders) as $folder) { |
@@ -135,99 +135,99 @@ discard block |
||
135 | 135 | // } |
136 | 136 | |
137 | 137 | // require_once $GLOBALS['xoops']->path('modules/songlist/include/uploader.php'); |
138 | - $category = $categoryHandler->get($id); |
|
139 | - $uploader = new Uploader( |
|
140 | - $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
141 | - explode('|', $GLOBALS['songlistModuleConfig']['allowed_mimetype']), |
|
142 | - $GLOBALS['songlistModuleConfig']['filesize_upload'], |
|
143 | - 0, |
|
144 | - 0, |
|
145 | - explode('|', $GLOBALS['songlistModuleConfig']['allowed_extensions']) |
|
146 | - ); |
|
147 | - try { |
|
148 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
149 | - } catch (Exception $e) { |
|
150 | - } |
|
151 | - |
|
152 | - if ($uploader->fetchMedia('image')) { |
|
153 | - if (!$uploader->upload()) { |
|
154 | - $adminObject = Admin::getInstance(); |
|
155 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
156 | - echo $uploader->getErrors(); |
|
157 | - require __DIR__ . '/admin_footer.php'; |
|
158 | - exit(0); |
|
159 | - } |
|
160 | - if (mb_strlen($category->getVar('image'))) { |
|
161 | - unlink($GLOBALS['xoops']->path($category->getVar('path')) . $category->getVar('image')); |
|
162 | - } |
|
163 | - |
|
164 | - $category->setVar('path', $GLOBALS['songlistModuleConfig']['upload_areas']); |
|
165 | - $category->setVar('image', $uploader->getSavedFileName()); |
|
166 | - @$categoryHandler->insert($category); |
|
167 | - } else { |
|
168 | - $adminObject = Admin::getInstance(); |
|
169 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
170 | - echo $uploader->getErrors(); |
|
171 | - require __DIR__ . '/admin_footer.php'; |
|
172 | - exit(0); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
177 | - redirect_header( |
|
178 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
179 | - 10, |
|
180 | - _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY |
|
181 | - ); |
|
182 | - } else { |
|
183 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
184 | - } |
|
185 | - exit(0); |
|
186 | - |
|
187 | - break; |
|
188 | - case 'savelist': |
|
189 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
190 | - foreach ($_REQUEST['id'] as $id) { |
|
191 | - $category = $categoryHandler->get($id); |
|
192 | - $category->setVars($_POST[$id]); |
|
193 | - if (!$categoryHandler->insert($category)) { |
|
194 | - redirect_header( |
|
195 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
196 | - 10, |
|
197 | - _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE |
|
198 | - ); |
|
199 | - exit(0); |
|
200 | - } |
|
201 | - } |
|
202 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
203 | - exit(0); |
|
204 | - break; |
|
205 | - case 'delete': |
|
206 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
207 | - $id = 0; |
|
208 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
209 | - $category = $categoryHandler->get($id); |
|
210 | - if (!$categoryHandler->delete($category)) { |
|
211 | - redirect_header( |
|
212 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
213 | - 10, |
|
214 | - _AM_SONGLIST_MSG_CATEGORY_FAILEDTODELETE |
|
215 | - ); |
|
216 | - exit(0); |
|
217 | - } |
|
218 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_DELETED); |
|
219 | - exit(0); |
|
220 | - } |
|
221 | - $category = $categoryHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
222 | - xoops_confirm( |
|
223 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
224 | - $_SERVER['SCRIPT_NAME'], |
|
225 | - sprintf(_AM_SONGLIST_MSG_CATEGORY_DELETE, $category->getVar('name')) |
|
226 | - ); |
|
227 | - |
|
228 | - break; |
|
229 | - } |
|
230 | - break; |
|
138 | + $category = $categoryHandler->get($id); |
|
139 | + $uploader = new Uploader( |
|
140 | + $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
141 | + explode('|', $GLOBALS['songlistModuleConfig']['allowed_mimetype']), |
|
142 | + $GLOBALS['songlistModuleConfig']['filesize_upload'], |
|
143 | + 0, |
|
144 | + 0, |
|
145 | + explode('|', $GLOBALS['songlistModuleConfig']['allowed_extensions']) |
|
146 | + ); |
|
147 | + try { |
|
148 | + $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
149 | + } catch (Exception $e) { |
|
150 | + } |
|
151 | + |
|
152 | + if ($uploader->fetchMedia('image')) { |
|
153 | + if (!$uploader->upload()) { |
|
154 | + $adminObject = Admin::getInstance(); |
|
155 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
156 | + echo $uploader->getErrors(); |
|
157 | + require __DIR__ . '/admin_footer.php'; |
|
158 | + exit(0); |
|
159 | + } |
|
160 | + if (mb_strlen($category->getVar('image'))) { |
|
161 | + unlink($GLOBALS['xoops']->path($category->getVar('path')) . $category->getVar('image')); |
|
162 | + } |
|
163 | + |
|
164 | + $category->setVar('path', $GLOBALS['songlistModuleConfig']['upload_areas']); |
|
165 | + $category->setVar('image', $uploader->getSavedFileName()); |
|
166 | + @$categoryHandler->insert($category); |
|
167 | + } else { |
|
168 | + $adminObject = Admin::getInstance(); |
|
169 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
170 | + echo $uploader->getErrors(); |
|
171 | + require __DIR__ . '/admin_footer.php'; |
|
172 | + exit(0); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
177 | + redirect_header( |
|
178 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
179 | + 10, |
|
180 | + _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY |
|
181 | + ); |
|
182 | + } else { |
|
183 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
184 | + } |
|
185 | + exit(0); |
|
186 | + |
|
187 | + break; |
|
188 | + case 'savelist': |
|
189 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
190 | + foreach ($_REQUEST['id'] as $id) { |
|
191 | + $category = $categoryHandler->get($id); |
|
192 | + $category->setVars($_POST[$id]); |
|
193 | + if (!$categoryHandler->insert($category)) { |
|
194 | + redirect_header( |
|
195 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
196 | + 10, |
|
197 | + _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE |
|
198 | + ); |
|
199 | + exit(0); |
|
200 | + } |
|
201 | + } |
|
202 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
203 | + exit(0); |
|
204 | + break; |
|
205 | + case 'delete': |
|
206 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
207 | + $id = 0; |
|
208 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
209 | + $category = $categoryHandler->get($id); |
|
210 | + if (!$categoryHandler->delete($category)) { |
|
211 | + redirect_header( |
|
212 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
213 | + 10, |
|
214 | + _AM_SONGLIST_MSG_CATEGORY_FAILEDTODELETE |
|
215 | + ); |
|
216 | + exit(0); |
|
217 | + } |
|
218 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_DELETED); |
|
219 | + exit(0); |
|
220 | + } |
|
221 | + $category = $categoryHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
222 | + xoops_confirm( |
|
223 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
224 | + $_SERVER['SCRIPT_NAME'], |
|
225 | + sprintf(_AM_SONGLIST_MSG_CATEGORY_DELETE, $category->getVar('name')) |
|
226 | + ); |
|
227 | + |
|
228 | + break; |
|
229 | + } |
|
230 | + break; |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | xoops_cp_footer(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | |
13 | 13 | /** @var Category $category */ |
14 | 14 | |
15 | -require __DIR__ . '/header.php'; |
|
15 | +require __DIR__.'/header.php'; |
|
16 | 16 | |
17 | 17 | xoops_loadLanguage('admin', 'songlist'); |
18 | 18 | |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
24 | 24 | $start = Request::getInt('start', 0, 'REQUEST'); |
25 | 25 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
26 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
27 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
26 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
27 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
28 | 28 | |
29 | 29 | switch ($op) { |
30 | 30 | default: |
@@ -40,14 +40,14 @@ discard block |
||
40 | 40 | |
41 | 41 | $criteria = $categoryHandler->getFilterCriteria($GLOBALS['filter']); |
42 | 42 | $ttl = $categoryHandler->getCount($criteria); |
43 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
44 | 44 | |
45 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
46 | 46 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
47 | 47 | |
48 | 48 | foreach ($categoryHandler->filterFields() as $id => $key) { |
49 | 49 | $GLOBALS['xoopsTpl']->assign( |
50 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
51 | 51 | '<a href="' |
52 | 52 | . $_SERVER['SCRIPT_NAME'] |
53 | 53 | . '?start=' |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | . '&sort=' |
58 | 58 | . $key |
59 | 59 | . '&order=' |
60 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
61 | 61 | . '&op=' |
62 | 62 | . $GLOBALS['op'] |
63 | 63 | . '&filter=' |
64 | 64 | . $GLOBALS['filter'] |
65 | 65 | . '">' |
66 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
67 | 67 | . '</a>' |
68 | 68 | ); |
69 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $categoryHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $categoryHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $criteria->setStart($GLOBALS['start']); |
80 | 80 | $criteria->setLimit($GLOBALS['limit']); |
81 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
82 | 82 | $criteria->setOrder($GLOBALS['order']); |
83 | 83 | |
84 | 84 | $categorys = $categoryHandler->getObjects($criteria, true); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | $category->setVars($_POST[$id]); |
120 | 120 | |
121 | 121 | if (!$id = $categoryHandler->insert($category)) { |
122 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE); |
|
122 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE); |
|
123 | 123 | exit(0); |
124 | 124 | } |
125 | 125 | if (Request::hasVar('image', 'FILES') && !empty($_FILES['image']['name'])) { |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | explode('|', $GLOBALS['songlistModuleConfig']['allowed_extensions']) |
146 | 146 | ); |
147 | 147 | try { |
148 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
148 | + $uploader->setPrefix(mb_substr(md5((string) microtime(true)), random_int(0, 20), 13)); |
|
149 | 149 | } catch (Exception $e) { |
150 | 150 | } |
151 | 151 | |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | $adminObject = Admin::getInstance(); |
155 | 155 | $adminObject->displayNavigation(basename(__FILE__)); |
156 | 156 | echo $uploader->getErrors(); |
157 | - require __DIR__ . '/admin_footer.php'; |
|
157 | + require __DIR__.'/admin_footer.php'; |
|
158 | 158 | exit(0); |
159 | 159 | } |
160 | 160 | if (mb_strlen($category->getVar('image'))) { |
161 | - unlink($GLOBALS['xoops']->path($category->getVar('path')) . $category->getVar('image')); |
|
161 | + unlink($GLOBALS['xoops']->path($category->getVar('path')).$category->getVar('image')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | $category->setVar('path', $GLOBALS['songlistModuleConfig']['upload_areas']); |
@@ -168,19 +168,19 @@ discard block |
||
168 | 168 | $adminObject = Admin::getInstance(); |
169 | 169 | $adminObject->displayNavigation(basename(__FILE__)); |
170 | 170 | echo $uploader->getErrors(); |
171 | - require __DIR__ . '/admin_footer.php'; |
|
171 | + require __DIR__.'/admin_footer.php'; |
|
172 | 172 | exit(0); |
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
176 | + if ('new'===$_REQUEST['state'][$_REQUEST['id']]) { |
|
177 | 177 | redirect_header( |
178 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
178 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
179 | 179 | 10, |
180 | 180 | _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY |
181 | 181 | ); |
182 | 182 | } else { |
183 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
183 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
184 | 184 | } |
185 | 185 | exit(0); |
186 | 186 | |
@@ -192,14 +192,14 @@ discard block |
||
192 | 192 | $category->setVars($_POST[$id]); |
193 | 193 | if (!$categoryHandler->insert($category)) { |
194 | 194 | redirect_header( |
195 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
195 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
196 | 196 | 10, |
197 | 197 | _AM_SONGLIST_MSG_CATEGORY_FAILEDTOSAVE |
198 | 198 | ); |
199 | 199 | exit(0); |
200 | 200 | } |
201 | 201 | } |
202 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
202 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_SAVEDOKEY); |
|
203 | 203 | exit(0); |
204 | 204 | break; |
205 | 205 | case 'delete': |
@@ -209,13 +209,13 @@ discard block |
||
209 | 209 | $category = $categoryHandler->get($id); |
210 | 210 | if (!$categoryHandler->delete($category)) { |
211 | 211 | redirect_header( |
212 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
212 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
213 | 213 | 10, |
214 | 214 | _AM_SONGLIST_MSG_CATEGORY_FAILEDTODELETE |
215 | 215 | ); |
216 | 216 | exit(0); |
217 | 217 | } |
218 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_DELETED); |
|
218 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_CATEGORY_DELETED); |
|
219 | 219 | exit(0); |
220 | 220 | } |
221 | 221 | $category = $categoryHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -3,10 +3,10 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Form\FormController, |
|
7 | - Helper, |
|
8 | - Voice, |
|
9 | - VoiceHandler, |
|
6 | + Form\FormController, |
|
7 | + Helper, |
|
8 | + Voice, |
|
9 | + VoiceHandler, |
|
10 | 10 | }; |
11 | 11 | |
12 | 12 | /** @var Voice $voice */ |
@@ -26,156 +26,156 @@ discard block |
||
26 | 26 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
27 | 27 | |
28 | 28 | switch ($op) { |
29 | - default: |
|
30 | - case 'voice': |
|
31 | - switch ($fct) { |
|
32 | - default: |
|
33 | - case 'list': |
|
34 | - $adminObject = Admin::getInstance(); |
|
35 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | - |
|
37 | - /** @var VoiceHandler $voiceHandler */ |
|
38 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
39 | - |
|
40 | - $criteria = $voiceHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | - $ttl = $voiceHandler->getCount($criteria); |
|
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | - |
|
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | - |
|
47 | - foreach ($voiceHandler->filterFields() as $id => $key) { |
|
48 | - $GLOBALS['xoopsTpl']->assign( |
|
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | - '<a href="' |
|
51 | - . $_SERVER['SCRIPT_NAME'] |
|
52 | - . '?start=' |
|
53 | - . $GLOBALS['start'] |
|
54 | - . '&limit=' |
|
55 | - . $GLOBALS['limit'] |
|
56 | - . '&sort=' |
|
57 | - . $key |
|
58 | - . '&order=' |
|
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | - . '&op=' |
|
61 | - . $GLOBALS['op'] |
|
62 | - . '&filter=' |
|
63 | - . $GLOBALS['filter'] |
|
64 | - . '">' |
|
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | - . '</a>' |
|
67 | - ); |
|
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $voiceHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | - } |
|
70 | - |
|
71 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | - |
|
78 | - $criteria->setStart($GLOBALS['start']); |
|
79 | - $criteria->setLimit($GLOBALS['limit']); |
|
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | - $criteria->setOrder($GLOBALS['order']); |
|
82 | - |
|
83 | - $voices = $voiceHandler->getObjects($criteria, true); |
|
84 | - foreach ($voices as $cid => $voice) { |
|
85 | - if (is_object($voice)) { |
|
86 | - $GLOBALS['xoopsTpl']->append('voice', $voice->toArray()); |
|
87 | - } |
|
88 | - } |
|
89 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormVoice(false)); |
|
90 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_voice_list.tpl'); |
|
92 | - break; |
|
93 | - case 'new': |
|
94 | - case 'edit': |
|
95 | - $adminObject = Admin::getInstance(); |
|
96 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | - |
|
98 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
99 | - if (Request::hasVar('id', 'REQUEST')) { |
|
100 | - $voice = $voiceHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | - } else { |
|
102 | - $voice = $voiceHandler->create(); |
|
103 | - } |
|
104 | - |
|
105 | - $GLOBALS['xoopsTpl']->assign('form', $voice->getForm()); |
|
106 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_voice_edit.tpl'); |
|
108 | - break; |
|
109 | - case 'save': |
|
110 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
111 | - $id = 0; |
|
112 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | - if ($id) { |
|
114 | - $voice = $voiceHandler->get($id); |
|
115 | - } else { |
|
116 | - $voice = $voiceHandler->create(); |
|
117 | - } |
|
118 | - $voice->setVars($_POST[$id]); |
|
119 | - |
|
120 | - if (!$id = $voiceHandler->insert($voice)) { |
|
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE); |
|
122 | - exit(0); |
|
123 | - } |
|
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | - redirect_header( |
|
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | - 10, |
|
128 | - _AM_SONGLIST_MSG_VOICE_SAVEDOKEY |
|
129 | - ); |
|
130 | - } else { |
|
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
132 | - } |
|
133 | - exit(0); |
|
134 | - |
|
135 | - break; |
|
136 | - case 'savelist': |
|
137 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
138 | - foreach ($_REQUEST['id'] as $id) { |
|
139 | - $voice = $voiceHandler->get($id); |
|
140 | - $voice->setVars($_POST[$id]); |
|
141 | - if (!$voiceHandler->insert($voice)) { |
|
142 | - redirect_header( |
|
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | - 10, |
|
145 | - _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE |
|
146 | - ); |
|
147 | - exit(0); |
|
148 | - } |
|
149 | - } |
|
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
151 | - exit(0); |
|
152 | - break; |
|
153 | - case 'delete': |
|
154 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
155 | - $id = 0; |
|
156 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | - $voice = $voiceHandler->get($id); |
|
158 | - if (!$voiceHandler->delete($voice)) { |
|
159 | - redirect_header( |
|
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | - 10, |
|
162 | - _AM_SONGLIST_MSG_VOICE_FAILEDTODELETE |
|
163 | - ); |
|
164 | - exit(0); |
|
165 | - } |
|
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_DELETED); |
|
167 | - exit(0); |
|
168 | - } |
|
169 | - $voice = $voiceHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | - xoops_confirm( |
|
171 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | - $_SERVER['SCRIPT_NAME'], |
|
173 | - sprintf(_AM_SONGLIST_MSG_VOICE_DELETE, $voice->getVar('name')) |
|
174 | - ); |
|
175 | - |
|
176 | - break; |
|
177 | - } |
|
178 | - break; |
|
29 | + default: |
|
30 | + case 'voice': |
|
31 | + switch ($fct) { |
|
32 | + default: |
|
33 | + case 'list': |
|
34 | + $adminObject = Admin::getInstance(); |
|
35 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | + |
|
37 | + /** @var VoiceHandler $voiceHandler */ |
|
38 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
39 | + |
|
40 | + $criteria = $voiceHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | + $ttl = $voiceHandler->getCount($criteria); |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | + |
|
47 | + foreach ($voiceHandler->filterFields() as $id => $key) { |
|
48 | + $GLOBALS['xoopsTpl']->assign( |
|
49 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + '<a href="' |
|
51 | + . $_SERVER['SCRIPT_NAME'] |
|
52 | + . '?start=' |
|
53 | + . $GLOBALS['start'] |
|
54 | + . '&limit=' |
|
55 | + . $GLOBALS['limit'] |
|
56 | + . '&sort=' |
|
57 | + . $key |
|
58 | + . '&order=' |
|
59 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . '&op=' |
|
61 | + . $GLOBALS['op'] |
|
62 | + . '&filter=' |
|
63 | + . $GLOBALS['filter'] |
|
64 | + . '">' |
|
65 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . '</a>' |
|
67 | + ); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $voiceHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + } |
|
70 | + |
|
71 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | + |
|
78 | + $criteria->setStart($GLOBALS['start']); |
|
79 | + $criteria->setLimit($GLOBALS['limit']); |
|
80 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setOrder($GLOBALS['order']); |
|
82 | + |
|
83 | + $voices = $voiceHandler->getObjects($criteria, true); |
|
84 | + foreach ($voices as $cid => $voice) { |
|
85 | + if (is_object($voice)) { |
|
86 | + $GLOBALS['xoopsTpl']->append('voice', $voice->toArray()); |
|
87 | + } |
|
88 | + } |
|
89 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormVoice(false)); |
|
90 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_voice_list.tpl'); |
|
92 | + break; |
|
93 | + case 'new': |
|
94 | + case 'edit': |
|
95 | + $adminObject = Admin::getInstance(); |
|
96 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | + |
|
98 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
99 | + if (Request::hasVar('id', 'REQUEST')) { |
|
100 | + $voice = $voiceHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | + } else { |
|
102 | + $voice = $voiceHandler->create(); |
|
103 | + } |
|
104 | + |
|
105 | + $GLOBALS['xoopsTpl']->assign('form', $voice->getForm()); |
|
106 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_voice_edit.tpl'); |
|
108 | + break; |
|
109 | + case 'save': |
|
110 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
111 | + $id = 0; |
|
112 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | + if ($id) { |
|
114 | + $voice = $voiceHandler->get($id); |
|
115 | + } else { |
|
116 | + $voice = $voiceHandler->create(); |
|
117 | + } |
|
118 | + $voice->setVars($_POST[$id]); |
|
119 | + |
|
120 | + if (!$id = $voiceHandler->insert($voice)) { |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE); |
|
122 | + exit(0); |
|
123 | + } |
|
124 | + if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | + redirect_header( |
|
126 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | + 10, |
|
128 | + _AM_SONGLIST_MSG_VOICE_SAVEDOKEY |
|
129 | + ); |
|
130 | + } else { |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
132 | + } |
|
133 | + exit(0); |
|
134 | + |
|
135 | + break; |
|
136 | + case 'savelist': |
|
137 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
138 | + foreach ($_REQUEST['id'] as $id) { |
|
139 | + $voice = $voiceHandler->get($id); |
|
140 | + $voice->setVars($_POST[$id]); |
|
141 | + if (!$voiceHandler->insert($voice)) { |
|
142 | + redirect_header( |
|
143 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | + 10, |
|
145 | + _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE |
|
146 | + ); |
|
147 | + exit(0); |
|
148 | + } |
|
149 | + } |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
151 | + exit(0); |
|
152 | + break; |
|
153 | + case 'delete': |
|
154 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
155 | + $id = 0; |
|
156 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | + $voice = $voiceHandler->get($id); |
|
158 | + if (!$voiceHandler->delete($voice)) { |
|
159 | + redirect_header( |
|
160 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | + 10, |
|
162 | + _AM_SONGLIST_MSG_VOICE_FAILEDTODELETE |
|
163 | + ); |
|
164 | + exit(0); |
|
165 | + } |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_DELETED); |
|
167 | + exit(0); |
|
168 | + } |
|
169 | + $voice = $voiceHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | + xoops_confirm( |
|
171 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | + $_SERVER['SCRIPT_NAME'], |
|
173 | + sprintf(_AM_SONGLIST_MSG_VOICE_DELETE, $voice->getVar('name')) |
|
174 | + ); |
|
175 | + |
|
176 | + break; |
|
177 | + } |
|
178 | + break; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | xoops_cp_footer(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | /** @var Voice $voice */ |
13 | 13 | |
14 | -require __DIR__ . '/header.php'; |
|
14 | +require __DIR__.'/header.php'; |
|
15 | 15 | |
16 | 16 | xoops_loadLanguage('admin', 'songlist'); |
17 | 17 | |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
23 | 23 | $start = Request::getInt('start', 0, 'REQUEST'); |
24 | 24 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
25 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
26 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
25 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
26 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
27 | 27 | |
28 | 28 | switch ($op) { |
29 | 29 | default: |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | |
40 | 40 | $criteria = $voiceHandler->getFilterCriteria($GLOBALS['filter']); |
41 | 41 | $ttl = $voiceHandler->getCount($criteria); |
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
43 | 43 | |
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
45 | 45 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
46 | 46 | |
47 | 47 | foreach ($voiceHandler->filterFields() as $id => $key) { |
48 | 48 | $GLOBALS['xoopsTpl']->assign( |
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
49 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
50 | 50 | '<a href="' |
51 | 51 | . $_SERVER['SCRIPT_NAME'] |
52 | 52 | . '?start=' |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | . '&sort=' |
57 | 57 | . $key |
58 | 58 | . '&order=' |
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
59 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | 60 | . '&op=' |
61 | 61 | . $GLOBALS['op'] |
62 | 62 | . '&filter=' |
63 | 63 | . $GLOBALS['filter'] |
64 | 64 | . '">' |
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
65 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | 66 | . '</a>' |
67 | 67 | ); |
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $voiceHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $voiceHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $criteria->setStart($GLOBALS['start']); |
79 | 79 | $criteria->setLimit($GLOBALS['limit']); |
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
80 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
81 | 81 | $criteria->setOrder($GLOBALS['order']); |
82 | 82 | |
83 | 83 | $voices = $voiceHandler->getObjects($criteria, true); |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | $voice->setVars($_POST[$id]); |
119 | 119 | |
120 | 120 | if (!$id = $voiceHandler->insert($voice)) { |
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE); |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE); |
|
122 | 122 | exit(0); |
123 | 123 | } |
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
124 | + if ('new'===$_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | 125 | redirect_header( |
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
126 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
127 | 127 | 10, |
128 | 128 | _AM_SONGLIST_MSG_VOICE_SAVEDOKEY |
129 | 129 | ); |
130 | 130 | } else { |
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
132 | 132 | } |
133 | 133 | exit(0); |
134 | 134 | |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | $voice->setVars($_POST[$id]); |
141 | 141 | if (!$voiceHandler->insert($voice)) { |
142 | 142 | redirect_header( |
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
143 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
144 | 144 | 10, |
145 | 145 | _AM_SONGLIST_MSG_VOICE_FAILEDTOSAVE |
146 | 146 | ); |
147 | 147 | exit(0); |
148 | 148 | } |
149 | 149 | } |
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_SAVEDOKEY); |
|
151 | 151 | exit(0); |
152 | 152 | break; |
153 | 153 | case 'delete': |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | $voice = $voiceHandler->get($id); |
158 | 158 | if (!$voiceHandler->delete($voice)) { |
159 | 159 | redirect_header( |
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
160 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
161 | 161 | 10, |
162 | 162 | _AM_SONGLIST_MSG_VOICE_FAILEDTODELETE |
163 | 163 | ); |
164 | 164 | exit(0); |
165 | 165 | } |
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_DELETED); |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_VOICE_DELETED); |
|
167 | 167 | exit(0); |
168 | 168 | } |
169 | 169 | $voice = $voiceHandler->get(Request::getInt('id', 0, 'REQUEST')); |
@@ -22,31 +22,31 @@ discard block |
||
22 | 22 | $file = ''; |
23 | 23 | |
24 | 24 | switch ($op) { |
25 | - default: |
|
26 | - case 'import': |
|
27 | - switch ($fct) { |
|
28 | - default: |
|
29 | - case 'actiona': |
|
30 | - if (Request::hasVar('xmlfile', 'SESSION')) { |
|
31 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
32 | - } |
|
33 | - $adminObject = Admin::getInstance(); |
|
34 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
25 | + default: |
|
26 | + case 'import': |
|
27 | + switch ($fct) { |
|
28 | + default: |
|
29 | + case 'actiona': |
|
30 | + if (Request::hasVar('xmlfile', 'SESSION')) { |
|
31 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
32 | + } |
|
33 | + $adminObject = Admin::getInstance(); |
|
34 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
35 | 35 | |
36 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImport(false)); |
|
37 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
38 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actiona.tpl'); |
|
39 | - break; |
|
40 | - case 'upload': |
|
41 | - if ('' != $_POST['file']) { |
|
42 | - try { |
|
43 | - $file = mb_substr(md5((string)microtime(true)), random_int(0, 20), 13) . '.xml'; |
|
44 | - } catch (Exception $e) { |
|
45 | - } |
|
46 | - copy($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $_POST['file'], $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $file); |
|
47 | - $_SESSION['xmlfile'] = $file; |
|
48 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $file . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_COPIED); |
|
49 | - } elseif (Request::hasVar('xmlfile', 'FILES') && mb_strlen($_FILES['xmlfile']['name'])) { |
|
36 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImport(false)); |
|
37 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
38 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actiona.tpl'); |
|
39 | + break; |
|
40 | + case 'upload': |
|
41 | + if ('' != $_POST['file']) { |
|
42 | + try { |
|
43 | + $file = mb_substr(md5((string)microtime(true)), random_int(0, 20), 13) . '.xml'; |
|
44 | + } catch (Exception $e) { |
|
45 | + } |
|
46 | + copy($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $_POST['file'], $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $file); |
|
47 | + $_SESSION['xmlfile'] = $file; |
|
48 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $file . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_COPIED); |
|
49 | + } elseif (Request::hasVar('xmlfile', 'FILES') && mb_strlen($_FILES['xmlfile']['name'])) { |
|
50 | 50 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
51 | 51 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
52 | 52 | // foreach (explode('/', $folders) as $folder) { |
@@ -59,540 +59,540 @@ discard block |
||
59 | 59 | // } |
60 | 60 | |
61 | 61 | // require_once $GLOBALS['xoops']->path('modules/songlist/include/uploader.php'); |
62 | - $uploader = new Uploader( |
|
63 | - $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
64 | - ['application/xml', 'text/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
|
65 | - 1024 * 1024 * 1024 * 32, |
|
66 | - 0, |
|
67 | - 0, |
|
68 | - ['xml'] |
|
69 | - ); |
|
70 | - try { |
|
71 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
72 | - } catch (Exception $e) { |
|
73 | - } |
|
62 | + $uploader = new Uploader( |
|
63 | + $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
|
64 | + ['application/xml', 'text/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
|
65 | + 1024 * 1024 * 1024 * 32, |
|
66 | + 0, |
|
67 | + 0, |
|
68 | + ['xml'] |
|
69 | + ); |
|
70 | + try { |
|
71 | + $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
72 | + } catch (Exception $e) { |
|
73 | + } |
|
74 | 74 | |
75 | - if ($uploader->fetchMedia('xmlfile')) { |
|
76 | - if (!$uploader->upload()) { |
|
77 | - $adminObject = Admin::getInstance(); |
|
78 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
79 | - echo $uploader->getErrors(); |
|
80 | - xoops_cp_footer(); |
|
81 | - exit(0); |
|
82 | - } |
|
83 | - $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
|
84 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
85 | - } else { |
|
86 | - $adminObject = Admin::getInstance(); |
|
87 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
88 | - echo $uploader->getErrors(); |
|
89 | - xoops_cp_footer(); |
|
90 | - exit(0); |
|
91 | - } |
|
92 | - } else { |
|
93 | - $adminObject = Admin::getInstance(); |
|
94 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
95 | - echo _AM_SONGLIST_IMPORT_NOFILE; |
|
96 | - xoops_cp_footer(); |
|
97 | - exit(0); |
|
98 | - } |
|
99 | - break; |
|
100 | - case 'actionb': |
|
101 | - $adminObject = Admin::getInstance(); |
|
102 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
75 | + if ($uploader->fetchMedia('xmlfile')) { |
|
76 | + if (!$uploader->upload()) { |
|
77 | + $adminObject = Admin::getInstance(); |
|
78 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
79 | + echo $uploader->getErrors(); |
|
80 | + xoops_cp_footer(); |
|
81 | + exit(0); |
|
82 | + } |
|
83 | + $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
|
84 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
85 | + } else { |
|
86 | + $adminObject = Admin::getInstance(); |
|
87 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
88 | + echo $uploader->getErrors(); |
|
89 | + xoops_cp_footer(); |
|
90 | + exit(0); |
|
91 | + } |
|
92 | + } else { |
|
93 | + $adminObject = Admin::getInstance(); |
|
94 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
95 | + echo _AM_SONGLIST_IMPORT_NOFILE; |
|
96 | + xoops_cp_footer(); |
|
97 | + exit(0); |
|
98 | + } |
|
99 | + break; |
|
100 | + case 'actionb': |
|
101 | + $adminObject = Admin::getInstance(); |
|
102 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
103 | 103 | |
104 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImportb($_SESSION['xmlfile'])); |
|
105 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
106 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actionb.tpl'); |
|
107 | - break; |
|
108 | - case 'import': |
|
109 | - $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
110 | - $albumsHandler = Helper::getInstance()->getHandler('Albums'); |
|
111 | - $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
112 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
113 | - $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
114 | - $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
104 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormImportb($_SESSION['xmlfile'])); |
|
105 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
106 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actionb.tpl'); |
|
107 | + break; |
|
108 | + case 'import': |
|
109 | + $songsHandler = Helper::getInstance()->getHandler('Songs'); |
|
110 | + $albumsHandler = Helper::getInstance()->getHandler('Albums'); |
|
111 | + $artistsHandler = Helper::getInstance()->getHandler('Artists'); |
|
112 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
113 | + $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
|
114 | + $categoryHandler = Helper::getInstance()->getHandler('Category'); |
|
115 | 115 | |
116 | - $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
117 | - $mb = floor($filesize / 1024 / 1024); |
|
118 | - if ($mb > 32) { |
|
119 | - ini_set('memory_limit', ($mb + 128) . 'M'); |
|
120 | - } |
|
116 | + $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
117 | + $mb = floor($filesize / 1024 / 1024); |
|
118 | + if ($mb > 32) { |
|
119 | + ini_set('memory_limit', ($mb + 128) . 'M'); |
|
120 | + } |
|
121 | 121 | |
122 | - $record = 0; |
|
122 | + $record = 0; |
|
123 | 123 | |
124 | - set_time_limit(3600); |
|
124 | + set_time_limit(3600); |
|
125 | 125 | |
126 | - $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
126 | + $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
127 | 127 | |
128 | - if (!empty($_POST['collection']) && mb_strlen($_POST['collection']) > 0) { |
|
129 | - if (!empty($_POST['record']) && mb_strlen($_POST['record']) > 0) { |
|
130 | - foreach ($xmlarray[$_POST['collection']][$_POST['record']] as $recid => $data) { |
|
131 | - if (Request::hasVar('limiting', 'POST')) { |
|
132 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
133 | - ++$record; |
|
134 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
135 | - $start = time(); |
|
136 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
137 | - } |
|
138 | - $records = 0; |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - $gid = 0; |
|
143 | - $gids = []; |
|
144 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
145 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
146 | - foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
147 | - $criteria = new \Criteria('name', trim($genre)); |
|
148 | - if ($genreHandler->getCount($criteria) > 0) { |
|
149 | - $objects = $genreHandler->getObjects($criteria, false); |
|
150 | - $gid = $objects[0]->getVar('gid'); |
|
151 | - } else { |
|
152 | - $object = $genreHandler->create(); |
|
153 | - $object->setVar('name', trim($genre)); |
|
154 | - $gid = $genreHandler->insert($object); |
|
155 | - } |
|
156 | - $gids[$gid] = $gid; |
|
157 | - } |
|
158 | - } |
|
159 | - } |
|
160 | - $vcid = 0; |
|
161 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
162 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
163 | - $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
164 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
165 | - $objects = $voiceHandler->getObjects($criteria, false); |
|
166 | - $vcid = $objects[0]->getVar('vcid'); |
|
167 | - } else { |
|
168 | - $object = $voiceHandler->create(); |
|
169 | - $object->setVar('name', trim($data[$_POST['voice']])); |
|
170 | - $vcid = $voiceHandler->insert($object); |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
128 | + if (!empty($_POST['collection']) && mb_strlen($_POST['collection']) > 0) { |
|
129 | + if (!empty($_POST['record']) && mb_strlen($_POST['record']) > 0) { |
|
130 | + foreach ($xmlarray[$_POST['collection']][$_POST['record']] as $recid => $data) { |
|
131 | + if (Request::hasVar('limiting', 'POST')) { |
|
132 | + if (true === Request::getInt('limiting', 0, 'POST')) { |
|
133 | + ++$record; |
|
134 | + if ($record > Request::getInt('records', 0, 'POST')) { |
|
135 | + $start = time(); |
|
136 | + while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
137 | + } |
|
138 | + $records = 0; |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + $gid = 0; |
|
143 | + $gids = []; |
|
144 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
145 | + if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
146 | + foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
147 | + $criteria = new \Criteria('name', trim($genre)); |
|
148 | + if ($genreHandler->getCount($criteria) > 0) { |
|
149 | + $objects = $genreHandler->getObjects($criteria, false); |
|
150 | + $gid = $objects[0]->getVar('gid'); |
|
151 | + } else { |
|
152 | + $object = $genreHandler->create(); |
|
153 | + $object->setVar('name', trim($genre)); |
|
154 | + $gid = $genreHandler->insert($object); |
|
155 | + } |
|
156 | + $gids[$gid] = $gid; |
|
157 | + } |
|
158 | + } |
|
159 | + } |
|
160 | + $vcid = 0; |
|
161 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
162 | + if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
163 | + $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
164 | + if ($voiceHandler->getCount($criteria) > 0) { |
|
165 | + $objects = $voiceHandler->getObjects($criteria, false); |
|
166 | + $vcid = $objects[0]->getVar('vcid'); |
|
167 | + } else { |
|
168 | + $object = $voiceHandler->create(); |
|
169 | + $object->setVar('name', trim($data[$_POST['voice']])); |
|
170 | + $vcid = $voiceHandler->insert($object); |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $cid = 0; |
|
176 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
177 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
178 | - $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
179 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
180 | - $objects = $categoryHandler->getObjects($criteria, false); |
|
181 | - $cid = $objects[0]->getVar('cid'); |
|
182 | - } else { |
|
183 | - $object = $categoryHandler->create(); |
|
184 | - $object->setVar('name', trim($data[$_POST['category']])); |
|
185 | - $cid = $categoryHandler->insert($object); |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - $aids = []; |
|
190 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
191 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
192 | - foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
193 | - $criteria = new \Criteria('name', trim($artist)); |
|
194 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
195 | - $objects = $artistsHandler->getObjects($criteria, false); |
|
196 | - $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
197 | - } else { |
|
198 | - $object = $artistsHandler->create(); // added PL |
|
199 | - $object->setVar('name', trim($artist)); |
|
200 | - $aid = $artistsHandler->insert($object); |
|
201 | - $aids[$aid] = $aid; |
|
202 | - } |
|
203 | - } |
|
204 | - } |
|
205 | - } |
|
206 | - $abid = 0; |
|
207 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
208 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
209 | - $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
210 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
211 | - $objects = $albumsHandler->getObjects($criteria, false); |
|
212 | - $abid = $objects[0]->getVar('abid'); |
|
213 | - } else { |
|
214 | - $object = $albumsHandler->create(); |
|
215 | - $object->setVar('cid', $cid); |
|
216 | - $object->setVar('aids', $aids); |
|
217 | - $object->setVar('title', trim($data[$_POST['album']])); |
|
218 | - $abid = $albumsHandler->insert($object); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - $sid = 0; |
|
223 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
224 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
225 | - $criteria = new \CriteriaCompo(); |
|
226 | - if ('' != trim($data[$_POST['songid']])) { |
|
227 | - $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
228 | - } |
|
229 | - if ('' != trim($data[$_POST['title']])) { |
|
230 | - $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
231 | - } |
|
232 | - if ($songsHandler->getCount($criteria) > 0) { |
|
233 | - $objects = $songsHandler->getObjects($criteria, false); |
|
234 | - $object = $objects[0]; |
|
235 | - } else { |
|
236 | - $object = $songsHandler->create(); |
|
237 | - } |
|
238 | - $object->setVar('cid', $cid); |
|
239 | - $object->setVar('gids', $gids); |
|
240 | - $object->setVar('vcid', $vcid); |
|
241 | - $object->setVar('aids', $aids); |
|
242 | - $object->setVar('abid', $abid); |
|
243 | - $object->setVar('songid', trim($data[$_POST['songid']])); |
|
244 | - $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
245 | - $object->setVar('title', trim($data[$_POST['title']])); |
|
246 | - $object->setVar('tags', trim($data[$_POST['tags']])); |
|
247 | - $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
248 | - $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
249 | - $sid = $songsHandler->insert($object); |
|
175 | + $cid = 0; |
|
176 | + if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
177 | + if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
178 | + $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
179 | + if ($categoryHandler->getCount($criteria) > 0) { |
|
180 | + $objects = $categoryHandler->getObjects($criteria, false); |
|
181 | + $cid = $objects[0]->getVar('cid'); |
|
182 | + } else { |
|
183 | + $object = $categoryHandler->create(); |
|
184 | + $object->setVar('name', trim($data[$_POST['category']])); |
|
185 | + $cid = $categoryHandler->insert($object); |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + $aids = []; |
|
190 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
191 | + if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
192 | + foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
193 | + $criteria = new \Criteria('name', trim($artist)); |
|
194 | + if ($artistsHandler->getCount($criteria) > 0) { |
|
195 | + $objects = $artistsHandler->getObjects($criteria, false); |
|
196 | + $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
197 | + } else { |
|
198 | + $object = $artistsHandler->create(); // added PL |
|
199 | + $object->setVar('name', trim($artist)); |
|
200 | + $aid = $artistsHandler->insert($object); |
|
201 | + $aids[$aid] = $aid; |
|
202 | + } |
|
203 | + } |
|
204 | + } |
|
205 | + } |
|
206 | + $abid = 0; |
|
207 | + if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
208 | + if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
209 | + $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
210 | + if ($albumsHandler->getCount($criteria) > 0) { |
|
211 | + $objects = $albumsHandler->getObjects($criteria, false); |
|
212 | + $abid = $objects[0]->getVar('abid'); |
|
213 | + } else { |
|
214 | + $object = $albumsHandler->create(); |
|
215 | + $object->setVar('cid', $cid); |
|
216 | + $object->setVar('aids', $aids); |
|
217 | + $object->setVar('title', trim($data[$_POST['album']])); |
|
218 | + $abid = $albumsHandler->insert($object); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + $sid = 0; |
|
223 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
224 | + if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
225 | + $criteria = new \CriteriaCompo(); |
|
226 | + if ('' != trim($data[$_POST['songid']])) { |
|
227 | + $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
228 | + } |
|
229 | + if ('' != trim($data[$_POST['title']])) { |
|
230 | + $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
231 | + } |
|
232 | + if ($songsHandler->getCount($criteria) > 0) { |
|
233 | + $objects = $songsHandler->getObjects($criteria, false); |
|
234 | + $object = $objects[0]; |
|
235 | + } else { |
|
236 | + $object = $songsHandler->create(); |
|
237 | + } |
|
238 | + $object->setVar('cid', $cid); |
|
239 | + $object->setVar('gids', $gids); |
|
240 | + $object->setVar('vcid', $vcid); |
|
241 | + $object->setVar('aids', $aids); |
|
242 | + $object->setVar('abid', $abid); |
|
243 | + $object->setVar('songid', trim($data[$_POST['songid']])); |
|
244 | + $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
245 | + $object->setVar('title', trim($data[$_POST['title']])); |
|
246 | + $object->setVar('tags', trim($data[$_POST['tags']])); |
|
247 | + $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
248 | + $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
249 | + $sid = $songsHandler->insert($object); |
|
250 | 250 | |
251 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
252 | - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
253 | - $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
254 | - } |
|
251 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
252 | + $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
253 | + $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
254 | + } |
|
255 | 255 | |
256 | - $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
257 | - $fields = $extrasHandler->getFields(null); |
|
258 | - $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
259 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
260 | - $extras = $extrasHandler->getObjects($criteria, false); |
|
261 | - $extra = $extras[0]; |
|
262 | - } else { |
|
263 | - $extra = $extrasHandler->create(); |
|
264 | - } |
|
265 | - $extra->setVar('sid', $sid); |
|
266 | - foreach ($fields as $field) { |
|
267 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
268 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
269 | - $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
270 | - } |
|
271 | - } |
|
272 | - } |
|
273 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
274 | - $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
275 | - $artistsHandler->insert($artist, true); |
|
276 | - } |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
280 | - } else { |
|
281 | - foreach ($xmlarray[$_POST['collection']] as $id => $records) { |
|
282 | - if (Request::hasVar('limiting', 'POST')) { |
|
283 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
284 | - ++$record; |
|
285 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
286 | - $start = time(); |
|
287 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
288 | - } |
|
289 | - $records = 0; |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - $gid = 0; |
|
294 | - $gids = []; |
|
295 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
296 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
297 | - foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
298 | - $criteria = new \Criteria('name', trim($genre)); |
|
299 | - if ($genreHandler->getCount($criteria) > 0) { |
|
300 | - $objects = $genreHandler->getObjects($criteria, false); |
|
301 | - $gid = $objects[0]->getVar('gid'); |
|
302 | - } else { |
|
303 | - $object = $genreHandler->create(); |
|
304 | - $object->setVar('name', trim($genre)); |
|
305 | - $gid = $genreHandler->insert($object); |
|
306 | - } |
|
307 | - $gids[$gid] = $gid; |
|
308 | - } |
|
309 | - } |
|
310 | - } |
|
311 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
312 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
313 | - $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
314 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
315 | - $objects = $voiceHandler->getObjects($criteria, false); |
|
316 | - $vcid = $objects[0]->getVar('vcid'); |
|
317 | - } else { |
|
318 | - $object = $voiceHandler->create(); |
|
319 | - $object->setVar('name', trim($data[$_POST['voice']])); |
|
320 | - $vcid = $voiceHandler->insert($object); |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - $cid = 0; |
|
325 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
326 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
327 | - $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
328 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
329 | - $objects = $categoryHandler->getObjects($criteria, false); |
|
330 | - $cid = $objects[0]->getVar('cid'); |
|
331 | - } else { |
|
332 | - $object = $categoryHandler->create(); |
|
333 | - $object->setVar('name', trim($data[$_POST['category']])); |
|
334 | - $cid = $categoryHandler->insert($object); |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - $aids = []; |
|
339 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
340 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
341 | - foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
342 | - $criteria = new \Criteria('name', trim($artist)); |
|
343 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
344 | - $objects = $artistsHandler->getObjects($criteria, false); |
|
345 | - $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
346 | - } else { |
|
347 | - $object = $artistsHandler->create(); //added PL |
|
348 | - $object->setVar('cid', $cid); |
|
349 | - $object->setVar('name', trim($data[$_POST['artist']])); |
|
350 | - $aid = $artistsHandler->insert($object); |
|
351 | - $aids[$aid] = $aid; |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
355 | - } |
|
356 | - $abid = 0; |
|
357 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
358 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
359 | - $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
360 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
361 | - $objects = $albumsHandler->getObjects($criteria, false); |
|
362 | - $abid = $objects[0]->getVar('abid'); |
|
363 | - } else { |
|
364 | - $object = $albumsHandler->create(); |
|
365 | - $object->setVar('cid', $cid); |
|
366 | - $object->setVar('aids', $aids); |
|
367 | - $object->setVar('title', trim($data[$_POST['album']])); |
|
368 | - $abid = $albumsHandler->insert($object); |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - $sid = 0; |
|
373 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
374 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
375 | - $criteria = new \CriteriaCompo(); |
|
376 | - if ('' != trim($data[$_POST['songid']])) { |
|
377 | - $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
378 | - } |
|
379 | - if ('' != trim($data[$_POST['title']])) { |
|
380 | - $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
381 | - } |
|
382 | - if ($songsHandler->getCount($criteria) > 0) { |
|
383 | - $objects = $songsHandler->getObjects($criteria, false); |
|
384 | - $object = $objects[0]; |
|
385 | - } else { |
|
386 | - $object = $songsHandler->create(); |
|
387 | - } |
|
388 | - $object->setVar('cid', $cid); |
|
389 | - $object->setVar('gids', $gids); |
|
390 | - $object->setVar('vcid', $vcid); |
|
391 | - $object->setVar('aids', $aids); |
|
392 | - $object->setVar('abid', $abid); |
|
393 | - $object->setVar('songid', trim($data[$_POST['songid']])); |
|
394 | - $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
395 | - $object->setVar('tags', trim($data[$_POST['tags']])); |
|
396 | - $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
397 | - $object->setVar('title', trim($data[$_POST['title']])); |
|
398 | - $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
399 | - $sid = $songsHandler->insert($object); |
|
256 | + $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
257 | + $fields = $extrasHandler->getFields(null); |
|
258 | + $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
259 | + if ($extrasHandler->getCount($criteria) > 0) { |
|
260 | + $extras = $extrasHandler->getObjects($criteria, false); |
|
261 | + $extra = $extras[0]; |
|
262 | + } else { |
|
263 | + $extra = $extrasHandler->create(); |
|
264 | + } |
|
265 | + $extra->setVar('sid', $sid); |
|
266 | + foreach ($fields as $field) { |
|
267 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
268 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
269 | + $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
270 | + } |
|
271 | + } |
|
272 | + } |
|
273 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
274 | + $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
275 | + $artistsHandler->insert($artist, true); |
|
276 | + } |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | + } else { |
|
281 | + foreach ($xmlarray[$_POST['collection']] as $id => $records) { |
|
282 | + if (Request::hasVar('limiting', 'POST')) { |
|
283 | + if (true === Request::getInt('limiting', 0, 'POST')) { |
|
284 | + ++$record; |
|
285 | + if ($record > Request::getInt('records', 0, 'POST')) { |
|
286 | + $start = time(); |
|
287 | + while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
288 | + } |
|
289 | + $records = 0; |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + $gid = 0; |
|
294 | + $gids = []; |
|
295 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
296 | + if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
297 | + foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
298 | + $criteria = new \Criteria('name', trim($genre)); |
|
299 | + if ($genreHandler->getCount($criteria) > 0) { |
|
300 | + $objects = $genreHandler->getObjects($criteria, false); |
|
301 | + $gid = $objects[0]->getVar('gid'); |
|
302 | + } else { |
|
303 | + $object = $genreHandler->create(); |
|
304 | + $object->setVar('name', trim($genre)); |
|
305 | + $gid = $genreHandler->insert($object); |
|
306 | + } |
|
307 | + $gids[$gid] = $gid; |
|
308 | + } |
|
309 | + } |
|
310 | + } |
|
311 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
312 | + if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
313 | + $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
314 | + if ($voiceHandler->getCount($criteria) > 0) { |
|
315 | + $objects = $voiceHandler->getObjects($criteria, false); |
|
316 | + $vcid = $objects[0]->getVar('vcid'); |
|
317 | + } else { |
|
318 | + $object = $voiceHandler->create(); |
|
319 | + $object->setVar('name', trim($data[$_POST['voice']])); |
|
320 | + $vcid = $voiceHandler->insert($object); |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + $cid = 0; |
|
325 | + if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
326 | + if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
327 | + $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
328 | + if ($categoryHandler->getCount($criteria) > 0) { |
|
329 | + $objects = $categoryHandler->getObjects($criteria, false); |
|
330 | + $cid = $objects[0]->getVar('cid'); |
|
331 | + } else { |
|
332 | + $object = $categoryHandler->create(); |
|
333 | + $object->setVar('name', trim($data[$_POST['category']])); |
|
334 | + $cid = $categoryHandler->insert($object); |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + $aids = []; |
|
339 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
340 | + if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
341 | + foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
342 | + $criteria = new \Criteria('name', trim($artist)); |
|
343 | + if ($artistsHandler->getCount($criteria) > 0) { |
|
344 | + $objects = $artistsHandler->getObjects($criteria, false); |
|
345 | + $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
346 | + } else { |
|
347 | + $object = $artistsHandler->create(); //added PL |
|
348 | + $object->setVar('cid', $cid); |
|
349 | + $object->setVar('name', trim($data[$_POST['artist']])); |
|
350 | + $aid = $artistsHandler->insert($object); |
|
351 | + $aids[$aid] = $aid; |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | + } |
|
356 | + $abid = 0; |
|
357 | + if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
358 | + if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
359 | + $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
360 | + if ($albumsHandler->getCount($criteria) > 0) { |
|
361 | + $objects = $albumsHandler->getObjects($criteria, false); |
|
362 | + $abid = $objects[0]->getVar('abid'); |
|
363 | + } else { |
|
364 | + $object = $albumsHandler->create(); |
|
365 | + $object->setVar('cid', $cid); |
|
366 | + $object->setVar('aids', $aids); |
|
367 | + $object->setVar('title', trim($data[$_POST['album']])); |
|
368 | + $abid = $albumsHandler->insert($object); |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + $sid = 0; |
|
373 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
374 | + if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
375 | + $criteria = new \CriteriaCompo(); |
|
376 | + if ('' != trim($data[$_POST['songid']])) { |
|
377 | + $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
378 | + } |
|
379 | + if ('' != trim($data[$_POST['title']])) { |
|
380 | + $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
381 | + } |
|
382 | + if ($songsHandler->getCount($criteria) > 0) { |
|
383 | + $objects = $songsHandler->getObjects($criteria, false); |
|
384 | + $object = $objects[0]; |
|
385 | + } else { |
|
386 | + $object = $songsHandler->create(); |
|
387 | + } |
|
388 | + $object->setVar('cid', $cid); |
|
389 | + $object->setVar('gids', $gids); |
|
390 | + $object->setVar('vcid', $vcid); |
|
391 | + $object->setVar('aids', $aids); |
|
392 | + $object->setVar('abid', $abid); |
|
393 | + $object->setVar('songid', trim($data[$_POST['songid']])); |
|
394 | + $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
395 | + $object->setVar('tags', trim($data[$_POST['tags']])); |
|
396 | + $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
397 | + $object->setVar('title', trim($data[$_POST['title']])); |
|
398 | + $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
399 | + $sid = $songsHandler->insert($object); |
|
400 | 400 | |
401 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
402 | - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
403 | - $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
404 | - } |
|
401 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
402 | + $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
403 | + $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
404 | + } |
|
405 | 405 | |
406 | - $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
407 | - $fields = $extrasHandler->getFields(null); |
|
408 | - $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
409 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
410 | - $extras = $extrasHandler->getObjects($criteria, false); |
|
411 | - $extra = $extras[0]; |
|
412 | - } else { |
|
413 | - $extra = $extrasHandler->create(); |
|
414 | - } |
|
415 | - $extra->setVar('sid', $sid); |
|
416 | - foreach ($fields as $field) { |
|
417 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
418 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
419 | - $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
420 | - } |
|
421 | - } |
|
422 | - } |
|
423 | - $extrasHandler->insert($extra, true); |
|
424 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
425 | - $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
426 | - $artistsHandler->insert($artist, true); |
|
427 | - } |
|
428 | - } |
|
429 | - } |
|
430 | - } |
|
431 | - } |
|
432 | - } else { |
|
433 | - foreach ($xmlarray as $recid => $data) { |
|
434 | - $cid = 0; |
|
435 | - $gid = 0; |
|
436 | - $vcid = 0; |
|
437 | - $aids = []; |
|
438 | - $abid = []; |
|
439 | - if (Request::hasVar('limiting', 'POST')) { |
|
440 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
441 | - ++$record; |
|
442 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
443 | - $start = time(); |
|
444 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
445 | - } |
|
446 | - $records = 0; |
|
447 | - } |
|
448 | - } |
|
449 | - } |
|
450 | - $gid = 0; |
|
451 | - $gids = []; |
|
452 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
453 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
454 | - foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
455 | - $criteria = new \Criteria('name', trim($genre)); |
|
456 | - if ($genreHandler->getCount($criteria) > 0) { |
|
457 | - $objects = $genreHandler->getObjects($criteria, false); |
|
458 | - $gid = $objects[0]->getVar('gid'); |
|
459 | - } else { |
|
460 | - $object = $genreHandler->create(); |
|
461 | - $object->setVar('name', trim($genre)); |
|
462 | - $gid = $genreHandler->insert($object); |
|
463 | - } |
|
464 | - $gids[$gid] = $gid; |
|
465 | - } |
|
466 | - } |
|
467 | - } |
|
406 | + $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
407 | + $fields = $extrasHandler->getFields(null); |
|
408 | + $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
409 | + if ($extrasHandler->getCount($criteria) > 0) { |
|
410 | + $extras = $extrasHandler->getObjects($criteria, false); |
|
411 | + $extra = $extras[0]; |
|
412 | + } else { |
|
413 | + $extra = $extrasHandler->create(); |
|
414 | + } |
|
415 | + $extra->setVar('sid', $sid); |
|
416 | + foreach ($fields as $field) { |
|
417 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
418 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
419 | + $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
420 | + } |
|
421 | + } |
|
422 | + } |
|
423 | + $extrasHandler->insert($extra, true); |
|
424 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
425 | + $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
426 | + $artistsHandler->insert($artist, true); |
|
427 | + } |
|
428 | + } |
|
429 | + } |
|
430 | + } |
|
431 | + } |
|
432 | + } else { |
|
433 | + foreach ($xmlarray as $recid => $data) { |
|
434 | + $cid = 0; |
|
435 | + $gid = 0; |
|
436 | + $vcid = 0; |
|
437 | + $aids = []; |
|
438 | + $abid = []; |
|
439 | + if (Request::hasVar('limiting', 'POST')) { |
|
440 | + if (true === Request::getInt('limiting', 0, 'POST')) { |
|
441 | + ++$record; |
|
442 | + if ($record > Request::getInt('records', 0, 'POST')) { |
|
443 | + $start = time(); |
|
444 | + while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
445 | + } |
|
446 | + $records = 0; |
|
447 | + } |
|
448 | + } |
|
449 | + } |
|
450 | + $gid = 0; |
|
451 | + $gids = []; |
|
452 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
453 | + if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
454 | + foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
|
455 | + $criteria = new \Criteria('name', trim($genre)); |
|
456 | + if ($genreHandler->getCount($criteria) > 0) { |
|
457 | + $objects = $genreHandler->getObjects($criteria, false); |
|
458 | + $gid = $objects[0]->getVar('gid'); |
|
459 | + } else { |
|
460 | + $object = $genreHandler->create(); |
|
461 | + $object->setVar('name', trim($genre)); |
|
462 | + $gid = $genreHandler->insert($object); |
|
463 | + } |
|
464 | + $gids[$gid] = $gid; |
|
465 | + } |
|
466 | + } |
|
467 | + } |
|
468 | 468 | |
469 | - $vcid = 0; |
|
470 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
471 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
472 | - $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
473 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
474 | - $objects = $voiceHandler->getObjects($criteria, false); |
|
475 | - $vcid = $objects[0]->getVar('vcid'); |
|
476 | - } else { |
|
477 | - $object = $voiceHandler->create(); |
|
478 | - $object->setVar('name', trim($data[$_POST['voice']])); |
|
479 | - $vcid = $voiceHandler->insert($object); |
|
480 | - } |
|
481 | - } |
|
482 | - } |
|
483 | - $cid = 0; |
|
484 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
485 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
486 | - $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
487 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
488 | - $objects = $categoryHandler->getObjects($criteria, false); |
|
489 | - $cid = $objects[0]->getVar('cid'); |
|
490 | - } else { |
|
491 | - $object = $categoryHandler->create(); |
|
492 | - $object->setVar('name', trim($data[$_POST['category']])); |
|
493 | - $cid = $categoryHandler->insert($object); |
|
494 | - } |
|
495 | - } |
|
496 | - } |
|
497 | - $aids = []; |
|
498 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
499 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
500 | - foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
501 | - $criteria = new \Criteria('name', trim($artist)); |
|
502 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
503 | - $objects = $artistsHandler->getObjects($criteria, false); |
|
504 | - $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
505 | - } else { |
|
506 | - $object = $artistsHandler->create(); //Added PL |
|
507 | - $object->setVar('cid', $cid); |
|
508 | - $object->setVar('name', trim($data[$_POST['artist']])); |
|
509 | - $aid = $artistsHandler->insert($object); |
|
510 | - $aids[$aid] = $aid; |
|
511 | - } |
|
512 | - } |
|
513 | - } |
|
514 | - } |
|
515 | - $abid = 0; |
|
516 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
517 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
518 | - $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
519 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
520 | - $objects = $albumsHandler->getObjects($criteria, false); |
|
521 | - $abid = $objects[0]->getVar('abid'); |
|
522 | - } else { |
|
523 | - $object = $albumsHandler->create(); |
|
524 | - $object->setVar('cid', $cid); |
|
525 | - $object->setVar('aids', $aids); |
|
526 | - $object->setVar('title', trim($data[$_POST['album']])); |
|
527 | - $abid = $albumsHandler->insert($object); |
|
528 | - } |
|
529 | - } |
|
530 | - } |
|
531 | - $sid = 0; |
|
532 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
533 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
534 | - $criteria = new \CriteriaCompo(); |
|
535 | - if ('' != trim($data[$_POST['songid']])) { |
|
536 | - $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
537 | - } |
|
538 | - if ('' != trim($data[$_POST['title']])) { |
|
539 | - $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
540 | - } |
|
541 | - if ($songsHandler->getCount($criteria) > 0) { |
|
542 | - $objects = $songsHandler->getObjects($criteria, false); |
|
543 | - $object = $objects[0]; |
|
544 | - } else { |
|
545 | - $object = $songsHandler->create(); |
|
546 | - } |
|
547 | - $object->setVar('cid', $cid); |
|
548 | - $object->setVar('gids', $gids); |
|
549 | - $object->setVar('vcid', $vcid); |
|
550 | - $object->setVar('aids', $aids); |
|
551 | - $object->setVar('abid', $abid); |
|
552 | - $object->setVar('songid', trim($data[$_POST['songid']])); |
|
553 | - $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
554 | - $object->setVar('title', trim($data[$_POST['title']])); |
|
555 | - $object->setVar('tags', trim($data[$_POST['tags']])); |
|
556 | - $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
557 | - $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
558 | - $sid = $songsHandler->insert($object); |
|
469 | + $vcid = 0; |
|
470 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
471 | + if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
472 | + $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
|
473 | + if ($voiceHandler->getCount($criteria) > 0) { |
|
474 | + $objects = $voiceHandler->getObjects($criteria, false); |
|
475 | + $vcid = $objects[0]->getVar('vcid'); |
|
476 | + } else { |
|
477 | + $object = $voiceHandler->create(); |
|
478 | + $object->setVar('name', trim($data[$_POST['voice']])); |
|
479 | + $vcid = $voiceHandler->insert($object); |
|
480 | + } |
|
481 | + } |
|
482 | + } |
|
483 | + $cid = 0; |
|
484 | + if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
485 | + if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
486 | + $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
|
487 | + if ($categoryHandler->getCount($criteria) > 0) { |
|
488 | + $objects = $categoryHandler->getObjects($criteria, false); |
|
489 | + $cid = $objects[0]->getVar('cid'); |
|
490 | + } else { |
|
491 | + $object = $categoryHandler->create(); |
|
492 | + $object->setVar('name', trim($data[$_POST['category']])); |
|
493 | + $cid = $categoryHandler->insert($object); |
|
494 | + } |
|
495 | + } |
|
496 | + } |
|
497 | + $aids = []; |
|
498 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
499 | + if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
500 | + foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
|
501 | + $criteria = new \Criteria('name', trim($artist)); |
|
502 | + if ($artistsHandler->getCount($criteria) > 0) { |
|
503 | + $objects = $artistsHandler->getObjects($criteria, false); |
|
504 | + $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
|
505 | + } else { |
|
506 | + $object = $artistsHandler->create(); //Added PL |
|
507 | + $object->setVar('cid', $cid); |
|
508 | + $object->setVar('name', trim($data[$_POST['artist']])); |
|
509 | + $aid = $artistsHandler->insert($object); |
|
510 | + $aids[$aid] = $aid; |
|
511 | + } |
|
512 | + } |
|
513 | + } |
|
514 | + } |
|
515 | + $abid = 0; |
|
516 | + if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
517 | + if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
518 | + $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
|
519 | + if ($albumsHandler->getCount($criteria) > 0) { |
|
520 | + $objects = $albumsHandler->getObjects($criteria, false); |
|
521 | + $abid = $objects[0]->getVar('abid'); |
|
522 | + } else { |
|
523 | + $object = $albumsHandler->create(); |
|
524 | + $object->setVar('cid', $cid); |
|
525 | + $object->setVar('aids', $aids); |
|
526 | + $object->setVar('title', trim($data[$_POST['album']])); |
|
527 | + $abid = $albumsHandler->insert($object); |
|
528 | + } |
|
529 | + } |
|
530 | + } |
|
531 | + $sid = 0; |
|
532 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
533 | + if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
534 | + $criteria = new \CriteriaCompo(); |
|
535 | + if ('' != trim($data[$_POST['songid']])) { |
|
536 | + $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
|
537 | + } |
|
538 | + if ('' != trim($data[$_POST['title']])) { |
|
539 | + $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
|
540 | + } |
|
541 | + if ($songsHandler->getCount($criteria) > 0) { |
|
542 | + $objects = $songsHandler->getObjects($criteria, false); |
|
543 | + $object = $objects[0]; |
|
544 | + } else { |
|
545 | + $object = $songsHandler->create(); |
|
546 | + } |
|
547 | + $object->setVar('cid', $cid); |
|
548 | + $object->setVar('gids', $gids); |
|
549 | + $object->setVar('vcid', $vcid); |
|
550 | + $object->setVar('aids', $aids); |
|
551 | + $object->setVar('abid', $abid); |
|
552 | + $object->setVar('songid', trim($data[$_POST['songid']])); |
|
553 | + $object->setVar('traxid', trim($data[$_POST['traxid']])); |
|
554 | + $object->setVar('title', trim($data[$_POST['title']])); |
|
555 | + $object->setVar('tags', trim($data[$_POST['tags']])); |
|
556 | + $object->setVar('mp3', trim($data[$_POST['mp3']])); |
|
557 | + $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
|
558 | + $sid = $songsHandler->insert($object); |
|
559 | 559 | |
560 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
561 | - $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
562 | - $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
563 | - } |
|
560 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
561 | + $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
|
562 | + $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
|
563 | + } |
|
564 | 564 | |
565 | - $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
566 | - $fields = $extrasHandler->getFields(null); |
|
567 | - $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
568 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
569 | - $extras = $extrasHandler->getObjects($criteria, false); |
|
570 | - $extra = $extras[0]; |
|
571 | - } else { |
|
572 | - $extra = $extrasHandler->create(); |
|
573 | - } |
|
574 | - $extra->setVar('sid', $sid); |
|
575 | - foreach ($fields as $field) { |
|
576 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
577 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
578 | - $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
579 | - } |
|
580 | - } |
|
581 | - } |
|
582 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
583 | - $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
584 | - $artistsHandler->insert($artist, true); |
|
585 | - } |
|
586 | - } |
|
587 | - } |
|
588 | - } |
|
589 | - } |
|
590 | - unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
591 | - unset($_SESSION['xmlfile']); |
|
592 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
593 | - break; |
|
594 | - } |
|
595 | - break; |
|
565 | + $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
|
566 | + $fields = $extrasHandler->getFields(null); |
|
567 | + $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
|
568 | + if ($extrasHandler->getCount($criteria) > 0) { |
|
569 | + $extras = $extrasHandler->getObjects($criteria, false); |
|
570 | + $extra = $extras[0]; |
|
571 | + } else { |
|
572 | + $extra = $extrasHandler->create(); |
|
573 | + } |
|
574 | + $extra->setVar('sid', $sid); |
|
575 | + foreach ($fields as $field) { |
|
576 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
577 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
578 | + $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
|
579 | + } |
|
580 | + } |
|
581 | + } |
|
582 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
583 | + $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
|
584 | + $artistsHandler->insert($artist, true); |
|
585 | + } |
|
586 | + } |
|
587 | + } |
|
588 | + } |
|
589 | + } |
|
590 | + unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
591 | + unset($_SESSION['xmlfile']); |
|
592 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
593 | + break; |
|
594 | + } |
|
595 | + break; |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | xoops_cp_footer(); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use XoopsModules\Songlist\Uploader; |
7 | 7 | use XoopsModules\Songlist\Form\FormController; |
8 | 8 | |
9 | -require __DIR__ . '/header.php'; |
|
9 | +require __DIR__.'/header.php'; |
|
10 | 10 | |
11 | 11 | xoops_loadLanguage('admin', 'songlist'); |
12 | 12 | |
@@ -17,8 +17,8 @@ discard block |
||
17 | 17 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
18 | 18 | $start = Request::getInt('start', 0, 'REQUEST'); |
19 | 19 | $order = $_REQUEST['order'] ?? 'DESC'; |
20 | -$sort = isset($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
21 | -$filter = isset($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
20 | +$sort = isset($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
21 | +$filter = isset($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
22 | 22 | $file = ''; |
23 | 23 | |
24 | 24 | switch ($op) { |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | default: |
29 | 29 | case 'actiona': |
30 | 30 | if (Request::hasVar('xmlfile', 'SESSION')) { |
31 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $_SESSION['xmlfile'] . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
31 | + redirect_header($_SERVER['SCRIPT_NAME'].'?file='.$_SESSION['xmlfile'].'&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
32 | 32 | } |
33 | 33 | $adminObject = Admin::getInstance(); |
34 | 34 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -38,14 +38,14 @@ discard block |
||
38 | 38 | $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_import_actiona.tpl'); |
39 | 39 | break; |
40 | 40 | case 'upload': |
41 | - if ('' != $_POST['file']) { |
|
41 | + if (''!=$_POST['file']) { |
|
42 | 42 | try { |
43 | - $file = mb_substr(md5((string)microtime(true)), random_int(0, 20), 13) . '.xml'; |
|
43 | + $file = mb_substr(md5((string) microtime(true)), random_int(0, 20), 13).'.xml'; |
|
44 | 44 | } catch (Exception $e) { |
45 | 45 | } |
46 | - copy($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $_POST['file'], $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']) . $file); |
|
46 | + copy($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']).$_POST['file'], $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']).$file); |
|
47 | 47 | $_SESSION['xmlfile'] = $file; |
48 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $file . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_COPIED); |
|
48 | + redirect_header($_SERVER['SCRIPT_NAME'].'?file='.$file.'&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_COPIED); |
|
49 | 49 | } elseif (Request::hasVar('xmlfile', 'FILES') && mb_strlen($_FILES['xmlfile']['name'])) { |
50 | 50 | // if (!is_dir($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']))) { |
51 | 51 | // foreach (explode('\\', $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'])) as $folders) { |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | $uploader = new Uploader( |
63 | 63 | $GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas']), |
64 | 64 | ['application/xml', 'text/xml', 'application/xml-dtd', 'application/xml-external-parsed-entity', 'text/xml xml xsl', 'text/xml-external-parsed-entity'], |
65 | - 1024 * 1024 * 1024 * 32, |
|
65 | + 1024*1024*1024*32, |
|
66 | 66 | 0, |
67 | 67 | 0, |
68 | 68 | ['xml'] |
69 | 69 | ); |
70 | 70 | try { |
71 | - $uploader->setPrefix(mb_substr(md5((string)microtime(true)), random_int(0, 20), 13)); |
|
71 | + $uploader->setPrefix(mb_substr(md5((string) microtime(true)), random_int(0, 20), 13)); |
|
72 | 72 | } catch (Exception $e) { |
73 | 73 | } |
74 | 74 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | exit(0); |
82 | 82 | } |
83 | 83 | $_SESSION['xmlfile'] = $uploader->getSavedFileName(); |
84 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?file=' . $uploader->getSavedFileName() . '&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
84 | + redirect_header($_SERVER['SCRIPT_NAME'].'?file='.$uploader->getSavedFileName().'&op=import&fct=actionb', 10, _AM_SONGLIST_XMLFILE_UPLOADED); |
|
85 | 85 | } else { |
86 | 86 | $adminObject = Admin::getInstance(); |
87 | 87 | $adminObject->displayNavigation(basename(__FILE__)); |
@@ -113,27 +113,27 @@ discard block |
||
113 | 113 | $voiceHandler = Helper::getInstance()->getHandler('Voice'); |
114 | 114 | $categoryHandler = Helper::getInstance()->getHandler('Category'); |
115 | 115 | |
116 | - $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
117 | - $mb = floor($filesize / 1024 / 1024); |
|
118 | - if ($mb > 32) { |
|
119 | - ini_set('memory_limit', ($mb + 128) . 'M'); |
|
116 | + $filesize = filesize($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])); |
|
117 | + $mb = floor($filesize/1024/1024); |
|
118 | + if ($mb>32) { |
|
119 | + ini_set('memory_limit', ($mb+128).'M'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | $record = 0; |
123 | 123 | |
124 | 124 | set_time_limit(3600); |
125 | 125 | |
126 | - $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])), false, 'tag'); |
|
126 | + $xmlarray = Utility::xml2array(file_get_contents($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])), false, 'tag'); |
|
127 | 127 | |
128 | - if (!empty($_POST['collection']) && mb_strlen($_POST['collection']) > 0) { |
|
129 | - if (!empty($_POST['record']) && mb_strlen($_POST['record']) > 0) { |
|
128 | + if (!empty($_POST['collection']) && mb_strlen($_POST['collection'])>0) { |
|
129 | + if (!empty($_POST['record']) && mb_strlen($_POST['record'])>0) { |
|
130 | 130 | foreach ($xmlarray[$_POST['collection']][$_POST['record']] as $recid => $data) { |
131 | 131 | if (Request::hasVar('limiting', 'POST')) { |
132 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
132 | + if (true===Request::getInt('limiting', 0, 'POST')) { |
|
133 | 133 | ++$record; |
134 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
134 | + if ($record>Request::getInt('records', 0, 'POST')) { |
|
135 | 135 | $start = time(); |
136 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
136 | + while (time()-$start<Request::getInt('wait', 0, 'POST')) { |
|
137 | 137 | } |
138 | 138 | $records = 0; |
139 | 139 | } |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | } |
142 | 142 | $gid = 0; |
143 | 143 | $gids = []; |
144 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
145 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
144 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre'])>1) { |
|
145 | + if (isset($data[$_POST['genre']]) && ''!=trim($_POST['genre'])) { |
|
146 | 146 | foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
147 | 147 | $criteria = new \Criteria('name', trim($genre)); |
148 | - if ($genreHandler->getCount($criteria) > 0) { |
|
148 | + if ($genreHandler->getCount($criteria)>0) { |
|
149 | 149 | $objects = $genreHandler->getObjects($criteria, false); |
150 | 150 | $gid = $objects[0]->getVar('gid'); |
151 | 151 | } else { |
@@ -158,10 +158,10 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | $vcid = 0; |
161 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
162 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
161 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice'])>1) { |
|
162 | + if (isset($data[$_POST['voice']]) && ''!=trim($_POST['voice'])) { |
|
163 | 163 | $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
164 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
164 | + if ($voiceHandler->getCount($criteria)>0) { |
|
165 | 165 | $objects = $voiceHandler->getObjects($criteria, false); |
166 | 166 | $vcid = $objects[0]->getVar('vcid'); |
167 | 167 | } else { |
@@ -173,10 +173,10 @@ discard block |
||
173 | 173 | } |
174 | 174 | |
175 | 175 | $cid = 0; |
176 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
177 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
176 | + if (!empty($_POST['category']) && mb_strlen($_POST['category'])>1) { |
|
177 | + if (isset($data[$_POST['category']]) && ''!=trim($_POST['category'])) { |
|
178 | 178 | $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
179 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
179 | + if ($categoryHandler->getCount($criteria)>0) { |
|
180 | 180 | $objects = $categoryHandler->getObjects($criteria, false); |
181 | 181 | $cid = $objects[0]->getVar('cid'); |
182 | 182 | } else { |
@@ -187,11 +187,11 @@ discard block |
||
187 | 187 | } |
188 | 188 | } |
189 | 189 | $aids = []; |
190 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
191 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
190 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist'])>1) { |
|
191 | + if (isset($data[$_POST['artist']]) && ''!=$_POST['artist']) { |
|
192 | 192 | foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
193 | 193 | $criteria = new \Criteria('name', trim($artist)); |
194 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
194 | + if ($artistsHandler->getCount($criteria)>0) { |
|
195 | 195 | $objects = $artistsHandler->getObjects($criteria, false); |
196 | 196 | $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
197 | 197 | } else { |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | } |
205 | 205 | } |
206 | 206 | $abid = 0; |
207 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
208 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
207 | + if (!empty($_POST['album']) && mb_strlen($_POST['album'])>1) { |
|
208 | + if (isset($data[$_POST['album']]) && ''!=trim($_POST['album'])) { |
|
209 | 209 | $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
210 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
210 | + if ($albumsHandler->getCount($criteria)>0) { |
|
211 | 211 | $objects = $albumsHandler->getObjects($criteria, false); |
212 | 212 | $abid = $objects[0]->getVar('abid'); |
213 | 213 | } else { |
@@ -220,16 +220,16 @@ discard block |
||
220 | 220 | } |
221 | 221 | } |
222 | 222 | $sid = 0; |
223 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
224 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
223 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid'])>1) || (!empty($_POST['title']) && mb_strlen($_POST['title'])>1)) { |
|
224 | + if ((isset($data[$_POST['songid']]) && ''!=$_POST['songid']) || (isset($data[$_POST['title']]) && ''!=$_POST['title'])) { |
|
225 | 225 | $criteria = new \CriteriaCompo(); |
226 | - if ('' != trim($data[$_POST['songid']])) { |
|
226 | + if (''!=trim($data[$_POST['songid']])) { |
|
227 | 227 | $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
228 | 228 | } |
229 | - if ('' != trim($data[$_POST['title']])) { |
|
229 | + if (''!=trim($data[$_POST['title']])) { |
|
230 | 230 | $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
231 | 231 | } |
232 | - if ($songsHandler->getCount($criteria) > 0) { |
|
232 | + if ($songsHandler->getCount($criteria)>0) { |
|
233 | 233 | $objects = $songsHandler->getObjects($criteria, false); |
234 | 234 | $object = $objects[0]; |
235 | 235 | } else { |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
249 | 249 | $sid = $songsHandler->insert($object); |
250 | 250 | |
251 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
251 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH.'/modules/tag/class/tag.php')) { |
|
252 | 252 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
253 | 253 | $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
254 | 254 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
257 | 257 | $fields = $extrasHandler->getFields(null); |
258 | 258 | $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
259 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
259 | + if ($extrasHandler->getCount($criteria)>0) { |
|
260 | 260 | $extras = $extrasHandler->getObjects($criteria, false); |
261 | 261 | $extra = $extras[0]; |
262 | 262 | } else { |
@@ -264,13 +264,13 @@ discard block |
||
264 | 264 | } |
265 | 265 | $extra->setVar('sid', $sid); |
266 | 266 | foreach ($fields as $field) { |
267 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
268 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
267 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')])>1) { |
|
268 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && ''!=trim($_POST[$field->getVar('field_name')])) { |
|
269 | 269 | $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
270 | 270 | } |
271 | 271 | } |
272 | 272 | } |
273 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
273 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '('.implode(',', $aids).')', 'IN'), true) as $aid => $artist) { |
|
274 | 274 | $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
275 | 275 | $artistsHandler->insert($artist, true); |
276 | 276 | } |
@@ -280,11 +280,11 @@ discard block |
||
280 | 280 | } else { |
281 | 281 | foreach ($xmlarray[$_POST['collection']] as $id => $records) { |
282 | 282 | if (Request::hasVar('limiting', 'POST')) { |
283 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
283 | + if (true===Request::getInt('limiting', 0, 'POST')) { |
|
284 | 284 | ++$record; |
285 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
285 | + if ($record>Request::getInt('records', 0, 'POST')) { |
|
286 | 286 | $start = time(); |
287 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
287 | + while (time()-$start<Request::getInt('wait', 0, 'POST')) { |
|
288 | 288 | } |
289 | 289 | $records = 0; |
290 | 290 | } |
@@ -292,11 +292,11 @@ discard block |
||
292 | 292 | } |
293 | 293 | $gid = 0; |
294 | 294 | $gids = []; |
295 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
296 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
295 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre'])>1) { |
|
296 | + if (isset($data[$_POST['genre']]) && ''!=trim($_POST['genre'])) { |
|
297 | 297 | foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
298 | 298 | $criteria = new \Criteria('name', trim($genre)); |
299 | - if ($genreHandler->getCount($criteria) > 0) { |
|
299 | + if ($genreHandler->getCount($criteria)>0) { |
|
300 | 300 | $objects = $genreHandler->getObjects($criteria, false); |
301 | 301 | $gid = $objects[0]->getVar('gid'); |
302 | 302 | } else { |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | } |
309 | 309 | } |
310 | 310 | } |
311 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
312 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
311 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice'])>1) { |
|
312 | + if (isset($data[$_POST['voice']]) && ''!=trim($_POST['voice'])) { |
|
313 | 313 | $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
314 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
314 | + if ($voiceHandler->getCount($criteria)>0) { |
|
315 | 315 | $objects = $voiceHandler->getObjects($criteria, false); |
316 | 316 | $vcid = $objects[0]->getVar('vcid'); |
317 | 317 | } else { |
@@ -322,10 +322,10 @@ discard block |
||
322 | 322 | } |
323 | 323 | } |
324 | 324 | $cid = 0; |
325 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
326 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
325 | + if (!empty($_POST['category']) && mb_strlen($_POST['category'])>1) { |
|
326 | + if (isset($data[$_POST['category']]) && ''!=trim($_POST['category'])) { |
|
327 | 327 | $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
328 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
328 | + if ($categoryHandler->getCount($criteria)>0) { |
|
329 | 329 | $objects = $categoryHandler->getObjects($criteria, false); |
330 | 330 | $cid = $objects[0]->getVar('cid'); |
331 | 331 | } else { |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | } |
337 | 337 | } |
338 | 338 | $aids = []; |
339 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
340 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
339 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist'])>1) { |
|
340 | + if (isset($data[$_POST['artist']]) && ''!=$_POST['artist']) { |
|
341 | 341 | foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
342 | 342 | $criteria = new \Criteria('name', trim($artist)); |
343 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
343 | + if ($artistsHandler->getCount($criteria)>0) { |
|
344 | 344 | $objects = $artistsHandler->getObjects($criteria, false); |
345 | 345 | $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
346 | 346 | } else { |
@@ -354,10 +354,10 @@ discard block |
||
354 | 354 | } |
355 | 355 | } |
356 | 356 | $abid = 0; |
357 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
358 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
357 | + if (!empty($_POST['album']) && mb_strlen($_POST['album'])>1) { |
|
358 | + if (isset($data[$_POST['album']]) && ''!=trim($_POST['album'])) { |
|
359 | 359 | $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
360 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
360 | + if ($albumsHandler->getCount($criteria)>0) { |
|
361 | 361 | $objects = $albumsHandler->getObjects($criteria, false); |
362 | 362 | $abid = $objects[0]->getVar('abid'); |
363 | 363 | } else { |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | } |
371 | 371 | } |
372 | 372 | $sid = 0; |
373 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
374 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
373 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid'])>1) || (!empty($_POST['title']) && mb_strlen($_POST['title'])>1)) { |
|
374 | + if ((isset($data[$_POST['songid']]) && ''!=$_POST['songid']) || (isset($data[$_POST['title']]) && ''!=$_POST['title'])) { |
|
375 | 375 | $criteria = new \CriteriaCompo(); |
376 | - if ('' != trim($data[$_POST['songid']])) { |
|
376 | + if (''!=trim($data[$_POST['songid']])) { |
|
377 | 377 | $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
378 | 378 | } |
379 | - if ('' != trim($data[$_POST['title']])) { |
|
379 | + if (''!=trim($data[$_POST['title']])) { |
|
380 | 380 | $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
381 | 381 | } |
382 | - if ($songsHandler->getCount($criteria) > 0) { |
|
382 | + if ($songsHandler->getCount($criteria)>0) { |
|
383 | 383 | $objects = $songsHandler->getObjects($criteria, false); |
384 | 384 | $object = $objects[0]; |
385 | 385 | } else { |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
399 | 399 | $sid = $songsHandler->insert($object); |
400 | 400 | |
401 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
401 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH.'/modules/tag/class/tag.php')) { |
|
402 | 402 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
403 | 403 | $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
404 | 404 | } |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
407 | 407 | $fields = $extrasHandler->getFields(null); |
408 | 408 | $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
409 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
409 | + if ($extrasHandler->getCount($criteria)>0) { |
|
410 | 410 | $extras = $extrasHandler->getObjects($criteria, false); |
411 | 411 | $extra = $extras[0]; |
412 | 412 | } else { |
@@ -414,14 +414,14 @@ discard block |
||
414 | 414 | } |
415 | 415 | $extra->setVar('sid', $sid); |
416 | 416 | foreach ($fields as $field) { |
417 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
418 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
417 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')])>1) { |
|
418 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && ''!=trim($_POST[$field->getVar('field_name')])) { |
|
419 | 419 | $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
420 | 420 | } |
421 | 421 | } |
422 | 422 | } |
423 | 423 | $extrasHandler->insert($extra, true); |
424 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
424 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '('.implode(',', $aids).')', 'IN'), true) as $aid => $artist) { |
|
425 | 425 | $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
426 | 426 | $artistsHandler->insert($artist, true); |
427 | 427 | } |
@@ -437,11 +437,11 @@ discard block |
||
437 | 437 | $aids = []; |
438 | 438 | $abid = []; |
439 | 439 | if (Request::hasVar('limiting', 'POST')) { |
440 | - if (true === Request::getInt('limiting', 0, 'POST')) { |
|
440 | + if (true===Request::getInt('limiting', 0, 'POST')) { |
|
441 | 441 | ++$record; |
442 | - if ($record > Request::getInt('records', 0, 'POST')) { |
|
442 | + if ($record>Request::getInt('records', 0, 'POST')) { |
|
443 | 443 | $start = time(); |
444 | - while (time() - $start < Request::getInt('wait', 0, 'POST')) { |
|
444 | + while (time()-$start<Request::getInt('wait', 0, 'POST')) { |
|
445 | 445 | } |
446 | 446 | $records = 0; |
447 | 447 | } |
@@ -449,11 +449,11 @@ discard block |
||
449 | 449 | } |
450 | 450 | $gid = 0; |
451 | 451 | $gids = []; |
452 | - if (!empty($_POST['genre']) && mb_strlen($_POST['genre']) > 1) { |
|
453 | - if (isset($data[$_POST['genre']]) && '' != trim($_POST['genre'])) { |
|
452 | + if (!empty($_POST['genre']) && mb_strlen($_POST['genre'])>1) { |
|
453 | + if (isset($data[$_POST['genre']]) && ''!=trim($_POST['genre'])) { |
|
454 | 454 | foreach (explode(',', trim($data[$_POST['genre']])) as $genre) { |
455 | 455 | $criteria = new \Criteria('name', trim($genre)); |
456 | - if ($genreHandler->getCount($criteria) > 0) { |
|
456 | + if ($genreHandler->getCount($criteria)>0) { |
|
457 | 457 | $objects = $genreHandler->getObjects($criteria, false); |
458 | 458 | $gid = $objects[0]->getVar('gid'); |
459 | 459 | } else { |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | } |
468 | 468 | |
469 | 469 | $vcid = 0; |
470 | - if (!empty($_POST['voice']) && mb_strlen($_POST['voice']) > 1) { |
|
471 | - if (isset($data[$_POST['voice']]) && '' != trim($_POST['voice'])) { |
|
470 | + if (!empty($_POST['voice']) && mb_strlen($_POST['voice'])>1) { |
|
471 | + if (isset($data[$_POST['voice']]) && ''!=trim($_POST['voice'])) { |
|
472 | 472 | $criteria = new \Criteria('name', trim($data[$_POST['voice']])); |
473 | - if ($voiceHandler->getCount($criteria) > 0) { |
|
473 | + if ($voiceHandler->getCount($criteria)>0) { |
|
474 | 474 | $objects = $voiceHandler->getObjects($criteria, false); |
475 | 475 | $vcid = $objects[0]->getVar('vcid'); |
476 | 476 | } else { |
@@ -481,10 +481,10 @@ discard block |
||
481 | 481 | } |
482 | 482 | } |
483 | 483 | $cid = 0; |
484 | - if (!empty($_POST['category']) && mb_strlen($_POST['category']) > 1) { |
|
485 | - if (isset($data[$_POST['category']]) && '' != trim($_POST['category'])) { |
|
484 | + if (!empty($_POST['category']) && mb_strlen($_POST['category'])>1) { |
|
485 | + if (isset($data[$_POST['category']]) && ''!=trim($_POST['category'])) { |
|
486 | 486 | $criteria = new \Criteria('name', trim($data[$_POST['category']])); |
487 | - if ($categoryHandler->getCount($criteria) > 0) { |
|
487 | + if ($categoryHandler->getCount($criteria)>0) { |
|
488 | 488 | $objects = $categoryHandler->getObjects($criteria, false); |
489 | 489 | $cid = $objects[0]->getVar('cid'); |
490 | 490 | } else { |
@@ -495,11 +495,11 @@ discard block |
||
495 | 495 | } |
496 | 496 | } |
497 | 497 | $aids = []; |
498 | - if (!empty($_POST['artist']) && mb_strlen($_POST['artist']) > 1) { |
|
499 | - if (isset($data[$_POST['artist']]) && '' != $_POST['artist']) { |
|
498 | + if (!empty($_POST['artist']) && mb_strlen($_POST['artist'])>1) { |
|
499 | + if (isset($data[$_POST['artist']]) && ''!=$_POST['artist']) { |
|
500 | 500 | foreach (explode(',', trim($data[$_POST['artist']])) as $artist) { |
501 | 501 | $criteria = new \Criteria('name', trim($artist)); |
502 | - if ($artistsHandler->getCount($criteria) > 0) { |
|
502 | + if ($artistsHandler->getCount($criteria)>0) { |
|
503 | 503 | $objects = $artistsHandler->getObjects($criteria, false); |
504 | 504 | $aids[$objects[0]->getVar('aid')] = $objects[0]->getVar('aid'); |
505 | 505 | } else { |
@@ -513,10 +513,10 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | $abid = 0; |
516 | - if (!empty($_POST['album']) && mb_strlen($_POST['album']) > 1) { |
|
517 | - if (isset($data[$_POST['album']]) && '' != trim($_POST['album'])) { |
|
516 | + if (!empty($_POST['album']) && mb_strlen($_POST['album'])>1) { |
|
517 | + if (isset($data[$_POST['album']]) && ''!=trim($_POST['album'])) { |
|
518 | 518 | $criteria = new \Criteria('title', trim($data[$_POST['album']])); |
519 | - if ($albumsHandler->getCount($criteria) > 0) { |
|
519 | + if ($albumsHandler->getCount($criteria)>0) { |
|
520 | 520 | $objects = $albumsHandler->getObjects($criteria, false); |
521 | 521 | $abid = $objects[0]->getVar('abid'); |
522 | 522 | } else { |
@@ -529,16 +529,16 @@ discard block |
||
529 | 529 | } |
530 | 530 | } |
531 | 531 | $sid = 0; |
532 | - if ((!empty($_POST['songid']) && mb_strlen($_POST['songid']) > 1) || (!empty($_POST['title']) && mb_strlen($_POST['title']) > 1)) { |
|
533 | - if ((isset($data[$_POST['songid']]) && '' != $_POST['songid']) || (isset($data[$_POST['title']]) && '' != $_POST['title'])) { |
|
532 | + if ((!empty($_POST['songid']) && mb_strlen($_POST['songid'])>1) || (!empty($_POST['title']) && mb_strlen($_POST['title'])>1)) { |
|
533 | + if ((isset($data[$_POST['songid']]) && ''!=$_POST['songid']) || (isset($data[$_POST['title']]) && ''!=$_POST['title'])) { |
|
534 | 534 | $criteria = new \CriteriaCompo(); |
535 | - if ('' != trim($data[$_POST['songid']])) { |
|
535 | + if (''!=trim($data[$_POST['songid']])) { |
|
536 | 536 | $criteria->add(new \Criteria('songid', trim($data[$_POST['songid']]))); |
537 | 537 | } |
538 | - if ('' != trim($data[$_POST['title']])) { |
|
538 | + if (''!=trim($data[$_POST['title']])) { |
|
539 | 539 | $criteria->add(new \Criteria('title', trim($data[$_POST['title']]))); |
540 | 540 | } |
541 | - if ($songsHandler->getCount($criteria) > 0) { |
|
541 | + if ($songsHandler->getCount($criteria)>0) { |
|
542 | 542 | $objects = $songsHandler->getObjects($criteria, false); |
543 | 543 | $object = $objects[0]; |
544 | 544 | } else { |
@@ -557,7 +557,7 @@ discard block |
||
557 | 557 | $object->setVar('lyrics', str_replace("\n", "<br>\n", trim($data[$_POST['lyrics']]))); |
558 | 558 | $sid = $songsHandler->insert($object); |
559 | 559 | |
560 | - if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH . '/modules/tag/class/tag.php')) { |
|
560 | + if ($GLOBALS['songlistModuleConfig']['tags'] && file_exists(XOOPS_ROOT_PATH.'/modules/tag/class/tag.php')) { |
|
561 | 561 | $tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); |
562 | 562 | $tagHandler->updateByItem(trim($data[$_POST['tags']]), $sid, $GLOBALS['songlistModule']->getVar('dirname'), $cid); |
563 | 563 | } |
@@ -565,7 +565,7 @@ discard block |
||
565 | 565 | $extrasHandler = Helper::getInstance()->getHandler('Extras'); |
566 | 566 | $fields = $extrasHandler->getFields(null); |
567 | 567 | $criteria = new \CriteriaCompo(new \Criteria('sid', $sid)); |
568 | - if ($extrasHandler->getCount($criteria) > 0) { |
|
568 | + if ($extrasHandler->getCount($criteria)>0) { |
|
569 | 569 | $extras = $extrasHandler->getObjects($criteria, false); |
570 | 570 | $extra = $extras[0]; |
571 | 571 | } else { |
@@ -573,13 +573,13 @@ discard block |
||
573 | 573 | } |
574 | 574 | $extra->setVar('sid', $sid); |
575 | 575 | foreach ($fields as $field) { |
576 | - if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')]) > 1) { |
|
577 | - if (isset($data[$_POST[$field->getVar('field_name')]]) && '' != trim($_POST[$field->getVar('field_name')])) { |
|
576 | + if (!empty($_POST[$field->getVar('field_name')]) && mb_strlen($_POST[$field->getVar('field_name')])>1) { |
|
577 | + if (isset($data[$_POST[$field->getVar('field_name')]]) && ''!=trim($_POST[$field->getVar('field_name')])) { |
|
578 | 578 | $extra->setVar($field->getVar('field_name'), trim($data[$_POST[$field->getVar('field_name')]])); |
579 | 579 | } |
580 | 580 | } |
581 | 581 | } |
582 | - foreach ($artistsHandler->getObjects(new \Criteria('aid', '(' . implode(',', $aids) . ')', 'IN'), true) as $aid => $artist) { |
|
582 | + foreach ($artistsHandler->getObjects(new \Criteria('aid', '('.implode(',', $aids).')', 'IN'), true) as $aid => $artist) { |
|
583 | 583 | $artist->setVar('sids', array_merge($artist->getVar('sids'), [$sid => $sid])); |
584 | 584 | $artistsHandler->insert($artist, true); |
585 | 585 | } |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | } |
588 | 588 | } |
589 | 589 | } |
590 | - unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'] . $_SESSION['xmlfile'])); |
|
590 | + unlink($GLOBALS['xoops']->path($GLOBALS['songlistModuleConfig']['upload_areas'].$_SESSION['xmlfile'])); |
|
591 | 591 | unset($_SESSION['xmlfile']); |
592 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
592 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op=import&fct=actiona', 10, _AM_SONGLIST_XMLFILE_COMPLETE); |
|
593 | 593 | break; |
594 | 594 | } |
595 | 595 | break; |
@@ -3,10 +3,10 @@ discard block |
||
3 | 3 | use Xmf\Module\Admin; |
4 | 4 | use Xmf\Request; |
5 | 5 | use XoopsModules\Songlist\{ |
6 | - Helper, |
|
7 | - Genre, |
|
8 | - GenreHandler, |
|
9 | - Form\FormController |
|
6 | + Helper, |
|
7 | + Genre, |
|
8 | + GenreHandler, |
|
9 | + Form\FormController |
|
10 | 10 | }; |
11 | 11 | |
12 | 12 | /** @var Genre $genre */ |
@@ -26,156 +26,156 @@ discard block |
||
26 | 26 | $filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
27 | 27 | |
28 | 28 | switch ($op) { |
29 | - default: |
|
30 | - case 'genre': |
|
31 | - switch ($fct) { |
|
32 | - default: |
|
33 | - case 'list': |
|
34 | - $adminObject = Admin::getInstance(); |
|
35 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | - |
|
37 | - /** @var GenreHandler $genreHandler */ |
|
38 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
39 | - |
|
40 | - $criteria = $genreHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | - $ttl = $genreHandler->getCount($criteria); |
|
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | - |
|
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | - $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | - |
|
47 | - foreach ($genreHandler->filterFields() as $id => $key) { |
|
48 | - $GLOBALS['xoopsTpl']->assign( |
|
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | - '<a href="' |
|
51 | - . $_SERVER['SCRIPT_NAME'] |
|
52 | - . '?start=' |
|
53 | - . $GLOBALS['start'] |
|
54 | - . '&limit=' |
|
55 | - . $GLOBALS['limit'] |
|
56 | - . '&sort=' |
|
57 | - . $key |
|
58 | - . '&order=' |
|
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | - . '&op=' |
|
61 | - . $GLOBALS['op'] |
|
62 | - . '&filter=' |
|
63 | - . $GLOBALS['filter'] |
|
64 | - . '">' |
|
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | - . '</a>' |
|
67 | - ); |
|
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $genreHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | - } |
|
70 | - |
|
71 | - $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | - $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | - $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | - $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | - $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | - $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | - |
|
78 | - $criteria->setStart($GLOBALS['start']); |
|
79 | - $criteria->setLimit($GLOBALS['limit']); |
|
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | - $criteria->setOrder($GLOBALS['order']); |
|
82 | - |
|
83 | - $genres = $genreHandler->getObjects($criteria, true); |
|
84 | - foreach ($genres as $cid => $genre) { |
|
85 | - if (is_object($genre)) { |
|
86 | - $GLOBALS['xoopsTpl']->append('genre', $genre->toArray()); |
|
87 | - } |
|
88 | - } |
|
89 | - $GLOBALS['xoopsTpl']->assign('form', FormController::getFormGenre(false)); |
|
90 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_genre_list.tpl'); |
|
92 | - break; |
|
93 | - case 'new': |
|
94 | - case 'edit': |
|
95 | - $adminObject = Admin::getInstance(); |
|
96 | - $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | - |
|
98 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
99 | - if (Request::hasVar('id', 'REQUEST')) { |
|
100 | - $genre = $genreHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | - } else { |
|
102 | - $genre = $genreHandler->create(); |
|
103 | - } |
|
104 | - |
|
105 | - $GLOBALS['xoopsTpl']->assign('form', $genre->getForm()); |
|
106 | - $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | - $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_genre_edit.tpl'); |
|
108 | - break; |
|
109 | - case 'save': |
|
110 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
111 | - $id = 0; |
|
112 | - $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | - if ($id) { |
|
114 | - $genre = $genreHandler->get($id); |
|
115 | - } else { |
|
116 | - $genre = $genreHandler->create(); |
|
117 | - } |
|
118 | - $genre->setVars($_POST[$id]); |
|
119 | - |
|
120 | - if (!$id = $genreHandler->insert($genre)) { |
|
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE); |
|
122 | - exit(0); |
|
123 | - } |
|
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | - redirect_header( |
|
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | - 10, |
|
128 | - _AM_SONGLIST_MSG_GENRE_SAVEDOKEY |
|
129 | - ); |
|
130 | - } else { |
|
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
132 | - } |
|
133 | - exit(0); |
|
134 | - |
|
135 | - break; |
|
136 | - case 'savelist': |
|
137 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
138 | - foreach ($_REQUEST['id'] as $id) { |
|
139 | - $genre = $genreHandler->get($id); |
|
140 | - $genre->setVars($_POST[$id]); |
|
141 | - if (!$genreHandler->insert($genre)) { |
|
142 | - redirect_header( |
|
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | - 10, |
|
145 | - _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE |
|
146 | - ); |
|
147 | - exit(0); |
|
148 | - } |
|
149 | - } |
|
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
151 | - exit(0); |
|
152 | - break; |
|
153 | - case 'delete': |
|
154 | - $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
155 | - $id = 0; |
|
156 | - if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | - $genre = $genreHandler->get($id); |
|
158 | - if (!$genreHandler->delete($genre)) { |
|
159 | - redirect_header( |
|
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | - 10, |
|
162 | - _AM_SONGLIST_MSG_GENRE_FAILEDTODELETE |
|
163 | - ); |
|
164 | - exit(0); |
|
165 | - } |
|
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_DELETED); |
|
167 | - exit(0); |
|
168 | - } |
|
169 | - $genre = $genreHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | - xoops_confirm( |
|
171 | - ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | - $_SERVER['SCRIPT_NAME'], |
|
173 | - sprintf(_AM_SONGLIST_MSG_GENRE_DELETE, $genre->getVar('name')) |
|
174 | - ); |
|
175 | - |
|
176 | - break; |
|
177 | - } |
|
178 | - break; |
|
29 | + default: |
|
30 | + case 'genre': |
|
31 | + switch ($fct) { |
|
32 | + default: |
|
33 | + case 'list': |
|
34 | + $adminObject = Admin::getInstance(); |
|
35 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
36 | + |
|
37 | + /** @var GenreHandler $genreHandler */ |
|
38 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
39 | + |
|
40 | + $criteria = $genreHandler->getFilterCriteria($GLOBALS['filter']); |
|
41 | + $ttl = $genreHandler->getCount($criteria); |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
43 | + |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
45 | + $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
|
46 | + |
|
47 | + foreach ($genreHandler->filterFields() as $id => $key) { |
|
48 | + $GLOBALS['xoopsTpl']->assign( |
|
49 | + \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
50 | + '<a href="' |
|
51 | + . $_SERVER['SCRIPT_NAME'] |
|
52 | + . '?start=' |
|
53 | + . $GLOBALS['start'] |
|
54 | + . '&limit=' |
|
55 | + . $GLOBALS['limit'] |
|
56 | + . '&sort=' |
|
57 | + . $key |
|
58 | + . '&order=' |
|
59 | + . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | + . '&op=' |
|
61 | + . $GLOBALS['op'] |
|
62 | + . '&filter=' |
|
63 | + . $GLOBALS['filter'] |
|
64 | + . '">' |
|
65 | + . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | + . '</a>' |
|
67 | + ); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $genreHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | + } |
|
70 | + |
|
71 | + $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
|
72 | + $GLOBALS['xoopsTpl']->assign('start', $GLOBALS['start']); |
|
73 | + $GLOBALS['xoopsTpl']->assign('order', $GLOBALS['order']); |
|
74 | + $GLOBALS['xoopsTpl']->assign('sort', $GLOBALS['sort']); |
|
75 | + $GLOBALS['xoopsTpl']->assign('filter', $GLOBALS['filter']); |
|
76 | + $GLOBALS['xoopsTpl']->assign('xoConfig', $GLOBALS['songlistModuleConfig']); |
|
77 | + |
|
78 | + $criteria->setStart($GLOBALS['start']); |
|
79 | + $criteria->setLimit($GLOBALS['limit']); |
|
80 | + $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
81 | + $criteria->setOrder($GLOBALS['order']); |
|
82 | + |
|
83 | + $genres = $genreHandler->getObjects($criteria, true); |
|
84 | + foreach ($genres as $cid => $genre) { |
|
85 | + if (is_object($genre)) { |
|
86 | + $GLOBALS['xoopsTpl']->append('genre', $genre->toArray()); |
|
87 | + } |
|
88 | + } |
|
89 | + $GLOBALS['xoopsTpl']->assign('form', FormController::getFormGenre(false)); |
|
90 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
91 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_genre_list.tpl'); |
|
92 | + break; |
|
93 | + case 'new': |
|
94 | + case 'edit': |
|
95 | + $adminObject = Admin::getInstance(); |
|
96 | + $adminObject->displayNavigation(basename(__FILE__)); |
|
97 | + |
|
98 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
99 | + if (Request::hasVar('id', 'REQUEST')) { |
|
100 | + $genre = $genreHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
101 | + } else { |
|
102 | + $genre = $genreHandler->create(); |
|
103 | + } |
|
104 | + |
|
105 | + $GLOBALS['xoopsTpl']->assign('form', $genre->getForm()); |
|
106 | + $GLOBALS['xoopsTpl']->assign('php_self', $_SERVER['SCRIPT_NAME']); |
|
107 | + $GLOBALS['xoopsTpl']->display('db:songlist_cpanel_genre_edit.tpl'); |
|
108 | + break; |
|
109 | + case 'save': |
|
110 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
111 | + $id = 0; |
|
112 | + $id = Request::getInt('id', 0, 'REQUEST'); |
|
113 | + if ($id) { |
|
114 | + $genre = $genreHandler->get($id); |
|
115 | + } else { |
|
116 | + $genre = $genreHandler->create(); |
|
117 | + } |
|
118 | + $genre->setVars($_POST[$id]); |
|
119 | + |
|
120 | + if (!$id = $genreHandler->insert($genre)) { |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE); |
|
122 | + exit(0); |
|
123 | + } |
|
124 | + if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | + redirect_header( |
|
126 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
127 | + 10, |
|
128 | + _AM_SONGLIST_MSG_GENRE_SAVEDOKEY |
|
129 | + ); |
|
130 | + } else { |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
132 | + } |
|
133 | + exit(0); |
|
134 | + |
|
135 | + break; |
|
136 | + case 'savelist': |
|
137 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
138 | + foreach ($_REQUEST['id'] as $id) { |
|
139 | + $genre = $genreHandler->get($id); |
|
140 | + $genre->setVars($_POST[$id]); |
|
141 | + if (!$genreHandler->insert($genre)) { |
|
142 | + redirect_header( |
|
143 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
144 | + 10, |
|
145 | + _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE |
|
146 | + ); |
|
147 | + exit(0); |
|
148 | + } |
|
149 | + } |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
151 | + exit(0); |
|
152 | + break; |
|
153 | + case 'delete': |
|
154 | + $genreHandler = Helper::getInstance()->getHandler('Genre'); |
|
155 | + $id = 0; |
|
156 | + if (Request::hasVar('id', 'POST') && $id = Request::getInt('id', 0, 'POST')) { |
|
157 | + $genre = $genreHandler->get($id); |
|
158 | + if (!$genreHandler->delete($genre)) { |
|
159 | + redirect_header( |
|
160 | + $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
161 | + 10, |
|
162 | + _AM_SONGLIST_MSG_GENRE_FAILEDTODELETE |
|
163 | + ); |
|
164 | + exit(0); |
|
165 | + } |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_DELETED); |
|
167 | + exit(0); |
|
168 | + } |
|
169 | + $genre = $genreHandler->get(Request::getInt('id', 0, 'REQUEST')); |
|
170 | + xoops_confirm( |
|
171 | + ['id' => $_REQUEST['id'], 'op' => $_REQUEST['op'], 'fct' => $_REQUEST['fct'], 'limit' => $_REQUEST['limit'], 'start' => $_REQUEST['start'], 'order' => $_REQUEST['order'], 'sort' => $_REQUEST['sort'], 'filter' => $_REQUEST['filter']], |
|
172 | + $_SERVER['SCRIPT_NAME'], |
|
173 | + sprintf(_AM_SONGLIST_MSG_GENRE_DELETE, $genre->getVar('name')) |
|
174 | + ); |
|
175 | + |
|
176 | + break; |
|
177 | + } |
|
178 | + break; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | xoops_cp_footer(); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | /** @var Genre $genre */ |
13 | 13 | |
14 | -require __DIR__ . '/header.php'; |
|
14 | +require __DIR__.'/header.php'; |
|
15 | 15 | |
16 | 16 | xoops_loadLanguage('admin', 'songlist'); |
17 | 17 | |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | $limit = Request::getInt('limit', 30, 'REQUEST'); |
23 | 23 | $start = Request::getInt('start', 0, 'REQUEST'); |
24 | 24 | $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'DESC'; |
25 | -$sort = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
26 | -$filter = !empty($_REQUEST['filter']) ? '' . $_REQUEST['filter'] . '' : '1,1'; |
|
25 | +$sort = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
26 | +$filter = !empty($_REQUEST['filter']) ? ''.$_REQUEST['filter'].'' : '1,1'; |
|
27 | 27 | |
28 | 28 | switch ($op) { |
29 | 29 | default: |
@@ -39,14 +39,14 @@ discard block |
||
39 | 39 | |
40 | 40 | $criteria = $genreHandler->getFilterCriteria($GLOBALS['filter']); |
41 | 41 | $ttl = $genreHandler->getCount($criteria); |
42 | - $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? '' . $_REQUEST['sort'] . '' : 'created'; |
|
42 | + $GLOBALS['sort'] = !empty($_REQUEST['sort']) ? ''.$_REQUEST['sort'].'' : 'created'; |
|
43 | 43 | |
44 | - $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit=' . $GLOBALS['limit'] . '&sort=' . $GLOBALS['sort'] . '&order=' . $GLOBALS['order'] . '&op=' . $GLOBALS['op'] . '&fct=' . $GLOBALS['fct'] . '&filter=' . $GLOBALS['filter']); |
|
44 | + $pagenav = new \XoopsPageNav($ttl, $GLOBALS['limit'], $GLOBALS['start'], 'start', 'limit='.$GLOBALS['limit'].'&sort='.$GLOBALS['sort'].'&order='.$GLOBALS['order'].'&op='.$GLOBALS['op'].'&fct='.$GLOBALS['fct'].'&filter='.$GLOBALS['filter']); |
|
45 | 45 | $GLOBALS['xoopsTpl']->assign('pagenav', $pagenav->renderNav()); |
46 | 46 | |
47 | 47 | foreach ($genreHandler->filterFields() as $id => $key) { |
48 | 48 | $GLOBALS['xoopsTpl']->assign( |
49 | - \mb_strtolower(str_replace('-', '_', $key) . '_th'), |
|
49 | + \mb_strtolower(str_replace('-', '_', $key).'_th'), |
|
50 | 50 | '<a href="' |
51 | 51 | . $_SERVER['SCRIPT_NAME'] |
52 | 52 | . '?start=' |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | . '&sort=' |
57 | 57 | . $key |
58 | 58 | . '&order=' |
59 | - . (($key == $GLOBALS['sort']) ? ('DESC' === $GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
59 | + . (($key==$GLOBALS['sort']) ? ('DESC'===$GLOBALS['order'] ? 'ASC' : 'DESC') : $GLOBALS['order']) |
|
60 | 60 | . '&op=' |
61 | 61 | . $GLOBALS['op'] |
62 | 62 | . '&filter=' |
63 | 63 | . $GLOBALS['filter'] |
64 | 64 | . '">' |
65 | - . (defined('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_' . \mb_strtoupper(str_replace('-', '_', $key))) |
|
65 | + . (defined('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) ? constant('_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) : '_AM_SONGLIST_TH_'.\mb_strtoupper(str_replace('-', '_', $key))) |
|
66 | 66 | . '</a>' |
67 | 67 | ); |
68 | - $GLOBALS['xoopsTpl']->assign('filter_' . \mb_strtolower(str_replace('-', '_', $key)) . '_th', $genreHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
68 | + $GLOBALS['xoopsTpl']->assign('filter_'.\mb_strtolower(str_replace('-', '_', $key)).'_th', $genreHandler->getFilterForm($GLOBALS['filter'], $key, $GLOBALS['sort'], $GLOBALS['op'], $GLOBALS['fct'])); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | $GLOBALS['xoopsTpl']->assign('limit', $GLOBALS['limit']); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | |
78 | 78 | $criteria->setStart($GLOBALS['start']); |
79 | 79 | $criteria->setLimit($GLOBALS['limit']); |
80 | - $criteria->setSort('`' . $GLOBALS['sort'] . '`'); |
|
80 | + $criteria->setSort('`'.$GLOBALS['sort'].'`'); |
|
81 | 81 | $criteria->setOrder($GLOBALS['order']); |
82 | 82 | |
83 | 83 | $genres = $genreHandler->getObjects($criteria, true); |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | $genre->setVars($_POST[$id]); |
119 | 119 | |
120 | 120 | if (!$id = $genreHandler->insert($genre)) { |
121 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE); |
|
121 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE); |
|
122 | 122 | exit(0); |
123 | 123 | } |
124 | - if ('new' === $_REQUEST['state'][$_REQUEST['id']]) { |
|
124 | + if ('new'===$_REQUEST['state'][$_REQUEST['id']]) { |
|
125 | 125 | redirect_header( |
126 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=edit&id=' . $_REQUEST['id'] . '&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
126 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=edit&id='.$_REQUEST['id'].'&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
127 | 127 | 10, |
128 | 128 | _AM_SONGLIST_MSG_GENRE_SAVEDOKEY |
129 | 129 | ); |
130 | 130 | } else { |
131 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
131 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
132 | 132 | } |
133 | 133 | exit(0); |
134 | 134 | |
@@ -140,14 +140,14 @@ discard block |
||
140 | 140 | $genre->setVars($_POST[$id]); |
141 | 141 | if (!$genreHandler->insert($genre)) { |
142 | 142 | redirect_header( |
143 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
143 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
144 | 144 | 10, |
145 | 145 | _AM_SONGLIST_MSG_GENRE_FAILEDTOSAVE |
146 | 146 | ); |
147 | 147 | exit(0); |
148 | 148 | } |
149 | 149 | } |
150 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
150 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_SAVEDOKEY); |
|
151 | 151 | exit(0); |
152 | 152 | break; |
153 | 153 | case 'delete': |
@@ -157,13 +157,13 @@ discard block |
||
157 | 157 | $genre = $genreHandler->get($id); |
158 | 158 | if (!$genreHandler->delete($genre)) { |
159 | 159 | redirect_header( |
160 | - $_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], |
|
160 | + $_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], |
|
161 | 161 | 10, |
162 | 162 | _AM_SONGLIST_MSG_GENRE_FAILEDTODELETE |
163 | 163 | ); |
164 | 164 | exit(0); |
165 | 165 | } |
166 | - redirect_header($_SERVER['SCRIPT_NAME'] . '?op=' . $GLOBALS['op'] . '&fct=list&limit=' . $GLOBALS['limit'] . '&start=' . $GLOBALS['start'] . '&order=' . $GLOBALS['order'] . '&sort=' . $GLOBALS['sort'] . '&filter=' . $GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_DELETED); |
|
166 | + redirect_header($_SERVER['SCRIPT_NAME'].'?op='.$GLOBALS['op'].'&fct=list&limit='.$GLOBALS['limit'].'&start='.$GLOBALS['start'].'&order='.$GLOBALS['order'].'&sort='.$GLOBALS['sort'].'&filter='.$GLOBALS['filter'], 10, _AM_SONGLIST_MSG_GENRE_DELETED); |
|
167 | 167 | exit(0); |
168 | 168 | } |
169 | 169 | $genre = $genreHandler->get(Request::getInt('id', 0, 'REQUEST')); |