forked from Wikia/app
/
gwbbcode.inc.php
1543 lines (1336 loc) · 49.4 KB
/
gwbbcode.inc.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
/***************************************************************************
* gwbbcode.inc.php
* -------------------
* begin : Tuesday, Apr 21, 2005
* copyright : (C) 2006-2007 Pierre 'pikiou' Scelles
* email : liu.pi.vipi@gmail.com
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* All images, skill names and descriptions are (C) ArenaNet.
***************************************************************************/
require_once (GWBBCODE_ROOT . '/config.php');
// Load the gwbbcode template
global $gwbbcode_tpl;
global $art_titel;
if (!isset($gwbbcode_tpl))
$gwbbcode_tpl = load_gwbbcode_template();
//Transforms gwBBCode text to HTML
//Better suited function name than gwbbcodize :/
function parse_gwbbcode($t, $n)
{
global $art_titel;
$art_titel = $n;
return gwbbcodize($t);
}
//Converts a gwBBCode text to HTML
function gwbbcodize($t)
{
$start = microtime_float();
// Replace all '['s inside [pre]..[/pre] by '['
if (!defined('SMF'))
{//SMF uses the [pre] tag already
$t = preg_replace_callback('#\[pre\](.*?)\[\/pre\]#isS', 'pre_replace', $t);
}
$t = preg_replace_callback('#\[nobb\](.*?)\[\/nobb\]#isS', 'pre_replace', $t);
// [rand seed=465468 players=2]
$t = preg_replace_callback('#\[rand([^\]]*)\]#isS', 'rand_replace', $t);
// Manage [build=...]
$t = preg_replace_callback('#\[build=([^\]]*)\]\]?(\[/build\])?\r?\n?#isS',
'build_id_replace', $t);
// Manage [build_name;template_code]
$t = preg_replace_callback('#\[(([^]\r\n]+);([^];\r\n]+))\]\r?\n?#isS',
'build_id_replace', $t);
// Replace all [skill_name] by [skill]skill_name[/skill] if skill_name is a valid skill name
$t = preg_replace_callback('#\[(.*?)\]#isS', 'skill_name_replace', $t);
// Manage [build]...[/build]
$t = preg_replace_callback('#\[build ([^\]]*)\](.*?)\[/build\]\r?\n?#isS',
'build_replace', $t);
// Manage [skill]...[/skill]
$t = preg_replace_callback('#\[skill([^\]]*)\](.*?)\[/skill\][ ]?#isS',
'skill_replace', $t);
// [pickup="arheu"]
$t = preg_replace_callback('#\[pickup([^\]]*)\]#isS', 'pickup_replace', $t);
//[gwbbcode runtime]
if (preg_match('@\[gwbbcode runtime\]@i', $t) !== false)
$t = preg_replace('@\[gwbbcode runtime\]@i', round(microtime_float() - $start, 3),
$t);//Precise enough
//Trick to use in MyBB against <p> elements screwing up first skill div, and some ending <br /> being removed
if (defined('IN_MYBB'))
{
$t = '</p>' . $t;
$t = str_replace("</div>\n", "</div><br>", $t);
}
return $t;
}
//Changes any '[' by '[', hence disabling bbcode
function pre_replace($reg)
{
list($all, $content) = $reg;
return str_replace('[', '[', $content);
}
//Processes the [pickup...] element
function pickup_replace($reg)
{
global $gwbbcode_tpl;
global $userdata;
list($all, $att) = $reg;
$att = html_safe_decode($att);
//Get all pickup users
$pickup = @load(PICKUP_PATH);
if ($pickup === false)
return $all;
if (preg_match('|^=\\"(.+)\\"|', $att, $reg) && $pickup !== false)
{
$id = preg_replace('|[\'"!]|', '', $reg[1]);
$username = $userdata['username'];
//Add or Remove links? (default=Add)
$action = 'add';
if (isset($pickup[$id]) && in_array($username, $pickup[$id]))
$action = 'remove';
$userlist = pickup_users($pickup, $username, $id, '');
$gwbbcode_root_path = GWBBCODE_ROOT;
return preg_replace("#\{(.*?)\}#ise", "isset($\\1)?$\\1:'\\0'", $gwbbcode_tpl['pickup']);
}
else
return "<script>alert('No id found for [pickup]; Please give one as in [pickup=\"75578\"]')</script>";
}
// Process [rand seed=465468 players=2]
function rand_replace($reg)
{
list($all, $att) = $reg;
$att = html_safe_decode($att);
//Get the seed
if (preg_match('|seed=([0-9]+)|', $att, $reg))
{
$seed = intval($reg[1]);
}
else
{
$seed = rand(1000, 100000);
}
srand($seed);
//Get the number of players
if (preg_match('|players=([0-9]+)|', $att, $reg))
{
$players = intval($reg[1]);
}
else
{
$players = 1;
}
//Generate random skills
$skills = array();
$elite = 0;
$max_elite = ($players + 1) * 3;
$normal = 0;
$max_normal = ($players + 1) * 14;
$total = 0;
$max_total = $max_elite + $max_normal;
while ($total < $max_total)
{
$id = rand(0, 2000);
if ($skill = gws_details($id))
{
//Skill exists!
if ($skill['elite'] == 1 && $elite < $max_elite)
{
$elite++;
$total++;
$skills[] = $skill;
}
else
if ($skill['elite'] == 0 && $normal < $max_normal)
{
$normal++;
$total++;
$skills[] = $skill;
}
}
}
//Sort and output the list of skills
uasort($skills, "skill_sort_cmp");
$skill_list = '';
foreach ($skills as $skill)
{
$skill_list .= '[' . $skill['name'] . ']';
}
return "Random skill set (seed=$seed):\n$skill_list";
}
//Returns a list of pickup users, highlighting one specified username.
function pickup_users($pickup, $username, $id, $nobody_msg)
{
//Output our pickup's users
if (empty($id) || !isset($pickup[$id]))
$userlist = '';
else
{
//Prepare list of users
$list = $pickup[$id];
sort($list);
foreach ($list as $key => $name)
if ($name === $username)
$list[$key] = "<span style=\"color: #40B030\">$name</span>";
$userlist = implode(', ', $list);
if (!empty($userlist))
$userlist .= '. ';
}
return empty($userlist) ? $nobody_msg:$userlist;
}
//Convert [Potential Skill Name] tags to [skill]Potential Skill Name[/skill]
function skill_name_replace($reg)
{
global $gwbbcode_tpl;
list($all, $name) = $reg;
$name = html_safe_decode($name);
$all = preg_replace('@ressurection@i',
'<span style="text-decoration: blink; color: black" onMouseOver="stm([\'\', \'<table width=\\\'400\\\' style=\\\'color: white\\\' id=\\\'translucent\\\'><tr><td>Re<b><u>s</u></b>u<b><u>rr</u></b>ection, one \\\'s\\\', two \\\'r\\\'s for Christ sake!</td></tr></table>\'],Style[0])" onMouseOut="htm()">Ressurection</span>',
$all);
$all = preg_replace('@\[gwbbcode version\]@i', GWBBCODE_VERSION, $all);
//'[[Skill Name]' => no icon
if ($name{0} == '[')
{
$noicon = true;
$name = substr($name, 1);
}
else
$noicon = false;
//"name@attr_value" -> $name and $attr_val
$attr = '';
if (preg_match('|([^@\]]+)@([^\]]+)|', $name, $reg))
{
$name = $reg[1];
$attr_val = preg_replace('@[^0-9+-]@', '', $reg[2]);
}
if (($id = gws_skill_id($name)) !== false)
{
//Handle [shock@8]
if (isset($attr_val))
{
$skill = gws_details($id);
$attr = gws_attribute_name($skill['attribute']);
$attr = " $attr=$attr_val";
}
//Handle the difference between [[shock] and [shock]
if ($noicon)
return "[skill noicon$attr]" . $name . '[/skill]';
else
return "[skill$attr]" . $name . '[/skill]';
}
else
return $all;
}
//Process the [build=id] element
function build_id_replace($reg)
{
list($all, $id) = $reg;
$new_code = template_to_gwbbcode($id);
return (strpos($new_code, '[') === 0) ? $new_code:$all;
}
//Process the [build] element
function build_replace($reg)
{
global $gwbbcode_tpl;
global $userdata;
global $art_titel;
$art_name = $art_titel;
$gwbbcode_root_path = GWBBCODE_ROOT;
list($all, $att, $skills) = $reg;
$att = str_replace("\n", "<br/>\n", html_safe_decode($att));
$load = rand();
$build = $gwbbcode_tpl['build'];
//Build name
$build_name = gws_build_name($att);
$build_name = str_replace('{br}', '<br/>', str_replace('{br/}', '<br/>',
str_replace('{BR}', '<br/>', str_replace('{BR/}', '<br/>', $build_name))));
//Professions
$prof = gws_build_profession($att);
$prof_imgs = '';
$cursor = 'help';
if ($prof !== false)
{
$prof_img = '<img class="build_icon" src="http://images.pvxbuilds.com/img_interface/{profession}.gif?r=1" style="cursor: {cursor};" onmouseover="return overlib(div(\'load' .
$load . '\').innerHTML);" onmouseout="return nd();"/>';
$primary = gws_prof_name($prof['primary']);
$secondary = gws_prof_name($prof['secondary']);
$showimg = '';
$prof_imgs .= str_replace('{profession}', $primary, $prof_img);
if ($secondary != 'No profession' && $secondary != $primary)
$prof_imgs .= str_replace('{profession}', $secondary, $prof_img);
}
else
{
$showimg = ' ;display: none';
$primary = '?';
$secondary = '?';
}
//Attributes
$attributes = '';
foreach (explode(' ', gws_attributes_clean($att)) as $value)
{
$value = explode('=', $value);
if ($att_name = gws_attr_name($value[0]))
{
$attributes .= str_replace('{attribute_name}', $att_name, $gwbbcode_tpl['attribute']);
$value[1] = str_replace('+', ' + ', $value[1]);
$attributes = str_replace('{attribute_value}', $value[1], $attributes);
}
}
$skills = str_replace('[skill', '[skill ' . $att, $skills);
//Build description
$desc = preg_match('|desc=\\"([^"]+)\\"|', $att, $reg) ? $reg[1]:'';
$desc = empty($desc) ? '':($desc . '<br/>');
$desc = str_replace('{br}', '<br/>', str_replace('{br/}', '<br/>', str_replace('{BR}',
'<br/>', str_replace('{BR/}', '<br/>', $desc))));
//Pickup status
$pickup_id = preg_match('|pickup=\\"([^"]+)\\"|', $att, $reg) ? $reg[1]:'';
//Get all pickup users
$pickup = load(PICKUP_PATH);
if (!empty($pickup_id) && $pickup !== false)
{
//Output status
$cursor = 'pointer';
$pickup = "Can play it: <span id=\"pickup_$pickup_id\">" . pickup_users($pickup,
$userdata['username'], $pickup_id, 'No one can!') . '</span>';
$pickup_link = " onclick=\"pickup('switch', '$pickup_id')\"";
}
else
{
$pickup = '';
$pickup_link = '';
}
$prof_imgs = str_replace('{cursor}', $cursor, $prof_imgs);
//Template: professions
$invalid_template = false;
static $prof_ids = array('No profession', 'Warrior', 'Ranger', 'Monk',
'Necromancer', 'Mesmer', 'Elementalist', 'Assassin', 'Ritualist', 'Paragon',
'Dervish');
$template = '0111000000';
$template .= int2bin(array_search($primary, $prof_ids), 4);
$template .= int2bin(array_search($secondary, $prof_ids), 4);
//Template: attributes
static $attr_ids = array('fas', 'ill', 'dom', 'ins', 'blo', 'dea', 'sou',
'cur', 'air', 'ear', 'fir', 'wat', 'ene', 'hea', 'smi', 'pro', 'div', 'str',
'axe', 'ham', 'swo', 'tac', 'bea', 'exp', 'wil', 'mar', 29 => 'dag', 'dead',
'sha', 'com', 'res', 'cha', 'cri', 'spa', 'spe', 'comma', 'mot', 'lea', 'scy',
'win', 'earthp', 'mys');
static $prof_attr_list = array('Air Magic' => 'Elementalist', 'Earth Magic' =>
'Elementalist', 'Energy Storage' => 'Elementalist', 'Fire Magic' =>
'Elementalist', 'Water Magic' => 'Elementalist', 'Domination Magic' => 'Mesmer',
'Fast Casting' => 'Mesmer', 'Illusion Magic' => 'Mesmer', 'Inspiration Magic' =>
'Mesmer', 'Divine Favor' => 'Monk', 'Healing Prayers' => 'Monk',
'Protection Prayers' => 'Monk', 'Smiting Prayers' => 'Monk', 'Blood Magic' =>
'Necromancer', 'Curses' => 'Necromancer', 'Death Magic' => 'Necromancer',
'Soul Reaping' => 'Necromancer', 'Beast Mastery' => 'Ranger', 'Expertise' =>
'Ranger', 'Marksmanship' => 'Ranger', 'Wilderness Survival' => 'Ranger',
'Axe Mastery' => 'Warrior', 'Hammer Mastery' => 'Warrior', 'Strength' =>
'Warrior', 'Swordsmanship' => 'Warrior', 'Tactics' => 'Warrior',
'Critical Strikes' => 'Assassin', 'Dagger Mastery' => 'Assassin', 'Deadly Arts' =>
'Assassin', 'Shadow Arts' => 'Assassin', 'Spawning Power' => 'Ritualist',
'Channeling Magic' => 'Ritualist', 'Communing' => 'Ritualist',
'Restoration Magic' => 'Ritualist', 'Spear Mastery' => 'Paragon', 'Command' =>
'Paragon', 'Motivation' => 'Paragon', 'Leadership' => 'Paragon',
'Scythe Mastery' => 'Dervish', 'Wind Prayers' => 'Dervish', 'Earth Prayers' =>
'Dervish', 'Mysticism' => 'Dervish');
$attr_list = attribute_list_raw($att);
arsort($attr_list);//=> First attribute is attribute of highest level
//Prepare a base attribute level and rune bonus list for primary and secondary attributes
$attr_primary = array();
$attr_secondary = array();
$attr_runes = array();
$available_helmet = true;
foreach ($attr_list as $attr => $raw_level)
{
//Separate base level and bonus
preg_match('@^([0-9]+)(\\+[+0-9]+)?@', $raw_level, $reg);
$base_level = $reg[1];
$bonus = isset($reg[2]) ? $reg[2]:'0';
//Primary attributes
if ($prof_attr_list[$attr] == $primary)
{
$bonus_level = @eval('return ' . $bonus . ';');
//Invalid attribute level bonus
if ($bonus_level > 4 || $bonus_level < 0 || ($bonus_level == 4 && !$available_helmet))
{
$invalid_template = true;
}
//Does attribute level bonus include a helmet?
else
if ($available_helmet && ($bonus_level == 4 || (substr_count($bonus, '+') > 1 &&
strpos($bonus, '+1') !== false)))
{
$available_helmet = false;
$attr_primary[$attr] = $base_level;
$attr_runes[$attr] = $bonus_level - 1;
}
//No helmet, but runes maybe
else
{
$attr_primary[$attr] = $base_level;
$attr_runes[$attr] = $bonus_level;
}
}
//Secondary attributes
else
if ($prof_attr_list[$attr] == $secondary)
{
$attr_secondary[$attr] = $base_level;
}
}
//Manage primary attribute levels
$points_secondary = attr_points($attr_secondary);
if (!empty($attr_primary))
{
//Set helmet if needed
if ($available_helmet && (max($attr_primary) > 12 || (attr_points($attr_primary) +
$points_secondary > 200)))
{
reset($attr_primary);
$attr_primary[key($attr_primary)]--;//First attribute is attribute of highest level, the one needing a helmet the most
}
//Assign runes
while ((max($attr_primary) > 12 || (attr_points($attr_primary) + $points_secondary >
200)) && min($attr_runes) < 3)
{
arsort($attr_primary);
foreach ($attr_runes as $attr => $rune)
{
if ($rune < 3)
{
$attr_primary[$attr]--;
$attr_runes[$attr]++;
break;
}
}
}
}
$attr_list = array_merge($attr_primary, $attr_secondary);
$template .= int2bin(count($attr_list), 4);
if (!empty($attr_list) && (max($attr_list) > 12 || min($attr_list) < 0 ||
attr_points($attr_list) > 200))
{
$invalid_template = true;
}
$attr_bit_size = 5;
$template_attrs = array();
foreach ($attr_list as $attr => $level)
{
$id = array_search(gws_attribute_name($attr), $attr_ids);
$template_attrs[$id] = $level;
if ($id >= 32)
{
$attr_bit_size = 6;
}
}
$template .= int2bin($attr_bit_size - 4, 4);
ksort($template_attrs);
foreach ($template_attrs as $id => $level)
{
$template .= int2bin($id, $attr_bit_size);
$template .= int2bin($level, 4);
}
//Template: skills
$skill_bit_size = 9;
$template_skills = array();
if (preg_match_all('#\[skill[^\]]*\](.*?)\[/skill\][ ]?#isS', $skills, $regs,
PREG_PATTERN_ORDER))
{
foreach ($regs[1] as $skill_name)
{
if (($id = gws_skill_id($skill_name)) !== false)
{
$template_skills[] = $id;
if ($id > 512)
{
$skill_bit_size = 11;
}
}
}
}
$template .= int2bin($skill_bit_size - 8, 4);
if (count($template_skills) > 8)
{
$invalid_template = true;
}
else
{
foreach ($template_skills as $id)
{
$template .= int2bin($id, $skill_bit_size);
}
//Complete with 0s
$template .= str_repeat(str_repeat('0', $skill_bit_size), 8 - count($template_skills));
}
//Manage template save icons
if (strstr($att, 'nosave') !== false)
{
$template_download = '';
}
else
{
if (!$invalid_template)
{
//Prepare template bbcode
$template_code = bin_to_template($template);
$template_name = preg_replace('@[];]@', '', preg_replace('@<br/>.*@', '', $build_name));
if (empty($template_name))
{
$template_name = gws_profession_abbr($primary);
if ($secondary != 'No profession' && $secondary != $primary)
{
$template_name .= '/' . gws_profession_abbr($secondary);
}
}
$p_abbr = gws_profession_abbr($primary);
$s_abbr = gws_profession_abbr($secondary);
// if our build has its own name, lets use it
if (strlen($build_name) != 0) $art_name = $p_abbr . "/" . $s_abbr . " " . $build_name;
$template_bbcode = "[$art_name;$template_code]";
$template_code = urlencode($template_code);
$template_size = strlen($template_bbcode);
$template_download = "<a href=\"\" onclick=\"return switch_template('$load');\"><img class=\"no_link\" src=\"http://images.pvxbuilds.com/img_interface/download.gif\" title=\"Copy $template_bbcode\" style=\"vertical-align: top;\"/></a>";
}
else
{
$template_download = "<img class=\"no_link\" src=\"http://images.pvxbuilds.com/img_interface/download_no.gif\" title=\"Incorrect build\" style=\"vertical-align: top;\"/>";
}
}
//Show a box around skills if "box" is in the build attribute list
if (strstr(strtolower($att), 'box') !== false)
{
$buildbox_left = 'class="buildbox_left"';
$buildbox_center = 'class="buildbox_center"';
$buildbox_right = 'class="buildbox_right"';
}
else
{
$buildbox_left = '';
$buildbox_center = '';
$buildbox_right = '';
}
return preg_replace("#\{(.*?)\}#ise", "isset($\\1)?$\\1:'\\0'", $build);
}
//Process the [skill] elements
function skill_replace($reg)
{
global $gwbbcode_tpl;
$gwbbcode_root_path = GWBBCODE_ROOT;
list($all, $att, $name) = $reg;
$att = html_safe_decode($att);
$name = html_safe_decode($name);
//Exit if skill doesn't exist
if (($id = gws_skill_id($name)) === false)
{
return $all;
}
//else
$details = gws_details($id);
if ($details === false)
die("Missing skill $id.");
extract($details, EXTR_OVERWRITE);
$load = rand();
//Blank skill slot
if ($name == 'No Skill')
{
$skill = $gwbbcode_tpl['blank_icon'];
}
//Skill slot
else
{
//Skill name or image on which to move cursor
if (gws_noicon($att))
{
if (GWSHACK)
{
$skill = $gwbbcode_tpl['noicon_gwshack'];
}
else
{
$skill = $gwbbcode_tpl['noicon'];
}
}
else
{
$name = str_replace("\"",""", $name);
$skill = $gwbbcode_tpl['icon'];
}
$skill .= $gwbbcode_tpl['skill'];
//What adrenaline/energy/energyregen is required?
$required = array();
$img_html = '<div class="bbcode_att_box"><span class="bbcode_att_span">%s</span><img src="http://images.pvxbuilds.com/att_%s.png" /></div>';
if ($recharge != 0)
$required[] = sprintf($img_html, $recharge, 'rech');
//Format casting time
if ($casting != 0)
{
$fastcast = calc_fastcasting($att, $type, $casting);
switch ($casting)
{
case 0.25:
$casting_frac = '¼';
break;
case 0.50:
$casting_frac = '½';
break;
case 0.75:
$casting_frac = '¾';
break;
default:
$casting_frac = $casting;
}
if ($fastcast && $fastcast != $casting)
$casting_frac .= '<span class="bbcode_expert">[' . sprintf('%.2f', $fastcast) .
']</span>';
$casting = $casting_frac;
$required[] = sprintf($img_html, $casting, 'cast');
}
//Format energy, adrenaline and upkeep
if ($adrenaline != 0)
$required[] = sprintf($img_html, $adrenaline, 'adre');
else
if ($energy != 0)
{
$ex_energy = calc_expertise($att, $type, $energy, $profession, $desc);
if ($ex_energy && $ex_energy != $energy)
$energy .= '<span class="bbcode_expert">[' . $ex_energy . ']</span>';
$required[] = sprintf($img_html, $energy, 'ener');
}
if ($eregen != 0)
$required[] = sprintf($img_html, -$eregen, 'eregen');
$required = implode(array_reverse($required));
//Have a nice golden background if skill is elite
if (isset($elite) && $elite)
{
$elite_background = 'bbcode_name_elite';
$type = 'Elite ' . $type;
}
else
{
$elite_background = 'bbcode_name_normal';
$yellow_elite = '';
}
//Campaign names
switch ($chapter)
{
case 0:
$chapter = "Core";
break;
case 1:
$chapter = "Prophecies";
break;
case 2:
$chapter = "Factions";
break;
case 3:
$chapter = "Nightfall";
break;
}
//Descriptions variables -> green and adapted to their attribute. (1..16 -> green 8)
$desc = gws_adapt_description($name, $attribute, $att, $desc);
$block_size = strlen($desc) * 1.33;
if ($block_size < 280)
$block_size = 295;
//Profession icon
if ($prof == '?')
$prof_img = "http://images.pvxbuilds.com/img_interface/No-Profession.png";
else
$prof_img = "http://images.pvxbuilds.com/img_interface/$profession.png";
//TODO: No profession img
}
$skill = preg_replace("#\{(.*?)\}#ise", "isset($\\1)?$\\1:'\\0'", $skill);
//Adds a space entity if the skill tag is followed by a space
//Necessary cause IE doesn't show spaces following divs
if ($all[strlen($all) - 1] === ' ')
{
$skill .= ' ';
}
return $skill;
}
//Returns either the id of a $skill_name, or false
//Also works if $skill_name is an abbreviation
function gws_skill_id($skill_name)
{
//Handle abbreviations
static $abbr_db = array();
$skill_name = strtolower($skill_name);
if (empty($abbr_db))
{
if (($abbr_db = @load(SKILLABBRS_PATH)) === false)
{
die("Missing abbreviation database.");
}
}
if (isset($abbr_db[$skill_name]))
{
$skill_name = $abbr_db[$skill_name];
}
//Retreive the id
if (!GWBBCODE_SQL)
{
//File DB
//Load the name to id listing from a file (only once)
static $list = array();
if (empty($list))
{
if (($list = @load(SKILLNAMES_PATH)) === false)
{
die("Missing skillname database.");
}
}
$name_id = preg_replace('|[\'"!]|', '', strtolower($skill_name));
$ret = isset($list[$name_id]) ? $list[$name_id]:false;
}
else
{
//SQL DB
$name_id = mysql_real_escape_string(preg_replace('@["\'!]@', '', strtolower($skill_name)));
$result = mysql_query("SELECT id FROM `skills` WHERE name_id='$name_id'") or die('Query failed: ' .
mysql_error());
$ret = mysql_fetch_assoc($result);
mysql_free_result($result);
$ret = $ret ? $ret['id']:false;//Directly return the id, not an array
}
return $ret;
}
//Returns either the skill information array of a $skill_id, or false
function gws_details($skill_id)
{
if (!GWBBCODE_SQL)
{
//File DB
//(Re)load skill list
static $skill_list = array();
if (empty($skill_list))
{
if (!file_exists(SKILLS_PATH_1) || !file_exists(SKILLS_PATH_2))
return false;
else
$skill_list = load(SKILLS_PATH_1);//Can't use array_merge here otherwise keys get lost
$add_list = load(SKILLS_PATH_2);
foreach ($add_list as $key => $val)
{
$skill_list[$key] = $val;
}
}
$ret = isset($skill_list[$skill_id]) ? $skill_list[$skill_id]:false;
}
else
{
//SQL DB
preg_match('@^[0-9]+$@', $skill_id) or die('Unsafe skill id');
$result = mysql_query("SELECT * FROM `skills` WHERE id=$skill_id") or die('Query failed: ' .
mysql_error());
$ret = mysql_fetch_assoc($result);
mysql_free_result($result);
}
return $ret;
}
//Returns values of the prof attribute of an attribute list (string $att), or false
//gws_build_profession(' prof=W/E tactics=16 desc="fdsfsdf"') === Array('primary' => 'W', 'secondary' => 'E', 'professions => 'W/E')
function gws_build_profession($att)
{
if (preg_match('|prof=(([^/ ]+)/([^ ]+))|', $att, $reg))
return array('primary' => $reg[2], 'secondary' => $reg[3], 'professions' => $reg[1]);
else
if (preg_match('|prof=([^/ ]+)|', $att, $reg))
return array('primary' => $reg[1], 'secondary' => '?', 'professions' => $reg[1]);
else
return false;
}
//Returns value of the name attribute of an attribute list (string $att), or ''
//gws_build_name(' prof=W/E name="Shock Warrior"') === 'Shock Warrior'
function gws_build_name($att)
{
return preg_match('|name=\\"([^\"]+)\\"|', $att, $reg) ? $reg[1]:'';
}
//Returns the full profession name of a partial one. Returns 'No profession' if no match is found
function gws_prof_name($profession)
{
//Look for a profession name corresponding to $profession
static $p = array('E' => 'Elementalist', 'Me' => 'Mesmer', 'Mo' => 'Monk', 'N' =>
'Necromancer', 'R' => 'Ranger', 'W' => 'Warrior', 'A' => 'Assassin', 'Rt' =>
'Ritualist', 'D' => 'Dervish', 'P' => 'Paragon', '?' => 'No profession');
$profession = strtolower($profession);
//Ritualist exception
if ($profession == 'rt')
return $p['Rt'];
foreach ($p as $prof)
if (strpos(strtolower($prof), $profession) === 0)
return $prof;
//No corresponding profession was found
return 'No profession';
}
//Returns the profession abbreviation of a partial one. Returns '?' if no match is found
function gws_profession_abbr($profession)
{
static $p = array('E' => 'Elementalist', 'Me' => 'Mesmer', 'Mo' => 'Monk', 'N' =>
'Necromancer', 'R' => 'Ranger', 'W' => 'Warrior', 'A' => 'Assassin', 'Rt' =>
'Ritualist', 'D' => 'Dervish', 'P' => 'Paragon', '?' => 'No profession');
return array_search(gws_prof_name($profession), $p);
}
//Returns the full attribute name of a partial or full one. Returns false if no match is found
function gws_attr_name($attr)
{
static $attribute_list = array('airmagic' => 'Air Magic', 'earthmagic' =>
'Earth Magic', 'energystorage' => 'Energy Storage', 'firemagic' => 'Fire Magic',
'watermagic' => 'Water Magic', 'dominationmagic' => 'Domination Magic',
'fastcasting' => 'Fast Casting', 'illusionmagic' => 'Illusion Magic',
'inspirationmagic' => 'Inspiration Magic', 'divinefavor' => 'Divine Favor',
'healingprayers' => 'Healing Prayers', 'protectionprayers' =>
'Protection Prayers', 'smitingprayers' => 'Smiting Prayers', 'bloodmagic' =>
'Blood Magic', 'curses' => 'Curses', 'deathmagic' => 'Death Magic',
'soulreaping' => 'Soul Reaping', 'beastmastery' => 'Beast Mastery', 'expertise' =>
'Expertise', 'marksmanship' => 'Marksmanship', 'wildernesssurvival' =>
'Wilderness Survival', 'axemastery' => 'Axe Mastery', 'hammermastery' =>
'Hammer Mastery', 'strength' => 'Strength', 'swordsmanship' => 'Swordsmanship',
'tactics' => 'Tactics', 'criticalstrikes' => 'Critical Strikes', 'daggermastery' =>
'Dagger Mastery', 'deadlyarts' => 'Deadly Arts', 'shadowarts' => 'Shadow Arts',
'spawningpower' => 'Spawning Power', 'channelingmagic' => 'Channeling Magic',
'communing' => 'Communing', 'restorationmagic' => 'Restoration Magic',
'spearmastery' => 'Spear Mastery', 'command' => 'Command', 'motivation' =>
'Motivation', 'leadership' => 'Leadership', 'scythemastery' => 'Scythe Mastery',
'windprayers' => 'Wind Prayers', 'earthprayers' => 'Earth Prayers', 'mysticism' =>
'Mysticism');
$attr = strtolower(str_replace('_', '', $attr));
if (empty($attr))
{
return false;
}
foreach ($attribute_list as $long_attr => $attribute)
{
if (strpos($long_attr, $attr) === 0)
{
return $attribute;
}
}
//else
return false;
}
//Returns the attribute name abbreviation of a partial one. Returns false if no match is found
function gws_attribute_name($attribute)
{
static $attribute_list = array('air' => 'airmagic', 'ear' => 'earthmagic', 'ene' =>
'energystorage', 'fir' => 'firemagic', 'wat' => 'watermagic', 'dom' =>
'dominationmagic', 'fas' => 'fastcasting', 'ill' => 'illusionmagic', 'ins' =>
'inspirationmagic', 'div' => 'divinefavor', 'hea' => 'healingprayers', 'pro' =>
'protectionprayers', 'smi' => 'smitingprayers', 'blo' => 'bloodmagic', 'cur' =>
'curses', 'dea' => 'deathmagic', 'sou' => 'soulreaping', 'bea' => 'beastmastery',
'exp' => 'expertise', 'mar' => 'marksmanship', 'wil' => 'wildernesssurvival',
'axe' => 'axemastery', 'ham' => 'hammermastery', 'str' => 'strength', 'swo' =>
'swordsmanship', 'tac' => 'tactics', 'cri' => 'criticalstrikes', 'dag' =>
'daggermastery', 'dead' => 'deadlyarts', 'sha' => 'shadowarts', 'spa' =>
'spawningpower', 'cha' => 'channelingmagic', 'com' => 'communing', 'res' =>
'restorationmagic', 'spe' => 'spearmastery', 'comma' => 'command', 'mot' =>
'motivation', 'lea' => 'leadership', 'scy' => 'scythemastery', 'win' =>
'windprayers', 'earthp' => 'earthprayers', 'mys' => 'mysticism');
$attribute = strtolower(str_replace(' ', '', $attribute));
foreach ($attribute_list as $attr => $long_attr)
{
if (strpos($long_attr, $attribute) === 0)
{
return $attr;
}
}
//else
return false;
}
//Returns an attribute list (string) cleaned of the prof, name, desc and pickup attributes
function gws_attributes_clean($att)
{
$att = preg_replace('|prof=[^ \]]*|', '', $att);
$att = preg_replace('|name=\\"[^"]+\\"|', '', $att);
$att = preg_replace('|desc=\\"[^"]+\\"|', '', $att);
$att = preg_replace('|pickup=\\"[^"]+\\"|', '', $att);
return trim($att);
}
//Returns a list of attributes and their string values (e.g "12+1+3")
function attribute_list_raw($att)
{
$list = array();
$clean_attr = explode(' ', gws_attributes_clean($att));
foreach ($clean_attr as $value)
{
$value = explode('=', $value);
//Only one '='?
if (count($value) == 2)
{
$attr_name = gws_attr_name($value[0]);
//Valid attribute name?
if ($attr_name !== false)
{
$attr_value = preg_replace('@[^0-9+-]@', '', $value[1]);
//Valid attribute value?
if (isset($attr_value) && $attr_value !== false)
{
//Alright record it
$list[$attr_name] = $attr_value;
}
}
}
}
return $list;
}
//Returns a list of attributes and their numeric values (e.g "12+1+3" will return 16)
function attribute_list($att)