├── doitphp ├── views │ ├── source │ │ ├── aispec.ttf │ │ ├── watermark.bmp │ │ ├── watermark.gif │ │ ├── watermark.jpg │ │ ├── watermark.png │ │ └── index.html │ ├── errors │ │ ├── error404.html │ │ ├── index.html │ │ ├── exception.php │ │ └── message.php │ └── index.html ├── index.html ├── core │ ├── index.html │ ├── DoitException.php │ ├── Log.php │ ├── Extension.php │ ├── WidgetTemplate.php │ ├── Configure.php │ ├── Response.php │ ├── Widget.php │ ├── AutoLoad.php │ └── Router.php ├── library │ ├── index.html │ ├── cache │ │ ├── index.html │ │ ├── File.php │ │ ├── Redis.php │ │ ├── Memcached.php │ │ └── Memcache.php │ ├── FileDownload.php │ ├── Language.php │ ├── Csv.php │ ├── Tree.php │ ├── Benchmark.php │ ├── FileUpload.php │ ├── Cookie.php │ ├── Calendar.php │ ├── Validation.php │ ├── Session.php │ ├── Client.php │ ├── Excel.php │ ├── Security.php │ ├── Curl.php │ ├── Ftp.php │ ├── MongoDb.php │ ├── Pagination.php │ ├── Encrypt.php │ └── File.php └── DoitPHP.php ├── robots.txt ├── cache ├── index.html ├── data │ └── index.html ├── temp │ └── index.html ├── htmls │ └── index.html ├── models │ └── index.html └── views │ └── index.html ├── logs └── index.html ├── assets ├── css │ └── index.html ├── index.html ├── js │ └── index.html └── images │ └── index.html ├── application ├── index.html ├── config │ ├── index.html │ └── application.php ├── language │ └── index.html ├── library │ └── index.html ├── models │ └── index.html ├── views │ ├── index.html │ ├── errors │ │ └── index.html │ ├── layouts │ │ └── index.html │ └── widgets │ │ └── index.html ├── widgets │ └── index.html ├── controllers │ ├── index.html │ └── IndexController.php └── extensions │ └── index.html ├── readme.txt ├── index.php ├── README.md └── license.txt /doitphp/views/source/aispec.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doitphp/doitphp_standard/HEAD/doitphp/views/source/aispec.ttf -------------------------------------------------------------------------------- /doitphp/views/source/watermark.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doitphp/doitphp_standard/HEAD/doitphp/views/source/watermark.bmp -------------------------------------------------------------------------------- /doitphp/views/source/watermark.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doitphp/doitphp_standard/HEAD/doitphp/views/source/watermark.gif -------------------------------------------------------------------------------- /doitphp/views/source/watermark.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doitphp/doitphp_standard/HEAD/doitphp/views/source/watermark.jpg -------------------------------------------------------------------------------- /doitphp/views/source/watermark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/doitphp/doitphp_standard/HEAD/doitphp/views/source/watermark.png -------------------------------------------------------------------------------- /robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Crawl-delay: 10 3 | Disallow: /doitphp/ 4 | Disallow: /application/ 5 | Disallow: /cache/ 6 | Disallow: /logs/ -------------------------------------------------------------------------------- /cache/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /logs/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /assets/css/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /assets/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /assets/js/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /cache/data/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /cache/temp/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /assets/images/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /cache/htmls/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /cache/models/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /cache/views/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/config/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/language/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/library/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/models/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/views/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/widgets/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/controllers/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/extensions/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/views/errors/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/views/layouts/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/views/widgets/index.html: -------------------------------------------------------------------------------- 1 | 403 Forbidden

Forbidden

Directory access is forbidden.

-------------------------------------------------------------------------------- /application/controllers/IndexController.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 404 Not Found 访问的网页不存在 6 | 11 | 12 | 13 | 14 |

404 Error

15 |

没有找到您要访问的页面

16 |

The requested URL was not found on this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/core/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/library/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/views/errors/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /doitphp/views/source/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (C) 2009-2012 www.doitphp.com All rights reserved. 7 | * @version $Id: index.php 2.5 2016-12-27 01:14:18Z tommy $ 8 | * @package application 9 | * @since 1.0 10 | */ 11 | 12 | define('IN_DOIT', true); 13 | 14 | /** 15 | * 定义项目所在路径(根目录):APP_ROOT 16 | */ 17 | define('APP_ROOT', dirname(__FILE__)); 18 | 19 | /** 20 | * 加载DoitPHP框架的初始化文件,如果必要可以修改文件路径 21 | */ 22 | require_once APP_ROOT . '/doitphp/DoitPHP.php'; 23 | 24 | $configFile = APP_ROOT . '/application/config/application.php'; 25 | 26 | /** 27 | * 启动应用程序(网站)进程 28 | */ 29 | Doit::run($configFile); -------------------------------------------------------------------------------- /doitphp/library/cache/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 403 Forbidden 6 | 11 | 12 | 13 | 14 |

Forbidden

15 |

403 Error

16 |

Your client does not have permission to get this directory from this server.

