123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php namespace Maze\Http;
- use Maze\Config\Lang;
- use Maze\Debug\Process as Debug;
- class Output
- {
-
- static public function result($msg, $print = true, $array = true)
- {
- $json = Input::get('json', false);
- $callback = Input::get('callback', false);
- $function = Input::get('function', false);
- if(!is_array($msg) && ($callback || $array == true))
- {
- $result['status'] = 1;
- $result['msg'] = $msg;
- }
- else
- {
- $result = $msg;
- }
- if(is_array($result))
- {
- //JSON_FORCE_OBJECT
- $result = json_encode($result);
- }
-
- ($json != false && is_array($result)) && $result = json_encode($result);
- $callback != false && $result = $callback . '('.$result.')';
- $function != false && $result = '<script>parent.'.$function.'('.$result.')'.'</script>';
- if($print == true)
- {
- self::export($result, true);
- }
- return $result;
- }
- /**
- * export
- * @param string $text
- *
- * @return string
- */
- static public function export($text, $exit = false)
- {
- if(is_array($text))
- {
- $callback = Input::get('callback', false);
- if($callback)
- {
- $text = $callback . '('.json_encode($text).')';
- }
-
- print_r($text);
- }
- else
- {
- echo $text;
- }
-
- if($exit == true)
- {
- Debug::data();
-
- die;
- }
- }
-
- /**
- * out
- * @param string $msg
- *
- * @return string
- */
- static public function abert($msg, $param = array())
- {
- $send['msg'] = Lang::get($msg, $param);
- $send['status'] = 2;
-
- $callback = Input::get('callback', false);
- $json = Input::get('json', false);
- $function = Input::get('function', false);
-
- if($callback || $json || $function)
- {
- self::result($send);
- }
- else
- {
- self::html($send);
- }
- //self::export($send, true);
- }
-
- /**
- * out
- * @param string $msg
- *
- * @return string
- */
- static public function html($msg)
- {
- $html = '<table border="1" style="color:red;margin:0 auto;width:100%;height:auto;">';
-
- foreach($msg as $k => $v)
- {
- $html .= '<tr><td>'.$k.'</td><td>'.$v.'</td></tr>';
- }
-
- $html .= '</table>';
-
- //$html .= Debug::html('');
-
- self::export($html, true);
- }
- }
|