Passed
Push — develop ( 005e98...b920bf )
by axel
02:00
created

getStat()   C

Complexity

Conditions 13
Paths 33

Size

Total Lines 133
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
eloc 77
nc 33
nop 2
dl 0
loc 133
rs 5.7951
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace scraper;
4
5
define('MAX_FILE_SIZE', 100000000);
6
7
use DateTime;
8
use Sunra\PhpSimple\HtmlDomParser;
9
10
function getTopAnimeType($type)
11
{
12
    $converted_type = '';
13
    switch ($type) {
14
        case '0':
15
            $converted_type = '';
16
            break;
17
        case '1':
18
            $converted_type = 'airing';
19
            break;
20
        case '2':
21
            $converted_type = 'upcoming';
22
            break;
23
        case '3':
24
            $converted_type = 'tv';
25
            break;
26
        case '4':
27
            $converted_type = 'movie';
28
            break;
29
        case '5':
30
            $converted_type = 'ova';
31
            break;
32
        case '6':
33
            $converted_type = 'special';
34
            break;
35
        case '7':
36
            $converted_type = 'bypopularity';
37
            break;
38
        case '8':
39
            $converted_type = 'favorite';
40
            break;
41
        default:
42
            $converted_type = '';
43
    }
44
45
    return $converted_type;
46
}
47
48
function getTopMangaType($type)
49
{
50
    $converted_type = '';
51
    switch ($type) {
52
        case '0':
53
            $converted_type = '';
54
            break;
55
        case '1':
56
            $converted_type = 'manga';
57
            break;
58
        case '2':
59
            $converted_type = 'novels';
60
            break;
61
        case '3':
62
            $converted_type = 'oneshots';
63
            break;
64
        case '4':
65
            $converted_type = 'doujin';
66
            break;
67
        case '5':
68
            $converted_type = 'manhwa';
69
            break;
70
        case '6':
71
            $converted_type = 'manhua';
72
            break;
73
        case '7':
74
            $converted_type = 'bypopularity';
75
            break;
76
        case '8':
77
            $converted_type = 'favorite';
78
            break;
79
        default:
80
            $converted_type = '';
81
    }
82
83
    return $converted_type;
84
}
85
86
function getCurrentSeason()
87
{
88
    $day = new DateTime();
89
90
    //  Days of spring
91
    $spring_starts = new DateTime('April 1');
92
    $spring_ends = new DateTime('June 30');
93
94
    //  Days of summer
95
    $summer_starts = new DateTime('July 1');
96
    $summer_ends = new DateTime('September 30');
97
98
    //  Days of autumn
99
    $autumn_starts = new DateTime('October 1');
100
    $autumn_ends = new DateTime('December 31');
101
102
    //  If $day is between the days of spring, summer, autumn, and winter
103
    if ($day >= $spring_starts && $day <= $spring_ends) :
104
        $season = 'spring'; elseif ($day >= $summer_starts && $day <= $summer_ends) :
105
        $season = 'summer'; elseif ($day >= $autumn_starts && $day <= $autumn_ends) :
106
        $season = 'fall'; else :
107
        $season = 'winter';
108
    endif;
109
110
    return $season;
111
}
112
113
function imageUrlCleaner($str)
114
{
115
    preg_match('/(questionmark)|(qm_50)/', $str, $temp_image);
116
    $str = $temp_image ? '' : $str;
117
    $str = str_replace('v.jpg', '.jpg', $str);
118
    $str = str_replace('_thumb.jpg', '.jpg', $str);
119
    $str = str_replace('userimages/thumbs', 'userimages', $str);
120
    $str = preg_replace('/r\/\d{1,3}x\d{1,3}\//', '', $str);
121
    $str = preg_replace('/\?.+/', '', $str);
122
123
    return $str;
124
}
125
126
function getInfo($type, $id)
127
{
128
    $url = 'https://myanimelist.net/'.$type.'/'.$id;
129
130
    $file_headers = @get_headers($url);
131
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
132
        return 404;
133
    }
134
135
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
136
    $html = str_replace('&quot;', '\"', $html);
137
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
138
    $html = HtmlDomParser::str_get_html($html);
139
140
    // title, cover
141
    $anime_cover = $html->find('img.ac', 0);
142
    $title = $anime_cover ? $anime_cover->alt : '';
143
    $cover = $anime_cover ? $anime_cover->src : '';
144
    unset($anime_cover);
145
146
    // id
147
    $anime_id = $html->find('#myinfo_anime_id', 0);
148
    $id = $anime_id->value;
149
    unset($anime_id);
150
151
    // anime info (left)
152
    $anime_info = $html->find('.js-scrollfix-bottom', 0);
153
154
    // alternative title
155
    $title2 = [];
156
157
    // english title
158
    preg_match('/(English:<\/span>)([^<]*)/', $anime_info->innertext, $english);
159
    $title2['english'] = trim($english ? $english[2] : '');
160
161
    // synonym title
162
    preg_match('/(Synonyms:<\/span>)([^<]*)/', $anime_info->innertext, $synonym);
163
    $title2['synonym'] = trim($synonym ? $synonym[2] : '');
164
165
    // japanese title
166
    preg_match('/(Japanese:<\/span>)([^<]*)/', $anime_info->innertext, $japanese);
167
    $title2['japanese'] = trim($japanese ? $japanese[2] : '');
168
169
    // other info
170
    $info = [];
171
    $other_info = (count($anime_info->find('h2')) > 2) ? $anime_info->find('h2', 1) : $anime_info->find('h2', 0);
0 ignored issues
show
Bug introduced by
It seems like $anime_info->find('h2') can also be of type simplehtmldom_1_5\simple_html_dom_node; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

171
    $other_info = (count(/** @scrutinizer ignore-type */ $anime_info->find('h2')) > 2) ? $anime_info->find('h2', 1) : $anime_info->find('h2', 0);
Loading history...
172
    $next_info = $other_info->next_sibling();
0 ignored issues
show
Bug introduced by
The method next_sibling() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
    /** @scrutinizer ignore-call */ 
173
    $next_info = $other_info->next_sibling();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
173
    while (true) {
174
        $info_type = $next_info->find('span', 0)->plaintext;
175
        $clean_info_type = strtolower(str_replace(': ', '', $info_type));
176
177
        $info_value = $next_info->plaintext;
178
        $clean_info_value = trim(str_replace($info_type, '', $info_value));
179
        $clean_info_value = preg_replace("/([\s])+/", ' ', $clean_info_value);
180
        $clean_info_value = str_replace([', add some', '?', 'Not yet aired', 'Unknown'], '', $clean_info_value);
181
182
        if ($clean_info_type == 'published' || $clean_info_type == 'aired') {
183
            $start_air = '';
184
            $end_air = '';
185
            if ($clean_info_value != 'Not available') {
186
                $parsed_airing = explode(' to ', $clean_info_value);
187
188
                $start_air = ($parsed_airing[0] != '?') ? date('Y-m-d', strtotime($parsed_airing[0])) : '';
189
                if (count($parsed_airing) > 1) {
190
                    $end_air = ($parsed_airing[1] != '?') ? date('Y-m-d', strtotime($parsed_airing[1])) : '';
191
                }
192
            }
193
194
            $clean_info_value = [];
195
            $clean_info_value['start'] = $start_air;
196
            $clean_info_value['end'] = $end_air;
197
        }
198
199
        if ($clean_info_type == 'producers'
200
            || $clean_info_type == 'licensors'
201
            || $clean_info_type == 'studios'
202
            || $clean_info_type == 'genres'
203
            || $clean_info_type == 'authors'
204
        ) {
205
            $info_temp = [];
206
            $info_temp_index = 0;
207
            if ($clean_info_value != 'None found') {
208
                foreach ($next_info->find('a') as $each_info) {
209
                    $temp_id = explode('/', $each_info->href);
210
                    $info_temp[$info_temp_index]['id'] = $clean_info_type == 'authors' ? $temp_id[2] : $temp_id[3];
211
                    $info_temp[$info_temp_index]['name'] = $each_info->plaintext;
212
                    $info_temp_index++;
213
                }
214
            }
215
            $clean_info_value = $info_temp;
216
        }
217
218
        $info[$clean_info_type] = $clean_info_value;
219
220
        $next_info = $next_info->next_sibling();
221
        if ($next_info->tag == 'h2' || $next_info->tag == 'br') {
222
            break;
223
        }
224
    }
225
    unset($other_info);
226
    unset($next_info);
227
    unset($anime_info);
228
229
    // score
230
    $score = $html->find('div[class="fl-l score"]', 0)->plaintext;
231
    $score = trim($score);
232
    $score = $score != 'N/A' ? $score : '';
233
234
    // voter
235
    $voter = $html->find('div[class="fl-l score"]', 0)->getAttribute('data-user');
236
    $voter = trim(str_replace(['users', 'user', ','], '', $voter));
237
238
    // rank
239
    $rank = $html->find('span[class="numbers ranked"] strong', 0)->plaintext;
240
    $rank = $rank != 'N/A' ? $rank : '';
241
    $rank = str_replace('#', '', $rank);
242
243
    // popularity
244
    $popularity = $html->find('span[class="numbers popularity"] strong', 0)->plaintext;
245
    $popularity = str_replace('#', '', $popularity);
246
247
    // members
248
    $members = $html->find('span[class="numbers members"] strong', 0)->plaintext;
249
    $members = str_replace(',', '', $members);
250
251
    // favorite
252
    $favorite = $html->find('div[data-id=info2]', 0)->next_sibling()->next_sibling()->next_sibling();
253
    $favorite_title = $favorite->find('span', 0)->plaintext;
254
    $favorite = $favorite->plaintext;
255
    $favorite = trim(str_replace($favorite_title, '', $favorite));
256
    $favorite = str_replace(',', '', $favorite);
257
    $favorite = preg_replace("/([\s])+/", ' ', $favorite);
258
259
    // synopsis
260
    $synopsis = $html->find('span[itemprop=description]', 0);
261
    if ($synopsis) {
262
        $synopsis = $synopsis->plaintext;
263
        $synopsis = trim(preg_replace('/\n[^\S\n]*/', "\n", $synopsis));
264
    } else {
265
        $synopsis = '';
266
    }
267
268
    // related
269
    $related = [];
270
    $related_area = $html->find('.anime_detail_related_anime', 0);
271
    if ($related_area) {
272
        foreach ($related_area->find('tr') as $rel) {
273
            $rel_type = $rel->find('td', 0)->plaintext;
274
            $rel_type = trim(strtolower(str_replace(':', '', $rel_type)));
275
276
            $each_rel = [];
277
            $each_rel_index = 0;
278
            $rel_anime = $rel->find('td', 1);
279
            foreach ($rel_anime->find('a') as $r) {
280
                $rel_anime_link = $r->href;
281
                $separated_anime_link = explode('/', $rel_anime_link);
282
283
                $each_rel[$each_rel_index]['id'] = $separated_anime_link[2];
284
                $each_rel[$each_rel_index]['title'] = $r->plaintext;
285
                $each_rel[$each_rel_index]['type'] = $separated_anime_link[1];
286
287
                $each_rel_index++;
288
            }
289
290
            $related[$rel_type] = $each_rel;
291
        }
292
    }
293
    unset($related_area);
294
295
    // character + va
296
    $character = [];
297
    $char_index = 0;
298
    $character_area = $html->find('div[class^=detail-characters-list]', 0);
299
    if ($character_area) {
300
        $character_left = $character_area->find('div[class*=fl-l]', 0);
301
        if ($character_left) {
302
            foreach ($character_left->find('table[width=100%]') as $each_char) {
303
                $char_image = $each_char->find('tr td', 0)->find('img', 0)->getAttribute('data-src');
304
                $char_image = imageUrlCleaner($char_image);
305
306
                $char = $each_char->find('tr td', 1);
307
308
                $char_id = $char->find('a', 0)->href;
309
                $char_id = explode('/', $char_id);
310
                $char_id = $char_id[4];
311
312
                $char_name = trim(preg_replace('/\s+/', ' ', $char->find('a', 0)->plaintext));
313
                $char_role = trim($char->find('small', 0)->plaintext);
314
315
                $character[$char_index]['id'] = $char_id;
316
                $character[$char_index]['name'] = $char_name;
317
                $character[$char_index]['role'] = $char_role;
318
                $character[$char_index]['image'] = $char_image;
319
320
                $va = $each_char->find('table td', 0);
321
                if ($va) {
322
                    $va_id = $va->find('a', 0)->href;
323
                    $va_id = explode('/', $va_id);
324
                    $va_id = $va_id[4];
325
326
                    $va_name = $va->find('a', 0)->plaintext;
327
                    $va_role = $va->find('small', 0)->plaintext;
328
329
                    $va_image = $each_char->find('table td', 1)->find('img', 0)->getAttribute('data-src');
330
                    $va_image = imageUrlCleaner($va_image);
331
                }
332
333
                $character[$char_index]['va_id'] = isset($va_id) ? $va_id : '';
334
                $character[$char_index]['va_name'] = isset($va_name) ? $va_name : '';
335
                $character[$char_index]['va_role'] = isset($va_role) ? $va_role : '';
336
                $character[$char_index]['va_image'] = isset($va_image) ? $va_image : '';
337
338
                $char_index++;
339
            }
340
        }
341
        unset($character_left);
342
343
        $character_right = $character_area->find('div[class*=fl-r]', 0);
344
        if ($character_right) {
345
            foreach ($character_right->find('table[width=100%]') as $each_char) {
346
                $char_image = $each_char->find('tr td', 0)->find('img', 0)->getAttribute('data-src');
347
                $char_image = imageUrlCleaner($char_image);
348
349
                $char = $each_char->find('tr td', 1);
350
351
                $char_id = $char->find('a', 0)->href;
352
                $char_id = explode('/', $char_id);
353
                $char_id = $char_id[4];
354
355
                $char_name = trim(preg_replace('/\s+/', ' ', $char->find('a', 0)->plaintext));
356
                $char_role = trim($char->find('small', 0)->plaintext);
357
358
                $character[$char_index]['id'] = $char_id;
359
                $character[$char_index]['name'] = $char_name;
360
                $character[$char_index]['role'] = $char_role;
361
                $character[$char_index]['image'] = $char_image;
362
363
                $va = $each_char->find('table td', 0);
364
                if ($va) {
365
                    $va_id = $va->find('a', 0)->href;
366
                    $va_id = explode('/', $va_id);
367
                    $va_id = $va_id[4];
368
369
                    $va_name = $va->find('a', 0)->plaintext;
370
                    $va_role = $va->find('small', 0)->plaintext;
371
372
                    $va_image = $each_char->find('table td', 1)->find('img', 0)->getAttribute('data-src');
373
                    $va_image = imageUrlCleaner($va_image);
374
375
                    $character[$char_index]['va_id'] = $va_id;
376
                    $character[$char_index]['va_name'] = $va_name;
377
                    $character[$char_index]['va_role'] = $va_role;
378
                    $character[$char_index]['va_image'] = $va_image;
379
                }
380
381
                $char_index++;
382
            }
383
        }
384
        unset($character_right);
385
    }
