HTML_Helper.php 19 KB

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