Ejemplo n.º 1
0
 public function action_default()
 {
     $file = $this->file;
     $type = $this->type;
     if (!preg_match('#^([a-zA-Z0-9_/\\-\\.]+)$#', $file) || !preg_match('#(' . $this->allow_suffix . ')$#', $type)) {
         Core::show_404();
     }
     $file = Core::find_file('statics', $file, $type);
     if ($file) {
         if (in_array($type, array('jpg', 'gif', 'png'))) {
             header('Content-Type: image/' . $type);
         } elseif ($type == 'css') {
             header('Content-Type: text/css');
         } elseif ($type == 'js') {
             header('Content-Type: application/x-javascript');
         } elseif ($type == 'swf') {
             header('Content-Type: application/swf');
         }
         header('Cache-Control: max-age=604800');
         header('Last-Modified: ' . date('D, d M Y H:i:s \\G\\M\\T', filemtime($file)));
         header('Expires: ' . date('D, d M Y H:i:s \\G\\M\\T', TIME + 86400 * 30));
         header('Pragma: cache');
         readfile($file);
         exit;
     } else {
         Core::show_404();
     }
 }
Ejemplo n.º 2
0
 public function set_filename($file)
 {
     $realfile = Core::find_file('views', $file);
     if ($realfile) {
         $this->_file = $realfile;
     } else {
         throw new Exception('指定的视图“' . $file . '”不存在');
     }
 }
Ejemplo n.º 3
0
 /**
  * 设置视图文件名
  *
  *      $view = new View();
  *      $view->set_filename('test_view');
  *
  * @param string $file
  * @throws Exception
  * @return View
  */
 public function set_filename($file)
 {
     $realfile = Core::find_file('views', $file);
     if ($realfile) {
         $this->_file = $realfile;
     } else {
         throw new Exception(__('The view :file does not exist', array(':file' => $file)));
     }
     return $this;
 }
Ejemplo n.º 4
0
 public function before()
 {
     // Use customized Markdown parser
     define('MARKDOWN_PARSER_CLASS', 'Docs_Markdown');
     if (!function_exists('Markdown')) {
         // Load Markdown support
         require Core::find_file('markdown', 'markdown');
     }
     $this->view = new View('docs/frame_view');
     ob_start();
 }
Ejemplo n.º 5
0
 public function action_default()
 {
     $file = $this->file;
     $type = $this->type;
     if (!\preg_match('#^([a-zA-Z0-9_/\\-\\.@]+)$#', $file) || !\preg_match('#(' . $this->allow_suffix . ')$#', $type)) {
         \Core::show_404();
     }
     $file = \Core::find_file('statics', $file, $type);
     if ($file) {
         \Core::close_buffers(false);
         // 清理所有已输出的header
         \header_remove();
         if ($type == 'jpg') {
             \header('Content-Type: image/jpeg');
         } elseif (\in_array($type, array('gif', 'png'))) {
             \header('Content-Type: image/' . $type);
         } elseif ($type == 'css') {
             \header('Content-Type: text/css');
         } elseif ($type == 'js') {
             \header('Content-Type: application/x-javascript');
         } elseif ($type == 'swf') {
             \header('Content-Type: application/swf');
         }
         \header('Cache-Control: max-age=604800');
         \header('Expires: ' . \date('D, d M Y H:i:s \\G\\M\\T', \TIME + 86400 * 30));
         \header('Pragma: cache');
         $fun = '\\apache_get_modules';
         if (\function_exists($fun)) {
             if (\in_array('mod_xsendfile', $fun())) {
                 $slen = \strlen(\DIR_SYSTEM);
                 if (\substr($file, 0, $slen) == \DIR_SYSTEM) {
                     // 采用xsendfile发送文件
                     \header('X-Sendfile: ' . \substr($file, $slen));
                     exit;
                 }
             }
         } else {
             \header('Last-Modified: ' . \date('D, d M Y H:i:s \\G\\M\\T', \filemtime($file)));
         }
         \readfile($file);
         exit;
     } else {
         \Core::show_404();
     }
 }