386
    unset($character_area);
387
    unset($char_index);
388
389
    // staff
390
    $staff = [];
391
    $staff_index = 0;
392
    $staff_area = $html->find('div[class^=detail-characters-list]', 1);
393
    if ($staff_area) {
394
        $staff_left = $staff_area->find('div[class*=fl-l]', 0);
395
        if ($staff_left) {
396
            foreach ($staff_left->find('table[width=100%]') as $each_staff) {
397
                $staff_image = $each_staff->find('tr td', 0)->find('img', 0)->getAttribute('data-src');
398
                $staff_image = imageUrlCleaner($staff_image);
399
400
                $st = $each_staff->find('tr td', 1);
401
402
                $staff_id = $st->find('a', 0)->href;
403
                $staff_id = explode('/', $staff_id);
404
                $staff_id = $staff_id[4];
405
406
                $staff_name = trim(preg_replace('/\s+/', ' ', $st->find('a', 0)->plaintext));
407
                $staff_role = trim($st->find('small', 0)->plaintext);
408
409
                $staff[$staff_index]['id'] = $staff_id;
410
                $staff[$staff_index]['name'] = $staff_name;
411
                $staff[$staff_index]['role'] = $staff_role;
412
                $staff[$staff_index]['image'] = $staff_image;
413
414
                $staff_index++;
415
            }
416
        }
417
        unset($staff_left);
418
419
        $staff_right = $staff_area->find('div[class*=fl-r]', 0);
420
        if ($staff_right) {
421
            foreach ($staff_right->find('table[width=100%]') as $each_staff) {
422
                $staff_image = $each_staff->find('tr td', 0)->find('img', 0)->getAttribute('data-src');
423
                $staff_image = imageUrlCleaner($staff_image);
424
425
                $st = $each_staff->find('tr td', 1);
426
427
                $staff_id = $st->find('a', 0)->href;
428
                $staff_id = explode('/', $staff_id);
429
                $staff_id = $staff_id[4];
430
431
                $staff_name = trim(preg_replace('/\s+/', ' ', $st->find('a', 0)->plaintext));
432
                $staff_role = trim($st->find('small', 0)->plaintext);
433
434
                $staff[$staff_index]['id'] = $staff_id;
435
                $staff[$staff_index]['name'] = $staff_name;
436
                $staff[$staff_index]['role'] = $staff_role;
437
                $staff[$staff_index]['image'] = $staff_image;
438
439
                $staff_index++;
440
            }
441
        }
442
        unset($staff_right);
443
    }
444
    unset($staff_area);
445
    unset($staff_index);
446
447
    // song
448
    $song = [];
449
    $song_area = $html->find('div[class*="theme-songs opnening"]', 0);
450
    if ($song_area) {
451
        foreach ($song_area->find('span.theme-song') as $each_song) {
452
            $each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext));
453
            $song['opening'][] = $each_song;
454
        }
455
    }
456
457
    $song_area = $html->find('div[class*="theme-songs ending"]', 0);
458
    if ($song_area) {
459
        foreach ($song_area->find('span.theme-song') as $each_song) {
460
            $each_song = trim(preg_replace('/#\d*:\s/', '', $each_song->plaintext));
461
            $song['closing'][] = $each_song;
462
        }
463
    }
464
    unset($song_area);
465
466
    $html->clear();
467
    unset($html);
468
469
    // combine all data
470
    $data = [
471
        'id'         => $id,
472
        'cover'      => $cover,
473
        'title'      => $title,
474
        'title2'     => $title2,
475
        'synopsis'   => $synopsis,
476
        'score'      => $score,
477
        'voter'      => $voter,
478
        'rank'       => $rank,
479
        'popularity' => $popularity,
480
        'members'    => $members,
481
        'favorite'   => $favorite,
482
    ];
483
484
    $data = array_merge($data, $info);
485
486
    $data2 = [
487
        'related'   => $related,
488
        'character' => $character,
489
        'staff'     => $staff,
490
        'song'      => $song,
491
    ];
492
493
    $data = array_merge($data, $data2);
494
495
    return $data;
496
}
497
498
function getCharacter($id)
499
{
500
    $url = 'https://myanimelist.net/character/'.$id;
501
502
    $file_headers = @get_headers($url);
503
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
504
        return 404;
505
    }
506
507
    $html = HtmlDomParser::file_get_html($url)->find('#contentWrapper', 0)->outertext;
508
    $html = str_replace('&quot;', '\"', $html);
509
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
510
    $html = HtmlDomParser::str_get_html($html);
511
512
    // nickname
513
    $nickname = $html->find('h1', 0)->plaintext;
514
    $nickname = trim(preg_replace('/\s+/', ' ', $nickname));
515
    preg_match('/\"([^"])*/', $nickname, $nickname);
0 ignored issues
show
Bug introduced by
$nickname of type string is incompatible with the type array|null expected by parameter $matches of preg_match(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

515
    preg_match('/\"([^"])*/', $nickname, /** @scrutinizer ignore-type */ $nickname);
Loading history...
516
    if ($nickname) {
517
        $nickname = substr($nickname[0], 1, strlen($nickname[0]) - 2);
518
    } else {
519
        $nickname = '';
520
    }
521
522
    $html = $html->find('#content table tr', 0);
523
    $left_area = $html->find('td', 0);
524
    $right_area = $left_area->next_sibling();
525
526
    // image
527
    $image = $left_area->find('div', 0)->find('a', 0);
528
    $image = $image->find('img', 0);
529
    $image = $image ? $image->src : '';
530
531
    // animeography
532
    $animeography = [];
533
    $animeography_index = 0;
534
    $animeography_area = $left_area->find('table', 0);
535
    $animeography_area = $animeography_area->find('tr');
536
    if ($animeography_area) {
537
        foreach ($animeography_area as $each_anime) {
538
            $anime_image = $each_anime->find('td', 0)->find('img', 0)->src;
539
            $anime_image = imageUrlCleaner($anime_image);
540
            $animeography[$animeography_index]['image'] = $anime_image;
541
542
            $each_anime = $each_anime->find('td', 1);
543
544
            // id
545
            $anime_id = $each_anime->find('a', 0)->href;
546
            $parsed_anime_id = explode('/', $anime_id);
547
            $anime_id = $parsed_anime_id[4];
548
            $animeography[$animeography_index]['id'] = $anime_id;
549
550
            // title
551
            $anime_title = $each_anime->find('a', 0)->plaintext;
552
            $animeography[$animeography_index]['title'] = $anime_title;
553
554
            // role
555
            $anime_role = $each_anime->find('div small', 0)->plaintext;
556
            $animeography[$animeography_index]['role'] = $anime_role;
557
558
            $animeography_index++;
559
        }
560
    }
561
    unset($animeography_area);
562
    unset($animeography_index);
563
564
    // mangaography
565
    $mangaography = [];
566
    $mangaography_index = 0;
567
    $mangaography_area = $left_area->find('table', 1);
568
    $mangaography_area = $mangaography_area->find('tr');
569
    if ($mangaography_area) {
570
        foreach ($mangaography_area as $each_manga) {
571
            $manga_image = $each_manga->find('td', 0)->find('img', 0)->src;
572
            $manga_image = imageUrlCleaner($manga_image);
573
            $mangaography[$mangaography_index]['image'] = $manga_image;
574
575
            $each_manga = $each_manga->find('td', 1);
576
577
            // id
578
            $manga_id = $each_manga->find('a', 0)->href;
579
            $parsed_manga_id = explode('/', $manga_id);
580
            $manga_id = $parsed_manga_id[4];
581
            $mangaography[$mangaography_index]['id'] = $manga_id;
582
583
            // title
584
            $manga_title = $each_manga->find('a', 0)->plaintext;
585
            $mangaography[$mangaography_index]['title'] = $manga_title;
586
587
            // role
588
            $manga_role = $each_manga->find('div small', 0)->plaintext;
589
            $mangaography[$mangaography_index]['role'] = $manga_role;
590
591
            $mangaography_index++;
592
        }
593
    }
594
    unset($mangaography_area);
595
    unset($mangaography_index);
596
597
    // favorite
598
    $favorite = $left_area->plaintext;
599
    preg_match('/(Member Favorites: ).+/', $favorite, $parsed_favorite);
600
    $favorite = trim($parsed_favorite[0]);
601
    $parsed_favorite = explode(': ', $favorite);
602
    $favorite = str_replace(',', '', $parsed_favorite[1]);
603
604
    // name
605
    $name_area = $right_area->find('div[class=normal_header]', 0);
606
    $name_kanji = $name_area->find('small', 0);
607
    $name_kanji = $name_kanji ? $name_kanji->plaintext : '';
608
609
    $name = trim(str_replace($name_kanji, '', $name_area->plaintext));
610
    $name_kanji = preg_replace('/(\(|\))/', '', $name_kanji);
611
612
    // about
613
    preg_match('/(<div class="normal_header" style="height: 15px;">).*(<div class="normal_header">)/', $right_area->outertext, $about);
614
615
    $about = str_replace($name_area->outertext, '', $about[0]);
616
    $about = str_replace('<div class="normal_header">', '', $about);
617
618
    preg_match('/(No biography written)/', $about, $temp_about);
619
    if (!$temp_about) {
620
        $about = str_replace(['<br>', '<br />', '  '], ["\n", "\n", ' '], $about);
621
        $about = strip_tags($about);
622
        $about = preg_replace('/\n[^\S\n]*/', "\n", $about);
623
    } else {
624
        $about = '';
625
    }
626
627
    // va
628
    $va = [];
629
    $va_index = 0;
630
    $va_area = $right_area->find('div[class=normal_header]', 1);
631
    $va_area = $va_area->next_sibling();
632
    if ($va_area->tag == 'table') {
633
        while (true) {
634
635
            // id
636
            $va_name_area = $va_area->find('td', 1);
637
            $va_id = $va_name_area->find('a', 0)->href;
638
            $parsed_va_id = explode('/', $va_id);
639
            $va_id = $parsed_va_id[4];
640
            $va[$va_index]['id'] = $va_id;
641
642
            // name
643
            $va_name = $va_name_area->find('a', 0)->plaintext;
644
            $va[$va_index]['name'] = $va_name;
645
646
            // role
647
            $va_role = $va_name_area->find('small', 0)->plaintext;
648
            $va[$va_index]['role'] = $va_role;
649
650
            // image
651
            $va_image = $va_area->find('img', 0)->src;
652
            $va_image = imageUrlCleaner($va_image);
653
            $va[$va_index]['image'] = $va_image;
654
655
            $va_area = $va_area->next_sibling();
656
            if ($va_area->tag != 'table') {
657
                break;
658
            } else {
659
                $va_index++;
660
            }
661
        }
662
    }
663
664
    $data = [
665
        'id'           => $id,
666
        'image'        => $image,
667
        'nickname'     => $nickname,
668
        'name'         => $name,
669
        'name_kanji'   => $name_kanji,
670
        'favorite'     => $favorite,
671
        'about'        => $about,
672
        'animeography' => $animeography,
673
        'mangaography' => $mangaography,
674
        'va'           => $va,
675
    ];
676
677
    return $data;
678
}
679
680
function getPeople($id)
681
{
682
    $url = 'https://myanimelist.net/people/'.$id;
683
684
    $file_headers = @get_headers($url);
685
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
686
        return 404;
687
    }
688
689
    $html = HtmlDomParser::file_get_html($url)->find('#contentWrapper', 0)->outertext;
690
    $html = str_replace('&quot;', '\"', $html);
691
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
692
    $html = HtmlDomParser::str_get_html($html);
693
694
    // name
695
    $name = $html->find('h1', 0)->plaintext;
696
697
    $html = $html->find('#content table tr', 0);
698
    $left_area = $html->find('td', 0);
699
    $right_area = $left_area->next_sibling();
700
701
    // image
702
    $image = $left_area->find('img', 0);
703
    $image = $image ? $image->src : '';
704
705
    // biodata
706
    $biodata = $left_area->innertext;
707
    $useless_biodata = '';
708
    $useless_area = $left_area->find('div', 0);
709
    for ($i = 0; $i < 4; $i++) {
710
        $useless_biodata .= $useless_area->outertext;
711
        $useless_area = $useless_area->next_sibling();
712
    }
713
    $biodata = str_replace($useless_biodata, '', $biodata);
714
    $biodata = preg_replace("/([\s])+/", ' ', $biodata);
715
716
    // given name
717
    $given_name = '';
718
    preg_match("/(Given name:<\/span>)[^<]*/", $biodata, $temp_given_name);
