Exemplo n.º 1
0
 /**
  * 创建Session
  *
  * @return  void
  */
 public function create()
 {
     session_name(Session::$config['name']);
     $this->destroy();
     $cookie_config = Core::config('cookie');
     # 这里对IP+非80端口的需要特殊处理下,经试验,当这种情况下,设置session id的cookie的话会失败
     if (preg_match('#^([0-9]+.[0-9]+.[0-9]+.[0-9]+):[0-9]+$#', $cookie_config['domain'], $m)) {
         # IP:PORT 方式
         $cookie_config['domain'] = $m[1];
     }
     $s_name = session_name();
     if (Session::$config['type'] == 'url') {
         $old_sid = HttpIO::COOKIE($s_name);
     } else {
         $old_sid = HttpIO::COOKIE($s_name);
     }
     if ($old_sid) {
         # 校验Session ID
         if (!Session::check_session_id($old_sid)) {
             # 如果检验的Session ID不合法,则重新生成一个
             session_id(Session::create_session_id());
         }
     } else {
         # 设置Session ID
         session_id(Session::create_session_id());
     }
     # Session ID 通过uri传递
     if (Session::$config['type'] == 'url') {
         @ini_set('session.use_cookies', 0);
         @ini_set('session.use_only_cookies', 0);
     } else {
         session_set_cookie_params($cookie_config['httponly'] ? 0 : Session::$config['expiration'], $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], $cookie_config['httponly']);
     }
     session_start();
 }
Exemplo n.º 2
0
 protected function send_header()
 {
     if (IS_DEBUG) {
         header_remove();
     }
     Core::close_buffers(false);
     HttpIO::set_cache_header(86400);
 }
Exemplo n.º 3
0
 /**
 * 项目管理统一进入接口
 *
 * 此控制器需要路由设置,路由会直接将project和uri传入到控制器的$this->project和$this->uri里
 *
 * 路由如下:
     'project' => array(
 		# 匹配的URL
 		'uri' => '/p/<project>(/<uri>)',
 		# 匹配正则
 		'preg' => array(
 			'project' => '[a-zA-Z0-9_]+',
 *',
 		),
 		# 默认值
 		'defalut' => array(
 			'controller' => 'Admin_P',
 			'action'     => 'default',
 		),
 	),
 */
 public function action_default()
 {
     if (!$this->project) {
         Core::show_404('请指定项目');
     }
     # 切换到指定项目
     Core::set_project($this->project);
     # 执行项目的后台
     HttpIO::execute(ltrim($this->uri, '/'));
 }
Exemplo n.º 4
0
 /**
 * 项目管理统一进入接口
 *
 * 此控制器需要路由设置,路由会直接将project和uri传入到控制器的$this->project和$this->uri里
 *
 * 路由如下:
     'project' => array(
 		# 匹配的URL
 		'uri' => '/p/<project>(/<uri>)',
 		# 匹配正则
 		'preg' => array(
 			'project' => '[a-zA-Z0-9_]+',
 *',
 		),
 		# 默认值
 		'defalut' => array(
 			'controller' => 'Admin__P',
 			'action'     => 'default',
 		),
 	),
 */
 public function action_default()
 {
     if (!$this->project) {
         Core::show_404('请指定项目');
     }
     define('IN_ADMIN', true);
     # 切换到指定项目
     Core::set_project($this->project);
     # 执行项目的后台
     HttpIO::execute(ltrim($this->uri, '/'), true, true, false, 'admin');
 }
Exemplo n.º 5
0
 protected function nodebug()
 {
     $url = Core::url('/opendebugger/logout');
     $str = '';
     if (isset($_GET['forward']) && $_GET['forward']) {
         $forward = HttpIO::GET('forward', HttpIO::PARAM_TYPE_URL);
         $str = '<a href="' . $forward . '">' . $forward . '</a>';
     }
     $view = new View('opendebugger');
     $view->str = $str;
     $view->url = $url;
     $view->open = false;
     $view->render();
 }