Ejemplo n.º 6
0
 /**
  * 获取IP地址
  *
  * @param string $ip 不传则为访客IP
  * @return string
  */
 public static function get($ip = null)
 {
     $ip or $ip = HttpIO::IP;
     if ($ip == '127.0.0.1' || $ip == '0.0.0.0') {
         return 'Local IP';
     }
     $return = '';
     if (preg_match('#^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$#', $ip)) {
         $iparray = explode('.', $ip);
         if ($iparray[0] == 10 || $iparray[0] == 127 || $iparray[0] == 192 && $iparray[1] == 168 || $iparray[0] == 172 && ($iparray[1] >= 16 && $iparray[1] <= 31)) {
             $return = 'LAN';
         } elseif ($iparray[0] > 255 || $iparray[1] > 255 || $iparray[2] > 255 || $iparray[3] > 255) {
             $return = 'Invalid IP Address';
         } else {
             if (true == ($tinyipfile = Core::find_file('data', 'tinyipdata', 'dat'))) {
                 $return = IpSource::_convertip_tiny($ip, $tinyipfile);
             } elseif (true == ($fullipfile = Core::find_file('data', 'wry', 'dat'))) {
                 $return = IpSource::_convertip_full($ip, $fullipfile);
             }
         }
     }
     return $return;
 }
Ejemplo n.º 7
0
 /**
  * 获取指定项目的指定key的配置
  *
  * @param string $key
  * @param string $project 跨项目读取配置,若本项目内的不需要传
  * @return 返回配置
  */
 protected static function project_config($key, $project)
 {
     $c = explode('.', $key);
     $cname = array_shift($c);
     if (!isset(Core::$config_projects[$project]) || !array_key_exists($cname, Core::$config_projects[$project])) {
         $config = array();
         $thefiles = Core::find_file('config', $cname, null, false, $project);
         if (is_array($thefiles)) {
             if (count($thefiles) > 1) {
                 krsort($thefiles);
                 //逆向排序
             }
             foreach ($thefiles as $thefile) {
                 if ($thefile) {
                     include $thefile;
                 }
             }
         }
         if (!isset(Core::$config_projects[$project][$cname])) {
             Core::$config_projects[$project][$cname] = $config;
         }
     }
     $v = Core::$config_projects[$project][$cname];
     foreach ($c as $i) {
         if (!isset($v[$i])) {
             return null;
         }
         $v = $v[$i];
     }
     return $v;
 }
Ejemplo n.º 8
0
 /**
  * 输出非css,js文件
  *
  * @throws Exception
  */
 protected function output_other_file()
 {
     $file_name = $this->file . ($this->is_min ? '.min' : '');
     $found_file = Core::find_file('assets', $file_name, '.' . $this->suffix);
     if ($found_file) {
         $this->output_by_file($found_file);
     } else {
         $this->get_assets_dir_file();
     }
 }
Ejemplo n.º 9
0
<div><?php 
include Core::find_file('views', '/admin/desktop/default');
?>
</div>

Ejemplo n.º 10
0
 public function file($page)
 {
     $file = Core::find_file('guide', strtolower($page), 'md');
     return $file;
 }
Ejemplo n.º 11
0
 public function before()
 {
     # 记录访问日志
     if (HttpIO::METHOD == 'POST') {
         Database::instance(Model_Admin::DATABASE)->insert(Core::config('admin/log.tablename'), array('uri' => $_SERVER["REQUEST_URI"], 'type' => 'log', 'ip' => HttpIO::IP, 'referer' => $_SERVER["HTTP_REFERER"], 'post' => serialize($_POST), 'admin_id' => $this->session()->member()->id));
     }
     if (!is_file(DIR_DATA . Core::$project . '/install.lock') && ($install_file = Core::find_file('controllers', 'install'))) {
         self::message('为保证系统安全请在data目录下创建安装锁文件:' . Core::$project . '/install.lock<br><br>或删除后台安装文件:' . Core::debug_path($install_file) . '<br><br>设置完毕后方可进入后台', -1);
     }
     # 不允许非超管跨项目访问
     if ($this->session()->member()->project != Core::$project && !$this->session()->member()->is_super_admin) {
         self::message('通道受限,您不具备此项目的操作权限,请联系管理员', -1);
     }
     ob_start();
 }
Ejemplo n.º 12
0
 /**
  * 加载语言包文件
  *
  * @link http://www.php.net/manual/en/function.parse-ini-file.php
  * @return Core_I18n
  */
 public function load()
 {
     $langdata = array();
     $files = Core::find_file('i18n', $this->lang, '.lang');
     if ($files) {
         $ext_len = strlen(EXT);
         if (count($files) > 1) {
             krsort($files);
             //逆向排序
         }
         foreach ($files as $langfile) {
             if (substr($langfile, -$ext_len) === EXT) {
                 $lang = Core_I18n::_include_lang_file($langfile);
             } else {
                 $lang = @parse_ini_file($langfile);
             }
             if (is_array($lang)) {
                 $langdata = array_merge($langdata, $lang);
             }
         }
     }
     Core_I18n::$data[$this->lang] = $langdata;
     return $this;
 }