719
    if ($temp_given_name) {
720
        $given_name = strip_tags($temp_given_name[0]);
721
        $parsed_given_name = explode(': ', $given_name);
722
        $given_name = trim($parsed_given_name[1]);
723
    }
724
725
    // family name
726
    $family_name = '';
727
    preg_match("/(Family name:<\/span>)([^<])*/", $biodata, $temp_family_name);
728
    if ($temp_family_name) {
729
        $family_name = strip_tags($temp_family_name[0]);
730
        $parsed_family_name = explode(': ', $family_name);
731
        $family_name = trim($parsed_family_name[1]);
732
    }
733
734
    // alternative name
735
    $alternative_name = '';
736
    preg_match("/(Alternate names:<\/span>)([^<])*/", $biodata, $temp_alternative_name);
737
    if ($temp_alternative_name) {
738
        $alternative_name = strip_tags($temp_alternative_name[0]);
739
        $parsed_alternative_name = explode(': ', $alternative_name);
740
        $alternative_name = trim($parsed_alternative_name[1]);
741
        $alternative_name = explode(', ', $alternative_name);
742
    }
743
744
    // birthday
745
    $birthday = '';
746
    preg_match("/(Birthday:<\/span>)([^<])*/", $biodata, $temp_birthday);
747
    if ($temp_birthday) {
748
        $birthday = strip_tags($temp_birthday[0]);
749
        $parsed_alternative_name = explode(': ', $birthday);
750
        $birthday = trim($parsed_alternative_name[1]);
751
    }
752
753
    // website
754
    $website = '';
755
    preg_match("/(Website:<\/span> <a)([^<])*/", $biodata, $temp_website);
756
    if ($temp_website) {
757
        preg_match('/".+"/', $temp_website[0], $temp_website);
758
        if ($temp_website[0] != '"http://"') {
759
            $website = str_replace('"', '', $temp_website[0]);
760
        }
761
    }
762
763
    // favorite
764
    $favorite = '';
765
    preg_match("/(Member Favorites:<\/span>)([^<])*/", $biodata, $temp_favorite);
766
    if ($temp_favorite) {
767
        $favorite = strip_tags($temp_favorite[0]);
768
        $parsed_favorite = explode(': ', $favorite);
769
        $favorite = trim($parsed_favorite[1]);
770
        $favorite = str_replace(',', '', $favorite);
771
    }
772
773
    // more
774
    $more = $left_area->find('div[class^=people-informantion-more]', 0)->plaintext;
775
    $more = preg_replace('/\n[^\S\n]*/', "\n", $more);
776
777
    // va
778
    $va = [];
779
    $va_index = 0;
780
    $va_area = $right_area->find('.normal_header', 0)->next_sibling();
781
    if ($va_area->tag == 'table') {
782
        if ($va_area->find('tr')) {
783
            foreach ($va_area->find('tr') as $each_va) {
784
                // anime image
785
                $anime_image = $each_va->find('td', 0)->find('img', 0)->getAttribute('data-src');
786
                $va[$va_index]['anime']['image'] = imageUrlCleaner($anime_image);
787
788
                $anime_area = $each_va->find('td', 1);
789
790
                // anime id
791
                $anime_id = $anime_area->find('a', 0)->href;
792
                $parsed_anime_id = explode('/', $anime_id);
793
                $anime_id = $parsed_anime_id[4];
794
                $va[$va_index]['anime']['id'] = $anime_id;
795
796
                // anime title
797
                $anime_title = $anime_area->find('a', 0)->plaintext;
798
                $va[$va_index]['anime']['title'] = $anime_title;
799
800
                // character image
801
                $character_image = $each_va->find('td', 3)->find('img', 0)->getAttribute('data-src');
802
                $va[$va_index]['character']['image'] = imageUrlCleaner($character_image);
803
804
                $character_area = $each_va->find('td', 2);
805
806
                // character id
807
                $character_id = $character_area->find('a', 0)->href;
808
                $parsed_character_id = explode('/', $character_id);
809
                $character_id = $parsed_character_id[4];
810
                $va[$va_index]['character']['id'] = $character_id;
811
812
                // character name
813
                $character_name = $character_area->find('a', 0)->plaintext;
814
                $va[$va_index]['character']['name'] = $character_name;
815
816
                // character role
817
                $character_role = $character_area->find('div', 0)->plaintext;
818
                $va[$va_index]['character']['role'] = $character_role;
819
820
                $va_index++;
821
            }
822
        }
823
    }
824
    unset($va_area);
825
826
    // staff
827
    $staff = [];
828
    $staff_index = 0;
829
    $staff_area = $right_area->find('.normal_header', 1)->next_sibling();
830
    if ($staff_area->tag == 'table') {
831
        foreach ($staff_area->find('tr') as $each_staff) {
832
            $anime_image = $each_staff->find('td', 0)->find('img', 0)->getAttribute('data-src');
833
            $staff[$staff_index]['image'] = imageUrlCleaner($anime_image);
834
835
            $each_staff = $each_staff->find('td', 1);
836
837
            // anime id
838
            $anime_id = $each_staff->find('a', 0)->href;
839
            $parsed_anime_id = explode('/', $anime_id);
840
            $anime_id = $parsed_anime_id[4];
841
            $staff[$staff_index]['id'] = $anime_id;
842
843
            // anime title
844
            $anime_title = $each_staff->find('a', 0)->plaintext;
845
            $staff[$staff_index]['title'] = $anime_title;
846
847
            // role
848
            $role = $each_staff->find('small', 0)->plaintext;
849
            $staff[$staff_index]['role'] = $role;
850
851
            $staff_index++;
852
        }
853
    }
854
    unset($staff_area);
855
856
    // manga
857
    $published_manga = [];
858
    $manga_index = 0;
859
    $manga_area = $right_area->find('.normal_header', 2)->next_sibling();
860
    if ($manga_area->tag == 'table') {
861
        foreach ($manga_area->find('tr') as $each_manga) {
862
            $manga_image = $each_manga->find('td', 0)->find('img', 0)->getAttribute('data-src');
863
            $published_manga[$manga_index]['image'] = imageUrlCleaner($manga_image);
864
865
            $each_manga = $each_manga->find('td', 1);
866
867
            // manga id
868
            $manga_id = $each_manga->find('a', 0)->href;
869
            $parsed_manga_id = explode('/', $manga_id);
870
            $manga_id = $parsed_manga_id[4];
871
            $published_manga[$manga_index]['id'] = $manga_id;
872
873
            // manga title
874
            $manga_title = $each_manga->find('a', 0)->plaintext;
875
            $published_manga[$manga_index]['title'] = $manga_title;
876
877
            // role
878
            $role = $each_manga->find('small', 0)->plaintext;
879
            $published_manga[$manga_index]['role'] = $role;
880
881
            $manga_index++;
882
        }
883
    }
884
    unset($manga_area);
885
886
    $data = [
887
        'id'               => $id,
888
        'name'             => $name,
889
        'image'            => $image,
890
        'given_name'       => $given_name,
891
        'family_name'      => $family_name,
892
        'alternative_name' => $alternative_name,
893
        'birthday'         => $birthday,
894
        'website'          => $website,
895
        'favorite'         => $favorite,
896
        'more'             => $more,
897
        'va'               => $va,
898
        'staff'            => $staff,
899
        'published_manga'  => $published_manga,
900
    ];
901
902
    return $data;
903
}
904
905
function getCharacterStaff($type, $id)
906
{
907
    $url = 'https://myanimelist.net/'.$type.'/'.$id;
908
909
    $file_headers = @get_headers($url);
910
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
911
        return 404;
912
    }
913
914
    $html = HtmlDomParser::file_get_html($url)->find('li a[href$=characters]', 0)->href;
915
916
    if ($type == 'manga') {
917
        $url = 'https://myanimelist.net'.$html;
918
    } else {
919
        $url = $html;
920
    }
921
922
    $html = HtmlDomParser::file_get_html($url)->find('.js-scrollfix-bottom-rel', 0)->outertext;
923
    $html = str_replace('&quot;', '\"', $html);
924
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
925
    $html = HtmlDomParser::str_get_html($html);
926
927
    // character
928
    $character = [];
929
    $character_index = 0;
930
    $char_table = $html->find('h2', 0);
931
    if ($char_table->next_sibling()->tag == 'table') {
932
        $char_table = $char_table->next_sibling();
933
        while (true) {
934
935
            // image
936
            $char_image = $char_table->find('td .picSurround img', 0)->getAttribute('data-src');
937
            $character[$character_index]['image'] = imageUrlCleaner($char_image);
938
939
            // id
940
            $char_name_area = $char_table->find('td', 1);
941
            $char_id = $char_name_area->find('a', 0)->href;
942
            $parsed_char_id = explode('/', $char_id);
943
            $char_id = $parsed_char_id[4];
944
            $character[$character_index]['id'] = $char_id;
945
946
            // name
947
            $char_name = $char_name_area->find('a', 0)->plaintext;
948
            $character[$character_index]['name'] = $char_name;
949
950
            // role
951
            $char_role = $char_name_area->find('small', 0)->plaintext;
952
            $character[$character_index]['role'] = $char_role;
953
954
            // va name + role
955
            $va = [];
956
            $va_index = 0;
957
            $char_va_area = $char_table->find('td', 2);
958
            if ($char_va_area) {
959
                $char_va_area = $char_va_area->find('table', 0);
960
                foreach ($char_va_area->find('tr') as $each_va) {
961
                    $va_name_area = $each_va->find('td', 0);
962
963
                    // id
964
                    $va_id = $va_name_area->find('a', 0)->href;
965
                    $parsed_va_id = explode('/', $va_id);
966
                    $va_id = $parsed_va_id[4];
967
                    $va[$va_index]['id'] = $va_id;
968
969
                    // name
970
                    $va_name = $va_name_area->find('a', 0)->plaintext;
971
                    $va[$va_index]['name'] = $va_name;
972
973
                    // role
974
                    $va_role = $va_name_area->find('small', 0)->plaintext;
975
                    $va[$va_index]['role'] = $va_role;
976
977
                    // image
978
                    $va_image = $each_va->find('td', 1)->find('img', 0)->getAttribute('data-src');
979
                    $va[$va_index]['image'] = imageUrlCleaner($va_image);
980
981
                    $va_index++;
982
                }
983
                $character[$character_index]['va'] = $va;
984
                unset($char_va_area);
985
            }
986
987
            $char_table = $char_table->next_sibling();
988
            if ($char_table->tag == 'br' || $char_table->tag == 'a' || $char_table->tag == 'h2' || $char_table->tag == 'div') {
989
                break;
990
            } else {
991
                $character_index++;
992
            }
993
        }
994
    }
995
    unset($char_table);
996
997
    // staff
998
    $staff = [];
999
    $staff_index = 0;
1000
    $staff_table = $html->find('h2', 1);
1001
    if ($staff_table) {
1002
        if ($staff_table->next_sibling()->tag == 'table') {
1003
            $staff_table = $staff_table->next_sibling();
1004
            while (true) {
1005
                // image
1006
                $staff_image = $staff_table->find('td .picSurround img', 0)->getAttribute('data-src');
1007
                $staff[$staff_index]['image'] = imageUrlCleaner($staff_image);
1008
1009
                // id
1010
                $staff_name_area = $staff_table->find('td', 1);
1011
                $staff_id = $staff_name_area->find('a', 0)->href;
1012
                $parsed_staff_id = explode('/', $staff_id);
1013
                $staff_id = $parsed_staff_id[4];
1014
                $staff[$staff_index]['id'] = $staff_id;
1015
1016
                // name
1017
                $staff_name = $staff_name_area->find('a', 0)->plaintext;
1018
                $staff[$staff_index]['name'] = $staff_name;
1019
1020
                // role
1021
                $staff_role = $staff_name_area->find('small', 0)->plaintext;
1022
                $staff[$staff_index]['role'] = $staff_role;
1023
1024
                $staff_table = $staff_table->next_sibling();
1025
                if (!$staff_table) {
1026
                    break;
1027
                } else {
1028
                    $staff_index++;
1029
                }
1030
            }
1031
        }
1032
    }
1033
    unset($staff_table);
1034
1035
    $data = [
1036
        'character' => $character,
1037
        'staff'     => $staff,
1038
    ];
1039
1040
    return $data;
1041
}
1042
1043
function getStat($type, $id)
1044
{
1045
    $url = 'https://myanimelist.net/'.$type.'/'.$id;
1046
1047
    $file_headers = @get_headers($url);
1048
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1049
        return 404;
1050
    }
1051
1052
    $html = HtmlDomParser::file_get_html($url)->find('li a[href$=stats]', 0)->href;
1053
1054
    if ($type == 'manga') {
1055
        $url = 'https://myanimelist.net'.$html;
1056
    } else {
1057
        $url = $html;
1058
    }
1059
1060
    $url .= "?m=all&show=1";
1061
1062
    $html = HtmlDomParser::file_get_html($url)->find('.js-scrollfix-bottom-rel', 0)->outertext;
1063
    $html = str_replace('&quot;', '\"', $html);
1064
    $html = str_replace('&nbsp;', ' ', $html);
1065
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1066
    $html = HtmlDomParser::str_get_html($html);
1067
1068
    // summary
1069
    $summary = [];
1070
    $summary_area = $html->find('h2', 0);
1071
    $summary_area = $summary_area->next_sibling();
1072
    if ($summary_area->tag == 'div') {
1073
        while (true) {
1074
1075
            // status
1076
            $temp_type = $summary_area->find('span', 0)->plaintext;
1077
            $summary_type = trim(str_replace(':', '', strtolower($temp_type)));
1078
1079
            // count
1080
            $status_area = $summary_area->plaintext;
1081
            $count = str_replace($temp_type, '', $status_area);
1082
            $summary[$summary_type] = trim(str_replace(',', '', $count));
1083
1084
            $summary_area = $summary_area->next_sibling();
1085
            if ($summary_area->tag != 'div') {
1086
                break;
1087
            }
1088
        }
1089
    }