Exemplo n.º 6
0
 public function action_index()
 {
     $member = array('message' => '', 'input' => '');
     $view = new View('admin/login');
     $not_login = false;
     $show_captcha = false;
     $db = Database::instance(Model_Admin::DATABASE);
     if ($db->count_records('admin_login_error_log', array('timeline<=' => TIME - 86400))) {
         # 清除24小时前的登录错误信息
         $db->where('timeline<=', TIME - 86400)->delete('admin_login_error_log');
     }
     $error = $db->from('admin_login_error_log')->where('ip', HttpIO::IP)->limit(1)->get()->current();
     if ($error) {
         $error_num = $error['error_num'];
         $config = Core::config('admin/core');
         if ($error_num >= $config['login_error_show_captcha_num'] - 1) {
             $show_captcha = true;
         }
         if ($config['login_max_error_num'] && $error_num >= $config['login_max_error_num']) {
             $not_login = true;
             $this->message = '尝试次数太多,暂不可登录';
         }
     }
     if (!$not_login && HttpIO::METHOD == 'POST') {
         $member = $this->post($_POST, $error_num);
         if ($member) {
             $member->last_login_ip = HttpIO::IP;
             $member->last_login_time = TIME;
             $member->last_login_session_id = $this->session()->id();
             $member->value_increment('login_num');
             $member->update();
             # 开启session
             $this->session()->start();
             $this->session()->set_member($member);
             $url = $_POST['forward'] ? HttpIO::POST('forward', HttpIO::PARAM_TYPE_URL) : Core::url('/');
             $this->redirect($url);
         } else {
             $view->shake = true;
         }
     }
     $login_message = $this->session()->get('admin_member_login_message');
     $view->show_captcha = $show_captcha;
     $view->message = $login_message ? $login_message : $this->message;
     $view->error_input = $this->error_input;
     if ($_POST) {
         $view->username = $_POST['username'];
     }
     $view->render();
 }
Exemplo n.º 7
0
 /**
  * 保存用户note
  */
 public function action_notepad()
 {
     if (null === $this->session()->member()->notepad) {
         $this->session()->member()->notepad = '';
     }
     $this->session()->member()->notepad = HttpIO::POST('data');
     try {
         $s = $this->session()->member()->update();
         if ($s) {
             $this->message('保存成功', 1);
         } else {
             $this->message('操作成功', 0);
         }
     } catch (Exception $e) {
         $this->message('保存数据失败。', -1);
     }
 }