Ejemplo n.º 13
0
 /**
  * Catches errors that are not caught by the error handler, such as E_PARSE.
  *
  * @uses    self::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;
             self::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_file('views', IS_CLI ? 'debug/profiler_cli' : 'debug/profiler');
         if ($file) {
             ob_start();
             include $file;
             $out = ob_get_clean();
             if (stripos(Core::$output, '</body>') !== false) {
                 Core::$output = str_ireplace('</body>', $out . '</body>', Core::$output);
             } else {
                 Core::$output .= $out;
             }
         }
     }
 }
Ejemplo n.º 14
0
 public function action_step_4()
 {
     # 关闭ob_start
     Core::close_buffers(true);
     $this->step = 4;
     View::set_global('config', self::$config);
     View::set_global('step', $this->step);
     $view = new View('admin/install/header');
     $view->page_title = $this->page_title;
     $view->location = $this->location;
     $view->admin_menu = Core::config('admin/menu/install');
     $view->render(true);
     $view = new View('admin/install/step_4');
     $view->render();
     $view = new View('admin/install/bottom');
     $view->render(true);
     # 将页面内容输出
     flush();
     $sqlfile = Core::find_file('data', 'install', 'sql');
     if ($sqlfile) {
         $sql = file_get_contents($sqlfile);
         $sql = str_replace("\r\n", "\n", $sql);
         $database = Core::config('admin/core.database');
         if (!$database) {
             $database = 'default';
         }
         $db = Database::instance($database);
         $this->run_query($db, $sql);
     }
     if ($this->lock_install()) {
         $this->show_js_message('安装成功。');
     } else {
         $this->show_js_message('安装完毕。');
         $this->show_js_message('<br><font color="red">请注意:</font>系统无法创建安装锁文件,请在data目录“<font color="blue">' . Core::$project . '/</font>”下创建<font color="red">install.lock</font>文件,以防止再次安装,请手动创建此文件。');
     }
     $this->show_js_message('<br>安全起见,请删除本安装文件:' . __FILE__);
     $this->show_js_message('<br /><input type="button" value="进入后台" class="submit" onclick="document.location=\'' . Core::url('/') . '\'" /> 用户名:admin,密码:123456');
     # 强制结束
     exit;
 }
Ejemplo n.º 15
0
 /**
  * render image
  *
  * @param array $config
  * @return image
  */
 public static function render($config = false)
 {
     if (is_array($config)) {
         Captcha::$config = array_merge(Captcha::$config, $config);
     }
     if (empty(Captcha::$response)) {
         Captcha::generate_challenge();
     }
     // Creates Captcha::$image
     Captcha::image_create(Captcha::$config['background']);
     // Add a random gradient
     if (empty(Captcha::$config['background'])) {
         $color1 = imagecolorallocate(Captcha::$image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         $color2 = imagecolorallocate(Captcha::$image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100));
         Captcha::image_gradient($color1, $color2);
     }
     // Add a few random circles
     for ($i = 0, $count = mt_rand(10, Captcha::$config['complexity'] * 3); $i < $count; $i++) {
         $color = imagecolorallocatealpha(Captcha::$image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120));
         $size = mt_rand(5, Captcha::$config['height'] / 3);
         imagefilledellipse(Captcha::$image, mt_rand(0, Captcha::$config['width']), mt_rand(0, Captcha::$config['height']), $size, $size, $color);
     }
     // Calculate character font-size and spacing
     $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen(Captcha::$response);
     $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen(Captcha::$response));
     // Background alphabetic character attributes
     $color_limit = mt_rand(96, 160);
     $chars = 'ABEFGJKLPQRTVY';
     // Draw each captcha character with varying attributes
     for ($i = 0, $strlen = strlen(Captcha::$response); $i < $strlen; $i++) {
         // Use different fonts if available
         $font = Core::find_file('data', Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])], false);
         $angle = mt_rand(-40, 20);
         // Scale the character size on image height
         $size = $default_size / 10 * mt_rand(8, 12);
         if (!function_exists('imageftbbox')) {
             Core::show_500(__('function imageftbbox not exist.'));
         }
         $box = imageftbbox($size, $angle, $font, Captcha::$response[$i]);
         // Calculate character starting coordinates
         $x = $spacing / 4 + $i * $spacing;
         $y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;
         // Draw captcha text character
         // Allocate random color, size and rotation attributes to text
         $color = imagecolorallocate(Captcha::$image, mt_rand(150, 255), mt_rand(200, 255), mt_rand(0, 255));
         // Write text character to image
         imagefttext(Captcha::$image, $size, $angle, $x, $y, $color, $font, Captcha::$response[$i]);
         // Draw "ghost" alphabetic character
         $text_color = imagecolorallocatealpha(Captcha::$image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120));
         $char = substr($chars, mt_rand(0, 14), 1);
         imagettftext(Captcha::$image, $size * 1.4, mt_rand(-45, 45), $x - mt_rand(5, 10), $y + mt_rand(5, 10), $text_color, $font, $char);
     }
     // Output
     return Captcha::image_render();
 }