1090
1091
    // score
1092
    $score = [];
1093
    $score_area = $html->find('h2', 1);
1094
    $score_area = $score_area->next_sibling();
1095
    if ($score_area->tag == 'table') {
1096
        foreach ($score_area->find('tr') as $each_score) {
1097
            $temp_score = [];
1098
1099
            // type
1100
            $score_type = $each_score->find('td', 0)->plaintext;
1101
            $temp_score['type'] = $score_type;
1102
1103
            // vote
1104
            $temp_vote = $each_score->find('td', 1)->find('span small', 0)->plaintext;
1105
            $vote = substr($temp_vote, 1, strlen($temp_vote) - 2);
1106
            $temp_score['vote'] = str_replace(' votes', '', $vote);
1107
1108
            // percent
1109
            $percent = $each_score->find('td', 1)->find('span', 0)->plaintext;
1110
            $percent = str_replace([$temp_vote, '%'], '', $percent);
1111
            $temp_score['percent'] = trim($percent);
1112
1113
            $score[] = $temp_score;
1114
        }
1115
    }
1116
1117
    // user
1118
    $user = [];
1119
    $user_area = $html->find('.table-recently-updated', 0);
1120
    if ($user_area) {
1121
        foreach ($user_area->find('tr') as $each_user) {
1122
            if (!$each_user->find('td', 0)->find('div', 0)) continue;
1123
            $temp_user = [];
1124
1125
            // username + image
1126
            $username_area = $each_user->find('td', 0);
1127
1128
            $user_image = $username_area->find('a', 0)->style;
1129
            $user_image = substr($user_image, 21, strlen($user_image)-22);
1130
            $temp_user['image'] = imageUrlCleaner($user_image);
1131
1132
            $username = $username_area->find('a', 1)->plaintext;
1133
            $temp_user['username'] = $username;
1134
1135
            // score
1136
            $user_score = $each_user->find('td', 1)->plaintext;
1137
            $temp_user['score'] = $user_score;
1138
1139
            // status
1140
            $status = $each_user->find('td', 2)->plaintext;
1141
            $temp_user['status'] = strtolower($status);
1142
1143
            if ($type == 'anime') {
1144
                // episode
1145
                $episode = $each_user->find('td', 3)->plaintext;
1146
                $temp_user['episode'] = str_replace(' ', '', $episode);
1147
1148
                // date
1149
                $date = $each_user->find('td', 4)->plaintext;
1150
                $temp_user['date'] = $date;
1151
            } else {
1152
                // volume
1153
                $volume = $each_user->find('td', 3)->plaintext;
1154
                $temp_user['volume'] = str_replace(' ', '', $volume);
1155
1156
                // chapter
1157
                $chapter = $each_user->find('td', 4)->plaintext;
1158
                $temp_user['chapter'] = str_replace(' ', '', $chapter);
1159
1160
                // date
1161
                $date = $each_user->find('td', 5)->plaintext;
1162
                $temp_user['date'] = $date;
1163
            }
1164
1165
            $user[] = $temp_user;
1166
        }
1167
    }
1168
1169
    $data = [
1170
        'summary' => $summary,
1171
        'score'   => $score,
1172
        'user'   => $user,
1173
    ];
1174
1175
    return $data;
1176
}
1177
1178
function getPicture($type, $id)
1179
{
1180
    $url = 'https://myanimelist.net/'.$type.'/'.$id;
1181
1182
    $file_headers = @get_headers($url);
1183
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1184
        return 404;
1185
    }
1186
1187
    $html = HtmlDomParser::file_get_html($url)->find('li a[href$=pics]', 0)->href;
1188
1189
    if ($type == 'manga') {
1190
        $url = 'https://myanimelist.net'.$html;
1191
    } else {
1192
        $url = $html;
1193
    }
1194
1195
    $html = HtmlDomParser::file_get_html($url)->find('.js-scrollfix-bottom-rel', 0)->outertext;
1196
    $html = str_replace('&quot;', '\"', $html);
1197
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1198
    $html = HtmlDomParser::str_get_html($html);
1199
1200
    $data = [];
1201
    $picture_table = $html->find('table', 0);
1202
    if ($picture_table) {
1203
        foreach ($picture_table->find('img') as $each_picture) {
1204
            if ($each_picture) {
1205
                $data[] = $each_picture->src;
1206
            }
1207
        }
1208
    }
1209
1210
    return $data;
1211
}
1212
1213
function getCharacterPicture($id)
1214
{
1215
    $url = 'https://myanimelist.net/character/'.$id;
1216
1217
    $file_headers = @get_headers($url);
1218
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1219
        return 404;
1220
    }
1221
1222
    $html = HtmlDomParser::file_get_html($url)->find('li a[href$=pictures]', 0)->href;
1223
    $html = HtmlDomParser::file_get_html($html)->find('#content table tr td', 0)->next_sibling()->outertext;
1224
    $html = str_replace('&quot;', '\"', $html);
1225
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1226
    $html = HtmlDomParser::str_get_html($html);
1227
1228
    $data = [];
1229
    $picture_table = $html->find('table', 0);
1230
    if ($picture_table) {
1231
        foreach ($picture_table->find('img') as $each_picture) {
1232
            if ($each_picture) {
1233
                $data[] = $each_picture->src;
1234
            }
1235
        }
1236
    }
1237
1238
    return $data;
1239
}
1240
1241
function getPeoplePicture($id)
1242
{
1243
    $url = 'https://myanimelist.net/people/'.$id;
1244
1245
    $file_headers = @get_headers($url);
1246
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1247
        return 404;
1248
    }
1249
1250
    $html = HtmlDomParser::file_get_html($url)->find('li a[href$=pictures]', 0)->href;
1251
    $html = HtmlDomParser::file_get_html($html)->find('#content table tr td', 0)->next_sibling()->outertext;
1252
    $html = str_replace('&quot;', '\"', $html);
1253
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1254
    $html = HtmlDomParser::str_get_html($html);
1255
1256
    $data = [];
1257
    $picture_table = $html->find('table', 0);
1258
    if ($picture_table) {
1259
        foreach ($picture_table->find('img') as $each_picture) {
1260
            if ($each_picture) {
1261
                $data[] = $each_picture->src;
1262
            }
1263
        }
1264
    }
1265
1266
    return $data;
1267
}
1268
1269
function getStudioProducer($id, $page = 1)
1270
{
1271
    $url = 'https://myanimelist.net/anime/producer/'.$id.'/?page='.$page;
1272
1273
    $file_headers = @get_headers($url);
1274
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1275
        return 404;
1276
    }
1277
1278
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->find('.js-categories-seasonal', 0)->outertext;
1279
    $html = str_replace('&quot;', '\"', $html);
1280
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1281
    $html = HtmlDomParser::str_get_html($html);
1282
1283
    $data = [];
1284
    $anime_table = $html->find('div[class="seasonal-anime js-seasonal-anime"]');
1285
    foreach ($anime_table as $each_anime) {
1286
        $result = [];
1287
1288
        // image
1289
        $image = $each_anime->find('div[class=image]', 0)->find('img', 0)->getAttribute('data-src');
1290
        $result['image'] = imageUrlCleaner($image);
1291
1292
        // id
1293
        $name_area = $each_anime->find('div[class=title]', 0);
1294
        $id = $name_area->find('p a', 0)->href;
1295
        $parsed_char_id = explode('/', $id);
1296
        $id = $parsed_char_id[4];
1297
        $result['id'] = $id;
1298
1299
        // title
1300
        $title = $name_area->find('p a', 0)->plaintext;
1301
        $result['title'] = $title;
1302
1303
        // producer
1304
        $producer = [];
1305
        $producer_area = $each_anime->find('div[class=prodsrc]', 0);
1306
        $temp_producer = $producer_area->find('span[class=producer]', 0);
1307
        foreach ($temp_producer->find('a') as $each_producer) {
1308
            $temp_prod = [];
1309
1310
            // prod id
1311
            $prod_id = $each_producer->href;
1312
            $parsed_prod_id = explode('/', $prod_id);
1313
            $temp_prod['id'] = $parsed_prod_id[3];
1314
1315
            // prod name
1316
            $prod_name = $each_producer->plaintext;
1317
            $temp_prod['name'] = $prod_name;
1318
1319
            $producer[] = $temp_prod;
1320
        }
1321
        $result['producer'] = $producer;
1322
1323
        // episode
1324
        $episode = $producer_area->find('div[class=eps]', 0)->plaintext;
1325
        $episode = trim(str_replace(['eps', 'ep'], '', $episode));
1326
        $result['episode'] = $episode;
1327
1328
        // source
1329
        $source = $producer_area->find('span[class=source]', 0)->plaintext;
1330
        $result['source'] = trim($source);
1331
1332
        // genre
1333
        $genre = [];
1334
        $genre_area = $each_anime->find('div[class="genres js-genre"]', 0);
1335
        foreach ($genre_area->find('a') as $each_genre) {
1336
            $genre[] = $each_genre->plaintext;
1337
        }
1338
        $result['genre'] = $genre;
1339
1340
        // synopsis
1341
        $synopsis = $each_anime->find('div[class="synopsis js-synopsis"]', 0)->plaintext;
1342
        $synopsis = trim(preg_replace("/([\s])+/", ' ', $synopsis));
1343
        $result['synopsis'] = $synopsis;
1344
1345
        // licensor
1346
        $licensor = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $licensor is dead and can be removed.
Loading history...
1347
        $temp_licensor = $each_anime->find('div[class="synopsis js-synopsis"] .licensors', 0)->getAttribute('data-licensors');
1348
        $licensor = explode(',', $temp_licensor);
1349
        $result['licensor'] = array_filter($licensor);
1350
1351
        // type
1352
        $info_area = $each_anime->find('.information', 0);
1353
        $type = $info_area->find('.info', 0)->plaintext;
1354
        $type = explode('-', $type);
1355
        $type = trim($type[0]);
1356
        $result['type'] = $type;
1357
1358
        // airing start
1359
        $airing_start = $info_area->find('.info .remain-time', 0)->plaintext;
1360
        $result['airing_start'] = trim($airing_start);
1361
1362
        // member
1363
        $member = $info_area->find('.scormem span[class^=member]', 0)->plaintext;
1364
        $result['member'] = trim(str_replace(',', '', $member));
1365
1366
        // score
1367
        $score = $info_area->find('.scormem .score', 0)->plaintext;
1368
        $result['score'] = trim($score);
1369
1370
        $data[] = $result;
1371
    }
1372
1373
    return $data;
1374
}
1375
1376
function getMagazine($id, $page = 1)
1377
{
1378
    $url = 'https://myanimelist.net/manga/magazine/'.$id.'/?page='.$page;
1379
1380
    $file_headers = @get_headers($url);
1381
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1382
        return 404;
1383
    }
1384
1385
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->find('.js-categories-seasonal', 0)->outertext;
1386
    $html = str_replace('&quot;', '\"', $html);
1387
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1388
    $html = HtmlDomParser::str_get_html($html);
1389
1390
    $data = [];
1391
    $anime_table = $html->find('div[class="seasonal-anime js-seasonal-anime"]');
1392
    foreach ($anime_table as $each_anime) {
1393
        $result = [];
1394
1395
        // image
1396
        $image = $each_anime->find('div[class=image]', 0)->find('img', 0)->getAttribute('data-src');
1397
        $result['image'] = imageUrlCleaner($image);
1398
1399
        // id
1400
        $name_area = $each_anime->find('div[class=title]', 0);
1401
        $id = $name_area->find('p a', 0)->href;
1402
        $parsed_char_id = explode('/', $id);
1403
        $id = $parsed_char_id[4];
1404
        $result['id'] = $id;
1405
1406
        // title
1407
        $title = $name_area->find('p a', 0)->plaintext;
1408
        $result['title'] = $title;
1409
1410
        // author
1411
        $author = [];
1412
        $producer_area = $each_anime->find('div[class=prodsrc]', 0);
1413
        $temp_producer = $producer_area->find('span[class=producer]', 0);
1414
        foreach ($temp_producer->find('a') as $each_producer) {
1415
            $temp_prod = [];
1416
1417
            // prod id
1418
            $prod_id = $each_producer->href;
1419
            $parsed_prod_id = explode('/', $prod_id);
1420
            $temp_prod['id'] = $parsed_prod_id[4];
1421
1422
            // prod name
1423
            $prod_name = $each_producer->plaintext;
1424
            $temp_prod['name'] = $prod_name;
1425
1426
            $author[] = $temp_prod;
1427
        }
1428
        $result['author'] = $author;
1429
1430
        // volume
1431
        $volume = $producer_area->find('div[class=eps]', 0)->plaintext;
1432
        $volume = trim(str_replace(['vols', 'vol'], '', $volume));
1433
        $result['volume'] = $volume;
1434
1435
        // source
1436
        $source = $producer_area->find('span[class=source]', 0)->plaintext;
1437
        $result['source'] = trim($source);
1438
1439
        // genre
1440
        $genre = [];
1441
        $genre_area = $each_anime->find('div[class="genres js-genre"]', 0);
1442
        foreach ($genre_area->find('a') as $each_genre) {
1443
            $genre[] = $each_genre->plaintext;
1444
        }
1445
        $result['genre'] = $genre;
1446
1447
        // synopsis
1448
        $synopsis = $each_anime->find('div[class="synopsis js-synopsis"]', 0)->plaintext;
1449
        $synopsis = trim(preg_replace("/([\s])+/", ' ', $synopsis));
1450
        $result['synopsis'] = $synopsis;
1451
1452
        // serialization
1453
        $serialization = $each_anime->find('div[class="synopsis js-synopsis"] .serialization a', 0);
1454
        $serialization = $serialization ? $serialization->plaintext : '';
1455
        $result['serialization'] = $serialization;
1456
1457
        // airing start
1458
        $info_area = $each_anime->find('.information', 0);
1459
        $airing_start = $info_area->find('.info .remain-time', 0)->plaintext;
1460
        $result['airing_start'] = trim($airing_start);
1461
1462
        // member
1463
        $member = $info_area->find('.scormem span[class^=member]', 0)->plaintext;
1464
        $result['member'] = trim(str_replace(',', '', $member));
1465
1466
        // score
1467
        $score = $info_area->find('.scormem .score', 0)->plaintext;
1468
        $result['score'] = trim($score);
1469
1470
        $data[] = $result;
1471
    }
