├── .htaccess ├── .ut.config ├── LICENSE ├── LICENSE.ADD ├── README.md ├── UTVER.ini ├── app ├── admin │ └── index.php ├── assets │ ├── js │ │ ├── jquery.lang.js │ │ ├── jquery.localize.js │ │ └── jquery.min.js │ ├── logo.png │ └── ut-logo.png ├── config.php ├── log │ ├── app.log │ ├── debug.log │ ├── other.log │ └── socket.log ├── modules │ ├── index.html │ └── ut-frame │ │ ├── cache │ │ └── index.html │ │ ├── front │ │ ├── error.php │ │ └── index.php │ │ └── skin │ │ └── front │ │ └── index.cms ├── plugins │ └── index.html └── template │ └── index.html ├── autoload.php ├── composer.json ├── index.php ├── install-dev ├── UTDev.sql └── index.php ├── lang ├── lg-en.json └── lg-zh.json ├── library ├── UsualToolAliopen.php ├── UsualToolCli.php ├── UsualToolCode.php ├── UsualToolData.php ├── UsualToolDebug.php ├── UsualToolInc.php ├── UsualToolLang.php ├── UsualToolLoad.php ├── UsualToolMail.php ├── UsualToolMemcache.php ├── UsualToolMongo.php ├── UsualToolMssql.php ├── UsualToolMysql.php ├── UsualToolPage.php ├── UsualToolPdo.php ├── UsualToolPgsql.php ├── UsualToolRedis.php ├── UsualToolRoute.php ├── UsualToolRsa.php ├── UsualToolSockets.php ├── UsualToolSpider.php ├── UsualToolSqlite.php ├── UsualToolTemp.php ├── UsualToolTree.php ├── UsualToolWater.php └── UsualToolWechat.php ├── update └── index.html ├── usualtool └── vendor └── index.html /.htaccess: -------------------------------------------------------------------------------- 1 | 2 | RewriteEngine On 3 | RewriteBase / 4 | RewriteRule ^index\.php$ - [L] 5 | RewriteCond %{REQUEST_FILENAME} !-f 6 | RewriteCond %{REQUEST_FILENAME} !-d 7 | RewriteRule ^((?!app/dev).)*$ index.php?$1 8 | -------------------------------------------------------------------------------- /.ut.config: -------------------------------------------------------------------------------- 1 | /*基础配置*/ 2 | LANG=zh 3 | LANG_OPTION=zh,en 4 | APPURL= 5 | APPNAME=UT框架 6 | UTCODE=0 7 | REWRITE=0 8 | TEMPCACHE=1 9 | TEMPFRONT=0 10 | TEMPADMIN=0 11 | DEFAULT_MOD=ut-frame 12 | DEFAULT_PAGE=index 13 | DEVELOP=1 14 | LOCKSCREEN=1 15 | UPDATEURL=http://frame.usualtool.com/down/update 16 | UTFURL=http://frame.usualtool.com/auth.php 17 | DEBUG=0 18 | DEBUG_BAR=0 19 | EDITOR= 20 | /*数据配置*/ 21 | DBTYPE=mysql 22 | DBCACHE= 23 | DBCACHE_TIME=3600 24 | PDO_DSN= 25 | PDO_USER= 26 | PDO_PASS= 27 | MYSQL_HOST=localhost 28 | MYSQL_PORT=3306 29 | MYSQL_USER= 30 | MYSQL_PASS= 31 | MYSQL_DB= 32 | MYSQL_CHARSET=utf8 33 | MSSQL_HOST=127.0.0.1 34 | MSSQL_PORT=1433 35 | MSSQL_DB= 36 | MSSQL_USER= 37 | MSSQL_PASS= 38 | PGSQL_HOST=127.0.0.1 39 | PGSQL_PORT=5432 40 | PGSQL_USER= 41 | PGSQL_PASS= 42 | PGSQL_DB=test 43 | SQLITE_DB= 44 | REDIS_HOST=127.0.0.1 45 | REDIS_PORT=6379 46 | REDIS_PASS=UT 47 | MONGO_HOST=127.0.0.1 48 | MONGO_PORT=27017 49 | MONGO_DB= 50 | MONGO_USER= 51 | MONGO_PASS= 52 | MEMCACHE_HOST=127.0.0.1 53 | MEMCACHE_PORT=11211 54 | MEMCACHE_USER= 55 | MEMCACHE_PASS= 56 | SOCKETS_HOST=127.0.0.1 57 | SOCKETS_WSIP=127.0.0.1 58 | SOCKETS_PORT=8080 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /LICENSE.ADD: -------------------------------------------------------------------------------- 1 | Copyright © 2018-2022 by UT (UsualTool Framework) All rights reserved. 2 | 您需要明确,UT核心(框架)是基于Apache2.0协议使用, 3 | 您可以通过http://www.apache.org/licenses/LICENSE-2.0了解或下载到详尽的协议内容。 4 | You need to be clear that the UT core (framework) is based on the Apache 2.0 protocol, 5 | and you can read or download the detailed protocol from the http://www.apache.org/licenses/license-2.0. 6 | 您需要明确,UT可视包(开发后端)可以免费使用,亦可以用于商业用途, 7 | 但必须遵循可视包的使用协议,保证可视包原始著作权人的相应权利不被损害和侵犯。 8 | You need to be clear that the UT visual package (development backend) can be used for free or for commercial purposes, 9 | However, the use agreement of the visual package must be followed to ensure that the corresponding rights of the original copyright owner of the visual package will not be damaged and infringed. 10 | UT(框架或可视包)若包含第三方资源,在发布时可能进行了简化,但您在使用时,请务必遵循其要求进行署名或使用,我们将不对此担责。 11 | If UT (framework or development backend) contains third-party resources, it may be simplified at the time of release, but when you use it, be sure to follow its requirements for signature or use, we will not be responsible for this. 12 | 您自愿使用UT(框架或可视包),必须了解可能存在的风险,需要明确UT著作权人与开源参与者不对任何使用UT的行为或目的提供任何明确的或隐含的赔偿或担保。 13 | If you voluntarily use UT (framework or development backend), you must understand the possible risks and make it clear that the UT copyright owner and open source participants will not provide any explicit or implicit compensation or guarantee for any behavior or purpose of using UT. 14 | 安装UT(框架或可视包)即表明您已经明确理解并同意相应协议,包括在您所在国的法律法规所允许的范围内合法使用UT,并且独立承担所有法律责任及义务。 15 | Install UT (framework or development backend) that you have a clear understanding and consent to the corresponding agreement, can be in your country's laws and regulations within the scope of use UT, can independently assume all legal responsibilities and obligations. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![release](https://img.shields.io/github/v/release/usualtool/framework?include_prereleases&style=social) 2 | ![license](https://img.shields.io/github/license/usualtool/ut-api?style=social) 3 | ![size](https://img.shields.io/github/languages/code-size/usualtool/framework?style=social) 4 | ### English | [简体中文](http://frame.usualtool.com/baike) 5 | #### Introduction 6 | UsualTool Framework (UT) is based on PHP multi-end development framework, class library perfect, suitable for the development of various types of applications. 7 | #### Schematic diagram 8 | Difference from traditional MVC 9 | ![schematic](http://frame.usualtool.com/image/utyl-en.jpg) 10 | #### Environment 11 | Support Nginx/Apache/IIS. 12 | Support PHP5/PHP7/PHP8 and other known upward distributions. 13 | #### Security 14 | .ut.config configuration contains sensitive information. 15 | You must set in the configuration file to prohibit non local access Config file. 16 | [Server configuration example](http://frame.usualtool.com/baike/config.php) 17 | install-dev is the installation directory of visual package on the development side. If visualization is not required, please delete this directory after deploying UT. 18 | #### system architecture 19 | ``` 20 | ┌─── app /*Application*/ 21 | ├────├─── assets /*Resource*/ 22 | ├────├─── admin /*Admin example*/ 23 | ├────├────└───index.php /*Admin controller*/ 24 | ├────├─── log /*Log*/ 25 | ├────├─── modules /*Module*/ 26 | ├────├────└───ut-frame 27 | ├────├────├────├─admin /*Admin model*/ 28 | ├────├────├────├─cache 29 | ├────├────├────├─skin 30 | ├────├────├────├────├─admin /*Admin view*/ 31 | ├────├────├────├────└─front /*Client view*/ 32 | ├────├────├────├─front /*Client model*/ 33 | ├────├────├────├────├─error.php 34 | ├────├────├────├────└─index.php 35 | ├────├─────────└─usualtool.config 36 | ├────├─── plugins /*Plugin*/ 37 | ├────├─── template /*Template engineering*/ 38 | ├────├────└───Template name 39 | ├────├─────────├─assets 40 | ├────├─────────├─move 41 | ├────├─────────├─skin /*Module view*/ 42 | ├────├─────────├───├─ut-frame 43 | ├────├─────────├───├────├─admin 44 | ├────├─────────├───├────├─cache 45 | ├────├─────────├───├────└─front 46 | ├────├─────────├───└─Other module view 47 | ├────├─────────└─usualtool.config 48 | ├────└─── config.php /*Application configuration*/ 49 | ├─── lang /*Language package*/ 50 | ├─── library /*Class library*/ 51 | ├─── update 52 | ├─── vendor /*Composer dependency*/ 53 | ├─── .ut.config /*Global configuration*/ 54 | ├─── autoload.php /*Bootloader*/ 55 | ├─── index.php /*Client controller*/ 56 | ├─── usualtool /*Command line*/ 57 | └─── UTVER.ini /*Version*/ 58 | ``` 59 | #### [Development documentation](http://frame.usualtool.com/baike) -------------------------------------------------------------------------------- /UTVER.ini: -------------------------------------------------------------------------------- 1 | 230504 -------------------------------------------------------------------------------- /app/admin/index.php: -------------------------------------------------------------------------------- 1 | 20 | * 当前示例表示后端共用头部模板 21 | * 以下设置/admin表示后端,/front表示前端 22 | */ 23 | $app->Runin("pubtemp",PUB_TEMP."/admin"); 24 | /** 25 | * 写入模板工程后端公共路径 26 | */ 27 | $app->Runin("template",$adminwork."/skin/".$config["DEFAULT_MOD"]."/admin"); 28 | /** 29 | * 权限验证机制 30 | * 排除不需要验证的页面 31 | * 数组形式Contain($p,array("login","captcha")),判断数组中是否包含页面名$p 32 | * 字符形式Contain("login",$p),判断页面名$p中是否包含login 33 | */ 34 | if(!UTInc::Contain($p,array("login","captcha"))){ 35 | /** 36 | * 加载自定义权限文件 37 | * 该文件亦可封装为函数让autoload自动加载 38 | */ 39 | require PUB_PATH.'/admin/session.php'; 40 | } 41 | /** 42 | * 拼接当前文件 43 | */ 44 | $modfile=$modpath."/admin/".$p.".php"; 45 | /** 46 | * 判断文件真实性 47 | */ 48 | if(library\UsualToolInc\UTInc::SearchFile($modfile)){ 49 | /** 50 | * 引用后端模板 51 | */ 52 | require_once $modfile; 53 | }else{ 54 | /** 55 | * 配置公共错误提示 56 | */ 57 | require_once PUB_PATH.'/front/error.php'; 58 | exit(); 59 | } 60 | if($config["DEBUG"]){ 61 | library\UsualToolDebug\UTDebug::Debug($config["DEBUG_BAR"]); 62 | } -------------------------------------------------------------------------------- /app/assets/js/jquery.lang.js: -------------------------------------------------------------------------------- 1 | /** 2 | * -------------------------------------------------------- 3 | * | ░░░░░░░░░ █ █░▀▀█▀▀░ ░░░░░░░░░ | 4 | * | ░░░░░░░ █▄▄▄█ █ | 5 | * | | 6 | * | Author:HuangDou Email:292951110@qq.com | 7 | * | QQ-Group:583610949 | 8 | * | WebSite:http://www.UsualTool.com | 9 | * | UT Framework is suitable for Apache2 protocol. | 10 | * -------------------------------------------------------- 11 | */ 12 | function changelang(){ 13 | var value = $("#language").children('option:selected').val(); 14 | if(value=="big5"){ 15 | setcookie(cookiename,"zh"); 16 | setcookie("chinaspeak","big5"); 17 | }else{ 18 | setcookie(cookiename,value); 19 | setcookie("chinaspeak",""); 20 | } 21 | location.reload(); 22 | } 23 | function clicklang(lang){ 24 | var lang = lang; 25 | if(lang=="big5"){ 26 | setcookie(cookiename,"zh"); 27 | setcookie("chinaspeak","big5"); 28 | }else{ 29 | setcookie(cookiename,lang); 30 | setcookie("chinaspeak",""); 31 | } 32 | location.reload(); 33 | } 34 | function setcookie(cookiename,value){ 35 | var Days = 30; 36 | var exp = new Date(); 37 | exp.setTime(exp.getTime() + Days*24*60*60*1000); 38 | document.cookie = cookiename + "="+ escape (value) + ";expires=" + exp.toGMTString(); 39 | } 40 | function transbig(){ 41 | document.body.innerHTML = document.body.innerHTML.transbig(); 42 | } 43 | function jsonstr(word){ 44 | var word; 45 | $.ajax({ 46 | url:jsonweb+"lang/lg-"+getcookie(""+cookiename+"")+".json", 47 | success:function(jsondata){ 48 | var data = eval(jsondata); 49 | alert(data["l"][word]); 50 | } 51 | }); 52 | } 53 | function getcookie(cookiename){ 54 | var arr = document.cookie.match(new RegExp("(^| )"+cookiename+"=([^;]*)(;|$)")); 55 | if(arr != null) return unescape(arr[2]); return null 56 | } 57 | (function($,undefined){ 58 | $(document).ready(function(){ 59 | var cookiename = "Language"; 60 | if(window.ROOTPATH=='' || window.ROOTPATH==undefined || window.ROOTPATH==null){ 61 | var jsonweb="http://"+document.domain+":"+location.port+"/"; 62 | }else{ 63 | var jsonweb=""+window.ROOTPATH+"/"; 64 | } 65 | String.prototype.transbig=function(){ 66 | htmlobj=$.ajax({url:jsonweb+"lang/lg-"+getcookie("chinaspeak")+".json",async:false}); 67 | var zhjsondata=(htmlobj.responseText); 68 | var obj = eval("("+zhjsondata+")"); 69 | var s=obj["l"]["simplified"]; 70 | var t=obj["l"]["traditional"]; 71 | var k=''; 72 | for(var i=0;i -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "zh"});} 91 | else if(mylanguage.indexOf("tw") > -1 || mylanguage.indexOf("hk") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "zh"});transbig();} 92 | else if(mylanguage.indexOf("en") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "en"});} 93 | else if(mylanguage.indexOf("ja") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "ja"});} 94 | else if(mylanguage.indexOf("ko") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "ko"});} 95 | else if(mylanguage.indexOf("ru") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "ru"});} 96 | else if(mylanguage.indexOf("fr") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "fr"});} 97 | else if(mylanguage.indexOf("ug") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "ug"});} 98 | else if(mylanguage.indexOf("de") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "de"});} 99 | else if(mylanguage.indexOf("ar") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "ar"});} 100 | else if(mylanguage.indexOf("pt") > -1) {$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "pt"});} 101 | else{$("[data-localize]").localize("lg", {pathPrefix: "lang", language: "zh"});} 102 | } 103 | }); 104 | })(jQuery); -------------------------------------------------------------------------------- /app/assets/js/jquery.localize.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) Jim Garvin (http://github.com/coderifous), 2008. 3 | Dual licensed under the GPL (http://dev.jquery.com/browser/trunk/jquery/GPL-LICENSE.txt) and MIT (http://dev.jquery.com/browser/trunk/jquery/MIT-LICENSE.txt) licenses. 4 | Written by Jim Garvin (@coderifous) for use on LMGTFY.com. 5 | http://github.com/coderifous/jquery-localize 6 | Based off of Keith Wood's Localisation jQuery plugin. 7 | http://keith-wood.name/localisation.html 8 | UT Frame 2018 Huangdou. 9 | */ 10 | (function($) { 11 | var normaliseLang; 12 | if(window.ROOTPATH=='' || window.ROOTPATH==undefined || window.ROOTPATH==null){ 13 | var weburl=document.location.protocol+"//"+document.domain+":"+location.port+"/"; 14 | }else{ 15 | var weburl=window.ROOTPATH+"/"; 16 | } 17 | normaliseLang = function(lang) { 18 | lang = lang.replace(/_/, '-').toLowerCase(); 19 | if (lang.length > 3) { 20 | lang = lang.substring(0, 3) + lang.substring(3).toUpperCase(); 21 | } 22 | return lang; 23 | }; 24 | $.defaultLanguage = normaliseLang(navigator.languages && navigator.languages.length > 0 ? navigator.languages[0] : navigator.language || navigator.userLanguage); 25 | $.localize = function(pkg, options) { 26 | var defaultCallback, deferred, fileExtension, intermediateLangData, jsonCall, lang, loadLanguage, localizeElement, localizeForSpecialKeys, localizeImageElement, localizeInputElement, localizeOptgroupElement, notifyDelegateLanguageLoaded, regexify, setAttrFromValueForKey, setTextFromValueForKey, valueForKey, wrappedSet; 27 | if (options == null) { 28 | options = {}; 29 | } 30 | wrappedSet = this; 31 | intermediateLangData = {}; 32 | fileExtension = options.fileExtension || "json"; 33 | deferred = $.Deferred(); 34 | loadLanguage = function(pkg, lang, level) { 35 | var file; 36 | if (level == null) { 37 | level = 1; 38 | } 39 | switch (level) { 40 | case 1: 41 | intermediateLangData = {}; 42 | if (options.loadBase) { 43 | file = pkg + ("." + fileExtension); 44 | return jsonCall(file, pkg, lang, level); 45 | } else { 46 | return loadLanguage(pkg, lang, 2); 47 | } 48 | break; 49 | case 2: 50 | file = "" + pkg + "-" + (lang.split('-')[0]) + "." + fileExtension; 51 | return jsonCall(file, pkg, lang, level); 52 | case 3: 53 | file = "" + pkg + "-" + (lang.split('-').slice(0, 2).join('-')) + "." + fileExtension; 54 | return jsonCall(file, pkg, lang, level); 55 | default: 56 | return deferred.resolve(); 57 | } 58 | }; 59 | jsonCall = function(file, pkg, lang, level) { 60 | var ajaxOptions, errorFunc, successFunc; 61 | if (options.pathPrefix != null) { 62 | file = weburl+"" + options.pathPrefix + "/" + file; 63 | } 64 | successFunc = function(d) { 65 | $.extend(intermediateLangData, d); 66 | notifyDelegateLanguageLoaded(intermediateLangData); 67 | return loadLanguage(pkg, lang, level + 1); 68 | }; 69 | errorFunc = function() { 70 | if (level === 2 && lang.indexOf('-') > -1) { 71 | return loadLanguage(pkg, lang, level + 1); 72 | } else if (options.fallback && options.fallback !== lang) { 73 | return loadLanguage(pkg, options.fallback); 74 | } 75 | }; 76 | ajaxOptions = { 77 | url: file, 78 | dataType: "json", 79 | async: true, 80 | timeout: options.timeout != null ? options.timeout : 500, 81 | success: successFunc, 82 | error: errorFunc 83 | }; 84 | if (window.location.protocol === "file:") { 85 | ajaxOptions.error = function(xhr) { 86 | return successFunc($.parseJSON(xhr.responseText)); 87 | }; 88 | } 89 | return $.ajax(ajaxOptions); 90 | }; 91 | notifyDelegateLanguageLoaded = function(data) { 92 | if (options.callback != null) { 93 | return options.callback(data, defaultCallback); 94 | } else { 95 | return defaultCallback(data); 96 | } 97 | }; 98 | defaultCallback = function(data) { 99 | $.localize.data[pkg] = data; 100 | return wrappedSet.each(function() { 101 | var elem, key, value; 102 | elem = $(this); 103 | key = elem.data("localize"); 104 | key || (key = elem.attr("rel").match(/localize\[(.*?)\]/)[1]); 105 | value = valueForKey(key, data); 106 | if (value != null) { 107 | return localizeElement(elem, key, value); 108 | } 109 | }); 110 | }; 111 | localizeElement = function(elem, key, value) { 112 | if (elem.is('input')) { 113 | localizeInputElement(elem, key, value); 114 | } else if (elem.is('textarea')) { 115 | localizeInputElement(elem, key, value); 116 | } else if (elem.is('img')) { 117 | localizeImageElement(elem, key, value); 118 | } else if (elem.is('optgroup')) { 119 | localizeOptgroupElement(elem, key, value); 120 | } else if (!$.isPlainObject(value)) { 121 | elem.html(value); 122 | } 123 | if ($.isPlainObject(value)) { 124 | return localizeForSpecialKeys(elem, value); 125 | } 126 | }; 127 | localizeInputElement = function(elem, key, value) { 128 | var val; 129 | val = $.isPlainObject(value) ? value.value : value; 130 | if (elem.is("[placeholder]")) { 131 | return elem.attr("placeholder", val); 132 | } else { 133 | return elem.val(val); 134 | } 135 | }; 136 | localizeForSpecialKeys = function(elem, value) { 137 | setAttrFromValueForKey(elem, "title", value); 138 | setAttrFromValueForKey(elem, "href", value); 139 | return setTextFromValueForKey(elem, "lang", value); 140 | }; 141 | localizeOptgroupElement = function(elem, key, value) { 142 | return elem.attr("label", value); 143 | }; 144 | localizeImageElement = function(elem, key, value) { 145 | setAttrFromValueForKey(elem, "alt", value); 146 | return setAttrFromValueForKey(elem, "src", value); 147 | }; 148 | valueForKey = function(key, data) { 149 | var keys, value, _i, _len; 150 | keys = key.split(/\./); 151 | value = data; 152 | for (_i = 0, _len = keys.length; _i < _len; _i++) { 153 | key = keys[_i]; 154 | value = value != null ? value[key] : null; 155 | } 156 | return value; 157 | }; 158 | setAttrFromValueForKey = function(elem, key, value) { 159 | value = valueForKey(key, value); 160 | if (value != null) { 161 | return elem.attr(key, value); 162 | } 163 | }; 164 | setTextFromValueForKey = function(elem, key, value) { 165 | value = valueForKey(key, value); 166 | if (value != null) { 167 | return elem.text(value); 168 | } 169 | }; 170 | regexify = function(string_or_regex_or_array) { 171 | var thing; 172 | if (typeof string_or_regex_or_array === "string") { 173 | return "^" + string_or_regex_or_array + "$"; 174 | } else if (string_or_regex_or_array.length != null) { 175 | return ((function() { 176 | var _i, _len, _results; 177 | _results = []; 178 | for (_i = 0, _len = string_or_regex_or_array.length; _i < _len; _i++) { 179 | thing = string_or_regex_or_array[_i]; 180 | _results.push(regexify(thing)); 181 | } 182 | return _results; 183 | })()).join("|"); 184 | } else { 185 | return string_or_regex_or_array; 186 | } 187 | }; 188 | lang = normaliseLang(options.language ? options.language : $.defaultLanguage); 189 | if (options.skipLanguage && lang.match(regexify(options.skipLanguage))) { 190 | deferred.resolve(); 191 | } else { 192 | loadLanguage(pkg, lang, 1); 193 | } 194 | wrappedSet.localizePromise = deferred; 195 | return wrappedSet; 196 | }; 197 | $.fn.localize = $.localize; 198 | return $.localize.data = {}; 199 | })(jQuery); -------------------------------------------------------------------------------- /app/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/usualtool/framework/d6f14a8523e209092f35aef4df4240e7585719ec/app/assets/logo.png -------------------------------------------------------------------------------- /app/assets/ut-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/usualtool/framework/d6f14a8523e209092f35aef4df4240e7585719ec/app/assets/ut-logo.png -------------------------------------------------------------------------------- /app/config.php: -------------------------------------------------------------------------------- 1 | Runin(array("setup","title"),array($setup,"Hello!UT")); 5 | $app->Open("index.cms"); -------------------------------------------------------------------------------- /app/modules/ut-frame/skin/front/index.cms: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <{$title}> 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 |