Ejemplo n.º 16
0
 /**
  * 加载upyun SDK
  */
 protected function load_upyun()
 {
     Core::find_file('sdk/upyun', 'upyun', 'class.php', true);
 }
Ejemplo n.º 17
0
 protected static function get_class_name($key)
 {
     $key = explode('/', $key);
     $profix = array_shift($key);
     if ($profix == 'classes' || $profix == 'models' || $profix == 'controllers' || $profix == 'shell' || $profix == 'orm') {
         static $profixArr = array('classes' => '.class');
         $class = implode('_', $key);
         if (preg_match('#^([a-z0-9_]+)(\\.[a-z]+)?(' . preg_quote(EXT) . ')$#i', $class, $m)) {
             if ($profix == 'controllers' || $profix == 'shell') {
                 $m[1] = str_replace('_', '__', $m[1]);
                 if (!class_exists('Controller_' . $m[1], false)) {
                     Core::find_file($profix, $m[1], null, true);
                 }
                 return 'Controller_' . $m[1];
             } elseif ($profix == 'models') {
                 return 'Model_' . $m[1];
             } elseif ($profix == 'orm') {
                 return 'ORM_' . $m[1] . '_Field';
             } else {
                 return $m[1];
             }
         }
     }
 }
Ejemplo n.º 18
0
        }
        ?>
	</table>
</div>
<?php 
    }
    if (isset($source_id)) {
        ?>
	<pre id="<?php 
        echo $source_id;
        ?>
" class="source collapsed"><code><?php 
        echo $step['source'];
        ?>
</code></pre>
<?php 
    }
    ?>