1472
1473
    return $data;
1474
}
1475
1476
function getGenre($type, $id, $page = 1)
1477
{
1478
    $url = 'https://myanimelist.net/'.$type.'/genre/'.$id.'/?page='.$page;
1479
1480
    $file_headers = @get_headers($url);
1481
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1482
        return 404;
1483
    }
1484
1485
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->find('.js-categories-seasonal', 0)->outertext;
1486
    $html = str_replace('&quot;', '\"', $html);
1487
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1488
    $html = HtmlDomParser::str_get_html($html);
1489
1490
    $data = [];
1491
    $anime_table = $html->find('div[class="seasonal-anime js-seasonal-anime"]');
1492
    foreach ($anime_table as $each_anime) {
1493
        $result = [];
1494
1495
        // image
1496
        $image = $each_anime->find('div[class=image]', 0)->find('img', 0)->getAttribute('data-src');
1497
        $result['image'] = imageUrlCleaner($image);
1498
1499
        // id
1500
        $name_area = $each_anime->find('div[class=title]', 0);
1501
        $id = $name_area->find('p a', 0)->href;
1502
        $parsed_char_id = explode('/', $id);
1503
        $id = $parsed_char_id[4];
1504
        $result['id'] = $id;
1505
1506
        // title
1507
        $title = $name_area->find('p a', 0)->plaintext;
1508
        $result['title'] = $title;
1509
1510
        // producer
1511
        $producer = [];
1512
        $producer_area = $each_anime->find('div[class=prodsrc]', 0);
1513
        $temp_producer = $producer_area->find('span[class=producer]', 0);
1514
        foreach ($temp_producer->find('a') as $each_producer) {
1515
            $temp_prod = [];
1516
1517
            // prod id
1518
            $prod_id = $each_producer->href;
1519
            $parsed_prod_id = explode('/', $prod_id);
1520
            $temp_prod['id'] = ($type == 'anime') ? $parsed_prod_id[3] : $parsed_prod_id[4];
1521
1522
            // prod name
1523
            $prod_name = $each_producer->plaintext;
1524
            $temp_prod['name'] = $prod_name;
1525
1526
            $producer[] = $temp_prod;
1527
        }
1528
1529
        if ($type == 'anime') {
1530
            $result['producer'] = $producer;
1531
        } else {
1532
            $result['author'] = $producer;
1533
        }
1534
1535
        // episode
1536
        $episode = $producer_area->find('div[class=eps]', 0)->plaintext;
1537
        $episode = trim(str_replace(['eps', 'ep', 'vols', 'vol'], '', $episode));
1538
        if ($type == 'anime') {
1539
            $result['episode'] = $episode;
1540
        } else {
1541
            $result['volume'] = $episode;
1542
        }
1543
1544
        // source
1545
        $source = $producer_area->find('span[class=source]', 0)->plaintext;
1546
        $result['source'] = trim($source);
1547
1548
        // genre
1549
        $genre = [];
1550
        $genre_area = $each_anime->find('div[class="genres js-genre"]', 0);
1551
        foreach ($genre_area->find('a') as $each_genre) {
1552
            $genre[] = $each_genre->plaintext;
1553
        }
1554
        $result['genre'] = $genre;
1555
1556
        // synopsis
1557
        $synopsis = $each_anime->find('div[class="synopsis js-synopsis"]', 0)->plaintext;
1558
        $synopsis = trim(preg_replace("/([\s])+/", ' ', $synopsis));
1559
        $result['synopsis'] = $synopsis;
1560
1561
        if ($type == 'anime') {
1562
            // licensor
1563
            $licensor = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $licensor is dead and can be removed.
Loading history...
1564
            $temp_licensor = $each_anime->find('div[class="synopsis js-synopsis"] .licensors', 0)->getAttribute('data-licensors');
1565
            $licensor = explode(',', $temp_licensor);
1566
            $result['licensor'] = array_filter($licensor);
1567
        } else {
1568
            // serialization
1569
            $serialization = $each_anime->find('div[class="synopsis js-synopsis"] .serialization a', 0);
1570
            $serialization = $serialization ? $serialization->plaintext : '';
1571
            $result['serialization'] = $serialization;
1572
        }
1573
1574
        $info_area = $each_anime->find('.information', 0);
1575
1576
        if ($type == 'anime') {
1577
            // type
1578
            $type = $info_area->find('.info', 0)->plaintext;
1579
            $type = explode('-', $type);
1580
            $type = trim($type[0]);
1581
            $result['type'] = $type;
1582
        }
1583
1584
        // airing start
1585
        $airing_start = $info_area->find('.info .remain-time', 0)->plaintext;
1586
        $result['airing_start'] = trim($airing_start);
1587
1588
        // member
1589
        $member = $info_area->find('.scormem span[class^=member]', 0)->plaintext;
1590
        $result['member'] = trim(str_replace(',', '', $member));
1591
1592
        // score
1593
        $score = $info_area->find('.scormem .score', 0)->plaintext;
1594
        $result['score'] = trim($score);
1595
1596
        $data[] = $result;
1597
    }
1598
1599
    return $data;
1600
}
1601
1602
function getAllAnimeGenre()
1603
{
1604
    $url = 'https://myanimelist.net/anime.php';
1605
1606
    $file_headers = @get_headers($url);
1607
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1608
        return 404;
1609
    }
1610
1611
    $html = HtmlDomParser::file_get_html($url)->find('.anime-manga-search', 0)->find('.genre-link', 0)->outertext;
1612
    $html = str_replace('&quot;', '\"', $html);
1613
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1614
    $html = HtmlDomParser::str_get_html($html);
1615
1616
    $data = [];
1617
    foreach ($html->find('.genre-list a') as $each_genre) {
1618
        $genre = [];
1619
1620
        // id
1621
        $link = $each_genre->href;
1622
        $link = explode('/', $link);
1623
        $id = $link[3];
1624
        $genre['id'] = $id;
1625
1626
        // name
1627
        $name = str_replace('_', ' ', $link[4]);
1628
        $genre['name'] = $name;
1629
1630
        // count
1631
        $count = $each_genre->plaintext;
1632
        preg_match('/\([0-9,]+\)/', $count, $count);
1633
        $count = substr($count[0], 1, strlen($count[0]) - 2);
1634
        $genre['count'] = str_replace(',', '', $count);
1635
1636
        $data[] = $genre;
1637
    }
1638
1639
    return $data;
1640
}
1641
1642
function getAllMangaGenre()
1643
{
1644
    $url = 'https://myanimelist.net/manga.php';
1645
1646
    $file_headers = @get_headers($url);
1647
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1648
        return 404;
1649
    }
1650
1651
    $html = HtmlDomParser::file_get_html($url)->find('.anime-manga-search', 0)->find('.genre-link', 0)->outertext;
1652
    $html = str_replace('&quot;', '\"', $html);
1653
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1654
    $html = HtmlDomParser::str_get_html($html);
1655
1656
    $data = [];
1657
    foreach ($html->find('.genre-list a') as $each_genre) {
1658
        $genre = [];
1659
1660
        // id
1661
        $link = $each_genre->href;
1662
        $link = explode('/', $link);
1663
        $id = $link[3];
1664
        $genre['id'] = $id;
1665
1666
        // name
1667
        $name = str_replace('_', ' ', $link[4]);
1668
        $genre['name'] = $name;
1669
1670
        // count
1671
        $count = $each_genre->plaintext;
1672
        preg_match('/\([0-9,]+\)/', $count, $count);
1673
        $count = substr($count[0], 1, strlen($count[0]) - 2);
1674
        $genre['count'] = str_replace(',', '', $count);
1675
1676
        $data[] = $genre;
1677
    }
1678
1679
    return $data;
1680
}
1681
1682
function getAllStudioProducer()
1683
{
1684
    $url = 'https://myanimelist.net/anime/producer';
1685
1686
    $file_headers = @get_headers($url);
1687
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1688
        return 404;
1689
    }
1690
1691
    $html = HtmlDomParser::file_get_html($url)->find('.anime-manga-search', 0)->outertext;
1692
    $html = str_replace('&quot;', '\"', $html);
1693
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1694
    $html = HtmlDomParser::str_get_html($html);
1695
1696
    $data = [];
1697
    foreach ($html->find('.genre-list a') as $each_studio) {
1698
        $studio = [];
1699
1700
        // id
1701
        $link = $each_studio->href;
1702
        $link = explode('/', $link);
1703
        $id = $link[3];
1704
        $studio['id'] = $id;
1705
1706
        // name
1707
        $name = $each_studio->plaintext;
1708
        $studio['name'] = trim(preg_replace('/\([0-9,]+\)/', '', $name));
1709
1710
        // count
1711
        $count = $each_studio->plaintext;
1712
        preg_match('/\([0-9,]+\)/', $count, $count);
1713
        $count = substr($count[0], 1, strlen($count[0]) - 2);
1714
        $studio['count'] = str_replace(',', '', $count);
1715
1716
        $data[] = $studio;
1717
    }
1718
1719
    return $data;
1720
}
1721
1722
function getAllMagazine()
1723
{
1724
    $url = 'https://myanimelist.net/manga/magazine';
1725
1726
    $file_headers = @get_headers($url);
1727
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1728
        return 404;
1729
    }
1730
1731
    $html = HtmlDomParser::file_get_html($url)->find('.anime-manga-search', 0)->outertext;
1732
    $html = str_replace('&quot;', '\"', $html);
1733
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1734
    $html = HtmlDomParser::str_get_html($html);
1735
1736
    $data = [];
1737
    foreach ($html->find('.genre-list a') as $each_magazine) {
1738
        $magazine = [];
1739
1740
        // id
1741
        $link = $each_magazine->href;
1742
        $link = explode('/', $link);
1743
        $id = $link[3];
1744
        $magazine['id'] = $id;
1745
1746
        // name
1747
        $name = $each_magazine->plaintext;
1748
        $magazine['name'] = trim(preg_replace('/\([0-9,]+\)/', '', $name));
1749
1750
        // count
1751
        $count = $each_magazine->plaintext;
1752
        preg_match('/\([0-9,]+\)/', $count, $count);
1753
        $count = substr($count[0], 1, strlen($count[0]) - 2);
1754
        $magazine['count'] = str_replace(',', '', $count);
1755
1756
        $data[] = $magazine;
1757
    }
1758
1759
    return $data;
1760
}
1761
1762
function searchAnime($q, $page = 1)
1763
{
1764
    if (strlen($q) < 3) {
1765
        return 400;
1766
    }
1767
1768
    $page = 50 * ($page - 1);
1769
1770
    $url = 'https://myanimelist.net/anime.php?q='.$q.'&show='.$page;
1771
1772
    $file_headers = @get_headers($url);
1773
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1774
        return 404;
1775
    }
1776
1777
    $html = HtmlDomParser::file_get_html($url)->find('div[class^=js-categories-seasonal]', 0)->outertext;
1778
    $html = str_replace('&quot;', '\"', $html);
1779
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1780
    $html = HtmlDomParser::str_get_html($html);
1781
1782
    $data = [];
1783
    $result_table = $html->find('table', 0);
1784
    $result_area = $result_table->find('tr', 0)->next_sibling();
1785
    while (true) {
1786
        $result = [];
1787
1788
        // image
1789
        $image = $result_area->find('td', 0)->find('a img', 0)->getAttribute('data-src');
1790
        $result['image'] = imageUrlCleaner($image);
1791
1792
        $name_area = $result_area->find('td', 1);
1793
1794
        // id
1795
        $id = $name_area->find('div[id^=sarea]', 0)->id;
1796
        $id = str_replace('sarea', '', $id);
1797
        $result['id'] = $id;
1798
1799
        // title
1800
        $title = $name_area->find('strong', 0)->plaintext;
1801
        $result['title'] = $title;
1802
1803
        // summary
1804
        $summary = $name_area->find('.pt4', 0)->plaintext;
1805
        $result['summary'] = str_replace('read more.', '', $summary);
1806
1807
        // type
1808
        $type = $result_area->find('td', 2)->plaintext;
1809
        $result['type'] = trim($type);
1810
1811
        // episode
1812
        $episode = $result_area->find('td', 3)->plaintext;
1813
        $episode = trim($episode);
1814
        $episode = $episode == '-' ? '' : $episode;
1815
        $result['episode'] = $episode;
1816
1817
        // score
1818
        $score = $result_area->find('td', 4)->plaintext;
1819
        $score = trim($score);
1820
        $score = $score == 'N/A' ? '' : $score;
1821
        $result['score'] = $score;
1822
1823
        $data[] = $result;
1824
1825
        $result_area = $result_area->next_sibling();
1826
        if (!$result_area) {
1827
            break;
1828
        }
1829
    }
1830
    unset($result_table);
1831
    unset($result_area);
1832
1833
    return $data;
1834
}
1835
1836
function searchManga($q, $page = 1)
1837
{
1838
    if (strlen($q) < 3) {
1839
        return 400;
1840
    }
1841
1842
    $page = 50 * ($page - 1);
1843
1844
    $url = 'https://myanimelist.net/manga.php?q='.$q.'&show='.$page;
1845
1846
    $file_headers = @get_headers($url);
1847
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1848
        return 404;
1849
    }
