-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPI.php
executable file
·774 lines (660 loc) · 22.3 KB
/
API.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
<?php
/*
XIVPads.com (v4) - Lodestone Query API
--------------------------------------------------
Author: Josh Freeman (Premium Virtue)
Support: http://xivpads.com/?Portal
Version: 4.0
PHP: 5.4
Always ensure you download from the github
https://github.com/viion/XIVPads-LodestoneAPI
--------------------------------------------------
*/
// Debug stuff
#error_reporting(-1);
//function show($Data) { echo '<pre>'; print_r($Data); echo '</pre>'; }
/* LodestoneAPI
* ------------
*/
class Lodestone_API extends Loadstone_Parser
{
// url addresses to various lodestone content. (DO NOT CHANGE, it will break some functionality of the API)
private $URL =
[
# Search related urls
'search' =>
[
'query' => '?q=%name%&worldname=%server%',
],
# Character related urls
'character' =>
[
'profile' => 'http://eu.finalfantasyxiv.com/lodestone/character/',
'achievement' => '/achievement/kind/',
],
# Free company related urls
'freecompany' =>
[
'profile' => 'http://eu.finalfantasyxiv.com/lodestone/freecompany/',
'member' => '/member/',
'memberpage' => '?page=%page%',
],
# Linkshell related urls
'linkshell' =>
[
'profile' => 'http://eu.finalfantasyxiv.com/lodestone/linkshell/',
'activity' => '/activity/',
],
];
// defaults
private $defaults =
[
'automaticallyParseFreeCompanyMembers' => false,
'pagesPerFreeCompanyMemberList' => 20,
];
// Configuration
public $AchievementCategories = [1, 2, 4, 5, 6, 8, 11, 12, 13];
public $ClassList = [];
public $ClassDisicpline = [];
// List of characters parsed
public $Characters = [];
public $Achievements = [];
public $Search = [];
// List of free company data parsed
public $FreeCompanyList = [];
public $FreeCompanyMembersList = [];
// List of linkshell data parsed
public $Linkshells = [];
public function __construct()
{
// Set classes
$this->ClassList = array(
"Gladiator", "Pugilist", "Marauder", "Lancer", "Archer", "Conjurer", "Thaumaturge", "Arcanist", "Carpenter", "Blacksmith",
"Armorer", "Goldsmith", "Leatherworker", "Weaver", "Alchemist", "Culinarian", "Miner", "Botanist", "Fisher"
);
// Set class by disicpline
$this->ClassDisicpline = array(
"dow" => array_slice($this->ClassList, 0, 5),
"dom" => array_slice($this->ClassList, 5, 3),
"doh" => array_slice($this->ClassList, 8, 8),
"dol" => array_slice($this->ClassList, 16, 3),
);
}
// Quick get
public function get($Array, $Options = null)
{
// Clean
$Name = isset($Array['name']) ? trim(ucwords($Array['name'])) : NULL;
$Server = isset($Array['server']) ? trim(ucwords($Array['server'])) : NULL;
$ID = isset($Array['id']) ? trim($Array['id']) : NULL;
// If no ID passed, find it.
if (!$ID)
{
// Search by Name + Server, exact
$this->searchCharacter($Name, $Server, true);
// Get by specific ID
$ID = $this->getSearch()['results'][0]['id'];
}
// If an ID
if ($ID)
{
// Parse profile
$this->parseProfile($ID);
// Return character
return $this->getCharacterByID($ID);
}
else
{
return false;
}
}
// Quick get free company
public function getFC($Array, $Options = null)
{
// Clean
$Name = isset($Array['name']) ? trim(ucwords($Array['name'])) : NULL;
$Server = isset($Array['server']) ? trim(ucwords($Array['server'])) : NULL;
$ID = isset($Array['id']) ? trim($Array['id']) : NULL;
// If no ID passed, find it.
if (!$ID)
{
// Search by Name + Server, exact
$this->searchFreeCompany($Name, $Server, true);
// Get by specific ID
$ID = $this->getSearch()['results'][0]['id'];
}
// If an ID
if ($ID)
{
// Parse profile
$this->parseFreeCompany($ID, $Options);
// Return character
return $this->getFreeCompanyByID($ID);
}
else
{
return false;
}
}
// Quick get linkshell
public function getLS($Array, $Options = null)
{
// Clean
$Name = isset($Array['name']) ? trim(ucwords($Array['name'])) : NULL;
$Server = isset($Array['server']) ? trim(ucwords($Array['server'])) : NULL;
$ID = isset($Array['id']) ? trim($Array['id']) : NULL;
// If no ID passed, find it.
if (!$ID)
{
// Search by Name + Server, exact
$this->searchLinkshell($Name, $Server, true);
// Get by specific ID
$ID = $this->getSearch()['results'][0]['id'];
}
// If an ID
if ($ID)
{
// Parse profile
$this->parseLinkshell($ID, $Options);
// Return character
return $this->getLinkshellByID($ID);
}
else
{
return false;
}
}
#-------------------------------------------#
# SEARCH #
#-------------------------------------------#
// Search a character by its name and server.
public function searchCharacter($Name, $Server, $GetExact = true)
{
if (!$Name)
{
echo "error: No Name Set.";
}
else if (!$Server)
{
echo "error: No Server Set.";
}
else
{
// Exact name for later
$ExactName = $Name;
// Get the source
$this->getSource($this->URL['character']['profile'] . str_ireplace(array('%name%', '%server%'), array(str_ireplace(" ", "+", $Name), $Server), $this->URL['search']['query']));
// Get all found characters
$Found = $this->findAll('thumb_cont_black_50', 10, NULL, false);
// Loop through results
if ($Found)
{
foreach($Found as $F)
{
$Avatar = explode('"', $F[1])[3];
$Data = explode('"', $F[6]);
$ID = trim(explode('/', $Data[3])[3]);
$NameServer = explode("(", trim(str_ireplace(">", NULL, strip_tags(html_entity_decode($Data[4])))));
$Name = htmlspecialchars_decode(trim($NameServer[0]), ENT_QUOTES);
$Server = trim(str_ireplace(")", NULL, $NameServer[1]));
$Language = $F[4];
// Append search results
$this->Search['results'][] = array(
"avatar" => $Avatar,
"name" => $Name,
"server" => $Server,
"id" => $ID,
);
}
// If to get exact
if ($GetExact)
{
$Exact = false;
foreach($this->Search['results'] as $Character)
{
//show($Character['name'] .' < > '. $ExactName);
//show(md5($Character['name']) .' < > '. md5($ExactName));
//show(strlen($Character['name']) .' < > '. strlen($ExactName));
if (($Character['name']) == ($ExactName) && strlen(trim($Character['name'])) == strlen(trim($ExactName)))
{
$Exact = true;
$this->Search['results'] = NULL;
$this->Search['results'][] = $Character;
$this->Search['isExact'] = true;
break;
}
}
// If no exist false, null array
if (!$Exact)
{
$this->Search = NULL;
}
}
// Number of results
$this->Search['total'] = count($this->Search['results']);
}
else
{
$this->Search['total'] = 0;
$this->Search['results'] = NULL;
}
}
}
// Search a free company by name and server
public function searchFreeCompany($Name, $Server, $GetExact = true)
{
if (!$Name)
{
echo "error: No Name Set.";
}
else if (!$Server)
{
echo "error: No Server Set.";
}
else
{
// Exact name for later
$ExactName = $Name;
// Get the source
$this->getSource($this->URL['freecompany']['profile'] . str_ireplace(array('%name%', '%server%'), array(str_ireplace(" ", "+", $Name), $Server), $this->URL['search']['query']));
// Get all found data
$Found = $this->findAll('ic_freecompany_box', 20, NULL, false);
// if found
if ($Found)
{
foreach($Found as $F)
{
$Company = $this->clean($F[3]);
$ID = trim(explode("/", $F[5])[3]);
$Name = trim(explode("(", $this->clean($F[5]))[0]);
$Server = str_ireplace(")", "", trim(explode("(", $this->clean($F[5]))[1]));
$Members = trim(explode(":", $this->clean($F[8]))[1]);
$Formed = trim(explode(",", explode("(", $F[13])[2])[0]);
$this->Search['results'][] =
array(
"id" => $ID,
"company" => $Company,
"name" => $Name,
"server" => $Server,
"members" => $Members,
"formed" => $Formed,
);
}
// If to get exact
if ($GetExact)
{
$Exact = false;
foreach($this->Search['results'] as $FreeCompany)
{
if (($FreeCompany['name']) == ($ExactName) && strlen(trim($FreeCompany['name'])) == strlen(trim($ExactName)))
{
$Exact = true;
$this->Search['results'] = NULL;
$this->Search['results'][] = $FreeCompany;
$this->Search['isExact'] = true;
break;
}
}
// If no exist false, null array
if (!$Exact)
{
$this->Search = NULL;
}
}
}
else
{
$this->Search['total'] = 0;
$this->Search['results'] = NULL;
}
}
}
// Search a linkshell by name and server
public function searchLinkshell($Name, $Server, $GetExact = true)
{
if (!$Name)
{
echo "error: No Name Set.";
}
else if (!$Server)
{
echo "error: No Server Set.";
}
else
{
// Exact name for later
$ExactName = $Name;
// Get the source
$this->getSource($this->URL['linkshell']['profile'] . str_ireplace(array('%name%', '%server%'), array(str_ireplace(" ", "+", $Name), $Server), $this->URL['search']['query']));
// Get all found data
$Found = $this->findAll('player_name_gold linkshell_name', 5, NULL, false);
// if found
if ($Found)
{
foreach($Found as $F)
{
$ID = trim(explode("/", $F[0])[3]);
$Name = trim(str_ireplace(['"', '<', '>'], null, explode("/", $F[0])[4]));
$Server = trim(strip_tags(html_entity_decode(str_ireplace(")", null, explode("(", $F[0])[1]))));
$Members = trim(explode(":", strip_tags(html_entity_decode($F[3])))[1]);
$this->Search['results'][] =
[
"id" => $ID,
"name" => $Name,
"server" => $Server,
"members" => $Members,
];
}
// If to get exact
if ($GetExact)
{
$Exact = false;
foreach($this->Search['results'] as $Linkshell)
{
if (($Linkshell['name']) == ($ExactName) && strlen(trim($Linkshell['name'])) == strlen(trim($ExactName)))
{
$Exact = true;
$this->Search['results'] = NULL;
$this->Search['results'][] = $Linkshell;
$this->Search['isExact'] = true;
break;
}
}
// If no exist false, null array
if (!$Exact)
{
$this->Search = NULL;
}
}
}
else
{
$this->Search['total'] = 0;
$this->Search['results'] = NULL;
}
}
}
// Get search results
public function getSearch() { return $this->Search; }
// Checks if an error page exists
public function errorPage($ID)
{
// Get the source
$this->getSource($this->URL['character']['profile'] . $ID);
// Check character tag
$PageNotFound = $this->find('/lodestone/character/');
// if not found, error.
if (!$PageNotFound) { return true; }
return false;
}
#-------------------------------------------#
# PROFILE #
#-------------------------------------------#
// Parse a profile based on ID.
public function parseProfile($ID)
{
if (!$ID)
{
echo "error: No ID Set.";
}
else if ($this->errorPage($ID))
{
echo "error: Character page does not exist.";
}
else
{
// Get the source
$this->getSource($this->URL['character']['profile'] . $ID);
// Create a new character object
$Character = new Lodestone_Character();
// Set Character Data
$Character->setID(trim($ID), $this->URL['character']['profile'] . $ID);
$Character->setNameServer($this->findRange('player_name_brown', 3));
// Only process if character name set
if (strlen($Character->getName()) > 3)
{
$Character->setAvatar($this->findRange('thumb_cont_black_40', 3, NULL, false));
$Character->setPortrait($this->findRange('bg_chara_264', 2, NULL, false));
$Character->setRaceClan($this->find('chara_profile_title'));
$Character->setLegacy($this->find('bt_legacy_history'));
$Character->setBirthGuardianCompany($this->findRange('chara_profile_list', 60, NULL, false));
$Character->setCity($this->findRange('City-state', 5));
$Character->setBiography($this->findRange('txt_selfintroduction', 5));
$Character->setHPMPTP($this->findRange('param_power_area', 10));
$Character->setAttributes($this->findRange('param_list_attributes', 8));
$Character->setElemental($this->findRange('param_list_elemental', 8));
$Character->setOffense($this->findRange('param_title_offense', 6));
$Character->setDefense($this->findRange('param_title_deffense', 6));
$Character->setPhysical($this->findRange('param_title_melle', 6));
$Character->setResists($this->findRange('param_title_melleresists', 6));
$Character->setActiveClassLevel($this->findRange('"class_info"', 3));
$Character->setActiveClassIcon($this->findRange('"ic_class_wh24_box"', 1, null, false));
// Set Gear (Also sets Active Class and Job)
$Gear = $this->findAll('item_detail_box', NULL, '//ITEM Detail', false);
$Character->setGear($Gear);
// The next few attributes are based on class
if (in_array($Character->getActiveClass(), $this->ClassDisicpline['dow']) || in_array($Character->getActiveClass(), $this->ClassDisicpline['dom']))
{
$Character->setSpell($this->findRange('param_title_spell', 6));
$Character->setPVP($this->findRange('param_title_pvpparam', 6));
}
else if (in_array($Character->getActiveClass(), $this->ClassDisicpline['doh']))
{
$Character->setCrafting($this->findRange('param_title_crafting', 6));
}
else if (in_array($Character->getActiveClass(), $this->ClassDisicpline['dol']))
{
$Character->setGathering($this->findRange('param_title_gathering', 6));
}
#$this->segment('area_header_w358_inner');
// Set Minions
$Minions = $this->findRange('area_header_w358_inner', NULL, '//Minion', false);
$Character->setMinions($Minions);
// Set Mounts
$Mounts = $this->findRange('area_header_w358_inner', NULL, '//Mount', false, 2);
$Character->setMounts($Mounts);
#$this->segment('class_fighter');
// Set ClassJob
$Character->setClassJob($this->findRange('class_fighter', NULL, '//Class Contents', false));
// Validate data
$Character->validate();
// Append character to array
$this->Characters[$ID] = $Character;
}
else
{
$this->Characters[$ID] = NULL;
}
}
}
// Parse just biography, based on ID.
public function parseBiography($ID)
{
// Get the source
$this->getSource($this->URL['character']['profile'] . $ID);
// Create a new character object
$Character = new Character();
// Get biography
$Character->setBiography($this->findRange('txt_selfintroduction', 5));
// Return biography
return $Character->getBiography();
}
// Get a list of parsed characters.
public function getCharacters() { return $this->Characters; }
// Get a character by id
public function getCharacterByID($ID) { return isset($this->Characters[$ID]) ? $this->Characters[$ID] : NULL; }
#-------------------------------------------#
# ACHIEVEMENTS #
#-------------------------------------------#
// Get a list of parsed characters
public function getAchievements() { return $this->Achievements; }
// Parse a achievements based on ID
public function parseAchievements()
{
$ID = $this->getID();
if (!$ID)
{
echo "error: No ID Set.";
}
else
{
// Loop through categories
foreach($this->AchievementCategories as $Category)
{
// Get the source
$x = $this->getSource($this->URL['character']['profile'] . $ID . $this->URL['character']['achievement'] .'category/'. $Category .'/');
// Create a new character object
$Achievements = new Achievements();
// Get Achievements
$Achievements->set($this->findAll('achievement_area_body', NULL, 'bt_more', false));
$Achievements->setPoints($this->findRange('total_point', 10));
$Achievements->setCategory($Category);
// Append character to array
$this->Achievements[$ID][$Category] = $Achievements;
}
}
}
// Parse achievement by category
public function parseAchievementsByCategory($cID, $ID = null)
{
if (!$ID)
{
$ID = $this->getID();
}
if (!$ID)
{
echo "error: No ID Set.";
}
else if (!$cID)
{
echo "No catagory id set.";
}
else
{
$Category = $this->AchievementCategories[$cID];
// Get the source
$this->getSource($this->URL['character']['profile'] . $ID . $this->URL['character']['achievement'] . $cID .'/');
// Create a new character object
$Achievements = new Achievements();
// Get Achievements
$Achievements->set($this->findAll('achievement_area_body', NULL, 'bt_more', false));
$Achievements->setPoints($this->findRange('total_point', 10));
$Achievements->setCategory($cID);
// Append character to array
$this->Achievements[$cID] = $Achievements;
}
}
public function getAchievementCategories()
{
return $this->AchievementCategories;
}
#-------------------------------------------#
# FREE COMPANY #
#-------------------------------------------#
// Parse free company profile
public function parseFreeCompany($ID, $Options = null)
{
if (!$ID)
{
echo "error: No ID Set.";
}
else
{
// Options
$this->defaults['automaticallyParseFreeCompanyMembers'] = (isset($Options['members'])) ? $Options['members'] : $this->defaults['automaticallyParseFreeCompanyMembers'];
// Get source
$this->getSource($this->URL['freecompany']['profile'] . $ID);
// Create a new character object
$FreeCompany = new Lodestone_FreeCompany();
// Set Character Data
$FreeCompany->setID(trim($ID), $this->URL['freecompany']['profile'] . $ID);
$FreeCompany->setNameServerCompany($this->findRange('ic_freecompany_box', 10));
$FreeCompany->setTagFormedMembersSlogan($this->findRange('table_black m0auto', 50, false, false));
// If to parse free company members
if ($this->defaults['automaticallyParseFreeCompanyMembers'])
{
// Temp array
$MembersList = [];
// Get number of pages
$TotalPages = ceil(round(intval($FreeCompany->getMemberCount()) / intval(trim($this->defaults['pagesPerFreeCompanyMemberList'])), 10));
// Get all members
for($Page = 1; $Page <= $TotalPages; $Page++)
{
// Parse Members page
$this->getSource($FreeCompany->getLodestone() . $this->URL['freecompany']['member'] . str_ireplace('%page%', $Page, $this->URL['freecompany']['memberpage']));
// Set Members
$MemberArray = $FreeCompany->parseMembers($this->findAll('player_name_area', 18, null, null));
// Merge existing member list with new member array
$MembersList = array_merge($MembersList, $MemberArray);
}
// End point for member list
$FreeCompany->setMembers($MembersList);
}
// Save free company
$this->FreeCompanies[$ID] = $FreeCompany;
}
}
// Get a list of parsed free companies.
public function getFreeCompanies() { return $this->FreeCompanies; }
// Get a free company by id
public function getFreeCompanyByID($ID) { return isset($this->FreeCompanies[$ID]) ? $this->FreeCompanies[$ID] : NULL; }
#-------------------------------------------#
# LINKSHELL #
#-------------------------------------------#
// Parse free company profile
public function parseLinkshell($ID, $Options = null)
{
if (!$ID)
{
echo "error: No ID Set.";
}
else
{
// Get source
$this->getSource($this->URL['linkshell']['profile'] . $ID);
// Create a new character object
$Linkshell = new Lodestone_Linkshell();
// Set Character Data
$Linkshell->setID(trim($ID), $this->URL['linkshell']['profile'] . $ID);
$Linkshell->setNameServer($this->findRange('player_name_brown', 10));
$Linkshell->setMemberCount($this->findRange('ic_silver', 5));
$Linkshell->setMembers($this->findAll('thumb_cont_black_50', 40, false, false));
// Save free company
$this->Linkshells[$ID] = $Linkshell;
}
}
// Get a list of parsed linkshells.
public function getLinkshells() { return $this->Linkshells; }
// Get a linkshell by id
public function getLinkshellByID($ID) { return isset($this->Linkshells[$ID]) ? $this->Linkshells[$ID] : NULL; }
#-------------------------------------------#
# FUNCTIONS #
#-------------------------------------------#
// This function will sort a multi dimentional array based on a key index, its global, do not use $var = sksort().
protected function sksort(&$array, $subkey, $sort_ascending)
{
if (count($array))
$temp_array[key($array)] = array_shift($array);
foreach($array as $key => $val){
$offset = 0;
$found = false;
foreach($temp_array as $tmp_key => $tmp_val)
{
if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey]))
{
$temp_array = array_merge( (array)array_slice($temp_array,0,$offset),
array($key => $val),
array_slice($temp_array,$offset)
);
$found = true;
}
$offset++;
}
if(!$found) $temp_array = array_merge($temp_array, array($key => $val));
}
if ($sort_ascending)
$array = array_reverse($temp_array);
else
$array = $temp_array;
}
}