74955be25f33b8d9969484b6f4c774fbae8b5dd5.svn-base 2.2 KB

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