1850
1851
    $html = HtmlDomParser::file_get_html($url)->find('div[class^=js-categories-seasonal]', 0)->outertext;
1852
    $html = str_replace('&quot;', '\"', $html);
1853
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1854
    $html = HtmlDomParser::str_get_html($html);
1855
1856
    $data = [];
1857
    $result_table = $html->find('table', 0);
1858
    $result_area = $result_table->find('tr', 0)->next_sibling();
1859
    while (true) {
1860
        $result = [];
1861
1862
        // image
1863
        $image = $result_area->find('td', 0)->find('a img', 0)->getAttribute('data-src');
1864
        $result['image'] = imageUrlCleaner($image);
1865
1866
        $name_area = $result_area->find('td', 1);
1867
1868
        // id
1869
        $id = $name_area->find('div[id^=sarea]', 0)->id;
1870
        $id = str_replace('sarea', '', $id);
1871
        $result['id'] = $id;
1872
1873
        // title
1874
        $title = $name_area->find('strong', 0)->plaintext;
1875
        $result['title'] = $title;
1876
1877
        // summary
1878
        $summary = $name_area->find('.pt4', 0)->plaintext;
1879
        $result['summary'] = str_replace('read more.', '', $summary);
1880
1881
        // type
1882
        $type = $result_area->find('td', 2)->plaintext;
1883
        $result['type'] = trim($type);
1884
1885
        // volume
1886
        $volume = $result_area->find('td', 3)->plaintext;
1887
        $result['volume'] = trim($volume);
1888
1889
        // score
1890
        $score = $result_area->find('td', 4)->plaintext;
1891
        $result['score'] = trim($score);
1892
1893
        $data[] = $result;
1894
1895
        $result_area = $result_area->next_sibling();
1896
        if (!$result_area) {
1897
            break;
1898
        }
1899
    }
1900
    unset($result_table);
1901
    unset($result_area);
1902
1903
    return $data;
1904
}
1905
1906
function searchCharacter($q, $page = 1)
1907
{
1908
    if (strlen($q) < 3) {
1909
        return 400;
1910
    }
1911
1912
    $url = 'https://myanimelist.net/character.php?q='.$q.'&show='.$page;
1913
1914
    $file_headers = @get_headers($url);
1915
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
1916
        return 404;
1917
    }
1918
1919
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
1920
    $html = str_replace('&quot;', '\"', $html);
1921
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
1922
    $html = HtmlDomParser::str_get_html($html);
1923
1924
    $data = [];
1925
    $result_table = $html->find('table', 0);
1926
    $result_area = $result_table->find('tr', 0)->next_sibling();
1927
    while (true) {
1928
        $result = [];
1929
1930
        // image
1931
        $image = $result_area->find('td', 0)->find('a img', 0)->src;
1932
        $result['image'] = imageUrlCleaner($image);
1933
1934
        $name_area = $result_area->find('td', 1);
1935
1936
        // id
1937
        $id = $name_area->find('a', 0)->href;
1938
        $parsed_char_id = explode('/', $id);
1939
        $id = $parsed_char_id[4];
1940
        $result['id'] = $id;
1941
1942
        // name
1943
        $name = $name_area->find('a', 0)->plaintext;
1944
        $result['name'] = $name;
1945
1946
        // nickname
1947
        $nickname = $name_area->find('small', 0);
1948
        $nickname = $nickname ? substr($nickname->plaintext, 1, strlen($nickname->plaintext) - 2) : '';
1949
        $result['nickname'] = $nickname;
1950
1951
        // role
1952
        $role = [];
1953
        $role['manga'] = $role['anime'] = [];
1954
        $role_area = $result_area->find('td', 2)->find('small', 0);
1955
        foreach ($role_area->find('a') as $each_role) {
1956
            $temp_role = [];
1957
1958
            // role id
1959
            $role_id = $each_role->href;
1960
            $parsed_role_id = explode('/', $role_id);
1961
            $role_id = $parsed_role_id[2];
1962
            $temp_role['id'] = $role_id;
1963
1964
            // role type
1965
            $role_type = $parsed_role_id[1];
1966
1967
            // role title
1968
            $role_title = $each_role->plaintext;
1969
            $temp_role['title'] = $role_title;
1970
1971
            if ($role_title) {
1972
                $role[$role_type][] = $temp_role;
1973
            }
1974
        }
1975
        $result = array_merge($result, $role);
1976
1977
        $data[] = $result;
1978
1979
        $result_area = $result_area->next_sibling();
1980
        if (!$result_area) {
1981
            break;
1982
        }
1983
    }
1984
1985
    return $data;
1986
}
1987
1988
function searchPeople($q, $page = 1)
1989
{
1990
    if (strlen($q) < 3) {
1991
        return 400;
1992
    }
1993
1994
    $page = 50 * ($page - 1);
1995
1996
    $url = 'https://myanimelist.net/people.php?q='.$q.'&show='.$page;
1997
1998
    $file_headers = @get_headers($url);
1999
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2000
        return 404;
2001
    }
2002
2003
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2004
    $html = str_replace('&quot;', '\"', $html);
2005
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2006
    $html = HtmlDomParser::str_get_html($html);
2007
2008
    $data = [];
2009
    $result_table = $html->find('table', 0);
2010
    $result_area = $result_table->find('tr', 0)->next_sibling();
2011
    while (true) {
2012
        $result = [];
2013
2014
        // image
2015
        $image = $result_area->find('td', 0)->find('a img', 0)->src;
2016
        $result['image'] = imageUrlCleaner($image);
2017
2018
        $name_area = $result_area->find('td', 1);
2019
2020
        // id
2021
        $id = $name_area->find('a', 0)->href;
2022
        $parsed_char_id = explode('/', $id);
2023
        $id = $parsed_char_id[2];
2024
        $result['id'] = $id;
2025
2026
        // name
2027
        $name = $name_area->find('a', 0)->plaintext;
2028
        $result['name'] = $name;
2029
2030
        // nickname
2031
        $nickname = $name_area->find('small', 0);
2032
        $nickname = $nickname ? substr($nickname->plaintext, 1, strlen($nickname->plaintext) - 2) : '';
2033
        $result['nickname'] = $nickname;
2034
2035
        $data[] = $result;
2036
2037
        $result_area = $result_area->next_sibling();
2038
        if (!$result_area) {
2039
            break;
2040
        }
2041
    }
2042
    unset($result_table);
2043
    unset($result_area);
2044
2045
    return $data;
2046
}
2047
2048
function searchUser($q, $page = 1)
2049
{
2050
    if (strlen($q) < 3) {
2051
        return 400;
2052
    }
2053
2054
    $page = 24 * ($page - 1);
2055
2056
    $url = 'https://myanimelist.net/users.php?q='.$q.'&show='.$page;
2057
2058
    $file_headers = @get_headers($url);
2059
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2060
        return 404;
2061
    }
2062
2063
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2064
    $html = str_replace('&quot;', '\"', $html);
2065
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2066
    $html = HtmlDomParser::str_get_html($html);
2067
2068
    $data = [];
2069
    foreach ($html->find('.borderClass') as $user) {
2070
        if ($user->align != 'center') {
2071
            continue;
2072
        }
2073
2074
        $temp_user = [];
2075
2076
        // username
2077
        $temp_user['name'] = $user->find('a', 0)->plaintext;
2078
2079
        // image
2080
        $temp_user['image'] = imageUrlCleaner($user->find('img', 0)->src);
2081
2082
        // last online
2083
        $temp_user['last_online'] = $user->find('small', 0)->plaintext;
2084
2085
        $data[] = $temp_user;
2086
    }
2087
2088
    return $data;
2089
}
2090
2091
function getSeason($year = false, $season = false)
2092
{
2093
    $year = !$year ? date('Y') : $year;
2094
    $season = !$season ? getCurrentSeason() : $season;
2095
2096
    $param = '/'.$year.'/'.$season;
2097
2098
    $url = 'https://myanimelist.net/anime/season'.$param;
2099
2100
    $file_headers = @get_headers($url);
2101
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2102
        return 404;
2103
    }
2104
2105
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->find('.js-categories-seasonal', 0)->outertext;
2106
    $html = str_replace('&quot;', '\"', $html);
2107
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2108
    $html = HtmlDomParser::str_get_html($html);
2109
2110
    $data = [];
2111
    $anime_table = $html->find('div[class="seasonal-anime js-seasonal-anime"]');
2112
    foreach ($anime_table as $each_anime) {
2113
        $result = [];
2114
2115
        // image
2116
        $temp_image = $each_anime->find('div[class=image]', 0)->find('img', 0);
2117
        $image = $temp_image->src;
2118
        if (!$image) {
2119
            $image = $temp_image->getAttribute('data-src');
2120
        }
2121
        $result['image'] = imageUrlCleaner($image);
2122
2123
        // id
2124
        $name_area = $each_anime->find('div[class=title]', 0);
2125
        $id = $name_area->find('p a', 0)->href;
2126
        $parsed_char_id = explode('/', $id);
2127
        $id = $parsed_char_id[4];
2128
        $result['id'] = $id;
2129
2130
        // title
2131
        $title = $name_area->find('p a', 0)->plaintext;
2132
        $result['title'] = $title;
2133
2134
        // producer
2135
        $producer = [];
2136
        $producer_area = $each_anime->find('div[class=prodsrc]', 0);
2137
        $temp_producer = $producer_area->find('span[class=producer]', 0);
2138
        foreach ($temp_producer->find('a') as $each_producer) {
2139
            $temp_prod = [];
2140
2141
            // prod id
2142
            $prod_id = $each_producer->href;
2143
            $parsed_prod_id = explode('/', $prod_id);
2144
            $temp_prod['id'] = $parsed_prod_id[3];
2145
2146
            // prod name
2147
            $prod_name = $each_producer->plaintext;
2148
            $temp_prod['name'] = $prod_name;
2149
2150
            $producer[] = $temp_prod;
2151
        }
2152
        $result['producer'] = $producer;
2153
2154
        // episode
2155
        $episode = $producer_area->find('div[class=eps]', 0)->plaintext;
2156
        $episode = trim(str_replace(['eps', 'ep'], '', $episode));
2157
        $episode = $episode == '?' ? '' : $episode;
2158
        $result['episode'] = $episode;
2159
2160
        // source
2161
        $source = $producer_area->find('span[class=source]', 0)->plaintext;
2162
        $result['source'] = trim($source);
2163
2164
        // genre
2165
        $genre = [];
2166
        $genre_area = $each_anime->find('div[class="genres js-genre"]', 0);
2167
        foreach ($genre_area->find('a') as $each_genre) {
2168
            $genre[] = $each_genre->plaintext;
2169
        }
2170
        $result['genre'] = $genre;
2171
2172
        // synopsis
2173
        $synopsis = $each_anime->find('div[class="synopsis js-synopsis"]', 0)->plaintext;
2174
        preg_match('/(No synopsis)/', $synopsis, $temp_synopsis);
2175
        if (!$temp_synopsis) {
2176
            $synopsis = trim(preg_replace("/([\s])+/", ' ', $synopsis));
2177
        } else {
2178
            $synopsis = '';
2179
        }
2180
        $result['synopsis'] = $synopsis;
2181
2182
        // licensor
2183
        $licensor = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $licensor is dead and can be removed.
Loading history...
2184
        $temp_licensor = $each_anime->find('div[class="synopsis js-synopsis"] .licensors', 0)->getAttribute('data-licensors');
2185
        $licensor = explode(',', $temp_licensor);
2186
        $result['licensor'] = array_filter($licensor);
2187
2188
        // type
2189
        $info_area = $each_anime->find('.information', 0);
2190
        $type = $info_area->find('.info', 0)->plaintext;
2191
        $type = explode('-', $type);
2192
        $type = trim($type[0]);
2193
        $result['type'] = $type;
2194
2195
        // airing start
2196
        $airing_start = $info_area->find('.info .remain-time', 0)->plaintext;
2197
        $result['airing_start'] = trim(str_replace(['?', ' ,'], ['', ','], $airing_start));
2198
2199
        // member
2200
        $member = $info_area->find('.scormem span[class^=member]', 0)->plaintext;
2201
        $result['member'] = trim(str_replace(',', '', $member));
2202
2203
        // score
2204
        $score = $info_area->find('.scormem .score', 0)->plaintext;
2205
        $result['score'] = trim(str_replace('N/A', '', $score));
2206
2207
        $data[] = $result;
2208
    }
2209
2210
    return $data;
2211
}
2212
2213
function getTopAnime($type = 0, $page = 1)
2214
{
2215
    $page = 50 * ($page - 1);
2216
    $type = getTopAnimeType($type);
2217
2218
    $url = 'https://myanimelist.net/topanime.php?type='.$type.'&limit='.$page;
2219
2220
    $file_headers = @get_headers($url);
2221
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2222
        return 404;
2223
    }
2224
2225
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2226
    $html = str_replace('&quot;', '\"', $html);
2227
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2228
    $html = HtmlDomParser::str_get_html($html);
2229
2230
    $data = [];
2231
    $data_index = 0;
2232
    $top_table = $html->find('table', 0);