Exemplo n.º 8
0
 /**
  * Create a new session.
  *
  * @return  void
  */
 public function create()
 {
     $cookie_config = Core::config('cookie');
     $_SESSION = array();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($this->session_name);
             break;
         case 'url':
             $sid = HttpIO::GET($this->session_name);
             break;
         default:
             $sid = HttpIO::COOKIE($this->session_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         $sid = Session::create_session_id();
         if (Session::$config['type'] != 'url') {
             # 将session存入cookie
             Core::cookie()->set($this->session_name, $sid, !Session::$config['httponly'] && Session::$config['expiration'] > 0 ? Session::$config['expiration'] : null, $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
         }
     }
     # 添加URL处理自动追加SESSION ID参数
     if (Session::$config['type'] == 'url') {
         Core::add_url_args(Session::$config['name'], $sid);
     }
     # 调试模式设置Session模式,避免开启缓存模式时获取不到Session
     if (IS_DEBUG) {
         $this->driver()->session_mode(true);
     }
     $_SESSION = $this->driver()->get($sid);
     if (IS_DEBUG) {
         $this->driver()->session_mode(false);
     }
     if (!is_array($_SESSION)) {
         $_SESSION = array();
     }
     # 将获取的值序列化MD5值
     Session_Driver_Cache::$OLD_SESSION_MD5 = md5(serialize($_SESSION));
     # 当前session id
     Session_Driver_Cache::$Session_ID = $sid;
 }
Exemplo n.º 9
0
 /**
  * Generates an opening HTML form tag.
  *
  * // Form will submit back to the current page using POST
  * echo Form::open();
  *
  * // Form will submit to 'search' using GET
  * echo Form::open('search', array('method' => 'get'));
  *
  * // When "file" inputs are present, you must include the "enctype"
  * echo Form::open(null, array('enctype' => 'multipart/form-data'));
  *
  * @param   string  form action, defaults to the current request URI
  * @param   array   html attributes
  * @return  string
  * @uses	HttpIO::instance
  * @uses	URL::site
  * @uses	HTML::attributes
  */
 public static function open($action = null, array $attributes = null)
 {
     if ($action === null) {
         // Use the current URI
         $action = HttpIO::current()->uri;
     }
     if (strpos($action, '://') === false) {
         // Make the URI absolute
         $action = Core::url($action);
     }
     // Add the form action to the attributes
     $attributes['action'] = $action;
     // Only accept the default character set
     $attributes['accept-charset'] = Core::$charset;
     if (!isset($attributes['method'])) {
         // Use POST method
         $attributes['method'] = 'post';
     }
     return '<form' . HTML::attributes($attributes) . '>';
 }
Exemplo n.º 10
0
 /**
  * 创建Session
  *
  * @return  void
  */
 public function create()
 {
     session_name(Session::$config['name']);
     $this->destroy();
     $cookie_config = Core::config('cookie');
     # 这里对IP+非80端口的需要特殊处理下,经试验,当这种情况下,设置session id的cookie的话会失败
     if (preg_match('#^([0-9]+.[0-9]+.[0-9]+.[0-9]+):[0-9]+$#', $cookie_config['domain'], $m)) {
         # IP:PORT 方式
         $cookie_config['domain'] = $m[1];
     }
     $s_name = session_name();
     switch (Session::$config['type']) {
         case 'auto':
             $sid = HttpIO::REQUEST($s_name);
             break;
         case 'url':
             $sid = HttpIO::GET($s_name);
             break;
         default:
             $sid = HttpIO::COOKIE($s_name);
             break;
     }
     if (!$sid || !Session::check_session_id($sid)) {
         # 如果检验的Session ID不合法,则重新生成一个
         session_id(Session::create_session_id());
     } else {
         session_id($sid);
     }
     # Session ID 通过uri传递
     if (Session::$config['type'] == 'url') {
         @ini_set('session.use_only_cookies', 0);
     } else {
         session_set_cookie_params(Session::$config['httponly'] ? 0 : (int) Session::$config['expiration'], $cookie_config['path'], $cookie_config['domain'], $cookie_config['secure'], Session::$config['httponly']);
     }
     session_start();
 }
Exemplo n.º 11
0
 /**
  * 页面输出header缓存
  *
  * 0表示不缓存
  *
  * @param int $time 缓存时间,单位秒
  */
 public static function header_cache($time = 86400)
 {
     HttpIO::set_cache_header($time);
 }
Exemplo n.º 12
0
 /**
  * 关闭分块输出
  *
  * !!! 执行此方法后将执行 `exit()`,程序将结束运行
  */
 public function push_end()
 {
     HttpIO::chunk_end();
 }
Exemplo n.º 13
0
 /**
  * 系统调用内容输出函数(请勿自行执行)
  */
 public static function _output_body()
 {
     # 发送header数据
     HttpIO::send_headers();
     if (IS_DEBUG && isset($_REQUEST['debug']) && class_exists('Profiler', true)) {
         # 调试打开时不缓存页面
         HttpIO::set_cache_header(0);
     }
     # 执行注册的关闭方法
     ob_start();
     Core::event_trigger('system.shutdown');
     $output = ob_get_clean();
     # 在页面输出前关闭所有的连接
     Core::close_all_connect();
     # 输出内容
     echo Core::$output, $output;
 }
Exemplo n.º 14
0
 protected function save(ORM_Admin_Member_Data $member)
 {
     try {
         if (!$member->id > 0) {
             # 创建新用户
             if (!$_POST['username']) {
                 throw new Exception('用户名不能空', -1);
             }
             if (!$_POST['new_password']) {
                 throw new Exception('密码不能空', -1);
             }
             if ($_POST['new_password'] != $_POST['new_password_2']) {
                 throw new Exception('两次输入的密码不一致,请重新确认', -1);
             }
             $model_admin = new Model_Admin_Administrator();
             if ($model_admin->get_by_username($_POST['username'])) {
                 throw new Exception('此用户名已存在,请换一个', -1);
             }
         }
         $member->nickname = $_POST['nickname'];
         $setting = HttpIO::POST('setting');
         # 修改权限模式
         if ($this->show_edit_perm) {
             # _group_admin 保留项
             if (isset($setting['_group_admin'])) {
                 unset($setting['_group_admin']);
             }
             # 修改权限
             $this->change_member_perm($member);
         } elseif (!$member->id > 0) {
             $member->perm_setting = null;
         }
         if ($setting) {
             if ($member->setting) {
                 $member->setting = array_merge($member->setting, $setting);
             } else {
                 $member->setting = $setting;
             }
         }
         # 修改用户其它信息
         $this->change_member_other_info($member);
         $tr = $member->orm()->db()->transaction();
         $tr->start();
         try {
             # 保存数据
             if ($member->id > 0) {
                 $is_add = false;
                 # 修改用户
                 $member->update();
             } else {
                 $is_add = true;
                 # 设置用户名
                 $member->username = $_POST['username'];
                 # 密码,在更新数据时会由ORM进行加密处理
                 $member->password = $_POST['new_password'];
                 # 所属项目
                 $member->project = Core::$project;
                 # 锁定=否
                 $member->shielded = 0;
                 # 插入用户数据
                 $member->insert();
             }
             if ($this->show_edit_perm) {
                 # 保存组权限设置
                 $this->save_member_group_perm($member, $is_add);
             }
             $tr->commit();
             $msg = '操作成功';
             $code = 1;
         } catch (Exception $e) {
             $tr->rollback();
             throw $e;
         }
     } catch (Exception $e) {
         $code = $e->getCode();
         $msg = $e->getMessage();
     }
     $this->message($msg, $code);
 }
Exemplo n.º 15
0
 /**
  * Catches errors that are not caught by the error handler, such as E_PARSE.
  *
  * @uses	Kohana::exception_handler
  * @return  void
  */
 public static function shutdown_handler()
 {
     $error = error_get_last();
     if ($error) {
         static $run = null;
         if (true === $run) {
             return;
         }
         $run = true;
         if (((\E_ERROR | \E_PARSE | \E_CORE_ERROR | \E_COMPILE_ERROR | \E_USER_ERROR | \E_RECOVERABLE_ERROR) & $error['type']) !== 0) {
             $run = true;
             static::exception_handler(new \ErrorException($error['message'], $error['type'], 0, $error['file'], $error['line']));
             exit(1);
         }
     }
     if (isset($_REQUEST['debug'])) {
         if (\Core::debug()->profiler('output')->is_open()) {
             \Core::debug()->profiler('output')->start('Views', 'Global Data');
             \Core::debug()->profiler('output')->stop(array('Global Data' => \View::get_global_data()));
         }
         // 输出debug信息
         $file = \Core::find_view('debug/profiler');
         if ($file) {
             if (\IS_CLI) {
                 include $file;
             } else {
                 \ob_start();
                 include $file;
                 $out = \ob_get_clean();
                 if (\stripos(\HttpIO::$body, '</body>') !== false) {
                     \HttpIO::$body = \str_ireplace('</body>', $out . '</body>', \HttpIO::$body);
                 } else {
                     \HttpIO::$body .= $out;
                 }
             }
         }
     }
 }
Exemplo n.º 16
0
 /**
  * 关闭分块输出
  *
  * !!! 执行此方法后将执行 `exit()`,程序将结束运行
  */
 public function output_chunk_end()
 {
     HttpIO::output_chunk_end();
 }
Exemplo n.º 17
0
 /**
  * 检查内部调用HASH是否有效
  *
  * @return boolean
  */
 protected static function check_system_request_allow()
 {
     $hash = $_SERVER['HTTP_X_MYQEE_SYSTEM_HASH'];
     //请求验证HASH
     $time = $_SERVER['HTTP_X_MYQEE_SYSTEM_TIME'];
     //请求验证时间
     $rstr = $_SERVER['HTTP_X_MYQEE_SYSTEM_RSTR'];
     //请求时的随机字符串
     if (!$hash || !$time || !$rstr) {
         return false;
     }
     # 请求时效检查
     if (\microtime(1) - $time > 600) {
         static::log('system request timeout', 'system-request');
         return false;
     }
     # 验证IP
     if ('127.0.0.1' != \HttpIO::IP && \HttpIO::IP != $_SERVER["SERVER_ADDR"]) {
         $allow_ip = static::config('core.system_exec_allow_ip');
         if (\is_array($allow_ip) && $allow_ip) {
             $allow = false;
             foreach ($allow_ip as $ip) {
                 if (\HttpIO::IP == $ip) {
                     $allow = true;
                     break;
                 }
                 if (\strpos($allow_ip, '*')) {
                     # 对IP进行匹配
                     if (\preg_match('#^' . \str_replace('\\*', '[^\\.]+', \preg_quote($allow_ip, '#')) . '$#', \HttpIO::IP)) {
                         $allow = true;
                         break;
                     }
                 }
             }
             if (!$allow) {
                 static::log('system request not allow ip:' . \HttpIO::IP, 'system-request');
                 return false;
             }
         }
     }
     $body = \http_build_query(\HttpIO::POST(null, \HttpIO::PARAM_TYPE_OLDDATA));
     # 系统调用密钥
     $system_exec_pass = static::config('core.system_exec_key');
     if ($system_exec_pass && \strlen($system_exec_pass) >= 10) {
         # 如果有则使用系统调用密钥
         $newhash = \sha1($body . $time . $system_exec_pass . $rstr);
     } else {
         # 没有,则用系统配置和数据库加密
         $newhash = \sha1($body . $time . \serialize(static::config('core')) . \serialize(static::config('database')) . $rstr);
     }
     if ($newhash == $hash) {
         return true;
     } else {
         static::log('system request hash error', 'system-request');
         return false;
     }
 }
Exemplo n.º 18
0
		if ( n==6 || n==0 )
		{
			t = -t;
		}
	}
	setInterval(run,80);
})();
</script>
</td>
</tr>
<tr>
<td height="200" valign="top">
<div id="login_form">
<form method="post" id="myform" autocomplete="off" onsubmit="return check_submit(this);">
    <input type="hidden" name="forward" value="<?php 
