4674d085d71de62e05c769dfbb89d2ae810e68b7.svn-base 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php namespace Maze\Http;
  2. use Maze\Config\Lang;
  3. use Maze\Debug\Process as Debug;
  4. class Output
  5. {
  6. static public function result($msg, $print = true, $array = true)
  7. {
  8. $json = Input::get('json', false);
  9. $callback = Input::get('callback', false);
  10. $function = Input::get('function', false);
  11. if(!is_array($msg) && ($callback || $array == true))
  12. {
  13. $result['status'] = 1;
  14. $result['msg'] = $msg;
  15. }
  16. else
  17. {
  18. $result = $msg;
  19. }
  20. if(is_array($result))
  21. {
  22. //JSON_FORCE_OBJECT
  23. $result = json_encode($result);
  24. }
  25. ($json != false && is_array($result)) && $result = json_encode($result);
  26. $callback != false && $result = $callback . '('.$result.')';
  27. $function != false && $result = '<script>parent.'.$function.'('.$result.')'.'</script>';
  28. if($print == true)
  29. {
  30. self::export($result, true);
  31. }
  32. return $result;
  33. }
  34. /**
  35. * export
  36. * @param string $text
  37. *
  38. * @return string
  39. */
  40. static public function export($text, $exit = false)
  41. {
  42. if(is_array($text))
  43. {
  44. $callback = Input::get('callback', false);
  45. if($callback)
  46. {
  47. $text = $callback . '('.json_encode($text).')';
  48. }
  49. print_r($text);
  50. }
  51. else
  52. {
  53. echo $text;
  54. }
  55. if($exit == true)
  56. {
  57. Debug::data();
  58. die;
  59. }
  60. }
  61. /**
  62. * out
  63. * @param string $msg
  64. *
  65. * @return string
  66. */
  67. static public function abert($msg, $param = array())
  68. {
  69. $send['msg'] = Lang::get($msg, $param);
  70. $send['status'] = 2;
  71. $callback = Input::get('callback', false);
  72. $json = Input::get('json', false);
  73. $function = Input::get('function', false);
  74. if($callback || $json || $function)
  75. {
  76. self::result($send);
  77. }
  78. else
  79. {
  80. self::html($send);
  81. }
  82. //self::export($send, true);
  83. }
  84. /**
  85. * out
  86. * @param string $msg
  87. *
  88. * @return string
  89. */
  90. static public function html($msg)
  91. {
  92. $html = '<table border="1" style="color:red;margin:0 auto;width:100%;height:auto;">';
  93. foreach($msg as $k => $v)
  94. {
  95. $html .= '<tr><td>'.$k.'</td><td>'.$v.'</td></tr>';
  96. }
  97. $html .= '</table>';
  98. //$html .= Debug::html('');
  99. self::export($html, true);
  100. }
  101. }