2233
    foreach ($top_table->find('tr[class=ranking-list]') as $each_anime) {
2234
2235
        // rank
2236
        $rank = $each_anime->find('td span', 0)->plaintext;
2237
        $data[$data_index]['rank'] = trim($rank);
2238
2239
        // image
2240
        $image = $each_anime->find('td', 1)->find('a img', 0)->getAttribute('data-src');
2241
        $data[$data_index]['image'] = imageUrlCleaner($image);
2242
2243
        // id
2244
        $name_area = $each_anime->find('td .detail', 0);
2245
        $id = $name_area->find('div', 0)->id;
2246
        $id = str_replace('area', '', $id);
2247
        $data[$data_index]['id'] = $id;
2248
2249
        // title
2250
        $title = $name_area->find('a', 0)->plaintext;
2251
        $data[$data_index]['title'] = $title;
2252
2253
        // type
2254
        $info_area = $name_area->find('div[class^=information]', 0);
2255
        $parsed_info = explode('<br>', $info_area->innertext);
2256
        $parsed_info[0] = trim(preg_replace("/([\s])+/", ' ', $parsed_info[0]));
2257
        $parsed_info_2 = explode(' ', $parsed_info[0]);
2258
        $type = $parsed_info_2[0];
2259
        $data[$data_index]['type'] = $type;
2260
2261
        // episode
2262
        $episode = str_replace('(', '', $parsed_info_2[1]);
2263
        $episode = $episode == '?' ? '' : $episode;
2264
        $data[$data_index]['episode'] = $episode;
2265
2266
        // date
2267
        $date = explode('-', $parsed_info[1]);
2268
        $start_date = trim($date[0]);
2269
        $end_date = trim($date[1]);
2270
        $data[$data_index]['start_date'] = $start_date;
2271
        $data[$data_index]['end_date'] = $end_date;
2272
2273
        // member
2274
        $member = trim(str_replace(['members', 'favorites', ','], '', $parsed_info[2]));
2275
        $data[$data_index]['member'] = $member;
2276
2277
        //score
2278
        $score = $each_anime->find('td', 2)->plaintext;
2279
        $data[$data_index]['score'] = trim(str_replace('N/A', '', $score));
2280
2281
        $data_index++;
2282
    }
2283
    unset($top_table);
2284
2285
    return $data;
2286
}
2287
2288
function getTopManga($type = 0, $page = 1)
2289
{
2290
    $page = 50 * ($page - 1);
2291
    $type = getTopMangaType($type);
2292
2293
    $url = 'https://myanimelist.net/topmanga.php?type='.$type.'&limit='.$page;
2294
2295
    $file_headers = @get_headers($url);
2296
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2297
        return 404;
2298
    }
2299
2300
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2301
    $html = str_replace('&quot;', '\"', $html);
2302
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2303
    $html = HtmlDomParser::str_get_html($html);
2304
2305
    $data = [];
2306
    $data_index = 0;
2307
    $top_table = $html->find('table', 0);
2308
    foreach ($top_table->find('tr[class=ranking-list]') as $each_anime) {
2309
2310
        // rank
2311
        $rank = $each_anime->find('td span', 0)->plaintext;
2312
        $data[$data_index]['rank'] = trim($rank);
2313
2314
        // image
2315
        $image = $each_anime->find('td', 1)->find('a img', 0)->getAttribute('data-src');
2316
        $data[$data_index]['image'] = imageUrlCleaner($image);
2317
2318
        // id
2319
        $name_area = $each_anime->find('td .detail', 0);
2320
        $id = $name_area->find('div', 0)->id;
2321
        $id = str_replace('area', '', $id);
2322
        $data[$data_index]['id'] = $id;
2323
2324
        // title
2325
        $title = $name_area->find('a', 0)->plaintext;
2326
        $data[$data_index]['title'] = $title;
2327
2328
        // type
2329
        $info_area = $name_area->find('div[class^=information]', 0);
2330
        $parsed_info = explode('<br>', $info_area->innertext);
2331
        $parsed_info[0] = trim(preg_replace("/([\s])+/", ' ', $parsed_info[0]));
2332
        $parsed_info_2 = explode(' ', $parsed_info[0]);
2333
        $type = $parsed_info_2[0];
2334
        $data[$data_index]['type'] = $type;
2335
2336
        // volume
2337
        $volume = str_replace('(', '', $parsed_info_2[1]);
2338
        $volume = $volume == '?' ? '' : $volume;
2339
        $data[$data_index]['volume'] = $volume;
2340
2341
        // date
2342
        $date = explode('-', $parsed_info[1]);
2343
        $start_date = trim($date[0]);
2344
        $end_date = trim($date[1]);
2345
        $data[$data_index]['start_date'] = $start_date;
2346
        $data[$data_index]['end_date'] = $end_date;
2347
2348
        // member
2349
        $member = trim(str_replace(['members', 'favorites', ','], '', $parsed_info[2]));
2350
        $data[$data_index]['member'] = $member;
2351
2352
        //score
2353
        $score = $each_anime->find('td', 2)->plaintext;
2354
        $data[$data_index]['score'] = trim(str_replace('N/A', '', $score));
2355
2356
        $data_index++;
2357
    }
2358
    unset($top_table);
2359
2360
    return $data;
2361
}
2362
2363
function getUser($user)
2364
{
2365
    $url = 'https://myanimelist.net/profile/'.$user;
2366
2367
    $file_headers = @get_headers($url);
2368
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2369
        return 404;
2370
    }
2371
2372
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2373
    $html = str_replace('&quot;', '\"', $html);
2374
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2375
    $html = HtmlDomParser::str_get_html($html);
2376
2377
    $left_area = $html->find('.container-left .user-profile', 0);
2378
    $right_area = $html->find('.container-right', 0);
2379
2380
    // image
2381
    $image = $left_area->find('.user-image img', 0);
2382
    $profile_image = $image ? imageUrlCleaner($image->src) : '';
2383
2384
    // status
2385
    $last_online = $gender = $birthday = $location = $joined_date = '';
2386
    $status_area = $left_area->find('.user-status', 0);
2387
    foreach ($status_area->find('li') as $each_status) {
2388
        $status_type = trim($each_status->find('span', 0)->plaintext);
2389
        $status_value = trim($each_status->find('span', 1)->plaintext);
2390
2391
        switch ($status_type) {
2392
            // last online
2393
            case 'Last Online':
2394
            $last_online = $status_value;
2395
            break;
2396
2397
            // gender
2398
            case 'Gender':
2399
            $gender = $status_value;
2400
            break;
2401
2402
            // birthday
2403
            case 'Birthday':
2404
            $birthday = $status_value;
2405
            break;
2406
2407
            // location
2408
            case 'Location':
2409
            $location = $status_value;
2410
            break;
2411
2412
            // joined date
2413
            case 'Joined':
2414
            $joined_date = $status_value;
2415
            break;
2416
2417
            default:
2418
            '';
2419
        }
2420
    }
2421
2422
    // forum post
2423
    $status_area = $left_area->find('.user-status', 2);
2424
    $forum_post = trim($status_area->find('li', 0)->find('span', 1)->plaintext);
2425
2426
    // review
2427
    $review = trim($status_area->find('li', 1)->find('span', 1)->plaintext);
2428
2429
    // recommendation
2430
    $recommendation = trim($status_area->find('li', 2)->find('span', 1)->plaintext);
2431
2432
    // blog post
2433
    $blog_post = trim($status_area->find('li', 1)->find('span', 1)->plaintext);
2434
2435
    // club
2436
    $club = trim($status_area->find('li', 1)->find('span', 1)->plaintext);
2437
2438
    // sns
2439
    $sns = [];
2440
    $sns_area = $left_area->find('.user-profile-sns', 0);
2441
    foreach ($sns_area->find('a') as $each_sns) {
2442
        if ($each_sns->class != 'di-ib mb8') {
2443
            $sns[] = $each_sns->href;
2444
        }
2445
    }
2446
    unset($sns_area);
2447
2448
    // friend
2449
    $friend = [];
2450
    $friend_area = $left_area->find('.user-friends', 0);
2451
2452
    $friend_count = $friend_area->prev_sibling()->find('a', 0)->plaintext;
2453
    preg_match('/\(\d+\)/', $friend_count, $friend_count);
2454
    $friend['count'] = str_replace(['(', ')'], '', $friend_count[0]);
2455
2456
    $friend['data'] = [];
2457
    foreach ($friend_area->find('a') as $f) {
2458
        $temp_friend = [];
2459
2460
        $temp_friend['name'] = $f->plaintext;
2461
        $temp_friend['image'] = imageUrlCleaner($f->getAttribute('data-bg'));
2462
2463
        $friend['data'][] = $temp_friend;
2464
    }
2465
    unset($friend_area);
2466
2467
    // about
2468
    $about = $right_area->find('table tr td div[class=word-break]', 0);
2469
    $about = $about ? trim($about->innertext) : '';
2470
2471
    // anime stats
2472
    $anime_stat = [];
2473
    $stat_area = $right_area->find('.user-statistics', 0);
2474
    $a_stat_area = $stat_area->find('div[class="user-statistics-stats mt16"]', 0);
2475
    $a_stat_score = $a_stat_area->find('.stat-score', 0);
2476
2477
    // days
2478
    $days = $a_stat_score->find('div', 0);
2479
    $temp_days = $days->find('span', 0)->plaintext;
2480
    $days = str_replace($temp_days, '', $days->plaintext);
2481
    $anime_stat['days'] = $days;
2482
2483
    // mean score
2484
    $mean_score = $a_stat_score->find('div', 1);
2485
    $temp_score = $mean_score->find('span', 0)->plaintext;
2486
    $mean_score = str_replace($temp_score, '', $mean_score->plaintext);
2487
    $anime_stat['mean_score'] = $mean_score;
2488
2489
    // anime status
2490
    $temp_stat = [];
2491
    $a_stat_status = $a_stat_area->find('ul[class=stats-status]', 0);
2492
    $temp_stat['watching'] = trim($a_stat_status->find('span', 0)->plaintext);
2493
    $temp_stat['completed'] = trim($a_stat_status->find('span', 1)->plaintext);
2494
    $temp_stat['on_hold'] = trim($a_stat_status->find('span', 2)->plaintext);
2495
    $temp_stat['dropped'] = trim($a_stat_status->find('span', 3)->plaintext);
2496
    $temp_stat['plan_to_watch'] = trim($a_stat_status->find('span', 4)->plaintext);
2497
2498
    $a_stat_status = $a_stat_area->find('ul[class=stats-data]', 0);
2499
    $temp_stat['total'] = str_replace(',', '', trim($a_stat_status->find('span', 1)->plaintext));
2500
    $temp_stat['rewatched'] = str_replace(',', '', trim($a_stat_status->find('span', 3)->plaintext));
2501
    $temp_stat['episode'] = str_replace(',', '', trim($a_stat_status->find('span', 5)->plaintext));
2502
2503
    $anime_stat['status'] = $temp_stat;
2504
2505
    // history
2506
    $history = [];
2507
    $a_history_area = $right_area->find('div[class="updates anime"]', 0);
2508
    foreach ($a_history_area->find('.statistics-updates') as $each_history) {
2509
        $temp_history = [];
2510
2511
        // image
2512
        $image = $each_history->find('img', 0)->src;
2513
        $temp_history['image'] = imageUrlCleaner($image);
2514
2515
        // id
2516
        $history_data_area = $each_history->find('.data', 0);
2517
        $id = $history_data_area->find('a', 0)->href;
2518
        $id = explode('/', $id);
2519
        $temp_history['id'] = $id[4];
2520
2521
        // title
2522
        $title = $history_data_area->find('a', 0)->plaintext;
2523
        $temp_history['title'] = $title;
2524
2525
        // date
2526
        $date = $history_data_area->find('span', 0)->plaintext;
2527
        $temp_history['date'] = trim($date);
2528
2529
        // progress
2530
        $progress = $history_data_area->find('.graph-content', 0)->next_sibling()->innertext;
2531
        $progress = trim(preg_replace("/([\s])+/", ' ', strip_tags($progress)));
2532
        $progress = explode('·', $progress);
2533
        $p1 = explode(' ', $progress[0]);
2534
2535
        $temp_history['status'] = strtolower(count($p1) > 3 ? $progress[0] : $p1[0]);
2536
        $temp_history['progress'] = count($p1) > 3 ? '-' : $p1[1];
2537
        $temp_history['score'] = trim(str_replace('Scored', '', $progress[1]));
2538
2539
        $history[] = $temp_history;
2540
    }
2541
2542
    $anime_stat['history'] = $history;
2543
2544
    // manga stats
2545
    $manga_stat = [];
2546
    $m_stat_area = $stat_area->find('div[class="user-statistics-stats mt16"]', 1);
2547
    $m_stat_score = $m_stat_area->find('.stat-score', 0);
2548
2549
    // days
2550
    $days = $m_stat_score->find('div', 0);
2551
    $temp_days = $days->find('span', 0)->plaintext;
2552
    $days = str_replace($temp_days, '', $days->plaintext);
2553
    $manga_stat['days'] = $days;
2554
2555
    // mean score
2556
    $mean_score = $m_stat_score->find('div', 1);
2557
    $temp_score = $mean_score->find('span', 0)->plaintext;
2558
    $mean_score = str_replace($temp_score, '', $mean_score->plaintext);
2559
    $manga_stat['mean_score'] = $mean_score;
2560
2561
    // manga status
2562
    $temp_stat = [];
2563
    $m_stat_status = $m_stat_area->find('ul[class=stats-status]', 0);
2564
    $temp_stat['reading'] = trim($m_stat_status->find('span', 0)->plaintext);
2565
    $temp_stat['completed'] = trim($m_stat_status->find('span', 1)->plaintext);
2566
    $temp_stat['on_hold'] = trim($m_stat_status->find('span', 2)->plaintext);
2567
    $temp_stat['dropped'] = trim($m_stat_status->find('span', 3)->plaintext);
2568
    $temp_stat['plan_to_read'] = trim($m_stat_status->find('span', 4)->plaintext);
2569
2570
    $m_stat_status = $m_stat_area->find('ul[class=stats-data]', 0);
2571
    $temp_stat['total'] = str_replace(',', '', trim($m_stat_status->find('span', 1)->plaintext));
2572
    $temp_stat['reread'] = str_replace(',', '', trim($m_stat_status->find('span', 3)->plaintext));
2573
    $temp_stat['chapter'] = str_replace(',', '', trim($m_stat_status->find('span', 5)->plaintext));