echo HttpIO::GET('forward', HttpIO::PARAM_TYPE_URL);
?>
" />
	<div style="position:absolute;margin-left:-60px;">
    	<h1><?php 
echo __('Administrator login');
?>
</h1>
    </div>
    <div class="input_div" style="margin-left:-60px;">
        <!--[if lt IE 6.9]><div class="input_bg_forie6"><div class="inputbg"></div></div><![endif]-->
    	<div style="padding:28px;">
        	<div class="input_bg_text" id="input_default_text_username"><?php 
echo __('Username');
?>
</div>
Exemplo n.º 19
0
 /**
  * 根据控制器设置参数
  *
  * @param Controller $controller
  */
 public static function set_params_controller(Controller $controller)
 {
     HttpIO::$params = get_object_vars($controller);
 }
Exemplo n.º 20
0
 /**
  * 记录慢查询
  *
  * @return boolean
  */
 protected static function save_slow_query()
 {
     if (!Database::$slow_querys) {
         return true;
     }
     // 记录URL信息
     $data = "\n" . str_pad(HttpIO::METHOD, 4, ' ') . ' ' . date('H:i:s', TIME) . ' - ' . str_pad((int) (1000 * (microtime(1) - START_TIME)), 6, ' ', STR_PAD_LEFT) . ' - ' . str_pad(HttpIO::IP, 15) . ' ' . $_SERVER["SCRIPT_URI"] . ('' !== $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : '') . (HttpIO::METHOD == 'POST' ? '   POST:' . json_encode(HttpIO::POST()) : '') . "\n";
     foreach (Database::$slow_querys as $item) {
         $data .= '     ' . date('H:i:s', $item[0]) . ' - ' . str_pad((int) $item[1], 6, ' ', STR_PAD_LEFT) . ' - ' . $item[2] . "\n";
     }
     // 写入LOG
     Core::log($data, 'log', 'slow_query/' . date('Y/m_d', TIME));
 }
