APPLICATION_Helper.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * App helper file.
  4. *
  5. * Provides a helper to perform app related operations.
  6. *
  7. * @category Helper.
  8. */
  9. /**
  10. * Require dependent files if not present.
  11. */
  12. require_once(PATH::HELPER . "Helper.php");
  13. /**
  14. * Application helper.
  15. *
  16. * Contains app-related utilities.
  17. *
  18. * @category Helper.
  19. */
  20. final class APPLICATION extends Helper{
  21. /**
  22. * Checks if a value is a valid one in a constant class.
  23. *
  24. * It will intentionally fail when used for a non constant class.
  25. *
  26. * @param string $class Name of the class.
  27. * @param int $value Value to check.
  28. * @return bool True if the value is defined, false otherwise.
  29. */
  30. public static function valid_id($class, $value){
  31. if (strtoupper($class) != $class){
  32. return false;
  33. }
  34. if (!class_exists($class, false)){
  35. return false;
  36. }
  37. $reflect = new ReflectionClass($class);
  38. if (in_array($value, $reflect->getConstants())){
  39. return true;
  40. }
  41. else{
  42. return false;
  43. }
  44. }
  45. /**
  46. * Forms an image URL.
  47. *
  48. * It will intentionally fail when used for a non constant class.
  49. *
  50. * @param string $type Image type. valid values are:
  51. * ICON, LOGO, CURRENCY, UNIT,
  52. * AREA, SKILL, ESSENCE, RUNE,
  53. * GRIND, ELEMENT, SKILL_GUILD, DECORATION,
  54. * SOURCE, SKILL_LEADER, INVENTORY, EFFECT,
  55. * BUILDING
  56. * @param string|int $name Filename, with no path or extension. It can also
  57. * skip the padding. An id can be used.
  58. * @return Image URL if found. If not, the URL to an 'unknown' icon.
  59. */
  60. public static function img($type, $name){
  61. $pad = 1;
  62. $url = URL::IMG["UNKNOWN"];
  63. while ($pad < 10){
  64. if (isset(PATH::IMG[$type]) && file_exists(PATH::IMG[$type] . str_pad($name, $pad, '0', STR_PAD_LEFT) . ".png")){
  65. $url = URL::IMG[$type] . str_pad($name, $pad, '0', STR_PAD_LEFT) . ".png";
  66. break;
  67. }
  68. $pad ++;
  69. }
  70. return $url;
  71. }
  72. }
  73. ?>