2574
    $temp_stat['volume'] = str_replace(',', '', trim($m_stat_status->find('span', 7)->plaintext));
2575
2576
    $manga_stat['status'] = $temp_stat;
2577
2578
    // history
2579
    $history = [];
2580
    $m_history_area = $right_area->find('div[class="updates manga"]', 0);
2581
    foreach ($m_history_area->find('.statistics-updates') as $each_history) {
2582
        $temp_history = [];
2583
2584
        // image
2585
        $image = $each_history->find('img', 0)->src;
2586
        $temp_history['image'] = imageUrlCleaner($image);
2587
2588
        // id
2589
        $history_data_area = $each_history->find('.data', 0);
2590
        $id = $history_data_area->find('a', 0)->href;
2591
        $id = explode('/', $id);
2592
        $temp_history['id'] = $id[4];
2593
2594
        // title
2595
        $title = $history_data_area->find('a', 0)->plaintext;
2596
        $temp_history['title'] = $title;
2597
2598
        // date
2599
        $date = $history_data_area->find('span', 0)->plaintext;
2600
        $temp_history['date'] = trim($date);
2601
2602
        // progress
2603
        $progress = $history_data_area->find('.graph-content', 0)->next_sibling()->innertext;
2604
        $progress = trim(preg_replace("/([\s])+/", ' ', strip_tags($progress)));
2605
        $progress = explode('·', $progress);
2606
        $p1 = explode(' ', $progress[0]);
2607
2608
        $temp_history['status'] = strtolower(count($p1) > 3 ? $progress[0] : $p1[0]);
2609
        $temp_history['progress'] = count($p1) > 3 ? '-' : $p1[1];
2610
        $temp_history['score'] = trim(str_replace('Scored', '', $progress[1]));
2611
2612
        $history[] = $temp_history;
2613
    }
2614
2615
    $manga_stat['history'] = $history;
2616
2617
    // favorite
2618
    $favorite = [];
2619
    $favorite_area = $right_area->find('.user-favorites-outer', 0);
2620
2621
    // favorite anime
2622
    $favorite['anime'] = [];
2623
    $anime_area = $favorite_area->find('ul[class="favorites-list anime"]', 0);
2624
    if ($anime_area) {
2625
        foreach ($anime_area->find('li') as $each_anime) {
2626
            $temp_anime = [];
2627
2628
            // image
2629
            $image = $each_anime->find('a', 0)->style;
2630
            preg_match('/\'([^\'])*/', $image, $image);
2631
            $image = substr($image[0], 1);
2632
            $temp_anime['image'] = imageUrlCleaner($image);
2633
2634
            // id
2635
            $id = $each_anime->find('a', 0)->href;
2636
            $id = explode('/', $id);
2637
            $temp_anime['id'] = $id[4];
2638
2639
            // title
2640
            $title = $each_anime->find('a', 1)->plaintext;
2641
            $temp_anime['title'] = $title;
2642
2643
            // type
2644
            $temp_type = $each_anime->find('span', 0)->plaintext;
2645
            $temp_type = explode('·', $temp_type);
2646
            $temp_anime['type'] = trim($temp_type[0]);
2647
2648
            // year
2649
            $temp_anime['year'] = trim($temp_type[1]);
2650
2651
            $favorite['anime'][] = $temp_anime;
2652
        }
2653
    }
2654
    unset($anime_area);
2655
2656
    // favorite manga
2657
    $favorite['manga'] = [];
2658
    $manga_area = $favorite_area->find('ul[class="favorites-list manga"]', 0);
2659
    if ($manga_area) {
2660
        foreach ($manga_area->find('li') as $each_manga) {
2661
            $temp_manga = [];
2662
2663
            // image
2664
            $image = $each_manga->find('a', 0)->style;
2665
            preg_match('/\'([^\'])*/', $image, $image);
2666
            $image = substr($image[0], 1);
2667
            $temp_manga['image'] = imageUrlCleaner($image);
2668
2669
            // id
2670
            $id = $each_manga->find('a', 0)->href;
2671
            $id = explode('/', $id);
2672
            $temp_manga['id'] = $id[4];
2673
2674
            // title
2675
            $title = $each_manga->find('a', 1)->plaintext;
2676
            $temp_manga['title'] = $title;
2677
2678
            // type
2679
            $temp_type = $each_manga->find('span', 0)->plaintext;
2680
            $temp_type = explode('·', $temp_type);
2681
            $temp_manga['type'] = trim($temp_type[0]);
2682
2683
            // year
2684
            $temp_manga['year'] = trim($temp_type[1]);
2685
2686
            $favorite['manga'][] = $temp_manga;
2687
        }
2688
    }
2689
    unset($manga_area);
2690
2691
    // favorite character
2692
    $favorite['character'] = [];
2693
    $char_area = $favorite_area->find('ul[class="favorites-list characters"]', 0);
2694
    if ($char_area) {
2695
        foreach ($char_area->find('li') as $each_char) {
2696
            $temp_char = [];
2697
2698
            // image
2699
            $image = $each_char->find('a', 0)->style;
2700
            preg_match('/\'([^\'])*/', $image, $image);
2701
            $image = substr($image[0], 1);
2702
            $temp_char['image'] = imageUrlCleaner($image);
2703
2704
            // id
2705
            $id = $each_char->find('a', 0)->href;
2706
            $id = explode('/', $id);
2707
            $temp_char['id'] = $id[4];
2708
2709
            // name
2710
            $name = $each_char->find('a', 1)->plaintext;
2711
            $temp_char['name'] = $name;
2712
2713
            // anime id
2714
            $anime_id = $each_char->find('a', 2)->href;
2715
            $anime_id = explode('/', $anime_id);
2716
            $temp_char['anime_id'] = $anime_id[2];
2717
2718
            // anime title
2719
            $anime_title = $each_char->find('a', 2)->plaintext;
2720
            $temp_char['anime_title'] = trim($anime_title);
2721
2722
            $favorite['character'][] = $temp_char;
2723
        }
2724
    }
2725
    unset($char_area);
2726
2727
    // favorite people
2728
    $favorite['people'] = [];
2729
    $people_area = $favorite_area->find('ul[class="favorites-list people"]', 0);
2730
    if ($people_area) {
2731
        foreach ($people_area->find('li') as $each_people) {
2732
            $temp_people = [];
2733
2734
            // image
2735
            $image = $each_people->find('a', 0)->style;
2736
            preg_match('/\'([^\'])*/', $image, $image);
2737
            $image = substr($image[0], 1);
2738
            $temp_people['image'] = imageUrlCleaner($image);
2739
2740
            // id
2741
            $id = $each_people->find('a', 0)->href;
2742
            $id = explode('/', $id);
2743
            $temp_people['id'] = $id[4];
2744
2745
            // name
2746
            $name = $each_people->find('a', 1)->plaintext;
2747
            $temp_people['name'] = $name;
2748
2749
            $favorite['people'][] = $temp_people;
2750
        }
2751
    }
2752
    unset($people_area);
2753
2754
    $data = [
2755
        'username'       => $user,
2756
        'image'          => $profile_image,
2757
        'last_online'    => $last_online,
2758
        'gender'         => $gender,
2759
        'birthday'       => $birthday,
2760
        'location'       => $location,
2761
        'joined_date'    => $joined_date,
2762
        'forum_post'     => $forum_post,
2763
        'review'         => $review,
2764
        'recommendation' => $recommendation,
2765
        'blog_post'      => $blog_post,
2766
        'club'           => $club,
2767
        'sns'            => $sns,
2768
        'friend'         => $friend,
2769
        'about'          => $about,
2770
        'anime_stat'     => $anime_stat,
2771
        'manga_stat'     => $manga_stat,
2772
        'favorite'       => $favorite,
2773
    ];
2774
2775
    return $data;
2776
}
2777
2778
function getUserFriend($user)
2779
{
2780
    $url = 'https://myanimelist.net/profile/'.$user;
2781
2782
    $file_headers = @get_headers($url);
2783
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2784
        return 404;
2785
    }
2786
2787
    $url = 'https://myanimelist.net/profile/'.$user.'/friends';
2788
2789
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2790
    $html = str_replace('&quot;', '\"', $html);
2791
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2792
    $html = HtmlDomParser::str_get_html($html);
2793
2794
    $friend = [];
2795
    $friend_area = $html->find('.majorPad', 0);
2796
    if ($friend_area) {
2797
        foreach ($friend_area->find('.friendHolder') as $f) {
2798
            $f_dump = [];
2799
            $f = $f->find('.friendBlock', 0);
2800
2801
            // picture
2802
            $f_dump['image'] = imageUrlCleaner($f->find('a img', 0)->src);
2803
2804
            // name
2805
            $name_temp = $f->find('a', 0)->href;
2806
            $name_temp = explode('/', $name_temp);
2807
            $f_dump['name'] = $name_temp[4];
2808
2809
            // last online
2810
            $last_online = $f->find('strong', 0)->parent()->parent()->next_sibling();
2811
            $f_dump['last_online'] = trim($last_online->plaintext);
2812
2813
            // friend since
2814
            $friend_since = $last_online->next_sibling();
2815
            $friend_since = str_replace('Friends since', '', $friend_since->plaintext);
2816
            $f_dump['friend_since'] = trim($friend_since);
2817
2818
            $friend[] = $f_dump;
2819
        }
2820
    }
2821
2822
    $data = $friend;
2823
2824
    return $data;
2825
}
2826
2827
function getUserHistory($user, $type = false)
2828
{
2829
    $url = 'https://myanimelist.net/profile/'.$user;
2830
2831
    $file_headers = @get_headers($url);
2832
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2833
        return 404;
2834
    }
2835
2836
    $url = 'https://myanimelist.net/history/'.$user;
2837
2838
    if ($type) {
2839
        $url .= '/'.$type;
2840
    }
2841
2842
    $html = HtmlDomParser::file_get_html($url)->find('#content', 0)->outertext;
2843
    $html = str_replace('&quot;', '\"', $html);
2844
    $html = html_entity_decode($html, ENT_QUOTES, 'UTF-8');
2845
    $html = HtmlDomParser::str_get_html($html);
2846
2847
    $data = [];
2848
    $history_area = $html->find('table', 0);
2849
    if ($history_area) {
2850
        foreach ($history_area->find('tr') as $history) {
2851
            if ($history->find('td', 0)->class != 'borderClass') {
2852
                continue;
2853
            }
2854
            $h_temp = [];
2855
2856
            $name_area = $history->find('td', 0);
2857
2858
            // id
2859
            $temp_id = $name_area->find('a', 0)->href;
2860
            $temp_id = explode('=', $temp_id);
2861
            $h_temp['id'] = $temp_id[1];
2862
2863
            // title
2864
            $h_temp['title'] = $name_area->find('a', 0)->plaintext;
2865
2866
            // type
2867
            $type = $name_area->find('a', 0)->href;
2868
            $type = explode('.php', $type);
2869
            $h_temp['type'] = substr($type[0], 1);
2870
2871
            // number
2872
            $progress = $name_area->find('strong', 0)->plaintext;
2873
            $h_temp['progress'] = $progress;
2874
2875
            // date
2876
            $date = $history->find('td', 1);
2877
            $useless_date = $date->find('a', 0);
2878
            $date = $date->plaintext;
2879
            if ($useless_date) {
2880
                $date = str_replace($useless_date, '', $date);
2881
            }
2882
            $h_temp['date'] = trim($date);
2883
2884
            $data[] = $h_temp;
2885
        }
2886
    }
2887
2888
    return $data;
2889
}
2890
2891
function getUserList($user, $type = 'anime', $status = 7)
2892
{
2893
    $url = 'https://myanimelist.net/'.$type.'list/'.$user.'?status='.$status;
2894
2895
    $file_headers = @get_headers($url);
2896
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 404 Not Found') {
0 ignored issues
show
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2897
        return 404;
2898
    }
2899
2900
    if (!$file_headers || $file_headers[0] == 'HTTP/1.1 403 Forbidden') {
0 ignored issues
show
introduced by
$file_headers is a non-empty array, thus ! $file_headers is always false.
Loading history...
Bug Best Practice introduced by
The expression $file_headers of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
2901
        return 403;
2902
    }
2903
2904
    $data = [];
2905
    $offset = 0;
2906
    while (true) {
2907
        $url = 'https://myanimelist.net/'.$type.'list/'.$user.'/load.json?offset='.$offset.'&status='.$status;
2908
2909
        $content = json_decode(file_get_contents($url), true);
2910
2911
        if ($content) {
2912
            for ($i = 0; $i < count($content); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
2913
                if (!empty($content[$i]['anime_image_path'])) {
2914
                    $content[$i]['anime_image_path'] = imageUrlCleaner($content[$i]['anime_image_path']);
2915
                } else {
2916
                    $content[$i]['manga_image_path'] = imageUrlCleaner($content[$i]['manga_image_path']);
2917
                }
2918
            }
2919
2920
            $data = array_merge($data, $content);
2921
2922
            $offset += 300;
2923
        } else {
2924
            break;
2925
        }
2926
    }
2927
2928
    return $data;
2929
}
2930
2931
function getUserCover($user, $type = 'anime', $style = false)
2932
{
2933
    if (!$style) {
2934
        $style = "tr:hover .animetitle[href*='/{id}/']:before{background-image:url({url})}";
2935
    }
2936
2937
    $list = getUserList($user, $type);
2938
2939
    $cover = '';
2940
    foreach ($list as $c) {
2941
        if ($type == 'anime') {
2942
            $temp = str_replace(['{id}', '{url}'], [$c['anime_id'], $c['anime_image_path']], $style);
2943
        } else {
2944
            $temp = str_replace(['{id}', '{url}'], [$c['manga_id'], $c['manga_image_path']], $style);
2945
        }
2946
2947
        $cover .= $temp."\n";
2948
    }
2949
2950
    return $cover;
2951
}
2952