Exemplo n.º 21
0
 /**
  * 执行指定URI的控制器
  *
  * @param string $uri
  */
 public static function execute($uri)
 {
     $found = self::find_controller($uri);
     if ($found) {
         require $found['file'];
         $class_name = $found['namespace'] . $found['class'];
         if (class_exists($class_name, false)) {
             $controller = new $class_name();
             Controller::$controllers[] = $controller;
             $rm_controoler = function () use($controller) {
                 foreach (Controller::$controllers as $k => $c) {
                     if ($c === $controller) {
                         unset(Controller::$controllers[$k]);
                     }
                 }
                 Controller::$controllers = array_values(Controller::$controllers);
             };
             $arguments = $found['args'];
             if ($arguments) {
                 $action = current($arguments);
                 if (0 === strlen($action)) {
                     $action = 'default';
                 }
             } else {
                 $action = 'index';
             }
             $action_name = 'action_' . $action;
             if (!method_exists($controller, $action_name)) {
                 if ($action_name != 'action_default' && method_exists($controller, 'action_default')) {
                     $action_name = 'action_default';
                 } elseif (method_exists($controller, '__call')) {
                     $controller->__call($action_name, $arguments);
                     $rm_controoler();
                     return;
                 } else {
                     $rm_controoler();
                     throw new Exception(__('Page Not Found'), 404);
                 }
             } else {
                 array_shift($arguments);
             }
             $ispublicmethod = new ReflectionMethod($controller, $action_name);
             if (!$ispublicmethod->isPublic()) {
                 $rm_controoler();
                 throw new Exception(__('Request Method Not Allowed.'), 405);
             }
             unset($ispublicmethod);
             # 将参数传递给控制器
             $controller->action = $action_name;
             $controller->controller = $found['class'];
             $controller->ids = $found['ids'];
             if (IS_SYSTEM_MODE) {
                 # 系统内部调用参数
                 $controller->arguments = @unserialize(HttpIO::POST('data', HttpIO::PARAM_TYPE_OLDDATA));
             } else {
                 $controller->arguments = $arguments;
             }
             # 前置方法
             if (method_exists($controller, 'before')) {
                 $controller->before();
             }
             # 执行方法
             $count_arguments = count($arguments);
             switch ($count_arguments) {
                 case 0:
                     $controller->{$action_name}();
                     break;
                 case 1:
                     $controller->{$action_name}($arguments[0]);
                     break;
                 case 2:
                     $controller->{$action_name}($arguments[0], $arguments[1]);
                     break;
                 case 3:
                     $controller->{$action_name}($arguments[0], $arguments[1], $arguments[2]);
                     break;
                 case 4:
                     $controller->{$action_name}($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
                     break;
                 default:
                     call_user_func_array(array($controller, $action_name), $arguments);
                     break;
             }
             # 后置方法
             if (method_exists($controller, 'after')) {
                 $controller->after();
             }
             # 移除控制器
             $rm_controoler();
         } else {
             throw new Exception(__('Page Not Found'), 404);
         }
     } else {
         throw new Exception(__('Page Not Found'), 404);
     }
 }
Exemplo n.º 22
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses    self::exception_text
  * @param   Exception $e object exception object
  * @return  bool
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         if (IS_CLI) {
             $str = self::exception_text($e) . "\n" . $e->__toString() . "\n";
             if ($return) {
                 return $str;
             } else {
                 echo $str;
             }
             return true;
         }
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (version_compare(PHP_VERSION, '5.3', '<')) {
                 // Workaround for a bug in ErrorException::getTrace() that exists in
                 // all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if (true !== $return) {
             Core::close_buffers(false);
             if ($e->getCode() === E_PAGE_NOT_FOUND) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 400 && $e->getCode() <= 410) {
                 HttpIO::$status = 404;
             } elseif ($e->getCode() >= 500 && $e->getCode() <= 510) {
                 HttpIO::$status = 404;
             } else {
                 HttpIO::$status = 500;
             }
             @header('Content-Type:text/html;charset=utf-8');
             HttpIO::send_headers();
         }
         ob_start();
         include Core::find_file('views', self::$template);
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return true;
     } catch (Exception $e) {
         ob_get_level() and ob_clean();
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
Exemplo n.º 23
0
 protected static function _class2url(&$class)
 {
     $strpos = strpos($class, '_');
     $prefix = '';
     if ($strpos !== false) {
         $prefix = strtolower(substr($class, 0, $strpos));
     }
     if ($prefix == 'i18n') {
         $dir = 'i18n';
         $class = substr($class, 5);
     } elseif ($prefix == 'model') {
         $dir = 'models';
         $class = substr($class, 6);
     } elseif ($prefix == 'orm') {
         $dir = 'orm';
         # 对ORM做些特殊处理
         # 将ORM_Test_Finder转化成Test_Test.Finder
         # 将ORM_Test_Test2_Finder转化成Test_Test_Test2.Finder
         $class = ltrim(preg_replace('#^orm(?:_(.*))?_([a-z0-9]+)_([a-z0-9]+)$#i', '$1_$2', $class), '_');
     } elseif ($prefix == 'controller') {
         $dir = HttpIO::current_controller()->dir;
         $class = substr($class, 11);
     } elseif ($prefix == 'shell') {
         $dir = 'shell';
         $class = substr($class, 5);
     } else {
         $dir = 'classes';
     }
     return $dir;
 }
Exemplo n.º 24
0
 /**
  * 记录慢查询
  *
  * @return boolean
  */
 protected static function save_slow_query()
 {
     if (!Database::$slow_querys) {
         return true;
     }
     $queries = array();
     foreach (Database::$slow_querys as $item) {
         $queries[] = array('from' => $item[0], 'to' => $item[1], 'use' => $item[1] - $item[0], 'sql' => $item[2]);
     }
     $data = array('url' => $_SERVER["SCRIPT_URI"] . ('' !== $_SERVER["QUERY_STRING"] ? '?' . $_SERVER["QUERY_STRING"] : ''), 'method' => HttpIO::METHOD, 'time' => TIME, 'ip' => HttpIO::IP, 'page_time' => microtime(1) - START_TIME, 'post' => HttpIO::POST(), 'queries' => $queries);
     // 写入LOG
     return Core::log('database.slow_query', $data, LOG_WARNING);
 }
Exemplo n.º 25
0
 /**
  * 开始分开输出
  *
  * @param int $time_limit
  */
 public static function chunk_start($time_limit = 0)
 {
     if (true === HttpIO::$IS_CHUNK_START) {
         return;
     }
     HttpIO::$IS_CHUNK_START = true;
     set_time_limit($time_limit);
     Core::close_buffers(false);
     header('Content-Type: text/plain');
     echo str_pad('', 1024), "\r\n";
     flush();
 }
Exemplo n.º 26
0
 /**
  * Inline exception handler, displays the error message, source of the
  * exception, and the stack trace of the error.
  *
  * @uses	Kohana::exception_text
  * @param   object   exception object
  * @return  boolean
  */
 public static function exception_handler(Exception $e, $return = false)
 {
     try {
         // Get the exception information
         $type = get_class($e);
         $code = $e->getCode();
         $message = $e->getMessage();
         $file = $e->getFile();
         $line = $e->getLine();
         if (isset(self::$php_errors[$code])) {
             $code = self::$php_errors[$code];
         }
         // Create a text version of the exception
         $error = self::exception_text($e);
         if (IS_CLI) {
             // Just display the text of the exception
             echo "\n{$error}\n";
             return TRUE;
         }
         // Get the exception backtrace
         $trace = $e->getTrace();
         if ($e instanceof ErrorException) {
             if (version_compare(PHP_VERSION, '5.3', '<')) {
                 // Workaround for a bug in ErrorException::getTrace() that exists in
                 // all PHP 5.2 versions. @see http://bugs.php.net/bug.php?id=45895
                 for ($i = count($trace) - 1; $i > 0; --$i) {
                     if (isset($trace[$i - 1]['args'])) {
                         // Re-position the args
                         $trace[$i]['args'] = $trace[$i - 1]['args'];
                         // Remove the args
                         unset($trace[$i - 1]['args']);
                     }
                 }
             }
         }
         if ($return !== true) {
             Core::close_buffers(FALSE);
         }
         if ($e->getCode() == 43) {
             HttpIO::$status = 404;
         } else {
             HttpIO::$status = 500;
         }
         HttpIO::send_headers();
         // Start an output buffer
         ob_start();
         // Include the exception HTML
         include Core::find_file('views', self::$template);
         // Display the contents of the output buffer
         $string = ob_get_clean();
         if ($return) {
             return $string;
         } else {
             echo $string;
         }
         return TRUE;
     } catch (Exception $e) {
         // Clean the output buffer if one exists
         ob_get_level() and ob_clean();
         // Display the exception text
         echo self::exception_text($e), "\n";
         exit(1);
     }
 }
Exemplo n.º 27
0
 /**
  * Generates the full URL for a certain page.
  *
  * @param   integer  page number
  * @return  string   page URL
  */
 public function url($page = 1)
 {
     // Clean the page number
     $page = \max(1, (int) $page);
     // No page number in URLs to first page
     if ($page === 1) {
         $page = null;
     }
     switch ($this->config['current_page']['source']) {
         case 'query_string':
             return \Core::url(\HttpIO::$uri) . \HttpIO::query(array($this->config['current_page']['key'] => $page));
         case 'route':
             return \Core::url(Core::route_url(array($this->config['current_page']['key'] => $page))) . \HttpIO::query();
         default:
             $tmparr = array();
             if (\is_numeric($this->config['current_page']['key'])) {
                 for ($i = 0; $i < $this->config['current_page']['key']; $i++) {
                     $tmparr[$i] = (string) \HttpIO::$params['arguments'][$i];
                 }
             }
             $tmparr[$this->config['current_page']['key']] = $page;
             return \Core::url(\HttpIO::uri($tmparr)) . \HttpIO::query();
     }
     return '#';
 }
Exemplo n.º 28
0
 /**
  * Create a URL from the current request. This is a shortcut for:
  *
  * echo URL::site($this->request->uri($params), $protocol);
  *
  * @param   string   route name
  * @param   array    URI parameters
  * @param   mixed    protocol string or boolean, adds protocol and domain
  * @return  string
  * @since   3.0.7
  * @uses    URL::site
  */
 public static function url(array $params = null, $protocol = null)
 {
     // Create a URI with the current route and convert it to a URL
     return Core::url(HttpIO::uri($params), $protocol);
 }