-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWoWItem.parser.php
1620 lines (1578 loc) · 45.6 KB
/
WoWItem.parser.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
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* WoWItem - this extension handles World of Warcraft items
*
* To activate this extension, add the following into your LocalSettings.php file:
* <code>require_once("$IP/extensions/WoWItem/WoWItem.setup.php");</code>
*
* @package MediaWiki
* @subpackage ParserHook
* @author James Twyford <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @version v0.10
* @link http://www.wowwiki.com WoWWiki
*/
/**
* Protect against register_globals vulnerabilities.
* This line must be present before any global variable is referenced.
*/
if (!defined('MEDIAWIKI')) {
echo("This is a MediaWiki extension, not a standalone PHP script.\n");
die(-1);
}
/**
* WoWItem parser class
*
* @package MediaWiki
* @author James Twyford <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later
* @link http://www.wowwiki.com WoWWiki
*/
class WoWItemParser
{
/**
* parse $input and $args and return an array defining the item
*
* @param string $input content between the <item>foo</item> tags
* @param array $args parameters to the <item foo=bar> opening tag
* @param Parser $parser the MWparser used to parse this page
*
* @return array a parsed string ready to display
*/
public function parse($input, $args, $parser)
{
//first, parse the $input
$attr = $this->_parseInput($input);
if (!is_array($attr)) {
return $attr; //error message
}
/*
* I'm passing the array into the parseArgs method so $args will
* override $input. $input is expected to be pretty much a
* copy-and-paste of a tooltip from the armory or an itemdb. $args is
* keyed parameters in the form of name="Corrupted Ashbringer", so
* it's rather explicit what's going on.
*/
$err = $this->_parseArgs($attr, $args);
if (is_string($err)) {
return $err;
}
//sanity check -- $attr can get modified, so watch out
$err = $this->_sanityCheck($attr);
if (is_string($err)) {
return $err;
}
//ok, its fully-defined and ready to go
return $attr;
}
/**
* parse input between <item>foo bar</item> tags
* input is expected to be a tooltip copy/pasted from elsewhere
*
* @param string $input the input between the item tags
*
* @return array formatted input in an array ready for reuse
*/
private function _parseInput($input)
{
$attr = array();
// $input is a string. I want an array.
$temp = explode("\n", htmlspecialchars($input));
// empty case, hopefully we've got params
if (count($temp) == 1) {
return $attr;
}
// I'm also inverting the order because...
$in = array_reverse($temp);
unset ($temp);
// faster to pop off the stack than it is to shift off the queue
$attr['name'] = array_pop($in); // name must be the first line, but...
if ($attr['name'] == '') { // may not be on the same line as the tag
$attr['name'] = array_pop($in);
}
// time to loop
$val = array_pop($in);
while ($val !== null) {
// start searching the string for a keyword
if (strpos($val, 'Heroic') !== false) {
$attr['heroic'] = true;
} elseif (strpos($val, 'Conjured') !== false) {
$attr['conjured'] = true;
} elseif (strpos($val, 'Binds') !== false) {
$bind = explode(' ', $val);
$attr['bind'] = $this->_binds($bind[2]);
if (!$attr['bind']) {
$attr = $this->_error(
'bind', 'one of the four bind types',
$attr['bind'], 'Bind'
);
}
unset ($bind);
} elseif (strpos($val, 'Quest Item') !== false) {
$attr['questitem'] = true;
} elseif (strpos($val, 'Unique') !== false) {
$uniq = explode(' ', $val);
if ($uniq[0] == 'Unique') {
if (count($uniq) == 1) {
$attr['unique'] = true;
} else {
$attr['uniqueN'] = substr($uniq[1], 1, -1);
}
} elseif ($uniq[0] == 'Unique-Equipped') {
if (count($uniq) == 1) {
$attr['uniqueEq'] = true;
} else {
$attr['uniqueEqN'] = substr($uniq[1], 1, -1);
}
}
unset ($uniq);
} elseif (strpos($val, 'Glyph') !== false) {
$glyph = substr($val, 0, 5);
if ($glyph == 'Major') {
$attr['glyph'] = '[[Major glyph|Major Glyph]]';
} elseif ($glyph == 'Minor') {
$attr['glyph'] = '[[Minor glyph|Minor Glyph]]';
} else {
return $this->_parseError(
'Glyphs are either "Major Glyph" or "Minor Glyph"',
'Major Glyph'
);
}
} elseif (strpos($val, 'Duration') !== false) { //FT
$attr['duration'] = trim(substr($val, 10));
} elseif (strpos($val, 'Begins a Quest') !== false) {
if (strlen(trim($val)) < 26) {
return $this->_parseError(
'Please add the started quest to the "This Item ' .
'Begins a Quest" line',
'This Item Begins a Quest Your Place in the World'
);
}
$attr['qbegin'] = trim(substr($val, 25));
} elseif (strpos($val, 'Speed') !== false) {
$attr['speed'] = trim(substr($val, 5));
} elseif (strpos($val, 'Damage') !== false) {
$dmg = explode(' ', $val);
$mid = strpos($dmg[0], '-');
$bonus = ($dmg[0][0] == '+'); // low-end starts with a +
if ($mid === false) { // "11 - 44 [Frost] Damage"
if ($bonus) {
$attr['bdmg'][0] = substr($dmg[0], 1);
$attr['bdmg'][1] = $dmg[2];
} else {
$attr['dmg'][0] = $dmg[0];
$attr['dmg'][1] = $dmg[2];
}
$school = $this->_school($dmg[3]); // 'Frost' or 'Damage'
if ($school !== false) {
$attr[
(($dmg[0][0] == '+') ? 'bonus' : '') .
'damageschool'
] = $school;
}
} else { // "11-44 [Frost] Damage"
if ($bonus) {
$attr['bdmg'][0] = substr($dmg[0], 1, $mid-1);
$attr['bdmg'][1] = substr($dmg[0], $mid+1);
} else {
$attr['dmg'][0] = substr($dmg[0], 0, $mid);
$attr['dmg'][1] = substr($dmg[0], $mid+1);
}
$school = $this->_school($dmg[1]); // 'Frost' or 'Damage'
if ($school !== false) {
$attr[
(($dmg[0][0] == '+') ? 'bonus' : '') .
'damageschool'
] = $school;
}
}
unset ($dmg) ;
} elseif (strpos($val, 'damage per second') !== false) {
$dps = explode(' ', $val);
if (is_numeric(substr($dps[0], 1))) {
$attr['dps'] = substr($dps[0], 1);
}
unset ($dps);
} elseif (strpos($val, 'feral attack power') !== false) {
// don't care. we will calculate it later
} elseif (strpos($val, 'Socket') !== false) {
// before the various stat checks so we catch sockbonuses
if (substr($val, 0, 6) == 'Socket') {
$attr['sockbonus'] = substr($val, 14);
} else {
$temp = $this->_socket($val[0]);
if ($temp !== false) {
$attr['socket'][] = $temp;
}
}
} elseif (strpos($val, 'Armor') !== false) {
$temp = trim(substr($val, 0, -6));
if (is_numeric($temp)) {
$attr['armor'] = $temp;
}
} elseif (strpos($val, 'Block') !== false) {
$temp = trim(substr($val, 0, -5));
if (is_numeric($temp)) {
$attr['block'] = $temp;
}
} elseif (strpos($val, 'Strength') !== false) {
$temp = trim(substr($val, 1, -9));
if (is_numeric($temp)) {
$attr['strength'] = $temp;
}
} elseif (strpos($val, 'Agility') !== false) {
$temp = trim(substr($val, 1, -8));
if (is_numeric($temp)) {
$attr['agility'] = $temp;
}
} elseif (strpos($val, 'Stamina') !== false) {
$temp = trim(substr($val, 1, -8));
if (is_numeric($temp)) {
$attr['stamina'] = $temp;
}
} elseif (strpos($val, 'Intellect') !== false) {
$temp = trim(substr($val, 1, -10));
if (is_numeric($temp)) {
$attr['intellect'] = $temp;
}
} elseif (strpos($val, 'Spirit') !== false) {
$temp = trim(substr($val, 1, -7));
if (is_numeric($temp)) {
$attr['spirit'] = $temp;
}
} elseif (strpos($val, 'Resistance') !== false) {
$res = explode(' ', $val);
$school = $this->_school($res[1]);
if ($school !== false) {
$attr['resist'][$school] = substr($res[0], 1);
}
} elseif (strpos($val, 'Durability') !== false) {
$dura = explode(' ', $val);
if (is_numeric($dura[1])) { //'dura 300 / 300'
$attr['durability'] = $dura[1];
} else {
$dur = substr(strstr($dura[1], '/'), 1);
if (is_numeric($dur)) { //'dura 300/300'
$attr['durability'] = $dur;
}
}
unset ($dura);
} elseif (strpos($val, 'defense rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['defense'] = $match[0];
} elseif (strpos($val, 'dodge rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['dodge'] = $match[0];
} elseif (strpos($val, 'parry rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['parry'] = $match[0];
} elseif (strpos($val, 'shield block rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['blockrating'] = $match[0];
} elseif (strpos($val, 'haste rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['haste'] = $match[0];
} elseif (strpos($val, 'hit rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['hit'] = $match[0];
} elseif (strpos($val, 'critical strike rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['crit'] = $match[0];
} elseif (strpos($val, 'resilience rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['resilience'] = $match[0];
} elseif (strpos($val, 'expertise rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['expertise'] = $match[0];
} elseif (strpos($val, 'attack power by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['ap'] = $match[0];
} elseif (strpos($val, 'mana per 5 sec.') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['mp5'] = $match[0];
} elseif (strpos($val, 'armor penetration rating by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['arp'] = $match[0];
} elseif (strpos($val, 'spell power by') !== false) {
preg_match('/(\d+)/', $val, $match);
$attr['spellpower'] = $match[0];
} elseif (strpos($val, 'Locked') !== false) {
$attr['locked'] = true;
} elseif (strpos($val, 'Lockpicking') !== false) {
$temp = substr(strstr($val, '('), 1, -1);
if (is_numeric($temp)) {
$attr['lockpick'] = $temp;
}
} elseif (strpos($val, 'Bag') !== false) {
$bag = explode(' ', $val);
if (is_numeric($bag[0])) {
$attr['bagslots'] = $bag[0];
$type = $this->_bagType($bag[2]);
if ($type !== false) {
$attr['bagtype'] = $type;
}
}
unset ($bag);
} elseif (strpos($val, 'Classes') !== false) {
$classes = explode(' ', $val);
unset ($classes[0]);
foreach ($classes as $c) {
$class = $this->_classes($c);
if ($class === false) {
return $this->_error(
'class', 'one of the playable classes', $val
);
} else {
$attr['class'][$class] = true;
}
}
} elseif (strpos($val, 'Races') !== false) {
$races = explode(' ', $val);
unset ($races[0]);
foreach ($races as $r) {
if ($r == 'Elf,') {
continue;
}
$race = $this->_races($r);
if ($race === false) {
return $this->_error('race', 'a playable race', $r);
} else {
$attr['race'][$race] = true;
}
}
} elseif (strpos($val, 'Requires Level') !== false) {
$temp = trim(substr($val, 15));
if (is_numeric($temp)) {
$attr['level'] = $temp;
}
} elseif (strpos($val, 'Item Level') !== false) {
$temp = trim(substr($val, 11));
if (is_numeric($temp)) {
$attr['ilvl'] = $temp;
}
} elseif (strpos($val, 'Charges') !== false) {
$chg = explode(' ', $val);
if (is_numeric($chg[0])) {
$attr['charges'] = $chg[0];
}
unset ($chg);
} elseif (strpos($val, 'Right Click to Read') !== false) {
$attr['read'] = true;
} elseif (strpos($val, 'Right Click to Open') !== false) {
$attr['open'] = true;
} elseif (strpos($val, 'Sell Price') !== false) {
$sell = explode(' ', $val);
foreach ($sell as $v) {
if (in_array(substr($v, -1), array('g','s','c'))) {
$k = substr($v, -1);
$$k = substr($v, 0, -1);
}
}
$attr['sell'] = '{{cost|' .
(isset ($g) ? "$g" : '') .
(isset ($s) ? "|$s" : '|') .
(isset ($c) ? "|$c" : '') . '}}';
unset ($sell);
} elseif (strpos($val, 'arena') !== false) {
$temp = trim(substr($val, 43));
if (is_numeric($temp)) {
$attr['arena'] = $temp;
}
} elseif ((strpos($val, '/') !== false) //x/y
|| (stripos($val, 'pieces') !== false) //x pieces
) { //set
$paren = strpos($val, '(');
$attr['set'] = trim(substr($val, 0, $paren-1));
$attr['setpieces'] = substr($val, $paren+1, 1); // (x pieces)
if (!is_numeric($attr['setpieces'])) {
return $this->_parseError(
'Please define the size of the equipment set on the ' .
'same line', 'Netherwind Regalia (0/8)'
);
} elseif (
($attr['setpieces'] == 0) || ($attr['setpieces'] == 1)
) { //(x/y). x isn't really all that useful
$pos = strpos($val, '/');
$attr['setpieces'] = substr($val, $pos+1, 1);
}
for ($i = 0; $i < $attr['setpieces']; $i++) {
array_pop($in) ."\n"; //pop set items. not our problem
}
$val = array_pop($in);
while ($val[0] == '(') {
$val = array_pop($in); //pop set bonuses. not our problem
}
array_push($in, $val); //first non set-bonus back on the stack
} elseif (substr($val, 0, 1) == '[') { //it's a recipe!
$end = strpos($val, ']');
$attr['create'] = substr($val, 1, $end-1);
$recipe = explode(' ', $val);
$qual = array_pop($recipe);
unset ($recipe);
if ($this->_quality($qual) !== false) {
$attr['createq'] = $this->_quality($qual);
} else {
return $this->_parseError(
'Please add the created item\'s quality to the end ' .
'of the line where it is listed.',
'[Heavy Runecloth Bandage] common'
);
}
} elseif (substr($val, 0, 6) == '"') { //favor!
$attr['flavor'] = substr($val, 6, -6);
} elseif (substr($val, 0, 14) == 'Chance on hit:') {
$attr['onhit'][] = trim(substr($val, 15));
} elseif (substr($val, 0, 6) == 'Equip:') {
$attr['equip'][] = trim(substr($val, 7));
} elseif (substr($val, 0, 4) == 'Use:') {
$attr['use'][] = trim(substr($val, 5));
} elseif (strpos($val, 'Requires') !== false) {
//ok... now it gets expensive. yuck.
//holiday, subskill, skill, faction, reagents
$requires = explode(' ', $val);
unset ($requires[0]);
if ($this->_holiday($requires[1]) !== false) {
$attr['holiday'] = $this->_holiday($requires[1]);
} elseif ($this->_subskill($requires[1]) !== false) {
$attr['subskill'] = $this->_subskill($requires[1]);
} elseif ($this->_profession($requires[1]) !== false) {
$attr['skill'] = $this->_profession($requires[1]);
preg_match('/(\d+)/', array_pop($requires), $match);
if (count($match) == 2) { //preg_match adds it twice?
$attr['skillrating'] = $match[0];
} else {
return $this->_parseError(
'Please add the numeric reputation requirement ' .
'to the end of the line where it is listed.',
'Requires ' . $attr['skill'] .' (400)'
);
}
} else {
$rep = array_pop($requires);
if ($this->_repRating($rep) !== false) {
array_pop($requires); //getting rid of the '-'
$attr['faction'] = implode($requires, ' ');
$attr['factionrating'] = $this->_repRating($rep);
} else { //reagents
array_push($requires, $rep);
$attr['reagents'] = implode($requires, ' ');
}
}
} elseif ($this->_types($val) !== false) {
$attr['type'] = $this->_types($val);
} elseif ($this->_slots($val) !== false) {
$attr['slot'] = $this->_slots($val);
} else { //out of ideas at this point.
$attr['undef'][] = $val;
}
$val = array_pop($in);
}
unset ($in);
return $attr;
}
/**
* parse arguments to the <item foo=bar/> tag
*
* @param array &$attr the array we're parsing the input in to
* @param array $args the input passed in the item tag
*
* @return string any error output
*/
private function _parseArgs(&$attr, $args)
{
//kd3 is lazy. $a is quicker to type than array_key_exists.
$h = 'htmlspecialchars'; //always, always, ALWAYS escape user input
// parse!
foreach ($args as $k => $v) {
switch (strtolower($h($k))) {
// one-letter keys used: abcd_ ghi _l_n_ qrstu_ _ z
case 'a': case 'armor':
$attr['armor'] = $h($v);
if (!is_numeric($attr['armor'])) {
return $this->_error('armor', 'numeric', $attr['armor']);
}
break;
case 'b': case 'bind': case 'binds':
$attr['bind'] = $this->_binds($h($v));
if (!$attr['bind']) {
return $this->_error(
'bind', 'one of the four bind types', $attr['bind']
);
}
break;
case 'c': case 'cl': case 'class': case 'classes':
$classes = explode(' ', $h($v));
foreach ($classes as $c) {
$class = $this->_classes($c);
if ($class === false) {
return $this->_error(
'class', 'one of the playable classes', $h($v)
);
} else {
$attr['class'][] = $class;
}
}
break;
case 'd': case 'dur': case 'dura': case 'durability':
$attr['durability'] = $h($v);
if (!is_numeric($attr['durability'])) {
return $this->_error(
'durability', 'numeric', $attr['durability']
);
}
break;
case 'g': case 'glyph':
if (stripos($h($v), 'mi') !== false) {
$attr['glyph'] = '[[Minor glyph|Minor Glyph]]';
} else {
$attr['glyph'] = '[[Major glyph|Major Glyph]]';
}
break;
case 'h': case 'heroic': //bool
$attr['heroic'] = true;
break;
case 'i': case 'icon': //mandatory
$attr['icon'] = ucfirst(strtolower($h($v)));
break;
case 'l': case 'level':
$attr['level'] = $h($v);
if (!is_numeric($attr['level'])) {
return $this->_error('level', 'numeric', $attr['level']);
}
break;
case 'n': case 'name': //FT mandatory
$attr['name'] = ucfirst($h($v));
break;
case 'q': case 'qual': case 'quality':
$attr['quality'] = $this->_quality($h($v));
if (!$attr['quality']) {
return $this->_error(
'quality', 'a valid item quality', $attr['quality']
);
}
break;
case 'r': case 'race': case 'races':
$races = explode(' ', $h($v));
foreach ($races as $r) {
$race = $this->_races($r);
if ($race === false) {
return $this->_error(
'race', 'one of the playable races', $h($v)
);
} else {
$attr['race'][$race] = true;
}
}
break;
case 's': case 'slot':
$attr['slot'] = $this->_slots($h($v));
if (!$attr['slot']) {
return $this->_error(
'slot', 'a valid equipment slot', $attr['slot']
);
}
break;
case 't': case 'type':
$attr['type'] = $this->_types($h($v));
if (!$attr['type']) {
return $this->_error(
'type', 'a valid armor/weapon type', $attr['type']
);
}
break;
case 'u': case 'un': case 'unique': //unique-eq check is later
$uniq = $h($v);
if (is_numeric($uniq)) {
$attr['uniqueN'] = $uniq; //"Unique (100)"
} else {
$attr['unique'] = true; //boolean -- "Unique (1)"
}
break;
case 'z': case 'ins': case 'zone':
case 'instance': case 'instancebind':
case 'loc': case 'location': case 'locationbind'://FT
$attr['locationbind'] = $h($v);
break;
//weapon stats
case 'damage': case 'dmg':
$dmg = explode(' ', $h($v));
$mid = strpos($dmg[0], '-');
if ($mid === false) { // '44 - 115 [Frost]'
$attr['dmg'][0] = $dmg[0];
$attr['dmg'][1] = $dmg[2];
} else { // '44 - 115 [Frost]'
$attr['dmg'][0] = substr($dmg[0], 0, $mid);
$attr['dmg'][1] = substr($dmg[0], $mid+1);
}
break;
case 'lowdamage': case 'damagelow': //explicitly-defined
$attr['dmg'][0] = $h($v);
break;
case 'hidamage': case 'damagehigh': case 'highdamage':
$attr['dmg'][1] = $h($v);
break;
case 'damageschool': case 'school':
$attr['damageschool'] = $this->_school($h($v));
if (!$attr['damageschool']) {
return $this->_error(
'damageschool', 'one of the WoW magic schools',
$attr['damageschool']
);
}
break;
case 'speed':
$attr['speed'] = $h($v);
break;
case 'bonus': case 'bdam':
$dmg = explode(' ', $h($v));
$mid = strpos($dmg[0], '-');
if ($mid !== 'false') { // '44-115'
$attr['bdmg'][0] = substr($dmg[0], 0, $mid);
$attr['bdmg'][1] = substr($dmg[0], $mid+1);
} else {
// '44 - 115'
$attr['bdmg'][0] = $dmg[0];
$attr['bdmg'][1] = $dmg[2];
}
break;
case 'bonuslowdamage': case 'bonusdamagelow':
$attr['bdmg'][0] = $h($v);
break;
case 'bonushidamage': case 'bonusdamagehigh':
case 'bonushighdamage':
$attr['bdmg'][1] = $h($v);
break;
case 'bonusdamageschool': case 'bonusschool':
$attr['bonusdamageschool'] = $this->_school($h($v));
if (!$attr['bonusdamageschool']) {
return $this->_error(
'bonusdamageschool', 'one of the WoW magic schools',
$attr['bonusdamageschool']
);
}
break;
case 'dps':
$attr['dps'] = $h($v);
break;
// core stats
case 'bl': case 'block':
$attr['block'] = $h($v);
break;
case 'str': case 'strength':
$attr['strength'] = $h($v);
break;
case 'agi': case 'agility':
$attr['agility'] = $h($v);
break;
case 'sta': case 'stam': case 'stamina':
$attr['stamina'] = $h($v);
break;
case 'int': case 'intellect':
$attr['intellect'] = $h($v);
break;
case 'spi': case 'spr': case 'spirit':
$attr['spirit'] = $h($v);
break;
//resists
case 'fire':
$attr['resist'][$this->_school('fire')] = $h($v);
break;
case 'frost':
$attr['resist'][$this->_school('frost')] = $h($v);
break;
case 'nature':
$attr['resist'][$this->_school('nature')] = $h($v);
break;
case 'shadow':
$attr['resist'][$this->_school('shadow')] = $h($v);
break;
case 'arcane':
$attr['resist'][$this->_school('arcane')] = $h($v);
break;
//bonuses
case 'defense': case 'def':
$attr['defense'] = $h($v);
break;
case 'dodge':
$attr['dodge'] = $h($v);
break;
case 'parry':
$attr['parry'] = $h($v);
break;
case 'resilience': case 'res': case 'resil':
$attr['resilience'] = $h($v);
break;
case 'blockrating': case 'blockvalue':
$attr['blockrating'] = $h($v);
break;
case 'hit':
$attr['hit'] = $h($v);
break;
case 'crit':
$attr['crit'] = $h($v);
break;
case 'haste':
$attr['haste'] = $h($v);
break;
case 'expertise': case 'exp':
$attr['expertise'] = $h($v);
break;
case 'attack': case 'ap': case 'attackpower':
$attr['ap'] = $h($v);
break;
case 'armorpen': case 'arp':
$attr['arp'] = $h($v);
break;
case 'mp5': case 'manaregen':
$attr['mp5'] = $h($v);
break;
case 'sp': case 'spellpower': case 'spell':
$attr['spellpower'] = $h($v);
break;
// others
case 'arena':
$attr['arena'] = $h($v);
break;
case 'bag': case 'bagslots':
$attr['bagslots'] = $h($v);
break;
case 'bagtype':
$attr['bagtype'] = $this->_bagType($h($v));
if (!$attr['bagtype']) {
return $this->_error(
'bagtype', 'a valid bag type', $attr['bagtype']
);
}
break;
case 'charge': case 'charges':
$attr['charges'] = $h($v);
break;
case 'con': case 'conj': case 'conjured': //bool
$attr['conjured'] = true;
break;
case 'create': //FT
$attr['create'] = $h($v);
break;
case 'createq':
$attr['createq'] = $this->_quality($h($v));
if (!$attr['createq']) {
return $this->_error(
'createq', 'a valid item quality', $attr['createq']
);
}
break;
case 'disambig': case 'disambigpage': case 'itempage': //FT
$attr['itempage'] = $h($v);
break;
case 'duration': //FT
$attr['duration'] = $h($v);
break;
case 'equip': //FT
$attr['equip'] = explode('/', $h($v));
break;
case 'faction': case 'rep': case 'reputation': //FT
$attr['faction'] = ucwords(strtolower($h($v)));
break;
case 'factionrating': case 'reprating':
$attr['factionrating'] = $this->_repRating($h($v));
if (!$attr['factionrating']) {
return $this->_error(
'factionrating', 'a valid reputation level',
$attr['factionrating']
);
}
break;
case 'flavor': //FT
$attr['flavor'] = $h($v);
break;
case 'heroic': //bool
$attr['heroic'] = true;
break;
case 'hol': case 'holiday': //FT
$attr['holiday'] = ucwords(strtolower($h($v)));
break;
case 'id': //mandatory
$attr['id'] = $h($v);
break;
case 'ilvl': //mandatory
$attr['ilvl'] = $h($v);
break;
case 'locked': case 'lock': case 'lockpick': case 'lockpicking':
$locked = $h($v);
if (is_numeric($locked)) {
$attr['lockpick'] = $h ($v);
} else {
$attr['locked'] = true;
}
break;
case 'onhit': //chance on hit FT
$attr['onhit'] = explode('/', $h($v));
break;
case 'open': // bool
$attr['open'] = true;
break;
case 'qb': case 'qbegin': case 'questbegin': case 'beginquest':
$attr['qbegin'] = $h ($v);
break;
case 'qi': case 'questitem': //bool
$attr['questitem'] = true;
break;
case 'read': // bool
$attr['read'] = true;
break;
case 'sell': // sell to vendor FT
$attr['sell'] = $h($v);
break;
case 'reagents': //FT
$attr['reagents'] = $h($v);
break;
case 'set': //FT
$attr['set'] = $h($v);
break;
case 'setpieces': case 'setpc':
$attr['setpieces'] = $h($v);
break;
case 'sock': case 'socket': case 'sockets':
$sockets = explode(' ', $h($v));
foreach ($sockets as $sock) {
$attr['socket'][] = $this->_socket($sock);
}
break;
case 'sockbonus': case 'socketbonus': //FT
$attr['sockbonus'] = $h($v);
break;
case 'skill': case 'prof': case 'profession':
$attr['skill'] = $this->_profession($h($v));
if (!$attr['skill']) {
return $this->_error(
'skill', 'a playable profession', $attr['skill']
);
}
break;
case 'skillrating': case 'profrating': case 'professionrating':
$attr['skillrating'] = $h($v);
if (!is_numeric($attr['skillrating'])) {
return $this->_error(
'skillrating', 'numeric', $attr['skillrating']
);
}
break;
case 'sub': case 'spec': case 'specialty': case 'subskill':
case 'specialization':
$attr['subskill'] = $this->_subskill($h($v));
if (!$attr['subskill']) {
return $this->_error(
'subskill', 'a valid profession specialization',
$attr['subskill']
);
}
break;
case 'unique-equipped': case 'ueq': case 'unique-eq':
$ueq = $h ($v);
if ($ueq === $h ($k)) { //yes, strictly equal...
$attr['uniqueEq'] = true; //Unique-Equipped
} else {
$attr['uniqueEqN'] = $ueq; //Unique-Equipped (something)
}
break;
case 'use':
$attr['use'] = explode('/', $h ($v));
break;
default:
$attr['undef'][] = $h($k).": ".$h($v);
}
}
//done with input parsing, yay! return true, we've modified the array
return true;
}
/**
* do some sanity checking before giving the all-clear
*
* @param array &$attr the hopefully-sane item array
*
* @return string any error output
*/
private function _sanityCheck(&$attr)
{
//kd3 is lazy. $a is quicker to type than array_key_exists.
$n = 'is_numeric';
/*
* need some attributes before we go any further, can't make them up:
* name, id, ilvl
*/
if (!isset ($attr['name'], $attr['id'], $attr['ilvl'])
|| !$n($attr['id']) || !$n($attr['ilvl'])
) {
return 'Tooltip error: <span class="error">All items must have ' .
'name, ID and iLvl defined!</span>';
}
/*
* If we're being lazy not defining a disambig page (should be most of
* the time) define it here so we only have to check itempage and not
* "maybe check itempage or name" in the renderers.
*/
if (!isset ($attr['itempage'])) {
$attr['itempage'] = $attr['name'];
}
//display an icon, even if the user doesn't define one. Bad user. Bad.
if (!isset ($attr['icon'])) {
$attr['icon'] = "Temp";
}
//quality poor if not defined. Bad user. Bad.
if (!isset ($attr['quality'])) {
$attr['quality'] = $this->_quality(0);
}
//weapon sanity check
$weapon = (isset ($attr['dmg'], $attr['speed'], $attr['dps'])
&& count($attr['dmg']) == 2 && $n($attr['dmg'][0])
&& $n($attr['dmg'][1]) && $n($attr['dps'])
&& $n($attr['speed']));
if ((isset ($attr['dmg']) && !$weapon)
|| (isset ($attr['speed']) && !$weapon)
|| (isset ($attr['dps']) && !$weapon)
) {
return 'Tooltip error: <span class="error">Weapons must have ' .
'low-end damage, high-end damage and attack speed defined!</span>';
}
if ($weapon) {
$attr['weapon'] = true;
//here. not the parsers. didn't know if 'type' was set then.
$feral = in_array(
$attr['type'], array('[[Staff]]', '[[Mace]]', '[[Polearm]]')
);
if ($feral && ($attr['dps'] > 54.8) ) {
$attr['feraldps'] = (($attr['dps'] - 54.8) * 14);
}
$bonusdamage = (isset ($attr['bdmg']) && (count($attr['bdmg']) == 2)
&& $n($attr['bdmg'][0]) && $n($attr['bdmg'][1]));
if (!$weapon && !$bonusdamage && isset ($attr['bdmg'])) {
return 'Tooltip error: <span class="error">Bonus low-end ' .
'damage and bonus high-end damage must be defined ' .
'together!</span>';
}
if ($bonusdamage) {
$attr['bonusdamage'] = true;
}
}
//recipe sanity check
$recipe = isset ($attr['create'], $attr['createq'], $attr['reagents']);
if ((isset ($attr['create']) && !$recipe)
|| (isset ($attr['createq']) && !$recipe)
|| (isset ($attr['reagents']) && !$recipe)
) {
return 'Tooltip error: <span class="error">Recipes must have ' .
'"create", "createq" and "reagents" defined!</span>';
}
if ($recipe) {
$attr['recipe'] = true;
}
//socket sanity check
$socketed = isset ($attr['socket'], $attr['sockbonus']);
if ((isset ($attr['socket']) && !$socketed)
|| (isset ($attr['sockbonus']) && !$socketed)
) {
return 'Tooltip error: <span class="error">Socketed items must ' .
'have a socket bonus!</span>';
}
if ($socketed) {
$attr['socketed'] = true;