/**

13 |

* The framework runs successfully.

14 | <{if $setup==0}>

* Visual development package not installed.

<{/if}> 15 |

* --------------------------------------------------------

16 |

17 |

* Author:HuangDou Email:usualtool@qq.com

18 |

* QQ-Group:583610949

19 |

* WebSite:http://www.UsualTool.com

20 |

* UT Framework is suitable for Apache2 protocol.

21 |

* --------------------------------------------------------

22 |

*/

23 |
24 | 25 | -------------------------------------------------------------------------------- /app/plugins/index.html: -------------------------------------------------------------------------------- 1 | /** 2 | * -------------------------------------------------------- 3 | * | ░░░░░░░░░ █ █░▀▀█▀▀░ ░░░░░░░░░ | 4 | * | ░░░░░░░ █▄▄▄█ █ | 5 | * | | 6 | * | Author:HuangDou Email:292951110@qq.com | 7 | * | QQ-Group:583610949 | 8 | * | WebSite:http://www.UsualTool.com | 9 | * | UT Framework is suitable for Apache2 protocol. | 10 | * -------------------------------------------------------- 11 | */ -------------------------------------------------------------------------------- /app/template/index.html: -------------------------------------------------------------------------------- 1 | /** 2 | * -------------------------------------------------------- 3 | * | ░░░░░░░░░ █ █░▀▀█▀▀░ ░░░░░░░░░ | 4 | * | ░░░░░░░ █▄▄▄█ █ | 5 | * | | 6 | * | Author:HuangDou Email:292951110@qq.com | 7 | * | QQ-Group:583610949 | 8 | * | WebSite:http://www.UsualTool.com | 9 | * | UT Framework is suitable for Apache2 protocol. | 10 | * -------------------------------------------------------- 11 | */ -------------------------------------------------------------------------------- /autoload.php: -------------------------------------------------------------------------------- 1 | $val){ 56 | $_GET[$key]=$val; 57 | } 58 | /** 59 | * 加载模块 60 | */ 61 | $m=empty($_GET["m"]) ? $config["DEFAULT_MOD"] : UTInc::SqlCheck($_GET["m"]); 62 | /** 63 | * 加载页面 64 | */ 65 | $p=empty($_GET["p"]) ? $config["DEFAULT_PAGE"] : UTInc::SqlCheck(str_replace(".php","",$_GET["p"])); 66 | /** 67 | * 当前模块 68 | */ 69 | $modpath=APP_ROOT."/modules/".$m; 70 | /** 71 | * 模板节点 72 | */ 73 | $endpath=UTInc::TempEndPath(); 74 | /** 75 | * 配置模块化模板及模板工程模板 76 | */ 77 | $frontwork=APP_ROOT."/template/".$config["TEMPFRONT"]; 78 | $adminwork=APP_ROOT."/template/".$config["TEMPADMIN"]; 79 | $isdevelop=UTInc::Contain("app/dev",UTInc::CurPageUrl()); 80 | /** 81 | * 开发端 82 | */ 83 | if($config["TEMPADMIN"]!='0' && $isdevelop): 84 | $skin=$adminwork."/skin/".$m; 85 | $cache=$skin."/cache"; 86 | /** 87 | * 客户端 88 | */ 89 | elseif($config["TEMPFRONT"]!='0' && !$isdevelop): 90 | $skin=$frontwork."/skin/".$m; 91 | $cache=$skin."/cache"; 92 | /** 93 | * 默认配置 94 | */ 95 | else: 96 | $skin=$modpath."/skin"; 97 | $cache=$modpath."/cache"; 98 | endif; 99 | $app=new UTTemp($config["TEMPCACHE"],$skin."/".$endpath,$cache."/".$endpath); 100 | /** 101 | * 基础绑定 102 | */ 103 | $app->Runin(array("appname","appurl","module","page","editor"),array($config["APPNAME"],$config["APPURL"],$m,$p,$config["EDITOR"])); 104 | /** 105 | * 语言配置 106 | */ 107 | $app->Runin(array("lang","thelang"),array(explode(",",$config["LANG_OPTION"]),$config["LANG"])); 108 | if(!empty($_COOKIE['Language'])): 109 | $language=UTInc::SqlCheck($_COOKIE['Language']); 110 | else: 111 | if($config["LANG"]=="big5"): 112 | $language="zh"; 113 | setcookie("Language","zh"); 114 | setcookie("chinaspeak","big5"); 115 | else: 116 | $language=$config["LANG"]; 117 | setcookie("Language",$config["LANG"]); 118 | setcookie("chinaspeak",""); 119 | endif; 120 | endif; -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "usualtool/framework", 3 | "description": "UT Framework is based on PHP multi-end development framework, class library perfect, suitable for the development of various types of applications.", 4 | "keywords": ["UT", "UsualTool", "UT Framework"], 5 | "homepage": "http://frame.usualtool.com", 6 | "license": "Apache-2.0", 7 | "authors": [{ 8 | "name": "HuangDou", 9 | "email": "292951110@qq.com" 10 | }], 11 | "require": { 12 | } 13 | } -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | Runin("pubtemp",PUB_TEMP."/front"); 18 | /** 19 | * 写入模板工程前端公共路径 20 | */ 21 | $app->Runin("template",$frontwork."/skin/".$config["DEFAULT_MOD"]."/front"); 22 | /** 23 | * 拼接当前文件 24 | */ 25 | $modfile=$modpath."/front/".$p.".php"; 26 | /** 27 | * 判断文件真实性 28 | */ 29 | if(library\UsualToolInc\UTInc::SearchFile($modfile)){ 30 | /** 31 | * 引用前端模板 32 | */ 33 | require_once $modfile; 34 | }else{ 35 | /** 36 | * 配置公共错误提示 37 | */ 38 | require_once PUB_PATH.'/front/error.php'; 39 | exit(); 40 | } 41 | if($config["DEBUG"]){ 42 | library\UsualToolDebug\UTDebug::Debug($config["DEBUG_BAR"]); 43 | } -------------------------------------------------------------------------------- /install-dev/UTDev.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE IF EXISTS `cms_admin`; 2 | CREATE TABLE `cms_admin` ( 3 | `id` int(11) NOT NULL AUTO_INCREMENT, 4 | `roleid` int(11) NOT NULL DEFAULT '1', 5 | `username` varchar(50) NOT NULL, 6 | `password` varchar(50) NOT NULL, 7 | `salts` varchar(20) NOT NULL, 8 | `avatar` varchar(250) DEFAULT NULL, 9 | `addtime` timestamp NOT NULL, 10 | PRIMARY KEY (`id`), 11 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 12 | DROP TABLE IF EXISTS `cms_admin_log`; 13 | CREATE TABLE `cms_admin_log` ( 14 | `id` int(11) NOT NULL AUTO_INCREMENT, 15 | `username` varchar(50) NOT NULL, 16 | `ip` varchar(50) NOT NULL, 17 | `logintime` datetime NOT NULL, 18 | PRIMARY KEY (`id`), 19 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 20 | DROP TABLE IF EXISTS `cms_admin_role`; 21 | CREATE TABLE `cms_admin_role` ( 22 | `id` int(11) NOT NULL AUTO_INCREMENT, 23 | `role` varchar(50) NOT NULL, 24 | `module` varchar(250) NOT NULL, 25 | PRIMARY KEY (`id`), 26 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 27 | DROP TABLE IF EXISTS `cms_api_set`; 28 | CREATE TABLE `cms_api_set` ( 29 | `id` int(11) NOT NULL AUTO_INCREMENT, 30 | `white` text, 31 | `opentable` text, 32 | `authtable` varchar(50) DEFAULT NULL, 33 | `authquery` varchar(250) DEFAULT NULL, 34 | PRIMARY KEY (`id`), 35 | UNIQUE KEY `id` (`id`) 36 | ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 37 | DROP TABLE IF EXISTS `cms_module`; 38 | CREATE TABLE `cms_module` ( 39 | `id` int(11) NOT NULL AUTO_INCREMENT, 40 | `bid` int(11) DEFAULT '0', 41 | `mid` varchar(50) DEFAULT NULL, 42 | `modname` varchar(100) DEFAULT NULL, 43 | `modurl` varchar(200) DEFAULT NULL, 44 | `isopen` int(11) DEFAULT '0', 45 | `ordernum` int(11) DEFAULT '0', 46 | `look` int(11) DEFAULT '0', 47 | `othername` varchar(100) DEFAULT NULL, 48 | `befoitem` varchar(250) DEFAULT NULL, 49 | `backitem` varchar(250) DEFAULT NULL, 50 | PRIMARY KEY (`id`), 51 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 52 | DROP TABLE IF EXISTS `cms_plugin`; 53 | CREATE TABLE `cms_plugin` ( 54 | `id` int(11) NOT NULL AUTO_INCREMENT, 55 | `pid` varchar(50) DEFAULT NULL, 56 | `type` varchar(50) DEFAULT NULL, 57 | `auther` varchar(50) DEFAULT NULL, 58 | `title` varchar(50) DEFAULT NULL, 59 | `ver` varchar(10) DEFAULT NULL, 60 | `description` text, 61 | PRIMARY KEY (`id`), 62 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 63 | DROP TABLE IF EXISTS `cms_search`; 64 | CREATE TABLE `cms_search` ( 65 | `id` int(11) NOT NULL AUTO_INCREMENT, 66 | `hit` int(11) DEFAULT '1', 67 | `keyword` varchar(100) DEFAULT NULL, 68 | `lang` varchar(20) DEFAULT 'zh', 69 | PRIMARY KEY (`id`), 70 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 71 | DROP TABLE IF EXISTS `cms_search_set`; 72 | CREATE TABLE `cms_search_set` ( 73 | `id` int(11) NOT NULL AUTO_INCREMENT, 74 | `dbs` varchar(50) DEFAULT NULL, 75 | `fields` varchar(100) DEFAULT NULL, 76 | `wheres` varchar(200) DEFAULT NULL, 77 | `pages` varchar(50) DEFAULT NULL, 78 | PRIMARY KEY (`id`), 79 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 80 | DROP TABLE IF EXISTS `cms_template`; 81 | CREATE TABLE `cms_template` ( 82 | `id` int(11) NOT NULL AUTO_INCREMENT, 83 | `tid` varchar(50) DEFAULT NULL, 84 | `lang` varchar(20) DEFAULT NULL, 85 | `title` varchar(50) DEFAULT NULL, 86 | `makefront` int(11) DEFAULT '0', 87 | `makeadmin` int(11) DEFAULT '0', 88 | PRIMARY KEY (`id`), 89 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 90 | DROP TABLE IF EXISTS `cms_update`; 91 | CREATE TABLE `cms_update` ( 92 | `id` int(11) NOT NULL AUTO_INCREMENT, 93 | `updateid` int(11) DEFAULT NULL, 94 | `updatetime` datetime DEFAULT NULL, 95 | PRIMARY KEY (`id`), 96 | UNIQUE KEY `id` (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 97 | INSERT INTO `cms_admin` VALUES (1, 1, 'admin', 'd9c51907cc016f4ad6164423c3ddd04f025aa037', 'qHCgJ', '/app/assets/images/noimage.png', '2021-08-08 00:00:00'); 98 | INSERT INTO `cms_admin_role` VALUES (1, '超级管理', 'ut-frame,ut-module,ut-plugin,ut-template,ut-cac,ut-system,ut-data,ut-api,ut-power'); 99 | INSERT INTO `cms_api_set` VALUES (1, NULL, NULL, 'cms_admin', 'username=[0] and password=[1]'); 100 | INSERT INTO `cms_module` VALUES (1, 3, 'ut-frame', 'UT公共模块', 'index.php', 1, 91, 0, '', NULL, NULL); 101 | INSERT INTO `cms_module` VALUES (2, 3, 'ut-module', '模块', 'index.php', 1, 92, 0, '', '', '模块市场:module.php,管理模块:index.php'); 102 | INSERT INTO `cms_module` VALUES (3, 3, 'ut-plugin', '插件', 'index.php', 1, 93, 0, '', '', '插件市场:plugin.php,管理插件:index.php'); 103 | INSERT INTO `cms_module` VALUES (4, 3, 'ut-template', '模板', 'index.php', 1, 94, 0, '', '', '模板市场:template.php,创建模板:template_creat.php,管理模板:index.php'); 104 | INSERT INTO `cms_module` VALUES (5, 3, 'ut-cac', 'CAC', 'index.php', 1, 95, 0, '', '', ''); 105 | INSERT INTO `cms_module` VALUES (6, 3, 'ut-system', '配置', 'index.php', 1, 96, 1, '', '', '系统:index.php,语言:lang.php,搜索:search.php'); 106 | INSERT INTO `cms_module` VALUES (7, 3, 'ut-data', '数据', 'index.php', 1, 97, 1, '', '', '表管理:index.php,SQL查询:sql.php,备份还原:backup.php'); 107 | INSERT INTO `cms_module` VALUES (8, 3, 'ut-api', '接口', 'index.php', 1, 98, 1, '', '', '接口列表:index.php,在线调试:test.php'); 108 | INSERT INTO `cms_module` VALUES (9, 3, 'ut-power', '权限', 'admin.php', 1, 99, 1, '', '', '角色:role.php,管理员:admin.php,登陆日志:log.php'); -------------------------------------------------------------------------------- /install-dev/index.php: -------------------------------------------------------------------------------- 1 | $v){ 35 | $info = preg_replace("/{$k}=(.*)/","{$k}={$v}",$info); 36 | } 37 | file_put_contents(UTF_ROOT."/.ut.config",$info); 38 | echo ""; 39 | } 40 | ?> 41 | 42 | 43 | 44 | UT框架可视化 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 |
55 |
56 |
/app/assets/ut-logo.png">
57 |
58 |
59 | 60 |

你即将安装UT框架可视化包,请再次核对协议及请求,并使网络保持通畅。

61 |

通讯状态:

62 |

PHP版本:

63 |
64 |
65 |
66 |
67 | 68 | "> 69 |
70 |
71 | 72 | "> 73 |
74 |
75 |
76 |
77 | 78 | "> 79 |
80 |
81 | 82 | "> 83 |
84 |
85 |
86 |
87 | 88 | "> 89 |
90 |
91 | 92 | "> 93 |
94 |
95 |
96 |
97 | 98 | "> 99 |
100 |
101 |
102 |
103 | 104 | 105 |
106 |
107 |
108 | 134 | 137 |

你即将导入SQL到数据库,请保持网络通畅。

138 |

通讯状态:

139 |
140 | 第".$k."条SQL执行成功!

"; 151 | }else{ 152 | $c=$c+1; 153 | echo"

第".$k."条SQL执行失败:".$arr[$i]."

"; 154 | } 155 | if($k==$total && $c==0){ 156 | echo ""; 157 | } 158 | } 159 | } 160 | ?> 161 |
162 | 163 |
164 | 167 |

你即将部署可视包源码,请保持网络通畅。

168 |

通讯状态:

169 |

请将app目录及update目录开启可写权限。权限校验: 170 | app: 可写"; 174 | else: 175 | $a=1; 176 | echo"不可写"; 177 | endif; 178 | ?> , 179 | update: 可写"; 183 | else: 184 | $b=1; 185 | echo"不可写"; 186 | endif; 187 | ?> 188 |

189 |
190 | 0){ 193 | echo"

请再次检查文件夹权限!

"; 194 | }else{ 195 | if($_GET["t"]=="db-dev"){ 196 | $res=UTInc::SaveFile("http://frame.usualtool.com/down/UTDev.zip",UTF_ROOT."/update","UTDev.zip",1); 197 | if(!empty($res)){ 198 | $zip=new ZipArchive; 199 | if($zip->open(UTF_ROOT."/update/UTDev.zip")===TRUE){ 200 | $zip->extractTo(UTF_ROOT."/update/"); 201 | $zip->close(); 202 | UTInc::MoveDir(UTF_ROOT."/update/UTDev/",UTF_ROOT); 203 | UTInc::DelDir(UTF_ROOT."/update/UTDev/"); 204 | unlink(UTF_ROOT."/update/UTDev.zip"); 205 | file_put_contents("./usualtool.lock","lock"); 206 | echo ""; 207 | }else{ 208 | echo ""; 209 | exit(); 210 | } 211 | }else{ 212 | echo ""; 213 | } 214 | } 215 | ?> 216 |
217 | 218 |
219 | 220 | 221 |
222 |
223 |
224 |
225 | UT使用协议 226 |
227 |

228 | 您需要明确,UT核心(框架)是基于Apache2.0协议使用, 229 | 您可以通过http://www.apache.org/licenses/LICENSE-2.0了解或下载到详尽的协议内容。 230 |

231 |

232 | You need to be clear that the UT core (framework) is based on the Apache 2.0 protocol, 233 | and you can read or download the detailed protocol from the http://www.apache.org/licenses/license-2.0. 234 |

235 |

236 | 您需要明确,UT可视包(UT开发后端)可以免费使用,可以用于商业用途,但必须保证原始著作权人的相应权利不被损害,不得将其任何一部分进行版权注册、抵押或发放许可证,还应当保留相关版权信息。 237 |

238 |

239 | You need to be clear that the UT visual package (UT development backend) can be used free of charge, can be used for commercial purposes, but must ensure that the corresponding rights of the original copyright owners are not infringed, no part of the copyright shall be registered, mortgaged or licensed, and the relevant copyright information shall be retained. 240 |

241 |

您自愿使用UT,必须了解可能存在的风险,需要明确UT著作权人与开源参与者不对任何使用UT的行为或目的提供任何明确的或隐含的赔偿或担保。

242 |

243 | If you voluntarily use UT, 244 | you must understand the possible risks and make it clear that 245 | the UT copyright owner and open source participants will not provide any explicit or implicit compensation or guarantee for any behavior or purpose of using UT. 246 |

247 |

248 | 安装UT即表明您已经明确理解并同意相应协议,包括在您所在国的法律法规所允许的范围内合法使用UT,并且独立承担所有法律责任及义务。 249 | 那么,您可以完全无后顾之忧地使用UT。 250 |

251 |

252 | Install UT that you have a clear understanding and consent to the corresponding agreement, 253 | can be in your country's laws and regulations within the scope of use UT, can independently assume all legal responsibilities and obligations. 254 | Then, you can use UT with no worries at all. 255 |

256 |
257 |
258 |
259 | 260 | -------------------------------------------------------------------------------- /lang/lg-en.json: -------------------------------------------------------------------------------- 1 | { 2 | "s": { 3 | "language": "en", 4 | "charset": "utf-8", 5 | "speak": "English", 6 | "web": "UT" 7 | }, 8 | "l": { 9 | "test": "Test" 10 | } 11 | } -------------------------------------------------------------------------------- /lang/lg-zh.json: -------------------------------------------------------------------------------- 1 | { 2 | "s": { 3 | "language": "zh", 4 | "charset": "utf-8", 5 | "speak": "中文简体", 6 | "web": "UT" 7 | }, 8 | "l": { 9 | "test": "测试" 10 | } 11 | } -------------------------------------------------------------------------------- /library/UsualToolAliopen.php: -------------------------------------------------------------------------------- 1 | appid=$appid; 24 | $this->appkey=$appkey; 25 | $this->alikey=$alikey; 26 | $this->appline=$appline; 27 | } 28 | function UtsetSign($data,$type='RSA2') { 29 | $search = [ 30 | "-----BEGIN RSA PRIVATE KEY-----", 31 | "-----END RSA PRIVATE KEY-----", 32 | "\n", 33 | "\r", 34 | "\r\n" 35 | ]; 36 | $private_key=str_replace($search,"",$this->appkey); 37 | $private_key=$search[0] . PHP_EOL . wordwrap($private_key, 64, "\n", true) . PHP_EOL . $search[1]; 38 | $res=openssl_get_privatekey($private_key); 39 | if($res){ 40 | if($type == 'RSA'){ 41 | openssl_sign($data, $sign,$res); 42 | }elseif($type == 'RSA2'){ 43 | openssl_sign($data, $sign,$res,OPENSSL_ALGO_SHA256); 44 | } 45 | openssl_free_key($res); 46 | }else { 47 | exit("UT应用私钥格式有误"); 48 | } 49 | $sign = base64_encode($sign); 50 | return $sign; 51 | } 52 | function UtchkSign($data,$sign,$type='RSA2') { 53 | $search = [ 54 | "-----BEGIN PUBLIC KEY-----", 55 | "-----END PUBLIC KEY-----", 56 | "\n", 57 | "\r", 58 | "\r\n" 59 | ]; 60 | $public_key=str_replace($search,"",$this->alikey); 61 | $public_key=$search[0] . PHP_EOL . wordwrap($public_key, 64, "\n", true) . PHP_EOL . $search[1]; 62 | $res=openssl_get_publickey($public_key); 63 | if($res){ 64 | if($type == 'RSA'){ 65 | $result = (bool)openssl_verify($data, base64_decode($sign), $res); 66 | }elseif($type == 'RSA2'){ 67 | $result = (bool)openssl_verify($data, base64_decode($sign), $res,OPENSSL_ALGO_SHA256); 68 | } 69 | openssl_free_key($res); 70 | }else{ 71 | exit("UT支付宝公钥格式有误"); 72 | } 73 | return $result; 74 | } 75 | function GetPin($method,$bizstr,$type=''){ 76 | if(!empty($type)){ 77 | $bizstrv=urlencode($bizstr); 78 | }else{ 79 | $bizstrv=$bizstr; 80 | } 81 | if(is_array($bizstr)){ 82 | $arr=array_merge(array("timestamp"=>date('Y-m-d H:i:s',time()), 83 | "app_id"=>$this->appid, 84 | "method"=>$method, 85 | "format"=>"json", 86 | "charset"=>"utf-8", 87 | "sign_type"=>"RSA2", 88 | "version"=>"1.0"),$bizstrv); 89 | }else{ 90 | $arr=array("timestamp"=>date('Y-m-d H:i:s',time()), 91 | "app_id"=>$this->appid, 92 | "method"=>$method, 93 | "format"=>"json", 94 | "charset"=>"utf-8", 95 | "sign_type"=>"RSA2", 96 | "version"=>"1.0", 97 | "biz_content"=>$bizstrv); 98 | } 99 | return $arr; 100 | } 101 | function GetStr($arr,$type = 'RSA2'){ 102 | if(isset($arr['sign'])){ 103 | unset($arr['sign']); 104 | } 105 | if(isset($arr['sign_type']) && $type == 'RSA'){ 106 | unset($arr['sign_type']); 107 | } 108 | ksort($arr); 109 | return$this->getUrl($arr,false); 110 | } 111 | function GetUrl($arr,$encode = true){ 112 | if($encode){ 113 | return http_build_query($arr); 114 | }else{ 115 | return urldecode(http_build_query($arr)); 116 | } 117 | } 118 | function GetSign($arr){ 119 | $signstr=md5($this->getStr($arr)); 120 | return $signstr; 121 | } 122 | function SetSign($arr){ 123 | $arr['sign'] = $this->getSign($arr); 124 | return $arr; 125 | } 126 | function GetRsaSign($arr){ 127 | return $this->utsetSign($this->getStr($arr),'RSA') ; 128 | } 129 | function SetRsaSign($arr){ 130 | $arr['sign'] = $this->getRsaSign($arr); 131 | return $arr; 132 | } 133 | function GetRsa2Sign($arr){ 134 | return $this->utsetSign($this->getStr($arr,'RSA2'),'RSA2') ; 135 | } 136 | function SetRsa2Sign($arr){ 137 | $arr['sign'] = $this->getRsa2Sign($arr); 138 | return $arr; 139 | } 140 | function CheckSign($arr){ 141 | $sign = $this->getSign($arr); 142 | if($sign == $arr['sign']){ 143 | return true; 144 | }else{ 145 | return false; 146 | } 147 | } 148 | function ApiRequest($method,$bizstr){ 149 | $sign=urlencode($this->getRsa2Sign($this->getPin($method,$bizstr))); 150 | if(is_array($bizstr)){ 151 | $pastr=$this->getStr($this->getPin($method,$bizstr))."&sign=".$sign; 152 | }else{ 153 | $pastr=$this->getStr($this->getPin($method,$bizstr,1))."&sign=".$sign; 154 | } 155 | $curl = curl_init(); 156 | $header = array('content-type:application/x-www-form-urlencoded;charset=utf-8'); 157 | curl_setopt($ch,CURLOPT_HTTPHEADER,$header); 158 | curl_setopt($curl, CURLOPT_URL, $this->appline); 159 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); 160 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); 161 | curl_setopt($curl, CURLOPT_POST, 1); 162 | curl_setopt($curl, CURLOPT_POSTFIELDS,$pastr); 163 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); 164 | $output = json_decode(curl_exec($curl),true); 165 | curl_close($curl); 166 | $node = str_replace(".", "_",$method) . "_response"; 167 | return json_encode($output[$node]); 168 | } 169 | } -------------------------------------------------------------------------------- /library/UsualToolCode.php: -------------------------------------------------------------------------------- 1 | font = APP_ROOT. '/assets/fonts/captcha.ttf'; 37 | } 38 | /** 39 | * 创建验证码 40 | */ 41 | private function CreateCode(){ 42 | $_len = strlen($this->charset) - 1; 43 | for ($i = 0; $i < $this->codelen; $i++) { 44 | $this->code .= $this->charset[mt_rand(0, $_len)]; 45 | } 46 | } 47 | /** 48 | * 创建背景 49 | */ 50 | private function CreateBg(){ 51 | $this->img = imagecreatetruecolor($this->width, $this->height); 52 | $color = imagecolorallocate($this->img, mt_rand(157, 255), mt_rand(157, 255), mt_rand(157, 255)); 53 | imagefilledrectangle($this->img, 0, $this->height, $this->width, 0, $color); 54 | } 55 | /** 56 | * 创建字符 57 | */ 58 | private function CreateFont(){ 59 | $_x = $this->width / $this->codelen; 60 | for ($i = 0; $i < $this->codelen; $i++) { 61 | $this->fontcolor = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); 62 | imagettftext($this->img, $this->fontsize, mt_rand(-30, 30), $_x * $i + mt_rand(1, 5), $this->height / 1.4, $this->fontcolor, $this->font, $this->code[$i]); 63 | } 64 | } 65 | /** 66 | * 创建干扰元素 67 | */ 68 | private function CreateLine(){ 69 | for ($i = 0; $i < 6; $i++) { 70 | $color = imagecolorallocate($this->img, mt_rand(0, 156), mt_rand(0, 156), mt_rand(0, 156)); 71 | imageline($this->img, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $color); 72 | } 73 | for ($i = 0; $i < 100; $i++) { 74 | $color = imagecolorallocate($this->img, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); 75 | imagestring($this->img, mt_rand(1, 5), mt_rand(0, $this->width), mt_rand(0, $this->height), '*', $color); 76 | } 77 | } 78 | /** 79 | * 输出验证码 80 | */ 81 | private function Output(){ 82 | header('Content-type:image/png'); 83 | imagepng($this->img); 84 | imagedestroy($this->img); 85 | } 86 | /** 87 | * 生成接口 88 | */ 89 | public function CreateImage(){ 90 | $this->CreateBg(); 91 | $this->CreateCode(); 92 | $this->CreateLine(); 93 | $this->CreateFont(); 94 | $this->Output(); 95 | } 96 | /** 97 | * 获取验证码 98 | */ 99 | public function GetCode(){ 100 | return strtolower($this->code); 101 | } 102 | } -------------------------------------------------------------------------------- /library/UsualToolDebug.php: -------------------------------------------------------------------------------- 1 | "; 43 | echo"Result:".$file." ".$line." line ".$typetext.":".$message; 44 | echo""; 45 | } 46 | $thisbug=array( 47 | "time"=>date('Y-m-d H:i:s',time()), 48 | "type"=>$typetext, 49 | "file"=>$file, 50 | "line"=>$line, 51 | "message"=>$message); 52 | $old=file_get_contents(APP_ROOT."/log/debug.log"); 53 | if(!empty($old)){ 54 | $arr[]=$thisbug; 55 | $old_data=json_decode($old,true); 56 | foreach($old_data as $val){ 57 | $arr[]=$val; 58 | } 59 | $string=json_encode($arr,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); 60 | }else{ 61 | $string=json_encode(array($thisbug),JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT); 62 | } 63 | file_put_contents(APP_ROOT."/log/debug.log",$string); 64 | } 65 | public static function Error($type='',$path=''){ 66 | echo"

"; 67 | echo"~( ´•︵•` )~ Don't hit me 404
"; 68 | echo"

"; 69 | echo"

"; 70 | echo"Error : Access denied.
"; 71 | if($type=="module"): 72 | echo"Message : This model or view doesn't exist under the module.
"; 73 | elseif($type=="view"): 74 | echo"Message : This view file does not exist.
"; 75 | else: 76 | echo"Message : Unknown error.
"; 77 | endif; 78 | echo$path."
"; 79 | echo"This is an error report on UT Framework."; 80 | echo"

"; 81 | exit(); 82 | } 83 | } -------------------------------------------------------------------------------- /library/UsualToolLang.php: -------------------------------------------------------------------------------- 1 | LangSet("speak",$lgfilename),"lgname"=>$lgfilename); 107 | endif; 108 | } 109 | return $lgfile; 110 | } 111 | } -------------------------------------------------------------------------------- /library/UsualToolLoad.php: -------------------------------------------------------------------------------- 1 | ssl = 1; 31 | $this->debug = FALSE; 32 | $this->port = $port; 33 | $this->relayhost = $host; 34 | $this->timeout = 30; 35 | $this->auth = $auth; 36 | $this->user = $user; 37 | $this->pass = $pass; 38 | $this->hostname = "localhost"; 39 | $this->logfile = ""; 40 | $this->sock = FALSE; 41 | } 42 | function SendMail($to,$from,$subject="",$body="",$mailtype,$cc="",$bcc="",$additional_headers =""){ 43 | $mailfrom = $this->GetAddress($this->StripComment($from)); 44 | $body = preg_replace("/(^|(\r\n))(\.)/", "\1.\3", $body); 45 | $header = "MIME-Version:1.0\r\n"; 46 | if($mailtype=="HTML"){ 47 | $header .= "Content-Type:text/html\r\n"; 48 | } 49 | $header .= "To: ".$to."\r\n"; 50 | if ($cc != "") { 51 | $header .= "Cc: ".$cc."\r\n"; 52 | } 53 | $header .= "From: $from<".$from.">\r\n"; 54 | $header .= "Subject: ".$subject."\r\n"; 55 | $header .= $additional_headers; 56 | $header .= "Date: ".date("r")."\r\n"; 57 | $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; 58 | list($msec, $sec) = explode(" ", microtime()); 59 | $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mailfrom.">\r\n"; 60 | $TO = explode(",", $this->StripComment($to)); 61 | if ($cc != "") { 62 | $TO = array_merge($TO, explode(",", $this->StripComment($cc))); 63 | } 64 | if ($bcc != "") { 65 | $TO = array_merge($TO, explode(",", $this->StripComment($bcc))); 66 | } 67 | $sent = TRUE; 68 | foreach ($TO as $rcpt_to) { 69 | $rcpt_to = $this->GetAddress($rcpt_to); 70 | if (!$this->SmtpCockopen($rcpt_to)) { 71 | $this->LogWrite("Error: Cannot send email to ".$rcpt_to."\n"); 72 | $sent = FALSE; 73 | continue; 74 | } 75 | if ($this->SmtpSend($this->hostname, $mailfrom, $rcpt_to, $header, $body)) { 76 | $this->LogWrite("E-mail has been sent to <".$rcpt_to.">\n"); 77 | } else { 78 | $this->LogWrite("Error: Cannot send email to <".$rcpt_to.">\n"); 79 | $sent = FALSE; 80 | } 81 | fclose($this->sock); 82 | $this->LogWrite("Disconnected from remote host\n"); 83 | } 84 | return $sent; 85 | } 86 | function SmtpSend($helo, $from, $to, $header, $body = ""){ 87 | if (!$this->SmtpPutcmd("HELO", $helo)) { 88 | return $this->SmtpError("sending HELO command"); 89 | } 90 | if($this->auth){ 91 | if (!$this->SmtpPutcmd("AUTH LOGIN", base64_encode($this->user))) { 92 | return $this->SmtpError("sending HELO command"); 93 | } 94 | if (!$this->SmtpPutcmd("", base64_encode($this->pass))) { 95 | return $this->SmtpError("sending HELO command"); 96 | } 97 | } 98 | if (!$this->SmtpPutcmd("MAIL", "FROM:<".$from.">")) { 99 | return $this->SmtpError("sending MAIL FROM command"); 100 | } 101 | if (!$this->SmtpPutcmd("RCPT", "TO:<".$to.">")) { 102 | return $this->SmtpError("sending RCPT TO command"); 103 | } 104 | if (!$this->SmtpPutcmd("DATA")) { 105 | return $this->SmtpError("sending DATA command"); 106 | } 107 | if (!$this->SmtpMessage($header, $body)) { 108 | return $this->SmtpError("sending message"); 109 | } 110 | if (!$this->SmtpEom()) { 111 | return $this->SmtpError("sending . [EOM]"); 112 | } 113 | if (!$this->SmtpPutcmd("QUIT")) { 114 | return $this->SmtpError("sending QUIT command"); 115 | } 116 | return TRUE; 117 | } 118 | function SmtpCockopen($address){ 119 | if ($this->relayhost == "") { 120 | return $this->SmtpCockopenMx($address); 121 | } else { 122 | return $this->SmtpCockopenRelay(); 123 | } 124 | } 125 | function SmtpCockopenRelay(){ 126 | $this->LogWrite("Trying to ".$this->relayhost.":".$this->port."\n"); 127 | if($this->ssl==1){ 128 | $this->sock = @fsockopen("ssl://".$this->relayhost, $this->port, $errno, $errstr, $this->timeout); 129 | }else{ 130 | $this->sock = @fsockopen($this->relayhost, $this->port, $errno, $errstr, $this->timeout); 131 | } 132 | if (!($this->sock && $this->SmtpOk())) { 133 | $this->LogWrite("Error: Cannot connenct to relay host ".$this->relayhost."\n"); 134 | $this->LogWrite("Error: ".$errstr." (".$errno.")\n"); 135 | return FALSE; 136 | } 137 | $this->LogWrite("Connected to relay host ".$this->relayhost."\n"); 138 | return TRUE; 139 | } 140 | function SmtpCockopenMx($address){ 141 | $domain = preg_replace("/^.+@([^@]+)$/", "\1", $address); 142 | if (!@getmxrr($domain, $MXHOSTS)) { 143 | $this->LogWrite("Error: Cannot resolve MX \"".$domain."\"\n"); 144 | return FALSE; 145 | } 146 | foreach ($MXHOSTS as $host) { 147 | $this->LogWrite("Trying to ".$host.":".$this->port."\n"); 148 | $this->sock = @fsockopen($host, $this->port, $errno, $errstr, $this->timeout); 149 | if (!($this->sock && $this->SmtpOk())) { 150 | $this->LogWrite("Warning: Cannot connect to mx host ".$host."\n"); 151 | $this->LogWrite("Error: ".$errstr." (".$errno.")\n"); 152 | continue; 153 | } 154 | $this->LogWrite("Connected to mx host ".$host."\n"); 155 | return TRUE; 156 | } 157 | $this->LogWrite("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); 158 | return FALSE; 159 | } 160 | function SmtpMessage($header, $body){ 161 | fputs($this->sock, $header."\r\n".$body); 162 | $this->SmtpDebug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); 163 | return TRUE; 164 | } 165 | function SmtpEom(){ 166 | fputs($this->sock, "\r\n.\r\n"); 167 | $this->SmtpDebug(". [EOM]\n"); 168 | return $this->SmtpOk(); 169 | } 170 | function SmtpOk(){ 171 | $response = str_replace("\r\n", "", fgets($this->sock, 512)); 172 | $this->SmtpDebug($response."\n"); 173 | if (!preg_match("/^[23]/", $response)) { 174 | fputs($this->sock, "QUIT\r\n"); 175 | fgets($this->sock, 512); 176 | $this->LogWrite("Error: Remote host returned \"".$response."\"\n"); 177 | return FALSE; 178 | } 179 | return TRUE; 180 | } 181 | function SmtpPutcmd($cmd, $arg = ""){ 182 | if ($arg != "") { 183 | if($cmd=="") $cmd = $arg; 184 | else $cmd = $cmd." ".$arg; 185 | } 186 | fputs($this->sock, $cmd."\r\n"); 187 | $this->SmtpDebug("> ".$cmd."\n"); 188 | return $this->SmtpOk(); 189 | } 190 | function SmtpError($string){ 191 | $this->LogWrite("Error: Error occurred while ".$string.".\n"); 192 | return FALSE; 193 | } 194 | function LogWrite($message){ 195 | $this->SmtpDebug($message); 196 | if ($this->logfile == "") { 197 | return TRUE; 198 | } 199 | $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; 200 | if (!@file_exists($this->logfile) || !($fp = @fopen($this->logfile, "a"))) { 201 | $this->SmtpDebug("Warning: Cannot open log file \"".$this->logfile."\"\n"); 202 | return FALSE; 203 | } 204 | flock($fp, LOCK_EX); 205 | fputs($fp, $message); 206 | fclose($fp); 207 | return TRUE; 208 | } 209 | function StripComment($address){ 210 | $comment = "/\([^()]*\)/"; 211 | while (preg_match($comment, $address)) { 212 | $address = preg_replace($comment, "", $address); 213 | } 214 | return $address; 215 | } 216 | function GetAddress($address){ 217 | $address = preg_replace("/([ \t\r\n])+/", "", $address); 218 | $address = preg_replace("/^.*<(.+)>.*$/", "\1", $address); 219 | return $address; 220 | } 221 | function SmtpDebug($message){ 222 | if ($this->debug){ 223 | echo $message; 224 | } 225 | } 226 | } -------------------------------------------------------------------------------- /library/UsualToolMemcache.php: -------------------------------------------------------------------------------- 1 | setOption(\Memcached::OPT_BINARY_PROTOCOL,true); 23 | if(strpos($config["MEMCACHE_HOST"],",")!==false){ 24 | $server=array(); 25 | $hosts=explode(',',$config["MEMCACHE_HOST"]); 26 | $ports=explode(',',$config["MEMCACHE_PORT"]); 27 | $you=round(1/count($hosts)*100); 28 | for($i=0;$iaddServers($server); 32 | }else{ 33 | $db->addServer($config["MEMCACHE_HOST"],$config["MEMCACHE_PORT"]); 34 | } 35 | if(!empty($config["MEMCACHE_USER"]) && !empty($config["MEMCACHE_PASS"])){ 36 | $db->setSaslAuthData($config["MEMCACHE_USER"],$config["MEMCACHE_PASS"]); 37 | } 38 | return $db; 39 | } 40 | /** 41 | * 判断元素是否存在 42 | * @param string $key 键 43 | * @return bool 44 | */ 45 | public static function ModTable($key){ 46 | $db=UTMemcache::GetMemcache(); 47 | $res=$db->get($key); 48 | if(!$res){ 49 | return false; 50 | }else{ 51 | return true; 52 | } 53 | } 54 | /** 55 | * 查询元素 56 | * @param string $key 键 57 | * @return bool/string/array 58 | */ 59 | public static function QueryData($key){ 60 | $db=UTMemcache::GetMemcache(); 61 | $msg=$db->get($key); 62 | if(!$msg){ 63 | return false; 64 | } 65 | return $msg; 66 | } 67 | /** 68 | * 创建元素 69 | * @param string $key 键 70 | * @param string|array $data 值 71 | * @param int $time 过期时间,0不设置过期时间,1设置过期时间为DBCACHE_TIME 72 | * @return bool 73 | */ 74 | public static function InsertData($key,$data,$time='0'){ 75 | $config=UsualToolInc\UTInc::GetConfig(); 76 | $db=UTMemcache::GetMemcache(); 77 | if($time==0){ 78 | return $db->set($key,$data,0); 79 | }else{ 80 | return $db->set($key,$data,$config["DBCACHE_TIME"]); 81 | } 82 | } 83 | /** 84 | * 更新元素 85 | * @param string $key 键 86 | * @param string $value 值 87 | * @param int $time 过期时间 88 | * @return bool 89 | */ 90 | public static function UpdateData($key,$data,$time='0'){ 91 | $db=UTMemcache::GetMemcache(); 92 | if(!UTMemcache::ModTable($key)){ 93 | return false; 94 | }else{ 95 | return $db->replace($key,$data,$time); 96 | } 97 | } 98 | /** 99 | * 删除元素 100 | * @param string $key 键 101 | * @param int $time 删除等待时间 102 | * @return bool 103 | */ 104 | public static function DelData($key,$time='0'){ 105 | $db=UTMemcache::GetMemcache(); 106 | if(!UTMemcache::ModTable($key)){ 107 | return false; 108 | }else{ 109 | return $db->delete($key,$time); 110 | } 111 | } 112 | /** 113 | * 清空元素 114 | * @return bool 115 | */ 116 | public static function Clear(){ 117 | $db=UTMemcache::GetMemcache(); 118 | return $db->flush(); 119 | } 120 | /** 121 | * 获取服务器池的统计信息 122 | * @return array 123 | */ 124 | public static function Status(){ 125 | $db=UTMemcache::GetMemcache(); 126 | return $db->getStats(); 127 | } 128 | } -------------------------------------------------------------------------------- /library/UsualToolMongo.php: -------------------------------------------------------------------------------- 1 | =7){ 25 | $db=new \MongoDB\Driver\Manager("mongodb://".$config["MONGO_USER"].":".$config["MONGO_PASS"]."@".$config["MONGO_HOST"].":".$config["MONGO_PORT"]."/".$config["MONGO_DB"]); 26 | }else{ 27 | $db=new \MongoDB\Driver\Manager("mongodb://".$config["MONGO_HOST"].":".$config["MONGO_PORT"]."/".$config["MONGO_DB"]); 28 | } 29 | return $db; 30 | } 31 | /** 32 | * 判断文档是否存在 33 | * @param string $table 34 | * @return bool 35 | */ 36 | public static function ModTable($table){ 37 | $db=UTMongo::GetMongo(); 38 | $filter=["name"=>['$regex'=>'\sw\d']]; 39 | $query=["limit"=>1]; 40 | if(empty(UTMongo::QueryData($table,$filter,$query))){ 41 | return false; 42 | }else{ 43 | return true; 44 | } 45 | } 46 | /** 47 | * 获取数据 48 | * @param string $table 表 49 | * @param array $filter 条件 50 | * @param array $writeOps 参数 51 | * @return array 52 | */ 53 | public static function QueryData($table,array $filter,array $writeOps=[]){ 54 | $cmd = [ 55 | "find"=> $table, 56 | "filter"=> $filter 57 | ]; 58 | $cmd += $writeOps; 59 | return UTMongo::Command($cmd); 60 | } 61 | /** 62 | * 插入数据 63 | * @param string $table 表 64 | * @param array $documents 文档数据 65 | * @param array $writeOps 参数 66 | * @return array 67 | */ 68 | public static function InsertData($table,array $documents,array $writeOps=[]){ 69 | $cmd = [ 70 | "insert"=> $table, 71 | "documents"=> $documents, 72 | ]; 73 | $cmd += $writeOps; 74 | return UTMongo::Command($cmd); 75 | } 76 | /** 77 | * 删除数据 78 | * @param string $table 79 | * @param array $deletes 删除条件 80 | * @param array $writeOps 参数 81 | * @return array 82 | */ 83 | public static function DelData($table,array $deletes,array $writeOps=[]) { 84 | foreach($deletes as &$_){ 85 | if(isset($_["q"]) && !$_["q"]){ 86 | $_["q"] = (Object)[]; 87 | } 88 | if(isset($_["limit"]) && !$_["limit"]){ 89 | $_["limit"] = 0; 90 | } 91 | } 92 | $cmd = [ 93 | "delete"=> $table, 94 | "deletes"=> $deletes, 95 | ]; 96 | $cmd += $writeOps; 97 | return UTMongo::Command($cmd); 98 | } 99 | /** 100 | * 更新数据 101 | * @param string $table writeOps 102 | * @param array $updates 条件 103 | * @param array $writeOps 参数 104 | * @return array 105 | */ 106 | public static function UpdateData($table,array $updates,array $writeOps=[]) { 107 | $cmd = [ 108 | "update"=> $table, 109 | "updates"=> $updates, 110 | ]; 111 | $cmd += $writeOps; 112 | return UTMongo::Command($cmd); 113 | } 114 | /** 115 | * 执行MongoDB命令 116 | * @param array $param 命令 117 | * @return array 118 | */ 119 | public static function Command(array $param) { 120 | $config=UsualToolInc\UTInc::GetConfig(); 121 | $db=UTMongo::GetMongo(); 122 | $cmd = new \MongoDB\Driver\Command($param); 123 | $data=$db->executeCommand($config["MONGO_DB"],$cmd); 124 | return $data->toArray(); 125 | } 126 | /** 127 | * 获取当前连接信息 128 | * @return array 129 | */ 130 | public static function GetMongoManager() { 131 | $db=UTMongo::GetMongo(); 132 | return $db; 133 | } 134 | } -------------------------------------------------------------------------------- /library/UsualToolMssql.php: -------------------------------------------------------------------------------- 1 | $config["MSSQL_USER"], 27 | 'PWD'=>$config["MSSQL_PASS"], 28 | 'Database'=>$config["MSSQL_DB"]) 29 | ); 30 | if(!$db){ 31 | print_r("Error:".sqlsrv_errors()); 32 | }else{ 33 | return $db; 34 | } 35 | } 36 | /** 37 | * 判断表是否存在 38 | * @param string $table 39 | * @return bool 40 | */ 41 | public static function ModTable($table){ 42 | $db=UTMssql::GetMssql(); 43 | if(sqlsrv_query($db,"select * from ".$table)===false){ 44 | return false; 45 | }else{ 46 | return true; 47 | } 48 | } 49 | /** 50 | * 执行SQL语句 51 | * @param string $sql SQL语句 52 | * @return bool 53 | */ 54 | public static function RunSql($sql){ 55 | $db=UTMssql::GetMssql(); 56 | $result = sqlsrv_query($db,$sql); 57 | if(!$result){ 58 | print_r(sqlsrv_errors()); 59 | }else{ 60 | return true; 61 | } 62 | } 63 | /** 64 | * 查询数据 65 | * @param string $table 被表名 66 | * @param string $field 查询字段,多个字段以‘,’分割 67 | * @param string $where 查询条件 68 | * @param string $order 排序方式,例:id desc/id asc 69 | * @param string|int $limit 数据显示数目,例:10 70 | * @param string $lang 是否开启语言识别 71 | * @return array 返回数组,例:array("querydata"=>array(),"curnum"=>0,"querynum"=>0) 72 | */ 73 | public static function QueryData($table,$field='',$where='',$order='',$limit='',$lang='0'){ 74 | $field=empty($field) ? "*" : $field; 75 | if($lang!="0"): 76 | if(is_numeric($lang)): 77 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 78 | else: 79 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 80 | endif; 81 | else: 82 | $where=empty($where) ? "" : "where ".$where; 83 | endif; 84 | $order=empty($order) ? "" : "order by ".$order; 85 | $limit=empty($limit) ? "" : "top ".$limit; 86 | if(UTMssql::ModTable($table)): 87 | $sql="select ".$limit." ".$field." from ".$table." ".$where." ".$order; 88 | $db=UTMssql::GetMssql(); 89 | $array = array(); 90 | $result = sqlsrv_query($db,$sql); 91 | $curnum=0; 92 | while($rows=UTMssql::FetchArray($result)){ 93 | $curnum++; 94 | if($field!="*"){ 95 | $key = $r[$field]; 96 | $array[$key] = $rows; 97 | }else{ 98 | $array[] = UTMssql::ObjectToArray($rows); 99 | } 100 | } 101 | $querynum=empty($limit) ? $curnum : UTMssql::QueryNum("select ".$field." from ".$table." ".$where." ".$order); 102 | return array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 103 | else: 104 | return array("querydata"=>array(),"curnum"=>$curnum,"querynum"=>0); 105 | endif; 106 | } 107 | /** 108 | * 执行SQL并返回结果集 109 | * @param string $sql SQL语句 110 | * @return array 返回数组,例:array("querydata"=>array(),"querynum"=>0) 111 | */ 112 | public static function JoinQuery($sql){ 113 | $db=UTMssql::GetMssql(); 114 | $array = array(); 115 | $result = sqlsrv_query($db,$sql); 116 | $curnum=0; 117 | while($rows=sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)){ 118 | $curnum++; 119 | $array[] = UTMssql::ObjectToArray($rows); 120 | } 121 | $querynum=UTMssql::QueryNum($sql); 122 | return array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 123 | } 124 | /** 125 | * 新增数据 126 | * @param string $table 被表名 127 | * @param string $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 128 | * @return bool 129 | */ 130 | public static function InsertData($table,$data){ 131 | $db=UTMssql::GetMssql(); 132 | $sql="insert into ".$table." (".implode(',',array_keys($data)).") values ('".implode("','",array_values($data))."');SELECT SCOPE_IDENTITY();"; 133 | $query=sqlsrv_query($db,$sql); 134 | sqlsrv_next_result($query); 135 | $result=sqlsrv_fetch_array($query); 136 | if(!$query): 137 | return false; 138 | else: 139 | if($result[0]): 140 | return $result[0]; 141 | else: 142 | return true; 143 | endif; 144 | endif; 145 | } 146 | /** 147 | * 更新数据 148 | * @param string $table 表名 149 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 150 | * @param string $where 条件 151 | * @return bool 152 | */ 153 | public static function UpdateData($table,$data,$where){ 154 | $db=UTMssql::GetMssql(); 155 | $updatestr=''; 156 | if(!empty($data)): 157 | foreach($data as $k=>$v): 158 | if(preg_match('/\+\d/is',$v)): 159 | $updatestr.=$k."=".$v.","; 160 | else: 161 | $updatestr.=$k."='".$v."',"; 162 | endif; 163 | endforeach; 164 | $updatestr=rtrim($updatestr,','); 165 | endif; 166 | $sql="update ".$table." set ".$updatestr." where ".$where; 167 | $query=UTMssql::RunSql($sql); 168 | if($query): 169 | return true; 170 | else: 171 | return false; 172 | endif; 173 | } 174 | /** 175 | * 删除数据 176 | * @param string $table 表名 177 | * @param string $where 条件 178 | * @return bool 179 | */ 180 | public static function DelData($table,$where){ 181 | $db=UTMssql::GetMssql(); 182 | $sql="delete from ".$table." where ".$where; 183 | $query=UTMssql::RunSql($sql); 184 | if($query): 185 | return true; 186 | else: 187 | return false; 188 | endif; 189 | } 190 | /** 191 | * 获取数据标签 192 | * @param string $table 表名 193 | * @param string $field 标签字段,只能为1个 194 | * @param string $where 条件 195 | * @param string $order 排序方式 196 | * @param string $lang 是否自动开启语言,默认0关闭 197 | * @return array 返回数组,例:array('tags'=>$taglist) 198 | */ 199 | public static function TagData($table,$field='',$where='',$order='',$lang='0'){ 200 | global$language; 201 | $db=UTMssql::GetMssql(); 202 | $tags=""; 203 | $field=empty($field) ? "*" : $field; 204 | if($lang!="0"): 205 | if(is_numeric($lang)): 206 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where.""; 207 | else: 208 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where.""; 209 | endif; 210 | else: 211 | $where=empty($where) ? "" : "where ".$where.""; 212 | endif; 213 | $order=empty($order) ? "" : "order by ".$order.""; 214 | if(UTMssql::ModTable($table)): 215 | $sql="select ".$field." from ".$table." ".$where." ".$order; 216 | $tag = sqlsrv_query($db,$sql); 217 | while($rows=UTMssql::FetchArray($tag)): 218 | $tags="".$tags.",".$rows[$field]; 219 | endwhile; 220 | $taglist=join(',',array_unique(array_diff(explode(",",$tags),array("")))); 221 | $taglists[]=array('tags'=>$taglist); 222 | return $taglists; 223 | else: 224 | return array(); 225 | endif; 226 | } 227 | /** 228 | * 获取数据首图 229 | * @param string $table 表名 230 | * @param string $field 检索字段,只能为1个 231 | * @param string $where 条件 232 | * @return array 返回数组,在其数组中返回指定字段的第一张图片imageurl 233 | */ 234 | public static function FigureData($table,$field,$where='',$limit=''){ 235 | $db=UTMssql::GetMssql(); 236 | $where=empty($where) ? "" : "where ".$where; 237 | $limit=empty($limit) ? "" : "top ".$limit; 238 | if(UTMssql::ModTable($table)): 239 | $sql="SELECT ".$limit." ".$field." from ".$table." ".$where; 240 | $query = sqlsrv_query($db,$sql); 241 | $figuredata=array(); 242 | while($rows=UTMssql::FetchArray($query)): 243 | $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.bmp|\.png]))[\'|\"].*?[\/]?>/"; 244 | preg_match_all($pattern,$rows[$field],$matchcontent); 245 | $rows['imageurl']=isset($matchcontent[1][0]) ? $matchcontent[1][0] : ''; 246 | $count=count($rows); 247 | for($i=0;$i<$count;$i++): 248 | unset($rows[$i]); 249 | endfor; 250 | array_push($figuredata,$rows); 251 | endwhile; 252 | return $figuredata; 253 | else: 254 | return array(); 255 | endif; 256 | } 257 | /** 258 | * 获取结果集数组 259 | * @param string $obj 对象 260 | * @return array 261 | */ 262 | public static function FetchArray($query,$type=SQLSRV_FETCH_ASSOC){ 263 | $cursor=0; 264 | if(is_resource($query)) return sqlsrv_fetch_array($query,$type); 265 | if($cursor $value){ 278 | if(is_array($value)){ 279 | $ret[$key] = UTMssql::ObjectToArray($value); 280 | }elseif(is_object($value)){ 281 | $value=(array)$value; 282 | $ret[$key] = UTMssql::ObjectToArray($value); 283 | }else{ 284 | $ret[$key] = $value; 285 | } 286 | } 287 | return $ret; 288 | } 289 | /** 290 | * 统计记录数目 291 | * @param string $sql SQL语句 292 | * @return int 293 | */ 294 | public static function QueryNum($sql){ 295 | $db=UTMssql::GetMssql(); 296 | $query=sqlsrv_query($db,$sql,array(),array("Scrollable"=>'static')); 297 | return sqlsrv_num_rows($query); 298 | } 299 | /** 300 | * 按字段及条件检索最小值 301 | * @param string $table 表名 302 | * @param string $field 检索字段,数字类型且只能为1个 303 | * @param string $where 条件 304 | */ 305 | public static function Min($table,$field,$where=''){ 306 | $db=UTMssql::GetMssql(); 307 | $min=""; 308 | $where=empty($where) ? "" : "where ".$where; 309 | $query=sqlsrv_query($db,"select min($field) as value from $table $where"); 310 | while($rows=UTMssql::FetchArray($query)): 311 | $min=$rows["value"]; 312 | endwhile; 313 | return $min; 314 | } 315 | /** 316 | * 按字段及条件检索最大值 317 | * @param string $table 表名 318 | * @param string $field 检索字段,数字类型且只能为1个 319 | * @param string $where 条件 320 | */ 321 | public static function Max($table,$field,$where=''){ 322 | $db=UTMssql::GetMssql(); 323 | $max=""; 324 | $where=empty($where) ? "" : "where ".$where; 325 | $query=sqlsrv_query($db,"select max($field) as value from $table $where"); 326 | while($rows=UTMssql::FetchArray($query)): 327 | $max=$rows["value"]; 328 | endwhile; 329 | return $max; 330 | } 331 | /** 332 | * 将GBK转UTF-8 333 | */ 334 | public static function ConvertUtf8($str){ 335 | return iconv("gbk","utf-8",$str); 336 | } 337 | /** 338 | * 将UTF-8转GBK 339 | */ 340 | public static function ConvertGbk($str){ 341 | return iconv("utf-8","gbk",$str); 342 | } 343 | /** 344 | * 关闭Mssql连接 345 | */ 346 | public static function Close(){ 347 | $db=UTMssql::GetMssql(); 348 | sqlsrv_close($db); 349 | } 350 | /** 351 | * 获取版本号 352 | */ 353 | public static function Ver(){ 354 | $db=UTMssql::GetMssql(); 355 | return sqlsrv_server_info($db); 356 | } 357 | } -------------------------------------------------------------------------------- /library/UsualToolMysql.php: -------------------------------------------------------------------------------- 1 | set_charset($config["MYSQL_CHARSET"]); 36 | return $db; 37 | endif; 38 | } 39 | /** 40 | * 测试Mysqli 41 | */ 42 | public static function TestDataBase($DBHOST,$DBPORT,$DBUSER,$DBPASS,$DBNAME){ 43 | $db=new \mysqli($DBHOST.":".$DBPORT,$DBUSER,$DBPASS,$DBNAME); 44 | if(!$db): 45 | return false; 46 | else: 47 | $db->set_charset("utf8"); 48 | return $db; 49 | endif; 50 | } 51 | /** 52 | * 判断表是否存在 53 | * @param string $table 54 | * @return bool 55 | */ 56 | public static function ModTable($table){ 57 | $db=UTMysql::GetMysql(); 58 | if(mysqli_num_rows($db->query("SHOW TABLES LIKE '". $table."'"))==1){ 59 | return true; 60 | }else{ 61 | return false; 62 | } 63 | } 64 | /** 65 | * Mysqli批量任务 66 | * @param string $sql SQL语句 67 | * @return bool 68 | */ 69 | public static function RunSql($sql){ 70 | $db=UTMysql::GetMysql(); 71 | if($db->multi_query($sql)){ 72 | return true; 73 | }else{ 74 | return false; 75 | } 76 | } 77 | /** 78 | * 获取单个或多个数据 79 | * @param string $table 被查询表名 80 | * @param string $field 查询字段,多个字段以‘,’分割 81 | * @param string $where 查询条件 82 | * @param string $order 排序方式,例:id desc/id asc 83 | * @param string|int $limit 数据显示数目,例:0,5/1 84 | * @param string $lang 是否开启语言识别 85 | * @return array 返回数组,例:array("querydata"=>array(),"curnum"=>0,"querynum"=>0) 86 | */ 87 | public static function QueryData($table,$field='',$where='',$order='',$limit='',$lang='0'){ 88 | global$language; 89 | $db=UTMysql::GetMysql(); 90 | $field=empty($field) ? "*" : $field; 91 | if($lang!="0"): 92 | if(is_numeric($lang)): 93 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 94 | else: 95 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 96 | endif; 97 | else: 98 | $where=empty($where) ? "" : "where ".$where; 99 | endif; 100 | $order=empty($order) ? "" : "order by ".$order; 101 | $limit=empty($limit) ? "" : "limit ".$limit; 102 | if(UTMysql::ModTable($table)): 103 | $sql="select ".$field." from `".$table."` ".$where." ".$order." ".$limit; 104 | $query=$db->query($sql); 105 | $curnum=mysqli_num_rows($query); 106 | $querynum=empty($limit) ? $curnum : UTMysql::QueryNum("select ".$field." from ".$table." ".$where." ".$order); 107 | $querydata=array(); 108 | $xu=0; 109 | while($rows=mysqli_fetch_array($query,MYSQLI_ASSOC)): 110 | $xu=$xu+1; 111 | $count=count($rows); 112 | for($i=0;$i<$count;$i++): 113 | unset($rows[$i]); 114 | endfor; 115 | $rows['xu']=$xu; 116 | array_push($querydata,$rows); 117 | endwhile; 118 | return array("querydata"=>$querydata,"curnum"=>$curnum,"querynum"=>$querynum); 119 | else: 120 | return array("querydata"=>array(),"curnum"=>0,"querynum"=>0); 121 | endif; 122 | } 123 | /** 124 | * 执行SQL并返回结果集 125 | * @param string $sql SQL语句 126 | * @return array 返回数组,例:array("querydata"=>array(),"querynum"=>0) 127 | */ 128 | public static function JoinQuery($sql){ 129 | $db=UTMysql::GetMysql(); 130 | $query=$db->query($sql); 131 | $curnum=mysqli_num_rows($query); 132 | $querynum=UTMysql::QueryNum($sql); 133 | $querydata=array(); 134 | while($rows=mysqli_fetch_array($query,MYSQLI_ASSOC)): 135 | array_push($querydata,$rows); 136 | endwhile; 137 | return array("querydata"=>$querydata,"curnum"=>$curnum,"querynum"=>$querynum); 138 | } 139 | /** 140 | * 添加数据 141 | * @param string $table 表名 142 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 143 | * @return bool 当结果为真时返回最新添加的记录id 144 | */ 145 | public static function InsertData($table,$data){ 146 | $db=UTMysql::GetMysql(); 147 | $sql="insert into `".$table."` (".implode(',',array_keys($data)).") values ('".implode("','",array_values($data))."')"; 148 | $query=$db->query($sql); 149 | if($query): 150 | return mysqli_insert_id($db); 151 | else: 152 | return false; 153 | endif; 154 | } 155 | /** 156 | * 编辑数据 157 | * @param string $table 表名 158 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 159 | * @param string $where 条件 160 | * @return bool 161 | */ 162 | public static function UpdateData($table,$data,$where){ 163 | $db=UTMysql::GetMysql(); 164 | $updatestr=''; 165 | if(!empty($data)): 166 | foreach($data as $k=>$v): 167 | if(preg_match('/\+\d/is',$v)): 168 | $updatestr.=$k."=".$v.","; 169 | else: 170 | $updatestr.=$k."='".$v."',"; 171 | endif; 172 | endforeach; 173 | $updatestr=rtrim($updatestr,','); 174 | endif; 175 | $sql="update `".$table."` set ".$updatestr." where ".$where; 176 | $query=$db->query($sql); 177 | if($query): 178 | return true; 179 | else: 180 | return false; 181 | endif; 182 | } 183 | /** 184 | * 删除数据 185 | * @param string $table 表名 186 | * @param string $where 条件 187 | * @return bool 188 | */ 189 | public static function DelData($table,$where){ 190 | $db=UTMysql::GetMysql(); 191 | $sql="delete from `".$table."` where ".$where; 192 | $query=$db->query($sql); 193 | if($query): 194 | return true; 195 | else: 196 | return false; 197 | endif; 198 | } 199 | /** 200 | * 复制数据 201 | * @param string $table 表名 202 | * @param string $where 条件 203 | * @param string $autokey 自动编号字段 204 | * @return bool 205 | */ 206 | public static function CopyData($table,$where,$autokey='id'){ 207 | $db=UTMysql::GetMysql(); 208 | $sql = "SELECT * FROM `".$table."` where ".$where; 209 | $query=$db->query($sql); 210 | $rows=mysqli_fetch_array($query,MYSQLI_ASSOC); 211 | unset($rows[$autokey]); 212 | $csql="insert into `".$table."` (".implode(',',array_keys($rows)).") values ('".implode("','",array_values($rows))."')"; 213 | $cquery=$db->query($csql); 214 | if($cquery): 215 | return mysqli_insert_id($db); 216 | else: 217 | return false; 218 | endif; 219 | $db->close(); 220 | } 221 | /** 222 | * 获取数据标签 223 | * @param string $table 表名 224 | * @param string $field 标签字段,只能为1个 225 | * @param string $where 条件 226 | * @param string $order 排序方式 227 | * @param string $lang 是否自动开启语言,默认0关闭 228 | * @return array 返回数组,例:array('tags'=>$taglist) 229 | */ 230 | public static function TagData($table,$field='',$where='',$order='',$lang='0'){ 231 | global$language; 232 | $db=UTMysql::GetMysql(); 233 | $tags=""; 234 | $field=empty($field) ? "*" : $field; 235 | if($lang!="0"): 236 | if(is_numeric($lang)): 237 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where.""; 238 | else: 239 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where.""; 240 | endif; 241 | else: 242 | $where=empty($where) ? "" : "where ".$where.""; 243 | endif; 244 | $order=empty($order) ? "" : "order by ".$order.""; 245 | if(UTMysql::ModTable($table)): 246 | $sql="select ".$field." from `".$table."` ".$where." ".$order; 247 | $tag=$db->query($sql); 248 | while($tagrow=$tag->fetch_row()): 249 | $tags="".$tags.",".$tagrow[0]; 250 | endwhile; 251 | $taglist=join(',',array_unique(array_diff(explode(",",$tags),array("")))); 252 | $taglists[]=array('tags'=>$taglist); 253 | return $taglists; 254 | else: 255 | return array(); 256 | endif; 257 | } 258 | /** 259 | * 获取数据首图 260 | * @param string $table 表名 261 | * @param string $field 检索字段,只能为1个 262 | * @param string $where 条件 263 | * @return array 返回数组,在其数组中返回指定字段的第一张图片imageurl 264 | */ 265 | public static function FigureData($table,$field,$where='',$limit=''){ 266 | $db=UTMysql::GetMysql(); 267 | $where=empty($where) ? "" : "where ".$where; 268 | $limit=empty($limit) ? "" : "limit ".$limit; 269 | if(UTMysql::ModTable($table)): 270 | $sql="SELECT ".$field." from `".$table."` ".$where." ".$limit; 271 | $query=$db->query($sql); 272 | $figuredata=array(); 273 | while($rows=mysqli_fetch_array($query,MYSQLI_ASSOC)): 274 | $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.bmp|\.png]))[\'|\"].*?[\/]?>/"; 275 | preg_match_all($pattern,$rows[$field],$matchcontent); 276 | $rows['imageurl']=isset($matchcontent[1][0]) ? $matchcontent[1][0] : ''; 277 | $count=count($rows); 278 | for($i=0;$i<$count;$i++): 279 | unset($rows[$i]); 280 | endfor; 281 | array_push($figuredata,$rows); 282 | endwhile; 283 | return $figuredata; 284 | else: 285 | return array(); 286 | endif; 287 | } 288 | /** 289 | * 搜索方法 290 | * @param string $keyword 关键词 291 | * @return array 返回数组 292 | */ 293 | public static function SearchData($keyword){ 294 | $db=UTMysql::GetMysql(); 295 | global$language; 296 | if(!empty($keyword)): 297 | $sql="SELECT * FROM `cms_search` WHERE keyword ='$keyword'"; 298 | $sdata=mysqli_query($db,$sql); 299 | if(mysqli_num_rows($sdata)>0): 300 | UTMysql::UpdateData("cms_search",array("hit"=>"hit+1"),"keyword ='$keyword' and lang='$language'"); 301 | endif; 302 | endif; 303 | $data=array(); 304 | $result=$db->query("select * from `cms_search_set`"); 305 | while($row=mysqli_fetch_array($result)){ 306 | $data[]=array("db"=>$row["dbs"],"field"=>$row["fields"],"where"=>$row["wheres"],"page"=>$row["pages"]); 307 | } 308 | $table="select 'search' as thepage,id,'0' as title,'0' as content from `cms_search` where id<0"; 309 | foreach($data as $key=>$val){ 310 | if(UTMysql::ModTable($val["db"])){ 311 | $table.=" union select '".$val["page"]."' as thepage,id,".$val["field"]." from ".$val["db"]." where ".str_replace("[keyword]","'%".$keyword."%'",$val["where"]).""; 312 | } 313 | } 314 | $search=$db->query($table); 315 | $searchnum=mysqli_num_rows($search); 316 | if(!empty($keyword) && $searchnum>0 && mysqli_num_rows($sdata)<=0): 317 | UTMysql::InsertData("cms_search",array("lang"=>$language,"keyword"=>$keyword)); 318 | endif; 319 | $searchdata=array(); 320 | $xu=0; 321 | while($rows=mysqli_fetch_array($search,MYSQLI_ASSOC)): 322 | $xu=$xu+1; 323 | $count=count($rows); 324 | for($i=0;$i<$count;$i++): 325 | unset($rows[$i]); 326 | endfor; 327 | $rows['xu']=$xu; 328 | array_push($searchdata,$rows); 329 | endwhile; 330 | return array("searchdata"=>$searchdata,"searchnum"=>$searchnum); 331 | } 332 | /** 333 | * 统计记录数目 334 | * @param string $sql SQL语句 335 | * @return int 336 | */ 337 | public static function QueryNum($sql){ 338 | $db=UTMysql::GetMysql(); 339 | $query=$db->query($sql); 340 | return mysqli_num_rows($query); 341 | } 342 | } -------------------------------------------------------------------------------- /library/UsualToolPage.php: -------------------------------------------------------------------------------- 1 | ShowPager(); 17 | * 默认支持bootstrap样式 18 | */ 19 | class UTPage{ 20 | var $nums; 21 | var $current_page; 22 | var $sub_pages; 23 | var $pagenums; 24 | var $each_num; 25 | var $page_array = array(); 26 | var $subpage_link; 27 | var $subpage_type; 28 | var $_lang = array( 29 | 'index_page' => '首页', 30 | 'pre_page' => '上页', 31 | 'next_page' => '下页', 32 | 'last_page' => '尾页', 33 | 'current_page' => '', 34 | 'total_page' => '总页数:', 35 | 'current_show' => '当前显示:', 36 | 'total_record' => '总记录数:' 37 | ); 38 | function __construct($total_page,$current_page,$sub_pages=10,$subpage_link='',$subpage_type=2){ 39 | $this->Pager($total_page,$current_page,$sub_pages,$subpage_link,$subpage_type); 40 | } 41 | /** 42 | * 执行分页 43 | * @param int $total_page 总页数 44 | * @param int $current_page 当前页数 45 | * @param int $sub_pages 每页显示数 46 | * @param string $subpage_link 分页链接 47 | * @param int $subpage_type 分页类型,默认为2 48 | */ 49 | function Pager($total_page,$current_page,$sub_pages=10,$subpage_link='',$subpage_type=2){ 50 | if(!$current_page){ 51 | $this->current_page=1; 52 | }else{ 53 | $this->current_page=intval($current_page); 54 | } 55 | $this->sub_pages=intval($sub_pages); 56 | $this->pagenums=ceil($total_page); 57 | if($subpage_link){ 58 | if(strpos($subpage_link,'?page=') === false AND strpos($subpage_link,'&page=') === false){ 59 | if(substr($subpage_link, -1)=="?" || substr($subpage_link, -1)=="&"){ 60 | $subpage_link .="page=";} 61 | else{ 62 | $subpage_link .= (strpos($subpage_link,'?') === false ? '?' : '&') . 'page='; 63 | } 64 | } 65 | } 66 | $this->subpage_link=$subpage_link ? $subpage_link : $_SERVER['PHP_SELF'] . '?page='; 67 | $this->subpage_type = $subpage_type; 68 | $this->each_num=5; 69 | } 70 | /** 71 | * 展示分页 72 | */ 73 | function ShowPager(){ 74 | if($this->subpage_type == 1){ 75 | return $this->PageListOne(); 76 | }elseif ($this->subpage_type == 2){ 77 | return $this->PageListTwo(); 78 | } 79 | } 80 | function InitArray(){ 81 | for($i=0;$i<$this->each_num;$i++){ 82 | $this->page_array[$i]=$i; 83 | } 84 | return $this->page_array; 85 | } 86 | function ConstructNumPage(){ 87 | if($this->pagenums < $this->each_num){ 88 | $current_array=array(); 89 | for($i=0;$i<$this->pagenums;$i++){ 90 | $current_array[$i]=$i+1; 91 | } 92 | }else{ 93 | $current_array=$this->InitArray(); 94 | if($this->current_page <=3 && $this->current_page>0){ 95 | for($i=0;$icurrent_page <= $this->pagenums && $this->current_page > $this->pagenums - $this->each_num + 1 ){ 99 | for($i=0;$ipagenums)-($this->each_num)+1+$i; 101 | } 102 | }else{ 103 | for($i=0;$icurrent_page-2+$i; 105 | } 106 | } 107 | } 108 | return $current_array; 109 | } 110 | /** 111 | * 分页类型1 112 | */ 113 | function PageListOne(){ 114 | $subPageCss1Str="
"; 135 | return $subPageCss1Str; 136 | } 137 | /** 138 | * 分页类型2 139 | */ 140 | function PageListTwo(){ 141 | $subPageCss2Str="
"; 172 | return $subPageCss2Str; 173 | } 174 | /** 175 | * 析构函数 176 | */ 177 | function __destruct(){ 178 | unset($nums); 179 | unset($current_page); 180 | unset($sub_pages); 181 | unset($pagenums); 182 | unset($each_num); 183 | unset($page_array); 184 | unset($subpage_link); 185 | unset($subpage_type); 186 | } 187 | } -------------------------------------------------------------------------------- /library/UsualToolPdo.php: -------------------------------------------------------------------------------- 1 | query("set names utf8"); 27 | }catch(Exception $e){ 28 | echo$e->getMessage(); 29 | exit(); 30 | } 31 | $db->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE,\PDO::FETCH_ASSOC); 32 | return $db; 33 | } 34 | /** 35 | * 判断表是否存在 36 | * @param string $table 37 | * @return bool 38 | */ 39 | public static function ModTable($table){ 40 | $db=UTPdo::GetPdo(); 41 | try{ 42 | $query=$db->query("SELECT 1 FROM $table LIMIT 1"); 43 | }catch(Exception $e){ 44 | return false; 45 | } 46 | return true; 47 | } 48 | /** 49 | * 执行语句 50 | * @param string $sql SQL语句 51 | * @return bool 52 | */ 53 | public static function RunSql($sql){ 54 | $db=UTPdo::GetPdo(); 55 | $query=$db->exec($sql); 56 | if($query): 57 | return true; 58 | else: 59 | return false; 60 | endif; 61 | } 62 | /** 63 | * 查询数据 64 | * @param string $table 被表名 65 | * @param string $field 查询字段,多个字段以‘,’分割 66 | * @param string $where 查询条件 67 | * @param string $order 排序方式,例:id desc/id asc 68 | * @param string|int $limit 数据显示数目,例:10 69 | * @param string $lang 是否开启语言识别 70 | * @return array 返回数组,例:array("querydata"=>array(),"curnum"=>0,"querynum"=>0) 71 | */ 72 | public static function QueryData($table,$field='',$where='',$order='',$limit='',$lang='0'){ 73 | $field=empty($field) ? "*" : $field; 74 | if($lang!="0"): 75 | if(is_numeric($lang)): 76 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 77 | else: 78 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 79 | endif; 80 | else: 81 | $where=empty($where) ? "" : "where ".$where; 82 | endif; 83 | $order=empty($order) ? "" : "order by ".$order; 84 | $config=UsualToolInc\UTInc::GetConfig(); 85 | if(strpos($config['PDO_DSN'],'sqlsrv')!==false): 86 | $limit=empty($limit) ? "" : "top ".$limit; 87 | $sql="select ".$limit." ".$field." from ".$table." ".$where." ".$order; 88 | else: 89 | $limit=empty($limit) ? "" : "limit ".$limit; 90 | $sql="select ".$field." from ".$table." ".$where." ".$order." ".$limit; 91 | endif; 92 | $db=UTPdo::GetPdo(); 93 | $array = array(); 94 | $res=$db->query($sql); 95 | $curnum=0; 96 | while($rows=$res->fetch()){ 97 | $curnum++; 98 | $array[]=$rows; 99 | } 100 | $querynum=empty($limit) ? $curnum : UTPdo::QueryNum("select count(*) from ".$table." ".$where." ".$order); 101 | $data=array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 102 | return $data; 103 | } 104 | /** 105 | * 执行SQL并返回结果集 106 | * @param string $sql SQL语句 107 | * @return array 返回数组,例:array("querydata"=>array(),"querynum"=>0) 108 | */ 109 | public static function JoinQuery($sql){ 110 | $db=UTPdo::GetPdo(); 111 | $array = array(); 112 | $res=$db->query($sql); 113 | $curnum=0; 114 | while($rows=$res->fetch()){ 115 | $curnum++; 116 | $array[]=$rows; 117 | } 118 | $querynum=UTPdo::QueryNum($sql); 119 | return array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 120 | } 121 | /** 122 | * 创建数据 123 | * @param string $table 被表名 124 | * @param string $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 125 | * @return bool 126 | */ 127 | public static function InsertData($table,$data){ 128 | $db=UTPdo::GetPdo(); 129 | $sql="insert into ".$table." (".implode(',',array_keys($data)).") values ('".implode("','",array_values($data))."')"; 130 | $db->exec($sql); 131 | $query=$db->lastInsertId(); 132 | if($query): 133 | return $query; 134 | else: 135 | return false; 136 | endif; 137 | } 138 | /** 139 | * 更新数据 140 | * @param string $table 表名 141 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 142 | * @param string $where 条件 143 | * @return bool 144 | */ 145 | public static function UpdateData($table,$data,$where){ 146 | $db=UTPdo::GetPdo(); 147 | $updatestr=''; 148 | if(!empty($data)): 149 | foreach($data as $k=>$v): 150 | if(preg_match('/\+\d/is',$v)): 151 | $updatestr.=$k."=".$v.","; 152 | else: 153 | $updatestr.=$k."='".$v."',"; 154 | endif; 155 | endforeach; 156 | $updatestr=rtrim($updatestr,','); 157 | endif; 158 | $sql="update ".$table." set ".$updatestr." where ".$where; 159 | $query=$db->exec($sql); 160 | if($query): 161 | return true; 162 | else: 163 | return false; 164 | endif; 165 | } 166 | /** 167 | * 删除数据 168 | * @param string $table 表名 169 | * @param string $where 条件 170 | * @return bool 171 | */ 172 | public static function DelData($table,$where){ 173 | $db=UTPdo::GetPdo(); 174 | $sql="delete from ".$table." where ".$where; 175 | $query=$db->exec($sql); 176 | if($query): 177 | return true; 178 | else: 179 | return false; 180 | endif; 181 | } 182 | /** 183 | * 统计记录数目 184 | * @param string $sql SQL语句 185 | * @return int 186 | */ 187 | public static function QueryNum($sql){ 188 | $db=UTPdo::GetPdo(); 189 | $query=$db->prepare($sql); 190 | $query->execute(); 191 | $querynum=$query->fetchColumn(); 192 | return $querynum; 193 | } 194 | } -------------------------------------------------------------------------------- /library/UsualToolPgsql.php: -------------------------------------------------------------------------------- 1 | array(),"curnum"=>0,"querynum"=>0) 69 | */ 70 | public static function QueryData($table,$field='',$where='',$order='',$limit='',$lang='0'){ 71 | $field=empty($field) ? "*" : $field; 72 | if($lang!="0"): 73 | if(is_numeric($lang)): 74 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 75 | else: 76 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 77 | endif; 78 | else: 79 | $where=empty($where) ? "" : "where ".$where; 80 | endif; 81 | $order=empty($order) ? "" : "order by ".$order; 82 | $limit=empty($limit) ? "" : "limit ".$limit; 83 | $sql="select ".$field." from ".$table." ".$where." ".$order." ".$limit; 84 | $db=UTPgsql::GetPgsql(); 85 | $array = array(); 86 | $result = @pg_query($db,$sql); 87 | $curnum=@pg_num_rows($result); 88 | $querynum=empty($limit) ? $curnum : UTPgsql::QueryNum("select ".$field." from ".$table." ".$where." ".$order); 89 | while($rows=@pg_fetch_object($result)){ 90 | $array[] = UTPgsql::ObjectToArray($rows); 91 | } 92 | $data=array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 93 | return $data; 94 | } 95 | /** 96 | * 执行SQL并返回结果集 97 | * @param string $sql SQL语句 98 | * @return array 返回数组,例:array("querydata"=>array(),"querynum"=>0) 99 | */ 100 | public static function JoinQuery($sql){ 101 | $db=UTPgsql::GetPgsql(); 102 | $array = array(); 103 | $result = @pg_query($db,$sql); 104 | $curnum=@pg_num_rows($result); 105 | $querynum=UTPgsql::QueryNum($sql); 106 | while($rows=@pg_fetch_object($result)){ 107 | $array[] = UTPgsql::ObjectToArray($rows); 108 | } 109 | return array("querydata"=>$array,"curnum"=>$curnum,"querynum"=>$querynum); 110 | } 111 | /** 112 | * 新增数据 113 | * @param string $table 被表名 114 | * @param string $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 115 | * @return bool 116 | */ 117 | public static function InsertData($table,$data){ 118 | $db=UTPgsql::GetPgsql(); 119 | $query=@pg_insert($db,$table,$data); 120 | if($query): 121 | return true; 122 | else: 123 | return false; 124 | endif; 125 | } 126 | /** 127 | * 更新数据 128 | * @param string $table 表名 129 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 130 | * @param string $where 条件 131 | * @return bool 132 | */ 133 | public static function UpdateData($table,$data,$where){ 134 | $db=UTPgsql::GetPgsql(); 135 | $updatestr=''; 136 | if(!empty($data)): 137 | foreach($data as $k=>$v): 138 | if(preg_match('/\+\d/is',$v)): 139 | $updatestr.=$k."=".$v.","; 140 | else: 141 | $updatestr.=$k."='".$v."',"; 142 | endif; 143 | endforeach; 144 | $updatestr=rtrim($updatestr,','); 145 | endif; 146 | $sql="update ".$table." set ".$updatestr." where ".$where; 147 | $query=@pg_query($db,$sql); 148 | if($query): 149 | return true; 150 | else: 151 | return false; 152 | endif; 153 | } 154 | /** 155 | * 删除数据 156 | * @param string $table 表名 157 | * @param string $where 条件 158 | * @return bool 159 | */ 160 | public static function DelData($table,$where){ 161 | $db=UTPgsql::GetPgsql(); 162 | $sql="delete from ".$table." where ".$where; 163 | $query=@pg_query($db,$sql); 164 | if($query): 165 | return true; 166 | else: 167 | return false; 168 | endif; 169 | } 170 | /** 171 | * 获取数据标签 172 | * @param string $table 表名 173 | * @param string $field 标签字段,只能为1个 174 | * @param string $where 条件 175 | * @param string $order 排序方式 176 | * @param string $lang 是否自动开启语言,默认0关闭 177 | * @return array 返回数组,例:array('tags'=>$taglist) 178 | */ 179 | public static function TagData($table,$field='',$where='',$order='',$lang='0'){ 180 | global$language; 181 | $db=UTPgsql::GetPgsql(); 182 | $tags=""; 183 | $field=empty($field) ? "*" : $field; 184 | if($lang!="0"): 185 | if(is_numeric($lang)): 186 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where.""; 187 | else: 188 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where.""; 189 | endif; 190 | else: 191 | $where=empty($where) ? "" : "where ".$where.""; 192 | endif; 193 | $order=empty($order) ? "" : "order by ".$order.""; 194 | if(UTPgsql::ModTable($table)): 195 | $sql="select ".$field." from ".$table." ".$where." ".$order; 196 | $tag = @pg_query($db,$sql); 197 | while($rows=@pg_fetch_object($tag)): 198 | $rows=UTPgsql::ObjectToArray($rows); 199 | $tags="".$tags.",".$rows[$field]; 200 | endwhile; 201 | $taglist=join(',',array_unique(array_diff(explode(",",$tags),array("")))); 202 | $taglists[]=array('tags'=>$taglist); 203 | return $taglists; 204 | else: 205 | return array(); 206 | endif; 207 | } 208 | /** 209 | * 获取数据首图 210 | * @param string $table 表名 211 | * @param string $field 检索字段,只能为1个 212 | * @param string $where 条件 213 | * @return array 返回数组,在其数组中返回指定字段的第一张图片imageurl 214 | */ 215 | public static function FigureData($table,$field,$where='',$limit=''){ 216 | $db=UTPgsql::GetPgsql(); 217 | $where=empty($where) ? "" : "where ".$where; 218 | $limit=empty($limit) ? "" : "limit ".$limit; 219 | if(UTPgsql::ModTable($table)): 220 | $sql="SELECT ".$field." from ".$table." ".$where." ".$limit; 221 | $query = @pg_query($db,$sql); 222 | $figuredata=array(); 223 | while($rows=@pg_fetch_object($query)): 224 | $rows=UTPgsql::ObjectToArray($rows); 225 | $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.bmp|\.png]))[\'|\"].*?[\/]?>/"; 226 | preg_match_all($pattern,$rows[$field],$matchcontent); 227 | $rows['imageurl']=isset($matchcontent[1][0]) ? $matchcontent[1][0] : ''; 228 | $count=count($rows); 229 | for($i=0;$i<$count;$i++): 230 | unset($rows[$i]); 231 | endfor; 232 | array_push($figuredata,$rows); 233 | endwhile; 234 | return $figuredata; 235 | else: 236 | return array(); 237 | endif; 238 | } 239 | /** 240 | * 对象转数组 241 | * @param string $obj 对象 242 | * @return array 243 | */ 244 | public static function ObjectToArray($obj){ 245 | $ret = array(); 246 | foreach($obj as $key => $value){ 247 | if(is_array($value) || is_object($value)){ 248 | $ret[$key] = UTPgsql::ObjectToArray($value); 249 | }else{ 250 | $ret[$key] = $value; 251 | } 252 | } 253 | return $ret; 254 | } 255 | /** 256 | * 统计记录数目 257 | * @param string $sql SQL语句 258 | * @return int 259 | */ 260 | public static function QueryNum($sql){ 261 | $db=UTPgsql::GetPgsql(); 262 | $query = @pg_query($db,$sql); 263 | return @pg_num_rows($query); 264 | } 265 | /** 266 | * 释放查询(pg_query)内存,终止结果 267 | * @return string 268 | * @return bool 269 | */ 270 | public static function FreeRes($res){ 271 | return @pg_free_result($res); 272 | } 273 | /** 274 | * 返回最近的出错记录 275 | * @return string 276 | */ 277 | public static function ErrorMsg(){ 278 | $db=UTPgsql::GetPgsql(); 279 | return @pg_last_error($db); 280 | } 281 | /** 282 | * 获取PostgreSQL版本号 283 | * @return array 284 | */ 285 | public static function Version(){ 286 | $db=UTPgsql::GetPgsql(); 287 | return @pg_version($db); 288 | } 289 | } -------------------------------------------------------------------------------- /library/UsualToolRedis.php: -------------------------------------------------------------------------------- 1 | connect($config["REDIS_HOST"],$config["REDIS_PORT"]); 26 | if($config["REDIS_PASS"]!="UT"): 27 | $db->auth($config["REDIS_PASS"]); 28 | endif; 29 | return $db; 30 | } 31 | /** 32 | * 判断元素是否存在 33 | * @param string $key 键 34 | * @return bool 35 | */ 36 | public static function ModTable($key){ 37 | $db=UTRedis::GetRedis(); 38 | $res=$db->exists($key); 39 | if(!$res){ 40 | return false; 41 | }else{ 42 | return true; 43 | } 44 | } 45 | /** 46 | * 查询数据 47 | * @param string|array $key 键,单查xxx或多查array("xxx","yyy") 48 | * @param string $type 是否批量查询。0为单查,1为多查。 49 | * @return array 50 | */ 51 | public static function QueryData($key,$type='0'){ 52 | $db=UTRedis::GetRedis(); 53 | if($type==0): 54 | return json_decode($db->get($key),true); 55 | else: 56 | return json_decode($db->mget(json_encode($key)),true); 57 | endif; 58 | } 59 | /** 60 | * 创建数据 61 | * @param string $key 键 62 | * @param string|array $data 值 63 | * @param int $time 秒,0不设置过期时间,1设置过期时间为DBCACHE_TIME 64 | * @return bool 65 | */ 66 | public static function InsertData($key,$data,$time='0'){ 67 | $db=UTRedis::GetRedis(); 68 | $data=is_array($data) ? json_encode($data) : $data; 69 | $config=UsualToolInc\UTInc::GetConfig(); 70 | if($time==0): 71 | $db->set($key,$data); 72 | else: 73 | $db->set($key,$data,$config["DBCACHE_TIME"]); 74 | endif; 75 | } 76 | /** 77 | * 编辑数据 78 | * @param string $key 键 79 | * @param string|array $data 值 80 | * @param int $time 秒,0不设置过期时间,1设置过期时间为REDIS_TIME 81 | * @return bool 82 | */ 83 | public static function UpdateData($key,$data,$time='0'){ 84 | $db=UTRedis::GetRedis(); 85 | $data=is_array($data) ? json_encode($data) : $data; 86 | if(!UTRedis::ModTable($key)): 87 | return false; 88 | else: 89 | if($time==0): 90 | $db->set($key,$data); 91 | else: 92 | $db->set($key,$data,$config["DBCACHE_TIME"]); 93 | endif; 94 | endif; 95 | } 96 | /** 97 | * 删除数据 98 | * @param string $key 键 99 | */ 100 | public static function DelData($key){ 101 | $db=UTRedis::GetRedis(); 102 | $db->del($key); 103 | } 104 | /** 105 | * 批量删除指定前缀的键 106 | * @param string $pix 前缀 107 | */ 108 | public static function DelKeys($pix){ 109 | $db=UTRedis::GetRedis(); 110 | $keys=$db->keys($pix.'*'); 111 | if(!empty($keys)): 112 | foreach($keys as $key): 113 | $db->del($key); 114 | endforeach; 115 | return true; 116 | else: 117 | return false; 118 | endif; 119 | } 120 | /** 121 | * 查询所有键及键前缀模糊查询 122 | * @return array 123 | */ 124 | public static function QueryKey($key=''){ 125 | $db=UTRedis::GetRedis(); 126 | if(!empty($key)){ 127 | return $db->keys($key."*"); 128 | }else{ 129 | return $db->keys("*"); 130 | } 131 | } 132 | /** 133 | * 创建队列任务 134 | * @param array $array 加入队列的数组 135 | */ 136 | public static function AddQueue($array){ 137 | $db=UTRedis::GetRedis(); 138 | foreach($array as $k=>$v){ 139 | $db->rpush("queue",$v); 140 | } 141 | } 142 | /** 143 | * 执行队列任务 144 | * @return array 145 | */ 146 | public static function RunQueue(){ 147 | $db=UTRedis::GetRedis(); 148 | $value=$db->lpop('queue'); 149 | if($value): 150 | echo$value; 151 | else: 152 | echo"Queue Complete"; 153 | endif; 154 | } 155 | /** 156 | * 清空当前数据库 157 | * @return bool 158 | */ 159 | public static function Clear(){ 160 | $db=UTRedis::GetRedis(); 161 | return $db->flushdb(); 162 | } 163 | } -------------------------------------------------------------------------------- /library/UsualToolRoute.php: -------------------------------------------------------------------------------- 1 | $val){ 116 | $r.=$key."-".$val."-"; 117 | } 118 | } 119 | if(empty($r)){ 120 | $link=$m.$p."index.html"; 121 | }else{ 122 | $link=substr($m.$p.$r,0,-1).".html"; 123 | } 124 | }elseif($rule==2){ 125 | /**{m}/{p}/id/{id}.html*/ 126 | $m=empty($module) ? "/".$config["DEFAULT_MOD"]."/" : "/".$module."/"; 127 | $p=empty($page) ? $config["DEFAULT_PAGE"]."/" : $page."/"; 128 | $r=""; 129 | if(!empty($param)){ 130 | foreach(UTRoute::UrlToArray($param) as $key=>$val){ 131 | $r.=$key."/".$val."/"; 132 | } 133 | } 134 | if(empty($r)){ 135 | $link=$m.$p; 136 | }else{ 137 | $link=substr($m.$p.$r,0,-1).".html"; 138 | } 139 | } 140 | $d=parse_url($config["APPURL"])["host"]; 141 | $e=str_replace("/","",explode($d,$config["APPURL"])[1]); 142 | if(!empty($e)){ 143 | return $appurl.$link; 144 | }else{ 145 | return $link; 146 | } 147 | } 148 | /** 149 | * 解析URL 150 | * @param string $url 151 | * @return array 152 | */ 153 | public static function UrlToArray($url){ 154 | $query = explode('&',$url); 155 | $params = array(); 156 | foreach ($query as $param) { 157 | $item = explode('=', $param); 158 | $params[$item[0]] = $item[1]; 159 | } 160 | return $params; 161 | } 162 | /** 163 | * 获取指定URL参数值 164 | * @param string $url 165 | * @param string $key 166 | * @return string 167 | */ 168 | public static function GetUrlVal($url,$key){ 169 | $res = ''; 170 | $a = strpos($url,'?'); 171 | if($a!==false){ 172 | $str = substr($url,$a+1); 173 | $arr = explode('&',$str); 174 | foreach($arr as $k=>$v){ 175 | $tmp = explode('=',$v); 176 | if(!empty($tmp[0]) && !empty($tmp[1])){ 177 | $barr[$tmp[0]] = $tmp[1]; 178 | } 179 | } 180 | } 181 | if(!empty($barr[$key])){ 182 | $res = $barr[$key]; 183 | } 184 | return $res; 185 | } 186 | } -------------------------------------------------------------------------------- /library/UsualToolRsa.php: -------------------------------------------------------------------------------- 1 | private_key=$private_key; 20 | $this->public_key=$public_key; 21 | } 22 | /** 23 | * 获取私钥 24 | * @return bool|resource 25 | */ 26 | public function GetPrivateKey() { 27 | $privKey = $this->private_key; 28 | return openssl_pkey_get_private($privKey); 29 | } 30 | /** 31 | * 获取公钥 32 | * @return bool|resource 33 | */ 34 | public function GetPublicKey(){ 35 | $publicKey = $this->public_key; 36 | return openssl_pkey_get_public($publicKey); 37 | } 38 | /** 39 | * 私钥加密 40 | * @param string $data 41 | * @return null|string 42 | */ 43 | public function PrivEncrypt($data=''){ 44 | if (!is_string($data)) { 45 | return null; 46 | } 47 | return openssl_private_encrypt($data,$encrypted,$this->GetPrivateKey()) ? base64_encode($encrypted) : null; 48 | } 49 | /** 50 | * 公钥加密 51 | * @param string $data 52 | * @return null|string 53 | */ 54 | public function PublicEncrypt($data=''){ 55 | if (!is_string($data)) { 56 | return null; 57 | } 58 | return openssl_public_encrypt($data,$encrypted,$this->GetPublicKey()) ? base64_encode($encrypted) : null; 59 | } 60 | /** 61 | * 私钥解密 62 | * @param string $encrypted 63 | * @return null 64 | */ 65 | public function PrivDecrypt($encrypted=''){ 66 | if (!is_string($encrypted)) { 67 | return null; 68 | } 69 | return (openssl_private_decrypt(base64_decode($encrypted), $decrypted, $this->GetPrivateKey())) ? $decrypted : null; 70 | } 71 | /** 72 | * 公钥解密 73 | * @param string $encrypted 74 | * @return null 75 | */ 76 | public function PublicDecrypt($encrypted=''){ 77 | if (!is_string($encrypted)) { 78 | return null; 79 | } 80 | return (openssl_public_decrypt(base64_decode($encrypted), $decrypted, $this->GetPublicKey())) ? $decrypted : null; 81 | } 82 | } -------------------------------------------------------------------------------- /library/UsualToolSockets.php: -------------------------------------------------------------------------------- 1 | master = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); 24 | socket_set_option($this->master, SOL_SOCKET, SO_REUSEADDR, 1); 25 | socket_bind($this->master,$host,$port); 26 | socket_listen($this->master, self::LISTEN_SOCKET_NUM); 27 | echo"UT WebSockets Connected.\r\n"; 28 | } catch (\Exception $e) { 29 | $err_code = socket_last_error(); 30 | $err_msg = socket_strerror($err_code); 31 | $this->error([ 32 | 'error_init_server', 33 | $err_code, 34 | $err_msg 35 | ]); 36 | echo$err_msg."\r\n"; 37 | } 38 | $this->sockets[0] = ['resource' => $this->master]; 39 | if(strpos(php_uname(),"Windows")!==false){ 40 | $pid = get_current_user(); 41 | }else{ 42 | $pid = posix_getpid(); 43 | } 44 | $this->Debug(array("server"=>$this->master,"pid"=>$pid)); 45 | 46 | while (true) { 47 | try { 48 | $this->DoServer(); 49 | } catch (\Exception $e) { 50 | $this->Error([ 51 | 'error_do_server', 52 | $e->getCode(), 53 | $e->getMessage() 54 | ]); 55 | } 56 | } 57 | } 58 | private function DoServer() { 59 | $write = $except = NULL; 60 | $sockets = array_column($this->sockets, 'resource'); 61 | $read_num = socket_select($sockets, $write, $except, NULL); 62 | if (false === $read_num) { 63 | $this->Error([ 64 | 'error_select', 65 | $err_code = socket_last_error(), 66 | socket_strerror($err_code) 67 | ]); 68 | return; 69 | } 70 | foreach ($sockets as $socket) { 71 | if ($socket == $this->master) { 72 | $client = socket_accept($this->master); 73 | if (false === $client) { 74 | $this->error([ 75 | 'err_accept', 76 | $err_code = socket_last_error(), 77 | socket_strerror($err_code) 78 | ]); 79 | continue; 80 | } else { 81 | self::Connect($client); 82 | continue; 83 | } 84 | } else { 85 | $bytes = @socket_recv($socket, $buffer, 2048, 0); 86 | if ($bytes < 9) { 87 | $recv_msg = $this->DisConnect($socket); 88 | } else { 89 | if (!$this->sockets[(int)$socket]['handshake']) { 90 | self::Handshake($socket, $buffer); 91 | continue; 92 | } else { 93 | $recv_msg = self::parse($buffer); 94 | } 95 | } 96 | array_unshift($recv_msg, 'receive_msg'); 97 | $msg = self::DealMsg($socket, $recv_msg); 98 | 99 | $this->Broadcast($msg); 100 | } 101 | } 102 | } 103 | /* 104 | * 将socket添加到已连接列表,但握手状态留空; 105 | */ 106 | public function Connect($socket) { 107 | socket_getpeername($socket, $ip, $port); 108 | $socket_info = [ 109 | 'resource' => $socket, 110 | 'uname' => '', 111 | 'handshake' => false, 112 | 'ip' => $ip, 113 | 'port' => $port, 114 | ]; 115 | $this->sockets[(int)$socket] = $socket_info; 116 | $this->Debug(array_merge(['socket_connect'], $socket_info)); 117 | } 118 | /* 119 | * 客户端关闭连接 120 | * @return array 121 | */ 122 | private function DisConnect($socket) { 123 | $recv_msg = [ 124 | 'type' => 'ut-out', 125 | 'content' => $this->sockets[(int)$socket]['uname'], 126 | ]; 127 | unset($this->sockets[(int)$socket]); 128 | return $recv_msg; 129 | } 130 | /* 131 | * 算法握手 132 | * @return bool 133 | */ 134 | public function Handshake($socket, $buffer) { 135 | $line_with_key = substr($buffer, strpos($buffer, 'Sec-WebSocket-Key:') + 18); 136 | $key = trim(substr($line_with_key, 0, strpos($line_with_key, "\r\n"))); 137 | $upgrade_key = base64_encode(sha1($key . "258EAFA5-E914-47DA-95CA-C5AB0DC85B11", true)); 138 | $upgrade_message = "HTTP/1.1 101 Switching Protocols\r\n"; 139 | $upgrade_message .= "Upgrade: websocket\r\n"; 140 | $upgrade_message .= "Sec-WebSocket-Version: 13\r\n"; 141 | $upgrade_message .= "Connection: Upgrade\r\n"; 142 | $upgrade_message .= "Sec-WebSocket-Accept:" . $upgrade_key . "\r\n\r\n"; 143 | socket_write($socket, $upgrade_message, strlen($upgrade_message)); 144 | $this->sockets[(int)$socket]['handshake'] = true; 145 | socket_getpeername($socket, $ip, $port); 146 | $this->Debug([ 147 | 'hand_shake', 148 | $socket, 149 | $ip, 150 | $port 151 | ]); 152 | $msg = [ 153 | 'type' => 'handshake', 154 | 'content' => 'done', 155 | ]; 156 | $msg = $this->Build(json_encode($msg)); 157 | socket_write($socket, $msg, strlen($msg)); 158 | return true; 159 | } 160 | /* 161 | * 解析数据 162 | * @return bool|string 163 | */ 164 | private function Parse($buffer) { 165 | $decoded = ''; 166 | $len = ord($buffer[1]) & 127; 167 | if ($len === 126) { 168 | $masks = substr($buffer, 4, 4); 169 | $data = substr($buffer, 8); 170 | } else if ($len === 127) { 171 | $masks = substr($buffer, 10, 4); 172 | $data = substr($buffer, 14); 173 | } else { 174 | $masks = substr($buffer, 2, 4); 175 | $data = substr($buffer, 6); 176 | } 177 | for ($index = 0; $index < strlen($data); $index++) { 178 | $decoded .= $data[$index] ^ $masks[$index % 4]; 179 | } 180 | return json_decode($decoded, true); 181 | } 182 | /* 183 | * 组装socket数据帧 184 | * @return string 185 | */ 186 | private function Build($msg) { 187 | $frame = []; 188 | $frame[0] = '81'; 189 | $len = strlen($msg); 190 | if ($len < 126) { 191 | $frame[1] = $len < 16 ? '0' . dechex($len) : dechex($len); 192 | } else if ($len < 65025) { 193 | $s = dechex($len); 194 | $frame[1] = '7e' . str_repeat('0', 4 - strlen($s)) . $s; 195 | } else { 196 | $s = dechex($len); 197 | $frame[1] = '7f' . str_repeat('0', 16 - strlen($s)) . $s; 198 | } 199 | $data = ''; 200 | $l = strlen($msg); 201 | for ($i = 0; $i < $l; $i++) { 202 | $data .= dechex(ord($msg[$i])); 203 | } 204 | $frame[2] = $data; 205 | $data = implode('', $frame); 206 | return pack("H*", $data); 207 | } 208 | /* 209 | * 拼装信息 210 | * @param $socket 211 | * @param $recv_msg 212 | * @return string 213 | */ 214 | private function DealMsg($socket, $recv_msg) { 215 | $msg_type = $recv_msg['type']; 216 | $msg_content = $recv_msg['content']; 217 | $response = []; 218 | switch ($msg_type) { 219 | //登陆消息 220 | case 'ut-login': 221 | $this->sockets[$socket]['uname'] = $msg_content; 222 | $response['type'] = 'ut-login'; 223 | $response['content'] = $msg_content; 224 | $response['user_list'] = array_column($this->sockets, 'uname'); 225 | $response['sendtime'] = date('Y-m-d H:i:s',time()); 226 | break; 227 | //退出消息 228 | case 'ut-out': 229 | $response['type'] = 'ut-out'; 230 | $response['content'] = $msg_content; 231 | $response['user_list'] = array_column($this->sockets, 'uname'); 232 | $response['sendtime'] = date('Y-m-d H:i:s',time()); 233 | break; 234 | //单对多消息 235 | case 'ut-room': 236 | $response['type'] = 'ut-room'; 237 | $response['roomid'] = $recv_msg['roomid']; 238 | $response['from'] = $this->sockets[$socket]['uname']; 239 | $response['content'] = $msg_content; 240 | $response['sendtime'] = date('Y-m-d H:i:s',time()); 241 | if(!empty($recv_msg['item']) && !empty($recv_msg['roomid'])){ 242 | file_put_contents(APP_ROOT.'/'.$recv_msg['item'].'/room-'.$recv_msg['roomid'].'-'.date("Ymd").'.utlog', json_encode($response) . "\r\n", FILE_APPEND); 243 | } 244 | break; 245 | //单对单消息 246 | case 'ut-chat': 247 | $response['type'] = 'ut-chat'; 248 | $response['startuid'] = $recv_msg['startuid']; 249 | $response['enduid'] = $recv_msg['enduid']; 250 | $response['from'] = $this->sockets[$socket]['uname']; 251 | $response['content'] = $msg_content; 252 | $response['sendtime'] = date('Y-m-d H:i:s',time()); 253 | if(!empty($recv_msg['item'])){ 254 | if(strpos($recv_msg['startuid'],'u')!==false){ 255 | file_put_contents(APP_ROOT.'/'.$recv_msg['item'].'/chat-'.$recv_msg['startuid'].'-'.$recv_msg['enduid'].'.utlog', json_encode($response) . "\r\n", FILE_APPEND); 256 | }else{ 257 | file_put_contents(APP_ROOT.'/'.$recv_msg['item'].'/chat-'.$recv_msg['enduid'].'-'.$recv_msg['startuid'].'.utlog', json_encode($response) . "\r\n", FILE_APPEND); 258 | } 259 | } 260 | break; 261 | } 262 | return $this->Build(json_encode($response)); 263 | } 264 | /* 265 | * 广播消息 266 | */ 267 | private function Broadcast($data) { 268 | foreach ($this->sockets as $socket) { 269 | if ($socket['resource'] == $this->master) { 270 | continue; 271 | } 272 | socket_write($socket['resource'], $data, strlen($data)); 273 | echo$data."\r\n"; 274 | } 275 | } 276 | /* 277 | * debug信息 278 | */ 279 | private function Debug(array $info) { 280 | $time = date('Y-m-d H:i:s'); 281 | array_unshift($info, $time); 282 | $info = array_map('json_encode', $info); 283 | file_put_contents(APP_ROOT.'/log/socket.log', implode(' | ', $info) . "\r\n", FILE_APPEND); 284 | } 285 | /* 286 | * 记录错误信息 287 | */ 288 | private function Error(array $info) { 289 | $time = date('Y-m-d H:i:s'); 290 | array_unshift($info, $time); 291 | $info = array_map('json_encode', $info); 292 | file_put_contents(APP_ROOT.'/log/socket.log', implode(' | ', $info) . "\r\n", FILE_APPEND); 293 | } 294 | } -------------------------------------------------------------------------------- /library/UsualToolSpider.php: -------------------------------------------------------------------------------- 1 | agent = $agent; 35 | return $this; 36 | } 37 | public function SetCookies($cookies){ 38 | $this->cookies = $cookies; 39 | return $this; 40 | } 41 | public function SetReferer($referer){ 42 | $this->referer = $referer; 43 | return $this; 44 | } 45 | public function SetIp($ip){ 46 | $this->ip = $ip; 47 | return $this; 48 | } 49 | // 设置curl参数 50 | public function SetOption($key, $value){ 51 | if ( $key===CURLOPT_HTTPHEADER ){ 52 | $this->header = array_merge($this->header,$value); 53 | }else{ 54 | $this->_option[$key] = $value; 55 | } 56 | return $this; 57 | } 58 | //设置多个列队默认排队数上限 59 | public function SetMultiMaxNum($num=0){ 60 | $this->multi_exec_num = (int)$num; 61 | return $this; 62 | } 63 | //用POST方式提交,支持多个URL 64 | public function Post($url, $vars, $timeout = 60){ 65 | # POST模式 66 | $this->SetOption( CURLOPT_HTTPHEADER, array('Accept-Language: zh-CN') ); 67 | $this->SetOption( CURLOPT_POST, true ); 68 | if (is_array($url)){ 69 | $myvars = array(); 70 | foreach ($url as $k=>$url){ 71 | if (isset($vars[$k])){ 72 | if (is_array($vars[$k])){ 73 | $myvars[$url] = http_build_query($vars[$k]); 74 | }else{ 75 | $myvars[$url] = $vars[$k]; 76 | } 77 | } 78 | } 79 | }else{ 80 | $myvars = array($url=>$vars); 81 | } 82 | $this->_post_data = $myvars; 83 | return $this->Get($url,$timeout); 84 | } 85 | //GET方式获取数据,支持多个URL 86 | public function Get($url, $timeout = 30){ 87 | if ( is_array($url) ){ 88 | $getone = false; 89 | $urls = $url; 90 | }else{ 91 | $getone = true; 92 | $urls = array($url); 93 | } 94 | $data = $this->RequestUrls($urls, $timeout); 95 | $this->ClearSet(); 96 | if ( $getone ){ 97 | $this->http_data = $this->http_data[$url]; 98 | $encode = mb_detect_encoding($data[$url], array('GB2312','GBK','UTF-8')); 99 | if($encode=="GB2312"){$datas = iconv("GBK","UTF-8",$data[$url]);} 100 | else if($encode=="GBK"){$datas = iconv("GBK","UTF-8",$data[$url]);} 101 | else if($encode=="EUC-CN"){$datas = iconv("GBK","UTF-8",$data[$url]);} 102 | else{$datas =$data[$url];} 103 | return $datas; 104 | }else{ 105 | return $data; 106 | } 107 | } 108 | //创建一个CURL对象 109 | public function _create($url,$timeout){ 110 | if ( false===strpos($url, '://') ){ 111 | preg_match('#^(http(?:s)?\://[^/]+/)#', $_SERVER["SCRIPT_URI"] , $m); 112 | $the_url = $m[1].ltrim($url,'/'); 113 | }else{ 114 | $the_url = $url; 115 | } 116 | if ($this->ip){ 117 | # 如果设置了IP,则把URL替换,然后设置Host的头即可 118 | if ( preg_match('#^(http(?:s)?)\://([^/\:]+)(\:[0-9]+)?/#', $the_url.'/',$m) ){ 119 | $this->header[] = 'Host: '.$m[2]; 120 | $the_url = $m[1].'://'.$this->ip.$m[3].'/'.substr($the_url,strlen($m[0])); 121 | } 122 | } 123 | $ch = curl_init(); 124 | curl_setopt($ch, CURLOPT_URL, $the_url); 125 | curl_setopt($ch, CURLOPT_HEADER, false); 126 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 127 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 128 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 129 | curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); 130 | if ( preg_match('#^https://#i', $the_url) ){ 131 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 132 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 133 | } 134 | if ( $this->cookies ){ 135 | curl_setopt($ch, CURLOPT_COOKIE, http_build_query($this->cookies, '', ';')); 136 | } 137 | if ( $this->referer ){ 138 | curl_setopt($ch, CURLOPT_REFERER, $this->referer); 139 | } 140 | if ( $this->agent ){ 141 | curl_setopt($ch, CURLOPT_USERAGENT, $this->agent); 142 | } 143 | elseif ( array_key_exists('HTTP_USER_AGENT', $_SERVER) ){ 144 | curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 145 | } 146 | foreach ( $this->_option as $k => $v ){ 147 | curl_setopt($ch, $k, $v); 148 | } 149 | if ( $this->header ){ 150 | $header = array(); 151 | foreach ($this->header as $item){ 152 | # 防止有重复的header 153 | if (preg_match('#(^[^:]*):.*$#', $item,$m)){ 154 | $header[$m[1]] = $item; 155 | } 156 | } 157 | curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($header)); 158 | } 159 | # 设置POST数据 160 | if (isset($this->_post_data[$the_url])){ 161 | curl_setopt($ch , CURLOPT_POSTFIELDS , $this->_post_data[$the_url]); 162 | } 163 | return $ch; 164 | } 165 | //支持多线程获取网页 166 | protected function RequestUrls($urls, $timeout = 10){ 167 | # 去重 168 | $urls = array_unique($urls); 169 | if (!$urls)return array(); 170 | $mh = curl_multi_init(); 171 | # 监听列表 172 | $listener_list = array(); 173 | # 返回值 174 | $result = array(); 175 | # 总列队数 176 | $list_num = 0; 177 | # 排队列表 178 | $multi_list = array(); 179 | foreach ( $urls as $url ){ 180 | # 创建一个curl对象 181 | $current = $this->_create($url, $timeout); 182 | if ( $this->multi_exec_num>0 && $list_num>=$this->multi_exec_num ){ 183 | # 加入排队列表 184 | $multi_list[] = $url; 185 | }else{ 186 | # 列队数控制 187 | curl_multi_add_handle($mh, $current); 188 | $listener_list[$url] = $current; 189 | $list_num++; 190 | } 191 | $result[$url] = null; 192 | $this->http_data[$url] = null; 193 | } 194 | unset($current); 195 | $running = null; 196 | # 已完成数 197 | $done_num = 0; 198 | do{ 199 | while ( ($execrun = curl_multi_exec($mh, $running)) == CURLM_CALL_MULTI_PERFORM ); 200 | if ( $execrun != CURLM_OK ) break; 201 | while ( true==($done = curl_multi_info_read($mh)) ){ 202 | foreach ( $listener_list as $done_url=>$listener ){ 203 | if ( $listener === $done['handle'] ){ 204 | # 获取内容 205 | $this->http_data[$done_url] = $this->GetData(curl_multi_getcontent($done['handle']), $done['handle']); 206 | if ( $this->http_data[$done_url]['code'] != 200 ){ 207 | $result[$done_url] = false; 208 | }else{ 209 | # 返回内容 210 | $result[$done_url] = $this->http_data[$done_url]['data']; 211 | } 212 | curl_close($done['handle']); 213 | curl_multi_remove_handle($mh, $done['handle']); 214 | # 把监听列表里移除 215 | unset($listener_list[$done_url],$listener); 216 | $done_num++; 217 | # 如果还有排队列表,则继续加入 218 | if ( $multi_list ){ 219 | # 获取列队中的一条URL 220 | $current_url = array_shift($multi_list); 221 | # 创建CURL对象 222 | $current = $this->_create($current_url, $timeout); 223 | # 加入到列队 224 | curl_multi_add_handle($mh, $current); 225 | # 更新监听列队信息 226 | $listener_list[$current_url] = $current; 227 | unset($current); 228 | # 更新列队数 229 | $list_num++; 230 | } 231 | break; 232 | } 233 | } 234 | } 235 | if ($done_num>=$list_num)break; 236 | } while (true); 237 | # 关闭列队 238 | curl_multi_close($mh); 239 | return $result; 240 | } 241 | public function GetResultData(){ 242 | return $this->http_data; 243 | } 244 | protected function GetData($data, $ch){ 245 | $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); 246 | $result['code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); 247 | $result['data'] = substr($data, $header_size); 248 | $result['header'] = explode("\r\n", substr($data, 0, $header_size)); 249 | $result['time'] = curl_getinfo($ch, CURLINFO_TOTAL_TIME); 250 | return $result; 251 | } 252 | protected function ClearSet(){ 253 | $this->_option = array(); 254 | $this->header = array(); 255 | $this->ip = null; 256 | $this->cookies = null; 257 | $this->referer = null; 258 | $this->_post_data = array(); 259 | } 260 | } -------------------------------------------------------------------------------- /library/UsualToolSqlite.php: -------------------------------------------------------------------------------- 1 | query("select count(*) from sqlite_master where type='table' and name = '".$table."';"); 39 | if(!$result){ 40 | return false; 41 | }else{ 42 | return true; 43 | } 44 | } 45 | /** 46 | * 执行SQL语句 47 | * @param string $sql SQL语句 48 | * @return bool 49 | */ 50 | public static function RunSql($sql){ 51 | $db=UTSqlite::GetSqlite(); 52 | $result = $db->exec($sql); 53 | if($result){ 54 | return true; 55 | }else{ 56 | return false; 57 | } 58 | } 59 | /** 60 | * 获取单个或多个数据 61 | * @param string $table 被表名 62 | * @param string $field 查询字段,多个字段以‘,’分割 63 | * @param string $where 查询条件 64 | * @param string $order 排序方式,例:id desc/id asc 65 | * @param string|int $limit 数据显示数目,例:10 66 | * @param string $lang 是否开启语言识别 67 | * @return array 返回数组,例:array("querydata"=>array(),"curnum"=>0,"querynum"=>0) 68 | */ 69 | public static function QueryData($table,$field='',$where='',$order='',$limit='',$lang='0'){ 70 | global$language; 71 | $db=UTSqlite::GetSqlite(); 72 | $field=empty($field) ? "*" : $field; 73 | if($lang!="0"): 74 | if(is_numeric($lang)): 75 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 76 | else: 77 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 78 | endif; 79 | else: 80 | $where=empty($where) ? "" : "where ".$where; 81 | endif; 82 | $order=empty($order) ? "" : "order by ".$order; 83 | $limit=empty($limit) ? "" : "limit ".$limit; 84 | if(UTSqlite::ModTable($table)): 85 | $sql="select ".$field." from ".$table." ".$where." ".$order." ".$limit; 86 | $query=$db->query($sql); 87 | $querydata=array(); 88 | $xu=0; 89 | while($rows=$query->fetchArray(SQLITE3_ASSOC)): 90 | $xu=$xu+1; 91 | $count=count($rows); 92 | for($i=0;$i<$count;$i++): 93 | unset($rows[$i]); 94 | endfor; 95 | $rows['xu']=$xu; 96 | array_push($querydata,$rows); 97 | endwhile; 98 | $curnum=$xu; 99 | $querynum=empty($limit) ? $curnum : UTSqlite::QueryNum("select count(*) from ".$table." ".$where." ".$order); 100 | return array("querydata"=>$querydata,"curnum"=>$curnum,"querynum"=>$querynum); 101 | else: 102 | return array("querydata"=>array(),"curnum"=>0,"querynum"=>0); 103 | endif; 104 | } 105 | /** 106 | * 执行SQL并返回结果集 107 | * @param string $sql SQL语句 108 | * @return array 返回数组,例:array("querydata"=>array(),"querynum"=>0) 109 | */ 110 | public static function JoinQuery($sql){ 111 | $db=UTSqlite::GetSqlite(); 112 | $query=$db->query($sql); 113 | $querydata=array(); 114 | $curnum=0; 115 | while($rows=$query->fetchArray(SQLITE3_ASSOC)): 116 | $curnum++; 117 | array_push($querydata,$rows); 118 | endwhile; 119 | $querynum=UTSqlite::QueryNum($sql); 120 | return array("querydata"=>$querydata,"curnum"=>$curnum,"querynum"=>$querynum); 121 | } 122 | /** 123 | * 新增数据 124 | * @param string $table 被表名 125 | * @param string $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 126 | * @return bool 127 | */ 128 | public static function InsertData($table,$data){ 129 | $db=UTSqlite::GetSqlite(); 130 | $sql="insert into ".$table." (".implode(',',array_keys($data)).") values ('".implode("','",array_values($data))."')"; 131 | $query=UTSqlite::RunSql($sql); 132 | if($query): 133 | return $db->lastInsertRowID(); 134 | else: 135 | return false; 136 | endif; 137 | } 138 | /** 139 | * 更新数据 140 | * @param string $table 表名 141 | * @param array $data 字段及值的数组,例:array("字段1"=>"值1","字段2"=>"值2") 142 | * @param string $where 条件 143 | * @return bool 144 | */ 145 | public static function UpdateData($table,$data,$where){ 146 | $db=UTSqlite::GetSqlite(); 147 | $updatestr=''; 148 | if(!empty($data)): 149 | foreach($data as $k=>$v): 150 | if(preg_match('/\+\d/is',$v)): 151 | $updatestr.=$k."=".$v.","; 152 | else: 153 | $updatestr.=$k."='".$v."',"; 154 | endif; 155 | endforeach; 156 | $updatestr=rtrim($updatestr,','); 157 | endif; 158 | $sql="update ".$table." set ".$updatestr." where ".$where; 159 | $query=UTSqlite::RunSql($sql); 160 | if($query): 161 | return true; 162 | else: 163 | return false; 164 | endif; 165 | } 166 | /** 167 | * 删除数据 168 | * @param string $table 表名 169 | * @param string $where 条件 170 | * @return bool 171 | */ 172 | public static function DelData($table,$where){ 173 | $db=UTSqlite::GetSqlite(); 174 | $sql="delete from ".$table." where ".$where; 175 | $query=UTSqlite::RunSql($sql); 176 | if($query): 177 | return true; 178 | else: 179 | return false; 180 | endif; 181 | } 182 | /** 183 | * 获取数据标签 184 | * @param string $table 表名 185 | * @param string $field 标签字段,只能为1个 186 | * @param string $where 条件 187 | * @param string $order 排序方式 188 | * @param string $lang 是否自动开启语言,默认0关闭 189 | * @return array 返回数组,例:array('tags'=>$taglist) 190 | */ 191 | public static function TagData($table,$field='',$where='',$order='',$lang='0'){ 192 | global$language; 193 | $db=UTSqlite::GetSqlite(); 194 | $tags=""; 195 | $field=empty($field) ? "*" : $field; 196 | if($lang!="0"): 197 | if(is_numeric($lang)): 198 | $where=empty($where) ? "where lang='$language'" : "where lang='$language' and ".$where; 199 | else: 200 | $where=empty($where) ? "where lang='$lang'" : "where lang='$lang' and ".$where; 201 | endif; 202 | else: 203 | $where=empty($where) ? "" : "where ".$where; 204 | endif; 205 | $order=empty($order) ? "" : "order by ".$order; 206 | if(UTSqlite::ModTable($table)): 207 | $sql="select ".$field." from ".$table." ".$where." ".$order; 208 | $tag=$db->query($sql); 209 | while($rows=$tag->fetchArray(SQLITE3_ASSOC)): 210 | $tags=$tags.",".$rows[$field]; 211 | endwhile; 212 | $taglist=join(',',array_unique(array_diff(explode(",",$tags),array("")))); 213 | $taglists[]=array('tags'=>$taglist); 214 | return $taglists; 215 | else: 216 | return array(); 217 | endif; 218 | } 219 | /** 220 | * 获取数据首图 221 | * @param string $table 表名 222 | * @param string $field 检索字段,只能为1个 223 | * @param string $where 条件 224 | * @return array 返回数组,在其数组中返回指定字段的第一张图片imageurl 225 | */ 226 | public static function FigureData($table,$field,$where='',$limit=''){ 227 | $db=UTSqlite::GetSqlite(); 228 | $where=empty($where) ? "" : "where ".$where; 229 | $limit=empty($limit) ? "" : "limit ".$limit; 230 | if(UTMysql::ModTable($table)): 231 | $sql="SELECT ".$field." from ".$table." ".$where." ".$limit; 232 | $query=$db->query($sql); 233 | $figuredata=array(); 234 | while($rows=$query->fetchArray(SQLITE3_ASSOC)): 235 | $pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.bmp|\.png]))[\'|\"].*?[\/]?>/"; 236 | preg_match_all($pattern,$rows[$field],$matchcontent); 237 | $rows['imageurl']=isset($matchcontent[1][0]) ? $matchcontent[1][0] : ''; 238 | $count=count($rows); 239 | for($i=0;$i<$count;$i++): 240 | unset($rows[$i]); 241 | endfor; 242 | array_push($figuredata,$rows); 243 | endwhile; 244 | return $figuredata; 245 | else: 246 | return array(); 247 | endif; 248 | } 249 | /** 250 | * 统计记录数目 251 | * @param string $sql SQL语句 252 | * @return int 253 | */ 254 | public static function QueryNum($sql){ 255 | $db=UTSqlite::GetSqlite(); 256 | $num=$db->querySingle($sql); 257 | return $num; 258 | } 259 | /** 260 | * 在内存中打开一个数据库 261 | * @param string $data 数据库 262 | */ 263 | public static function Open($data){ 264 | $sqlite=new \SQLite3(); 265 | $db=$sqlite->open($data); 266 | return $db; 267 | } 268 | /** 269 | * 返回最近的出错记录 270 | * @return string 271 | */ 272 | public static function ErrorMsg(){ 273 | $db=UTSqlite::GetSqlite(); 274 | return $db->lastErrorMsg(); 275 | } 276 | /** 277 | * 获取SQLITE版本号 278 | * @return array 279 | */ 280 | public static function Version(){ 281 | $db=UTSqlite::GetSqlite(); 282 | return $db->version(); 283 | } 284 | } -------------------------------------------------------------------------------- /library/UsualToolWater.php: -------------------------------------------------------------------------------- 1 | $r,'g'=>$g,'b'=>$b); 110 | } 111 | } -------------------------------------------------------------------------------- /update/index.html: -------------------------------------------------------------------------------- 1 | /** 2 | * -------------------------------------------------------- 3 | * | ░░░░░░░░░ █ █░▀▀█▀▀░ ░░░░░░░░░ | 4 | * | ░░░░░░░ █▄▄▄█ █ | 5 | * | | 6 | * | Author:HuangDou Email:292951110@qq.com | 7 | * | QQ-Group:583610949 | 8 | * | WebSite:http://www.UsualTool.com | 9 | * | UT Framework is suitable for Apache2 protocol. | 10 | * -------------------------------------------------------- 11 | */ -------------------------------------------------------------------------------- /usualtool: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 |