17 | 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DoitPHP 标准版 V2.6 2 | ============================= 3 | 感谢您选用DoitPHP, 这是一个简单易用,运行高效,易于扩展的轻量级PHP框架 4 | 5 | [![Build Status](http://www.doitphp.com/assets/images/doitphp_friendlink_logo.jpg)](http://www.doitphp.com) 6 | 7 | 环境要求 8 | ------------ 9 | 基本要求:web服务器运行的PHP版为5.1.0或更高,支持SPL(PHP标准库)。 10 | 11 | 12 | 安装 13 | ------------ 14 | 1.将doitphp的压缩包解压后,在解压后的文件内你会看到以下文件和目录 15 | 16 | index.php 项目入口文件 17 | doitphp/ DoitPHP框架的源文件 18 | application/ 项目应用目录 19 | assets/ 静态文件存放目录 20 | cache/ 缓存文件存放目录 21 | logs/ 运行日志文件存放目录 22 | LICENSE doitphp的许可证 23 | 24 | 25 | 2.如果想更快速的开发项目代码,请另行下载DoitPHP Tools v2.6来辅助开发。 26 | 27 | 官方网址: 28 | ------------ 29 | 如果想获取更多关于DoitPHP的信息,或查看使用文档请访问官方网址。 30 | 31 | http://www.doitphp.com/ -------------------------------------------------------------------------------- /doitphp/views/errors/exception.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Exception 6 | 15 | 16 | 17 | 18 |

Exception

19 | 20 |

Description

21 |

22 | 23 |

24 | 25 |

Source File

26 |

27 | 28 |

29 | 30 |

Stack Trace

31 |
32 |
33 | 
34 | 
35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /doitphp/views/errors/message.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 提示信息 6 | 11 | 12 | 13 | 14 |
15 |
提示信息:
16 |
17 |
18 | 19 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | The DoitPHP is free software. It is released under the terms of 2 | the following BSD License. 3 | 4 | Copyright © 2010-2011 by Tommy software studio LLC (http://www.doitphp.com) 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Yii Software LLC nor the names of its 17 | contributors may be used to endorse or promote products derived 18 | from this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. 32 | -------------------------------------------------------------------------------- /doitphp/library/FileDownload.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: FileDownload.php 2.0 2012-12-23 20:24:43Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | class FileDownload { 15 | 16 | /** 17 | * http下载文件 18 | * 19 | * Reads a file and send a header to force download it. 20 | * 21 | * @access public 22 | * 23 | * @param string $filePath 文件路径 24 | * @param string $rename 文件重命名后的名称 25 | * 26 | * @return void 27 | */ 28 | public static function getData($filePath, $rename = null) { 29 | 30 | //参数分析 31 | if(!$filePath) { 32 | return false; 33 | } 34 | 35 | if(headers_sent()) { 36 | return false; 37 | } 38 | 39 | //分析文件是否存在 40 | if (!is_file($filePath)) { 41 | Response::showMsg('Error 404:The file not found!'); 42 | } 43 | 44 | //分析文件名 45 | $fileName = (!$rename) ? basename($filePath) : $rename; 46 | 47 | header('Content-Description: File Transfer'); 48 | header('Content-Type: application/octet-stream'); 49 | header("Content-Disposition: attachment; filename=\"{$fileName}\""); 50 | header('Expires: 0'); 51 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 52 | header('Pragma: public'); 53 | header('Content-Length: ' . filesize($filePath)); 54 | ob_clean(); 55 | flush(); 56 | 57 | readfile($filePath); 58 | 59 | exit(); 60 | } 61 | } -------------------------------------------------------------------------------- /doitphp/core/DoitException.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: DoitException.php 1.0 2012-12-04 10:56:13Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | class DoitException extends Exception { 15 | 16 | /** 17 | * 异常输出 18 | * 19 | * 注:当调试模式关闭时,异常提示信息将会写入日志 20 | * 21 | * @access public 22 | * @return string 23 | */ 24 | public function __toString() { 25 | 26 | //分析获取异常信息 27 | $code = $this->getCode(); 28 | $exceptionMsg = $this->getMessage(); 29 | $message = ($code ? "Error Code:{$code}
" : '') . ($exceptionMsg ? "Error Message:{$exceptionMsg}" : ''); 30 | 31 | $line = $this->getLine(); 32 | $sourceFile = $this->getFile() . (!$line ? '' : "({$line})"); 33 | 34 | if (DOIT_DEBUG === true) { 35 | $traceString = ''; 36 | $traces = $this->getTrace(); 37 | foreach ($traces as $key=>$trace) { 38 | //代码跟踪级别限制 39 | if ($key > 2) { 40 | break; 41 | } 42 | $traceString .= "#{$key} {$trace['file']}({$trace['line']})
"; 43 | } 44 | } 45 | 46 | //定义错误级别(当错误级别为Normal时,则不显示代码跟踪信息) 47 | $level = 'Error'; 48 | 49 | ob_start(); 50 | //加载,分析,并输出excepiton文件内容 51 | include_once DOIT_ROOT . '/views/errors/exception.php'; 52 | 53 | $exceptionMessage = ob_get_clean(); 54 | 55 | if (DOIT_DEBUG === false) { 56 | $exceptionMsg = str_replace('
', ' ', $exceptionMsg); 57 | $logContent = ((!$code) ? "" : "Error Code:{$code} ") . "Error Message:{$exceptionMsg} File:{$sourceFile}"; 58 | //写入程序运行日志 59 | Log::write($logContent); 60 | } 61 | 62 | return $exceptionMessage; 63 | } 64 | 65 | } -------------------------------------------------------------------------------- /doitphp/library/Language.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Language.php 2.0 2012-12-22 19:41:54Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Language { 19 | 20 | /** 21 | * 语言包的目录 22 | * 23 | * @var string 24 | */ 25 | protected $_langPath = null; 26 | 27 | /** 28 | * 构造方法 29 | * 30 | * 用于初始化运行环境,或对基本变量进行赋值 31 | * 32 | * @access public 33 | * @return boolean 34 | */ 35 | public function __construct() { 36 | 37 | //获取默认的语言包目录的路径 38 | $this->_langPath = BASE_PATH . '/language'; 39 | 40 | return true; 41 | } 42 | 43 | /** 44 | * 获取语言包的基本路径 45 | * 46 | * @access public 47 | * @return string 48 | */ 49 | public static function getLanguagePath() { 50 | 51 | return $this->_langPath; 52 | } 53 | 54 | /** 55 | * 设置语言包的基本路径 56 | * 57 | * @access public 58 | * 59 | * @param string $path 语言包的基本路径 60 | * 61 | * @return boolean 62 | */ 63 | public function setLanguagePath($path) { 64 | 65 | //参数分析 66 | if (!$path) { 67 | return false; 68 | } 69 | 70 | $this->_langPath = $path; 71 | 72 | return $this; 73 | } 74 | 75 | /** 76 | * 加载语言数据文件 77 | * 78 | * @access public 79 | * 80 | * @param string $langName 语言名称 81 | * 82 | * @return array 83 | */ 84 | public function loadLanguage($langName = 'zh_cn') { 85 | 86 | //参数分析 87 | if (!$langName) { 88 | return false; 89 | } 90 | 91 | $langFilePath = $this->_langPath . DS . $langName . '.php'; 92 | 93 | static $_langArray = array(); 94 | if (!isset($_langArray[$langName])) { 95 | //分析语言文件是否存在 96 | if (!is_file($langFilePath)) { 97 | Response::halt("The Langueage File: {$langFilePath} is not found!"); 98 | } 99 | 100 | //获取语言包内容 101 | $lang = array(); 102 | include_once $langFilePath; 103 | $_langArray[$langName] = $lang; 104 | } 105 | 106 | return $_langArray[$langName]; 107 | } 108 | 109 | /** 110 | * 获取语言包某键值的内容 111 | * 112 | * @access public 113 | * 114 | * @param string $key 键值 115 | * @param string $langName 语言名称 116 | * 117 | * @return mixed 118 | */ 119 | public function get($key, $langName = 'zh_cn') { 120 | 121 | //参数分析 122 | if (!$key) { 123 | return null; 124 | } 125 | 126 | $langArray = $this->loadLanguage($langName); 127 | 128 | return isset($langArray[$key]) ? $langArray[$key] : null; 129 | } 130 | 131 | } -------------------------------------------------------------------------------- /application/config/application.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) Copyright (c) 2012 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: application.php 1.0 2013-01-11 21:53:32Z tommy $ 10 | * @package config 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | /** 19 | * 设置时区,默认时区为东八区(中国)时区(Asia/ShangHai)。 20 | */ 21 | //$config['application']['defaultTimeZone'] = 'Asia/ShangHai'; 22 | 23 | /** 24 | * 设置URL网址的格式。 25 | * Configure::GET_FORMAT为:index.php?router=controller/action¶ms=value; 26 | * Configure::PATH_FORMAT为:index.php/controller/action/params/value。 27 | * 默认为:Configure::PATH_FORMAT 28 | */ 29 | //$config['application']['urlFormat'] = Configure::GET_FORMAT; 30 | 31 | /** 32 | * 设置是否开启URL路由网址重写(Rewrite)功能。true:开启;false:关闭。默认:关闭。 33 | */ 34 | //$config['application']['rewrite'] = true; 35 | 36 | /** 37 | * 设置是否开启Debug调用功能。true:开启;false:关闭。默认:关闭。 38 | */ 39 | //$config['application']['debug'] = true; 40 | 41 | /** 42 | * 设置是否开启日志记录功能。true:开启;false:关闭。默认:关闭。 43 | */ 44 | //$config['application']['log'] = true; 45 | 46 | /** 47 | * 自定义项目(application)目录路径的设置。注:结尾无需"/",建议用绝对路径。 48 | */ 49 | //$config['application']['basePath'] = APP_ROOT . '/application'; 50 | 51 | /** 52 | * 自定义缓存(cache)目录路径的设置。注:结尾无需"/",建议用绝对路径。 53 | */ 54 | //$config['application']['cachePath'] = APP_ROOT . '/cache'; 55 | 56 | /** 57 | * 自定义日志(log)目录路径的设置。注:结尾无需"/",建议用绝对路径。 58 | */ 59 | //$config['application']['logPath'] = APP_ROOT . '/logs'; 60 | 61 | /** 62 | * 设置视图文件的格式。Configure::VIEW_EXT_HTML为html;Configure::VIEW_EXT_PHP为php。默认为:php。 63 | */ 64 | //$config['application']['viewExt'] = Configure::VIEW_EXT_HTML; 65 | 66 | /** 67 | * 设置数据库(关系型数据库)的连接参数。 注:仅支持PDO连接。 68 | * 69 | * @example 70 | * 例一:单数据库 71 | * $config['db'] = array( 72 | * 'dsn' => 'mysql:host=localhost;dbname=doitphp', 73 | * 'username' => 'root', 74 | * 'password' => '123qwe', 75 | * 'prefix' => 'do_', 76 | * 'charset' => 'utf8', 77 | * ); 78 | * 79 | * 例二:数据库主从分离 80 | * $config['db'] = array( 81 | * 'master' => array( 82 | * 'dsn' => '...', 83 | * 'username' => '...', 84 | * 'password' => '...', 85 | * ), 86 | * 'slave' => array( 87 | * 'dsn' => '...', 88 | * 'username' => '...', 89 | * 'password' => '...', 90 | * ), 91 | * 'prefix' => 'do_', 92 | * 'charset' => 'utf8', 93 | * ); 94 | * 注:prefix为数据表前缀。当没有前缀时,此参数可以省略。charset为数库编码。默认值为:utf8。如编码为utf8时,此参数也可以省略。 95 | */ 96 | /*$config['db'] = array( 97 | 'dsn' => 'mysql:host=localhost;dbname=yourDbname', 98 | 'username' => 'yourUsername', 99 | 'password' => 'yourPassword', 100 | 'prefix' => '', 101 | 'charset' => 'utf8', 102 | );*/ 103 | 104 | 105 | /** 106 | * 设置Cookie生存周期 107 | */ 108 | //$config['cookie']['expire'] = 3600; 109 | 110 | /** 111 | * 设置Session生存周期 112 | */ 113 | //$config['session']['expire'] = 3600; -------------------------------------------------------------------------------- /doitphp/library/Csv.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright (c) 2010 Tommycode Studio 9 | * @link http://www.doitphp.com 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Csv.php 2.0 2012-12-23 15:56:01Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class Csv { 21 | 22 | /** 23 | * 将CSV文件转化为数组 24 | * 25 | * @access public 26 | * 27 | * @param string $fileName csv文件名(路径) 28 | * @param string $delimiter 单元分割符(逗号或制表符) 29 | * 30 | * @return array 31 | */ 32 | public static function readCsv($fileName, $delimiter = ",") { 33 | 34 | //参数分析 35 | if (!$fileName) { 36 | return false; 37 | } 38 | 39 | setlocale(LC_ALL, 'en_US.UTF-8'); 40 | 41 | //读取csv文件内容 42 | $handle = fopen($fileName, 'r'); 43 | 44 | $outputArray = array(); 45 | $row = 0; 46 | while ($data = fgetcsv($handle, 1000, $delimiter)) { 47 | $num = count($data); 48 | for ($i = 0; $i < $num; $i ++) { 49 | $outputArray[$row][$i] = $data[$i]; 50 | } 51 | $row++; 52 | } 53 | fclose($handle); 54 | 55 | return $outputArray; 56 | } 57 | 58 | /** 59 | * 生成csv文件 60 | * 61 | * @access public 62 | * 63 | * @param string $fileName 所要生成的文件名 64 | * @param array $data csv数据内容, 注:本参数为二维数组 65 | * @param boolean $isDownLoad 生成Csv文件的方式是否为浏览器下载(true:是/false:不是) 66 | * 67 | * @return mixed 68 | */ 69 | public static function createCsv($fileName, $data, $isDownLoad = true) { 70 | 71 | //参数分析 72 | if (!$fileName || !$data || !is_array($data)) { 73 | return false; 74 | } 75 | if (stripos($fileName, '.csv') === false) { 76 | $fileName .= '.csv'; 77 | } 78 | 79 | //分析$data内容 80 | $content = ''; 81 | foreach ($data as $lines) { 82 | if ($lines && is_array($lines)) { 83 | foreach ($lines as $key=>$value) { 84 | if (is_string($value)) { 85 | $lines[$key] = '"' . $value . '"'; 86 | } 87 | } 88 | $content .= implode(",", $lines) . "\n"; 89 | } 90 | } 91 | 92 | //当文件生成方式不为浏览器下载时 93 | if ($isDownLoad === false) { 94 | //分析文件所在的目录 95 | $dirPath = dirname($fileName); 96 | if (!is_dir($dirPath)) { 97 | mkdir($dirPath, 0777, true); 98 | } 99 | 100 | return file_put_contents($fileName, $content, LOCK_EX); 101 | } 102 | 103 | header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 104 | header("Expires:0"); 105 | header("Pragma:public"); 106 | header("Cache-Control: public"); 107 | header("Content-type:text/csv"); 108 | header("Content-Disposition:attachment;filename=" . $fileName); 109 | 110 | echo $content; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /doitphp/library/Tree.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Tree.php 3.0 2016-12-22 19:01:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Tree { 19 | 20 | /** 21 | * 分类的父ID的键名(key) 22 | * 23 | * @var integer 24 | */ 25 | private $_parentId = 'pid'; 26 | 27 | /** 28 | * 分类的ID(key) 29 | * 30 | * @var integer 31 | */ 32 | private $_id = 'id'; 33 | 34 | /** 35 | * 分类名 36 | * 37 | * @var string 38 | */ 39 | private $_name = 'name'; 40 | 41 | /** 42 | * 子分类名 43 | * 44 | * @var string 45 | */ 46 | private $_child = 'child'; 47 | 48 | /** 49 | * 设置分类树数组的Key,即节点数组的字段名(初始化配置) 50 | * 51 | * @access public 52 | * 53 | * @param string $nodeId 分类树数组key的节点Id 54 | * @param string $nodeName 分类树数组key的节点名称 55 | * @param string $nodeParentId 分类树数组key的分节点Id 56 | * @param string $nodeChildName 分类树数组key的子节点Id 57 | * 58 | * @return $this 59 | */ 60 | public function setKeyName($nodeId = 'id', $nodeName = 'name', $nodeParentId = 'pid', $nodeChildName = 'child') { 61 | 62 | $this->_id = (!$nodeId) ? $this->_id : $nodeId; 63 | $this->_name = (!$nodeName) ? $this->_name : $nodeName; 64 | $this->_parentId = (!$nodeParentId) ? $this->_parentId : $nodeParentId; 65 | $this->_child = (!$nodeChildName) ? $this->_child : $nodeChildName; 66 | 67 | return $this; 68 | } 69 | 70 | 71 | /** 72 | * 获取无限分类树 73 | * 74 | * @access public 75 | * 76 | * @param array $data 待处理的数组 77 | * @param integer $parentId 父ID 78 | * 79 | * @return array 80 | */ 81 | public function getTree($data, $parentId = 0) { 82 | 83 | //parse params 84 | if (!$data || !is_array($data)) { 85 | return array(); 86 | } 87 | 88 | //get child tree array 89 | $childArray = $this->_getChildren($data, $parentId); 90 | //当子分类无元素时,结果递归 91 | if(!$childArray) { 92 | return array(); 93 | } 94 | 95 | $treeArray = array(); 96 | foreach ($childArray as $lines) { 97 | $treeArray[$lines[$this->_id]] = array( 98 | $this->_id => $lines[$this->_id], 99 | $this->_name => $lines[$this->_name], 100 | $this->_child => $this->getTree($data, $lines[$this->_id]), 101 | ); 102 | } 103 | 104 | return $treeArray; 105 | } 106 | 107 | /** 108 | * 无限级分类树-获取子类 109 | * 110 | * @access public 111 | * 112 | * @param array $data 树的数组 113 | * @param integer $id 父类ID 114 | * 115 | * @return array 116 | */ 117 | protected function _getChildren($data, $id) { 118 | 119 | $childrenArray = array(); 120 | foreach ($data as $value) { 121 | if ($value[$this->_parentId] == $id) { 122 | $childrenArray[] = $value; 123 | } 124 | } 125 | 126 | return $childrenArray; 127 | } 128 | } -------------------------------------------------------------------------------- /doitphp/library/Benchmark.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Benchmark.php 2.0 2012-12-31 11:12:25Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | class Benchmark { 17 | 18 | /** 19 | * 标记时间数据存贮容器 20 | * 21 | * @var array 22 | */ 23 | protected static $_timeArray = array(); 24 | 25 | /** 26 | * 标记内存占用数据存贮容器 27 | * 28 | * @var array 29 | */ 30 | protected static $_memoArray = array(); 31 | 32 | /** 33 | * 标记当前点的基准数据 34 | * 35 | * @access public 36 | * 37 | * @param string $name 标记名 38 | * 39 | * @return boolean 40 | */ 41 | public static function mark($name) { 42 | 43 | //参数分析 44 | if (!$name) { 45 | return false; 46 | } 47 | 48 | //获取当前时间及内存占用 49 | self::$_timeArray[$name] = microtime(true); 50 | self::$_memoArray[$name] = self::_getMemUsage(); 51 | 52 | return true; 53 | } 54 | 55 | /** 56 | * 获取测试代码片段的总的内存占用及执行时间 57 | * 58 | * @access public 59 | * 60 | * @param string $startName 开始标记名 61 | * @param string $endName 结束标记名 62 | * 63 | * @return array 64 | */ 65 | public static function get($startName, $endName = null) { 66 | 67 | //参数分析 68 | if (!$startName) { 69 | return false; 70 | } 71 | 72 | //判断标记点时否存在 73 | if (!isset(self::$_timeArray[$startName])) { 74 | return false; 75 | } 76 | if ($endName && !isset(self::$_timeArray[$endName])) { 77 | return false; 78 | } 79 | 80 | $startTime = self::$_timeArray[$startName]; 81 | $startMemo = self::$_memoArray[$startName]; 82 | 83 | $endTime = (!$endName) ? microtime(true) : self::$_timeArray[$endName]; 84 | $endMemo = (!$endName) ? self::_getMemUsage() : self::$_memoArray[$endName]; 85 | 86 | $time = sprintf('%6fs',$endTime - $startTime); 87 | $memory = $endMemo = $startMemo; 88 | 89 | return array('time'=>$time, 'memory'=>$memory); 90 | } 91 | 92 | /** 93 | * 获取当前内存的占用数据 94 | * 95 | * @access protected 96 | * @return string 97 | */ 98 | protected static function _getMemUsage() { 99 | 100 | return memory_get_usage(); 101 | } 102 | 103 | /** 104 | * 获取每个标记点的内存及执行时间 105 | * 106 | * @access public 107 | * @return array 108 | */ 109 | public static function getAll() { 110 | 111 | $data = array(); 112 | foreach (self::$_timeArray as $key =>$value) { 113 | $data[$key] = array('time'=>$value, 'memory'=>self::$_memoArray[$key]); 114 | } 115 | 116 | return $data; 117 | } 118 | 119 | /** 120 | * 获取每个标记点的时间 121 | * 122 | * @access public 123 | * @return array 124 | */ 125 | public static function getTime() { 126 | 127 | return self::$_timeArray; 128 | } 129 | 130 | /** 131 | * 获取每个标记点的内存占用 132 | * 133 | * @access public 134 | * @return array 135 | */ 136 | public static function getMemory() { 137 | 138 | return self::$_memoArray; 139 | } 140 | } -------------------------------------------------------------------------------- /doitphp/library/FileUpload.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: FileUpload.php 2.0 2012-12-23 22:30:38Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | class FileUpload { 15 | 16 | /** 17 | * 文件限制大小(默认:8M) 18 | * 19 | * @var integer 20 | */ 21 | protected $_limitSize = 8388608; 22 | 23 | /** 24 | * 上传的文件信息 25 | * 26 | * @var string 27 | */ 28 | protected $_files = array(); 29 | 30 | /** 31 | * 文件的限制类型 32 | * 33 | * @var string 34 | */ 35 | protected $_limitType = array(); 36 | 37 | /** 38 | * 返回的错误信息 39 | * 40 | * @var string 41 | */ 42 | protected $_errorMsg = null; 43 | 44 | /** 45 | * 文件上传处理 46 | * 47 | * @access public 48 | * 49 | * @param array $files $_FILE的参数名 50 | * @param string $destFile 上传后的文件路径 51 | * 52 | * @return boolean 53 | */ 54 | public function moveFile($files, $destFile) { 55 | 56 | //参数分析 57 | if (!$files || !$destFile) { 58 | return false; 59 | } 60 | 61 | $this->_files = $files; 62 | 63 | //分析文件大小 64 | if (!$this->_parseFileSize()) { 65 | return false; 66 | } 67 | 68 | //分析文件类型 69 | if (!$this->_parseFileType()) { 70 | return false; 71 | } 72 | 73 | if (!move_uploaded_file($this->_files['tmp_name'], $destFile)) { 74 | $this->_errorMsg = '文件上传失败!请重新上传'; 75 | return false; 76 | } 77 | 78 | return true; 79 | } 80 | 81 | /** 82 | * 设置上传文件的限制格式,即:文件后缀。 83 | * 84 | * @access public 85 | * 86 | * @param array $type 所限制上传文件后缀。注:本参数为数组 87 | * 88 | * @return object 89 | */ 90 | public function setLimitType($type) { 91 | 92 | //参数分析 93 | if ($type && is_array($type)) { 94 | $this->_limitType = $type; 95 | } 96 | 97 | return $this; 98 | } 99 | 100 | /** 101 | * 设置上传文件的最大的限制大小 102 | * 103 | * @access public 104 | * 105 | * @param integer $fileSize 文件的大小(file size)。 106 | * 107 | * @return object 108 | */ 109 | public function setLimitSize($fileSize) { 110 | 111 | //参数分析 112 | if ($fileSize) { 113 | $this->_limitSize = (int)$fileSize; 114 | } 115 | 116 | return $this; 117 | } 118 | 119 | /** 120 | * 获取错误提示信息 121 | * 122 | * @access public 123 | * @return string 124 | */ 125 | public function getErrorInfo() { 126 | 127 | return $this->_errorMsg; 128 | } 129 | 130 | /** 131 | * 分析文件大小 132 | * 133 | * @access protected 134 | * @return boolean 135 | */ 136 | protected function _parseFileSize() { 137 | 138 | if ($this->_limitSize) { 139 | if ($this->_files['size'] > $this->_limitSize) { 140 | $this->_errorMsg = '上传文件的大小超出所允许的上传范围!'; 141 | return false; 142 | } 143 | } 144 | 145 | return true; 146 | } 147 | 148 | /** 149 | * 分析文件的格式类型(Mime Tyep) 150 | * 151 | * @access protected 152 | * @return boolean 153 | */ 154 | protected function _parseFileType() { 155 | 156 | if ($this->_limitType && is_array($this->_limitType)) { 157 | 158 | //获取文件后缀 159 | $extName = strtolower(substr(strrchr($this->_files['name'], '.'), 1)); 160 | if (!in_array($extName, $this->_limitType)) { 161 | $this->_errorMsg = '上传文件的格式不正确!'; 162 | return false; 163 | } 164 | } 165 | 166 | return true; 167 | } 168 | 169 | } -------------------------------------------------------------------------------- /doitphp/library/Cookie.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Cookie.php 2.0 2012-12-20 22:07:17Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Cookie { 19 | 20 | /** 21 | * Cookie存贮默认配置信息 22 | * 23 | * @var array 24 | */ 25 | protected $_defaultOptions = array( 26 | 'expire' => 3600, 27 | 'path' => '/', 28 | 'domain' => null, 29 | ); 30 | 31 | /** 32 | * Cookie的存贮设置选项 33 | * 34 | * @var array 35 | */ 36 | protected $_options = null; 37 | 38 | /** 39 | * 构造函数 40 | * 41 | * @access public 42 | * @return boolean 43 | */ 44 | public function __construct() { 45 | $options = Configure::get('cookie'); 46 | $this->_options = ($options && is_array($options)) ? $options : array(); 47 | $this->_options += $this->_defaultOptions; 48 | 49 | return true; 50 | } 51 | 52 | /** 53 | * 获取某cookie变量的值 54 | * 55 | * @access public 56 | * 57 | * @param string $cookieName cookie变量名 58 | * @param mixed $default 默认值 59 | * 60 | * @return mixed 61 | */ 62 | public function get($cookieName, $default = null) { 63 | 64 | //参数分析 65 | if (!$cookieName) { 66 | return null; 67 | } 68 | if (!isset($_COOKIE[$cookieName])) { 69 | return $default; 70 | } 71 | 72 | if ($this->_options['secretkey']) { 73 | $value = Doit::singleton('Encrypt')->decode($_COOKIE[$cookieName], $this->_options['secretkey']); 74 | return unserialize($value); 75 | } 76 | 77 | return unserialize(base64_decode($_COOKIE[$cookieName])); 78 | } 79 | 80 | /** 81 | * 设置某cookie变量的值 82 | * 83 | * @access public 84 | * 85 | * @param string $cookieName cookie的变量名 86 | * @param mixed $value cookie值 87 | * @param integer $expire cookie的生存周期 88 | * @param string $path cookie所存放的目录 89 | * @param string $domain cookie所支持的域名 90 | * 91 | * @return boolean 92 | */ 93 | public function set($cookieName, $value, $expire = null, $path = null, $domain = null) { 94 | 95 | //参数分析 96 | if (!$cookieName) { 97 | return false; 98 | } 99 | 100 | $expire = is_null($expire) ? $this->_options['expire'] : $expire; 101 | $path = is_null($path) ? $this->_options['path'] : $path; 102 | $domain = is_null($domain) ? $this->_options['domain'] : $domain; 103 | 104 | $expire = $_SERVER['REQUEST_TIME'] + $expire; 105 | if ($this->_options['secretkey']) { 106 | $value = Doit::singleton('Encrypt')->encode(serialize($value), $this->_options['secretkey']); 107 | } else { 108 | $value = base64_encode(serialize($value)); 109 | } 110 | 111 | setcookie($cookieName, $value, $expire, $path, $domain); 112 | $_COOKIE[$cookieName] = $value; 113 | 114 | return true; 115 | } 116 | 117 | /** 118 | * 删除某个Cookie变量 119 | * 120 | * @access public 121 | * 122 | * @param string $name cookie的名称 123 | * 124 | * @return boolean 125 | */ 126 | public function delete($name) { 127 | 128 | //参数分析 129 | if (!$name) { 130 | return false; 131 | } 132 | 133 | self::set($name, null, '-3600'); 134 | unset($_COOKIE[$name]); 135 | 136 | return true; 137 | } 138 | 139 | /** 140 | * 清空cookie 141 | * 142 | * @access public 143 | * @return boolean 144 | */ 145 | public function clear() { 146 | 147 | if (isset($_COOKIE)) { 148 | unset($_COOKIE); 149 | } 150 | 151 | return true; 152 | } 153 | 154 | } -------------------------------------------------------------------------------- /doitphp/core/Log.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Log.php 2.0 2012-11-29 23:33:00Z tommy $ 12 | * @package core 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | abstract class Log { 21 | 22 | /** 23 | * 写入日志 24 | * 25 | * @access public 26 | * 27 | * @param string $message 所要写入的日志内容 28 | * @param string $level 日志类型. 参数:Warning, Error, Notice 29 | * @param string $logFileName 日志文件名 30 | * 31 | * @return boolean 32 | */ 33 | public static function write($message, $level = 'Error', $logFileName = null) { 34 | 35 | //参数分析 36 | if (!$message) { 37 | return false; 38 | } 39 | 40 | //当日志写入功能关闭时 41 | if(Configure::get('application.log') === false){ 42 | return true; 43 | } 44 | 45 | $logFilePath = self::_getLogFilePath($logFileName); 46 | 47 | //分析日志文件存放目录 48 | $logDir = dirname($logFilePath); 49 | if (!is_dir($logDir)) { 50 | mkdir($logDir, 0777, true); 51 | } 52 | 53 | //分析记录日志的当前页面 54 | $controllerId = Doit::getControllerName(); 55 | $actionId = Doit::getActionName(); 56 | 57 | //分析日志内容 58 | $message = "[{$controllerId}][{$actionId}]:" . $message; 59 | 60 | return error_log(date('[Y-m-d H:i:s]') . " {$level}: {$message} IP: {$_SERVER['REMOTE_ADDR']}\n", 3, $logFilePath); 61 | } 62 | 63 | /** 64 | * 显示日志内容 65 | * 66 | * 显示日志文件内容,以列表的形式显示.便于程序调用查看日志 67 | * 68 | * @access public 69 | * 70 | * @param string $logFileName 所要显示的日志文件内容,默认为null, 即当天的日志文件名.注:不带后缀名.log 71 | * 72 | * @return string 73 | */ 74 | public static function show($logFileName = null) { 75 | 76 | //参数分析 77 | $logFilePath = self::_getLogFilePath($logFileName); 78 | $logContent = is_file($logFilePath) ? file_get_contents($logFilePath) : ''; 79 | 80 | $logArray = explode("\n", $logContent); 81 | $totalLines = sizeof($logArray); 82 | 83 | //清除不必要内存占用 84 | unset($logContent); 85 | 86 | //输出日志内容 87 | echo ''; 88 | 89 | foreach ($logArray as $key=>$logString) { 90 | 91 | if ($key == $totalLines - 1) { 92 | continue; 93 | } 94 | 95 | $bgColor = ($key % 2 == 0) ? '#FFFFFF' : '#C6E7FF'; 96 | 97 | echo ''; 98 | } 99 | 100 | echo '
 ' . $logString . '
'; 101 | } 102 | 103 | /** 104 | * 获取当前日志文件名 105 | * 106 | * @example 107 | * 108 | * $this->_getLogFilePath('sql'); 109 | * 或 110 | * $this->_getLogFilePath('2012-11.2012-11-23'); 111 | * 或 112 | * $this->_getLogFilePath('2012-11/2012-11-23'); 113 | * 114 | * @access private 115 | * 116 | * @param $logFileName 日志文件名 117 | * 118 | * @return string 119 | */ 120 | private static function _getLogFilePath($logFileName = null) { 121 | 122 | //参数分析 123 | if ($logFileName && strpos($logFileName, '.') !== false) { 124 | $logFileName = str_replace('.', '/', $logFileName); 125 | } 126 | 127 | //组装日志文件路径 128 | $logFilePath = rtrim(Configure::get('application.logPath'), '/'); 129 | if (!$logFileName) { 130 | $logFilePath .= DS . date('Y-m') . '/' . date('Y-m-d'); 131 | } else { 132 | if (strpos($logFileName, '/') !== false) { 133 | $logFilePath .= DS . $logFileName; 134 | } else { 135 | $logFilePath .= DS . date('Y-m') . '/' . $logFileName; 136 | } 137 | } 138 | $logFilePath .= '.log'; 139 | 140 | return $logFilePath; 141 | } 142 | } -------------------------------------------------------------------------------- /doitphp/core/Extension.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Extension.php 2.0 2012-12-19 23:29:01Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | abstract class Extension extends Controller { 19 | 20 | /** 21 | * 扩展模块实例化对象存贮数组 22 | * 23 | * @var object 24 | */ 25 | private static $_extensionObjArray = array(); 26 | 27 | /** 28 | * 设置视图文件布局结构视图的文件名(layout) 29 | * 30 | * 挂件(Widget)的视图机制不支持layout视图 31 | * 32 | * @access public 33 | * 34 | * @param string $layoutName 所要设置的layout名称。默认值为:null,即:不使用layout视图 35 | * 36 | * @return boolean 37 | */ 38 | public function setLayout($layoutName = null) { 39 | 40 | return false; 41 | } 42 | 43 | /** 44 | * 分析并加载视图缓存 45 | * 46 | * 注:挂件(Widget)的视图机制不支持视图缓存 47 | * 48 | * @access public 49 | * 50 | * @param string $cacheId 页面文件的缓存ID 51 | * @param integer $expire 页面缓存的生存周期 52 | * 53 | * @return mixed 54 | */ 55 | public function cache($cacheId = null, $expire = null) { 56 | 57 | return false; 58 | } 59 | 60 | /** 61 | * 加载视图处理类并完成视图类的实例化 62 | * 63 | * 注:本类方法为回调类方法。 64 | * 65 | * @access protected 66 | * @return object 67 | */ 68 | protected function initView() { 69 | 70 | return null; 71 | } 72 | 73 | /** 74 | * 显示当前页面的视图内容 75 | * 76 | * 注:挂件(Widget)的视图机制不支持Layout视图 77 | * 78 | * @access public 79 | * 80 | * @param string $fileName 视图名称 81 | * 82 | * @return string 83 | */ 84 | public function display($fileName = null) { 85 | 86 | return false; 87 | } 88 | 89 | /** 90 | * 视图变量赋值操作 91 | * 92 | * @access public 93 | * 94 | * @param mixed $keys 视图变量名 95 | * @param mixed $value 视图变量值 96 | * 97 | * @return void 98 | */ 99 | public function assign($keys, $value = null) { 100 | 101 | return false; 102 | } 103 | 104 | /** 105 | * 加载并显示视图片段文件内容 106 | * 107 | * 相当于include 代码片段,当$return为:true时返回代码代码片段内容,反之则显示代码片段内容 108 | * 109 | * @access public 110 | * 111 | * @param string $fileName 视图片段文件名称 112 | * @param array $data 视图模板变量,注:数组型 113 | * @param boolean $return 视图内容是否为返回,当为true时为返回,为false时则为显示。 默认为:false 114 | * 115 | * @return string 116 | */ 117 | public function render($fileName = null, $data = array(), $return = false) { 118 | 119 | return false; 120 | } 121 | 122 | /** 123 | * 获取当前扩展目录的路径 124 | * 125 | * @access protected 126 | * 127 | * @param string $extensionName 扩展插件名称 128 | * 129 | * @return string 130 | */ 131 | protected static function _getExtRoot($extensionName) { 132 | 133 | return BASE_PATH . '/extensions/' . $extensionName; 134 | } 135 | 136 | /** 137 | * 获取当前扩展目录的路径 138 | * 139 | * @access public 140 | * @return string 141 | */ 142 | public function getExtRoot() { 143 | 144 | return BASE_PATH . '/extensions/' . $this->getExtName(); 145 | } 146 | 147 | /** 148 | * 获取当前的扩展模块的名称 149 | * 150 | * @access public 151 | * @return string 152 | */ 153 | public function getExtName() { 154 | 155 | return substr(get_class($this), 0, -3); 156 | } 157 | 158 | /** 159 | * 加载并单例模式实例化扩展模块(通常为第三方程序) 160 | * 161 | * 注:这里所调用的扩展模声要放在项目extension目录里的子目录中 162 | * 163 | * @access public 164 | * 165 | * @param string $extensionName 扩展插件名称 166 | * 167 | * @access object 168 | */ 169 | final public static function loadExtension($extensionName) { 170 | 171 | //参数分析 172 | if (!$extensionName) { 173 | return false; 174 | } 175 | 176 | //当所加载的扩展模块还示被实例化时 177 | if (!isset(self::$_extensionObjArray[$extensionName])) { 178 | 179 | //加载扩展模块的引导文件(index) 180 | $extensionPath = self::_getExtRoot($extensionName) . DS . $extensionName . 'Ext.php'; 181 | Doit::loadFile($extensionPath); 182 | 183 | self::$_extensionObjArray[$extensionName] = Doit::singleton($extensionName . 'Ext'); 184 | } 185 | 186 | return self::$_extensionObjArray[$extensionName]; 187 | } 188 | } -------------------------------------------------------------------------------- /doitphp/library/Calendar.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Calendar.php 2.0 2012-12-30 01:28:54Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Calendar { 19 | 20 | /** 21 | * 日历的年份 22 | * 23 | * @var integer 24 | */ 25 | protected $_year = null; 26 | 27 | /** 28 | * 日历的月份 29 | * 30 | * @var integer 31 | */ 32 | protected $_month = null; 33 | 34 | /** 35 | * 日历中已使用的日期 36 | * 37 | * @var array 38 | */ 39 | protected $_usedDays = array(); 40 | 41 | /** 42 | * 设置日历的年份 43 | * 44 | * 默认为当前的年份 45 | * 46 | * @access public 47 | * 48 | * @param integer $year 所要设置的年份 49 | * 50 | * @return object 51 | */ 52 | public function setYear($year) { 53 | 54 | //参数分析 55 | if ($year && is_int($year)) { 56 | $this->_year = $year; 57 | } 58 | 59 | return $this; 60 | } 61 | 62 | /** 63 | * 设置月份 64 | * 65 | * 默认为当前月份 66 | * 67 | * @access public 68 | * 69 | * @param integer $month 所要设置的月份 70 | * 71 | * @return object 72 | */ 73 | public function setMonth($month) { 74 | 75 | //参数分析 76 | if ($month && is_int($month)) { 77 | $this->_month = $month; 78 | } 79 | 80 | return $this; 81 | } 82 | 83 | /** 84 | * 设置已占用的日期 85 | * 86 | * @access public 87 | * 88 | * @param array $days 已占用的日期。注:本参数为数组 89 | * 90 | * @return object 91 | */ 92 | public function setUsedDays($days) { 93 | 94 | //参数分析 95 | if ($days && is_array($days)) { 96 | $this->_usedDays = $days; 97 | } 98 | 99 | return $this; 100 | } 101 | 102 | /** 103 | * 输出日历数组 104 | * 105 | * @access public 106 | * @return array 107 | */ 108 | public function render() { 109 | 110 | return $this->_processData(); 111 | } 112 | 113 | /** 114 | * 处理日历数组 115 | * 116 | * @access protected 117 | * @return array 118 | */ 119 | protected function _processData() { 120 | 121 | //分析数组 122 | $this->_year = (!$this->_year) ? date('Y') : $this->_year; 123 | $this->_month = (!$this->_month) ? date('m') : $this->_month; 124 | 125 | $yearNow = date('Y'); 126 | $monthNow = date('m'); 127 | $dateNow = date('j'); 128 | 129 | $timeIndex = mktime(0, 0, 0, $this->_month, 1, $this->_year); 130 | 131 | //获取当前所在月份的总天数,第一天的星期数。 132 | $totalDays = date('t', $timeIndex); 133 | $dayIndex = date('w', $timeIndex); 134 | 135 | //计算日历的总行数。 136 | $totalRowNum = ceil(($totalDays + $dayIndex)/7); 137 | 138 | //分析日期占用 139 | $usedDayArray = (!$this->_usedDays) ? array() : array_keys($this->_usedDays); 140 | 141 | //分析日历数组 142 | $data = array('year'=>$this->_year, 'month'=>$this->_month, 'list'=>array()); 143 | 144 | for ($i = 0; $i < $totalRowNum; $i ++) { 145 | for($k = 0; $k < 7; $k ++) { 146 | //所要显示的日期 147 | $dateShow = intval( 7 * $i + $k - $dayIndex + 1); 148 | if (($dateShow < 1) || ($dateShow > $totalDays)) { 149 | $data['list'][$i][$k] = array('date'=> null, 'status'=> false); 150 | } else { 151 | //分析已占用的日期状态 152 | $usedStatus = in_array($dateShow, $usedDayArray) ? true : false; 153 | $todayStatus = (!$usedStatus && ($dateShow == $dateNow) && ($yearNow == $this->_year && $monthNow == $this->_month)) ? true : false; 154 | 155 | $data['list'][$i][$k] = array('date' => $dateShow); 156 | if ($usedStatus) { 157 | $data['list'][$i][$k]['status'] = 'used'; 158 | $data['list'][$i][$k]['ext'] = $this->_usedDays[$dateShow]; 159 | } else if ($todayStatus) { 160 | $data['list'][$i][$k]['status'] = 'today'; 161 | } else { 162 | $data['list'][$i][$k]['status'] = true; 163 | } 164 | } 165 | } 166 | } 167 | 168 | return $data; 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /doitphp/library/Validation.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright (c) 2010 Tommy Software Studio 9 | * @link http://www.doitphp.com 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Validation.php 2.0 2012-12-22 23:50:01Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class Validation { 21 | 22 | /** 23 | * 使用正则表达式验证是否为email格式 24 | * 25 | * @param string $string 所要验证的邮箱地址 26 | * @return boolean 27 | */ 28 | public static function isEmail($string) { 29 | 30 | if (!$string) { 31 | return false; 32 | } 33 | 34 | return preg_match('#[a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+#is', $string) ? true : false; 35 | } 36 | 37 | /** 38 | * 使用正则表达式验证是否为网址格式 39 | * 40 | * @param string $string 所要验证的网址 41 | * @return boolean 42 | */ 43 | public static function isUrl($string) { 44 | 45 | if (!$string) { 46 | return false; 47 | } 48 | 49 | return preg_match('#(http|https|ftp|ftps)://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?#i', $string) ? true : false; 50 | } 51 | 52 | /** 53 | * 使用正则表达式验证字符串中是否含有汉字 54 | * 55 | * @param integer $string 所要验证的字符串。注:字符串编码仅支持UTF-8 56 | * @return boolean 57 | */ 58 | public static function isChineseCharacter($string) { 59 | 60 | if (!$string) { 61 | return false; 62 | } 63 | 64 | return preg_match('~[\x{4e00}-\x{9fa5}]+~u', $string) ? true : false; 65 | } 66 | 67 | /** 68 | * 使用正则表达式验证字符串中是否含有非法字符 69 | * 70 | * @param string $string 待验证的字符串 71 | * @return boolean 72 | */ 73 | public static function isInvalidStr($string) { 74 | 75 | if (!$string) { 76 | return false; 77 | } 78 | 79 | return preg_match('#[!\#$%^&*(){}~`"\';:?+=<>/\[\]]+#', $string) ? true : false; 80 | } 81 | 82 | /** 83 | * 使用用正则表达式验证是否为邮证编码 84 | * 85 | * @param integer $num 所要验证的邮政编码 86 | * @return boolean 87 | */ 88 | public static function isPostNum($num) { 89 | 90 | if (!$num) { 91 | return false; 92 | } 93 | 94 | return preg_match('#^[1-9][0-9]{5}$#', $num) ? true : false; 95 | } 96 | 97 | /** 98 | * 使用正则表达式验证是滞为身份证号码(中国大陆区) 99 | * 100 | * @param integer $num 所要验证的身份证号码 101 | * @return boolean 102 | */ 103 | public static function isPersonalCard($num) { 104 | 105 | if (!$num) { 106 | return false; 107 | } 108 | 109 | return preg_match('#^[\d]{15}$|^[\d]{18}$#', $num) ? true : false; 110 | } 111 | 112 | /** 113 | * 使用正则表达式验证是否为IP地址(IPv4). 114 | * 115 | * @param string $string 所要验证的IP地址 116 | * @return boolean 117 | */ 118 | public static function isIPv4($string) { 119 | 120 | if (!$string) { 121 | return false; 122 | } 123 | 124 | if (!preg_match('#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $string)) { 125 | return false; 126 | } 127 | 128 | $ipArray = explode('.', $string); 129 | 130 | //真实的ip地址每个数字不能大于255(0-255) 131 | return ($ipArray[0]<=255 && $ipArray[1]<=255 && $ipArray[2]<=255 && $ipArray[3]<=255) ? true : false; 132 | } 133 | 134 | /** 135 | * 使用正则表达式验证是否为出版物的ISBN号 136 | * 137 | * @param integer $str 所要验证的ISBN号,通常是由13位数字构成 138 | * @return boolean 139 | */ 140 | public static function isBookIsbn($str) { 141 | 142 | if (!$str) { 143 | return false; 144 | } 145 | 146 | return preg_match('#^978[\d]{10}$|^978-[\d]{10}$#', $str) ? true : false; 147 | } 148 | 149 | /** 150 | * 使用正则表达式验证手机号码(中国大陆区) 151 | * @param integer $num 所要验证的手机号 152 | * @return boolean 153 | */ 154 | public static function isMobile($num) { 155 | 156 | if (!$num) { 157 | return false; 158 | } 159 | 160 | return preg_match('#^13[\d]{9}$|14^[0-9]\d{8}|^15[0-9]\d{8}$|^17[0-9]\d{8}$|^18[0-9]\d{8}$#', $num) ? true : false; 161 | } 162 | 163 | /** 164 | * 检查字符串长度 165 | * 166 | * @access public 167 | * @param string $string 字符串内容 168 | * @param integer $min 最小的字符串数 169 | * @param integer $max 最大的字符串数 170 | */ 171 | public static function isLength($string = null, $min = 0, $max = 255) { 172 | 173 | //参数分析 174 | if (is_null($string)) { 175 | return false; 176 | } 177 | //获取字符串长度 178 | $length = (strlen($string) + mb_strlen($string, 'UTF8')) / 2; 179 | 180 | return (($length >= (int)$min) && ($length <= (int)$max)) ? true : false; 181 | } 182 | } -------------------------------------------------------------------------------- /doitphp/library/Session.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Session.php 2.0 2012-12-20 23:09:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Session { 19 | 20 | /** 21 | * session的启动状态 22 | * 23 | * @var boolean 24 | */ 25 | protected static $_start = false; 26 | 27 | /** 28 | * 构造方法 29 | * 30 | * @access public 31 | * @return void 32 | */ 33 | public function __construct() { 34 | 35 | //设置session的生存周期 36 | $this->_setTimeout(); 37 | 38 | //启动session 39 | $this->start(); 40 | 41 | return true; 42 | } 43 | 44 | /** 45 | * 启动session 46 | * 47 | * @access public 48 | * @return boolean 49 | */ 50 | public static function start() { 51 | 52 | if (self::$_start === true) { 53 | return true; 54 | } 55 | 56 | //设置项目系统session的存放目录 57 | $sessionPath = Configure::get('session.path'); 58 | if ($sessionPath && is_dir($sessionPath) && is_writable($sessionPath)) { 59 | session_save_path($sessionPath); 60 | } 61 | 62 | session_start(); 63 | self::$_start = true; 64 | 65 | return true; 66 | } 67 | 68 | /** 69 | * 设置session变量的值 70 | * 71 | * @access public 72 | * 73 | * @param string $key session变量名 74 | * @param mixed $value session值 75 | * 76 | * @return boolean 77 | */ 78 | public static function set($key, $value = null) { 79 | 80 | //参数分析 81 | if (!$key) { 82 | return false; 83 | } 84 | 85 | //分析是否开启session 86 | if (self::$_start === false) { 87 | self::start(); 88 | } 89 | 90 | $_SESSION[$key] = $value; 91 | 92 | return true; 93 | } 94 | 95 | /** 96 | * 获取某session变量的值 97 | * 98 | * @access public 99 | * 100 | * @param string $key session变量名 101 | * @param mixted $default 默认值 102 | * 103 | * @return mixted 104 | */ 105 | public static function get($key, $default = null) { 106 | 107 | //参数分析 108 | if (!$key) { 109 | return isset($_SESSION) ? $_SESSION : null; 110 | } 111 | 112 | //分析是否开启session 113 | if (self::$_start === false) { 114 | self::start(); 115 | } 116 | 117 | //当查询的session不存在时,返回默认值 118 | if (!isset($_SESSION[$key])) { 119 | return $default; 120 | } 121 | 122 | return $_SESSION[$key]; 123 | } 124 | 125 | /** 126 | * 删除某session的值 127 | * 128 | * @access public 129 | * @return boolean 130 | */ 131 | public static function delete($key) { 132 | 133 | //参数分析 134 | if (!$key) { 135 | return false; 136 | } 137 | 138 | if (!isset($_SESSION[$key])){ 139 | return false; 140 | } 141 | 142 | unset($_SESSION[$key]); 143 | 144 | return true; 145 | } 146 | 147 | /** 148 | * 清空session值 149 | * 150 | * @access public 151 | * @return boolean 152 | */ 153 | public static function clear(){ 154 | 155 | $_SESSION = array(); 156 | 157 | return true; 158 | } 159 | 160 | /** 161 | * 注销session 162 | * 163 | * @access public 164 | * @return boolean 165 | */ 166 | public static function destory() { 167 | 168 | if (self::$_start === true){ 169 | unset($_SESSION); 170 | session_destroy(); 171 | } 172 | 173 | return true; 174 | } 175 | 176 | /** 177 | * 停止session写入 178 | * 179 | * @access public 180 | * @return boolean 181 | */ 182 | public static function close(){ 183 | 184 | if (self::$_start === true) { 185 | session_write_close(); 186 | } 187 | 188 | return true; 189 | } 190 | 191 | /** 192 | * 设置session最大存活时间. 193 | * 194 | * @access protected 195 | * @return boolean 196 | */ 197 | protected static function _setTimeout() { 198 | 199 | //获取session的系统配置信息 200 | $configExpire = Configure::get('session.expire'); 201 | 202 | if (!$configExpire) { 203 | return false; 204 | } 205 | 206 | return ini_set('session.gc_maxlifetime', $configExpire); 207 | } 208 | 209 | /** 210 | * 析构函数 211 | * 212 | * 程序执行完毕,打扫战场 213 | * 214 | * @access public 215 | * 216 | * @return void 217 | */ 218 | public function __destruct() { 219 | 220 | $this->close(); 221 | return true; 222 | } 223 | } -------------------------------------------------------------------------------- /doitphp/library/Client.php: -------------------------------------------------------------------------------- 1 | 7 | * @copyright Copyright (c) 2010 Tommy Software Studio 8 | * @link http://www.doitphp.com 9 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 10 | * @version $Id: Client.php 1.3 2011-11-11 20:50:01Z tommy $ 11 | * @package library 12 | * @since 1.0 13 | */ 14 | 15 | if (!defined('IN_DOIT')) { 16 | exit(); 17 | } 18 | 19 | class Client { 20 | 21 | /** 22 | * 获取客户端系统语言 23 | * 24 | * @access public 25 | * @return string 26 | */ 27 | public static function getLanguage() { 28 | 29 | return isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? htmlspecialchars($_SERVER['HTTP_ACCEPT_LANGUAGE']) : null; 30 | } 31 | 32 | /** 33 | * 获取当前页面的url来源 34 | * 35 | * @access public 36 | * @return string 37 | */ 38 | public static function getUrlSource() { 39 | 40 | return isset($_SERVER['HTTP_REFERER']) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : null; 41 | } 42 | 43 | /** 44 | * 获取客户端信息. 45 | * 46 | * @access public 47 | * @return string 48 | */ 49 | public static function getUserAgent() { 50 | 51 | return isset($_SERVER['HTTP_USER_AGENT']) ? htmlspecialchars($_SERVER['HTTP_USER_AGENT']) : null; 52 | } 53 | 54 | /** 55 | * 获取客户端浏览器信息 56 | * 57 | * @access public 58 | * @return string 59 | */ 60 | public static function getBrowser() { 61 | 62 | $userAgentInfo = htmlspecialchars($_SERVER['HTTP_USER_AGENT']); 63 | 64 | $browserArray = array( 65 | 'Edge' => 'Edge', 66 | 'rv:11.0' => 'IE11', 67 | 'MSIE 11.0' => 'IE11', 68 | 'MSIE 10.0' => 'IE10', 69 | 'MSIE 9.0' => 'IE9', 70 | 'MSIE 8.0' => 'IE8', 71 | 'MSIE 7.0' => 'IE7', 72 | 'MSIE 6.0' => 'IE6', 73 | 'Firefox' => 'Firefox', 74 | 'Chrome' => 'Chrome', 75 | 'Safari' => 'Safari', 76 | 'Elinks' => 'Elinks', 77 | 'OmniWeb' => 'OmniWeb', 78 | 'Links' => 'Links', 79 | 'Lynx' => 'Lynx', 80 | 'Arora' => 'Arora', 81 | 'Epiphany' => 'Epiphany', 82 | 'Konqueror' => 'Konqueror', 83 | 'EudoraWeb' => 'EudoraWeb', 84 | 'Minimo' => 'Minimo', 85 | 'NetFront' => 'NetFront', 86 | 'POLARIS' => 'Polaris', 87 | 'BlackBerry'=> 'BlackBerry', 88 | 'Nokia' => 'Nokia', 89 | ); 90 | 91 | foreach ($browserArray as $key=>$value) { 92 | if(strpos($userAgentInfo,$key)) { 93 | return $value; 94 | } 95 | } 96 | 97 | return 'Others'; 98 | } 99 | 100 | /** 101 | * 获取客户端操作系统信息 102 | * 103 | * @access public 104 | * @return string 105 | */ 106 | public static function getOs() { 107 | 108 | $userAgentInfo = htmlspecialchars($_SERVER['HTTP_USER_AGENT']); 109 | 110 | $OsArray = array( 111 | 'Windows NT 10.0' => 'Windows 10', 112 | 'Windows NT 6.3' => 'Windows 8.1', 113 | 'Windows NT 6.2' => 'Windows 8', 114 | 'Windows NT 6.1' => 'Windows 7', 115 | 'Windows NT 5.1' => 'Windows XP', 116 | 'Android' => 'Android', 117 | 'iPhone' => 'iPhone', 118 | 'Symbian' => 'Symbian', 119 | 'Mac OS X' => 'Mac OS X', 120 | 'Windows Phone' => 'Windows Phone', 121 | 'Ubuntu' => 'Ubuntu', 122 | 'Debian' => 'Debian', 123 | 'Fedora' => 'Fedora', 124 | 'redhat' => 'RedHat', 125 | 'Linux' => 'Linux', 126 | 'FreeBSD' => 'FreeBSD', 127 | 'SunOS' => 'SunOS', 128 | 'OpenBSD' => 'OpenBSD', 129 | 'NetBSD' => 'NetBSD', 130 | 'Mac OS X Mach-O' => 'OS X Mach', 131 | 'Windows NT 6.0' => 'Windows Vista', 132 | 'Windows NT 5.2' => 'Windows 2003', 133 | 'Windows NT 5.0' => 'Windows 2000', 134 | 'Windows ME' => 'Windows ME', 135 | 'PPC Mac OS X' => 'OS X PPC', 136 | 'Intel Mac OS X' => 'OS X Intel', 137 | 'Win98' => 'Windows 98', 138 | 'Win95' => 'Windows 95', 139 | 'WinNT4.0' => 'Windows NT4.0', 140 | 'AppleWebKit' => 'WebKit', 141 | 'Mint/8' => 'Mint 8', 142 | 'Minefield' => 'Minefield Alpha', 143 | 'gentoo' => 'Gentoo', 144 | 'Kubuntu' => 'Kubuntu', 145 | 'Slackware/13.0' => 'Slackware 13', 146 | 'DragonFly' => 'DragonFly', 147 | 'IRIX' => 'IRIX', 148 | 'Windows CE' => 'Windows CE', 149 | 'PalmOS' => 'PalmOS', 150 | 'DragonFly' => 'DragonFly', 151 | 'webOS' => 'webOS', 152 | 'PalmSource' => 'PalmSource', 153 | ); 154 | 155 | foreach ($OsArray as $key=>$value) { 156 | if(strpos($userAgentInfo,$key)) { 157 | return $value; 158 | } 159 | } 160 | 161 | return 'Others'; 162 | } 163 | } -------------------------------------------------------------------------------- /doitphp/library/cache/File.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2012 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Cache_File.php 2.0 2012-12-30 21:04:41Z tommy $ 10 | * @package cache 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Cache_File { 19 | 20 | /** 21 | * 单例模式实例化本类 22 | * 23 | * @var object 24 | */ 25 | protected static $_instance = null; 26 | 27 | /** 28 | * 缓存目录 29 | * 30 | * @var string 31 | */ 32 | protected $_cachePath = null; 33 | 34 | /** 35 | * 默认的缓存策略 36 | * 37 | * @var array 38 | */ 39 | protected $_defaultOptions = array('expire' => 86400); 40 | 41 | /** 42 | * 构造方法 43 | * 44 | * @access public 45 | * @return boolean 46 | */ 47 | public function __construct() { 48 | 49 | $this->_cachePath = CACHE_PATH . '/data'; 50 | 51 | return true; 52 | } 53 | 54 | /** 55 | * 设置缓存 56 | * 57 | * @access public 58 | * 59 | * @param string $key 缓存数据key 60 | * @param mixed $value 缓存数据值 61 | * @param string $expire 缓存生存周期 62 | * 63 | * @return boolean 64 | */ 65 | public function set($key, $value, $expire = null) { 66 | 67 | //参数分析 68 | if (!$key) { 69 | return false; 70 | } 71 | if(is_null($expire)){ 72 | $expire = $_SERVER['REQUEST_TIME'] + $this->_defaultOptions['expire']; 73 | }else if ($expire === 0) { 74 | $expire = 0; 75 | }else{ 76 | $expire += $_SERVER['REQUEST_TIME']; 77 | } 78 | 79 | //分析缓存文件 80 | $filePath = $this->_parseCacheFile($key); 81 | 82 | //分析缓存内容 83 | $content = '_parseCacheFile($key); 106 | 107 | if (!is_file($filePath)) { 108 | return false; 109 | } 110 | 111 | $data = include $filePath; 112 | 113 | //当缓存文件非永久且过期时 114 | if ($data[0] && $_SERVER['REQUEST_TIME'] > $data[0]) { 115 | unlink($filePath); 116 | return false; 117 | } 118 | 119 | return $data[1]; 120 | } 121 | 122 | /** 123 | * 缓存一个变量到数据存储 124 | * 125 | * @access public 126 | * 127 | * @param string $key 数据key 128 | * @param mixed $value 数据值 129 | * @param int $expire 缓存时间(秒) 130 | * 131 | * @return boolean 132 | */ 133 | public function add($key, $value, $expire = null) { 134 | 135 | //参数分析 136 | if (!$key) { 137 | return false; 138 | } 139 | $expire = is_null($expire) ? $this->_defaultOptions['expire'] : $expire; 140 | 141 | return !$this->get($key) ? $this->set($key, $value, $expire) : false; 142 | } 143 | 144 | /** 145 | * 删除一条缓存数据 146 | * 147 | * @access public 148 | * 149 | * @param string $key 缓存数据key 150 | * 151 | * @return boolean 152 | */ 153 | public function delete($key) { 154 | 155 | //参数分析 156 | if (!$key) { 157 | return false; 158 | } 159 | 160 | //分析缓存文件 161 | $filePath = $this->_parseCacheFile($key); 162 | 163 | return is_file($filePath) ? unlink($filePath) : true; 164 | } 165 | 166 | /** 167 | * 清空所有的文件缓存 168 | * 169 | * @access public 170 | * @return boolean 171 | */ 172 | public function clear() { 173 | 174 | $fileList = File::readDir($this->_cachePath); 175 | 176 | //删除所有的缓存文件 177 | foreach ($fileList as $fileName) { 178 | if (strpos($fileName, '.filecache.php') !== false) { 179 | unlink($this->_cachePath . DS . $fileName); 180 | } 181 | } 182 | 183 | return true; 184 | } 185 | 186 | /** 187 | * 分析缓存文件名 188 | * 189 | * @access protected 190 | * 191 | * @param string $key 缓存数据key 192 | * 193 | * @return string 194 | */ 195 | protected function _parseCacheFile($key) { 196 | 197 | return $this->_cachePath . DS . md5($key) . '.filecache.php'; 198 | } 199 | 200 | /** 201 | * 单例模式 202 | * 203 | * 用于本类的单例模式(singleton)实例化 204 | * 205 | * @access public 206 | * @return object 207 | */ 208 | public static function getInstance() { 209 | 210 | if (!self::$_instance) { 211 | self::$_instance = new self(); 212 | } 213 | 214 | return self::$_instance; 215 | } 216 | } -------------------------------------------------------------------------------- /doitphp/core/WidgetTemplate.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: WidgetTemplate.php 2.0 2012-12-16 23:12:00Z tommy $ 12 | * @package core 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class WidgetTemplate extends Template { 21 | 22 | /** 23 | * 单例模式实现化对象 24 | * 25 | * @var object 26 | */ 27 | protected static $_instance = null; 28 | 29 | /** 30 | * 视图变量数组 31 | * 32 | * @var array 33 | */ 34 | protected $_options = array(); 35 | 36 | /** 37 | * widget的名称,默认为null 38 | * 39 | * @var string 40 | */ 41 | public $widgetId = null; 42 | 43 | 44 | /** 45 | * 构造方法(函数) 46 | * 47 | * 用于初始化程序运行环境,或对基本变量进行赋值 48 | * 49 | * @access public 50 | * @return boolean 51 | */ 52 | public function __construct() { 53 | 54 | //设置挂件视图模板目录的路径 55 | $this->_viewPath = BASE_PATH . '/views/widgets'; 56 | //设置视图编译缓存文件的默认目录路径 57 | $this->_compilePath = CACHE_PATH . '/views/widgets'; 58 | 59 | return true; 60 | } 61 | 62 | /** 63 | * 设置视图文件布局结构视图的文件名(layout) 64 | * 65 | * 挂件(Widget)的视图机制不支持layout视图 66 | * 67 | * @access public 68 | * 69 | * @param string $layoutName 所要设置的layout名称。默认值为:null,即:不使用layout视图 70 | * 71 | * @return boolean 72 | */ 73 | public function setLayout($layoutName = null) { 74 | 75 | return false; 76 | } 77 | 78 | /** 79 | * 分析并加载视图缓存 80 | * 81 | * 注:挂件(Widget)的视图机制不支持视图缓存 82 | * 83 | * @access public 84 | * 85 | * @param string $cacheId 页面文件的缓存ID 86 | * @param integer $expire 页面缓存的生存周期 87 | * 88 | * @return mixed 89 | */ 90 | public function cache($cacheId = null, $expire = null) { 91 | 92 | return false; 93 | } 94 | 95 | /** 96 | * 加载并显示视图片段文件内容 97 | * 98 | * 相当于include 代码片段,当$return为:true时返回代码代码片段内容,反之则显示代码片段内容 99 | * 100 | * @access public 101 | * 102 | * @param string $fileName 视图片段文件名称 103 | * @param array $data 视图模板变量,注:数组型 104 | * @param boolean $return 视图内容是否为返回,当为true时为返回,为false时则为显示。 默认为:false 105 | * 106 | * @return string 107 | */ 108 | public function render($fileName = null, $data = array(), $return = false) { 109 | 110 | //模板变量赋值 111 | if ($data && is_array($data)) { 112 | extract($data, EXTR_PREFIX_SAME, 'data'); 113 | unset($data); 114 | } else { 115 | //当且仅当本方法在处理action视图(非视图片段)时,对本类assign()所传递的视图变量进行赋值 116 | if (!$fileName && $this->_options) { 117 | extract($this->_options, EXTR_PREFIX_SAME, 'data'); 118 | $this->_options = array(); 119 | } 120 | } 121 | 122 | //分析挂件视图名称 123 | $fileName = (!$fileName) ? $this->widgetId : $fileName; 124 | 125 | //获取视图模板文件及编译文件的路径 126 | $viewFile = $this->_getViewFile($fileName); 127 | $compileFile = $this->_getCompileFile($fileName); 128 | 129 | //分析视图编译文件是否需要重新生成 130 | if ($this->_isCompile($viewFile, $compileFile)) { 131 | $templateContent = $this->_loadViewFile($viewFile); 132 | //重新生成编译缓存文件 133 | $this->_createCompileFile($compileFile, $templateContent); 134 | } 135 | 136 | //加载编译缓存文件 137 | ob_start(); 138 | include $compileFile; 139 | $widgetContent = ob_get_clean(); 140 | 141 | //返回信息 142 | if (!$return) { 143 | echo $widgetContent; 144 | } else { 145 | return $widgetContent; 146 | } 147 | } 148 | 149 | /** 150 | * 显示当前页面的视图内容 151 | * 152 | * 注:挂件(Widget)的视图机制不支持Layout视图 153 | * 154 | * @access public 155 | * 156 | * @param string $fileName 视图名称 157 | * 158 | * @return string 159 | */ 160 | public function display($fileName = null) { 161 | 162 | //参数分析 163 | if (!$fileName) { 164 | $fileName = $this->widgetId; 165 | } 166 | 167 | //模板变量赋值 168 | if ($this->_options) { 169 | extract($this->_options, EXTR_PREFIX_SAME, 'data'); 170 | $this->_options = array(); 171 | } 172 | 173 | //获取视图模板文件及编译文件的路径 174 | $viewFile = $this->_getViewFile($fileName); 175 | $compileFile = $this->_getCompileFile($fileName); 176 | 177 | //分析视图编译文件是否需要重新生成 178 | if ($this->_isCompile($viewFile, $compileFile)) { 179 | $templateContent = $this->_loadViewFile($viewFile); 180 | //重新生成编译缓存文件 181 | $this->_createCompileFile($compileFile, $templateContent); 182 | } 183 | 184 | //加载编译缓存文件 185 | ob_start(); 186 | include $compileFile; 187 | $widgetContent = ob_get_clean(); 188 | 189 | //显示挂件视图内容 190 | echo $widgetContent; 191 | } 192 | 193 | /** 194 | * 获取视图编译文件的路径 195 | * 196 | * @access protected 197 | * 198 | * @param string $fileName 视图名. 注:不带后缀 199 | * 200 | * @return string 201 | */ 202 | protected function _getCompileFile($fileName) { 203 | 204 | return $this->_compilePath . DS . $fileName . '.widget.compilecache.php'; 205 | } 206 | 207 | /** 208 | * 单例模式实例化当前模型类 209 | * 210 | * @access public 211 | * @return object 212 | */ 213 | public static function getInstance() { 214 | 215 | if (self::$_instance === null) { 216 | self::$_instance = new self(); 217 | } 218 | 219 | return self::$_instance; 220 | } 221 | } -------------------------------------------------------------------------------- /doitphp/core/Configure.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (C) 2012 www.doitphp.com All rights reserved. 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Configure.php 1.0 2012-11-11 22:01:36Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | abstract class Configure { 19 | 20 | /* 21 | * 网址格式 22 | * 23 | * @var string 24 | */ 25 | const PATH_FORMAT = 'path'; 26 | const GET_FORMAT = 'get'; 27 | 28 | /* 29 | * 视图格式 30 | * 31 | * @var string 32 | */ 33 | const VIEW_EXT_HTML = '.html'; 34 | const VIEW_EXT_PHP = '.php'; 35 | 36 | /** 37 | * 项目配置文件内容临时存贮数组 38 | * 39 | * @var array 40 | */ 41 | private static $_config = array(); 42 | 43 | /** 44 | * 应用配置文件内容存贮数组 45 | * 46 | * @var array 47 | */ 48 | private static $_data = array(); 49 | 50 | /** 51 | * 类方法:loadConfig()调用状态。如果调用则为true,反之为false。 52 | * 53 | * @var boolean 54 | */ 55 | private static $_isStart = false; 56 | 57 | /** 58 | * 加载应用配置文件 59 | * 60 | * 加载应用配置文件,分析该配置文件内容,并将分析后的数据赋值给self::$_data。 61 | * 62 | * @access public 63 | * 64 | * @param string $filePath 应用配置文件路径 65 | * 66 | * @return boolean 67 | */ 68 | public static function loadConfig($filePath = null) { 69 | 70 | //判断本方法是否被调用过,如果调用过,则直接返回。 71 | if (self::$_isStart == true) { 72 | return true; 73 | } 74 | 75 | //获取应用配置文件内容默认值 76 | $defaultConfig = self::_getDefaultConfig(); 77 | 78 | $config = array(); 79 | //当配置文件路径存在时 80 | if ($filePath) { 81 | //分析配置文件是否存在 82 | if (!is_file($filePath)) { 83 | Response::halt('The configuration file: ' . $filePath . ' is not found!'); 84 | } 85 | //获取应用配置文件内容 86 | include_once $filePath; 87 | 88 | //应用配置文件内容的默认值与配置文件值进行整合 89 | $config['application'] = (isset($config['application']) && is_array($config['application'])) ? $config['application'] + $defaultConfig : $defaultConfig; 90 | } else { 91 | $config['application'] = $defaultConfig; 92 | } 93 | 94 | self::$_data = $config; 95 | self::$_isStart = true; 96 | 97 | return true; 98 | } 99 | 100 | /** 101 | * 获取参数值 102 | * 103 | * 根据某参数名,获取应用配置文件的该参数的参数值 104 | * 105 | * @access public 106 | * 107 | * @param string $key 应用配置文件内容的参数名 108 | * 109 | * @return mixed 110 | */ 111 | public static function get($key) { 112 | 113 | //分析参数 114 | if (!$key) { 115 | return false; 116 | } 117 | 118 | if (strpos($key, '.') === false) { 119 | if (!isset(self::$_data[$key])) { 120 | return false; 121 | } 122 | return self::$_data[$key]; 123 | } 124 | 125 | $keyArray = explode('.', $key); 126 | 127 | $value = false; 128 | if ($keyArray) { 129 | foreach ($keyArray as $keyId=>$keyName) { 130 | if ($keyId == 0) { 131 | if (!isset(self::$_data[$keyName])) { 132 | $value = false; 133 | break; 134 | } 135 | $value = self::$_data[$keyName]; 136 | } else { 137 | if (!isset($value[$keyName])) { 138 | $value = false; 139 | break; 140 | } 141 | $value = $value[$keyName]; 142 | } 143 | } 144 | } 145 | 146 | return $value; 147 | } 148 | 149 | /** 150 | * 获取项目配置文件内容 151 | * 152 | * 根据DoitPHP项目的配置文件名称,获取该项目配置文件的内容,并将该内容进行返回 153 | * 154 | * @access public 155 | * 156 | * @param string $fileName 项目配置文件名。注:不含“.php”后缀。 157 | * 158 | * @return array 159 | */ 160 | public static function getConfig($fileName) { 161 | 162 | //参数分析. 163 | if (!$fileName) { 164 | return false; 165 | } 166 | 167 | if (!isset(self::$_config[$fileName])) { 168 | $filePath = BASE_PATH . '/config/' . $fileName . '.php'; 169 | //判断文件是否存在 170 | if (!is_file($filePath)) { 171 | Response::halt('The configuration file: ' . $fileName . '.php is not exists!'); 172 | } 173 | 174 | $config = array(); 175 | include_once $filePath; 176 | self::$_config[$fileName] = $config; 177 | } 178 | 179 | return self::$_config[$fileName]; 180 | } 181 | 182 | /** 183 | * 获取应用配置文件的默认值 184 | * 185 | * @access private 186 | * @return array 187 | */ 188 | private static function _getDefaultConfig() { 189 | 190 | //定义变量$defaultConfig 191 | $defaultConfig = array(); 192 | 193 | //设置应用目录(application)的路径 194 | $defaultConfig['basePath'] = APP_ROOT . '/application'; 195 | 196 | //设置缓存目录的路径 197 | $defaultConfig['cachePath'] = APP_ROOT . '/cache'; 198 | 199 | //设置日志目录的路径 200 | $defaultConfig['logPath'] = APP_ROOT . '/logs'; 201 | 202 | //设置是否开启调试模式(开启后,程序运行出现错误时,显示错误信息,便于程序调试) 203 | $defaultConfig['debug'] = false; 204 | 205 | //设置日志写入功能是否开启 206 | $defaultConfig['log'] = false; 207 | 208 | //设置路由网址的重写模式是否开启 209 | $defaultConfig['rewrite'] = false; 210 | 211 | //设置路由网址格式(path:为url路由格式;get:为标准普通url格式) 212 | $defaultConfig['urlFormat'] = self::PATH_FORMAT; 213 | 214 | //设置路由分割符 215 | $defaultConfig['urlSegmentation'] = '/'; 216 | 217 | //设置默认controller及action名 218 | $defaultConfig['defaultController'] = 'Index'; 219 | $defaultConfig['defaultAction'] = 'index'; 220 | 221 | //设置时区,默认时区为东八区(中国)时区(Asia/ShangHai)。 222 | $defaultConfig['defaultTimeZone'] = 'Asia/ShangHai'; 223 | 224 | //设置视图文件的格式(php或html, 默认为php) 225 | $defaultConfig['viewExt'] = self::VIEW_EXT_PHP; 226 | 227 | return $defaultConfig; 228 | } 229 | } -------------------------------------------------------------------------------- /doitphp/library/Excel.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Excel.php 2.0 2012-12-23 00:50:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Excel { 19 | 20 | /** 21 | * EXCEL表格的xml代码 22 | * 23 | * @var string 24 | */ 25 | protected $_xmlTable; 26 | 27 | /** 28 | * EXCEL的标题xml代码 29 | * 30 | * @var string 31 | */ 32 | protected $_xmlMenu; 33 | 34 | /** 35 | * 处理EXCEL中一行代码,相当于HTML中的行标签 36 | * 37 | * @access protected 38 | * 39 | * @param array $data 行数据 40 | * 41 | * @return string 42 | */ 43 | protected function _handleRow($data) { 44 | 45 | //参数分析 46 | if (empty($data) || !is_array($data)) { 47 | return false; 48 | } 49 | 50 | $xml = "\n"; 51 | foreach ($data as $key=>$value) { 52 | $xml .= ($key>0&&empty($data[$key-1])) ? $this->_handleIndexCell($value, $key+1) : $this->_handleCell($value); 53 | } 54 | $xml .= "\n"; 55 | 56 | return $xml; 57 | } 58 | 59 | /** 60 | * 处理EXCEL多行数据的代码. 61 | * 62 | * @access protected 63 | * 64 | * @param array $data 多行数据 65 | * 66 | * @return string 67 | */ 68 | protected function _addRows($data) { 69 | 70 | //参数分析 71 | if (empty($data) || !is_array($data) || !is_array($data[0])) { 72 | return false; 73 | } 74 | 75 | $xmlArray = array(); 76 | foreach ($data as $row) { 77 | $xmlArray[] = $this->_handleRow($row); 78 | } 79 | 80 | return implode('', $xmlArray); 81 | } 82 | 83 | /** 84 | * 配置EXCEL表格的标题 85 | * 86 | * @access public 87 | * 88 | * @param array $data 所要生成的excel的标题,注:参数为数组 89 | * 90 | * @return boolean 91 | */ 92 | public function setMenu($data) { 93 | 94 | //参数分析 95 | if (empty($data) || !is_array($data) || is_array($data[0]) || array_search('', $data)) { 96 | return false; 97 | } 98 | 99 | $xml = "\n"; 100 | foreach ($data as $value) { 101 | $type = (is_numeric($data)&&(substr($data, 0, 1)!=0)) ? 'Number' : 'String'; 102 | $xml .= "" . $value . "\n"; 103 | } 104 | $xml .= "\n"; 105 | $this->_xmlMenu = $xml; 106 | 107 | return true; 108 | } 109 | 110 | /** 111 | * 处理EXCEL表格的内容,相当于table. 112 | * 113 | * @access public 114 | * 115 | * @param array $data Excel内容数据 116 | * 117 | * @return string 118 | */ 119 | public function setData($data) { 120 | 121 | //参数分析 122 | if (!$data || !is_array($data) || !is_array($data[0])) { 123 | return false; 124 | } 125 | 126 | $xmlRows = $this->_addRows($data); 127 | 128 | if (!$xmlRows) { 129 | if (!$this->_xmlMenu) { 130 | return false; 131 | } else { 132 | $content = $this->_xmlMenu; 133 | } 134 | } else { 135 | if (!$this->_xmlMenu) { 136 | $content = $xmlRows; 137 | } else { 138 | $content = $this->_xmlMenu.$xmlRows; 139 | } 140 | } 141 | 142 | return $this->_xmlTable = "\n" . $content . "
\n"; 143 | } 144 | 145 | /** 146 | * 处理EXCEL表格信息代码 147 | * 148 | * @access protected 149 | * @return string 150 | */ 151 | protected function _parseTable() { 152 | 153 | $xmlWorksheet = "\n"; 154 | 155 | if (empty($this->_xmlTable)) { 156 | $xmlWorksheet .= "\n"; 157 | } else{ 158 | $xmlWorksheet .= $this->_xmlTable; 159 | } 160 | 161 | $xmlWorksheet .= "\n"; 162 | 163 | return $xmlWorksheet; 164 | } 165 | 166 | /** 167 | * 处理EXCEL中的表格,相当于html中的标签 168 | * 169 | * @access protected 170 | * 171 | * @param string $data 表格数据 172 | * 173 | * @return string 174 | */ 175 | protected function _handleCell($data) { 176 | 177 | //参数分析 178 | if (is_array($data)) { 179 | return false; 180 | } 181 | 182 | $type = (is_numeric($data)&&(substr($data, 0, 1)!=0)) ? 'Number' : 'String'; 183 | 184 | return "" . $data . "\n"; 185 | } 186 | 187 | /** 188 | * 处理EXCEL中CELL代码,当该CELL前的一个CELL内容为空时. 189 | * 190 | * @access protected 191 | * 192 | * @param string $data 表格数据 193 | * @param integer $key 键值 194 | * 195 | * @return string 196 | */ 197 | protected function _handleIndexCell($data, $key) { 198 | 199 | //参数分析 200 | if (is_array($data)) { 201 | return false; 202 | } 203 | 204 | $type = (is_numeric($data)&&(substr($data, 0, 1)!=0)) ? 'Number' : 'String'; 205 | 206 | return "" . $data . "\n"; 207 | } 208 | 209 | 210 | /** 211 | * 分析EXCEL的文件头 212 | * 213 | * @access protected 214 | * @return string 215 | */ 216 | protected function _parseHeader() { 217 | 218 | return " 219 | \n"; 224 | } 225 | 226 | /** 227 | * 生成EXCEL文件并下载. 228 | * 229 | * @access public 230 | * 231 | * @param string $fileName 所要生成的excel的文件名,注:文件名中不含后缀名 232 | * 233 | * @return void 234 | */ 235 | public function download($fileName) { 236 | 237 | //参数分析 238 | if (empty($fileName)) { 239 | return false; 240 | } 241 | 242 | header('Pragma: no-cache'); 243 | header("Content-Type: application/vnd.ms-excel; charset=utf-8"); 244 | header("Content-Disposition: inline; filename=\"" . $fileName . ".xls\""); 245 | $excelXml = $this->_parseHeader().$this->_parseTable().""; 246 | 247 | echo $excelXml; 248 | } 249 | 250 | /** 251 | * 析构函数(类方法) 252 | * 253 | * @return void 254 | */ 255 | public function __destruct(){ 256 | 257 | exit(); 258 | } 259 | } -------------------------------------------------------------------------------- /doitphp/library/Security.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Security.php 2.0 2012-12-29 15:57:21Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class Security { 21 | 22 | /** 23 | * Token生存时间周期 24 | * 25 | * @var integer 26 | */ 27 | protected static $_expire = 7200; 28 | 29 | /** 30 | * 加密字符串(密钥) 31 | * 32 | * @var string 33 | */ 34 | protected static $_key = 'your-secret-code'; 35 | 36 | /** 37 | * 过滤XSS(跨网站攻击)代码 38 | * 39 | * 通常用于富文本提交内容的过滤。提升网站安全必备 40 | * 41 | * @access public 42 | * 43 | * @param string $string 待过滤的内容 44 | * 45 | * @return string 46 | */ 47 | public static function removeXss($string) { 48 | 49 | //参数分析 50 | if (!$string) { 51 | return $string; 52 | } 53 | 54 | if (is_array($string)) { 55 | return array_map(array('Security', 'removeXss'), $string); 56 | } 57 | 58 | // remove all non-printable characters. CR(0a) and LF(0b) and TAB(9) are allowed 59 | // this prevents some character re-spacing such as 60 | // note that you have to handle splits with \n, \r, and \t later since they *are* allowed in some inputs 61 | $string = preg_replace('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '', $string); 62 | 63 | // straight replacements, the user should never need these since they're normal characters 64 | // this prevents like 65 | $search= 'abcdefghijklmnopqrstuvwxyz'; 66 | $search .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; 67 | $search .= '1234567890!@#$%^&*()'; 68 | $search .= '~`";:?+/={}[]-_|\'\\'; 69 | 70 | for ($i = 0; $i < strlen($search); $i++) { 71 | // ;? matches the ;, which is optional 72 | // 0{0,7} matches any padded zeros, which are optional and go up to 8 chars 73 | 74 | // @ @ search for the hex values 75 | $string = preg_replace('/(&#[xX]0{0,8}'.dechex(ord($search[$i])).';?)/i', $search[$i], $string); // with a ; 76 | // @ @ 0{0,7} matches '0' zero to seven times 77 | $string = preg_replace('/(�{0,8}'.ord($search[$i]).';?)/', $search[$i], $string); // with a ; 78 | } 79 | 80 | // now the only remaining whitespace attacks are \t, \n, and \r 81 | $ra1 = array('javascript', 'vbscript', 'expression', 'applet', 'meta', 'xml', 'blink', 'link', 'style', 'script', 'embed', 'object', 'iframe', 'frame', 'frameset', 'ilayer', 'layer', 'bgsound', 'title', 'base'); 82 | $ra2 = array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavailable', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterchange', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowenter', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'); 83 | $ra = array_merge($ra1, $ra2); 84 | 85 | $found = true; // keep replacing as long as the previous round replaced something 86 | while ($found == true) { 87 | $stringBefore = $string; 88 | for ($i = 0; $i < sizeof($ra); $i++) { 89 | $pattern = '/'; 90 | for ($j = 0; $j < strlen($ra[$i]); $j++) { 91 | if ($j > 0) { 92 | $pattern .= '('; 93 | $pattern .= '(&#[xX]0{0,8}([9ab]);)'; 94 | $pattern .= '|'; 95 | $pattern .= '|(�{0,8}([9|10|13]);)'; 96 | $pattern .= ')*'; 97 | } 98 | $pattern .= $ra[$i][$j]; 99 | } 100 | $pattern .= '/i'; 101 | $replacement = substr($ra[$i], 0, 2).''.substr($ra[$i], 2); // add in <> to nerf the tag 102 | $string = preg_replace($pattern, $replacement, $string); // filter out the hex tags 103 | if ($stringBefore == $string) { 104 | // no replacements were made, so exit the loop 105 | $found = false; 106 | } 107 | } 108 | } 109 | 110 | return $string; 111 | } 112 | 113 | /** 114 | * 生成令牌密码 115 | * 116 | * @access public 117 | * 118 | * @param string $string 所要加密的字符(也可以是随机的) 119 | * @param string $expire 令版密码的有效时间(单位:秒) 120 | * @param string $key 自定义密钥 121 | * 122 | * @return string 123 | */ 124 | public static function getToken($string, $expire = null, $key = null) { 125 | 126 | //参数分析 127 | if (!$string) { 128 | return false; 129 | } 130 | 131 | //设置token生存周期及附加加密码 132 | $expire = (!$expire) ? self::$_expire : $expire; 133 | $key = (!$key) ? self::$_key : $key; 134 | $per = ceil($_SERVER['REQUEST_TIME'] / $expire); 135 | 136 | return hash_hmac('md5', $per . $string, $key); 137 | } 138 | 139 | /** 140 | * 令牌密码验证 141 | * 142 | * @access public 143 | * 144 | * @param string $string 所要加密的字符(也可以是随机的) 145 | * @param string $tokenCode 所要验证的加密字符串 146 | * @param string $expire 令版密码的有效时间(单位:秒) 147 | * @param string $key 自定义密钥 148 | * 149 | * @return boolean 150 | */ 151 | public function checkToken($string, $tokenCode, $expire = null, $key = null) { 152 | 153 | //参数分析 154 | if (!$string || !$tokenCode) { 155 | return false; 156 | } 157 | 158 | //设置token生存周期及附加加密码 159 | $expire = (!$expire) ? self::$_expire : $expire; 160 | $key = (!$key) ? self::$_key : $key; 161 | $per = ceil($_SERVER['REQUEST_TIME'] / $expire); 162 | 163 | //获取token值 164 | $sourceToken = hash_hmac('md5', $per . $string, $key); 165 | 166 | return ($sourceToken == $tokenCode) ? true : false; 167 | } 168 | } -------------------------------------------------------------------------------- /doitphp/library/cache/Redis.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Cache_Redis.php 2.0 2012-12-30 19:48:01Z tommy $ 10 | * @package cache 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Cache_Redis { 19 | 20 | /** 21 | * 单例模式实例化对象 22 | * 23 | * @var object 24 | */ 25 | protected static $_instance; 26 | 27 | /** 28 | * 数据库连接ID 29 | * 30 | * @var object 31 | */ 32 | protected $_Redis; 33 | 34 | /** 35 | * 数据库连接参数默认值 36 | * 37 | * @var array 38 | */ 39 | protected $_defaultOptions = array( 40 | 'host' => '127.0.0.1', 41 | 'port' => '6379', 42 | 'password' => null, 43 | 'database' => 0, 44 | 'persistent' => false, 45 | 'expire' => 900, 46 | ); 47 | 48 | /** 49 | * 构造函数 50 | * 51 | * @access public 52 | * 53 | * @param array $params 数据库连接参数,如主机名,数据库用户名,密码等 54 | * 55 | * @return boolean 56 | */ 57 | public function __construct($options = null) { 58 | 59 | if (!extension_loaded('redis')) { 60 | Response::halt('The redis extension to be loaded!'); 61 | } 62 | 63 | //当参数为空时,程序则自动加载配置文件中数据库连接参数 64 | if (!$options || !is_array($options)) { 65 | $options = Configure::get('redis'); 66 | if (!$options) { 67 | $options = array(); 68 | } 69 | } 70 | 71 | $options += $this->_defaultOptions; 72 | //连接数据库 73 | $this->_Redis = new Redis(); 74 | $connect = (!$options['persistent']) ? 'connect' : 'pconnect'; 75 | $linkId = $this->_Redis->$connect($options['host'], $options['port'], $options['expire']); 76 | 77 | if ($linkId && $options['password']) { 78 | $linkId = $this->_Redis->auth($options['password']); 79 | } 80 | if ($linkId && $options['database']) { 81 | $linkId = $this->_Redis->select($options['database']); 82 | } 83 | 84 | return $linkId; 85 | } 86 | 87 | /** 88 | * 设置数据值 89 | * 90 | * @access public 91 | * 92 | * @param string $key KEY名称 93 | * @param mixed $value 获取得到的数据 94 | * @param integer $expire 缓存的生存周期 95 | * 96 | * @return boolean 97 | */ 98 | public function set($key, $value, $expire = null) { 99 | 100 | //参数分析 101 | if (!$key) { 102 | return false; 103 | } 104 | 105 | $value = json_encode($value); 106 | $result = $this->_Redis->set($key, $value); 107 | 108 | if ($expire > 0) { 109 | $this->_Redis->setTimeout($key, $expire); 110 | } 111 | 112 | return $result; 113 | } 114 | 115 | /** 116 | * 通过KEY获取数据 117 | * 118 | * @access public 119 | * 120 | * @param string $key 数据Key 121 | * 122 | * @return mixed 123 | */ 124 | public function get($key) { 125 | 126 | //参数分析 127 | if (!$key) { 128 | return false; 129 | } 130 | 131 | $value = $this->_Redis->get($key); 132 | return json_decode($value, true); 133 | } 134 | 135 | /** 136 | * 删除一条数据 137 | * 138 | * @access public 139 | * 140 | * @param string $key 数据key 141 | * 142 | * @return boolean 143 | */ 144 | public function delete($key) { 145 | 146 | //参数分析 147 | if (!$key) { 148 | return false; 149 | } 150 | 151 | return $this->_Redis->delete($key); 152 | } 153 | 154 | /** 155 | * 清空数据 156 | * 157 | * @access public 158 | * @return boolean 159 | */ 160 | public function clear() { 161 | 162 | return $this->_Redis->flushAll(); 163 | } 164 | 165 | /** 166 | * 数据入队列 167 | * 168 | * @access public 169 | * 170 | * @param string $key KEY名称 171 | * @param mixed $value 获取得到的数据 172 | * @param bool $right 是否从右边开始入 173 | * 174 | * @return boolean 175 | */ 176 | public function push($key, $value, $right = true) { 177 | 178 | //参数分析 179 | if (!$key) { 180 | return false; 181 | } 182 | 183 | $value = json_encode($value); 184 | return ($right == true) ? $this->_Redis->rPush($key, $value) : $this->_Redis->lPush($key, $value); 185 | } 186 | 187 | /** 188 | * 数据出队列 189 | * 190 | * @access public 191 | * 192 | * @param string $key KEY名称 193 | * @param bool $left 是否从左边开始出数据 194 | * 195 | * @return mixed 196 | */ 197 | public function pop($key, $left = true) { 198 | 199 | //参数分析 200 | if (!$key) { 201 | return false; 202 | } 203 | 204 | $value = ($left == true) ? $this->_Redis->lPop($key) : $this->_Redis->rPop($key); 205 | return json_decode($value); 206 | } 207 | 208 | /** 209 | * 数据自增 210 | * 211 | * @access public 212 | * 213 | * @param string $key 数据key 214 | * @param integer $value 自增数据值 215 | * 216 | * @return boolean 217 | */ 218 | public function increment($key, $value = 1) { 219 | 220 | //参数分析 221 | if (!$key) { 222 | return false; 223 | } 224 | 225 | return $this->_Redis->incrBy($key, $value); 226 | } 227 | 228 | /** 229 | * 数据自减 230 | * 231 | * @access public 232 | * 233 | * @param string $key 数据key 234 | * @param integer $value 自减数据值 235 | * 236 | * @return boolean 237 | */ 238 | public function decrement($key, $value = 1) { 239 | 240 | //参数分析 241 | if (!$key) { 242 | return false; 243 | } 244 | 245 | return $this->_Redis->decrBy($key, $value); 246 | } 247 | 248 | /** 249 | * key是否存在,存在返回ture 250 | * 251 | * @access public 252 | * 253 | * @param string $key KEY名称 254 | * 255 | * @return boolean 256 | */ 257 | public function exists($key) { 258 | 259 | //参数分析 260 | if (!$key) { 261 | return false; 262 | } 263 | 264 | return $this->_Redis->exists($key); 265 | } 266 | 267 | /** 268 | * 返回redis对象 269 | * 270 | * @access public 271 | * @return object 272 | */ 273 | public function getConnection() { 274 | 275 | return $this->_Redis; 276 | } 277 | 278 | /** 279 | * 单例模式 280 | * 281 | * @access public 282 | * 283 | * @param array $params 数据库连接参数 284 | * 285 | * @return object 286 | */ 287 | public static function getInstance($params = null) { 288 | 289 | if (!self::$_instance) { 290 | self::$_instance = new self($params); 291 | } 292 | 293 | return self::$_instance; 294 | } 295 | 296 | } -------------------------------------------------------------------------------- /doitphp/library/cache/Memcached.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2015 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Cache_Memcached.php 2.0 2015-04-01 15:00:01Z tommy $ 10 | * @package cache 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | /** 19 | * 使用说明 20 | * 21 | * @author tommy 22 | * 23 | * @example 24 | * 25 | * 参数范例 26 | * $memOptions = array( 27 | * 'servers'=> array( 28 | * array('host'=>'127.0.0.1', 'port'=>11211, 'persistent'=>true, 'weight'=>1, 'timeout'=>60), 29 | * array('host'=>'192.168.0.101', 'port'=>11211, 'persistent'=>true, 'weight'=>2, 'timeout'=>60), 30 | * ), 31 | * 'compressed'=>true, 32 | * 'expire' => 3600, 33 | * 'persistent' => true, 34 | * ); 35 | * 36 | * 实例化 37 | * 38 | * 法一: 39 | * $memcached = new Cache_Memcached($memOptions); 40 | * 41 | */ 42 | 43 | class Cache_Memcached { 44 | 45 | /** 46 | * 单例模式实例化本类 47 | * 48 | * @var object 49 | */ 50 | protected static $_instance = null; 51 | 52 | /** 53 | * Memcached实例 54 | * 55 | * @var objeact 56 | */ 57 | private $_Memcached; 58 | 59 | /** 60 | * 默认的缓存服务器 61 | * 62 | * @var array 63 | */ 64 | protected $_defaultServer = array( 65 | /** 66 | * 缓存服务器地址或主机名 67 | */ 68 | 'host' => '127.0.0.1', 69 | 70 | /** 71 | * 缓存服务器端口 72 | */ 73 | 'port' => '11211', 74 | ); 75 | 76 | /** 77 | * 默认的缓存策略 78 | * 79 | * @var array 80 | */ 81 | protected $_defaultOptions = array( 82 | 83 | /** 84 | * 缓存服务器配置,参看$_defaultServer 85 | * 允许多个缓存服务器 86 | */ 87 | 'servers' => array(), 88 | 89 | /** 90 | * 是否压缩缓存数据 91 | */ 92 | 'compressed' => false, 93 | 94 | /** 95 | * 缓存有效时间 96 | * 97 | * 如果设置为 0 表示缓存永不过期 98 | */ 99 | 'expire' => 900, 100 | 101 | /** 102 | * 是否使用持久连接 103 | */ 104 | 'persistent' => true, 105 | ); 106 | 107 | /** 108 | * 构造方法 109 | * 110 | * @access public 111 | * 112 | * @param array $params 数据库连接参数,如主机名,数据库用户名,密码等 113 | * 114 | * @return boolean 115 | */ 116 | public function __construct($options = null) { 117 | 118 | //分析memcached扩展模块的加载 119 | if (!extension_loaded('memcached')) { 120 | Response::halt('The memcached extension to be loaded before use!'); 121 | } 122 | 123 | //获取Memcache服务器连接参数 124 | if (!$options || !is_array($options)) { 125 | $options = Configure::get('memcached'); 126 | } 127 | 128 | if (is_array($options) && $options) { 129 | $this->_defaultOptions = $options + $this->_defaultOptions; 130 | } 131 | 132 | if (!$this->_defaultOptions['servers']) { 133 | $this->_defaultOptions['servers'][] = $this->_defaultServer; 134 | } 135 | 136 | $this->_Memcached = new Memcached(); 137 | 138 | foreach ($this->_defaultOptions['servers'] as $server) { 139 | $server += array('host' => '127.0.0.1', 'port' => 11211, 'persistent' => true); 140 | $this->_Memcached->addServer($server['host'], $server['port'], $this->_defaultOptions['persistent']); 141 | } 142 | 143 | return true; 144 | } 145 | 146 | /** 147 | * 写入缓存 148 | * 149 | * @access public 150 | * 151 | * @param string $key 缓存Key 152 | * @param mixed $data 缓存内容 153 | * @param int $expire 缓存时间(秒) 154 | * 155 | * @return boolean 156 | */ 157 | public function set($key, $data, $expire = null) { 158 | 159 | //参数分析 160 | if (!$key) { 161 | return false; 162 | } 163 | if (is_null($expire)) { 164 | $expire = $this->_defaultOptions['expire']; 165 | } 166 | 167 | return $this->_Memcached->set($key, $data, $expire); 168 | } 169 | 170 | /** 171 | * 读取缓存,失败或缓存撒失效时返回false 172 | * 173 | * @access public 174 | * 175 | * @param string $key 所要读取数据的key 176 | * 177 | * @return mixed 178 | */ 179 | public function get($key) { 180 | 181 | //参数分析 182 | if (!$key) { 183 | return false; 184 | } 185 | 186 | return $this->_Memcached->get($key); 187 | } 188 | 189 | /** 190 | * 删除指定的缓存 191 | * 192 | * @access public 193 | * 194 | * @param string $key 所要删除数据的Key 195 | * 196 | * @return boolean 197 | */ 198 | public function delete($key) { 199 | 200 | //参数分析 201 | if (!$key) { 202 | return false; 203 | } 204 | 205 | return $this->_Memcached->delete($key); 206 | } 207 | 208 | /** 209 | * 数据自增 210 | * 211 | * @access public 212 | * 213 | * @author ColaPHP 214 | * @param string $key 数据key 215 | * @param integer $value 自增数据值 216 | * 217 | * @return boolean 218 | */ 219 | public function increment($key, $value = 1) { 220 | 221 | //参数分析 222 | if (!$key) { 223 | return false; 224 | } 225 | 226 | return $this->_Memcached->increment($key, $value); 227 | } 228 | 229 | /** 230 | * 数据自减 231 | * 232 | * @access public 233 | * 234 | * @param string $key 数据key 235 | * @param integer $value 自减数据值 236 | * 237 | * @return boolean 238 | */ 239 | public function decrement($key, $value = 1) { 240 | 241 | //参数分析 242 | if (!$key) { 243 | return false; 244 | } 245 | 246 | return $this->_Memcached->decrement($key, $value); 247 | } 248 | 249 | /** 250 | * 清除所有的缓存数据 251 | * 252 | * @access public 253 | * @return boolean 254 | */ 255 | public function clear() { 256 | 257 | return $this->_Memcached->flush(); 258 | } 259 | 260 | /** 261 | * 返回memcached实例化对象 262 | * 263 | * @access public 264 | * @return object 265 | */ 266 | public function getConnection() { 267 | 268 | return $this->_Memcached; 269 | } 270 | 271 | /** 272 | * 析构函数 273 | * 274 | * @access public 275 | * @return boolean 276 | */ 277 | public function __destruct() { 278 | 279 | if ($this->_Memcached) { 280 | $this->_Memcached->quit(); 281 | } 282 | 283 | return true; 284 | } 285 | 286 | /** 287 | * 单例模式 288 | * 289 | * 用于本类的单例模式(singleton)实例化 290 | * 291 | * @access public 292 | * 293 | * @param array $params 数据库连接参数 294 | * 295 | * @return object 296 | */ 297 | public static function getInstance($params = null) { 298 | 299 | if (!self::$_instance) { 300 | self::$_instance = new self($params); 301 | } 302 | 303 | return self::$_instance; 304 | } 305 | } -------------------------------------------------------------------------------- /doitphp/library/Curl.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Curl.php 2.0 2012-12-22 21:45:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Curl { 19 | 20 | /** 21 | * 浏览器的AGENT信息 22 | * 23 | * @var string 24 | */ 25 | protected static $_userAgent = null; 26 | 27 | /** 28 | * cookie的存贮文件路径 29 | * 30 | * @var string 31 | */ 32 | protected static $_cookieFilePath = null; 33 | 34 | /** 35 | * 是否curl get获取页面信息时支持cookie存贮 36 | * 37 | * @var boolean 38 | */ 39 | protected static $_cookieSupport = false; 40 | 41 | 42 | /** 43 | * 设置浏览器的AGENT信息 44 | * 45 | * @access public 46 | * 47 | * @param string $userAgent 浏览器的AGENT信息 48 | * 49 | * @return object 50 | */ 51 | public function setUserAgent($userAgent) { 52 | 53 | //参数分析 54 | if (!$userAgent) { 55 | return false; 56 | } 57 | 58 | self::$_userAgent = $userAgent; 59 | 60 | return $this; 61 | } 62 | 63 | /** 64 | * 设置cookie的存贮文件路径 65 | * 66 | * @access public 67 | * 68 | * @param string $filePath 存贮cookie的文件路径 69 | * 70 | * @return object 71 | */ 72 | public function setCookieFile($filePath) { 73 | 74 | //参数分析 75 | if (!$filePath) { 76 | return false; 77 | } 78 | 79 | self::$_cookieSupport = true; 80 | self::$_cookieFilePath = $filePath; 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * 设置cookie功能是否开启 87 | * 88 | * @access public 89 | * 90 | * @param boolean $isTurnOn 是否开启 91 | * 92 | * @return object 93 | */ 94 | public function setCookieStatus($isTurnOn = true) { 95 | 96 | self::$_cookieSupport = $isTurnOn; 97 | 98 | return $this; 99 | } 100 | 101 | /** 102 | * 用CURL模拟获取网页页面内容 103 | * 104 | * @access public 105 | * 106 | * @param string $url 所要获取内容的网址 107 | * @param array $data 所要提交的数据 108 | * @param string $proxy 代理设置 109 | * @param integer $expire 时间限制 110 | * 111 | * @return string 112 | * 113 | * @example 114 | * 115 | * $url = 'http://www.doitphp.com/'; 116 | * 117 | * $curl = new Curl(); 118 | * $curl ->get($url); 119 | */ 120 | public static function get($url, $data = array(), $proxy = null, $expire = 30) { 121 | 122 | //参数分析 123 | if (!$url) { 124 | return false; 125 | } 126 | 127 | //分析是否开启SSL加密 128 | $ssl = strtolower(substr($url, 0, 8)) == 'https://' ? true : false; 129 | 130 | //读取网址内容 131 | $ch = curl_init(); 132 | 133 | //设置代理 134 | if (!$proxy) { 135 | curl_setopt ($ch, CURLOPT_PROXY, $proxy); 136 | } 137 | 138 | //分析网址中的参数 139 | if ($data) { 140 | $paramUrl = http_build_query($data, '', '&'); 141 | $extStr = (strpos($url, '?') !== false) ? '&' : '?'; 142 | $url = $url . (($paramUrl) ? $extStr . $paramUrl : ''); 143 | } 144 | 145 | curl_setopt($ch, CURLOPT_URL, $url); 146 | 147 | if ($ssl) { 148 | // 对认证证书来源的检查 149 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 150 | // 从证书中检查SSL加密算法是否存在 151 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); 152 | } 153 | 154 | if (self::$_cookieSupport === true) { 155 | $cookieFile = self::_parseCookieFile(); 156 | //cookie设置 157 | curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 158 | curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 159 | } 160 | 161 | //设置浏览器 162 | if (self::$_userAgent || $_SERVER['HTTP_USER_AGENT']) { 163 | curl_setopt($ch, CURLOPT_USERAGENT, (!self::$_userAgent) ? $_SERVER['HTTP_USER_AGENT'] : self::$_userAgent); 164 | curl_setopt($ch, CURLOPT_HEADER, 0); 165 | } 166 | 167 | //使用自动跳转 168 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 169 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 170 | curl_setopt($ch, CURLOPT_TIMEOUT, $expire); 171 | 172 | $content = curl_exec($ch); 173 | curl_close($ch); 174 | 175 | return $content; 176 | } 177 | 178 | /** 179 | * 获取cookie存贮文件的路径 180 | * 181 | * @access protected 182 | * @return stirng 183 | */ 184 | protected static function _parseCookieFile() { 185 | 186 | //分析cookie数据存贮文件 187 | if (self::$_cookieFilePath) { 188 | return self::$_cookieFilePath; 189 | } 190 | 191 | return CACHE_PATH . '/temp/' . md5('doitphp_curl_cookie') . '.txt'; 192 | } 193 | 194 | /** 195 | * 用CURL模拟提交数据 196 | * 197 | * @access public 198 | * 199 | * @param string $url post所要提交的网址 200 | * @param array $data 所要提交的数据 201 | * @param string $proxy 代理设置 202 | * @param integer $expire 所用的时间限制 203 | * 204 | * @return string 205 | */ 206 | public static function post($url, $data = array(), $proxy = null, $expire = 30) { 207 | 208 | //参数分析 209 | if (!$url) { 210 | return false; 211 | } 212 | 213 | //分析是否开启SSL加密 214 | $ssl = strtolower(substr($url, 0, 8)) == 'https://' ? true : false; 215 | 216 | //读取网址内容 217 | $ch = curl_init(); 218 | 219 | //设置代理 220 | if (!$proxy) { 221 | curl_setopt ($ch, CURLOPT_PROXY, $proxy); 222 | } 223 | 224 | curl_setopt($ch, CURLOPT_URL, $url); 225 | 226 | if ($ssl) { 227 | // 对认证证书来源的检查 228 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 229 | // 从证书中检查SSL加密算法是否存在 230 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1); 231 | } 232 | 233 | if (self::$_cookieSupport === true) { 234 | $cookieFile = self::_parseCookieFile(); 235 | //cookie设置 236 | curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile); 237 | curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile); 238 | } 239 | 240 | //设置浏览器 241 | if (self::$_userAgent || $_SERVER['HTTP_USER_AGENT']) { 242 | curl_setopt($ch, CURLOPT_USERAGENT, (!self::$_userAgent) ? $_SERVER['HTTP_USER_AGENT'] : self::$_userAgent); 243 | curl_setopt($ch, CURLOPT_HEADER, 0); 244 | } 245 | 246 | //发送一个常规的Post请求 247 | curl_setopt($ch, CURLOPT_POST, true); 248 | //Post提交的数据包 249 | if ($data) { 250 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 251 | } 252 | 253 | //使用自动跳转 254 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 255 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 256 | curl_setopt($ch, CURLOPT_TIMEOUT, $expire); 257 | 258 | $content = curl_exec($ch); 259 | curl_close($ch); 260 | 261 | return $content; 262 | } 263 | } -------------------------------------------------------------------------------- /doitphp/library/cache/Memcache.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright (c) 2010 Tommy Software Studio 9 | * @link http://www.doitphp.com 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Cache_Memcache.php 2.0 2012-12-30 18:00:01Z tommy $ 12 | * @package cache 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | /** 21 | * 使用说明 22 | * 23 | * @author tommy 24 | * 25 | * @example 26 | * 27 | * 参数范例 28 | * $memOptions = array( 29 | * 'servers'=> array( 30 | * array('host'=>'127.0.0.1', 'port'=>11211, 'persistent'=>true, 'weight'=>1, 'timeout'=>60), 31 | * array('host'=>'192.168.0.101', 'port'=>11211, 'persistent'=>true, 'weight'=>2, 'timeout'=>60), 32 | * ), 33 | * 'compressed'=>true, 34 | * 'expire' => 3600, 35 | * 'persistent' => true, 36 | * ); 37 | * 38 | * 实例化 39 | * 40 | * 法一: 41 | * $memcache = new Cache_Memcache($memOptions); 42 | * 43 | */ 44 | 45 | class Cache_Memcache { 46 | 47 | /** 48 | * 单例模式实例化本类 49 | * 50 | * @var object 51 | */ 52 | protected static $_instance = null; 53 | 54 | /** 55 | * Memcached实例 56 | * 57 | * @var objeact 58 | */ 59 | private $_Memcache; 60 | 61 | /** 62 | * 默认的缓存服务器 63 | * 64 | * @var array 65 | */ 66 | protected $_defaultServer = array( 67 | /** 68 | * 缓存服务器地址或主机名 69 | */ 70 | 'host' => '127.0.0.1', 71 | 72 | /** 73 | * 缓存服务器端口 74 | */ 75 | 'port' => '11211', 76 | ); 77 | 78 | /** 79 | * 默认的缓存策略 80 | * 81 | * @var array 82 | */ 83 | protected $_defaultOptions = array( 84 | 85 | /** 86 | * 缓存服务器配置,参看$_defaultServer 87 | * 允许多个缓存服务器 88 | */ 89 | 'servers' => array(), 90 | 91 | /** 92 | * 是否压缩缓存数据 93 | */ 94 | 'compressed' => false, 95 | 96 | /** 97 | * 缓存有效时间 98 | * 99 | * 如果设置为 0 表示缓存永不过期 100 | */ 101 | 'expire' => 900, 102 | 103 | /** 104 | * 是否使用持久连接 105 | */ 106 | 'persistent' => true, 107 | ); 108 | 109 | /** 110 | * 构造方法 111 | * 112 | * @access public 113 | * 114 | * @param array $params 数据库连接参数,如主机名,数据库用户名,密码等 115 | * 116 | * @return boolean 117 | */ 118 | public function __construct($options = null) { 119 | 120 | //分析memcache扩展模块的加载 121 | if (!extension_loaded('memcache')) { 122 | Response::halt('The memcache extension to be loaded before use!'); 123 | } 124 | 125 | //获取Memcache服务器连接参数 126 | if (!$options || !is_array($options)) { 127 | $options = Configure::get('memcache'); 128 | } 129 | 130 | if (is_array($options) && $options) { 131 | $this->_defaultOptions = $options + $this->_defaultOptions; 132 | } 133 | 134 | if (!$this->_defaultOptions['servers']) { 135 | $this->_defaultOptions['servers'][] = $this->_defaultServer; 136 | } 137 | 138 | $this->_Memcache = new Memcache(); 139 | 140 | foreach ($this->_defaultOptions['servers'] as $server) { 141 | $server += array('host' => '127.0.0.1', 'port' => 11211, 'persistent' => true); 142 | $this->_Memcache->addServer($server['host'], $server['port'], $this->_defaultOptions['persistent']); 143 | } 144 | 145 | return true; 146 | } 147 | 148 | /** 149 | * 写入缓存 150 | * 151 | * @access public 152 | * 153 | * @param string $key 缓存Key 154 | * @param mixed $data 缓存内容 155 | * @param int $expire 缓存时间(秒) 156 | * 157 | * @return boolean 158 | */ 159 | public function set($key, $data, $expire = null) { 160 | 161 | //参数分析 162 | if (!$key) { 163 | return false; 164 | } 165 | if (is_null($expire)) { 166 | $expire = $this->_defaultOptions['expire']; 167 | } 168 | 169 | return $this->_Memcache->set($key, $data, (!$this->_defaultOptions['compressed']) ? 0 : MEMCACHE_COMPRESSED, $expire); 170 | } 171 | 172 | /** 173 | * 读取缓存,失败或缓存撒失效时返回false 174 | * 175 | * @access public 176 | * 177 | * @param string $key 所要读取数据的key 178 | * 179 | * @return mixed 180 | */ 181 | public function get($key) { 182 | 183 | //参数分析 184 | if (!$key) { 185 | return false; 186 | } 187 | 188 | return $this->_Memcache->get($key); 189 | } 190 | 191 | /** 192 | * 删除指定的缓存 193 | * 194 | * @access public 195 | * 196 | * @param string $key 所要删除数据的Key 197 | * 198 | * @return boolean 199 | */ 200 | public function delete($key) { 201 | 202 | //参数分析 203 | if (!$key) { 204 | return false; 205 | } 206 | 207 | return $this->_Memcache->delete($key); 208 | } 209 | 210 | /** 211 | * 数据自增 212 | * 213 | * @access public 214 | * 215 | * @author ColaPHP 216 | * @param string $key 数据key 217 | * @param integer $value 自增数据值 218 | * 219 | * @return boolean 220 | */ 221 | public function increment($key, $value = 1) { 222 | 223 | //参数分析 224 | if (!$key) { 225 | return false; 226 | } 227 | 228 | return $this->_Memcache->increment($key, $value); 229 | } 230 | 231 | /** 232 | * 数据自减 233 | * 234 | * @access public 235 | * 236 | * @param string $key 数据key 237 | * @param integer $value 自减数据值 238 | * 239 | * @return boolean 240 | */ 241 | public function decrement($key, $value = 1) { 242 | 243 | //参数分析 244 | if (!$key) { 245 | return false; 246 | } 247 | 248 | return $this->_Memcache->decrement($key, $value); 249 | } 250 | 251 | /** 252 | * 清除所有的缓存数据 253 | * 254 | * @access public 255 | * @return boolean 256 | */ 257 | public function clear() { 258 | 259 | return $this->_Memcache->flush(); 260 | } 261 | 262 | /** 263 | * 返回memcached实例化对象 264 | * 265 | * @access public 266 | * @return object 267 | */ 268 | public function getConnection() { 269 | 270 | return $this->_Memcache; 271 | } 272 | 273 | /** 274 | * 析构函数 275 | * 276 | * @access public 277 | * @return boolean 278 | */ 279 | public function __destruct() { 280 | 281 | if ($this->_Memcache) { 282 | $this->_Memcache->close(); 283 | } 284 | 285 | return true; 286 | } 287 | 288 | /** 289 | * 单例模式 290 | * 291 | * 用于本类的单例模式(singleton)实例化 292 | * 293 | * @access public 294 | * 295 | * @param array $params 数据库连接参数 296 | * 297 | * @return object 298 | */ 299 | public static function getInstance($params = null) { 300 | 301 | if (!self::$_instance) { 302 | self::$_instance = new self($params); 303 | } 304 | 305 | return self::$_instance; 306 | } 307 | } -------------------------------------------------------------------------------- /doitphp/library/Ftp.php: -------------------------------------------------------------------------------- 1 | , tommy 6 | * @copyright CopyRight DoitPHP team, initphp team 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Ftp.php 2.0 2012-12-23 00:05:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Ftp { 19 | 20 | /** 21 | * FTP 连接 ID 22 | * 23 | * @var object 24 | */ 25 | private $_linkId; 26 | 27 | 28 | /** 29 | * 连接FTP服务器 30 | * 31 | * @access public 32 | * 33 | * @param string $server FTP服务器地址 34 | * @param integer $port FTP服务器端口 35 | * @param string $username FTP用户名 36 | * @param string $password FTP密码 37 | * 38 | * @return boolean 39 | */ 40 | public function connect($server, $port = 21, $username, $password) { 41 | 42 | //参数分析 43 | if (!$server || !$username || !$password) { 44 | return false; 45 | } 46 | 47 | try { 48 | $this->_linkId = @ftp_connect($server, $port); 49 | if (!@ftp_login($this->_linkId, $username, $password)){ 50 | Response::showMsg('Ftp Server 登陆失败'); 51 | } 52 | 53 | //打开被动模拟 54 | ftp_pasv($this->_linkId, 1); 55 | 56 | return true; 57 | } catch (Exception $exception) { 58 | 59 | //抛出异常信息 60 | throw new DoitException('Ftp server connect error!
' . $exception->getMessage(), $exception->getCode()); 61 | } 62 | } 63 | 64 | /** 65 | * FTP-文件上传 66 | * 67 | * @access public 68 | * 69 | * @param string $localFile 本地文件 70 | * @param string $ftpFile Ftp文件 71 | * 72 | * @return boolean 73 | */ 74 | public function upload($localFile, $ftpFile) { 75 | 76 | if (!$localFile || !$ftpFile) { 77 | return false; 78 | } 79 | 80 | $ftpPath = dirname($ftpFile); 81 | if ($ftpPath) { 82 | //创建目录 83 | $this->makeDir($ftpPath); 84 | @ftp_chdir($this->_linkId, $ftpPath); 85 | $ftpFile = basename($ftpFile); 86 | } 87 | 88 | $ret = ftp_nb_put($this->_linkId, $ftpFile, $localFile, FTP_BINARY); 89 | while ($ret == FTP_MOREDATA) { 90 | $ret = ftp_nb_continue($this->_linkId); 91 | } 92 | 93 | if ($ret != FTP_FINISHED) { 94 | return false; 95 | } 96 | 97 | return true; 98 | } 99 | 100 | /** 101 | * FTP-文件下载 102 | * 103 | * @access public 104 | * 105 | * @param string $localFile 本地文件 106 | * @param string $ftpFile Ftp文件 107 | * 108 | * @return boolean 109 | */ 110 | public function download($localFile, $ftpFile) { 111 | 112 | if (!$localFile || !$ftpFile) { 113 | return false; 114 | } 115 | 116 | $ret = ftp_nb_get($this->_linkId, $localFile, $ftpFile, FTP_BINARY); 117 | while ($ret == FTP_MOREDATA) { 118 | $ret = ftp_nb_continue ($this->_linkId); 119 | } 120 | 121 | if ($ret != FTP_FINISHED) { 122 | return false; 123 | } 124 | 125 | return true; 126 | } 127 | 128 | /** 129 | * FTP-创建目录 130 | * 131 | * @access public 132 | * 133 | * @param string $path 路径地址 134 | * 135 | * @return boolean 136 | */ 137 | public function makeDir($path) { 138 | 139 | if (!$path) { 140 | return false; 141 | } 142 | 143 | $dir = explode("/", $path); 144 | $path = ftp_pwd($this->_linkId) . '/'; 145 | $ret = true; 146 | for ($i=0; $i_linkId, $path)) { 149 | if (!@ftp_mkdir($this->_linkId, $dir[$i])) { 150 | $ret = false; 151 | break; 152 | } 153 | } 154 | @ftp_chdir($this->_linkId, $path); 155 | } 156 | 157 | if (!$ret) { 158 | return false; 159 | } 160 | 161 | return true; 162 | } 163 | 164 | /** 165 | * FTP-删除文件目录 166 | * 167 | * @access public 168 | * 169 | * @param string $dir 删除文件目录 170 | * 171 | * @return boolean 172 | */ 173 | public function deleteDir($dir) { 174 | 175 | //参数分析 176 | if (!$dir) { 177 | return false; 178 | } 179 | 180 | $dir = $this->checkpath($dir); 181 | if (@!ftp_rmdir($this->_linkId, $dir)) { 182 | return false; 183 | } 184 | 185 | return true; 186 | } 187 | 188 | /** 189 | * FTP-删除文件 190 | * 191 | * @access public 192 | * 193 | * @param string $file 删除文件 194 | * 195 | * @return boolean 196 | */ 197 | public function deleteFile($file) { 198 | 199 | //参数分析 200 | if (!$file) { 201 | return false; 202 | } 203 | 204 | $file = $this->checkpath($file); 205 | if (@!ftp_delete($this->_linkId, $file)) { 206 | return false; 207 | } 208 | 209 | return true; 210 | } 211 | 212 | /** 213 | * FTP-FTP上的文件列表 214 | * 215 | * @access public 216 | * 217 | * @param string $path 路径 218 | * 219 | * @return boolean 220 | */ 221 | public function nlist($path = '/') { 222 | 223 | return ftp_nlist($this->_linkId, $path); 224 | } 225 | 226 | /** 227 | * FTP-改变文件权限值 228 | * 229 | * @access public 230 | * 231 | * @param string $file 文件 232 | * @param string $value 值 233 | * 234 | * @return boolean 235 | */ 236 | public function chmod($file, $value = 0777) { 237 | 238 | //参数分析 239 | if (!$file) { 240 | return false; 241 | } 242 | 243 | return @ftp_chmod($this->_linkId, $value, $file); 244 | } 245 | 246 | /** 247 | * FTP-返回文件大小 248 | * 249 | * @access public 250 | * 251 | * @param string $file 文件 252 | * 253 | * @return boolean 254 | */ 255 | public function fileSize($file) { 256 | 257 | //参数分析 258 | if (!$file) { 259 | return false; 260 | } 261 | 262 | return ftp_size($this->_linkId, $file); 263 | } 264 | 265 | /** 266 | * FTP-文件修改时间 267 | * 268 | * @access public 269 | * 270 | * @param string $file 文件 271 | * 272 | * @return boolean 273 | */ 274 | public function mdtime($file) { 275 | 276 | //参数分析 277 | if (!$file) { 278 | return false; 279 | } 280 | 281 | return ftp_mdtm($this->_linkId, $file); 282 | } 283 | 284 | /** 285 | * FTP-更改ftp上的文件名称 286 | * 287 | * @access public 288 | * 289 | * @param string $oldname 旧文件 290 | * @param string $newname 新文件名称 291 | * 292 | * @return boolean 293 | */ 294 | public function rename($oldname, $newname) { 295 | 296 | //参数分析 297 | if (!$oldname || !$newname) { 298 | return false; 299 | } 300 | 301 | return ftp_rename ($this->_linkId, $oldname, $newname); 302 | } 303 | 304 | /** 305 | * 析构函数 306 | * 307 | * @access public 308 | * @return boolean 309 | */ 310 | public function __destruct() { 311 | 312 | if ($this->_linkId) { 313 | ftp_close($this->_linkId); 314 | } 315 | 316 | return true; 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /doitphp/library/MongoDb.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright (c) 2010 Tommy Software Studio 9 | * @link http://www.doitphp.com 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: MongoDb.php 2.0 2012-12-29 21:31:01Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class MongoDb { 21 | 22 | /** 23 | * 单例模式实例化本类 24 | * 25 | * @var object 26 | */ 27 | protected static $_instance = null; 28 | 29 | /** 30 | * 数据库连接实例化对象名 31 | * 32 | * @var object 33 | */ 34 | protected $_dbConnection = null; 35 | 36 | /** 37 | * mongo实例化对象 38 | * 39 | * @var object 40 | */ 41 | protected $_mongo = null; 42 | 43 | /** 44 | * 数据库连接参数默认值 45 | * 46 | * @var array 47 | */ 48 | protected $_defaultConfig = array( 49 | 'dsn' => 'mongodb://localhost:27017', 50 | 'option' => array('connect' => true), 51 | ); 52 | 53 | /** 54 | * 构造方法 55 | * 56 | * 用于初始化运行环境,或对基本变量进行赋值 57 | * 58 | * @access public 59 | * 60 | * @param array $params 数据库连接参数,如主机名,数据库用户名,密码等 61 | * 62 | * @return boolean 63 | */ 64 | public function __construct($params = array()) { 65 | 66 | if (!extension_loaded('mongo')) { 67 | Response::halt('The mongo extension to be loaded!'); 68 | } 69 | 70 | //参数分析 71 | if (!$params || !is_array($params)) { 72 | //加载数据库配置文件. 73 | $params = Configure::get('mongo'); 74 | } 75 | 76 | $params = is_array($params) ? $params + $this->_defaultConfig : $this->_defaultConfig; 77 | if (!isset($params['dbname']) || !$params['dbname']) { 78 | Response::halt('The file of MongoDB config is error, dbname is not found!'); 79 | } 80 | 81 | try { 82 | //实例化mongo 83 | $this->_mongo = new Mongo($params['dsn'], $params['option']); 84 | 85 | //连接mongo数据库 86 | $this->_dbConnection = $this->_mongo->selectDB($params['dbname']); 87 | 88 | //用户登录 89 | if (isset($params['username']) && isset($params['password'])) { 90 | $this->_dbConnection->authenticate($params['username'], $params['password']); 91 | } 92 | 93 | return true; 94 | } catch (Exception $exception) { 95 | 96 | //抛出异常信息 97 | throw new DoitException('MongoDb connect error!
' . $exception->getMessage(), $exception->getCode()); 98 | } 99 | } 100 | 101 | /** 102 | * Select Collection 103 | * 104 | * @author ColaPHP 105 | * 106 | * @access public 107 | * 108 | * @param string $collection 集合名称(相当于关系数据库中的表) 109 | * 110 | * @return object 111 | */ 112 | public function collection($collection) { 113 | 114 | return $this->_dbConnection->selectCollection($collection); 115 | } 116 | 117 | /** 118 | * 查询一条记录 119 | * 120 | * @access public 121 | * 122 | * @param string $collnections 集合名称(相当于关系数据库中的表) 123 | * @param array $query 查询的条件array(key=>value) 相当于key=value 124 | * @param array fields 需要列表的字段信息array(filed1,filed2) 125 | * 126 | * @return array 127 | */ 128 | public function getOne($collnections, $query, $fields=array()) { 129 | 130 | return $this->collection($collnections)->findOne($query, $fields); 131 | } 132 | 133 | /** 134 | * 查询多条记录 135 | * 136 | * @access public 137 | * 138 | * @param string $collnections 集合名称(相当于关系数据库中的表) 139 | * @param array $query 查询的条件array(key=>value) 相当于key=value 140 | * @param array fields 需要列表的字段信息array(filed1,filed2) 141 | * 142 | * @return array 143 | */ 144 | public function getAll($collnections, $query, $fields=array()) { 145 | 146 | $result = array(); 147 | $cursor = $this->collection($collnections)->find($query, $fields); 148 | while ($cursor->hasNext()) { 149 | $result[] = $cursor->getNext(); 150 | } 151 | 152 | return $result; 153 | } 154 | 155 | /** 156 | * 插入数据 157 | * 158 | * @access public 159 | * 160 | * @param string $collnections 集合名称(相当于关系数据库中的表) 161 | * @param array $data 所要写入的数据信息 162 | * 163 | * @return boolean 164 | */ 165 | public function insert($collnections, $data) { 166 | 167 | return $this->collection($collnections)->insert($data); 168 | } 169 | 170 | /** 171 | * 更改数据 172 | * 173 | * @access public 174 | * 175 | * @param string $collnections 集合名称(相当于关系数据库中的表) 176 | * @param array $query 查询的条件array(key=>value) 相当于key=value 177 | * @param array $data 所要更改的信息 178 | * @param array $options 选项 179 | * 180 | * @return boolean 181 | */ 182 | public function update($collection, $query, $data, $options=array('safe'=>true,'multiple'=>true)) { 183 | 184 | return $this->collection($collection)->update($query, $data, $options); 185 | } 186 | 187 | /** 188 | * 删除数据 189 | * 190 | * @access public 191 | * 192 | * @param string $collnections 集合名称(相当于关系数据库中的表) 193 | * @param array $query 查询的条件array(key=>value) 相当于key=value 194 | * @param array $option 选项 195 | * 196 | * @return boolean 197 | */ 198 | public function delete($collection, $query, $option=array("justOne"=>false)) { 199 | 200 | return $this->collection($collection)->remove($query, $option); 201 | } 202 | 203 | /** 204 | * MongoId 205 | * 206 | * @author ColaPHP 207 | * 208 | * @access public 209 | * 210 | * @param string $id 获取mongoId 211 | * 212 | * @return object 213 | */ 214 | public static function id($id = null) 215 | { 216 | return new MongoId($id); 217 | } 218 | 219 | /** 220 | * MongoTimestamp 221 | * 222 | * @author ColaPHP 223 | * 224 | * @access public 225 | * 226 | * @param int $sec 227 | * @param int $inc 228 | * 229 | * @return MongoTimestamp 230 | */ 231 | public static function Timestamp($sec = null, $inc = 0) 232 | { 233 | if (!$sec) { 234 | $sec = $_SERVER['REQUEST_TIME']; 235 | } 236 | 237 | return new MongoTimestamp($sec, $inc); 238 | } 239 | 240 | /** 241 | * GridFS 242 | * 243 | * @author ColaPHP 244 | * 245 | * @access public 246 | * 247 | * @return object 248 | */ 249 | public function gridFS($prefix = 'fs') 250 | { 251 | return $this->_dbConnection->getGridFS($prefix); 252 | } 253 | 254 | /** 255 | * 析构函数 256 | * 257 | * 程序执行完毕,打扫战场 258 | * 259 | * @access public 260 | * 261 | * @return void 262 | */ 263 | public function __destruct() { 264 | 265 | if ($this->_dbConnection) { 266 | $this->_dbConnection = null; 267 | } 268 | 269 | if ($this->_mongo) { 270 | $this->_mongo->close(); 271 | } 272 | 273 | return true; 274 | } 275 | 276 | /** 277 | * 单例模式 278 | * 279 | * 用于本类的单例模式(singleton)实例化 280 | * 281 | * @access public 282 | * 283 | * @param array $params 数据库连接参数,如数据库服务器名,用户名,密码等 284 | * 285 | * @return object 286 | */ 287 | public static function getInstance($params = array()) { 288 | 289 | if (!self::$_instance) { 290 | self::$_instance = new self($params); 291 | } 292 | 293 | return self::$_instance; 294 | } 295 | 296 | } -------------------------------------------------------------------------------- /doitphp/core/Response.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Response.php 2.0 2012-11-28 00:50:27Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | abstract class Response { 19 | 20 | /** 21 | * 设置页面编码 22 | * 23 | * @access public 24 | * 25 | * @param string $encode 编码名称 26 | * 27 | * @return void 28 | */ 29 | public static function charset($encode = 'UTF-8') { 30 | 31 | header("Content-Type:text/html; charset={$encode}"); 32 | 33 | return true; 34 | } 35 | 36 | /** 37 | * 禁用浏览器缓存 38 | * 39 | * @access public 40 | * @return boolean 41 | */ 42 | public static function noCache() { 43 | 44 | header("Cache-Control: no-store, no-cache, must-revalidate"); 45 | header("Cache-Control: post-check=0, pre-check=0", false); 46 | header("Pragma: no-cache"); 47 | 48 | return true; 49 | } 50 | 51 | /** 52 | * 设置网页生存周期 53 | * 54 | * @access public 55 | * 56 | * @param integer $seconds 生存周期(单位:秒) 57 | * 58 | * @return boolean 59 | */ 60 | public static function expires($seconds = 1800) { 61 | 62 | $time = date('D, d M Y H:i:s', $_SERVER['REQUEST_TIME'] + $seconds) . ' GMT'; 63 | header("Expires: {$time}"); 64 | 65 | return true; 66 | } 67 | 68 | /** 69 | * 网址(URL)跳转操作 70 | * 71 | * 页面跳转方法,例:运行页面跳转到自定义的网址(即:URL重定向) 72 | * 73 | * @access public 74 | * 75 | * @param string $url 所要跳转的网址(URL) 76 | * 77 | * @return void 78 | */ 79 | public static function redirect($url) { 80 | 81 | //参数分析. 82 | if (!$url) { 83 | return false; 84 | } 85 | 86 | if (!headers_sent()) { 87 | header("Location:" . $url); 88 | }else { 89 | echo ''; 90 | } 91 | 92 | exit(); 93 | } 94 | 95 | /** 96 | * 显示提示信息操作 97 | * 98 | * 本方法支持URL的自动跳转,当显示时间有效期失效时则跳转到自定义网址,若跳转网址为空则函数不执行跳转功能,当自定义网址参数为-1时默认为:返回上一页。 99 | * 注:显示提示信息的页面模板内容可以自定义. 方法:在项目视图目录中的error子目录中新建message.php文件,自定义该文件内容。 100 | * 模板文件输出信息处代码参考doitphp子目录中文件:views/errors/message.php 101 | * 102 | * @access public 103 | * 104 | * @param string $message 所要显示的提示信息 105 | * @param string $targetUrl 所要跳转的自定义网址 106 | * @param integer $holdTime 显示信息的有效期,注:(单位:秒) 默认为3秒 107 | * 108 | * @return string 109 | */ 110 | public static function showMsg($message, $targetUrl = null, $holdTime = 3) { 111 | 112 | //参数分析 113 | if (!$message) { 114 | return false; 115 | } 116 | 117 | //当为Ajax调用时 118 | if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest')) { 119 | return self::ajax(false, $message); 120 | } 121 | 122 | //当自定义跳转网址存在时 123 | if ($targetUrl) { 124 | $holdTime = 1000 * $holdTime; 125 | //分析自定义网址是否为返回页 126 | if ($targetUrl == -1) { 127 | $targetUrl = 'javascript:history.go(-1);'; 128 | $message .= '
如果你的浏览器没反应,请点击这里...'; 129 | } else{ 130 | //防止网址过长,有换行引起跳转变不正确 131 | $targetUrl = str_replace(array("\n","\r"), '', $targetUrl); 132 | $message .= '
如果你的浏览器没反应,请点击这里...'; 133 | } 134 | $message .= ''; 135 | } 136 | 137 | $messageTemplateFile = BASE_PATH . '/views/errors/message.php'; 138 | 139 | is_file($messageTemplateFile) ? include_once $messageTemplateFile : include_once DOIT_ROOT . '/views/errors/message.php'; 140 | 141 | exit(); 142 | } 143 | 144 | /** 145 | * 优雅输出print_r()函数所要输出的内容 146 | * 147 | * 用于程序调试时,完美输出调试数据,功能相当于print_r().当第二参数为true时(默认为:false),功能相当于var_dump()。 148 | * 注:本方法一般用于程序调试 149 | * 150 | * @access public 151 | * 152 | * @param mixed $data 所要输出的数据 153 | * @param boolean $option 选项:true(显示var_dump()的内容)/ false(显示print_r()的内容) 154 | * 155 | * @return string 156 | */ 157 | public static function dump($data = null, $option = false) { 158 | 159 | //设置页面编码 160 | if (!headers_sent()) { 161 | header("Content-Type:text/html; charset=utf-8"); 162 | } 163 | 164 | //当输出print_r()内容时 165 | if(!$option){ 166 | echo '
';
167 |             print_r($data);
168 |             echo '
'; 169 | } else { 170 | ob_start(); 171 | var_dump($data); 172 | $output = ob_get_clean(); 173 | 174 | $output = str_replace('"', '', $output); 175 | $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); 176 | 177 | echo '
', $output, '
'; 178 | } 179 | 180 | exit(); 181 | } 182 | 183 | /** 184 | * 用于显示错误信息 185 | * 186 | * 若调试模式关闭时(即:DOIT_DEBUG为false时),则将错误信息并写入日志 187 | * 188 | * @access public 189 | * @param string $message 所要显示的错误信息 190 | * @return string 191 | */ 192 | public static function halt($message) { 193 | 194 | //参数分析 195 | if (!$message) { 196 | return false; 197 | } 198 | 199 | //当为Ajax调用时 200 | if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest')) { 201 | return self::ajax(false, $message); 202 | } 203 | 204 | //调试模式下优雅输出错误信息 205 | $traces = debug_backtrace(); 206 | $traceString = ''; 207 | $sourceFile = $traces[0]['file'] . '(' . $traces[0]['line'] . ')'; 208 | 209 | if (defined('DOIT_DEBUG') && DOIT_DEBUG === true) { 210 | foreach ($traces as $key=>$trace) { 211 | //代码跟踪级别限制 212 | if ($key > 1) { 213 | break; 214 | } 215 | $argsString = ($trace['args'] && is_array($trace['args'])) ? '(' . implode('.', $trace['args']) . ')': ''; 216 | $traceString .= "#{$key} {$trace['file']}({$trace['line']}){$trace['class']}{$trace['type']}{$trace['function']}{$argsString}
"; 217 | } 218 | } 219 | 220 | //加载,分析,并输出excepiton文件内容 221 | include_once DOIT_ROOT . '/views/errors/exception.php'; 222 | 223 | if (defined('DOIT_DEBUG') && DOIT_DEBUG === false) { 224 | //写入程序运行日志 225 | Log::write($message); 226 | } 227 | 228 | //终止程序 229 | exit(); 230 | } 231 | 232 | /** 233 | * 输出供Ajax所调用的页面返回信息 234 | * 235 | * 返回json数据,供前台ajax调用 236 | * 237 | * @access public 238 | * 239 | * @param boolean $status 执行状态 : true/false 或 1/0 240 | * @param string $msg 返回信息, 默认为空 241 | * @param array $data 返回数据,支持数组。 242 | * 243 | * @return string 244 | */ 245 | public static function ajax($status, $msg = null, $data = array()) { 246 | 247 | $result = array(); 248 | $result['status'] = $status; 249 | $result['msg'] = !is_null($msg) ? $msg : ''; 250 | $result['data'] = $data; 251 | 252 | //设置页面编码 253 | header("Content-Type:text/html; charset=utf-8"); 254 | 255 | exit(json_encode($result)); 256 | } 257 | 258 | } -------------------------------------------------------------------------------- /doitphp/core/Widget.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Widget.php 2.0 2012-12-16 21:45:57Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | abstract class Widget extends Controller { 19 | 20 | /** 21 | * 视图变量数组容器 22 | * 23 | * @var array 24 | */ 25 | protected $_options = array(); 26 | 27 | /** 28 | * 视图目录路径 29 | * 30 | * @var string 31 | */ 32 | protected $_viewPath = null; 33 | 34 | /** 35 | * Widget的前函数(类方法) 36 | * 37 | * @access protected 38 | * @return boolean 39 | */ 40 | protected function init() { 41 | 42 | //获取当前视图的目录(当视图文件的格式为PHP时) 43 | if (VIEW_EXT == Configure::VIEW_EXT_PHP) { 44 | $this->_viewPath = BASE_PATH . '/views/widgets'; 45 | } 46 | 47 | return true; 48 | } 49 | 50 | /** 51 | * 加载视图处理类并完成视图类的实例化 52 | * 53 | * 注:本类方法为回调类方法。 54 | * 55 | * @access protected 56 | * @return object 57 | */ 58 | protected function initView() { 59 | 60 | //当视图文件格式为PHP时,采用Widget自身的视图机制。即:非View Class的视图机制 61 | if (VIEW_EXT == Configure::VIEW_EXT_PHP) { 62 | return null; 63 | } 64 | 65 | //分析视图类文件路径 66 | $filePath = DOIT_ROOT . '/core/WidgetTemplate.php'; 67 | 68 | //加载视图处理类文件 69 | Doit::loadFile($filePath); 70 | 71 | //实例化视图类 72 | $viewObject = WidgetTemplate::getInstance(); 73 | $viewObject->widgetId = $this->_getWidgetName(); 74 | 75 | return $viewObject; 76 | } 77 | 78 | /** 79 | * 设置视图文件布局结构视图的文件名(layout) 80 | * 81 | * 挂件(Widget)的视图机制不支持layout视图 82 | * 83 | * @access public 84 | * 85 | * @param string $layoutName 所要设置的layout名称。默认值为:null,即:不使用layout视图 86 | * 87 | * @return boolean 88 | */ 89 | public function setLayout($layoutName = null) { 90 | 91 | return false; 92 | } 93 | 94 | /** 95 | * 分析并加载视图缓存 96 | * 97 | * 注:挂件(Widget)的视图机制不支持视图缓存 98 | * 99 | * @access public 100 | * 101 | * @param string $cacheId 页面文件的缓存ID 102 | * @param integer $expire 页面缓存的生存周期 103 | * 104 | * @return mixed 105 | */ 106 | public function cache($cacheId = null, $expire = null) { 107 | 108 | return false; 109 | } 110 | 111 | /** 112 | * 显示当前页面的视图内容 113 | * 114 | * 注:挂件(Widget)的视图机制不支持Layout视图 115 | * 116 | * @access public 117 | * 118 | * @param string $fileName 视图名称 119 | * 120 | * @return string 121 | */ 122 | public function display($fileName = null) { 123 | 124 | //当视图格式为HTML时 125 | if (VIEW_EXT == Configure::VIEW_EXT_HTML) { 126 | return self::$_viewObject->display($fileName); 127 | } 128 | 129 | //模板变量赋值 130 | if ($this->_options) { 131 | extract($this->_options, EXTR_PREFIX_SAME, 'data'); 132 | //清空不必要的内存占用 133 | $this->_options = array(); 134 | } 135 | 136 | //当视图格式为PHP时 137 | $viewFile = $this->_parseViewFile($fileName); 138 | 139 | ob_start(); 140 | include $viewFile; 141 | $widgetContent = ob_get_clean(); 142 | 143 | echo $widgetContent; 144 | } 145 | 146 | /** 147 | * 视图变量赋值操作 148 | * 149 | * @access public 150 | * 151 | * @param mixed $keys 视图变量名 152 | * @param mixed $value 视图变量值 153 | * 154 | * @return void 155 | */ 156 | public function assign($keys, $value = null) { 157 | 158 | //参数分析 159 | if (!$keys) { 160 | return false; 161 | } 162 | 163 | //当视图格式为HTML时 164 | if (VIEW_EXT == Configure::VIEW_EXT_HTML) { 165 | return self::$_viewObject->assign($keys, $value); 166 | } 167 | 168 | if (!is_array($keys)) { 169 | $this->_options[$keys] = $value; 170 | return true; 171 | } 172 | 173 | foreach ($keys as $handle=>$lines) { 174 | $this->_options[$handle] = $lines; 175 | } 176 | 177 | return true; 178 | } 179 | 180 | /** 181 | * 加载并显示视图片段文件内容 182 | * 183 | * 相当于include 代码片段,当$return为:true时返回代码代码片段内容,反之则显示代码片段内容 184 | * 185 | * @access public 186 | * 187 | * @param string $fileName 视图片段文件名称 188 | * @param array $data 视图模板变量,注:数组型 189 | * @param boolean $return 视图内容是否为返回,当为true时为返回,为false时则为显示。 默认为:false 190 | * 191 | * @return string 192 | */ 193 | public function render($fileName = null, $data = array(), $return = false) { 194 | 195 | //分析视图文件路径 196 | $viewFile = $this->_parseViewFile($fileName); 197 | 198 | //模板变量赋值 199 | if ($data && is_array($data)) { 200 | extract($data, EXTR_PREFIX_SAME, 'data'); 201 | unset($data); 202 | } else { 203 | //当且仅当本方法在处理action视图(非视图片段)时,对本类assign()所传递的视图变量进行赋值 204 | if (!$fileName && $this->_options) { 205 | extract($this->_options, EXTR_PREFIX_SAME, 'data'); 206 | $this->_options = array(); 207 | } 208 | } 209 | 210 | //获取当前视图的页面内容(视图片段) 211 | ob_start(); 212 | include $viewFile; 213 | $widgetContent = ob_get_clean(); 214 | 215 | //返回信息 216 | if (!$return) { 217 | echo $widgetContent; 218 | } else { 219 | return $widgetContent; 220 | } 221 | } 222 | 223 | /** 224 | * 分析挂件(widget)的视图文件路径 225 | * 226 | * 注:这里的视图指的是挂件的视图文件(PHP格式) 227 | * 228 | * @access protected 229 | * 230 | * @param string $fileName 视图文件名。注:不含文件后缀 231 | * 232 | * @return string 233 | */ 234 | protected function _parseViewFile($fileName = null) { 235 | 236 | $fileName = (!$fileName) ? $this->_getWidgetName() : $fileName; 237 | $viewPath = $this->_viewPath . DS . $fileName . VIEW_EXT; 238 | 239 | //检查视图文件路径是否正确 240 | if (!is_file($viewPath)) { 241 | Response::halt("The widget view file: {$viewPath} is not found!"); 242 | } 243 | 244 | return $viewPath; 245 | } 246 | 247 | /** 248 | * 获取当前的视图目录的路径 249 | * 250 | * @access public 251 | * @return string 252 | */ 253 | public function getViewPath() { 254 | 255 | return $this->_viewPath; 256 | } 257 | 258 | /** 259 | * 设置当前的视图目录路径 260 | * 261 | * @access public 262 | * 263 | * @param string $viewPath 视图目录的路径 264 | * 265 | * @return boolean 266 | */ 267 | public function setViewPath($viewPath) { 268 | 269 | //参数分析 270 | if (!$viewPath) { 271 | return false; 272 | } 273 | 274 | $this->_viewPath = $viewPath; 275 | 276 | return true; 277 | } 278 | 279 | /** 280 | * 返回视图的实例化对象 281 | * 282 | * @access public 283 | * @return object 284 | */ 285 | public static function getView() { 286 | 287 | if (VIEW_EXT == Configure::VIEW_EXT_PHP) { 288 | return $this; 289 | } 290 | 291 | return self::$_viewObject; 292 | } 293 | 294 | /** 295 | * 获取当前Widget的名称 296 | * 297 | * @access protected 298 | * @return string 299 | */ 300 | protected function _getWidgetName() { 301 | 302 | return substr(get_class($this), 0, -6); 303 | } 304 | 305 | /** 306 | * 运行挂件 307 | * 308 | * @access public 309 | * 310 | * @param array $params 参数. 如array('id'=>23) 311 | * 312 | * @return void 313 | */ 314 | public function renderContent($params = null){ 315 | 316 | return true; 317 | } 318 | } -------------------------------------------------------------------------------- /doitphp/core/AutoLoad.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.doitphp.com 7 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: AutoLoad.php 2.0 2012-12-01 11:52:00Z tommy $ 10 | * @package core 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | abstract class AutoLoad { 19 | 20 | /** 21 | * DoitPHP核心类引导数组 22 | * 23 | * 用于自动加载文件运行时,引导路径 24 | * @var array 25 | */ 26 | private static $_coreClassArray = array( 27 | 'Request' => 'core/Request.php', 28 | 'Response' => 'core/Response.php', 29 | 'Model' => 'core/Model.php', 30 | 'DbCommand' => 'core/DbCommand.php', 31 | 'DbPdo' => 'core/DbPdo.php', 32 | 'Log' => 'core/Log.php', 33 | 'DoitException' => 'core/DoitException.php', 34 | 'Widget' => 'core/Widget.php', 35 | 'View' => 'core/View.php', 36 | 'Template' => 'core/Template.php', 37 | 'WidgetTemplate' => 'core/WidgetTemplate.php', 38 | 'Extension' => 'core/Extension.php', 39 | 'Pagination' => 'library/Pagination.php', 40 | 'File' => 'library/File.php', 41 | 'Html' => 'library/Html.php', 42 | 'Cookie' => 'library/Cookie.php', 43 | 'Session' => 'library/Session.php', 44 | 'Image' => 'library/Image.php', 45 | 'Captcha' => 'library/Captcha.php', 46 | 'Curl' => 'library/Curl.php', 47 | 'Client' => 'library/Client.php', 48 | 'Validation' => 'library/Validation.php', 49 | 'FileDownload' => 'library/FileDownload.php', 50 | 'FileUpload' => 'library/FileUpload.php', 51 | 'Excel' => 'library/Excel.php', 52 | 'Csv' => 'library/Csv.php', 53 | 'Security' => 'library/Security.php', 54 | 'Text' => 'library/Text.php', 55 | 'Encrypt' => 'library/Encrypt.php', 56 | 'Tree' => 'library/Tree.php', 57 | 'MongoDb' => 'library/MongoDb.php', 58 | 'Language' => 'library/Language.php', 59 | 'Cache_Memcached' => 'library/cache/Memcached.php', 60 | 'Cache_Memcache' => 'library/cache/Memcache.php', 61 | 'Cache_Redis' => 'library/cache/Redis.php', 62 | 'Cache_File' => 'library/cache/File.php', 63 | 'Pinyin' => 'library/Pinyin.php', 64 | 'Calendar' => 'library/Calendar.php', 65 | 'Benchmark' => 'library/Benchmark.php', 66 | 'HttpResponse' => 'library/HttpResponse.php', 67 | 'Ftp' => 'library/Ftp.php', 68 | ); 69 | 70 | /** 71 | * 项目文件的自动加载 72 | * 73 | * doitPHP系统自动加载核心类库文件(core目录内的文件)及运行所需的controller文件、model文件、widget文件等 74 | * 75 | * 注:并非程序初始化时将所有的controller,model等文件都统统加载完,再执行其它。 76 | * 理解本函数前一定要先理解AutoLoad的作用。 77 | * 当程序运行时发现所需的文件没有找到时,AutoLoad才会被激发,按照loadClass()的程序设计来完成对该文件的加载 78 | * 79 | * @access public 80 | * 81 | * @param string $className 所需要加载的类的名称,注:不含后缀名 82 | * 83 | * @return void 84 | */ 85 | public static function loadClass($className) { 86 | 87 | //doitPHP核心类文件的加载分析 88 | if (isset(self::$_coreClassArray[$className])) { 89 | //当$className在核心类引导数组中存在时, 加载核心类文件 90 | Doit::loadFile(DOIT_ROOT . DS . self::$_coreClassArray[$className]); 91 | } elseif (substr($className, -10) == 'Controller') { 92 | //controller文件自动载分析 93 | self::_loadTagFile($className, 'Controller'); 94 | } elseif (substr($className, -5) == 'Model') { 95 | //modlel文件自动加载分析 96 | self::_loadTagFile($className, 'Model'); 97 | } elseif (substr($className, -6) == 'Widget') { 98 | //加载所要运行的widget文件 99 | self::_loadTagFile($className, 'Widget'); 100 | } else { 101 | //加载所使用命名空间的类文件 102 | if (strpos($className, '\\') !== false) { 103 | $filePath = BASE_PATH . DS . str_replace('\\', DS, $className) . '.php'; 104 | if (!is_file($filePath)) { 105 | //当使用命名空间的文件不存在时,提示错误信息 106 | Response::halt('The File: ' . $filePath .' is not found !'); 107 | } 108 | Doit::loadFile($filePath); 109 | return true; 110 | } 111 | //分析加载扩展类文件目录(library)的文件 112 | if (!self::_loadTagFile($className, 'Library')) { 113 | //根据配置文件improt的引导设置,自动加载文件 114 | if (!self::_loadImportConfigFile($className)) { 115 | //最后,当运行上述自动加载规则,均没有加载所需要的文件时,提示错误信息 116 | Response::halt('The Class: ' . $className .' is not found !'); 117 | } 118 | } 119 | } 120 | 121 | return true; 122 | } 123 | 124 | /** 125 | * 自动加载标签文件 126 | * 127 | * @access private 128 | * 129 | * @param string $className 所需要加载的类的名称,注:不含后缀名 130 | * @param string $tagName 类文件的行为标签。如Controller, Widget, Model 131 | * 132 | * @return void 133 | */ 134 | private static function _loadTagFile($className, $tagName) { 135 | 136 | //分析标签文件目录路径 137 | switch ($tagName) { 138 | 139 | case 'Controller': 140 | $dirName = 'controllers'; 141 | //当controller文件存放于子目录时 142 | if (strpos($className, '_') !== false) { 143 | $childDirArray = explode('_', strtolower($className)); 144 | $className = ucfirst(array_pop($childDirArray)); 145 | $className = implode(DS, $childDirArray) . DS . $className; 146 | } 147 | break; 148 | 149 | case 'Model': 150 | $dirName = 'models'; 151 | break; 152 | 153 | case 'Widget': 154 | $dirName = 'widgets'; 155 | break; 156 | 157 | case 'Library': 158 | $dirName = 'library'; 159 | break; 160 | 161 | default: 162 | $dirName = 'library'; 163 | } 164 | 165 | //分析标签文件的实际路径 166 | $tagFilePath = BASE_PATH . DS . $dirName . DS . str_replace('_', DS, $className) . '.php'; 167 | 168 | //当标签文件存在时 169 | if (!is_file($tagFilePath)) { 170 | if ($tagName == 'Library') { 171 | return false; 172 | } 173 | //当所要加载的标签文件不存在时,显示错误提示信息 174 | Response::halt('The File: ' . $tagFilePath . ' is not found!'); 175 | } 176 | 177 | //加载标签文件 178 | Doit::loadFile($tagFilePath); 179 | return true; 180 | } 181 | 182 | /** 183 | * 加载自定义配置文件所引导的文件 184 | * 185 | * @access private 186 | * 187 | * @param string $className 所需要加载的类的名称,注:不含后缀名 188 | * 189 | * @return void 190 | */ 191 | private static function _loadImportConfigFile($className) { 192 | 193 | //定义自动加载状态。(true:已加载/false:未加载) 194 | $atuoLoadStatus = false; 195 | 196 | //分析配置文件import引导信息 197 | $importRules = Configure::get('import'); 198 | 199 | //当配置文件引导信息合法时 200 | if ($importRules && is_array($importRules)) { 201 | foreach ($importRules as $rules) { 202 | if (!$rules) { 203 | continue; 204 | } 205 | 206 | //当配置文件引导信息中含有*'时,将设置的规则中的*替换为所要加载的文件类名 207 | if (strpos($rules, '*') !== false) { 208 | $filePath = str_replace('*', $className, $rules); 209 | } else { 210 | $filePath = $rules . DS . str_replace('_', DS, $className) . '.php'; 211 | } 212 | 213 | //当自定义自动加载的文件存在时 214 | if (is_file($filePath)) { 215 | //加载文件 216 | Doit::loadFile($filePath); 217 | $atuoLoadStatus = true; 218 | break; 219 | } 220 | } 221 | } 222 | 223 | return $atuoLoadStatus; 224 | } 225 | } -------------------------------------------------------------------------------- /doitphp/core/Router.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: Router.php 2.0 2012-11-20 20:52:54Z tommy $ 12 | * @package core 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | abstract class Router { 21 | 22 | /** 23 | * 当网址格式为$_GET模式时,Ctroller、Action等路由变量的变量名 24 | * 25 | * @var string 26 | */ 27 | private static $_routerVar = 'router'; 28 | 29 | /** 30 | * 分析路由网址, 获取当前的Controller名及action名 31 | * 32 | * @access public 33 | * @return array 34 | */ 35 | public static function getRequest() { 36 | 37 | //当访问网址的格式时。如:http://yourdomain/index.php?router=member/list/index&id=23 38 | if (URL_FORMAT == Configure::GET_FORMAT) { 39 | 40 | if (isset($_GET[self::$_routerVar]) && $_GET[self::$_routerVar] == true) { 41 | 42 | $routerArray = explode(URL_SEGEMENTATION, trim($_GET[self::$_routerVar], URL_SEGEMENTATION)); 43 | 44 | //获取和分析网址中的路由信息 45 | if (isset($routerArray[0]) && $routerArray[0]) { 46 | //获取Controller、Action名称 47 | $controllerName = $routerArray[0]; 48 | $actionName = (isset($routerArray[1]) && $routerArray[1] == true) ? $routerArray[1] : DEFAULT_ACTION; 49 | 50 | return array('controller'=>$controllerName, 'action'=>$actionName); 51 | } 52 | } 53 | 54 | return array('controller'=>DEFAULT_CONTROLLER, 'action'=>DEFAULT_ACTION); 55 | } 56 | 57 | //当网址格式为路由网址时。如:http://yourdomain/index.php/member/list/mid/23/page/7 58 | if (isset($_SERVER['SCRIPT_NAME']) && isset($_SERVER['REQUEST_URI'])) { 59 | //网址分析 60 | $uri = self::_parseUri(); 61 | //将处理过后的有效URL进行分析,提取有用数据. 62 | $uriInfoArray = explode(URL_SEGEMENTATION, $uri); 63 | 64 | if (isset($uriInfoArray[0]) && $uriInfoArray[0] == true) { 65 | //获取controller及action名称 66 | $controllerName = $uriInfoArray[0]; 67 | $actionName = (isset($uriInfoArray[1]) && $uriInfoArray[1] == true) ? $uriInfoArray[1] : DEFAULT_ACTION; 68 | 69 | //变量重组,将网址(URL)中的参数变量及其值赋值到$_GET全局超级变量数组中 70 | if (($totalNum = sizeof($uriInfoArray)) > 3) { 71 | for ($i = 2; $i < $totalNum; $i += 2) { 72 | if (!isset($uriInfoArray[$i]) || !$uriInfoArray[$i] || !isset($uriInfoArray[$i + 1])) { 73 | continue; 74 | } 75 | $_GET[$uriInfoArray[$i]] = $uriInfoArray[$i + 1]; 76 | } 77 | } 78 | 79 | return array('controller'=>$controllerName, 'action'=>$actionName); 80 | } 81 | } 82 | 83 | return array('controller'=>DEFAULT_CONTROLLER, 'action'=>DEFAULT_ACTION); 84 | } 85 | 86 | /** 87 | * 在CLI模式下获取当前的Controller及Action名 88 | * 89 | * @access public 90 | * @return array 91 | */ 92 | public static function getCliRequest() { 93 | 94 | if(isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == true) { 95 | 96 | //获取Controller、Action名称 97 | $controllerName = $_SERVER['argv'][1]; 98 | $actionName = (isset($_SERVER['argv'][2]) && $_SERVER['argv'][2] == true) ? $_SERVER['argv'][2] : DEFAULT_ACTION; 99 | 100 | //分析并获取参数, 参数格式如: --param_name=param_value 101 | if (($totalNum = sizeof($_SERVER['argv'])) > 3) { 102 | for ($i = 3; $i < $totalNum; $i ++) { 103 | if (!isset($_SERVER['argv'][$i]) || !$_SERVER['argv'][$i]) { 104 | continue; 105 | } 106 | 107 | //CLI运行环境下参数模式:如 --debug=true, 不支持 -h -r等模式 108 | if (substr($_SERVER['argv'][$i], 0, 2) == '--') { 109 | $pos = strpos($_SERVER['argv'][$i], '='); 110 | if ($pos !== false) { 111 | $key = substr($_SERVER['argv'][$i], 2, $pos - 2); 112 | $_SERVER['argv'][$key] = substr($_SERVER['argv'][$i], $pos + 1); 113 | unset($_SERVER['argv'][$i]); 114 | } 115 | } 116 | } 117 | } 118 | 119 | return array('controller'=>$controllerName, 'action'=>$actionName); 120 | } 121 | 122 | return array('controller'=>DEFAULT_CONTROLLER, 'action'=>DEFAULT_ACTION); 123 | } 124 | 125 | /** 126 | * 网址分析,获取路由网址有效的URI 127 | * 128 | * @access private 129 | * @return string 130 | */ 131 | private static function _parseUri() { 132 | 133 | //初始化$uri 134 | $uri = $_SERVER['REQUEST_URI']; 135 | if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0) { 136 | $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME'])); 137 | } else { 138 | //网址中省略引导文件名时 139 | $scriptBaseUrl = dirname($_SERVER['SCRIPT_NAME']); 140 | if (strpos($uri, $scriptBaseUrl) === 0) { 141 | $uri = substr($uri, strlen($scriptBaseUrl)); 142 | } 143 | } 144 | 145 | $uri = ltrim($uri, '/'); 146 | //当uri的内容极为简单,没有包含任何路由信息时 147 | if (!$uri) { 148 | return URL_SEGEMENTATION; 149 | } 150 | 151 | //如网址(URL)含有'?'(问号),则过滤掉问号(?)及其后面的所有字符串 152 | $pos = strpos($uri, '?'); 153 | if ($pos !== false) { 154 | $uri = substr($uri, 0, $pos); 155 | } 156 | 157 | //当uri的内容极为简单,没有包含任何路由信息时 158 | if (!$uri || $uri == '/') { 159 | return URL_SEGEMENTATION; 160 | } 161 | 162 | return trim($uri, URL_SEGEMENTATION); 163 | } 164 | 165 | /** 166 | * 网址(URL)组装操作 167 | * 168 | * 注:组装绝对路径的URL 169 | * 170 | * @example 171 | * $memberUrl = Router::createUrl('member/list', array('mid'=>23, 'page'=>7)); 172 | * 或 173 | * $memberUrl = Router::createUrl('member.list', array('mid'=>23, 'page'=>7)); 174 | * 175 | * @access public 176 | * 177 | * @param string $route controller与action。例:controllerName/actionName 178 | * @param array $params URL路由其它字段。注:url的参数信息 179 | * 180 | * @return string 181 | */ 182 | public static function createUrl($route, $params = array()) { 183 | 184 | //参数分析 185 | if (!$route) { 186 | return false; 187 | } 188 | 189 | //获取项目访问的基本网址 190 | $url = self::getBaseUrl() . '/'; 191 | 192 | //统一路由网址分割符的操作 193 | $route = str_replace(array('//', '/', '.'), URL_SEGEMENTATION, $route); 194 | 195 | //当前的网址格式为:路由网址模式时 196 | if (URL_FORMAT == Configure::PATH_FORMAT) { 197 | 198 | $url .= ((DOIT_REWRITE === false) ? ENTRY_SCRIPT_NAME . '/' : '') . $route; 199 | 200 | if ($params && is_array($params)) { 201 | $paramArray = array(); 202 | foreach ($params as $key=>$value) { 203 | $paramArray[] = trim($key) . URL_SEGEMENTATION . trim($value); 204 | } 205 | $url .= URL_SEGEMENTATION . implode(URL_SEGEMENTATION, $paramArray); 206 | 207 | //清空不必要的内存占用 208 | unset($paramArray); 209 | } 210 | 211 | return $url; 212 | } 213 | 214 | $url .= ((DOIT_REWRITE === false) ? ENTRY_SCRIPT_NAME : '') . '?' . self::$_routerVar . '=' . $route; 215 | 216 | if ($params && is_array($params)) { 217 | $url .= '&' . http_build_query($params); 218 | } 219 | 220 | return $url; 221 | } 222 | 223 | /** 224 | * 获取当前项目的根目录的URL 225 | * 226 | * 本类方法常用于网页的CSS, JavaScript,图片等文件的调用 227 | * 228 | * @access public 229 | * @return string 230 | */ 231 | public static function getBaseUrl() { 232 | 233 | //处理URL中的//或\\情况,即:出现/或\重复的现象 234 | $url = str_replace(array('\\', '//'), '/', dirname($_SERVER['SCRIPT_NAME'])); 235 | 236 | return rtrim($url, '/'); 237 | } 238 | 239 | } -------------------------------------------------------------------------------- /doitphp/library/Pagination.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommy Software Studio 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Pagination.php 2.6 2012-12-29 11:40:01Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Pagination { 19 | 20 | /** 21 | * 分页链接网址 22 | * 23 | * @var string 24 | */ 25 | protected $_baseUrl = null; 26 | 27 | /** 28 | * 当前页 29 | * 30 | * @var integer 31 | */ 32 | protected $_currentPage = 1; 33 | 34 | /** 35 | * list总数 36 | * 37 | * @var integer 38 | */ 39 | protected $_totalItems = 0; 40 | 41 | /** 42 | * 分页总数 43 | * 44 | * @var integer 45 | */ 46 | protected $_totalPages = 0; 47 | 48 | /** 49 | * 每个页面显示的list数目 50 | * 51 | * @var integer 52 | */ 53 | protected $_perPageItems = 10; 54 | 55 | /** 56 | * list允许放页码数量,如:1.2.3.4就这4个数字,则$_perCircleLimit为4 57 | * 58 | * @var integer 59 | */ 60 | protected $_perCircleLimit = 10; 61 | 62 | /** 63 | * list中的坐标. 如:7,8,九,10,11这里的九为当前页,在list中排第三位,则$_circleCenterCount为3 64 | * 65 | * @var integer 66 | */ 67 | protected $_circleCenterCount = 3; 68 | 69 | /** 70 | * 分页隐藏开关 71 | * 72 | * @var boolean 73 | */ 74 | protected $_hiddenStatus = false; 75 | 76 | /** 77 | * 第一页 78 | * 79 | * @var string 80 | */ 81 | public $firstPage = '第一页'; 82 | 83 | /** 84 | * 上一页 85 | * 86 | * @var string 87 | */ 88 | public $prePage = '上一页'; 89 | 90 | /** 91 | * 下一页 92 | * 93 | * @var string 94 | */ 95 | public $nextPage = '下一页'; 96 | 97 | /** 98 | * 最后一页 99 | * 100 | * @var string 101 | */ 102 | public $lastPage = '最末页'; 103 | 104 | /** 105 | * 获取总页数 106 | * 107 | * @access protected 108 | * @return integer 109 | */ 110 | protected function _getTotalPage() { 111 | 112 | return ceil($this->_totalItems / $this->_perPageItems); 113 | } 114 | 115 | /** 116 | * 获取当前页数 117 | * 118 | * @access protected 119 | * @return integer 120 | */ 121 | protected function _parseCurrentPage() { 122 | 123 | //当URL中?page=5的page参数大于总页数时 124 | return ($this->_currentPage > $this->_totalPages) ? $this->_totalPages : $this->_currentPage; 125 | } 126 | 127 | /** 128 | * 设置每页显示的列表数 129 | * 130 | * @access public 131 | * 132 | * @param integer $num 每页显示的列表数 133 | * 134 | * @return object 135 | */ 136 | public function num($num = null) { 137 | 138 | //参数分析 139 | if ($num) { 140 | $this->_perPageItems = $num; 141 | } 142 | 143 | return $this; 144 | } 145 | 146 | /** 147 | * 设置总列表数 148 | * 149 | * @access public 150 | * 151 | * @param integer $totalNum 总列表数 152 | * 153 | * @return object 154 | */ 155 | public function total($totalNum = null) { 156 | 157 | //参数分析 158 | if ($totalNum) { 159 | $this->_totalItems = $totalNum; 160 | } 161 | 162 | return $this; 163 | } 164 | 165 | /** 166 | * 开启分页的隐藏功能 167 | * 168 | * @access public 169 | * 170 | * @param boolean $item 隐藏开关 , 默认为true 171 | * 172 | * @return object 173 | */ 174 | public function hide($item = true) { 175 | 176 | if ($item === true) { 177 | $this->_hiddenStatus = true; 178 | } 179 | 180 | return $this; 181 | } 182 | 183 | /** 184 | * 设置分页跳转的网址 185 | * 186 | * @access public 187 | * 188 | * @param string $baseUrl 分页跳转的网址 189 | * 190 | * @return object 191 | */ 192 | public function url($baseUrl = null) { 193 | 194 | //当网址不存在时 195 | if ($baseUrl) { 196 | $this->_baseUrl = trim($baseUrl); 197 | } 198 | 199 | return $this; 200 | } 201 | 202 | /** 203 | * 设置当前的页数 204 | * 205 | * @access public 206 | * 207 | * @param integer $onPage 当前的页数 208 | * 209 | * @return object 210 | */ 211 | public function page($onPage = null) { 212 | 213 | //参数分析 214 | if($onPage) { 215 | $this->_currentPage = $onPage; 216 | } 217 | 218 | return $this; 219 | } 220 | 221 | /** 222 | * 设置分页列表的重心 223 | * 224 | * @access public 225 | * 226 | * @param integer $countNum 分页列表重心(即:页数) 227 | * 228 | * @return object 229 | */ 230 | public function center($countNum) { 231 | 232 | //参数分析 233 | if ($countNum && is_int($countNum)) { 234 | $this->_circleCenterCount = $countNum; 235 | } 236 | 237 | return $this; 238 | } 239 | 240 | /** 241 | * 设置分页列表的列表数 242 | * 243 | * @access public 244 | * 245 | * @param integer $num 分页列表的列表数 246 | * 247 | * @return object 248 | */ 249 | public function circle($limitNum) { 250 | 251 | //参数分析 252 | if ($limitNum && is_int($limitNum)) { 253 | $this->_perCircleLimit = $limitNum; 254 | } 255 | 256 | return $this; 257 | } 258 | 259 | /** 260 | * 获取分页数组 261 | * 262 | * @access public 263 | * @return array 264 | */ 265 | public function getArray() { 266 | 267 | //支持长的url. 268 | $this->_baseUrl = trim(str_replace(array("\n","\r"), '', $this->_baseUrl)); 269 | //获取总页数. 270 | $this->_totalPages = $this->_getTotalPage(); 271 | //获取当前页. 272 | $this->_currentPage = $this->_parseCurrentPage(); 273 | 274 | $data = array(); 275 | 276 | //当未有分页数据时 277 | if (!$this->_totalPages) { 278 | return $data; 279 | } 280 | 281 | //当分页隐藏功能开启时 282 | if (($this->_hiddenStatus === true) && ($this->_totalItems <= $this->_perPageItems)) { 283 | return $data; 284 | } 285 | 286 | $data['num_items'] = $this->_totalItems; 287 | $data['per_page'] = $this->_perPageItems; 288 | $data['num_pages'] = $this->_totalPages; 289 | $data['page'] = $this->_currentPage; 290 | 291 | //分析上一页 292 | $data['is_previous'] = 0; 293 | if ($this->_currentPage != 1 && $this->_totalPages > 1) { 294 | $data['first_page'] = array('page_number' => $this->firstPage, 'page_url' => $this->_baseUrl . 1); 295 | $data['previous_page'] = array('page_number' => $this->prePage, 'page_url' => $this->_baseUrl . ($this->_currentPage - 1)); 296 | $data['is_previous'] = 1; 297 | } 298 | 299 | //分析下一页 300 | $data['is_next'] = 0; 301 | if ($this->_currentPage != $this->_totalPages && $this->_totalPages > 1) { 302 | $data['next_page'] = array('page_number' => $this->nextPage, 'page_url' => $this->_baseUrl . ($this->_currentPage + 1)); 303 | $data['last_page'] = array('page_number' => $this->lastPage, 'page_url' => $this->_baseUrl . $this->_totalPages); 304 | $data['is_next'] = 1; 305 | } 306 | 307 | //分析分页列表 308 | if ($this->_totalPages > $this->_perCircleLimit) { 309 | if ($this->_currentPage + $this->_perCircleLimit >= $this->_totalPages + $this->_circleCenterCount) { 310 | $listStart = $this->_totalPages - $this->_perCircleLimit + 1; 311 | $listEnd = $this->_totalPages; 312 | } else { 313 | $listStart = ($this->_currentPage > $this->_circleCenterCount) ? $this->_currentPage - $this->_circleCenterCount + 1 : 1; 314 | $listEnd = ($this->_currentPage > $this->_circleCenterCount) ? $this->_currentPage + $this->_perCircleLimit - $this->_circleCenterCount : $this->_perCircleLimit; 315 | } 316 | } else { 317 | $listStart = 1; 318 | $listEnd = $this->_totalPages; 319 | } 320 | 321 | for($i = $listStart; $i <= $listEnd; $i ++) { 322 | $data['page_list'][$i] = array('page_number' => $i, 'is_current' => 0, 'page_url' => $this->_baseUrl . $i); 323 | //分析当前页 324 | if ($i == $this->_currentPage) { 325 | $data['page_list'][$i]['is_current'] = 1; 326 | } 327 | } 328 | 329 | return $data; 330 | } 331 | } -------------------------------------------------------------------------------- /doitphp/library/Encrypt.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright Copyright (c) 2010 Tommycode Studio, ColaPHP 7 | * @link http://www.doitphp.com 8 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 9 | * @version $Id: Encrypt.php 2.0 2012-12-29 16:20:14Z tommy $ 10 | * @package library 11 | * @since 1.0 12 | */ 13 | 14 | if (!defined('IN_DOIT')) { 15 | exit(); 16 | } 17 | 18 | class Encrypt { 19 | 20 | /** 21 | * config data 22 | * 23 | * @var array 24 | */ 25 | protected $_config = array(); 26 | 27 | /** 28 | * 加密字符串(密钥) 29 | * 30 | * @var string 31 | */ 32 | protected static $_key = 'your-secret-code'; 33 | 34 | /** 35 | * 构造方法 36 | * 37 | * @access public 38 | * @return boolean 39 | */ 40 | public function __construct() { 41 | 42 | //set config infomation 43 | $this->_config = array( 44 | 'hash' => 'sha1', 45 | 'xor' => false, 46 | 'mcrypt' => function_exists('mcrypt_encrypt') ? true : false, 47 | 'noise' => true, 48 | 'cipher' => MCRYPT_RIJNDAEL_256, 49 | 'mode' => MCRYPT_MODE_ECB 50 | ); 51 | 52 | return true; 53 | } 54 | 55 | /** 56 | * 设置或获取配置参数($_config)信息 57 | * 58 | * @access public 59 | * 60 | * @param mixed $key 键值 61 | * @param mixed $value 参数值 62 | * 63 | * @return mixed 64 | */ 65 | public function config($key = null, $value = null) { 66 | 67 | if (is_null($key)) { 68 | return $this->_config; 69 | } 70 | 71 | if (is_array($key)) { 72 | $this->_config = $key + $this->_config; 73 | return $this; 74 | } 75 | 76 | if (is_null($value)) { 77 | return $this->_config[$key]; 78 | } 79 | 80 | $this->_config[$key] = $value; 81 | 82 | return $this; 83 | } 84 | 85 | /** 86 | * 加密 87 | * 88 | * @access public 89 | * 90 | * @param string $string 待加密的字符串 91 | * @param string $key 密钥 92 | * 93 | * @return string 94 | */ 95 | public function encode($string, $key = null) { 96 | 97 | if (is_null($key)) { 98 | $key = self::$_key; 99 | } 100 | 101 | if ($this->_config['xor']) { 102 | $string = $this->_xorEncode($string, $key); 103 | } 104 | 105 | if ($this->_config['mcrypt']) { 106 | $string = $this->_mcryptEncode($string, $key); 107 | } 108 | 109 | if ($this->_config['noise']) { 110 | $string = $this->_noise($string, $key); 111 | } 112 | 113 | return base64_encode($string); 114 | } 115 | 116 | /** 117 | * 解密 118 | * 119 | * @access public 120 | * 121 | * @param string $string 待解密的字符串 122 | * @param string $key 附加码 123 | * 124 | * @return string 125 | */ 126 | public function decode($string, $key = null) { 127 | 128 | if (is_null($key)) { 129 | $key = self::$_key; 130 | } 131 | 132 | if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) { 133 | return false; 134 | } 135 | 136 | $string = base64_decode($string); 137 | 138 | if ($this->_config['noise']) { 139 | $string = $this->_denoise($string, $key); 140 | } 141 | 142 | if ($this->_config['mcrypt']) { 143 | $string = $this->_mcryptDecode($string, $key); 144 | } 145 | 146 | if ($this->_config['xor']) { 147 | $string = $this->_xorDecode($string, $key); 148 | } 149 | 150 | return $string; 151 | } 152 | 153 | /** 154 | * Mcrypt encode 155 | * 156 | * @access protected 157 | * 158 | * @param string $string 待加密的字符串 159 | * @param string $key 附加码 160 | * 161 | * @return string 162 | */ 163 | protected function _mcryptEncode($string, $key) { 164 | 165 | $cipher = $this->_config['cipher']; 166 | $mode = $this->_config['mode']; 167 | $size = mcrypt_get_iv_size($cipher, $mode); 168 | $vect = mcrypt_create_iv($size, MCRYPT_RAND); 169 | 170 | return mcrypt_encrypt($cipher, $key, $string, $mode, $vect); 171 | } 172 | 173 | /** 174 | * Mcrypt decode 175 | * 176 | * @access protected 177 | * 178 | * @param string $string 待解密的字符串 179 | * @param string $key 附加码 180 | * 181 | * @return string 182 | */ 183 | protected function _mcryptDecode($string, $key) { 184 | 185 | $cipher = $this->_config['cipher']; 186 | $mode = $this->_config['mode']; 187 | $size = mcrypt_get_iv_size($cipher, $mode); 188 | $vect = mcrypt_create_iv($size, MCRYPT_RAND); 189 | 190 | return rtrim(mcrypt_decrypt($cipher, $key, $string, $mode, $vect), "\0"); 191 | } 192 | 193 | /** 194 | * XOR encode 195 | * 196 | * @access protected 197 | * 198 | * @param string $string 待加密的字符串 199 | * @param string $key 附加码 200 | * 201 | * @return string 202 | */ 203 | protected function _xorEncode($string, $key) { 204 | 205 | $rand = $this->_config['hash'](rand()); 206 | $code = ''; 207 | for ($i = 0; $i < strlen($string); $i++) { 208 | $r = substr($rand, ($i % strlen($rand)), 1); 209 | $code .= $r . ($r ^ substr($string, $i, 1)); 210 | } 211 | 212 | return $this->_xor($code, $key); 213 | } 214 | 215 | /** 216 | * XOR decode 217 | * 218 | * @access protected 219 | * 220 | * @param string $string 待解密的字符串 221 | * @param string $key 附加码 222 | * 223 | * @return string 224 | */ 225 | protected function _xorDecode($string, $key) { 226 | 227 | $string = $this->_xor($string, $key); 228 | $code = ''; 229 | for ($i = 0; $i < strlen($string); $i++) { 230 | $code .= (substr($string, $i++, 1) ^ substr($string, $i, 1)); 231 | } 232 | 233 | return $code; 234 | } 235 | 236 | /** 237 | * XOR 238 | * 239 | * @access protected 240 | * 241 | * @param string $string 待加密的字符串 242 | * @param string $key 附加码 243 | * 244 | * @return string 245 | */ 246 | protected function _xor($string, $key) { 247 | 248 | $hash = $this->_config['hash']($key); 249 | $code = ''; 250 | for ($i = 0; $i < strlen($string); $i++) { 251 | $code .= substr($string, $i, 1) ^ substr($hash, ($i % strlen($hash)), 1); 252 | } 253 | 254 | return $code; 255 | } 256 | 257 | /** 258 | * Noise 259 | * 260 | * @access protected 261 | * 262 | * @see http://www.ciphersbyritter.com/GLOSSARY.HTM#IV 263 | * 264 | * @param string $string 待加密的字符串 265 | * @param string $key 附加码 266 | * 267 | * @return string 268 | */ 269 | protected function _noise($string, $key) { 270 | 271 | $hash = $this->_config['hash']($key); 272 | $hashlen = strlen($hash); 273 | $strlen = strlen($string); 274 | $code = ''; 275 | 276 | for ($i = 0, $j = 0; $i < $strlen; ++$i, ++$j) { 277 | if ($j >= $hashlen) $j = 0; 278 | $code .= chr((ord($string[$i]) + ord($hash[$j])) % 256); 279 | } 280 | 281 | return $code; 282 | } 283 | 284 | /** 285 | * Denoise 286 | * 287 | * @access protected 288 | * 289 | * @param string $string 待解密的字符串 290 | * @param string $key 附加码 291 | * 292 | * @return string 293 | */ 294 | protected function _denoise($string, $key) { 295 | 296 | $hash = $this->_config['hash']($key); 297 | $hashlen = strlen($hash); 298 | $strlen = strlen($string); 299 | $code = ''; 300 | 301 | for ($i = 0, $j = 0; $i < $strlen; ++$i, ++$j) { 302 | if ($j >= $hashlen) $j = 0; 303 | $temp = ord($string[$i]) - ord($hash[$j]); 304 | if ($temp < 0) $temp = $temp + 256; 305 | $code .= chr($temp); 306 | } 307 | 308 | return $code; 309 | } 310 | 311 | /** 312 | * 生成随机码 313 | * 314 | * @access public 315 | * 316 | * @param integer $length 随机码长度 (0~32) 317 | * 318 | * @return string 319 | */ 320 | public static function randCode($length = 5) { 321 | 322 | //参数分析 323 | $length = (int)$length; 324 | $length = ($length > 32) ? 32 : $length; 325 | 326 | $code = md5(uniqid(mt_rand(), true)); 327 | $start = mt_rand(0, 32 - $length); 328 | 329 | return substr($code, $start, $length); 330 | } 331 | } -------------------------------------------------------------------------------- /doitphp/library/File.php: -------------------------------------------------------------------------------- 1 | 8 | * @copyright Copyright (c) 2010 Tommy Software Studio 9 | * @link http://www.doitphp.com 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: File.php 2.0 2012-12-23 18:30:01Z tommy $ 12 | * @package library 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | class File { 21 | 22 | /** 23 | * 分析目标目录的读写权限 24 | * 25 | * @access public 26 | * 27 | * @param string $dirPath 目标目录 28 | * @param string $mod 权限值,默认:0755 29 | * 30 | * @return boolean 31 | */ 32 | public static function makeDir($dirPath, $mode = 0755) { 33 | 34 | //参数分析 35 | if (!$dirPath) { 36 | return false; 37 | } 38 | 39 | if (is_dir($dirPath)) { 40 | return true; 41 | } 42 | mkdir($dirPath, $mode, true); 43 | 44 | return true; 45 | } 46 | 47 | /** 48 | * 获取目录内文件 49 | * 50 | * @access public 51 | * 52 | * @param string $dirPath 所要读取内容的目录名 53 | * 54 | * @return string 55 | */ 56 | public static function readDir($dirPath) { 57 | 58 | //参数分析 59 | if (!$dirPath) { 60 | return false; 61 | } 62 | 63 | //define filter file name 64 | $filterArray = array('.cvs', '.svn', '.git'); 65 | 66 | $dir = self::_parseDir($dirPath); 67 | $handle = opendir($dir); 68 | 69 | $files = array(); 70 | while (false !== ($file = readdir($handle))) { 71 | if ($file == '.' || $file == '..' || in_array($file, $filterArray)) { 72 | continue; 73 | } 74 | $files[] = $file; 75 | } 76 | 77 | closedir($handle); 78 | 79 | return $files; 80 | } 81 | 82 | /** 83 | * 将一个文件夹内容复制到另一个文件夹 84 | * 85 | * @access public 86 | * 87 | * @param string $source 被复制的文件夹名 88 | * @param string $dest 所要复制文件的目标文件夹 89 | * 90 | * @return boolean 91 | */ 92 | public static function copyDir($source, $dest) { 93 | 94 | //参数分析 95 | if (!$source || !$dest) { 96 | return false; 97 | } 98 | 99 | $parseDir = self::_parseDir($source); 100 | $destDir = self::_parseDir($dest, true); 101 | 102 | $fileList = self::readDir($parseDir); 103 | 104 | foreach ($fileList as $file) { 105 | if (is_dir($parseDir . DS . $file)) { 106 | self::copyDir($parseDir . DS . $file, $destDir . DS . $file); 107 | } else { 108 | copy($parseDir . DS . $file, $destDir . DS . $file); 109 | } 110 | } 111 | 112 | return true; 113 | } 114 | 115 | /** 116 | * 移动文件夹, 相当于WIN下的ctr+x(剪切操作) 117 | * 118 | * @access public 119 | * 120 | * @param string $source 原目录名 121 | * @param string $dest 目标目录 122 | * 123 | * @return boolean 124 | */ 125 | public static function moveDir($source, $dest) { 126 | 127 | //参数分析 128 | if (!$source || !$dest) { 129 | return false; 130 | } 131 | 132 | $parseDir = self::_parseDir($source); 133 | $destDir = self::_parseDir($dest, true); 134 | 135 | $fileList = self::readDir($parseDir); 136 | 137 | foreach ($fileList as $file) { 138 | if (is_dir($parseDir . DS . $file)) { 139 | self::moveDir($parseDir . DS . $file, $destDir . DS . $file); 140 | } else { 141 | if (copy($parseDir . DS . $file, $destDir . DS . $file)) { 142 | unlink($parseDir . DS . $file); 143 | } 144 | } 145 | } 146 | 147 | rmdir($parseDir); 148 | 149 | return true; 150 | } 151 | 152 | /** 153 | * 删除文件夹 154 | * 155 | * @access public 156 | * 157 | * @param string $dirPath 所要删除文件的路径 158 | * 159 | * @return boolean 160 | */ 161 | public static function deleteDir($dirPath) { 162 | 163 | //参数分析 164 | if (!$dirPath){ 165 | return false; 166 | } 167 | 168 | //清空子目录及内部文件 169 | self::clearDir($dirPath); 170 | 171 | rmdir($dirPath); 172 | 173 | return true; 174 | } 175 | 176 | /** 177 | * 清空文件夹内的文件及子目录 178 | * 179 | * @access public 180 | * 181 | * @param string $dirPath 所要清空内容的文件夹名称 182 | * @param boolean $option 是否删除子目录, 注:当为false时,只删除子目录中的文件,目录不会删除 183 | * 184 | * @return boolean 185 | */ 186 | public static function clearDir($dirPath, $option = true) { 187 | 188 | //参数分析 189 | if (!$dirPath){ 190 | return false; 191 | } 192 | 193 | $parseDir = self::_parseDir($dirPath); 194 | $fileList = self::readDir($parseDir); 195 | 196 | foreach ($fileList as $file) { 197 | if (is_dir($parseDir . DS . $file)) { 198 | self::clearDir($parseDir . DS . $file, $option); 199 | if ($option == true) { 200 | rmdir($parseDir . DS . $file); 201 | } 202 | } else { 203 | unlink($parseDir . DS . $file); 204 | } 205 | } 206 | 207 | return true; 208 | } 209 | 210 | /** 211 | * 分析文件夹是否存在 212 | * 213 | * @access protected 214 | * 215 | * @param string $dirPath 所要操作的文件目录名 216 | * @param boolean $isMkdirStatus 是否创建目录 217 | * 218 | * @return string 219 | */ 220 | protected static function _parseDir($dirPath, $isMkdirStatus = false) { 221 | 222 | //参数分析 223 | if (!$dirPath) { 224 | return false; 225 | } 226 | 227 | if ($isMkdirStatus === true) { 228 | self::makeDir($dirPath, 0755); 229 | } else { 230 | if (!is_dir($dirPath)) { 231 | Response::halt('The dir: ' . $dirPath . ' is not found!'); 232 | } 233 | } 234 | 235 | return $dirPath; 236 | } 237 | 238 | /** 239 | * 文件写操作 240 | * 241 | * @access public 242 | * 243 | * @param string $filePath 文件路径 244 | * @param string $content 文件内容 245 | * 246 | * @return boolean 247 | */ 248 | public static function writeFile($filePath, $content = '') { 249 | 250 | //参数分析 251 | if (!$filePath) { 252 | return false; 253 | } 254 | 255 | //分析文件目录 256 | self::_parseDir(dirname($filePath), true); 257 | 258 | return file_put_contents($filePath, $content, LOCK_EX); 259 | } 260 | 261 | /** 262 | * 文件复制 263 | * 264 | * @access public 265 | * 266 | * @param string $sourceFile 源文件(被复制的文件) 267 | * @param string $destFile 所要复制的文件 268 | * 269 | * @return boolean 270 | */ 271 | public static function copyFile($sourceFile, $destFile) { 272 | 273 | //参数分析 274 | if (!$sourceFile || !$destFile) { 275 | return false; 276 | } 277 | 278 | //文件及目录分析 279 | if (!is_file($sourceFile)) { 280 | Response::halt('The file: ' . $sourceFile . ' is not found!'); 281 | } 282 | self::_parseDir(dirname($destFile), true); 283 | 284 | return copy($sourceFile, $destFile); 285 | } 286 | 287 | /** 288 | * 文件重命名或移动文件 289 | * 290 | * @access public 291 | * 292 | * @param string $sourceFile 源文件 293 | * @param string $destFile 新文件名或路径 294 | * 295 | * @return boolean 296 | */ 297 | public static function moveFile($sourceFile, $destFile) { 298 | 299 | //参数分析 300 | if (!$sourceFile || !$destFile) { 301 | return false; 302 | } 303 | 304 | //文件及目录分析 305 | if (!is_file($sourceFile)) { 306 | Response::halt('The file:' . $sourceFile . ' is not found!'); 307 | } 308 | self::_parseDir(dirname($destFile), true); 309 | 310 | return rename($sourceFile, $destFile); 311 | } 312 | 313 | /** 314 | * 删除文件 315 | * 316 | * @access public 317 | * 318 | * @param string $filePath 文件路径 319 | * 320 | * @return boolean 321 | */ 322 | public static function deleteFile($filePath) { 323 | 324 | //参数分析 325 | if (!$filePath) { 326 | return false; 327 | } 328 | 329 | //文件分析 330 | if (!is_file($filePath)) { 331 | return true; 332 | } 333 | 334 | return unlink($filePath); 335 | } 336 | 337 | /** 338 | * 字节格式化 把字节数格式为 B K M G T 描述的大小 339 | * 340 | * @access public 341 | * 342 | * @param integer $bytes 文件大小 343 | * @param integer $dec 小数点后的位数 344 | * 345 | * @return string 346 | */ 347 | public static function formatBytes($bytes, $dec = 2) { 348 | 349 | $unitPow = array('B', 'KB', 'MB', 'GB', 'TB', 'PB'); 350 | $pos = 0; 351 | while ($bytes >= 1024) { 352 | $bytes /= 1024; 353 | $pos++; 354 | } 355 | 356 | return round($bytes, $dec) . ' ' . $unitPow[$pos]; 357 | } 358 | } -------------------------------------------------------------------------------- /doitphp/DoitPHP.php: -------------------------------------------------------------------------------- 1 | 8 | * @link http://www.doitphp.com 9 | * @copyright Copyright (C) 2015 www.doitphp.com All rights reserved. 10 | * @license New BSD License.{@link http://www.opensource.org/licenses/bsd-license.php} 11 | * @version $Id: DoitPHP.php 2.6 2017-02-02 21:15:00Z tommy $ 12 | * @package core 13 | * @since 1.0 14 | */ 15 | 16 | if (!defined('IN_DOIT')) { 17 | exit(); 18 | } 19 | 20 | /** 21 | * 定义错误提示级别 22 | */ 23 | error_reporting(E_ALL^E_NOTICE); 24 | 25 | /** 26 | * 定义目录分隔符 27 | */ 28 | if (!defined('DS')) { 29 | define('DS', DIRECTORY_SEPARATOR); 30 | } 31 | 32 | /** 33 | * 定义DoitPHP项目的基本路径 34 | */ 35 | if (!defined('APP_ROOT')) { 36 | define('APP_ROOT', dirname(__FILE__) . DS . '..'); 37 | } 38 | 39 | /** 40 | * 定义DoitPHP框架文件所在路径 41 | */ 42 | if (!defined('DOIT_ROOT')) { 43 | define('DOIT_ROOT', dirname(__FILE__)); 44 | } 45 | 46 | 47 | /** 48 | * Doitphp框架核心全局控制类 49 | * 50 | * 用于初始化程序运行及完成基本设置 51 | * @author tommy 52 | * @version 2.0 53 | */ 54 | abstract class Doit { 55 | 56 | /** 57 | * 控制器(controller) 58 | * 59 | * @var string 60 | */ 61 | private static $_controller; 62 | 63 | /** 64 | * 动作(action) 65 | * 66 | * @var string 67 | */ 68 | private static $_action; 69 | 70 | /** 71 | * 对象注册表 72 | * 73 | * @var array 74 | */ 75 | private static $_objects = array(); 76 | 77 | /** 78 | * 载入的文件名(用于PHP函数include所加载过的) 79 | * 80 | * @var array 81 | */ 82 | private static $_incFiles = array(); 83 | 84 | /** 85 | * 项目执行 86 | * 87 | * 供项目入口文件所调用,用于启动框架程序运行 88 | * 89 | * @access public 90 | * 91 | * @param string $configFilePath 配置文件的路径 92 | * 93 | * @return object 94 | */ 95 | public static function run($configFilePath = null) { 96 | 97 | //初始化运行环境 98 | self::_init($configFilePath); 99 | 100 | return self::_createWebApplication(Router::getRequest()); 101 | } 102 | 103 | /** 104 | * 在PHP CLI运行模式下的项目执行 105 | * 106 | * 在CLI运行模式下供项目入口文件所调用,用于启动框架程序运行 107 | * 108 | * @access public 109 | * 110 | * @param string $configFilePath 配置文件的路径 111 | * 112 | * @return object 113 | */ 114 | public static function execute($configFilePath = null) { 115 | 116 | //当前PHP运行模式不为CLI时 117 | if (PHP_SAPI != 'cli') { 118 | return false; 119 | } 120 | 121 | //初始化运行环境 122 | self::_init($configFilePath); 123 | 124 | return self::_createWebApplication(Router::getCliRequest()); 125 | } 126 | 127 | /** 128 | * 创建页面控制器对象 129 | * 130 | * @access private 131 | * 132 | * @param array $routeInfo URL路由信息 133 | * 134 | * @return object 135 | */ 136 | private static function _createWebApplication($routerInfo) { 137 | 138 | //参数分析 139 | if (!$routerInfo || !is_array($routerInfo)) { 140 | return false; 141 | } 142 | 143 | //定义变量_app 144 | static $_app = array(); 145 | 146 | self::$_controller = ucfirst($routerInfo['controller']); 147 | self::$_action = strtolower($routerInfo['action']); 148 | 149 | $appId = self::$_controller . '-' . self::$_action; 150 | 151 | if (!isset($_app[$appId])) { 152 | 153 | //通过实例化及调用所实例化对象的方法,来完成controller中action页面的加载 154 | $controller = self::$_controller . 'Controller'; 155 | $action = self::$_action . 'Action'; 156 | 157 | //分析Controller子目录的情况。注:controller文件的命名中下划线'_'相当于目录的'/'。 158 | if (strpos($controller, '_') !== false) { 159 | //当controller名中含有'_'字符时,将'_'替换为路径分割符。如:"/" 或 "\" 160 | $childDirArray = explode('_', strtolower(self::$_controller)); 161 | $tagFileName = ucfirst(array_pop($childDirArray)); 162 | $childDirName = implode(DS, $childDirArray); 163 | $tagFileName = $childDirName . DS . $tagFileName . 'Controller'; 164 | } else { 165 | $tagFileName = $controller; 166 | } 167 | 168 | //分析controller文件的路径 169 | $controllerFilePath = BASE_PATH . '/controllers/' . $tagFileName . '.php'; 170 | if (!is_file($controllerFilePath)) { 171 | //当controller名称中不含有'_'字符时 172 | self::_show404Error(); 173 | } 174 | //当文件在controller根目录下存在时,直接加载。 175 | self::loadFile($controllerFilePath); 176 | 177 | //创建一个页面控制器对象(Controller Object) 178 | $appObject = new $controller(); 179 | 180 | if (method_exists($controller, $action)){ 181 | $_app[$appId] = $appObject->$action(); 182 | } else { 183 | //所调用方法在所实例化的对象中不存在时 184 | self::_show404Error(); 185 | } 186 | } 187 | 188 | return $_app[$appId]; 189 | } 190 | 191 | /** 192 | * 初始化常用的全局常量 193 | * 194 | * 定义常用的全局常量:重写模式、路由分割符、伪静态网址的后缀、基本网址 195 | * 196 | * @access private 197 | * 198 | * @param string $filePath 配置文件的路径 199 | * 200 | * @return boolean 201 | */ 202 | private static function _init($filePath = null) { 203 | 204 | //加载对配置文件管理的类文件 205 | self::loadFile(DOIT_ROOT . '/core/Configure.php'); 206 | //加载路由网址分析的类文件 207 | self::loadFile(DOIT_ROOT . '/core/Router.php'); 208 | //加载Controller基类 209 | self::loadFile(DOIT_ROOT . '/core/Controller.php'); 210 | 211 | //加载并分析项目的主配置文件 212 | Configure::loadConfig($filePath); 213 | 214 | //定义是否开启调试模式。开启后,程序运行出现错误时,显示错误信息,便于程序调试。 215 | if (!defined('DOIT_DEBUG')) { 216 | define('DOIT_DEBUG', Configure::get('application.debug')); 217 | } 218 | 219 | //定义URL的Rewrite功能是否开启。如开启后,需WEB服务器软件如:apache或nginx等,要开启Rewrite功能。 220 | if (!defined('DOIT_REWRITE')) { 221 | define('DOIT_REWRITE', Configure::get('application.rewrite')); 222 | } 223 | 224 | //定义项目应用目录(application)的基本路径 225 | if (!defined('BASE_PATH')) { 226 | define('BASE_PATH', rtrim(Configure::get('application.basePath'), '/')); 227 | } 228 | 229 | //定义项目缓存目录(cache)的基本路径 230 | if (!defined('CACHE_PATH')) { 231 | define('CACHE_PATH', rtrim(Configure::get('application.cachePath'), '/')); 232 | } 233 | 234 | //定义项目入口文件的名称 235 | if (!defined('ENTRY_SCRIPT_NAME')) { 236 | define('ENTRY_SCRIPT_NAME', basename($_SERVER['SCRIPT_NAME'])); 237 | } 238 | 239 | //定义网址路由的分割符。注:分割符不要与其它网址参数等数据相冲突 240 | if (!defined('URL_SEGEMENTATION')) { 241 | define('URL_SEGEMENTATION', Configure::get('application.urlSegmentation')); 242 | } 243 | 244 | //定义路由网址的格式。注:get/path 245 | if (!defined('URL_FORMAT')) { 246 | define('URL_FORMAT', Configure::get('application.urlFormat')); 247 | } 248 | 249 | //定义视图文件格式 250 | if (!defined('VIEW_EXT')) { 251 | define('VIEW_EXT', Configure::get('application.viewExt')); 252 | } 253 | 254 | //定义默认的Controller名称。注:为提高不同系统平台的兼容性,名称首字母要大写,其余小写 255 | if (!defined('DEFAULT_CONTROLLER')) { 256 | define('DEFAULT_CONTROLLER', Configure::get('application.defaultController')); 257 | } 258 | 259 | //定义默认的Action名称。注:名称要全部使用小写字母 260 | if (!defined('DEFAULT_ACTION')) { 261 | define('DEFAULT_ACTION', Configure::get('application.defaultAction')); 262 | } 263 | 264 | return true; 265 | } 266 | 267 | /** 268 | * 显示404错误提示 269 | * 270 | * 当程序没有找到相关的页面信息时,或当前页面不存在时,显示的提示信息内容 271 | * 272 | * @access private 273 | * @return string 274 | */ 275 | private static function _show404Error() { 276 | 277 | //当为Ajax调用时 278 | if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH']==='XMLHttpRequest')) { 279 | Response::ajax(false, 'Error 404 : Not Found'); 280 | } 281 | 282 | $viewFilePath = BASE_PATH . '/views/errors/error404.html'; 283 | //判断自定义404页面文件是否存在,若不存在则加载默认404页面 284 | is_file($viewFilePath) ? self::loadFile($viewFilePath) : self::loadFile(DOIT_ROOT . '/views/errors/error404.html'); 285 | 286 | //既然提示404错误信息,程序继续执行下去也毫无意义,所以要终止(exit). 287 | exit(); 288 | } 289 | 290 | /** 291 | * 返回唯一的实例(单例模式) 292 | * 293 | * 程序开发中,model, widget, 或其它类在实例化的时候,将类名登记到doitPHP注册表数组($_objects)中,当程序再次实例化时,直接从注册表数组中返回所要的对象. 294 | * 若在注册表数组中没有查询到相关的实例化对象,则进行实例化,并将所实例化的对象登记在注册表数组中.此功能等同于类的单例模式. 295 | * 296 | * 注:本方法只支持实例化无须参数的类.如$object = new pagelist(); 不支持实例化含有参数的. 297 | * 如:$object = new pgelist($total_list, $page); 298 | * 299 | * 300 | * $object = Doit::singleton('pagelist'); 301 | * 302 | * 303 | * @access public 304 | * @param string $className 要获取的对象的类名字 305 | * @return object 返回对象实例 306 | */ 307 | public static function singleton($className) { 308 | 309 | //参数分析 310 | if (!$className) { 311 | return false; 312 | } 313 | 314 | $className = trim($className); 315 | 316 | if (isset(self::$_objects[$className])) { 317 | return self::$_objects[$className]; 318 | } 319 | 320 | return self::$_objects[$className] = new $className(); 321 | } 322 | 323 | /** 324 | * 静态加载文件(相当于PHP函数require_once) 325 | * 326 | * include 以$fileName为名的php文件,如果加载了,这里将不再加载. 327 | * @param string $filePath 文件路径,注:含后缀名 328 | * @return boolean 329 | */ 330 | public static function loadFile($filePath) { 331 | 332 | //参数分析 333 | if (!$filePath) { 334 | return false; 335 | } 336 | 337 | //判断文件有没有加载过,加载过的直接返回true 338 | if (!isset(self::$_incFiles[$filePath])) { 339 | 340 | //分析文件是不是真实存在,若文件不存在,则只能... 341 | if (!is_file($filePath)) { 342 | //当所要加载的文件不存在时,错误提示 343 | Response::halt('The File: ' . $filePath . ' is not found!'); 344 | } 345 | 346 | include_once $filePath; 347 | self::$_incFiles[$filePath] = true; 348 | } 349 | 350 | return self::$_incFiles[$filePath]; 351 | } 352 | 353 | /** 354 | * 获取当前运行的Controller名称 355 | * 356 | * @example $controllerName = Doit::getControllerName(); 357 | * 358 | * @access public 359 | * @return string controller名称(字母全部小写) 360 | */ 361 | public static function getControllerName() { 362 | 363 | return strtolower(self::$_controller); 364 | } 365 | 366 | /** 367 | * 获取当前运行的Action名称 368 | * 369 | * @example $actionName = Doit::getActionName(); 370 | * 371 | * @access public 372 | * @return string action名称(字母全部小写) 373 | */ 374 | public static function getActionName() { 375 | 376 | return self::$_action; 377 | } 378 | } 379 | 380 | /** 381 | * 自动加载引导文件的加载 382 | */ 383 | Doit::loadFile(DOIT_ROOT . '/core/AutoLoad.php'); 384 | 385 | /** 386 | * 调用SPL扩展,注册__autoload()函数. 387 | */ 388 | spl_autoload_register(array('AutoLoad', 'loadClass')); 389 | --------------------------------------------------------------------------------