</li>
<?php 
    unset($args_id, $source_id);
}
?>
</ol>
</div>
</div>
<?php 
include Core::find_file('views', 'debug/environment', '.view.php');
?>
</div>
Ejemplo n.º 19
0
 /**
  * 执行请求,并将输出结果返回
  *
  * @param string $path_info 路径信息
  * @param boolean $print 是否直接输出
  * @param boolean $use_route 是否尝试在路由中搜索
  * @param boolean $is_internal 是否内部调用,默认:否
  * @param string $controller_dir 指定控制器目录,命令行下默认为shell,网站运行为controllers
  * @return string
  */
 public static function execute($uri, $print = true, $use_route = true, $is_internal = false, $controller_dir = null)
 {
     $ob_open = false;
     if (!$print && !IS_CLI) {
         ob_start();
         $ob_open = true;
     }
     $params = false;
     # 路由设置
     if (IS_CLI != true && true === $use_route && Core::$project_config['route'] && ($route = Core::route()->get($uri))) {
         $params = $route;
         # 默认控制器
         if ($params['controller']) {
             $params['controller'] = str_replace('/', '_', $params['controller']);
         } else {
             $params['controller'] = Core::$project_config['default_controller'];
         }
         $dir = 'controllers';
         if (IS_SYSTEM_MODE) {
             $file = '[system]/' . $params['controller'];
         } elseif (IS_CLI) {
             $file = '[shell]/' . $params['controller'];
         } elseif (Core::$is_admin_url) {
             $file = '[admin]/' . $params['controller'];
         } else {
             $file = $params['controller'];
         }
         if ($controller_dir && preg_match('#^[a-zA-Z0-9_]+$#', $controller_dir)) {
             $dir = $controller_dir;
             $file = strtolower(str_replace('__', '/', $file));
         }
         if (!Core::find_file($dir, $file, null, true)) {
             Core::debug()->error('没有找到控制器:' . $params['controller']);
             if ($ob_open) {
                 ob_end_clean();
             }
             return false;
         }
         $is_use_route = true;
         if (Core_Route::$last_route) {
             Core_Route::$current_route = Core_Route::$last_route;
             Core_Route::$route_list[] = Core_Route::$current_route;
         }
     } else {
         $params = HttpIO::find_controller($uri, $controller_dir, $is_internal);
         if (!IS_CLI && null === HttpIO::$uri && HttpIO::METHOD == 'GET' && !$is_internal && isset($params['need_redirect']) && $params['need_redirect'] == true) {
             # 页面结尾自动加/
             $request = explode('?', $_SERVER['REQUEST_URI'], 2);
             Core::close_buffers(false);
             HttpIO::redirect($request[0] . '/' . (isset($request[1]) ? '?' . $request[1] : ''), 301);
             exit;
         }
         $is_use_route = false;
     }
     if (false === $params) {
         Core::debug()->error('没有找到指定页面');
         if ($ob_open) {
             ob_end_clean();
         }
         return false;
     }
     # 初始化$uri
     if (null === HttpIO::$uri) {
         HttpIO::$uri = $uri;
     }
     if (null === HttpIO::$params) {
         HttpIO::$params = $params;
     }
     # 控制器名称
     $controller_name = 'Controller_' . $params['controller'];
     # 参数
     $arguments = isset($params['arguments']) ? $params['arguments'] : array();
     if (IS_SYSTEM_MODE) {
         $params['arguments'] = @unserialize(HttpIO::POST('data', HttpIO::PARAM_TYPE_OLDDATA));
     }
     if ($is_internal) {
         $prefix = 'sub_action';
     } else {
         $prefix = 'action';
     }
     # 方法
     $action_name = $params['action'];
     if (!$action_name) {
         $action_name = $prefix . '_' . Core::$project_config['default_action'];
     } else {
         $action_name = $prefix . '_' . $action_name;
     }
     # 如果不存在控制器类则抛404页面
     if (!class_exists($controller_name, false)) {
         Core::debug()->error('控制器:' . $controller_name . '不存在。');
         if ($ob_open) {
             ob_end_clean();
         }
         return false;
     }
     # 构造新控制器
     if (!isset(HttpIO::$controlers[$controller_name])) {
         HttpIO::$controlers[$controller_name] = new $controller_name();
     }
     $old_current_controller = HttpIO::$current_controller;
     HttpIO::$current_controller = $controller = HttpIO::$controlers[$controller_name];
     # 存控制器的数据
     static $obj_params = array();
     if (!isset($obj_params[$controller_name]) || !is_array($obj_params[$controller_name])) {
         $obj_params[$controller_name] = array();
     }
     if (method_exists($controller, '_callback_get_vars')) {
         # 将控制器参数记录下来
         $obj_params[$controller_name][] = $controller->_callback_get_vars();
     }
     if (method_exists($controller, '_callback_set_vars')) {
         # 将参数传递给控制器
         $controller->_callback_set_vars($params);
     }
     if (!$is_internal && !method_exists($controller, $action_name)) {
         $action_name = $prefix . '_default';
         if (!method_exists($controller, $action_name)) {
             $action_name = '__call';
             $arguments = array($action_name, $arguments);
             if (!method_exists($controller, $action_name)) {
                 Core::debug()->error('控制器:' . $controller_name . '方法:' . $action_name . '不存在。');
                 if ($ob_open) {
                     ob_end_clean();
                 }
                 return false;
             }
         }
     }
     # Method is Public?
     $ispublicmethod = new ReflectionMethod($controller, $action_name);
     if (!$ispublicmethod->isPublic()) {
         Core::debug()->error('控制器:' . $controller_name . '方法:' . $action_name . '受保护。');
         if ($ob_open) {
             ob_end_clean();
         }
         return false;
     }
     if (!$is_internal) {
         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:
             # Resort to using call_user_func_array for many segments
             call_user_func_array(array($controller, $action_name), $arguments);
             break;
     }
     if (!$is_internal) {
         if (method_exists($controller, 'after')) {
             $controller->after();
         }
     }
     # 将原来的数据重新设置回去
     if (method_exists($controller, '_callback_set_vars')) {
         if (is_array($obj_params[$controller_name])) {
             $tmp_params = array_pop($obj_params[$controller_name]);
             $controller->_callback_set_vars($tmp_params);
         }
     }
     HttpIO::$current_controller = $old_current_controller;
     unset($old_current_controller);
     unset($controller);
     if (!count($obj_params[$controller_name])) {
         unset(HttpIO::$controlers[$controller_name]);
     }
     if (true == $is_use_route) {
         # 路由列队
         array_pop(Core_Route::$route_list);
         if (Core_Route::$route_list) {
             end(Core_Route::$route_list);
             $key = key(Core_Route::$route_list);
             Core_Route::$last_route = Core_Route::$current_route = Core_Route::$route_list[$key];
         } else {
             Core_Route::$route_list = null;
         }
     }
     if (!$print && !IS_CLI) {
         $output = ob_get_clean();
         return $output;
     } else {
         if ($ob_open) {
             ob_end_clean();
         }
         return '';
     }
 }