html.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <?php
  2. /**
  3. * Alias for htmlspecialchars([input], ENT_QUOTES)
  4. *
  5. * @param input Text to escape.
  6. * @return Escaped text.
  7. */
  8. function e($input){
  9. return htmlspecialchars($input, ENT_QUOTES);
  10. }
  11. /**
  12. * Generates a monster panel.
  13. *
  14. * @param unit Unit/K_Unit Entity to get the info from.
  15. * @return string HTML content for a monster panel. Empty on error.
  16. */
  17. function html_unit_panel($unit) {
  18. global $path;
  19. if ($unit instanceof Unit){
  20. $k = $unit->unit;
  21. $stars = $unit->stars;
  22. $level = true;
  23. $teams = (sizeof($unit->teams) > 0);
  24. $lock = $unit->lock;
  25. $storage = $unit->in_storage;
  26. $maxed = ($unit->level == 40 && $unit->are_skills_maxed());
  27. }
  28. elseif ($unit instanceof K_Unit){
  29. $k = $unit;
  30. $stars = $unit->base_stars;
  31. $level = false;
  32. $teams = 0;
  33. $lock = false;
  34. $storage = false;
  35. $maxed = false;
  36. }
  37. else{
  38. return "";
  39. }
  40. $html = "";
  41. if ($k->awakens_from == "" && $k->awakens_to == ""){
  42. // No to, no from, silver monster.
  43. $star_class ="star_silver";
  44. }
  45. elseif ($k->awakens_from != ""){
  46. // Already awakened
  47. if ($k->base_stars - $k->natural_stars == 1){
  48. // Normal awaken.
  49. $star_class ="star_purple";
  50. }
  51. else{
  52. // Second awaken.
  53. $star_class ="star_red";
  54. }
  55. }
  56. elseif ($k->awakens_to != ""){
  57. // Awakeable.
  58. $star_class ="star_gold";
  59. }
  60. $html .= "<span class='stars'>\n";
  61. for ($i = 0; $i < $stars; $i ++){
  62. $html .= "<img class='star $star_class' src='" . $path["img"]["icon"] . "star.png'/>\n";
  63. }
  64. $html .= "</span>\n";
  65. $html .= "<img title='" . $unit->title . "' class='monster border_" . $k->element_name . "' src='" . $k->get_image() . "'/>\n";
  66. if ($level){
  67. $html .= "<span class='level'>\n";
  68. $html .= $unit->level . "\n";
  69. $html .= "</span>\n";
  70. }
  71. $html .= "<span class='badges'>\n";
  72. if ($maxed){
  73. $html .= "<img title='Maxed unit' src='" . $path["img"]["icon"] . "maxed.png'>";
  74. }
  75. if ($teams > 0){
  76. $title = $teams . " teams";
  77. if ($teams == 1){
  78. $title = "1 team: " . $unit->teams[0]->name;
  79. }
  80. $html .= "<img title='$title' src='" . $path["img"]["icon"] . "team.png'>";
  81. }
  82. if ($lock == 1){
  83. $html .= "<img title='Locked' src='" . $path["img"]["icon"] . "lock.png'>";
  84. }
  85. if ($storage){
  86. $html .= "<img title='In storage' src='" . $path["img"]["icon"] . "storage.png'>";
  87. }
  88. $html .= "</span>\n";
  89. return $html;
  90. }
  91. /**
  92. * Generates a transformed monster panel.
  93. *
  94. * @param unit Unit/K_Unit Entity to get the info from.
  95. * @return string HTML content for a monster panel. Empty on error.
  96. */
  97. function html_unit_transformation_panel($unit) {
  98. global $path;
  99. $html = "";
  100. if ($unit instanceof Unit){
  101. $k = $unit->unit;
  102. }
  103. elseif ($unit instanceof K_Unit){
  104. $k = $unit;
  105. }
  106. else{
  107. return "";
  108. }
  109. if ($k->transformation == null){
  110. return "";
  111. }
  112. $html .= "<div class='monster_transformation_panel'>\n";
  113. $html .= "<img title='" . $unit->title . " (transformed)' class='monster_transformation border_" . $k->element_name . "' src='" . $k->transformation->get_image() . "'/>\n";
  114. $html .= "</div>\n";
  115. return $html;
  116. }
  117. /**
  118. * Generates a rune panel.
  119. *
  120. * @param Rune rune Entity to get the info from.
  121. * @param Unit unit Optional. The unit the rune is assigned to.
  122. * @return string HTML content for a rune panel. Empty on error.
  123. */
  124. function html_rune_panel($rune, $unit = null) {
  125. global $path;
  126. if (!($rune instanceof Rune)){
  127. return "";
  128. }
  129. $html = "";
  130. $html .= "<div class='rune_panel rune_slot_" . $rune->slot . " rune_level_" . $rune->level . " rune_quality_" . strtolower($rune->quality_name) . " rune_original_quality_" . strtolower($rune->original_quality_name) . " rune_ancient_" . $rune->ancient . "'>\n";
  131. $html .= "<img class='rune_base' src='" . $path["img"]["rune"] . "base.png'/>\n";
  132. $html .= "<img class='rune_icon' src='" . $rune->type->get_image() . "'/>\n";
  133. $html .= "<span class='rune_stars'>\n";
  134. for ($i = 0; $i < $rune->stars; $i ++){
  135. $html .= "<img class='star' src='" . $path["img"]["icon"] . "star.png'/>\n";
  136. }
  137. $html .= "</span>\n";
  138. $html .= "<span class='rune_level'>\n";
  139. $html .= $rune->level . "\n";
  140. $html .= "</span>\n";
  141. $html .= "</div>\n";
  142. if ($unit instanceof Unit){
  143. $html .= "<div class='assigned'>\n";
  144. $html .= "<a target='blank' href='/monsters/" . $unit->id . "'>\n";
  145. $html .= "<img title='" . $unit->title . "' class='monster_image border_" . $unit->unit->element_name . "' src='" . $unit->unit->get_image() . "'/>\n";
  146. $html .= "</a>\n";
  147. $html .= "</div>\n";
  148. }
  149. return $html;
  150. }
  151. /**
  152. * Generates a rune table.
  153. *
  154. * @param Rune rune Entity to get the info from.
  155. * @param Unit unit Optional. The unit the rune is assigned to.
  156. * @return string HTML content for a rune table. Empty on error.
  157. */
  158. function html_rune_table($rune, $unit = null) {
  159. global $path;
  160. if (!($rune instanceof Rune)){
  161. return "";
  162. }
  163. $html = "";
  164. $html .= "<table class='rune'>\n";
  165. $html .= "<tr>\n";
  166. $html .= "<td class='icon'>\n";
  167. $html .= html_rune_panel($rune, $unit) . "\n";
  168. $html .= "</td>\n";
  169. $html .= "<td class='stats'>\n";
  170. $html .= "<table>\n";
  171. // Main stat
  172. $html .= "<tr class='main_stat'>\n";
  173. $html .= "<td class='stat'>\n";
  174. if (in_array($rune->main_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  175. $stat_name = str_replace("%", "", $rune->main_stat_name);
  176. $stat_value = "+ " . $rune->main_stat_value . "%";
  177. }
  178. else{
  179. $stat_name = $rune->main_stat_name;
  180. $stat_value = "+ " . $rune->main_stat_value;
  181. }
  182. $html .= $stat_name . "\n";
  183. $html .= "</td>\n";
  184. $html .= "<td class='value'>\n";
  185. $html .= $stat_value . "\n";
  186. $html .= "<td>\n";
  187. $html .= "</tr>\n";
  188. // Innate stat
  189. $html .= "<tr class='innate_stat'>\n";
  190. $html .= "<td class='stat'>\n";
  191. if (strlen($rune->innate_stat) == 0){
  192. $stat_name = "&nbsp;";
  193. $stat_value = "";
  194. }
  195. elseif (in_array($rune->innate_stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  196. $stat_name = str_replace("%", "", $rune->innate_stat_name);
  197. $stat_value = "+ " . $rune->innate_stat_value . "%";
  198. }
  199. else{
  200. $stat_name = $rune->innate_stat_name;
  201. $stat_value = "+ " . $rune->innate_stat_value;
  202. }
  203. $html .= $stat_name . "\n";
  204. $html .= "</td>\n";
  205. $html .= "<td class='value'>\n";
  206. $html .= $stat_value . "\n";
  207. $html .= "<td>\n";
  208. $html .= "</tr>\n";
  209. $substats = array($rune->substat_1, $rune->substat_2, $rune->substat_3, $rune->substat_4);
  210. $substats_name = array($rune->substat_1_name, $rune->substat_2_name, $rune->substat_3_name, $rune->substat_4_name);
  211. $substats_value = array($rune->substat_1_value, $rune->substat_2_value, $rune->substat_3_value, $rune->substat_4_value);
  212. $substats_grind = array($rune->substat_1_grind, $rune->substat_2_grind, $rune->substat_3_grind, $rune->substat_4_grind);
  213. $substats_enchant = array($rune->substat_1_enchant, $rune->substat_2_enchant, $rune->substat_3_enchant, $rune->substat_4_enchant);
  214. for ($i = 0; $i < 4; $i ++){
  215. if (strlen($substats_name[$i]) == 0){
  216. $stat_name = "&nbsp;";
  217. $stat_value = "";
  218. }
  219. elseif (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  220. $stat_name = str_replace("%", "", $substats_name[$i]);
  221. $stat_value = "+ " . $substats_value[$i] . "%";
  222. }
  223. else{
  224. $stat_name = $substats_name[$i];
  225. $stat_value = "+ " . $substats_value[$i];
  226. }
  227. $grind = "";
  228. if ($substats_grind[$i] > 0){
  229. $grind = "+" . $substats_grind[$i];
  230. if (in_array($substats_name[$i], array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  231. $grind = $grind . "%";
  232. }
  233. }
  234. $html .= "<tr class=substat>\n";
  235. $html .= "<td class='stat'>\n";
  236. $html .= $stat_name . "\n";
  237. $html .= "</td>\n";
  238. $html .= "<td class='value'>\n";
  239. $html .= $stat_value . "\n";
  240. $html .= "<span class='grind grind_$grind'>\n";
  241. $html .= $grind . "\n";
  242. $html .= "</span>\n";
  243. if ($substats_enchant[$i] == 1){
  244. $html .= "<img title='Enchanted' src='" . $path["img"]["rune"] . "enchanted.png'/>\n";
  245. }
  246. $html .= "</td>\n";
  247. $html .= "</tr>\n";
  248. }
  249. $html .= "</table>\n";
  250. $html .= "</td>\n";
  251. // Details
  252. $html .= "<td class='details'>\n";
  253. $html .= "<table class='table_details'>\n";
  254. $html .= "<tr>\n";
  255. $html .= "<td class='title'>\n";
  256. $html .= "Quality:\n";
  257. $html .= "</td>\n";
  258. $html .= "<td class='value'>\n";
  259. $html .= "<span class='quality quality_" . strtolower($rune->quality_name) . "'>\n";
  260. $html .= $rune->quality_name . "\n";
  261. $html .= "</span>\n";
  262. $html .= "</td>\n";
  263. $html .= "</tr>\n";
  264. $html .= "<tr>\n";
  265. $html .= "<td class='title'>\n";
  266. $html .= "Origina q.:\n";
  267. $html .= "</td>\n";
  268. $html .= "<td class='value'>\n";
  269. $html .= "<span class='quality quality_" . strtolower($rune->original_quality_name) . "'>\n";
  270. $html .= $rune->original_quality_name . "\n";
  271. $html .= "</span>\n";
  272. $html .= "</td>\n";
  273. $html .= "</tr>\n";
  274. $html .= "<tr>\n";
  275. $html .= "<td class='title'>\n";
  276. $html .= "Value:\n";
  277. $html .= "</td>\n";
  278. $html .= "<td class='value'>\n";
  279. $html .= number_format($rune->value, 0, ".", ",") . "\n";
  280. $html .= "</td>\n";
  281. $html .= "</tr>\n";
  282. $html .= "<tr>\n";
  283. $html .= "<td class='title'>\n";
  284. $html .= "Efficiency:\n";
  285. $html .= "</td>\n";
  286. $html .= "<td class='value'>\n";
  287. $html .= number_format($rune->efficiency, 2, ".", ",") . "%\n";
  288. $html .= "</td>\n";
  289. $html .= "</tr>\n";
  290. $html .= "<tr>\n";
  291. $html .= "<td class='title'>\n";
  292. $html .= "Max. eff.:\n";
  293. $html .= "</td>\n";
  294. $html .= "<td class='value'>\n";
  295. $html .= number_format($rune->max_efficiency, 2, ".", ",") . "%\n";
  296. $html .= "</td>\n";
  297. $html .= "</tr>\n";
  298. $html .= "<tr>\n";
  299. $html .= "<td class='title'>\n";
  300. $html .= "Reached. eff.:\n";
  301. $html .= "</td>\n";
  302. $html .= "<td class='value'>\n";
  303. $html .= number_format($rune->efficiency * 100 / $rune->max_efficiency, 2, ".", ",") . "%\n";
  304. $html .= "</td>\n";
  305. $html .= "</tr>\n";
  306. $html .= "</table>\n";
  307. $html .= "</td>\n";
  308. $html .= "</tr>\n";
  309. $html .= "</table>\n";
  310. return $html;
  311. }
  312. /**
  313. * Generates a grindstone or gem panel.
  314. *
  315. * @param Rune_Craft craft Entity to get the info from.
  316. * @return string HTML content for a rune panel. Empty on error.
  317. */
  318. function html_craft_panel($craft) {
  319. global $path;
  320. if (!($craft instanceof Rune_Craft)){
  321. return "";
  322. }
  323. $html = "";
  324. if ($craft->gem == 1){
  325. if ($craft->inmemorial == 1){
  326. $base = $path["img"]["grind"] . "gem_inmemorial.png";
  327. }
  328. else{
  329. $base = $path["img"]["grind"] . "gem.png";
  330. }
  331. }
  332. else{
  333. if ($craft->inmemorial == 1){
  334. $base = $path["img"]["grind"] . "grind_inmemorial.png";
  335. }
  336. else{
  337. $base = $path["img"]["grind"] . "grind.png";
  338. }
  339. }
  340. if ($craft->inmemorial == 0 && isset($craft->rune)){
  341. $icon = "<img class='craft_icon' src='" . $craft->rune->get_image() . "'/>\n";
  342. }
  343. else{
  344. $icon = "";
  345. }
  346. if (in_array($craft->stat_name, array("CRR", "CRD", "RES", "ACC", "HP%", "ATK%", "DEF%"))){
  347. $stat_name = str_replace("%", "", $craft->stat_name);
  348. $stat_value = "+ " . $craft->min . "~" . $craft->max . "%";
  349. }
  350. else{
  351. $stat_name = $craft->stat_name;
  352. $stat_value = "+ " . $craft->min . "~" . $craft->max;
  353. }
  354. $html .= "<div class='craft_panel craft_quality_" . strtolower($craft->quality_name) . " rune_ancient_" . $craft->ancient . "'>\n";
  355. $html .= "<img class='craft_base' src='" . $base . "'/>\n";
  356. $html .= $icon;
  357. $html .= "<span class='craft_stat'>\n";
  358. $html .= "<span class='craft_stat_name'>" . $stat_name . "</span>\n";
  359. $html .= "<span class='craft_stat_value'>" . $stat_value . "</span>\n";
  360. $html .= "</span>\n";
  361. $html .= "</div>\n";
  362. return $html;
  363. }
  364. /**
  365. * Generates a building panel.
  366. *
  367. * @param unit Building/Decoration/K_Building/K_Decoration Entity to get the info from.
  368. * @return string HTML content for a building panel. Empty on error.
  369. */
  370. function html_building_panel($building) {
  371. global $path;
  372. if ($building instanceof Building){
  373. $level = false;
  374. $title = $building->building->name;
  375. $description = $building->building->description;
  376. $img = $building->building->get_image();
  377. }
  378. elseif ($building instanceof K_Building){
  379. $level = false;
  380. $title = $building->name;
  381. $description = $building->building->description;
  382. $img = $building->get_image();
  383. }
  384. elseif ($building instanceof Decoration){
  385. $level = $building->level;
  386. $title = $building->decoration->name;
  387. $description = $building->decoration->description;
  388. $img = $building->decoration->get_image();
  389. }
  390. elseif ($building instanceof K_Decoration){
  391. $level = false;
  392. $title = $building->name;
  393. $description = $building->building->description;
  394. $img = $building->get_image();
  395. }
  396. else{
  397. return "";
  398. }
  399. if (strlen($description) > 0){
  400. $title .= ": " . $description;
  401. }
  402. $html = "";
  403. $html = "<div class='building_panel'>\n";
  404. $html .= "<img title='" . $title . "' class='building' src='" . $img . "'/>\n";
  405. if ($level){
  406. $html .= "<span class='level'>\n";
  407. $html .= $level . "\n";
  408. $html .= "</span>\n";
  409. }
  410. $html .= "</div>\n";
  411. return $html;
  412. }
  413. /**
  414. * Generates a item panel.
  415. *
  416. * @param item Inventory Entity to get the info from.
  417. * @return string HTML content for a building panel. Empty on error.
  418. */
  419. function html_item_panel($item) {
  420. global $path;
  421. global $INVENTORY_TYPE;
  422. if (!($item instanceof Inventory)){
  423. return "";
  424. }
  425. $html = "";
  426. $html = "<div class='item_panel'>\n";
  427. $html .= "<img title='" . $item->name . "' class='item' src='" . $item->get_image() . "'/>\n";
  428. $html .= "<span class='amount'>\n";
  429. $html .= $item->amount . "\n";
  430. $html .= "</span>\n";
  431. $html .= "</div>\n";
  432. return $html;
  433. }
  434. ?>