From 892d3ca6c96498e87f6d5ac8a3cee6a0e73a509e Mon Sep 17 00:00:00 2001 From: Tinywan <756684177@qq.com> Date: Sun, 3 Jul 2016 09:22:15 +0800 Subject: [PATCH] Begin Project --- .htaccess | 8 + .idea/.name | 1 + .idea/ThinkPhpStudy.iml | 8 + .idea/copyright/profiles_settings.xml | 3 + .idea/encodings.xml | 6 + .idea/misc.xml | 19 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + Backend/Common/Common/index.html | 1 + Backend/Common/Conf/config.php | 4 + Backend/Common/Conf/index.html | 1 + Backend/Common/index.html | 1 + Backend/Home/Common/index.html | 1 + Backend/Home/Conf/config.php | 4 + Backend/Home/Conf/index.html | 1 + .../Home/Controller/IndexController.class.php | 8 + Backend/Home/Controller/index.html | 1 + Backend/Home/Model/index.html | 1 + Backend/Home/View/index.html | 1 + Backend/Home/index.html | 1 + .../Home/20914c0f075f91df3579ffbdf5180b02.php | 1 + Backend/Runtime/Cache/Home/index.html | 1 + Backend/Runtime/Cache/index.html | 1 + Backend/Runtime/Data/index.html | 1 + Backend/Runtime/Logs/Home/16_07_03.log | 20 + Backend/Runtime/Logs/Home/index.html | 1 + Backend/Runtime/Logs/index.html | 1 + Backend/Runtime/Temp/index.html | 1 + Backend/Runtime/index.html | 1 + Frontend/Common/Common/index.html | 1 + Frontend/Common/Conf/config.php | 4 + Frontend/Common/Conf/index.html | 1 + Frontend/Common/index.html | 1 + Frontend/Home/Common/index.html | 1 + Frontend/Home/Conf/config.php | 4 + Frontend/Home/Conf/index.html | 1 + .../Home/Controller/IndexController.class.php | 8 + Frontend/Home/Controller/index.html | 1 + Frontend/Home/Model/index.html | 1 + Frontend/Home/View/index.html | 1 + Frontend/Home/index.html | 1 + .../Home/20914c0f075f91df3579ffbdf5180b02.php | 1 + Frontend/Runtime/Cache/Home/index.html | 1 + Frontend/Runtime/Cache/index.html | 1 + Frontend/Runtime/Data/index.html | 1 + Frontend/Runtime/Logs/Home/16_07_03.log | 20 + Frontend/Runtime/Logs/Home/index.html | 1 + Frontend/Runtime/Logs/index.html | 1 + Frontend/Runtime/Temp/index.html | 1 + Frontend/Runtime/index.html | 1 + Public/README.md | 1 + README.md | 37 + ThinkPHP/Common/functions.php | 1550 ++++++++ ThinkPHP/Conf/convention.php | 167 + ThinkPHP/Conf/debug.php | 27 + ThinkPHP/LICENSE.txt | 32 + ThinkPHP/Lang/en-us.php | 51 + ThinkPHP/Lang/pt-br.php | 51 + ThinkPHP/Lang/zh-cn.php | 51 + ThinkPHP/Lang/zh-tw.php | 51 + .../Behavior/AgentCheckBehavior.class.php | 24 + .../Library/Behavior/BorisBehavior.class.php | 42 + .../Behavior/BrowserCheckBehavior.class.php | 34 + .../Behavior/BuildLiteBehavior.class.php | 87 + .../CheckActionRouteBehavior.class.php | 194 + .../Behavior/CheckLangBehavior.class.php | 77 + .../ChromeShowPageTraceBehavior.class.php | 610 ++++ .../Behavior/ContentReplaceBehavior.class.php | 47 + .../Behavior/CronRunBehavior.class.php | 66 + .../FireShowPageTraceBehavior.class.php | 2079 +++++++++++ .../Behavior/ParseTemplateBehavior.class.php | 95 + .../Behavior/ReadHtmlCacheBehavior.class.php | 117 + .../Behavior/RobotCheckBehavior.class.php | 41 + .../Behavior/ShowPageTraceBehavior.class.php | 119 + .../Behavior/ShowRuntimeBehavior.class.php | 69 + .../Behavior/TokenBuildBehavior.class.php | 54 + .../Behavior/UpgradeNoticeBehavior.class.php | 117 + .../Behavior/WriteHtmlCacheBehavior.class.php | 29 + ThinkPHP/Library/Org/Net/Http.class.php | 271 ++ ThinkPHP/Library/Org/Net/IpLocation.class.php | 233 ++ ThinkPHP/Library/Org/Util/ArrayList.class.php | 240 ++ .../Library/Org/Util/CodeSwitch.class.php | 200 + ThinkPHP/Library/Org/Util/Date.class.php | 569 +++ ThinkPHP/Library/Org/Util/Rbac.class.php | 285 ++ ThinkPHP/Library/Org/Util/Stack.class.php | 51 + ThinkPHP/Library/Org/Util/String.class.php | 248 ++ ThinkPHP/Library/Think/App.class.php | 213 ++ ThinkPHP/Library/Think/Auth.class.php | 231 ++ ThinkPHP/Library/Think/Behavior.class.php | 24 + ThinkPHP/Library/Think/Build.class.php | 165 + ThinkPHP/Library/Think/Cache.class.php | 127 + .../Think/Cache/Driver/Apachenote.class.php | 124 + .../Library/Think/Cache/Driver/Apc.class.php | 86 + .../Library/Think/Cache/Driver/Db.class.php | 138 + .../Think/Cache/Driver/Eaccelerator.class.php | 77 + .../Library/Think/Cache/Driver/File.class.php | 181 + .../Think/Cache/Driver/Memcache.class.php | 103 + .../Think/Cache/Driver/Memcached.class.php | 102 + .../Think/Cache/Driver/Memcachesae.class.php | 144 + .../Think/Cache/Driver/Redis.class.php | 107 + .../Think/Cache/Driver/Shmop.class.php | 186 + .../Think/Cache/Driver/Sqlite.class.php | 119 + .../Think/Cache/Driver/Wincache.class.php | 88 + .../Think/Cache/Driver/Xcache.class.php | 90 + ThinkPHP/Library/Think/Controller.class.php | 307 ++ .../Controller/HproseController.class.php | 61 + .../Controller/JsonRpcController.class.php | 39 + .../Think/Controller/RestController.class.php | 234 ++ .../Think/Controller/RpcController.class.php | 56 + .../Think/Controller/YarController.class.php | 42 + ThinkPHP/Library/Think/Crypt.class.php | 53 + .../Think/Crypt/Driver/Base64.class.php | 74 + .../Think/Crypt/Driver/Crypt.class.php | 83 + .../Library/Think/Crypt/Driver/Des.class.php | 241 ++ .../Think/Crypt/Driver/Think.class.php | 86 + .../Think/Crypt/Driver/Xxtea.class.php | 116 + ThinkPHP/Library/Think/Db.class.php | 137 + ThinkPHP/Library/Think/Db/Driver.class.php | 1149 ++++++ .../Think/Db/Driver/Firebird.class.php | 151 + .../Library/Think/Db/Driver/Mongo.class.php | 821 +++++ .../Library/Think/Db/Driver/Mysql.class.php | 235 ++ .../Library/Think/Db/Driver/Oracle.class.php | 168 + .../Library/Think/Db/Driver/Pgsql.class.php | 91 + .../Library/Think/Db/Driver/Sqlite.class.php | 98 + .../Library/Think/Db/Driver/Sqlsrv.class.php | 166 + ThinkPHP/Library/Think/Db/Lite.class.php | 466 +++ ThinkPHP/Library/Think/Dispatcher.class.php | 339 ++ ThinkPHP/Library/Think/Exception.class.php | 16 + ThinkPHP/Library/Think/Hook.class.php | 121 + ThinkPHP/Library/Think/Image.class.php | 191 + .../Library/Think/Image/Driver/GIF.class.php | 567 +++ .../Library/Think/Image/Driver/Gd.class.php | 542 +++ .../Think/Image/Driver/Imagick.class.php | 593 +++ ThinkPHP/Library/Think/Log.class.php | 104 + .../Library/Think/Log/Driver/File.class.php | 50 + .../Library/Think/Log/Driver/Sae.class.php | 49 + ThinkPHP/Library/Think/Model.class.php | 1910 ++++++++++ .../Library/Think/Model/AdvModel.class.php | 595 +++ .../Library/Think/Model/MergeModel.class.php | 403 +++ .../Library/Think/Model/MongoModel.class.php | 422 +++ .../Think/Model/RelationModel.class.php | 412 +++ .../Library/Think/Model/ViewModel.class.php | 243 ++ ThinkPHP/Library/Think/Page.class.php | 145 + ThinkPHP/Library/Think/Route.class.php | 316 ++ .../Library/Think/Session/Driver/Db.class.php | 173 + .../Think/Session/Driver/Memcache.class.php | 79 + .../Think/Session/Driver/Mysqli.class.php | 184 + ThinkPHP/Library/Think/Storage.class.php | 40 + .../Think/Storage/Driver/File.class.php | 123 + .../Think/Storage/Driver/Sae.class.php | 193 + ThinkPHP/Library/Think/Template.class.php | 700 ++++ .../Think/Template/Driver/Ease.class.php | 41 + .../Think/Template/Driver/Lite.class.php | 39 + .../Think/Template/Driver/Mobile.class.php | 28 + .../Think/Template/Driver/Smart.class.php | 40 + .../Think/Template/Driver/Smarty.class.php | 41 + .../Library/Think/Template/TagLib.class.php | 246 ++ .../Think/Template/TagLib/Cx.class.php | 614 ++++ .../Think/Template/TagLib/Html.class.php | 523 +++ ThinkPHP/Library/Think/Think.class.php | 344 ++ ThinkPHP/Library/Think/Upload.class.php | 429 +++ .../Library/Think/Upload/Driver/Bcs.class.php | 238 ++ .../Think/Upload/Driver/Bcs/bcs.class.php | 1318 +++++++ .../Upload/Driver/Bcs/mimetypes.class.php | 137 + .../Upload/Driver/Bcs/requestcore.class.php | 837 +++++ .../Library/Think/Upload/Driver/Ftp.class.php | 163 + .../Think/Upload/Driver/Local.class.php | 118 + .../Think/Upload/Driver/Qiniu.class.php | 102 + .../Driver/Qiniu/QiniuStorage.class.php | 333 ++ .../Library/Think/Upload/Driver/Sae.class.php | 106 + .../Think/Upload/Driver/Upyun.class.php | 218 ++ ThinkPHP/Library/Think/Verify.class.php | 293 ++ ThinkPHP/Library/Think/Verify/bgs/1.jpg | Bin 0 -> 30428 bytes ThinkPHP/Library/Think/Verify/bgs/2.jpg | Bin 0 -> 29677 bytes ThinkPHP/Library/Think/Verify/bgs/3.jpg | Bin 0 -> 32109 bytes ThinkPHP/Library/Think/Verify/bgs/4.jpg | Bin 0 -> 29081 bytes ThinkPHP/Library/Think/Verify/bgs/5.jpg | Bin 0 -> 27940 bytes ThinkPHP/Library/Think/Verify/bgs/6.jpg | Bin 0 -> 31381 bytes ThinkPHP/Library/Think/Verify/bgs/7.jpg | Bin 0 -> 30234 bytes ThinkPHP/Library/Think/Verify/bgs/8.jpg | Bin 0 -> 30188 bytes ThinkPHP/Library/Think/Verify/ttfs/1.ttf | Bin 0 -> 57520 bytes ThinkPHP/Library/Think/Verify/ttfs/2.ttf | Bin 0 -> 28328 bytes ThinkPHP/Library/Think/Verify/ttfs/3.ttf | Bin 0 -> 39308 bytes ThinkPHP/Library/Think/Verify/ttfs/4.ttf | Bin 0 -> 34852 bytes ThinkPHP/Library/Think/Verify/ttfs/5.ttf | Bin 0 -> 32664 bytes ThinkPHP/Library/Think/Verify/ttfs/6.ttf | Bin 0 -> 28036 bytes ThinkPHP/Library/Think/View.class.php | 229 ++ ThinkPHP/Library/Vendor/Boris/Boris.php | 174 + .../Vendor/Boris/CLIOptionsHandler.php | 85 + .../Library/Vendor/Boris/ColoredInspector.php | 273 ++ ThinkPHP/Library/Vendor/Boris/Config.php | 85 + .../Library/Vendor/Boris/DumpInspector.php | 16 + ThinkPHP/Library/Vendor/Boris/EvalWorker.php | 247 ++ .../Library/Vendor/Boris/ExportInspector.php | 14 + ThinkPHP/Library/Vendor/Boris/Inspector.php | 19 + .../Library/Vendor/Boris/ReadlineClient.php | 109 + .../Library/Vendor/Boris/ShallowParser.php | 233 ++ .../Vendor/EaseTemplate/template.core.php | 970 +++++ .../Vendor/EaseTemplate/template.ease.php | 42 + .../Vendor/Hprose/HproseClassManager.php | 53 + .../Library/Vendor/Hprose/HproseClient.php | 134 + .../Library/Vendor/Hprose/HproseCommon.php | 816 +++++ .../Library/Vendor/Hprose/HproseFormatter.php | 40 + .../Vendor/Hprose/HproseHttpClient.php | 314 ++ .../Vendor/Hprose/HproseHttpServer.php | 483 +++ ThinkPHP/Library/Vendor/Hprose/HproseIO.php | 29 + .../Library/Vendor/Hprose/HproseIOStream.php | 349 ++ .../Library/Vendor/Hprose/HproseReader.php | 672 ++++ ThinkPHP/Library/Vendor/Hprose/HproseTags.php | 62 + .../Library/Vendor/Hprose/HproseWriter.php | 301 ++ ThinkPHP/Library/Vendor/README.txt | 1 + .../SmartTemplate/class.smarttemplate.php | 392 ++ .../class.smarttemplatedebugger.php | 456 +++ .../class.smarttemplateparser.php | 365 ++ .../Library/Vendor/Smarty/Smarty.class.php | 1473 ++++++++ .../Library/Vendor/Smarty/SmartyBC.class.php | 460 +++ ThinkPHP/Library/Vendor/Smarty/debug.tpl | 133 + .../Smarty/plugins/block.textformat.php | 113 + .../Smarty/plugins/function.counter.php | 78 + .../Vendor/Smarty/plugins/function.cycle.php | 106 + .../Vendor/Smarty/plugins/function.fetch.php | 216 ++ .../plugins/function.html_checkboxes.php | 216 ++ .../Smarty/plugins/function.html_image.php | 138 + .../Smarty/plugins/function.html_options.php | 174 + .../Smarty/plugins/function.html_radios.php | 200 + .../plugins/function.html_select_date.php | 394 ++ .../plugins/function.html_select_time.php | 366 ++ .../Smarty/plugins/function.html_table.php | 177 + .../Vendor/Smarty/plugins/function.mailto.php | 152 + .../Vendor/Smarty/plugins/function.math.php | 87 + .../Smarty/plugins/modifier.capitalize.php | 65 + .../Smarty/plugins/modifier.date_format.php | 62 + .../plugins/modifier.debug_print_var.php | 105 + .../Vendor/Smarty/plugins/modifier.escape.php | 143 + .../Smarty/plugins/modifier.regex_replace.php | 55 + .../Smarty/plugins/modifier.replace.php | 33 + .../Smarty/plugins/modifier.spacify.php | 27 + .../Smarty/plugins/modifier.truncate.php | 59 + .../Smarty/plugins/modifiercompiler.cat.php | 30 + .../modifiercompiler.count_characters.php | 33 + .../modifiercompiler.count_paragraphs.php | 28 + .../modifiercompiler.count_sentences.php | 28 + .../plugins/modifiercompiler.count_words.php | 32 + .../plugins/modifiercompiler.default.php | 35 + .../plugins/modifiercompiler.escape.php | 90 + .../plugins/modifiercompiler.from_charset.php | 34 + .../plugins/modifiercompiler.indent.php | 32 + .../Smarty/plugins/modifiercompiler.lower.php | 31 + .../plugins/modifiercompiler.noprint.php | 25 + .../modifiercompiler.string_format.php | 26 + .../Smarty/plugins/modifiercompiler.strip.php | 33 + .../plugins/modifiercompiler.strip_tags.php | 33 + .../plugins/modifiercompiler.to_charset.php | 34 + .../plugins/modifiercompiler.unescape.php | 48 + .../Smarty/plugins/modifiercompiler.upper.php | 30 + .../plugins/modifiercompiler.wordwrap.php | 46 + .../plugins/outputfilter.trimwhitespace.php | 92 + .../plugins/shared.escape_special_chars.php | 51 + .../plugins/shared.literal_compiler_param.php | 33 + .../Smarty/plugins/shared.make_timestamp.php | 42 + .../Smarty/plugins/shared.mb_str_replace.php | 55 + .../Smarty/plugins/shared.mb_unicode.php | 48 + .../Smarty/plugins/shared.mb_wordwrap.php | 83 + .../variablefilter.htmlspecialchars.php | 21 + .../sysplugins/smarty_cacheresource.php | 381 ++ .../smarty_cacheresource_custom.php | 238 ++ .../smarty_cacheresource_keyvaluestore.php | 463 +++ .../sysplugins/smarty_config_source.php | 95 + .../smarty_internal_cacheresource_file.php | 264 ++ .../smarty_internal_compile_append.php | 53 + .../smarty_internal_compile_assign.php | 77 + .../smarty_internal_compile_block.php | 238 ++ .../smarty_internal_compile_break.php | 77 + .../smarty_internal_compile_call.php | 130 + .../smarty_internal_compile_capture.php | 98 + .../smarty_internal_compile_config_load.php | 85 + .../smarty_internal_compile_continue.php | 78 + .../smarty_internal_compile_debug.php | 43 + .../smarty_internal_compile_eval.php | 73 + .../smarty_internal_compile_extends.php | 121 + .../smarty_internal_compile_for.php | 151 + .../smarty_internal_compile_foreach.php | 231 ++ .../smarty_internal_compile_function.php | 165 + .../sysplugins/smarty_internal_compile_if.php | 207 ++ .../smarty_internal_compile_include.php | 215 ++ .../smarty_internal_compile_include_php.php | 108 + .../smarty_internal_compile_insert.php | 142 + .../smarty_internal_compile_ldelim.php | 41 + .../smarty_internal_compile_nocache.php | 73 + ..._internal_compile_private_block_plugin.php | 87 + ...ternal_compile_private_function_plugin.php | 73 + ...arty_internal_compile_private_modifier.php | 81 + ..._compile_private_object_block_function.php | 88 + ...ternal_compile_private_object_function.php | 79 + ...ernal_compile_private_print_expression.php | 156 + ...ernal_compile_private_registered_block.php | 113 + ...al_compile_private_registered_function.php | 81 + ...ernal_compile_private_special_variable.php | 104 + .../smarty_internal_compile_rdelim.php | 41 + .../smarty_internal_compile_section.php | 203 ++ .../smarty_internal_compile_setfilter.php | 72 + .../smarty_internal_compile_while.php | 94 + .../smarty_internal_compilebase.php | 176 + .../sysplugins/smarty_internal_config.php | 303 ++ .../smarty_internal_config_file_compiler.php | 144 + .../smarty_internal_configfilelexer.php | 606 ++++ .../smarty_internal_configfileparser.php | 928 +++++ .../sysplugins/smarty_internal_data.php | 551 +++ .../sysplugins/smarty_internal_debug.php | 206 ++ .../smarty_internal_filter_handler.php | 70 + .../smarty_internal_function_call_handler.php | 55 + .../smarty_internal_get_include_path.php | 43 + .../smarty_internal_nocache_insert.php | 53 + .../sysplugins/smarty_internal_parsetree.php | 395 ++ .../smarty_internal_resource_eval.php | 94 + .../smarty_internal_resource_extends.php | 148 + .../smarty_internal_resource_file.php | 90 + .../smarty_internal_resource_php.php | 114 + .../smarty_internal_resource_registered.php | 95 + .../smarty_internal_resource_stream.php | 76 + .../smarty_internal_resource_string.php | 96 + ...smarty_internal_smartytemplatecompiler.php | 127 + .../sysplugins/smarty_internal_template.php | 684 ++++ .../smarty_internal_templatebase.php | 763 ++++ .../smarty_internal_templatecompilerbase.php | 626 ++++ .../smarty_internal_templatelexer.php | 1190 ++++++ .../smarty_internal_templateparser.php | 3218 +++++++++++++++++ .../sysplugins/smarty_internal_utility.php | 810 +++++ .../sysplugins/smarty_internal_write_file.php | 70 + .../Smarty/sysplugins/smarty_resource.php | 820 +++++ .../sysplugins/smarty_resource_custom.php | 96 + .../sysplugins/smarty_resource_recompiled.php | 36 + .../sysplugins/smarty_resource_uncompiled.php | 44 + .../Smarty/sysplugins/smarty_security.php | 427 +++ .../Vendor/TemplateLite/class.compiler.php | 986 +++++ .../Vendor/TemplateLite/class.config.php | 165 + .../Vendor/TemplateLite/class.template.php | 926 +++++ .../internal/compile.compile_config.php | 74 + .../internal/compile.compile_custom_block.php | 60 + .../compile.compile_custom_function.php | 44 + .../internal/compile.compile_if.php | 154 + ...compile.generate_compiler_debug_output.php | 35 + .../TemplateLite/internal/compile.include.php | 56 + .../internal/compile.parse_is_expr.php | 77 + .../internal/compile.section_start.php | 129 + .../Vendor/TemplateLite/internal/debug.tpl | 77 + .../internal/template.build_dir.php | 28 + .../internal/template.config_loader.php | 76 + .../internal/template.destroy_dir.php | 68 + .../template.fetch_compile_include.php | 42 + .../template.generate_debug_output.php | 37 + .../Library/Vendor/jsonRPC/jsonRPCClient.php | 165 + .../Library/Vendor/jsonRPC/jsonRPCServer.php | 85 + ThinkPHP/Library/Vendor/phpRPC/bigint.php | 369 ++ ThinkPHP/Library/Vendor/phpRPC/compat.php | 242 ++ ThinkPHP/Library/Vendor/phpRPC/dhparams.php | 77 + .../Library/Vendor/phpRPC/dhparams/1024.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/128.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/1536.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/160.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/192.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/2048.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/256.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/3072.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/4096.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/512.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/768.dhp | 1 + .../Library/Vendor/phpRPC/dhparams/96.dhp | 1 + .../Library/Vendor/phpRPC/pecl/xxtea/CREDITS | 2 + .../Library/Vendor/phpRPC/pecl/xxtea/INSTALL | 66 + .../Library/Vendor/phpRPC/pecl/xxtea/LICENSE | 68 + .../Library/Vendor/phpRPC/pecl/xxtea/README | 28 + .../Vendor/phpRPC/pecl/xxtea/config.m4 | 7 + .../Vendor/phpRPC/pecl/xxtea/config.w32 | 6 + .../Vendor/phpRPC/pecl/xxtea/php_xxtea.c | 193 + .../Vendor/phpRPC/pecl/xxtea/php_xxtea.dsp | 179 + .../Vendor/phpRPC/pecl/xxtea/php_xxtea.h | 49 + .../Vendor/phpRPC/pecl/xxtea/php_xxtea.sln | 25 + .../Vendor/phpRPC/pecl/xxtea/php_xxtea.vcproj | 520 +++ .../Vendor/phpRPC/pecl/xxtea/test/test.php | 8 + .../Library/Vendor/phpRPC/pecl/xxtea/xxtea.c | 54 + .../Library/Vendor/phpRPC/pecl/xxtea/xxtea.h | 47 + .../Library/Vendor/phpRPC/phprpc_client.php | 583 +++ .../Library/Vendor/phpRPC/phprpc_date.php | 522 +++ .../Library/Vendor/phpRPC/phprpc_server.php | 496 +++ ThinkPHP/Library/Vendor/phpRPC/xxtea.php | 134 + ThinkPHP/Library/Vendor/spyc/COPYING | 21 + ThinkPHP/Library/Vendor/spyc/README.md | 30 + ThinkPHP/Library/Vendor/spyc/Spyc.php | 1147 ++++++ ThinkPHP/Library/Vendor/spyc/composer.json | 27 + .../Vendor/spyc/examples/yaml-dump.php | 25 + .../Vendor/spyc/examples/yaml-load.php | 21 + ThinkPHP/Library/Vendor/spyc/php4/5to4.php | 17 + ThinkPHP/Library/Vendor/spyc/php4/spyc.php4 | 1023 ++++++ ThinkPHP/Library/Vendor/spyc/php4/test.php4 | 162 + ThinkPHP/Library/Vendor/spyc/spyc.yaml | 219 ++ .../Library/Vendor/spyc/tests/DumpTest.php | 136 + .../Library/Vendor/spyc/tests/IndentTest.php | 65 + .../Library/Vendor/spyc/tests/ParseTest.php | 401 ++ .../Vendor/spyc/tests/RoundTripTest.php | 78 + .../Library/Vendor/spyc/tests/comments.yaml | 3 + .../Library/Vendor/spyc/tests/failing1.yaml | 2 + .../Library/Vendor/spyc/tests/indent_1.yaml | 65 + .../Library/Vendor/spyc/tests/quotes.yaml | 8 + ThinkPHP/Mode/Api/App.class.php | 143 + ThinkPHP/Mode/Api/Controller.class.php | 92 + ThinkPHP/Mode/Api/Dispatcher.class.php | 232 ++ ThinkPHP/Mode/Api/functions.php | 1109 ++++++ ThinkPHP/Mode/Lite/App.class.php | 156 + ThinkPHP/Mode/Lite/Controller.class.php | 275 ++ ThinkPHP/Mode/Lite/Dispatcher.class.php | 264 ++ ThinkPHP/Mode/Lite/Model.class.php | 1485 ++++++++ ThinkPHP/Mode/Lite/View.class.php | 293 ++ ThinkPHP/Mode/Lite/convention.php | 163 + ThinkPHP/Mode/Lite/functions.php | 1378 +++++++ ThinkPHP/Mode/Sae/convention.php | 39 + ThinkPHP/Mode/api.php | 44 + ThinkPHP/Mode/common.php | 71 + ThinkPHP/Mode/lite.php | 47 + ThinkPHP/Mode/sae.php | 68 + ThinkPHP/ThinkPHP.php | 97 + ThinkPHP/Tpl/dispatch_jump.tpl | 49 + ThinkPHP/Tpl/page_trace.tpl | 67 + ThinkPHP/Tpl/think_exception.tpl | 58 + ThinkPHP/logo.png | Bin 0 -> 7396 bytes admin.php | 26 + composer.json | 18 + index.php | 26 + 428 files changed, 78040 insertions(+) create mode 100644 .htaccess create mode 100644 .idea/.name create mode 100644 .idea/ThinkPhpStudy.iml create mode 100644 .idea/copyright/profiles_settings.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Backend/Common/Common/index.html create mode 100644 Backend/Common/Conf/config.php create mode 100644 Backend/Common/Conf/index.html create mode 100644 Backend/Common/index.html create mode 100644 Backend/Home/Common/index.html create mode 100644 Backend/Home/Conf/config.php create mode 100644 Backend/Home/Conf/index.html create mode 100644 Backend/Home/Controller/IndexController.class.php create mode 100644 Backend/Home/Controller/index.html create mode 100644 Backend/Home/Model/index.html create mode 100644 Backend/Home/View/index.html create mode 100644 Backend/Home/index.html create mode 100644 Backend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php create mode 100644 Backend/Runtime/Cache/Home/index.html create mode 100644 Backend/Runtime/Cache/index.html create mode 100644 Backend/Runtime/Data/index.html create mode 100644 Backend/Runtime/Logs/Home/16_07_03.log create mode 100644 Backend/Runtime/Logs/Home/index.html create mode 100644 Backend/Runtime/Logs/index.html create mode 100644 Backend/Runtime/Temp/index.html create mode 100644 Backend/Runtime/index.html create mode 100644 Frontend/Common/Common/index.html create mode 100644 Frontend/Common/Conf/config.php create mode 100644 Frontend/Common/Conf/index.html create mode 100644 Frontend/Common/index.html create mode 100644 Frontend/Home/Common/index.html create mode 100644 Frontend/Home/Conf/config.php create mode 100644 Frontend/Home/Conf/index.html create mode 100644 Frontend/Home/Controller/IndexController.class.php create mode 100644 Frontend/Home/Controller/index.html create mode 100644 Frontend/Home/Model/index.html create mode 100644 Frontend/Home/View/index.html create mode 100644 Frontend/Home/index.html create mode 100644 Frontend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php create mode 100644 Frontend/Runtime/Cache/Home/index.html create mode 100644 Frontend/Runtime/Cache/index.html create mode 100644 Frontend/Runtime/Data/index.html create mode 100644 Frontend/Runtime/Logs/Home/16_07_03.log create mode 100644 Frontend/Runtime/Logs/Home/index.html create mode 100644 Frontend/Runtime/Logs/index.html create mode 100644 Frontend/Runtime/Temp/index.html create mode 100644 Frontend/Runtime/index.html create mode 100644 Public/README.md create mode 100644 README.md create mode 100644 ThinkPHP/Common/functions.php create mode 100644 ThinkPHP/Conf/convention.php create mode 100644 ThinkPHP/Conf/debug.php create mode 100644 ThinkPHP/LICENSE.txt create mode 100644 ThinkPHP/Lang/en-us.php create mode 100644 ThinkPHP/Lang/pt-br.php create mode 100644 ThinkPHP/Lang/zh-cn.php create mode 100644 ThinkPHP/Lang/zh-tw.php create mode 100644 ThinkPHP/Library/Behavior/AgentCheckBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/BorisBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/BrowserCheckBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/CheckActionRouteBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/CheckLangBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ChromeShowPageTraceBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/CronRunBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/RobotCheckBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/ShowRuntimeBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/TokenBuildBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/UpgradeNoticeBehavior.class.php create mode 100644 ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php create mode 100644 ThinkPHP/Library/Org/Net/Http.class.php create mode 100644 ThinkPHP/Library/Org/Net/IpLocation.class.php create mode 100644 ThinkPHP/Library/Org/Util/ArrayList.class.php create mode 100644 ThinkPHP/Library/Org/Util/CodeSwitch.class.php create mode 100644 ThinkPHP/Library/Org/Util/Date.class.php create mode 100644 ThinkPHP/Library/Org/Util/Rbac.class.php create mode 100644 ThinkPHP/Library/Org/Util/Stack.class.php create mode 100644 ThinkPHP/Library/Org/Util/String.class.php create mode 100644 ThinkPHP/Library/Think/App.class.php create mode 100644 ThinkPHP/Library/Think/Auth.class.php create mode 100644 ThinkPHP/Library/Think/Behavior.class.php create mode 100644 ThinkPHP/Library/Think/Build.class.php create mode 100644 ThinkPHP/Library/Think/Cache.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Apachenote.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Apc.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Db.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Eaccelerator.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/File.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Memcache.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Memcached.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Memcachesae.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Redis.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Shmop.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Sqlite.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Wincache.class.php create mode 100644 ThinkPHP/Library/Think/Cache/Driver/Xcache.class.php create mode 100644 ThinkPHP/Library/Think/Controller.class.php create mode 100644 ThinkPHP/Library/Think/Controller/HproseController.class.php create mode 100644 ThinkPHP/Library/Think/Controller/JsonRpcController.class.php create mode 100644 ThinkPHP/Library/Think/Controller/RestController.class.php create mode 100644 ThinkPHP/Library/Think/Controller/RpcController.class.php create mode 100644 ThinkPHP/Library/Think/Controller/YarController.class.php create mode 100644 ThinkPHP/Library/Think/Crypt.class.php create mode 100644 ThinkPHP/Library/Think/Crypt/Driver/Base64.class.php create mode 100644 ThinkPHP/Library/Think/Crypt/Driver/Crypt.class.php create mode 100644 ThinkPHP/Library/Think/Crypt/Driver/Des.class.php create mode 100644 ThinkPHP/Library/Think/Crypt/Driver/Think.class.php create mode 100644 ThinkPHP/Library/Think/Crypt/Driver/Xxtea.class.php create mode 100644 ThinkPHP/Library/Think/Db.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Firebird.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Mongo.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Mysql.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Oracle.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Pgsql.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Sqlite.class.php create mode 100644 ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php create mode 100644 ThinkPHP/Library/Think/Db/Lite.class.php create mode 100644 ThinkPHP/Library/Think/Dispatcher.class.php create mode 100644 ThinkPHP/Library/Think/Exception.class.php create mode 100644 ThinkPHP/Library/Think/Hook.class.php create mode 100644 ThinkPHP/Library/Think/Image.class.php create mode 100644 ThinkPHP/Library/Think/Image/Driver/GIF.class.php create mode 100644 ThinkPHP/Library/Think/Image/Driver/Gd.class.php create mode 100644 ThinkPHP/Library/Think/Image/Driver/Imagick.class.php create mode 100644 ThinkPHP/Library/Think/Log.class.php create mode 100644 ThinkPHP/Library/Think/Log/Driver/File.class.php create mode 100644 ThinkPHP/Library/Think/Log/Driver/Sae.class.php create mode 100644 ThinkPHP/Library/Think/Model.class.php create mode 100644 ThinkPHP/Library/Think/Model/AdvModel.class.php create mode 100644 ThinkPHP/Library/Think/Model/MergeModel.class.php create mode 100644 ThinkPHP/Library/Think/Model/MongoModel.class.php create mode 100644 ThinkPHP/Library/Think/Model/RelationModel.class.php create mode 100644 ThinkPHP/Library/Think/Model/ViewModel.class.php create mode 100644 ThinkPHP/Library/Think/Page.class.php create mode 100644 ThinkPHP/Library/Think/Route.class.php create mode 100644 ThinkPHP/Library/Think/Session/Driver/Db.class.php create mode 100644 ThinkPHP/Library/Think/Session/Driver/Memcache.class.php create mode 100644 ThinkPHP/Library/Think/Session/Driver/Mysqli.class.php create mode 100644 ThinkPHP/Library/Think/Storage.class.php create mode 100644 ThinkPHP/Library/Think/Storage/Driver/File.class.php create mode 100644 ThinkPHP/Library/Think/Storage/Driver/Sae.class.php create mode 100644 ThinkPHP/Library/Think/Template.class.php create mode 100644 ThinkPHP/Library/Think/Template/Driver/Ease.class.php create mode 100644 ThinkPHP/Library/Think/Template/Driver/Lite.class.php create mode 100644 ThinkPHP/Library/Think/Template/Driver/Mobile.class.php create mode 100644 ThinkPHP/Library/Think/Template/Driver/Smart.class.php create mode 100644 ThinkPHP/Library/Think/Template/Driver/Smarty.class.php create mode 100644 ThinkPHP/Library/Think/Template/TagLib.class.php create mode 100644 ThinkPHP/Library/Think/Template/TagLib/Cx.class.php create mode 100644 ThinkPHP/Library/Think/Template/TagLib/Html.class.php create mode 100644 ThinkPHP/Library/Think/Think.class.php create mode 100644 ThinkPHP/Library/Think/Upload.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Bcs.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Bcs/bcs.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Bcs/mimetypes.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Bcs/requestcore.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Ftp.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Local.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Qiniu.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Qiniu/QiniuStorage.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Sae.class.php create mode 100644 ThinkPHP/Library/Think/Upload/Driver/Upyun.class.php create mode 100644 ThinkPHP/Library/Think/Verify.class.php create mode 100644 ThinkPHP/Library/Think/Verify/bgs/1.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/2.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/3.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/4.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/5.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/6.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/7.jpg create mode 100644 ThinkPHP/Library/Think/Verify/bgs/8.jpg create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/1.ttf create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/2.ttf create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/3.ttf create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/4.ttf create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/5.ttf create mode 100644 ThinkPHP/Library/Think/Verify/ttfs/6.ttf create mode 100644 ThinkPHP/Library/Think/View.class.php create mode 100644 ThinkPHP/Library/Vendor/Boris/Boris.php create mode 100644 ThinkPHP/Library/Vendor/Boris/CLIOptionsHandler.php create mode 100644 ThinkPHP/Library/Vendor/Boris/ColoredInspector.php create mode 100644 ThinkPHP/Library/Vendor/Boris/Config.php create mode 100644 ThinkPHP/Library/Vendor/Boris/DumpInspector.php create mode 100644 ThinkPHP/Library/Vendor/Boris/EvalWorker.php create mode 100644 ThinkPHP/Library/Vendor/Boris/ExportInspector.php create mode 100644 ThinkPHP/Library/Vendor/Boris/Inspector.php create mode 100644 ThinkPHP/Library/Vendor/Boris/ReadlineClient.php create mode 100644 ThinkPHP/Library/Vendor/Boris/ShallowParser.php create mode 100644 ThinkPHP/Library/Vendor/EaseTemplate/template.core.php create mode 100644 ThinkPHP/Library/Vendor/EaseTemplate/template.ease.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseClient.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseCommon.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseIO.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseReader.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseTags.php create mode 100644 ThinkPHP/Library/Vendor/Hprose/HproseWriter.php create mode 100644 ThinkPHP/Library/Vendor/README.txt create mode 100644 ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplate.php create mode 100644 ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php create mode 100644 ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplateparser.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/Smarty.class.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/SmartyBC.class.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/debug.tpl create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/block.textformat.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.counter.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.cycle.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.fetch.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_checkboxes.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_image.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_options.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_radios.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_select_date.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_select_time.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.html_table.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.mailto.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/function.math.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.capitalize.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.date_format.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.debug_print_var.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.escape.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.regex_replace.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.replace.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.spacify.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifier.truncate.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.cat.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.count_characters.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.count_paragraphs.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.count_sentences.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.count_words.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.default.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.escape.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.from_charset.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.indent.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.lower.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.noprint.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.string_format.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.strip.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.strip_tags.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.to_charset.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.unescape.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.upper.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/modifiercompiler.wordwrap.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/outputfilter.trimwhitespace.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.escape_special_chars.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.literal_compiler_param.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.make_timestamp.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.mb_str_replace.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.mb_unicode.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/shared.mb_wordwrap.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/plugins/variablefilter.htmlspecialchars.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_cacheresource.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_cacheresource_custom.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_cacheresource_keyvaluestore.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_config_source.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_cacheresource_file.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_append.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_assign.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_block.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_break.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_call.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_capture.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_config_load.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_continue.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_debug.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_eval.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_extends.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_for.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_foreach.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_function.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_if.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_include.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_include_php.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_insert.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_ldelim.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_nocache.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_block_plugin.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_function_plugin.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_modifier.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_object_block_function.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_object_function.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_print_expression.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_registered_block.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_registered_function.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_private_special_variable.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_rdelim.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_section.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_setfilter.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compile_while.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_compilebase.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_config.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_config_file_compiler.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_configfilelexer.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_configfileparser.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_data.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_debug.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_filter_handler.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_function_call_handler.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_get_include_path.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_nocache_insert.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_parsetree.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_eval.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_extends.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_file.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_php.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_registered.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_stream.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_resource_string.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_smartytemplatecompiler.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_template.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatebase.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatecompilerbase.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templatelexer.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_templateparser.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_utility.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_internal_write_file.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_resource.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_resource_custom.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_resource_recompiled.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_resource_uncompiled.php create mode 100644 ThinkPHP/Library/Vendor/Smarty/sysplugins/smarty_security.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/class.compiler.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/class.config.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/class.template.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.compile_config.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.compile_custom_block.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.compile_custom_function.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.compile_if.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.generate_compiler_debug_output.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.include.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.parse_is_expr.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/compile.section_start.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/debug.tpl create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/template.build_dir.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/template.config_loader.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/template.destroy_dir.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/template.fetch_compile_include.php create mode 100644 ThinkPHP/Library/Vendor/TemplateLite/internal/template.generate_debug_output.php create mode 100644 ThinkPHP/Library/Vendor/jsonRPC/jsonRPCClient.php create mode 100644 ThinkPHP/Library/Vendor/jsonRPC/jsonRPCServer.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/bigint.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/compat.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/1024.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/128.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/1536.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/160.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/192.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/2048.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/256.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/3072.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/4096.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/512.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/768.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/dhparams/96.dhp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/CREDITS create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/INSTALL create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/LICENSE create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/README create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/config.m4 create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/config.w32 create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/php_xxtea.c create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/php_xxtea.dsp create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/php_xxtea.h create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/php_xxtea.sln create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/php_xxtea.vcproj create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/test/test.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/xxtea.c create mode 100644 ThinkPHP/Library/Vendor/phpRPC/pecl/xxtea/xxtea.h create mode 100644 ThinkPHP/Library/Vendor/phpRPC/phprpc_client.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/phprpc_date.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/phprpc_server.php create mode 100644 ThinkPHP/Library/Vendor/phpRPC/xxtea.php create mode 100644 ThinkPHP/Library/Vendor/spyc/COPYING create mode 100644 ThinkPHP/Library/Vendor/spyc/README.md create mode 100644 ThinkPHP/Library/Vendor/spyc/Spyc.php create mode 100644 ThinkPHP/Library/Vendor/spyc/composer.json create mode 100644 ThinkPHP/Library/Vendor/spyc/examples/yaml-dump.php create mode 100644 ThinkPHP/Library/Vendor/spyc/examples/yaml-load.php create mode 100644 ThinkPHP/Library/Vendor/spyc/php4/5to4.php create mode 100644 ThinkPHP/Library/Vendor/spyc/php4/spyc.php4 create mode 100644 ThinkPHP/Library/Vendor/spyc/php4/test.php4 create mode 100644 ThinkPHP/Library/Vendor/spyc/spyc.yaml create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/DumpTest.php create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/IndentTest.php create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/ParseTest.php create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/RoundTripTest.php create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/comments.yaml create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/failing1.yaml create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/indent_1.yaml create mode 100644 ThinkPHP/Library/Vendor/spyc/tests/quotes.yaml create mode 100644 ThinkPHP/Mode/Api/App.class.php create mode 100644 ThinkPHP/Mode/Api/Controller.class.php create mode 100644 ThinkPHP/Mode/Api/Dispatcher.class.php create mode 100644 ThinkPHP/Mode/Api/functions.php create mode 100644 ThinkPHP/Mode/Lite/App.class.php create mode 100644 ThinkPHP/Mode/Lite/Controller.class.php create mode 100644 ThinkPHP/Mode/Lite/Dispatcher.class.php create mode 100644 ThinkPHP/Mode/Lite/Model.class.php create mode 100644 ThinkPHP/Mode/Lite/View.class.php create mode 100644 ThinkPHP/Mode/Lite/convention.php create mode 100644 ThinkPHP/Mode/Lite/functions.php create mode 100644 ThinkPHP/Mode/Sae/convention.php create mode 100644 ThinkPHP/Mode/api.php create mode 100644 ThinkPHP/Mode/common.php create mode 100644 ThinkPHP/Mode/lite.php create mode 100644 ThinkPHP/Mode/sae.php create mode 100644 ThinkPHP/ThinkPHP.php create mode 100644 ThinkPHP/Tpl/dispatch_jump.tpl create mode 100644 ThinkPHP/Tpl/page_trace.tpl create mode 100644 ThinkPHP/Tpl/think_exception.tpl create mode 100644 ThinkPHP/logo.png create mode 100644 admin.php create mode 100644 composer.json create mode 100644 index.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..929995c --- /dev/null +++ b/.htaccess @@ -0,0 +1,8 @@ + + Options +FollowSymlinks + RewriteEngine On + + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] + \ No newline at end of file diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..ac5ea50 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +ThinkPhpStudy \ No newline at end of file diff --git a/.idea/ThinkPhpStudy.iml b/.idea/ThinkPhpStudy.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/ThinkPhpStudy.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..97626ba --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c9a8380 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b2a07c7 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Backend/Common/Common/index.html b/Backend/Common/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Common/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Common/Conf/config.php b/Backend/Common/Conf/config.php new file mode 100644 index 0000000..cc42ec6 --- /dev/null +++ b/Backend/Common/Conf/config.php @@ -0,0 +1,4 @@ +'配置值' +); \ No newline at end of file diff --git a/Backend/Common/Conf/index.html b/Backend/Common/Conf/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Common/Conf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Common/index.html b/Backend/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/Common/index.html b/Backend/Home/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/Conf/config.php b/Backend/Home/Conf/config.php new file mode 100644 index 0000000..cc42ec6 --- /dev/null +++ b/Backend/Home/Conf/config.php @@ -0,0 +1,4 @@ +'配置值' +); \ No newline at end of file diff --git a/Backend/Home/Conf/index.html b/Backend/Home/Conf/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/Conf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/Controller/IndexController.class.php b/Backend/Home/Controller/IndexController.class.php new file mode 100644 index 0000000..32e52da --- /dev/null +++ b/Backend/Home/Controller/IndexController.class.php @@ -0,0 +1,8 @@ +show('

:)

欢迎使用 ThinkPHP


版本 V{$Think.version}
','utf-8'); + } +} \ No newline at end of file diff --git a/Backend/Home/Controller/index.html b/Backend/Home/Controller/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/Controller/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/Model/index.html b/Backend/Home/Model/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/Model/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/View/index.html b/Backend/Home/View/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/View/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Home/index.html b/Backend/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php b/Backend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php new file mode 100644 index 0000000..1e6326c --- /dev/null +++ b/Backend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php @@ -0,0 +1 @@ +

:)

欢迎使用 ThinkPHP


版本 V
\ No newline at end of file diff --git a/Backend/Runtime/Cache/Home/index.html b/Backend/Runtime/Cache/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Cache/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Cache/index.html b/Backend/Runtime/Cache/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Cache/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Data/index.html b/Backend/Runtime/Data/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Data/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Logs/Home/16_07_03.log b/Backend/Runtime/Logs/Home/16_07_03.log new file mode 100644 index 0000000..79f0ccd --- /dev/null +++ b/Backend/Runtime/Logs/Home/16_07_03.log @@ -0,0 +1,20 @@ +[ 2016-07-03T09:20:49+08:00 ] 127.0.0.1 /ThinkPhpStudy/admin.php +INFO: [ app_init ] --START-- +INFO: Run Behavior\BuildLiteBehavior [ RunTime:0.000000s ] +INFO: [ app_init ] --END-- [ RunTime:0.000000s ] +INFO: [ app_begin ] --START-- +INFO: Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000000s ] +INFO: [ app_begin ] --END-- [ RunTime:0.000000s ] +INFO: [ view_parse ] --START-- +INFO: [ template_filter ] --START-- +INFO: Run Behavior\ContentReplaceBehavior [ RunTime:0.000000s ] +INFO: [ template_filter ] --END-- [ RunTime:0.000000s ] +INFO: Run Behavior\ParseTemplateBehavior [ RunTime:0.000000s ] +INFO: [ view_parse ] --END-- [ RunTime:0.000000s ] +INFO: [ view_filter ] --START-- +INFO: Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000000s ] +INFO: [ view_filter ] --END-- [ RunTime:0.000000s ] +INFO: [ app_end ] --START-- +INFO: Run Behavior\ShowPageTraceBehavior [ RunTime:0.000000s ] +INFO: [ app_end ] --END-- [ RunTime:0.000000s ] + diff --git a/Backend/Runtime/Logs/Home/index.html b/Backend/Runtime/Logs/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Logs/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Logs/index.html b/Backend/Runtime/Logs/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Logs/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/Temp/index.html b/Backend/Runtime/Temp/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/Temp/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Backend/Runtime/index.html b/Backend/Runtime/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Backend/Runtime/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Common/Common/index.html b/Frontend/Common/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Common/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Common/Conf/config.php b/Frontend/Common/Conf/config.php new file mode 100644 index 0000000..cc42ec6 --- /dev/null +++ b/Frontend/Common/Conf/config.php @@ -0,0 +1,4 @@ +'配置值' +); \ No newline at end of file diff --git a/Frontend/Common/Conf/index.html b/Frontend/Common/Conf/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Common/Conf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Common/index.html b/Frontend/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/Common/index.html b/Frontend/Home/Common/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/Common/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/Conf/config.php b/Frontend/Home/Conf/config.php new file mode 100644 index 0000000..cc42ec6 --- /dev/null +++ b/Frontend/Home/Conf/config.php @@ -0,0 +1,4 @@ +'配置值' +); \ No newline at end of file diff --git a/Frontend/Home/Conf/index.html b/Frontend/Home/Conf/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/Conf/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/Controller/IndexController.class.php b/Frontend/Home/Controller/IndexController.class.php new file mode 100644 index 0000000..32e52da --- /dev/null +++ b/Frontend/Home/Controller/IndexController.class.php @@ -0,0 +1,8 @@ +show('

:)

欢迎使用 ThinkPHP


版本 V{$Think.version}
','utf-8'); + } +} \ No newline at end of file diff --git a/Frontend/Home/Controller/index.html b/Frontend/Home/Controller/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/Controller/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/Model/index.html b/Frontend/Home/Model/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/Model/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/View/index.html b/Frontend/Home/View/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/View/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Home/index.html b/Frontend/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php b/Frontend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php new file mode 100644 index 0000000..1e6326c --- /dev/null +++ b/Frontend/Runtime/Cache/Home/20914c0f075f91df3579ffbdf5180b02.php @@ -0,0 +1 @@ +

:)

欢迎使用 ThinkPHP


版本 V
\ No newline at end of file diff --git a/Frontend/Runtime/Cache/Home/index.html b/Frontend/Runtime/Cache/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Cache/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Cache/index.html b/Frontend/Runtime/Cache/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Cache/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Data/index.html b/Frontend/Runtime/Data/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Data/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Logs/Home/16_07_03.log b/Frontend/Runtime/Logs/Home/16_07_03.log new file mode 100644 index 0000000..c2a07b9 --- /dev/null +++ b/Frontend/Runtime/Logs/Home/16_07_03.log @@ -0,0 +1,20 @@ +[ 2016-07-03T09:20:18+08:00 ] 127.0.0.1 /ThinkPhpStudy/ +INFO: [ app_init ] --START-- +INFO: Run Behavior\BuildLiteBehavior [ RunTime:0.000000s ] +INFO: [ app_init ] --END-- [ RunTime:0.001000s ] +INFO: [ app_begin ] --START-- +INFO: Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.001000s ] +INFO: [ app_begin ] --END-- [ RunTime:0.001000s ] +INFO: [ view_parse ] --START-- +INFO: [ template_filter ] --START-- +INFO: Run Behavior\ContentReplaceBehavior [ RunTime:0.008001s ] +INFO: [ template_filter ] --END-- [ RunTime:0.008001s ] +INFO: Run Behavior\ParseTemplateBehavior [ RunTime:0.015001s ] +INFO: [ view_parse ] --END-- [ RunTime:0.015001s ] +INFO: [ view_filter ] --START-- +INFO: Run Behavior\WriteHtmlCacheBehavior [ RunTime:0.000000s ] +INFO: [ view_filter ] --END-- [ RunTime:0.001000s ] +INFO: [ app_end ] --START-- +INFO: Run Behavior\ShowPageTraceBehavior [ RunTime:0.000000s ] +INFO: [ app_end ] --END-- [ RunTime:0.001000s ] + diff --git a/Frontend/Runtime/Logs/Home/index.html b/Frontend/Runtime/Logs/Home/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Logs/Home/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Logs/index.html b/Frontend/Runtime/Logs/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Logs/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/Temp/index.html b/Frontend/Runtime/Temp/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/Temp/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Frontend/Runtime/index.html b/Frontend/Runtime/index.html new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/Frontend/Runtime/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/Public/README.md b/Public/README.md new file mode 100644 index 0000000..40f011a --- /dev/null +++ b/Public/README.md @@ -0,0 +1 @@ +资源文件目录 \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ad85157 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +## 简介 + +ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。 + +## 全面的WEB开发特性支持 + +最新的ThinkPHP为WEB应用开发提供了强有力的支持,这些支持包括: + +* MVC支持-基于多层模型(M)、视图(V)、控制器(C)的设计模式 +* ORM支持-提供了全功能和高性能的ORM支持,支持大部分数据库 +* 模板引擎支持-内置了高性能的基于标签库和XML标签的编译型模板引擎 +* RESTFul支持-通过REST控制器扩展提供了RESTFul支持,为你打造全新的URL设计和访问体验 +* 云平台支持-提供了对新浪SAE平台和百度BAE平台的强力支持,具备“横跨性”和“平滑性”,支持本地化开发和调试以及部署切换,让你轻松过渡,打造全新的开发体验。 +* CLI支持-支持基于命令行的应用开发 +* RPC支持-提供包括PHPRpc、HProse、jsonRPC和Yar在内远程调用解决方案 +* MongoDb支持-提供NoSQL的支持 +* 缓存支持-提供了包括文件、数据库、Memcache、Xcache、Redis等多种类型的缓存支持 + +## 大道至简的开发理念 + +ThinkPHP从诞生以来一直秉承大道至简的开发理念,无论从底层实现还是应用开发,我们都倡导用最少的代码完成相同的功能,正是由于对简单的执着和代码的修炼,让我们长期保持出色的性能和极速的开发体验。在主流PHP开发框架的评测数据中表现卓越,简单和快速开发是我们不变的宗旨。 + +## 安全性 + +框架在系统层面提供了众多的安全特性,确保你的网站和产品安全无忧。这些特性包括: + +* XSS安全防护 +* 表单自动验证 +* 强制数据类型转换 +* 输入数据过滤 +* 表单令牌验证 +* 防SQL注入 +* 图像上传检测 + +## 商业友好的开源协议 + +ThinkPHP遵循Apache2开源协议发布。Apache Licence是著名的非盈利开源组织Apache采用的协议。该协议和BSD类似,鼓励代码共享和尊重原作者的著作权,同样允许代码修改,再作为开源或商业软件发布。 \ No newline at end of file diff --git a/ThinkPHP/Common/functions.php b/ThinkPHP/Common/functions.php new file mode 100644 index 0000000..417f046 --- /dev/null +++ b/ThinkPHP/Common/functions.php @@ -0,0 +1,1550 @@ + +// +---------------------------------------------------------------------- + +/** + * Think 系统函数库 + */ + +/** + * 获取和设置配置参数 支持批量定义 + * @param string|array $name 配置变量 + * @param mixed $value 配置值 + * @param mixed $default 默认值 + * @return mixed + */ +function C($name=null, $value=null,$default=null) { + static $_config = array(); + // 无参数时获取所有 + if (empty($name)) { + return $_config; + } + // 优先执行设置获取或赋值 + if (is_string($name)) { + if (!strpos($name, '.')) { + $name = strtoupper($name); + if (is_null($value)) + return isset($_config[$name]) ? $_config[$name] : $default; + $_config[$name] = $value; + return null; + } + // 二维数组设置和获取支持 + $name = explode('.', $name); + $name[0] = strtoupper($name[0]); + if (is_null($value)) + return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : $default; + $_config[$name[0]][$name[1]] = $value; + return null; + } + // 批量设置 + if (is_array($name)){ + $_config = array_merge($_config, array_change_key_case($name,CASE_UPPER)); + return null; + } + return null; // 避免非法参数 +} + +/** + * 加载配置文件 支持格式转换 仅支持一级配置 + * @param string $file 配置文件名 + * @param string $parse 配置解析方法 有些格式需要用户自己解析 + * @return array + */ +function load_config($file,$parse=CONF_PARSE){ + $ext = pathinfo($file,PATHINFO_EXTENSION); + switch($ext){ + case 'php': + return include $file; + case 'ini': + return parse_ini_file($file); + case 'yaml': + return yaml_parse_file($file); + case 'xml': + return (array)simplexml_load_file($file); + case 'json': + return json_decode(file_get_contents($file), true); + default: + if(function_exists($parse)){ + return $parse($file); + }else{ + E(L('_NOT_SUPPORT_').':'.$ext); + } + } +} + +/** + * 解析yaml文件返回一个数组 + * @param string $file 配置文件名 + * @return array + */ +if (!function_exists('yaml_parse_file')) { + function yaml_parse_file($file) { + vendor('spyc.Spyc'); + return Spyc::YAMLLoad($file); + } +} + +/** + * 抛出异常处理 + * @param string $msg 异常消息 + * @param integer $code 异常代码 默认为0 + * @throws Think\Exception + * @return void + */ +function E($msg, $code=0) { + throw new Think\Exception($msg, $code); +} + +/** + * 记录和统计时间(微秒)和内存使用情况 + * 使用方法: + * + * G('begin'); // 记录开始标记位 + * // ... 区间运行代码 + * G('end'); // 记录结束标签位 + * echo G('begin','end',6); // 统计区间运行时间 精确到小数后6位 + * echo G('begin','end','m'); // 统计区间内存使用情况 + * 如果end标记位没有定义,则会自动以当前作为标记位 + * 其中统计内存使用需要 MEMORY_LIMIT_ON 常量为true才有效 + * + * @param string $start 开始标签 + * @param string $end 结束标签 + * @param integer|string $dec 小数位或者m + * @return mixed + */ +function G($start,$end='',$dec=4) { + static $_info = array(); + static $_mem = array(); + if(is_float($end)) { // 记录时间 + $_info[$start] = $end; + }elseif(!empty($end)){ // 统计时间和内存使用 + if(!isset($_info[$end])) $_info[$end] = microtime(TRUE); + if(MEMORY_LIMIT_ON && $dec=='m'){ + if(!isset($_mem[$end])) $_mem[$end] = memory_get_usage(); + return number_format(($_mem[$end]-$_mem[$start])/1024); + }else{ + return number_format(($_info[$end]-$_info[$start]),$dec); + } + + }else{ // 记录时间和内存使用 + $_info[$start] = microtime(TRUE); + if(MEMORY_LIMIT_ON) $_mem[$start] = memory_get_usage(); + } + return null; +} + +/** + * 获取和设置语言定义(不区分大小写) + * @param string|array $name 语言变量 + * @param mixed $value 语言值或者变量 + * @return mixed + */ +function L($name=null, $value=null) { + static $_lang = array(); + // 空参数返回所有定义 + if (empty($name)) + return $_lang; + // 判断语言获取(或设置) + // 若不存在,直接返回全大写$name + if (is_string($name)) { + $name = strtoupper($name); + if (is_null($value)){ + return isset($_lang[$name]) ? $_lang[$name] : $name; + }elseif(is_array($value)){ + // 支持变量 + $replace = array_keys($value); + foreach($replace as &$v){ + $v = '{$'.$v.'}'; + } + return str_replace($replace,$value,isset($_lang[$name]) ? $_lang[$name] : $name); + } + $_lang[$name] = $value; // 语言定义 + return null; + } + // 批量定义 + if (is_array($name)) + $_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER)); + return null; +} + +/** + * 添加和获取页面Trace记录 + * @param string $value 变量 + * @param string $label 标签 + * @param string $level 日志级别 + * @param boolean $record 是否记录日志 + * @return void|array + */ +function trace($value='[think]',$label='',$level='DEBUG',$record=false) { + return Think\Think::trace($value,$label,$level,$record); +} + +/** + * 编译文件 + * @param string $filename 文件名 + * @return string + */ +function compile($filename) { + $content = php_strip_whitespace($filename); + $content = trim(substr($content, 5)); + // 替换预编译指令 + $content = preg_replace('/\/\/\[RUNTIME\](.*?)\/\/\[\/RUNTIME\]/s', '', $content); + if(0===strpos($content,'namespace')){ + $content = preg_replace('/namespace\s(.*?);/','namespace \\1{',$content,1); + }else{ + $content = 'namespace {'.$content; + } + if ('?>' == substr($content, -2)) + $content = substr($content, 0, -2); + return $content.'}'; +} + +/** + * 获取模版文件 格式 资源://模块@主题/控制器/操作 + * @param string $template 模版资源地址 + * @param string $layer 视图层(目录)名称 + * @return string + */ +function T($template='',$layer=''){ + + // 解析模版资源地址 + if(false === strpos($template,'://')){ + $template = 'http://'.str_replace(':', '/',$template); + } + $info = parse_url($template); + $file = $info['host'].(isset($info['path'])?$info['path']:''); + $module = isset($info['user'])?$info['user'].'/':MODULE_NAME.'/'; + $extend = $info['scheme']; + $layer = $layer?$layer:C('DEFAULT_V_LAYER'); + + // 获取当前主题的模版路径 + $auto = C('AUTOLOAD_NAMESPACE'); + if($auto && isset($auto[$extend])){ // 扩展资源 + $baseUrl = $auto[$extend].$module.$layer.'/'; + }elseif(C('VIEW_PATH')){ + // 改变模块视图目录 + $baseUrl = C('VIEW_PATH'); + }elseif(defined('TMPL_PATH')){ + // 指定全局视图目录 + $baseUrl = TMPL_PATH.$module; + }else{ + $baseUrl = APP_PATH.$module.$layer.'/'; + } + + // 获取主题 + $theme = substr_count($file,'/')<2 ? C('DEFAULT_THEME') : ''; + + // 分析模板文件规则 + $depr = C('TMPL_FILE_DEPR'); + if('' == $file) { + // 如果模板文件名为空 按照默认规则定位 + $file = CONTROLLER_NAME . $depr . ACTION_NAME; + }elseif(false === strpos($file, '/')){ + $file = CONTROLLER_NAME . $depr . $file; + }elseif('/' != $depr){ + $file = substr_count($file,'/')>1 ? substr_replace($file,$depr,strrpos($file,'/'),1) : str_replace('/', $depr, $file); + } + return $baseUrl.($theme?$theme.'/':'').$file.C('TMPL_TEMPLATE_SUFFIX'); +} + +/** + * 获取输入参数 支持过滤和默认值 + * 使用方法: + * + * I('id',0); 获取id参数 自动判断get或者post + * I('post.name','','htmlspecialchars'); 获取$_POST['name'] + * I('get.'); 获取$_GET + * + * @param string $name 变量的名称 支持指定类型 + * @param mixed $default 不存在的时候默认值 + * @param mixed $filter 参数过滤方法 + * @param mixed $datas 要获取的额外数据源 + * @return mixed + */ +function I($name,$default='',$filter=null,$datas=null) { + static $_PUT = null; + if(strpos($name,'/')){ // 指定修饰符 + list($name,$type) = explode('/',$name,2); + }elseif(C('VAR_AUTO_STRING')){ // 默认强制转换为字符串 + $type = 's'; + } + if(strpos($name,'.')) { // 指定参数来源 + list($method,$name) = explode('.',$name,2); + }else{ // 默认为自动判断 + $method = 'param'; + } + switch(strtolower($method)) { + case 'get' : + $input =& $_GET; + break; + case 'post' : + $input =& $_POST; + break; + case 'put' : + if(is_null($_PUT)){ + parse_str(file_get_contents('php://input'), $_PUT); + } + $input = $_PUT; + break; + case 'param' : + switch($_SERVER['REQUEST_METHOD']) { + case 'POST': + $input = $_POST; + break; + case 'PUT': + if(is_null($_PUT)){ + parse_str(file_get_contents('php://input'), $_PUT); + } + $input = $_PUT; + break; + default: + $input = $_GET; + } + break; + case 'path' : + $input = array(); + if(!empty($_SERVER['PATH_INFO'])){ + $depr = C('URL_PATHINFO_DEPR'); + $input = explode($depr,trim($_SERVER['PATH_INFO'],$depr)); + } + break; + case 'request' : + $input =& $_REQUEST; + break; + case 'session' : + $input =& $_SESSION; + break; + case 'cookie' : + $input =& $_COOKIE; + break; + case 'server' : + $input =& $_SERVER; + break; + case 'globals' : + $input =& $GLOBALS; + break; + case 'data' : + $input =& $datas; + break; + default: + return null; + } + if(''==$name) { // 获取全部变量 + $data = $input; + $filters = isset($filter)?$filter:C('DEFAULT_FILTER'); + if($filters) { + if(is_string($filters)){ + $filters = explode(',',$filters); + } + foreach($filters as $filter){ + $data = array_map_recursive($filter,$data); // 参数过滤 + } + } + }elseif(isset($input[$name])) { // 取值操作 + $data = $input[$name]; + $filters = isset($filter)?$filter:C('DEFAULT_FILTER'); + if($filters) { + if(is_string($filters)){ + if(0 === strpos($filters,'/')){ + if(1 !== preg_match($filters,(string)$data)){ + // 支持正则验证 + return isset($default) ? $default : null; + } + }else{ + $filters = explode(',',$filters); + } + }elseif(is_int($filters)){ + $filters = array($filters); + } + + if(is_array($filters)){ + foreach($filters as $filter){ + if(function_exists($filter)) { + $data = is_array($data) ? array_map_recursive($filter,$data) : $filter($data); // 参数过滤 + }else{ + $data = filter_var($data,is_int($filter) ? $filter : filter_id($filter)); + if(false === $data) { + return isset($default) ? $default : null; + } + } + } + } + } + if(!empty($type)){ + switch(strtolower($type)){ + case 'a': // 数组 + $data = (array)$data; + break; + case 'd': // 数字 + $data = (int)$data; + break; + case 'f': // 浮点 + $data = (float)$data; + break; + case 'b': // 布尔 + $data = (boolean)$data; + break; + case 's': // 字符串 + default: + $data = (string)$data; + } + } + }else{ // 变量默认值 + $data = isset($default)?$default:null; + } + is_array($data) && array_walk_recursive($data,'think_filter'); + return $data; +} + +function array_map_recursive($filter, $data) { + $result = array(); + foreach ($data as $key => $val) { + $result[$key] = is_array($val) + ? array_map_recursive($filter, $val) + : call_user_func($filter, $val); + } + return $result; + } + +/** + * 设置和获取统计数据 + * 使用方法: + * + * N('db',1); // 记录数据库操作次数 + * N('read',1); // 记录读取次数 + * echo N('db'); // 获取当前页面数据库的所有操作次数 + * echo N('read'); // 获取当前页面读取次数 + * + * @param string $key 标识位置 + * @param integer $step 步进值 + * @param boolean $save 是否保存结果 + * @return mixed + */ +function N($key, $step=0,$save=false) { + static $_num = array(); + if (!isset($_num[$key])) { + $_num[$key] = (false !== $save)? S('N_'.$key) : 0; + } + if (empty($step)){ + return $_num[$key]; + }else{ + $_num[$key] = $_num[$key] + (int)$step; + } + if(false !== $save){ // 保存结果 + S('N_'.$key,$_num[$key],$save); + } + return null; +} + +/** + * 字符串命名风格转换 + * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格 + * @param string $name 字符串 + * @param integer $type 转换类型 + * @return string + */ +function parse_name($name, $type=0) { + if ($type) { + return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function($match){return strtoupper($match[1]);}, $name)); + } else { + return strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $name), "_")); + } +} + +/** + * 优化的require_once + * @param string $filename 文件地址 + * @return boolean + */ +function require_cache($filename) { + static $_importFiles = array(); + if (!isset($_importFiles[$filename])) { + if (file_exists_case($filename)) { + require $filename; + $_importFiles[$filename] = true; + } else { + $_importFiles[$filename] = false; + } + } + return $_importFiles[$filename]; +} + +/** + * 区分大小写的文件存在判断 + * @param string $filename 文件地址 + * @return boolean + */ +function file_exists_case($filename) { + if (is_file($filename)) { + if (IS_WIN && APP_DEBUG) { + if (basename(realpath($filename)) != basename($filename)) + return false; + } + return true; + } + return false; +} + +/** + * 导入所需的类库 同java的Import 本函数有缓存功能 + * @param string $class 类库命名空间字符串 + * @param string $baseUrl 起始路径 + * @param string $ext 导入的文件扩展名 + * @return boolean + */ +function import($class, $baseUrl = '', $ext=EXT) { + static $_file = array(); + $class = str_replace(array('.', '#'), array('/', '.'), $class); + if (isset($_file[$class . $baseUrl])) + return true; + else + $_file[$class . $baseUrl] = true; + $class_strut = explode('/', $class); + if (empty($baseUrl)) { + if ('@' == $class_strut[0] || MODULE_NAME == $class_strut[0]) { + //加载当前模块的类库 + $baseUrl = MODULE_PATH; + $class = substr_replace($class, '', 0, strlen($class_strut[0]) + 1); + }elseif ('Common' == $class_strut[0]) { + //加载公共模块的类库 + $baseUrl = COMMON_PATH; + $class = substr($class, 7); + }elseif (in_array($class_strut[0],array('Think','Org','Behavior','Com','Vendor')) || is_dir(LIB_PATH.$class_strut[0])) { + // 系统类库包和第三方类库包 + $baseUrl = LIB_PATH; + }else { // 加载其他模块的类库 + $baseUrl = APP_PATH; + } + } + if (substr($baseUrl, -1) != '/') + $baseUrl .= '/'; + $classfile = $baseUrl . $class . $ext; + if (!class_exists(basename($class),false)) { + // 如果类不存在 则导入类库文件 + return require_cache($classfile); + } + return null; +} + +/** + * 基于命名空间方式导入函数库 + * load('@.Util.Array') + * @param string $name 函数库命名空间字符串 + * @param string $baseUrl 起始路径 + * @param string $ext 导入的文件扩展名 + * @return void + */ +function load($name, $baseUrl='', $ext='.php') { + $name = str_replace(array('.', '#'), array('/', '.'), $name); + if (empty($baseUrl)) { + if (0 === strpos($name, '@/')) {//加载当前模块函数库 + $baseUrl = MODULE_PATH.'Common/'; + $name = substr($name, 2); + } else { //加载其他模块函数库 + $array = explode('/', $name); + $baseUrl = APP_PATH . array_shift($array).'/Common/'; + $name = implode('/',$array); + } + } + if (substr($baseUrl, -1) != '/') + $baseUrl .= '/'; + require_cache($baseUrl . $name . $ext); +} + +/** + * 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面 + * @param string $class 类库 + * @param string $baseUrl 基础目录 + * @param string $ext 类库后缀 + * @return boolean + */ +function vendor($class, $baseUrl = '', $ext='.php') { + if (empty($baseUrl)) + $baseUrl = VENDOR_PATH; + return import($class, $baseUrl, $ext); +} + +/** + * 实例化模型类 格式 [资源://][模块/]模型 + * @param string $name 资源地址 + * @param string $layer 模型层名称 + * @return Think\Model + */ +function D($name='',$layer='') { + if(empty($name)) return new Think\Model; + static $_model = array(); + $layer = $layer? : C('DEFAULT_M_LAYER'); + if(isset($_model[$name.$layer])) + return $_model[$name.$layer]; + $class = parse_res_name($name,$layer); + if(class_exists($class)) { + $model = new $class(basename($name)); + }elseif(false === strpos($name,'/')){ + // 自动加载公共模块下面的模型 + if(!C('APP_USE_NAMESPACE')){ + import('Common/'.$layer.'/'.$class); + }else{ + $class = '\\Common\\'.$layer.'\\'.$name.$layer; + } + $model = class_exists($class)? new $class($name) : new Think\Model($name); + }else { + Think\Log::record('D方法实例化没找到模型类'.$class,Think\Log::NOTICE); + $model = new Think\Model(basename($name)); + } + $_model[$name.$layer] = $model; + return $model; +} + +/** + * 实例化一个没有模型文件的Model + * @param string $name Model名称 支持指定基础模型 例如 MongoModel:User + * @param string $tablePrefix 表前缀 + * @param mixed $connection 数据库连接信息 + * @return Think\Model + */ +function M($name='', $tablePrefix='',$connection='') { + static $_model = array(); + if(strpos($name,':')) { + list($class,$name) = explode(':',$name); + }else{ + $class = 'Think\\Model'; + } + $guid = (is_array($connection)?implode('',$connection):$connection).$tablePrefix . $name . '_' . $class; + if (!isset($_model[$guid])) + $_model[$guid] = new $class($name,$tablePrefix,$connection); + return $_model[$guid]; +} + +/** + * 解析资源地址并导入类库文件 + * 例如 module/controller addon://module/behavior + * @param string $name 资源地址 格式:[扩展://][模块/]资源名 + * @param string $layer 分层名称 + * @param integer $level 控制器层次 + * @return string + */ +function parse_res_name($name,$layer,$level=1){ + if(strpos($name,'://')) {// 指定扩展资源 + list($extend,$name) = explode('://',$name); + }else{ + $extend = ''; + } + if(strpos($name,'/') && substr_count($name, '/')>=$level){ // 指定模块 + list($module,$name) = explode('/',$name,2); + }else{ + $module = defined('MODULE_NAME') ? MODULE_NAME : '' ; + } + $array = explode('/',$name); + if(!C('APP_USE_NAMESPACE')){ + $class = parse_name($name, 1); + import($module.'/'.$layer.'/'.$class.$layer); + }else{ + $class = $module.'\\'.$layer; + foreach($array as $name){ + $class .= '\\'.parse_name($name, 1); + } + // 导入资源类库 + if($extend){ // 扩展资源 + $class = $extend.'\\'.$class; + } + } + return $class.$layer; +} + +/** + * 用于实例化访问控制器 + * @param string $name 控制器名 + * @param string $path 控制器命名空间(路径) + * @return Think\Controller|false + */ +function controller($name,$path=''){ + $layer = C('DEFAULT_C_LAYER'); + if(!C('APP_USE_NAMESPACE')){ + $class = parse_name($name, 1).$layer; + import(MODULE_NAME.'/'.$layer.'/'.$class); + }else{ + $class = ( $path ? basename(ADDON_PATH).'\\'.$path : MODULE_NAME ).'\\'.$layer; + $array = explode('/',$name); + foreach($array as $name){ + $class .= '\\'.parse_name($name, 1); + } + $class .= $layer; + } + if(class_exists($class)) { + return new $class(); + }else { + return false; + } +} + +/** + * 实例化多层控制器 格式:[资源://][模块/]控制器 + * @param string $name 资源地址 + * @param string $layer 控制层名称 + * @param integer $level 控制器层次 + * @return Think\Controller|false + */ +function A($name,$layer='',$level=0) { + static $_action = array(); + $layer = $layer? : C('DEFAULT_C_LAYER'); + $level = $level? : ($layer == C('DEFAULT_C_LAYER')?C('CONTROLLER_LEVEL'):1); + if(isset($_action[$name.$layer])) + return $_action[$name.$layer]; + + $class = parse_res_name($name,$layer,$level); + if(class_exists($class)) { + $action = new $class(); + $_action[$name.$layer] = $action; + return $action; + }else { + return false; + } +} + + +/** + * 远程调用控制器的操作方法 URL 参数格式 [资源://][模块/]控制器/操作 + * @param string $url 调用地址 + * @param string|array $vars 调用参数 支持字符串和数组 + * @param string $layer 要调用的控制层名称 + * @return mixed + */ +function R($url,$vars=array(),$layer='') { + $info = pathinfo($url); + $action = $info['basename']; + $module = $info['dirname']; + $class = A($module,$layer); + if($class){ + if(is_string($vars)) { + parse_str($vars,$vars); + } + return call_user_func_array(array(&$class,$action.C('ACTION_SUFFIX')),$vars); + }else{ + return false; + } +} + +/** + * 处理标签扩展 + * @param string $tag 标签名称 + * @param mixed $params 传入参数 + * @return void + */ +function tag($tag, &$params=NULL) { + \Think\Hook::listen($tag,$params); +} + +/** + * 执行某个行为 + * @param string $name 行为名称 + * @param string $tag 标签名称(行为类无需传入) + * @param Mixed $params 传入的参数 + * @return void + */ +function B($name, $tag='',&$params=NULL) { + if(''==$tag){ + $name .= 'Behavior'; + } + return \Think\Hook::exec($name,$tag,$params); +} + +/** + * 去除代码中的空白和注释 + * @param string $content 代码内容 + * @return string + */ +function strip_whitespace($content) { + $stripStr = ''; + //分析php源码 + $tokens = token_get_all($content); + $last_space = false; + for ($i = 0, $j = count($tokens); $i < $j; $i++) { + if (is_string($tokens[$i])) { + $last_space = false; + $stripStr .= $tokens[$i]; + } else { + switch ($tokens[$i][0]) { + //过滤各种PHP注释 + case T_COMMENT: + case T_DOC_COMMENT: + break; + //过滤空格 + case T_WHITESPACE: + if (!$last_space) { + $stripStr .= ' '; + $last_space = true; + } + break; + case T_START_HEREDOC: + $stripStr .= "<<'; + } else { + $output = $label . print_r($var, true); + } + } else { + ob_start(); + var_dump($var); + $output = ob_get_clean(); + if (!extension_loaded('xdebug')) { + $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output); + $output = '
' . $label . htmlspecialchars($output, ENT_QUOTES) . '
'; + } + } + if ($echo) { + echo($output); + return null; + }else + return $output; +} + +/** + * 设置当前页面的布局 + * @param string|false $layout 布局名称 为false的时候表示关闭布局 + * @return void + */ +function layout($layout) { + if(false !== $layout) { + // 开启布局 + C('LAYOUT_ON',true); + if(is_string($layout)) { // 设置新的布局模板 + C('LAYOUT_NAME',$layout); + } + }else{// 临时关闭布局 + C('LAYOUT_ON',false); + } +} + +/** + * URL组装 支持不同URL模式 + * @param string $url URL表达式,格式:'[模块/控制器/操作#锚点@域名]?参数1=值1&参数2=值2...' + * @param string|array $vars 传入的参数,支持数组和字符串 + * @param string|boolean $suffix 伪静态后缀,默认为true表示获取配置值 + * @param boolean $domain 是否显示域名 + * @return string + */ +function U($url='',$vars='',$suffix=true,$domain=false) { + // 解析URL + $info = parse_url($url); + $url = !empty($info['path'])?$info['path']:ACTION_NAME; + if(isset($info['fragment'])) { // 解析锚点 + $anchor = $info['fragment']; + if(false !== strpos($anchor,'?')) { // 解析参数 + list($anchor,$info['query']) = explode('?',$anchor,2); + } + if(false !== strpos($anchor,'@')) { // 解析域名 + list($anchor,$host) = explode('@',$anchor, 2); + } + }elseif(false !== strpos($url,'@')) { // 解析域名 + list($url,$host) = explode('@',$info['path'], 2); + } + // 解析子域名 + if(isset($host)) { + $domain = $host.(strpos($host,'.')?'':strstr($_SERVER['HTTP_HOST'],'.')); + }elseif($domain===true){ + $domain = $_SERVER['HTTP_HOST']; + if(C('APP_SUB_DOMAIN_DEPLOY') ) { // 开启子域名部署 + $domain = $domain=='localhost'?'localhost':'www'.strstr($_SERVER['HTTP_HOST'],'.'); + // '子域名'=>array('模块[/控制器]'); + foreach (C('APP_SUB_DOMAIN_RULES') as $key => $rule) { + $rule = is_array($rule)?$rule[0]:$rule; + if(false === strpos($key,'*') && 0=== strpos($url,$rule)) { + $domain = $key.strstr($domain,'.'); // 生成对应子域名 + $url = substr_replace($url,'',0,strlen($rule)); + break; + } + } + } + } + + // 解析参数 + if(is_string($vars)) { // aaa=1&bbb=2 转换成数组 + parse_str($vars,$vars); + }elseif(!is_array($vars)){ + $vars = array(); + } + if(isset($info['query'])) { // 解析地址里面参数 合并到vars + parse_str($info['query'],$params); + $vars = array_merge($params,$vars); + } + + // URL组装 + $depr = C('URL_PATHINFO_DEPR'); + $urlCase = C('URL_CASE_INSENSITIVE'); + if($url) { + if(0=== strpos($url,'/')) {// 定义路由 + $route = true; + $url = substr($url,1); + if('/' != $depr) { + $url = str_replace('/',$depr,$url); + } + }else{ + if('/' != $depr) { // 安全替换 + $url = str_replace('/',$depr,$url); + } + // 解析模块、控制器和操作 + $url = trim($url,$depr); + $path = explode($depr,$url); + $var = array(); + $varModule = C('VAR_MODULE'); + $varController = C('VAR_CONTROLLER'); + $varAction = C('VAR_ACTION'); + $var[$varAction] = !empty($path)?array_pop($path):ACTION_NAME; + $var[$varController] = !empty($path)?array_pop($path):CONTROLLER_NAME; + if($maps = C('URL_ACTION_MAP')) { + if(isset($maps[strtolower($var[$varController])])) { + $maps = $maps[strtolower($var[$varController])]; + if($action = array_search(strtolower($var[$varAction]),$maps)){ + $var[$varAction] = $action; + } + } + } + if($maps = C('URL_CONTROLLER_MAP')) { + if($controller = array_search(strtolower($var[$varController]),$maps)){ + $var[$varController] = $controller; + } + } + if($urlCase) { + $var[$varController] = parse_name($var[$varController]); + } + $module = ''; + + if(!empty($path)) { + $var[$varModule] = implode($depr,$path); + }else{ + if(C('MULTI_MODULE')) { + if(MODULE_NAME != C('DEFAULT_MODULE') || !C('MODULE_ALLOW_LIST')){ + $var[$varModule]= MODULE_NAME; + } + } + } + if($maps = C('URL_MODULE_MAP')) { + if($_module = array_search(strtolower($var[$varModule]),$maps)){ + $var[$varModule] = $_module; + } + } + if(isset($var[$varModule])){ + $module = $var[$varModule]; + unset($var[$varModule]); + } + + } + } + + if(C('URL_MODEL') == 0) { // 普通模式URL转换 + $url = __APP__.'?'.C('VAR_MODULE')."={$module}&".http_build_query(array_reverse($var)); + if($urlCase){ + $url = strtolower($url); + } + if(!empty($vars)) { + $vars = http_build_query($vars); + $url .= '&'.$vars; + } + }else{ // PATHINFO模式或者兼容URL模式 + if(isset($route)) { + $url = __APP__.'/'.rtrim($url,$depr); + }else{ + $module = (defined('BIND_MODULE') && BIND_MODULE==$module )? '' : $module; + $url = __APP__.'/'.($module?$module.MODULE_PATHINFO_DEPR:'').implode($depr,array_reverse($var)); + } + if($urlCase){ + $url = strtolower($url); + } + if(!empty($vars)) { // 添加参数 + foreach ($vars as $var => $val){ + if('' !== trim($val)) $url .= $depr . $var . $depr . urlencode($val); + } + } + if($suffix) { + $suffix = $suffix===true?C('URL_HTML_SUFFIX'):$suffix; + if($pos = strpos($suffix, '|')){ + $suffix = substr($suffix, 0, $pos); + } + if($suffix && '/' != substr($url,-1)){ + $url .= '.'.ltrim($suffix,'.'); + } + } + } + if(isset($anchor)){ + $url .= '#'.$anchor; + } + if($domain) { + $url = (is_ssl()?'https://':'http://').$domain.$url; + } + return $url; +} + +/** + * 渲染输出Widget + * @param string $name Widget名称 + * @param array $data 传入的参数 + * @return void + */ +function W($name, $data=array()) { + return R($name,$data,'Widget'); +} + +/** + * 判断是否SSL协议 + * @return boolean + */ +function is_ssl() { + if(isset($_SERVER['HTTPS']) && ('1' == $_SERVER['HTTPS'] || 'on' == strtolower($_SERVER['HTTPS']))){ + return true; + }elseif(isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'] )) { + return true; + } + return false; +} + +/** + * URL重定向 + * @param string $url 重定向的URL地址 + * @param integer $time 重定向的等待时间(秒) + * @param string $msg 重定向前的提示信息 + * @return void + */ +function redirect($url, $time=0, $msg='') { + //多行URL地址支持 + $url = str_replace(array("\n", "\r"), '', $url); + if (empty($msg)) + $msg = "系统将在{$time}秒之后自动跳转到{$url}!"; + if (!headers_sent()) { + // redirect + if (0 === $time) { + header('Location: ' . $url); + } else { + header("refresh:{$time};url={$url}"); + echo($msg); + } + exit(); + } else { + $str = ""; + if ($time != 0) + $str .= $msg; + exit($str); + } +} + +/** + * 缓存管理 + * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 + * @param mixed $value 缓存值 + * @param mixed $options 缓存参数 + * @return mixed + */ +function S($name,$value='',$options=null) { + static $cache = ''; + if(is_array($options)){ + // 缓存操作的同时初始化 + $type = isset($options['type'])?$options['type']:''; + $cache = Think\Cache::getInstance($type,$options); + }elseif(is_array($name)) { // 缓存初始化 + $type = isset($name['type'])?$name['type']:''; + $cache = Think\Cache::getInstance($type,$name); + return $cache; + }elseif(empty($cache)) { // 自动初始化 + $cache = Think\Cache::getInstance(); + } + if(''=== $value){ // 获取缓存 + return $cache->get($name); + }elseif(is_null($value)) { // 删除缓存 + return $cache->rm($name); + }else { // 缓存数据 + if(is_array($options)) { + $expire = isset($options['expire'])?$options['expire']:NULL; + }else{ + $expire = is_numeric($options)?$options:NULL; + } + return $cache->set($name, $value, $expire); + } +} + +/** + * 快速文件数据读取和保存 针对简单类型数据 字符串、数组 + * @param string $name 缓存名称 + * @param mixed $value 缓存值 + * @param string $path 缓存路径 + * @return mixed + */ +function F($name, $value='', $path=DATA_PATH) { + static $_cache = array(); + $filename = $path . $name . '.php'; + if ('' !== $value) { + if (is_null($value)) { + // 删除缓存 + if(false !== strpos($name,'*')){ + return false; // TODO + }else{ + unset($_cache[$name]); + return Think\Storage::unlink($filename,'F'); + } + } else { + Think\Storage::put($filename,serialize($value),'F'); + // 缓存数据 + $_cache[$name] = $value; + return null; + } + } + // 获取缓存数据 + if (isset($_cache[$name])) + return $_cache[$name]; + if (Think\Storage::has($filename,'F')){ + $value = unserialize(Think\Storage::read($filename,'F')); + $_cache[$name] = $value; + } else { + $value = false; + } + return $value; +} + +/** + * 根据PHP各种类型变量生成唯一标识号 + * @param mixed $mix 变量 + * @return string + */ +function to_guid_string($mix) { + if (is_object($mix)) { + return spl_object_hash($mix); + } elseif (is_resource($mix)) { + $mix = get_resource_type($mix) . strval($mix); + } else { + $mix = serialize($mix); + } + return md5($mix); +} + +/** + * XML编码 + * @param mixed $data 数据 + * @param string $root 根节点名 + * @param string $item 数字索引的子节点名 + * @param string $attr 根节点属性 + * @param string $id 数字索引子节点key转换的属性名 + * @param string $encoding 数据编码 + * @return string + */ +function xml_encode($data, $root='think', $item='item', $attr='', $id='id', $encoding='utf-8') { + if(is_array($attr)){ + $_attr = array(); + foreach ($attr as $key => $value) { + $_attr[] = "{$key}=\"{$value}\""; + } + $attr = implode(' ', $_attr); + } + $attr = trim($attr); + $attr = empty($attr) ? '' : " {$attr}"; + $xml = ""; + $xml .= "<{$root}{$attr}>"; + $xml .= data_to_xml($data, $item, $id); + $xml .= ""; + return $xml; +} + +/** + * 数据XML编码 + * @param mixed $data 数据 + * @param string $item 数字索引时的节点名称 + * @param string $id 数字索引key转换为的属性名 + * @return string + */ +function data_to_xml($data, $item='item', $id='id') { + $xml = $attr = ''; + foreach ($data as $key => $val) { + if(is_numeric($key)){ + $id && $attr = " {$id}=\"{$key}\""; + $key = $item; + } + $xml .= "<{$key}{$attr}>"; + $xml .= (is_array($val) || is_object($val)) ? data_to_xml($val, $item, $id) : $val; + $xml .= ""; + } + return $xml; +} + +/** + * session管理函数 + * @param string|array $name session名称 如果为数组则表示进行session设置 + * @param mixed $value session值 + * @return mixed + */ +function session($name='',$value='') { + $prefix = C('SESSION_PREFIX'); + if(is_array($name)) { // session初始化 在session_start 之前调用 + if(isset($name['prefix'])) C('SESSION_PREFIX',$name['prefix']); + if(C('VAR_SESSION_ID') && isset($_REQUEST[C('VAR_SESSION_ID')])){ + session_id($_REQUEST[C('VAR_SESSION_ID')]); + }elseif(isset($name['id'])) { + session_id($name['id']); + } + if('common' == APP_MODE){ // 其它模式可能不支持 + ini_set('session.auto_start', 0); + } + if(isset($name['name'])) session_name($name['name']); + if(isset($name['path'])) session_save_path($name['path']); + if(isset($name['domain'])) ini_set('session.cookie_domain', $name['domain']); + if(isset($name['expire'])) { + ini_set('session.gc_maxlifetime', $name['expire']); + ini_set('session.cookie_lifetime', $name['expire']); + } + if(isset($name['use_trans_sid'])) ini_set('session.use_trans_sid', $name['use_trans_sid']?1:0); + if(isset($name['use_cookies'])) ini_set('session.use_cookies', $name['use_cookies']?1:0); + if(isset($name['cache_limiter'])) session_cache_limiter($name['cache_limiter']); + if(isset($name['cache_expire'])) session_cache_expire($name['cache_expire']); + if(isset($name['type'])) C('SESSION_TYPE',$name['type']); + if(C('SESSION_TYPE')) { // 读取session驱动 + $type = C('SESSION_TYPE'); + $class = strpos($type,'\\')? $type : 'Think\\Session\\Driver\\'. ucwords(strtolower($type)); + $hander = new $class(); + session_set_save_handler( + array(&$hander,"open"), + array(&$hander,"close"), + array(&$hander,"read"), + array(&$hander,"write"), + array(&$hander,"destroy"), + array(&$hander,"gc")); + } + // 启动session + if(C('SESSION_AUTO_START')) session_start(); + }elseif('' === $value){ + if(''===$name){ + // 获取全部的session + return $prefix ? $_SESSION[$prefix] : $_SESSION; + }elseif(0===strpos($name,'[')) { // session 操作 + if('[pause]'==$name){ // 暂停session + session_write_close(); + }elseif('[start]'==$name){ // 启动session + session_start(); + }elseif('[destroy]'==$name){ // 销毁session + $_SESSION = array(); + session_unset(); + session_destroy(); + }elseif('[regenerate]'==$name){ // 重新生成id + session_regenerate_id(); + } + }elseif(0===strpos($name,'?')){ // 检查session + $name = substr($name,1); + if(strpos($name,'.')){ // 支持数组 + list($name1,$name2) = explode('.',$name); + return $prefix?isset($_SESSION[$prefix][$name1][$name2]):isset($_SESSION[$name1][$name2]); + }else{ + return $prefix?isset($_SESSION[$prefix][$name]):isset($_SESSION[$name]); + } + }elseif(is_null($name)){ // 清空session + if($prefix) { + unset($_SESSION[$prefix]); + }else{ + $_SESSION = array(); + } + }elseif($prefix){ // 获取session + if(strpos($name,'.')){ + list($name1,$name2) = explode('.',$name); + return isset($_SESSION[$prefix][$name1][$name2])?$_SESSION[$prefix][$name1][$name2]:null; + }else{ + return isset($_SESSION[$prefix][$name])?$_SESSION[$prefix][$name]:null; + } + }else{ + if(strpos($name,'.')){ + list($name1,$name2) = explode('.',$name); + return isset($_SESSION[$name1][$name2])?$_SESSION[$name1][$name2]:null; + }else{ + return isset($_SESSION[$name])?$_SESSION[$name]:null; + } + } + }elseif(is_null($value)){ // 删除session + if(strpos($name,'.')){ + list($name1,$name2) = explode('.',$name); + if($prefix){ + unset($_SESSION[$prefix][$name1][$name2]); + }else{ + unset($_SESSION[$name1][$name2]); + } + }else{ + if($prefix){ + unset($_SESSION[$prefix][$name]); + }else{ + unset($_SESSION[$name]); + } + } + }else{ // 设置session + if(strpos($name,'.')){ + list($name1,$name2) = explode('.',$name); + if($prefix){ + $_SESSION[$prefix][$name1][$name2] = $value; + }else{ + $_SESSION[$name1][$name2] = $value; + } + }else{ + if($prefix){ + $_SESSION[$prefix][$name] = $value; + }else{ + $_SESSION[$name] = $value; + } + } + } + return null; +} + +/** + * Cookie 设置、获取、删除 + * @param string $name cookie名称 + * @param mixed $value cookie值 + * @param mixed $option cookie参数 + * @return mixed + */ +function cookie($name='', $value='', $option=null) { + // 默认设置 + $config = array( + 'prefix' => C('COOKIE_PREFIX'), // cookie 名称前缀 + 'expire' => C('COOKIE_EXPIRE'), // cookie 保存时间 + 'path' => C('COOKIE_PATH'), // cookie 保存路径 + 'domain' => C('COOKIE_DOMAIN'), // cookie 有效域名 + 'secure' => C('COOKIE_SECURE'), // cookie 启用安全传输 + 'httponly' => C('COOKIE_HTTPONLY'), // httponly设置 + ); + // 参数设置(会覆盖黙认设置) + if (!is_null($option)) { + if (is_numeric($option)) + $option = array('expire' => $option); + elseif (is_string($option)) + parse_str($option, $option); + $config = array_merge($config, array_change_key_case($option)); + } + if(!empty($config['httponly'])){ + ini_set("session.cookie_httponly", 1); + } + // 清除指定前缀的所有cookie + if (is_null($name)) { + if (empty($_COOKIE)) + return null; + // 要删除的cookie前缀,不指定则删除config设置的指定前缀 + $prefix = empty($value) ? $config['prefix'] : $value; + if (!empty($prefix)) {// 如果前缀为空字符串将不作处理直接返回 + foreach ($_COOKIE as $key => $val) { + if (0 === stripos($key, $prefix)) { + setcookie($key, '', time() - 3600, $config['path'], $config['domain'],$config['secure'],$config['httponly']); + unset($_COOKIE[$key]); + } + } + } + return null; + }elseif('' === $name){ + // 获取全部的cookie + return $_COOKIE; + } + $name = $config['prefix'] . str_replace('.', '_', $name); + if ('' === $value) { + if(isset($_COOKIE[$name])){ + $value = $_COOKIE[$name]; + if(0===strpos($value,'think:')){ + $value = substr($value,6); + return array_map('urldecode',json_decode(MAGIC_QUOTES_GPC?stripslashes($value):$value,true)); + }else{ + return $value; + } + }else{ + return null; + } + } else { + if (is_null($value)) { + setcookie($name, '', time() - 3600, $config['path'], $config['domain'],$config['secure'],$config['httponly']); + unset($_COOKIE[$name]); // 删除指定cookie + } else { + // 设置cookie + if(is_array($value)){ + $value = 'think:'.json_encode(array_map('urlencode',$value)); + } + $expire = !empty($config['expire']) ? time() + intval($config['expire']) : 0; + setcookie($name, $value, $expire, $config['path'], $config['domain'],$config['secure'],$config['httponly']); + $_COOKIE[$name] = $value; + } + } + return null; +} + +/** + * 加载动态扩展文件 + * @var string $path 文件路径 + * @return void + */ +function load_ext_file($path) { + // 加载自定义外部文件 + if($files = C('LOAD_EXT_FILE')) { + $files = explode(',',$files); + foreach ($files as $file){ + $file = $path.'Common/'.$file.'.php'; + if(is_file($file)) include $file; + } + } + // 加载自定义的动态配置文件 + if($configs = C('LOAD_EXT_CONFIG')) { + if(is_string($configs)) $configs = explode(',',$configs); + foreach ($configs as $key=>$config){ + $file = is_file($config)? $config : $path.'Conf/'.$config.CONF_EXT; + if(is_file($file)) { + is_numeric($key)?C(load_config($file)):C($key,load_config($file)); + } + } + } +} + +/** + * 获取客户端IP地址 + * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 + * @param boolean $adv 是否进行高级模式获取(有可能被伪装) + * @return mixed + */ +function get_client_ip($type = 0,$adv=false) { + $type = $type ? 1 : 0; + static $ip = NULL; + if ($ip !== NULL) return $ip[$type]; + if($adv){ + if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); + $pos = array_search('unknown',$arr); + if(false !== $pos) unset($arr[$pos]); + $ip = trim($arr[0]); + }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { + $ip = $_SERVER['HTTP_CLIENT_IP']; + }elseif (isset($_SERVER['REMOTE_ADDR'])) { + $ip = $_SERVER['REMOTE_ADDR']; + } + }elseif (isset($_SERVER['REMOTE_ADDR'])) { + $ip = $_SERVER['REMOTE_ADDR']; + } + // IP地址合法验证 + $long = sprintf("%u",ip2long($ip)); + $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); + return $ip[$type]; +} + +/** + * 发送HTTP状态 + * @param integer $code 状态码 + * @return void + */ +function send_http_status($code) { + static $_status = array( + // Informational 1xx + 100 => 'Continue', + 101 => 'Switching Protocols', + // Success 2xx + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + // Redirection 3xx + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Moved Temporarily ', // 1.1 + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + // 306 is deprecated but reserved + 307 => 'Temporary Redirect', + // Client Error 4xx + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + // Server Error 5xx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 509 => 'Bandwidth Limit Exceeded' + ); + if(isset($_status[$code])) { + header('HTTP/1.1 '.$code.' '.$_status[$code]); + // 确保FastCGI模式下正常 + header('Status:'.$code.' '.$_status[$code]); + } +} + +function think_filter(&$value){ + // TODO 其他安全过滤 + + // 过滤查询特殊字符 + if(preg_match('/^(EXP|NEQ|GT|EGT|LT|ELT|OR|XOR|LIKE|NOTLIKE|NOT BETWEEN|NOTBETWEEN|BETWEEN|NOTIN|NOT IN|IN)$/i',$value)){ + $value .= ' '; + } +} + +// 不区分大小写的in_array实现 +function in_array_case($value,$array){ + return in_array(strtolower($value),array_map('strtolower',$array)); +} diff --git a/ThinkPHP/Conf/convention.php b/ThinkPHP/Conf/convention.php new file mode 100644 index 0000000..4061933 --- /dev/null +++ b/ThinkPHP/Conf/convention.php @@ -0,0 +1,167 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP惯例配置文件 + * 该文件请不要修改,如果要覆盖惯例配置的值,可在应用配置文件中设定和惯例不符的配置项 + * 配置名称大小写任意,系统会统一转换成小写 + * 所有配置参数都可以在生效前动态改变 + */ +defined('THINK_PATH') or exit(); +return array( + /* 应用设定 */ + 'APP_USE_NAMESPACE' => true, // 应用类库是否使用命名空间 + 'APP_SUB_DOMAIN_DEPLOY' => false, // 是否开启子域名部署 + 'APP_SUB_DOMAIN_RULES' => array(), // 子域名部署规则 + 'APP_DOMAIN_SUFFIX' => '', // 域名后缀 如果是com.cn net.cn 之类的后缀必须设置 + 'ACTION_SUFFIX' => '', // 操作方法后缀 + 'MULTI_MODULE' => true, // 是否允许多模块 如果为false 则必须设置 DEFAULT_MODULE + 'MODULE_DENY_LIST' => array('Common','Runtime'), + 'CONTROLLER_LEVEL' => 1, + 'APP_AUTOLOAD_LAYER' => 'Controller,Model', // 自动加载的应用类库层 关闭APP_USE_NAMESPACE后有效 + 'APP_AUTOLOAD_PATH' => '', // 自动加载的路径 关闭APP_USE_NAMESPACE后有效 + + /* Cookie设置 */ + 'COOKIE_EXPIRE' => 0, // Cookie有效期 + 'COOKIE_DOMAIN' => '', // Cookie有效域名 + 'COOKIE_PATH' => '/', // Cookie路径 + 'COOKIE_PREFIX' => '', // Cookie前缀 避免冲突 + 'COOKIE_SECURE' => false, // Cookie安全传输 + 'COOKIE_HTTPONLY' => '', // Cookie httponly设置 + + /* 默认设定 */ + 'DEFAULT_M_LAYER' => 'Model', // 默认的模型层名称 + 'DEFAULT_C_LAYER' => 'Controller', // 默认的控制器层名称 + 'DEFAULT_V_LAYER' => 'View', // 默认的视图层名称 + 'DEFAULT_LANG' => 'zh-cn', // 默认语言 + 'DEFAULT_THEME' => '', // 默认模板主题名称 + 'DEFAULT_MODULE' => 'Home', // 默认模块 + 'DEFAULT_CONTROLLER' => 'Index', // 默认控制器名称 + 'DEFAULT_ACTION' => 'index', // 默认操作名称 + 'DEFAULT_CHARSET' => 'utf-8', // 默认输出编码 + 'DEFAULT_TIMEZONE' => 'PRC', // 默认时区 + 'DEFAULT_AJAX_RETURN' => 'JSON', // 默认AJAX 数据返回格式,可选JSON XML ... + 'DEFAULT_JSONP_HANDLER' => 'jsonpReturn', // 默认JSONP格式返回的处理方法 + 'DEFAULT_FILTER' => 'htmlspecialchars', // 默认参数过滤方法 用于I函数... + + /* 数据库设置 */ + 'DB_TYPE' => '', // 数据库类型 + 'DB_HOST' => '', // 服务器地址 + 'DB_NAME' => '', // 数据库名 + 'DB_USER' => '', // 用户名 + 'DB_PWD' => '', // 密码 + 'DB_PORT' => '', // 端口 + 'DB_PREFIX' => '', // 数据库表前缀 + 'DB_PARAMS' => array(), // 数据库连接参数 + 'DB_DEBUG' => TRUE, // 数据库调试模式 开启后可以记录SQL日志 + 'DB_FIELDS_CACHE' => true, // 启用字段缓存 + 'DB_CHARSET' => 'utf8', // 数据库编码默认采用utf8 + 'DB_DEPLOY_TYPE' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'DB_RW_SEPARATE' => false, // 数据库读写是否分离 主从式有效 + 'DB_MASTER_NUM' => 1, // 读写分离后 主服务器数量 + 'DB_SLAVE_NO' => '', // 指定从服务器序号 + + /* 数据缓存设置 */ + 'DATA_CACHE_TIME' => 0, // 数据缓存有效期 0表示永久缓存 + 'DATA_CACHE_COMPRESS' => false, // 数据缓存是否压缩缓存 + 'DATA_CACHE_CHECK' => false, // 数据缓存是否校验缓存 + 'DATA_CACHE_PREFIX' => '', // 缓存前缀 + 'DATA_CACHE_TYPE' => 'File', // 数据缓存类型,支持:File|Db|Apc|Memcache|Shmop|Sqlite|Xcache|Apachenote|Eaccelerator + 'DATA_CACHE_PATH' => TEMP_PATH,// 缓存路径设置 (仅对File方式缓存有效) + 'DATA_CACHE_KEY' => '', // 缓存文件KEY (仅对File方式缓存有效) + 'DATA_CACHE_SUBDIR' => false, // 使用子目录缓存 (自动根据缓存标识的哈希创建子目录) + 'DATA_PATH_LEVEL' => 1, // 子目录缓存级别 + + /* 错误设置 */ + 'ERROR_MESSAGE' => '页面错误!请稍后再试~',//错误显示信息,非调试模式有效 + 'ERROR_PAGE' => '', // 错误定向页面 + 'SHOW_ERROR_MSG' => false, // 显示错误信息 + 'TRACE_MAX_RECORD' => 100, // 每个级别的错误信息 最大记录数 + + /* 日志设置 */ + 'LOG_RECORD' => false, // 默认不记录日志 + 'LOG_TYPE' => 'File', // 日志记录类型 默认为文件方式 + 'LOG_LEVEL' => 'EMERG,ALERT,CRIT,ERR',// 允许记录的日志级别 + 'LOG_FILE_SIZE' => 2097152, // 日志文件大小限制 + 'LOG_EXCEPTION_RECORD' => false, // 是否记录异常信息日志 + + /* SESSION设置 */ + 'SESSION_AUTO_START' => true, // 是否自动开启Session + 'SESSION_OPTIONS' => array(), // session 配置数组 支持type name id path expire domain 等参数 + 'SESSION_TYPE' => '', // session hander类型 默认无需设置 除非扩展了session hander驱动 + 'SESSION_PREFIX' => '', // session 前缀 + //'VAR_SESSION_ID' => 'session_id', //sessionID的提交变量 + + /* 模板引擎设置 */ + 'TMPL_CONTENT_TYPE' => 'text/html', // 默认模板输出类型 + 'TMPL_ACTION_ERROR' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认错误跳转对应的模板文件 + 'TMPL_ACTION_SUCCESS' => THINK_PATH.'Tpl/dispatch_jump.tpl', // 默认成功跳转对应的模板文件 + 'TMPL_EXCEPTION_FILE' => THINK_PATH.'Tpl/think_exception.tpl',// 异常页面的模板文件 + 'TMPL_DETECT_THEME' => false, // 自动侦测模板主题 + 'TMPL_TEMPLATE_SUFFIX' => '.html', // 默认模板文件后缀 + 'TMPL_FILE_DEPR' => '/', //模板文件CONTROLLER_NAME与ACTION_NAME之间的分割符 + // 布局设置 + 'TMPL_ENGINE_TYPE' => 'Think', // 默认模板引擎 以下设置仅对使用Think模板引擎有效 + 'TMPL_CACHFILE_SUFFIX' => '.php', // 默认模板缓存后缀 + 'TMPL_DENY_FUNC_LIST' => 'echo,exit', // 模板引擎禁用函数 + 'TMPL_DENY_PHP' => false, // 默认模板引擎是否禁用PHP原生代码 + 'TMPL_L_DELIM' => '{', // 模板引擎普通标签开始标记 + 'TMPL_R_DELIM' => '}', // 模板引擎普通标签结束标记 + 'TMPL_VAR_IDENTIFY' => 'array', // 模板变量识别。留空自动判断,参数为'obj'则表示对象 + 'TMPL_STRIP_SPACE' => true, // 是否去除模板文件里面的html空格与换行 + 'TMPL_CACHE_ON' => true, // 是否开启模板编译缓存,设为false则每次都会重新编译 + 'TMPL_CACHE_PREFIX' => '', // 模板缓存前缀标识,可以动态改变 + 'TMPL_CACHE_TIME' => 0, // 模板缓存有效期 0 为永久,(以数字为值,单位:秒) + 'TMPL_LAYOUT_ITEM' => '{__CONTENT__}', // 布局模板的内容替换标识 + 'LAYOUT_ON' => false, // 是否启用布局 + 'LAYOUT_NAME' => 'layout', // 当前布局名称 默认为layout + + // Think模板引擎标签库相关设定 + 'TAGLIB_BEGIN' => '<', // 标签库标签开始标记 + 'TAGLIB_END' => '>', // 标签库标签结束标记 + 'TAGLIB_LOAD' => true, // 是否使用内置标签库之外的其它标签库,默认自动检测 + 'TAGLIB_BUILD_IN' => 'cx', // 内置标签库名称(标签使用不必指定标签库名称),以逗号分隔 注意解析顺序 + 'TAGLIB_PRE_LOAD' => '', // 需要额外加载的标签库(须指定标签库名称),多个以逗号分隔 + + /* URL设置 */ + 'URL_CASE_INSENSITIVE' => true, // 默认false 表示URL区分大小写 true则表示不区分大小写 + 'URL_MODEL' => 1, // URL访问模式,可选参数0、1、2、3,代表以下四种模式: + // 0 (普通模式); 1 (PATHINFO 模式); 2 (REWRITE 模式); 3 (兼容模式) 默认为PATHINFO 模式 + 'URL_PATHINFO_DEPR' => '/', // PATHINFO模式下,各参数之间的分割符号 + 'URL_PATHINFO_FETCH' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', // 用于兼容判断PATH_INFO 参数的SERVER替代变量列表 + 'URL_REQUEST_URI' => 'REQUEST_URI', // 获取当前页面地址的系统变量 默认为REQUEST_URI + 'URL_HTML_SUFFIX' => 'html', // URL伪静态后缀设置 + 'URL_DENY_SUFFIX' => 'ico|png|gif|jpg', // URL禁止访问的后缀设置 + 'URL_PARAMS_BIND' => true, // URL变量绑定到Action方法参数 + 'URL_PARAMS_BIND_TYPE' => 0, // URL变量绑定的类型 0 按变量名绑定 1 按变量顺序绑定 + 'URL_PARAMS_FILTER' => false, // URL变量绑定过滤 + 'URL_PARAMS_FILTER_TYPE'=> '', // URL变量绑定过滤方法 如果为空 调用DEFAULT_FILTER + 'URL_ROUTER_ON' => false, // 是否开启URL路由 + 'URL_ROUTE_RULES' => array(), // 默认路由规则 针对模块 + 'URL_MAP_RULES' => array(), // URL映射定义规则 + + /* 系统变量名称设置 */ + 'VAR_MODULE' => 'm', // 默认模块获取变量 + 'VAR_ADDON' => 'addon', // 默认的插件控制器命名空间变量 + 'VAR_CONTROLLER' => 'c', // 默认控制器获取变量 + 'VAR_ACTION' => 'a', // 默认操作获取变量 + 'VAR_AJAX_SUBMIT' => 'ajax', // 默认的AJAX提交变量 + 'VAR_JSONP_HANDLER' => 'callback', + 'VAR_PATHINFO' => 's', // 兼容模式PATHINFO获取变量例如 ?s=/module/action/id/1 后面的参数取决于URL_PATHINFO_DEPR + 'VAR_TEMPLATE' => 't', // 默认模板切换变量 + 'VAR_AUTO_STRING' => false, // 输入变量是否自动强制转换为字符串 如果开启则数组变量需要手动传入变量修饰符获取变量 + + 'HTTP_CACHE_CONTROL' => 'private', // 网页缓存控制 + 'CHECK_APP_DIR' => true, // 是否检查应用目录是否创建 + 'FILE_UPLOAD_TYPE' => 'Local', // 文件上传方式 + 'DATA_CRYPT_TYPE' => 'Think', // 数据加密方式 + +); diff --git a/ThinkPHP/Conf/debug.php b/ThinkPHP/Conf/debug.php new file mode 100644 index 0000000..06674b9 --- /dev/null +++ b/ThinkPHP/Conf/debug.php @@ -0,0 +1,27 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP 默认的调试模式配置文件 + */ +defined('THINK_PATH') or exit(); +// 调试模式下面默认设置 可以在应用配置目录下重新定义 debug.php 覆盖 +return array( + 'LOG_RECORD' => true, // 进行日志记录 + 'LOG_EXCEPTION_RECORD' => true, // 是否记录异常信息日志 + 'LOG_LEVEL' => 'EMERG,ALERT,CRIT,ERR,WARN,NOTIC,INFO,DEBUG,SQL', // 允许记录的日志级别 + 'DB_FIELDS_CACHE' => false, // 字段缓存信息 + 'DB_DEBUG' => true, // 开启调试模式 记录SQL日志 + 'TMPL_CACHE_ON' => false, // 是否开启模板编译缓存,设为false则每次都会重新编译 + 'TMPL_STRIP_SPACE' => false, // 是否去除模板文件里面的html空格与换行 + 'SHOW_ERROR_MSG' => true, // 显示错误信息 + 'URL_CASE_INSENSITIVE' => false, // URL区分大小写 +); \ No newline at end of file diff --git a/ThinkPHP/LICENSE.txt b/ThinkPHP/LICENSE.txt new file mode 100644 index 0000000..581f906 --- /dev/null +++ b/ThinkPHP/LICENSE.txt @@ -0,0 +1,32 @@ + +ThinkPHP遵循Apache2开源协议发布,并提供免费使用。 +版权所有Copyright © 2006-2014 by ThinkPHP (http://thinkphp.cn) +All rights reserved。 +ThinkPHP® 商标和著作权所有者为上海顶想信息科技有限公司。 + +Apache Licence是著名的非盈利开源组织Apache采用的协议。 +该协议和BSD类似,鼓励代码共享和尊重原作者的著作权, +允许代码修改,再作为开源或商业软件发布。需要满足 +的条件: +1. 需要给代码的用户一份Apache Licence ; +2. 如果你修改了代码,需要在被修改的文件中说明; +3. 在延伸的代码中(修改和有源代码衍生的代码中)需要 +带有原来代码中的协议,商标,专利声明和其他原来作者规 +定需要包含的说明; +4. 如果再发布的产品中包含一个Notice文件,则在Notice文 +件中需要带有本协议内容。你可以在Notice中增加自己的 +许可,但不可以表现为对Apache Licence构成更改。 +具体的协议参考:http://www.apache.org/licenses/LICENSE-2.0 + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/ThinkPHP/Lang/en-us.php b/ThinkPHP/Lang/en-us.php new file mode 100644 index 0000000..706b9da --- /dev/null +++ b/ThinkPHP/Lang/en-us.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP English language package + */ +return array( + /* core language package */ + '_MODULE_NOT_EXIST_' => "Module can't be loaded", + '_CONTROLLER_NOT_EXIST_' => "Controller can't be loaded", + '_ERROR_ACTION_' => 'Illegal Action', + '_LANGUAGE_NOT_LOAD_' => "Can't load language package", + '_TEMPLATE_NOT_EXIST_' => "Template doesn't exist", + '_MODULE_' => 'Module', + '_ACTION_' => 'Action', + '_MODEL_NOT_EXIST_' => "Model can't be loaded", + '_VALID_ACCESS_' => 'No access', + '_XML_TAG_ERROR_' => 'XML tag syntax errors', + '_DATA_TYPE_INVALID_' => 'Illegal data objects!', + '_OPERATION_WRONG_' => 'Operation error occurs', + '_NOT_LOAD_DB_' => 'Unable to load the database', + '_NO_DB_DRIVER_' => 'Unable to load database driver', + '_NOT_SUPPORT_DB_' => 'The system is temporarily not support database', + '_NO_DB_CONFIG_' => 'Not define the database configuration', + '_NOT_SUPPORT_' => 'The system does not support', + '_CACHE_TYPE_INVALID_' => 'Unable to load the cache type', + '_FILE_NOT_WRITABLE_' => 'Directory (file) is not writable', + '_METHOD_NOT_EXIST_' => 'The method you requested does not exist!', + '_CLASS_NOT_EXIST_' => 'Instantiating a class does not exist!', + '_CLASS_CONFLICT_' => 'Class name conflicts', + '_TEMPLATE_ERROR_' => 'Template Engine errors', + '_CACHE_WRITE_ERROR_' => 'Cache file write failed!', + '_TAGLIB_NOT_EXIST_' => 'Tag library is not defined', + '_OPERATION_FAIL_' => 'Operation failed!', + '_OPERATION_SUCCESS_' => 'Operation succeed!', + '_SELECT_NOT_EXIST_' => 'Record does not exist!', + '_EXPRESS_ERROR_' => 'Expression errors', + '_TOKEN_ERROR_' => "Form's token errors", + '_RECORD_HAS_UPDATE_' => 'Record has been updated', + '_NOT_ALLOW_PHP_' => 'PHP codes are not allowed in the template', + '_PARAM_ERROR_' => 'Parameter error or undefined', + '_ERROR_QUERY_EXPRESS_' => 'Query express error', +); diff --git a/ThinkPHP/Lang/pt-br.php b/ThinkPHP/Lang/pt-br.php new file mode 100644 index 0000000..e0ef3fa --- /dev/null +++ b/ThinkPHP/Lang/pt-br.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP Portuguese language package + */ +return array( + /* core language package */ + '_MODULE_NOT_EXIST_' => "Módulo não pode ser carregado", + '_CONTROLLER_NOT_EXIST_' => "Controller não pode ser carregado", + '_ERROR_ACTION_' => 'Ação ilegal', + '_LANGUAGE_NOT_LOAD_' => "Não é possível carregar pacote da linguagem", + '_TEMPLATE_NOT_EXIST_' => "Template não existe", + '_MODULE_' => 'Módulo', + '_ACTION_' => 'Ação', + '_MODEL_NOT_EXIST_' => "Modelo não pode ser carregado", + '_VALID_ACCESS_' => 'Sem acesso', + '_XML_TAG_ERROR_' => 'Erro de sintaxe - XML tag', + '_DATA_TYPE_INVALID_' => 'Tipos de dados ilegais!', + '_OPERATION_WRONG_' => 'Erro na operação', + '_NOT_LOAD_DB_' => 'Impossível carregar banco de dados', + '_NO_DB_DRIVER_' => 'Impossível carregar driver do bando de dados', + '_NOT_SUPPORT_DB_' => 'Temporariamente sem suporte ao banco', + '_NO_DB_CONFIG_' => 'Não define a configuração do banco', + '_NOT_SUPPORT_' => 'O sistema não suporta', + '_CACHE_TYPE_INVALID_' => 'Impossível carregar o tipo de cache', + '_FILE_NOT_WRITABLE_' => 'Diretório (arquivo) não pode ser escrito', + '_METHOD_NOT_EXIST_' => 'O método solicitado não existe!', + '_CLASS_NOT_EXIST_' => 'Não existe instância da classe', + '_CLASS_CONFLICT_' => 'Conflitos com nome da classe', + '_TEMPLATE_ERROR_' => 'Erros na contrução do template', + '_CACHE_WRITE_ERROR_' => 'Escrita do arquivo de cache falhou!', + '_TAGLIB_NOT_EXIST_' => 'Biblioteca da tag não foi definida', + '_OPERATION_FAIL_' => 'Operação falhou!', + '_OPERATION_SUCCESS_' => 'Operação bem sucessida!', + '_SELECT_NOT_EXIST_' => 'Gravação não existe!', + '_EXPRESS_ERROR_' => 'Erros de expressão', + '_TOKEN_ERROR_' => 'Erro no token do formulário', + '_RECORD_HAS_UPDATE_' => 'Gravação não foi atualizada', + '_NOT_ALLOW_PHP_' => 'Código PHP não é permitido no template', + '_PARAM_ERROR_' => 'Parâmetro errado ou indefinido', + '_ERROR_QUERY_EXPRESS_' => 'Erros na expressão da query', +); diff --git a/ThinkPHP/Lang/zh-cn.php b/ThinkPHP/Lang/zh-cn.php new file mode 100644 index 0000000..57ef25b --- /dev/null +++ b/ThinkPHP/Lang/zh-cn.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP 简体中文语言包 + */ +return array( + /* 核心语言变量 */ + '_MODULE_NOT_EXIST_' => '无法加载模块', + '_CONTROLLER_NOT_EXIST_' => '无法加载控制器', + '_ERROR_ACTION_' => '非法操作', + '_LANGUAGE_NOT_LOAD_' => '无法加载语言包', + '_TEMPLATE_NOT_EXIST_' => '模板不存在', + '_MODULE_' => '模块', + '_ACTION_' => '操作', + '_MODEL_NOT_EXIST_' => '模型不存在或者没有定义', + '_VALID_ACCESS_' => '没有权限', + '_XML_TAG_ERROR_' => 'XML标签语法错误', + '_DATA_TYPE_INVALID_' => '非法数据对象!', + '_OPERATION_WRONG_' => '操作出现错误', + '_NOT_LOAD_DB_' => '无法加载数据库', + '_NO_DB_DRIVER_' => '无法加载数据库驱动', + '_NOT_SUPPORT_DB_' => '系统暂时不支持数据库', + '_NO_DB_CONFIG_' => '没有定义数据库配置', + '_NOT_SUPPORT_' => '系统不支持', + '_CACHE_TYPE_INVALID_' => '无法加载缓存类型', + '_FILE_NOT_WRITABLE_' => '目录(文件)不可写', + '_METHOD_NOT_EXIST_' => '方法不存在!', + '_CLASS_NOT_EXIST_' => '实例化一个不存在的类!', + '_CLASS_CONFLICT_' => '类名冲突', + '_TEMPLATE_ERROR_' => '模板引擎错误', + '_CACHE_WRITE_ERROR_' => '缓存文件写入失败!', + '_TAGLIB_NOT_EXIST_' => '标签库未定义', + '_OPERATION_FAIL_' => '操作失败!', + '_OPERATION_SUCCESS_' => '操作成功!', + '_SELECT_NOT_EXIST_' => '记录不存在!', + '_EXPRESS_ERROR_' => '表达式错误', + '_TOKEN_ERROR_' => '表单令牌错误', + '_RECORD_HAS_UPDATE_' => '记录已经更新', + '_NOT_ALLOW_PHP_' => '模板禁用PHP代码', + '_PARAM_ERROR_' => '参数错误或者未定义', + '_ERROR_QUERY_EXPRESS_' => '错误的查询条件', +); diff --git a/ThinkPHP/Lang/zh-tw.php b/ThinkPHP/Lang/zh-tw.php new file mode 100644 index 0000000..327f334 --- /dev/null +++ b/ThinkPHP/Lang/zh-tw.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- + +/** + * ThinkPHP 繁体中文語言包 + */ +return array( + /* 核心語言變數 */ + '_MODULE_NOT_EXIST_' => '無法載入模組', + '_CONTROLLER_NOT_EXIST_' => '無法載入控制器', + '_ERROR_ACTION_' => '非法操作', + '_LANGUAGE_NOT_LOAD_' => '無法載入語言包', + '_TEMPLATE_NOT_EXIST_' => '模板不存在', + '_MODULE_' => '模組', + '_ACTION_' => '操作', + '_MODEL_NOT_EXIST_' => '模型不存在或者沒有定義', + '_VALID_ACCESS_' => '沒有權限', + '_XML_TAG_ERROR_' => 'XML標籤語法錯誤', + '_DATA_TYPE_INVALID_' => '非法資料物件!', + '_OPERATION_WRONG_' => '操作出現錯誤', + '_NOT_LOAD_DB_' => '無法載入資料庫', + '_NO_DB_DRIVER_' => '無法載入資料庫驅動', + '_NOT_SUPPORT_DB_' => '系統暫時不支援資料庫', + '_NO_DB_CONFIG_' => '沒有定義資料庫設定', + '_NOT_SUPPORT_' => '系統不支援', + '_CACHE_TYPE_INVALID_' => '無法載入快取類型', + '_FILE_NOT_WRITABLE_' => '目錄(檔案)不可寫', + '_METHOD_NOT_EXIST_' => '方法不存在!', + '_CLASS_NOT_EXIST_' => '實例化一個不存在的類別!', + '_CLASS_CONFLICT_' => '類別名稱衝突', + '_TEMPLATE_ERROR_' => '模板引擎錯誤', + '_CACHE_WRITE_ERROR_' => '快取檔案寫入失敗!', + '_TAGLIB_NOT_EXIST_' => '標籤庫未定義', + '_OPERATION_FAIL_' => '操作失敗!', + '_OPERATION_SUCCESS_' => '操作成功!', + '_SELECT_NOT_EXIST_' => '記錄不存在!', + '_EXPRESS_ERROR_' => '運算式錯誤', + '_TOKEN_ERROR_' => '表單權限錯誤', + '_RECORD_HAS_UPDATE_' => '記錄已經更新', + '_NOT_ALLOW_PHP_' => '模板禁用PHP代碼', + '_PARAM_ERROR_' => '參數錯誤或者未定義', + '_ERROR_QUERY_EXPRESS_' => '錯誤的查詢條件', +); diff --git a/ThinkPHP/Library/Behavior/AgentCheckBehavior.class.php b/ThinkPHP/Library/Behavior/AgentCheckBehavior.class.php new file mode 100644 index 0000000..77c271b --- /dev/null +++ b/ThinkPHP/Library/Behavior/AgentCheckBehavior.class.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 行为扩展:代理检测 + */ +class AgentCheckBehavior { + public function run(&$params) { + // 代理访问检测 + $limitProxyVisit = C('LIMIT_PROXY_VISIT',null,true); + if($limitProxyVisit && ($_SERVER['HTTP_X_FORWARDED_FOR'] || $_SERVER['HTTP_VIA'] || $_SERVER['HTTP_PROXY_CONNECTION'] || $_SERVER['HTTP_USER_AGENT_VIA'])) { + // 禁止代理访问 + exit('Access Denied'); + } + } +} diff --git a/ThinkPHP/Library/Behavior/BorisBehavior.class.php b/ThinkPHP/Library/Behavior/BorisBehavior.class.php new file mode 100644 index 0000000..7143746 --- /dev/null +++ b/ThinkPHP/Library/Behavior/BorisBehavior.class.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +use Think\Think; +/** + * Boris行为扩展 + */ +class BorisBehavior { + public function run(&$params) { + if(IS_CLI){ + if(!function_exists('pcntl_signal')) + E("pcntl_signal not working.\nRepl mode based on Linux OS or PHP for OS X(http://php-osx.liip.ch/)\n"); + Think::addMap(array( + 'Boris\Boris' => VENDOR_PATH . 'Boris/Boris.php', + 'Boris\Config' => VENDOR_PATH . 'Boris/Config.php', + 'Boris\CLIOptionsHandler' => VENDOR_PATH . 'Boris/CLIOptionsHandler.php', + 'Boris\ColoredInspector' => VENDOR_PATH . 'Boris/ColoredInspector.php', + 'Boris\DumpInspector' => VENDOR_PATH . 'Boris/DumpInspector.php', + 'Boris\EvalWorker' => VENDOR_PATH . 'Boris/EvalWorker.php', + 'Boris\ExportInspector' => VENDOR_PATH . 'Boris/ExportInspector.php', + 'Boris\Inspector' => VENDOR_PATH . 'Boris/Inspector.php', + 'Boris\ReadlineClient' => VENDOR_PATH . 'Boris/ReadlineClient.php', + 'Boris\ShallowParser' => VENDOR_PATH . 'Boris/ShallowParser.php', + )); + $boris = new \Boris\Boris(">>> "); + $config = new \Boris\Config(); + $config->apply($boris, true); + $options = new \Boris\CLIOptionsHandler(); + $options->handle($boris); + $boris->onStart(sprintf("echo 'REPL MODE FOR THINKPHP \nTHINKPHP_VERSION: %s, PHP_VERSION: %s, BORIS_VERSION: %s\n';", THINK_VERSION, PHP_VERSION, $boris::VERSION)); + $boris->start(); + } + } +} diff --git a/ThinkPHP/Library/Behavior/BrowserCheckBehavior.class.php b/ThinkPHP/Library/Behavior/BrowserCheckBehavior.class.php new file mode 100644 index 0000000..b1ed896 --- /dev/null +++ b/ThinkPHP/Library/Behavior/BrowserCheckBehavior.class.php @@ -0,0 +1,34 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 浏览器防刷新检测 + */ +class BrowserCheckBehavior { + public function run(&$params) { + if($_SERVER['REQUEST_METHOD'] == 'GET') { + // 启用页面防刷新机制 + $guid = md5($_SERVER['PHP_SELF']); + // 浏览器防刷新的时间间隔(秒) 默认为10 + $refleshTime = C('LIMIT_REFLESH_TIMES',null,10); + // 检查页面刷新间隔 + if(cookie('_last_visit_time_'.$guid) && cookie('_last_visit_time_'.$guid)>time()-$refleshTime) { + // 页面刷新读取浏览器缓存 + header('HTTP/1.1 304 Not Modified'); + exit; + }else{ + // 缓存当前地址访问时间 + cookie('_last_visit_time_'.$guid, $_SERVER['REQUEST_TIME']); + //header('Last-Modified:'.(date('D,d M Y H:i:s',$_SERVER['REQUEST_TIME']-C('LIMIT_REFLESH_TIMES'))).' GMT'); + } + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php b/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php new file mode 100644 index 0000000..5b8f9b8 --- /dev/null +++ b/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php @@ -0,0 +1,87 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +// 创建Lite运行文件 +// 可以替换框架入口文件运行 +// 建议绑定位置app_init +class BuildLiteBehavior { + public function run(&$params) { + if(!defined('BUILD_LITE_FILE')) return ; + $litefile = C('RUNTIME_LITE_FILE',null,RUNTIME_PATH.'lite.php'); + if(is_file($litefile)) return; + + $defs = get_defined_constants(TRUE); + $content = 'namespace {$GLOBALS[\'_beginTime\'] = microtime(TRUE);'; + if(MEMORY_LIMIT_ON) { + $content .= '$GLOBALS[\'_startUseMems\'] = memory_get_usage();'; + } + + // 生成数组定义 + unset($defs['user']['BUILD_LITE_FILE']); + $content .= $this->buildArrayDefine($defs['user']).'}'; + + // 读取编译列表文件 + $filelist = is_file(CONF_PATH.'lite.php')? + include CONF_PATH.'lite.php': + array( + THINK_PATH.'Common/functions.php', + COMMON_PATH.'Common/function.php', + CORE_PATH . 'Think'.EXT, + CORE_PATH . 'Hook'.EXT, + CORE_PATH . 'App'.EXT, + CORE_PATH . 'Dispatcher'.EXT, + CORE_PATH . 'Log'.EXT, + CORE_PATH . 'Log/Driver/File'.EXT, + CORE_PATH . 'Route'.EXT, + CORE_PATH . 'Controller'.EXT, + CORE_PATH . 'View'.EXT, + CORE_PATH . 'Storage'.EXT, + CORE_PATH . 'Storage/Driver/File'.EXT, + CORE_PATH . 'Exception'.EXT, + BEHAVIOR_PATH . 'ParseTemplateBehavior'.EXT, + BEHAVIOR_PATH . 'ContentReplaceBehavior'.EXT, + ); + + // 编译文件 + foreach ($filelist as $file){ + if(is_file($file)) { + $content .= compile($file); + } + } + + // 处理Think类的start方法 + $content = preg_replace('/\$runtimefile = RUNTIME_PATH(.+?)(if\(APP_STATUS)/','\2',$content,1); + $content .= "\nnamespace { Think\Think::addMap(".var_export(\Think\Think::getMap(),true).");"; + $content .= "\nL(".var_export(L(),true).");\nC(".var_export(C(),true).');Think\Hook::import('.var_export(\Think\Hook::get(),true).');Think\Think::start();}'; + + // 生成运行Lite文件 + file_put_contents($litefile,strip_whitespace(' $val) { + $key = strtoupper($key); + $content .= 'defined(\'' . $key . '\') or '; + if (is_int($val) || is_float($val)) { + $content .= "define('" . $key . "'," . $val . ');'; + } elseif (is_bool($val)) { + $val = ($val) ? 'true' : 'false'; + $content .= "define('" . $key . "'," . $val . ');'; + } elseif (is_string($val)) { + $content .= "define('" . $key . "','" . addslashes($val) . "');"; + } + $content .= "\n"; + } + return $content; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/CheckActionRouteBehavior.class.php b/ThinkPHP/Library/Behavior/CheckActionRouteBehavior.class.php new file mode 100644 index 0000000..5e1fb9c --- /dev/null +++ b/ThinkPHP/Library/Behavior/CheckActionRouteBehavior.class.php @@ -0,0 +1,194 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 系统行为扩展:操作路由检测 + */ +class CheckActionRouteBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$config){ + // 优先检测是否存在PATH_INFO + $regx = trim($_SERVER['PATH_INFO'],'/'); + if(empty($regx)) return ; + // 路由定义文件优先于config中的配置定义 + // 路由处理 + $routes = $config['routes']; + if(!empty($routes)) { + $depr = C('URL_PATHINFO_DEPR'); + // 分隔符替换 确保路由定义使用统一的分隔符 + $regx = str_replace($depr,'/',$regx); + $regx = substr_replace($regx,'',0,strlen(__URL__)); + foreach ($routes as $rule=>$route){ + if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { // 正则路由 + return C('ACTION_NAME',$this->parseRegex($matches,$route,$regx)); + }else{ // 规则路由 + $len1 = substr_count($regx,'/'); + $len2 = substr_count($rule,'/'); + if($len1>=$len2) { + if('$' == substr($rule,-1,1)) {// 完整匹配 + if($len1 != $len2) { + continue; + }else{ + $rule = substr($rule,0,-1); + } + } + $match = $this->checkUrlMatch($regx,$rule); + if($match) return C('ACTION_NAME',$this->parseRule($rule,$route,$regx)); + } + } + } + } + } + + // 检测URL和规则路由是否匹配 + private function checkUrlMatch($regx,$rule) { + $m1 = explode('/',$regx); + $m2 = explode('/',$rule); + $match = true; // 是否匹配 + foreach ($m2 as $key=>$val){ + if(':' == substr($val,0,1)) {// 动态变量 + if(strpos($val,'\\')) { + $type = substr($val,-1); + if('d'==$type && !is_numeric($m1[$key])) { + $match = false; + break; + } + }elseif(strpos($val,'^')){ + $array = explode('|',substr(strstr($val,'^'),1)); + if(in_array($m1[$key],$array)) { + $match = false; + break; + } + } + }elseif(0 !== strcasecmp($val,$m1[$key])){ + $match = false; + break; + } + } + return $match; + } + + // 解析规范的路由地址 + // 地址格式 操作?参数1=值1&参数2=值2... + private function parseUrl($url) { + $var = array(); + if(false !== strpos($url,'?')) { // 操作?参数1=值1&参数2=值2... + $info = parse_url($url); + $path = $info['path']; + parse_str($info['query'],$var); + }else{ // 操作 + $path = $url; + } + $var[C('VAR_ACTION')] = $path; + return $var; + } + + // 解析规则路由 + // '路由规则'=>'操作?额外参数1=值1&额外参数2=值2...' + // '路由规则'=>array('操作','额外参数1=值1&额外参数2=值2...') + // '路由规则'=>'外部地址' + // '路由规则'=>array('外部地址','重定向代码') + // 路由规则中 :开头 表示动态变量 + // 外部地址中可以用动态变量 采用 :1 :2 的方式 + // 'news/:month/:day/:id'=>array('News/read?cate=1','status=1'), + // 'new/:id'=>array('/new.php?id=:1',301), 重定向 + private function parseRule($rule,$route,$regx) { + // 获取路由地址规则 + $url = is_array($route)?$route[0]:$route; + // 获取URL地址中的参数 + $paths = explode('/',$regx); + // 解析路由规则 + $matches = array(); + $rule = explode('/',$rule); + foreach ($rule as $item){ + if(0===strpos($item,':')) { // 动态变量获取 + if($pos = strpos($item,'^') ) { + $var = substr($item,1,$pos-1); + }elseif(strpos($item,'\\')){ + $var = substr($item,1,-2); + }else{ + $var = substr($item,1); + } + $matches[$var] = array_shift($paths); + }else{ // 过滤URL中的静态变量 + array_shift($paths); + } + } + if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转 + if(strpos($url,':')) { // 传递动态参数 + $values = array_values($matches); + $url = preg_replace('/:(\d+)/e','$values[\\1-1]',$url); + } + header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); + exit; + }else{ + // 解析路由地址 + $var = $this->parseUrl($url); + // 解析路由地址里面的动态参数 + $values = array_values($matches); + foreach ($var as $key=>$val){ + if(0===strpos($val,':')) { + $var[$key] = $values[substr($val,1)-1]; + } + } + $var = array_merge($matches,$var); + // 解析剩余的URL参数 + if($paths) { + preg_replace('@(\w+)\/([^\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', implode('/',$paths)); + } + // 解析路由自动传入参数 + if(is_array($route) && isset($route[1])) { + parse_str($route[1],$params); + $var = array_merge($var,$params); + } + $action = $var[C('VAR_ACTION')]; + unset($var[C('VAR_ACTION')]); + $_GET = array_merge($var,$_GET); + return $action; + } + } + + // 解析正则路由 + // '路由正则'=>'[分组/模块/操作]?参数1=值1&参数2=值2...' + // '路由正则'=>array('[分组/模块/操作]?参数1=值1&参数2=值2...','额外参数1=值1&额外参数2=值2...') + // '路由正则'=>'外部地址' + // '路由正则'=>array('外部地址','重定向代码') + // 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式 + // '/new\/(\d+)\/(\d+)/'=>array('News/read?id=:1&page=:2&cate=1','status=1'), + // '/new\/(\d+)/'=>array('/new.php?id=:1&page=:2&status=1','301'), 重定向 + private function parseRegex($matches,$route,$regx) { + // 获取路由地址规则 + $url = is_array($route)?$route[0]:$route; + $url = preg_replace('/:(\d+)/e','$matches[\\1]',$url); + if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转 + header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); + exit; + }else{ + // 解析路由地址 + $var = $this->parseUrl($url); + // 解析剩余的URL参数 + $regx = substr_replace($regx,'',0,strlen($matches[0])); + if($regx) { + preg_replace('@(\w+)\/([^,\/]+)@e', '$var[strtolower(\'\\1\')]=strip_tags(\'\\2\');', $regx); + } + // 解析路由自动传入参数 + if(is_array($route) && isset($route[1])) { + parse_str($route[1],$params); + $var = array_merge($var,$params); + } + $action = $var[C('VAR_ACTION')]; + unset($var[C('VAR_ACTION')]); + $_GET = array_merge($var,$_GET); + } + return $action; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/CheckLangBehavior.class.php b/ThinkPHP/Library/Behavior/CheckLangBehavior.class.php new file mode 100644 index 0000000..c4d46a2 --- /dev/null +++ b/ThinkPHP/Library/Behavior/CheckLangBehavior.class.php @@ -0,0 +1,77 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 语言检测 并自动加载语言包 + */ +class CheckLangBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$params){ + // 检测语言 + $this->checkLanguage(); + } + + /** + * 语言检查 + * 检查浏览器支持语言,并自动加载语言包 + * @access private + * @return void + */ + private function checkLanguage() { + // 不开启语言包功能,仅仅加载框架语言文件直接返回 + if (!C('LANG_SWITCH_ON',null,false)){ + return; + } + $langSet = C('DEFAULT_LANG'); + $varLang = C('VAR_LANGUAGE',null,'l'); + $langList = C('LANG_LIST',null,'zh-cn'); + // 启用了语言包功能 + // 根据是否启用自动侦测设置获取语言选择 + if (C('LANG_AUTO_DETECT',null,true)){ + if(isset($_GET[$varLang])){ + $langSet = $_GET[$varLang];// url中设置了语言变量 + cookie('think_language',$langSet,3600); + }elseif(cookie('think_language')){// 获取上次用户的选择 + $langSet = cookie('think_language'); + }elseif(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){// 自动侦测浏览器语言 + preg_match('/^([a-z\d\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches); + $langSet = $matches[1]; + cookie('think_language',$langSet,3600); + } + if(false === stripos($langList,$langSet)) { // 非法语言参数 + $langSet = C('DEFAULT_LANG'); + } + } + // 定义当前语言 + define('LANG_SET',strtolower($langSet)); + + // 读取框架语言包 + $file = THINK_PATH.'Lang/'.LANG_SET.'.php'; + if(LANG_SET != C('DEFAULT_LANG') && is_file($file)) + L(include $file); + + // 读取应用公共语言包 + $file = LANG_PATH.LANG_SET.'.php'; + if(is_file($file)) + L(include $file); + + // 读取模块语言包 + $file = MODULE_PATH.'Lang/'.LANG_SET.'.php'; + if(is_file($file)) + L(include $file); + + // 读取当前控制器语言包 + $file = MODULE_PATH.'Lang/'.LANG_SET.'/'.strtolower(CONTROLLER_NAME).'.php'; + if (is_file($file)) + L(include $file); + } +} diff --git a/ThinkPHP/Library/Behavior/ChromeShowPageTraceBehavior.class.php b/ThinkPHP/Library/Behavior/ChromeShowPageTraceBehavior.class.php new file mode 100644 index 0000000..8abf892 --- /dev/null +++ b/ThinkPHP/Library/Behavior/ChromeShowPageTraceBehavior.class.php @@ -0,0 +1,610 @@ + +// +---------------------------------------------------------------------- +// $Id$ + +/** + * 将Trace信息输出到chrome浏览器的控制器,从而不影响ajax效果和页面的布局。 + * 使用前,你需要先安装 chrome log 这个插件: http://craig.is/writing/chrome-logger。 + * 定义应用的tags.php文件 Application/Common/Conf/tags.php, + * + * array( + * 'Behavior\ChromeShowPageTrace' + * ) + * ); + * + * 如果trace信息没有正常输出,请查看您的日志。 + * 这是通过http headers和chrome通信,所以要保证在输出trace信息之前不能有 + * headers输出,你可以在入口文件第一行加入代码 ob_start(); 或者配置output_buffering + * + */ +namespace Behavior; +use Think\Log; + +/** + * 系统行为扩展 页面Trace显示输出 + */ +class ChromeShowPageTraceBehavior { + + protected $tracePageTabs = array('BASE'=>'基本','FILE'=>'文件','INFO'=>'流程','ERR|NOTIC'=>'错误','SQL'=>'SQL','DEBUG'=>'调试'); + + // 行为扩展的执行入口必须是run + public function run(&$params){ + if(C('SHOW_PAGE_TRACE')) $this->showTrace(); + } + + + /** + * 显示页面Trace信息 + * @access private + */ + private function showTrace() { + // 系统默认显示信息 + $files = get_included_files(); + $info = array(); + foreach ($files as $key=>$file){ + $info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )'; + } + $trace = array(); + $base = array( + '请求信息' => date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__, + '运行时间' => $this->showTime(), + '吞吐率' => number_format(1/G('beginTime','viewEndTime'),2).'req/s', + '内存开销' => MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持', + '查询信息' => N('db_query').' queries '.N('db_write').' writes ', + '文件加载' => count(get_included_files()), + '缓存信息' => N('cache_read').' gets '.N('cache_write').' writes ', + '配置加载' => count(c()), + '会话信息' => 'SESSION_ID='.session_id(), + ); + // 读取应用定义的Trace文件 + $traceFile = COMMON_PATH.'Conf/trace.php'; + if(is_file($traceFile)) { + $base = array_merge($base,include $traceFile); + } + + $debug = trace(); + $tabs = C('TRACE_PAGE_TABS',null,$this->tracePageTabs); + foreach ($tabs as $name=>$title){ + switch(strtoupper($name)) { + case 'BASE':// 基本信息 + $trace[$title] = $base; + break; + case 'FILE': // 文件信息 + $trace[$title] = $info; + break; + default:// 调试信息 + $name = strtoupper($name); + if(strpos($name,'|')) {// 多组信息 + $array = explode('|',$name); + $result = array(); + foreach($array as $name){ + $result += isset($debug[$name])?$debug[$name]:array(); + } + $trace[$title] = $result; + }else{ + $trace[$title] = isset($debug[$name])?$debug[$name]:''; + } + } + } + chrome_debug('TRACE信息:'.__SELF__,'group'); + //输出日志 + foreach($trace as $title=>$log){ + '错误'==$title?chrome_debug($title,'group'):chrome_debug($title,'groupCollapsed'); + foreach($log as $i=>$logstr){ + chrome_debug($i.'.'.$logstr,'log'); + } + chrome_debug('','groupEnd'); + } + chrome_debug('','groupEnd'); + if($save = C('PAGE_TRACE_SAVE')) { // 保存页面Trace日志 + if(is_array($save)) {// 选择选项卡保存 + $tabs = C('TRACE_PAGE_TABS',null,$this->tracePageTabs); + $array = array(); + foreach ($save as $tab){ + $array[] = $tabs[$tab]; + } + } + $content = date('[ c ]').' '.get_client_ip().' '.$_SERVER['REQUEST_URI']."\r\n"; + foreach ($trace as $key=>$val){ + if(!isset($array) || in_array($key,$array)) { + $content .= '[ '.$key." ]\r\n"; + if(is_array($val)) { + foreach ($val as $k=>$v){ + $content .= (!is_numeric($k)?$k.':':'').print_r($v,true)."\r\n"; + } + }else{ + $content .= print_r($val,true)."\r\n"; + } + $content .= "\r\n"; + } + } + error_log(str_replace('
',"\r\n",$content), 3,LOG_PATH.date('y_m_d').'_trace.log'); + } + unset($files,$info,$base); + } + + /** + * 获取运行时间 + */ + private function showTime() { + // 显示运行时间 + G('beginTime',$GLOBALS['_beginTime']); + G('viewEndTime'); + // 显示详细运行时间 + return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; + } +} +if(!function_exists('chrome_debug')){ +//ChromePhp 输出trace的函数 +function chrome_debug($msg,$type='trace',$trace_level=1){ + if('trace'==$type){ + ChromePhp::groupCollapsed($msg); + $traces=debug_backtrace(false); + $traces=array_reverse($traces); + $max=count($traces)-$trace_level; + for($i=0;$i<$max;$i++){ + $trace=$traces[$i]; + $fun=isset($trace['class'])?$trace['class'].'::'.$trace['function']:$trace['function']; + $file=isset($trace['file'])?$trace['file']:'unknown file'; + $line=isset($trace['line'])?$trace['line']:'unknown line'; + $trace_msg='#'.$i.' '.$fun.' called at ['.$file.':'.$line.']'; + if(!empty($trace['args'])){ + ChromePhp::groupCollapsed($trace_msg); + ChromePhp::log($trace['args']); + ChromePhp::groupEnd(); + }else{ + ChromePhp::log($trace_msg); + } + } + ChromePhp::groupEnd(); + }else{ + if(method_exists('Behavior\ChromePhp',$type)){ + //支持type trace,warn,log,error,group, groupCollapsed, groupEnd等 + call_user_func(array('Behavior\ChromePhp',$type),$msg); + }else{ + //如果type不为trace,warn,log等,则为log的标签 + call_user_func_array(array('Behavior\ChromePhp','log'),func_get_args()); + } + } +} + + + +/** + * Server Side Chrome PHP debugger class + * + * @package ChromePhp + * @author Craig Campbell + */ +class ChromePhp{ + /** + * @var string + */ + const VERSION = '4.1.0'; + + /** + * @var string + */ + const HEADER_NAME = 'X-ChromeLogger-Data'; + + /** + * @var string + */ + const BACKTRACE_LEVEL = 'backtrace_level'; + + /** + * @var string + */ + const LOG = 'log'; + + /** + * @var string + */ + const WARN = 'warn'; + + /** + * @var string + */ + const ERROR = 'error'; + + /** + * @var string + */ + const GROUP = 'group'; + + /** + * @var string + */ + const INFO = 'info'; + + /** + * @var string + */ + const GROUP_END = 'groupEnd'; + + /** + * @var string + */ + const GROUP_COLLAPSED = 'groupCollapsed'; + + /** + * @var string + */ + const TABLE = 'table'; + + /** + * @var string + */ + protected $_php_version; + + /** + * @var int + */ + protected $_timestamp; + + /** + * @var array + */ + protected $_json = array( + 'version' => self::VERSION, + 'columns' => array('log', 'backtrace', 'type'), + 'rows' => array() + ); + + /** + * @var array + */ + protected $_backtraces = array(); + + /** + * @var bool + */ + protected $_error_triggered = false; + + /** + * @var array + */ + protected $_settings = array( + self::BACKTRACE_LEVEL => 1 + ); + + /** + * @var ChromePhp + */ + protected static $_instance; + + /** + * Prevent recursion when working with objects referring to each other + * + * @var array + */ + protected $_processed = array(); + + /** + * constructor + */ + private function __construct() + { + $this->_php_version = phpversion(); + $this->_timestamp = $this->_php_version >= 5.1 ? $_SERVER['REQUEST_TIME'] : time(); + $this->_json['request_uri'] = $_SERVER['REQUEST_URI']; + } + + /** + * gets instance of this class + * + * @return ChromePhp + */ + public static function getInstance() + { + if (self::$_instance === null) { + self::$_instance = new self(); + } + return self::$_instance; + } + + /** + * logs a variable to the console + * + * @param mixed $data,... unlimited OPTIONAL number of additional logs [...] + * @return void + */ + public static function log() + { + $args = func_get_args(); + return self::_log('', $args); + } + + /** + * logs a warning to the console + * + * @param mixed $data,... unlimited OPTIONAL number of additional logs [...] + * @return void + */ + public static function warn() + { + $args = func_get_args(); + return self::_log(self::WARN, $args); + } + + /** + * logs an error to the console + * + * @param mixed $data,... unlimited OPTIONAL number of additional logs [...] + * @return void + */ + public static function error() + { + $args = func_get_args(); + return self::_log(self::ERROR, $args); + } + + /** + * sends a group log + * + * @param string value + */ + public static function group() + { + $args = func_get_args(); + return self::_log(self::GROUP, $args); + } + + /** + * sends an info log + * + * @param mixed $data,... unlimited OPTIONAL number of additional logs [...] + * @return void + */ + public static function info() + { + $args = func_get_args(); + return self::_log(self::INFO, $args); + } + + /** + * sends a collapsed group log + * + * @param string value + */ + public static function groupCollapsed() + { + $args = func_get_args(); + return self::_log(self::GROUP_COLLAPSED, $args); + } + + /** + * ends a group log + * + * @param string value + */ + public static function groupEnd() + { + $args = func_get_args(); + return self::_log(self::GROUP_END, $args); + } + + /** + * sends a table log + * + * @param string value + */ + public static function table() + { + $args = func_get_args(); + return self::_log(self::TABLE, $args); + } + + /** + * internal logging call + * + * @param string $type + * @return void + */ + protected static function _log($type, array $args) + { + // nothing passed in, don't do anything + if (count($args) == 0 && $type != self::GROUP_END) { + return; + } + + $logger = self::getInstance(); + + $logger->_processed = array(); + + $logs = array(); + foreach ($args as $arg) { + $logs[] = $logger->_convert($arg); + } + + $backtrace = debug_backtrace(false); + $level = $logger->getSetting(self::BACKTRACE_LEVEL); + + $backtrace_message = 'unknown'; + if (isset($backtrace[$level]['file']) && isset($backtrace[$level]['line'])) { + $backtrace_message = $backtrace[$level]['file'] . ' : ' . $backtrace[$level]['line']; + } + + $logger->_addRow($logs, $backtrace_message, $type); + } + + /** + * converts an object to a better format for logging + * + * @param Object + * @return array + */ + protected function _convert($object) + { + // if this isn't an object then just return it + if (!is_object($object)) { + return $object; + } + + //Mark this object as processed so we don't convert it twice and it + //Also avoid recursion when objects refer to each other + $this->_processed[] = $object; + + $object_as_array = array(); + + // first add the class name + $object_as_array['___class_name'] = get_class($object); + + // loop through object vars + $object_vars = get_object_vars($object); + foreach ($object_vars as $key => $value) { + + // same instance as parent object + if ($value === $object || in_array($value, $this->_processed, true)) { + $value = 'recursion - parent object [' . get_class($value) . ']'; + } + $object_as_array[$key] = $this->_convert($value); + } + + $reflection = new ReflectionClass($object); + + // loop through the properties and add those + foreach ($reflection->getProperties() as $property) { + + // if one of these properties was already added above then ignore it + if (array_key_exists($property->getName(), $object_vars)) { + continue; + } + $type = $this->_getPropertyKey($property); + + if ($this->_php_version >= 5.3) { + $property->setAccessible(true); + } + + try { + $value = $property->getValue($object); + } catch (ReflectionException $e) { + $value = 'only PHP 5.3 can access private/protected properties'; + } + + // same instance as parent object + if ($value === $object || in_array($value, $this->_processed, true)) { + $value = 'recursion - parent object [' . get_class($value) . ']'; + } + + $object_as_array[$type] = $this->_convert($value); + } + return $object_as_array; + } + + /** + * takes a reflection property and returns a nicely formatted key of the property name + * + * @param ReflectionProperty + * @return string + */ + protected function _getPropertyKey(ReflectionProperty $property) + { + $static = $property->isStatic() ? ' static' : ''; + if ($property->isPublic()) { + return 'public' . $static . ' ' . $property->getName(); + } + + if ($property->isProtected()) { + return 'protected' . $static . ' ' . $property->getName(); + } + + if ($property->isPrivate()) { + return 'private' . $static . ' ' . $property->getName(); + } + } + + /** + * adds a value to the data array + * + * @var mixed + * @return void + */ + protected function _addRow(array $logs, $backtrace, $type) + { + // if this is logged on the same line for example in a loop, set it to null to save space + if (in_array($backtrace, $this->_backtraces)) { + $backtrace = null; + } + + // for group, groupEnd, and groupCollapsed + // take out the backtrace since it is not useful + if ($type == self::GROUP || $type == self::GROUP_END || $type == self::GROUP_COLLAPSED) { + $backtrace = null; + } + + if ($backtrace !== null) { + $this->_backtraces[] = $backtrace; + } + + $row = array($logs, $backtrace, $type); + + $this->_json['rows'][] = $row; + $this->_writeHeader($this->_json); + } + + protected function _writeHeader($data) + { + header(self::HEADER_NAME . ': ' . $this->_encode($data)); + } + + /** + * encodes the data to be sent along with the request + * + * @param array $data + * @return string + */ + protected function _encode($data) + { + return base64_encode(utf8_encode(json_encode($data))); + } + + /** + * adds a setting + * + * @param string key + * @param mixed value + * @return void + */ + public function addSetting($key, $value) + { + $this->_settings[$key] = $value; + } + + /** + * add ability to set multiple settings in one call + * + * @param array $settings + * @return void + */ + public function addSettings(array $settings) + { + foreach ($settings as $key => $value) { + $this->addSetting($key, $value); + } + } + + /** + * gets a setting + * + * @param string key + * @return mixed + */ + public function getSetting($key) + { + if (!isset($this->_settings[$key])) { + return null; + } + return $this->_settings[$key]; + } +} +} diff --git a/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php b/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php new file mode 100644 index 0000000..c572223 --- /dev/null +++ b/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php @@ -0,0 +1,47 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 系统行为扩展:模板内容输出替换 + */ +class ContentReplaceBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$content){ + $content = $this->templateContentReplace($content); + } + + /** + * 模板内容替换 + * @access protected + * @param string $content 模板内容 + * @return string + */ + protected function templateContentReplace($content) { + // 系统默认的特殊变量替换 + $replace = array( + '__ROOT__' => __ROOT__, // 当前网站地址 + '__APP__' => __APP__, // 当前应用地址 + '__MODULE__' => __MODULE__, + '__ACTION__' => __ACTION__, // 当前操作地址 + '__SELF__' => htmlentities(__SELF__), // 当前页面地址 + '__CONTROLLER__'=> __CONTROLLER__, + '__URL__' => __CONTROLLER__, + '__PUBLIC__' => __ROOT__.'/Public',// 站点公共目录 + ); + // 允许用户自定义模板的字符串替换 + if(is_array(C('TMPL_PARSE_STRING')) ) + $replace = array_merge($replace,C('TMPL_PARSE_STRING')); + $content = str_replace(array_keys($replace),array_values($replace),$content); + return $content; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/CronRunBehavior.class.php b/ThinkPHP/Library/Behavior/CronRunBehavior.class.php new file mode 100644 index 0000000..36c732e --- /dev/null +++ b/ThinkPHP/Library/Behavior/CronRunBehavior.class.php @@ -0,0 +1,66 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 自动执行任务 + */ +class CronRunBehavior { + + public function run(&$params) { + // 锁定自动执行 + $lockfile = RUNTIME_PATH.'cron.lock'; + if(is_writable($lockfile) && filemtime($lockfile) > $_SERVER['REQUEST_TIME'] - C('CRON_MAX_TIME',null,60)) { + return ; + } else { + touch($lockfile); + } + set_time_limit(1000); + ignore_user_abort(true); + + // 载入cron配置文件 + // 格式 return array( + // 'cronname'=>array('filename',intervals,nextruntime),... + // ); + if(is_file(RUNTIME_PATH.'~crons.php')) { + $crons = include RUNTIME_PATH.'~crons.php'; + }elseif(is_file(COMMON_PATH.'Conf/crons.php')){ + $crons = include COMMON_PATH.'Conf/crons.php'; + } + if(isset($crons) && is_array($crons)) { + $update = false; + $log = array(); + foreach ($crons as $key=>$cron){ + if(empty($cron[2]) || $_SERVER['REQUEST_TIME']>=$cron[2]) { + // 到达时间 执行cron文件 + G('cronStart'); + include COMMON_PATH.'Cron/'.$cron[0].'.php'; + G('cronEnd'); + $_useTime = G('cronStart','cronEnd', 6); + // 更新cron记录 + $cron[2] = $_SERVER['REQUEST_TIME']+$cron[1]; + $crons[$key] = $cron; + $log[] = "Cron:$key Runat ".date('Y-m-d H:i:s')." Use $_useTime s\n"; + $update = true; + } + } + if($update) { + // 记录Cron执行日志 + \Think\Log::write(implode('',$log)); + // 更新cron文件 + $content = ""; + file_put_contents(RUNTIME_PATH.'~crons.php',$content); + } + } + // 解除锁定 + unlink($lockfile); + return ; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.class.php b/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.class.php new file mode 100644 index 0000000..82c828a --- /dev/null +++ b/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.class.php @@ -0,0 +1,2079 @@ + +// +---------------------------------------------------------------------- +// $Id$ + +/** + * 将Trace信息输出到火狐的firebug,从而不影响ajax效果和页面的布局。 + * 使用前,你需要先在火狐浏览器上安装firebug和firePHP两个插件。 + * 定义应用的tags.php文件, + * + * array( + * 'FireShowPageTrace' + * ) + * ); + * + * 再将此文件放到应用的Behavior文件夹中即可 + * 如果trace信息没有正常输出,请查看您的日志。 + * firePHP,是通过http headers和firebug通讯的,所以要保证在输出trace信息之前不能有 + * headers输出,你可以在入口文件第一行加入代码 ob_start(); 或者配置output_buffering + * + */ +namespace Behavior; +/** + * 系统行为扩展 页面Trace显示输出 + */ +class FireShowPageTraceBehavior { + protected $tracePagTabs = array('BASE'=>'基本','FILE'=>'文件','INFO'=>'流程','ERR|NOTIC'=>'错误','SQL'=>'SQL','DEBUG'=>'调试'); + + // 行为扩展的执行入口必须是run + public function run(&$params){ + if(C('FIRE_SHOW_PAGE_TRACE',null,true)) $this->showTrace(); + } + + /** + * 显示页面Trace信息 + * @access private + */ + private function showTrace() { + // 系统默认显示信息 + $files = get_included_files(); + $info = array(); + foreach ($files as $key=>$file){ + $info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )'; + } + $trace = array(); + $base = array( + '请求信息'=> date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__, + '运行时间'=> $this->showTime(), + '内存开销'=> MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持', + '查询信息'=> N('db_query').' queries '.N('db_write').' writes ', + '文件加载'=> count(get_included_files()), + '缓存信息'=> N('cache_read').' gets '.N('cache_write').' writes ', + '配置加载'=> count(c()), + '会话信息'=> 'SESSION_ID='.session_id(), + ); + // 读取应用定义的Trace文件 + $traceFile = CONF_PATH.'trace.php'; + if(is_file($traceFile)) { + $base = array_merge($base,include $traceFile); + } + $debug = trace(); + $tabs = C('TRACE_PAGE_TABS',null,$this->tracePagTabs); + foreach ($tabs as $name=>$title){ + switch(strtoupper($name)) { + case 'BASE':// 基本信息 + $trace[$title] = $base; + break; + case 'FILE': // 文件信息 + $trace[$title] = $info; + break; + default:// 调试信息 + if(strpos($name,'|')) {// 多组信息 + $array = explode('|',$name); + $result = array(); + foreach($array as $name){ + $result += isset($debug[$name])?$debug[$name]:array(); + } + $trace[$title] = $result; + }else{ + $trace[$title] = isset($debug[$name])?$debug[$name]:''; + } + } + } + foreach ($trace as $key=>$val){ + if(!is_array($val) && empty($val)) + $val=array(); + if(is_array($val)){ + $fire=array( + array('','') + ); + foreach($val as $k=>$v){ + $fire[]=array($k,$v); + } + fb(array($key,$fire),FirePHP::TABLE); + }else{ + fb($val,$key); + } + } + unset($files,$info,$log,$base); + } + + /** + * 获取运行时间 + */ + private function showTime() { + // 显示运行时间 + G('beginTime',$GLOBALS['_beginTime']); + G('viewEndTime'); + // 显示详细运行时间 + return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; + } + +} + + +function fb() +{ + $instance = FirePHP::getInstance(true); + + $args = func_get_args(); + return call_user_func_array(array($instance,'fb'),$args); +} + + +class FB +{ + /** + * Enable and disable logging to Firebug + * + * @see FirePHP->setEnabled() + * @param boolean $Enabled TRUE to enable, FALSE to disable + * @return void + */ + public static function setEnabled($Enabled) + { + $instance = FirePHP::getInstance(true); + $instance->setEnabled($Enabled); + } + + /** + * Check if logging is enabled + * + * @see FirePHP->getEnabled() + * @return boolean TRUE if enabled + */ + public static function getEnabled() + { + $instance = FirePHP::getInstance(true); + return $instance->getEnabled(); + } + + /** + * Specify a filter to be used when encoding an object + * + * Filters are used to exclude object members. + * + * @see FirePHP->setObjectFilter() + * @param string $Class The class name of the object + * @param array $Filter An array or members to exclude + * @return void + */ + public static function setObjectFilter($Class, $Filter) + { + $instance = FirePHP::getInstance(true); + $instance->setObjectFilter($Class, $Filter); + } + + /** + * Set some options for the library + * + * @see FirePHP->setOptions() + * @param array $Options The options to be set + * @return void + */ + public static function setOptions($Options) + { + $instance = FirePHP::getInstance(true); + $instance->setOptions($Options); + } + + /** + * Get options for the library + * + * @see FirePHP->getOptions() + * @return array The options + */ + public static function getOptions() + { + $instance = FirePHP::getInstance(true); + return $instance->getOptions(); + } + + /** + * Log object to firebug + * + * @see http://www.firephp.org/Wiki/Reference/Fb + * @param mixed $Object + * @return true + * @throws Exception + */ + public static function send() + { + $instance = FirePHP::getInstance(true); + $args = func_get_args(); + return call_user_func_array(array($instance,'fb'),$args); + } + + /** + * Start a group for following messages + * + * Options: + * Collapsed: [true|false] + * Color: [#RRGGBB|ColorName] + * + * @param string $Name + * @param array $Options OPTIONAL Instructions on how to log the group + * @return true + */ + public static function group($Name, $Options=null) + { + $instance = FirePHP::getInstance(true); + return $instance->group($Name, $Options); + } + + /** + * Ends a group you have started before + * + * @return true + * @throws Exception + */ + public static function groupEnd() + { + return self::send(null, null, FirePHP::GROUP_END); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::LOG + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public static function log($Object, $Label=null) + { + return self::send($Object, $Label, FirePHP::LOG); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::INFO + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public static function info($Object, $Label=null) + { + return self::send($Object, $Label, FirePHP::INFO); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::WARN + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public static function warn($Object, $Label=null) + { + return self::send($Object, $Label, FirePHP::WARN); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::ERROR + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public static function error($Object, $Label=null) + { + return self::send($Object, $Label, FirePHP::ERROR); + } + + /** + * Dumps key and variable to firebug server panel + * + * @see FirePHP::DUMP + * @param string $Key + * @param mixed $Variable + * @return true + * @throws Exception + */ + public static function dump($Key, $Variable) + { + return self::send($Variable, $Key, FirePHP::DUMP); + } + + /** + * Log a trace in the firebug console + * + * @see FirePHP::TRACE + * @param string $Label + * @return true + * @throws Exception + */ + public static function trace($Label) + { + return self::send($Label, FirePHP::TRACE); + } + + /** + * Log a table in the firebug console + * + * @see FirePHP::TABLE + * @param string $Label + * @param string $Table + * @return true + * @throws Exception + */ + public static function table($Label, $Table) + { + return self::send($Table, $Label, FirePHP::TABLE); + } + +} + +if (!defined('E_STRICT')) { + define('E_STRICT', 2048); +} +if (!defined('E_RECOVERABLE_ERROR')) { + define('E_RECOVERABLE_ERROR', 4096); +} +if (!defined('E_DEPRECATED')) { + define('E_DEPRECATED', 8192); +} +if (!defined('E_USER_DEPRECATED')) { + define('E_USER_DEPRECATED', 16384); +} + +/** + * Sends the given data to the FirePHP Firefox Extension. + * The data can be displayed in the Firebug Console or in the + * "Server" request tab. + * + * For more information see: http://www.firephp.org/ + * + * @copyright Copyright (C) 2007-2009 Christoph Dorn + * @author Christoph Dorn + * @license http://www.opensource.org/licenses/bsd-license.php + * @package FirePHPCore + */ +class FirePHP { + + /** + * FirePHP version + * + * @var string + */ + const VERSION = '0.3'; // @pinf replace '0.3' with '%%package.version%%' + + /** + * Firebug LOG level + * + * Logs a message to firebug console. + * + * @var string + */ + const LOG = 'LOG'; + + /** + * Firebug INFO level + * + * Logs a message to firebug console and displays an info icon before the message. + * + * @var string + */ + const INFO = 'INFO'; + + /** + * Firebug WARN level + * + * Logs a message to firebug console, displays an warning icon before the message and colors the line turquoise. + * + * @var string + */ + const WARN = 'WARN'; + + /** + * Firebug ERROR level + * + * Logs a message to firebug console, displays an error icon before the message and colors the line yellow. Also increments the firebug error count. + * + * @var string + */ + const ERROR = 'ERROR'; + + /** + * Dumps a variable to firebug's server panel + * + * @var string + */ + const DUMP = 'DUMP'; + + /** + * Displays a stack trace in firebug console + * + * @var string + */ + const TRACE = 'TRACE'; + + /** + * Displays an exception in firebug console + * + * Increments the firebug error count. + * + * @var string + */ + const EXCEPTION = 'EXCEPTION'; + + /** + * Displays an table in firebug console + * + * @var string + */ + const TABLE = 'TABLE'; + + /** + * Starts a group in firebug console + * + * @var string + */ + const GROUP_START = 'GROUP_START'; + + /** + * Ends a group in firebug console + * + * @var string + */ + const GROUP_END = 'GROUP_END'; + + /** + * Singleton instance of FirePHP + * + * @var FirePHP + */ + protected static $instance = null; + + /** + * Flag whether we are logging from within the exception handler + * + * @var boolean + */ + protected $inExceptionHandler = false; + + /** + * Flag whether to throw PHP errors that have been converted to ErrorExceptions + * + * @var boolean + */ + protected $throwErrorExceptions = true; + + /** + * Flag whether to convert PHP assertion errors to Exceptions + * + * @var boolean + */ + protected $convertAssertionErrorsToExceptions = true; + + /** + * Flag whether to throw PHP assertion errors that have been converted to Exceptions + * + * @var boolean + */ + protected $throwAssertionExceptions = false; + + /** + * Wildfire protocol message index + * + * @var int + */ + protected $messageIndex = 1; + + /** + * Options for the library + * + * @var array + */ + protected $options = array('maxDepth' => 10, + 'maxObjectDepth' => 5, + 'maxArrayDepth' => 5, + 'useNativeJsonEncode' => true, + 'includeLineNumbers' => true); + + /** + * Filters used to exclude object members when encoding + * + * @var array + */ + protected $objectFilters = array( + 'firephp' => array('objectStack', 'instance', 'json_objectStack'), + 'firephp_test_class' => array('objectStack', 'instance', 'json_objectStack') + ); + + /** + * A stack of objects used to detect recursion during object encoding + * + * @var object + */ + protected $objectStack = array(); + + /** + * Flag to enable/disable logging + * + * @var boolean + */ + protected $enabled = true; + + /** + * The insight console to log to if applicable + * + * @var object + */ + protected $logToInsightConsole = null; + + /** + * When the object gets serialized only include specific object members. + * + * @return array + */ + public function __sleep() + { + return array('options','objectFilters','enabled'); + } + + /** + * Gets singleton instance of FirePHP + * + * @param boolean $AutoCreate + * @return FirePHP + */ + public static function getInstance($AutoCreate = false) + { + if ($AutoCreate===true && !self::$instance) { + self::init(); + } + return self::$instance; + } + + /** + * Creates FirePHP object and stores it for singleton access + * + * @return FirePHP + */ + public static function init() + { + return self::setInstance(new self()); + } + + /** + * Set the instance of the FirePHP singleton + * + * @param FirePHP $instance The FirePHP object instance + * @return FirePHP + */ + public static function setInstance($instance) + { + return self::$instance = $instance; + } + + /** + * Set an Insight console to direct all logging calls to + * + * @param object $console The console object to log to + * @return void + */ + public function setLogToInsightConsole($console) + { + if(is_string($console)) { + if(get_class($this)!='FirePHP_Insight' && !is_subclass_of($this, 'FirePHP_Insight')) { + throw new Exception('FirePHP instance not an instance or subclass of FirePHP_Insight!'); + } + $this->logToInsightConsole = $this->to('request')->console($console); + } else { + $this->logToInsightConsole = $console; + } + } + + /** + * Enable and disable logging to Firebug + * + * @param boolean $Enabled TRUE to enable, FALSE to disable + * @return void + */ + public function setEnabled($Enabled) + { + $this->enabled = $Enabled; + } + + /** + * Check if logging is enabled + * + * @return boolean TRUE if enabled + */ + public function getEnabled() + { + return $this->enabled; + } + + /** + * Specify a filter to be used when encoding an object + * + * Filters are used to exclude object members. + * + * @param string $Class The class name of the object + * @param array $Filter An array of members to exclude + * @return void + */ + public function setObjectFilter($Class, $Filter) + { + $this->objectFilters[strtolower($Class)] = $Filter; + } + + /** + * Set some options for the library + * + * Options: + * - maxDepth: The maximum depth to traverse (default: 10) + * - maxObjectDepth: The maximum depth to traverse objects (default: 5) + * - maxArrayDepth: The maximum depth to traverse arrays (default: 5) + * - useNativeJsonEncode: If true will use json_encode() (default: true) + * - includeLineNumbers: If true will include line numbers and filenames (default: true) + * + * @param array $Options The options to be set + * @return void + */ + public function setOptions($Options) + { + $this->options = array_merge($this->options,$Options); + } + + /** + * Get options from the library + * + * @return array The currently set options + */ + public function getOptions() + { + return $this->options; + } + + /** + * Set an option for the library + * + * @param string $Name + * @param mixed $Value + * @throws Exception + * @return void + */ + public function setOption($Name, $Value) + { + if (!isset($this->options[$Name])) { + throw $this->newException('Unknown option: ' . $Name); + } + $this->options[$Name] = $Value; + } + + /** + * Get an option from the library + * + * @param string $Name + * @throws Exception + * @return mixed + */ + public function getOption($Name) + { + if (!isset($this->options[$Name])) { + throw $this->newException('Unknown option: ' . $Name); + } + return $this->options[$Name]; + } + + /** + * Register FirePHP as your error handler + * + * Will throw exceptions for each php error. + * + * @return mixed Returns a string containing the previously defined error handler (if any) + */ + public function registerErrorHandler($throwErrorExceptions = false) + { + //NOTE: The following errors will not be caught by this error handler: + // E_ERROR, E_PARSE, E_CORE_ERROR, + // E_CORE_WARNING, E_COMPILE_ERROR, + // E_COMPILE_WARNING, E_STRICT + + $this->throwErrorExceptions = $throwErrorExceptions; + + return set_error_handler(array($this,'errorHandler')); + } + + /** + * FirePHP's error handler + * + * Throws exception for each php error that will occur. + * + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @param array $errcontext + */ + public function errorHandler($errno, $errstr, $errfile, $errline, $errcontext) + { + // Don't throw exception if error reporting is switched off + if (error_reporting() == 0) { + return; + } + // Only throw exceptions for errors we are asking for + if (error_reporting() & $errno) { + + $exception = new ErrorException($errstr, 0, $errno, $errfile, $errline); + if ($this->throwErrorExceptions) { + throw $exception; + } else { + $this->fb($exception); + } + } + } + + /** + * Register FirePHP as your exception handler + * + * @return mixed Returns the name of the previously defined exception handler, + * or NULL on error. + * If no previous handler was defined, NULL is also returned. + */ + public function registerExceptionHandler() + { + return set_exception_handler(array($this,'exceptionHandler')); + } + + /** + * FirePHP's exception handler + * + * Logs all exceptions to your firebug console and then stops the script. + * + * @param Exception $Exception + * @throws Exception + */ + function exceptionHandler($Exception) + { + + $this->inExceptionHandler = true; + + header('HTTP/1.1 500 Internal Server Error'); + + try { + $this->fb($Exception); + } catch (Exception $e) { + echo 'We had an exception: ' . $e; + } + $this->inExceptionHandler = false; + } + + /** + * Register FirePHP driver as your assert callback + * + * @param boolean $convertAssertionErrorsToExceptions + * @param boolean $throwAssertionExceptions + * @return mixed Returns the original setting or FALSE on errors + */ + public function registerAssertionHandler($convertAssertionErrorsToExceptions = true, $throwAssertionExceptions = false) + { + $this->convertAssertionErrorsToExceptions = $convertAssertionErrorsToExceptions; + $this->throwAssertionExceptions = $throwAssertionExceptions; + + if ($throwAssertionExceptions && !$convertAssertionErrorsToExceptions) { + throw $this->newException('Cannot throw assertion exceptions as assertion errors are not being converted to exceptions!'); + } + + return assert_options(ASSERT_CALLBACK, array($this, 'assertionHandler')); + } + + /** + * FirePHP's assertion handler + * + * Logs all assertions to your firebug console and then stops the script. + * + * @param string $file File source of assertion + * @param int $line Line source of assertion + * @param mixed $code Assertion code + */ + public function assertionHandler($file, $line, $code) + { + if ($this->convertAssertionErrorsToExceptions) { + + $exception = new ErrorException('Assertion Failed - Code[ '.$code.' ]', 0, null, $file, $line); + + if ($this->throwAssertionExceptions) { + throw $exception; + } else { + $this->fb($exception); + } + + } else { + $this->fb($code, 'Assertion Failed', FirePHP::ERROR, array('File'=>$file,'Line'=>$line)); + } + } + + /** + * Start a group for following messages. + * + * Options: + * Collapsed: [true|false] + * Color: [#RRGGBB|ColorName] + * + * @param string $Name + * @param array $Options OPTIONAL Instructions on how to log the group + * @return true + * @throws Exception + */ + public function group($Name, $Options = null) + { + + if (!$Name) { + throw $this->newException('You must specify a label for the group!'); + } + + if ($Options) { + if (!is_array($Options)) { + throw $this->newException('Options must be defined as an array!'); + } + if (array_key_exists('Collapsed', $Options)) { + $Options['Collapsed'] = ($Options['Collapsed'])?'true':'false'; + } + } + + return $this->fb(null, $Name, FirePHP::GROUP_START, $Options); + } + + /** + * Ends a group you have started before + * + * @return true + * @throws Exception + */ + public function groupEnd() + { + return $this->fb(null, null, FirePHP::GROUP_END); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::LOG + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public function log($Object, $Label = null, $Options = array()) + { + return $this->fb($Object, $Label, FirePHP::LOG, $Options); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::INFO + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public function info($Object, $Label = null, $Options = array()) + { + return $this->fb($Object, $Label, FirePHP::INFO, $Options); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::WARN + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public function warn($Object, $Label = null, $Options = array()) + { + return $this->fb($Object, $Label, FirePHP::WARN, $Options); + } + + /** + * Log object with label to firebug console + * + * @see FirePHP::ERROR + * @param mixes $Object + * @param string $Label + * @return true + * @throws Exception + */ + public function error($Object, $Label = null, $Options = array()) + { + return $this->fb($Object, $Label, FirePHP::ERROR, $Options); + } + + /** + * Dumps key and variable to firebug server panel + * + * @see FirePHP::DUMP + * @param string $Key + * @param mixed $Variable + * @return true + * @throws Exception + */ + public function dump($Key, $Variable, $Options = array()) + { + if (!is_string($Key)) { + throw $this->newException('Key passed to dump() is not a string'); + } + if (strlen($Key)>100) { + throw $this->newException('Key passed to dump() is longer than 100 characters'); + } + if (!preg_match_all('/^[a-zA-Z0-9-_\.:]*$/', $Key, $m)) { + throw $this->newException('Key passed to dump() contains invalid characters [a-zA-Z0-9-_\.:]'); + } + return $this->fb($Variable, $Key, FirePHP::DUMP, $Options); + } + + /** + * Log a trace in the firebug console + * + * @see FirePHP::TRACE + * @param string $Label + * @return true + * @throws Exception + */ + public function trace($Label) + { + return $this->fb($Label, FirePHP::TRACE); + } + + /** + * Log a table in the firebug console + * + * @see FirePHP::TABLE + * @param string $Label + * @param string $Table + * @return true + * @throws Exception + */ + public function table($Label, $Table, $Options = array()) + { + return $this->fb($Table, $Label, FirePHP::TABLE, $Options); + } + + /** + * Insight API wrapper + * + * @see Insight_Helper::to() + */ + public static function to() + { + $instance = self::getInstance(); + if (!method_exists($instance, "_to")) { + throw new Exception("FirePHP::to() implementation not loaded"); + } + $args = func_get_args(); + return call_user_func_array(array($instance, '_to'), $args); + } + + /** + * Insight API wrapper + * + * @see Insight_Helper::plugin() + */ + public static function plugin() + { + $instance = self::getInstance(); + if (!method_exists($instance, "_plugin")) { + throw new Exception("FirePHP::plugin() implementation not loaded"); + } + $args = func_get_args(); + return call_user_func_array(array($instance, '_plugin'), $args); + } + + /** + * Check if FirePHP is installed on client + * + * @return boolean + */ + public function detectClientExtension() + { + // Check if FirePHP is installed on client via User-Agent header + if (@preg_match_all('/\sFirePHP\/([\.\d]*)\s?/si',$this->getUserAgent(),$m) && + version_compare($m[1][0],'0.0.6','>=')) { + return true; + } else + // Check if FirePHP is installed on client via X-FirePHP-Version header + if (@preg_match_all('/^([\.\d]*)$/si',$this->getRequestHeader("X-FirePHP-Version"),$m) && + version_compare($m[1][0],'0.0.6','>=')) { + return true; + } + return false; + } + + /** + * Log varible to Firebug + * + * @see http://www.firephp.org/Wiki/Reference/Fb + * @param mixed $Object The variable to be logged + * @return true Return TRUE if message was added to headers, FALSE otherwise + * @throws Exception + */ + public function fb($Object) + { + if($this instanceof FirePHP_Insight && method_exists($this, '_logUpgradeClientMessage')) { + if(!FirePHP_Insight::$upgradeClientMessageLogged) { // avoid infinite recursion as _logUpgradeClientMessage() logs a message + $this->_logUpgradeClientMessage(); + } + } + + static $insightGroupStack = array(); + + if (!$this->getEnabled()) { + return false; + } + + if ($this->headersSent($filename, $linenum)) { + // If we are logging from within the exception handler we cannot throw another exception + if ($this->inExceptionHandler) { + // Simply echo the error out to the page + echo '
FirePHP ERROR: Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.
'; + } else { + throw $this->newException('Headers already sent in '.$filename.' on line '.$linenum.'. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.'); + } + } + + $Type = null; + $Label = null; + $Options = array(); + + if (func_num_args()==1) { + } else + if (func_num_args()==2) { + switch(func_get_arg(1)) { + case self::LOG: + case self::INFO: + case self::WARN: + case self::ERROR: + case self::DUMP: + case self::TRACE: + case self::EXCEPTION: + case self::TABLE: + case self::GROUP_START: + case self::GROUP_END: + $Type = func_get_arg(1); + break; + default: + $Label = func_get_arg(1); + break; + } + } else + if (func_num_args()==3) { + $Type = func_get_arg(2); + $Label = func_get_arg(1); + } else + if (func_num_args()==4) { + $Type = func_get_arg(2); + $Label = func_get_arg(1); + $Options = func_get_arg(3); + } else { + throw $this->newException('Wrong number of arguments to fb() function!'); + } + + if($this->logToInsightConsole!==null && (get_class($this)=='FirePHP_Insight' || is_subclass_of($this, 'FirePHP_Insight'))) { + $msg = $this->logToInsightConsole; + if ($Object instanceof Exception) { + $Type = self::EXCEPTION; + } + if($Label && $Type!=self::TABLE && $Type!=self::GROUP_START) { + $msg = $msg->label($Label); + } + switch($Type) { + case self::DUMP: + case self::LOG: + return $msg->log($Object); + case self::INFO: + return $msg->info($Object); + case self::WARN: + return $msg->warn($Object); + case self::ERROR: + return $msg->error($Object); + case self::TRACE: + return $msg->trace($Object); + case self::EXCEPTION: + return $this->plugin('engine')->handleException($Object, $msg); + case self::TABLE: + if (isset($Object[0]) && !is_string($Object[0]) && $Label) { + $Object = array($Label, $Object); + } + return $msg->table($Object[0], array_slice($Object[1],1), $Object[1][0]); + case self::GROUP_START: + $insightGroupStack[] = $msg->group(md5($Label))->open(); + return $msg->log($Label); + case self::GROUP_END: + if(count($insightGroupStack)==0) { + throw new Error('Too many groupEnd() as opposed to group() calls!'); + } + $group = array_pop($insightGroupStack); + return $group->close(); + default: + return $msg->log($Object); + } + } + + if (!$this->detectClientExtension()) { + return false; + } + + $meta = array(); + $skipFinalObjectEncode = false; + + if ($Object instanceof Exception) { + + $meta['file'] = $this->_escapeTraceFile($Object->getFile()); + $meta['line'] = $Object->getLine(); + + $trace = $Object->getTrace(); + if ($Object instanceof ErrorException + && isset($trace[0]['function']) + && $trace[0]['function']=='errorHandler' + && isset($trace[0]['class']) + && $trace[0]['class']=='FirePHP') { + + $severity = false; + switch($Object->getSeverity()) { + case E_WARNING: $severity = 'E_WARNING'; break; + case E_NOTICE: $severity = 'E_NOTICE'; break; + case E_USER_ERROR: $severity = 'E_USER_ERROR'; break; + case E_USER_WARNING: $severity = 'E_USER_WARNING'; break; + case E_USER_NOTICE: $severity = 'E_USER_NOTICE'; break; + case E_STRICT: $severity = 'E_STRICT'; break; + case E_RECOVERABLE_ERROR: $severity = 'E_RECOVERABLE_ERROR'; break; + case E_DEPRECATED: $severity = 'E_DEPRECATED'; break; + case E_USER_DEPRECATED: $severity = 'E_USER_DEPRECATED'; break; + } + + $Object = array('Class'=>get_class($Object), + 'Message'=>$severity.': '.$Object->getMessage(), + 'File'=>$this->_escapeTraceFile($Object->getFile()), + 'Line'=>$Object->getLine(), + 'Type'=>'trigger', + 'Trace'=>$this->_escapeTrace(array_splice($trace,2))); + $skipFinalObjectEncode = true; + } else { + $Object = array('Class'=>get_class($Object), + 'Message'=>$Object->getMessage(), + 'File'=>$this->_escapeTraceFile($Object->getFile()), + 'Line'=>$Object->getLine(), + 'Type'=>'throw', + 'Trace'=>$this->_escapeTrace($trace)); + $skipFinalObjectEncode = true; + } + $Type = self::EXCEPTION; + + } else + if ($Type==self::TRACE) { + + $trace = debug_backtrace(); + if (!$trace) return false; + for( $i=0 ; $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' + || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { + /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ + } else + if (isset($trace[$i]['class']) + && isset($trace[$i+1]['file']) + && $trace[$i]['class']=='FirePHP' + && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { + /* Skip fb() */ + } else + if ($trace[$i]['function']=='fb' + || $trace[$i]['function']=='trace' + || $trace[$i]['function']=='send') { + + $Object = array('Class'=>isset($trace[$i]['class'])?$trace[$i]['class']:'', + 'Type'=>isset($trace[$i]['type'])?$trace[$i]['type']:'', + 'Function'=>isset($trace[$i]['function'])?$trace[$i]['function']:'', + 'Message'=>$trace[$i]['args'][0], + 'File'=>isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):'', + 'Line'=>isset($trace[$i]['line'])?$trace[$i]['line']:'', + 'Args'=>isset($trace[$i]['args'])?$this->encodeObject($trace[$i]['args']):'', + 'Trace'=>$this->_escapeTrace(array_splice($trace,$i+1))); + + $skipFinalObjectEncode = true; + $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; + $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; + break; + } + } + + } else + if ($Type==self::TABLE) { + + if (isset($Object[0]) && is_string($Object[0])) { + $Object[1] = $this->encodeTable($Object[1]); + } else { + $Object = $this->encodeTable($Object); + } + + $skipFinalObjectEncode = true; + + } else + if ($Type==self::GROUP_START) { + + if (!$Label) { + throw $this->newException('You must specify a label for the group!'); + } + + } else { + if ($Type===null) { + $Type = self::LOG; + } + } + + if ($this->options['includeLineNumbers']) { + if (!isset($meta['file']) || !isset($meta['line'])) { + + $trace = debug_backtrace(); + for( $i=0 ; $trace && $i_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php' + || substr($this->_standardizePath($trace[$i]['file']),-29,29)=='FirePHPCore/FirePHP.class.php')) { + /* Skip - FB::trace(), FB::send(), $firephp->trace(), $firephp->fb() */ + } else + if (isset($trace[$i]['class']) + && isset($trace[$i+1]['file']) + && $trace[$i]['class']=='FirePHP' + && substr($this->_standardizePath($trace[$i+1]['file']),-18,18)=='FirePHPCore/fb.php') { + /* Skip fb() */ + } else + if (isset($trace[$i]['file']) + && substr($this->_standardizePath($trace[$i]['file']),-18,18)=='FirePHPCore/fb.php') { + /* Skip FB::fb() */ + } else { + $meta['file'] = isset($trace[$i]['file'])?$this->_escapeTraceFile($trace[$i]['file']):''; + $meta['line'] = isset($trace[$i]['line'])?$trace[$i]['line']:''; + break; + } + } + } + } else { + unset($meta['file']); + unset($meta['line']); + } + + $this->setHeader('X-Wf-Protocol-1','http://meta.wildfirehq.org/Protocol/JsonStream/0.2'); + $this->setHeader('X-Wf-1-Plugin-1','http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/'.self::VERSION); + + $structure_index = 1; + if ($Type==self::DUMP) { + $structure_index = 2; + $this->setHeader('X-Wf-1-Structure-2','http://meta.firephp.org/Wildfire/Structure/FirePHP/Dump/0.1'); + } else { + $this->setHeader('X-Wf-1-Structure-1','http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1'); + } + + if ($Type==self::DUMP) { + $msg = '{"'.$Label.'":'.$this->jsonEncode($Object, $skipFinalObjectEncode).'}'; + } else { + $msg_meta = $Options; + $msg_meta['Type'] = $Type; + if ($Label!==null) { + $msg_meta['Label'] = $Label; + } + if (isset($meta['file']) && !isset($msg_meta['File'])) { + $msg_meta['File'] = $meta['file']; + } + if (isset($meta['line']) && !isset($msg_meta['Line'])) { + $msg_meta['Line'] = $meta['line']; + } + $msg = '['.$this->jsonEncode($msg_meta).','.$this->jsonEncode($Object, $skipFinalObjectEncode).']'; + } + + $parts = explode("\n",chunk_split($msg, 5000, "\n")); + + for( $i=0 ; $i2) { + // Message needs to be split into multiple parts + $this->setHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, + (($i==0)?strlen($msg):'') + . '|' . $part . '|' + . (($isetHeader('X-Wf-1-'.$structure_index.'-'.'1-'.$this->messageIndex, + strlen($part) . '|' . $part . '|'); + } + + $this->messageIndex++; + + if ($this->messageIndex > 99999) { + throw $this->newException('Maximum number (99,999) of messages reached!'); + } + } + } + + $this->setHeader('X-Wf-1-Index',$this->messageIndex-1); + + return true; + } + + /** + * Standardizes path for windows systems. + * + * @param string $Path + * @return string + */ + protected function _standardizePath($Path) + { + return preg_replace('/\\\\+/','/',$Path); + } + + /** + * Escape trace path for windows systems + * + * @param array $Trace + * @return array + */ + protected function _escapeTrace($Trace) + { + if (!$Trace) return $Trace; + for( $i=0 ; $i_escapeTraceFile($Trace[$i]['file']); + } + if (isset($Trace[$i]['args'])) { + $Trace[$i]['args'] = $this->encodeObject($Trace[$i]['args']); + } + } + return $Trace; + } + + /** + * Escape file information of trace for windows systems + * + * @param string $File + * @return string + */ + protected function _escapeTraceFile($File) + { + /* Check if we have a windows filepath */ + if (strpos($File,'\\')) { + /* First strip down to single \ */ + + $file = preg_replace('/\\\\+/','\\',$File); + + return $file; + } + return $File; + } + + /** + * Check if headers have already been sent + * + * @param string $Filename + * @param integer $Linenum + */ + protected function headersSent(&$Filename, &$Linenum) + { + return headers_sent($Filename, $Linenum); + } + + /** + * Send header + * + * @param string $Name + * @param string $Value + */ + protected function setHeader($Name, $Value) + { + return header($Name.': '.$Value); + } + + /** + * Get user agent + * + * @return string|false + */ + protected function getUserAgent() + { + if (!isset($_SERVER['HTTP_USER_AGENT'])) return false; + return $_SERVER['HTTP_USER_AGENT']; + } + + /** + * Get all request headers + * + * @return array + */ + public static function getAllRequestHeaders() { + static $_cached_headers = false; + if($_cached_headers!==false) { + return $_cached_headers; + } + $headers = array(); + if(function_exists('getallheaders')) { + foreach( getallheaders() as $name => $value ) { + $headers[strtolower($name)] = $value; + } + } else { + foreach($_SERVER as $name => $value) { + if(substr($name, 0, 5) == 'HTTP_') { + $headers[strtolower(str_replace(' ', '-', str_replace('_', ' ', substr($name, 5))))] = $value; + } + } + } + return $_cached_headers = $headers; + } + + /** + * Get a request header + * + * @return string|false + */ + protected function getRequestHeader($Name) + { + $headers = self::getAllRequestHeaders(); + if (isset($headers[strtolower($Name)])) { + return $headers[strtolower($Name)]; + } + return false; + } + + /** + * Returns a new exception + * + * @param string $Message + * @return Exception + */ + protected function newException($Message) + { + return new Exception($Message); + } + + /** + * Encode an object into a JSON string + * + * Uses PHP's jeson_encode() if available + * + * @param object $Object The object to be encoded + * @return string The JSON string + */ + public function jsonEncode($Object, $skipObjectEncode = false) + { + if (!$skipObjectEncode) { + $Object = $this->encodeObject($Object); + } + + if (function_exists('json_encode') + && $this->options['useNativeJsonEncode']!=false) { + + return json_encode($Object); + } else { + return $this->json_encode($Object); + } + } + + /** + * Encodes a table by encoding each row and column with encodeObject() + * + * @param array $Table The table to be encoded + * @return array + */ + protected function encodeTable($Table) + { + + if (!$Table) return $Table; + + $new_table = array(); + foreach($Table as $row) { + + if (is_array($row)) { + $new_row = array(); + + foreach($row as $item) { + $new_row[] = $this->encodeObject($item); + } + + $new_table[] = $new_row; + } + } + + return $new_table; + } + + /** + * Encodes an object including members with + * protected and private visibility + * + * @param Object $Object The object to be encoded + * @param int $Depth The current traversal depth + * @return array All members of the object + */ + protected function encodeObject($Object, $ObjectDepth = 1, $ArrayDepth = 1, $MaxDepth = 1) + { + if ($MaxDepth > $this->options['maxDepth']) { + return '** Max Depth ('.$this->options['maxDepth'].') **'; + } + + $return = array(); + + if (is_resource($Object)) { + + return '** '.(string)$Object.' **'; + + } else + if (is_object($Object)) { + + if ($ObjectDepth > $this->options['maxObjectDepth']) { + return '** Max Object Depth ('.$this->options['maxObjectDepth'].') **'; + } + + foreach ($this->objectStack as $refVal) { + if ($refVal === $Object) { + return '** Recursion ('.get_class($Object).') **'; + } + } + array_push($this->objectStack, $Object); + + $return['__className'] = $class = get_class($Object); + $class_lower = strtolower($class); + + $reflectionClass = new ReflectionClass($class); + $properties = array(); + foreach( $reflectionClass->getProperties() as $property) { + $properties[$property->getName()] = $property; + } + + $members = (array)$Object; + + foreach( $properties as $plain_name => $property ) { + + $name = $raw_name = $plain_name; + if ($property->isStatic()) { + $name = 'static:'.$name; + } + if ($property->isPublic()) { + $name = 'public:'.$name; + } else + if ($property->isPrivate()) { + $name = 'private:'.$name; + $raw_name = "\0".$class."\0".$raw_name; + } else + if ($property->isProtected()) { + $name = 'protected:'.$name; + $raw_name = "\0".'*'."\0".$raw_name; + } + + if (!(isset($this->objectFilters[$class_lower]) + && is_array($this->objectFilters[$class_lower]) + && in_array($plain_name,$this->objectFilters[$class_lower]))) { + + if (array_key_exists($raw_name,$members) + && !$property->isStatic()) { + + $return[$name] = $this->encodeObject($members[$raw_name], $ObjectDepth + 1, 1, $MaxDepth + 1); + + } else { + if (method_exists($property,'setAccessible')) { + $property->setAccessible(true); + $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1); + } else + if ($property->isPublic()) { + $return[$name] = $this->encodeObject($property->getValue($Object), $ObjectDepth + 1, 1, $MaxDepth + 1); + } else { + $return[$name] = '** Need PHP 5.3 to get value **'; + } + } + } else { + $return[$name] = '** Excluded by Filter **'; + } + } + + // Include all members that are not defined in the class + // but exist in the object + foreach( $members as $raw_name => $value ) { + + $name = $raw_name; + + if ($name{0} == "\0") { + $parts = explode("\0", $name); + $name = $parts[2]; + } + + $plain_name = $name; + + if (!isset($properties[$name])) { + $name = 'undeclared:'.$name; + + if (!(isset($this->objectFilters[$class_lower]) + && is_array($this->objectFilters[$class_lower]) + && in_array($plain_name,$this->objectFilters[$class_lower]))) { + + $return[$name] = $this->encodeObject($value, $ObjectDepth + 1, 1, $MaxDepth + 1); + } else { + $return[$name] = '** Excluded by Filter **'; + } + } + } + + array_pop($this->objectStack); + + } elseif (is_array($Object)) { + + if ($ArrayDepth > $this->options['maxArrayDepth']) { + return '** Max Array Depth ('.$this->options['maxArrayDepth'].') **'; + } + + foreach ($Object as $key => $val) { + + // Encoding the $GLOBALS PHP array causes an infinite loop + // if the recursion is not reset here as it contains + // a reference to itself. This is the only way I have come up + // with to stop infinite recursion in this case. + if ($key=='GLOBALS' + && is_array($val) + && array_key_exists('GLOBALS',$val)) { + $val['GLOBALS'] = '** Recursion (GLOBALS) **'; + } + + $return[$key] = $this->encodeObject($val, 1, $ArrayDepth + 1, $MaxDepth + 1); + } + } else { + if (self::is_utf8($Object)) { + return $Object; + } else { + return utf8_encode($Object); + } + } + return $return; + } + + /** + * Returns true if $string is valid UTF-8 and false otherwise. + * + * @param mixed $str String to be tested + * @return boolean + */ + protected static function is_utf8($str) + { + if(function_exists('mb_detect_encoding')) { + return (mb_detect_encoding($str) == 'UTF-8'); + } + $c=0; $b=0; + $bits=0; + $len=strlen($str); + for($i=0; $i<$len; $i++){ + $c=ord($str[$i]); + if ($c > 128){ + if (($c >= 254)) return false; + elseif ($c >= 252) $bits=6; + elseif ($c >= 248) $bits=5; + elseif ($c >= 240) $bits=4; + elseif ($c >= 224) $bits=3; + elseif ($c >= 192) $bits=2; + else return false; + if (($i+$bits) > $len) return false; + while($bits > 1){ + $i++; + $b=ord($str[$i]); + if ($b < 128 || $b > 191) return false; + $bits--; + } + } + } + return true; + } + + /** + * Converts to and from JSON format. + * + * JSON (JavaScript Object Notation) is a lightweight data-interchange + * format. It is easy for humans to read and write. It is easy for machines + * to parse and generate. It is based on a subset of the JavaScript + * Programming Language, Standard ECMA-262 3rd Edition - December 1999. + * This feature can also be found in Python. JSON is a text format that is + * completely language independent but uses conventions that are familiar + * to programmers of the C-family of languages, including C, C++, C#, Java, + * JavaScript, Perl, TCL, and many others. These properties make JSON an + * ideal data-interchange language. + * + * This package provides a simple encoder and decoder for JSON notation. It + * is intended for use with client-side Javascript applications that make + * use of HTTPRequest to perform server communication functions - data can + * be encoded into JSON notation for use in a client-side javascript, or + * decoded from incoming Javascript requests. JSON format is native to + * Javascript, and can be directly eval()'ed with no further parsing + * overhead + * + * All strings should be in ASCII or UTF-8 format! + * + * LICENSE: Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: Redistributions of source code must retain the + * above copyright notice, this list of conditions and the following + * disclaimer. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * @category + * @package Services_JSON + * @author Michal Migurski + * @author Matt Knapp + * @author Brett Stimmerman + * @author Christoph Dorn + * @copyright 2005 Michal Migurski + * @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $ + * @license http://www.opensource.org/licenses/bsd-license.php + * @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198 + */ + + + /** + * Keep a list of objects as we descend into the array so we can detect recursion. + */ + private $json_objectStack = array(); + + + /** + * convert a string from one UTF-8 char to one UTF-16 char + * + * Normally should be handled by mb_convert_encoding, but + * provides a slower PHP-only method for installations + * that lack the multibye string extension. + * + * @param string $utf8 UTF-8 character + * @return string UTF-16 character + * @access private + */ + private function json_utf82utf16($utf8) + { + // oh please oh please oh please oh please oh please + if (function_exists('mb_convert_encoding')) { + return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8'); + } + + switch(strlen($utf8)) { + case 1: + // this case should never be reached, because we are in ASCII range + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return $utf8; + + case 2: + // return a UTF-16 character from a 2-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr(0x07 & (ord($utf8{0}) >> 2)) + . chr((0xC0 & (ord($utf8{0}) << 6)) + | (0x3F & ord($utf8{1}))); + + case 3: + // return a UTF-16 character from a 3-byte UTF-8 char + // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + return chr((0xF0 & (ord($utf8{0}) << 4)) + | (0x0F & (ord($utf8{1}) >> 2))) + . chr((0xC0 & (ord($utf8{1}) << 6)) + | (0x7F & ord($utf8{2}))); + } + + // ignoring UTF-32 for now, sorry + return ''; + } + + /** + * encodes an arbitrary variable into JSON format + * + * @param mixed $var any number, boolean, string, array, or object to be encoded. + * see argument 1 to Services_JSON() above for array-parsing behavior. + * if var is a strng, note that encode() always expects it + * to be in ASCII or UTF-8 format! + * + * @return mixed JSON string representation of input var or an error if a problem occurs + * @access public + */ + private function json_encode($var) + { + + if (is_object($var)) { + if (in_array($var,$this->json_objectStack)) { + return '"** Recursion **"'; + } + } + + switch (gettype($var)) { + case 'boolean': + return $var ? 'true' : 'false'; + + case 'NULL': + return 'null'; + + case 'integer': + return (int) $var; + + case 'double': + case 'float': + return (float) $var; + + case 'string': + // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT + $ascii = ''; + $strlen_var = strlen($var); + + /* + * Iterate over every character in the string, + * escaping with a slash or encoding to UTF-8 where necessary + */ + for ($c = 0; $c < $strlen_var; ++$c) { + + $ord_var_c = ord($var{$c}); + + switch (true) { + case $ord_var_c == 0x08: + $ascii .= '\b'; + break; + case $ord_var_c == 0x09: + $ascii .= '\t'; + break; + case $ord_var_c == 0x0A: + $ascii .= '\n'; + break; + case $ord_var_c == 0x0C: + $ascii .= '\f'; + break; + case $ord_var_c == 0x0D: + $ascii .= '\r'; + break; + + case $ord_var_c == 0x22: + case $ord_var_c == 0x2F: + case $ord_var_c == 0x5C: + // double quote, slash, slosh + $ascii .= '\\'.$var{$c}; + break; + + case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): + // characters U-00000000 - U-0000007F (same as ASCII) + $ascii .= $var{$c}; + break; + + case (($ord_var_c & 0xE0) == 0xC0): + // characters U-00000080 - U-000007FF, mask 110XXXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, ord($var{$c + 1})); + $c += 1; + $utf16 = $this->json_utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF0) == 0xE0): + // characters U-00000800 - U-0000FFFF, mask 1110XXXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2})); + $c += 2; + $utf16 = $this->json_utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xF8) == 0xF0): + // characters U-00010000 - U-001FFFFF, mask 11110XXX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3})); + $c += 3; + $utf16 = $this->json_utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFC) == 0xF8): + // characters U-00200000 - U-03FFFFFF, mask 111110XX + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4})); + $c += 4; + $utf16 = $this->json_utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + + case (($ord_var_c & 0xFE) == 0xFC): + // characters U-04000000 - U-7FFFFFFF, mask 1111110X + // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 + $char = pack('C*', $ord_var_c, + ord($var{$c + 1}), + ord($var{$c + 2}), + ord($var{$c + 3}), + ord($var{$c + 4}), + ord($var{$c + 5})); + $c += 5; + $utf16 = $this->json_utf82utf16($char); + $ascii .= sprintf('\u%04s', bin2hex($utf16)); + break; + } + } + + return '"'.$ascii.'"'; + + case 'array': + /* + * As per JSON spec if any array key is not an integer + * we must treat the the whole array as an object. We + * also try to catch a sparsely populated associative + * array with numeric keys here because some JS engines + * will create an array with empty indexes up to + * max_index which can cause memory issues and because + * the keys, which may be relevant, will be remapped + * otherwise. + * + * As per the ECMA and JSON specification an object may + * have any string as a property. Unfortunately due to + * a hole in the ECMA specification if the key is a + * ECMA reserved word or starts with a digit the + * parameter is only accessible using ECMAScript's + * bracket notation. + */ + + // treat as a JSON object + if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) { + + $this->json_objectStack[] = $var; + + $properties = array_map(array($this, 'json_name_value'), + array_keys($var), + array_values($var)); + + array_pop($this->json_objectStack); + + foreach($properties as $property) { + if ($property instanceof Exception) { + return $property; + } + } + + return '{' . join(',', $properties) . '}'; + } + + $this->json_objectStack[] = $var; + + // treat it like a regular array + $elements = array_map(array($this, 'json_encode'), $var); + + array_pop($this->json_objectStack); + + foreach($elements as $element) { + if ($element instanceof Exception) { + return $element; + } + } + + return '[' . join(',', $elements) . ']'; + + case 'object': + $vars = self::encodeObject($var); + + $this->json_objectStack[] = $var; + + $properties = array_map(array($this, 'json_name_value'), + array_keys($vars), + array_values($vars)); + + array_pop($this->json_objectStack); + + foreach($properties as $property) { + if ($property instanceof Exception) { + return $property; + } + } + + return '{' . join(',', $properties) . '}'; + + default: + return null; + } + } + + /** + * array-walking function for use in generating JSON-formatted name-value pairs + * + * @param string $name name of key to use + * @param mixed $value reference to an array element to be encoded + * + * @return string JSON-formatted name-value pair, like '"name":value' + * @access private + */ + private function json_name_value($name, $value) + { + // Encoding the $GLOBALS PHP array causes an infinite loop + // if the recursion is not reset here as it contains + // a reference to itself. This is the only way I have come up + // with to stop infinite recursion in this case. + if ($name=='GLOBALS' + && is_array($value) + && array_key_exists('GLOBALS',$value)) { + $value['GLOBALS'] = '** Recursion **'; + } + + $encoded_value = $this->json_encode($value); + + if ($encoded_value instanceof Exception) { + return $encoded_value; + } + + return $this->json_encode(strval($name)) . ':' . $encoded_value; + } + + /** + * @deprecated + */ + public function setProcessorUrl($URL) + { + trigger_error("The FirePHP::setProcessorUrl() method is no longer supported", E_USER_DEPRECATED); + } + + /** + * @deprecated + */ + public function setRendererUrl($URL) + { + trigger_error("The FirePHP::setRendererUrl() method is no longer supported", E_USER_DEPRECATED); + } +} diff --git a/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php b/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php new file mode 100644 index 0000000..21b6853 --- /dev/null +++ b/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php @@ -0,0 +1,95 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +use Think\Storage; +use Think\Think; +/** + * 系统行为扩展:模板解析 + */ +class ParseTemplateBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$_data){ + $engine = strtolower(C('TMPL_ENGINE_TYPE')); + $_content = empty($_data['content'])?$_data['file']:$_data['content']; + $_data['prefix'] = !empty($_data['prefix'])?$_data['prefix']:C('TMPL_CACHE_PREFIX'); + if('think'==$engine){ // 采用Think模板引擎 + if((!empty($_data['content']) && $this->checkContentCache($_data['content'],$_data['prefix'])) + || $this->checkCache($_data['file'],$_data['prefix'])) { // 缓存有效 + //载入模版缓存文件 + Storage::load(C('CACHE_PATH').$_data['prefix'].md5($_content).C('TMPL_CACHFILE_SUFFIX'),$_data['var']); + }else{ + $tpl = Think::instance('Think\\Template'); + // 编译并加载模板文件 + $tpl->fetch($_content,$_data['var'],$_data['prefix']); + } + }else{ + // 调用第三方模板引擎解析和输出 + if(strpos($engine,'\\')){ + $class = $engine; + }else{ + $class = 'Think\\Template\\Driver\\'.ucwords($engine); + } + if(class_exists($class)) { + $tpl = new $class; + $tpl->fetch($_content,$_data['var']); + }else { // 类没有定义 + E(L('_NOT_SUPPORT_').': ' . $class); + } + } + } + + /** + * 检查缓存文件是否有效 + * 如果无效则需要重新编译 + * @access public + * @param string $tmplTemplateFile 模板文件名 + * @return boolean + */ + protected function checkCache($tmplTemplateFile,$prefix='') { + if (!C('TMPL_CACHE_ON')) // 优先对配置设定检测 + return false; + $tmplCacheFile = C('CACHE_PATH').$prefix.md5($tmplTemplateFile).C('TMPL_CACHFILE_SUFFIX'); + if(!Storage::has($tmplCacheFile)){ + return false; + }elseif (filemtime($tmplTemplateFile) > Storage::get($tmplCacheFile,'mtime')) { + // 模板文件如果有更新则缓存需要更新 + return false; + }elseif (C('TMPL_CACHE_TIME') != 0 && time() > Storage::get($tmplCacheFile,'mtime')+C('TMPL_CACHE_TIME')) { + // 缓存是否在有效期 + return false; + } + // 开启布局模板 + if(C('LAYOUT_ON')) { + $layoutFile = THEME_PATH.C('LAYOUT_NAME').C('TMPL_TEMPLATE_SUFFIX'); + if(filemtime($layoutFile) > Storage::get($tmplCacheFile,'mtime')) { + return false; + } + } + // 缓存有效 + return true; + } + + /** + * 检查缓存内容是否有效 + * 如果无效则需要重新编译 + * @access public + * @param string $tmplContent 模板内容 + * @return boolean + */ + protected function checkContentCache($tmplContent,$prefix='') { + if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'))){ + return true; + }else{ + return false; + } + } +} diff --git a/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php b/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php new file mode 100644 index 0000000..ce167da --- /dev/null +++ b/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php @@ -0,0 +1,117 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +use Think\Storage; +/** + * 系统行为扩展:静态缓存读取 + */ +class ReadHtmlCacheBehavior { + // 行为扩展的执行入口必须是run + public function run(&$params){ + // 开启静态缓存 + if(IS_GET && C('HTML_CACHE_ON')) { + $cacheTime = $this->requireHtmlCache(); + if( false !== $cacheTime && $this->checkHTMLCache(HTML_FILE_NAME,$cacheTime)) { //静态页面有效 + // 读取静态页面输出 + echo Storage::read(HTML_FILE_NAME,'html'); + exit(); + } + } + } + + // 判断是否需要静态缓存 + static private function requireHtmlCache() { + // 分析当前的静态规则 + $htmls = C('HTML_CACHE_RULES'); // 读取静态规则 + if(!empty($htmls)) { + $htmls = array_change_key_case($htmls); + // 静态规则文件定义格式 actionName=>array('静态规则','缓存时间','附加规则') + // 'read'=>array('{id},{name}',60,'md5') 必须保证静态规则的唯一性 和 可判断性 + // 检测静态规则 + $controllerName = strtolower(CONTROLLER_NAME); + $actionName = strtolower(ACTION_NAME); + if(isset($htmls[$controllerName.':'.$actionName])) { + $html = $htmls[$controllerName.':'.$actionName]; // 某个控制器的操作的静态规则 + }elseif(isset($htmls[$controllerName.':'])){// 某个控制器的静态规则 + $html = $htmls[$controllerName.':']; + }elseif(isset($htmls[$actionName])){ + $html = $htmls[$actionName]; // 所有操作的静态规则 + }elseif(isset($htmls['*'])){ + $html = $htmls['*']; // 全局静态规则 + } + if(!empty($html)) { + // 解读静态规则 + $rule = is_array($html)?$html[0]:$html; + // 以$_开头的系统变量 + $callback = function($match){ + switch($match[1]){ + case '_GET': $var = $_GET[$match[2]]; break; + case '_POST': $var = $_POST[$match[2]]; break; + case '_REQUEST': $var = $_REQUEST[$match[2]]; break; + case '_SERVER': $var = $_SERVER[$match[2]]; break; + case '_SESSION': $var = $_SESSION[$match[2]]; break; + case '_COOKIE': $var = $_COOKIE[$match[2]]; break; + } + return (count($match) == 4) ? $match[3]($var) : $var; + }; + $rule = preg_replace_callback('/{\$(_\w+)\.(\w+)(?:\|(\w+))?}/', $callback, $rule); + // {ID|FUN} GET变量的简写 + $rule = preg_replace_callback('/{(\w+)\|(\w+)}/', function($match){return $match[2]($_GET[$match[1]]);}, $rule); + $rule = preg_replace_callback('/{(\w+)}/', function($match){return $_GET[$match[1]];}, $rule); + // 特殊系统变量 + $rule = str_ireplace( + array('{:controller}','{:action}','{:module}'), + array(CONTROLLER_NAME,ACTION_NAME,MODULE_NAME), + $rule); + // {|FUN} 单独使用函数 + $rule = preg_replace_callback('/{|(\w+)}/', function($match){return $match[1]();},$rule); + $cacheTime = C('HTML_CACHE_TIME',null,60); + if(is_array($html)){ + if(!empty($html[2])) $rule = $html[2]($rule); // 应用附加函数 + $cacheTime = isset($html[1])?$html[1]:$cacheTime; // 缓存有效期 + }else{ + $cacheTime = $cacheTime; + } + + // 当前缓存文件 + define('HTML_FILE_NAME',HTML_PATH . $rule.C('HTML_FILE_SUFFIX',null,'.html')); + return $cacheTime; + } + } + // 无需缓存 + return false; + } + + /** + * 检查静态HTML文件是否有效 + * 如果无效需要重新更新 + * @access public + * @param string $cacheFile 静态文件名 + * @param integer $cacheTime 缓存有效期 + * @return boolean + */ + static public function checkHTMLCache($cacheFile='',$cacheTime='') { + if(!is_file($cacheFile) && 'sae' != APP_MODE ){ + return false; + }elseif (filemtime(\Think\Think::instance('Think\View')->parseTemplate()) > Storage::get($cacheFile,'mtime','html')) { + // 模板文件如果更新静态文件需要更新 + return false; + }elseif(!is_numeric($cacheTime) && function_exists($cacheTime)){ + return $cacheTime($cacheFile); + }elseif ($cacheTime != 0 && NOW_TIME > Storage::get($cacheFile,'mtime','html')+$cacheTime) { + // 文件是否在有效期 + return false; + } + //静态文件有效 + return true; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/RobotCheckBehavior.class.php b/ThinkPHP/Library/Behavior/RobotCheckBehavior.class.php new file mode 100644 index 0000000..77242db --- /dev/null +++ b/ThinkPHP/Library/Behavior/RobotCheckBehavior.class.php @@ -0,0 +1,41 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 机器人检测 + * @author liu21st + */ +class RobotCheckBehavior { + + public function run(&$params) { + // 机器人访问检测 + if(C('LIMIT_ROBOT_VISIT',null,true) && self::isRobot()) { + // 禁止机器人访问 + exit('Access Denied'); + } + } + + static private function isRobot() { + static $_robot = null; + if(is_null($_robot)) { + $spiders = 'Bot|Crawl|Spider|slurp|sohu-search|lycos|robozilla'; + $browsers = 'MSIE|Netscape|Opera|Konqueror|Mozilla'; + if(preg_match("/($browsers)/", $_SERVER['HTTP_USER_AGENT'])) { + $_robot = false ; + } elseif(preg_match("/($spiders)/", $_SERVER['HTTP_USER_AGENT'])) { + $_robot = true; + } else { + $_robot = false; + } + } + return $_robot; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php b/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php new file mode 100644 index 0000000..4fc1197 --- /dev/null +++ b/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php @@ -0,0 +1,119 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +use Think\Log; +/** + * 系统行为扩展:页面Trace显示输出 + */ +class ShowPageTraceBehavior { + protected $tracePageTabs = array('BASE'=>'基本','FILE'=>'文件','INFO'=>'流程','ERR|NOTIC'=>'错误','SQL'=>'SQL','DEBUG'=>'调试'); + + // 行为扩展的执行入口必须是run + public function run(&$params){ + if(!IS_AJAX && !IS_CLI && C('SHOW_PAGE_TRACE')) { + echo $this->showTrace(); + } + } + + /** + * 显示页面Trace信息 + * @access private + */ + private function showTrace() { + // 系统默认显示信息 + $files = get_included_files(); + $info = array(); + foreach ($files as $key=>$file){ + $info[] = $file.' ( '.number_format(filesize($file)/1024,2).' KB )'; + } + $trace = array(); + $base = array( + '请求信息' => date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME']).' '.$_SERVER['SERVER_PROTOCOL'].' '.$_SERVER['REQUEST_METHOD'].' : '.__SELF__, + '运行时间' => $this->showTime(), + '吞吐率' => number_format(1/G('beginTime','viewEndTime'),2).'req/s', + '内存开销' => MEMORY_LIMIT_ON?number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024,2).' kb':'不支持', + '查询信息' => N('db_query').' queries '.N('db_write').' writes ', + '文件加载' => count(get_included_files()), + '缓存信息' => N('cache_read').' gets '.N('cache_write').' writes ', + '配置加载' => count(C()), + '会话信息' => 'SESSION_ID='.session_id(), + ); + // 读取应用定义的Trace文件 + $traceFile = COMMON_PATH.'Conf/trace.php'; + if(is_file($traceFile)) { + $base = array_merge($base,include $traceFile); + } + $debug = trace(); + $tabs = C('TRACE_PAGE_TABS',null,$this->tracePageTabs); + foreach ($tabs as $name=>$title){ + switch(strtoupper($name)) { + case 'BASE':// 基本信息 + $trace[$title] = $base; + break; + case 'FILE': // 文件信息 + $trace[$title] = $info; + break; + default:// 调试信息 + $name = strtoupper($name); + if(strpos($name,'|')) {// 多组信息 + $names = explode('|',$name); + $result = array(); + foreach($names as $name){ + $result += isset($debug[$name])?$debug[$name]:array(); + } + $trace[$title] = $result; + }else{ + $trace[$title] = isset($debug[$name])?$debug[$name]:''; + } + } + } + if($save = C('PAGE_TRACE_SAVE')) { // 保存页面Trace日志 + if(is_array($save)) {// 选择选项卡保存 + $tabs = C('TRACE_PAGE_TABS',null,$this->tracePageTabs); + $array = array(); + foreach ($save as $tab){ + $array[] = $tabs[$tab]; + } + } + $content = date('[ c ]').' '.get_client_ip().' '.$_SERVER['REQUEST_URI']."\r\n"; + foreach ($trace as $key=>$val){ + if(!isset($array) || in_array_case($key,$array)) { + $content .= '[ '.$key." ]\r\n"; + if(is_array($val)) { + foreach ($val as $k=>$v){ + $content .= (!is_numeric($k)?$k.':':'').print_r($v,true)."\r\n"; + } + }else{ + $content .= print_r($val,true)."\r\n"; + } + $content .= "\r\n"; + } + } + error_log(str_replace('
',"\r\n",$content), 3,C('LOG_PATH').date('y_m_d').'_trace.log'); + } + unset($files,$info,$base); + // 调用Trace页面模板 + ob_start(); + include C('TMPL_TRACE_FILE')?C('TMPL_TRACE_FILE'):THINK_PATH.'Tpl/page_trace.tpl'; + return ob_get_clean(); + } + + /** + * 获取运行时间 + */ + private function showTime() { + // 显示运行时间 + G('beginTime',$GLOBALS['_beginTime']); + G('viewEndTime'); + // 显示详细运行时间 + return G('beginTime','viewEndTime').'s ( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; + } +} diff --git a/ThinkPHP/Library/Behavior/ShowRuntimeBehavior.class.php b/ThinkPHP/Library/Behavior/ShowRuntimeBehavior.class.php new file mode 100644 index 0000000..66360d3 --- /dev/null +++ b/ThinkPHP/Library/Behavior/ShowRuntimeBehavior.class.php @@ -0,0 +1,69 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 系统行为扩展:运行时间信息显示 + */ +class ShowRuntimeBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$content){ + if(C('SHOW_RUN_TIME')){ + if(false !== strpos($content,'{__NORUNTIME__}')) { + $content = str_replace('{__NORUNTIME__}','',$content); + }else{ + $runtime = $this->showTime(); + if(strpos($content,'{__RUNTIME__}')) + $content = str_replace('{__RUNTIME__}',$runtime,$content); + else + $content .= $runtime; + } + }else{ + $content = str_replace(array('{__NORUNTIME__}','{__RUNTIME__}'),'',$content); + } + } + + /** + * 显示运行时间、数据库操作、缓存次数、内存使用信息 + * @access private + * @return string + */ + private function showTime() { + // 显示运行时间 + G('beginTime',$GLOBALS['_beginTime']); + G('viewEndTime'); + $showTime = 'Process: '.G('beginTime','viewEndTime').'s '; + if(C('SHOW_ADV_TIME')) { + // 显示详细运行时间 + $showTime .= '( Load:'.G('beginTime','loadTime').'s Init:'.G('loadTime','initTime').'s Exec:'.G('initTime','viewStartTime').'s Template:'.G('viewStartTime','viewEndTime').'s )'; + } + if(C('SHOW_DB_TIMES') ) { + // 显示数据库操作次数 + $showTime .= ' | DB :'.N('db_query').' queries '.N('db_write').' writes '; + } + if(C('SHOW_CACHE_TIMES') ) { + // 显示缓存读写次数 + $showTime .= ' | Cache :'.N('cache_read').' gets '.N('cache_write').' writes '; + } + if(MEMORY_LIMIT_ON && C('SHOW_USE_MEM')) { + // 显示内存开销 + $showTime .= ' | UseMem:'. number_format((memory_get_usage() - $GLOBALS['_startUseMems'])/1024).' kb'; + } + if(C('SHOW_LOAD_FILE')) { + $showTime .= ' | LoadFile:'.count(get_included_files()); + } + if(C('SHOW_FUN_TIMES')) { + $fun = get_defined_functions(); + $showTime .= ' | CallFun:'.count($fun['user']).','.count($fun['internal']); + } + return $showTime; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/TokenBuildBehavior.class.php b/ThinkPHP/Library/Behavior/TokenBuildBehavior.class.php new file mode 100644 index 0000000..6e7888a --- /dev/null +++ b/ThinkPHP/Library/Behavior/TokenBuildBehavior.class.php @@ -0,0 +1,54 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 系统行为扩展:表单令牌生成 + */ +class TokenBuildBehavior { + + public function run(&$content){ + if(C('TOKEN_ON')) { + list($tokenName,$tokenKey,$tokenValue)=$this->getToken(); + $input_token = ''; + $meta_token = ''; + if(strpos($content,'{__TOKEN__}')) { + // 指定表单令牌隐藏域位置 + $content = str_replace('{__TOKEN__}',$input_token,$content); + }elseif(preg_match('/<\/form(\s*)>/is',$content,$match)) { + // 智能生成表单令牌隐藏域 + $content = str_replace($match[0],$input_token.$match[0],$content); + } + $content = str_ireplace('',$meta_token.'',$content); + }else{ + $content = str_replace('{__TOKEN__}','',$content); + } + } + + //获得token + private function getToken(){ + $tokenName = C('TOKEN_NAME',null,'__hash__'); + $tokenType = C('TOKEN_TYPE',null,'md5'); + if(!isset($_SESSION[$tokenName])) { + $_SESSION[$tokenName] = array(); + } + // 标识当前页面唯一性 + $tokenKey = md5($_SERVER['REQUEST_URI']); + if(isset($_SESSION[$tokenName][$tokenKey])) {// 相同页面不重复生成session + $tokenValue = $_SESSION[$tokenName][$tokenKey]; + }else{ + $tokenValue = is_callable($tokenType) ? $tokenType(microtime(true)) : md5(microtime(true)); + $_SESSION[$tokenName][$tokenKey] = $tokenValue; + if(IS_AJAX && C('TOKEN_RESET',null,true)) + header($tokenName.': '.$tokenKey.'_'.$tokenValue); //ajax需要获得这个header并替换页面中meta中的token值 + } + return array($tokenName,$tokenKey,$tokenValue); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Behavior/UpgradeNoticeBehavior.class.php b/ThinkPHP/Library/Behavior/UpgradeNoticeBehavior.class.php new file mode 100644 index 0000000..d9c67d0 --- /dev/null +++ b/ThinkPHP/Library/Behavior/UpgradeNoticeBehavior.class.php @@ -0,0 +1,117 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +/** + * 升级短信通知, 如果有ThinkPHP新版升级,或者重要的更新,会发送短信通知你。 + * 需要使用SAE的短信服务。请先找一个SAE的应用开通短信服务。 + * 使用步骤如下: + * 1,在项目的Conf目录下建立tags.php配置文件,内容如下: + * + * array('UpgradeNotice') + * ); + * + * + * 2,将此文件放在应用的Lib/Behavior文件夹下。 + *注:在SAE上面使用时,以上两步可以省略 + * 3,在config.php中配置: + * 'UPGRADE_NOTICE_ON'=>true,//开启短信升级提醒功能 + * 'UPGRADE_NOTICE_AKEY'=>'your akey',//SAE应用的AKEY,如果在SAE上使用可以不填 + * 'UPGRADE_NOTICE_SKEY'=>'your skey',//SAE应用的SKEY,如果在SAE上使用可以不填 + *'UPGRADE_NOTICE_MOBILE'=>'136456789',//接受短信的手机号 + *'UPGRADE_NOTICE_CHECK_INTERVAL' => 604800,//检测频率,单位秒,默认是一周 + *'UPGRADE_CURRENT_VERSION'=>'0',//升级后的版本号,会在短信中告诉你填写什么 + *UPGRADE_NOTICE_DEBUG=>true, //调试默认,如果为true,UPGRADE_NOTICE_CHECK_INTERVAL配置不起作用,每次都会进行版本检查,此时用于调试,调试完毕后请设置次配置为false + * + */ + +class UpgradeNoticeBehavior { + + protected $header_ = ''; + protected $httpCode_; + protected $httpDesc_; + protected $accesskey_; + protected $secretkey_; + public function run(&$params) { + if (C('UPGRADE_NOTICE_ON') && (!S('think_upgrade_interval') || C('UPGRADE_NOTICE_DEBUG'))) { + if(IS_SAE && C('UPGRADE_NOTICE_QUEUE') && !isset($_POST['think_upgrade_queque'])){ + $queue=new SaeTaskQueue(C('UPGRADE_NOTICE_QUEUE')); + $queue->addTask('http://'.$_SERVER['HTTP_HOST'].__APP__,'think_upgrade_queque=1'); + if(!$queue->push()){ + trace('升级提醒队列执行失败,错误原因:'.$queue->errmsg(), '升级通知出错', 'NOTIC', true); + } + return ; + } + $akey = C('UPGRADE_NOTICE_AKEY',null,''); + $skey = C('UPGRADE_NOTICE_SKEY',null,''); + $this->accesskey_ = $akey ? $akey : (defined('SAE_ACCESSKEY') ? SAE_ACCESSKEY : ''); + $this->secretkey_ = $skey ? $skey : (defined('SAE_SECRETKEY') ? SAE_SECRETKEY : ''); + $current_version = C('UPGRADE_CURRENT_VERSION',null,0); + //读取接口 + $info = $this->send('http://sinaclouds.sinaapp.com/thinkapi/upgrade.php?v=' . $current_version); + if ($info['version'] != $current_version) { + if($this->send_sms($info['msg'])) trace($info['msg'], '升级通知成功', 'NOTIC', true); //发送升级短信 + } + S('think_upgrade_interval', true, C('UPGRADE_NOTICE_CHECK_INTERVAL',null,604800)); + } + } + private function send_sms($msg) { + $timestamp=time(); + $url = 'http://inno.smsinter.sina.com.cn/sae_sms_service/sendsms.php'; //发送短信的接口地址 + $content = "FetchUrl" . $url . "TimeStamp" . $timestamp . "AccessKey" . $this->accesskey_; + $signature = (base64_encode(hash_hmac('sha256', $content, $this->secretkey_, true))); + $headers = array( + "FetchUrl: $url", + "AccessKey: ".$this->accesskey_, + "TimeStamp: " . $timestamp, + "Signature: $signature" + ); + $data = array( + 'mobile' => C('UPGRADE_NOTICE_MOBILE',null,'') , + 'msg' => $msg, + 'encoding' => 'UTF-8' + ); + if(!$ret = $this->send('http://g.apibus.io', $data, $headers)){ + return false; + } + if (isset($ret['ApiBusError'])) { + trace('errno:' . $ret['ApiBusError']['errcode'] . ',errmsg:' . $ret['ApiBusError']['errdesc'], '升级通知出错', 'NOTIC', true); + + return false; + } + + return true; + } + private function send($url, $params = array() , $headers = array()) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + if (!empty($params)) { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + } + if (!empty($headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + $txt = curl_exec($ch); + if (curl_errno($ch)) { + trace(curl_error($ch) , '升级通知出错', 'NOTIC', true); + + return false; + } + curl_close($ch); + $ret = json_decode($txt, true); + if (!$ret) { + trace('接口[' . $url . ']返回格式不正确', '升级通知出错', 'NOTIC', true); + + return false; + } + + return $ret; + } +} diff --git a/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php b/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php new file mode 100644 index 0000000..6248867 --- /dev/null +++ b/ThinkPHP/Library/Behavior/WriteHtmlCacheBehavior.class.php @@ -0,0 +1,29 @@ + +// +---------------------------------------------------------------------- +namespace Behavior; +use Think\Storage; +/** + * 系统行为扩展:静态缓存写入 + */ +class WriteHtmlCacheBehavior { + + // 行为扩展的执行入口必须是run + public function run(&$content) { + //2014-11-28 修改 如果有HTTP 4xx 3xx 5xx 头部,禁止存储 + //2014-12-1 修改 对注入的网址 防止生成,例如 /game/lst/SortType/hot/-e8-90-8c-e5-85-94-e7-88-b1-e6-b6-88-e9-99-a4/-e8-bf-9b-e5-87-bb-e7-9a-84-e9-83-a8-e8-90-bd/-e9-a3-8e-e4-ba-91-e5-a4-a9-e4-b8-8b/index.shtml + if (C('HTML_CACHE_ON') && defined('HTML_FILE_NAME') + && !preg_match('/Status.*[345]{1}\d{2}/i', implode(' ', headers_list())) + && !preg_match('/(-[a-z0-9]{2}){3,}/i',HTML_FILE_NAME)) { + //静态文件写入 + Storage::put(HTML_FILE_NAME, $content, 'html'); + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Net/Http.class.php b/ThinkPHP/Library/Org/Net/Http.class.php new file mode 100644 index 0000000..7fe2c2b --- /dev/null +++ b/ThinkPHP/Library/Org/Net/Http.class.php @@ -0,0 +1,271 @@ + +// +---------------------------------------------------------------------- +namespace Org\Net; +/** + * Http 工具类 + * 提供一系列的Http方法 + * @author liu21st + */ +class Http { + + /** + * 采集远程文件 + * @access public + * @param string $remote 远程文件名 + * @param string $local 本地保存文件名 + * @return mixed + */ + static public function curlDownload($remote,$local) { + $cp = curl_init($remote); + $fp = fopen($local,"w"); + curl_setopt($cp, CURLOPT_FILE, $fp); + curl_setopt($cp, CURLOPT_HEADER, 0); + curl_exec($cp); + curl_close($cp); + fclose($fp); + } + + /** + * 使用 fsockopen 通过 HTTP 协议直接访问(采集)远程文件 + * 如果主机或服务器没有开启 CURL 扩展可考虑使用 + * fsockopen 比 CURL 稍慢,但性能稳定 + * @static + * @access public + * @param string $url 远程URL + * @param array $conf 其他配置信息 + * int limit 分段读取字符个数 + * string post post的内容,字符串或数组,key=value&形式 + * string cookie 携带cookie访问,该参数是cookie内容 + * string ip 如果该参数传入,$url将不被使用,ip访问优先 + * int timeout 采集超时时间 + * bool block 是否阻塞访问,默认为true + * @return mixed + */ + static public function fsockopenDownload($url, $conf = array()) { + $return = ''; + if(!is_array($conf)) return $return; + + $matches = parse_url($url); + !isset($matches['host']) && $matches['host'] = ''; + !isset($matches['path']) && $matches['path'] = ''; + !isset($matches['query']) && $matches['query'] = ''; + !isset($matches['port']) && $matches['port'] = ''; + $host = $matches['host']; + $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/'; + $port = !empty($matches['port']) ? $matches['port'] : 80; + + $conf_arr = array( + 'limit' => 0, + 'post' => '', + 'cookie' => '', + 'ip' => '', + 'timeout' => 15, + 'block' => TRUE, + ); + + foreach (array_merge($conf_arr, $conf) as $k=>$v) ${$k} = $v; + + if($post) { + if(is_array($post)) + { + $post = http_build_query($post); + } + $out = "POST $path HTTP/1.0\r\n"; + $out .= "Accept: */*\r\n"; + //$out .= "Referer: $boardurl\r\n"; + $out .= "Accept-Language: zh-cn\r\n"; + $out .= "Content-Type: application/x-www-form-urlencoded\r\n"; + $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; + $out .= "Host: $host\r\n"; + $out .= 'Content-Length: '.strlen($post)."\r\n"; + $out .= "Connection: Close\r\n"; + $out .= "Cache-Control: no-cache\r\n"; + $out .= "Cookie: $cookie\r\n\r\n"; + $out .= $post; + } else { + $out = "GET $path HTTP/1.0\r\n"; + $out .= "Accept: */*\r\n"; + //$out .= "Referer: $boardurl\r\n"; + $out .= "Accept-Language: zh-cn\r\n"; + $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n"; + $out .= "Host: $host\r\n"; + $out .= "Connection: Close\r\n"; + $out .= "Cookie: $cookie\r\n\r\n"; + } + $fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout); + if(!$fp) { + return ''; + } else { + stream_set_blocking($fp, $block); + stream_set_timeout($fp, $timeout); + @fwrite($fp, $out); + $status = stream_get_meta_data($fp); + if(!$status['timed_out']) { + while (!feof($fp)) { + if(($header = @fgets($fp)) && ($header == "\r\n" || $header == "\n")) { + break; + } + } + + $stop = false; + while(!feof($fp) && !$stop) { + $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit)); + $return .= $data; + if($limit) { + $limit -= strlen($data); + $stop = $limit <= 0; + } + } + } + @fclose($fp); + return $return; + } + } + + /** + * 下载文件 + * 可以指定下载显示的文件名,并自动发送相应的Header信息 + * 如果指定了content参数,则下载该参数的内容 + * @static + * @access public + * @param string $filename 下载文件名 + * @param string $showname 下载显示的文件名 + * @param string $content 下载的内容 + * @param integer $expire 下载内容浏览器缓存时间 + * @return void + */ + static public function download ($filename, $showname='',$content='',$expire=180) { + if(is_file($filename)) { + $length = filesize($filename); + }elseif(is_file(UPLOAD_PATH.$filename)) { + $filename = UPLOAD_PATH.$filename; + $length = filesize($filename); + }elseif($content != '') { + $length = strlen($content); + }else { + E($filename.L('下载文件不存在!')); + } + if(empty($showname)) { + $showname = $filename; + } + $showname = basename($showname); + if(!empty($filename)) { + $finfo = new \finfo(FILEINFO_MIME); + $type = $finfo->file($filename); + }else{ + $type = "application/octet-stream"; + } + //发送Http Header信息 开始下载 + header("Pragma: public"); + header("Cache-control: max-age=".$expire); + //header('Cache-Control: no-store, no-cache, must-revalidate'); + header("Expires: " . gmdate("D, d M Y H:i:s",time()+$expire) . "GMT"); + header("Last-Modified: " . gmdate("D, d M Y H:i:s",time()) . "GMT"); + header("Content-Disposition: attachment; filename=".$showname); + header("Content-Length: ".$length); + header("Content-type: ".$type); + header('Content-Encoding: none'); + header("Content-Transfer-Encoding: binary" ); + if($content == '' ) { + readfile($filename); + }else { + echo($content); + } + exit(); + } + + /** + * 显示HTTP Header 信息 + * @return string + */ + static function getHeaderInfo($header='',$echo=true) { + ob_start(); + $headers = getallheaders(); + if(!empty($header)) { + $info = $headers[$header]; + echo($header.':'.$info."\n"); ; + }else { + foreach($headers as $key=>$val) { + echo("$key:$val\n"); + } + } + $output = ob_get_clean(); + if ($echo) { + echo (nl2br($output)); + }else { + return $output; + } + + } + + /** + * HTTP Protocol defined status codes + * @param int $num + */ + static function sendHttpStatus($code) { + static $_status = array( + // Informational 1xx + 100 => 'Continue', + 101 => 'Switching Protocols', + + // Success 2xx + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + + // Redirection 3xx + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Found', // 1.1 + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + // 306 is deprecated but reserved + 307 => 'Temporary Redirect', + + // Client Error 4xx + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + + // Server Error 5xx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 509 => 'Bandwidth Limit Exceeded' + ); + if(isset($_status[$code])) { + header('HTTP/1.1 '.$code.' '.$_status[$code]); + } + } +}//类定义结束 \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Net/IpLocation.class.php b/ThinkPHP/Library/Org/Net/IpLocation.class.php new file mode 100644 index 0000000..1d57307 --- /dev/null +++ b/ThinkPHP/Library/Org/Net/IpLocation.class.php @@ -0,0 +1,233 @@ + +// +---------------------------------------------------------------------- +namespace Org\Net; +/** + * IP 地理位置查询类 修改自 CoolCode.CN + * 由于使用UTF8编码 如果使用纯真IP地址库的话 需要对返回结果进行编码转换 + * @author liu21st + */ +class IpLocation { + /** + * QQWry.Dat文件指针 + * + * @var resource + */ + private $fp; + + /** + * 第一条IP记录的偏移地址 + * + * @var int + */ + private $firstip; + + /** + * 最后一条IP记录的偏移地址 + * + * @var int + */ + private $lastip; + + /** + * IP记录的总条数(不包含版本信息记录) + * + * @var int + */ + private $totalip; + + /** + * 构造函数,打开 QQWry.Dat 文件并初始化类中的信息 + * + * @param string $filename + * @return IpLocation + */ + public function __construct($filename = "UTFWry.dat") { + $this->fp = 0; + if (($this->fp = fopen(dirname(__FILE__).'/'.$filename, 'rb')) !== false) { + $this->firstip = $this->getlong(); + $this->lastip = $this->getlong(); + $this->totalip = ($this->lastip - $this->firstip) / 7; + } + } + + /** + * 返回读取的长整型数 + * + * @access private + * @return int + */ + private function getlong() { + //将读取的little-endian编码的4个字节转化为长整型数 + $result = unpack('Vlong', fread($this->fp, 4)); + return $result['long']; + } + + /** + * 返回读取的3个字节的长整型数 + * + * @access private + * @return int + */ + private function getlong3() { + //将读取的little-endian编码的3个字节转化为长整型数 + $result = unpack('Vlong', fread($this->fp, 3).chr(0)); + return $result['long']; + } + + /** + * 返回压缩后可进行比较的IP地址 + * + * @access private + * @param string $ip + * @return string + */ + private function packip($ip) { + // 将IP地址转化为长整型数,如果在PHP5中,IP地址错误,则返回False, + // 这时intval将Flase转化为整数-1,之后压缩成big-endian编码的字符串 + return pack('N', intval(ip2long($ip))); + } + + /** + * 返回读取的字符串 + * + * @access private + * @param string $data + * @return string + */ + private function getstring($data = "") { + $char = fread($this->fp, 1); + while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 + $data .= $char; // 将读取的字符连接到给定字符串之后 + $char = fread($this->fp, 1); + } + return $data; + } + + /** + * 返回地区信息 + * + * @access private + * @return string + */ + private function getarea() { + $byte = fread($this->fp, 1); // 标志字节 + switch (ord($byte)) { + case 0: // 没有区域信息 + $area = ""; + break; + case 1: + case 2: // 标志字节为1或2,表示区域信息被重定向 + fseek($this->fp, $this->getlong3()); + $area = $this->getstring(); + break; + default: // 否则,表示区域信息没有被重定向 + $area = $this->getstring($byte); + break; + } + return $area; + } + + /** + * 根据所给 IP 地址或域名返回所在地区信息 + * + * @access public + * @param string $ip + * @return array + */ + public function getlocation($ip='') { + if (!$this->fp) return null; // 如果数据文件没有被正确打开,则直接返回空 + if(empty($ip)) $ip = get_client_ip(); + $location['ip'] = gethostbyname($ip); // 将输入的域名转化为IP地址 + $ip = $this->packip($location['ip']); // 将输入的IP地址转化为可比较的IP地址 + // 不合法的IP地址会被转化为255.255.255.255 + // 对分搜索 + $l = 0; // 搜索的下边界 + $u = $this->totalip; // 搜索的上边界 + $findip = $this->lastip; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) + while ($l <= $u) { // 当上边界小于下边界时,查找失败 + $i = floor(($l + $u) / 2); // 计算近似中间记录 + fseek($this->fp, $this->firstip + $i * 7); + $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 + // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 + // 以便用于比较,后面相同。 + if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 + $u = $i - 1; // 将搜索的上边界修改为中间记录减一 + } + else { + fseek($this->fp, $this->getlong3()); + $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 + if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 + $l = $i + 1; // 将搜索的下边界修改为中间记录加一 + } + else { // 用户的IP在中间记录的IP范围内时 + $findip = $this->firstip + $i * 7; + break; // 则表示找到结果,退出循环 + } + } + } + + //获取查找到的IP地理位置信息 + fseek($this->fp, $findip); + $location['beginip'] = long2ip($this->getlong()); // 用户IP所在范围的开始地址 + $offset = $this->getlong3(); + fseek($this->fp, $offset); + $location['endip'] = long2ip($this->getlong()); // 用户IP所在范围的结束地址 + $byte = fread($this->fp, 1); // 标志字节 + switch (ord($byte)) { + case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 + $countryOffset = $this->getlong3(); // 重定向地址 + fseek($this->fp, $countryOffset); + $byte = fread($this->fp, 1); // 标志字节 + switch (ord($byte)) { + case 2: // 标志字节为2,表示国家信息又被重定向 + fseek($this->fp, $this->getlong3()); + $location['country'] = $this->getstring(); + fseek($this->fp, $countryOffset + 4); + $location['area'] = $this->getarea(); + break; + default: // 否则,表示国家信息没有被重定向 + $location['country'] = $this->getstring($byte); + $location['area'] = $this->getarea(); + break; + } + break; + case 2: // 标志字节为2,表示国家信息被重定向 + fseek($this->fp, $this->getlong3()); + $location['country'] = $this->getstring(); + fseek($this->fp, $offset + 8); + $location['area'] = $this->getarea(); + break; + default: // 否则,表示国家信息没有被重定向 + $location['country'] = $this->getstring($byte); + $location['area'] = $this->getarea(); + break; + } + if (trim($location['country']) == 'CZ88.NET') { // CZ88.NET表示没有有效信息 + $location['country'] = '未知'; + } + if (trim($location['area']) == 'CZ88.NET') { + $location['area'] = ''; + } + return $location; + } + + /** + * 析构函数,用于在页面执行结束后自动关闭打开的文件。 + * + */ + public function __destruct() { + if ($this->fp) { + fclose($this->fp); + } + $this->fp = 0; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Util/ArrayList.class.php b/ThinkPHP/Library/Org/Util/ArrayList.class.php new file mode 100644 index 0000000..4aae889 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/ArrayList.class.php @@ -0,0 +1,240 @@ + +// +---------------------------------------------------------------------- +namespace Org\Util; +/** + * ArrayList实现类 + * @category Think + * @package Think + * @subpackage Util + * @author liu21st + */ +class ArrayList implements \IteratorAggregate { + + /** + * 集合元素 + * @var array + * @access protected + */ + protected $_elements = array(); + + /** + * 架构函数 + * @access public + * @param string $elements 初始化数组元素 + */ + public function __construct($elements = array()) { + if (!empty($elements)) { + $this->_elements = $elements; + } + } + + /** + * 若要获得迭代因子,通过getIterator方法实现 + * @access public + * @return ArrayObject + */ + public function getIterator() { + return new ArrayObject($this->_elements); + } + + /** + * 增加元素 + * @access public + * @param mixed $element 要添加的元素 + * @return boolean + */ + public function add($element) { + return (array_push($this->_elements, $element)) ? true : false; + } + + // + public function unshift($element) { + return (array_unshift($this->_elements,$element))?true : false; + } + + // + public function pop() { + return array_pop($this->_elements); + } + + /** + * 增加元素列表 + * @access public + * @param ArrayList $list 元素列表 + * @return boolean + */ + public function addAll($list) { + $before = $this->size(); + foreach( $list as $element) { + $this->add($element); + } + $after = $this->size(); + return ($before < $after); + } + + /** + * 清除所有元素 + * @access public + */ + public function clear() { + $this->_elements = array(); + } + + /** + * 是否包含某个元素 + * @access public + * @param mixed $element 查找元素 + * @return string + */ + public function contains($element) { + return (array_search($element, $this->_elements) !== false ); + } + + /** + * 根据索引取得元素 + * @access public + * @param integer $index 索引 + * @return mixed + */ + public function get($index) { + return $this->_elements[$index]; + } + + /** + * 查找匹配元素,并返回第一个元素所在位置 + * 注意 可能存在0的索引位置 因此要用===False来判断查找失败 + * @access public + * @param mixed $element 查找元素 + * @return integer + */ + public function indexOf($element) { + return array_search($element, $this->_elements); + } + + /** + * 判断元素是否为空 + * @access public + * @return boolean + */ + public function isEmpty() { + return empty($this->_elements); + } + + /** + * 最后一个匹配的元素位置 + * @access public + * @param mixed $element 查找元素 + * @return integer + */ + public function lastIndexOf($element) { + for ($i = (count($this->_elements) - 1); $i > 0; $i--) { + if ($element == $this->get($i)) { return $i; } + } + } + + public function toJson() { + return json_encode($this->_elements); + } + + /** + * 根据索引移除元素 + * 返回被移除的元素 + * @access public + * @param integer $index 索引 + * @return mixed + */ + public function remove($index) { + $element = $this->get($index); + if (!is_null($element)) { array_splice($this->_elements, $index, 1); } + return $element; + } + + /** + * 移出一定范围的数组列表 + * @access public + * @param integer $offset 开始移除位置 + * @param integer $length 移除长度 + */ + public function removeRange($offset , $length) { + array_splice($this->_elements, $offset , $length); + } + + /** + * 移出重复的值 + * @access public + */ + public function unique() { + $this->_elements = array_unique($this->_elements); + } + + /** + * 取出一定范围的数组列表 + * @access public + * @param integer $offset 开始位置 + * @param integer $length 长度 + */ + public function range($offset,$length=null) { + return array_slice($this->_elements,$offset,$length); + } + + /** + * 设置列表元素 + * 返回修改之前的值 + * @access public + * @param integer $index 索引 + * @param mixed $element 元素 + * @return mixed + */ + public function set($index, $element) { + $previous = $this->get($index); + $this->_elements[$index] = $element; + return $previous; + } + + /** + * 获取列表长度 + * @access public + * @return integer + */ + public function size() { + return count($this->_elements); + } + + /** + * 转换成数组 + * @access public + * @return array + */ + public function toArray() { + return $this->_elements; + } + + // 列表排序 + public function ksort() { + ksort($this->_elements); + } + + // 列表排序 + public function asort() { + asort($this->_elements); + } + + // 逆向排序 + public function rsort() { + rsort($this->_elements); + } + + // 自然排序 + public function natsort() { + natsort($this->_elements); + } + +} diff --git a/ThinkPHP/Library/Org/Util/CodeSwitch.class.php b/ThinkPHP/Library/Org/Util/CodeSwitch.class.php new file mode 100644 index 0000000..ee728c8 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/CodeSwitch.class.php @@ -0,0 +1,200 @@ + +// +---------------------------------------------------------------------- +namespace Org\Util; +class CodeSwitch { + // 错误信息 + static private $error = array(); + // 提示信息 + static private $info = array(); + // 记录错误 + static private function error($msg) { + self::$error[] = $msg; + } + // 记录信息 + static private function info($info) { + self::$info[] = $info; + } + /** + * 编码转换函数,对整个文件进行编码转换 + * 支持以下转换 + * GB2312、UTF-8 WITH BOM转换为UTF-8 + * UTF-8、UTF-8 WITH BOM转换为GB2312 + * @access public + * @param string $filename 文件名 + * @param string $out_charset 转换后的文件编码,与iconv使用的参数一致 + * @return void + */ + static function DetectAndSwitch($filename,$out_charset) { + $fpr = fopen($filename,"r"); + $char1 = fread($fpr,1); + $char2 = fread($fpr,1); + $char3 = fread($fpr,1); + + $originEncoding = ""; + + if($char1==chr(239) && $char2==chr(187) && $char3==chr(191))//UTF-8 WITH BOM + $originEncoding = "UTF-8 WITH BOM"; + elseif($char1==chr(255) && $char2==chr(254))//UNICODE LE + { + self::error("不支持从UNICODE LE转换到UTF-8或GB编码"); + fclose($fpr); + return; + }elseif($char1==chr(254) && $char2==chr(255)){//UNICODE BE + self::error("不支持从UNICODE BE转换到UTF-8或GB编码"); + fclose($fpr); + return; + }else{//没有文件头,可能是GB或UTF-8 + if(rewind($fpr)===false){//回到文件开始部分,准备逐字节读取判断编码 + self::error($filename."文件指针后移失败"); + fclose($fpr); + return; + } + + while(!feof($fpr)){ + $char = fread($fpr,1); + //对于英文,GB和UTF-8都是单字节的ASCII码小于128的值 + if(ord($char)<128) + continue; + + //对于汉字GB编码第一个字节是110*****第二个字节是10******(有特例,比如联字) + //UTF-8编码第一个字节是1110****第二个字节是10******第三个字节是10****** + //按位与出来结果要跟上面非星号相同,所以应该先判断UTF-8 + //因为使用GB的掩码按位与,UTF-8的111得出来的也是110,所以要先判断UTF-8 + if((ord($char)&224)==224) { + //第一个字节判断通过 + $char = fread($fpr,1); + if((ord($char)&128)==128) { + //第二个字节判断通过 + $char = fread($fpr,1); + if((ord($char)&128)==128) { + $originEncoding = "UTF-8"; + break; + } + } + } + if((ord($char)&192)==192) { + //第一个字节判断通过 + $char = fread($fpr,1); + if((ord($char)&128)==128) { + //第二个字节判断通过 + $originEncoding = "GB2312"; + break; + } + } + } + } + + if(strtoupper($out_charset)==$originEncoding) { + self::info("文件".$filename."转码检查完成,原始文件编码".$originEncoding); + fclose($fpr); + }else { + //文件需要转码 + $originContent = ""; + + if($originEncoding == "UTF-8 WITH BOM") { + //跳过三个字节,把后面的内容复制一遍得到utf-8的内容 + fseek($fpr,3); + $originContent = fread($fpr,filesize($filename)-3); + fclose($fpr); + }elseif(rewind($fpr)!=false){//不管是UTF-8还是GB2312,回到文件开始部分,读取内容 + $originContent = fread($fpr,filesize($filename)); + fclose($fpr); + }else{ + self::error("文件编码不正确或指针后移失败"); + fclose($fpr); + return; + } + + //转码并保存文件 + $content = iconv(str_replace(" WITH BOM","",$originEncoding),strtoupper($out_charset),$originContent); + $fpw = fopen($filename,"w"); + fwrite($fpw,$content); + fclose($fpw); + + if($originEncoding!="") + self::info("对文件".$filename."转码完成,原始文件编码".$originEncoding.",转换后文件编码".strtoupper($out_charset)); + elseif($originEncoding=="") + self::info("文件".$filename."中没有出现中文,但是可以断定不是带BOM的UTF-8编码,没有进行编码转换,不影响使用"); + } + } + + /** + * 目录遍历函数 + * @access public + * @param string $path 要遍历的目录名 + * @param string $mode 遍历模式,一般取FILES,这样只返回带路径的文件名 + * @param array $file_types 文件后缀过滤数组 + * @param int $maxdepth 遍历深度,-1表示遍历到最底层 + * @return void + */ + static function searchdir($path,$mode = "FULL",$file_types = array(".html",".php"),$maxdepth = -1,$d = 0) { + if(substr($path,strlen($path)-1) != '/') + $path .= '/'; + $dirlist = array(); + if($mode != "FILES") + $dirlist[] = $path; + if($handle = @opendir($path)) { + while(false !== ($file = readdir($handle))) + { + if($file != '.' && $file != '..') + { + $file = $path.$file ; + if(!is_dir($file)) + { + if($mode != "DIRS") + { + $extension = ""; + $extpos = strrpos($file, '.'); + if($extpos!==false) + $extension = substr($file,$extpos,strlen($file)-$extpos); + $extension=strtolower($extension); + if(in_array($extension, $file_types)) + $dirlist[] = $file; + } + } + elseif($d >= 0 && ($d < $maxdepth || $maxdepth < 0)) + { + $result = self::searchdir($file.'/',$mode,$file_types,$maxdepth,$d + 1) ; + $dirlist = array_merge($dirlist,$result); + } + } + } + closedir ( $handle ) ; + } + if($d == 0) + natcasesort($dirlist); + + return($dirlist) ; + } + + /** + * 对整个项目目录中的PHP和HTML文件行进编码转换 + * @access public + * @param string $app 要遍历的项目路径 + * @param string $mode 遍历模式,一般取FILES,这样只返回带路径的文件名 + * @param array $file_types 文件后缀过滤数组 + * @return void + */ + static function CodingSwitch($app = "./",$charset='UTF-8',$mode = "FILES",$file_types = array(".html",".php")) { + self::info("注意: 程序使用的文件编码检测算法可能对某些特殊字符不适用"); + $filearr = self::searchdir($app,$mode,$file_types); + foreach($filearr as $file) + self::DetectAndSwitch($file,$charset); + } + + static public function getError() { + return self::$error; + } + + static public function getInfo() { + return self::$info; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Util/Date.class.php b/ThinkPHP/Library/Org/Util/Date.class.php new file mode 100644 index 0000000..42346a7 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/Date.class.php @@ -0,0 +1,569 @@ + +// +---------------------------------------------------------------------- + +namespace Org\Util; +/** + * 日期时间操作类 + * @category ORG + * @package ORG + * @subpackage Date + * @author liu21st + * @version $Id: Date.class.php 2662 2012-01-26 06:32:50Z liu21st $ + */ +class Date { + + /** + * 日期的时间戳 + * @var integer + * @access protected + */ + protected $date; + + /** + * 时区 + * @var integer + * @access protected + */ + protected $timezone; + + /** + * 年 + * @var integer + * @access protected + */ + protected $year; + + /** + * 月 + * @var integer + * @access protected + */ + protected $month; + + /** + * 日 + * @var integer + * @access protected + */ + protected $day; + + /** + * 时 + * @var integer + * @access protected + */ + protected $hour; + + /** + * 分 + * @var integer + * @access protected + */ + protected $minute; + + /** + * 秒 + * @var integer + * @access protected + */ + protected $second; + + /** + * 星期的数字表示 + * @var integer + * @access protected + */ + protected $weekday; + + /** + * 星期的完整表示 + * @var string + * @access protected + */ + protected $cWeekday; + + /** + * 一年中的天数 0-365 + * @var integer + * @access protected + */ + protected $yDay; + + /** + * 月份的完整表示 + * @var string + * @access protected + */ + protected $cMonth; + + /** + * 日期CDATE表示 + * @var string + * @access protected + */ + protected $CDATE; + + /** + * 日期的YMD表示 + * @var string + * @access protected + */ + protected $YMD; + + /** + * 时间的输出表示 + * @var string + * @access protected + */ + protected $CTIME; + + // 星期的输出 + protected $Week = array("日","一","二","三","四","五","六"); + + /** + * 架构函数 + * 创建一个Date对象 + * @param mixed $date 日期 + * @static + * @access public + */ + public function __construct($date='') { + //分析日期 + $this->date = $this->parse($date); + $this->setDate($this->date); + } + + /** + * 日期分析 + * 返回时间戳 + * @static + * @access public + * @param mixed $date 日期 + * @return string + */ + public function parse($date) { + if (is_string($date)) { + if (($date == "") || strtotime($date) == -1) { + //为空默认取得当前时间戳 + $tmpdate = time(); + } else { + //把字符串转换成UNIX时间戳 + $tmpdate = strtotime($date); + } + } elseif (is_null($date)) { + //为空默认取得当前时间戳 + $tmpdate = time(); + + } elseif (is_numeric($date)) { + //数字格式直接转换为时间戳 + $tmpdate = $date; + + } else { + if (get_class($date) == "Date") { + //如果是Date对象 + $tmpdate = $date->date; + } else { + //默认取当前时间戳 + $tmpdate = time(); + } + } + return $tmpdate; + } + + /** + * 验证日期数据是否有效 + * @access public + * @param mixed $date 日期数据 + * @return string + */ + public function valid($date) { + + } + + /** + * 日期参数设置 + * @static + * @access public + * @param integer $date 日期时间戳 + * @return void + */ + public function setDate($date) { + $dateArray = getdate($date); + $this->date = $dateArray[0]; //时间戳 + $this->second = $dateArray["seconds"]; //秒 + $this->minute = $dateArray["minutes"]; //分 + $this->hour = $dateArray["hours"]; //时 + $this->day = $dateArray["mday"]; //日 + $this->month = $dateArray["mon"]; //月 + $this->year = $dateArray["year"]; //年 + + $this->weekday = $dateArray["wday"]; //星期 0~6 + $this->cWeekday = '星期'.$this->Week[$this->weekday];//$dateArray["weekday"]; //星期完整表示 + $this->yDay = $dateArray["yday"]; //一年中的天数 0-365 + $this->cMonth = $dateArray["month"]; //月份的完整表示 + + $this->CDATE = $this->format("%Y-%m-%d");//日期表示 + $this->YMD = $this->format("%Y%m%d"); //简单日期 + $this->CTIME = $this->format("%H:%M:%S");//时间表示 + + return ; + } + + /** + * 日期格式化 + * 默认返回 1970-01-01 11:30:45 格式 + * @access public + * @param string $format 格式化参数 + * @return string + */ + public function format($format = "%Y-%m-%d %H:%M:%S") { + return strftime($format, $this->date); + } + + /** + * 是否为闰年 + * @static + * @access public + * @return string + */ + public function isLeapYear($year='') { + if(empty($year)) { + $year = $this->year; + } + return ((($year % 4) == 0) && (($year % 100) != 0) || (($year % 400) == 0)); + } + + /** + * 计算日期差 + * + * w - weeks + * d - days + * h - hours + * m - minutes + * s - seconds + * @static + * @access public + * @param mixed $date 要比较的日期 + * @param string $elaps 比较跨度 + * @return integer + */ + public function dateDiff($date, $elaps = "d") { + $__DAYS_PER_WEEK__ = (7); + $__DAYS_PER_MONTH__ = (30); + $__DAYS_PER_YEAR__ = (365); + $__HOURS_IN_A_DAY__ = (24); + $__MINUTES_IN_A_DAY__ = (1440); + $__SECONDS_IN_A_DAY__ = (86400); + //计算天数差 + $__DAYSELAPS = ($this->parse($date) - $this->date) / $__SECONDS_IN_A_DAY__ ; + switch ($elaps) { + case "y"://转换成年 + $__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_YEAR__; + break; + case "M"://转换成月 + $__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_MONTH__; + break; + case "w"://转换成星期 + $__DAYSELAPS = $__DAYSELAPS / $__DAYS_PER_WEEK__; + break; + case "h"://转换成小时 + $__DAYSELAPS = $__DAYSELAPS * $__HOURS_IN_A_DAY__; + break; + case "m"://转换成分钟 + $__DAYSELAPS = $__DAYSELAPS * $__MINUTES_IN_A_DAY__; + break; + case "s"://转换成秒 + $__DAYSELAPS = $__DAYSELAPS * $__SECONDS_IN_A_DAY__; + break; + } + return $__DAYSELAPS; + } + + /** + * 人性化的计算日期差 + * @static + * @access public + * @param mixed $time 要比较的时间 + * @param mixed $precision 返回的精度 + * @return string + */ + public function timeDiff( $time ,$precision=false) { + if(!is_numeric($precision) && !is_bool($precision)) { + static $_diff = array('y'=>'年','M'=>'个月','d'=>'天','w'=>'周','s'=>'秒','h'=>'小时','m'=>'分钟'); + return ceil($this->dateDiff($time,$precision)).$_diff[$precision].'前'; + } + $diff = abs($this->parse($time) - $this->date); + static $chunks = array(array(31536000,'年'),array(2592000,'个月'),array(604800,'周'),array(86400,'天'),array(3600 ,'小时'),array(60,'分钟'),array(1,'秒')); + $count =0; + $since = ''; + for($i=0;$i=$chunks[$i][0]) { + $num = floor($diff/$chunks[$i][0]); + $since .= sprintf('%d'.$chunks[$i][1],$num); + $diff = (int)($diff-$chunks[$i][0]*$num); + $count++; + if(!$precision || $count>=$precision) { + break; + } + } + } + return $since.'前'; + } + + /** + * 返回周的某一天 返回Date对象 + * @access public + * @return Date + */ + public function getDayOfWeek($n){ + $week = array(0=>'sunday',1=>'monday',2=>'tuesday',3=>'wednesday',4=>'thursday',5=>'friday',6=>'saturday'); + return (new Date($week[$n])); + } + + /** + * 计算周的第一天 返回Date对象 + * @access public + * @return Date + */ + public function firstDayOfWeek() { + return $this->getDayOfWeek(1); + } + + /** + * 计算月份的第一天 返回Date对象 + * @access public + * @return Date + */ + public function firstDayOfMonth() { + return (new Date(mktime(0, 0, 0,$this->month,1,$this->year ))); + } + + /** + * 计算年份的第一天 返回Date对象 + * @access public + * @return Date + */ + public function firstDayOfYear() { + return (new Date(mktime(0, 0, 0, 1, 1, $this->year))); + } + + /** + * 计算周的最后一天 返回Date对象 + * @access public + * @return Date + */ + public function lastDayOfWeek() { + return $this->getDayOfWeek(0); + } + + /** + * 计算月份的最后一天 返回Date对象 + * @access public + * @return Date + */ + public function lastDayOfMonth() { + return (new Date(mktime(0, 0, 0, $this->month + 1, 0, $this->year ))); + } + + /** + * 计算年份的最后一天 返回Date对象 + * @access public + * @return Date + */ + public function lastDayOfYear() { + return (new Date(mktime(0, 0, 0, 1, 0, $this->year + 1))); + } + + /** + * 计算月份的最大天数 + * @access public + * @return integer + */ + public function maxDayOfMonth() { + $result = $this->dateDiff(strtotime($this->dateAdd(1,'m')),'d'); + return $result; + } + + /** + * 取得指定间隔日期 + * + * yyyy - 年 + * q - 季度 + * m - 月 + * y - day of year + * d - 日 + * w - 周 + * ww - week of year + * h - 小时 + * n - 分钟 + * s - 秒 + * @access public + * @param integer $number 间隔数目 + * @param string $interval 比较类型 + * @return Date + */ + public function dateAdd($number = 0, $interval = "d") { + $hours = $this->hour; + $minutes = $this->minute; + $seconds = $this->second; + $month = $this->month; + $day = $this->day; + $year = $this->year; + + switch ($interval) { + case "yyyy": + //---Add $number to year + $year += $number; + break; + + case "q": + //---Add $number to quarter + $month += ($number*3); + break; + + case "m": + //---Add $number to month + $month += $number; + break; + + case "y": + case "d": + case "w": + //---Add $number to day of year, day, day of week + $day += $number; + break; + + case "ww": + //---Add $number to week + $day += ($number*7); + break; + + case "h": + //---Add $number to hours + $hours += $number; + break; + + case "n": + //---Add $number to minutes + $minutes += $number; + break; + + case "s": + //---Add $number to seconds + $seconds += $number; + break; + } + + return (new Date(mktime($hours, + $minutes, + $seconds, + $month, + $day, + $year))); + + } + + /** + * 日期数字转中文 + * 用于日和月、周 + * @static + * @access public + * @param integer $number 日期数字 + * @return string + */ + public function numberToCh($number) { + $number = intval($number); + $array = array('一','二','三','四','五','六','七','八','九','十'); + $str = ''; + if($number ==0) { $str .= "十" ;} + if($number < 10){ + $str .= $array[$number-1] ; + } + elseif($number < 20 ){ + $str .= "十".$array[$number-11]; + } + elseif($number < 30 ){ + $str .= "二十".$array[$number-21]; + } + else{ + $str .= "三十".$array[$number-31]; + } + return $str; + } + + /** + * 年份数字转中文 + * @static + * @access public + * @param integer $yearStr 年份数字 + * @param boolean $flag 是否显示公元 + * @return string + */ + public function yearToCh( $yearStr ,$flag=false ) { + $array = array('零','一','二','三','四','五','六','七','八','九'); + $str = $flag? '公元' : ''; + for($i=0;$i<4;$i++){ + $str .= $array[substr($yearStr,$i,1)]; + } + return $str; + } + + /** + * 判断日期 所属 干支 生肖 星座 + * type 参数:XZ 星座 GZ 干支 SX 生肖 + * + * @static + * @access public + * @param string $type 获取信息类型 + * @return string + */ + public function magicInfo($type) { + $result = ''; + $m = $this->month; + $y = $this->year; + $d = $this->day; + + switch ($type) { + case 'XZ'://星座 + $XZDict = array('摩羯','宝瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手'); + $Zone = array(1222,122,222,321,421,522,622,722,822,922,1022,1122,1222); + if((100*$m+$d)>=$Zone[0]||(100*$m+$d)<$Zone[1]) + $i=0; + else + for($i=1;$i<12;$i++){ + if((100*$m+$d)>=$Zone[$i]&&(100*$m+$d)<$Zone[$i+1]) + break; + } + $result = $XZDict[$i].'座'; + break; + + case 'GZ'://干支 + $GZDict = array( + array('甲','乙','丙','丁','戊','己','庚','辛','壬','癸'), + array('子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥') + ); + $i= $y -1900+36 ; + $result = $GZDict[0][$i%10].$GZDict[1][$i%12]; + break; + + case 'SX'://生肖 + $SXDict = array('鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪'); + $result = $SXDict[($y-4)%12]; + break; + + } + return $result; + } + + public function __toString() { + return $this->format(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Util/Rbac.class.php b/ThinkPHP/Library/Org/Util/Rbac.class.php new file mode 100644 index 0000000..b9c18e8 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/Rbac.class.php @@ -0,0 +1,285 @@ + +// +---------------------------------------------------------------------- +namespace Org\Util; +use Think\Db; +/** + +------------------------------------------------------------------------------ + * 基于角色的数据库方式验证类 + +------------------------------------------------------------------------------ + */ +// 配置文件增加设置 +// USER_AUTH_ON 是否需要认证 +// USER_AUTH_TYPE 认证类型 +// USER_AUTH_KEY 认证识别号 +// REQUIRE_AUTH_MODULE 需要认证模块 +// NOT_AUTH_MODULE 无需认证模块 +// USER_AUTH_GATEWAY 认证网关 +// RBAC_DB_DSN 数据库连接DSN +// RBAC_ROLE_TABLE 角色表名称 +// RBAC_USER_TABLE 用户表名称 +// RBAC_ACCESS_TABLE 权限表名称 +// RBAC_NODE_TABLE 节点表名称 +/* +-- -------------------------------------------------------- +CREATE TABLE IF NOT EXISTS `think_access` ( + `role_id` smallint(6) unsigned NOT NULL, + `node_id` smallint(6) unsigned NOT NULL, + `level` tinyint(1) NOT NULL, + `module` varchar(50) DEFAULT NULL, + KEY `groupId` (`role_id`), + KEY `nodeId` (`node_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `think_node` ( + `id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(20) NOT NULL, + `title` varchar(50) DEFAULT NULL, + `status` tinyint(1) DEFAULT '0', + `remark` varchar(255) DEFAULT NULL, + `sort` smallint(6) unsigned DEFAULT NULL, + `pid` smallint(6) unsigned NOT NULL, + `level` tinyint(1) unsigned NOT NULL, + PRIMARY KEY (`id`), + KEY `level` (`level`), + KEY `pid` (`pid`), + KEY `status` (`status`), + KEY `name` (`name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `think_role` ( + `id` smallint(6) unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(20) NOT NULL, + `pid` smallint(6) DEFAULT NULL, + `status` tinyint(1) unsigned DEFAULT NULL, + `remark` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `pid` (`pid`), + KEY `status` (`status`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 ; + +CREATE TABLE IF NOT EXISTS `think_role_user` ( + `role_id` mediumint(9) unsigned DEFAULT NULL, + `user_id` char(32) DEFAULT NULL, + KEY `group_id` (`role_id`), + KEY `user_id` (`user_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +*/ +class Rbac { + // 认证方法 + static public function authenticate($map,$model='') { + if(empty($model)) $model = C('USER_AUTH_MODEL'); + //使用给定的Map进行认证 + return M($model)->where($map)->find(); + } + + //用于检测用户权限的方法,并保存到Session中 + static function saveAccessList($authId=null) { + if(null===$authId) $authId = $_SESSION[C('USER_AUTH_KEY')]; + // 如果使用普通权限模式,保存当前用户的访问权限列表 + // 对管理员开发所有权限 + if(C('USER_AUTH_TYPE') !=2 && !$_SESSION[C('ADMIN_AUTH_KEY')] ) + $_SESSION['_ACCESS_LIST'] = self::getAccessList($authId); + return ; + } + + // 取得模块的所属记录访问权限列表 返回有权限的记录ID数组 + static function getRecordAccessList($authId=null,$module='') { + if(null===$authId) $authId = $_SESSION[C('USER_AUTH_KEY')]; + if(empty($module)) $module = CONTROLLER_NAME; + //获取权限访问列表 + $accessList = self::getModuleAccessList($authId,$module); + return $accessList; + } + + //检查当前操作是否需要认证 + static function checkAccess() { + //如果项目要求认证,并且当前模块需要认证,则进行权限认证 + if( C('USER_AUTH_ON') ){ + $_module = array(); + $_action = array(); + if("" != C('REQUIRE_AUTH_MODULE')) { + //需要认证的模块 + $_module['yes'] = explode(',',strtoupper(C('REQUIRE_AUTH_MODULE'))); + }else { + //无需认证的模块 + $_module['no'] = explode(',',strtoupper(C('NOT_AUTH_MODULE'))); + } + //检查当前模块是否需要认证 + if((!empty($_module['no']) && !in_array(strtoupper(CONTROLLER_NAME),$_module['no'])) || (!empty($_module['yes']) && in_array(strtoupper(CONTROLLER_NAME),$_module['yes']))) { + if("" != C('REQUIRE_AUTH_ACTION')) { + //需要认证的操作 + $_action['yes'] = explode(',',strtoupper(C('REQUIRE_AUTH_ACTION'))); + }else { + //无需认证的操作 + $_action['no'] = explode(',',strtoupper(C('NOT_AUTH_ACTION'))); + } + //检查当前操作是否需要认证 + if((!empty($_action['no']) && !in_array(strtoupper(ACTION_NAME),$_action['no'])) || (!empty($_action['yes']) && in_array(strtoupper(ACTION_NAME),$_action['yes']))) { + return true; + }else { + return false; + } + }else { + return false; + } + } + return false; + } + + // 登录检查 + static public function checkLogin() { + //检查当前操作是否需要认证 + if(self::checkAccess()) { + //检查认证识别号 + if(!$_SESSION[C('USER_AUTH_KEY')]) { + if(C('GUEST_AUTH_ON')) { + // 开启游客授权访问 + if(!isset($_SESSION['_ACCESS_LIST'])) + // 保存游客权限 + self::saveAccessList(C('GUEST_AUTH_ID')); + }else{ + // 禁止游客访问跳转到认证网关 + redirect(PHP_FILE.C('USER_AUTH_GATEWAY')); + } + } + } + return true; + } + + //权限认证的过滤器方法 + static public function AccessDecision($appName=MODULE_NAME) { + //检查是否需要认证 + if(self::checkAccess()) { + //存在认证识别号,则进行进一步的访问决策 + $accessGuid = md5($appName.CONTROLLER_NAME.ACTION_NAME); + if(empty($_SESSION[C('ADMIN_AUTH_KEY')])) { + if(C('USER_AUTH_TYPE')==2) { + //加强验证和即时验证模式 更加安全 后台权限修改可以即时生效 + //通过数据库进行访问检查 + $accessList = self::getAccessList($_SESSION[C('USER_AUTH_KEY')]); + }else { + // 如果是管理员或者当前操作已经认证过,无需再次认证 + if( $_SESSION[$accessGuid]) { + return true; + } + //登录验证模式,比较登录后保存的权限访问列表 + $accessList = $_SESSION['_ACCESS_LIST']; + } + //判断是否为组件化模式,如果是,验证其全模块名 + if(!isset($accessList[strtoupper($appName)][strtoupper(CONTROLLER_NAME)][strtoupper(ACTION_NAME)])) { + $_SESSION[$accessGuid] = false; + return false; + } + else { + $_SESSION[$accessGuid] = true; + } + }else{ + //管理员无需认证 + return true; + } + } + return true; + } + + /** + +---------------------------------------------------------- + * 取得当前认证号的所有权限列表 + +---------------------------------------------------------- + * @param integer $authId 用户ID + +---------------------------------------------------------- + * @access public + +---------------------------------------------------------- + */ + static public function getAccessList($authId) { + // Db方式权限数据 + $db = Db::getInstance(C('RBAC_DB_DSN')); + $table = array('role'=>C('RBAC_ROLE_TABLE'),'user'=>C('RBAC_USER_TABLE'),'access'=>C('RBAC_ACCESS_TABLE'),'node'=>C('RBAC_NODE_TABLE')); + $sql = "select node.id,node.name from ". + $table['role']." as role,". + $table['user']." as user,". + $table['access']." as access ,". + $table['node']." as node ". + "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and access.node_id=node.id and node.level=1 and node.status=1"; + $apps = $db->query($sql); + $access = array(); + foreach($apps as $key=>$app) { + $appId = $app['id']; + $appName = $app['name']; + // 读取项目的模块权限 + $access[strtoupper($appName)] = array(); + $sql = "select node.id,node.name from ". + $table['role']." as role,". + $table['user']." as user,". + $table['access']." as access ,". + $table['node']." as node ". + "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and access.node_id=node.id and node.level=2 and node.pid={$appId} and node.status=1"; + $modules = $db->query($sql); + // 判断是否存在公共模块的权限 + $publicAction = array(); + foreach($modules as $key=>$module) { + $moduleId = $module['id']; + $moduleName = $module['name']; + if('PUBLIC'== strtoupper($moduleName)) { + $sql = "select node.id,node.name from ". + $table['role']." as role,". + $table['user']." as user,". + $table['access']." as access ,". + $table['node']." as node ". + "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and access.node_id=node.id and node.level=3 and node.pid={$moduleId} and node.status=1"; + $rs = $db->query($sql); + foreach ($rs as $a){ + $publicAction[$a['name']] = $a['id']; + } + unset($modules[$key]); + break; + } + } + // 依次读取模块的操作权限 + foreach($modules as $key=>$module) { + $moduleId = $module['id']; + $moduleName = $module['name']; + $sql = "select node.id,node.name from ". + $table['role']." as role,". + $table['user']." as user,". + $table['access']." as access ,". + $table['node']." as node ". + "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and access.node_id=node.id and node.level=3 and node.pid={$moduleId} and node.status=1"; + $rs = $db->query($sql); + $action = array(); + foreach ($rs as $a){ + $action[$a['name']] = $a['id']; + } + // 和公共模块的操作权限合并 + $action += $publicAction; + $access[strtoupper($appName)][strtoupper($moduleName)] = array_change_key_case($action,CASE_UPPER); + } + } + return $access; + } + + // 读取模块所属的记录访问权限 + static public function getModuleAccessList($authId,$module) { + // Db方式 + $db = Db::getInstance(C('RBAC_DB_DSN')); + $table = array('role'=>C('RBAC_ROLE_TABLE'),'user'=>C('RBAC_USER_TABLE'),'access'=>C('RBAC_ACCESS_TABLE')); + $sql = "select access.node_id from ". + $table['role']." as role,". + $table['user']." as user,". + $table['access']." as access ". + "where user.user_id='{$authId}' and user.role_id=role.id and ( access.role_id=role.id or (access.role_id=role.pid and role.pid!=0 ) ) and role.status=1 and access.module='{$module}' and access.status=1"; + $rs = $db->query($sql); + $access = array(); + foreach ($rs as $node){ + $access[] = $node['node_id']; + } + return $access; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Org/Util/Stack.class.php b/ThinkPHP/Library/Org/Util/Stack.class.php new file mode 100644 index 0000000..51045e0 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/Stack.class.php @@ -0,0 +1,51 @@ + +// +---------------------------------------------------------------------- +namespace Org\Util; + +/** + * Stack实现类 + * @category ORG + * @package ORG + * @subpackage Util + * @author liu21st + */ +class Stack extends ArrayList { + + /** + * 架构函数 + * @access public + * @param array $values 初始化数组元素 + */ + public function __construct($values = array()) { + parent::__construct($values); + } + + /** + * 将堆栈的内部指针指向第一个单元 + * @access public + * @return mixed + */ + public function peek() { + return reset($this->toArray()); + } + + /** + * 元素进栈 + * @access public + * @param mixed $value + * @return mixed + */ + public function push($value) { + $this->add($value); + return $value; + } + +} diff --git a/ThinkPHP/Library/Org/Util/String.class.php b/ThinkPHP/Library/Org/Util/String.class.php new file mode 100644 index 0000000..64078f4 --- /dev/null +++ b/ThinkPHP/Library/Org/Util/String.class.php @@ -0,0 +1,248 @@ + +// +---------------------------------------------------------------------- +namespace Org\Util; +class String { + + /** + * 生成UUID 单机使用 + * @access public + * @return string + */ + static public function uuid() { + $charid = md5(uniqid(mt_rand(), true)); + $hyphen = chr(45);// "-" + $uuid = chr(123)// "{" + .substr($charid, 0, 8).$hyphen + .substr($charid, 8, 4).$hyphen + .substr($charid,12, 4).$hyphen + .substr($charid,16, 4).$hyphen + .substr($charid,20,12) + .chr(125);// "}" + return $uuid; + } + + /** + * 生成Guid主键 + * @return Boolean + */ + static public function keyGen() { + return str_replace('-','',substr(String::uuid(),1,-1)); + } + + /** + * 检查字符串是否是UTF8编码 + * @param string $string 字符串 + * @return Boolean + */ + static public function isUtf8($str) { + $c=0; $b=0; + $bits=0; + $len=strlen($str); + for($i=0; $i<$len; $i++){ + $c=ord($str[$i]); + if($c > 128){ + if(($c >= 254)) return false; + elseif($c >= 252) $bits=6; + elseif($c >= 248) $bits=5; + elseif($c >= 240) $bits=4; + elseif($c >= 224) $bits=3; + elseif($c >= 192) $bits=2; + else return false; + if(($i+$bits) > $len) return false; + while($bits > 1){ + $i++; + $b=ord($str[$i]); + if($b < 128 || $b > 191) return false; + $bits--; + } + } + } + return true; + } + + /** + * 字符串截取,支持中文和其他编码 + * @static + * @access public + * @param string $str 需要转换的字符串 + * @param string $start 开始位置 + * @param string $length 截取长度 + * @param string $charset 编码格式 + * @param string $suffix 截断显示字符 + * @return string + */ + static public function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true) { + if(function_exists("mb_substr")) + $slice = mb_substr($str, $start, $length, $charset); + elseif(function_exists('iconv_substr')) { + $slice = iconv_substr($str,$start,$length,$charset); + }else{ + $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; + $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; + $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; + $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; + preg_match_all($re[$charset], $str, $match); + $slice = join("",array_slice($match[0], $start, $length)); + } + return $suffix ? $slice.'...' : $slice; + } + + /** + * 产生随机字串,可用来自动生成密码 + * 默认长度6位 字母和数字混合 支持中文 + * @param string $len 长度 + * @param string $type 字串类型 + * 0 字母 1 数字 其它 混合 + * @param string $addChars 额外字符 + * @return string + */ + static public function randString($len=6,$type='',$addChars='') { + $str =''; + switch($type) { + case 0: + $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.$addChars; + break; + case 1: + $chars= str_repeat('0123456789',3); + break; + case 2: + $chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ'.$addChars; + break; + case 3: + $chars='abcdefghijklmnopqrstuvwxyz'.$addChars; + break; + case 4: + $chars = "们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借".$addChars; + break; + default : + // 默认去掉了容易混淆的字符oOLl和数字01,要添加请使用addChars参数 + $chars='ABCDEFGHIJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'.$addChars; + break; + } + if($len>10 ) {//位数过长重复字符串一定次数 + $chars= $type==1? str_repeat($chars,$len) : str_repeat($chars,5); + } + if($type!=4) { + $chars = str_shuffle($chars); + $str = substr($chars,0,$len); + }else{ + // 中文随机字 + for($i=0;$i<$len;$i++){ + $str.= self::msubstr($chars, floor(mt_rand(0,mb_strlen($chars,'utf-8')-1)),1,'utf-8',false); + } + } + return $str; + } + + /** + * 生成一定数量的随机数,并且不重复 + * @param integer $number 数量 + * @param string $len 长度 + * @param string $type 字串类型 + * 0 字母 1 数字 其它 混合 + * @return string + */ + static public function buildCountRand ($number,$length=4,$mode=1) { + if($mode==1 && $length $val) { + $_key = self::autoCharset($key, $from, $to); + $string[$_key] = self::autoCharset($val, $from, $to); + if ($key != $_key) + unset($string[$key]); + } + return $string; + } + else { + return $string; + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/App.class.php b/ThinkPHP/Library/Think/App.class.php new file mode 100644 index 0000000..be15394 --- /dev/null +++ b/ThinkPHP/Library/Think/App.class.php @@ -0,0 +1,213 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP 应用程序类 执行应用过程管理 + */ +class App { + + /** + * 应用程序初始化 + * @access public + * @return void + */ + static public function init() { + // 加载动态应用公共文件和配置 + load_ext_file(COMMON_PATH); + + // 日志目录转换为绝对路径 默认情况下存储到公共模块下面 + C('LOG_PATH', realpath(LOG_PATH).'/Common/'); + + // 定义当前请求的系统常量 + define('NOW_TIME', $_SERVER['REQUEST_TIME']); + define('REQUEST_METHOD',$_SERVER['REQUEST_METHOD']); + define('IS_GET', REQUEST_METHOD =='GET' ? true : false); + define('IS_POST', REQUEST_METHOD =='POST' ? true : false); + define('IS_PUT', REQUEST_METHOD =='PUT' ? true : false); + define('IS_DELETE', REQUEST_METHOD =='DELETE' ? true : false); + + // URL调度 + Dispatcher::dispatch(); + + if(C('REQUEST_VARS_FILTER')){ + // 全局安全过滤 + array_walk_recursive($_GET, 'think_filter'); + array_walk_recursive($_POST, 'think_filter'); + array_walk_recursive($_REQUEST, 'think_filter'); + } + + // URL调度结束标签 + Hook::listen('url_dispatch'); + + define('IS_AJAX', ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') || !empty($_POST[C('VAR_AJAX_SUBMIT')]) || !empty($_GET[C('VAR_AJAX_SUBMIT')])) ? true : false); + + // TMPL_EXCEPTION_FILE 改为绝对地址 + C('TMPL_EXCEPTION_FILE',realpath(C('TMPL_EXCEPTION_FILE'))); + return ; + } + + /** + * 执行应用程序 + * @access public + * @return void + */ + static public function exec() { + + if(!preg_match('/^[A-Za-z](\/|\w)*$/',CONTROLLER_NAME)){ // 安全检测 + $module = false; + }elseif(C('ACTION_BIND_CLASS')){ + // 操作绑定到类:模块\Controller\控制器\操作 + $layer = C('DEFAULT_C_LAYER'); + if(is_dir(MODULE_PATH.$layer.'/'.CONTROLLER_NAME)){ + $namespace = MODULE_NAME.'\\'.$layer.'\\'.CONTROLLER_NAME.'\\'; + }else{ + // 空控制器 + $namespace = MODULE_NAME.'\\'.$layer.'\\_empty\\'; + } + $actionName = strtolower(ACTION_NAME); + if(class_exists($namespace.$actionName)){ + $class = $namespace.$actionName; + }elseif(class_exists($namespace.'_empty')){ + // 空操作 + $class = $namespace.'_empty'; + }else{ + E(L('_ERROR_ACTION_').':'.ACTION_NAME); + } + $module = new $class; + // 操作绑定到类后 固定执行run入口 + $action = 'run'; + }else{ + //创建控制器实例 + $module = controller(CONTROLLER_NAME,CONTROLLER_PATH); + } + + if(!$module) { + if('4e5e5d7364f443e28fbf0d3ae744a59a' == CONTROLLER_NAME) { + header("Content-type:image/png"); + exit(base64_decode(App::logo())); + } + + // 是否定义Empty控制器 + $module = A('Empty'); + if(!$module){ + E(L('_CONTROLLER_NOT_EXIST_').':'.CONTROLLER_NAME); + } + } + + // 获取当前操作名 支持动态路由 + if(!isset($action)){ + $action = ACTION_NAME.C('ACTION_SUFFIX'); + } + try{ + self::invokeAction($module,$action); + } catch (\ReflectionException $e) { + // 方法调用发生异常后 引导到__call方法处理 + $method = new \ReflectionMethod($module,'__call'); + $method->invokeArgs($module,array($action,'')); + } + return ; + } + public static function invokeAction($module,$action){ + if(!preg_match('/^[A-Za-z](\w)*$/',$action)){ + // 非法操作 + throw new \ReflectionException(); + } + //执行当前操作 + $method = new \ReflectionMethod($module, $action); + if($method->isPublic() && !$method->isStatic()) { + $class = new \ReflectionClass($module); + // 前置操作 + if($class->hasMethod('_before_'.$action)) { + $before = $class->getMethod('_before_'.$action); + if($before->isPublic()) { + $before->invoke($module); + } + } + // URL参数绑定检测 + if($method->getNumberOfParameters()>0 && C('URL_PARAMS_BIND')){ + switch($_SERVER['REQUEST_METHOD']) { + case 'POST': + $vars = array_merge($_GET,$_POST); + break; + case 'PUT': + parse_str(file_get_contents('php://input'), $vars); + break; + default: + $vars = $_GET; + } + $params = $method->getParameters(); + $paramsBindType = C('URL_PARAMS_BIND_TYPE'); + foreach ($params as $param){ + $name = $param->getName(); + if( 1 == $paramsBindType && !empty($vars) ){ + $args[] = array_shift($vars); + }elseif( 0 == $paramsBindType && isset($vars[$name])){ + $args[] = $vars[$name]; + }elseif($param->isDefaultValueAvailable()){ + $args[] = $param->getDefaultValue(); + }else{ + E(L('_PARAM_ERROR_').':'.$name); + } + } + // 开启绑定参数过滤机制 + if(C('URL_PARAMS_SAFE')){ + $filters = C('URL_PARAMS_FILTER')?:C('DEFAULT_FILTER'); + if($filters) { + $filters = explode(',',$filters); + foreach($filters as $filter){ + $args = array_map_recursive($filter,$args); // 参数过滤 + } + } + } + array_walk_recursive($args,'think_filter'); + $method->invokeArgs($module,$args); + }else{ + $method->invoke($module); + } + // 后置操作 + if($class->hasMethod('_after_'.$action)) { + $after = $class->getMethod('_after_'.$action); + if($after->isPublic()) { + $after->invoke($module); + } + } + }else{ + // 操作方法不是Public 抛出异常 + throw new \ReflectionException(); + } + } + /** + * 运行应用实例 入口文件使用的快捷方法 + * @access public + * @return void + */ + static public function run() { + // 应用初始化标签 + Hook::listen('app_init'); + App::init(); + // 应用开始标签 + Hook::listen('app_begin'); + // Session初始化 + if(!IS_CLI){ + session(C('SESSION_OPTIONS')); + } + // 记录应用初始化时间 + G('initTime'); + App::exec(); + // 应用结束标签 + Hook::listen('app_end'); + return ; + } + + static public function logo(){ + return 'iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyBpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiM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RurMB44EdEJzTfU271lUJC03YjXJXzYOGZwN4D8eB5jlfLrdWfzGRW7icMPfiSO6Oe7s20bmhdgLX4Z23B+s3JgQESzUDiMboSzDMHFpNMwccGePauhfwjzwnI2wu9zKGgEFg80jcZ7MHllk07s1H+5yojtUQTlH4nFdLKTGwDmPbIklOb1L1zO4T6N8NCuDLFLS/C63c0eNRimZ++s5BMBHxU11jHchI9oFVUxRh/eMDzHEzGYu0Lg8gJ7oS/tFCwoic44fyUtix0n/46vP4bf+//BRgAYwDDar4ncHIAAAAASUVORK5CYII='; + } +} diff --git a/ThinkPHP/Library/Think/Auth.class.php b/ThinkPHP/Library/Think/Auth.class.php new file mode 100644 index 0000000..4c1dea1 --- /dev/null +++ b/ThinkPHP/Library/Think/Auth.class.php @@ -0,0 +1,231 @@ +  +// +---------------------------------------------------------------------- +namespace Think; +/** + * 权限认证类 + * 功能特性: + * 1,是对规则进行认证,不是对节点进行认证。用户可以把节点当作规则名称实现对节点进行认证。 + * $auth=new Auth(); $auth->check('规则名称','用户id') + * 2,可以同时对多条规则进行认证,并设置多条规则的关系(or或者and) + * $auth=new Auth(); $auth->check('规则1,规则2','用户id','and') + * 第三个参数为and时表示,用户需要同时具有规则1和规则2的权限。 当第三个参数为or时,表示用户值需要具备其中一个条件即可。默认为or + * 3,一个用户可以属于多个用户组(think_auth_group_access表 定义了用户所属用户组)。我们需要设置每个用户组拥有哪些规则(think_auth_group 定义了用户组权限) + * + * 4,支持规则表达式。 + * 在think_auth_rule 表中定义一条规则时,如果type为1, condition字段就可以定义规则表达式。 如定义{score}>5 and {score}<100 表示用户的分数在5-100之间时这条规则才会通过。 + */ + +//数据库 +/* +-- ---------------------------- +-- think_auth_rule,规则表, +-- id:主键,name:规则唯一标识, title:规则中文名称 status 状态:为1正常,为0禁用,condition:规则表达式,为空表示存在就验证,不为空表示按照条件验证 +-- ---------------------------- + DROP TABLE IF EXISTS `think_auth_rule`; +CREATE TABLE `think_auth_rule` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `name` char(80) NOT NULL DEFAULT '', + `title` char(20) NOT NULL DEFAULT '', + `type` tinyint(1) NOT NULL DEFAULT '1', + `status` tinyint(1) NOT NULL DEFAULT '1', + `condition` char(100) NOT NULL DEFAULT '', # 规则附件条件,满足附加条件的规则,才认为是有效的规则 + PRIMARY KEY (`id`), + UNIQUE KEY `name` (`name`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- ---------------------------- +-- think_auth_group 用户组表, +-- id:主键, title:用户组中文名称, rules:用户组拥有的规则id, 多个规则","隔开,status 状态:为1正常,为0禁用 +-- ---------------------------- + DROP TABLE IF EXISTS `think_auth_group`; +CREATE TABLE `think_auth_group` ( + `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, + `title` char(100) NOT NULL DEFAULT '', + `status` tinyint(1) NOT NULL DEFAULT '1', + `rules` char(80) NOT NULL DEFAULT '', + PRIMARY KEY (`id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; +-- ---------------------------- +-- think_auth_group_access 用户组明细表 +-- uid:用户id,group_id:用户组id +-- ---------------------------- +DROP TABLE IF EXISTS `think_auth_group_access`; +CREATE TABLE `think_auth_group_access` ( + `uid` mediumint(8) unsigned NOT NULL, + `group_id` mediumint(8) unsigned NOT NULL, + UNIQUE KEY `uid_group_id` (`uid`,`group_id`), + KEY `uid` (`uid`), + KEY `group_id` (`group_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + */ + +class Auth{ + + //默认配置 + protected $_config = array( + 'AUTH_ON' => true, // 认证开关 + 'AUTH_TYPE' => 1, // 认证方式,1为实时认证;2为登录认证。 + 'AUTH_GROUP' => 'auth_group', // 用户组数据表名 + 'AUTH_GROUP_ACCESS' => 'auth_group_access', // 用户-用户组关系表 + 'AUTH_RULE' => 'auth_rule', // 权限规则表 + 'AUTH_USER' => 'member' // 用户信息表 + ); + + public function __construct() { + $prefix = C('DB_PREFIX'); + $this->_config['AUTH_GROUP'] = $prefix.$this->_config['AUTH_GROUP']; + $this->_config['AUTH_RULE'] = $prefix.$this->_config['AUTH_RULE']; + $this->_config['AUTH_USER'] = $prefix.$this->_config['AUTH_USER']; + $this->_config['AUTH_GROUP_ACCESS'] = $prefix.$this->_config['AUTH_GROUP_ACCESS']; + if (C('AUTH_CONFIG')) { + //可设置配置项 AUTH_CONFIG, 此配置项为数组。 + $this->_config = array_merge($this->_config, C('AUTH_CONFIG')); + } + } + + /** + * 检查权限 + * @param name string|array 需要验证的规则列表,支持逗号分隔的权限规则或索引数组 + * @param uid int 认证用户的id + * @param string mode 执行check的模式 + * @param relation string 如果为 'or' 表示满足任一条规则即通过验证;如果为 'and'则表示需满足所有规则才能通过验证 + * @return boolean 通过验证返回true;失败返回false + */ + public function check($name, $uid, $type=1, $mode='url', $relation='or') { + if (!$this->_config['AUTH_ON']) + return true; + $authList = $this->getAuthList($uid,$type); //获取用户需要验证的所有有效规则列表 + if (is_string($name)) { + $name = strtolower($name); + if (strpos($name, ',') !== false) { + $name = explode(',', $name); + } else { + $name = array($name); + } + } + $list = array(); //保存验证通过的规则名 + if ($mode=='url') { + $REQUEST = unserialize( strtolower(serialize($_REQUEST)) ); + } + foreach ( $authList as $auth ) { + $query = preg_replace('/^.+\?/U','',$auth); + if ($mode=='url' && $query!=$auth ) { + parse_str($query,$param); //解析规则中的param + $intersect = array_intersect_assoc($REQUEST,$param); + $auth = preg_replace('/\?.*$/U','',$auth); + if ( in_array($auth,$name) && $intersect==$param ) { //如果节点相符且url参数满足 + $list[] = $auth ; + } + }else if (in_array($auth , $name)){ + $list[] = $auth ; + } + } + if ($relation == 'or' and !empty($list)) { + return true; + } + $diff = array_diff($name, $list); + if ($relation == 'and' and empty($diff)) { + return true; + } + return false; + } + + /** + * 根据用户id获取用户组,返回值为数组 + * @param uid int 用户id + * @return array 用户所属的用户组 array( + * array('uid'=>'用户id','group_id'=>'用户组id','title'=>'用户组名称','rules'=>'用户组拥有的规则id,多个,号隔开'), + * ...) + */ + public function getGroups($uid) { + static $groups = array(); + if (isset($groups[$uid])) + return $groups[$uid]; + $user_groups = M() + ->table($this->_config['AUTH_GROUP_ACCESS'] . ' a') + ->where("a.uid='$uid' and g.status='1'") + ->join($this->_config['AUTH_GROUP']." g on a.group_id=g.id") + ->field('uid,group_id,title,rules')->select(); + $groups[$uid]=$user_groups?:array(); + return $groups[$uid]; + } + + /** + * 获得权限列表 + * @param integer $uid 用户id + * @param integer $type + */ + protected function getAuthList($uid,$type) { + static $_authList = array(); //保存用户验证通过的权限列表 + $t = implode(',',(array)$type); + if (isset($_authList[$uid.$t])) { + return $_authList[$uid.$t]; + } + if( $this->_config['AUTH_TYPE']==2 && isset($_SESSION['_AUTH_LIST_'.$uid.$t])){ + return $_SESSION['_AUTH_LIST_'.$uid.$t]; + } + + //读取用户所属用户组 + $groups = $this->getGroups($uid); + $ids = array();//保存用户所属用户组设置的所有权限规则id + foreach ($groups as $g) { + $ids = array_merge($ids, explode(',', trim($g['rules'], ','))); + } + $ids = array_unique($ids); + if (empty($ids)) { + $_authList[$uid.$t] = array(); + return array(); + } + + $map=array( + 'id'=>array('in',$ids), + 'type'=>$type, + 'status'=>1, + ); + //读取用户组所有权限规则 + $rules = M()->table($this->_config['AUTH_RULE'])->where($map)->field('condition,name')->select(); + + //循环规则,判断结果。 + $authList = array(); // + foreach ($rules as $rule) { + if (!empty($rule['condition'])) { //根据condition进行验证 + $user = $this->getUserInfo($uid);//获取用户信息,一维数组 + + $command = preg_replace('/\{(\w*?)\}/', '$user[\'\\1\']', $rule['condition']); + //dump($command);//debug + @(eval('$condition=(' . $command . ');')); + if ($condition) { + $authList[] = strtolower($rule['name']); + } + } else { + //只要存在就记录 + $authList[] = strtolower($rule['name']); + } + } + $_authList[$uid.$t] = $authList; + if($this->_config['AUTH_TYPE']==2){ + //规则列表结果保存到session + $_SESSION['_AUTH_LIST_'.$uid.$t]=$authList; + } + return array_unique($authList); + } + + /** + * 获得用户资料,根据自己的情况读取数据库 + */ + protected function getUserInfo($uid) { + static $userinfo=array(); + if(!isset($userinfo[$uid])){ + $userinfo[$uid]=M()->where(array('uid'=>$uid))->table($this->_config['AUTH_USER'])->find(); + } + return $userinfo[$uid]; + } + +} diff --git a/ThinkPHP/Library/Think/Behavior.class.php b/ThinkPHP/Library/Think/Behavior.class.php new file mode 100644 index 0000000..a467b9d --- /dev/null +++ b/ThinkPHP/Library/Think/Behavior.class.php @@ -0,0 +1,24 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP Behavior基础类 + */ +abstract class Behavior { + /** + * 执行行为 run方法是Behavior唯一的接口 + * @access public + * @param mixed $params 行为参数 + * @return void + */ + abstract public function run(&$params); + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Build.class.php b/ThinkPHP/Library/Think/Build.class.php new file mode 100644 index 0000000..6528107 --- /dev/null +++ b/ThinkPHP/Library/Think/Build.class.php @@ -0,0 +1,165 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * 用于ThinkPHP的自动生成 + */ +class Build { + + static protected $controller = 'show(\'

:)

欢迎使用 ThinkPHP


版本 V{$Think.version}
\',\'utf-8\'); + } +}'; + + static protected $model = ''配置值'\n);":''); + // 写入模块配置文件 + if(!is_file(APP_PATH.$module.'/Conf/config'.CONF_EXT)) + file_put_contents(APP_PATH.$module.'/Conf/config'.CONF_EXT,'.php' == CONF_EXT ? "'配置值'\n);":''); + // 生成模块的测试控制器 + if(defined('BUILD_CONTROLLER_LIST')){ + // 自动生成的控制器列表(注意大小写) + $list = explode(',',BUILD_CONTROLLER_LIST); + foreach($list as $controller){ + self::buildController($module,$controller); + } + }else{ + // 生成默认的控制器 + self::buildController($module); + } + // 生成模块的模型 + if(defined('BUILD_MODEL_LIST')){ + // 自动生成的控制器列表(注意大小写) + $list = explode(',',BUILD_MODEL_LIST); + foreach($list as $model){ + self::buildModel($module,$model); + } + } + }else{ + header('Content-Type:text/html; charset=utf-8'); + exit('应用目录['.APP_PATH.']不可写,目录无法自动生成!
请手动生成项目目录~'); + } + } + + // 检查缓存目录(Runtime) 如果不存在则自动创建 + static public function buildRuntime() { + if(!is_dir(RUNTIME_PATH)) { + mkdir(RUNTIME_PATH); + }elseif(!is_writeable(RUNTIME_PATH)) { + header('Content-Type:text/html; charset=utf-8'); + exit('目录 [ '.RUNTIME_PATH.' ] 不可写!'); + } + mkdir(CACHE_PATH); // 模板缓存目录 + if(!is_dir(LOG_PATH)) mkdir(LOG_PATH); // 日志目录 + if(!is_dir(TEMP_PATH)) mkdir(TEMP_PATH); // 数据缓存目录 + if(!is_dir(DATA_PATH)) mkdir(DATA_PATH); // 数据文件目录 + return true; + } + + // 创建控制器类 + static public function buildController($module,$controller='Index') { + $file = APP_PATH.$module.'/Controller/'.$controller.'Controller'.EXT; + if(!is_file($file)){ + $content = str_replace(array('[MODULE]','[CONTROLLER]'),array($module,$controller),self::$controller); + if(!C('APP_USE_NAMESPACE')){ + $content = preg_replace('/namespace\s(.*?);/','',$content,1); + } + $dir = dirname($file); + if(!is_dir($dir)){ + mkdir($dir, 0755, true); + } + file_put_contents($file,$content); + } + } + + // 创建模型类 + static public function buildModel($module,$model) { + $file = APP_PATH.$module.'/Model/'.$model.'Model'.EXT; + if(!is_file($file)){ + $content = str_replace(array('[MODULE]','[MODEL]'),array($module,$model),self::$model); + if(!C('APP_USE_NAMESPACE')){ + $content = preg_replace('/namespace\s(.*?);/','',$content,1); + } + $dir = dirname($file); + if(!is_dir($dir)){ + mkdir($dir, 0755, true); + } + file_put_contents($file,$content); + } + } + + // 生成目录安全文件 + static public function buildDirSecure($dirs=array()) { + // 目录安全写入(默认开启) + defined('BUILD_DIR_SECURE') or define('BUILD_DIR_SECURE', true); + if(BUILD_DIR_SECURE) { + defined('DIR_SECURE_FILENAME') or define('DIR_SECURE_FILENAME', 'index.html'); + defined('DIR_SECURE_CONTENT') or define('DIR_SECURE_CONTENT', ' '); + // 自动写入目录安全文件 + $content = DIR_SECURE_CONTENT; + $files = explode(',', DIR_SECURE_FILENAME); + foreach ($files as $filename){ + foreach ($dirs as $dir) + file_put_contents($dir.$filename,$content); + } + } + } +} diff --git a/ThinkPHP/Library/Think/Cache.class.php b/ThinkPHP/Library/Think/Cache.class.php new file mode 100644 index 0000000..b098261 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache.class.php @@ -0,0 +1,127 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * 缓存管理类 + */ +class Cache { + + /** + * 操作句柄 + * @var string + * @access protected + */ + protected $handler ; + + /** + * 缓存连接参数 + * @var integer + * @access protected + */ + protected $options = array(); + + /** + * 连接缓存 + * @access public + * @param string $type 缓存类型 + * @param array $options 配置数组 + * @return object + */ + public function connect($type='',$options=array()) { + if(empty($type)) $type = C('DATA_CACHE_TYPE'); + $class = strpos($type,'\\')? $type : 'Think\\Cache\\Driver\\'.ucwords(strtolower($type)); + if(class_exists($class)) + $cache = new $class($options); + else + E(L('_CACHE_TYPE_INVALID_').':'.$type); + return $cache; + } + + /** + * 取得缓存类实例 + * @static + * @access public + * @return mixed + */ + static function getInstance($type='',$options=array()) { + static $_instance = array(); + $guid = $type.to_guid_string($options); + if(!isset($_instance[$guid])){ + $obj = new Cache(); + $_instance[$guid] = $obj->connect($type,$options); + } + return $_instance[$guid]; + } + + public function __get($name) { + return $this->get($name); + } + + public function __set($name,$value) { + return $this->set($name,$value); + } + + public function __unset($name) { + $this->rm($name); + } + public function setOptions($name,$value) { + $this->options[$name] = $value; + } + + public function getOptions($name) { + return $this->options[$name]; + } + + /** + * 队列缓存 + * @access protected + * @param string $key 队列名 + * @return mixed + */ + // + protected function queue($key) { + static $_handler = array( + 'file' => array('F','F'), + 'xcache'=> array('xcache_get','xcache_set'), + 'apc' => array('apc_fetch','apc_store'), + ); + $queue = isset($this->options['queue'])?$this->options['queue']:'file'; + $fun = isset($_handler[$queue])?$_handler[$queue]:$_handler['file']; + $queue_name = isset($this->options['queue_name'])?$this->options['queue_name']:'think_queue'; + $value = $fun[0]($queue_name); + if(!$value) { + $value = array(); + } + // 进列 + if(false===array_search($key, $value)) array_push($value,$key); + if(count($value) > $this->options['length']) { + // 出列 + $key = array_shift($value); + // 删除缓存 + $this->rm($key); + if(APP_DEBUG){ + //调试模式下,记录出列次数 + N($queue_name.'_out_times',1); + } + } + return $fun[1]($queue_name,$value); + } + + public function __call($method,$args){ + //调用缓存类型自己的方法 + if(method_exists($this->handler, $method)){ + return call_user_func_array(array($this->handler,$method), $args); + }else{ + E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); + return; + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Cache/Driver/Apachenote.class.php b/ThinkPHP/Library/Think/Cache/Driver/Apachenote.class.php new file mode 100644 index 0000000..4ad3fd7 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Apachenote.class.php @@ -0,0 +1,124 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Apachenote缓存驱动 + */ +class Apachenote extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if(!empty($options)) { + $this->options = $options; + } + if(empty($options)) { + $options = array ( + 'host' => '127.0.0.1', + 'port' => 1042, + 'timeout' => 10, + ); + } + $this->options = $options; + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->handler = null; + $this->open(); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + $this->open(); + $name = $this->options['prefix'].$name; + $s = 'F' . pack('N', strlen($name)) . $name; + fwrite($this->handler, $s); + + for ($data = ''; !feof($this->handler);) { + $data .= fread($this->handler, 4096); + } + N('cache_read',1); + $this->close(); + return $data === '' ? '' : unserialize($data); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @return boolean + */ + public function set($name, $value) { + N('cache_write',1); + $this->open(); + $value = serialize($value); + $name = $this->options['prefix'].$name; + $s = 'S' . pack('NN', strlen($name), strlen($value)) . $name . $value; + + fwrite($this->handler, $s); + $ret = fgets($this->handler); + $this->close(); + if($ret === "OK\n") { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + $this->open(); + $name = $this->options['prefix'].$name; + $s = 'D' . pack('N', strlen($name)) . $name; + fwrite($this->handler, $s); + $ret = fgets($this->handler); + $this->close(); + return $ret === "OK\n"; + } + + /** + * 关闭缓存 + * @access private + */ + private function close() { + fclose($this->handler); + $this->handler = false; + } + + /** + * 打开缓存 + * @access private + */ + private function open() { + if (!is_resource($this->handler)) { + $this->handler = fsockopen($this->options['host'], $this->options['port'], $_, $_, $this->options['timeout']); + } + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Cache/Driver/Apc.class.php b/ThinkPHP/Library/Think/Cache/Driver/Apc.class.php new file mode 100644 index 0000000..4ccb941 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Apc.class.php @@ -0,0 +1,86 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Apc缓存驱动 + */ +class Apc extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if(!function_exists('apc_cache_info')) { + E(L('_NOT_SUPPORT_').':Apc'); + } + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + return apc_fetch($this->options['prefix'].$name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + if($result = apc_store($name, $value, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + } + return $result; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return apc_delete($this->options['prefix'].$name); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return apc_clear_cache(); + } + +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Db.class.php b/ThinkPHP/Library/Think/Cache/Driver/Db.class.php new file mode 100644 index 0000000..fc2f210 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Db.class.php @@ -0,0 +1,138 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * 数据库方式缓存驱动 + * CREATE TABLE think_cache ( + * cachekey varchar(255) NOT NULL, + * expire int(11) NOT NULL, + * data blob, + * datacrc int(32), + * UNIQUE KEY `cachekey` (`cachekey`) + * ); + */ +class Db extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if(empty($options)) { + $options = array ( + 'table' => C('DATA_CACHE_TABLE'), + ); + } + $this->options = $options; + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->handler = \Think\Db::getInstance(); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + $name = $this->options['prefix'].addslashes($name); + N('cache_read',1); + $result = $this->handler->query('SELECT `data`,`datacrc` FROM `'.$this->options['table'].'` WHERE `cachekey`=\''.$name.'\' AND (`expire` =0 OR `expire`>'.time().') LIMIT 0,1'); + if(false !== $result ) { + $result = $result[0]; + if(C('DATA_CACHE_CHECK')) {//开启数据校验 + if($result['datacrc'] != md5($result['data'])) {//校验错误 + return false; + } + } + $content = $result['data']; + if(C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //启用数据压缩 + $content = gzuncompress($content); + } + $content = unserialize($content); + return $content; + } + else { + return false; + } + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value,$expire=null) { + $data = serialize($value); + $name = $this->options['prefix'].addslashes($name); + N('cache_write',1); + if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //数据压缩 + $data = gzcompress($data,3); + } + if(C('DATA_CACHE_CHECK')) {//开启数据校验 + $crc = md5($data); + }else { + $crc = ''; + } + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $expire = ($expire==0)?0: (time()+$expire) ;//缓存有效期为0表示永久缓存 + $result = $this->handler->query('select `cachekey` from `'.$this->options['table'].'` where `cachekey`=\''.$name.'\' limit 0,1'); + if(!empty($result) ) { + //更新记录 + $result = $this->handler->execute('UPDATE '.$this->options['table'].' SET data=\''.$data.'\' ,datacrc=\''.$crc.'\',expire='.$expire.' WHERE `cachekey`=\''.$name.'\''); + }else { + //新增记录 + $result = $this->handler->execute('INSERT INTO '.$this->options['table'].' (`cachekey`,`data`,`datacrc`,`expire`) VALUES (\''.$name.'\',\''.$data.'\',\''.$crc.'\','.$expire.')'); + } + if($result) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + }else { + return false; + } + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + $name = $this->options['prefix'].addslashes($name); + return $this->handler->execute('DELETE FROM `'.$this->options['table'].'` WHERE `cachekey`=\''.$name.'\''); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return $this->handler->execute('TRUNCATE TABLE `'.$this->options['table'].'`'); + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Cache/Driver/Eaccelerator.class.php b/ThinkPHP/Library/Think/Cache/Driver/Eaccelerator.class.php new file mode 100644 index 0000000..751ef24 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Eaccelerator.class.php @@ -0,0 +1,77 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Eaccelerator缓存驱动 + */ +class Eaccelerator extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + return eaccelerator_get($this->options['prefix'].$name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + eaccelerator_lock($name); + if(eaccelerator_put($name, $value, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return eaccelerator_rm($this->options['prefix'].$name); + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Cache/Driver/File.class.php b/ThinkPHP/Library/Think/Cache/Driver/File.class.php new file mode 100644 index 0000000..c5c64ef --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/File.class.php @@ -0,0 +1,181 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * 文件类型缓存类 + */ +class File extends Cache { + + /** + * 架构函数 + * @access public + */ + public function __construct($options=array()) { + if(!empty($options)) { + $this->options = $options; + } + $this->options['temp'] = !empty($options['temp'])? $options['temp'] : C('DATA_CACHE_PATH'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + if(substr($this->options['temp'], -1) != '/') $this->options['temp'] .= '/'; + $this->init(); + } + + /** + * 初始化检查 + * @access private + * @return boolean + */ + private function init() { + // 创建应用缓存目录 + if (!is_dir($this->options['temp'])) { + mkdir($this->options['temp']); + } + } + + /** + * 取得变量的存储文件名 + * @access private + * @param string $name 缓存变量名 + * @return string + */ + private function filename($name) { + $name = md5(C('DATA_CACHE_KEY').$name); + if(C('DATA_CACHE_SUBDIR')) { + // 使用子目录 + $dir =''; + for($i=0;$ioptions['temp'].$dir)) { + mkdir($this->options['temp'].$dir,0755,true); + } + $filename = $dir.$this->options['prefix'].$name.'.php'; + }else{ + $filename = $this->options['prefix'].$name.'.php'; + } + return $this->options['temp'].$filename; + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + $filename = $this->filename($name); + if (!is_file($filename)) { + return false; + } + N('cache_read',1); + $content = file_get_contents($filename); + if( false !== $content) { + $expire = (int)substr($content,8, 12); + if($expire != 0 && time() > filemtime($filename) + $expire) { + //缓存过期删除缓存文件 + unlink($filename); + return false; + } + if(C('DATA_CACHE_CHECK')) {//开启数据校验 + $check = substr($content,20, 32); + $content = substr($content,52, -3); + if($check != md5($content)) {//校验错误 + return false; + } + }else { + $content = substr($content,20, -3); + } + if(C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //启用数据压缩 + $content = gzuncompress($content); + } + $content = unserialize($content); + return $content; + } + else { + return false; + } + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param int $expire 有效时间 0为永久 + * @return boolean + */ + public function set($name,$value,$expire=null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $filename = $this->filename($name); + $data = serialize($value); + if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //数据压缩 + $data = gzcompress($data,3); + } + if(C('DATA_CACHE_CHECK')) {//开启数据校验 + $check = md5($data); + }else { + $check = ''; + } + $data = ""; + $result = file_put_contents($filename,$data); + if($result) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + clearstatcache(); + return true; + }else { + return false; + } + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return unlink($this->filename($name)); + } + + /** + * 清除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function clear() { + $path = $this->options['temp']; + $files = scandir($path); + if($files){ + foreach($files as $file){ + if ($file != '.' && $file != '..' && is_dir($path.$file) ){ + array_map( 'unlink', glob( $path.$file.'/*.*' ) ); + }elseif(is_file($path.$file)){ + unlink( $path . $file ); + } + } + return true; + } + return false; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Cache/Driver/Memcache.class.php b/ThinkPHP/Library/Think/Cache/Driver/Memcache.class.php new file mode 100644 index 0000000..ff53ebe --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Memcache.class.php @@ -0,0 +1,103 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Memcache缓存驱动 + */ +class Memcache extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + function __construct($options=array()) { + if ( !extension_loaded('memcache') ) { + E(L('_NOT_SUPPORT_').':memcache'); + } + + $options = array_merge(array ( + 'host' => C('MEMCACHE_HOST') ? : '127.0.0.1', + 'port' => C('MEMCACHE_PORT') ? : 11211, + 'timeout' => C('DATA_CACHE_TIMEOUT') ? : false, + 'persistent' => false, + ),$options); + + $this->options = $options; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $func = $options['persistent'] ? 'pconnect' : 'connect'; + $this->handler = new \Memcache; + $options['timeout'] === false ? + $this->handler->$func($options['host'], $options['port']) : + $this->handler->$func($options['host'], $options['port'], $options['timeout']); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + return $this->handler->get($this->options['prefix'].$name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + if($this->handler->set($name, $value, 0, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name, $ttl = false) { + $name = $this->options['prefix'].$name; + return $ttl === false ? + $this->handler->delete($name) : + $this->handler->delete($name, $ttl); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return $this->handler->flush(); + } +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Memcached.class.php b/ThinkPHP/Library/Think/Cache/Driver/Memcached.class.php new file mode 100644 index 0000000..929bdca --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Memcached.class.php @@ -0,0 +1,102 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Cache\Driver; + +use Memcached as MemcachedResource; +use Think\Cache; + +/** + * Memcached缓存驱动 + */ +class Memcached extends Cache { + + /** + * + * @param array $options + */ + public function __construct($options = array()) { + if ( !extension_loaded('memcached') ) { + E(L('_NOT_SUPPORT_').':memcached'); + } + + $options = array_merge(array( + 'servers' => C('MEMCACHED_SERVER') ? : null, + 'lib_options' => C('MEMCACHED_LIB') ? : null + ), $options); + + $this->options = $options; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + + $this->handler = new MemcachedResource; + $options['servers'] && $this->handler->addServers($options['servers']); + $options['lib_options'] && $this->handler->setOptions($options['lib_options']); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + return $this->handler->get($this->options['prefix'].$name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + if($this->handler->set($name, $value, time() + $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name, $ttl = false) { + $name = $this->options['prefix'].$name; + return $ttl === false ? + $this->handler->delete($name) : + $this->handler->delete($name, $ttl); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return $this->handler->flush(); + } +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Memcachesae.class.php b/ThinkPHP/Library/Think/Cache/Driver/Memcachesae.class.php new file mode 100644 index 0000000..a1d1c56 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Memcachesae.class.php @@ -0,0 +1,144 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; + +defined('THINK_PATH') or exit(); +/** + * Memcache缓存驱动 + * @category Extend + * @package Extend + * @subpackage Driver.Cache + * @author liu21st + */ +class Memcachesae extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + function __construct($options=array()) { + $options = array_merge(array ( + 'host' => C('MEMCACHE_HOST') ? : '127.0.0.1', + 'port' => C('MEMCACHE_PORT') ? : 11211, + 'timeout' => C('DATA_CACHE_TIMEOUT') ? : false, + 'persistent' => false, + ),$options); + + $this->options = $options; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->handler = memcache_init();//[sae] 下实例化 + //[sae] 下不用链接 + $this->connected=true; + } + + /** + * 是否连接 + * @access private + * @return boolean + */ + private function isConnected() { + return $this->connected; + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + return $this->handler->get($_SERVER['HTTP_APPVERSION'].'/'.$this->options['prefix'].$name); + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + if($this->handler->set($_SERVER['HTTP_APPVERSION'].'/'.$name, $value, 0, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name, $ttl = false) { + $name = $_SERVER['HTTP_APPVERSION'].'/'.$this->options['prefix'].$name; + return $ttl === false ? + $this->handler->delete($name) : + $this->handler->delete($name, $ttl); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return $this->handler->flush(); + } + + /** + * 队列缓存 + * @access protected + * @param string $key 队列名 + * @return mixed + */ + //[sae] 下重写queque队列缓存方法 + protected function queue($key) { + $queue_name=isset($this->options['queue_name'])?$this->options['queue_name']:'think_queue'; + $value = F($queue_name); + if(!$value) { + $value = array(); + } + // 进列 + if(false===array_search($key, $value)) array_push($value,$key); + if(count($value) > $this->options['length']) { + // 出列 + $key = array_shift($value); + // 删除缓存 + $this->rm($key); + if (APP_DEBUG) { + //调试模式下记录出队次数 + $counter = Think::instance('SaeCounter'); + if ($counter->exists($queue_name.'_out_times')) + $counter->incr($queue_name.'_out_times'); + else + $counter->create($queue_name.'_out_times', 1); + } + } + return F($queue_name,$value); + } + +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Redis.class.php b/ThinkPHP/Library/Think/Cache/Driver/Redis.class.php new file mode 100644 index 0000000..132cefb --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Redis.class.php @@ -0,0 +1,107 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); + +/** + * Redis缓存驱动 + * 要求安装phpredis扩展:https://github.com/nicolasff/phpredis + */ +class Redis extends Cache { + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if ( !extension_loaded('redis') ) { + E(L('_NOT_SUPPORT_').':redis'); + } + $options = array_merge(array ( + 'host' => C('REDIS_HOST') ? : '127.0.0.1', + 'port' => C('REDIS_PORT') ? : 6379, + 'timeout' => C('DATA_CACHE_TIMEOUT') ? : false, + 'persistent' => false, + ),$options); + + $this->options = $options; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $func = $options['persistent'] ? 'pconnect' : 'connect'; + $this->handler = new \Redis; + $options['timeout'] === false ? + $this->handler->$func($options['host'], $options['port']) : + $this->handler->$func($options['host'], $options['port'], $options['timeout']); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + $value = $this->handler->get($this->options['prefix'].$name); + $jsonData = json_decode( $value, true ); + return ($jsonData === NULL) ? $value : $jsonData; //检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value, $expire = null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + //对数组/对象数据进行缓存处理,保证数据完整性 + $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; + if(is_int($expire) && $expire) { + $result = $this->handler->setex($name, $expire, $value); + }else{ + $result = $this->handler->set($name, $value); + } + if($result && $this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return $result; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return $this->handler->delete($this->options['prefix'].$name); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return $this->handler->flushDB(); + } + +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Shmop.class.php b/ThinkPHP/Library/Think/Cache/Driver/Shmop.class.php new file mode 100644 index 0000000..60927c3 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Shmop.class.php @@ -0,0 +1,186 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Shmop缓存驱动 + */ +class Shmop extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if ( !extension_loaded('shmop') ) { + E(L('_NOT_SUPPORT_').':shmop'); + } + if(!empty($options)){ + $options = array( + 'size' => C('SHARE_MEM_SIZE'), + 'temp' => TEMP_PATH, + 'project' => 's', + 'length' => 0, + ); + } + $this->options = $options; + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->handler = $this->_ftok($this->options['project']); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name = false) { + N('cache_read',1); + $id = shmop_open($this->handler, 'c', 0600, 0); + if ($id !== false) { + $ret = unserialize(shmop_read($id, 0, shmop_size($id))); + shmop_close($id); + + if ($name === false) { + return $ret; + } + $name = $this->options['prefix'].$name; + if(isset($ret[$name])) { + $content = $ret[$name]; + if(C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //启用数据压缩 + $content = gzuncompress($content); + } + return $content; + }else { + return null; + } + }else { + return false; + } + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @return boolean + */ + public function set($name, $value) { + N('cache_write',1); + $lh = $this->_lock(); + $val = $this->get(); + if (!is_array($val)) $val = array(); + if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //数据压缩 + $value = gzcompress($value,3); + } + $name = $this->options['prefix'].$name; + $val[$name] = $value; + $val = serialize($val); + if($this->_write($val, $lh)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + $lh = $this->_lock(); + $val = $this->get(); + if (!is_array($val)) $val = array(); + $name = $this->options['prefix'].$name; + unset($val[$name]); + $val = serialize($val); + return $this->_write($val, $lh); + } + + /** + * 生成IPC key + * @access private + * @param string $project 项目标识名 + * @return integer + */ + private function _ftok($project) { + if (function_exists('ftok')) return ftok(__FILE__, $project); + if(strtoupper(PHP_OS) == 'WINNT'){ + $s = stat(__FILE__); + return sprintf("%u", (($s['ino'] & 0xffff) | (($s['dev'] & 0xff) << 16) | + (($project & 0xff) << 24))); + }else { + $filename = __FILE__ . (string) $project; + for($key = array(); sizeof($key) < strlen($filename); $key[] = ord(substr($filename, sizeof($key), 1))); + return dechex(array_sum($key)); + } + } + + /** + * 写入操作 + * @access private + * @param string $name 缓存变量名 + * @return integer|boolean + */ + private function _write(&$val, &$lh) { + $id = shmop_open($this->handler, 'c', 0600, $this->options['size']); + if ($id) { + $ret = shmop_write($id, $val, 0) == strlen($val); + shmop_close($id); + $this->_unlock($lh); + return $ret; + } + $this->_unlock($lh); + return false; + } + + /** + * 共享锁定 + * @access private + * @param string $name 缓存变量名 + * @return boolean + */ + private function _lock() { + if (function_exists('sem_get')) { + $fp = sem_get($this->handler, 1, 0600, 1); + sem_acquire ($fp); + } else { + $fp = fopen($this->options['temp'].$this->options['prefix'].md5($this->handler), 'w'); + flock($fp, LOCK_EX); + } + return $fp; + } + + /** + * 解除共享锁定 + * @access private + * @param string $name 缓存变量名 + * @return boolean + */ + private function _unlock(&$fp) { + if (function_exists('sem_release')) { + sem_release($fp); + } else { + fclose($fp); + } + } +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Sqlite.class.php b/ThinkPHP/Library/Think/Cache/Driver/Sqlite.class.php new file mode 100644 index 0000000..33bd222 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Sqlite.class.php @@ -0,0 +1,119 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Sqlite缓存驱动 + */ +class Sqlite extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if ( !extension_loaded('sqlite') ) { + E(L('_NOT_SUPPORT_').':sqlite'); + } + if(empty($options)) { + $options = array ( + 'db' => ':memory:', + 'table' => 'sharedmemory', + ); + } + $this->options = $options; + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + + $func = $this->options['persistent'] ? 'sqlite_popen' : 'sqlite_open'; + $this->handler = $func($this->options['db']); + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + $name = $this->options['prefix'].sqlite_escape_string($name); + $sql = 'SELECT value FROM '.$this->options['table'].' WHERE var=\''.$name.'\' AND (expire=0 OR expire >'.time().') LIMIT 1'; + $result = sqlite_query($this->handler, $sql); + if (sqlite_num_rows($result)) { + $content = sqlite_fetch_single($result); + if(C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //启用数据压缩 + $content = gzuncompress($content); + } + return unserialize($content); + } + return false; + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value,$expire=null) { + N('cache_write',1); + $name = $this->options['prefix'].sqlite_escape_string($name); + $value = sqlite_escape_string(serialize($value)); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $expire = ($expire==0)?0: (time()+$expire) ;//缓存有效期为0表示永久缓存 + if( C('DATA_CACHE_COMPRESS') && function_exists('gzcompress')) { + //数据压缩 + $value = gzcompress($value,3); + } + $sql = 'REPLACE INTO '.$this->options['table'].' (var, value,expire) VALUES (\''.$name.'\', \''.$value.'\', \''.$expire.'\')'; + if(sqlite_query($this->handler, $sql)){ + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + $name = $this->options['prefix'].sqlite_escape_string($name); + $sql = 'DELETE FROM '.$this->options['table'].' WHERE var=\''.$name.'\''; + sqlite_query($this->handler, $sql); + return true; + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + $sql = 'DELETE FROM '.$this->options['table']; + sqlite_query($this->handler, $sql); + return ; + } +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Wincache.class.php b/ThinkPHP/Library/Think/Cache/Driver/Wincache.class.php new file mode 100644 index 0000000..9d118e9 --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Wincache.class.php @@ -0,0 +1,88 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Wincache缓存驱动 + */ +class Wincache extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if ( !function_exists('wincache_ucache_info') ) { + E(L('_NOT_SUPPORT_').':WinCache'); + } + $this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])? $options['length'] : 0; + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + $name = $this->options['prefix'].$name; + return wincache_ucache_exists($name)? wincache_ucache_get($name) : false; + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value,$expire=null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire']; + } + $name = $this->options['prefix'].$name; + if(wincache_ucache_set($name, $value, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return wincache_ucache_delete($this->options['prefix'].$name); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return wincache_ucache_clear(); + } + +} diff --git a/ThinkPHP/Library/Think/Cache/Driver/Xcache.class.php b/ThinkPHP/Library/Think/Cache/Driver/Xcache.class.php new file mode 100644 index 0000000..ccb1fdd --- /dev/null +++ b/ThinkPHP/Library/Think/Cache/Driver/Xcache.class.php @@ -0,0 +1,90 @@ + +// +---------------------------------------------------------------------- +namespace Think\Cache\Driver; +use Think\Cache; +defined('THINK_PATH') or exit(); +/** + * Xcache缓存驱动 + */ +class Xcache extends Cache { + + /** + * 架构函数 + * @param array $options 缓存参数 + * @access public + */ + public function __construct($options=array()) { + if ( !function_exists('xcache_info') ) { + E(L('_NOT_SUPPORT_').':Xcache'); + } + $this->options['expire'] = isset($options['expire'])?$options['expire']:C('DATA_CACHE_TIME'); + $this->options['prefix'] = isset($options['prefix'])?$options['prefix']:C('DATA_CACHE_PREFIX'); + $this->options['length'] = isset($options['length'])?$options['length']:0; + } + + /** + * 读取缓存 + * @access public + * @param string $name 缓存变量名 + * @return mixed + */ + public function get($name) { + N('cache_read',1); + $name = $this->options['prefix'].$name; + if (xcache_isset($name)) { + return xcache_get($name); + } + return false; + } + + /** + * 写入缓存 + * @access public + * @param string $name 缓存变量名 + * @param mixed $value 存储数据 + * @param integer $expire 有效时间(秒) + * @return boolean + */ + public function set($name, $value,$expire=null) { + N('cache_write',1); + if(is_null($expire)) { + $expire = $this->options['expire'] ; + } + $name = $this->options['prefix'].$name; + if(xcache_set($name, $value, $expire)) { + if($this->options['length']>0) { + // 记录缓存队列 + $this->queue($name); + } + return true; + } + return false; + } + + /** + * 删除缓存 + * @access public + * @param string $name 缓存变量名 + * @return boolean + */ + public function rm($name) { + return xcache_unset($this->options['prefix'].$name); + } + + /** + * 清除缓存 + * @access public + * @return boolean + */ + public function clear() { + return xcache_clear_cache(1, -1); + } +} diff --git a/ThinkPHP/Library/Think/Controller.class.php b/ThinkPHP/Library/Think/Controller.class.php new file mode 100644 index 0000000..ce0f2a1 --- /dev/null +++ b/ThinkPHP/Library/Think/Controller.class.php @@ -0,0 +1,307 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP 控制器基类 抽象类 + */ +abstract class Controller { + + /** + * 视图实例对象 + * @var view + * @access protected + */ + protected $view = null; + + /** + * 控制器参数 + * @var config + * @access protected + */ + protected $config = array(); + + /** + * 架构函数 取得模板对象实例 + * @access public + */ + public function __construct() { + Hook::listen('action_begin',$this->config); + //实例化视图类 + $this->view = Think::instance('Think\View'); + //控制器初始化 + if(method_exists($this,'_initialize')) + $this->_initialize(); + } + + /** + * 模板显示 调用内置的模板引擎显示方法, + * @access protected + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @param string $charset 输出编码 + * @param string $contentType 输出类型 + * @param string $content 输出内容 + * @param string $prefix 模板缓存前缀 + * @return void + */ + protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') { + $this->view->display($templateFile,$charset,$contentType,$content,$prefix); + } + + /** + * 输出内容文本可以包括Html 并支持内容解析 + * @access protected + * @param string $content 输出内容 + * @param string $charset 模板输出字符集 + * @param string $contentType 输出类型 + * @param string $prefix 模板缓存前缀 + * @return mixed + */ + protected function show($content,$charset='',$contentType='',$prefix='') { + $this->view->display('',$charset,$contentType,$content,$prefix); + } + + /** + * 获取输出页面内容 + * 调用内置的模板引擎fetch方法, + * @access protected + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @param string $content 模板输出内容 + * @param string $prefix 模板缓存前缀* + * @return string + */ + protected function fetch($templateFile='',$content='',$prefix='') { + return $this->view->fetch($templateFile,$content,$prefix); + } + + /** + * 创建静态页面 + * @access protected + * @htmlfile 生成的静态文件名称 + * @htmlpath 生成的静态文件路径 + * @param string $templateFile 指定要调用的模板文件 + * 默认为空 由系统自动定位模板文件 + * @return string + */ + protected function buildHtml($htmlfile='',$htmlpath='',$templateFile='') { + $content = $this->fetch($templateFile); + $htmlpath = !empty($htmlpath)?$htmlpath:HTML_PATH; + $htmlfile = $htmlpath.$htmlfile.C('HTML_FILE_SUFFIX'); + Storage::put($htmlfile,$content,'html'); + return $content; + } + + /** + * 模板主题设置 + * @access protected + * @param string $theme 模版主题 + * @return Action + */ + protected function theme($theme){ + $this->view->theme($theme); + return $this; + } + + /** + * 模板变量赋值 + * @access protected + * @param mixed $name 要显示的模板变量 + * @param mixed $value 变量的值 + * @return Action + */ + protected function assign($name,$value='') { + $this->view->assign($name,$value); + return $this; + } + + public function __set($name,$value) { + $this->assign($name,$value); + } + + /** + * 取得模板显示变量的值 + * @access protected + * @param string $name 模板显示变量 + * @return mixed + */ + public function get($name='') { + return $this->view->get($name); + } + + public function __get($name) { + return $this->get($name); + } + + /** + * 检测模板变量的值 + * @access public + * @param string $name 名称 + * @return boolean + */ + public function __isset($name) { + return $this->get($name); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args) { + if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) { + if(method_exists($this,'_empty')) { + // 如果定义了_empty操作 则调用 + $this->_empty($method,$args); + }elseif(file_exists_case($this->view->parseTemplate())){ + // 检查是否存在默认模版 如果有直接输出模版 + $this->display(); + }else{ + E(L('_ERROR_ACTION_').':'.ACTION_NAME); + } + }else{ + E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); + return; + } + } + + /** + * 操作错误跳转的快捷方法 + * @access protected + * @param string $message 错误信息 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @return void + */ + protected function error($message='',$jumpUrl='',$ajax=false) { + $this->dispatchJump($message,0,$jumpUrl,$ajax); + } + + /** + * 操作成功跳转的快捷方法 + * @access protected + * @param string $message 提示信息 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @return void + */ + protected function success($message='',$jumpUrl='',$ajax=false) { + $this->dispatchJump($message,1,$jumpUrl,$ajax); + } + + /** + * Ajax方式返回数据到客户端 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type AJAX返回数据格式 + * @param int $json_option 传递给json_encode的option参数 + * @return void + */ + protected function ajaxReturn($data,$type='',$json_option=0) { + if(empty($type)) $type = C('DEFAULT_AJAX_RETURN'); + switch (strtoupper($type)){ + case 'JSON' : + // 返回JSON数据格式到客户端 包含状态信息 + header('Content-Type:application/json; charset=utf-8'); + exit(json_encode($data,$json_option)); + case 'XML' : + // 返回xml格式数据 + header('Content-Type:text/xml; charset=utf-8'); + exit(xml_encode($data)); + case 'JSONP': + // 返回JSON数据格式到客户端 包含状态信息 + header('Content-Type:application/json; charset=utf-8'); + $handler = isset($_GET[C('VAR_JSONP_HANDLER')]) ? $_GET[C('VAR_JSONP_HANDLER')] : C('DEFAULT_JSONP_HANDLER'); + exit($handler.'('.json_encode($data,$json_option).');'); + case 'EVAL' : + // 返回可执行的js脚本 + header('Content-Type:text/html; charset=utf-8'); + exit($data); + default : + // 用于扩展其他返回格式数据 + Hook::listen('ajax_return',$data); + } + } + + /** + * Action跳转(URL重定向) 支持指定模块和延时跳转 + * @access protected + * @param string $url 跳转的URL表达式 + * @param array $params 其它URL参数 + * @param integer $delay 延时跳转的时间 单位为秒 + * @param string $msg 跳转提示信息 + * @return void + */ + protected function redirect($url,$params=array(),$delay=0,$msg='') { + $url = U($url,$params); + redirect($url,$delay,$msg); + } + + /** + * 默认跳转操作 支持错误导向和正确跳转 + * 调用模板显示 默认为public目录下面的success页面 + * 提示页面为可配置 支持模板标签 + * @param string $message 提示信息 + * @param Boolean $status 状态 + * @param string $jumpUrl 页面跳转地址 + * @param mixed $ajax 是否为Ajax方式 当数字时指定跳转时间 + * @access private + * @return void + */ + private function dispatchJump($message,$status=1,$jumpUrl='',$ajax=false) { + if(true === $ajax || IS_AJAX) {// AJAX提交 + $data = is_array($ajax)?$ajax:array(); + $data['info'] = $message; + $data['status'] = $status; + $data['url'] = $jumpUrl; + $this->ajaxReturn($data); + } + if(is_int($ajax)) $this->assign('waitSecond',$ajax); + if(!empty($jumpUrl)) $this->assign('jumpUrl',$jumpUrl); + // 提示标题 + $this->assign('msgTitle',$status? L('_OPERATION_SUCCESS_') : L('_OPERATION_FAIL_')); + //如果设置了关闭窗口,则提示完毕后自动关闭窗口 + if($this->get('closeWin')) $this->assign('jumpUrl','javascript:window.close();'); + $this->assign('status',$status); // 状态 + //保证输出不受静态缓存影响 + C('HTML_CACHE_ON',false); + if($status) { //发送成功信息 + $this->assign('message',$message);// 提示信息 + // 成功操作后默认停留1秒 + if(!isset($this->waitSecond)) $this->assign('waitSecond','1'); + // 默认操作成功自动返回操作前页面 + if(!isset($this->jumpUrl)) $this->assign("jumpUrl",$_SERVER["HTTP_REFERER"]); + $this->display(C('TMPL_ACTION_SUCCESS')); + }else{ + $this->assign('error',$message);// 提示信息 + //发生错误时候默认停留3秒 + if(!isset($this->waitSecond)) $this->assign('waitSecond','3'); + // 默认发生错误的话自动返回上页 + if(!isset($this->jumpUrl)) $this->assign('jumpUrl',"javascript:history.back(-1);"); + $this->display(C('TMPL_ACTION_ERROR')); + // 中止执行 避免出错后继续执行 + exit ; + } + } + + /** + * 析构方法 + * @access public + */ + public function __destruct() { + // 执行后续操作 + Hook::listen('action_end'); + } +} +// 设置控制器别名 便于升级 +class_alias('Think\Controller','Think\Action'); diff --git a/ThinkPHP/Library/Think/Controller/HproseController.class.php b/ThinkPHP/Library/Think/Controller/HproseController.class.php new file mode 100644 index 0000000..88d3a1c --- /dev/null +++ b/ThinkPHP/Library/Think/Controller/HproseController.class.php @@ -0,0 +1,61 @@ + +// +---------------------------------------------------------------------- +namespace Think\Controller; +/** + * ThinkPHP Hprose控制器类 + */ +class HproseController { + + protected $allowMethodList = ''; + protected $crossDomain = false; + protected $P3P = false; + protected $get = true; + protected $debug = false; + + /** + * 架构函数 + * @access public + */ + public function __construct() { + //控制器初始化 + if(method_exists($this,'_initialize')) + $this->_initialize(); + //导入类库 + Vendor('Hprose.HproseHttpServer'); + //实例化HproseHttpServer + $server = new \HproseHttpServer(); + if($this->allowMethodList){ + $methods = $this->allowMethodList; + }else{ + $methods = get_class_methods($this); + $methods = array_diff($methods,array('__construct','__call','_initialize')); + } + $server->addMethods($methods,$this); + if(APP_DEBUG || $this->debug ) { + $server->setDebugEnabled(true); + } + // Hprose设置 + $server->setCrossDomainEnabled($this->crossDomain); + $server->setP3PEnabled($this->P3P); + $server->setGetEnabled($this->get); + // 启动server + $server->start(); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args){} +} diff --git a/ThinkPHP/Library/Think/Controller/JsonRpcController.class.php b/ThinkPHP/Library/Think/Controller/JsonRpcController.class.php new file mode 100644 index 0000000..a73ca5c --- /dev/null +++ b/ThinkPHP/Library/Think/Controller/JsonRpcController.class.php @@ -0,0 +1,39 @@ + +// +---------------------------------------------------------------------- +namespace Think\Controller; +/** + * ThinkPHP JsonRPC控制器类 + */ +class JsonRpcController { + + /** + * 架构函数 + * @access public + */ + public function __construct() { + //控制器初始化 + if(method_exists($this,'_initialize')) + $this->_initialize(); + //导入类库 + Vendor('jsonRPC.jsonRPCServer'); + // 启动server + \jsonRPCServer::handle($this); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args){} +} diff --git a/ThinkPHP/Library/Think/Controller/RestController.class.php b/ThinkPHP/Library/Think/Controller/RestController.class.php new file mode 100644 index 0000000..2a62662 --- /dev/null +++ b/ThinkPHP/Library/Think/Controller/RestController.class.php @@ -0,0 +1,234 @@ + +// +---------------------------------------------------------------------- +namespace Think\Controller; +use Think\Controller; +use Think\App; +/** + * ThinkPHP REST控制器类 + */ +class RestController extends Controller { + // 当前请求类型 + protected $_method = ''; + // 当前请求的资源类型 + protected $_type = ''; + // REST允许的请求类型列表 + protected $allowMethod = array('get','post','put','delete'); + // REST默认请求类型 + protected $defaultMethod = 'get'; + // REST允许请求的资源类型列表 + protected $allowType = array('html','xml','json','rss'); + // 默认的资源类型 + protected $defaultType = 'html'; + // REST允许输出的资源类型列表 + protected $allowOutputType= array( + 'xml' => 'application/xml', + 'json' => 'application/json', + 'html' => 'text/html', + ); + + /** + * 架构函数 + * @access public + */ + public function __construct() { + // 资源类型检测 + if(''==__EXT__) { // 自动检测资源类型 + $this->_type = $this->getAcceptType(); + }elseif(!in_array(__EXT__,$this->allowType)) { + // 资源类型非法 则用默认资源类型访问 + $this->_type = $this->defaultType; + }else{ + $this->_type = __EXT__ ; + } + + // 请求方式检测 + $method = strtolower(REQUEST_METHOD); + if(!in_array($method,$this->allowMethod)) { + // 请求方式非法 则用默认请求方法 + $method = $this->defaultMethod; + } + $this->_method = $method; + + parent::__construct(); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args) { + if( 0 === strcasecmp($method,ACTION_NAME.C('ACTION_SUFFIX'))) { + if(method_exists($this,$method.'_'.$this->_method.'_'.$this->_type)) { // RESTFul方法支持 + $fun = $method.'_'.$this->_method.'_'.$this->_type; + App::invokeAction($this,$fun); + }elseif($this->_method == $this->defaultMethod && method_exists($this,$method.'_'.$this->_type) ){ + $fun = $method.'_'.$this->_type; + App::invokeAction($this,$fun); + }elseif($this->_type == $this->defaultType && method_exists($this,$method.'_'.$this->_method) ){ + $fun = $method.'_'.$this->_method; + App::invokeAction($this,$fun); + }elseif(method_exists($this,'_empty')) { + // 如果定义了_empty操作 则调用 + $this->_empty($method,$args); + }elseif(file_exists_case($this->view->parseTemplate())){ + // 检查是否存在默认模版 如果有直接输出模版 + $this->display(); + }else{ + E(L('_ERROR_ACTION_').':'.ACTION_NAME); + } + } + } + + /** + * 获取当前请求的Accept头信息 + * @return string + */ + protected function getAcceptType(){ + $type = array( + 'xml' => 'application/xml,text/xml,application/x-xml', + 'json' => 'application/json,text/x-json,application/jsonrequest,text/json', + 'js' => 'text/javascript,application/javascript,application/x-javascript', + 'css' => 'text/css', + 'rss' => 'application/rss+xml', + 'yaml' => 'application/x-yaml,text/yaml', + 'atom' => 'application/atom+xml', + 'pdf' => 'application/pdf', + 'text' => 'text/plain', + 'png' => 'image/png', + 'jpg' => 'image/jpg,image/jpeg,image/pjpeg', + 'gif' => 'image/gif', + 'csv' => 'text/csv', + 'html' => 'text/html,application/xhtml+xml,*/*' + ); + + foreach($type as $key=>$val){ + $array = explode(',',$val); + foreach($array as $k=>$v){ + if(stristr($_SERVER['HTTP_ACCEPT'], $v)) { + return $key; + } + } + } + return false; + } + + // 发送Http状态信息 + protected function sendHttpStatus($code) { + static $_status = array( + // Informational 1xx + 100 => 'Continue', + 101 => 'Switching Protocols', + // Success 2xx + 200 => 'OK', + 201 => 'Created', + 202 => 'Accepted', + 203 => 'Non-Authoritative Information', + 204 => 'No Content', + 205 => 'Reset Content', + 206 => 'Partial Content', + // Redirection 3xx + 300 => 'Multiple Choices', + 301 => 'Moved Permanently', + 302 => 'Moved Temporarily ', // 1.1 + 303 => 'See Other', + 304 => 'Not Modified', + 305 => 'Use Proxy', + // 306 is deprecated but reserved + 307 => 'Temporary Redirect', + // Client Error 4xx + 400 => 'Bad Request', + 401 => 'Unauthorized', + 402 => 'Payment Required', + 403 => 'Forbidden', + 404 => 'Not Found', + 405 => 'Method Not Allowed', + 406 => 'Not Acceptable', + 407 => 'Proxy Authentication Required', + 408 => 'Request Timeout', + 409 => 'Conflict', + 410 => 'Gone', + 411 => 'Length Required', + 412 => 'Precondition Failed', + 413 => 'Request Entity Too Large', + 414 => 'Request-URI Too Long', + 415 => 'Unsupported Media Type', + 416 => 'Requested Range Not Satisfiable', + 417 => 'Expectation Failed', + // Server Error 5xx + 500 => 'Internal Server Error', + 501 => 'Not Implemented', + 502 => 'Bad Gateway', + 503 => 'Service Unavailable', + 504 => 'Gateway Timeout', + 505 => 'HTTP Version Not Supported', + 509 => 'Bandwidth Limit Exceeded' + ); + if(isset($_status[$code])) { + header('HTTP/1.1 '.$code.' '.$_status[$code]); + // 确保FastCGI模式下正常 + header('Status:'.$code.' '.$_status[$code]); + } + } + + /** + * 编码数据 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type 返回类型 JSON XML + * @return string + */ + protected function encodeData($data,$type='') { + if(empty($data)) return ''; + if('json' == $type) { + // 返回JSON数据格式到客户端 包含状态信息 + $data = json_encode($data); + }elseif('xml' == $type){ + // 返回xml格式数据 + $data = xml_encode($data); + }elseif('php'==$type){ + $data = serialize($data); + }// 默认直接输出 + $this->setContentType($type); + //header('Content-Length: ' . strlen($data)); + return $data; + } + + /** + * 设置页面输出的CONTENT_TYPE和编码 + * @access public + * @param string $type content_type 类型对应的扩展名 + * @param string $charset 页面输出编码 + * @return void + */ + public function setContentType($type, $charset=''){ + if(headers_sent()) return; + if(empty($charset)) $charset = C('DEFAULT_CHARSET'); + $type = strtolower($type); + if(isset($this->allowOutputType[$type])) //过滤content_type + header('Content-Type: '.$this->allowOutputType[$type].'; charset='.$charset); + } + + /** + * 输出返回数据 + * @access protected + * @param mixed $data 要返回的数据 + * @param String $type 返回类型 JSON XML + * @param integer $code HTTP状态 + * @return void + */ + protected function response($data,$type='',$code=200) { + $this->sendHttpStatus($code); + exit($this->encodeData($data,strtolower($type))); + } +} diff --git a/ThinkPHP/Library/Think/Controller/RpcController.class.php b/ThinkPHP/Library/Think/Controller/RpcController.class.php new file mode 100644 index 0000000..737e737 --- /dev/null +++ b/ThinkPHP/Library/Think/Controller/RpcController.class.php @@ -0,0 +1,56 @@ + +// +---------------------------------------------------------------------- +namespace Think\Controller; +/** + * ThinkPHP RPC控制器类 + */ +class RpcController { + + protected $allowMethodList = ''; + protected $debug = false; + + /** + * 架构函数 + * @access public + */ + public function __construct() { + //控制器初始化 + if(method_exists($this,'_initialize')) + $this->_initialize(); + //导入类库 + Vendor('phpRPC.phprpc_server'); + //实例化phprpc + $server = new \PHPRPC_Server(); + if($this->allowMethodList){ + $methods = $this->allowMethodList; + }else{ + $methods = get_class_methods($this); + $methods = array_diff($methods,array('__construct','__call','_initialize')); + } + $server->add($methods,$this); + + if(APP_DEBUG || $this->debug ) { + $server->setDebugMode(true); + } + $server->setEnableGZIP(true); + $server->start(); + echo $server->comment(); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args){} +} diff --git a/ThinkPHP/Library/Think/Controller/YarController.class.php b/ThinkPHP/Library/Think/Controller/YarController.class.php new file mode 100644 index 0000000..40245b4 --- /dev/null +++ b/ThinkPHP/Library/Think/Controller/YarController.class.php @@ -0,0 +1,42 @@ + +// +---------------------------------------------------------------------- +namespace Think\Controller; +/** + * ThinkPHP Yar控制器类 + */ +class YarController { + + /** + * 架构函数 + * @access public + */ + public function __construct() { + //控制器初始化 + if(method_exists($this,'_initialize')) + $this->_initialize(); + //判断扩展是否存在 + if(!extension_loaded('yar')) + E(L('_NOT_SUPPORT_').':yar'); + //实例化Yar_Server + $server = new \Yar_Server($this); + // 启动server + $server->handle(); + } + + /** + * 魔术方法 有不存在的操作的时候执行 + * @access public + * @param string $method 方法名 + * @param array $args 参数 + * @return mixed + */ + public function __call($method,$args){} +} diff --git a/ThinkPHP/Library/Think/Crypt.class.php b/ThinkPHP/Library/Think/Crypt.class.php new file mode 100644 index 0000000..ee7bafa --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt.class.php @@ -0,0 +1,53 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * 加密解密类 + */ +class Crypt { + + private static $handler = ''; + + public static function init($type=''){ + $type = $type?:C('DATA_CRYPT_TYPE'); + $class = strpos($type,'\\')? $type: 'Think\\Crypt\\Driver\\'. ucwords(strtolower($type)); + self::$handler = $class; + } + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) 0 为永久有效 + * @return string + */ + public static function encrypt($data,$key,$expire=0){ + if(empty(self::$handler)){ + self::init(); + } + $class = self::$handler; + return $class::encrypt($data,$key,$expire); + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($data,$key){ + if(empty(self::$handler)){ + self::init(); + } + $class = self::$handler; + return $class::decrypt($data,$key); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Crypt/Driver/Base64.class.php b/ThinkPHP/Library/Think/Crypt/Driver/Base64.class.php new file mode 100644 index 0000000..44f6014 --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt/Driver/Base64.class.php @@ -0,0 +1,74 @@ + +// +---------------------------------------------------------------------- +namespace Think\Crypt\Driver; +/** + * Base64 加密实现类 + */ +class Base64 { + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) + * @return string + */ + public static function encrypt($data,$key,$expire=0) { + $expire = sprintf('%010d', $expire ? $expire + time():0); + $key = md5($key); + $data = base64_encode($expire.$data); + $x=0; + $len = strlen($data); + $l = strlen($key); + for ($i=0;$i< $len;$i++) { + if ($x== $l) $x=0; + $char .=substr($key,$x,1); + $x++; + } + + for ($i=0;$i< $len;$i++) { + $str .=chr(ord(substr($data,$i,1))+(ord(substr($char,$i,1)))%256); + } + return $str; + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($data,$key) { + $key = md5($key); + $x=0; + $len = strlen($data); + $l = strlen($key); + for ($i=0;$i< $len;$i++) { + if ($x== $l) $x=0; + $char .=substr($key,$x,1); + $x++; + } + for ($i=0;$i< $len;$i++) { + if (ord(substr($data,$i,1)) 0 && $expire < time()) { + return ''; + } + $data = substr($data,10); + return $data; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Crypt/Driver/Crypt.class.php b/ThinkPHP/Library/Think/Crypt/Driver/Crypt.class.php new file mode 100644 index 0000000..382425f --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt/Driver/Crypt.class.php @@ -0,0 +1,83 @@ + +// +---------------------------------------------------------------------- +namespace Think\Crypt\Driver; +/** + * Crypt 加密实现类 + * @category ORG + * @package ORG + * @subpackage Crypt + * @author liu21st + */ +class Crypt { + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) + * @return string + */ + public static function encrypt($str,$key,$expire=0){ + $expire = sprintf('%010d', $expire ? $expire + time():0); + $r = md5($key); + $c = 0; + $v = ""; + $str = $expire.$str; + $len = strlen($str); + $l = strlen($r); + for ($i=0;$i<$len;$i++){ + if ($c== $l) $c=0; + $v .= substr($r,$c,1) . + (substr($str,$i,1) ^ substr($r,$c,1)); + $c++; + } + return self::ed($v,$key); + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($str,$key) { + $str = self::ed($str,$key); + $v = ""; + $len = strlen($str); + for ($i=0;$i<$len;$i++){ + $md5 = substr($str,$i,1); + $i++; + $v .= (substr($str,$i,1) ^ $md5); + } + $data = $v; + $expire = substr($data,0,10); + if($expire > 0 && $expire < time()) { + return ''; + } + $data = substr($data,10); + return $data; + } + + + static private function ed($str,$key) { + $r = md5($key); + $c = 0; + $v = ''; + $len = strlen($str); + $l = strlen($r); + for ($i=0;$i<$len;$i++) { + if ($c==$l) $c=0; + $v .= substr($str,$i,1) ^ substr($r,$c,1); + $c++; + } + return $v; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Crypt/Driver/Des.class.php b/ThinkPHP/Library/Think/Crypt/Driver/Des.class.php new file mode 100644 index 0000000..db1bad6 --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt/Driver/Des.class.php @@ -0,0 +1,241 @@ + +// +---------------------------------------------------------------------- +namespace Think\Crypt\Driver; +/** + * Des 加密实现类 + * Converted from JavaScript to PHP by Jim Gibbs, June 2004 Paul Tero, July 2001 + * Optimised for performance with large blocks by Michael Hayworth, November 2001 + * http://www.netdealing.com + */ + +class Des { + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) + * @return string + */ + public static function encrypt($str, $key,$expire=0) { + if ($str == "") { + return ""; + } + $expire = sprintf('%010d', $expire ? $expire + time():0); + $str = $expire.$str; + return self::_des($key,$str,1); + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($str, $key) { + if ($str == "") { + return ""; + } + $data = self::_des($key,$str,0); + $expire = substr($data,0,10); + if($expire > 0 && $expire < time()) { + return ''; + } + $data = substr($data,10); + return $data; + } + + /** + * Des算法 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + private static function _des($key, $message, $encrypt, $mode=0, $iv=null) { + //declaring this locally speeds things up a bit + $spfunction1 = array (0x1010400,0,0x10000,0x1010404,0x1010004,0x10404,0x4,0x10000,0x400,0x1010400,0x1010404,0x400,0x1000404,0x1010004,0x1000000,0x4,0x404,0x1000400,0x1000400,0x10400,0x10400,0x1010000,0x1010000,0x1000404,0x10004,0x1000004,0x1000004,0x10004,0,0x404,0x10404,0x1000000,0x10000,0x1010404,0x4,0x1010000,0x1010400,0x1000000,0x1000000,0x400,0x1010004,0x10000,0x10400,0x1000004,0x400,0x4,0x1000404,0x10404,0x1010404,0x10004,0x1010000,0x1000404,0x1000004,0x404,0x10404,0x1010400,0x404,0x1000400,0x1000400,0,0x10004,0x10400,0,0x1010004); + $spfunction2 = array (-0x7fef7fe0,-0x7fff8000,0x8000,0x108020,0x100000,0x20,-0x7fefffe0,-0x7fff7fe0,-0x7fffffe0,-0x7fef7fe0,-0x7fef8000,-0x80000000,-0x7fff8000,0x100000,0x20,-0x7fefffe0,0x108000,0x100020,-0x7fff7fe0,0,-0x80000000,0x8000,0x108020,-0x7ff00000,0x100020,-0x7fffffe0,0,0x108000,0x8020,-0x7fef8000,-0x7ff00000,0x8020,0,0x108020,-0x7fefffe0,0x100000,-0x7fff7fe0,-0x7ff00000,-0x7fef8000,0x8000,-0x7ff00000,-0x7fff8000,0x20,-0x7fef7fe0,0x108020,0x20,0x8000,-0x80000000,0x8020,-0x7fef8000,0x100000,-0x7fffffe0,0x100020,-0x7fff7fe0,-0x7fffffe0,0x100020,0x108000,0,-0x7fff8000,0x8020,-0x80000000,-0x7fefffe0,-0x7fef7fe0,0x108000); + $spfunction3 = array (0x208,0x8020200,0,0x8020008,0x8000200,0,0x20208,0x8000200,0x20008,0x8000008,0x8000008,0x20000,0x8020208,0x20008,0x8020000,0x208,0x8000000,0x8,0x8020200,0x200,0x20200,0x8020000,0x8020008,0x20208,0x8000208,0x20200,0x20000,0x8000208,0x8,0x8020208,0x200,0x8000000,0x8020200,0x8000000,0x20008,0x208,0x20000,0x8020200,0x8000200,0,0x200,0x20008,0x8020208,0x8000200,0x8000008,0x200,0,0x8020008,0x8000208,0x20000,0x8000000,0x8020208,0x8,0x20208,0x20200,0x8000008,0x8020000,0x8000208,0x208,0x8020000,0x20208,0x8,0x8020008,0x20200); + $spfunction4 = array (0x802001,0x2081,0x2081,0x80,0x802080,0x800081,0x800001,0x2001,0,0x802000,0x802000,0x802081,0x81,0,0x800080,0x800001,0x1,0x2000,0x800000,0x802001,0x80,0x800000,0x2001,0x2080,0x800081,0x1,0x2080,0x800080,0x2000,0x802080,0x802081,0x81,0x800080,0x800001,0x802000,0x802081,0x81,0,0,0x802000,0x2080,0x800080,0x800081,0x1,0x802001,0x2081,0x2081,0x80,0x802081,0x81,0x1,0x2000,0x800001,0x2001,0x802080,0x800081,0x2001,0x2080,0x800000,0x802001,0x80,0x800000,0x2000,0x802080); + $spfunction5 = array (0x100,0x2080100,0x2080000,0x42000100,0x80000,0x100,0x40000000,0x2080000,0x40080100,0x80000,0x2000100,0x40080100,0x42000100,0x42080000,0x80100,0x40000000,0x2000000,0x40080000,0x40080000,0,0x40000100,0x42080100,0x42080100,0x2000100,0x42080000,0x40000100,0,0x42000000,0x2080100,0x2000000,0x42000000,0x80100,0x80000,0x42000100,0x100,0x2000000,0x40000000,0x2080000,0x42000100,0x40080100,0x2000100,0x40000000,0x42080000,0x2080100,0x40080100,0x100,0x2000000,0x42080000,0x42080100,0x80100,0x42000000,0x42080100,0x2080000,0,0x40080000,0x42000000,0x80100,0x2000100,0x40000100,0x80000,0,0x40080000,0x2080100,0x40000100); + $spfunction6 = array (0x20000010,0x20400000,0x4000,0x20404010,0x20400000,0x10,0x20404010,0x400000,0x20004000,0x404010,0x400000,0x20000010,0x400010,0x20004000,0x20000000,0x4010,0,0x400010,0x20004010,0x4000,0x404000,0x20004010,0x10,0x20400010,0x20400010,0,0x404010,0x20404000,0x4010,0x404000,0x20404000,0x20000000,0x20004000,0x10,0x20400010,0x404000,0x20404010,0x400000,0x4010,0x20000010,0x400000,0x20004000,0x20000000,0x4010,0x20000010,0x20404010,0x404000,0x20400000,0x404010,0x20404000,0,0x20400010,0x10,0x4000,0x20400000,0x404010,0x4000,0x400010,0x20004010,0,0x20404000,0x20000000,0x400010,0x20004010); + $spfunction7 = array (0x200000,0x4200002,0x4000802,0,0x800,0x4000802,0x200802,0x4200800,0x4200802,0x200000,0,0x4000002,0x2,0x4000000,0x4200002,0x802,0x4000800,0x200802,0x200002,0x4000800,0x4000002,0x4200000,0x4200800,0x200002,0x4200000,0x800,0x802,0x4200802,0x200800,0x2,0x4000000,0x200800,0x4000000,0x200800,0x200000,0x4000802,0x4000802,0x4200002,0x4200002,0x2,0x200002,0x4000000,0x4000800,0x200000,0x4200800,0x802,0x200802,0x4200800,0x802,0x4000002,0x4200802,0x4200000,0x200800,0,0x2,0x4200802,0,0x200802,0x4200000,0x800,0x4000002,0x4000800,0x800,0x200002); + $spfunction8 = array (0x10001040,0x1000,0x40000,0x10041040,0x10000000,0x10001040,0x40,0x10000000,0x40040,0x10040000,0x10041040,0x41000,0x10041000,0x41040,0x1000,0x40,0x10040000,0x10000040,0x10001000,0x1040,0x41000,0x40040,0x10040040,0x10041000,0x1040,0,0,0x10040040,0x10000040,0x10001000,0x41040,0x40000,0x41040,0x40000,0x10041000,0x1000,0x40,0x10040040,0x1000,0x41040,0x10001000,0x40,0x10000040,0x10040000,0x10040040,0x10000000,0x40000,0x10001040,0,0x10041040,0x40040,0x10000040,0x10040000,0x10001000,0x10001040,0,0x10041040,0x41000,0x41000,0x1040,0x1040,0x40040,0x10000000,0x10041000); + $masks = array (4294967295,2147483647,1073741823,536870911,268435455,134217727,67108863,33554431,16777215,8388607,4194303,2097151,1048575,524287,262143,131071,65535,32767,16383,8191,4095,2047,1023,511,255,127,63,31,15,7,3,1,0); + + //create the 16 or 48 subkeys we will need + $keys = self::_createKeys ($key); + $m=0; + $len = strlen($message); + $chunk = 0; + //set up the loops for single and triple des + $iterations = ((count($keys) == 32) ? 3 : 9); //single or triple des + if ($iterations == 3) {$looping = (($encrypt) ? array (0, 32, 2) : array (30, -2, -2));} + else {$looping = (($encrypt) ? array (0, 32, 2, 62, 30, -2, 64, 96, 2) : array (94, 62, -2, 32, 64, 2, 30, -2, -2));} + + $message .= (chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0) . chr(0)); //pad the message out with null bytes + //store the result here + $result = ""; + $tempresult = ""; + + if ($mode == 1) { //CBC mode + $cbcleft = (ord($iv{$m++}) << 24) | (ord($iv{$m++}) << 16) | (ord($iv{$m++}) << 8) | ord($iv{$m++}); + $cbcright = (ord($iv{$m++}) << 24) | (ord($iv{$m++}) << 16) | (ord($iv{$m++}) << 8) | ord($iv{$m++}); + $m=0; + } + + //loop through each 64 bit chunk of the message + while ($m < $len) { + $left = (ord($message{$m++}) << 24) | (ord($message{$m++}) << 16) | (ord($message{$m++}) << 8) | ord($message{$m++}); + $right = (ord($message{$m++}) << 24) | (ord($message{$m++}) << 16) | (ord($message{$m++}) << 8) | ord($message{$m++}); + + //for Cipher Block Chaining mode, xor the message with the previous result + if ($mode == 1) {if ($encrypt) {$left ^= $cbcleft; $right ^= $cbcright;} else {$cbcleft2 = $cbcleft; $cbcright2 = $cbcright; $cbcleft = $left; $cbcright = $right;}} + + //first each 64 but chunk of the message must be permuted according to IP + $temp = (($left >> 4 & $masks[4]) ^ $right) & 0x0f0f0f0f; $right ^= $temp; $left ^= ($temp << 4); + $temp = (($left >> 16 & $masks[16]) ^ $right) & 0x0000ffff; $right ^= $temp; $left ^= ($temp << 16); + $temp = (($right >> 2 & $masks[2]) ^ $left) & 0x33333333; $left ^= $temp; $right ^= ($temp << 2); + $temp = (($right >> 8 & $masks[8]) ^ $left) & 0x00ff00ff; $left ^= $temp; $right ^= ($temp << 8); + $temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1); + + $left = (($left << 1) | ($left >> 31 & $masks[31])); + $right = (($right << 1) | ($right >> 31 & $masks[31])); + + //do this either 1 or 3 times for each chunk of the message + for ($j=0; $j<$iterations; $j+=3) { + $endloop = $looping[$j+1]; + $loopinc = $looping[$j+2]; + //now go through and perform the encryption or decryption + for ($i=$looping[$j]; $i!=$endloop; $i+=$loopinc) { //for efficiency + $right1 = $right ^ $keys[$i]; + $right2 = (($right >> 4 & $masks[4]) | ($right << 28)) ^ $keys[$i+1]; + //the result is attained by passing these bytes through the S selection functions + $temp = $left; + $left = $right; + $right = $temp ^ ($spfunction2[($right1 >> 24 & $masks[24]) & 0x3f] | $spfunction4[($right1 >> 16 & $masks[16]) & 0x3f] + | $spfunction6[($right1 >> 8 & $masks[8]) & 0x3f] | $spfunction8[$right1 & 0x3f] + | $spfunction1[($right2 >> 24 & $masks[24]) & 0x3f] | $spfunction3[($right2 >> 16 & $masks[16]) & 0x3f] + | $spfunction5[($right2 >> 8 & $masks[8]) & 0x3f] | $spfunction7[$right2 & 0x3f]); + } + $temp = $left; $left = $right; $right = $temp; //unreverse left and right + } //for either 1 or 3 iterations + + //move then each one bit to the right + $left = (($left >> 1 & $masks[1]) | ($left << 31)); + $right = (($right >> 1 & $masks[1]) | ($right << 31)); + + //now perform IP-1, which is IP in the opposite direction + $temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1); + $temp = (($right >> 8 & $masks[8]) ^ $left) & 0x00ff00ff; $left ^= $temp; $right ^= ($temp << 8); + $temp = (($right >> 2 & $masks[2]) ^ $left) & 0x33333333; $left ^= $temp; $right ^= ($temp << 2); + $temp = (($left >> 16 & $masks[16]) ^ $right) & 0x0000ffff; $right ^= $temp; $left ^= ($temp << 16); + $temp = (($left >> 4 & $masks[4]) ^ $right) & 0x0f0f0f0f; $right ^= $temp; $left ^= ($temp << 4); + + //for Cipher Block Chaining mode, xor the message with the previous result + if ($mode == 1) {if ($encrypt) {$cbcleft = $left; $cbcright = $right;} else {$left ^= $cbcleft2; $right ^= $cbcright2;}} + $tempresult .= (chr($left>>24 & $masks[24]) . chr(($left>>16 & $masks[16]) & 0xff) . chr(($left>>8 & $masks[8]) & 0xff) . chr($left & 0xff) . chr($right>>24 & $masks[24]) . chr(($right>>16 & $masks[16]) & 0xff) . chr(($right>>8 & $masks[8]) & 0xff) . chr($right & 0xff)); + + $chunk += 8; + if ($chunk == 512) {$result .= $tempresult; $tempresult = ""; $chunk = 0;} + } //for every 8 characters, or 64 bits in the message + + //return the result as an array + return ($result . $tempresult); + } //end of des + + /** + * createKeys + * this takes as input a 64 bit key (even though only 56 bits are used) + * as an array of 2 integers, and returns 16 48 bit keys + * @param string $key 加密key + * @return string + */ + private static function _createKeys ($key) { + //declaring this locally speeds things up a bit + $pc2bytes0 = array (0,0x4,0x20000000,0x20000004,0x10000,0x10004,0x20010000,0x20010004,0x200,0x204,0x20000200,0x20000204,0x10200,0x10204,0x20010200,0x20010204); + $pc2bytes1 = array (0,0x1,0x100000,0x100001,0x4000000,0x4000001,0x4100000,0x4100001,0x100,0x101,0x100100,0x100101,0x4000100,0x4000101,0x4100100,0x4100101); + $pc2bytes2 = array (0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808,0,0x8,0x800,0x808,0x1000000,0x1000008,0x1000800,0x1000808); + $pc2bytes3 = array (0,0x200000,0x8000000,0x8200000,0x2000,0x202000,0x8002000,0x8202000,0x20000,0x220000,0x8020000,0x8220000,0x22000,0x222000,0x8022000,0x8222000); + $pc2bytes4 = array (0,0x40000,0x10,0x40010,0,0x40000,0x10,0x40010,0x1000,0x41000,0x1010,0x41010,0x1000,0x41000,0x1010,0x41010); + $pc2bytes5 = array (0,0x400,0x20,0x420,0,0x400,0x20,0x420,0x2000000,0x2000400,0x2000020,0x2000420,0x2000000,0x2000400,0x2000020,0x2000420); + $pc2bytes6 = array (0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002,0,0x10000000,0x80000,0x10080000,0x2,0x10000002,0x80002,0x10080002); + $pc2bytes7 = array (0,0x10000,0x800,0x10800,0x20000000,0x20010000,0x20000800,0x20010800,0x20000,0x30000,0x20800,0x30800,0x20020000,0x20030000,0x20020800,0x20030800); + $pc2bytes8 = array (0,0x40000,0,0x40000,0x2,0x40002,0x2,0x40002,0x2000000,0x2040000,0x2000000,0x2040000,0x2000002,0x2040002,0x2000002,0x2040002); + $pc2bytes9 = array (0,0x10000000,0x8,0x10000008,0,0x10000000,0x8,0x10000008,0x400,0x10000400,0x408,0x10000408,0x400,0x10000400,0x408,0x10000408); + $pc2bytes10 = array (0,0x20,0,0x20,0x100000,0x100020,0x100000,0x100020,0x2000,0x2020,0x2000,0x2020,0x102000,0x102020,0x102000,0x102020); + $pc2bytes11 = array (0,0x1000000,0x200,0x1000200,0x200000,0x1200000,0x200200,0x1200200,0x4000000,0x5000000,0x4000200,0x5000200,0x4200000,0x5200000,0x4200200,0x5200200); + $pc2bytes12 = array (0,0x1000,0x8000000,0x8001000,0x80000,0x81000,0x8080000,0x8081000,0x10,0x1010,0x8000010,0x8001010,0x80010,0x81010,0x8080010,0x8081010); + $pc2bytes13 = array (0,0x4,0x100,0x104,0,0x4,0x100,0x104,0x1,0x5,0x101,0x105,0x1,0x5,0x101,0x105); + $masks = array (4294967295,2147483647,1073741823,536870911,268435455,134217727,67108863,33554431,16777215,8388607,4194303,2097151,1048575,524287,262143,131071,65535,32767,16383,8191,4095,2047,1023,511,255,127,63,31,15,7,3,1,0); + + //how many iterations (1 for des, 3 for triple des) + $iterations = ((strlen($key) >= 24) ? 3 : 1); + //stores the return keys + $keys = array (); // size = 32 * iterations but you don't specify this in php + //now define the left shifts which need to be done + $shifts = array (0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0); + //other variables + $m=0; + $n=0; + + for ($j=0; $j<$iterations; $j++) { //either 1 or 3 iterations + $left = (ord($key{$m++}) << 24) | (ord($key{$m++}) << 16) | (ord($key{$m++}) << 8) | ord($key{$m++}); + $right = (ord($key{$m++}) << 24) | (ord($key{$m++}) << 16) | (ord($key{$m++}) << 8) | ord($key{$m++}); + + $temp = (($left >> 4 & $masks[4]) ^ $right) & 0x0f0f0f0f; $right ^= $temp; $left ^= ($temp << 4); + $temp = (($right >> 16 & $masks[16]) ^ $left) & 0x0000ffff; $left ^= $temp; $right ^= ($temp << -16); + $temp = (($left >> 2 & $masks[2]) ^ $right) & 0x33333333; $right ^= $temp; $left ^= ($temp << 2); + $temp = (($right >> 16 & $masks[16]) ^ $left) & 0x0000ffff; $left ^= $temp; $right ^= ($temp << -16); + $temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1); + $temp = (($right >> 8 & $masks[8]) ^ $left) & 0x00ff00ff; $left ^= $temp; $right ^= ($temp << 8); + $temp = (($left >> 1 & $masks[1]) ^ $right) & 0x55555555; $right ^= $temp; $left ^= ($temp << 1); + + //the right side needs to be shifted and to get the last four bits of the left side + $temp = ($left << 8) | (($right >> 20 & $masks[20]) & 0x000000f0); + //left needs to be put upside down + $left = ($right << 24) | (($right << 8) & 0xff0000) | (($right >> 8 & $masks[8]) & 0xff00) | (($right >> 24 & $masks[24]) & 0xf0); + $right = $temp; + + //now go through and perform these shifts on the left and right keys + for ($i=0; $i < count($shifts); $i++) { + //shift the keys either one or two bits to the left + if ($shifts[$i] > 0) { + $left = (($left << 2) | ($left >> 26 & $masks[26])); + $right = (($right << 2) | ($right >> 26 & $masks[26])); + } else { + $left = (($left << 1) | ($left >> 27 & $masks[27])); + $right = (($right << 1) | ($right >> 27 & $masks[27])); + } + $left = $left & -0xf; + $right = $right & -0xf; + + //now apply PC-2, in such a way that E is easier when encrypting or decrypting + //this conversion will look like PC-2 except only the last 6 bits of each byte are used + //rather than 48 consecutive bits and the order of lines will be according to + //how the S selection functions will be applied: S2, S4, S6, S8, S1, S3, S5, S7 + $lefttemp = $pc2bytes0[$left >> 28 & $masks[28]] | $pc2bytes1[($left >> 24 & $masks[24]) & 0xf] + | $pc2bytes2[($left >> 20 & $masks[20]) & 0xf] | $pc2bytes3[($left >> 16 & $masks[16]) & 0xf] + | $pc2bytes4[($left >> 12 & $masks[12]) & 0xf] | $pc2bytes5[($left >> 8 & $masks[8]) & 0xf] + | $pc2bytes6[($left >> 4 & $masks[4]) & 0xf]; + $righttemp = $pc2bytes7[$right >> 28 & $masks[28]] | $pc2bytes8[($right >> 24 & $masks[24]) & 0xf] + | $pc2bytes9[($right >> 20 & $masks[20]) & 0xf] | $pc2bytes10[($right >> 16 & $masks[16]) & 0xf] + | $pc2bytes11[($right >> 12 & $masks[12]) & 0xf] | $pc2bytes12[($right >> 8 & $masks[8]) & 0xf] + | $pc2bytes13[($right >> 4 & $masks[4]) & 0xf]; + $temp = (($righttemp >> 16 & $masks[16]) ^ $lefttemp) & 0x0000ffff; + $keys[$n++] = $lefttemp ^ $temp; $keys[$n++] = $righttemp ^ ($temp << 16); + } + } //for each iterations + //return the keys we've created + return $keys; + } //end of des_createKeys + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Crypt/Driver/Think.class.php b/ThinkPHP/Library/Think/Crypt/Driver/Think.class.php new file mode 100644 index 0000000..f8ae9e1 --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt/Driver/Think.class.php @@ -0,0 +1,86 @@ + +// +---------------------------------------------------------------------- +namespace Think\Crypt\Driver; +/** + * Base64 加密实现类 + */ +class Think { + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) + * @return string + */ + public static function encrypt($data,$key,$expire=0) { + $expire = sprintf('%010d', $expire ? $expire + time():0); + $key = md5($key); + $data = base64_encode($expire.$data); + $x = 0; + $len = strlen($data); + $l = strlen($key); + $char = $str = ''; + + for ($i = 0; $i < $len; $i++) { + if ($x == $l) $x = 0; + $char .= substr($key, $x, 1); + $x++; + } + + for ($i = 0; $i < $len; $i++) { + $str .= chr(ord(substr($data, $i, 1)) + (ord(substr($char, $i, 1)))%256); + } + return str_replace(array('+','/','='),array('-','_',''),base64_encode($str)); + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($data,$key) { + $key = md5($key); + $data = str_replace(array('-','_'),array('+','/'),$data); + $mod4 = strlen($data) % 4; + if ($mod4) { + $data .= substr('====', $mod4); + } + $data = base64_decode($data); + + $x = 0; + $len = strlen($data); + $l = strlen($key); + $char = $str = ''; + + for ($i = 0; $i < $len; $i++) { + if ($x == $l) $x = 0; + $char .= substr($key, $x, 1); + $x++; + } + + for ($i = 0; $i < $len; $i++) { + if (ord(substr($data, $i, 1)) 0 && $expire < time()) { + return ''; + } + $data = substr($data,10); + return $data; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Crypt/Driver/Xxtea.class.php b/ThinkPHP/Library/Think/Crypt/Driver/Xxtea.class.php new file mode 100644 index 0000000..3f506a1 --- /dev/null +++ b/ThinkPHP/Library/Think/Crypt/Driver/Xxtea.class.php @@ -0,0 +1,116 @@ + +// +---------------------------------------------------------------------- +namespace Think\Crypt\Driver; +/** + * Xxtea 加密实现类 + */ +class Xxtea { + + /** + * 加密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @param integer $expire 有效期(秒) + * @return string + */ + public static function encrypt($str, $key,$expire=0) { + $expire = sprintf('%010d', $expire ? $expire + time():0); + $str = $expire.$str; + $v = self::str2long($str, true); + $k = self::str2long($key, false); + $n = count($v) - 1; + + $z = $v[$n]; + $y = $v[0]; + $delta = 0x9E3779B9; + $q = floor(6 + 52 / ($n + 1)); + $sum = 0; + while (0 < $q--) { + $sum = self::int32($sum + $delta); + $e = $sum >> 2 & 3; + for ($p = 0; $p < $n; $p++) { + $y = $v[$p + 1]; + $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); + $z = $v[$p] = self::int32($v[$p] + $mx); + } + $y = $v[0]; + $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); + $z = $v[$n] = self::int32($v[$n] + $mx); + } + return self::long2str($v, false); + } + + /** + * 解密字符串 + * @param string $str 字符串 + * @param string $key 加密key + * @return string + */ + public static function decrypt($str, $key) { + $v = self::str2long($str, false); + $k = self::str2long($key, false); + $n = count($v) - 1; + + $z = $v[$n]; + $y = $v[0]; + $delta = 0x9E3779B9; + $q = floor(6 + 52 / ($n + 1)); + $sum = self::int32($q * $delta); + while ($sum != 0) { + $e = $sum >> 2 & 3; + for ($p = $n; $p > 0; $p--) { + $z = $v[$p - 1]; + $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); + $y = $v[$p] = self::int32($v[$p] - $mx); + } + $z = $v[$n]; + $mx = self::int32((($z >> 5 & 0x07ffffff) ^ $y << 2) + (($y >> 3 & 0x1fffffff) ^ $z << 4)) ^ self::int32(($sum ^ $y) + ($k[$p & 3 ^ $e] ^ $z)); + $y = $v[0] = self::int32($v[0] - $mx); + $sum = self::int32($sum - $delta); + } + $data = self::long2str($v, true); + $expire = substr($data,0,10); + if($expire > 0 && $expire < time()) { + return ''; + } + $data = substr($data,10); + return $data; + } + + private static function long2str($v, $w) { + $len = count($v); + $s = array(); + for ($i = 0; $i < $len; $i++) { + $s[$i] = pack("V", $v[$i]); + } + if ($w) { + return substr(join('', $s), 0, $v[$len - 1]); + }else{ + return join('', $s); + } + } + + private static function str2long($s, $w) { + $v = unpack("V*", $s. str_repeat("\0", (4 - strlen($s) % 4) & 3)); + $v = array_values($v); + if ($w) { + $v[count($v)] = strlen($s); + } + return $v; + } + + private static function int32($n) { + while ($n >= 2147483648) $n -= 4294967296; + while ($n <= -2147483649) $n += 4294967296; + return (int)$n; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Db.class.php b/ThinkPHP/Library/Think/Db.class.php new file mode 100644 index 0000000..5c46e2f --- /dev/null +++ b/ThinkPHP/Library/Think/Db.class.php @@ -0,0 +1,137 @@ + +// +---------------------------------------------------------------------- + +namespace Think; + +/** + * ThinkPHP 数据库中间层实现类 + */ +class Db { + + static private $instance = array(); // 数据库连接实例 + static private $_instance = null; // 当前数据库连接实例 + + /** + * 取得数据库类实例 + * @static + * @access public + * @param mixed $config 连接配置 + * @return Object 返回数据库驱动类 + */ + static public function getInstance($config=array()) { + $md5 = md5(serialize($config)); + if(!isset(self::$instance[$md5])) { + // 解析连接参数 支持数组和字符串 + $options = self::parseConfig($config); + // 兼容mysqli + if('mysqli' == $options['type']) $options['type'] = 'mysql'; + // 如果采用lite方式 仅支持原生SQL 包括query和execute方法 + $class = !empty($options['lite'])? 'Think\Db\Lite' : 'Think\\Db\\Driver\\'.ucwords(strtolower($options['type'])); + if(class_exists($class)){ + self::$instance[$md5] = new $class($options); + }else{ + // 类没有定义 + E(L('_NO_DB_DRIVER_').': ' . $class); + } + } + self::$_instance = self::$instance[$md5]; + return self::$_instance; + } + + /** + * 数据库连接参数解析 + * @static + * @access private + * @param mixed $config + * @return array + */ + static private function parseConfig($config){ + if(!empty($config)){ + if(is_string($config)) { + return self::parseDsn($config); + } + $config = array_change_key_case($config); + $config = array ( + 'type' => $config['db_type'], + 'username' => $config['db_user'], + 'password' => $config['db_pwd'], + 'hostname' => $config['db_host'], + 'hostport' => $config['db_port'], + 'database' => $config['db_name'], + 'dsn' => isset($config['db_dsn'])?$config['db_dsn']:null, + 'params' => isset($config['db_params'])?$config['db_params']:null, + 'charset' => isset($config['db_charset'])?$config['db_charset']:'utf8', + 'deploy' => isset($config['db_deploy_type'])?$config['db_deploy_type']:0, + 'rw_separate' => isset($config['db_rw_separate'])?$config['db_rw_separate']:false, + 'master_num' => isset($config['db_master_num'])?$config['db_master_num']:1, + 'slave_no' => isset($config['db_slave_no'])?$config['db_slave_no']:'', + 'debug' => isset($config['db_debug'])?$config['db_debug']:APP_DEBUG, + 'lite' => isset($config['db_lite'])?$config['db_lite']:false, + ); + }else { + $config = array ( + 'type' => C('DB_TYPE'), + 'username' => C('DB_USER'), + 'password' => C('DB_PWD'), + 'hostname' => C('DB_HOST'), + 'hostport' => C('DB_PORT'), + 'database' => C('DB_NAME'), + 'dsn' => C('DB_DSN'), + 'params' => C('DB_PARAMS'), + 'charset' => C('DB_CHARSET'), + 'deploy' => C('DB_DEPLOY_TYPE'), + 'rw_separate' => C('DB_RW_SEPARATE'), + 'master_num' => C('DB_MASTER_NUM'), + 'slave_no' => C('DB_SLAVE_NO'), + 'debug' => C('DB_DEBUG',null,APP_DEBUG), + 'lite' => C('DB_LITE'), + ); + } + return $config; + } + + /** + * DSN解析 + * 格式: mysql://username:passwd@localhost:3306/DbName?param1=val1¶m2=val2#utf8 + * @static + * @access private + * @param string $dsnStr + * @return array + */ + static private function parseDsn($dsnStr) { + if( empty($dsnStr) ){return false;} + $info = parse_url($dsnStr); + if(!$info) { + return false; + } + $dsn = array( + 'type' => $info['scheme'], + 'username' => isset($info['user']) ? $info['user'] : '', + 'password' => isset($info['pass']) ? $info['pass'] : '', + 'hostname' => isset($info['host']) ? $info['host'] : '', + 'hostport' => isset($info['port']) ? $info['port'] : '', + 'database' => isset($info['path']) ? substr($info['path'],1) : '', + 'charset' => isset($info['fragment'])?$info['fragment']:'utf8', + ); + + if(isset($info['query'])) { + parse_str($info['query'],$dsn['params']); + }else{ + $dsn['params'] = array(); + } + return $dsn; + } + + // 调用驱动类的方法 + static public function __callStatic($method, $params){ + return call_user_func_array(array(self::$_instance, $method), $params); + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver.class.php b/ThinkPHP/Library/Think/Db/Driver.class.php new file mode 100644 index 0000000..fb46beb --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver.class.php @@ -0,0 +1,1149 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db; +use Think\Config; +use Think\Debug; +use Think\Log; +use PDO; + +abstract class Driver { + // PDO操作实例 + protected $PDOStatement = null; + // 当前操作所属的模型名 + protected $model = '_think_'; + // 当前SQL指令 + protected $queryStr = ''; + protected $modelSql = array(); + // 最后插入ID + protected $lastInsID = null; + // 返回或者影响记录数 + protected $numRows = 0; + // 事务指令数 + protected $transTimes = 0; + // 错误信息 + protected $error = ''; + // 数据库连接ID 支持多个连接 + protected $linkID = array(); + // 当前连接ID + protected $_linkID = null; + // 数据库连接参数配置 + protected $config = array( + 'type' => '', // 数据库类型 + 'hostname' => '127.0.0.1', // 服务器地址 + 'database' => '', // 数据库名 + 'username' => '', // 用户名 + 'password' => '', // 密码 + 'hostport' => '', // 端口 + 'dsn' => '', // + 'params' => array(), // 数据库连接参数 + 'charset' => 'utf8', // 数据库编码默认采用utf8 + 'prefix' => '', // 数据库表前缀 + 'debug' => false, // 数据库调试模式 + 'deploy' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'rw_separate' => false, // 数据库读写是否分离 主从式有效 + 'master_num' => 1, // 读写分离后 主服务器数量 + 'slave_no' => '', // 指定从服务器序号 + 'db_like_fields' => '', + ); + // 数据库表达式 + protected $exp = array('eq'=>'=','neq'=>'<>','gt'=>'>','egt'=>'>=','lt'=>'<','elt'=>'<=','notlike'=>'NOT LIKE','like'=>'LIKE','in'=>'IN','notin'=>'NOT IN','not in'=>'NOT IN','between'=>'BETWEEN','not between'=>'NOT BETWEEN','notbetween'=>'NOT BETWEEN'); + // 查询表达式 + protected $selectSql = 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%FORCE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT% %UNION%%LOCK%%COMMENT%'; + // 查询次数 + protected $queryTimes = 0; + // 执行次数 + protected $executeTimes = 0; + // PDO连接参数 + protected $options = array( + PDO::ATTR_CASE => PDO::CASE_LOWER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + ); + protected $bind = array(); // 参数绑定 + + /** + * 架构函数 读取数据库配置信息 + * @access public + * @param array $config 数据库配置数组 + */ + public function __construct($config=''){ + if(!empty($config)) { + $this->config = array_merge($this->config,$config); + if(is_array($this->config['params'])){ + $this->options = $this->config['params'] + $this->options; + } + } + } + + /** + * 连接数据库方法 + * @access public + */ + public function connect($config='',$linkNum=0,$autoConnection=false) { + if ( !isset($this->linkID[$linkNum]) ) { + if(empty($config)) $config = $this->config; + try{ + if(empty($config['dsn'])) { + $config['dsn'] = $this->parseDsn($config); + } + if(version_compare(PHP_VERSION,'5.3.6','<=')){ + // 禁用模拟预处理语句 + $this->options[PDO::ATTR_EMULATE_PREPARES] = false; + } + $this->linkID[$linkNum] = new PDO( $config['dsn'], $config['username'], $config['password'],$this->options); + }catch (\PDOException $e) { + if($autoConnection){ + trace($e->getMessage(),'','ERR'); + return $this->connect($autoConnection,$linkNum); + }elseif($config['debug']){ + E($e->getMessage()); + } + } + } + return $this->linkID[$linkNum]; + } + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){} + + /** + * 释放查询结果 + * @access public + */ + public function free() { + $this->PDOStatement = null; + } + + /** + * 执行查询 返回数据集 + * @access public + * @param string $str sql指令 + * @param boolean $fetchSql 不执行只是获取SQL + * @return mixed + */ + public function query($str,$fetchSql=false) { + $this->initConnect(false); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($this->bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$this->bind)); + } + if($fetchSql){ + return $this->queryStr; + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->queryTimes++; + N('db_query',1); // 兼容代码 + // 调试开始 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement){ + $this->error(); + return false; + } + foreach ($this->bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $this->bind = array(); + try{ + $result = $this->PDOStatement->execute(); + // 调试结束 + $this->debug(false); + if ( false === $result ) { + $this->error(); + return false; + } else { + return $this->getResult(); + } + }catch (\PDOException $e) { + $this->error(); + return false; + } + } + + /** + * 执行语句 + * @access public + * @param string $str sql指令 + * @param boolean $fetchSql 不执行只是获取SQL + * @return mixed + */ + public function execute($str,$fetchSql=false) { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($this->bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$this->bind)); + } + if($fetchSql){ + return $this->queryStr; + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->executeTimes++; + N('db_write',1); // 兼容代码 + // 记录开始执行时间 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement) { + $this->error(); + return false; + } + foreach ($this->bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $this->bind = array(); + try{ + $result = $this->PDOStatement->execute(); + // 调试结束 + $this->debug(false); + if ( false === $result) { + $this->error(); + return false; + } else { + $this->numRows = $this->PDOStatement->rowCount(); + if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { + $this->lastInsID = $this->_linkID->lastInsertId(); + } + return $this->numRows; + } + }catch (\PDOException $e) { + $this->error(); + return false; + } + } + + /** + * 启动事务 + * @access public + * @return void + */ + public function startTrans() { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + //数据rollback 支持 + if ($this->transTimes == 0) { + $this->_linkID->beginTransaction(); + } + $this->transTimes++; + return ; + } + + /** + * 用于非自动提交状态下面的查询提交 + * @access public + * @return boolean + */ + public function commit() { + if ($this->transTimes > 0) { + $result = $this->_linkID->commit(); + $this->transTimes = 0; + if(!$result){ + $this->error(); + return false; + } + } + return true; + } + + /** + * 事务回滚 + * @access public + * @return boolean + */ + public function rollback() { + if ($this->transTimes > 0) { + $result = $this->_linkID->rollback(); + $this->transTimes = 0; + if(!$result){ + $this->error(); + return false; + } + } + return true; + } + + /** + * 获得所有的查询数据 + * @access private + * @return array + */ + private function getResult() { + //返回数据集 + $result = $this->PDOStatement->fetchAll(PDO::FETCH_ASSOC); + $this->numRows = count( $result ); + return $result; + } + + /** + * 获得查询次数 + * @access public + * @param boolean $execute 是否包含所有查询 + * @return integer + */ + public function getQueryTimes($execute=false){ + return $execute?$this->queryTimes+$this->executeTimes:$this->queryTimes; + } + + /** + * 获得执行次数 + * @access public + * @return integer + */ + public function getExecuteTimes(){ + return $this->executeTimes; + } + + /** + * 关闭数据库 + * @access public + */ + public function close() { + $this->_linkID = null; + } + + /** + * 数据库错误信息 + * 并显示当前的SQL语句 + * @access public + * @return string + */ + public function error() { + if($this->PDOStatement) { + $error = $this->PDOStatement->errorInfo(); + $this->error = $error[1].':'.$error[2]; + }else{ + $this->error = ''; + } + if('' != $this->queryStr){ + $this->error .= "\n [ SQL语句 ] : ".$this->queryStr; + } + // 记录错误日志 + trace($this->error,'','ERR'); + if($this->config['debug']) {// 开启数据库调试模式 + E($this->error); + }else{ + return $this->error; + } + } + + /** + * 设置锁机制 + * @access protected + * @return string + */ + protected function parseLock($lock=false) { + return $lock? ' FOR UPDATE ' : ''; + } + + /** + * set分析 + * @access protected + * @param array $data + * @return string + */ + protected function parseSet($data) { + foreach ($data as $key=>$val){ + if(is_array($val) && 'exp' == $val[0]){ + $set[] = $this->parseKey($key).'='.$val[1]; + }elseif(is_null($val)){ + $set[] = $this->parseKey($key).'=NULL'; + }elseif(is_scalar($val)) {// 过滤非标量数据 + if(0===strpos($val,':') && in_array($val,array_keys($this->bind)) ){ + $set[] = $this->parseKey($key).'='.$this->escapeString($val); + }else{ + $name = count($this->bind); + $set[] = $this->parseKey($key).'=:'.$name; + $this->bindParam($name,$val); + } + } + } + return ' SET '.implode(',',$set); + } + + /** + * 参数绑定 + * @access protected + * @param string $name 绑定参数名 + * @param mixed $value 绑定值 + * @return void + */ + protected function bindParam($name,$value){ + $this->bind[':'.$name] = $value; + } + + /** + * 字段名分析 + * @access protected + * @param string $key + * @return string + */ + protected function parseKey(&$key) { + return $key; + } + + /** + * value分析 + * @access protected + * @param mixed $value + * @return string + */ + protected function parseValue($value) { + if(is_string($value)) { + $value = strpos($value,':') === 0 && in_array($value,array_keys($this->bind))? $this->escapeString($value) : '\''.$this->escapeString($value).'\''; + }elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){ + $value = $this->escapeString($value[1]); + }elseif(is_array($value)) { + $value = array_map(array($this, 'parseValue'),$value); + }elseif(is_bool($value)){ + $value = $value ? '1' : '0'; + }elseif(is_null($value)){ + $value = 'null'; + } + return $value; + } + + /** + * field分析 + * @access protected + * @param mixed $fields + * @return string + */ + protected function parseField($fields) { + if(is_string($fields) && '' !== $fields) { + $fields = explode(',',$fields); + } + if(is_array($fields)) { + // 完善数组方式传字段名的支持 + // 支持 'field1'=>'field2' 这样的字段别名定义 + $array = array(); + foreach ($fields as $key=>$field){ + if(!is_numeric($key)) + $array[] = $this->parseKey($key).' AS '.$this->parseKey($field); + else + $array[] = $this->parseKey($field); + } + $fieldsStr = implode(',', $array); + }else{ + $fieldsStr = '*'; + } + //TODO 如果是查询全部字段,并且是join的方式,那么就把要查的表加个别名,以免字段被覆盖 + return $fieldsStr; + } + + /** + * table分析 + * @access protected + * @param mixed $table + * @return string + */ + protected function parseTable($tables) { + if(is_array($tables)) {// 支持别名定义 + $array = array(); + foreach ($tables as $table=>$alias){ + if(!is_numeric($table)) + $array[] = $this->parseKey($table).' '.$this->parseKey($alias); + else + $array[] = $this->parseKey($alias); + } + $tables = $array; + }elseif(is_string($tables)){ + $tables = explode(',',$tables); + array_walk($tables, array(&$this, 'parseKey')); + } + return implode(',',$tables); + } + + /** + * where分析 + * @access protected + * @param mixed $where + * @return string + */ + protected function parseWhere($where) { + $whereStr = ''; + if(is_string($where)) { + // 直接使用字符串条件 + $whereStr = $where; + }else{ // 使用数组表达式 + $operate = isset($where['_logic'])?strtoupper($where['_logic']):''; + if(in_array($operate,array('AND','OR','XOR'))){ + // 定义逻辑运算规则 例如 OR XOR AND NOT + $operate = ' '.$operate.' '; + unset($where['_logic']); + }else{ + // 默认进行 AND 运算 + $operate = ' AND '; + } + foreach ($where as $key=>$val){ + if(is_numeric($key)){ + $key = '_complex'; + } + if(0===strpos($key,'_')) { + // 解析特殊条件表达式 + $whereStr .= $this->parseThinkWhere($key,$val); + }else{ + // 查询字段的安全过滤 + // if(!preg_match('/^[A-Z_\|\&\-.a-z0-9\(\)\,]+$/',trim($key))){ + // E(L('_EXPRESS_ERROR_').':'.$key); + // } + // 多条件支持 + $multi = is_array($val) && isset($val['_multi']); + $key = trim($key); + if(strpos($key,'|')) { // 支持 name|title|nickname 方式定义查询字段 + $array = explode('|',$key); + $str = array(); + foreach ($array as $m=>$k){ + $v = $multi?$val[$m]:$val; + $str[] = $this->parseWhereItem($this->parseKey($k),$v); + } + $whereStr .= '( '.implode(' OR ',$str).' )'; + }elseif(strpos($key,'&')){ + $array = explode('&',$key); + $str = array(); + foreach ($array as $m=>$k){ + $v = $multi?$val[$m]:$val; + $str[] = '('.$this->parseWhereItem($this->parseKey($k),$v).')'; + } + $whereStr .= '( '.implode(' AND ',$str).' )'; + }else{ + $whereStr .= $this->parseWhereItem($this->parseKey($key),$val); + } + } + $whereStr .= $operate; + } + $whereStr = substr($whereStr,0,-strlen($operate)); + } + return empty($whereStr)?'':' WHERE '.$whereStr; + } + + // where子单元分析 + protected function parseWhereItem($key,$val) { + $whereStr = ''; + if(is_array($val)) { + if(is_string($val[0])) { + $exp = strtolower($val[0]); + if(preg_match('/^(eq|neq|gt|egt|lt|elt)$/',$exp)) { // 比较运算 + $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]); + }elseif(preg_match('/^(notlike|like)$/',$exp)){// 模糊查找 + if(is_array($val[1])) { + $likeLogic = isset($val[2])?strtoupper($val[2]):'OR'; + if(in_array($likeLogic,array('AND','OR','XOR'))){ + $like = array(); + foreach ($val[1] as $item){ + $like[] = $key.' '.$this->exp[$exp].' '.$this->parseValue($item); + } + $whereStr .= '('.implode(' '.$likeLogic.' ',$like).')'; + } + }else{ + $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($val[1]); + } + }elseif('bind' == $exp ){ // 使用表达式 + $whereStr .= $key.' = :'.$val[1]; + }elseif('exp' == $exp ){ // 使用表达式 + $whereStr .= $key.' '.$val[1]; + }elseif(preg_match('/^(notin|not in|in)$/',$exp)){ // IN 运算 + if(isset($val[2]) && 'exp'==$val[2]) { + $whereStr .= $key.' '.$this->exp[$exp].' '.$val[1]; + }else{ + if(is_string($val[1])) { + $val[1] = explode(',',$val[1]); + } + $zone = implode(',',$this->parseValue($val[1])); + $whereStr .= $key.' '.$this->exp[$exp].' ('.$zone.')'; + } + }elseif(preg_match('/^(notbetween|not between|between)$/',$exp)){ // BETWEEN运算 + $data = is_string($val[1])? explode(',',$val[1]):$val[1]; + $whereStr .= $key.' '.$this->exp[$exp].' '.$this->parseValue($data[0]).' AND '.$this->parseValue($data[1]); + }else{ + E(L('_EXPRESS_ERROR_').':'.$val[0]); + } + }else { + $count = count($val); + $rule = isset($val[$count-1]) ? (is_array($val[$count-1]) ? strtoupper($val[$count-1][0]) : strtoupper($val[$count-1]) ) : '' ; + if(in_array($rule,array('AND','OR','XOR'))) { + $count = $count -1; + }else{ + $rule = 'AND'; + } + for($i=0;$i<$count;$i++) { + $data = is_array($val[$i])?$val[$i][1]:$val[$i]; + if('exp'==strtolower($val[$i][0])) { + $whereStr .= $key.' '.$data.' '.$rule.' '; + }else{ + $whereStr .= $this->parseWhereItem($key,$val[$i]).' '.$rule.' '; + } + } + $whereStr = '( '.substr($whereStr,0,-4).' )'; + } + }else { + //对字符串类型字段采用模糊匹配 + $likeFields = $this->config['db_like_fields']; + if($likeFields && preg_match('/^('.$likeFields.')$/i',$key)) { + $whereStr .= $key.' LIKE '.$this->parseValue('%'.$val.'%'); + }else { + $whereStr .= $key.' = '.$this->parseValue($val); + } + } + return $whereStr; + } + + /** + * 特殊条件分析 + * @access protected + * @param string $key + * @param mixed $val + * @return string + */ + protected function parseThinkWhere($key,$val) { + $whereStr = ''; + switch($key) { + case '_string': + // 字符串模式查询条件 + $whereStr = $val; + break; + case '_complex': + // 复合查询条件 + $whereStr = substr($this->parseWhere($val),6); + break; + case '_query': + // 字符串模式查询条件 + parse_str($val,$where); + if(isset($where['_logic'])) { + $op = ' '.strtoupper($where['_logic']).' '; + unset($where['_logic']); + }else{ + $op = ' AND '; + } + $array = array(); + foreach ($where as $field=>$data) + $array[] = $this->parseKey($field).' = '.$this->parseValue($data); + $whereStr = implode($op,$array); + break; + } + return '( '.$whereStr.' )'; + } + + /** + * limit分析 + * @access protected + * @param mixed $lmit + * @return string + */ + protected function parseLimit($limit) { + return !empty($limit)? ' LIMIT '.$limit.' ':''; + } + + /** + * join分析 + * @access protected + * @param mixed $join + * @return string + */ + protected function parseJoin($join) { + $joinStr = ''; + if(!empty($join)) { + $joinStr = ' '.implode(' ',$join).' '; + } + return $joinStr; + } + + /** + * order分析 + * @access protected + * @param mixed $order + * @return string + */ + protected function parseOrder($order) { + if(is_array($order)) { + $array = array(); + foreach ($order as $key=>$val){ + if(is_numeric($key)) { + $array[] = $this->parseKey($val); + }else{ + $array[] = $this->parseKey($key).' '.$val; + } + } + $order = implode(',',$array); + } + return !empty($order)? ' ORDER BY '.$order:''; + } + + /** + * group分析 + * @access protected + * @param mixed $group + * @return string + */ + protected function parseGroup($group) { + return !empty($group)? ' GROUP BY '.$group:''; + } + + /** + * having分析 + * @access protected + * @param string $having + * @return string + */ + protected function parseHaving($having) { + return !empty($having)? ' HAVING '.$having:''; + } + + /** + * comment分析 + * @access protected + * @param string $comment + * @return string + */ + protected function parseComment($comment) { + return !empty($comment)? ' /* '.$comment.' */':''; + } + + /** + * distinct分析 + * @access protected + * @param mixed $distinct + * @return string + */ + protected function parseDistinct($distinct) { + return !empty($distinct)? ' DISTINCT ' :''; + } + + /** + * union分析 + * @access protected + * @param mixed $union + * @return string + */ + protected function parseUnion($union) { + if(empty($union)) return ''; + if(isset($union['_all'])) { + $str = 'UNION ALL '; + unset($union['_all']); + }else{ + $str = 'UNION '; + } + foreach ($union as $u){ + $sql[] = $str.(is_array($u)?$this->buildSelectSql($u):$u); + } + return implode(' ',$sql); + } + + /** + * 参数绑定分析 + * @access protected + * @param array $bind + * @return array + */ + protected function parseBind($bind){ + $this->bind = array_merge($this->bind,$bind); + } + + /** + * index分析,可在操作链中指定需要强制使用的索引 + * @access protected + * @param mixed $index + * @return string + */ + protected function parseForce($index) { + if(empty($index)) return ''; + if(is_array($index)) $index = join(",", $index); + return sprintf(" FORCE INDEX ( %s ) ", $index); + } + + /** + * ON DUPLICATE KEY UPDATE 分析 + * @access protected + * @param mixed $duplicate + * @return string + */ + protected function parseDuplicate($duplicate){ + return ''; + } + + /** + * 插入记录 + * @access public + * @param mixed $data 数据 + * @param array $options 参数表达式 + * @param boolean $replace 是否replace + * @return false | integer + */ + public function insert($data,$options=array(),$replace=false) { + $values = $fields = array(); + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + foreach ($data as $key=>$val){ + if(is_array($val) && 'exp' == $val[0]){ + $fields[] = $this->parseKey($key); + $values[] = $val[1]; + }elseif(is_null($val)){ + $fields[] = $this->parseKey($key); + $values[] = 'NULL'; + }elseif(is_scalar($val)) { // 过滤非标量数据 + $fields[] = $this->parseKey($key); + if(0===strpos($val,':') && in_array($val,array_keys($this->bind))){ + $values[] = $this->parseValue($val); + }else{ + $name = count($this->bind); + $values[] = ':'.$name; + $this->bindParam($name,$val); + } + } + } + // 兼容数字传入方式 + $replace= (is_numeric($replace) && $replace>0)?true:$replace; + $sql = (true===$replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES ('.implode(',', $values).')'.$this->parseDuplicate($replace); + $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + + /** + * 批量插入记录 + * @access public + * @param mixed $dataSet 数据集 + * @param array $options 参数表达式 + * @param boolean $replace 是否replace + * @return false | integer + */ + public function insertAll($dataSet,$options=array(),$replace=false) { + $values = array(); + $this->model = $options['model']; + if(!is_array($dataSet[0])) return false; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $fields = array_map(array($this,'parseKey'),array_keys($dataSet[0])); + foreach ($dataSet as $data){ + $value = array(); + foreach ($data as $key=>$val){ + if(is_array($val) && 'exp' == $val[0]){ + $value[] = $val[1]; + }elseif(is_null($val)){ + $value[] = 'NULL'; + }elseif(is_scalar($val)){ + if(0===strpos($val,':') && in_array($val,array_keys($this->bind))){ + $value[] = $this->parseValue($val); + }else{ + $name = count($this->bind); + $value[] = ':'.$name; + $this->bindParam($name,$val); + } + } + } + $values[] = 'SELECT '.implode(',', $value); + } + $sql = 'INSERT INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') '.implode(' UNION ALL ',$values); + $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * 通过Select方式插入记录 + * @access public + * @param string $fields 要插入的数据表字段名 + * @param string $table 要插入的数据表名 + * @param array $option 查询数据参数 + * @return false | integer + */ + public function selectInsert($fields,$table,$options=array()) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + if(is_string($fields)) $fields = explode(',',$fields); + array_walk($fields, array($this, 'parseKey')); + $sql = 'INSERT INTO '.$this->parseTable($table).' ('.implode(',', $fields).') '; + $sql .= $this->buildSelectSql($options); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * 更新记录 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @return false | integer + */ + public function update($data,$options) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $table = $this->parseTable($options['table']); + $sql = 'UPDATE ' . $table . $this->parseSet($data); + if(strpos($table,',')){// 多表更新支持JOIN操作 + $sql .= $this->parseJoin(!empty($options['join'])?$options['join']:''); + } + $sql .= $this->parseWhere(!empty($options['where'])?$options['where']:''); + if(!strpos($table,',')){ + // 单表更新支持order和lmit + $sql .= $this->parseOrder(!empty($options['order'])?$options['order']:'') + .$this->parseLimit(!empty($options['limit'])?$options['limit']:''); + } + $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * 删除记录 + * @access public + * @param array $options 表达式 + * @return false | integer + */ + public function delete($options=array()) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $table = $this->parseTable($options['table']); + $sql = 'DELETE FROM '.$table; + if(strpos($table,',')){// 多表删除支持USING和JOIN操作 + if(!empty($options['using'])){ + $sql .= ' USING '.$this->parseTable($options['using']).' '; + } + $sql .= $this->parseJoin(!empty($options['join'])?$options['join']:''); + } + $sql .= $this->parseWhere(!empty($options['where'])?$options['where']:''); + if(!strpos($table,',')){ + // 单表删除支持order和limit + $sql .= $this->parseOrder(!empty($options['order'])?$options['order']:'') + .$this->parseLimit(!empty($options['limit'])?$options['limit']:''); + } + $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * 查找记录 + * @access public + * @param array $options 表达式 + * @return mixed + */ + public function select($options=array()) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $sql = $this->buildSelectSql($options); + $result = $this->query($sql,!empty($options['fetch_sql']) ? true : false); + return $result; + } + + /** + * 生成查询SQL + * @access public + * @param array $options 表达式 + * @return string + */ + public function buildSelectSql($options=array()) { + if(isset($options['page'])) { + // 根据页数计算limit + list($page,$listRows) = $options['page']; + $page = $page>0 ? $page : 1; + $listRows= $listRows>0 ? $listRows : (is_numeric($options['limit'])?$options['limit']:20); + $offset = $listRows*($page-1); + $options['limit'] = $offset.','.$listRows; + } + $sql = $this->parseSql($this->selectSql,$options); + return $sql; + } + + /** + * 替换SQL语句中表达式 + * @access public + * @param array $options 表达式 + * @return string + */ + public function parseSql($sql,$options=array()){ + $sql = str_replace( + array('%TABLE%','%DISTINCT%','%FIELD%','%JOIN%','%WHERE%','%GROUP%','%HAVING%','%ORDER%','%LIMIT%','%UNION%','%LOCK%','%COMMENT%','%FORCE%'), + array( + $this->parseTable($options['table']), + $this->parseDistinct(isset($options['distinct'])?$options['distinct']:false), + $this->parseField(!empty($options['field'])?$options['field']:'*'), + $this->parseJoin(!empty($options['join'])?$options['join']:''), + $this->parseWhere(!empty($options['where'])?$options['where']:''), + $this->parseGroup(!empty($options['group'])?$options['group']:''), + $this->parseHaving(!empty($options['having'])?$options['having']:''), + $this->parseOrder(!empty($options['order'])?$options['order']:''), + $this->parseLimit(!empty($options['limit'])?$options['limit']:''), + $this->parseUnion(!empty($options['union'])?$options['union']:''), + $this->parseLock(isset($options['lock'])?$options['lock']:false), + $this->parseComment(!empty($options['comment'])?$options['comment']:''), + $this->parseForce(!empty($options['force'])?$options['force']:'') + ),$sql); + return $sql; + } + + /** + * 获取最近一次查询的sql语句 + * @param string $model 模型名 + * @access public + * @return string + */ + public function getLastSql($model='') { + return $model?$this->modelSql[$model]:$this->queryStr; + } + + /** + * 获取最近插入的ID + * @access public + * @return string + */ + public function getLastInsID() { + return $this->lastInsID; + } + + /** + * 获取最近的错误信息 + * @access public + * @return string + */ + public function getError() { + return $this->error; + } + + /** + * SQL指令安全过滤 + * @access public + * @param string $str SQL字符串 + * @return string + */ + public function escapeString($str) { + return addslashes($str); + } + + /** + * 设置当前操作模型 + * @access public + * @param string $model 模型名 + * @return void + */ + public function setModel($model){ + $this->model = $model; + } + + /** + * 数据库调试 记录当前SQL + * @access protected + * @param boolean $start 调试开始标记 true 开始 false 结束 + */ + protected function debug($start) { + if($this->config['debug']) {// 开启数据库调试模式 + if($start) { + G('queryStartTime'); + }else{ + $this->modelSql[$this->model] = $this->queryStr; + //$this->model = '_think_'; + // 记录操作结束时间 + G('queryEndTime'); + trace($this->queryStr.' [ RunTime:'.G('queryStartTime','queryEndTime').'s ]','','SQL'); + } + } + } + + /** + * 初始化数据库连接 + * @access protected + * @param boolean $master 主服务器 + * @return void + */ + protected function initConnect($master=true) { + if(!empty($this->config['deploy'])) + // 采用分布式数据库 + $this->_linkID = $this->multiConnect($master); + else + // 默认单数据库 + if ( !$this->_linkID ) $this->_linkID = $this->connect(); + } + + /** + * 连接分布式服务器 + * @access protected + * @param boolean $master 主服务器 + * @return void + */ + protected function multiConnect($master=false) { + // 分布式数据库配置解析 + $_config['username'] = explode(',',$this->config['username']); + $_config['password'] = explode(',',$this->config['password']); + $_config['hostname'] = explode(',',$this->config['hostname']); + $_config['hostport'] = explode(',',$this->config['hostport']); + $_config['database'] = explode(',',$this->config['database']); + $_config['dsn'] = explode(',',$this->config['dsn']); + $_config['charset'] = explode(',',$this->config['charset']); + + $m = floor(mt_rand(0,$this->config['master_num']-1)); + // 数据库读写是否分离 + if($this->config['rw_separate']){ + // 主从式采用读写分离 + if($master) + // 主服务器写入 + $r = $m; + else{ + if(is_numeric($this->config['slave_no'])) {// 指定服务器读 + $r = $this->config['slave_no']; + }else{ + // 读操作连接从服务器 + $r = floor(mt_rand($this->config['master_num'],count($_config['hostname'])-1)); // 每次随机连接的数据库 + } + } + }else{ + // 读写操作不区分服务器 + $r = floor(mt_rand(0,count($_config['hostname'])-1)); // 每次随机连接的数据库 + } + + if($m != $r ){ + $db_master = array( + 'username' => isset($_config['username'][$m])?$_config['username'][$m]:$_config['username'][0], + 'password' => isset($_config['password'][$m])?$_config['password'][$m]:$_config['password'][0], + 'hostname' => isset($_config['hostname'][$m])?$_config['hostname'][$m]:$_config['hostname'][0], + 'hostport' => isset($_config['hostport'][$m])?$_config['hostport'][$m]:$_config['hostport'][0], + 'database' => isset($_config['database'][$m])?$_config['database'][$m]:$_config['database'][0], + 'dsn' => isset($_config['dsn'][$m])?$_config['dsn'][$m]:$_config['dsn'][0], + 'charset' => isset($_config['charset'][$m])?$_config['charset'][$m]:$_config['charset'][0], + ); + } + $db_config = array( + 'username' => isset($_config['username'][$r])?$_config['username'][$r]:$_config['username'][0], + 'password' => isset($_config['password'][$r])?$_config['password'][$r]:$_config['password'][0], + 'hostname' => isset($_config['hostname'][$r])?$_config['hostname'][$r]:$_config['hostname'][0], + 'hostport' => isset($_config['hostport'][$r])?$_config['hostport'][$r]:$_config['hostport'][0], + 'database' => isset($_config['database'][$r])?$_config['database'][$r]:$_config['database'][0], + 'dsn' => isset($_config['dsn'][$r])?$_config['dsn'][$r]:$_config['dsn'][0], + 'charset' => isset($_config['charset'][$r])?$_config['charset'][$r]:$_config['charset'][0], + ); + return $this->connect($db_config,$r,$r == $m ? false : $db_master); + } + + /** + * 析构方法 + * @access public + */ + public function __destruct() { + // 释放查询 + if ($this->PDOStatement){ + $this->free(); + } + // 关闭连接 + $this->close(); + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Firebird.class.php b/ThinkPHP/Library/Think/Db/Driver/Firebird.class.php new file mode 100644 index 0000000..6cc281d --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Firebird.class.php @@ -0,0 +1,151 @@ + +// +---------------------------------------------------------------------- +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * Firebird数据库驱动 + */ +class Firebird extends Driver{ + protected $selectSql = 'SELECT %LIMIT% %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%'; + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'firebird:dbname='.$config['hostname'].'/'.($config['hostport']?:3050).':'.$config['database']; + return $dsn; + } + + /** + * 执行语句 + * @access public + * @param string $str sql指令 + * @param boolean $fetchSql 不执行只是获取SQL + * @return mixed + */ + public function execute($str,$fetchSql=false) { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($this->bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$this->bind)); + } + if($fetchSql){ + return $this->queryStr; + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->executeTimes++; + N('db_write',1); // 兼容代码 + // 记录开始执行时间 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement) { + E($this->error()); + } + foreach ($this->bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $this->bind = array(); + $result = $this->PDOStatement->execute(); + $this->debug(false); + if ( false === $result) { + $this->error(); + return false; + } else { + $this->numRows = $this->PDOStatement->rowCount(); + return $this->numRows; + } + } + + /** + * 取得数据表的字段信息 + * @access public + */ + public function getFields($tableName) { + $this->initConnect(true); + list($tableName) = explode(' ', $tableName); + $sql='SELECT RF.RDB$FIELD_NAME AS FIELD,RF.RDB$DEFAULT_VALUE AS DEFAULT1,RF.RDB$NULL_FLAG AS NULL1,TRIM(T.RDB$TYPE_NAME) || \'(\' || F.RDB$FIELD_LENGTH || \')\' as TYPE FROM RDB$RELATION_FIELDS RF LEFT JOIN RDB$FIELDS F ON (F.RDB$FIELD_NAME = RF.RDB$FIELD_SOURCE) LEFT JOIN RDB$TYPES T ON (T.RDB$TYPE = F.RDB$FIELD_TYPE) WHERE RDB$RELATION_NAME=UPPER(\''.$tableName.'\') AND T.RDB$FIELD_NAME = \'RDB$FIELD_TYPE\' ORDER By RDB$FIELD_POSITION'; + $result = $this->query($sql); + $info = array(); + if($result){ + foreach($result as $key => $val){ + $info[trim($val['field'])] = array( + 'name' => trim($val['field']), + 'type' => $val['type'], + 'notnull' => (bool) ($val['null1'] ==1), // 1表示不为Null + 'default' => $val['default1'], + 'primary' => false, + 'autoinc' => false, + ); + } + } + //获取主键 + $sql='select b.rdb$field_name as field_name from rdb$relation_constraints a join rdb$index_segments b on a.rdb$index_name=b.rdb$index_name where a.rdb$constraint_type=\'PRIMARY KEY\' and a.rdb$relation_name=UPPER(\''.$tableName.'\')'; + $rs_temp = $this->query($sql); + foreach($rs_temp as $row) { + $info[trim($row['field_name'])]['primary']= true; + } + return $info; + } + + /** + * 取得数据库的表信息 + * @access public + */ + public function getTables($dbName='') { + $sql='SELECT DISTINCT RDB$RELATION_NAME FROM RDB$RELATION_FIELDS WHERE RDB$SYSTEM_FLAG=0'; + $result = $this->query($sql); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = trim(current($val)); + } + return $info; + } + + /** + * SQL指令安全过滤 + * @access public + * @param string $str SQL指令 + * @return string + */ + public function escapeString($str) { + return str_replace("'", "''", $str); + } + + /** + * limit + * @access public + * @param $limit limit表达式 + * @return string + */ + public function parseLimit($limit) { + $limitStr = ''; + if(!empty($limit)) { + $limit = explode(',',$limit); + if(count($limit)>1) { + $limitStr = ' FIRST '.$limit[1].' SKIP '.$limit[0].' '; + }else{ + $limitStr = ' FIRST '.$limit[0].' '; + } + } + return $limitStr; + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Mongo.class.php b/ThinkPHP/Library/Think/Db/Driver/Mongo.class.php new file mode 100644 index 0000000..a070b8c --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Mongo.class.php @@ -0,0 +1,821 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * Mongo数据库驱动 + */ +class Mongo extends Driver { + + protected $_mongo = null; // MongoDb Object + protected $_collection = null; // MongoCollection Object + protected $_dbName = ''; // dbName + protected $_collectionName = ''; // collectionName + protected $_cursor = null; // MongoCursor Object + protected $comparison = array('neq'=>'ne','ne'=>'ne','gt'=>'gt','egt'=>'gte','gte'=>'gte','lt'=>'lt','elt'=>'lte','lte'=>'lte','in'=>'in','not in'=>'nin','nin'=>'nin'); + + /** + * 架构函数 读取数据库配置信息 + * @access public + * @param array $config 数据库配置数组 + */ + public function __construct($config=''){ + if ( !class_exists('mongoClient') ) { + E(L('_NOT_SUPPORT_').':Mongo'); + } + if(!empty($config)) { + $this->config = array_merge($this->config,$config); + if(empty($this->config['params'])){ + $this->config['params'] = array(); + } + } + } + + /** + * 连接数据库方法 + * @access public + */ + public function connect($config='',$linkNum=0) { + if ( !isset($this->linkID[$linkNum]) ) { + if(empty($config)) $config = $this->config; + $host = 'mongodb://'.($config['username']?"{$config['username']}":'').($config['password']?":{$config['password']}@":'').$config['hostname'].($config['hostport']?":{$config['hostport']}":'').'/'.($config['database']?"{$config['database']}":''); + try{ + $this->linkID[$linkNum] = new \mongoClient( $host,$this->config['params']); + }catch (\MongoConnectionException $e){ + E($e->getmessage()); + } + } + return $this->linkID[$linkNum]; + } + + /** + * 切换当前操作的Db和Collection + * @access public + * @param string $collection collection + * @param string $db db + * @param boolean $master 是否主服务器 + * @return void + */ + public function switchCollection($collection,$db='',$master=true){ + // 当前没有连接 则首先进行数据库连接 + if ( !$this->_linkID ) $this->initConnect($master); + try{ + if(!empty($db)) { // 传人Db则切换数据库 + // 当前MongoDb对象 + $this->_dbName = $db; + $this->_mongo = $this->_linkID->selectDb($db); + } + // 当前MongoCollection对象 + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.getCollection('.$collection.')'; + } + if($this->_collectionName != $collection) { + $this->queryTimes++; + N('db_query',1); // 兼容代码 + $this->debug(true); + $this->_collection = $this->_mongo->selectCollection($collection); + $this->debug(false); + $this->_collectionName = $collection; // 记录当前Collection名称 + } + }catch (MongoException $e){ + E($e->getMessage()); + } + } + + /** + * 释放查询结果 + * @access public + */ + public function free() { + $this->_cursor = null; + } + + /** + * 执行命令 + * @access public + * @param array $command 指令 + * @return array + */ + public function command($command=array(), $options=array()) { + $cache = isset($options['cache'])?$options['cache']:false; + if($cache) { // 查询缓存检测 + $key = is_string($cache['key'])?$cache['key']:md5(serialize($command)); + $value = S($key,'','',$cache['type']); + if(false !== $value) { + return $value; + } + } + N('db_write',1); // 兼容代码 + $this->executeTimes++; + try{ + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.runCommand('; + $this->queryStr .= json_encode($command); + $this->queryStr .= ')'; + } + $this->debug(true); + $result = $this->_mongo->command($command); + $this->debug(false); + + if($cache && $result['ok']) { // 查询缓存写入 + S($key,$result,$cache['expire'],$cache['type']); + } + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 执行语句 + * @access public + * @param string $code sql指令 + * @param array $args 参数 + * @return mixed + */ + public function execute($code,$args=array()) { + $this->executeTimes++; + N('db_write',1); // 兼容代码 + $this->debug(true); + $this->queryStr = 'execute:'.$code; + $result = $this->_mongo->execute($code,$args); + $this->debug(false); + if($result['ok']) { + return $result['retval']; + }else{ + E($result['errmsg']); + } + } + + /** + * 关闭数据库 + * @access public + */ + public function close() { + if($this->_linkID) { + $this->_linkID->close(); + $this->_linkID = null; + $this->_mongo = null; + $this->_collection = null; + $this->_cursor = null; + } + } + + /** + * 数据库错误信息 + * @access public + * @return string + */ + public function error() { + $this->error = $this->_mongo->lastError(); + trace($this->error,'','ERR'); + return $this->error; + } + + /** + * 插入记录 + * @access public + * @param mixed $data 数据 + * @param array $options 参数表达式 + * @param boolean $replace 是否replace + * @return false | integer + */ + public function insert($data,$options=array(),$replace=false) { + if(isset($options['table'])) { + $this->switchCollection($options['table']); + } + $this->model = $options['model']; + $this->executeTimes++; + N('db_write',1); // 兼容代码 + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.insert('; + $this->queryStr .= $data?json_encode($data):'{}'; + $this->queryStr .= ')'; + } + try{ + $this->debug(true); + $result = $replace? $this->_collection->save($data): $this->_collection->insert($data); + $this->debug(false); + if($result) { + $_id = $data['_id']; + if(is_object($_id)) { + $_id = $_id->__toString(); + } + $this->lastInsID = $_id; + } + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 插入多条记录 + * @access public + * @param array $dataList 数据 + * @param array $options 参数表达式 + * @return bool + */ + public function insertAll($dataList,$options=array()) { + if(isset($options['table'])) { + $this->switchCollection($options['table']); + } + $this->model = $options['model']; + $this->executeTimes++; + N('db_write',1); // 兼容代码 + try{ + $this->debug(true); + $result = $this->_collection->batchInsert($dataList); + $this->debug(false); + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 生成下一条记录ID 用于自增非MongoId主键 + * @access public + * @param string $pk 主键名 + * @return integer + */ + public function getMongoNextId($pk) { + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.find({},{'.$pk.':1}).sort({'.$pk.':-1}).limit(1)'; + } + try{ + $this->debug(true); + $result = $this->_collection->find(array(),array($pk=>1))->sort(array($pk=>-1))->limit(1); + $this->debug(false); + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + $data = $result->getNext(); + return isset($data[$pk])?$data[$pk]+1:1; + } + + /** + * 更新记录 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @return bool + */ + public function update($data,$options) { + if(isset($options['table'])) { + $this->switchCollection($options['table']); + } + $this->executeTimes++; + N('db_write',1); // 兼容代码 + $this->model = $options['model']; + $query = $this->parseWhere(isset($options['where'])?$options['where']:array()); + $set = $this->parseSet($data); + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.update('; + $this->queryStr .= $query?json_encode($query):'{}'; + $this->queryStr .= ','.json_encode($set).')'; + } + try{ + $this->debug(true); + if(isset($options['limit']) && $options['limit'] == 1) { + $multiple = array("multiple" => false); + }else{ + $multiple = array("multiple" => true); + } + $result = $this->_collection->update($query,$set,$multiple); + $this->debug(false); + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 删除记录 + * @access public + * @param array $options 表达式 + * @return false | integer + */ + public function delete($options=array()) { + if(isset($options['table'])) { + $this->switchCollection($options['table']); + } + $query = $this->parseWhere(isset($options['where'])?$options['where']:array()); + $this->model = $options['model']; + $this->executeTimes++; + N('db_write',1); // 兼容代码 + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.remove('.json_encode($query).')'; + } + try{ + $this->debug(true); + $result = $this->_collection->remove($query); + $this->debug(false); + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 清空记录 + * @access public + * @param array $options 表达式 + * @return false | integer + */ + public function clear($options=array()){ + if(isset($options['table'])) { + $this->switchCollection($options['table']); + } + $this->model = $options['model']; + $this->executeTimes++; + N('db_write',1); // 兼容代码 + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.remove({})'; + } + try{ + $this->debug(true); + $result = $this->_collection->drop(); + $this->debug(false); + return $result; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 查找记录 + * @access public + * @param array $options 表达式 + * @return iterator + */ + public function select($options=array()) { + if(isset($options['table'])) { + $this->switchCollection($options['table'],'',false); + } + $this->model = $options['model']; + $this->queryTimes++; + N('db_query',1); // 兼容代码 + $query = $this->parseWhere(isset($options['where'])?$options['where']:array()); + $field = $this->parseField(isset($options['field'])?$options['field']:array()); + try{ + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.find('; + $this->queryStr .= $query? json_encode($query):'{}'; + if(is_array($field) && count($field)) { + foreach ($field as $f=>$v) + $_field_array[$f] = $v ? 1 : 0; + + $this->queryStr .= $field? ', '.json_encode($_field_array):', {}'; + } + $this->queryStr .= ')'; + } + $this->debug(true); + $_cursor = $this->_collection->find($query,$field); + if(!empty($options['order'])) { + $order = $this->parseOrder($options['order']); + if($this->config['debug']) { + $this->queryStr .= '.sort('.json_encode($order).')'; + } + $_cursor = $_cursor->sort($order); + } + if(isset($options['page'])) { // 根据页数计算limit + list($page,$length) = $options['page']; + $page = $page>0 ? $page : 1; + $length = $length>0 ? $length : (is_numeric($options['limit'])?$options['limit']:20); + $offset = $length*((int)$page-1); + $options['limit'] = $offset.','.$length; + } + if(isset($options['limit'])) { + list($offset,$length) = $this->parseLimit($options['limit']); + if(!empty($offset)) { + if($this->config['debug']) { + $this->queryStr .= '.skip('.intval($offset).')'; + } + $_cursor = $_cursor->skip(intval($offset)); + } + if($this->config['debug']) { + $this->queryStr .= '.limit('.intval($length).')'; + } + $_cursor = $_cursor->limit(intval($length)); + } + $this->debug(false); + $this->_cursor = $_cursor; + $resultSet = iterator_to_array($_cursor); + return $resultSet; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 查找某个记录 + * @access public + * @param array $options 表达式 + * @return array + */ + public function find($options=array()){ + $options['limit'] = 1; + $find = $this->select($options); + return array_shift($find); + } + + /** + * 统计记录数 + * @access public + * @param array $options 表达式 + * @return iterator + */ + public function count($options=array()){ + if(isset($options['table'])) { + $this->switchCollection($options['table'],'',false); + } + $this->model = $options['model']; + $this->queryTimes++; + N('db_query',1); // 兼容代码 + $query = $this->parseWhere(isset($options['where'])?$options['where']:array()); + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName; + $this->queryStr .= $query?'.find('.json_encode($query).')':''; + $this->queryStr .= '.count()'; + } + try{ + $this->debug(true); + $count = $this->_collection->count($query); + $this->debug(false); + return $count; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + public function group($keys,$initial,$reduce,$options=array()){ + if(isset($options['table']) && $this->_collectionName != $options['table']) { + $this->switchCollection($options['table'],'',false); + } + + $cache = isset($options['cache'])?$options['cache']:false; + if($cache) { + $key = is_string($cache['key'])?$cache['key']:md5(serialize($options)); + $value = S($key,'','',$cache['type']); + if(false !== $value) { + return $value; + } + } + + $this->model = $options['model']; + $this->queryTimes++; + N('db_query',1); // 兼容代码 + $query = $this->parseWhere(isset($options['where'])?$options['where']:array()); + + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.group({key:'.json_encode($keys).',cond:'. + json_encode($options['condition']) . ',reduce:' . + json_encode($reduce).',initial:'. + json_encode($initial).'})'; + } + try{ + $this->debug(true); + $option = array('condition'=>$options['condition'], 'finalize'=>$options['finalize'], 'maxTimeMS'=>$options['maxTimeMS']); + $group = $this->_collection->group($keys,$initial,$reduce,$options); + $this->debug(false); + + if($cache && $group['ok']) + S($key,$group,$cache['expire'],$cache['type']); + + return $group; + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + } + + /** + * 取得数据表的字段信息 + * @access public + * @return array + */ + public function getFields($collection=''){ + if(!empty($collection) && $collection != $this->_collectionName) { + $this->switchCollection($collection,'',false); + } + $this->queryTimes++; + N('db_query',1); // 兼容代码 + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.'.$this->_collectionName.'.findOne()'; + } + try{ + $this->debug(true); + $result = $this->_collection->findOne(); + $this->debug(false); + } catch (\MongoCursorException $e) { + E($e->getMessage()); + } + if($result) { // 存在数据则分析字段 + $info = array(); + foreach ($result as $key=>$val){ + $info[$key] = array( + 'name' => $key, + 'type' => getType($val), + ); + } + return $info; + } + // 暂时没有数据 返回false + return false; + } + + /** + * 取得当前数据库的collection信息 + * @access public + */ + public function getTables(){ + if($this->config['debug']) { + $this->queryStr = $this->_dbName.'.getCollenctionNames()'; + } + $this->queryTimes++; + N('db_query',1); // 兼容代码 + $this->debug(true); + $list = $this->_mongo->listCollections(); + $this->debug(false); + $info = array(); + foreach ($list as $collection){ + $info[] = $collection->getName(); + } + return $info; + } + + /** + * 取得当前数据库的对象 + * @access public + * @return object mongoClient + */ + public function getDB(){ + return $this->_mongo; + } + + /** + * 取得当前集合的对象 + * @access public + * @return object MongoCollection + */ + public function getCollection(){ + return $this->_collection; + } + + /** + * set分析 + * @access protected + * @param array $data + * @return string + */ + protected function parseSet($data) { + $result = array(); + foreach ($data as $key=>$val){ + if(is_array($val)) { + switch($val[0]) { + case 'inc': + $result['$inc'][$key] = (int)$val[1]; + break; + case 'set': + case 'unset': + case 'push': + case 'pushall': + case 'addtoset': + case 'pop': + case 'pull': + case 'pullall': + $result['$'.$val[0]][$key] = $val[1]; + break; + default: + $result['$set'][$key] = $val; + } + }else{ + $result['$set'][$key] = $val; + } + } + return $result; + } + + /** + * order分析 + * @access protected + * @param mixed $order + * @return array + */ + protected function parseOrder($order) { + if(is_string($order)) { + $array = explode(',',$order); + $order = array(); + foreach ($array as $key=>$val){ + $arr = explode(' ',trim($val)); + if(isset($arr[1])) { + $arr[1] = $arr[1]=='asc'?1:-1; + }else{ + $arr[1] = 1; + } + $order[$arr[0]] = $arr[1]; + } + } + return $order; + } + + /** + * limit分析 + * @access protected + * @param mixed $limit + * @return array + */ + protected function parseLimit($limit) { + if(strpos($limit,',')) { + $array = explode(',',$limit); + }else{ + $array = array(0,$limit); + } + return $array; + } + + /** + * field分析 + * @access protected + * @param mixed $fields + * @return array + */ + public function parseField($fields){ + if(empty($fields)) { + $fields = array(); + } + if(is_string($fields)) { + $_fields = explode(',',$fields); + $fields = array(); + foreach ($_fields as $f) + $fields[$f] = true; + }elseif(is_array($fields)) { + $_fields = $fields; + $fields = array(); + foreach ($_fields as $f=>$v) { + if(is_numeric($f)) + $fields[$v] = true; + else + $fields[$f] = $v ? true : false; + } + } + return $fields; + } + + /** + * where分析 + * @access protected + * @param mixed $where + * @return array + */ + public function parseWhere($where){ + $query = array(); + $return = array(); + $_logic = '$and'; + if(isset($where['_logic'])){ + $where['_logic'] = strtolower($where['_logic']); + $_logic = in_array($where['_logic'], array('or','xor','nor', 'and'))?'$'.$where['_logic']:$_logic; + unset($where['_logic']); + } + foreach ($where as $key=>$val){ + if('_id' != $key && 0===strpos($key,'_')) { + // 解析特殊条件表达式 + $parse = $this->parseThinkWhere($key,$val); + $query = array_merge($query,$parse); + }else{ + // 查询字段的安全过滤 + if(!preg_match('/^[A-Z_\|\&\-.a-z0-9]+$/',trim($key))){ + E(L('_ERROR_QUERY_').':'.$key); + } + $key = trim($key); + if(strpos($key,'|')) { + $array = explode('|',$key); + $str = array(); + foreach ($array as $k){ + $str[] = $this->parseWhereItem($k,$val); + } + $query['$or'] = $str; + }elseif(strpos($key,'&')){ + $array = explode('&',$key); + $str = array(); + foreach ($array as $k){ + $str[] = $this->parseWhereItem($k,$val); + } + $query = array_merge($query,$str); + }else{ + $str = $this->parseWhereItem($key,$val); + $query = array_merge($query,$str); + } + } + } + if($_logic == '$and') + return $query; + + foreach($query as $key=>$val) + $return[$_logic][] = array($key=>$val); + + return $return; + } + + /** + * 特殊条件分析 + * @access protected + * @param string $key + * @param mixed $val + * @return string + */ + protected function parseThinkWhere($key,$val) { + $query = array(); + $_logic = array('or','xor','nor', 'and'); + + switch($key) { + case '_query': // 字符串模式查询条件 + parse_str($val,$query); + if(isset($query['_logic']) && strtolower($query['_logic']) == 'or' ) { + unset($query['_logic']); + $query['$or'] = $query; + } + break; + case '_complex': // 子查询模式查询条件 + $__logic = strtolower($val['_logic']); + if(isset($val['_logic']) && in_array($__logic, $_logic) ) { + unset($val['_logic']); + $query['$'.$__logic] = $val; + } + break; + case '_string':// MongoCode查询 + $query['$where'] = new \MongoCode($val); + break; + } + //兼容 MongoClient OR条件查询方法 + if(isset($query['$or']) && !is_array(current($query['$or']))) { + $val = array(); + foreach ($query['$or'] as $k=>$v) + $val[] = array($k=>$v); + $query['$or'] = $val; + } + return $query; + } + + /** + * where子单元分析 + * @access protected + * @param string $key + * @param mixed $val + * @return array + */ + protected function parseWhereItem($key,$val) { + $query = array(); + if(is_array($val)) { + if(is_string($val[0])) { + $con = strtolower($val[0]); + if(in_array($con,array('neq','ne','gt','egt','gte','lt','lte','elt'))) { // 比较运算 + $k = '$'.$this->comparison[$con]; + $query[$key] = array($k=>$val[1]); + }elseif('like'== $con){ // 模糊查询 采用正则方式 + $query[$key] = new \MongoRegex("/".$val[1]."/"); + }elseif('mod'==$con){ // mod 查询 + $query[$key] = array('$mod'=>$val[1]); + }elseif('regex'==$con){ // 正则查询 + $query[$key] = new \MongoRegex($val[1]); + }elseif(in_array($con,array('in','nin','not in'))){ // IN NIN 运算 + $data = is_string($val[1])? explode(',',$val[1]):$val[1]; + $k = '$'.$this->comparison[$con]; + $query[$key] = array($k=>$data); + }elseif('all'==$con){ // 满足所有指定条件 + $data = is_string($val[1])? explode(',',$val[1]):$val[1]; + $query[$key] = array('$all'=>$data); + }elseif('between'==$con){ // BETWEEN运算 + $data = is_string($val[1])? explode(',',$val[1]):$val[1]; + $query[$key] = array('$gte'=>$data[0],'$lte'=>$data[1]); + }elseif('not between'==$con){ + $data = is_string($val[1])? explode(',',$val[1]):$val[1]; + $query[$key] = array('$lt'=>$data[0],'$gt'=>$data[1]); + }elseif('exp'==$con){ // 表达式查询 + $query['$where'] = new \MongoCode($val[1]); + }elseif('exists'==$con){ // 字段是否存在 + $query[$key] = array('$exists'=>(bool)$val[1]); + }elseif('size'==$con){ // 限制属性大小 + $query[$key] = array('$size'=>intval($val[1])); + }elseif('type'==$con){ // 限制字段类型 1 浮点型 2 字符型 3 对象或者MongoDBRef 5 MongoBinData 7 MongoId 8 布尔型 9 MongoDate 10 NULL 15 MongoCode 16 32位整型 17 MongoTimestamp 18 MongoInt64 如果是数组的话判断元素的类型 + $query[$key] = array('$type'=>intval($val[1])); + }else{ + $query[$key] = $val; + } + return $query; + } + } + $query[$key] = $val; + return $query; + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php new file mode 100644 index 0000000..ee0a338 --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php @@ -0,0 +1,235 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * mysql数据库驱动 + */ +class Mysql extends Driver{ + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'mysql:dbname='.$config['database'].';host='.$config['hostname']; + if(!empty($config['hostport'])) { + $dsn .= ';port='.$config['hostport']; + }elseif(!empty($config['socket'])){ + $dsn .= ';unix_socket='.$config['socket']; + } + + if(!empty($config['charset'])){ + //为兼容各版本PHP,用两种方式设置编码 + $this->options[\PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES '.$config['charset']; + $dsn .= ';charset='.$config['charset']; + } + return $dsn; + } + + /** + * 取得数据表的字段信息 + * @access public + */ + public function getFields($tableName) { + $this->initConnect(true); + list($tableName) = explode(' ', $tableName); + if(strpos($tableName,'.')){ + list($dbName,$tableName) = explode('.',$tableName); + $sql = 'SHOW COLUMNS FROM `'.$dbName.'`.`'.$tableName.'`'; + }else{ + $sql = 'SHOW COLUMNS FROM `'.$tableName.'`'; + } + + $result = $this->query($sql); + $info = array(); + if($result) { + foreach ($result as $key => $val) { + if(\PDO::CASE_LOWER != $this->_linkID->getAttribute(\PDO::ATTR_CASE)){ + $val = array_change_key_case ( $val , CASE_LOWER ); + } + $info[$val['field']] = array( + 'name' => $val['field'], + 'type' => $val['type'], + 'notnull' => (bool) ($val['null'] === ''), // not null is empty, null is yes + 'default' => $val['default'], + 'primary' => (strtolower($val['key']) == 'pri'), + 'autoinc' => (strtolower($val['extra']) == 'auto_increment'), + ); + } + } + return $info; + } + + /** + * 取得数据库的表信息 + * @access public + */ + public function getTables($dbName='') { + $sql = !empty($dbName)?'SHOW TABLES FROM '.$dbName:'SHOW TABLES '; + $result = $this->query($sql); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = current($val); + } + return $info; + } + + /** + * 字段和表名处理 + * @access protected + * @param string $key + * @return string + */ + protected function parseKey(&$key) { + $key = trim($key); + if(!is_numeric($key) && !preg_match('/[,\'\"\*\(\)`.\s]/',$key)) { + $key = '`'.$key.'`'; + } + return $key; + } + + /** + * 批量插入记录 + * @access public + * @param mixed $dataSet 数据集 + * @param array $options 参数表达式 + * @param boolean $replace 是否replace + * @return false | integer + */ + public function insertAll($dataSet,$options=array(),$replace=false) { + $values = array(); + $this->model = $options['model']; + if(!is_array($dataSet[0])) return false; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $fields = array_map(array($this,'parseKey'),array_keys($dataSet[0])); + foreach ($dataSet as $data){ + $value = array(); + foreach ($data as $key=>$val){ + if(is_array($val) && 'exp' == $val[0]){ + $value[] = $val[1]; + }elseif(is_null($val)){ + $value[] = 'NULL'; + }elseif(is_scalar($val)){ + if(0===strpos($val,':') && in_array($val,array_keys($this->bind))){ + $value[] = $this->parseValue($val); + }else{ + $name = count($this->bind); + $value[] = ':'.$name; + $this->bindParam($name,$val); + } + } + } + $values[] = '('.implode(',', $value).')'; + } + // 兼容数字传入方式 + $replace= (is_numeric($replace) && $replace>0)?true:$replace; + $sql = (true===$replace?'REPLACE':'INSERT').' INTO '.$this->parseTable($options['table']).' ('.implode(',', $fields).') VALUES '.implode(',',$values).$this->parseDuplicate($replace); + $sql .= $this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * ON DUPLICATE KEY UPDATE 分析 + * @access protected + * @param mixed $duplicate + * @return string + */ + protected function parseDuplicate($duplicate){ + // 布尔值或空则返回空字符串 + if(is_bool($duplicate) || empty($duplicate)) return ''; + + if(is_string($duplicate)){ + // field1,field2 转数组 + $duplicate = explode(',', $duplicate); + }elseif(is_object($duplicate)){ + // 对象转数组 + $duplicate = get_class_vars($duplicate); + } + $updates = array(); + foreach((array) $duplicate as $key=>$val){ + if(is_numeric($key)){ // array('field1', 'field2', 'field3') 解析为 ON DUPLICATE KEY UPDATE field1=VALUES(field1), field2=VALUES(field2), field3=VALUES(field3) + $updates[] = $this->parseKey($val)."=VALUES(".$this->parseKey($val).")"; + }else{ + if(is_scalar($val)) // 兼容标量传值方式 + $val = array('value', $val); + if(!isset($val[1])) continue; + switch($val[0]){ + case 'exp': // 表达式 + $updates[] = $this->parseKey($key)."=($val[1])"; + break; + case 'value': // 值 + default: + $name = count($this->bind); + $updates[] = $this->parseKey($key)."=:".$name; + $this->bindParam($name, $val[1]); + break; + } + } + } + if(empty($updates)) return ''; + return " ON DUPLICATE KEY UPDATE ".join(', ', $updates); + } + + + + /** + * 执行存储过程查询 返回多个数据集 + * @access public + * @param string $str sql指令 + * @param boolean $fetchSql 不执行只是获取SQL + * @return mixed + */ + public function procedure($str,$fetchSql=false) { + $this->initConnect(false); + $this->_linkID->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if($fetchSql){ + return $this->queryStr; + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->queryTimes++; + N('db_query',1); // 兼容代码 + // 调试开始 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement){ + $this->error(); + return false; + } + try{ + $result = $this->PDOStatement->execute(); + // 调试结束 + $this->debug(false); + do + { + $result = $this->PDOStatement->fetchAll(\PDO::FETCH_ASSOC); + if ($result) + { + $resultArr[] = $result; + } + } + while ($this->PDOStatement->nextRowset()); + $this->_linkID->setAttribute(\PDO::ATTR_ERRMODE, $this->options[\PDO::ATTR_ERRMODE]); + return $resultArr; + }catch (\PDOException $e) { + $this->error(); + $this->_linkID->setAttribute(\PDO::ATTR_ERRMODE, $this->options[\PDO::ATTR_ERRMODE]); + return false; + } + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Oracle.class.php b/ThinkPHP/Library/Think/Db/Driver/Oracle.class.php new file mode 100644 index 0000000..6bf5477 --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Oracle.class.php @@ -0,0 +1,168 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * Oracle数据库驱动 + */ +class Oracle extends Driver{ + + private $table = ''; + protected $selectSql = 'SELECT * FROM (SELECT thinkphp.*, rownum AS numrow FROM (SELECT %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%) thinkphp ) %LIMIT%%COMMENT%'; + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'oci:dbname=//'.$config['hostname'].($config['hostport']?':'.$config['hostport']:'').'/'.$config['database']; + if(!empty($config['charset'])) { + $dsn .= ';charset='.$config['charset']; + } + return $dsn; + } + + /** + * 执行语句 + * @access public + * @param string $str sql指令 + * @param boolean $fetchSql 不执行只是获取SQL + * @return integer + */ + public function execute($str,$fetchSql=false) { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($this->bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$this->bind)); + } + if($fetchSql){ + return $this->queryStr; + } + $flag = false; + if(preg_match("/^\s*(INSERT\s+INTO)\s+(\w+)\s+/i", $str, $match)) { + $this->table = C("DB_SEQUENCE_PREFIX").str_ireplace(C("DB_PREFIX"), "", $match[2]); + $flag = (boolean)$this->query("SELECT * FROM user_sequences WHERE sequence_name='" . strtoupper($this->table) . "'"); + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->executeTimes++; + N('db_write',1); // 兼容代码 + // 记录开始执行时间 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement) { + $this->error(); + return false; + } + foreach ($this->bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $this->bind = array(); + $result = $this->PDOStatement->execute(); + $this->debug(false); + if ( false === $result) { + $this->error(); + return false; + } else { + $this->numRows = $this->PDOStatement->rowCount(); + if($flag || preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { + $this->lastInsID = $this->_linkID->lastInsertId(); + } + return $this->numRows; + } + } + + /** + * 取得数据表的字段信息 + * @access public + */ + public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); + $result = $this->query("select a.column_name,data_type,decode(nullable,'Y',0,1) notnull,data_default,decode(a.column_name,b.column_name,1,0) pk " + ."from user_tab_columns a,(select column_name from user_constraints c,user_cons_columns col " + ."where c.constraint_name=col.constraint_name and c.constraint_type='P'and c.table_name='".strtoupper($tableName) + ."') b where table_name='".strtoupper($tableName)."' and a.column_name=b.column_name(+)"); + $info = array(); + if($result) { + foreach ($result as $key => $val) { + $info[strtolower($val['column_name'])] = array( + 'name' => strtolower($val['column_name']), + 'type' => strtolower($val['data_type']), + 'notnull' => $val['notnull'], + 'default' => $val['data_default'], + 'primary' => $val['pk'], + 'autoinc' => $val['pk'], + ); + } + } + return $info; + } + + /** + * 取得数据库的表信息(暂时实现取得用户表信息) + * @access public + */ + public function getTables($dbName='') { + $result = $this->query("select table_name from user_tables"); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = current($val); + } + return $info; + } + + /** + * SQL指令安全过滤 + * @access public + * @param string $str SQL指令 + * @return string + */ + public function escapeString($str) { + return str_ireplace("'", "''", $str); + } + + /** + * limit + * @access public + * @return string + */ + public function parseLimit($limit) { + $limitStr = ''; + if(!empty($limit)) { + $limit = explode(',',$limit); + if(count($limit)>1) + $limitStr = "(numrow>" . $limit[0] . ") AND (numrow<=" . ($limit[0]+$limit[1]) . ")"; + else + $limitStr = "(numrow>0 AND numrow<=".$limit[0].")"; + } + return $limitStr?' WHERE '.$limitStr:''; + } + + /** + * 设置锁机制 + * @access protected + * @return string + */ + protected function parseLock($lock=false) { + if(!$lock) return ''; + return ' FOR UPDATE NOWAIT '; + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Pgsql.class.php b/ThinkPHP/Library/Think/Db/Driver/Pgsql.class.php new file mode 100644 index 0000000..e1223a4 --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Pgsql.class.php @@ -0,0 +1,91 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * Pgsql数据库驱动 + */ +class Pgsql extends Driver{ + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'pgsql:dbname='.$config['database'].';host='.$config['hostname']; + if(!empty($config['hostport'])) { + $dsn .= ';port='.$config['hostport']; + } + return $dsn; + } + + /** + * 取得数据表的字段信息 + * @access public + * @return array + */ + public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); + $result = $this->query('select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg('.$tableName.');'); + $info = array(); + if($result){ + foreach ($result as $key => $val) { + $info[$val['field']] = array( + 'name' => $val['field'], + 'type' => $val['type'], + 'notnull' => (bool) ($val['null'] === ''), // not null is empty, null is yes + 'default' => $val['default'], + 'primary' => (strtolower($val['key']) == 'pri'), + 'autoinc' => (strtolower($val['extra']) == 'auto_increment'), + ); + } + } + return $info; + } + + /** + * 取得数据库的表信息 + * @access public + * @return array + */ + public function getTables($dbName='') { + $result = $this->query("select tablename as Tables_in_test from pg_tables where schemaname ='public'"); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = current($val); + } + return $info; + } + + /** + * limit分析 + * @access protected + * @param mixed $lmit + * @return string + */ + public function parseLimit($limit) { + $limitStr = ''; + if(!empty($limit)) { + $limit = explode(',',$limit); + if(count($limit)>1) { + $limitStr .= ' LIMIT '.$limit[1].' OFFSET '.$limit[0].' '; + }else{ + $limitStr .= ' LIMIT '.$limit[0].' '; + } + } + return $limitStr; + } + +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Sqlite.class.php b/ThinkPHP/Library/Think/Db/Driver/Sqlite.class.php new file mode 100644 index 0000000..d7fd641 --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Sqlite.class.php @@ -0,0 +1,98 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; + +/** + * Sqlite数据库驱动 + */ +class Sqlite extends Driver { + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'sqlite:'.$config['database']; + return $dsn; + } + + /** + * 取得数据表的字段信息 + * @access public + * @return array + */ + public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); + $result = $this->query('PRAGMA table_info( '.$tableName.' )'); + $info = array(); + if($result){ + foreach ($result as $key => $val) { + $info[$val['field']] = array( + 'name' => $val['field'], + 'type' => $val['type'], + 'notnull' => (bool) ($val['null'] === ''), // not null is empty, null is yes + 'default' => $val['default'], + 'primary' => (strtolower($val['dey']) == 'pri'), + 'autoinc' => (strtolower($val['extra']) == 'auto_increment'), + ); + } + } + return $info; + } + + /** + * 取得数据库的表信息 + * @access public + * @return array + */ + public function getTables($dbName='') { + $result = $this->query("SELECT name FROM sqlite_master WHERE type='table' " + . "UNION ALL SELECT name FROM sqlite_temp_master " + . "WHERE type='table' ORDER BY name"); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = current($val); + } + return $info; + } + + /** + * SQL指令安全过滤 + * @access public + * @param string $str SQL指令 + * @return string + */ + public function escapeString($str) { + return str_ireplace("'", "''", $str); + } + + /** + * limit + * @access public + * @return string + */ + public function parseLimit($limit) { + $limitStr = ''; + if(!empty($limit)) { + $limit = explode(',',$limit); + if(count($limit)>1) { + $limitStr .= ' LIMIT '.$limit[1].' OFFSET '.$limit[0].' '; + }else{ + $limitStr .= ' LIMIT '.$limit[0].' '; + } + } + return $limitStr; + } +} diff --git a/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php b/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php new file mode 100644 index 0000000..9df1c92 --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Driver/Sqlsrv.class.php @@ -0,0 +1,166 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db\Driver; +use Think\Db\Driver; +use PDO; + +/** + * Sqlsrv数据库驱动 + */ +class Sqlsrv extends Driver{ + protected $selectSql = 'SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER (%ORDER%) AS ROW_NUMBER FROM (SELECT %DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING% %UNION%) AS thinkphp) AS T1 %LIMIT%%COMMENT%'; + // PDO连接参数 + protected $options = array( + PDO::ATTR_CASE => PDO::CASE_LOWER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_STRINGIFY_FETCHES => false, + PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_UTF8, + ); + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){ + $dsn = 'sqlsrv:Database='.$config['database'].';Server='.$config['hostname']; + if(!empty($config['hostport'])) { + $dsn .= ','.$config['hostport']; + } + return $dsn; + } + + /** + * 取得数据表的字段信息 + * @access public + * @return array + */ + public function getFields($tableName) { + list($tableName) = explode(' ', $tableName); + $result = $this->query("SELECT column_name, data_type, column_default, is_nullable + FROM information_schema.tables AS t + JOIN information_schema.columns AS c + ON t.table_catalog = c.table_catalog + AND t.table_schema = c.table_schema + AND t.table_name = c.table_name + WHERE t.table_name = '$tableName'"); + $info = array(); + if($result) { + foreach ($result as $key => $val) { + $info[$val['column_name']] = array( + 'name' => $val['column_name'], + 'type' => $val['data_type'], + 'notnull' => (bool) ($val['is_nullable'] === ''), // not null is empty, null is yes + 'default' => $val['column_default'], + 'primary' => false, + 'autoinc' => false, + ); + } + } + return $info; + } + + /** + * 取得数据表的字段信息 + * @access public + * @return array + */ + public function getTables($dbName='') { + $result = $this->query("SELECT TABLE_NAME + FROM INFORMATION_SCHEMA.TABLES + WHERE TABLE_TYPE = 'BASE TABLE' + "); + $info = array(); + foreach ($result as $key => $val) { + $info[$key] = current($val); + } + return $info; + } + + /** + * order分析 + * @access protected + * @param mixed $order + * @return string + */ + protected function parseOrder($order) { + return !empty($order)? ' ORDER BY '.$order:' ORDER BY rand()'; + } + + /** + * 字段名分析 + * @access protected + * @param string $key + * @return string + */ + protected function parseKey(&$key) { + $key = trim($key); + if(!is_numeric($key) && !preg_match('/[,\'\"\*\(\)\[.\s]/',$key)) { + $key = '['.$key.']'; + } + return $key; + } + + /** + * limit + * @access public + * @param mixed $limit + * @return string + */ + public function parseLimit($limit) { + if(empty($limit)) return ''; + $limit = explode(',',$limit); + if(count($limit)>1) + $limitStr = '(T1.ROW_NUMBER BETWEEN '.$limit[0].' + 1 AND '.$limit[0].' + '.$limit[1].')'; + else + $limitStr = '(T1.ROW_NUMBER BETWEEN 1 AND '.$limit[0].")"; + return 'WHERE '.$limitStr; + } + + /** + * 更新记录 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @return false | integer + */ + public function update($data,$options) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $sql = 'UPDATE ' + .$this->parseTable($options['table']) + .$this->parseSet($data) + .$this->parseWhere(!empty($options['where'])?$options['where']:'') + .$this->parseLock(isset($options['lock'])?$options['lock']:false) + .$this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + + /** + * 删除记录 + * @access public + * @param array $options 表达式 + * @return false | integer + */ + public function delete($options=array()) { + $this->model = $options['model']; + $this->parseBind(!empty($options['bind'])?$options['bind']:array()); + $sql = 'DELETE FROM ' + .$this->parseTable($options['table']) + .$this->parseWhere(!empty($options['where'])?$options['where']:'') + .$this->parseLock(isset($options['lock'])?$options['lock']:false) + .$this->parseComment(!empty($options['comment'])?$options['comment']:''); + return $this->execute($sql,!empty($options['fetch_sql']) ? true : false); + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Db/Lite.class.php b/ThinkPHP/Library/Think/Db/Lite.class.php new file mode 100644 index 0000000..577c44b --- /dev/null +++ b/ThinkPHP/Library/Think/Db/Lite.class.php @@ -0,0 +1,466 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Db; +use Think\Config; +use Think\Debug; +use Think\Log; +use PDO; + +class Lite { + // PDO操作实例 + protected $PDOStatement = null; + // 当前操作所属的模型名 + protected $model = '_think_'; + // 当前SQL指令 + protected $queryStr = ''; + protected $modelSql = array(); + // 最后插入ID + protected $lastInsID = null; + // 返回或者影响记录数 + protected $numRows = 0; + // 事务指令数 + protected $transTimes = 0; + // 错误信息 + protected $error = ''; + // 数据库连接ID 支持多个连接 + protected $linkID = array(); + // 当前连接ID + protected $_linkID = null; + // 数据库连接参数配置 + protected $config = array( + 'type' => '', // 数据库类型 + 'hostname' => '127.0.0.1', // 服务器地址 + 'database' => '', // 数据库名 + 'username' => '', // 用户名 + 'password' => '', // 密码 + 'hostport' => '', // 端口 + 'dsn' => '', // + 'params' => array(), // 数据库连接参数 + 'charset' => 'utf8', // 数据库编码默认采用utf8 + 'prefix' => '', // 数据库表前缀 + 'debug' => false, // 数据库调试模式 + 'deploy' => 0, // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器) + 'rw_separate' => false, // 数据库读写是否分离 主从式有效 + 'master_num' => 1, // 读写分离后 主服务器数量 + 'slave_no' => '', // 指定从服务器序号 + ); + // 数据库表达式 + protected $comparison = array('eq'=>'=','neq'=>'<>','gt'=>'>','egt'=>'>=','lt'=>'<','elt'=>'<=','notlike'=>'NOT LIKE','like'=>'LIKE','in'=>'IN','notin'=>'NOT IN'); + // 查询表达式 + protected $selectSql = 'SELECT%DISTINCT% %FIELD% FROM %TABLE%%JOIN%%WHERE%%GROUP%%HAVING%%ORDER%%LIMIT% %UNION%%COMMENT%'; + // 查询次数 + protected $queryTimes = 0; + // 执行次数 + protected $executeTimes = 0; + // PDO连接参数 + protected $options = array( + PDO::ATTR_CASE => PDO::CASE_LOWER, + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, + PDO::ATTR_STRINGIFY_FETCHES => false, + ); + + /** + * 架构函数 读取数据库配置信息 + * @access public + * @param array $config 数据库配置数组 + */ + public function __construct($config=''){ + if(!empty($config)) { + $this->config = array_merge($this->config,$config); + if(is_array($this->config['params'])){ + $this->options += $this->config['params']; + } + } + } + + /** + * 连接数据库方法 + * @access public + */ + public function connect($config='',$linkNum=0) { + if ( !isset($this->linkID[$linkNum]) ) { + if(empty($config)) $config = $this->config; + try{ + if(empty($config['dsn'])) { + $config['dsn'] = $this->parseDsn($config); + } + if(version_compare(PHP_VERSION,'5.3.6','<=')){ //禁用模拟预处理语句 + $this->options[PDO::ATTR_EMULATE_PREPARES] = false; + } + $this->linkID[$linkNum] = new PDO( $config['dsn'], $config['username'], $config['password'],$this->options); + }catch (\PDOException $e) { + E($e->getMessage()); + } + } + return $this->linkID[$linkNum]; + } + + /** + * 解析pdo连接的dsn信息 + * @access public + * @param array $config 连接信息 + * @return string + */ + protected function parseDsn($config){} + + /** + * 释放查询结果 + * @access public + */ + public function free() { + $this->PDOStatement = null; + } + + /** + * 执行查询 返回数据集 + * @access public + * @param string $str sql指令 + * @param array $bind 参数绑定 + * @return mixed + */ + public function query($str,$bind=array()) { + $this->initConnect(false); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$bind)); + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->queryTimes++; + N('db_query',1); // 兼容代码 + // 调试开始 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement) + E($this->error()); + foreach ($bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $result = $this->PDOStatement->execute(); + // 调试结束 + $this->debug(false); + if ( false === $result ) { + $this->error(); + return false; + } else { + return $this->getResult(); + } + } + + /** + * 执行语句 + * @access public + * @param string $str sql指令 + * @param array $bind 参数绑定 + * @return integer + */ + public function execute($str,$bind=array()) { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + $this->queryStr = $str; + if(!empty($bind)){ + $that = $this; + $this->queryStr = strtr($this->queryStr,array_map(function($val) use($that){ return '\''.$that->escapeString($val).'\''; },$bind)); + } + //释放前次的查询结果 + if ( !empty($this->PDOStatement) ) $this->free(); + $this->executeTimes++; + N('db_write',1); // 兼容代码 + // 记录开始执行时间 + $this->debug(true); + $this->PDOStatement = $this->_linkID->prepare($str); + if(false === $this->PDOStatement) { + E($this->error()); + } + foreach ($bind as $key => $val) { + if(is_array($val)){ + $this->PDOStatement->bindValue($key, $val[0], $val[1]); + }else{ + $this->PDOStatement->bindValue($key, $val); + } + } + $result = $this->PDOStatement->execute(); + $this->debug(false); + if ( false === $result) { + $this->error(); + return false; + } else { + $this->numRows = $this->PDOStatement->rowCount(); + if(preg_match("/^\s*(INSERT\s+INTO|REPLACE\s+INTO)\s+/i", $str)) { + $this->lastInsID = $this->_linkID->lastInsertId(); + } + return $this->numRows; + } + } + + /** + * 启动事务 + * @access public + * @return void + */ + public function startTrans() { + $this->initConnect(true); + if ( !$this->_linkID ) return false; + //数据rollback 支持 + if ($this->transTimes == 0) { + $this->_linkID->beginTransaction(); + } + $this->transTimes++; + return ; + } + + /** + * 用于非自动提交状态下面的查询提交 + * @access public + * @return boolean + */ + public function commit() { + if ($this->transTimes > 0) { + $result = $this->_linkID->commit(); + $this->transTimes = 0; + if(!$result){ + $this->error(); + return false; + } + } + return true; + } + + /** + * 事务回滚 + * @access public + * @return boolean + */ + public function rollback() { + if ($this->transTimes > 0) { + $result = $this->_linkID->rollback(); + $this->transTimes = 0; + if(!$result){ + $this->error(); + return false; + } + } + return true; + } + + /** + * 获得所有的查询数据 + * @access private + * @return array + */ + private function getResult() { + //返回数据集 + $result = $this->PDOStatement->fetchAll(PDO::FETCH_ASSOC); + $this->numRows = count( $result ); + return $result; + } + + /** + * 获得查询次数 + * @access public + * @param boolean $execute 是否包含所有查询 + * @return integer + */ + public function getQueryTimes($execute=false){ + return $execute?$this->queryTimes+$this->executeTimes:$this->queryTimes; + } + + /** + * 获得执行次数 + * @access public + * @return integer + */ + public function getExecuteTimes(){ + return $this->executeTimes; + } + + /** + * 关闭数据库 + * @access public + */ + public function close() { + $this->_linkID = null; + } + + /** + * 数据库错误信息 + * 并显示当前的SQL语句 + * @access public + * @return string + */ + public function error() { + if($this->PDOStatement) { + $error = $this->PDOStatement->errorInfo(); + $this->error = $error[1].':'.$error[2]; + }else{ + $this->error = ''; + } + if('' != $this->queryStr){ + $this->error .= "\n [ SQL语句 ] : ".$this->queryStr; + } + // 记录错误日志 + trace($this->error,'','ERR'); + if($this->config['debug']) {// 开启数据库调试模式 + E($this->error); + }else{ + return $this->error; + } + } + + /** + * 获取最近一次查询的sql语句 + * @param string $model 模型名 + * @access public + * @return string + */ + public function getLastSql($model='') { + return $model?$this->modelSql[$model]:$this->queryStr; + } + + /** + * 获取最近插入的ID + * @access public + * @return string + */ + public function getLastInsID() { + return $this->lastInsID; + } + + /** + * 获取最近的错误信息 + * @access public + * @return string + */ + public function getError() { + return $this->error; + } + + /** + * SQL指令安全过滤 + * @access public + * @param string $str SQL字符串 + * @return string + */ + public function escapeString($str) { + return addslashes($str); + } + + /** + * 设置当前操作模型 + * @access public + * @param string $model 模型名 + * @return void + */ + public function setModel($model){ + $this->model = $model; + } + + /** + * 数据库调试 记录当前SQL + * @access protected + * @param boolean $start 调试开始标记 true 开始 false 结束 + */ + protected function debug($start) { + if($this->config['debug']) {// 开启数据库调试模式 + if($start) { + G('queryStartTime'); + }else{ + $this->modelSql[$this->model] = $this->queryStr; + //$this->model = '_think_'; + // 记录操作结束时间 + G('queryEndTime'); + trace($this->queryStr.' [ RunTime:'.G('queryStartTime','queryEndTime').'s ]','','SQL'); + } + } + } + + /** + * 初始化数据库连接 + * @access protected + * @param boolean $master 主服务器 + * @return void + */ + protected function initConnect($master=true) { + if(!empty($this->config['deploy'])) + // 采用分布式数据库 + $this->_linkID = $this->multiConnect($master); + else + // 默认单数据库 + if ( !$this->_linkID ) $this->_linkID = $this->connect(); + } + + /** + * 连接分布式服务器 + * @access protected + * @param boolean $master 主服务器 + * @return void + */ + protected function multiConnect($master=false) { + // 分布式数据库配置解析 + $_config['username'] = explode(',',$this->config['username']); + $_config['password'] = explode(',',$this->config['password']); + $_config['hostname'] = explode(',',$this->config['hostname']); + $_config['hostport'] = explode(',',$this->config['hostport']); + $_config['database'] = explode(',',$this->config['database']); + $_config['dsn'] = explode(',',$this->config['dsn']); + $_config['charset'] = explode(',',$this->config['charset']); + + // 数据库读写是否分离 + if($this->config['rw_separate']){ + // 主从式采用读写分离 + if($master) + // 主服务器写入 + $r = floor(mt_rand(0,$this->config['master_num']-1)); + else{ + if(is_numeric($this->config['slave_no'])) {// 指定服务器读 + $r = $this->config['slave_no']; + }else{ + // 读操作连接从服务器 + $r = floor(mt_rand($this->config['master_num'],count($_config['hostname'])-1)); // 每次随机连接的数据库 + } + } + }else{ + // 读写操作不区分服务器 + $r = floor(mt_rand(0,count($_config['hostname'])-1)); // 每次随机连接的数据库 + } + $db_config = array( + 'username' => isset($_config['username'][$r])?$_config['username'][$r]:$_config['username'][0], + 'password' => isset($_config['password'][$r])?$_config['password'][$r]:$_config['password'][0], + 'hostname' => isset($_config['hostname'][$r])?$_config['hostname'][$r]:$_config['hostname'][0], + 'hostport' => isset($_config['hostport'][$r])?$_config['hostport'][$r]:$_config['hostport'][0], + 'database' => isset($_config['database'][$r])?$_config['database'][$r]:$_config['database'][0], + 'dsn' => isset($_config['dsn'][$r])?$_config['dsn'][$r]:$_config['dsn'][0], + 'charset' => isset($_config['charset'][$r])?$_config['charset'][$r]:$_config['charset'][0], + ); + return $this->connect($db_config,$r); + } + + /** + * 析构方法 + * @access public + */ + public function __destruct() { + // 释放查询 + if ($this->PDOStatement){ + $this->free(); + } + // 关闭连接 + $this->close(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Dispatcher.class.php b/ThinkPHP/Library/Think/Dispatcher.class.php new file mode 100644 index 0000000..0065cfb --- /dev/null +++ b/ThinkPHP/Library/Think/Dispatcher.class.php @@ -0,0 +1,339 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP内置的Dispatcher类 + * 完成URL解析、路由和调度 + */ +class Dispatcher { + + /** + * URL映射到控制器 + * @access public + * @return void + */ + static public function dispatch() { + $varPath = C('VAR_PATHINFO'); + $varAddon = C('VAR_ADDON'); + $varModule = C('VAR_MODULE'); + $varController = C('VAR_CONTROLLER'); + $varAction = C('VAR_ACTION'); + $urlCase = C('URL_CASE_INSENSITIVE'); + if(isset($_GET[$varPath])) { // 判断URL里面是否有兼容模式参数 + $_SERVER['PATH_INFO'] = $_GET[$varPath]; + unset($_GET[$varPath]); + }elseif(IS_CLI){ // CLI模式下 index.php module/controller/action/params/... + $_SERVER['PATH_INFO'] = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; + } + + // 开启子域名部署 + if(C('APP_SUB_DOMAIN_DEPLOY')) { + $rules = C('APP_SUB_DOMAIN_RULES'); + if(isset($rules[$_SERVER['HTTP_HOST']])) { // 完整域名或者IP配置 + define('APP_DOMAIN',$_SERVER['HTTP_HOST']); // 当前完整域名 + $rule = $rules[APP_DOMAIN]; + }else{ + if(strpos(C('APP_DOMAIN_SUFFIX'),'.')){ // com.cn net.cn + $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -3); + }else{ + $domain = array_slice(explode('.', $_SERVER['HTTP_HOST']), 0, -2); + } + if(!empty($domain)) { + $subDomain = implode('.', $domain); + define('SUB_DOMAIN',$subDomain); // 当前完整子域名 + $domain2 = array_pop($domain); // 二级域名 + if($domain) { // 存在三级域名 + $domain3 = array_pop($domain); + } + if(isset($rules[$subDomain])) { // 子域名 + $rule = $rules[$subDomain]; + }elseif(isset($rules['*.' . $domain2]) && !empty($domain3)){ // 泛三级域名 + $rule = $rules['*.' . $domain2]; + $panDomain = $domain3; + }elseif(isset($rules['*']) && !empty($domain2) && 'www' != $domain2 ){ // 泛二级域名 + $rule = $rules['*']; + $panDomain = $domain2; + } + } + } + + if(!empty($rule)) { + // 子域名部署规则 '子域名'=>array('模块名[/控制器名]','var1=a&var2=b'); + if(is_array($rule)){ + list($rule,$vars) = $rule; + } + $array = explode('/',$rule); + // 模块绑定 + define('BIND_MODULE',array_shift($array)); + // 控制器绑定 + if(!empty($array)) { + $controller = array_shift($array); + if($controller){ + define('BIND_CONTROLLER',$controller); + } + } + if(isset($vars)) { // 传入参数 + parse_str($vars,$parms); + if(isset($panDomain)){ + $pos = array_search('*', $parms); + if(false !== $pos) { + // 泛域名作为参数 + $parms[$pos] = $panDomain; + } + } + $_GET = array_merge($_GET,$parms); + } + } + } + // 分析PATHINFO信息 + if(!isset($_SERVER['PATH_INFO'])) { + $types = explode(',',C('URL_PATHINFO_FETCH')); + foreach ($types as $type){ + if(0===strpos($type,':')) {// 支持函数判断 + $_SERVER['PATH_INFO'] = call_user_func(substr($type,1)); + break; + }elseif(!empty($_SERVER[$type])) { + $_SERVER['PATH_INFO'] = (0 === strpos($_SERVER[$type],$_SERVER['SCRIPT_NAME']))? + substr($_SERVER[$type], strlen($_SERVER['SCRIPT_NAME'])) : $_SERVER[$type]; + break; + } + } + } + + $depr = C('URL_PATHINFO_DEPR'); + define('MODULE_PATHINFO_DEPR', $depr); + + if(empty($_SERVER['PATH_INFO'])) { + $_SERVER['PATH_INFO'] = ''; + define('__INFO__',''); + define('__EXT__',''); + }else{ + define('__INFO__',trim($_SERVER['PATH_INFO'],'/')); + // URL后缀 + define('__EXT__', strtolower(pathinfo($_SERVER['PATH_INFO'],PATHINFO_EXTENSION))); + $_SERVER['PATH_INFO'] = __INFO__; + if(!defined('BIND_MODULE') && (!C('URL_ROUTER_ON') || !Route::check())){ + if (__INFO__ && C('MULTI_MODULE')){ // 获取模块名 + $paths = explode($depr,__INFO__,2); + $allowList = C('MODULE_ALLOW_LIST'); // 允许的模块列表 + $module = preg_replace('/\.' . __EXT__ . '$/i', '',$paths[0]); + if( empty($allowList) || (is_array($allowList) && in_array_case($module, $allowList))){ + $_GET[$varModule] = $module; + $_SERVER['PATH_INFO'] = isset($paths[1])?$paths[1]:''; + } + } + } + } + + // URL常量 + define('__SELF__',strip_tags($_SERVER[C('URL_REQUEST_URI')])); + + // 获取模块名称 + define('MODULE_NAME', defined('BIND_MODULE')? BIND_MODULE : self::getModule($varModule)); + + // 检测模块是否存在 + if( MODULE_NAME && (defined('BIND_MODULE') || !in_array_case(MODULE_NAME,C('MODULE_DENY_LIST')) ) && is_dir(APP_PATH.MODULE_NAME)){ + // 定义当前模块路径 + define('MODULE_PATH', APP_PATH.MODULE_NAME.'/'); + // 定义当前模块的模版缓存路径 + C('CACHE_PATH',CACHE_PATH.MODULE_NAME.'/'); + // 定义当前模块的日志目录 + C('LOG_PATH', realpath(LOG_PATH).'/'.MODULE_NAME.'/'); + + // 模块检测 + Hook::listen('module_check'); + + // 加载模块配置文件 + if(is_file(MODULE_PATH.'Conf/config'.CONF_EXT)) + C(load_config(MODULE_PATH.'Conf/config'.CONF_EXT)); + // 加载应用模式对应的配置文件 + if('common' != APP_MODE && is_file(MODULE_PATH.'Conf/config_'.APP_MODE.CONF_EXT)) + C(load_config(MODULE_PATH.'Conf/config_'.APP_MODE.CONF_EXT)); + // 当前应用状态对应的配置文件 + if(APP_STATUS && is_file(MODULE_PATH.'Conf/'.APP_STATUS.CONF_EXT)) + C(load_config(MODULE_PATH.'Conf/'.APP_STATUS.CONF_EXT)); + + // 加载模块别名定义 + if(is_file(MODULE_PATH.'Conf/alias.php')) + Think::addMap(include MODULE_PATH.'Conf/alias.php'); + // 加载模块tags文件定义 + if(is_file(MODULE_PATH.'Conf/tags.php')) + Hook::import(include MODULE_PATH.'Conf/tags.php'); + // 加载模块函数文件 + if(is_file(MODULE_PATH.'Common/function.php')) + include MODULE_PATH.'Common/function.php'; + + $urlCase = C('URL_CASE_INSENSITIVE'); + // 加载模块的扩展配置文件 + load_ext_file(MODULE_PATH); + }else{ + E(L('_MODULE_NOT_EXIST_').':'.MODULE_NAME); + } + + if(!defined('__APP__')){ + $urlMode = C('URL_MODEL'); + if($urlMode == URL_COMPAT ){// 兼容模式判断 + define('PHP_FILE',_PHP_FILE_.'?'.$varPath.'='); + }elseif($urlMode == URL_REWRITE ) { + $url = dirname(_PHP_FILE_); + if($url == '/' || $url == '\\') + $url = ''; + define('PHP_FILE',$url); + }else { + define('PHP_FILE',_PHP_FILE_); + } + // 当前应用地址 + define('__APP__',strip_tags(PHP_FILE)); + } + // 模块URL地址 + $moduleName = defined('MODULE_ALIAS')? MODULE_ALIAS : MODULE_NAME; + define('__MODULE__',(defined('BIND_MODULE') || !C('MULTI_MODULE'))? __APP__ : __APP__.'/'.($urlCase ? strtolower($moduleName) : $moduleName)); + + if('' != $_SERVER['PATH_INFO'] && (!C('URL_ROUTER_ON') || !Route::check()) ){ // 检测路由规则 如果没有则按默认规则调度URL + Hook::listen('path_info'); + // 检查禁止访问的URL后缀 + if(C('URL_DENY_SUFFIX') && preg_match('/\.('.trim(C('URL_DENY_SUFFIX'),'.').')$/i', $_SERVER['PATH_INFO'])){ + send_http_status(404); + exit; + } + + // 去除URL后缀 + $_SERVER['PATH_INFO'] = preg_replace(C('URL_HTML_SUFFIX')? '/\.('.trim(C('URL_HTML_SUFFIX'),'.').')$/i' : '/\.'.__EXT__.'$/i', '', $_SERVER['PATH_INFO']); + + $depr = C('URL_PATHINFO_DEPR'); + $paths = explode($depr,trim($_SERVER['PATH_INFO'],$depr)); + + if(!defined('BIND_CONTROLLER')) {// 获取控制器 + if(C('CONTROLLER_LEVEL')>1){// 控制器层次 + $_GET[$varController] = implode('/',array_slice($paths,0,C('CONTROLLER_LEVEL'))); + $paths = array_slice($paths, C('CONTROLLER_LEVEL')); + }else{ + $_GET[$varController] = array_shift($paths); + } + } + // 获取操作 + if(!defined('BIND_ACTION')){ + $_GET[$varAction] = array_shift($paths); + } + // 解析剩余的URL参数 + $var = array(); + if(C('URL_PARAMS_BIND') && 1 == C('URL_PARAMS_BIND_TYPE')){ + // URL参数按顺序绑定变量 + $var = $paths; + }else{ + preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){$var[$match[1]]=strip_tags($match[2]);}, implode('/',$paths)); + } + $_GET = array_merge($var,$_GET); + } + // 获取控制器的命名空间(路径) + define('CONTROLLER_PATH', self::getSpace($varAddon,$urlCase)); + // 获取控制器和操作名 + define('CONTROLLER_NAME', defined('BIND_CONTROLLER')? BIND_CONTROLLER : self::getController($varController,$urlCase)); + define('ACTION_NAME', defined('BIND_ACTION')? BIND_ACTION : self::getAction($varAction,$urlCase)); + + // 当前控制器的UR地址 + $controllerName = defined('CONTROLLER_ALIAS')? CONTROLLER_ALIAS : CONTROLLER_NAME; + define('__CONTROLLER__',__MODULE__.$depr.(defined('BIND_CONTROLLER')? '': ( $urlCase ? parse_name($controllerName) : $controllerName )) ); + + // 当前操作的URL地址 + define('__ACTION__',__CONTROLLER__.$depr.(defined('ACTION_ALIAS')?ACTION_ALIAS:ACTION_NAME)); + + //保证$_REQUEST正常取值 + $_REQUEST = array_merge($_POST,$_GET,$_COOKIE); // -- 加了$_COOKIE. 保证哦.. + } + + /** + * 获得控制器的命名空间路径 便于插件机制访问 + */ + static private function getSpace($var,$urlCase) { + $space = !empty($_GET[$var])?strip_tags($_GET[$var]):''; + unset($_GET[$var]); + return $space; + } + + /** + * 获得实际的控制器名称 + */ + static private function getController($var,$urlCase) { + $controller = (!empty($_GET[$var])? $_GET[$var]:C('DEFAULT_CONTROLLER')); + unset($_GET[$var]); + if($maps = C('URL_CONTROLLER_MAP')) { + if(isset($maps[strtolower($controller)])) { + // 记录当前别名 + define('CONTROLLER_ALIAS',strtolower($controller)); + // 获取实际的控制器名 + return ucfirst($maps[CONTROLLER_ALIAS]); + }elseif(array_search(strtolower($controller),$maps)){ + // 禁止访问原始控制器 + return ''; + } + } + if($urlCase) { + // URL地址不区分大小写 + // 智能识别方式 user_type 识别到 UserTypeController 控制器 + $controller = parse_name($controller,1); + } + return strip_tags(ucfirst($controller)); + } + + /** + * 获得实际的操作名称 + */ + static private function getAction($var,$urlCase) { + $action = !empty($_POST[$var]) ? + $_POST[$var] : + (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_ACTION')); + unset($_POST[$var],$_GET[$var]); + if($maps = C('URL_ACTION_MAP')) { + if(isset($maps[strtolower(CONTROLLER_NAME)])) { + $maps = $maps[strtolower(CONTROLLER_NAME)]; + if(isset($maps[strtolower($action)])) { + // 记录当前别名 + define('ACTION_ALIAS',strtolower($action)); + // 获取实际的操作名 + if(is_array($maps[ACTION_ALIAS])){ + parse_str($maps[ACTION_ALIAS][1],$vars); + $_GET = array_merge($_GET,$vars); + return $maps[ACTION_ALIAS][0]; + }else{ + return $maps[ACTION_ALIAS]; + } + + }elseif(array_search(strtolower($action),$maps)){ + // 禁止访问原始操作 + return ''; + } + } + } + return strip_tags( $urlCase? strtolower($action) : $action ); + } + + /** + * 获得实际的模块名称 + */ + static private function getModule($var) { + $module = (!empty($_GET[$var])?$_GET[$var]:C('DEFAULT_MODULE')); + unset($_GET[$var]); + if($maps = C('URL_MODULE_MAP')) { + if(isset($maps[strtolower($module)])) { + // 记录当前别名 + define('MODULE_ALIAS',strtolower($module)); + // 获取实际的模块名 + return ucfirst($maps[MODULE_ALIAS]); + }elseif(array_search(strtolower($module),$maps)){ + // 禁止访问原始模块 + return ''; + } + } + return strip_tags(ucfirst($module)); + } + +} diff --git a/ThinkPHP/Library/Think/Exception.class.php b/ThinkPHP/Library/Think/Exception.class.php new file mode 100644 index 0000000..7b4a918 --- /dev/null +++ b/ThinkPHP/Library/Think/Exception.class.php @@ -0,0 +1,16 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP系统异常基类 + */ +class Exception extends \Exception { +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Hook.class.php b/ThinkPHP/Library/Think/Hook.class.php new file mode 100644 index 0000000..51176c7 --- /dev/null +++ b/ThinkPHP/Library/Think/Hook.class.php @@ -0,0 +1,121 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP系统钩子实现 + */ +class Hook { + + static private $tags = array(); + + /** + * 动态添加插件到某个标签 + * @param string $tag 标签名称 + * @param mixed $name 插件名称 + * @return void + */ + static public function add($tag,$name) { + if(!isset(self::$tags[$tag])){ + self::$tags[$tag] = array(); + } + if(is_array($name)){ + self::$tags[$tag] = array_merge(self::$tags[$tag],$name); + }else{ + self::$tags[$tag][] = $name; + } + } + + /** + * 批量导入插件 + * @param array $data 插件信息 + * @param boolean $recursive 是否递归合并 + * @return void + */ + static public function import($data,$recursive=true) { + if(!$recursive){ // 覆盖导入 + self::$tags = array_merge(self::$tags,$data); + }else{ // 合并导入 + foreach ($data as $tag=>$val){ + if(!isset(self::$tags[$tag])) + self::$tags[$tag] = array(); + if(!empty($val['_overlay'])){ + // 可以针对某个标签指定覆盖模式 + unset($val['_overlay']); + self::$tags[$tag] = $val; + }else{ + // 合并模式 + self::$tags[$tag] = array_merge(self::$tags[$tag],$val); + } + } + } + } + + /** + * 获取插件信息 + * @param string $tag 插件位置 留空获取全部 + * @return array + */ + static public function get($tag='') { + if(empty($tag)){ + // 获取全部的插件信息 + return self::$tags; + }else{ + return self::$tags[$tag]; + } + } + + /** + * 监听标签的插件 + * @param string $tag 标签名称 + * @param mixed $params 传入参数 + * @return void + */ + static public function listen($tag, &$params=NULL) { + if(isset(self::$tags[$tag])) { + if(APP_DEBUG) { + G($tag.'Start'); + trace('[ '.$tag.' ] --START--','','INFO'); + } + foreach (self::$tags[$tag] as $name) { + APP_DEBUG && G($name.'_start'); + $result = self::exec($name, $tag,$params); + if(APP_DEBUG){ + G($name.'_end'); + trace('Run '.$name.' [ RunTime:'.G($name.'_start',$name.'_end',6).'s ]','','INFO'); + } + if(false === $result) { + // 如果返回false 则中断插件执行 + return ; + } + } + if(APP_DEBUG) { // 记录行为的执行日志 + trace('[ '.$tag.' ] --END-- [ RunTime:'.G($tag.'Start',$tag.'End',6).'s ]','','INFO'); + } + } + return; + } + + /** + * 执行某个插件 + * @param string $name 插件名称 + * @param string $tag 方法名(标签名) + * @param Mixed $params 传入的参数 + * @return void + */ + static public function exec($name, $tag,&$params=NULL) { + if('Behavior' == substr($name,-8) ){ + // 行为扩展必须用run入口方法 + $tag = 'run'; + } + $addon = new $name(); + return $addon->$tag($params); + } +} diff --git a/ThinkPHP/Library/Think/Image.class.php b/ThinkPHP/Library/Think/Image.class.php new file mode 100644 index 0000000..178365e --- /dev/null +++ b/ThinkPHP/Library/Think/Image.class.php @@ -0,0 +1,191 @@ + +// +---------------------------------------------------------------------- +// | ThinkImage.class.php 2013-03-05 +// +---------------------------------------------------------------------- + +namespace Think; + +/** + * 图片处理驱动类,可配置图片处理库 + * 目前支持GD库和imagick + * @author 麦当苗儿 + */ +class Image{ + /* 驱动相关常量定义 */ + const IMAGE_GD = 1; //常量,标识GD库类型 + const IMAGE_IMAGICK = 2; //常量,标识imagick库类型 + + /* 缩略图相关常量定义 */ + const IMAGE_THUMB_SCALE = 1 ; //常量,标识缩略图等比例缩放类型 + const IMAGE_THUMB_FILLED = 2 ; //常量,标识缩略图缩放后填充类型 + const IMAGE_THUMB_CENTER = 3 ; //常量,标识缩略图居中裁剪类型 + const IMAGE_THUMB_NORTHWEST = 4 ; //常量,标识缩略图左上角裁剪类型 + const IMAGE_THUMB_SOUTHEAST = 5 ; //常量,标识缩略图右下角裁剪类型 + const IMAGE_THUMB_FIXED = 6 ; //常量,标识缩略图固定尺寸缩放类型 + + /* 水印相关常量定义 */ + const IMAGE_WATER_NORTHWEST = 1 ; //常量,标识左上角水印 + const IMAGE_WATER_NORTH = 2 ; //常量,标识上居中水印 + const IMAGE_WATER_NORTHEAST = 3 ; //常量,标识右上角水印 + const IMAGE_WATER_WEST = 4 ; //常量,标识左居中水印 + const IMAGE_WATER_CENTER = 5 ; //常量,标识居中水印 + const IMAGE_WATER_EAST = 6 ; //常量,标识右居中水印 + const IMAGE_WATER_SOUTHWEST = 7 ; //常量,标识左下角水印 + const IMAGE_WATER_SOUTH = 8 ; //常量,标识下居中水印 + const IMAGE_WATER_SOUTHEAST = 9 ; //常量,标识右下角水印 + + /** + * 图片资源 + * @var resource + */ + private $img; + + /** + * 构造方法,用于实例化一个图片处理对象 + * @param string $type 要使用的类库,默认使用GD库 + */ + public function __construct($type = self::IMAGE_GD, $imgname = null){ + /* 判断调用库的类型 */ + switch ($type) { + case self::IMAGE_GD: + $class = 'Gd'; + break; + case self::IMAGE_IMAGICK: + $class = 'Imagick'; + break; + default: + E('不支持的图片处理库类型'); + } + + /* 引入处理库,实例化图片处理对象 */ + $class = "Think\\Image\\Driver\\{$class}"; + $this->img = new $class($imgname); + } + + /** + * 打开一幅图像 + * @param string $imgname 图片路径 + * @return Object 当前图片处理库对象 + */ + public function open($imgname){ + $this->img->open($imgname); + return $this; + } + + /** + * 保存图片 + * @param string $imgname 图片保存名称 + * @param string $type 图片类型 + * @param integer $quality 图像质量 + * @param boolean $interlace 是否对JPEG类型图片设置隔行扫描 + * @return Object 当前图片处理库对象 + */ + public function save($imgname, $type = null, $quality=80,$interlace = true){ + $this->img->save($imgname, $type, $quality,$interlace); + return $this; + } + + /** + * 返回图片宽度 + * @return integer 图片宽度 + */ + public function width(){ + return $this->img->width(); + } + + /** + * 返回图片高度 + * @return integer 图片高度 + */ + public function height(){ + return $this->img->height(); + } + + /** + * 返回图像类型 + * @return string 图片类型 + */ + public function type(){ + return $this->img->type(); + } + + /** + * 返回图像MIME类型 + * @return string 图像MIME类型 + */ + public function mime(){ + return $this->img->mime(); + } + + /** + * 返回图像尺寸数组 0 - 图片宽度,1 - 图片高度 + * @return array 图片尺寸 + */ + public function size(){ + return $this->img->size(); + } + + /** + * 裁剪图片 + * @param integer $w 裁剪区域宽度 + * @param integer $h 裁剪区域高度 + * @param integer $x 裁剪区域x坐标 + * @param integer $y 裁剪区域y坐标 + * @param integer $width 图片保存宽度 + * @param integer $height 图片保存高度 + * @return Object 当前图片处理库对象 + */ + public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){ + $this->img->crop($w, $h, $x, $y, $width, $height); + return $this; + } + + /** + * 生成缩略图 + * @param integer $width 缩略图最大宽度 + * @param integer $height 缩略图最大高度 + * @param integer $type 缩略图裁剪类型 + * @return Object 当前图片处理库对象 + */ + public function thumb($width, $height, $type = self::IMAGE_THUMB_SCALE){ + $this->img->thumb($width, $height, $type); + return $this; + } + + /** + * 添加水印 + * @param string $source 水印图片路径 + * @param integer $locate 水印位置 + * @param integer $alpha 水印透明度 + * @return Object 当前图片处理库对象 + */ + public function water($source, $locate = self::IMAGE_WATER_SOUTHEAST,$alpha=80){ + $this->img->water($source, $locate,$alpha); + return $this; + } + + /** + * 图像添加文字 + * @param string $text 添加的文字 + * @param string $font 字体路径 + * @param integer $size 字号 + * @param string $color 文字颜色 + * @param integer $locate 文字写入位置 + * @param integer $offset 文字相对当前位置的偏移量 + * @param integer $angle 文字倾斜角度 + * @return Object 当前图片处理库对象 + */ + public function text($text, $font, $size, $color = '#00000000', + $locate = self::IMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0){ + $this->img->text($text, $font, $size, $color, $locate, $offset, $angle); + return $this; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Image/Driver/GIF.class.php b/ThinkPHP/Library/Think/Image/Driver/GIF.class.php new file mode 100644 index 0000000..359d2ae --- /dev/null +++ b/ThinkPHP/Library/Think/Image/Driver/GIF.class.php @@ -0,0 +1,567 @@ + +// +---------------------------------------------------------------------- +// | GIF.class.php 2013-03-09 +// +---------------------------------------------------------------------- +namespace Think\Image\Driver; +class GIF{ + /** + * GIF帧列表 + * @var array + */ + private $frames = array(); + + /** + * 每帧等待时间列表 + * @var array + */ + private $delays = array(); + + /** + * 构造方法,用于解码GIF图片 + * @param string $src GIF图片数据 + * @param string $mod 图片数据类型 + */ + public function __construct($src = null, $mod = 'url') { + if(!is_null($src)){ + if('url' == $mod && is_file($src)){ + $src = file_get_contents($src); + } + + /* 解码GIF图片 */ + try{ + $de = new GIFDecoder($src); + $this->frames = $de->GIFGetFrames(); + $this->delays = $de->GIFGetDelays(); + } catch(\Exception $e){ + E("解码GIF图片出错"); + } + } + } + + /** + * 设置或获取当前帧的数据 + * @param string $stream 二进制数据流 + * @return boolean 获取到的数据 + */ + public function image($stream = null){ + if(is_null($stream)){ + $current = current($this->frames); + return false === $current ? reset($this->frames) : $current; + } else { + $this->frames[key($this->frames)] = $stream; + } + } + + /** + * 将当前帧移动到下一帧 + * @return string 当前帧数据 + */ + public function nextImage(){ + return next($this->frames); + } + + /** + * 编码并保存当前GIF图片 + * @param string $gifname 图片名称 + */ + public function save($gifname){ + $gif = new GIFEncoder($this->frames, $this->delays, 0, 2, 0, 0, 0, 'bin'); + file_put_contents($gifname, $gif->GetAnimation()); + } + +} + + +/* +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: GIFEncoder Version 2.0 by László Zsidi, http://gifs.hu +:: +:: This class is a rewritten 'GifMerge.class.php' version. +:: +:: Modification: +:: - Simplified and easy code, +:: - Ultra fast encoding, +:: - Built-in errors, +:: - Stable working +:: +:: +:: Updated at 2007. 02. 13. '00.05.AM' +:: +:: +:: +:: Try on-line GIFBuilder Form demo based on GIFEncoder. +:: +:: http://gifs.hu/phpclasses/demos/GifBuilder/ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +*/ + +Class GIFEncoder { + private $GIF = "GIF89a"; /* GIF header 6 bytes */ + private $VER = "GIFEncoder V2.05"; /* Encoder version */ + + private $BUF = Array ( ); + private $LOP = 0; + private $DIS = 2; + private $COL = -1; + private $IMG = -1; + + private $ERR = Array ( + 'ERR00' => "Does not supported function for only one image!", + 'ERR01' => "Source is not a GIF image!", + 'ERR02' => "Unintelligible flag ", + 'ERR03' => "Does not make animation from animated GIF source", + ); + + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFEncoder... + :: + */ + public function __construct($GIF_src, $GIF_dly, $GIF_lop, $GIF_dis,$GIF_red, $GIF_grn, $GIF_blu, $GIF_mod) { + if ( ! is_array ( $GIF_src ) && ! is_array ( $GIF_dly ) ) { + printf ( "%s: %s", $this->VER, $this->ERR [ 'ERR00' ] ); + exit ( 0 ); + } + $this->LOP = ( $GIF_lop > -1 ) ? $GIF_lop : 0; + $this->DIS = ( $GIF_dis > -1 ) ? ( ( $GIF_dis < 3 ) ? $GIF_dis : 3 ) : 2; + $this->COL = ( $GIF_red > -1 && $GIF_grn > -1 && $GIF_blu > -1 ) ? + ( $GIF_red | ( $GIF_grn << 8 ) | ( $GIF_blu << 16 ) ) : -1; + + for ( $i = 0; $i < count ( $GIF_src ); $i++ ) { + if ( strToLower ( $GIF_mod ) == "url" ) { + $this->BUF [ ] = fread ( fopen ( $GIF_src [ $i ], "rb" ), filesize ( $GIF_src [ $i ] ) ); + } + else if ( strToLower ( $GIF_mod ) == "bin" ) { + $this->BUF [ ] = $GIF_src [ $i ]; + } + else { + printf ( "%s: %s ( %s )!", $this->VER, $this->ERR [ 'ERR02' ], $GIF_mod ); + exit ( 0 ); + } + if ( substr ( $this->BUF [ $i ], 0, 6 ) != "GIF87a" && substr ( $this->BUF [ $i ], 0, 6 ) != "GIF89a" ) { + printf ( "%s: %d %s", $this->VER, $i, $this->ERR [ 'ERR01' ] ); + exit ( 0 ); + } + for ( $j = ( 13 + 3 * ( 2 << ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ) ) ), $k = TRUE; $k; $j++ ) { + switch ( $this->BUF [ $i ] { $j } ) { + case "!": + if ( ( substr ( $this->BUF [ $i ], ( $j + 3 ), 8 ) ) == "NETSCAPE" ) { + printf ( "%s: %s ( %s source )!", $this->VER, $this->ERR [ 'ERR03' ], ( $i + 1 ) ); + exit ( 0 ); + } + break; + case ";": + $k = FALSE; + break; + } + } + } + $this->GIFAddHeader ( ); + for ( $i = 0; $i < count ( $this->BUF ); $i++ ) { + $this->GIFAddFrames ( $i, $GIF_dly [ $i ] ); + } + $this->GIFAddFooter ( ); + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFAddHeader... + :: + */ + private function GIFAddHeader ( ) { + $cmap = 0; + + if ( ord ( $this->BUF [ 0 ] { 10 } ) & 0x80 ) { + $cmap = 3 * ( 2 << ( ord ( $this->BUF [ 0 ] { 10 } ) & 0x07 ) ); + + $this->GIF .= substr ( $this->BUF [ 0 ], 6, 7 ); + $this->GIF .= substr ( $this->BUF [ 0 ], 13, $cmap ); + $this->GIF .= "!\377\13NETSCAPE2.0\3\1" . $this->GIFWord ( $this->LOP ) . "\0"; + } + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFAddFrames... + :: + */ + private function GIFAddFrames ( $i, $d ) { + + $Locals_str = 13 + 3 * ( 2 << ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ) ); + + $Locals_end = strlen ( $this->BUF [ $i ] ) - $Locals_str - 1; + $Locals_tmp = substr ( $this->BUF [ $i ], $Locals_str, $Locals_end ); + + $Global_len = 2 << ( ord ( $this->BUF [ 0 ] { 10 } ) & 0x07 ); + $Locals_len = 2 << ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ); + + $Global_rgb = substr ( $this->BUF [ 0 ], 13, + 3 * ( 2 << ( ord ( $this->BUF [ 0 ] { 10 } ) & 0x07 ) ) ); + $Locals_rgb = substr ( $this->BUF [ $i ], 13, + 3 * ( 2 << ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ) ) ); + + $Locals_ext = "!\xF9\x04" . chr ( ( $this->DIS << 2 ) + 0 ) . + chr ( ( $d >> 0 ) & 0xFF ) . chr ( ( $d >> 8 ) & 0xFF ) . "\x0\x0"; + + if ( $this->COL > -1 && ord ( $this->BUF [ $i ] { 10 } ) & 0x80 ) { + for ( $j = 0; $j < ( 2 << ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ) ); $j++ ) { + if ( + ord ( $Locals_rgb { 3 * $j + 0 } ) == ( ( $this->COL >> 16 ) & 0xFF ) && + ord ( $Locals_rgb { 3 * $j + 1 } ) == ( ( $this->COL >> 8 ) & 0xFF ) && + ord ( $Locals_rgb { 3 * $j + 2 } ) == ( ( $this->COL >> 0 ) & 0xFF ) + ) { + $Locals_ext = "!\xF9\x04" . chr ( ( $this->DIS << 2 ) + 1 ) . + chr ( ( $d >> 0 ) & 0xFF ) . chr ( ( $d >> 8 ) & 0xFF ) . chr ( $j ) . "\x0"; + break; + } + } + } + switch ( $Locals_tmp { 0 } ) { + case "!": + $Locals_img = substr ( $Locals_tmp, 8, 10 ); + $Locals_tmp = substr ( $Locals_tmp, 18, strlen ( $Locals_tmp ) - 18 ); + break; + case ",": + $Locals_img = substr ( $Locals_tmp, 0, 10 ); + $Locals_tmp = substr ( $Locals_tmp, 10, strlen ( $Locals_tmp ) - 10 ); + break; + } + if ( ord ( $this->BUF [ $i ] { 10 } ) & 0x80 && $this->IMG > -1 ) { + if ( $Global_len == $Locals_len ) { + if ( $this->GIFBlockCompare ( $Global_rgb, $Locals_rgb, $Global_len ) ) { + $this->GIF .= ( $Locals_ext . $Locals_img . $Locals_tmp ); + } + else { + $byte = ord ( $Locals_img { 9 } ); + $byte |= 0x80; + $byte &= 0xF8; + $byte |= ( ord ( $this->BUF [ 0 ] { 10 } ) & 0x07 ); + $Locals_img { 9 } = chr ( $byte ); + $this->GIF .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp ); + } + } + else { + $byte = ord ( $Locals_img { 9 } ); + $byte |= 0x80; + $byte &= 0xF8; + $byte |= ( ord ( $this->BUF [ $i ] { 10 } ) & 0x07 ); + $Locals_img { 9 } = chr ( $byte ); + $this->GIF .= ( $Locals_ext . $Locals_img . $Locals_rgb . $Locals_tmp ); + } + } + else { + $this->GIF .= ( $Locals_ext . $Locals_img . $Locals_tmp ); + } + $this->IMG = 1; + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFAddFooter... + :: + */ + private function GIFAddFooter ( ) { + $this->GIF .= ";"; + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFBlockCompare... + :: + */ + private function GIFBlockCompare ( $GlobalBlock, $LocalBlock, $Len ) { + + for ( $i = 0; $i < $Len; $i++ ) { + if ( + $GlobalBlock { 3 * $i + 0 } != $LocalBlock { 3 * $i + 0 } || + $GlobalBlock { 3 * $i + 1 } != $LocalBlock { 3 * $i + 1 } || + $GlobalBlock { 3 * $i + 2 } != $LocalBlock { 3 * $i + 2 } + ) { + return ( 0 ); + } + } + + return ( 1 ); + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFWord... + :: + */ + private function GIFWord ( $int ) { + + return ( chr ( $int & 0xFF ) . chr ( ( $int >> 8 ) & 0xFF ) ); + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GetAnimation... + :: + */ + public function GetAnimation ( ) { + return ( $this->GIF ); + } +} + + +/* +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:: +:: GIFDecoder Version 2.0 by László Zsidi, http://gifs.hu +:: +:: Created at 2007. 02. 01. '07.47.AM' +:: +:: +:: +:: +:: Try on-line GIFBuilder Form demo based on GIFDecoder. +:: +:: http://gifs.hu/phpclasses/demos/GifBuilder/ +:: +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +*/ + +Class GIFDecoder { + private $GIF_buffer = Array ( ); + private $GIF_arrays = Array ( ); + private $GIF_delays = Array ( ); + private $GIF_stream = ""; + private $GIF_string = ""; + private $GIF_bfseek = 0; + + private $GIF_screen = Array ( ); + private $GIF_global = Array ( ); + private $GIF_sorted; + private $GIF_colorS; + private $GIF_colorC; + private $GIF_colorF; + + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFDecoder ( $GIF_pointer ) + :: + */ + public function __construct ( $GIF_pointer ) { + $this->GIF_stream = $GIF_pointer; + + $this->GIFGetByte ( 6 ); // GIF89a + $this->GIFGetByte ( 7 ); // Logical Screen Descriptor + + $this->GIF_screen = $this->GIF_buffer; + $this->GIF_colorF = $this->GIF_buffer [ 4 ] & 0x80 ? 1 : 0; + $this->GIF_sorted = $this->GIF_buffer [ 4 ] & 0x08 ? 1 : 0; + $this->GIF_colorC = $this->GIF_buffer [ 4 ] & 0x07; + $this->GIF_colorS = 2 << $this->GIF_colorC; + + if ( $this->GIF_colorF == 1 ) { + $this->GIFGetByte ( 3 * $this->GIF_colorS ); + $this->GIF_global = $this->GIF_buffer; + } + /* + * + * 05.06.2007. + * Made a little modification + * + * + - for ( $cycle = 1; $cycle; ) { + + if ( GIFDecoder::GIFGetByte ( 1 ) ) { + - switch ( $this->GIF_buffer [ 0 ] ) { + - case 0x21: + - GIFDecoder::GIFReadExtensions ( ); + - break; + - case 0x2C: + - GIFDecoder::GIFReadDescriptor ( ); + - break; + - case 0x3B: + - $cycle = 0; + - break; + - } + - } + + else { + + $cycle = 0; + + } + - } + */ + for ( $cycle = 1; $cycle; ) { + if ( $this->GIFGetByte ( 1 ) ) { + switch ( $this->GIF_buffer [ 0 ] ) { + case 0x21: + $this->GIFReadExtensions ( ); + break; + case 0x2C: + $this->GIFReadDescriptor ( ); + break; + case 0x3B: + $cycle = 0; + break; + } + } + else { + $cycle = 0; + } + } + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFReadExtension ( ) + :: + */ + private function GIFReadExtensions ( ) { + $this->GIFGetByte ( 1 ); + for ( ; ; ) { + $this->GIFGetByte ( 1 ); + if ( ( $u = $this->GIF_buffer [ 0 ] ) == 0x00 ) { + break; + } + $this->GIFGetByte ( $u ); + /* + * 07.05.2007. + * Implemented a new line for a new function + * to determine the originaly delays between + * frames. + * + */ + if ( $u == 4 ) { + $this->GIF_delays [ ] = ( $this->GIF_buffer [ 1 ] | $this->GIF_buffer [ 2 ] << 8 ); + } + } + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFReadExtension ( ) + :: + */ + private function GIFReadDescriptor ( ) { + $GIF_screen = Array ( ); + + $this->GIFGetByte ( 9 ); + $GIF_screen = $this->GIF_buffer; + $GIF_colorF = $this->GIF_buffer [ 8 ] & 0x80 ? 1 : 0; + if ( $GIF_colorF ) { + $GIF_code = $this->GIF_buffer [ 8 ] & 0x07; + $GIF_sort = $this->GIF_buffer [ 8 ] & 0x20 ? 1 : 0; + } + else { + $GIF_code = $this->GIF_colorC; + $GIF_sort = $this->GIF_sorted; + } + $GIF_size = 2 << $GIF_code; + $this->GIF_screen [ 4 ] &= 0x70; + $this->GIF_screen [ 4 ] |= 0x80; + $this->GIF_screen [ 4 ] |= $GIF_code; + if ( $GIF_sort ) { + $this->GIF_screen [ 4 ] |= 0x08; + } + $this->GIF_string = "GIF87a"; + $this->GIFPutByte ( $this->GIF_screen ); + if ( $GIF_colorF == 1 ) { + $this->GIFGetByte ( 3 * $GIF_size ); + $this->GIFPutByte ( $this->GIF_buffer ); + } + else { + $this->GIFPutByte ( $this->GIF_global ); + } + $this->GIF_string .= chr ( 0x2C ); + $GIF_screen [ 8 ] &= 0x40; + $this->GIFPutByte ( $GIF_screen ); + $this->GIFGetByte ( 1 ); + $this->GIFPutByte ( $this->GIF_buffer ); + for ( ; ; ) { + $this->GIFGetByte ( 1 ); + $this->GIFPutByte ( $this->GIF_buffer ); + if ( ( $u = $this->GIF_buffer [ 0 ] ) == 0x00 ) { + break; + } + $this->GIFGetByte ( $u ); + $this->GIFPutByte ( $this->GIF_buffer ); + } + $this->GIF_string .= chr ( 0x3B ); + /* + Add frames into $GIF_stream array... + */ + $this->GIF_arrays [ ] = $this->GIF_string; + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFGetByte ( $len ) + :: + */ + + /* + * + * 05.06.2007. + * Made a little modification + * + * + - function GIFGetByte ( $len ) { + - $this->GIF_buffer = Array ( ); + - + - for ( $i = 0; $i < $len; $i++ ) { + + if ( $this->GIF_bfseek > strlen ( $this->GIF_stream ) ) { + + return 0; + + } + - $this->GIF_buffer [ ] = ord ( $this->GIF_stream { $this->GIF_bfseek++ } ); + - } + + return 1; + - } + */ + private function GIFGetByte ( $len ) { + $this->GIF_buffer = Array ( ); + + for ( $i = 0; $i < $len; $i++ ) { + if ( $this->GIF_bfseek > strlen ( $this->GIF_stream ) ) { + return 0; + } + $this->GIF_buffer [ ] = ord ( $this->GIF_stream { $this->GIF_bfseek++ } ); + } + return 1; + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFPutByte ( $bytes ) + :: + */ + private function GIFPutByte ( $bytes ) { + for ( $i = 0; $i < count ( $bytes ); $i++ ) { + $this->GIF_string .= chr ( $bytes [ $i ] ); + } + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: PUBLIC FUNCTIONS + :: + :: + :: GIFGetFrames ( ) + :: + */ + public function GIFGetFrames ( ) { + return ( $this->GIF_arrays ); + } + /* + ::::::::::::::::::::::::::::::::::::::::::::::::::: + :: + :: GIFGetDelays ( ) + :: + */ + public function GIFGetDelays ( ) { + return ( $this->GIF_delays ); + } +} diff --git a/ThinkPHP/Library/Think/Image/Driver/Gd.class.php b/ThinkPHP/Library/Think/Image/Driver/Gd.class.php new file mode 100644 index 0000000..0df7554 --- /dev/null +++ b/ThinkPHP/Library/Think/Image/Driver/Gd.class.php @@ -0,0 +1,542 @@ + +// +---------------------------------------------------------------------- +// | ImageGd.class.php 2013-03-05 +// +---------------------------------------------------------------------- +namespace Think\Image\Driver; +use Think\Image; +class Gd{ + /** + * 图像资源对象 + * @var resource + */ + private $img; + + /** + * 图像信息,包括width,height,type,mime,size + * @var array + */ + private $info; + + /** + * 构造方法,可用于打开一张图像 + * @param string $imgname 图像路径 + */ + public function __construct($imgname = null) { + $imgname && $this->open($imgname); + } + + /** + * 打开一张图像 + * @param string $imgname 图像路径 + */ + public function open($imgname){ + //检测图像文件 + if(!is_file($imgname)) E('不存在的图像文件'); + + //获取图像信息 + $info = getimagesize($imgname); + + //检测图像合法性 + if(false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))){ + E('非法图像文件'); + } + + //设置图像信息 + $this->info = array( + 'width' => $info[0], + 'height' => $info[1], + 'type' => image_type_to_extension($info[2], false), + 'mime' => $info['mime'], + ); + + //销毁已存在的图像 + empty($this->img) || imagedestroy($this->img); + + //打开图像 + if('gif' == $this->info['type']){ + $class = 'Think\\Image\\Driver\\GIF'; + $this->gif = new $class($imgname); + $this->img = imagecreatefromstring($this->gif->image()); + } else { + $fun = "imagecreatefrom{$this->info['type']}"; + $this->img = $fun($imgname); + } + } + + /** + * 保存图像 + * @param string $imgname 图像保存名称 + * @param string $type 图像类型 + * @param integer $quality 图像质量 + * @param boolean $interlace 是否对JPEG类型图像设置隔行扫描 + */ + public function save($imgname, $type = null, $quality=80,$interlace = true){ + if(empty($this->img)) E('没有可以被保存的图像资源'); + + //自动获取图像类型 + if(is_null($type)){ + $type = $this->info['type']; + } else { + $type = strtolower($type); + } + //保存图像 + if('jpeg' == $type || 'jpg' == $type){ + //JPEG图像设置隔行扫描 + imageinterlace($this->img, $interlace); + imagejpeg($this->img, $imgname,$quality); + }elseif('gif' == $type && !empty($this->gif)){ + $this->gif->save($imgname); + }else{ + $fun = 'image'.$type; + $fun($this->img, $imgname); + } + } + + /** + * 返回图像宽度 + * @return integer 图像宽度 + */ + public function width(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['width']; + } + + /** + * 返回图像高度 + * @return integer 图像高度 + */ + public function height(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['height']; + } + + /** + * 返回图像类型 + * @return string 图像类型 + */ + public function type(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['type']; + } + + /** + * 返回图像MIME类型 + * @return string 图像MIME类型 + */ + public function mime(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['mime']; + } + + /** + * 返回图像尺寸数组 0 - 图像宽度,1 - 图像高度 + * @return array 图像尺寸 + */ + public function size(){ + if(empty($this->img)) E('没有指定图像资源'); + return array($this->info['width'], $this->info['height']); + } + + /** + * 裁剪图像 + * @param integer $w 裁剪区域宽度 + * @param integer $h 裁剪区域高度 + * @param integer $x 裁剪区域x坐标 + * @param integer $y 裁剪区域y坐标 + * @param integer $width 图像保存宽度 + * @param integer $height 图像保存高度 + */ + public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){ + if(empty($this->img)) E('没有可以被裁剪的图像资源'); + + //设置保存尺寸 + empty($width) && $width = $w; + empty($height) && $height = $h; + + do { + //创建新图像 + $img = imagecreatetruecolor($width, $height); + // 调整默认颜色 + $color = imagecolorallocate($img, 255, 255, 255); + imagefill($img, 0, 0, $color); + + //裁剪 + imagecopyresampled($img, $this->img, 0, 0, $x, $y, $width, $height, $w, $h); + imagedestroy($this->img); //销毁原图 + + //设置新图像 + $this->img = $img; + } while(!empty($this->gif) && $this->gifNext()); + + $this->info['width'] = $width; + $this->info['height'] = $height; + } + + /** + * 生成缩略图 + * @param integer $width 缩略图最大宽度 + * @param integer $height 缩略图最大高度 + * @param integer $type 缩略图裁剪类型 + */ + public function thumb($width, $height, $type = Image::IMAGE_THUMB_SCALE){ + if(empty($this->img)) E('没有可以被缩略的图像资源'); + + //原图宽度和高度 + $w = $this->info['width']; + $h = $this->info['height']; + + /* 计算缩略图生成的必要参数 */ + switch ($type) { + /* 等比例缩放 */ + case Image::IMAGE_THUMB_SCALE: + //原图尺寸小于缩略图尺寸则不进行缩略 + if($w < $width && $h < $height) return; + + //计算缩放比例 + $scale = min($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $x = $y = 0; + $width = $w * $scale; + $height = $h * $scale; + break; + + /* 居中裁剪 */ + case Image::IMAGE_THUMB_CENTER: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $w = $width/$scale; + $h = $height/$scale; + $x = ($this->info['width'] - $w)/2; + $y = ($this->info['height'] - $h)/2; + break; + + /* 左上角裁剪 */ + case Image::IMAGE_THUMB_NORTHWEST: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $x = $y = 0; + $w = $width/$scale; + $h = $height/$scale; + break; + + /* 右下角裁剪 */ + case Image::IMAGE_THUMB_SOUTHEAST: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $w = $width/$scale; + $h = $height/$scale; + $x = $this->info['width'] - $w; + $y = $this->info['height'] - $h; + break; + + /* 填充 */ + case Image::IMAGE_THUMB_FILLED: + //计算缩放比例 + if($w < $width && $h < $height){ + $scale = 1; + } else { + $scale = min($width/$w, $height/$h); + } + + //设置缩略图的坐标及宽度和高度 + $neww = $w * $scale; + $newh = $h * $scale; + $posx = ($width - $w * $scale)/2; + $posy = ($height - $h * $scale)/2; + + do{ + //创建新图像 + $img = imagecreatetruecolor($width, $height); + // 调整默认颜色 + $color = imagecolorallocate($img, 255, 255, 255); + imagefill($img, 0, 0, $color); + + //裁剪 + imagecopyresampled($img, $this->img, $posx, $posy, $x, $y, $neww, $newh, $w, $h); + imagedestroy($this->img); //销毁原图 + $this->img = $img; + } while(!empty($this->gif) && $this->gifNext()); + + $this->info['width'] = $width; + $this->info['height'] = $height; + return; + + /* 固定 */ + case Image::IMAGE_THUMB_FIXED: + $x = $y = 0; + break; + + default: + E('不支持的缩略图裁剪类型'); + } + + /* 裁剪图像 */ + $this->crop($w, $h, $x, $y, $width, $height); + } + + /** + * 添加水印 + * @param string $source 水印图片路径 + * @param integer $locate 水印位置 + * @param integer $alpha 水印透明度 + */ + public function water($source, $locate = Image::IMAGE_WATER_SOUTHEAST,$alpha=80){ + //资源检测 + if(empty($this->img)) E('没有可以被添加水印的图像资源'); + if(!is_file($source)) E('水印图像不存在'); + + //获取水印图像信息 + $info = getimagesize($source); + if(false === $info || (IMAGETYPE_GIF === $info[2] && empty($info['bits']))){ + E('非法水印文件'); + } + + //创建水印图像资源 + $fun = 'imagecreatefrom' . image_type_to_extension($info[2], false); + $water = $fun($source); + + //设定水印图像的混色模式 + imagealphablending($water, true); + + /* 设定水印位置 */ + switch ($locate) { + /* 右下角水印 */ + case Image::IMAGE_WATER_SOUTHEAST: + $x = $this->info['width'] - $info[0]; + $y = $this->info['height'] - $info[1]; + break; + + /* 左下角水印 */ + case Image::IMAGE_WATER_SOUTHWEST: + $x = 0; + $y = $this->info['height'] - $info[1]; + break; + + /* 左上角水印 */ + case Image::IMAGE_WATER_NORTHWEST: + $x = $y = 0; + break; + + /* 右上角水印 */ + case Image::IMAGE_WATER_NORTHEAST: + $x = $this->info['width'] - $info[0]; + $y = 0; + break; + + /* 居中水印 */ + case Image::IMAGE_WATER_CENTER: + $x = ($this->info['width'] - $info[0])/2; + $y = ($this->info['height'] - $info[1])/2; + break; + + /* 下居中水印 */ + case Image::IMAGE_WATER_SOUTH: + $x = ($this->info['width'] - $info[0])/2; + $y = $this->info['height'] - $info[1]; + break; + + /* 右居中水印 */ + case Image::IMAGE_WATER_EAST: + $x = $this->info['width'] - $info[0]; + $y = ($this->info['height'] - $info[1])/2; + break; + + /* 上居中水印 */ + case Image::IMAGE_WATER_NORTH: + $x = ($this->info['width'] - $info[0])/2; + $y = 0; + break; + + /* 左居中水印 */ + case Image::IMAGE_WATER_WEST: + $x = 0; + $y = ($this->info['height'] - $info[1])/2; + break; + + default: + /* 自定义水印坐标 */ + if(is_array($locate)){ + list($x, $y) = $locate; + } else { + E('不支持的水印位置类型'); + } + } + + do{ + //添加水印 + $src = imagecreatetruecolor($info[0], $info[1]); + // 调整默认颜色 + $color = imagecolorallocate($src, 255, 255, 255); + imagefill($src, 0, 0, $color); + + imagecopy($src, $this->img, 0, 0, $x, $y, $info[0], $info[1]); + imagecopy($src, $water, 0, 0, 0, 0, $info[0], $info[1]); + imagecopymerge($this->img, $src, $x, $y, 0, 0, $info[0], $info[1], $alpha); + + //销毁零时图片资源 + imagedestroy($src); + } while(!empty($this->gif) && $this->gifNext()); + + //销毁水印资源 + imagedestroy($water); + } + + /** + * 图像添加文字 + * @param string $text 添加的文字 + * @param string $font 字体路径 + * @param integer $size 字号 + * @param string $color 文字颜色 + * @param integer $locate 文字写入位置 + * @param integer $offset 文字相对当前位置的偏移量 + * @param integer $angle 文字倾斜角度 + */ + public function text($text, $font, $size, $color = '#00000000', + $locate = Image::IMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0){ + //资源检测 + if(empty($this->img)) E('没有可以被写入文字的图像资源'); + if(!is_file($font)) E("不存在的字体文件:{$font}"); + + //获取文字信息 + $info = imagettfbbox($size, $angle, $font, $text); + $minx = min($info[0], $info[2], $info[4], $info[6]); + $maxx = max($info[0], $info[2], $info[4], $info[6]); + $miny = min($info[1], $info[3], $info[5], $info[7]); + $maxy = max($info[1], $info[3], $info[5], $info[7]); + + /* 计算文字初始坐标和尺寸 */ + $x = $minx; + $y = abs($miny); + $w = $maxx - $minx; + $h = $maxy - $miny; + + /* 设定文字位置 */ + switch ($locate) { + /* 右下角文字 */ + case Image::IMAGE_WATER_SOUTHEAST: + $x += $this->info['width'] - $w; + $y += $this->info['height'] - $h; + break; + + /* 左下角文字 */ + case Image::IMAGE_WATER_SOUTHWEST: + $y += $this->info['height'] - $h; + break; + + /* 左上角文字 */ + case Image::IMAGE_WATER_NORTHWEST: + // 起始坐标即为左上角坐标,无需调整 + break; + + /* 右上角文字 */ + case Image::IMAGE_WATER_NORTHEAST: + $x += $this->info['width'] - $w; + break; + + /* 居中文字 */ + case Image::IMAGE_WATER_CENTER: + $x += ($this->info['width'] - $w)/2; + $y += ($this->info['height'] - $h)/2; + break; + + /* 下居中文字 */ + case Image::IMAGE_WATER_SOUTH: + $x += ($this->info['width'] - $w)/2; + $y += $this->info['height'] - $h; + break; + + /* 右居中文字 */ + case Image::IMAGE_WATER_EAST: + $x += $this->info['width'] - $w; + $y += ($this->info['height'] - $h)/2; + break; + + /* 上居中文字 */ + case Image::IMAGE_WATER_NORTH: + $x += ($this->info['width'] - $w)/2; + break; + + /* 左居中文字 */ + case Image::IMAGE_WATER_WEST: + $y += ($this->info['height'] - $h)/2; + break; + + default: + /* 自定义文字坐标 */ + if(is_array($locate)){ + list($posx, $posy) = $locate; + $x += $posx; + $y += $posy; + } else { + E('不支持的文字位置类型'); + } + } + + /* 设置偏移量 */ + if(is_array($offset)){ + $offset = array_map('intval', $offset); + list($ox, $oy) = $offset; + } else{ + $offset = intval($offset); + $ox = $oy = $offset; + } + + /* 设置颜色 */ + if(is_string($color) && 0 === strpos($color, '#')){ + $color = str_split(substr($color, 1), 2); + $color = array_map('hexdec', $color); + if(empty($color[3]) || $color[3] > 127){ + $color[3] = 0; + } + } elseif (!is_array($color)) { + E('错误的颜色值'); + } + + do{ + /* 写入文字 */ + $col = imagecolorallocatealpha($this->img, $color[0], $color[1], $color[2], $color[3]); + imagettftext($this->img, $size, $angle, $x + $ox, $y + $oy, $col, $font, $text); + } while(!empty($this->gif) && $this->gifNext()); + } + + /* 切换到GIF的下一帧并保存当前帧,内部使用 */ + private function gifNext(){ + ob_start(); + ob_implicit_flush(0); + imagegif($this->img); + $img = ob_get_clean(); + + $this->gif->image($img); + $next = $this->gif->nextImage(); + + if($next){ + $this->img = imagecreatefromstring($next); + return $next; + } else { + $this->img = imagecreatefromstring($this->gif->image()); + return false; + } + } + + /** + * 析构方法,用于销毁图像资源 + */ + public function __destruct() { + empty($this->img) || imagedestroy($this->img); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Image/Driver/Imagick.class.php b/ThinkPHP/Library/Think/Image/Driver/Imagick.class.php new file mode 100644 index 0000000..df952a6 --- /dev/null +++ b/ThinkPHP/Library/Think/Image/Driver/Imagick.class.php @@ -0,0 +1,593 @@ + +// +---------------------------------------------------------------------- +// | ImageImagick.class.php 2013-03-06 +// +---------------------------------------------------------------------- +namespace Think\Image\Driver; +use Think\Image; +class Imagick{ + /** + * 图像资源对象 + * @var resource + */ + private $img; + + /** + * 图像信息,包括width,height,type,mime,size + * @var array + */ + private $info; + + /** + * 构造方法,可用于打开一张图像 + * @param string $imgname 图像路径 + */ + public function __construct($imgname = null) { + $imgname && $this->open($imgname); + } + + /** + * 打开一张图像 + * @param string $imgname 图像路径 + */ + public function open($imgname){ + //检测图像文件 + if(!is_file($imgname)) E('不存在的图像文件'); + + //销毁已存在的图像 + empty($this->img) || $this->img->destroy(); + + //载入图像 + $this->img = new \Imagick(realpath($imgname)); + + //设置图像信息 + $this->info = array( + 'width' => $this->img->getImageWidth(), + 'height' => $this->img->getImageHeight(), + 'type' => strtolower($this->img->getImageFormat()), + 'mime' => $this->img->getImageMimeType(), + ); + } + + /** + * 保存图像 + * @param string $imgname 图像保存名称 + * @param string $type 图像类型 + * @param integer $quality JPEG图像质量 + * @param boolean $interlace 是否对JPEG类型图像设置隔行扫描 + */ + public function save($imgname, $type = null, $quality=80,$interlace = true){ + if(empty($this->img)) E('没有可以被保存的图像资源'); + + //设置图片类型 + if(is_null($type)){ + $type = $this->info['type']; + } else { + $type = strtolower($type); + $this->img->setImageFormat($type); + } + + //JPEG图像设置隔行扫描 + if('jpeg' == $type || 'jpg' == $type){ + $this->img->setImageInterlaceScheme(1); + } + + // 设置图像质量 + $this->img->setImageCompressionQuality($quality); + + //去除图像配置信息 + $this->img->stripImage(); + + //保存图像 + $imgname = realpath(dirname($imgname)) . '/' . basename($imgname); //强制绝对路径 + if ('gif' == $type) { + $this->img->writeImages($imgname, true); + } else { + $this->img->writeImage($imgname); + } + } + + /** + * 返回图像宽度 + * @return integer 图像宽度 + */ + public function width(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['width']; + } + + /** + * 返回图像高度 + * @return integer 图像高度 + */ + public function height(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['height']; + } + + /** + * 返回图像类型 + * @return string 图像类型 + */ + public function type(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['type']; + } + + /** + * 返回图像MIME类型 + * @return string 图像MIME类型 + */ + public function mime(){ + if(empty($this->img)) E('没有指定图像资源'); + return $this->info['mime']; + } + + /** + * 返回图像尺寸数组 0 - 图像宽度,1 - 图像高度 + * @return array 图像尺寸 + */ + public function size(){ + if(empty($this->img)) E('没有指定图像资源'); + return array($this->info['width'], $this->info['height']); + } + + /** + * 裁剪图像 + * @param integer $w 裁剪区域宽度 + * @param integer $h 裁剪区域高度 + * @param integer $x 裁剪区域x坐标 + * @param integer $y 裁剪区域y坐标 + * @param integer $width 图像保存宽度 + * @param integer $height 图像保存高度 + */ + public function crop($w, $h, $x = 0, $y = 0, $width = null, $height = null){ + if(empty($this->img)) E('没有可以被裁剪的图像资源'); + + //设置保存尺寸 + empty($width) && $width = $w; + empty($height) && $height = $h; + + //裁剪图片 + if('gif' == $this->info['type']){ + $img = $this->img->coalesceImages(); + $this->img->destroy(); //销毁原图 + + //循环裁剪每一帧 + do { + $this->_crop($w, $h, $x, $y, $width, $height, $img); + } while ($img->nextImage()); + + //压缩图片 + $this->img = $img->deconstructImages(); + $img->destroy(); //销毁零时图片 + } else { + $this->_crop($w, $h, $x, $y, $width, $height); + } + } + + /* 裁剪图片,内部调用 */ + private function _crop($w, $h, $x, $y, $width, $height, $img = null){ + is_null($img) && $img = $this->img; + + //裁剪 + $info = $this->info; + if($x != 0 || $y != 0 || $w != $info['width'] || $h != $info['height']){ + $img->cropImage($w, $h, $x, $y); + $img->setImagePage($w, $h, 0, 0); //调整画布和图片一致 + } + + //调整大小 + if($w != $width || $h != $height){ + $img->sampleImage($width, $height); + } + + //设置缓存尺寸 + $this->info['width'] = $width; + $this->info['height'] = $height; + } + + /** + * 生成缩略图 + * @param integer $width 缩略图最大宽度 + * @param integer $height 缩略图最大高度 + * @param integer $type 缩略图裁剪类型 + */ + public function thumb($width, $height, $type = Image::IMAGE_THUMB_SCALE){ + if(empty($this->img)) E('没有可以被缩略的图像资源'); + + //原图宽度和高度 + $w = $this->info['width']; + $h = $this->info['height']; + + /* 计算缩略图生成的必要参数 */ + switch ($type) { + /* 等比例缩放 */ + case Image::IMAGE_THUMB_SCALE: + //原图尺寸小于缩略图尺寸则不进行缩略 + if($w < $width && $h < $height) return; + + //计算缩放比例 + $scale = min($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $x = $y = 0; + $width = $w * $scale; + $height = $h * $scale; + break; + + /* 居中裁剪 */ + case Image::IMAGE_THUMB_CENTER: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $w = $width/$scale; + $h = $height/$scale; + $x = ($this->info['width'] - $w)/2; + $y = ($this->info['height'] - $h)/2; + break; + + /* 左上角裁剪 */ + case Image::IMAGE_THUMB_NORTHWEST: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $x = $y = 0; + $w = $width/$scale; + $h = $height/$scale; + break; + + /* 右下角裁剪 */ + case Image::IMAGE_THUMB_SOUTHEAST: + //计算缩放比例 + $scale = max($width/$w, $height/$h); + + //设置缩略图的坐标及宽度和高度 + $w = $width/$scale; + $h = $height/$scale; + $x = $this->info['width'] - $w; + $y = $this->info['height'] - $h; + break; + + /* 填充 */ + case Image::IMAGE_THUMB_FILLED: + //计算缩放比例 + if($w < $width && $h < $height){ + $scale = 1; + } else { + $scale = min($width/$w, $height/$h); + } + + //设置缩略图的坐标及宽度和高度 + $neww = $w * $scale; + $newh = $h * $scale; + $posx = ($width - $w * $scale)/2; + $posy = ($height - $h * $scale)/2; + + //创建一张新图像 + $newimg = new \Imagick(); + $newimg->newImage($width, $height, 'white', $this->info['type']); + + + if('gif' == $this->info['type']){ + $imgs = $this->img->coalesceImages(); + $img = new \Imagick(); + $this->img->destroy(); //销毁原图 + + //循环填充每一帧 + do { + //填充图像 + $image = $this->_fill($newimg, $posx, $posy, $neww, $newh, $imgs); + + $img->addImage($image); + $img->setImageDelay($imgs->getImageDelay()); + $img->setImagePage($width, $height, 0, 0); + + $image->destroy(); //销毁零时图片 + + } while ($imgs->nextImage()); + + //压缩图片 + $this->img->destroy(); + $this->img = $img->deconstructImages(); + $imgs->destroy(); //销毁零时图片 + $img->destroy(); //销毁零时图片 + + } else { + //填充图像 + $img = $this->_fill($newimg, $posx, $posy, $neww, $newh); + //销毁原图 + $this->img->destroy(); + $this->img = $img; + } + + //设置新图像属性 + $this->info['width'] = $width; + $this->info['height'] = $height; + return; + + /* 固定 */ + case Image::IMAGE_THUMB_FIXED: + $x = $y = 0; + break; + + default: + E('不支持的缩略图裁剪类型'); + } + + /* 裁剪图像 */ + $this->crop($w, $h, $x, $y, $width, $height); + } + + /* 填充指定图像,内部使用 */ + private function _fill($newimg, $posx, $posy, $neww, $newh, $img = null){ + is_null($img) && $img = $this->img; + + /* 将指定图片绘入空白图片 */ + $draw = new \ImagickDraw(); + $draw->composite($img->getImageCompose(), $posx, $posy, $neww, $newh, $img); + $image = $newimg->clone(); + $image->drawImage($draw); + $draw->destroy(); + + return $image; + } + + /** + * 添加水印 + * @param string $source 水印图片路径 + * @param integer $locate 水印位置 + * @param integer $alpha 水印透明度 + */ + public function water($source, $locate = Image::IMAGE_WATER_SOUTHEAST,$alpha=80){ + //资源检测 + if(empty($this->img)) E('没有可以被添加水印的图像资源'); + if(!is_file($source)) E('水印图像不存在'); + + //创建水印图像资源 + $water = new \Imagick(realpath($source)); + $info = array($water->getImageWidth(), $water->getImageHeight()); + + /* 设定水印位置 */ + switch ($locate) { + /* 右下角水印 */ + case Image::IMAGE_WATER_SOUTHEAST: + $x = $this->info['width'] - $info[0]; + $y = $this->info['height'] - $info[1]; + break; + + /* 左下角水印 */ + case Image::IMAGE_WATER_SOUTHWEST: + $x = 0; + $y = $this->info['height'] - $info[1]; + break; + + /* 左上角水印 */ + case Image::IMAGE_WATER_NORTHWEST: + $x = $y = 0; + break; + + /* 右上角水印 */ + case Image::IMAGE_WATER_NORTHEAST: + $x = $this->info['width'] - $info[0]; + $y = 0; + break; + + /* 居中水印 */ + case Image::IMAGE_WATER_CENTER: + $x = ($this->info['width'] - $info[0])/2; + $y = ($this->info['height'] - $info[1])/2; + break; + + /* 下居中水印 */ + case Image::IMAGE_WATER_SOUTH: + $x = ($this->info['width'] - $info[0])/2; + $y = $this->info['height'] - $info[1]; + break; + + /* 右居中水印 */ + case Image::IMAGE_WATER_EAST: + $x = $this->info['width'] - $info[0]; + $y = ($this->info['height'] - $info[1])/2; + break; + + /* 上居中水印 */ + case Image::IMAGE_WATER_NORTH: + $x = ($this->info['width'] - $info[0])/2; + $y = 0; + break; + + /* 左居中水印 */ + case Image::IMAGE_WATER_WEST: + $x = 0; + $y = ($this->info['height'] - $info[1])/2; + break; + + default: + /* 自定义水印坐标 */ + if(is_array($locate)){ + list($x, $y) = $locate; + } else { + E('不支持的水印位置类型'); + } + } + + //创建绘图资源 + $draw = new \ImagickDraw(); + $draw->composite($water->getImageCompose(), $x, $y, $info[0], $info[1], $water); + + if('gif' == $this->info['type']){ + $img = $this->img->coalesceImages(); + $this->img->destroy(); //销毁原图 + + do{ + //添加水印 + $img->drawImage($draw); + } while ($img->nextImage()); + + //压缩图片 + $this->img = $img->deconstructImages(); + $img->destroy(); //销毁零时图片 + + } else { + //添加水印 + $this->img->drawImage($draw); + } + + //销毁水印资源 + $draw->destroy(); + $water->destroy(); + } + + /** + * 图像添加文字 + * @param string $text 添加的文字 + * @param string $font 字体路径 + * @param integer $size 字号 + * @param string $color 文字颜色 + * @param integer $locate 文字写入位置 + * @param integer $offset 文字相对当前位置的偏移量 + * @param integer $angle 文字倾斜角度 + */ + public function text($text, $font, $size, $color = '#00000000', + $locate = Image::IMAGE_WATER_SOUTHEAST, $offset = 0, $angle = 0){ + //资源检测 + if(empty($this->img)) E('没有可以被写入文字的图像资源'); + if(!is_file($font)) E("不存在的字体文件:{$font}"); + + //获取颜色和透明度 + if(is_array($color)){ + $color = array_map('dechex', $color); + foreach ($color as &$value) { + $value = str_pad($value, 2, '0', STR_PAD_LEFT); + } + $color = '#' . implode('', $color); + } elseif(!is_string($color) || 0 !== strpos($color, '#')) { + E('错误的颜色值'); + } + $col = substr($color, 0, 7); + $alp = strlen($color) == 9 ? substr($color, -2) : 0; + + + //获取文字信息 + $draw = new \ImagickDraw(); + $draw->setFont(realpath($font)); + $draw->setFontSize($size); + $draw->setFillColor($col); + $draw->setFillAlpha(1-hexdec($alp)/127); + $draw->setTextAntialias(true); + $draw->setStrokeAntialias(true); + + $metrics = $this->img->queryFontMetrics($draw, $text); + + /* 计算文字初始坐标和尺寸 */ + $x = 0; + $y = $metrics['ascender']; + $w = $metrics['textWidth']; + $h = $metrics['textHeight']; + + /* 设定文字位置 */ + switch ($locate) { + /* 右下角文字 */ + case Image::IMAGE_WATER_SOUTHEAST: + $x += $this->info['width'] - $w; + $y += $this->info['height'] - $h; + break; + + /* 左下角文字 */ + case Image::IMAGE_WATER_SOUTHWEST: + $y += $this->info['height'] - $h; + break; + + /* 左上角文字 */ + case Image::IMAGE_WATER_NORTHWEST: + // 起始坐标即为左上角坐标,无需调整 + break; + + /* 右上角文字 */ + case Image::IMAGE_WATER_NORTHEAST: + $x += $this->info['width'] - $w; + break; + + /* 居中文字 */ + case Image::IMAGE_WATER_CENTER: + $x += ($this->info['width'] - $w)/2; + $y += ($this->info['height'] - $h)/2; + break; + + /* 下居中文字 */ + case Image::IMAGE_WATER_SOUTH: + $x += ($this->info['width'] - $w)/2; + $y += $this->info['height'] - $h; + break; + + /* 右居中文字 */ + case Image::IMAGE_WATER_EAST: + $x += $this->info['width'] - $w; + $y += ($this->info['height'] - $h)/2; + break; + + /* 上居中文字 */ + case Image::IMAGE_WATER_NORTH: + $x += ($this->info['width'] - $w)/2; + break; + + /* 左居中文字 */ + case Image::IMAGE_WATER_WEST: + $y += ($this->info['height'] - $h)/2; + break; + + default: + /* 自定义文字坐标 */ + if(is_array($locate)){ + list($posx, $posy) = $locate; + $x += $posx; + $y += $posy; + } else { + E('不支持的文字位置类型'); + } + } + + /* 设置偏移量 */ + if(is_array($offset)){ + $offset = array_map('intval', $offset); + list($ox, $oy) = $offset; + } else{ + $offset = intval($offset); + $ox = $oy = $offset; + } + + /* 写入文字 */ + if('gif' == $this->info['type']){ + $img = $this->img->coalesceImages(); + $this->img->destroy(); //销毁原图 + do{ + $img->annotateImage($draw, $x + $ox, $y + $oy, $angle, $text); + } while ($img->nextImage()); + + //压缩图片 + $this->img = $img->deconstructImages(); + $img->destroy(); //销毁零时图片 + + } else { + $this->img->annotateImage($draw, $x + $ox, $y + $oy, $angle, $text); + } + $draw->destroy(); + } + + /** + * 析构方法,用于销毁图像资源 + */ + public function __destruct() { + empty($this->img) || $this->img->destroy(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Log.class.php b/ThinkPHP/Library/Think/Log.class.php new file mode 100644 index 0000000..09b1155 --- /dev/null +++ b/ThinkPHP/Library/Think/Log.class.php @@ -0,0 +1,104 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * 日志处理类 + */ +class Log { + + // 日志级别 从上到下,由低到高 + const EMERG = 'EMERG'; // 严重错误: 导致系统崩溃无法使用 + const ALERT = 'ALERT'; // 警戒性错误: 必须被立即修改的错误 + const CRIT = 'CRIT'; // 临界值错误: 超过临界值的错误,例如一天24小时,而输入的是25小时这样 + const ERR = 'ERR'; // 一般错误: 一般性错误 + const WARN = 'WARN'; // 警告性错误: 需要发出警告的错误 + const NOTICE = 'NOTIC'; // 通知: 程序可以运行但是还不够完美的错误 + const INFO = 'INFO'; // 信息: 程序输出信息 + const DEBUG = 'DEBUG'; // 调试: 调试信息 + const SQL = 'SQL'; // SQL:SQL语句 注意只在调试模式开启时有效 + + // 日志信息 + static protected $log = array(); + + // 日志存储 + static protected $storage = null; + + // 日志初始化 + static public function init($config=array()){ + $type = isset($config['type']) ? $config['type'] : 'File'; + $class = strpos($type,'\\')? $type: 'Think\\Log\\Driver\\'. ucwords(strtolower($type)); + unset($config['type']); + self::$storage = new $class($config); + } + + /** + * 记录日志 并且会过滤未经设置的级别 + * @static + * @access public + * @param string $message 日志信息 + * @param string $level 日志级别 + * @param boolean $record 是否强制记录 + * @return void + */ + static function record($message,$level=self::ERR,$record=false) { + if($record || false !== strpos(C('LOG_LEVEL'),$level)) { + self::$log[] = "{$level}: {$message}\r\n"; + } + } + + /** + * 日志保存 + * @static + * @access public + * @param integer $type 日志记录方式 + * @param string $destination 写入目标 + * @return void + */ + static function save($type='',$destination='') { + if(empty(self::$log)) return ; + + if(empty($destination)){ + $destination = C('LOG_PATH').date('y_m_d').'.log'; + } + if(!self::$storage){ + $type = $type ? : C('LOG_TYPE'); + $class = 'Think\\Log\\Driver\\'. ucwords($type); + self::$storage = new $class(); + } + $message = implode('',self::$log); + self::$storage->write($message,$destination); + // 保存后清空日志缓存 + self::$log = array(); + } + + /** + * 日志直接写入 + * @static + * @access public + * @param string $message 日志信息 + * @param string $level 日志级别 + * @param integer $type 日志记录方式 + * @param string $destination 写入目标 + * @return void + */ + static function write($message,$level=self::ERR,$type='',$destination='') { + if(!self::$storage){ + $type = $type ? : C('LOG_TYPE'); + $class = 'Think\\Log\\Driver\\'. ucwords($type); + $config['log_path'] = C('LOG_PATH'); + self::$storage = new $class($config); + } + if(empty($destination)){ + $destination = C('LOG_PATH').date('y_m_d').'.log'; + } + self::$storage->write("{$level}: {$message}", $destination); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Log/Driver/File.class.php b/ThinkPHP/Library/Think/Log/Driver/File.class.php new file mode 100644 index 0000000..290746e --- /dev/null +++ b/ThinkPHP/Library/Think/Log/Driver/File.class.php @@ -0,0 +1,50 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Log\Driver; + +class File { + + protected $config = array( + 'log_time_format' => ' c ', + 'log_file_size' => 2097152, + 'log_path' => '', + ); + + // 实例化并传入参数 + public function __construct($config=array()){ + $this->config = array_merge($this->config,$config); + } + + /** + * 日志写入接口 + * @access public + * @param string $log 日志信息 + * @param string $destination 写入目标 + * @return void + */ + public function write($log,$destination='') { + $now = date($this->config['log_time_format']); + if(empty($destination)){ + $destination = $this->config['log_path'].date('y_m_d').'.log'; + } + // 自动创建日志目录 + $log_dir = dirname($destination); + if (!is_dir($log_dir)) { + mkdir($log_dir, 0755, true); + } + //检测日志文件大小,超过配置大小则备份日志文件重新生成 + if(is_file($destination) && floor($this->config['log_file_size']) <= filesize($destination) ){ + rename($destination,dirname($destination).'/'.time().'-'.basename($destination)); + } + error_log("[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n", 3,$destination); + } +} diff --git a/ThinkPHP/Library/Think/Log/Driver/Sae.class.php b/ThinkPHP/Library/Think/Log/Driver/Sae.class.php new file mode 100644 index 0000000..accbcae --- /dev/null +++ b/ThinkPHP/Library/Think/Log/Driver/Sae.class.php @@ -0,0 +1,49 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Log\Driver; + +class Sae { + + protected $config = array( + 'log_time_format' => ' c ', + ); + + // 实例化并传入参数 + public function __construct($config=array()){ + $this->config = array_merge($this->config,$config); + } + + /** + * 日志写入接口 + * @access public + * @param string $log 日志信息 + * @param string $destination 写入目标 + * @return void + */ + public function write($log,$destination='') { + static $is_debug=null; + $now = date($this->config['log_time_format']); + $logstr="[{$now}] ".$_SERVER['REMOTE_ADDR'].' '.$_SERVER['REQUEST_URI']."\r\n{$log}\r\n"; + if(is_null($is_debug)){ + preg_replace('@(\w+)\=([^;]*)@e', '$appSettings[\'\\1\']="\\2";', $_SERVER['HTTP_APPCOOKIE']); + $is_debug = in_array($_SERVER['HTTP_APPVERSION'], explode(',', $appSettings['debug'])) ? true : false; + } + if($is_debug){ + sae_set_display_errors(false);//记录日志不将日志打印出来 + } + sae_debug($logstr); + if($is_debug){ + sae_set_display_errors(true); + } + + } +} diff --git a/ThinkPHP/Library/Think/Model.class.php b/ThinkPHP/Library/Think/Model.class.php new file mode 100644 index 0000000..e56474b --- /dev/null +++ b/ThinkPHP/Library/Think/Model.class.php @@ -0,0 +1,1910 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP Model模型类 + * 实现了ORM和ActiveRecords模式 + */ +class Model { + // 操作状态 + const MODEL_INSERT = 1; // 插入模型数据 + const MODEL_UPDATE = 2; // 更新模型数据 + const MODEL_BOTH = 3; // 包含上面两种方式 + const MUST_VALIDATE = 1; // 必须验证 + const EXISTS_VALIDATE = 0; // 表单存在字段则验证 + const VALUE_VALIDATE = 2; // 表单值不为空则验证 + + // 当前数据库操作对象 + protected $db = null; + // 数据库对象池 + private $_db = array(); + // 主键名称 + protected $pk = 'id'; + // 主键是否自动增长 + protected $autoinc = false; + // 数据表前缀 + protected $tablePrefix = null; + // 模型名称 + protected $name = ''; + // 数据库名称 + protected $dbName = ''; + //数据库配置 + protected $connection = ''; + // 数据表名(不包含表前缀) + protected $tableName = ''; + // 实际数据表名(包含表前缀) + protected $trueTableName = ''; + // 最近错误信息 + protected $error = ''; + // 字段信息 + protected $fields = array(); + // 数据信息 + protected $data = array(); + // 查询表达式参数 + protected $options = array(); + protected $_validate = array(); // 自动验证定义 + protected $_auto = array(); // 自动完成定义 + protected $_map = array(); // 字段映射定义 + protected $_scope = array(); // 命名范围定义 + // 是否自动检测数据表字段信息 + protected $autoCheckFields = true; + // 是否批处理验证 + protected $patchValidate = false; + // 链操作方法列表 + protected $methods = array('strict','order','alias','having','group','lock','distinct','auto','filter','validate','result','token','index','force'); + + /** + * 架构函数 + * 取得DB类的实例对象 字段检查 + * @access public + * @param string $name 模型名称 + * @param string $tablePrefix 表前缀 + * @param mixed $connection 数据库连接信息 + */ + public function __construct($name='',$tablePrefix='',$connection='') { + // 模型初始化 + $this->_initialize(); + // 获取模型名称 + if(!empty($name)) { + if(strpos($name,'.')) { // 支持 数据库名.模型名的 定义 + list($this->dbName,$this->name) = explode('.',$name); + }else{ + $this->name = $name; + } + }elseif(empty($this->name)){ + $this->name = $this->getModelName(); + } + // 设置表前缀 + if(is_null($tablePrefix)) {// 前缀为Null表示没有前缀 + $this->tablePrefix = ''; + }elseif('' != $tablePrefix) { + $this->tablePrefix = $tablePrefix; + }elseif(!isset($this->tablePrefix)){ + $this->tablePrefix = C('DB_PREFIX'); + } + + // 数据库初始化操作 + // 获取数据库操作对象 + // 当前模型有独立的数据库连接信息 + $this->db(0,empty($this->connection)?$connection:$this->connection,true); + } + + /** + * 自动检测数据表信息 + * @access protected + * @return void + */ + protected function _checkTableInfo() { + // 如果不是Model类 自动记录数据表信息 + // 只在第一次执行记录 + if(empty($this->fields)) { + // 如果数据表字段没有定义则自动获取 + if(C('DB_FIELDS_CACHE')) { + $db = $this->dbName?:C('DB_NAME'); + $fields = F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name)); + if($fields) { + $this->fields = $fields; + if(!empty($fields['_pk'])){ + $this->pk = $fields['_pk']; + } + return ; + } + } + // 每次都会读取数据表信息 + $this->flush(); + } + } + + /** + * 获取字段信息并缓存 + * @access public + * @return void + */ + public function flush() { + // 缓存不存在则查询数据表信息 + $this->db->setModel($this->name); + $fields = $this->db->getFields($this->getTableName()); + if(!$fields) { // 无法获取字段信息 + return false; + } + $this->fields = array_keys($fields); + unset($this->fields['_pk']); + foreach ($fields as $key=>$val){ + // 记录字段类型 + $type[$key] = $val['type']; + if($val['primary']) { + // 增加复合主键支持 + if (isset($this->fields['_pk']) && $this->fields['_pk'] != null) { + if (is_string($this->fields['_pk'])) { + $this->pk = array($this->fields['_pk']); + $this->fields['_pk'] = $this->pk; + } + $this->pk[] = $key; + $this->fields['_pk'][] = $key; + } else { + $this->pk = $key; + $this->fields['_pk'] = $key; + } + if($val['autoinc']) $this->autoinc = true; + } + } + // 记录字段类型信息 + $this->fields['_type'] = $type; + + // 2008-3-7 增加缓存开关控制 + if(C('DB_FIELDS_CACHE')){ + // 永久缓存数据表信息 + $db = $this->dbName?:C('DB_NAME'); + F('_fields/'.strtolower($db.'.'.$this->tablePrefix.$this->name),$this->fields); + } + } + + /** + * 设置数据对象的值 + * @access public + * @param string $name 名称 + * @param mixed $value 值 + * @return void + */ + public function __set($name,$value) { + // 设置数据对象属性 + $this->data[$name] = $value; + } + + /** + * 获取数据对象的值 + * @access public + * @param string $name 名称 + * @return mixed + */ + public function __get($name) { + return isset($this->data[$name])?$this->data[$name]:null; + } + + /** + * 检测数据对象的值 + * @access public + * @param string $name 名称 + * @return boolean + */ + public function __isset($name) { + return isset($this->data[$name]); + } + + /** + * 销毁数据对象的值 + * @access public + * @param string $name 名称 + * @return void + */ + public function __unset($name) { + unset($this->data[$name]); + } + + /** + * 利用__call方法实现一些特殊的Model方法 + * @access public + * @param string $method 方法名称 + * @param array $args 调用参数 + * @return mixed + */ + public function __call($method,$args) { + if(in_array(strtolower($method),$this->methods,true)) { + // 连贯操作的实现 + $this->options[strtolower($method)] = $args[0]; + return $this; + }elseif(in_array(strtolower($method),array('count','sum','min','max','avg'),true)){ + // 统计查询的实现 + $field = isset($args[0])?$args[0]:'*'; + return $this->getField(strtoupper($method).'('.$field.') AS tp_'.$method); + }elseif(strtolower(substr($method,0,5))=='getby') { + // 根据某个字段获取记录 + $field = parse_name(substr($method,5)); + $where[$field] = $args[0]; + return $this->where($where)->find(); + }elseif(strtolower(substr($method,0,10))=='getfieldby') { + // 根据某个字段获取记录的某个值 + $name = parse_name(substr($method,10)); + $where[$name] =$args[0]; + return $this->where($where)->getField($args[1]); + }elseif(isset($this->_scope[$method])){// 命名范围的单独调用支持 + return $this->scope($method,$args[0]); + }else{ + E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); + return; + } + } + // 回调方法 初始化模型 + protected function _initialize() {} + + /** + * 对保存到数据库的数据进行处理 + * @access protected + * @param mixed $data 要操作的数据 + * @return boolean + */ + protected function _facade($data) { + + // 检查数据字段合法性 + if(!empty($this->fields)) { + if(!empty($this->options['field'])) { + $fields = $this->options['field']; + unset($this->options['field']); + if(is_string($fields)) { + $fields = explode(',',$fields); + } + }else{ + $fields = $this->fields; + } + foreach ($data as $key=>$val){ + if(!in_array($key,$fields,true)){ + if(!empty($this->options['strict'])){ + E(L('_DATA_TYPE_INVALID_').':['.$key.'=>'.$val.']'); + } + unset($data[$key]); + }elseif(is_scalar($val)) { + // 字段类型检查 和 强制转换 + $this->_parseType($data,$key); + } + } + } + + // 安全过滤 + if(!empty($this->options['filter'])) { + $data = array_map($this->options['filter'],$data); + unset($this->options['filter']); + } + $this->_before_write($data); + return $data; + } + + // 写入数据前的回调方法 包括新增和更新 + protected function _before_write(&$data) {} + + /** + * 新增数据 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @param boolean $replace 是否replace + * @return mixed + */ + public function add($data='',$options=array(),$replace=false) { + if(empty($data)) { + // 没有传递数据,获取当前数据对象的值 + if(!empty($this->data)) { + $data = $this->data; + // 重置数据 + $this->data = array(); + }else{ + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + } + // 数据处理 + $data = $this->_facade($data); + // 分析表达式 + $options = $this->_parseOptions($options); + if(false === $this->_before_insert($data,$options)) { + return false; + } + // 写入数据到数据库 + $result = $this->db->insert($data,$options,$replace); + if(false !== $result && is_numeric($result)) { + $pk = $this->getPk(); + // 增加复合主键支持 + if (is_array($pk)) return $result; + $insertId = $this->getLastInsID(); + if($insertId) { + // 自增主键返回插入ID + $data[$pk] = $insertId; + if(false === $this->_after_insert($data,$options)) { + return false; + } + return $insertId; + } + if(false === $this->_after_insert($data,$options)) { + return false; + } + } + return $result; + } + // 插入数据前的回调方法 + protected function _before_insert(&$data,$options) {} + // 插入成功后的回调方法 + protected function _after_insert($data,$options) {} + + public function addAll($dataList,$options=array(),$replace=false){ + if(empty($dataList)) { + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + // 数据处理 + foreach ($dataList as $key=>$data){ + $dataList[$key] = $this->_facade($data); + } + // 分析表达式 + $options = $this->_parseOptions($options); + // 写入数据到数据库 + $result = $this->db->insertAll($dataList,$options,$replace); + if(false !== $result ) { + $insertId = $this->getLastInsID(); + if($insertId) { + return $insertId; + } + } + return $result; + } + + /** + * 通过Select方式添加记录 + * @access public + * @param string $fields 要插入的数据表字段名 + * @param string $table 要插入的数据表名 + * @param array $options 表达式 + * @return boolean + */ + public function selectAdd($fields='',$table='',$options=array()) { + // 分析表达式 + $options = $this->_parseOptions($options); + // 写入数据到数据库 + if(false === $result = $this->db->selectInsert($fields?:$options['field'],$table?:$this->getTableName(),$options)){ + // 数据库插入操作失败 + $this->error = L('_OPERATION_WRONG_'); + return false; + }else { + // 插入成功 + return $result; + } + } + + /** + * 保存数据 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @return boolean + */ + public function save($data='',$options=array()) { + if(empty($data)) { + // 没有传递数据,获取当前数据对象的值 + if(!empty($this->data)) { + $data = $this->data; + // 重置数据 + $this->data = array(); + }else{ + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + } + // 数据处理 + $data = $this->_facade($data); + if(empty($data)){ + // 没有数据则不执行 + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + // 分析表达式 + $options = $this->_parseOptions($options); + $pk = $this->getPk(); + if(!isset($options['where']) ) { + // 如果存在主键数据 则自动作为更新条件 + if (is_string($pk) && isset($data[$pk])) { + $where[$pk] = $data[$pk]; + unset($data[$pk]); + } elseif (is_array($pk)) { + // 增加复合主键支持 + foreach ($pk as $field) { + if(isset($data[$field])) { + $where[$field] = $data[$field]; + } else { + // 如果缺少复合主键数据则不执行 + $this->error = L('_OPERATION_WRONG_'); + return false; + } + unset($data[$field]); + } + } + if(!isset($where)){ + // 如果没有任何更新条件则不执行 + $this->error = L('_OPERATION_WRONG_'); + return false; + }else{ + $options['where'] = $where; + } + } + + if(is_array($options['where']) && isset($options['where'][$pk])){ + $pkValue = $options['where'][$pk]; + } + if(false === $this->_before_update($data,$options)) { + return false; + } + $result = $this->db->update($data,$options); + if(false !== $result && is_numeric($result)) { + if(isset($pkValue)) $data[$pk] = $pkValue; + $this->_after_update($data,$options); + } + return $result; + } + // 更新数据前的回调方法 + protected function _before_update(&$data,$options) {} + // 更新成功后的回调方法 + protected function _after_update($data,$options) {} + + /** + * 删除数据 + * @access public + * @param mixed $options 表达式 + * @return mixed + */ + public function delete($options=array()) { + $pk = $this->getPk(); + if(empty($options) && empty($this->options['where'])) { + // 如果删除条件为空 则删除当前数据对象所对应的记录 + if(!empty($this->data) && isset($this->data[$pk])) + return $this->delete($this->data[$pk]); + else + return false; + } + if(is_numeric($options) || is_string($options)) { + // 根据主键删除记录 + if(strpos($options,',')) { + $where[$pk] = array('IN', $options); + }else{ + $where[$pk] = $options; + } + $options = array(); + $options['where'] = $where; + } + // 根据复合主键删除记录 + if (is_array($options) && (count($options) > 0) && is_array($pk)) { + $count = 0; + foreach (array_keys($options) as $key) { + if (is_int($key)) $count++; + } + if ($count == count($pk)) { + $i = 0; + foreach ($pk as $field) { + $where[$field] = $options[$i]; + unset($options[$i++]); + } + $options['where'] = $where; + } else { + return false; + } + } + // 分析表达式 + $options = $this->_parseOptions($options); + if(empty($options['where'])){ + // 如果条件为空 不进行删除操作 除非设置 1=1 + return false; + } + if(is_array($options['where']) && isset($options['where'][$pk])){ + $pkValue = $options['where'][$pk]; + } + + if(false === $this->_before_delete($options)) { + return false; + } + $result = $this->db->delete($options); + if(false !== $result && is_numeric($result)) { + $data = array(); + if(isset($pkValue)) $data[$pk] = $pkValue; + $this->_after_delete($data,$options); + } + // 返回删除记录个数 + return $result; + } + // 删除数据前的回调方法 + protected function _before_delete($options) {} + // 删除成功后的回调方法 + protected function _after_delete($data,$options) {} + + /** + * 查询数据集 + * @access public + * @param array $options 表达式参数 + * @return mixed + */ + public function select($options=array()) { + $pk = $this->getPk(); + if(is_string($options) || is_numeric($options)) { + // 根据主键查询 + if(strpos($options,',')) { + $where[$pk] = array('IN',$options); + }else{ + $where[$pk] = $options; + } + $options = array(); + $options['where'] = $where; + }elseif (is_array($options) && (count($options) > 0) && is_array($pk)) { + // 根据复合主键查询 + $count = 0; + foreach (array_keys($options) as $key) { + if (is_int($key)) $count++; + } + if ($count == count($pk)) { + $i = 0; + foreach ($pk as $field) { + $where[$field] = $options[$i]; + unset($options[$i++]); + } + $options['where'] = $where; + } else { + return false; + } + } elseif(false === $options){ // 用于子查询 不查询只返回SQL + $options['fetch_sql'] = true; + } + // 分析表达式 + $options = $this->_parseOptions($options); + // 判断查询缓存 + if(isset($options['cache'])){ + $cache = $options['cache']; + $key = is_string($cache['key'])?$cache['key']:md5(serialize($options)); + $data = S($key,'',$cache); + if(false !== $data){ + return $data; + } + } + $resultSet = $this->db->select($options); + if(false === $resultSet) { + return false; + } + if(!empty($resultSet)) { // 有查询结果 + if(is_string($resultSet)){ + return $resultSet; + } + + $resultSet = array_map(array($this,'_read_data'),$resultSet); + $this->_after_select($resultSet,$options); + if(isset($options['index'])){ // 对数据集进行索引 + $index = explode(',',$options['index']); + foreach ($resultSet as $result){ + $_key = $result[$index[0]]; + if(isset($index[1]) && isset($result[$index[1]])){ + $cols[$_key] = $result[$index[1]]; + }else{ + $cols[$_key] = $result; + } + } + $resultSet = $cols; + } + } + + if(isset($cache)){ + S($key,$resultSet,$cache); + } + return $resultSet; + } + // 查询成功后的回调方法 + protected function _after_select(&$resultSet,$options) {} + + /** + * 生成查询SQL 可用于子查询 + * @access public + * @return string + */ + public function buildSql() { + return '( '.$this->fetchSql(true)->select().' )'; + } + + /** + * 分析表达式 + * @access protected + * @param array $options 表达式参数 + * @return array + */ + protected function _parseOptions($options=array()) { + if(is_array($options)) + $options = array_merge($this->options,$options); + + if(!isset($options['table'])){ + // 自动获取表名 + $options['table'] = $this->getTableName(); + $fields = $this->fields; + }else{ + // 指定数据表 则重新获取字段列表 但不支持类型检测 + $fields = $this->getDbFields(); + } + + // 数据表别名 + if(!empty($options['alias'])) { + $options['table'] .= ' '.$options['alias']; + } + // 记录操作的模型名称 + $options['model'] = $this->name; + + // 字段类型验证 + if(isset($options['where']) && is_array($options['where']) && !empty($fields) && !isset($options['join'])) { + // 对数组查询条件进行字段类型检查 + foreach ($options['where'] as $key=>$val){ + $key = trim($key); + if(in_array($key,$fields,true)){ + if(is_scalar($val)) { + $this->_parseType($options['where'],$key); + } + }elseif(!is_numeric($key) && '_' != substr($key,0,1) && false === strpos($key,'.') && false === strpos($key,'(') && false === strpos($key,'|') && false === strpos($key,'&')){ + if(!empty($this->options['strict'])){ + E(L('_ERROR_QUERY_EXPRESS_').':['.$key.'=>'.$val.']'); + } + unset($options['where'][$key]); + } + } + } + // 查询过后清空sql表达式组装 避免影响下次查询 + $this->options = array(); + // 表达式过滤 + $this->_options_filter($options); + return $options; + } + // 表达式过滤回调方法 + protected function _options_filter(&$options) {} + + /** + * 数据类型检测 + * @access protected + * @param mixed $data 数据 + * @param string $key 字段名 + * @return void + */ + protected function _parseType(&$data,$key) { + if(!isset($this->options['bind'][':'.$key]) && isset($this->fields['_type'][$key])){ + $fieldType = strtolower($this->fields['_type'][$key]); + if(false !== strpos($fieldType,'enum')){ + // 支持ENUM类型优先检测 + }elseif(false === strpos($fieldType,'bigint') && false !== strpos($fieldType,'int')) { + $data[$key] = intval($data[$key]); + }elseif(false !== strpos($fieldType,'float') || false !== strpos($fieldType,'double')){ + $data[$key] = floatval($data[$key]); + }elseif(false !== strpos($fieldType,'bool')){ + $data[$key] = (bool)$data[$key]; + } + } + } + + /** + * 数据读取后的处理 + * @access protected + * @param array $data 当前数据 + * @return array + */ + protected function _read_data($data) { + // 检查字段映射 + if(!empty($this->_map) && C('READ_DATA_MAP')) { + foreach ($this->_map as $key=>$val){ + if(isset($data[$val])) { + $data[$key] = $data[$val]; + unset($data[$val]); + } + } + } + return $data; + } + + /** + * 查询数据 + * @access public + * @param mixed $options 表达式参数 + * @return mixed + */ + public function find($options=array()) { + if(is_numeric($options) || is_string($options)) { + $where[$this->getPk()] = $options; + $options = array(); + $options['where'] = $where; + } + // 根据复合主键查找记录 + $pk = $this->getPk(); + if (is_array($options) && (count($options) > 0) && is_array($pk)) { + // 根据复合主键查询 + $count = 0; + foreach (array_keys($options) as $key) { + if (is_int($key)) $count++; + } + if ($count == count($pk)) { + $i = 0; + foreach ($pk as $field) { + $where[$field] = $options[$i]; + unset($options[$i++]); + } + $options['where'] = $where; + } else { + return false; + } + } + // 总是查找一条记录 + $options['limit'] = 1; + // 分析表达式 + $options = $this->_parseOptions($options); + // 判断查询缓存 + if(isset($options['cache'])){ + $cache = $options['cache']; + $key = is_string($cache['key'])?$cache['key']:md5(serialize($options)); + $data = S($key,'',$cache); + if(false !== $data){ + $this->data = $data; + return $data; + } + } + $resultSet = $this->db->select($options); + if(false === $resultSet) { + return false; + } + if(empty($resultSet)) {// 查询结果为空 + return null; + } + if(is_string($resultSet)){ + return $resultSet; + } + + // 读取数据后的处理 + $data = $this->_read_data($resultSet[0]); + $this->_after_find($data,$options); + if(!empty($this->options['result'])) { + return $this->returnResult($data,$this->options['result']); + } + $this->data = $data; + if(isset($cache)){ + S($key,$data,$cache); + } + return $this->data; + } + // 查询成功的回调方法 + protected function _after_find(&$result,$options) {} + + protected function returnResult($data,$type=''){ + if ($type){ + if(is_callable($type)){ + return call_user_func($type,$data); + } + switch (strtolower($type)){ + case 'json': + return json_encode($data); + case 'xml': + return xml_encode($data); + } + } + return $data; + } + + /** + * 处理字段映射 + * @access public + * @param array $data 当前数据 + * @param integer $type 类型 0 写入 1 读取 + * @return array + */ + public function parseFieldsMap($data,$type=1) { + // 检查字段映射 + if(!empty($this->_map)) { + foreach ($this->_map as $key=>$val){ + if($type==1) { // 读取 + if(isset($data[$val])) { + $data[$key] = $data[$val]; + unset($data[$val]); + } + }else{ + if(isset($data[$key])) { + $data[$val] = $data[$key]; + unset($data[$key]); + } + } + } + } + return $data; + } + + /** + * 设置记录的某个字段值 + * 支持使用数据库字段和方法 + * @access public + * @param string|array $field 字段名 + * @param string $value 字段值 + * @return boolean + */ + public function setField($field,$value='') { + if(is_array($field)) { + $data = $field; + }else{ + $data[$field] = $value; + } + return $this->save($data); + } + + /** + * 字段值增长 + * @access public + * @param string $field 字段名 + * @param integer $step 增长值 + * @param integer $lazyTime 延时时间(s) + * @return boolean + */ + public function setInc($field,$step=1,$lazyTime=0) { + if($lazyTime>0) {// 延迟写入 + $condition = $this->options['where']; + $guid = md5($this->name.'_'.$field.'_'.serialize($condition)); + $step = $this->lazyWrite($guid,$step,$lazyTime); + if(empty($step)) { + return true; // 等待下次写入 + }elseif($step < 0) { + $step = '-'.$step; + } + } + return $this->setField($field,array('exp',$field.'+'.$step)); + } + + /** + * 字段值减少 + * @access public + * @param string $field 字段名 + * @param integer $step 减少值 + * @param integer $lazyTime 延时时间(s) + * @return boolean + */ + public function setDec($field,$step=1,$lazyTime=0) { + if($lazyTime>0) {// 延迟写入 + $condition = $this->options['where']; + $guid = md5($this->name.'_'.$field.'_'.serialize($condition)); + $step = $this->lazyWrite($guid,-$step,$lazyTime); + if(empty($step)) { + return true; // 等待下次写入 + }elseif($step > 0) { + $step = '-'.$step; + } + } + return $this->setField($field,array('exp',$field.'-'.$step)); + } + + /** + * 延时更新检查 返回false表示需要延时 + * 否则返回实际写入的数值 + * @access public + * @param string $guid 写入标识 + * @param integer $step 写入步进值 + * @param integer $lazyTime 延时时间(s) + * @return false|integer + */ + protected function lazyWrite($guid,$step,$lazyTime) { + if(false !== ($value = S($guid))) { // 存在缓存写入数据 + if(NOW_TIME > S($guid.'_time')+$lazyTime) { + // 延时更新时间到了,删除缓存数据 并实际写入数据库 + S($guid,NULL); + S($guid.'_time',NULL); + return $value+$step; + }else{ + // 追加数据到缓存 + S($guid,$value+$step); + return false; + } + }else{ // 没有缓存数据 + S($guid,$step); + // 计时开始 + S($guid.'_time',NOW_TIME); + return false; + } + } + + /** + * 获取一条记录的某个字段值 + * @access public + * @param string $field 字段名 + * @param string $spea 字段数据间隔符号 NULL返回数组 + * @return mixed + */ + public function getField($field,$sepa=null) { + $options['field'] = $field; + $options = $this->_parseOptions($options); + // 判断查询缓存 + if(isset($options['cache'])){ + $cache = $options['cache']; + $key = is_string($cache['key'])?$cache['key']:md5($sepa.serialize($options)); + $data = S($key,'',$cache); + if(false !== $data){ + return $data; + } + } + $field = trim($field); + if(strpos($field,',') && false !== $sepa) { // 多字段 + if(!isset($options['limit'])){ + $options['limit'] = is_numeric($sepa)?$sepa:''; + } + $resultSet = $this->db->select($options); + if(!empty($resultSet)) { + if(is_string($resultSet)){ + return $resultSet; + } + $_field = explode(',', $field); + $field = array_keys($resultSet[0]); + $key1 = array_shift($field); + $key2 = array_shift($field); + $cols = array(); + $count = count($_field); + foreach ($resultSet as $result){ + $name = $result[$key1]; + if(2==$count) { + $cols[$name] = $result[$key2]; + }else{ + $cols[$name] = is_string($sepa)?implode($sepa,array_slice($result,1)):$result; + } + } + if(isset($cache)){ + S($key,$cols,$cache); + } + return $cols; + } + }else{ // 查找一条记录 + // 返回数据个数 + if(true !== $sepa) {// 当sepa指定为true的时候 返回所有数据 + $options['limit'] = is_numeric($sepa)?$sepa:1; + } + $result = $this->db->select($options); + if(!empty($result)) { + if(is_string($result)){ + return $result; + } + if(true !== $sepa && 1==$options['limit']) { + $data = reset($result[0]); + if(isset($cache)){ + S($key,$data,$cache); + } + return $data; + } + foreach ($result as $val){ + $array[] = $val[$field]; + } + if(isset($cache)){ + S($key,$array,$cache); + } + return $array; + } + } + return null; + } + + /** + * 创建数据对象 但不保存到数据库 + * @access public + * @param mixed $data 创建数据 + * @param string $type 状态 + * @return mixed + */ + public function create($data='',$type='') { + // 如果没有传值默认取POST数据 + if(empty($data)) { + $data = I('post.'); + }elseif(is_object($data)){ + $data = get_object_vars($data); + } + // 验证数据 + if(empty($data) || !is_array($data)) { + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + + // 状态 + $type = $type?:(!empty($data[$this->getPk()])?self::MODEL_UPDATE:self::MODEL_INSERT); + + // 检查字段映射 + $data = $this->parseFieldsMap($data,0); + + // 检测提交字段的合法性 + if(isset($this->options['field'])) { // $this->field('field1,field2...')->create() + $fields = $this->options['field']; + unset($this->options['field']); + }elseif($type == self::MODEL_INSERT && isset($this->insertFields)) { + $fields = $this->insertFields; + }elseif($type == self::MODEL_UPDATE && isset($this->updateFields)) { + $fields = $this->updateFields; + } + if(isset($fields)) { + if(is_string($fields)) { + $fields = explode(',',$fields); + } + // 判断令牌验证字段 + if(C('TOKEN_ON')) $fields[] = C('TOKEN_NAME', null, '__hash__'); + foreach ($data as $key=>$val){ + if(!in_array($key,$fields)) { + unset($data[$key]); + } + } + } + + // 数据自动验证 + if(!$this->autoValidation($data,$type)) return false; + + // 表单令牌验证 + if(!$this->autoCheckToken($data)) { + $this->error = L('_TOKEN_ERROR_'); + return false; + } + + // 验证完成生成数据对象 + if($this->autoCheckFields) { // 开启字段检测 则过滤非法字段数据 + $fields = $this->getDbFields(); + foreach ($data as $key=>$val){ + if(!in_array($key,$fields)) { + unset($data[$key]); + }elseif(MAGIC_QUOTES_GPC && is_string($val)){ + $data[$key] = stripslashes($val); + } + } + } + + // 创建完成对数据进行自动处理 + $this->autoOperation($data,$type); + // 赋值当前数据对象 + $this->data = $data; + // 返回创建的数据以供其他调用 + return $data; + } + + // 自动表单令牌验证 + // TODO ajax无刷新多次提交暂不能满足 + public function autoCheckToken($data) { + // 支持使用token(false) 关闭令牌验证 + if(isset($this->options['token']) && !$this->options['token']) return true; + if(C('TOKEN_ON')){ + $name = C('TOKEN_NAME', null, '__hash__'); + if(!isset($data[$name]) || !isset($_SESSION[$name])) { // 令牌数据无效 + return false; + } + + // 令牌验证 + list($key,$value) = explode('_',$data[$name]); + if(isset($_SESSION[$name][$key]) && $value && $_SESSION[$name][$key] === $value) { // 防止重复提交 + unset($_SESSION[$name][$key]); // 验证完成销毁session + return true; + } + // 开启TOKEN重置 + if(C('TOKEN_RESET')) unset($_SESSION[$name][$key]); + return false; + } + return true; + } + + /** + * 使用正则验证数据 + * @access public + * @param string $value 要验证的数据 + * @param string $rule 验证规则 + * @return boolean + */ + public function regex($value,$rule) { + $validate = array( + 'require' => '/\S+/', + 'email' => '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', + 'url' => '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/', + 'currency' => '/^\d+(\.\d+)?$/', + 'number' => '/^\d+$/', + 'zip' => '/^\d{6}$/', + 'integer' => '/^[-\+]?\d+$/', + 'double' => '/^[-\+]?\d+(\.\d+)?$/', + 'english' => '/^[A-Za-z]+$/', + ); + // 检查是否有内置的正则表达式 + if(isset($validate[strtolower($rule)])) + $rule = $validate[strtolower($rule)]; + return preg_match($rule,$value)===1; + } + + /** + * 自动表单处理 + * @access public + * @param array $data 创建数据 + * @param string $type 创建类型 + * @return mixed + */ + private function autoOperation(&$data,$type) { + if(false === $this->options['auto']){ + // 关闭自动完成 + return $data; + } + if(!empty($this->options['auto'])) { + $_auto = $this->options['auto']; + unset($this->options['auto']); + }elseif(!empty($this->_auto)){ + $_auto = $this->_auto; + } + // 自动填充 + if(isset($_auto)) { + foreach ($_auto as $auto){ + // 填充因子定义格式 + // array('field','填充内容','填充条件','附加规则',[额外参数]) + if(empty($auto[2])) $auto[2] = self::MODEL_INSERT; // 默认为新增的时候自动填充 + if( $type == $auto[2] || $auto[2] == self::MODEL_BOTH) { + if(empty($auto[3])) $auto[3] = 'string'; + switch(trim($auto[3])) { + case 'function': // 使用函数进行填充 字段的值作为参数 + case 'callback': // 使用回调方法 + $args = isset($auto[4])?(array)$auto[4]:array(); + if(isset($data[$auto[0]])) { + array_unshift($args,$data[$auto[0]]); + } + if('function'==$auto[3]) { + $data[$auto[0]] = call_user_func_array($auto[1], $args); + }else{ + $data[$auto[0]] = call_user_func_array(array(&$this,$auto[1]), $args); + } + break; + case 'field': // 用其它字段的值进行填充 + $data[$auto[0]] = $data[$auto[1]]; + break; + case 'ignore': // 为空忽略 + if($auto[1]===$data[$auto[0]]) + unset($data[$auto[0]]); + break; + case 'string': + default: // 默认作为字符串填充 + $data[$auto[0]] = $auto[1]; + } + if(isset($data[$auto[0]]) && false === $data[$auto[0]] ) unset($data[$auto[0]]); + } + } + } + return $data; + } + + /** + * 自动表单验证 + * @access protected + * @param array $data 创建数据 + * @param string $type 创建类型 + * @return boolean + */ + protected function autoValidation($data,$type) { + if(false === $this->options['validate'] ){ + // 关闭自动验证 + return true; + } + if(!empty($this->options['validate'])) { + $_validate = $this->options['validate']; + unset($this->options['validate']); + }elseif(!empty($this->_validate)){ + $_validate = $this->_validate; + } + // 属性验证 + if(isset($_validate)) { // 如果设置了数据自动验证则进行数据验证 + if($this->patchValidate) { // 重置验证错误信息 + $this->error = array(); + } + foreach($_validate as $key=>$val) { + // 验证因子定义格式 + // array(field,rule,message,condition,type,when,params) + // 判断是否需要执行验证 + if(empty($val[5]) || ( $val[5]== self::MODEL_BOTH && $type < 3 ) || $val[5]== $type ) { + if(0==strpos($val[2],'{%') && strpos($val[2],'}')) + // 支持提示信息的多语言 使用 {%语言定义} 方式 + $val[2] = L(substr($val[2],2,-1)); + $val[3] = isset($val[3])?$val[3]:self::EXISTS_VALIDATE; + $val[4] = isset($val[4])?$val[4]:'regex'; + // 判断验证条件 + switch($val[3]) { + case self::MUST_VALIDATE: // 必须验证 不管表单是否有设置该字段 + if(false === $this->_validationField($data,$val)) + return false; + break; + case self::VALUE_VALIDATE: // 值不为空的时候才验证 + if('' != trim($data[$val[0]])) + if(false === $this->_validationField($data,$val)) + return false; + break; + default: // 默认表单存在该字段就验证 + if(isset($data[$val[0]])) + if(false === $this->_validationField($data,$val)) + return false; + } + } + } + // 批量验证的时候最后返回错误 + if(!empty($this->error)) return false; + } + return true; + } + + /** + * 验证表单字段 支持批量验证 + * 如果批量验证返回错误的数组信息 + * @access protected + * @param array $data 创建数据 + * @param array $val 验证因子 + * @return boolean + */ + protected function _validationField($data,$val) { + if($this->patchValidate && isset($this->error[$val[0]])) + return ; //当前字段已经有规则验证没有通过 + if(false === $this->_validationFieldItem($data,$val)){ + if($this->patchValidate) { + $this->error[$val[0]] = $val[2]; + }else{ + $this->error = $val[2]; + return false; + } + } + return ; + } + + /** + * 根据验证因子验证字段 + * @access protected + * @param array $data 创建数据 + * @param array $val 验证因子 + * @return boolean + */ + protected function _validationFieldItem($data,$val) { + switch(strtolower(trim($val[4]))) { + case 'function':// 使用函数进行验证 + case 'callback':// 调用方法进行验证 + $args = isset($val[6])?(array)$val[6]:array(); + if(is_string($val[0]) && strpos($val[0], ',')) + $val[0] = explode(',', $val[0]); + if(is_array($val[0])){ + // 支持多个字段验证 + foreach($val[0] as $field) + $_data[$field] = $data[$field]; + array_unshift($args, $_data); + }else{ + array_unshift($args, $data[$val[0]]); + } + if('function'==$val[4]) { + return call_user_func_array($val[1], $args); + }else{ + return call_user_func_array(array(&$this, $val[1]), $args); + } + case 'confirm': // 验证两个字段是否相同 + return $data[$val[0]] == $data[$val[1]]; + case 'unique': // 验证某个值是否唯一 + if(is_string($val[0]) && strpos($val[0],',')) + $val[0] = explode(',',$val[0]); + $map = array(); + if(is_array($val[0])) { + // 支持多个字段验证 + foreach ($val[0] as $field) + $map[$field] = $data[$field]; + }else{ + $map[$val[0]] = $data[$val[0]]; + } + $pk = $this->getPk(); + if(!empty($data[$pk]) && is_string($pk)) { // 完善编辑的时候验证唯一 + $map[$pk] = array('neq',$data[$pk]); + } + if($this->where($map)->find()) return false; + return true; + default: // 检查附加规则 + return $this->check($data[$val[0]],$val[1],$val[4]); + } + } + + /** + * 验证数据 支持 in between equal length regex expire ip_allow ip_deny + * @access public + * @param string $value 验证数据 + * @param mixed $rule 验证表达式 + * @param string $type 验证方式 默认为正则验证 + * @return boolean + */ + public function check($value,$rule,$type='regex'){ + $type = strtolower(trim($type)); + switch($type) { + case 'in': // 验证是否在某个指定范围之内 逗号分隔字符串或者数组 + case 'notin': + $range = is_array($rule)? $rule : explode(',',$rule); + return $type == 'in' ? in_array($value ,$range) : !in_array($value ,$range); + case 'between': // 验证是否在某个范围 + case 'notbetween': // 验证是否不在某个范围 + if (is_array($rule)){ + $min = $rule[0]; + $max = $rule[1]; + }else{ + list($min,$max) = explode(',',$rule); + } + return $type == 'between' ? $value>=$min && $value<=$max : $value<$min || $value>$max; + case 'equal': // 验证是否等于某个值 + case 'notequal': // 验证是否等于某个值 + return $type == 'equal' ? $value == $rule : $value != $rule; + case 'length': // 验证长度 + $length = mb_strlen($value,'utf-8'); // 当前数据长度 + if(strpos($rule,',')) { // 长度区间 + list($min,$max) = explode(',',$rule); + return $length >= $min && $length <= $max; + }else{// 指定长度 + return $length == $rule; + } + case 'expire': + list($start,$end) = explode(',',$rule); + if(!is_numeric($start)) $start = strtotime($start); + if(!is_numeric($end)) $end = strtotime($end); + return NOW_TIME >= $start && NOW_TIME <= $end; + case 'ip_allow': // IP 操作许可验证 + return in_array(get_client_ip(),explode(',',$rule)); + case 'ip_deny': // IP 操作禁止验证 + return !in_array(get_client_ip(),explode(',',$rule)); + case 'regex': + default: // 默认使用正则验证 可以使用验证类中定义的验证名称 + // 检查附加规则 + return $this->regex($value,$rule); + } + } + + /** + * 存储过程返回多数据集 + * @access public + * @param string $sql SQL指令 + * @param mixed $parse 是否需要解析SQL + * @return array + */ + public function procedure($sql, $parse = false) { + return $this->db->procedure($sql, $parse); + } + + /** + * SQL查询 + * @access public + * @param string $sql SQL指令 + * @param mixed $parse 是否需要解析SQL + * @return mixed + */ + public function query($sql,$parse=false) { + if(!is_bool($parse) && !is_array($parse)) { + $parse = func_get_args(); + array_shift($parse); + } + $sql = $this->parseSql($sql,$parse); + return $this->db->query($sql); + } + + /** + * 执行SQL语句 + * @access public + * @param string $sql SQL指令 + * @param mixed $parse 是否需要解析SQL + * @return false | integer + */ + public function execute($sql,$parse=false) { + if(!is_bool($parse) && !is_array($parse)) { + $parse = func_get_args(); + array_shift($parse); + } + $sql = $this->parseSql($sql,$parse); + return $this->db->execute($sql); + } + + /** + * 解析SQL语句 + * @access public + * @param string $sql SQL指令 + * @param boolean $parse 是否需要解析SQL + * @return string + */ + protected function parseSql($sql,$parse) { + // 分析表达式 + if(true === $parse) { + $options = $this->_parseOptions(); + $sql = $this->db->parseSql($sql,$options); + }elseif(is_array($parse)){ // SQL预处理 + $parse = array_map(array($this->db,'escapeString'),$parse); + $sql = vsprintf($sql,$parse); + }else{ + $sql = strtr($sql,array('__TABLE__'=>$this->getTableName(),'__PREFIX__'=>$this->tablePrefix)); + $prefix = $this->tablePrefix; + $sql = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $sql); + } + $this->db->setModel($this->name); + return $sql; + } + + /** + * 切换当前的数据库连接 + * @access public + * @param integer $linkNum 连接序号 + * @param mixed $config 数据库连接信息 + * @param boolean $force 强制重新连接 + * @return Model + */ + public function db($linkNum='',$config='',$force=false) { + if('' === $linkNum && $this->db) { + return $this->db; + } + + if(!isset($this->_db[$linkNum]) || $force ) { + // 创建一个新的实例 + if(!empty($config) && is_string($config) && false === strpos($config,'/')) { // 支持读取配置参数 + $config = C($config); + } + $this->_db[$linkNum] = Db::getInstance($config); + }elseif(NULL === $config){ + $this->_db[$linkNum]->close(); // 关闭数据库连接 + unset($this->_db[$linkNum]); + return ; + } + + // 切换数据库连接 + $this->db = $this->_db[$linkNum]; + $this->_after_db(); + // 字段检测 + if(!empty($this->name) && $this->autoCheckFields) $this->_checkTableInfo(); + return $this; + } + // 数据库切换后回调方法 + protected function _after_db() {} + + /** + * 得到当前的数据对象名称 + * @access public + * @return string + */ + public function getModelName() { + if(empty($this->name)){ + $name = substr(get_class($this),0,-strlen(C('DEFAULT_M_LAYER'))); + if ( $pos = strrpos($name,'\\') ) {//有命名空间 + $this->name = substr($name,$pos+1); + }else{ + $this->name = $name; + } + } + return $this->name; + } + + /** + * 得到完整的数据表名 + * @access public + * @return string + */ + public function getTableName() { + if(empty($this->trueTableName)) { + $tableName = !empty($this->tablePrefix) ? $this->tablePrefix : ''; + if(!empty($this->tableName)) { + $tableName .= $this->tableName; + }else{ + $tableName .= parse_name($this->name); + } + $this->trueTableName = strtolower($tableName); + } + return (!empty($this->dbName)?$this->dbName.'.':'').$this->trueTableName; + } + + /** + * 启动事务 + * @access public + * @return void + */ + public function startTrans() { + $this->commit(); + $this->db->startTrans(); + return ; + } + + /** + * 提交事务 + * @access public + * @return boolean + */ + public function commit() { + return $this->db->commit(); + } + + /** + * 事务回滚 + * @access public + * @return boolean + */ + public function rollback() { + return $this->db->rollback(); + } + + /** + * 返回模型的错误信息 + * @access public + * @return string + */ + public function getError(){ + return $this->error; + } + + /** + * 返回数据库的错误信息 + * @access public + * @return string + */ + public function getDbError() { + return $this->db->getError(); + } + + /** + * 返回最后插入的ID + * @access public + * @return string + */ + public function getLastInsID() { + return $this->db->getLastInsID(); + } + + /** + * 返回最后执行的sql语句 + * @access public + * @return string + */ + public function getLastSql() { + return $this->db->getLastSql($this->name); + } + // 鉴于getLastSql比较常用 增加_sql 别名 + public function _sql(){ + return $this->getLastSql(); + } + + /** + * 获取主键名称 + * @access public + * @return string + */ + public function getPk() { + return $this->pk; + } + + /** + * 获取数据表字段信息 + * @access public + * @return array + */ + public function getDbFields(){ + if(isset($this->options['table'])) {// 动态指定表名 + if(is_array($this->options['table'])){ + $table = key($this->options['table']); + }else{ + $table = $this->options['table']; + if(strpos($table,')')){ + // 子查询 + return false; + } + } + $fields = $this->db->getFields($table); + return $fields ? array_keys($fields) : false; + } + if($this->fields) { + $fields = $this->fields; + unset($fields['_type'],$fields['_pk']); + return $fields; + } + return false; + } + + /** + * 设置数据对象值 + * @access public + * @param mixed $data 数据 + * @return Model + */ + public function data($data=''){ + if('' === $data && !empty($this->data)) { + return $this->data; + } + if(is_object($data)){ + $data = get_object_vars($data); + }elseif(is_string($data)){ + parse_str($data,$data); + }elseif(!is_array($data)){ + E(L('_DATA_TYPE_INVALID_')); + } + $this->data = $data; + return $this; + } + + /** + * 指定当前的数据表 + * @access public + * @param mixed $table + * @return Model + */ + public function table($table) { + $prefix = $this->tablePrefix; + if(is_array($table)) { + $this->options['table'] = $table; + }elseif(!empty($table)) { + //将__TABLE_NAME__替换成带前缀的表名 + $table = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $table); + $this->options['table'] = $table; + } + return $this; + } + + /** + * USING支持 用于多表删除 + * @access public + * @param mixed $using + * @return Model + */ + public function using($using){ + $prefix = $this->tablePrefix; + if(is_array($using)) { + $this->options['using'] = $using; + }elseif(!empty($using)) { + //将__TABLE_NAME__替换成带前缀的表名 + $using = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $using); + $this->options['using'] = $using; + } + return $this; + } + + /** + * 查询SQL组装 join + * @access public + * @param mixed $join + * @param string $type JOIN类型 + * @return Model + */ + public function join($join,$type='INNER') { + $prefix = $this->tablePrefix; + if(is_array($join)) { + foreach ($join as $key=>&$_join){ + $_join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $_join); + $_join = false !== stripos($_join,'JOIN')? $_join : $type.' JOIN ' .$_join; + } + $this->options['join'] = $join; + }elseif(!empty($join)) { + //将__TABLE_NAME__字符串替换成带前缀的表名 + $join = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $join); + $this->options['join'][] = false !== stripos($join,'JOIN')? $join : $type.' JOIN '.$join; + } + return $this; + } + + /** + * 查询SQL组装 union + * @access public + * @param mixed $union + * @param boolean $all + * @return Model + */ + public function union($union,$all=false) { + if(empty($union)) return $this; + if($all) { + $this->options['union']['_all'] = true; + } + if(is_object($union)) { + $union = get_object_vars($union); + } + // 转换union表达式 + if(is_string($union) ) { + $prefix = $this->tablePrefix; + //将__TABLE_NAME__字符串替换成带前缀的表名 + $options = preg_replace_callback("/__([A-Z0-9_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $union); + }elseif(is_array($union)){ + if(isset($union[0])) { + $this->options['union'] = array_merge($this->options['union'],$union); + return $this; + }else{ + $options = $union; + } + }else{ + E(L('_DATA_TYPE_INVALID_')); + } + $this->options['union'][] = $options; + return $this; + } + + /** + * 查询缓存 + * @access public + * @param mixed $key + * @param integer $expire + * @param string $type + * @return Model + */ + public function cache($key=true,$expire=null,$type=''){ + // 增加快捷调用方式 cache(10) 等同于 cache(true, 10) + if(is_numeric($key) && is_null($expire)){ + $expire = $key; + $key = true; + } + if(false !== $key) + $this->options['cache'] = array('key'=>$key,'expire'=>$expire,'type'=>$type); + return $this; + } + + /** + * 指定查询字段 支持字段排除 + * @access public + * @param mixed $field + * @param boolean $except 是否排除 + * @return Model + */ + public function field($field,$except=false){ + if(true === $field) {// 获取全部字段 + $fields = $this->getDbFields(); + $field = $fields?:'*'; + }elseif($except) {// 字段排除 + if(is_string($field)) { + $field = explode(',',$field); + } + $fields = $this->getDbFields(); + $field = $fields?array_diff($fields,$field):$field; + } + $this->options['field'] = $field; + return $this; + } + + /** + * 调用命名范围 + * @access public + * @param mixed $scope 命名范围名称 支持多个 和直接定义 + * @param array $args 参数 + * @return Model + */ + public function scope($scope='',$args=NULL){ + if('' === $scope) { + if(isset($this->_scope['default'])) { + // 默认的命名范围 + $options = $this->_scope['default']; + }else{ + return $this; + } + }elseif(is_string($scope)){ // 支持多个命名范围调用 用逗号分割 + $scopes = explode(',',$scope); + $options = array(); + foreach ($scopes as $name){ + if(!isset($this->_scope[$name])) continue; + $options = array_merge($options,$this->_scope[$name]); + } + if(!empty($args) && is_array($args)) { + $options = array_merge($options,$args); + } + }elseif(is_array($scope)){ // 直接传入命名范围定义 + $options = $scope; + } + + if(is_array($options) && !empty($options)){ + $this->options = array_merge($this->options,array_change_key_case($options)); + } + return $this; + } + + /** + * 指定查询条件 支持安全过滤 + * @access public + * @param mixed $where 条件表达式 + * @param mixed $parse 预处理参数 + * @return Model + */ + public function where($where,$parse=null){ + if(!is_null($parse) && is_string($where)) { + if(!is_array($parse)) { + $parse = func_get_args(); + array_shift($parse); + } + $parse = array_map(array($this->db,'escapeString'),$parse); + $where = vsprintf($where,$parse); + }elseif(is_object($where)){ + $where = get_object_vars($where); + } + if(is_string($where) && '' != $where){ + $map = array(); + $map['_string'] = $where; + $where = $map; + } + if(isset($this->options['where'])){ + $this->options['where'] = array_merge($this->options['where'],$where); + }else{ + $this->options['where'] = $where; + } + + return $this; + } + + /** + * 指定查询数量 + * @access public + * @param mixed $offset 起始位置 + * @param mixed $length 查询数量 + * @return Model + */ + public function limit($offset,$length=null){ + if(is_null($length) && strpos($offset,',')){ + list($offset,$length) = explode(',',$offset); + } + $this->options['limit'] = intval($offset).( $length? ','.intval($length) : '' ); + return $this; + } + + /** + * 指定分页 + * @access public + * @param mixed $page 页数 + * @param mixed $listRows 每页数量 + * @return Model + */ + public function page($page,$listRows=null){ + if(is_null($listRows) && strpos($page,',')){ + list($page,$listRows) = explode(',',$page); + } + $this->options['page'] = array(intval($page),intval($listRows)); + return $this; + } + + /** + * 查询注释 + * @access public + * @param string $comment 注释 + * @return Model + */ + public function comment($comment){ + $this->options['comment'] = $comment; + return $this; + } + + /** + * 获取执行的SQL语句 + * @access public + * @param boolean $fetch 是否返回sql + * @return Model + */ + public function fetchSql($fetch=true){ + $this->options['fetch_sql'] = $fetch; + return $this; + } + + /** + * 参数绑定 + * @access public + * @param string $key 参数名 + * @param mixed $value 绑定的变量及绑定参数 + * @return Model + */ + public function bind($key,$value=false) { + if(is_array($key)){ + $this->options['bind'] = $key; + }else{ + $num = func_num_args(); + if($num>2){ + $params = func_get_args(); + array_shift($params); + $this->options['bind'][$key] = $params; + }else{ + $this->options['bind'][$key] = $value; + } + } + return $this; + } + + /** + * 设置模型的属性值 + * @access public + * @param string $name 名称 + * @param mixed $value 值 + * @return Model + */ + public function setProperty($name,$value) { + if(property_exists($this,$name)) + $this->$name = $value; + return $this; + } + +} diff --git a/ThinkPHP/Library/Think/Model/AdvModel.class.php b/ThinkPHP/Library/Think/Model/AdvModel.class.php new file mode 100644 index 0000000..2e91992 --- /dev/null +++ b/ThinkPHP/Library/Think/Model/AdvModel.class.php @@ -0,0 +1,595 @@ + +// +---------------------------------------------------------------------- +namespace Think\Model; +use Think\Model; +/** + * 高级模型扩展 + */ +class AdvModel extends Model { + protected $optimLock = 'lock_version'; + protected $returnType = 'array'; + protected $blobFields = array(); + protected $blobValues = null; + protected $serializeField = array(); + protected $readonlyField = array(); + protected $_filter = array(); + protected $partition = array(); + + public function __construct($name='',$tablePrefix='',$connection='') { + if('' !== $name || is_subclass_of($this,'AdvModel') ){ + // 如果是AdvModel子类或者有传入模型名称则获取字段缓存 + }else{ + // 空的模型 关闭字段缓存 + $this->autoCheckFields = false; + } + parent::__construct($name,$tablePrefix,$connection); + } + + /** + * 利用__call方法重载 实现一些特殊的Model方法 (魔术方法) + * @access public + * @param string $method 方法名称 + * @param mixed $args 调用参数 + * @return mixed + */ + public function __call($method,$args) { + if(strtolower(substr($method,0,3))=='top'){ + // 获取前N条记录 + $count = substr($method,3); + array_unshift($args,$count); + return call_user_func_array(array(&$this, 'topN'), $args); + }else{ + return parent::__call($method,$args); + } + } + + /** + * 对保存到数据库的数据进行处理 + * @access protected + * @param mixed $data 要操作的数据 + * @return boolean + */ + protected function _facade($data) { + // 检查序列化字段 + $data = $this->serializeField($data); + return parent::_facade($data); + } + + // 查询成功后的回调方法 + protected function _after_find(&$result,$options='') { + // 检查序列化字段 + $this->checkSerializeField($result); + // 获取文本字段 + $this->getBlobFields($result); + // 检查字段过滤 + $result = $this->getFilterFields($result); + // 缓存乐观锁 + $this->cacheLockVersion($result); + } + + // 查询数据集成功后的回调方法 + protected function _after_select(&$resultSet,$options='') { + // 检查序列化字段 + $resultSet = $this->checkListSerializeField($resultSet); + // 获取文本字段 + $resultSet = $this->getListBlobFields($resultSet); + // 检查列表字段过滤 + $resultSet = $this->getFilterListFields($resultSet); + } + + // 写入前的回调方法 + protected function _before_insert(&$data,$options='') { + // 记录乐观锁 + $data = $this->recordLockVersion($data); + // 检查文本字段 + $data = $this->checkBlobFields($data); + // 检查字段过滤 + $data = $this->setFilterFields($data); + } + + protected function _after_insert($data,$options) { + // 保存文本字段 + $this->saveBlobFields($data); + } + + // 更新前的回调方法 + protected function _before_update(&$data,$options='') { + // 检查乐观锁 + $pk = $this->getPK(); + if(isset($options['where'][$pk])){ + $id = $options['where'][$pk]; + if(!$this->checkLockVersion($id,$data)) { + return false; + } + } + // 检查文本字段 + $data = $this->checkBlobFields($data); + // 检查只读字段 + $data = $this->checkReadonlyField($data); + // 检查字段过滤 + $data = $this->setFilterFields($data); + } + + protected function _after_update($data,$options) { + // 保存文本字段 + $this->saveBlobFields($data); + } + + protected function _after_delete($data,$options) { + // 删除Blob数据 + $this->delBlobFields($data); + } + + /** + * 记录乐观锁 + * @access protected + * @param array $data 数据对象 + * @return array + */ + protected function recordLockVersion($data) { + // 记录乐观锁 + if($this->optimLock && !isset($data[$this->optimLock]) ) { + if(in_array($this->optimLock,$this->fields,true)) { + $data[$this->optimLock] = 0; + } + } + return $data; + } + + /** + * 缓存乐观锁 + * @access protected + * @param array $data 数据对象 + * @return void + */ + protected function cacheLockVersion($data) { + if($this->optimLock) { + if(isset($data[$this->optimLock]) && isset($data[$this->getPk()])) { + // 只有当存在乐观锁字段和主键有值的时候才记录乐观锁 + $_SESSION[$this->name.'_'.$data[$this->getPk()].'_lock_version'] = $data[$this->optimLock]; + } + } + } + + /** + * 检查乐观锁 + * @access protected + * @param inteter $id 当前主键 + * @param array $data 当前数据 + * @return mixed + */ + protected function checkLockVersion($id,&$data) { + // 检查乐观锁 + $identify = $this->name.'_'.$id.'_lock_version'; + if($this->optimLock && isset($_SESSION[$identify])) { + $lock_version = $_SESSION[$identify]; + $vo = $this->field($this->optimLock)->find($id); + $_SESSION[$identify] = $lock_version; + $curr_version = $vo[$this->optimLock]; + if(isset($curr_version)) { + if($curr_version>0 && $lock_version != $curr_version) { + // 记录已经更新 + $this->error = L('_RECORD_HAS_UPDATE_'); + return false; + }else{ + // 更新乐观锁 + $save_version = $data[$this->optimLock]; + if($save_version != $lock_version+1) { + $data[$this->optimLock] = $lock_version+1; + } + $_SESSION[$identify] = $lock_version+1; + } + } + } + return true; + } + + /** + * 查找前N个记录 + * @access public + * @param integer $count 记录个数 + * @param array $options 查询表达式 + * @return array + */ + public function topN($count,$options=array()) { + $options['limit'] = $count; + return $this->select($options); + } + + /** + * 查询符合条件的第N条记录 + * 0 表示第一条记录 -1 表示最后一条记录 + * @access public + * @param integer $position 记录位置 + * @param array $options 查询表达式 + * @return mixed + */ + public function getN($position=0,$options=array()) { + if($position>=0) { // 正向查找 + $options['limit'] = $position.',1'; + $list = $this->select($options); + return $list?$list[0]:false; + }else{ // 逆序查找 + $list = $this->select($options); + return $list?$list[count($list)-abs($position)]:false; + } + } + + /** + * 获取满足条件的第一条记录 + * @access public + * @param array $options 查询表达式 + * @return mixed + */ + public function first($options=array()) { + return $this->getN(0,$options); + } + + /** + * 获取满足条件的最后一条记录 + * @access public + * @param array $options 查询表达式 + * @return mixed + */ + public function last($options=array()) { + return $this->getN(-1,$options); + } + + /** + * 返回数据 + * @access public + * @param array $data 数据 + * @param string $type 返回类型 默认为数组 + * @return mixed + */ + public function returnResult($data,$type='') { + if('' === $type) + $type = $this->returnType; + switch($type) { + case 'array' : return $data; + case 'object': return (object)$data; + default:// 允许用户自定义返回类型 + if(class_exists($type)) + return new $type($data); + else + E(L('_CLASS_NOT_EXIST_').':'.$type); + } + } + + /** + * 获取数据的时候过滤数据字段 + * @access protected + * @param mixed $result 查询的数据 + * @return array + */ + protected function getFilterFields(&$result) { + if(!empty($this->_filter)) { + foreach ($this->_filter as $field=>$filter){ + if(isset($result[$field])) { + $fun = $filter[1]; + if(!empty($fun)) { + if(isset($filter[2]) && $filter[2]){ + // 传递整个数据对象作为参数 + $result[$field] = call_user_func($fun,$result); + }else{ + // 传递字段的值作为参数 + $result[$field] = call_user_func($fun,$result[$field]); + } + } + } + } + } + return $result; + } + + protected function getFilterListFields(&$resultSet) { + if(!empty($this->_filter)) { + foreach ($resultSet as $key=>$result) + $resultSet[$key] = $this->getFilterFields($result); + } + return $resultSet; + } + + /** + * 写入数据的时候过滤数据字段 + * @access protected + * @param mixed $result 查询的数据 + * @return array + */ + protected function setFilterFields($data) { + if(!empty($this->_filter)) { + foreach ($this->_filter as $field=>$filter){ + if(isset($data[$field])) { + $fun = $filter[0]; + if(!empty($fun)) { + if(isset($filter[2]) && $filter[2]) { + // 传递整个数据对象作为参数 + $data[$field] = call_user_func($fun,$data); + }else{ + // 传递字段的值作为参数 + $data[$field] = call_user_func($fun,$data[$field]); + } + } + } + } + } + return $data; + } + + /** + * 返回数据列表 + * @access protected + * @param array $resultSet 数据 + * @param string $type 返回类型 默认为数组 + * @return void + */ + protected function returnResultSet(&$resultSet,$type='') { + foreach ($resultSet as $key=>$data) + $resultSet[$key] = $this->returnResult($data,$type); + return $resultSet; + } + + protected function checkBlobFields(&$data) { + // 检查Blob文件保存字段 + if(!empty($this->blobFields)) { + foreach ($this->blobFields as $field){ + if(isset($data[$field])) { + if(isset($data[$this->getPk()])) + $this->blobValues[$this->name.'/'.$data[$this->getPk()].'_'.$field] = $data[$field]; + else + $this->blobValues[$this->name.'/@?id@_'.$field] = $data[$field]; + unset($data[$field]); + } + } + } + return $data; + } + + /** + * 获取数据集的文本字段 + * @access protected + * @param mixed $resultSet 查询的数据 + * @param string $field 查询的字段 + * @return void + */ + protected function getListBlobFields(&$resultSet,$field='') { + if(!empty($this->blobFields)) { + foreach ($resultSet as $key=>$result){ + $result = $this->getBlobFields($result,$field); + $resultSet[$key] = $result; + } + } + return $resultSet; + } + + /** + * 获取数据的文本字段 + * @access protected + * @param mixed $data 查询的数据 + * @param string $field 查询的字段 + * @return void + */ + protected function getBlobFields(&$data,$field='') { + if(!empty($this->blobFields)) { + $pk = $this->getPk(); + $id = $data[$pk]; + if(empty($field)) { + foreach ($this->blobFields as $field){ + $identify = $this->name.'/'.$id.'_'.$field; + $data[$field] = F($identify); + } + return $data; + }else{ + $identify = $this->name.'/'.$id.'_'.$field; + return F($identify); + } + } + } + + /** + * 保存File方式的字段 + * @access protected + * @param mixed $data 保存的数据 + * @return void + */ + protected function saveBlobFields(&$data) { + if(!empty($this->blobFields)) { + foreach ($this->blobValues as $key=>$val){ + if(strpos($key,'@?id@')) + $key = str_replace('@?id@',$data[$this->getPk()],$key); + F($key,$val); + } + } + } + + /** + * 删除File方式的字段 + * @access protected + * @param mixed $data 保存的数据 + * @param string $field 查询的字段 + * @return void + */ + protected function delBlobFields(&$data,$field='') { + if(!empty($this->blobFields)) { + $pk = $this->getPk(); + $id = $data[$pk]; + if(empty($field)) { + foreach ($this->blobFields as $field){ + $identify = $this->name.'/'.$id.'_'.$field; + F($identify,null); + } + }else{ + $identify = $this->name.'/'.$id.'_'.$field; + F($identify,null); + } + } + } + + /** + * 检查序列化数据字段 + * @access protected + * @param array $data 数据 + * @return array + */ + protected function serializeField(&$data) { + // 检查序列化字段 + if(!empty($this->serializeField)) { + // 定义方式 $this->serializeField = array('ser'=>array('name','email')); + foreach ($this->serializeField as $key=>$val){ + if(empty($data[$key])) { + $serialize = array(); + foreach ($val as $name){ + if(isset($data[$name])) { + $serialize[$name] = $data[$name]; + unset($data[$name]); + } + } + if(!empty($serialize)) { + $data[$key] = serialize($serialize); + } + } + } + } + return $data; + } + + // 检查返回数据的序列化字段 + protected function checkSerializeField(&$result) { + // 检查序列化字段 + if(!empty($this->serializeField)) { + foreach ($this->serializeField as $key=>$val){ + if(isset($result[$key])) { + $serialize = unserialize($result[$key]); + foreach ($serialize as $name=>$value) + $result[$name] = $value; + unset($serialize,$result[$key]); + } + } + } + return $result; + } + + // 检查数据集的序列化字段 + protected function checkListSerializeField(&$resultSet) { + // 检查序列化字段 + if(!empty($this->serializeField)) { + foreach ($this->serializeField as $key=>$val){ + foreach ($resultSet as $k=>$result){ + if(isset($result[$key])) { + $serialize = unserialize($result[$key]); + foreach ($serialize as $name=>$value) + $result[$name] = $value; + unset($serialize,$result[$key]); + $resultSet[$k] = $result; + } + } + } + } + return $resultSet; + } + + /** + * 检查只读字段 + * @access protected + * @param array $data 数据 + * @return array + */ + protected function checkReadonlyField(&$data) { + if(!empty($this->readonlyField)) { + foreach ($this->readonlyField as $key=>$field){ + if(isset($data[$field])) + unset($data[$field]); + } + } + return $data; + } + + /** + * 批处理执行SQL语句 + * 批处理的指令都认为是execute操作 + * @access public + * @param array $sql SQL批处理指令 + * @return boolean + */ + public function patchQuery($sql=array()) { + if(!is_array($sql)) return false; + // 自动启动事务支持 + $this->startTrans(); + try{ + foreach ($sql as $_sql){ + $result = $this->execute($_sql); + if(false === $result) { + // 发生错误自动回滚事务 + $this->rollback(); + return false; + } + } + // 提交事务 + $this->commit(); + } catch (ThinkException $e) { + $this->rollback(); + } + return true; + } + + /** + * 得到分表的的数据表名 + * @access public + * @param array $data 操作的数据 + * @return string + */ + public function getPartitionTableName($data=array()) { + // 对数据表进行分区 + if(isset($data[$this->partition['field']])) { + $field = $data[$this->partition['field']]; + switch($this->partition['type']) { + case 'id': + // 按照id范围分表 + $step = $this->partition['expr']; + $seq = floor($field / $step)+1; + break; + case 'year': + // 按照年份分表 + if(!is_numeric($field)) { + $field = strtotime($field); + } + $seq = date('Y',$field)-$this->partition['expr']+1; + break; + case 'mod': + // 按照id的模数分表 + $seq = ($field % $this->partition['num'])+1; + break; + case 'md5': + // 按照md5的序列分表 + $seq = (ord(substr(md5($field),0,1)) % $this->partition['num'])+1; + break; + default : + if(function_exists($this->partition['type'])) { + // 支持指定函数哈希 + $fun = $this->partition['type']; + $seq = (ord(substr($fun($field),0,1)) % $this->partition['num'])+1; + }else{ + // 按照字段的首字母的值分表 + $seq = (ord($field{0}) % $this->partition['num'])+1; + } + } + return $this->getTableName().'_'.$seq; + }else{ + // 当设置的分表字段不在查询条件或者数据中 + // 进行联合查询,必须设定 partition['num'] + $tableName = array(); + for($i=0;$i<$this->partition['num'];$i++) + $tableName[] = 'SELECT * FROM '.$this->getTableName().'_'.($i+1); + $tableName = '( '.implode(" UNION ",$tableName).') AS '.$this->name; + return $tableName; + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Model/MergeModel.class.php b/ThinkPHP/Library/Think/Model/MergeModel.class.php new file mode 100644 index 0000000..21b32a8 --- /dev/null +++ b/ThinkPHP/Library/Think/Model/MergeModel.class.php @@ -0,0 +1,403 @@ + +// +---------------------------------------------------------------------- +namespace Think\Model; +use Think\Model; +/** + * ThinkPHP 聚合模型扩展 + */ +class MergeModel extends Model { + + protected $modelList = array(); // 包含的模型列表 第一个必须是主表模型 + protected $masterModel = ''; // 主模型 + protected $joinType = 'INNER'; // 聚合模型的查询JOIN类型 + protected $fk = ''; // 外键名 默认为主表名_id + protected $mapFields = array(); // 需要处理的模型映射字段,避免混淆 array( id => 'user.id' ) + + /** + * 架构函数 + * 取得DB类的实例对象 字段检查 + * @access public + * @param string $name 模型名称 + * @param string $tablePrefix 表前缀 + * @param mixed $connection 数据库连接信息 + */ + public function __construct($name='',$tablePrefix='',$connection=''){ + parent::__construct($name,$tablePrefix,$connection); + // 聚合模型的字段信息 + if(empty($this->fields) && !empty($this->modelList)){ + $fields = array(); + foreach($this->modelList as $model){ + // 获取模型的字段信息 + $result = $this->db->getFields(M($model)->getTableName()); + $_fields = array_keys($result); + // $this->mapFields = array_intersect($fields,$_fields); + $fields = array_merge($fields,$_fields); + } + $this->fields = $fields; + } + + // 设置第一个模型为主表模型 + if(empty($this->masterModel) && !empty($this->modelList)){ + $this->masterModel = $this->modelList[0]; + } + // 主表的主键名 + $this->pk = M($this->masterModel)->getPk(); + + // 设置默认外键名 仅支持单一外键 + if(empty($this->fk)){ + $this->fk = strtolower($this->masterModel).'_id'; + } + + } + + /** + * 得到完整的数据表名 + * @access public + * @return string + */ + public function getTableName() { + if(empty($this->trueTableName)) { + $tableName = array(); + $models = $this->modelList; + foreach($models as $model){ + $tableName[] = M($model)->getTableName().' '.$model; + } + $this->trueTableName = implode(',',$tableName); + } + return $this->trueTableName; + } + + /** + * 自动检测数据表信息 + * @access protected + * @return void + */ + protected function _checkTableInfo() {} + + /** + * 新增聚合数据 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @param boolean $replace 是否replace + * @return mixed + */ + public function add($data='',$options=array(),$replace=false){ + if(empty($data)) { + // 没有传递数据,获取当前数据对象的值 + if(!empty($this->data)) { + $data = $this->data; + // 重置数据 + $this->data = array(); + }else{ + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + } + // 启动事务 + $this->startTrans(); + // 写入主表数据 + $result = M($this->masterModel)->strict(false)->add($data); + if($result){ + // 写入外键数据 + $data[$this->fk] = $result; + $models = $this->modelList; + array_shift($models); + // 写入附表数据 + foreach($models as $model){ + $res = M($model)->strict(false)->add($data); + if(!$res){ + $this->rollback(); + return false; + } + } + // 提交事务 + $this->commit(); + }else{ + $this->rollback(); + return false; + } + return $result; + } + + /** + * 对保存到数据库的数据进行处理 + * @access protected + * @param mixed $data 要操作的数据 + * @return boolean + */ + protected function _facade($data) { + + // 检查数据字段合法性 + if(!empty($this->fields)) { + if(!empty($this->options['field'])) { + $fields = $this->options['field']; + unset($this->options['field']); + if(is_string($fields)) { + $fields = explode(',',$fields); + } + }else{ + $fields = $this->fields; + } + foreach ($data as $key=>$val){ + if(!in_array($key,$fields,true)){ + unset($data[$key]); + }elseif(array_key_exists($key,$this->mapFields)){ + // 需要处理映射字段 + $data[$this->mapFields[$key]] = $val; + unset($data[$key]); + } + } + } + + // 安全过滤 + if(!empty($this->options['filter'])) { + $data = array_map($this->options['filter'],$data); + unset($this->options['filter']); + } + $this->_before_write($data); + return $data; + } + + /** + * 保存聚合模型数据 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @return boolean + */ + public function save($data='',$options=array()){ + // 根据主表的主键更新 + if(empty($data)) { + // 没有传递数据,获取当前数据对象的值 + if(!empty($this->data)) { + $data = $this->data; + // 重置数据 + $this->data = array(); + }else{ + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + } + if(empty($data)){ + // 没有数据则不执行 + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + // 如果存在主键数据 则自动作为更新条件 + $pk = $this->pk; + if(isset($data[$pk])) { + $where[$pk] = $data[$pk]; + $options['where'] = $where; + unset($data[$pk]); + } + $options['join'] = ''; + $options = $this->_parseOptions($options); + // 更新操作不使用JOIN + $options['table'] = $this->getTableName(); + + if(is_array($options['where']) && isset($options['where'][$pk])){ + $pkValue = $options['where'][$pk]; + } + if(false === $this->_before_update($data,$options)) { + return false; + } + $result = $this->db->update($data,$options); + if(false !== $result) { + if(isset($pkValue)) $data[$pk] = $pkValue; + $this->_after_update($data,$options); + } + return $result; + } + + /** + * 删除聚合模型数据 + * @access public + * @param mixed $options 表达式 + * @return mixed + */ + public function delete($options=array()){ + $pk = $this->pk; + if(empty($options) && empty($this->options['where'])) { + // 如果删除条件为空 则删除当前数据对象所对应的记录 + if(!empty($this->data) && isset($this->data[$pk])) + return $this->delete($this->data[$pk]); + else + return false; + } + + if(is_numeric($options) || is_string($options)) { + // 根据主键删除记录 + if(strpos($options,',')) { + $where[$pk] = array('IN', $options); + }else{ + $where[$pk] = $options; + } + $options = array(); + $options['where'] = $where; + } + // 分析表达式 + $options['join'] = ''; + $options = $this->_parseOptions($options); + if(empty($options['where'])){ + // 如果条件为空 不进行删除操作 除非设置 1=1 + return false; + } + if(is_array($options['where']) && isset($options['where'][$pk])){ + $pkValue = $options['where'][$pk]; + } + + $options['table'] = implode(',',$this->modelList); + $options['using'] = $this->getTableName(); + if(false === $this->_before_delete($options)) { + return false; + } + $result = $this->db->delete($options); + if(false !== $result) { + $data = array(); + if(isset($pkValue)) $data[$pk] = $pkValue; + $this->_after_delete($data,$options); + } + // 返回删除记录个数 + return $result; + } + + /** + * 表达式过滤方法 + * @access protected + * @param string $options 表达式 + * @return void + */ + protected function _options_filter(&$options) { + if(!isset($options['join'])){ + $models = $this->modelList; + array_shift($models); + foreach($models as $model){ + $options['join'][] = $this->joinType.' JOIN '.M($model)->getTableName().' '.$model.' ON '.$this->masterModel.'.'.$this->pk.' = '.$model.'.'.$this->fk; + } + } + $options['table'] = M($this->masterModel)->getTableName().' '.$this->masterModel; + $options['field'] = $this->checkFields(isset($options['field'])?$options['field']:''); + if(isset($options['group'])) + $options['group'] = $this->checkGroup($options['group']); + if(isset($options['where'])) + $options['where'] = $this->checkCondition($options['where']); + if(isset($options['order'])) + $options['order'] = $this->checkOrder($options['order']); + } + + /** + * 检查条件中的聚合字段 + * @access protected + * @param mixed $data 条件表达式 + * @return array + */ + protected function checkCondition($where) { + if(is_array($where)) { + $view = array(); + foreach($where as $name=>$value){ + if(array_key_exists($name,$this->mapFields)){ + // 需要处理映射字段 + $view[$this->mapFields[$name]] = $value; + unset($where[$name]); + } + } + $where = array_merge($where,$view); + } + return $where; + } + + /** + * 检查Order表达式中的聚合字段 + * @access protected + * @param string $order 字段 + * @return string + */ + protected function checkOrder($order='') { + if(is_string($order) && !empty($order)) { + $orders = explode(',',$order); + $_order = array(); + foreach ($orders as $order){ + $array = explode(' ',trim($order)); + $field = $array[0]; + $sort = isset($array[1])?$array[1]:'ASC'; + if(array_key_exists($field,$this->mapFields)){ + // 需要处理映射字段 + $field = $this->mapFields[$field]; + } + $_order[] = $field.' '.$sort; + } + $order = implode(',',$_order); + } + return $order; + } + + /** + * 检查Group表达式中的聚合字段 + * @access protected + * @param string $group 字段 + * @return string + */ + protected function checkGroup($group='') { + if(!empty($group)) { + $groups = explode(',',$group); + $_group = array(); + foreach ($groups as $field){ + // 解析成聚合字段 + if(array_key_exists($field,$this->mapFields)){ + // 需要处理映射字段 + $field = $this->mapFields[$field]; + } + $_group[] = $field; + } + $group = implode(',',$_group); + } + return $group; + } + + /** + * 检查fields表达式中的聚合字段 + * @access protected + * @param string $fields 字段 + * @return string + */ + protected function checkFields($fields='') { + if(empty($fields) || '*'==$fields ) { + // 获取全部聚合字段 + $fields = $this->fields; + } + if(!is_array($fields)) + $fields = explode(',',$fields); + + // 解析成聚合字段 + $array = array(); + foreach ($fields as $field){ + if(array_key_exists($field,$this->mapFields)){ + // 需要处理映射字段 + $array[] = $this->mapFields[$field].' AS '.$field; + }else{ + $array[] = $field; + } + } + $fields = implode(',',$array); + return $fields; + } + + /** + * 获取数据表字段信息 + * @access public + * @return array + */ + public function getDbFields(){ + return $this->fields; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Model/MongoModel.class.php b/ThinkPHP/Library/Think/Model/MongoModel.class.php new file mode 100644 index 0000000..d1927d7 --- /dev/null +++ b/ThinkPHP/Library/Think/Model/MongoModel.class.php @@ -0,0 +1,422 @@ + +// +---------------------------------------------------------------------- +namespace Think\Model; +use Think\Model; +/** + * MongoModel模型类 + * 实现了ODM和ActiveRecords模式 + */ +class MongoModel extends Model{ + // 主键类型 + const TYPE_OBJECT = 1; + const TYPE_INT = 2; + const TYPE_STRING = 3; + + // 主键名称 + protected $pk = '_id'; + // _id 类型 1 Object 采用MongoId对象 2 Int 整形 支持自动增长 3 String 字符串Hash + protected $_idType = self::TYPE_OBJECT; + // 主键是否自增 + protected $_autoinc = true; + // Mongo默认关闭字段检测 可以动态追加字段 + protected $autoCheckFields = false; + // 链操作方法列表 + protected $methods = array('table','order','auto','filter','validate'); + + /** + * 利用__call方法实现一些特殊的Model方法 + * @access public + * @param string $method 方法名称 + * @param array $args 调用参数 + * @return mixed + */ + public function __call($method,$args) { + if(in_array(strtolower($method),$this->methods,true)) { + // 连贯操作的实现 + $this->options[strtolower($method)] = $args[0]; + return $this; + }elseif(strtolower(substr($method,0,5))=='getby') { + // 根据某个字段获取记录 + $field = parse_name(substr($method,5)); + $where[$field] =$args[0]; + return $this->where($where)->find(); + }elseif(strtolower(substr($method,0,10))=='getfieldby') { + // 根据某个字段获取记录的某个值 + $name = parse_name(substr($method,10)); + $where[$name] =$args[0]; + return $this->where($where)->getField($args[1]); + }else{ + E(__CLASS__.':'.$method.L('_METHOD_NOT_EXIST_')); + return; + } + } + + /** + * 获取字段信息并缓存 主键和自增信息直接配置 + * @access public + * @return void + */ + public function flush() { + // 缓存不存在则查询数据表信息 + $fields = $this->db->getFields(); + if(!$fields) { // 暂时没有数据无法获取字段信息 下次查询 + return false; + } + $this->fields = array_keys($fields); + foreach ($fields as $key=>$val){ + // 记录字段类型 + $type[$key] = $val['type']; + } + // 记录字段类型信息 + if(C('DB_FIELDTYPE_CHECK')) $this->fields['_type'] = $type; + + // 2008-3-7 增加缓存开关控制 + if(C('DB_FIELDS_CACHE')){ + // 永久缓存数据表信息 + $db = $this->dbName?$this->dbName:C('DB_NAME'); + F('_fields/'.$db.'.'.$this->name,$this->fields); + } + } + + // 写入数据前的回调方法 包括新增和更新 + protected function _before_write(&$data) { + $pk = $this->getPk(); + // 根据主键类型处理主键数据 + if(isset($data[$pk]) && $this->_idType == self::TYPE_OBJECT) { + $data[$pk] = new \MongoId($data[$pk]); + } + } + + /** + * count统计 配合where连贯操作 + * @access public + * @return integer + */ + public function count(){ + // 分析表达式 + $options = $this->_parseOptions(); + return $this->db->count($options); + } + + /** + * 获取唯一值 + * @access public + * @return array | false + */ + public function distinct($field, $where=array() ){ + // 分析表达式 + $this->options = $this->_parseOptions(); + $this->options['where'] = array_merge((array)$this->options['where'], $where); + + $command = array( + "distinct" => $this->options['table'], + "key" => $field, + "query" => $this->options['where'] + ); + + $result = $this->command($command); + return isset($result['values']) ? $result['values'] : false; + } + + /** + * 获取下一ID 用于自动增长型 + * @access public + * @param string $pk 字段名 默认为主键 + * @return mixed + */ + public function getMongoNextId($pk=''){ + if(empty($pk)) { + $pk = $this->getPk(); + } + return $this->db->getMongoNextId($pk); + } + + /** + * 新增数据 + * @access public + * @param mixed $data 数据 + * @param array $options 表达式 + * @param boolean $replace 是否replace + * @return mixed + */ + public function add($data='',$options=array(),$replace=false) { + if(empty($data)) { + // 没有传递数据,获取当前数据对象的值 + if(!empty($this->data)) { + $data = $this->data; + // 重置数据 + $this->data = array(); + }else{ + $this->error = L('_DATA_TYPE_INVALID_'); + return false; + } + } + // 分析表达式 + $options = $this->_parseOptions($options); + // 数据处理 + $data = $this->_facade($data); + if(false === $this->_before_insert($data,$options)) { + return false; + } + // 写入数据到数据库 + $result = $this->db->insert($data,$options,$replace); + if(false !== $result ) { + $this->_after_insert($data,$options); + if(isset($data[$this->getPk()])){ + return $data[$this->getPk()]; + } + } + return $result; + } + + // 插入数据前的回调方法 + protected function _before_insert(&$data,$options) { + // 写入数据到数据库 + if($this->_autoinc && $this->_idType== self::TYPE_INT) { // 主键自动增长 + $pk = $this->getPk(); + if(!isset($data[$pk])) { + $data[$pk] = $this->db->getMongoNextId($pk); + } + } + } + + public function clear(){ + return $this->db->clear(); + } + + // 查询成功后的回调方法 + protected function _after_select(&$resultSet,$options) { + array_walk($resultSet,array($this,'checkMongoId')); + } + + /** + * 获取MongoId + * @access protected + * @param array $result 返回数据 + * @return array + */ + protected function checkMongoId(&$result){ + if(is_object($result['_id'])) { + $result['_id'] = $result['_id']->__toString(); + } + return $result; + } + + // 表达式过滤回调方法 + protected function _options_filter(&$options) { + $id = $this->getPk(); + if(isset($options['where'][$id]) && is_scalar($options['where'][$id]) && $this->_idType== self::TYPE_OBJECT) { + $options['where'][$id] = new \MongoId($options['where'][$id]); + } + } + + /** + * 查询数据 + * @access public + * @param mixed $options 表达式参数 + * @return mixed + */ + public function find($options=array()) { + if( is_numeric($options) || is_string($options)) { + $id = $this->getPk(); + $where[$id] = $options; + $options = array(); + $options['where'] = $where; + } + // 分析表达式 + $options = $this->_parseOptions($options); + $result = $this->db->find($options); + if(false === $result) { + return false; + } + if(empty($result)) {// 查询结果为空 + return null; + }else{ + $this->checkMongoId($result); + } + $this->data = $result; + $this->_after_find($this->data,$options); + return $this->data; + } + + /** + * 字段值增长 + * @access public + * @param string $field 字段名 + * @param integer $step 增长值 + * @return boolean + */ + public function setInc($field,$step=1) { + return $this->setField($field,array('inc',$step)); + } + + /** + * 字段值减少 + * @access public + * @param string $field 字段名 + * @param integer $step 减少值 + * @return boolean + */ + public function setDec($field,$step=1) { + return $this->setField($field,array('inc','-'.$step)); + } + + /** + * 获取一条记录的某个字段值 + * @access public + * @param string $field 字段名 + * @param string $spea 字段数据间隔符号 + * @return mixed + */ + public function getField($field,$sepa=null) { + $options['field'] = $field; + $options = $this->_parseOptions($options); + if(strpos($field,',')) { // 多字段 + if(is_numeric($sepa)) {// 限定数量 + $options['limit'] = $sepa; + $sepa = null;// 重置为null 返回数组 + } + $resultSet = $this->db->select($options); + if(!empty($resultSet)) { + $_field = explode(',', $field); + $field = array_keys($resultSet[0]); + $key = array_shift($field); + $key2 = array_shift($field); + $cols = array(); + $count = count($_field); + foreach ($resultSet as $result){ + $name = $result[$key]; + if(2==$count) { + $cols[$name] = $result[$key2]; + }else{ + $cols[$name] = is_null($sepa)?$result:implode($sepa,$result); + } + } + return $cols; + } + }else{ + // 返回数据个数 + if(true !== $sepa) {// 当sepa指定为true的时候 返回所有数据 + $options['limit'] = is_numeric($sepa)?$sepa:1; + } // 查找符合的记录 + $result = $this->db->select($options); + if(!empty($result)) { + if(1==$options['limit']) { + $result = reset($result); + return $result[$field]; + } + foreach ($result as $val){ + $array[] = $val[$field]; + } + return $array; + } + } + return null; + } + + /** + * 执行Mongo指令 + * @access public + * @param array $command 指令 + * @return mixed + */ + public function command($command, $options=array()) { + $options = $this->_parseOptions($options); + return $this->db->command($command, $options); + } + + /** + * 执行MongoCode + * @access public + * @param string $code MongoCode + * @param array $args 参数 + * @return mixed + */ + public function mongoCode($code,$args=array()) { + return $this->db->execute($code,$args); + } + + // 数据库切换后回调方法 + protected function _after_db() { + // 切换Collection + $this->db->switchCollection($this->getTableName(),$this->dbName?$this->dbName:C('db_name')); + } + + /** + * 得到完整的数据表名 Mongo表名不带dbName + * @access public + * @return string + */ + public function getTableName() { + if(empty($this->trueTableName)) { + $tableName = !empty($this->tablePrefix) ? $this->tablePrefix : ''; + if(!empty($this->tableName)) { + $tableName .= $this->tableName; + }else{ + $tableName .= parse_name($this->name); + } + $this->trueTableName = strtolower($tableName); + } + return $this->trueTableName; + } + + /** + * 分组查询 + * @access public + * @return string + */ + public function group($key, $init, $reduce, $option=array()) { + $option = $this->_parseOptions($option); + + //合并查询条件 + if(isset($option['where'])) + $option['condition'] = array_merge((array)$option['condition'], $option['where']); + + return $this->db->group($key, $init, $reduce, $option); + } + + /** + * 返回Mongo运行错误信息 + * @access public + * @return json + */ + public function getLastError(){ + return $this->db->command(array('getLastError'=>1)); + } + + /** + * 返回指定集合的统计信息,包括数据大小、已分配的存储空间和索引的大小 + * @access public + * @return json + */ + public function status(){ + $option = $this->_parseOptions(); + return $this->db->command(array('collStats'=>$option['table'])); + } + + /** + * 取得当前数据库的对象 + * @access public + * @return object + */ + public function getDB(){ + return $this->db->getDB(); + } + + /** + * 取得集合对象,可以进行创建索引等查询 + * @access public + * @return object + */ + public function getCollection(){ + return $this->db->getCollection(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Model/RelationModel.class.php b/ThinkPHP/Library/Think/Model/RelationModel.class.php new file mode 100644 index 0000000..6a3b39e --- /dev/null +++ b/ThinkPHP/Library/Think/Model/RelationModel.class.php @@ -0,0 +1,412 @@ + +// +---------------------------------------------------------------------- +namespace Think\Model; +use Think\Model; +/** + * ThinkPHP关联模型扩展 + */ +class RelationModel extends Model { + + const HAS_ONE = 1; + const BELONGS_TO = 2; + const HAS_MANY = 3; + const MANY_TO_MANY= 4; + + // 关联定义 + protected $_link = array(); + + /** + * 动态方法实现 + * @access public + * @param string $method 方法名称 + * @param array $args 调用参数 + * @return mixed + */ + public function __call($method,$args) { + if(strtolower(substr($method,0,8))=='relation'){ + $type = strtoupper(substr($method,8)); + if(in_array($type,array('ADD','SAVE','DEL'),true)) { + array_unshift($args,$type); + return call_user_func_array(array(&$this, 'opRelation'), $args); + } + }else{ + return parent::__call($method,$args); + } + } + + /** + * 得到关联的数据表名 + * @access public + * @return string + */ + public function getRelationTableName($relation) { + $relationTable = !empty($this->tablePrefix) ? $this->tablePrefix : ''; + $relationTable .= $this->tableName?$this->tableName:$this->name; + $relationTable .= '_'.$relation->getModelName(); + return strtolower($relationTable); + } + + // 查询成功后的回调方法 + protected function _after_find(&$result,$options) { + // 获取关联数据 并附加到结果中 + if(!empty($options['link'])) + $this->getRelation($result,$options['link']); + } + + // 查询数据集成功后的回调方法 + protected function _after_select(&$result,$options) { + // 获取关联数据 并附加到结果中 + if(!empty($options['link'])) + $this->getRelations($result,$options['link']); + } + + // 写入成功后的回调方法 + protected function _after_insert($data,$options) { + // 关联写入 + if(!empty($options['link'])) + $this->opRelation('ADD',$data,$options['link']); + } + + // 更新成功后的回调方法 + protected function _after_update($data,$options) { + // 关联更新 + if(!empty($options['link'])) + $this->opRelation('SAVE',$data,$options['link']); + } + + // 删除成功后的回调方法 + protected function _after_delete($data,$options) { + // 关联删除 + if(!empty($options['link'])) + $this->opRelation('DEL',$data,$options['link']); + } + + /** + * 对保存到数据库的数据进行处理 + * @access protected + * @param mixed $data 要操作的数据 + * @return boolean + */ + protected function _facade($data) { + $this->_before_write($data); + return $data; + } + + /** + * 获取返回数据集的关联记录 + * @access protected + * @param array $resultSet 返回数据 + * @param string|array $name 关联名称 + * @return array + */ + protected function getRelations(&$resultSet,$name='') { + // 获取记录集的主键列表 + foreach($resultSet as $key=>$val) { + $val = $this->getRelation($val,$name); + $resultSet[$key] = $val; + } + return $resultSet; + } + + /** + * 获取返回数据的关联记录 + * @access protected + * @param mixed $result 返回数据 + * @param string|array $name 关联名称 + * @param boolean $return 是否返回关联数据本身 + * @return array + */ + protected function getRelation(&$result,$name='',$return=false) { + if(!empty($this->_link)) { + foreach($this->_link as $key=>$val) { + $mappingName = !empty($val['mapping_name'])?$val['mapping_name']:$key; // 映射名称 + if(empty($name) || true === $name || $mappingName == $name || (is_array($name) && in_array($mappingName,$name))) { + $mappingType = !empty($val['mapping_type'])?$val['mapping_type']:$val; // 关联类型 + $mappingClass = !empty($val['class_name'])?$val['class_name']:$key; // 关联类名 + $mappingFields = !empty($val['mapping_fields'])?$val['mapping_fields']:'*'; // 映射字段 + $mappingCondition = !empty($val['condition'])?$val['condition']:'1=1'; // 关联条件 + $mappingKey =!empty($val['mapping_key'])? $val['mapping_key'] : $this->getPk(); // 关联键名 + if(strtoupper($mappingClass)==strtoupper($this->name)) { + // 自引用关联 获取父键名 + $mappingFk = !empty($val['parent_key'])? $val['parent_key'] : 'parent_id'; + }else{ + $mappingFk = !empty($val['foreign_key'])?$val['foreign_key']:strtolower($this->name).'_id'; // 关联外键 + } + // 获取关联模型对象 + $model = D($mappingClass); + switch($mappingType) { + case self::HAS_ONE: + $pk = $result[$mappingKey]; + $mappingCondition .= " AND {$mappingFk}='{$pk}'"; + $relationData = $model->where($mappingCondition)->field($mappingFields)->find(); + if (!empty($val['relation_deep'])){ + $model->getRelation($relationData,$val['relation_deep']); + } + break; + case self::BELONGS_TO: + if(strtoupper($mappingClass)==strtoupper($this->name)) { + // 自引用关联 获取父键名 + $mappingFk = !empty($val['parent_key'])? $val['parent_key'] : 'parent_id'; + }else{ + $mappingFk = !empty($val['foreign_key'])?$val['foreign_key']:strtolower($model->getModelName()).'_id'; // 关联外键 + } + $fk = $result[$mappingFk]; + $mappingCondition .= " AND {$model->getPk()}='{$fk}'"; + $relationData = $model->where($mappingCondition)->field($mappingFields)->find(); + if (!empty($val['relation_deep'])){ + $model->getRelation($relationData,$val['relation_deep']); + } + break; + case self::HAS_MANY: + $pk = $result[$mappingKey]; + $mappingCondition .= " AND {$mappingFk}='{$pk}'"; + $mappingOrder = !empty($val['mapping_order'])?$val['mapping_order']:''; + $mappingLimit = !empty($val['mapping_limit'])?$val['mapping_limit']:''; + // 延时获取关联记录 + $relationData = $model->where($mappingCondition)->field($mappingFields)->order($mappingOrder)->limit($mappingLimit)->select(); + if (!empty($val['relation_deep'])){ + foreach($relationData as $key=>$data){ + $model->getRelation($data,$val['relation_deep']); + $relationData[$key] = $data; + } + } + break; + case self::MANY_TO_MANY: + $pk = $result[$mappingKey]; + $prefix = $this->tablePrefix; + $mappingCondition = " {$mappingFk}='{$pk}'"; + $mappingOrder = $val['mapping_order']; + $mappingLimit = $val['mapping_limit']; + $mappingRelationFk = $val['relation_foreign_key']?$val['relation_foreign_key']:$model->getModelName().'_id'; + if(isset($val['relation_table'])){ + $mappingRelationTable = preg_replace_callback("/__([A-Z_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $val['relation_table']); + }else{ + $mappingRelationTable = $this->getRelationTableName($model); + } + $sql = "SELECT b.{$mappingFields} FROM {$mappingRelationTable} AS a, ".$model->getTableName()." AS b WHERE a.{$mappingRelationFk} = b.{$model->getPk()} AND a.{$mappingCondition}"; + if(!empty($val['condition'])) { + $sql .= ' AND '.$val['condition']; + } + if(!empty($mappingOrder)) { + $sql .= ' ORDER BY '.$mappingOrder; + } + if(!empty($mappingLimit)) { + $sql .= ' LIMIT '.$mappingLimit; + } + $relationData = $this->query($sql); + if (!empty($val['relation_deep'])){ + foreach($relationData as $key=>$data){ + $model->getRelation($data,$val['relation_deep']); + $relationData[$key] = $data; + } + } + break; + } + if(!$return){ + if(isset($val['as_fields']) && in_array($mappingType,array(self::HAS_ONE,self::BELONGS_TO)) ) { + // 支持直接把关联的字段值映射成数据对象中的某个字段 + // 仅仅支持HAS_ONE BELONGS_TO + $fields = explode(',',$val['as_fields']); + foreach ($fields as $field){ + if(strpos($field,':')) { + list($relationName,$nick) = explode(':',$field); + $result[$nick] = $relationData[$relationName]; + }else{ + $result[$field] = $relationData[$field]; + } + } + }else{ + $result[$mappingName] = $relationData; + } + unset($relationData); + }else{ + return $relationData; + } + } + } + } + return $result; + } + + /** + * 操作关联数据 + * @access protected + * @param string $opType 操作方式 ADD SAVE DEL + * @param mixed $data 数据对象 + * @param string $name 关联名称 + * @return mixed + */ + protected function opRelation($opType,$data='',$name='') { + $result = false; + if(empty($data) && !empty($this->data)){ + $data = $this->data; + }elseif(!is_array($data)){ + // 数据无效返回 + return false; + } + if(!empty($this->_link)) { + // 遍历关联定义 + foreach($this->_link as $key=>$val) { + // 操作制定关联类型 + $mappingName = $val['mapping_name']?$val['mapping_name']:$key; // 映射名称 + if(empty($name) || true === $name || $mappingName == $name || (is_array($name) && in_array($mappingName,$name)) ) { + // 操作制定的关联 + $mappingType = !empty($val['mapping_type'])?$val['mapping_type']:$val; // 关联类型 + $mappingClass = !empty($val['class_name'])?$val['class_name']:$key; // 关联类名 + $mappingKey =!empty($val['mapping_key'])? $val['mapping_key'] : $this->getPk(); // 关联键名 + // 当前数据对象主键值 + $pk = $data[$mappingKey]; + if(strtoupper($mappingClass)==strtoupper($this->name)) { + // 自引用关联 获取父键名 + $mappingFk = !empty($val['parent_key'])? $val['parent_key'] : 'parent_id'; + }else{ + $mappingFk = !empty($val['foreign_key'])?$val['foreign_key']:strtolower($this->name).'_id'; // 关联外键 + } + if(!empty($val['condition'])) { + $mappingCondition = $val['condition']; + }else{ + $mappingCondition = array(); + $mappingCondition[$mappingFk] = $pk; + } + // 获取关联model对象 + $model = D($mappingClass); + $mappingData = isset($data[$mappingName])?$data[$mappingName]:false; + if(!empty($mappingData) || $opType == 'DEL') { + switch($mappingType) { + case self::HAS_ONE: + switch (strtoupper($opType)){ + case 'ADD': // 增加关联数据 + $mappingData[$mappingFk] = $pk; + $result = $model->add($mappingData); + break; + case 'SAVE': // 更新关联数据 + $result = $model->where($mappingCondition)->save($mappingData); + break; + case 'DEL': // 根据外键删除关联数据 + $result = $model->where($mappingCondition)->delete(); + break; + } + break; + case self::BELONGS_TO: + break; + case self::HAS_MANY: + switch (strtoupper($opType)){ + case 'ADD' : // 增加关联数据 + $model->startTrans(); + foreach ($mappingData as $val){ + $val[$mappingFk] = $pk; + $result = $model->add($val); + } + $model->commit(); + break; + case 'SAVE' : // 更新关联数据 + $model->startTrans(); + $pk = $model->getPk(); + foreach ($mappingData as $vo){ + if(isset($vo[$pk])) {// 更新数据 + $mappingCondition = "$pk ={$vo[$pk]}"; + $result = $model->where($mappingCondition)->save($vo); + }else{ // 新增数据 + $vo[$mappingFk] = $data[$mappingKey]; + $result = $model->add($vo); + } + } + $model->commit(); + break; + case 'DEL' : // 删除关联数据 + $result = $model->where($mappingCondition)->delete(); + break; + } + break; + case self::MANY_TO_MANY: + $mappingRelationFk = $val['relation_foreign_key']?$val['relation_foreign_key']:$model->getModelName().'_id';// 关联 + $prefix = $this->tablePrefix; + if(isset($val['relation_table'])){ + $mappingRelationTable = preg_replace_callback("/__([A-Z_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $val['relation_table']); + }else{ + $mappingRelationTable = $this->getRelationTableName($model); + } + if(is_array($mappingData)) { + $ids = array(); + foreach ($mappingData as $vo) + $ids[] = $vo[$mappingKey]; + $relationId = implode(',',$ids); + } + switch (strtoupper($opType)){ + case 'ADD': // 增加关联数据 + if(isset($relationId)) { + $this->startTrans(); + // 插入关联表数据 + $sql = 'INSERT INTO '.$mappingRelationTable.' ('.$mappingFk.','.$mappingRelationFk.') SELECT a.'.$this->getPk().',b.'.$model->getPk().' FROM '.$this->getTableName().' AS a ,'.$model->getTableName()." AS b where a.".$this->getPk().' ='. $pk.' AND b.'.$model->getPk().' IN ('.$relationId.") "; + $result = $model->execute($sql); + if(false !== $result) + // 提交事务 + $this->commit(); + else + // 事务回滚 + $this->rollback(); + } + break; + case 'SAVE': // 更新关联数据 + if(isset($relationId)) { + $this->startTrans(); + // 删除关联表数据 + $this->table($mappingRelationTable)->where($mappingCondition)->delete(); + // 插入关联表数据 + $sql = 'INSERT INTO '.$mappingRelationTable.' ('.$mappingFk.','.$mappingRelationFk.') SELECT a.'.$this->getPk().',b.'.$model->getPk().' FROM '.$this->getTableName().' AS a ,'.$model->getTableName()." AS b where a.".$this->getPk().' ='. $pk.' AND b.'.$model->getPk().' IN ('.$relationId.") "; + $result = $model->execute($sql); + if(false !== $result) + // 提交事务 + $this->commit(); + else + // 事务回滚 + $this->rollback(); + } + break; + case 'DEL': // 根据外键删除中间表关联数据 + $result = $this->table($mappingRelationTable)->where($mappingCondition)->delete(); + break; + } + break; + } + if (!empty($val['relation_deep'])){ + $model->opRelation($opType,$mappingData,$val['relation_deep']); + } + } + } + } + } + return $result; + } + + /** + * 进行关联查询 + * @access public + * @param mixed $name 关联名称 + * @return Model + */ + public function relation($name) { + $this->options['link'] = $name; + return $this; + } + + /** + * 关联数据获取 仅用于查询后 + * @access public + * @param string $name 关联名称 + * @return array + */ + public function relationGet($name) { + if(empty($this->data)) + return false; + return $this->getRelation($this->data,$name,true); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Model/ViewModel.class.php b/ThinkPHP/Library/Think/Model/ViewModel.class.php new file mode 100644 index 0000000..692874e --- /dev/null +++ b/ThinkPHP/Library/Think/Model/ViewModel.class.php @@ -0,0 +1,243 @@ + +// +---------------------------------------------------------------------- +namespace Think\Model; +use Think\Model; +/** + * ThinkPHP视图模型扩展 + */ +class ViewModel extends Model { + + protected $viewFields = array(); + + /** + * 自动检测数据表信息 + * @access protected + * @return void + */ + protected function _checkTableInfo() {} + + /** + * 得到完整的数据表名 + * @access public + * @return string + */ + public function getTableName() { + if(empty($this->trueTableName)) { + $tableName = ''; + foreach ($this->viewFields as $key=>$view){ + // 获取数据表名称 + if(isset($view['_table'])) { // 2011/10/17 添加实际表名定义支持 可以实现同一个表的视图 + $tableName .= $view['_table']; + $prefix = $this->tablePrefix; + $tableName = preg_replace_callback("/__([A-Z_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $tableName); + }else{ + $class = $key.'Model'; + $Model = class_exists($class)?new $class():M($key); + $tableName .= $Model->getTableName(); + } + // 表别名定义 + $tableName .= !empty($view['_as'])?' '.$view['_as']:' '.$key; + // 支持ON 条件定义 + $tableName .= !empty($view['_on'])?' ON '.$view['_on']:''; + // 指定JOIN类型 例如 RIGHT INNER LEFT 下一个表有效 + $type = !empty($view['_type'])?$view['_type']:''; + $tableName .= ' '.strtoupper($type).' JOIN '; + $len = strlen($type.'_JOIN '); + } + $tableName = substr($tableName,0,-$len); + $this->trueTableName = $tableName; + } + return $this->trueTableName; + } + + /** + * 表达式过滤方法 + * @access protected + * @param string $options 表达式 + * @return void + */ + protected function _options_filter(&$options) { + if(isset($options['field'])) + $options['field'] = $this->checkFields($options['field']); + else + $options['field'] = $this->checkFields(); + if(isset($options['group'])) + $options['group'] = $this->checkGroup($options['group']); + if(isset($options['where'])) + $options['where'] = $this->checkCondition($options['where']); + if(isset($options['order'])) + $options['order'] = $this->checkOrder($options['order']); + } + + /** + * 检查是否定义了所有字段 + * @access protected + * @param string $name 模型名称 + * @param array $fields 字段数组 + * @return array + */ + private function _checkFields($name,$fields) { + if(false !== $pos = array_search('*',$fields)) {// 定义所有字段 + $fields = array_merge($fields,M($name)->getDbFields()); + unset($fields[$pos]); + } + return $fields; + } + + /** + * 检查条件中的视图字段 + * @access protected + * @param mixed $data 条件表达式 + * @return array + */ + protected function checkCondition($where) { + if(is_array($where)) { + $view = array(); + // 检查视图字段 + foreach ($this->viewFields as $key=>$val){ + $k = isset($val['_as'])?$val['_as']:$key; + $val = $this->_checkFields($key,$val); + foreach ($where as $name=>$value){ + if(false !== $field = array_search($name,$val,true)) { + // 存在视图字段 + $_key = is_numeric($field)? $k.'.'.$name : $k.'.'.$field; + $view[$_key] = $value; + unset($where[$name]); + } + } + } + $where = array_merge($where,$view); + } + return $where; + } + + /** + * 检查Order表达式中的视图字段 + * @access protected + * @param string $order 字段 + * @return string + */ + protected function checkOrder($order='') { + if(is_string($order) && !empty($order)) { + $orders = explode(',',$order); + $_order = array(); + foreach ($orders as $order){ + $array = explode(' ',trim($order)); + $field = $array[0]; + $sort = isset($array[1])?$array[1]:'ASC'; + // 解析成视图字段 + foreach ($this->viewFields as $name=>$val){ + $k = isset($val['_as'])?$val['_as']:$name; + $val = $this->_checkFields($name,$val); + if(false !== $_field = array_search($field,$val,true)) { + // 存在视图字段 + $field = is_numeric($_field)?$k.'.'.$field:$k.'.'.$_field; + break; + } + } + $_order[] = $field.' '.$sort; + } + $order = implode(',',$_order); + } + return $order; + } + + /** + * 检查Group表达式中的视图字段 + * @access protected + * @param string $group 字段 + * @return string + */ + protected function checkGroup($group='') { + if(!empty($group)) { + $groups = explode(',',$group); + $_group = array(); + foreach ($groups as $field){ + // 解析成视图字段 + foreach ($this->viewFields as $name=>$val){ + $k = isset($val['_as'])?$val['_as']:$name; + $val = $this->_checkFields($name,$val); + if(false !== $_field = array_search($field,$val,true)) { + // 存在视图字段 + $field = is_numeric($_field)?$k.'.'.$field:$k.'.'.$_field; + break; + } + } + $_group[] = $field; + } + $group = implode(',',$_group); + } + return $group; + } + + /** + * 检查fields表达式中的视图字段 + * @access protected + * @param string $fields 字段 + * @return string + */ + protected function checkFields($fields='') { + if(empty($fields) || '*'==$fields ) { + // 获取全部视图字段 + $fields = array(); + foreach ($this->viewFields as $name=>$val){ + $k = isset($val['_as'])?$val['_as']:$name; + $val = $this->_checkFields($name,$val); + foreach ($val as $key=>$field){ + if(is_numeric($key)) { + $fields[] = $k.'.'.$field.' AS '.$field; + }elseif('_' != substr($key,0,1)) { + // 以_开头的为特殊定义 + if( false !== strpos($key,'*') || false !== strpos($key,'(') || false !== strpos($key,'.')) { + //如果包含* 或者 使用了sql方法 则不再添加前面的表名 + $fields[] = $key.' AS '.$field; + }else{ + $fields[] = $k.'.'.$key.' AS '.$field; + } + } + } + } + $fields = implode(',',$fields); + }else{ + if(!is_array($fields)) + $fields = explode(',',$fields); + // 解析成视图字段 + $array = array(); + foreach ($fields as $key=>$field){ + if(strpos($field,'(') || strpos(strtolower($field),' as ')){ + // 使用了函数或者别名 + $array[] = $field; + unset($fields[$key]); + } + } + foreach ($this->viewFields as $name=>$val){ + $k = isset($val['_as'])?$val['_as']:$name; + $val = $this->_checkFields($name,$val); + foreach ($fields as $key=>$field){ + if(false !== $_field = array_search($field,$val,true)) { + // 存在视图字段 + if(is_numeric($_field)) { + $array[] = $k.'.'.$field.' AS '.$field; + }elseif('_' != substr($_field,0,1)){ + if( false !== strpos($_field,'*') || false !== strpos($_field,'(') || false !== strpos($_field,'.')) + //如果包含* 或者 使用了sql方法 则不再添加前面的表名 + $array[] = $_field.' AS '.$field; + else + $array[] = $k.'.'.$_field.' AS '.$field; + } + } + } + } + $fields = implode(',',$array); + } + return $fields; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Page.class.php b/ThinkPHP/Library/Think/Page.class.php new file mode 100644 index 0000000..8a57cb6 --- /dev/null +++ b/ThinkPHP/Library/Think/Page.class.php @@ -0,0 +1,145 @@ + +// +---------------------------------------------------------------------- +namespace Think; + +class Page{ + public $firstRow; // 起始行数 + public $listRows; // 列表每页显示行数 + public $parameter; // 分页跳转时要带的参数 + public $totalRows; // 总行数 + public $totalPages; // 分页总页面数 + public $rollPage = 11;// 分页栏每页显示的页数 + public $lastSuffix = true; // 最后一页是否显示总页数 + + private $p = 'p'; //分页参数名 + private $url = ''; //当前链接URL + private $nowPage = 1; + + // 分页显示定制 + private $config = array( + 'header' => '共 %TOTAL_ROW% 条记录', + 'prev' => '<<', + 'next' => '>>', + 'first' => '1...', + 'last' => '...%TOTAL_PAGE%', + 'theme' => '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%', + ); + + /** + * 架构函数 + * @param array $totalRows 总的记录数 + * @param array $listRows 每页显示记录数 + * @param array $parameter 分页跳转的参数 + */ + public function __construct($totalRows, $listRows=20, $parameter = array()) { + C('VAR_PAGE') && $this->p = C('VAR_PAGE'); //设置分页参数名称 + /* 基础设置 */ + $this->totalRows = $totalRows; //设置总记录数 + $this->listRows = $listRows; //设置每页显示行数 + $this->parameter = empty($parameter) ? $_GET : $parameter; + $this->nowPage = empty($_GET[$this->p]) ? 1 : intval($_GET[$this->p]); + $this->nowPage = $this->nowPage>0 ? $this->nowPage : 1; + $this->firstRow = $this->listRows * ($this->nowPage - 1); + } + + /** + * 定制分页链接设置 + * @param string $name 设置名称 + * @param string $value 设置值 + */ + public function setConfig($name,$value) { + if(isset($this->config[$name])) { + $this->config[$name] = $value; + } + } + + /** + * 生成链接URL + * @param integer $page 页码 + * @return string + */ + private function url($page){ + return str_replace(urlencode('[PAGE]'), $page, $this->url); + } + + /** + * 组装分页链接 + * @return string + */ + public function show() { + if(0 == $this->totalRows) return ''; + + /* 生成URL */ + $this->parameter[$this->p] = '[PAGE]'; + $this->url = U(ACTION_NAME, $this->parameter); + /* 计算分页信息 */ + $this->totalPages = ceil($this->totalRows / $this->listRows); //总页数 + if(!empty($this->totalPages) && $this->nowPage > $this->totalPages) { + $this->nowPage = $this->totalPages; + } + + /* 计算分页临时变量 */ + $now_cool_page = $this->rollPage/2; + $now_cool_page_ceil = ceil($now_cool_page); + $this->lastSuffix && $this->config['last'] = $this->totalPages; + + //上一页 + $up_row = $this->nowPage - 1; + $up_page = $up_row > 0 ? '' : ''; + + //下一页 + $down_row = $this->nowPage + 1; + $down_page = ($down_row <= $this->totalPages) ? '' : ''; + + //第一页 + $the_first = ''; + if($this->totalPages > $this->rollPage && ($this->nowPage - $now_cool_page) >= 1){ + $the_first = '' . $this->config['first'] . ''; + } + + //最后一页 + $the_end = ''; + if($this->totalPages > $this->rollPage && ($this->nowPage + $now_cool_page) < $this->totalPages){ + $the_end = '' . $this->config['last'] . ''; + } + + //数字连接 + $link_page = ""; + for($i = 1; $i <= $this->rollPage; $i++){ + if(($this->nowPage - $now_cool_page) <= 0 ){ + $page = $i; + }elseif(($this->nowPage + $now_cool_page - 1) >= $this->totalPages){ + $page = $this->totalPages - $this->rollPage + $i; + }else{ + $page = $this->nowPage - $now_cool_page_ceil + $i; + } + if($page > 0 && $page != $this->nowPage){ + + if($page <= $this->totalPages){ + $link_page .= '' . $page . ''; + }else{ + break; + } + }else{ + if($page > 0 && $this->totalPages != 1){ + $link_page .= '' . $page . ''; + } + } + } + + //替换分页内容 + $page_str = str_replace( + array('%HEADER%', '%NOW_PAGE%', '%UP_PAGE%', '%DOWN_PAGE%', '%FIRST%', '%LINK_PAGE%', '%END%', '%TOTAL_ROW%', '%TOTAL_PAGE%'), + array($this->config['header'], $this->nowPage, $up_page, $down_page, $the_first, $link_page, $the_end, $this->totalRows, $this->totalPages), + $this->config['theme']); + return "
{$page_str}
"; + } +} diff --git a/ThinkPHP/Library/Think/Route.class.php b/ThinkPHP/Library/Think/Route.class.php new file mode 100644 index 0000000..c1bf8a5 --- /dev/null +++ b/ThinkPHP/Library/Think/Route.class.php @@ -0,0 +1,316 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP路由解析类 + */ +class Route { + + // 路由检测 + public static function check(){ + $depr = C('URL_PATHINFO_DEPR'); + $regx = preg_replace('/\.'.__EXT__.'$/i','',trim($_SERVER['PATH_INFO'],$depr)); + // 分隔符替换 确保路由定义使用统一的分隔符 + if('/' != $depr){ + $regx = str_replace($depr,'/',$regx); + } + // URL映射定义(静态路由) + $maps = C('URL_MAP_RULES'); + if(isset($maps[$regx])) { + $var = self::parseUrl($maps[$regx]); + $_GET = array_merge($var, $_GET); + return true; + } + // 动态路由处理 + $routes = C('URL_ROUTE_RULES'); + if(!empty($routes)) { + foreach ($routes as $rule=>$route){ + if(is_numeric($rule)){ + // 支持 array('rule','adddress',...) 定义路由 + $rule = array_shift($route); + } + if(is_array($route) && isset($route[2])){ + // 路由参数 + $options = $route[2]; + if(isset($options['ext']) && __EXT__ != $options['ext']){ + // URL后缀检测 + continue; + } + if(isset($options['method']) && REQUEST_METHOD != strtoupper($options['method'])){ + // 请求类型检测 + continue; + } + // 自定义检测 + if(!empty($options['callback']) && is_callable($options['callback'])) { + if(false === call_user_func($options['callback'])) { + continue; + } + } + } + if(0===strpos($rule,'/') && preg_match($rule,$regx,$matches)) { // 正则路由 + if($route instanceof \Closure) { + // 执行闭包 + $result = self::invokeRegx($route, $matches); + // 如果返回布尔值 则继续执行 + return is_bool($result) ? $result : exit; + }else{ + return self::parseRegex($matches,$route,$regx); + } + }else{ // 规则路由 + $len1 = substr_count($regx,'/'); + $len2 = substr_count($rule,'/'); + if($len1>=$len2 || strpos($rule,'[')) { + if('$' == substr($rule,-1,1)) {// 完整匹配 + if($len1 != $len2) { + continue; + }else{ + $rule = substr($rule,0,-1); + } + } + $match = self::checkUrlMatch($regx,$rule); + if(false !== $match) { + if($route instanceof \Closure) { + // 执行闭包 + $result = self::invokeRule($route, $match); + // 如果返回布尔值 则继续执行 + return is_bool($result) ? $result : exit; + }else{ + return self::parseRule($rule,$route,$regx); + } + } + } + } + } + } + return false; + } + + // 检测URL和规则路由是否匹配 + private static function checkUrlMatch($regx,$rule) { + $m1 = explode('/',$regx); + $m2 = explode('/',$rule); + $var = array(); + foreach ($m2 as $key=>$val){ + if(0 === strpos($val,'[:')){ + $val = substr($val,1,-1); + } + + if(':' == substr($val,0,1)) {// 动态变量 + if($pos = strpos($val,'|')){ + // 使用函数过滤 + $val = substr($val,1,$pos-1); + } + if(strpos($val,'\\')) { + $type = substr($val,-1); + if('d'==$type) { + if(isset($m1[$key]) && !is_numeric($m1[$key])) + return false; + } + $name = substr($val, 1, -2); + }elseif($pos = strpos($val,'^')){ + $array = explode('-',substr(strstr($val,'^'),1)); + if(in_array($m1[$key],$array)) { + return false; + } + $name = substr($val, 1, $pos - 1); + }else{ + $name = substr($val, 1); + } + $var[$name] = isset($m1[$key])?$m1[$key]:''; + }elseif(0 !== strcasecmp($val,$m1[$key])){ + return false; + } + } + // 成功匹配后返回URL中的动态变量数组 + return $var; + } + + // 解析规范的路由地址 + // 地址格式 [控制器/操作?]参数1=值1&参数2=值2... + private static function parseUrl($url) { + $var = array(); + if(false !== strpos($url,'?')) { // [控制器/操作?]参数1=值1&参数2=值2... + $info = parse_url($url); + $path = explode('/',$info['path']); + parse_str($info['query'],$var); + }elseif(strpos($url,'/')){ // [控制器/操作] + $path = explode('/',$url); + }else{ // 参数1=值1&参数2=值2... + parse_str($url,$var); + } + if(isset($path)) { + $var[C('VAR_ACTION')] = array_pop($path); + if(!empty($path)) { + $var[C('VAR_CONTROLLER')] = array_pop($path); + } + if(!empty($path)) { + $var[C('VAR_MODULE')] = array_pop($path); + } + } + return $var; + } + + // 解析规则路由 + // '路由规则'=>'[控制器/操作]?额外参数1=值1&额外参数2=值2...' + // '路由规则'=>array('[控制器/操作]','额外参数1=值1&额外参数2=值2...') + // '路由规则'=>'外部地址' + // '路由规则'=>array('外部地址','重定向代码') + // 路由规则中 :开头 表示动态变量 + // 外部地址中可以用动态变量 采用 :1 :2 的方式 + // 'news/:month/:day/:id'=>array('News/read?cate=1','status=1'), + // 'new/:id'=>array('/new.php?id=:1',301), 重定向 + private static function parseRule($rule,$route,$regx) { + // 获取路由地址规则 + $url = is_array($route)?$route[0]:$route; + // 获取URL地址中的参数 + $paths = explode('/',$regx); + // 解析路由规则 + $matches = array(); + $rule = explode('/',$rule); + foreach ($rule as $item){ + $fun = ''; + if(0 === strpos($item,'[:')){ + $item = substr($item,1,-1); + } + if(0===strpos($item,':')) { // 动态变量获取 + if($pos = strpos($item,'|')){ + // 支持函数过滤 + $fun = substr($item,$pos+1); + $item = substr($item,0,$pos); + } + if($pos = strpos($item,'^') ) { + $var = substr($item,1,$pos-1); + }elseif(strpos($item,'\\')){ + $var = substr($item,1,-2); + }else{ + $var = substr($item,1); + } + $matches[$var] = !empty($fun)? $fun(array_shift($paths)) : array_shift($paths); + }else{ // 过滤URL中的静态变量 + array_shift($paths); + } + } + + if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转 + if(strpos($url,':')) { // 传递动态参数 + $values = array_values($matches); + $url = preg_replace_callback('/:(\d+)/', function($match) use($values){ return $values[$match[1] - 1]; }, $url); + } + header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); + exit; + }else{ + // 解析路由地址 + $var = self::parseUrl($url); + // 解析路由地址里面的动态参数 + $values = array_values($matches); + foreach ($var as $key=>$val){ + if(0===strpos($val,':')) { + $var[$key] = $values[substr($val,1)-1]; + } + } + $var = array_merge($matches,$var); + // 解析剩余的URL参数 + if(!empty($paths)) { + preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){ $var[strtolower($match[1])]=strip_tags($match[2]);}, implode('/',$paths)); + } + // 解析路由自动传入参数 + if(is_array($route) && isset($route[1])) { + if(is_array($route[1])){ + $params = $route[1]; + }else{ + parse_str($route[1],$params); + } + $var = array_merge($var,$params); + } + $_GET = array_merge($var,$_GET); + } + return true; + } + + // 解析正则路由 + // '路由正则'=>'[控制器/操作]?参数1=值1&参数2=值2...' + // '路由正则'=>array('[控制器/操作]?参数1=值1&参数2=值2...','额外参数1=值1&额外参数2=值2...') + // '路由正则'=>'外部地址' + // '路由正则'=>array('外部地址','重定向代码') + // 参数值和外部地址中可以用动态变量 采用 :1 :2 的方式 + // '/new\/(\d+)\/(\d+)/'=>array('News/read?id=:1&page=:2&cate=1','status=1'), + // '/new\/(\d+)/'=>array('/new.php?id=:1&page=:2&status=1','301'), 重定向 + private static function parseRegex($matches,$route,$regx) { + // 获取路由地址规则 + $url = is_array($route)?$route[0]:$route; + $url = preg_replace_callback('/:(\d+)/', function($match) use($matches){return $matches[$match[1]];}, $url); + if(0=== strpos($url,'/') || 0===strpos($url,'http')) { // 路由重定向跳转 + header("Location: $url", true,(is_array($route) && isset($route[1]))?$route[1]:301); + exit; + }else{ + // 解析路由地址 + $var = self::parseUrl($url); + // 处理函数 + foreach($var as $key=>$val){ + if(strpos($val,'|')){ + list($val,$fun) = explode('|',$val); + $var[$key] = $fun($val); + } + } + // 解析剩余的URL参数 + $regx = substr_replace($regx,'',0,strlen($matches[0])); + if($regx) { + preg_replace_callback('/(\w+)\/([^\/]+)/', function($match) use(&$var){ + $var[strtolower($match[1])] = strip_tags($match[2]); + }, $regx); + } + // 解析路由自动传入参数 + if(is_array($route) && isset($route[1])) { + if(is_array($route[1])){ + $params = $route[1]; + }else{ + parse_str($route[1],$params); + } + $var = array_merge($var,$params); + } + $_GET = array_merge($var,$_GET); + } + return true; + } + + // 执行正则匹配下的闭包方法 支持参数调用 + static private function invokeRegx($closure, $var = array()) { + $reflect = new \ReflectionFunction($closure); + $params = $reflect->getParameters(); + $args = array(); + array_shift($var); + foreach ($params as $param){ + if(!empty($var)) { + $args[] = array_shift($var); + }elseif($param->isDefaultValueAvailable()){ + $args[] = $param->getDefaultValue(); + } + } + return $reflect->invokeArgs($args); + } + + // 执行规则匹配下的闭包方法 支持参数调用 + static private function invokeRule($closure, $var = array()) { + $reflect = new \ReflectionFunction($closure); + $params = $reflect->getParameters(); + $args = array(); + foreach ($params as $param){ + $name = $param->getName(); + if(isset($var[$name])) { + $args[] = $var[$name]; + }elseif($param->isDefaultValueAvailable()){ + $args[] = $param->getDefaultValue(); + } + } + return $reflect->invokeArgs($args); + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Session/Driver/Db.class.php b/ThinkPHP/Library/Think/Session/Driver/Db.class.php new file mode 100644 index 0000000..76ab3be --- /dev/null +++ b/ThinkPHP/Library/Think/Session/Driver/Db.class.php @@ -0,0 +1,173 @@ + +// +---------------------------------------------------------------------- +namespace Think\Session\Driver; +/** + * 数据库方式Session驱动 + * CREATE TABLE think_session ( + * session_id varchar(255) NOT NULL, + * session_expire int(11) NOT NULL, + * session_data blob, + * UNIQUE KEY `session_id` (`session_id`) + * ); + */ +class Db { + + /** + * Session有效时间 + */ + protected $lifeTime = ''; + + /** + * session保存的数据库名 + */ + protected $sessionTable = ''; + + /** + * 数据库句柄 + */ + protected $hander = array(); + + /** + * 打开Session + * @access public + * @param string $savePath + * @param mixed $sessName + */ + public function open($savePath, $sessName) { + $this->lifeTime = C('SESSION_EXPIRE')?C('SESSION_EXPIRE'):ini_get('session.gc_maxlifetime'); + $this->sessionTable = C('SESSION_TABLE')?C('SESSION_TABLE'):C("DB_PREFIX")."session"; + //分布式数据库 + $host = explode(',',C('DB_HOST')); + $port = explode(',',C('DB_PORT')); + $name = explode(',',C('DB_NAME')); + $user = explode(',',C('DB_USER')); + $pwd = explode(',',C('DB_PWD')); + if(1 == C('DB_DEPLOY_TYPE')){ + //读写分离 + if(C('DB_RW_SEPARATE')){ + $w = floor(mt_rand(0,C('DB_MASTER_NUM')-1)); + if(is_numeric(C('DB_SLAVE_NO'))){//指定服务器读 + $r = C('DB_SLAVE_NO'); + }else{ + $r = floor(mt_rand(C('DB_MASTER_NUM'),count($host)-1)); + } + //主数据库链接 + $hander = mysql_connect( + $host[$w].(isset($port[$w])?':'.$port[$w]:':'.$port[0]), + isset($user[$w])?$user[$w]:$user[0], + isset($pwd[$w])?$pwd[$w]:$pwd[0] + ); + $dbSel = mysql_select_db( + isset($name[$w])?$name[$w]:$name[0] + ,$hander); + if(!$hander || !$dbSel) + return false; + $this->hander[0] = $hander; + //从数据库链接 + $hander = mysql_connect( + $host[$r].(isset($port[$r])?':'.$port[$r]:':'.$port[0]), + isset($user[$r])?$user[$r]:$user[0], + isset($pwd[$r])?$pwd[$r]:$pwd[0] + ); + $dbSel = mysql_select_db( + isset($name[$r])?$name[$r]:$name[0] + ,$hander); + if(!$hander || !$dbSel) + return false; + $this->hander[1] = $hander; + return true; + } + } + //从数据库链接 + $r = floor(mt_rand(0,count($host)-1)); + $hander = mysql_connect( + $host[$r].(isset($port[$r])?':'.$port[$r]:':'.$port[0]), + isset($user[$r])?$user[$r]:$user[0], + isset($pwd[$r])?$pwd[$r]:$pwd[0] + ); + $dbSel = mysql_select_db( + isset($name[$r])?$name[$r]:$name[0] + ,$hander); + if(!$hander || !$dbSel) + return false; + $this->hander = $hander; + return true; + } + + /** + * 关闭Session + * @access public + */ + public function close() { + if(is_array($this->hander)){ + $this->gc($this->lifeTime); + return (mysql_close($this->hander[0]) && mysql_close($this->hander[1])); + } + $this->gc($this->lifeTime); + return mysql_close($this->hander); + } + + /** + * 读取Session + * @access public + * @param string $sessID + */ + public function read($sessID) { + $hander = is_array($this->hander)?$this->hander[1]:$this->hander; + $res = mysql_query('SELECT session_data AS data FROM '.$this->sessionTable." WHERE session_id = '$sessID' AND session_expire >".time(),$hander); + if($res) { + $row = mysql_fetch_assoc($res); + return $row['data']; + } + return ""; + } + + /** + * 写入Session + * @access public + * @param string $sessID + * @param String $sessData + */ + public function write($sessID,$sessData) { + $hander = is_array($this->hander)?$this->hander[0]:$this->hander; + $expire = time() + $this->lifeTime; + $sessData = addslashes($sessData); + mysql_query('REPLACE INTO '.$this->sessionTable." ( session_id, session_expire, session_data) VALUES( '$sessID', '$expire', '$sessData')",$hander); + if(mysql_affected_rows($hander)) + return true; + return false; + } + + /** + * 删除Session + * @access public + * @param string $sessID + */ + public function destroy($sessID) { + $hander = is_array($this->hander)?$this->hander[0]:$this->hander; + mysql_query('DELETE FROM '.$this->sessionTable." WHERE session_id = '$sessID'",$hander); + if(mysql_affected_rows($hander)) + return true; + return false; + } + + /** + * Session 垃圾回收 + * @access public + * @param string $sessMaxLifeTime + */ + public function gc($sessMaxLifeTime) { + $hander = is_array($this->hander)?$this->hander[0]:$this->hander; + mysql_query('DELETE FROM '.$this->sessionTable.' WHERE session_expire < '.time(),$hander); + return mysql_affected_rows($hander); + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Session/Driver/Memcache.class.php b/ThinkPHP/Library/Think/Session/Driver/Memcache.class.php new file mode 100644 index 0000000..4c80bbe --- /dev/null +++ b/ThinkPHP/Library/Think/Session/Driver/Memcache.class.php @@ -0,0 +1,79 @@ +lifeTime = C('SESSION_EXPIRE') ? C('SESSION_EXPIRE') : $this->lifeTime; + // $this->sessionName = $sessName; + $options = array( + 'timeout' => C('SESSION_TIMEOUT') ? C('SESSION_TIMEOUT') : 1, + 'persistent' => C('SESSION_PERSISTENT') ? C('SESSION_PERSISTENT') : 0 + ); + $this->handle = new \Memcache; + $hosts = explode(',', C('MEMCACHE_HOST')); + $ports = explode(',', C('MEMCACHE_PORT')); + foreach ($hosts as $i=>$host) { + $port = isset($ports[$i]) ? $ports[$i] : $ports[0]; + $this->handle->addServer($host, $port, true, 1, $options['timeout']); + } + return true; + } + + /** + * 关闭Session + * @access public + */ + public function close() { + $this->gc(ini_get('session.gc_maxlifetime')); + $this->handle->close(); + $this->handle = null; + return true; + } + + /** + * 读取Session + * @access public + * @param string $sessID + */ + public function read($sessID) { + return $this->handle->get($this->sessionName.$sessID); + } + + /** + * 写入Session + * @access public + * @param string $sessID + * @param String $sessData + */ + public function write($sessID, $sessData) { + return $this->handle->set($this->sessionName.$sessID, $sessData, 0, $this->lifeTime); + } + + /** + * 删除Session + * @access public + * @param string $sessID + */ + public function destroy($sessID) { + return $this->handle->delete($this->sessionName.$sessID); + } + + /** + * Session 垃圾回收 + * @access public + * @param string $sessMaxLifeTime + */ + public function gc($sessMaxLifeTime) { + return true; + } +} diff --git a/ThinkPHP/Library/Think/Session/Driver/Mysqli.class.php b/ThinkPHP/Library/Think/Session/Driver/Mysqli.class.php new file mode 100644 index 0000000..b29ec2f --- /dev/null +++ b/ThinkPHP/Library/Think/Session/Driver/Mysqli.class.php @@ -0,0 +1,184 @@ + liu21st +// +---------------------------------------------------------------------- +// | change mysql to mysqli 解决php7没有mysql扩展时数据库存放session无法操作的问题 +// +---------------------------------------------------------------------- +namespace Think\Session\Driver; +/** + * 数据库方式Session驱动 + * CREATE TABLE think_session ( + * session_id varchar(255) NOT NULL, + * session_expire int(11) NOT NULL, + * session_data blob, + * UNIQUE KEY `session_id` (`session_id`) + * ); + */ +class Mysqli +{ + + /** + * Session有效时间 + */ + protected $lifeTime = ''; + + /** + * session保存的数据库名 + */ + protected $sessionTable = ''; + + /** + * 数据库句柄 + */ + protected $hander = array(); + + /** + * 打开Session + * @access public + * @param string $savePath + * @param mixed $sessName + */ + public function open($savePath, $sessName) + { + $this->lifeTime = C('SESSION_EXPIRE') ? C('SESSION_EXPIRE') : ini_get('session.gc_maxlifetime'); + $this->sessionTable = C('SESSION_TABLE') ? C('SESSION_TABLE') : C("DB_PREFIX") . "session"; + //分布式数据库 + $host = explode(',', C('DB_HOST')); + $port = explode(',', C('DB_PORT')); + $name = explode(',', C('DB_NAME')); + $user = explode(',', C('DB_USER')); + $pwd = explode(',', C('DB_PWD')); + if (1 == C('DB_DEPLOY_TYPE')) { + //读写分离 + if (C('DB_RW_SEPARATE')) { + $w = floor(mt_rand(0, C('DB_MASTER_NUM') - 1)); + if (is_numeric(C('DB_SLAVE_NO'))) {//指定服务器读 + $r = C('DB_SLAVE_NO'); + } else { + $r = floor(mt_rand(C('DB_MASTER_NUM'), count($host) - 1)); + } + //主数据库链接 + $hander = mysqli_connect( + $host[$w] . (isset($port[$w]) ? ':' . $port[$w] : ':' . $port[0]), + isset($user[$w]) ? $user[$w] : $user[0], + isset($pwd[$w]) ? $pwd[$w] : $pwd[0] + ); + $dbSel = mysqli_select_db( + $hander, + isset($name[$w]) ? $name[$w] : $name[0] + ); + if (!$hander || !$dbSel) + return false; + $this->hander[0] = $hander; + //从数据库链接 + $hander = mysqli_connect( + $host[$r] . (isset($port[$r]) ? ':' . $port[$r] : ':' . $port[0]), + isset($user[$r]) ? $user[$r] : $user[0], + isset($pwd[$r]) ? $pwd[$r] : $pwd[0] + ); + $dbSel = mysqli_select_db( + $hander, + isset($name[$r]) ? $name[$r] : $name[0] + ); + if (!$hander || !$dbSel) + return false; + $this->hander[1] = $hander; + return true; + } + } + //从数据库链接 + $r = floor(mt_rand(0, count($host) - 1)); + $hander = mysqli_connect( + $host[$r] . (isset($port[$r]) ? ':' . $port[$r] : ':' . $port[0]), + isset($user[$r]) ? $user[$r] : $user[0], + isset($pwd[$r]) ? $pwd[$r] : $pwd[0] + ); + $dbSel = mysqli_select_db( + $hander, + isset($name[$r]) ? $name[$r] : $name[0] + ); + if (!$hander || !$dbSel) + return false; + $this->hander = $hander; + return true; + } + + /** + * 关闭Session + * @access public + */ + public function close() + { + if (is_array($this->hander)) { + $this->gc($this->lifeTime); + return (mysqli_close($this->hander[0]) && mysqli_close($this->hander[1])); + } + $this->gc($this->lifeTime); + return mysqli_close($this->hander); + } + + /** + * 读取Session + * @access public + * @param string $sessID + */ + public function read($sessID) + { + $hander = is_array($this->hander) ? $this->hander[1] : $this->hander; + $res = mysqli_query($hander, "SELECT session_data AS data FROM " . $this->sessionTable . " WHERE session_id = '$sessID' AND session_expire >" . time()); + if ($res) { + $row = mysqli_fetch_assoc($res); + return $row['data']; + } + return ""; + } + + /** + * 写入Session + * @access public + * @param string $sessID + * @param String $sessData + */ + public function write($sessID, $sessData) + { + $hander = is_array($this->hander) ? $this->hander[0] : $this->hander; + $expire = time() + $this->lifeTime; + mysqli_query($hander, "REPLACE INTO " . $this->sessionTable . " ( session_id, session_expire, session_data) VALUES( '$sessID', '$expire', '$sessData')"); + if (mysqli_affected_rows($hander)) + return true; + return false; + } + + /** + * 删除Session + * @access public + * @param string $sessID + */ + public function destroy($sessID) + { + $hander = is_array($this->hander) ? $this->hander[0] : $this->hander; + mysqli_query($hander, "DELETE FROM " . $this->sessionTable . " WHERE session_id = '$sessID'"); + if (mysqli_affected_rows($hander)) + return true; + return false; + } + + /** + * Session 垃圾回收 + * @access public + * @param string $sessMaxLifeTime + */ + public function gc($sessMaxLifeTime) + { + $hander = is_array($this->hander) ? $this->hander[0] : $this->hander; + mysqli_query($hander, "DELETE FROM " . $this->sessionTable . " WHERE session_expire < " . time()); + return mysqli_affected_rows($hander); + } + +} diff --git a/ThinkPHP/Library/Think/Storage.class.php b/ThinkPHP/Library/Think/Storage.class.php new file mode 100644 index 0000000..653e136 --- /dev/null +++ b/ThinkPHP/Library/Think/Storage.class.php @@ -0,0 +1,40 @@ + +// +---------------------------------------------------------------------- +namespace Think; +// 分布式文件存储类 +class Storage { + + /** + * 操作句柄 + * @var string + * @access protected + */ + static protected $handler ; + + /** + * 连接分布式文件系统 + * @access public + * @param string $type 文件类型 + * @param array $options 配置数组 + * @return void + */ + static public function connect($type='File',$options=array()) { + $class = 'Think\\Storage\\Driver\\'.ucwords($type); + self::$handler = new $class($options); + } + + static public function __callstatic($method,$args){ + //调用缓存驱动的方法 + if(method_exists(self::$handler, $method)){ + return call_user_func_array(array(self::$handler,$method), $args); + } + } +} diff --git a/ThinkPHP/Library/Think/Storage/Driver/File.class.php b/ThinkPHP/Library/Think/Storage/Driver/File.class.php new file mode 100644 index 0000000..ea9d925 --- /dev/null +++ b/ThinkPHP/Library/Think/Storage/Driver/File.class.php @@ -0,0 +1,123 @@ + +// +---------------------------------------------------------------------- +namespace Think\Storage\Driver; +use Think\Storage; +// 本地文件写入存储类 +class File extends Storage{ + + private $contents=array(); + + /** + * 架构函数 + * @access public + */ + public function __construct() { + } + + /** + * 文件内容读取 + * @access public + * @param string $filename 文件名 + * @return string + */ + public function read($filename,$type=''){ + return $this->get($filename,'content',$type); + } + + /** + * 文件写入 + * @access public + * @param string $filename 文件名 + * @param string $content 文件内容 + * @return boolean + */ + public function put($filename,$content,$type=''){ + $dir = dirname($filename); + if(!is_dir($dir)){ + mkdir($dir,0777,true); + } + if(false === file_put_contents($filename,$content)){ + E(L('_STORAGE_WRITE_ERROR_').':'.$filename); + }else{ + $this->contents[$filename]=$content; + return true; + } + } + + /** + * 文件追加写入 + * @access public + * @param string $filename 文件名 + * @param string $content 追加的文件内容 + * @return boolean + */ + public function append($filename,$content,$type=''){ + if(is_file($filename)){ + $content = $this->read($filename,$type).$content; + } + return $this->put($filename,$content,$type); + } + + /** + * 加载文件 + * @access public + * @param string $filename 文件名 + * @param array $vars 传入变量 + * @return void + */ + public function load($_filename,$vars=null){ + if(!is_null($vars)){ + extract($vars, EXTR_OVERWRITE); + } + include $_filename; + } + + /** + * 文件是否存在 + * @access public + * @param string $filename 文件名 + * @return boolean + */ + public function has($filename,$type=''){ + return is_file($filename); + } + + /** + * 文件删除 + * @access public + * @param string $filename 文件名 + * @return boolean + */ + public function unlink($filename,$type=''){ + unset($this->contents[$filename]); + return is_file($filename) ? unlink($filename) : false; + } + + /** + * 读取文件信息 + * @access public + * @param string $filename 文件名 + * @param string $name 信息名 mtime或者content + * @return boolean + */ + public function get($filename,$name,$type=''){ + if(!isset($this->contents[$filename])){ + if(!is_file($filename)) return false; + $this->contents[$filename]=file_get_contents($filename); + } + $content=$this->contents[$filename]; + $info = array( + 'mtime' => filemtime($filename), + 'content' => $content + ); + return $info[$name]; + } +} diff --git a/ThinkPHP/Library/Think/Storage/Driver/Sae.class.php b/ThinkPHP/Library/Think/Storage/Driver/Sae.class.php new file mode 100644 index 0000000..3756115 --- /dev/null +++ b/ThinkPHP/Library/Think/Storage/Driver/Sae.class.php @@ -0,0 +1,193 @@ + +// +---------------------------------------------------------------------- +namespace Think\Storage\Driver; +use Think\Storage; +// SAE环境文件写入存储类 +class Sae extends Storage{ + + /** + * 架构函数 + * @access public + */ + private $mc; + private $kvs = array(); + private $htmls = array(); + private $contents = array(); + public function __construct() { + if(!function_exists('memcache_init')){ + header('Content-Type:text/html;charset=utf-8'); + exit('请在SAE平台上运行代码。'); + } + $this->mc = @memcache_init(); + if(!$this->mc){ + header('Content-Type:text/html;charset=utf-8'); + exit('您未开通Memcache服务,请在SAE管理平台初始化Memcache服务'); + } + } + + /** + * 获得SaeKv对象 + */ + private function getKv(){ + static $kv; + if(!$kv){ + $kv = new \SaeKV(); + if(!$kv->init()) + E('您没有初始化KVDB,请在SAE管理平台初始化KVDB服务'); + } + return $kv; + } + + + /** + * 文件内容读取 + * @access public + * @param string $filename 文件名 + * @return string + */ + public function read($filename,$type=''){ + switch(strtolower($type)){ + case 'f': + $kv = $this->getKv(); + if(!isset($this->kvs[$filename])){ + $this->kvs[$filename]=$kv->get($filename); + } + return $this->kvs[$filename]; + default: + return $this->get($filename,'content',$type); + } + } + + /** + * 文件写入 + * @access public + * @param string $filename 文件名 + * @param string $content 文件内容 + * @return boolean + */ + public function put($filename,$content,$type=''){ + switch(strtolower($type)){ + case 'f': + $kv = $this->getKv(); + $this->kvs[$filename] = $content; + return $kv->set($filename,$content); + case 'html': + $kv = $this->getKv(); + $content = time().$content; + $this->htmls[$filename] = $content; + return $kv->set($filename,$content); + default: + $content = time().$content; + if(!$this->mc->set($filename,$content,MEMCACHE_COMPRESSED,0)){ + E(L('_STORAGE_WRITE_ERROR_').':'.$filename); + }else{ + $this->contents[$filename] = $content; + return true; + } + } + } + + /** + * 文件追加写入 + * @access public + * @param string $filename 文件名 + * @param string $content 追加的文件内容 + * @return boolean + */ + public function append($filename,$content,$type=''){ + if($old_content = $this->read($filename,$type)){ + $content = $old_content.$content; + } + return $this->put($filename,$content,$type); + } + + /** + * 加载文件 + * @access public + * @param string $_filename 文件名 + * @param array $vars 传入变量 + * @return void + */ + public function load($_filename,$vars=null){ + if(!is_null($vars)) + extract($vars, EXTR_OVERWRITE); + eval('?>'.$this->read($_filename)); + } + + /** + * 文件是否存在 + * @access public + * @param string $filename 文件名 + * @return boolean + */ + public function has($filename,$type=''){ + if($this->read($filename,$type)){ + return true; + }else{ + return false; + } + } + + /** + * 文件删除 + * @access public + * @param string $filename 文件名 + * @return boolean + */ + public function unlink($filename,$type=''){ + switch(strtolower($type)){ + case 'f': + $kv = $this->getKv(); + unset($this->kvs[$filename]); + return $kv->delete($filename); + case 'html': + $kv = $this->getKv(); + unset($this->htmls[$filename]); + return $kv->delete($filename); + default: + unset($this->contents[$filename]); + return $this->mc->delete($filename); + } + } + + /** + * 读取文件信息 + * @access public + * @param string $filename 文件名 + * @param string $name 信息名 mtime或者content + * @return boolean + */ + public function get($filename,$name,$type=''){ + switch(strtolower($type)){ + case 'html': + if(!isset($this->htmls[$filename])){ + $kv = $this->getKv(); + $this->htmls[$filename] = $kv->get($filename); + } + $content = $this->htmls[$filename]; + break; + default: + if(!isset($this->contents[$filename])){ + $this->contents[$filename] = $this->mc->get($filename); + } + $content = $this->contents[$filename]; + } + if(false===$content){ + return false; + } + $info = array( + 'mtime' => substr($content,0,10), + 'content' => substr($content,10) + ); + return $info[$name]; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template.class.php b/ThinkPHP/Library/Think/Template.class.php new file mode 100644 index 0000000..c43a97a --- /dev/null +++ b/ThinkPHP/Library/Think/Template.class.php @@ -0,0 +1,700 @@ + +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP内置模板引擎类 + * 支持XML标签和普通标签的模板解析 + * 编译型模板引擎 支持动态缓存 + */ +class Template { + + // 模板页面中引入的标签库列表 + protected $tagLib = array(); + // 当前模板文件 + protected $templateFile = ''; + // 模板变量 + public $tVar = array(); + public $config = array(); + private $literal = array(); + private $block = array(); + + /** + * 架构函数 + * @access public + */ + public function __construct(){ + $this->config['cache_path'] = C('CACHE_PATH'); + $this->config['template_suffix'] = C('TMPL_TEMPLATE_SUFFIX'); + $this->config['cache_suffix'] = C('TMPL_CACHFILE_SUFFIX'); + $this->config['tmpl_cache'] = C('TMPL_CACHE_ON'); + $this->config['cache_time'] = C('TMPL_CACHE_TIME'); + $this->config['taglib_begin'] = $this->stripPreg(C('TAGLIB_BEGIN')); + $this->config['taglib_end'] = $this->stripPreg(C('TAGLIB_END')); + $this->config['tmpl_begin'] = $this->stripPreg(C('TMPL_L_DELIM')); + $this->config['tmpl_end'] = $this->stripPreg(C('TMPL_R_DELIM')); + $this->config['default_tmpl'] = C('TEMPLATE_NAME'); + $this->config['layout_item'] = C('TMPL_LAYOUT_ITEM'); + } + + private function stripPreg($str) { + return str_replace( + array('{','}','(',')','|','[',']','-','+','*','.','^','?'), + array('\{','\}','\(','\)','\|','\[','\]','\-','\+','\*','\.','\^','\?'), + $str); + } + + // 模板变量获取和设置 + public function get($name) { + if(isset($this->tVar[$name])) + return $this->tVar[$name]; + else + return false; + } + + public function set($name,$value) { + $this->tVar[$name]= $value; + } + + /** + * 加载模板 + * @access public + * @param string $templateFile 模板文件 + * @param array $templateVar 模板变量 + * @param string $prefix 模板标识前缀 + * @return void + */ + public function fetch($templateFile,$templateVar,$prefix='') { + $this->tVar = $templateVar; + $templateCacheFile = $this->loadTemplate($templateFile,$prefix); + Storage::load($templateCacheFile,$this->tVar,null,'tpl'); + } + + /** + * 加载主模板并缓存 + * @access public + * @param string $templateFile 模板文件 + * @param string $prefix 模板标识前缀 + * @return string + * @throws ThinkExecption + */ + public function loadTemplate ($templateFile,$prefix='') { + if(is_file($templateFile)) { + $this->templateFile = $templateFile; + // 读取模板文件内容 + $tmplContent = file_get_contents($templateFile); + }else{ + $tmplContent = $templateFile; + } + // 根据模版文件名定位缓存文件 + $tmplCacheFile = $this->config['cache_path'].$prefix.md5($templateFile).$this->config['cache_suffix']; + + // 判断是否启用布局 + if(C('LAYOUT_ON')) { + if(false !== strpos($tmplContent,'{__NOLAYOUT__}')) { // 可以单独定义不使用布局 + $tmplContent = str_replace('{__NOLAYOUT__}','',$tmplContent); + }else{ // 替换布局的主体内容 + $layoutFile = THEME_PATH.C('LAYOUT_NAME').$this->config['template_suffix']; + // 检查布局文件 + if(!is_file($layoutFile)) { + E(L('_TEMPLATE_NOT_EXIST_').':'.$layoutFile); + } + $tmplContent = str_replace($this->config['layout_item'],$tmplContent,file_get_contents($layoutFile)); + } + } + // 编译模板内容 + $tmplContent = $this->compiler($tmplContent); + Storage::put($tmplCacheFile,trim($tmplContent),'tpl'); + return $tmplCacheFile; + } + + /** + * 编译模板文件内容 + * @access protected + * @param mixed $tmplContent 模板内容 + * @return string + */ + protected function compiler($tmplContent) { + //模板解析 + $tmplContent = $this->parse($tmplContent); + // 还原被替换的Literal标签 + $tmplContent = preg_replace_callback('//is', array($this, 'restoreLiteral'), $tmplContent); + // 添加安全代码 + $tmplContent = ''.$tmplContent; + // 优化生成的php代码 + $tmplContent = str_replace('?>config['taglib_begin']; + $end = $this->config['taglib_end']; + // 检查include语法 + $content = $this->parseInclude($content); + // 检查PHP语法 + $content = $this->parsePhp($content); + // 首先替换literal标签内容 + $content = preg_replace_callback('/'.$begin.'literal'.$end.'(.*?)'.$begin.'\/literal'.$end.'/is', array($this, 'parseLiteral'),$content); + + // 获取需要引入的标签库列表 + // 标签库只需要定义一次,允许引入多个一次 + // 一般放在文件的最前面 + // 格式: + // 当TAGLIB_LOAD配置为true时才会进行检测 + if(C('TAGLIB_LOAD')) { + $this->getIncludeTagLib($content); + if(!empty($this->tagLib)) { + // 对导入的TagLib进行解析 + foreach($this->tagLib as $tagLibName) { + $this->parseTagLib($tagLibName,$content); + } + } + } + // 预先加载的标签库 无需在每个模板中使用taglib标签加载 但必须使用标签库XML前缀 + if(C('TAGLIB_PRE_LOAD')) { + $tagLibs = explode(',',C('TAGLIB_PRE_LOAD')); + foreach ($tagLibs as $tag){ + $this->parseTagLib($tag,$content); + } + } + // 内置标签库 无需使用taglib标签导入就可以使用 并且不需使用标签库XML前缀 + $tagLibs = explode(',',C('TAGLIB_BUILD_IN')); + foreach ($tagLibs as $tag){ + $this->parseTagLib($tag,$content,true); + } + //解析普通模板标签 {$tagName} + $content = preg_replace_callback('/('.$this->config['tmpl_begin'].')([^\d\w\s'.$this->config['tmpl_begin'].$this->config['tmpl_end'].'].+?)('.$this->config['tmpl_end'].')/is', array($this, 'parseTag'),$content); + return $content; + } + + // 检查PHP语法 + protected function parsePhp($content) { + if(ini_get('short_open_tag')){ + // 开启短标签的情况要将'."\n", $content ); + } + // PHP语法检查 + if(C('TMPL_DENY_PHP') && false !== strpos($content,'config['taglib_begin'].'layout\s(.+?)\s*?\/'.$this->config['taglib_end'].'/is',$content,$matches); + if($find) { + //替换Layout标签 + $content = str_replace($matches[0],'',$content); + //解析Layout标签 + $array = $this->parseXmlAttrs($matches[1]); + if(!C('LAYOUT_ON') || C('LAYOUT_NAME') !=$array['name'] ) { + // 读取布局模板 + $layoutFile = THEME_PATH.$array['name'].$this->config['template_suffix']; + $replace = isset($array['replace'])?$array['replace']:$this->config['layout_item']; + // 替换布局的主体内容 + $content = str_replace($replace,$content,file_get_contents($layoutFile)); + } + }else{ + $content = str_replace('{__NOLAYOUT__}','',$content); + } + return $content; + } + + // 解析模板中的include标签 + protected function parseInclude($content, $extend = true) { + // 解析继承 + if($extend) + $content = $this->parseExtend($content); + // 解析布局 + $content = $this->parseLayout($content); + // 读取模板中的include标签 + $find = preg_match_all('/'.$this->config['taglib_begin'].'include\s(.+?)\s*?\/'.$this->config['taglib_end'].'/is',$content,$matches); + if($find) { + for($i=0;$i<$find;$i++) { + $include = $matches[1][$i]; + $array = $this->parseXmlAttrs($include); + $file = $array['file']; + unset($array['file']); + $content = str_replace($matches[0][$i],$this->parseIncludeItem($file,$array,$extend),$content); + } + } + return $content; + } + + // 解析模板中的extend标签 + protected function parseExtend($content) { + $begin = $this->config['taglib_begin']; + $end = $this->config['taglib_end']; + // 读取模板中的继承标签 + $find = preg_match('/'.$begin.'extend\s(.+?)\s*?\/'.$end.'/is',$content,$matches); + if($find) { + //替换extend标签 + $content = str_replace($matches[0],'',$content); + // 记录页面中的block标签 + preg_replace_callback('/'.$begin.'block\sname=[\'"](.+?)[\'"]\s*?'.$end.'(.*?)'.$begin.'\/block'.$end.'/is', array($this, 'parseBlock'),$content); + // 读取继承模板 + $array = $this->parseXmlAttrs($matches[1]); + $content = $this->parseTemplateName($array['name']); + $content = $this->parseInclude($content, false); //对继承模板中的include进行分析 + // 替换block标签 + $content = $this->replaceBlock($content); + }else{ + $content = preg_replace_callback('/'.$begin.'block\sname=[\'"](.+?)[\'"]\s*?'.$end.'(.*?)'.$begin.'\/block'.$end.'/is', function($match){return stripslashes($match[2]);}, $content); + } + return $content; + } + + /** + * 分析XML属性 + * @access private + * @param string $attrs XML属性字符串 + * @return array + */ + private function parseXmlAttrs($attrs) { + $xml = ''; + $xml = simplexml_load_string($xml); + if(!$xml) + E(L('_XML_TAG_ERROR_')); + $xml = (array)($xml->tag->attributes()); + $array = array_change_key_case($xml['@attributes']); + return $array; + } + + /** + * 替换页面中的literal标签 + * @access private + * @param string $content 模板内容 + * @return string|false + */ + private function parseLiteral($content) { + if(is_array($content)) $content = $content[1]; + if(trim($content)=='') return ''; + //$content = stripslashes($content); + $i = count($this->literal); + $parseStr = ""; + $this->literal[$i] = $content; + return $parseStr; + } + + /** + * 还原被替换的literal标签 + * @access private + * @param string $tag literal标签序号 + * @return string|false + */ + private function restoreLiteral($tag) { + if(is_array($tag)) $tag = $tag[1]; + // 还原literal标签 + $parseStr = $this->literal[$tag]; + // 销毁literal记录 + unset($this->literal[$tag]); + return $parseStr; + } + + /** + * 记录当前页面中的block标签 + * @access private + * @param string $name block名称 + * @param string $content 模板内容 + * @return string + */ + private function parseBlock($name,$content = '') { + if(is_array($name)){ + $content = $name[2]; + $name = $name[1]; + } + $this->block[$name] = $content; + return ''; + } + + /** + * 替换继承模板中的block标签 + * @access private + * @param string $content 模板内容 + * @return string + */ + private function replaceBlock($content){ + static $parse = 0; + $begin = $this->config['taglib_begin']; + $end = $this->config['taglib_end']; + $reg = '/('.$begin.'block\sname=[\'"](.+?)[\'"]\s*?'.$end.')(.*?)'.$begin.'\/block'.$end.'/is'; + if(is_string($content)){ + do{ + $content = preg_replace_callback($reg, array($this, 'replaceBlock'), $content); + } while ($parse && $parse--); + return $content; + } elseif(is_array($content)){ + if(preg_match('/'.$begin.'block\sname=[\'"](.+?)[\'"]\s*?'.$end.'/is', $content[3])){ //存在嵌套,进一步解析 + $parse = 1; + $content[3] = preg_replace_callback($reg, array($this, 'replaceBlock'), "{$content[3]}{$begin}/block{$end}"); + return $content[1] . $content[3]; + } else { + $name = $content[2]; + $content = $content[3]; + $content = isset($this->block[$name]) ? $this->block[$name] : $content; + return $content; + } + } + } + + /** + * 搜索模板页面中包含的TagLib库 + * 并返回列表 + * @access public + * @param string $content 模板内容 + * @return string|false + */ + public function getIncludeTagLib(& $content) { + //搜索是否有TagLib标签 + $find = preg_match('/'.$this->config['taglib_begin'].'taglib\s(.+?)(\s*?)\/'.$this->config['taglib_end'].'\W/is',$content,$matches); + if($find) { + //替换TagLib标签 + $content = str_replace($matches[0],'',$content); + //解析TagLib标签 + $array = $this->parseXmlAttrs($matches[1]); + $this->tagLib = explode(',',$array['name']); + } + return; + } + + /** + * TagLib库解析 + * @access public + * @param string $tagLib 要解析的标签库 + * @param string $content 要解析的模板内容 + * @param boolean $hide 是否隐藏标签库前缀 + * @return string + */ + public function parseTagLib($tagLib,&$content,$hide=false) { + $begin = $this->config['taglib_begin']; + $end = $this->config['taglib_end']; + if(strpos($tagLib,'\\')){ + // 支持指定标签库的命名空间 + $className = $tagLib; + $tagLib = substr($tagLib,strrpos($tagLib,'\\')+1); + }else{ + $className = 'Think\\Template\TagLib\\'.ucwords($tagLib); + } + $tLib = \Think\Think::instance($className); + $that = $this; + foreach ($tLib->getTags() as $name=>$val){ + $tags = array($name); + if(isset($val['alias'])) {// 别名设置 + $tags = explode(',',$val['alias']); + $tags[] = $name; + } + $level = isset($val['level'])?$val['level']:1; + $closeTag = isset($val['close'])?$val['close']:true; + foreach ($tags as $tag){ + $parseTag = !$hide? $tagLib.':'.$tag: $tag;// 实际要解析的标签名称 + if(!method_exists($tLib,'_'.$tag)) { + // 别名可以无需定义解析方法 + $tag = $name; + } + $n1 = empty($val['attr'])?'(\s*?)':'\s([^'.$end.']*)'; + $this->tempVar = array($tagLib, $tag); + + if (!$closeTag){ + $patterns = '/'.$begin.$parseTag.$n1.'\/(\s*?)'.$end.'/is'; + $content = preg_replace_callback($patterns, function($matches) use($tLib,$tag,$that){ + return $that->parseXmlTag($tLib,$tag,$matches[1],$matches[2]); + },$content); + }else{ + $patterns = '/'.$begin.$parseTag.$n1.$end.'(.*?)'.$begin.'\/'.$parseTag.'(\s*?)'.$end.'/is'; + for($i=0;$i<$level;$i++) { + $content=preg_replace_callback($patterns,function($matches) use($tLib,$tag,$that){ + return $that->parseXmlTag($tLib,$tag,$matches[1],$matches[2]); + },$content); + } + } + } + } + } + + /** + * 解析标签库的标签 + * 需要调用对应的标签库文件解析类 + * @access public + * @param object $tagLib 标签库对象实例 + * @param string $tag 标签名 + * @param string $attr 标签属性 + * @param string $content 标签内容 + * @return string|false + */ + public function parseXmlTag($tagLib,$tag,$attr,$content) { + if(ini_get('magic_quotes_sybase')) + $attr = str_replace('\"','\'',$attr); + $parse = '_'.$tag; + $content = trim($content); + $tags = $tagLib->parseXmlAttr($attr,$tag); + return $tagLib->$parse($tags,$content); + } + + /** + * 模板标签解析 + * 格式: {TagName:args [|content] } + * @access public + * @param string $tagStr 标签内容 + * @return string + */ + public function parseTag($tagStr){ + if(is_array($tagStr)) $tagStr = $tagStr[2]; + //if (MAGIC_QUOTES_GPC) { + $tagStr = stripslashes($tagStr); + //} + $flag = substr($tagStr,0,1); + $flag2 = substr($tagStr,1,1); + $name = substr($tagStr,1); + if('$' == $flag && '.' != $flag2 && '(' != $flag2){ //解析模板变量 格式 {$varName} + return $this->parseVar($name); + }elseif('-' == $flag || '+'== $flag){ // 输出计算 + return ''; + }elseif(':' == $flag){ // 输出某个函数的结果 + return ''; + }elseif('~' == $flag){ // 执行某个函数 + return ''; + }elseif(substr($tagStr,0,2)=='//' || (substr($tagStr,0,2)=='/*' && substr(rtrim($tagStr),-2)=='*/')){ + //注释标签 + return ''; + } + // 未识别的标签直接返回 + return C('TMPL_L_DELIM') . $tagStr .C('TMPL_R_DELIM'); + } + + /** + * 模板变量解析,支持使用函数 + * 格式: {$varname|function1|function2=arg1,arg2} + * @access public + * @param string $varStr 变量数据 + * @return string + */ + public function parseVar($varStr){ + $varStr = trim($varStr); + static $_varParseList = array(); + //如果已经解析过该变量字串,则直接返回变量值 + if(isset($_varParseList[$varStr])) return $_varParseList[$varStr]; + $parseStr = ''; + $varExists = true; + if(!empty($varStr)){ + $varArray = explode('|',$varStr); + //取得变量名称 + $var = array_shift($varArray); + if('Think.' == substr($var,0,6)){ + // 所有以Think.打头的以特殊变量对待 无需模板赋值就可以输出 + $name = $this->parseThinkVar($var); + }elseif( false !== strpos($var,'.')) { + //支持 {$var.property} + $vars = explode('.',$var); + $var = array_shift($vars); + switch(strtolower(C('TMPL_VAR_IDENTIFY'))) { + case 'array': // 识别为数组 + $name = '$'.$var; + foreach ($vars as $key=>$val) + $name .= '["'.$val.'"]'; + break; + case 'obj': // 识别为对象 + $name = '$'.$var; + foreach ($vars as $key=>$val) + $name .= '->'.$val; + break; + default: // 自动判断数组或对象 只支持二维 + $name = 'is_array($'.$var.')?$'.$var.'["'.$vars[0].'"]:$'.$var.'->'.$vars[0]; + } + }elseif(false !== strpos($var,'[')) { + //支持 {$var['key']} 方式输出数组 + $name = "$".$var; + preg_match('/(.+?)\[(.+?)\]/is',$var,$match); + $var = $match[1]; + }elseif(false !==strpos($var,':') && false ===strpos($var,'(') && false ===strpos($var,'::') && false ===strpos($var,'?')){ + //支持 {$var:property} 方式输出对象的属性 + $vars = explode(':',$var); + $var = str_replace(':','->',$var); + $name = "$".$var; + $var = $vars[0]; + }else { + $name = "$$var"; + } + //对变量使用函数 + if(count($varArray)>0) + $name = $this->parseVarFunction($name,$varArray); + $parseStr = ''; + } + $_varParseList[$varStr] = $parseStr; + return $parseStr; + } + + /** + * 对模板变量使用函数 + * 格式 {$varname|function1|function2=arg1,arg2} + * @access public + * @param string $name 变量名 + * @param array $varArray 函数列表 + * @return string + */ + public function parseVarFunction($name,$varArray){ + //对变量使用函数 + $length = count($varArray); + //取得模板禁止使用函数列表 + $template_deny_funs = explode(',',C('TMPL_DENY_FUNC_LIST')); + for($i=0;$i<$length ;$i++ ){ + $args = explode('=',$varArray[$i],2); + //模板函数过滤 + $fun = trim($args[0]); + switch($fun) { + case 'default': // 特殊模板函数 + $name = '(isset('.$name.') && ('.$name.' !== ""))?('.$name.'):'.$args[1]; + break; + default: // 通用模板函数 + if(!in_array($fun,$template_deny_funs)){ + if(isset($args[1])){ + if(strstr($args[1],'###')){ + $args[1] = str_replace('###',$name,$args[1]); + $name = "$fun($args[1])"; + }else{ + $name = "$fun($name,$args[1])"; + } + }else if(!empty($args[0])){ + $name = "$fun($name)"; + } + } + } + } + return $name; + } + + /** + * 特殊模板变量解析 + * 格式 以 $Think. 打头的变量属于特殊模板变量 + * @access public + * @param string $varStr 变量字符串 + * @return string + */ + public function parseThinkVar($varStr){ + $vars = explode('.',$varStr); + $vars[1] = strtoupper(trim($vars[1])); + $parseStr = ''; + if(count($vars)>=3){ + $vars[2] = trim($vars[2]); + switch($vars[1]){ + case 'SERVER': + $parseStr = '$_SERVER[\''.strtoupper($vars[2]).'\']';break; + case 'GET': + $parseStr = '$_GET[\''.$vars[2].'\']';break; + case 'POST': + $parseStr = '$_POST[\''.$vars[2].'\']';break; + case 'COOKIE': + if(isset($vars[3])) { + $parseStr = '$_COOKIE[\''.$vars[2].'\'][\''.$vars[3].'\']'; + }else{ + $parseStr = 'cookie(\''.$vars[2].'\')'; + } + break; + case 'SESSION': + if(isset($vars[3])) { + $parseStr = '$_SESSION[\''.$vars[2].'\'][\''.$vars[3].'\']'; + }else{ + $parseStr = 'session(\''.$vars[2].'\')'; + } + break; + case 'ENV': + $parseStr = '$_ENV[\''.strtoupper($vars[2]).'\']';break; + case 'REQUEST': + $parseStr = '$_REQUEST[\''.$vars[2].'\']';break; + case 'CONST': + $parseStr = strtoupper($vars[2]);break; + case 'LANG': + $parseStr = 'L("'.$vars[2].'")';break; + case 'CONFIG': + if(isset($vars[3])) { + $vars[2] .= '.'.$vars[3]; + } + $parseStr = 'C("'.$vars[2].'")';break; + default:break; + } + }else if(count($vars)==2){ + switch($vars[1]){ + case 'NOW': + $parseStr = "date('Y-m-d g:i a',time())"; + break; + case 'VERSION': + $parseStr = 'THINK_VERSION'; + break; + case 'TEMPLATE': + $parseStr = "'".$this->templateFile."'";//'C("TEMPLATE_NAME")'; + break; + case 'LDELIM': + $parseStr = 'C("TMPL_L_DELIM")'; + break; + case 'RDELIM': + $parseStr = 'C("TMPL_R_DELIM")'; + break; + default: + if(defined($vars[1])) + $parseStr = $vars[1]; + } + } + return $parseStr; + } + + /** + * 加载公共模板并缓存 和当前模板在同一路径,否则使用相对路径 + * @access private + * @param string $tmplPublicName 公共模板文件名 + * @param array $vars 要传递的变量列表 + * @return string + */ + private function parseIncludeItem($tmplPublicName,$vars=array(),$extend){ + // 分析模板文件名并读取内容 + $parseStr = $this->parseTemplateName($tmplPublicName); + // 替换变量 + foreach ($vars as $key=>$val) { + $parseStr = str_replace('['.$key.']',$val,$parseStr); + } + // 再次对包含文件进行模板分析 + return $this->parseInclude($parseStr,$extend); + } + + /** + * 分析加载的模板文件并读取内容 支持多个模板文件读取 + * @access private + * @param string $tmplPublicName 模板文件名 + * @return string + */ + private function parseTemplateName($templateName){ + if(substr($templateName,0,1)=='$') + //支持加载变量文件名 + $templateName = $this->get(substr($templateName,1)); + $array = explode(',',$templateName); + $parseStr = ''; + foreach ($array as $templateName){ + if(empty($templateName)) continue; + if(false === strpos($templateName,$this->config['template_suffix'])) { + // 解析规则为 模块@主题/控制器/操作 + $templateName = T($templateName); + } + // 获取模板文件内容 + $parseStr .= file_get_contents($templateName); + } + return $parseStr; + } +} diff --git a/ThinkPHP/Library/Think/Template/Driver/Ease.class.php b/ThinkPHP/Library/Think/Template/Driver/Ease.class.php new file mode 100644 index 0000000..192bde0 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/Driver/Ease.class.php @@ -0,0 +1,41 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\Driver; +/** + * EaseTemplate模板引擎驱动 + */ +class Ease { + /** + * 渲染模板输出 + * @access public + * @param string $templateFile 模板文件名 + * @param array $var 模板变量 + * @return void + */ + public function fetch($templateFile,$var) { + $templateFile = substr($templateFile,strlen(THEME_PATH),-5); + $CacheDir = substr(CACHE_PATH,0,-1); + $TemplateDir = substr(THEME_PATH,0,-1); + vendor('EaseTemplate.template#ease'); + $config = array( + 'CacheDir' => $CacheDir, + 'TemplateDir' => $TemplateDir, + 'TplType' => 'html' + ); + if(C('TMPL_ENGINE_CONFIG')) { + $config = array_merge($config,C('TMPL_ENGINE_CONFIG')); + } + $tpl = new \EaseTemplate($config); + $tpl->set_var($var); + $tpl->set_file($templateFile); + $tpl->p(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template/Driver/Lite.class.php b/ThinkPHP/Library/Think/Template/Driver/Lite.class.php new file mode 100644 index 0000000..5f73a02 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/Driver/Lite.class.php @@ -0,0 +1,39 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\Driver; +/** + * TemplateLite模板引擎驱动 + */ +class Lite { + /** + * 渲染模板输出 + * @access public + * @param string $templateFile 模板文件名 + * @param array $var 模板变量 + * @return void + */ + public function fetch($templateFile,$var) { + vendor("TemplateLite.class#template"); + $templateFile = substr($templateFile,strlen(THEME_PATH)); + $tpl = new \Template_Lite(); + $tpl->template_dir = THEME_PATH; + $tpl->compile_dir = CACHE_PATH ; + $tpl->cache_dir = TEMP_PATH ; + if(C('TMPL_ENGINE_CONFIG')) { + $config = C('TMPL_ENGINE_CONFIG'); + foreach ($config as $key=>$val){ + $tpl->{$key} = $val; + } + } + $tpl->assign($var); + $tpl->display($templateFile); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template/Driver/Mobile.class.php b/ThinkPHP/Library/Think/Template/Driver/Mobile.class.php new file mode 100644 index 0000000..db39e7f --- /dev/null +++ b/ThinkPHP/Library/Think/Template/Driver/Mobile.class.php @@ -0,0 +1,28 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\Driver; +/** + * MobileTemplate模板引擎驱动 + */ +class Mobile { + /** + * 渲染模板输出 + * @access public + * @param string $templateFile 模板文件名 + * @param array $var 模板变量 + * @return void + */ + public function fetch($templateFile,$var) { + $templateFile=substr($templateFile,strlen(THEME_PATH)); + $var['_think_template_path']=$templateFile; + exit(json_encode($var)); + } +} diff --git a/ThinkPHP/Library/Think/Template/Driver/Smart.class.php b/ThinkPHP/Library/Think/Template/Driver/Smart.class.php new file mode 100644 index 0000000..5a2eb1c --- /dev/null +++ b/ThinkPHP/Library/Think/Template/Driver/Smart.class.php @@ -0,0 +1,40 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\Driver; +/** + * Smart模板引擎驱动 + */ +class Smart { + /** + * 渲染模板输出 + * @access public + * @param string $templateFile 模板文件名 + * @param array $var 模板变量 + * @return void + */ + public function fetch($templateFile,$var) { + $templateFile = substr($templateFile,strlen(THEME_PATH)); + vendor('SmartTemplate.class#smarttemplate'); + $tpl = new \SmartTemplate($templateFile); + $tpl->caching = C('TMPL_CACHE_ON'); + $tpl->template_dir = THEME_PATH; + $tpl->compile_dir = CACHE_PATH ; + $tpl->cache_dir = TEMP_PATH ; + if(C('TMPL_ENGINE_CONFIG')) { + $config = C('TMPL_ENGINE_CONFIG'); + foreach ($config as $key=>$val){ + $tpl->{$key} = $val; + } + } + $tpl->assign($var); + $tpl->output(); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template/Driver/Smarty.class.php b/ThinkPHP/Library/Think/Template/Driver/Smarty.class.php new file mode 100644 index 0000000..aecdc10 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/Driver/Smarty.class.php @@ -0,0 +1,41 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\Driver; +/** + * Smarty模板引擎驱动 + */ +class Smarty { + + /** + * 渲染模板输出 + * @access public + * @param string $templateFile 模板文件名 + * @param array $var 模板变量 + * @return void + */ + public function fetch($templateFile,$var) { + $templateFile = substr($templateFile,strlen(THEME_PATH)); + vendor('Smarty.Smarty#class'); + $tpl = new \Smarty(); + $tpl->caching = C('TMPL_CACHE_ON'); + $tpl->template_dir = THEME_PATH; + $tpl->compile_dir = CACHE_PATH ; + $tpl->cache_dir = TEMP_PATH ; + if(C('TMPL_ENGINE_CONFIG')) { + $config = C('TMPL_ENGINE_CONFIG'); + foreach ($config as $key=>$val){ + $tpl->{$key} = $val; + } + } + $tpl->assign($var); + $tpl->display($templateFile); + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template/TagLib.class.php b/ThinkPHP/Library/Think/Template/TagLib.class.php new file mode 100644 index 0000000..18e3be8 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/TagLib.class.php @@ -0,0 +1,246 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template; +/** + * ThinkPHP标签库TagLib解析基类 + */ +class TagLib { + + /** + * 标签库定义XML文件 + * @var string + * @access protected + */ + protected $xml = ''; + protected $tags = array();// 标签定义 + /** + * 标签库名称 + * @var string + * @access protected + */ + protected $tagLib =''; + + /** + * 标签库标签列表 + * @var string + * @access protected + */ + protected $tagList = array(); + + /** + * 标签库分析数组 + * @var string + * @access protected + */ + protected $parse = array(); + + /** + * 标签库是否有效 + * @var string + * @access protected + */ + protected $valid = false; + + /** + * 当前模板对象 + * @var object + * @access protected + */ + protected $tpl; + + protected $comparison = array(' nheq '=>' !== ',' heq '=>' === ',' neq '=>' != ',' eq '=>' == ',' egt '=>' >= ',' gt '=>' > ',' elt '=>' <= ',' lt '=>' < '); + + /** + * 架构函数 + * @access public + */ + public function __construct() { + $this->tagLib = strtolower(substr(get_class($this),6)); + $this->tpl = \Think\Think::instance('Think\\Template'); + } + + /** + * TagLib标签属性分析 返回标签属性数组 + * @access public + * @param string $tagStr 标签内容 + * @return array + */ + public function parseXmlAttr($attr,$tag) { + //XML解析安全过滤 + $attr = str_replace('&','___', $attr); + $xml = ''; + $xml = simplexml_load_string($xml); + if(!$xml) { + E(L('_XML_TAG_ERROR_').' : '.$attr); + } + $xml = (array)($xml->tag->attributes()); + if(isset($xml['@attributes'])){ + $array = array_change_key_case($xml['@attributes']); + if($array) { + $tag = strtolower($tag); + if(!isset($this->tags[$tag])){ + // 检测是否存在别名定义 + foreach($this->tags as $key=>$val){ + if(isset($val['alias']) && in_array($tag,explode(',',$val['alias']))){ + $item = $val; + break; + } + } + }else{ + $item = $this->tags[$tag]; + } + $attrs = explode(',',$item['attr']); + if(isset($item['must'])){ + $must = explode(',',$item['must']); + }else{ + $must = array(); + } + foreach($attrs as $name) { + if( isset($array[$name])) { + $array[$name] = str_replace('___','&',$array[$name]); + }elseif(false !== array_search($name,$must)){ + E(L('_PARAM_ERROR_').':'.$name); + } + } + return $array; + } + }else{ + return array(); + } + } + + /** + * 解析条件表达式 + * @access public + * @param string $condition 表达式标签内容 + * @return array + */ + public function parseCondition($condition) { + $condition = str_ireplace(array_keys($this->comparison),array_values($this->comparison),$condition); + $condition = preg_replace('/\$(\w+):(\w+)\s/is','$\\1->\\2 ',$condition); + switch(strtolower(C('TMPL_VAR_IDENTIFY'))) { + case 'array': // 识别为数组 + $condition = preg_replace('/\$(\w+)\.(\w+)\s/is','$\\1["\\2"] ',$condition); + break; + case 'obj': // 识别为对象 + $condition = preg_replace('/\$(\w+)\.(\w+)\s/is','$\\1->\\2 ',$condition); + break; + default: // 自动判断数组或对象 只支持二维 + $condition = preg_replace('/\$(\w+)\.(\w+)\s/is','(is_array($\\1)?$\\1["\\2"]:$\\1->\\2) ',$condition); + } + if(false !== strpos($condition, '$Think')) + $condition = preg_replace_callback('/(\$Think.*?)\s/is', array($this, 'parseThinkVar'), $condition); + return $condition; + } + + /** + * 自动识别构建变量 + * @access public + * @param string $name 变量描述 + * @return string + */ + public function autoBuildVar($name) { + if('Think.' == substr($name,0,6)){ + // 特殊变量 + return $this->parseThinkVar($name); + }elseif(strpos($name,'.')) { + $vars = explode('.',$name); + $var = array_shift($vars); + switch(strtolower(C('TMPL_VAR_IDENTIFY'))) { + case 'array': // 识别为数组 + $name = '$'.$var; + foreach ($vars as $key=>$val){ + if(0===strpos($val,'$')) { + $name .= '["{'.$val.'}"]'; + }else{ + $name .= '["'.$val.'"]'; + } + } + break; + case 'obj': // 识别为对象 + $name = '$'.$var; + foreach ($vars as $key=>$val) + $name .= '->'.$val; + break; + default: // 自动判断数组或对象 只支持二维 + $name = 'is_array($'.$var.')?$'.$var.'["'.$vars[0].'"]:$'.$var.'->'.$vars[0]; + } + }elseif(strpos($name,':')){ + // 额外的对象方式支持 + $name = '$'.str_replace(':','->',$name); + }elseif(!defined($name)) { + $name = '$'.$name; + } + return $name; + } + + /** + * 用于标签属性里面的特殊模板变量解析 + * 格式 以 Think. 打头的变量属于特殊模板变量 + * @access public + * @param string $varStr 变量字符串 + * @return string + */ + public function parseThinkVar($varStr){ + if(is_array($varStr)){//用于正则替换回调函数 + $varStr = $varStr[1]; + } + $vars = explode('.',$varStr); + $vars[1] = strtoupper(trim($vars[1])); + $parseStr = ''; + if(count($vars)>=3){ + $vars[2] = trim($vars[2]); + switch($vars[1]){ + case 'SERVER': $parseStr = '$_SERVER[\''.$vars[2].'\']';break; + case 'GET': $parseStr = '$_GET[\''.$vars[2].'\']';break; + case 'POST': $parseStr = '$_POST[\''.$vars[2].'\']';break; + case 'COOKIE': + if(isset($vars[3])) { + $parseStr = '$_COOKIE[\''.$vars[2].'\'][\''.$vars[3].'\']'; + }elseif(C('COOKIE_PREFIX')){ + $parseStr = '$_COOKIE[\''.C('COOKIE_PREFIX').$vars[2].'\']'; + }else{ + $parseStr = '$_COOKIE[\''.$vars[2].'\']'; + } + break; + case 'SESSION': + if(isset($vars[3])) { + $parseStr = '$_SESSION[\''.$vars[2].'\'][\''.$vars[3].'\']'; + }elseif(C('SESSION_PREFIX')){ + $parseStr = '$_SESSION[\''.C('SESSION_PREFIX').'\'][\''.$vars[2].'\']'; + }else{ + $parseStr = '$_SESSION[\''.$vars[2].'\']'; + } + break; + case 'ENV': $parseStr = '$_ENV[\''.$vars[2].'\']';break; + case 'REQUEST': $parseStr = '$_REQUEST[\''.$vars[2].'\']';break; + case 'CONST': $parseStr = strtoupper($vars[2]);break; + case 'LANG': $parseStr = 'L("'.$vars[2].'")';break; + case 'CONFIG': $parseStr = 'C("'.$vars[2].'")';break; + } + }else if(count($vars)==2){ + switch($vars[1]){ + case 'NOW': $parseStr = "date('Y-m-d g:i a',time())";break; + case 'VERSION': $parseStr = 'THINK_VERSION';break; + case 'TEMPLATE':$parseStr = 'C("TEMPLATE_NAME")';break; + case 'LDELIM': $parseStr = 'C("TMPL_L_DELIM")';break; + case 'RDELIM': $parseStr = 'C("TMPL_R_DELIM")';break; + default: if(defined($vars[1])) $parseStr = $vars[1]; + } + } + return $parseStr; + } + + // 获取标签定义 + public function getTags(){ + return $this->tags; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php b/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php new file mode 100644 index 0000000..67b5dd4 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/TagLib/Cx.class.php @@ -0,0 +1,614 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\TagLib; +use Think\Template\TagLib; +/** + * CX标签库解析类 + */ +class Cx extends TagLib { + + // 标签定义 + protected $tags = array( + // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 + 'php' => array(), + 'volist' => array('attr'=>'name,id,offset,length,key,mod','level'=>3,'alias'=>'iterate'), + 'foreach' => array('attr'=>'name,item,key','level'=>3), + 'if' => array('attr'=>'condition','level'=>2), + 'elseif' => array('attr'=>'condition','close'=>0), + 'else' => array('attr'=>'','close'=>0), + 'switch' => array('attr'=>'name','level'=>2), + 'case' => array('attr'=>'value,break'), + 'default' => array('attr'=>'','close'=>0), + 'compare' => array('attr'=>'name,value,type','level'=>3,'alias'=>'eq,equal,notequal,neq,gt,lt,egt,elt,heq,nheq'), + 'range' => array('attr'=>'name,value,type','level'=>3,'alias'=>'in,notin,between,notbetween'), + 'empty' => array('attr'=>'name','level'=>3), + 'notempty' => array('attr'=>'name','level'=>3), + 'present' => array('attr'=>'name','level'=>3), + 'notpresent'=> array('attr'=>'name','level'=>3), + 'defined' => array('attr'=>'name','level'=>3), + 'notdefined'=> array('attr'=>'name','level'=>3), + 'import' => array('attr'=>'file,href,type,value,basepath','close'=>0,'alias'=>'load,css,js'), + 'assign' => array('attr'=>'name,value','close'=>0), + 'define' => array('attr'=>'name,value','close'=>0), + 'for' => array('attr'=>'start,end,name,comparison,step', 'level'=>3), + ); + + /** + * php标签解析 + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _php($tag,$content) { + $parseStr = ''; + return $parseStr; + } + + /** + * volist标签解析 循环输出数据集 + * 格式: + * + * {user.username} + * {user.email} + * + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string|void + */ + public function _volist($tag,$content) { + $name = $tag['name']; + $id = $tag['id']; + $empty = isset($tag['empty'])?$tag['empty']:''; + $key = !empty($tag['key'])?$tag['key']:'i'; + $mod = isset($tag['mod'])?$tag['mod']:'2'; + // 允许使用函数设定数据集 {$vo.name} + $parseStr = 'autoBuildVar($name); + } + $parseStr .= 'if(is_array('.$name.')): $'.$key.' = 0;'; + if(isset($tag['length']) && '' !=$tag['length'] ) { + $parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].','.$tag['length'].',true);'; + }elseif(isset($tag['offset']) && '' !=$tag['offset']){ + $parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].',null,true);'; + }else{ + $parseStr .= ' $__LIST__ = '.$name.';'; + } + $parseStr .= 'if( count($__LIST__)==0 ) : echo "'.$empty.'" ;'; + $parseStr .= 'else: '; + $parseStr .= 'foreach($__LIST__ as $key=>$'.$id.'): '; + $parseStr .= '$mod = ($'.$key.' % '.$mod.' );'; + $parseStr .= '++$'.$key.';?>'; + $parseStr .= $this->tpl->parse($content); + $parseStr .= ''; + + if(!empty($parseStr)) { + return $parseStr; + } + return ; + } + + /** + * foreach标签解析 循环输出数据集 + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string|void + */ + public function _foreach($tag,$content) { + $name = $tag['name']; + $item = $tag['item']; + $key = !empty($tag['key'])?$tag['key']:'key'; + $name = $this->autoBuildVar($name); + $parseStr = '$'.$item.'): ?>'; + $parseStr .= $this->tpl->parse($content); + $parseStr .= ''; + + if(!empty($parseStr)) { + return $parseStr; + } + return ; + } + + /** + * if标签解析 + * 格式: + * + * + * + * + * 表达式支持 eq neq gt egt lt elt == > >= < <= or and || && + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _if($tag,$content) { + $condition = $this->parseCondition($tag['condition']); + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * else标签解析 + * 格式:见if标签 + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _elseif($tag,$content) { + $condition = $this->parseCondition($tag['condition']); + $parseStr = ''; + return $parseStr; + } + + /** + * else标签解析 + * @access public + * @param array $tag 标签属性 + * @return string + */ + public function _else($tag) { + $parseStr = ''; + return $parseStr; + } + + /** + * switch标签解析 + * 格式: + * + * 1 + * 2 + * other + * + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _switch($tag,$content) { + $name = $tag['name']; + $varArray = explode('|',$name); + $name = array_shift($varArray); + $name = $this->autoBuildVar($name); + if(count($varArray)>0) + $name = $this->tpl->parseVarFunction($name,$varArray); + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * case标签解析 需要配合switch才有效 + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _case($tag,$content) { + $value = $tag['value']; + if('$' == substr($value,0,1)) { + $varArray = explode('|',$value); + $value = array_shift($varArray); + $value = $this->autoBuildVar(substr($value,1)); + if(count($varArray)>0) + $value = $this->tpl->parseVarFunction($value,$varArray); + $value = 'case '.$value.': '; + }elseif(strpos($value,'|')){ + $values = explode('|',$value); + $value = ''; + foreach ($values as $val){ + $value .= 'case "'.addslashes($val).'": '; + } + }else{ + $value = 'case "'.$value.'": '; + } + $parseStr = ''.$content; + $isBreak = isset($tag['break']) ? $tag['break'] : ''; + if('' ==$isBreak || $isBreak) { + $parseStr .= ''; + } + return $parseStr; + } + + /** + * default标签解析 需要配合switch才有效 + * 使用: ddfdf + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _default($tag) { + $parseStr = ''; + return $parseStr; + } + + /** + * compare标签解析 + * 用于值的比较 支持 eq neq gt lt egt elt heq nheq 默认是eq + * 格式: content + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _compare($tag,$content,$type='eq') { + $name = $tag['name']; + $value = $tag['value']; + $type = isset($tag['type'])?$tag['type']:$type; + $type = $this->parseCondition(' '.$type.' '); + $varArray = explode('|',$name); + $name = array_shift($varArray); + $name = $this->autoBuildVar($name); + if(count($varArray)>0) + $name = $this->tpl->parseVarFunction($name,$varArray); + if('$' == substr($value,0,1)) { + $value = $this->autoBuildVar(substr($value,1)); + }else { + $value = '"'.$value.'"'; + } + $parseStr = ''.$content.''; + return $parseStr; + } + + public function _eq($tag,$content) { + return $this->_compare($tag,$content,'eq'); + } + + public function _equal($tag,$content) { + return $this->_compare($tag,$content,'eq'); + } + + public function _neq($tag,$content) { + return $this->_compare($tag,$content,'neq'); + } + + public function _notequal($tag,$content) { + return $this->_compare($tag,$content,'neq'); + } + + public function _gt($tag,$content) { + return $this->_compare($tag,$content,'gt'); + } + + public function _lt($tag,$content) { + return $this->_compare($tag,$content,'lt'); + } + + public function _egt($tag,$content) { + return $this->_compare($tag,$content,'egt'); + } + + public function _elt($tag,$content) { + return $this->_compare($tag,$content,'elt'); + } + + public function _heq($tag,$content) { + return $this->_compare($tag,$content,'heq'); + } + + public function _nheq($tag,$content) { + return $this->_compare($tag,$content,'nheq'); + } + + /** + * range标签解析 + * 如果某个变量存在于某个范围 则输出内容 type= in 表示在范围内 否则表示在范围外 + * 格式: content + * example: content + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @param string $type 比较类型 + * @return string + */ + public function _range($tag,$content,$type='in') { + $name = $tag['name']; + $value = $tag['value']; + $varArray = explode('|',$name); + $name = array_shift($varArray); + $name = $this->autoBuildVar($name); + if(count($varArray)>0) + $name = $this->tpl->parseVarFunction($name,$varArray); + + $type = isset($tag['type'])?$tag['type']:$type; + + if('$' == substr($value,0,1)) { + $value = $this->autoBuildVar(substr($value,1)); + $str = 'is_array('.$value.')?'.$value.':explode(\',\','.$value.')'; + }else{ + $value = '"'.$value.'"'; + $str = 'explode(\',\','.$value.')'; + } + if($type=='between') { + $parseStr = '= $_RANGE_VAR_[0] && '.$name.'<= $_RANGE_VAR_[1]):?>'.$content.''; + }elseif($type=='notbetween'){ + $parseStr = '$_RANGE_VAR_[1]):?>'.$content.''; + }else{ + $fun = ($type == 'in')? 'in_array' : '!in_array'; + $parseStr = ''.$content.''; + } + return $parseStr; + } + + // range标签的别名 用于in判断 + public function _in($tag,$content) { + return $this->_range($tag,$content,'in'); + } + + // range标签的别名 用于notin判断 + public function _notin($tag,$content) { + return $this->_range($tag,$content,'notin'); + } + + public function _between($tag,$content){ + return $this->_range($tag,$content,'between'); + } + + public function _notbetween($tag,$content){ + return $this->_range($tag,$content,'notbetween'); + } + + /** + * present标签解析 + * 如果某个变量已经设置 则输出内容 + * 格式: content + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _present($tag,$content) { + $name = $tag['name']; + $name = $this->autoBuildVar($name); + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * notpresent标签解析 + * 如果某个变量没有设置,则输出内容 + * 格式: content + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _notpresent($tag,$content) { + $name = $tag['name']; + $name = $this->autoBuildVar($name); + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * empty标签解析 + * 如果某个变量为empty 则输出内容 + * 格式: content + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _empty($tag,$content) { + $name = $tag['name']; + $name = $this->autoBuildVar($name); + $parseStr = ''.$content.''; + return $parseStr; + } + + public function _notempty($tag,$content) { + $name = $tag['name']; + $name = $this->autoBuildVar($name); + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * 判断是否已经定义了该常量 + * 已定义 + * @param $attr + * @param $content + * @return string + */ + public function _defined($tag,$content) { + $name = $tag['name']; + $parseStr = ''.$content.''; + return $parseStr; + } + + public function _notdefined($tag,$content) { + $name = $tag['name']; + $parseStr = ''.$content.''; + return $parseStr; + } + + /** + * import 标签解析 + * + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @param boolean $isFile 是否文件方式 + * @param string $type 类型 + * @return string + */ + public function _import($tag,$content,$isFile=false,$type='') { + $file = isset($tag['file'])?$tag['file']:$tag['href']; + $parseStr = ''; + $endStr = ''; + // 判断是否存在加载条件 允许使用函数判断(默认为isset) + if (isset($tag['value'])) { + $varArray = explode('|',$tag['value']); + $name = array_shift($varArray); + $name = $this->autoBuildVar($name); + if (!empty($varArray)) + $name = $this->tpl->parseVarFunction($name,$varArray); + else + $name = 'isset('.$name.')'; + $parseStr .= ''; + $endStr = ''; + } + if($isFile) { + // 根据文件名后缀自动识别 + $type = $type?$type:(!empty($tag['type'])?strtolower($tag['type']):null); + // 文件方式导入 + $array = explode(',',$file); + foreach ($array as $val){ + if (!$type || isset($reset)) { + $type = $reset = strtolower(substr(strrchr($val, '.'),1)); + } + switch($type) { + case 'js': + $parseStr .= ''; + break; + case 'css': + $parseStr .= ''; + break; + case 'php': + $parseStr .= ''; + break; + } + } + }else{ + // 命名空间导入模式 默认是js + $type = $type?$type:(!empty($tag['type'])?strtolower($tag['type']):'js'); + $basepath = !empty($tag['basepath'])?$tag['basepath']:__ROOT__.'/Public'; + // 命名空间方式导入外部文件 + $array = explode(',',$file); + foreach ($array as $val){ + if(strpos ($val, '?')) { + list($val,$version) = explode('?',$val); + } else { + $version = ''; + } + switch($type) { + case 'js': + $parseStr .= ''; + break; + case 'css': + $parseStr .= ''; + break; + case 'php': + $parseStr .= ''; + break; + } + } + } + return $parseStr.$endStr; + } + + // import别名 采用文件方式加载(要使用命名空间必须用import) 例如 + public function _load($tag,$content) { + return $this->_import($tag,$content,true); + } + + // import别名使用 导入css文件 + public function _css($tag,$content) { + return $this->_import($tag,$content,true,'css'); + } + + // import别名使用 导入js文件 + public function _js($tag,$content) { + return $this->_import($tag,$content,true,'js'); + } + + /** + * assign标签解析 + * 在模板中给某个变量赋值 支持变量赋值 + * 格式: + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _assign($tag,$content) { + $name = $this->autoBuildVar($tag['name']); + if('$'==substr($tag['value'],0,1)) { + $value = $this->autoBuildVar(substr($tag['value'],1)); + }else{ + $value = '\''.$tag['value']. '\''; + } + $parseStr = ''; + return $parseStr; + } + + /** + * define标签解析 + * 在模板中定义常量 支持变量赋值 + * 格式: + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _define($tag,$content) { + $name = '\''.$tag['name']. '\''; + if('$'==substr($tag['value'],0,1)) { + $value = $this->autoBuildVar(substr($tag['value'],1)); + }else{ + $value = '\''.$tag['value']. '\''; + } + $parseStr = ''; + return $parseStr; + } + + /** + * for标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @param string $content 标签内容 + * @return string + */ + public function _for($tag, $content){ + //设置默认值 + $start = 0; + $end = 0; + $step = 1; + $comparison = 'lt'; + $name = 'i'; + $rand = rand(); //添加随机数,防止嵌套变量冲突 + //获取属性 + foreach ($tag as $key => $value){ + $value = trim($value); + if(':'==substr($value,0,1)) + $value = substr($value,1); + elseif('$'==substr($value,0,1)) + $value = $this->autoBuildVar(substr($value,1)); + switch ($key){ + case 'start': + $start = $value; break; + case 'end' : + $end = $value; break; + case 'step': + $step = $value; break; + case 'comparison': + $comparison = $value; break; + case 'name': + $name = $value; break; + } + } + + $parseStr = 'parseCondition('$'.$name.' '.$comparison.' $__FOR_END_'.$rand.'__').';$'.$name.'+='.$step.'){ ?>'; + $parseStr .= $content; + $parseStr .= ''; + return $parseStr; + } + +} diff --git a/ThinkPHP/Library/Think/Template/TagLib/Html.class.php b/ThinkPHP/Library/Think/Template/TagLib/Html.class.php new file mode 100644 index 0000000..4b39499 --- /dev/null +++ b/ThinkPHP/Library/Think/Template/TagLib/Html.class.php @@ -0,0 +1,523 @@ + +// +---------------------------------------------------------------------- +namespace Think\Template\TagLib; +use Think\Template\TagLib; +/** + * Html标签库驱动 + */ +class Html extends TagLib{ + // 标签定义 + protected $tags = array( + // 标签定义: attr 属性列表 close 是否闭合(0 或者1 默认1) alias 标签别名 level 嵌套层次 + 'editor' => array('attr'=>'id,name,style,width,height,type','close'=>1), + 'select' => array('attr'=>'name,options,values,output,multiple,id,size,first,change,selected,dblclick','close'=>0), + 'grid' => array('attr'=>'id,pk,style,action,actionlist,show,datasource','close'=>0), + 'list' => array('attr'=>'id,pk,style,action,actionlist,show,datasource,checkbox','close'=>0), + 'imagebtn' => array('attr'=>'id,name,value,type,style,click','close'=>0), + 'checkbox' => array('attr'=>'name,checkboxes,checked,separator','close'=>0), + 'radio' => array('attr'=>'name,radios,checked,separator','close'=>0) + ); + + /** + * editor标签解析 插入可视化编辑器 + * 格式: {$vo.remark} + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _editor($tag,$content) { + $id = !empty($tag['id'])?$tag['id']: '_editor'; + $name = $tag['name']; + $style = !empty($tag['style'])?$tag['style']:''; + $width = !empty($tag['width'])?$tag['width']: '100%'; + $height = !empty($tag['height'])?$tag['height'] :'320px'; + // $content = $tag['content']; + $type = $tag['type'] ; + switch(strtoupper($type)) { + case 'FCKEDITOR': + $parseStr = ' '; + break; + case 'FCKMINI': + $parseStr = ' '; + break; + case 'EWEBEDITOR': + $parseStr = ""; + break; + case 'NETEASE': + $parseStr = ''; + break; + case 'UBB': + $parseStr = '
'; + break; + case 'KINDEDITOR': + $parseStr = ''; + break; + default : + $parseStr = ''; + } + + return $parseStr; + } + + /** + * imageBtn标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _imageBtn($tag) { + $name = $tag['name']; //名称 + $value = $tag['value']; //文字 + $id = isset($tag['id'])?$tag['id']:''; //ID + $style = isset($tag['style'])?$tag['style']:''; //样式名 + $click = isset($tag['click'])?$tag['click']:''; //点击 + $type = empty($tag['type'])?'button':$tag['type']; //按钮类型 + + if(!empty($name)) { + $parseStr = '
'; + }else { + $parseStr = '
'; + } + + return $parseStr; + } + + /** + * imageLink标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _imgLink($tag) { + $name = $tag['name']; //名称 + $alt = $tag['alt']; //文字 + $id = $tag['id']; //ID + $style = $tag['style']; //样式名 + $click = $tag['click']; //点击 + $type = $tag['type']; //点击 + if(empty($type)) { + $type = 'button'; + } + $parseStr = ''; + + return $parseStr; + } + + /** + * select标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _select($tag) { + $name = $tag['name']; + $options = $tag['options']; + $values = $tag['values']; + $output = $tag['output']; + $multiple = $tag['multiple']; + $id = $tag['id']; + $size = $tag['size']; + $first = $tag['first']; + $selected = $tag['selected']; + $style = $tag['style']; + $ondblclick = $tag['dblclick']; + $onchange = $tag['change']; + + if(!empty($multiple)) { + $parseStr = ''; + } + if(!empty($first)) { + $parseStr .= ''; + } + if(!empty($options)) { + $parseStr .= '$val) { ?>'; + if(!empty($selected)) { + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + }else { + $parseStr .= ''; + } + $parseStr .= ''; + }else if(!empty($values)) { + $parseStr .= ''; + if(!empty($selected)) { + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + }else { + $parseStr .= ''; + } + $parseStr .= ''; + } + $parseStr .= ''; + return $parseStr; + } + + /** + * checkbox标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _checkbox($tag) { + $name = $tag['name']; + $checkboxes = $tag['checkboxes']; + $checked = $tag['checked']; + $separator = $tag['separator']; + $checkboxes = $this->tpl->get($checkboxes); + $checked = $this->tpl->get($checked)?$this->tpl->get($checked):$checked; + $parseStr = ''; + foreach($checkboxes as $key=>$val) { + if($checked == $key || in_array($key,$checked) ) { + $parseStr .= ''.$val.$separator; + }else { + $parseStr .= ''.$val.$separator; + } + } + return $parseStr; + } + + /** + * radio标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string|void + */ + public function _radio($tag) { + $name = $tag['name']; + $radios = $tag['radios']; + $checked = $tag['checked']; + $separator = $tag['separator']; + $radios = $this->tpl->get($radios); + $checked = $this->tpl->get($checked)?$this->tpl->get($checked):$checked; + $parseStr = ''; + foreach($radios as $key=>$val) { + if($checked == $key ) { + $parseStr .= ''.$val.$separator; + }else { + $parseStr .= ''.$val.$separator; + } + + } + return $parseStr; + } + + /** + * list标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string + */ + public function _grid($tag) { + $id = $tag['id']; //表格ID + $datasource = $tag['datasource']; //列表显示的数据源VoList名称 + $pk = empty($tag['pk'])?'id':$tag['pk'];//主键名,默认为id + $style = $tag['style']; //样式名 + $name = !empty($tag['name'])?$tag['name']:'vo'; //Vo对象名 + $action = !empty($tag['action'])?$tag['action']:false; //是否显示功能操作 + $key = !empty($tag['key'])?true:false; + if(isset($tag['actionlist'])) { + $actionlist = explode(',',trim($tag['actionlist'])); //指定功能列表 + } + + if(substr($tag['show'],0,1)=='$') { + $show = $this->tpl->get(substr($tag['show'],1)); + }else { + $show = $tag['show']; + } + $show = explode(',',$show); //列表显示字段列表 + + //计算表格的列数 + $colNum = count($show); + if(!empty($action)) $colNum++; + if(!empty($key)) $colNum++; + + //显示开始 + $parseStr = "\n"; + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + //列表需要显示的字段 + $fields = array(); + foreach($show as $val) { + $fields[] = explode(':',$val); + } + + if(!empty($key)) { + $parseStr .= ''; + } + foreach($fields as $field) {//显示指定的字段 + $property = explode('|',$field[0]); + $showname = explode('|',$field[1]); + if(isset($showname[1])) { + $parseStr .= ''; + } + if(!empty($action)) {//如果指定显示操作功能列 + $parseStr .= ''; + } + $parseStr .= ''; + $parseStr .= ''; //支持鼠标移动单元行颜色变化 具体方法在js中定义 + + if(!empty($key)) { + $parseStr .= ''; + } + foreach($fields as $field) { + //显示定义的列表字段 + $parseStr .= ''; + + } + if(!empty($action)) {//显示功能操作 + if(!empty($actionlist[0])) {//显示指定的功能项 + $parseStr .= ''; + } + } + $parseStr .= '
No'; + }else { + $parseStr .= ''; + } + $parseStr .= $showname[0].'操作
{$i}'; + if(!empty($field[2])) { + // 支持列表字段链接功能 具体方法由JS函数实现 + $href = explode('|',$field[2]); + if(count($href)>1) { + //指定链接传的字段值 + // 支持多个字段传递 + $array = explode('^',$href[1]); + if(count($array)>1) { + foreach ($array as $a){ + $temp[] = '\'{$'.$name.'.'.$a.'|addslashes}\''; + } + $parseStr .= ''; + }else{ + $parseStr .= ''; + } + }else { + //如果没有指定默认传编号值 + $parseStr .= ''; + } + } + if(strpos($field[0],'^')) { + $property = explode('^',$field[0]); + foreach ($property as $p){ + $unit = explode('|',$p); + if(count($unit)>1) { + $parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} '; + }else { + $parseStr .= '{$'.$name.'.'.$p.'} '; + } + } + }else{ + $property = explode('|',$field[0]); + if(count($property)>1) { + $parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}'; + }else { + $parseStr .= '{$'.$name.'.'.$field[0].'}'; + } + } + if(!empty($field[2])) { + $parseStr .= ''; + } + $parseStr .= ''; + foreach($actionlist as $val) { + if(strpos($val,':')) { + $a = explode(':',$val); + if(count($a)>2) { + $parseStr .= ''.$a[1].' '; + }else { + $parseStr .= ''.$a[1].' '; + } + }else{ + $array = explode('|',$val); + if(count($array)>2) { + $parseStr .= ' '.$array[2].' '; + }else{ + $parseStr .= ' {$'.$name.'.'.$val.'} '; + } + } + } + $parseStr .= '
'; + $parseStr .= "\n\n"; + return $parseStr; + } + + /** + * list标签解析 + * 格式: + * @access public + * @param array $tag 标签属性 + * @return string + */ + public function _list($tag) { + $id = $tag['id']; //表格ID + $datasource = $tag['datasource']; //列表显示的数据源VoList名称 + $pk = empty($tag['pk'])?'id':$tag['pk'];//主键名,默认为id + $style = $tag['style']; //样式名 + $name = !empty($tag['name'])?$tag['name']:'vo'; //Vo对象名 + $action = $tag['action']=='true'?true:false; //是否显示功能操作 + $key = !empty($tag['key'])?true:false; + $sort = $tag['sort']=='false'?false:true; + $checkbox = $tag['checkbox']; //是否显示Checkbox + if(isset($tag['actionlist'])) { + if(substr($tag['actionlist'],0,1)=='$') { + $actionlist = $this->tpl->get(substr($tag['actionlist'],1)); + }else { + $actionlist = $tag['actionlist']; + } + $actionlist = explode(',',trim($actionlist)); //指定功能列表 + } + + if(substr($tag['show'],0,1)=='$') { + $show = $this->tpl->get(substr($tag['show'],1)); + }else { + $show = $tag['show']; + } + $show = explode(',',$show); //列表显示字段列表 + + //计算表格的列数 + $colNum = count($show); + if(!empty($checkbox)) $colNum++; + if(!empty($action)) $colNum++; + if(!empty($key)) $colNum++; + + //显示开始 + $parseStr = "\n"; + $parseStr .= ''; + $parseStr .= ''; + $parseStr .= ''; + //列表需要显示的字段 + $fields = array(); + foreach($show as $val) { + $fields[] = explode(':',$val); + } + if(!empty($checkbox) && 'true'==strtolower($checkbox)) {//如果指定需要显示checkbox列 + $parseStr .=''; + } + if(!empty($key)) { + $parseStr .= ''; + } + foreach($fields as $field) {//显示指定的字段 + $property = explode('|',$field[0]); + $showname = explode('|',$field[1]); + if(isset($showname[1])) { + $parseStr .= ''; + }else{ + $parseStr .= $showname[0].''; + } + + } + if(!empty($action)) {//如果指定显示操作功能列 + $parseStr .= ''; + } + + $parseStr .= ''; + $parseStr .= ''; + } + if(!empty($key)) { + $parseStr .= ''; + } + foreach($fields as $field) { + //显示定义的列表字段 + $parseStr .= ''; + + } + if(!empty($action)) {//显示功能操作 + if(!empty($actionlist[0])) {//显示指定的功能项 + $parseStr .= ''; + } + } + $parseStr .= '
No'; + }else { + $parseStr .= ''; + } + $showname[2] = isset($showname[2])?$showname[2]:$showname[0]; + if($sort) { + $parseStr .= ''.$showname[0].'操作
{$i}'; + if(!empty($field[2])) { + // 支持列表字段链接功能 具体方法由JS函数实现 + $href = explode('|',$field[2]); + if(count($href)>1) { + //指定链接传的字段值 + // 支持多个字段传递 + $array = explode('^',$href[1]); + if(count($array)>1) { + foreach ($array as $a){ + $temp[] = '\'{$'.$name.'.'.$a.'|addslashes}\''; + } + $parseStr .= ''; + }else{ + $parseStr .= ''; + } + }else { + //如果没有指定默认传编号值 + $parseStr .= ''; + } + } + if(strpos($field[0],'^')) { + $property = explode('^',$field[0]); + foreach ($property as $p){ + $unit = explode('|',$p); + if(count($unit)>1) { + $parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} '; + }else { + $parseStr .= '{$'.$name.'.'.$p.'} '; + } + } + }else{ + $property = explode('|',$field[0]); + if(count($property)>1) { + $parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}'; + }else { + $parseStr .= '{$'.$name.'.'.$field[0].'}'; + } + } + if(!empty($field[2])) { + $parseStr .= ''; + } + $parseStr .= ''; + foreach($actionlist as $val) { + if(strpos($val,':')) { + $a = explode(':',$val); + if(count($a)>2) { + $parseStr .= ''.$a[1].' '; + }else { + $parseStr .= ''.$a[1].' '; + } + }else{ + $array = explode('|',$val); + if(count($array)>2) { + $parseStr .= ' '.$array[2].' '; + }else{ + $parseStr .= ' {$'.$name.'.'.$val.'} '; + } + } + } + $parseStr .= '
'; + $parseStr .= "\n\n"; + return $parseStr; + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Think.class.php b/ThinkPHP/Library/Think/Think.class.php new file mode 100644 index 0000000..3bd1864 --- /dev/null +++ b/ThinkPHP/Library/Think/Think.class.php @@ -0,0 +1,344 @@ + +// +---------------------------------------------------------------------- + +namespace Think; +/** + * ThinkPHP 引导类 + */ +class Think { + + // 类映射 + private static $_map = array(); + + // 实例化对象 + private static $_instance = array(); + + /** + * 应用程序初始化 + * @access public + * @return void + */ + static public function start() { + // 注册AUTOLOAD方法 + spl_autoload_register('Think\Think::autoload'); + // 设定错误和异常处理 + register_shutdown_function('Think\Think::fatalError'); + set_error_handler('Think\Think::appError'); + set_exception_handler('Think\Think::appException'); + + // 初始化文件存储方式 + Storage::connect(STORAGE_TYPE); + + $runtimefile = RUNTIME_PATH.APP_MODE.'~runtime.php'; + if(!APP_DEBUG && Storage::has($runtimefile)){ + Storage::load($runtimefile); + }else{ + if(Storage::has($runtimefile)) + Storage::unlink($runtimefile); + $content = ''; + // 读取应用模式 + $mode = include is_file(CONF_PATH.'core.php')?CONF_PATH.'core.php':MODE_PATH.APP_MODE.'.php'; + // 加载核心文件 + foreach ($mode['core'] as $file){ + if(is_file($file)) { + include $file; + if(!APP_DEBUG) $content .= compile($file); + } + } + + // 加载应用模式配置文件 + foreach ($mode['config'] as $key=>$file){ + is_numeric($key)?C(load_config($file)):C($key,load_config($file)); + } + + // 读取当前应用模式对应的配置文件 + if('common' != APP_MODE && is_file(CONF_PATH.'config_'.APP_MODE.CONF_EXT)) + C(load_config(CONF_PATH.'config_'.APP_MODE.CONF_EXT)); + + // 加载模式别名定义 + if(isset($mode['alias'])){ + self::addMap(is_array($mode['alias'])?$mode['alias']:include $mode['alias']); + } + + // 加载应用别名定义文件 + if(is_file(CONF_PATH.'alias.php')) + self::addMap(include CONF_PATH.'alias.php'); + + // 加载模式行为定义 + if(isset($mode['tags'])) { + Hook::import(is_array($mode['tags'])?$mode['tags']:include $mode['tags']); + } + + // 加载应用行为定义 + if(is_file(CONF_PATH.'tags.php')) + // 允许应用增加开发模式配置定义 + Hook::import(include CONF_PATH.'tags.php'); + + // 加载框架底层语言包 + L(include THINK_PATH.'Lang/'.strtolower(C('DEFAULT_LANG')).'.php'); + + if(!APP_DEBUG){ + $content .= "\nnamespace { Think\\Think::addMap(".var_export(self::$_map,true).");"; + $content .= "\nL(".var_export(L(),true).");\nC(".var_export(C(),true).');Think\Hook::import('.var_export(Hook::get(),true).');}'; + Storage::put($runtimefile,strip_whitespace('getMessage(); + $trace = $e->getTrace(); + if('E'==$trace[0]['function']) { + $error['file'] = $trace[0]['file']; + $error['line'] = $trace[0]['line']; + }else{ + $error['file'] = $e->getFile(); + $error['line'] = $e->getLine(); + } + $error['trace'] = $e->getTraceAsString(); + Log::record($error['message'],Log::ERR); + // 发送404信息 + header('HTTP/1.1 404 Not Found'); + header('Status:404 Not Found'); + self::halt($error); + } + + /** + * 自定义错误处理 + * @access public + * @param int $errno 错误类型 + * @param string $errstr 错误信息 + * @param string $errfile 错误文件 + * @param int $errline 错误行数 + * @return void + */ + static public function appError($errno, $errstr, $errfile, $errline) { + switch ($errno) { + case E_ERROR: + case E_PARSE: + case E_CORE_ERROR: + case E_COMPILE_ERROR: + case E_USER_ERROR: + ob_end_clean(); + $errorStr = "$errstr ".$errfile." 第 $errline 行."; + if(C('LOG_RECORD')) Log::write("[$errno] ".$errorStr,Log::ERR); + self::halt($errorStr); + break; + default: + $errorStr = "[$errno] $errstr ".$errfile." 第 $errline 行."; + self::trace($errorStr,'','NOTIC'); + break; + } + } + + // 致命错误捕获 + static public function fatalError() { + Log::save(); + if ($e = error_get_last()) { + switch($e['type']){ + case E_ERROR: + case E_PARSE: + case E_CORE_ERROR: + case E_COMPILE_ERROR: + case E_USER_ERROR: + ob_end_clean(); + self::halt($e); + break; + } + } + } + + /** + * 错误输出 + * @param mixed $error 错误 + * @return void + */ + static public function halt($error) { + $e = array(); + if (APP_DEBUG || IS_CLI) { + //调试模式下输出错误信息 + if (!is_array($error)) { + $trace = debug_backtrace(); + $e['message'] = $error; + $e['file'] = $trace[0]['file']; + $e['line'] = $trace[0]['line']; + ob_start(); + debug_print_backtrace(); + $e['trace'] = ob_get_clean(); + } else { + $e = $error; + } + if(IS_CLI){ + exit(iconv('UTF-8','gbk',$e['message']).PHP_EOL.'FILE: '.$e['file'].'('.$e['line'].')'.PHP_EOL.$e['trace']); + } + } else { + //否则定向到错误页面 + $error_page = C('ERROR_PAGE'); + if (!empty($error_page)) { + redirect($error_page); + } else { + $message = is_array($error) ? $error['message'] : $error; + $e['message'] = C('SHOW_ERROR_MSG')? $message : C('ERROR_MESSAGE'); + } + } + // 包含异常页面模板 + $exceptionFile = C('TMPL_EXCEPTION_FILE',null,THINK_PATH.'Tpl/think_exception.tpl'); + include $exceptionFile; + exit; + } + + /** + * 添加和获取页面Trace记录 + * @param string $value 变量 + * @param string $label 标签 + * @param string $level 日志级别(或者页面Trace的选项卡) + * @param boolean $record 是否记录日志 + * @return void|array + */ + static public function trace($value='[think]',$label='',$level='DEBUG',$record=false) { + static $_trace = array(); + if('[think]' === $value){ // 获取trace信息 + return $_trace; + }else{ + $info = ($label?$label.':':'').print_r($value,true); + $level = strtoupper($level); + + if((defined('IS_AJAX') && IS_AJAX) || !C('SHOW_PAGE_TRACE') || $record) { + Log::record($info,$level,$record); + }else{ + if(!isset($_trace[$level]) || count($_trace[$level])>C('TRACE_MAX_RECORD')) { + $_trace[$level] = array(); + } + $_trace[$level][] = $info; + } + } + } +} diff --git a/ThinkPHP/Library/Think/Upload.class.php b/ThinkPHP/Library/Think/Upload.class.php new file mode 100644 index 0000000..89a04ac --- /dev/null +++ b/ThinkPHP/Library/Think/Upload.class.php @@ -0,0 +1,429 @@ + +// +---------------------------------------------------------------------- +namespace Think; +class Upload { + /** + * 默认上传配置 + * @var array + */ + private $config = array( + 'mimes' => array(), //允许上传的文件MiMe类型 + 'maxSize' => 0, //上传的文件大小限制 (0-不做限制) + 'exts' => array(), //允许上传的文件后缀 + 'autoSub' => true, //自动子目录保存文件 + 'subName' => array('date', 'Y-m-d'), //子目录创建方式,[0]-函数名,[1]-参数,多个参数使用数组 + 'rootPath' => './Uploads/', //保存根路径 + 'savePath' => '', //保存路径 + 'saveName' => array('uniqid', ''), //上传文件命名规则,[0]-函数名,[1]-参数,多个参数使用数组 + 'saveExt' => '', //文件保存后缀,空则使用原后缀 + 'replace' => false, //存在同名是否覆盖 + 'hash' => true, //是否生成hash编码 + 'callback' => false, //检测文件是否存在回调,如果存在返回文件信息数组 + 'driver' => '', // 文件上传驱动 + 'driverConfig' => array(), // 上传驱动配置 + ); + + /** + * 上传错误信息 + * @var string + */ + private $error = ''; //上传错误信息 + + /** + * 上传驱动实例 + * @var Object + */ + private $uploader; + + /** + * 构造方法,用于构造上传实例 + * @param array $config 配置 + * @param string $driver 要使用的上传驱动 LOCAL-本地上传驱动,FTP-FTP上传驱动 + */ + public function __construct($config = array(), $driver = '', $driverConfig = null){ + /* 获取配置 */ + $this->config = array_merge($this->config, $config); + + /* 设置上传驱动 */ + $this->setDriver($driver, $driverConfig); + + /* 调整配置,把字符串配置参数转换为数组 */ + if(!empty($this->config['mimes'])){ + if(is_string($this->mimes)) { + $this->config['mimes'] = explode(',', $this->mimes); + } + $this->config['mimes'] = array_map('strtolower', $this->mimes); + } + if(!empty($this->config['exts'])){ + if (is_string($this->exts)){ + $this->config['exts'] = explode(',', $this->exts); + } + $this->config['exts'] = array_map('strtolower', $this->exts); + } + } + + /** + * 使用 $this->name 获取配置 + * @param string $name 配置名称 + * @return multitype 配置值 + */ + public function __get($name) { + return $this->config[$name]; + } + + public function __set($name,$value){ + if(isset($this->config[$name])) { + $this->config[$name] = $value; + if($name == 'driverConfig'){ + //改变驱动配置后重置上传驱动 + //注意:必须选改变驱动然后再改变驱动配置 + $this->setDriver(); + } + } + } + + public function __isset($name){ + return isset($this->config[$name]); + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + + /** + * 上传单个文件 + * @param array $file 文件数组 + * @return array 上传成功后的文件信息 + */ + public function uploadOne($file){ + $info = $this->upload(array($file)); + return $info ? $info[0] : $info; + } + + /** + * 上传文件 + * @param 文件信息数组 $files ,通常是 $_FILES数组 + */ + public function upload($files='') { + if('' === $files){ + $files = $_FILES; + } + if(empty($files)){ + $this->error = '没有上传的文件!'; + return false; + } + + /* 检测上传根目录 */ + if(!$this->uploader->checkRootPath($this->rootPath)){ + $this->error = $this->uploader->getError(); + return false; + } + + /* 检查上传目录 */ + if(!$this->uploader->checkSavePath($this->savePath)){ + $this->error = $this->uploader->getError(); + return false; + } + + /* 逐个检测并上传文件 */ + $info = array(); + if(function_exists('finfo_open')){ + $finfo = finfo_open ( FILEINFO_MIME_TYPE ); + } + // 对上传文件数组信息处理 + $files = $this->dealFiles($files); + foreach ($files as $key => $file) { + $file['name'] = strip_tags($file['name']); + if(!isset($file['key'])) $file['key'] = $key; + /* 通过扩展获取文件类型,可解决FLASH上传$FILES数组返回文件类型错误的问题 */ + if(isset($finfo)){ + $file['type'] = finfo_file ( $finfo , $file['tmp_name'] ); + } + + /* 获取上传文件后缀,允许上传无后缀文件 */ + $file['ext'] = pathinfo($file['name'], PATHINFO_EXTENSION); + + /* 文件上传检测 */ + if (!$this->check($file)){ + continue; + } + + /* 获取文件hash */ + if($this->hash){ + $file['md5'] = md5_file($file['tmp_name']); + $file['sha1'] = sha1_file($file['tmp_name']); + } + + /* 调用回调函数检测文件是否存在 */ + $data = call_user_func($this->callback, $file); + if( $this->callback && $data ){ + if ( file_exists('.'.$data['path']) ) { + $info[$key] = $data; + continue; + }elseif($this->removeTrash){ + call_user_func($this->removeTrash,$data);//删除垃圾据 + } + } + + /* 生成保存文件名 */ + $savename = $this->getSaveName($file); + if(false == $savename){ + continue; + } else { + $file['savename'] = $savename; + } + + /* 检测并创建子目录 */ + $subpath = $this->getSubPath($file['name']); + if(false === $subpath){ + continue; + } else { + $file['savepath'] = $this->savePath . $subpath; + } + + /* 对图像文件进行严格检测 */ + $ext = strtolower($file['ext']); + if(in_array($ext, array('gif','jpg','jpeg','bmp','png','swf'))) { + $imginfo = getimagesize($file['tmp_name']); + if(empty($imginfo) || ($ext == 'gif' && empty($imginfo['bits']))){ + $this->error = '非法图像文件!'; + continue; + } + } + + /* 保存文件 并记录保存成功的文件 */ + if ($this->uploader->save($file,$this->replace)) { + unset($file['error'], $file['tmp_name']); + $info[$key] = $file; + } else { + $this->error = $this->uploader->getError(); + } + } + if(isset($finfo)){ + finfo_close($finfo); + } + return empty($info) ? false : $info; + } + + /** + * 转换上传文件数组变量为正确的方式 + * @access private + * @param array $files 上传的文件变量 + * @return array + */ + private function dealFiles($files) { + $fileArray = array(); + $n = 0; + foreach ($files as $key=>$file){ + if(is_array($file['name'])) { + $keys = array_keys($file); + $count = count($file['name']); + for ($i=0; $i<$count; $i++) { + $fileArray[$n]['key'] = $key; + foreach ($keys as $_key){ + $fileArray[$n][$_key] = $file[$_key][$i]; + } + $n++; + } + }else{ + $fileArray = $files; + break; + } + } + return $fileArray; + } + + /** + * 设置上传驱动 + * @param string $driver 驱动名称 + * @param array $config 驱动配置 + */ + private function setDriver($driver = null, $config = null){ + $driver = $driver ? : ($this->driver ? : C('FILE_UPLOAD_TYPE')); + $config = $config ? : ($this->driverConfig ? : C('UPLOAD_TYPE_CONFIG')); + $class = strpos($driver,'\\')? $driver : 'Think\\Upload\\Driver\\'.ucfirst(strtolower($driver)); + $this->uploader = new $class($config); + if(!$this->uploader){ + E("不存在上传驱动:{$name}"); + } + } + + /** + * 检查上传的文件 + * @param array $file 文件信息 + */ + private function check($file) { + /* 文件上传失败,捕获错误代码 */ + if ($file['error']) { + $this->error($file['error']); + return false; + } + + /* 无效上传 */ + if (empty($file['name'])){ + $this->error = '未知上传错误!'; + } + + /* 检查是否合法上传 */ + if (!is_uploaded_file($file['tmp_name'])) { + $this->error = '非法上传文件!'; + return false; + } + + /* 检查文件大小 */ + if (!$this->checkSize($file['size'])) { + $this->error = '上传文件大小不符!'; + return false; + } + + /* 检查文件Mime类型 */ + //TODO:FLASH上传的文件获取到的mime类型都为application/octet-stream + if (!$this->checkMime($file['type'])) { + $this->error = '上传文件MIME类型不允许!'; + return false; + } + + /* 检查文件后缀 */ + if (!$this->checkExt($file['ext'])) { + $this->error = '上传文件后缀不允许'; + return false; + } + + /* 通过检测 */ + return true; + } + + + /** + * 获取错误代码信息 + * @param string $errorNo 错误号 + */ + private function error($errorNo) { + switch ($errorNo) { + case 1: + $this->error = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值!'; + break; + case 2: + $this->error = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值!'; + break; + case 3: + $this->error = '文件只有部分被上传!'; + break; + case 4: + $this->error = '没有文件被上传!'; + break; + case 6: + $this->error = '找不到临时文件夹!'; + break; + case 7: + $this->error = '文件写入失败!'; + break; + default: + $this->error = '未知上传错误!'; + } + } + + /** + * 检查文件大小是否合法 + * @param integer $size 数据 + */ + private function checkSize($size) { + return !($size > $this->maxSize) || (0 == $this->maxSize); + } + + /** + * 检查上传的文件MIME类型是否合法 + * @param string $mime 数据 + */ + private function checkMime($mime) { + return empty($this->config['mimes']) ? true : in_array(strtolower($mime), $this->mimes); + } + + /** + * 检查上传的文件后缀是否合法 + * @param string $ext 后缀 + */ + private function checkExt($ext) { + return empty($this->config['exts']) ? true : in_array(strtolower($ext), $this->exts); + } + + /** + * 根据上传文件命名规则取得保存文件名 + * @param string $file 文件信息 + */ + private function getSaveName($file) { + $rule = $this->saveName; + if (empty($rule)) { //保持文件名不变 + /* 解决pathinfo中文文件名BUG */ + $filename = substr(pathinfo("_{$file['name']}", PATHINFO_FILENAME), 1); + $savename = $filename; + } else { + $savename = $this->getName($rule, $file['name']); + if(empty($savename)){ + $this->error = '文件命名规则错误!'; + return false; + } + } + + /* 文件保存后缀,支持强制更改文件后缀 */ + $ext = empty($this->config['saveExt']) ? $file['ext'] : $this->saveExt; + + return $savename . '.' . $ext; + } + + /** + * 获取子目录的名称 + * @param array $file 上传的文件信息 + */ + private function getSubPath($filename) { + $subpath = ''; + $rule = $this->subName; + if ($this->autoSub && !empty($rule)) { + $subpath = $this->getName($rule, $filename) . '/'; + + if(!empty($subpath) && !$this->uploader->mkdir($this->savePath . $subpath)){ + $this->error = $this->uploader->getError(); + return false; + } + } + return $subpath; + } + + /** + * 根据指定的规则获取文件或目录名称 + * @param array $rule 规则 + * @param string $filename 原文件名 + * @return string 文件或目录名称 + */ + private function getName($rule, $filename){ + $name = ''; + if(is_array($rule)){ //数组规则 + $func = $rule[0]; + $param = (array)$rule[1]; + foreach ($param as &$value) { + $value = str_replace('__FILE__', $filename, $value); + } + $name = call_user_func_array($func, $param); + } elseif (is_string($rule)){ //字符串规则 + if(function_exists($rule)){ + $name = call_user_func($rule); + } else { + $name = $rule; + } + } + return $name; + } + +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Bcs.class.php b/ThinkPHP/Library/Think/Upload/Driver/Bcs.class.php new file mode 100644 index 0000000..437fefd --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Bcs.class.php @@ -0,0 +1,238 @@ + +// +---------------------------------------------------------------------- +namespace Think\Upload\Driver; +use Think\Upload\Driver\Bcs\BaiduBcs; +class Bcs { + /** + * 上传文件根目录 + * @var string + */ + private $rootPath; + const DEFAULT_URL = 'bcs.duapp.com'; + + /** + * 上传错误信息 + * @var string + */ + private $error = ''; + + public $config = array( + 'AccessKey'=> '', + 'SecretKey'=> '', //百度云服务器 + 'bucket' => '', //空间名称 + 'rename' => false, + 'timeout' => 3600, //超时时间 + ); + + public $bcs = null; + + /** + * 构造函数,用于设置上传根路径 + * @param array $config FTP配置 + */ + public function __construct($config){ + /* 默认FTP配置 */ + $this->config = array_merge($this->config, $config); + + $bcsClass = dirname(__FILE__). "/Bcs/bcs.class.php"; + if(is_file($bcsClass)) + require_once($bcsClass); + $this->bcs = new BaiduBCS ( $this->config['AccessKey'], $this->config['SecretKey'], self:: DEFAULT_URL ); + } + + /** + * 检测上传根目录(百度云上传时支持自动创建目录,直接返回) + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + /* 设置根目录 */ + $this->rootPath = str_replace('./', '/', $rootpath); + return true; + } + + /** + * 检测上传目录(百度云上传时支持自动创建目录,直接返回) + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + return true; + } + + /** + * 创建文件夹 (百度云上传时支持自动创建目录,直接返回) + * @param string $savepath 目录名称 + * @return boolean true-创建成功,false-创建失败 + */ + public function mkdir($savepath){ + return true; + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save(&$file,$replace=true) { + $opt = array (); + $opt ['acl'] = BaiduBCS::BCS_SDK_ACL_TYPE_PUBLIC_WRITE; + $opt ['curlopts'] = array ( + CURLOPT_CONNECTTIMEOUT => 10, + CURLOPT_TIMEOUT => 1800 + ); + $object = "/{$file['savepath']}{$file['savename']}"; + $response = $this->bcs->create_object ( $this->config['bucket'], $object, $file['tmp_name'], $opt ); + $url = $this->download($object); + $file['url'] = $url; + return $response->isOK() ? true : false; + } + + public function download($file){ + $file = str_replace('./', '/', $file); + $opt = array(); + $opt['time'] = mktime('2049-12-31'); //这是最长有效时间!-- + $response = $this->bcs->generate_get_object_url ( $this->config['bucket'], $file, $opt ); + return $response; + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + + /** + * 请求百度云服务器 + * @param string $path 请求的PATH + * @param string $method 请求方法 + * @param array $headers 请求header + * @param resource $body 上传文件资源 + * @return boolean + */ + private function request($path, $method, $headers = null, $body = null){ + $ch = curl_init($path); + + $_headers = array('Expect:'); + if (!is_null($headers) && is_array($headers)){ + foreach($headers as $k => $v) { + array_push($_headers, "{$k}: {$v}"); + } + } + + $length = 0; + $date = gmdate('D, d M Y H:i:s \G\M\T'); + + if (!is_null($body)) { + if(is_resource($body)){ + fseek($body, 0, SEEK_END); + $length = ftell($body); + fseek($body, 0); + + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_INFILE, $body); + curl_setopt($ch, CURLOPT_INFILESIZE, $length); + } else { + $length = @strlen($body); + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + } else { + array_push($_headers, "Content-Length: {$length}"); + } + + // array_push($_headers, 'Authorization: ' . $this->sign($method, $uri, $date, $length)); + array_push($_headers, "Date: {$date}"); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->config['timeout']); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + + if ($method == 'PUT' || $method == 'POST') { + curl_setopt($ch, CURLOPT_POST, 1); + } else { + curl_setopt($ch, CURLOPT_POST, 0); + } + + if ($method == 'HEAD') { + curl_setopt($ch, CURLOPT_NOBODY, true); + } + + $response = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + list($header, $body) = explode("\r\n\r\n", $response, 2); + + if ($status == 200) { + if ($method == 'GET') { + return $body; + } else { + $data = $this->response($header); + return count($data) > 0 ? $data : true; + } + } else { + $this->error($header); + return false; + } + } + + /** + * 获取响应数据 + * @param string $text 响应头字符串 + * @return array 响应数据列表 + */ + private function response($text){ + $items = json_decode($text, true); + return $items; + } + + /** + * 生成请求签名 + * @return string 请求签名 + */ + private function sign($method, $Bucket, $object='/', $size=''){ + if(!$size) + $size = $this->config['size']; + $param = array( + 'ak'=>$this->config['AccessKey'], + 'sk'=>$this->config['SecretKey'], + 'size'=>$size, + 'bucket'=>$Bucket, + 'host'=>self :: DEFAULT_URL, + 'date'=>time()+$this->config['timeout'], + 'ip'=>'', + 'object'=>$object + ); + $response = $this->request($this->apiurl.'?'.http_build_query($param), 'POST'); + if($response) + $response = json_decode($response, true); + return $response['content'][$method]; + } + + + /** + * 获取请求错误信息 + * @param string $header 请求返回头信息 + */ + private function error($header) { + list($status, $stash) = explode("\r\n", $header, 2); + list($v, $code, $message) = explode(" ", $status, 3); + $message = is_null($message) ? 'File Not Found' : "[{$status}]:{$message}"; + $this->error = $message; + } + +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Bcs/bcs.class.php b/ThinkPHP/Library/Think/Upload/Driver/Bcs/bcs.class.php new file mode 100644 index 0000000..a990aec --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Bcs/bcs.class.php @@ -0,0 +1,1318 @@ +ak = $ak; + $this->sk = $sk; + } elseif (defined ( 'BCS_AK' ) && defined ( 'BCS_SK' ) && strlen ( BCS_AK ) > 0 && strlen ( BCS_SK ) > 0) { + $this->ak = BCS_AK; + $this->sk = BCS_SK; + } elseif (false !== getenv ( 'HTTP_BAE_ENV_AK' ) && false !== getenv ( 'HTTP_BAE_ENV_SK' )) { + $this->ak = getenv ( 'HTTP_BAE_ENV_AK' ); + $this->sk = getenv ( 'HTTP_BAE_ENV_SK' ); + } else { + throw new BCS_Exception ( 'Construct can not get ak &sk pair, please check!' ); + } + //valid $hostname + if (NULL !== $hostname) { + $this->hostname = $hostname; + } elseif (false !== getenv ( 'HTTP_BAE_ENV_ADDR_BCS' )) { + $this->hostname = getenv ( 'HTTP_BAE_ENV_ADDR_BCS' ); + } else { + $this->hostname = self::DEFAULT_URL; + } + } + + /** + * 将消息发往Baidu BCS. + * @param array $opt + * @return BCS_ResponseCore + */ + private function authenticate($opt) { + //set common param into opt + $opt [self::AK] = $this->ak; + $opt [self::SK] = $this->sk; + + // Validate the S3 bucket name, only list_bucket didnot need validate_bucket + if (! ('/' == $opt [self::OBJECT] && '' == $opt [self::BUCKET] && 'GET' == $opt [self::METHOD] && ! isset ( $opt [self::QUERY_STRING] [self::ACL] )) && ! self::validate_bucket ( $opt [self::BUCKET] )) { + throw new BCS_Exception ( $opt [self::BUCKET] . 'is not valid, please check!' ); + } + //Validate object + if (isset ( $opt [self::OBJECT] ) && ! self::validate_object ( $opt [self::OBJECT] )) { + throw new BCS_Exception ( "Invalid object param[" . $opt [self::OBJECT] . "], please check.", - 1 ); + } + //construct url + $url = $this->format_url ( $opt ); + if ($url === false) { + throw new BCS_Exception ( 'Can not format url, please check your param!', - 1 ); + } + $opt ['url'] = $url; + $this->log ( "[method:" . $opt [self::METHOD] . "][url:$url]", $opt ); + //build request + $request = new BCS_RequestCore ( $opt ['url'] ); + $headers = array ( + 'Content-Type' => 'application/x-www-form-urlencoded' ); + + $request->set_method ( $opt [self::METHOD] ); + //Write get_object content to fileWriteTo + if (isset ( $opt ['fileWriteTo'] )) { + $request->set_write_file ( $opt ['fileWriteTo'] ); + } + // Merge the HTTP headers + if (isset ( $opt [self::HEADERS] )) { + $headers = array_merge ( $headers, $opt [self::HEADERS] ); + } + // Set content to Http-Body + if (isset ( $opt ['content'] )) { + $request->set_body ( $opt ['content'] ); + } + // Upload file + if (isset ( $opt ['fileUpload'] )) { + if (! file_exists ( $opt ['fileUpload'] )) { + throw new BCS_Exception ( 'File[' . $opt ['fileUpload'] . '] not found!', - 1 ); + } + $request->set_read_file ( $opt ['fileUpload'] ); + // Determine the length to read from the file + $length = $request->read_stream_size; // The file size by default + $file_size = $length; + if (isset ( $opt ["length"] )) { + if ($opt ["length"] > $file_size) { + throw new BCS_Exception ( "Input opt[length] invalid! It can not bigger than file-size", - 1 ); + } + $length = $opt ['length']; + } + if (isset ( $opt ['seekTo'] ) && ! isset ( $opt ["length"] )) { + // Read from seekTo until EOF by default, when set seekTo but not set $opt["length"] + $length -= ( integer ) $opt ['seekTo']; + } + $request->set_read_stream_size ( $length ); + // Attempt to guess the correct mime-type + if ($headers ['Content-Type'] === 'application/x-www-form-urlencoded') { + $extension = explode ( '.', $opt ['fileUpload'] ); + $extension = array_pop ( $extension ); + $mime_type = BCS_MimeTypes::get_mimetype ( $extension ); + $headers ['Content-Type'] = $mime_type; + } + $headers ['Content-MD5'] = ''; + } + // Handle streaming file offsets + if (isset ( $opt ['seekTo'] )) { + // Pass the seek position to BCS_RequestCore + $request->set_seek_position ( ( integer ) $opt ['seekTo'] ); + } + // Add headers to request and compute the string to sign + foreach ( $headers as $header_key => $header_value ) { + // Strip linebreaks from header values as they're illegal and can allow for security issues + $header_value = str_replace ( array ( + "\r", + "\n" ), '', $header_value ); + // Add the header if it has a value + if ($header_value !== '') { + $request->add_header ( $header_key, $header_value ); + } + } + // Set the curl options. + if (isset ( $opt ['curlopts'] ) && count ( $opt ['curlopts'] )) { + $request->set_curlopts ( $opt ['curlopts'] ); + } + $request->send_request (); + require_once(dirname(__FILE__). "/requestcore.class.php"); + return new BCS_ResponseCore ( $request->get_response_header (), $request->get_response_body (), $request->get_response_code () ); + } + + /** + * 获取当前密钥对拥有者的bucket列表 + * @param array $opt (Optional) + * BaiduBCS::IMPORT_BCS_LOG_METHOD - String - Optional: 支持用户传入日志处理函数,函数定义如 function f($log) + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function list_bucket($opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = ''; + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = '/'; + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "List bucket success!" : "List bucket failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 创建 bucket + * @param string $bucket (Required) bucket名称 + * @param string $acl (Optional) bucket权限设置,若为null,使用server分配的默认权限 + * @param array $opt (Optional) + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function create_bucket($bucket, $acl = NULL, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'PUT'; + $opt [self::OBJECT] = '/'; + if (NULL !== $acl) { + if (! in_array ( $acl, self::$ACL_TYPES )) { + throw new BCS_Exception ( "Invalid acl_type[" . $acl . "], please check!", - 1 ); + } + self::set_header_into_opt ( "x-bs-acl", $acl, $opt ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Create bucket success!" : "Create bucket failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 删除bucket + * @param string $bucket (Required) + * @param array $opt (Optional) + * @return boolean|BCS_ResponseCore + */ + public function delete_bucket($bucket, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'DELETE'; + $opt [self::OBJECT] = '/'; + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Delete bucket success!" : "Delete bucket failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 设置bucket的acl,有三种模式, + * (1).设置详细json格式的acl; + * a. $acl 为json的array + * b. $acl 为json的string + * (2).通过acl_type字段进行设置 + * a. $acl 为BaiduBCS::$ACL_TYPES中的字段 + * @param string $bucket (Required) + * @param string $acl (Required) + * @param array $opt (Optional) + * @return boolean|BCS_ResponseCore + */ + public function set_bucket_acl($bucket, $acl, $opt = array()) { + $this->assertParameterArray ( $opt ); + $result = $this->analyze_user_acl ( $acl ); + $opt = array_merge ( $opt, $result ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'PUT'; + $opt [self::OBJECT] = '/'; + $opt [self::QUERY_STRING] = array ( + self::ACL => 1 ); + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Set bucket acl success!" : "Set bucket acl failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 获取bucket的acl + * @param string $bucket (Required) + * @param array $opt (Optional) + * @return BCS_ResponseCore + */ + public function get_bucket_acl($bucket, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = '/'; + $opt [self::QUERY_STRING] = array ( + self::ACL => 1 ); + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Get bucket acl success!" : "Get bucket acl failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 获取bucket中object列表 + * @param string $bucket (Required) + * @param array $opt (Optional) + * start : 主要用于翻页功能,用法同mysql中start的用法 + * limit : 主要用于翻页功能,用法同mysql中limit的用法 + * prefix: 只返回以prefix为前缀的object,此处prefix必须以'/'开头 + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function list_object($bucket, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + if (empty ( $opt [self::BUCKET] )) { + throw new BCS_Exception ( "Bucket should not be empty, please check", - 1 ); + } + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = '/'; + $opt [self::QUERY_STRING] = array (); + if (isset ( $opt ['start'] ) && is_int ( $opt ['start'] )) { + $opt [self::QUERY_STRING] ['start'] = $opt ['start']; + } + if (isset ( $opt ['limit'] ) && is_int ( $opt ['limit'] )) { + $opt [self::QUERY_STRING] ['limit'] = $opt ['limit']; + } + if (isset ( $opt ['prefix'] )) { + $opt [self::QUERY_STRING] ['prefix'] = rawurlencode ( $opt ['prefix'] ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "List object success!" : "Lit object failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 以目录形式获取bucket中object列表 + * @param string $bucket (Required) + * @param $dir (Required) + * 目录名,格式为必须以'/'开头和结尾,默认为'/' + * @param string $list_model (Required) + * 目录展现形式,值可以为0,1,2,默认为2,以下对各个值的功能进行介绍: + * 0->只返回object列表,不返回子目录列表 + * 1->只返回子目录列表,不返回object列表 + * 2->同时返回子目录列表和object列表 + * @param array $opt (Optional) + * start : 主要用于翻页功能,用法同mysql中start的用法 + * limit : 主要用于翻页功能,用法同mysql中limit的用法 + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function list_object_by_dir($bucket, $dir = '/', $list_model = 2, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + if (empty ( $opt [self::BUCKET] )) { + throw new BCS_Exception ( "Bucket should not be empty, please check", - 1 ); + } + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = '/'; + $opt [self::QUERY_STRING] = array (); + if (isset ( $opt ['start'] ) && is_int ( $opt ['start'] )) { + $opt [self::QUERY_STRING] ['start'] = $opt ['start']; + } + if (isset ( $opt ['limit'] ) && is_int ( $opt ['limit'] )) { + $opt [self::QUERY_STRING] ['limit'] = $opt ['limit']; + } + + $opt [self::QUERY_STRING] ['prefix'] = rawurlencode ( $dir ); + $opt [self::QUERY_STRING] ['dir'] = $list_model; + + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "List object success!" : "Lit object failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 上传文件 + * @param string $bucket (Required) + * @param string $object (Required) + * @param string $file (Required); 需要上传的文件的文件路径 + * @param array $opt (Optional) + * filename - Optional; 指定文件名 + * acl - Optional ; 上传文件的acl,只能使用acl_type + * seekTo - Optional; 上传文件的偏移位置 + * length - Optional; 待上传长度 + * @return BCS_ResponseCore + */ + public function create_object($bucket, $object, $file, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::OBJECT] = $object; + $opt ['fileUpload'] = $file; + $opt [self::METHOD] = 'PUT'; + if (isset ( $opt ['acl'] )) { + if (in_array ( $opt ['acl'], self::$ACL_TYPES )) { + self::set_header_into_opt ( "x-bs-acl", $opt ['acl'], $opt ); + } else { + throw new BCS_Exception ( "Invalid acl string, it should be acl_type", - 1 ); + } + unset ( $opt ['acl'] ); + } + if (isset ( $opt ['filename'] )) { + self::set_header_into_opt ( "Content-Disposition", 'attachment; filename=' . $opt ['filename'], $opt ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Create object[$object] file[$file] success!" : "Create object[$object] file[$file] failed! Response: [" . $response->body . "] Logid[" . $response->header ["x-bs-request-id"] . "]", $opt ); + return $response; + } + + /** + * 上传文件 + * @param string $bucket (Required) + * @param string $object (Required) + * @param string $file (Required); 需要上传的文件的文件路径 + * @param array $opt (Optional) + * filename - Optional; 指定文件名 + * acl - Optional ; 上传文件的acl,只能使用acl_type + * @return BCS_ResponseCore + */ + public function create_object_by_content($bucket, $object, $content, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::OBJECT] = $object; + $opt [self::METHOD] = 'PUT'; + if ($content !== NULL && is_string ( $content )) { + $opt ['content'] = $content; + } else { + throw new BCS_Exception ( "Invalid object content, please check.", - 1 ); + } + if (isset ( $opt ['acl'] )) { + if (in_array ( $opt ['acl'], self::$ACL_TYPES )) { + self::set_header_into_opt ( "x-bs-acl", $opt ['acl'], $opt ); + } else { + throw new BCS_Exception ( "Invalid acl string, it should be acl_type", - 1 ); + } + unset ( $opt ['acl'] ); + } + if (isset ( $opt ['filename'] )) { + self::set_header_into_opt ( "Content-Disposition", 'attachment; filename=' . $opt ['filename'], $opt ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Create object[$object] success!" : "Create object[$object] failed! Response: [" . $response->body . "] Logid[" . $response->header ["x-bs-request-id"] . "]", $opt ); + return $response; + } + + /** + * 通过superfile的方式上传文件 + * @param string $bucket (Required) + * @param string $object (Required) + * @param string $file (Required); 需要上传的文件的文件路径 + * @param array $opt (Optional) + * filename - Optional; 指定文件名 + * sub_object_size - Optional; 指定子文件的划分大小,单位B,建议以256KB为单位进行子object划分,默认为1MB进行划分 + * @return BCS_ResponseCore + */ + public function create_object_superfile($bucket, $object, $file, $opt = array()) { + if (isset ( $opt ['length'] ) || isset ( $opt ['seekTo'] )) { + throw new BCS_Exception ( "Temporary unsupport opt of length and seekTo of superfile.", - 1 ); + } + //$opt array + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt ['fileUpload'] = $file; + $opt [self::METHOD] = 'PUT'; + if (isset ( $opt ['acl'] )) { + if (in_array ( $opt ['acl'], self::$ACL_TYPES )) { + self::set_header_into_opt ( "x-bs-acl", $opt ['acl'], $opt ); + } else { + throw new BCS_Exception ( "Invalid acl string, it should be acl_type", - 1 ); + } + unset ( $opt ['acl'] ); + } + //切片上传 + if (! file_exists ( $opt ['fileUpload'] )) { + throw new BCS_Exception ( 'File not found!', - 1 ); + } + $fileSize = filesize ( $opt ['fileUpload'] ); + $sub_object_size = 1024 * 1024; //default 1MB + if (defined ( "BCS_SUPERFILE_SLICE_SIZE" )) { + $sub_object_size = BCS_SUPERFILE_SLICE_SIZE; + } + if (isset ( $opt ["sub_object_size"] )) { + if (is_int ( $opt ["sub_object_size"] ) && $opt ["sub_object_size"] > 0) { + $sub_object_size = $opt ["sub_object_size"]; + } else { + throw new BCS_Exception ( "Param [sub_object_size] invalid ,please check!", - 1 ); + } + } + $sliceNum = intval ( ceil ( $fileSize / $sub_object_size ) ); + $this->log ( "File[" . $opt ['fileUpload'] . "], size=[$fileSize], sub_object_size=[$sub_object_size], sub_object_num=[$sliceNum]", $opt ); + $object_list = array ( + 'object_list' => array () ); + for($i = 0; $i < $sliceNum; $i ++) { + //send slice + $opt ['seekTo'] = $i * $sub_object_size; + + if (($i + 1) === $sliceNum) { + //last sub object + $opt ['length'] = (0 === $fileSize % $sub_object_size) ? $sub_object_size : $fileSize % $sub_object_size; + } else { + $opt ['length'] = $sub_object_size; + } + $opt [self::OBJECT] = $object . BCS_SUPERFILE_POSTFIX . $i; + $object_list ['object_list'] ['part_' . $i] = array (); + $object_list ['object_list'] ['part_' . $i] ['url'] = 'bs://' . $bucket . $opt [self::OBJECT]; + $this->log ( "Begin to upload Sub-object[" . $opt [self::OBJECT] . "][$i/$sliceNum][seekto:" . $opt ['seekTo'] . "][Length:" . $opt ['length'] . "]", $opt ); + $response = $this->create_object ( $bucket, $opt [self::OBJECT], $file, $opt ); + if ($response->isOK ()) { + $this->log ( "Sub-object upload[" . $opt [self::OBJECT] . "][$i/$sliceNum][seekto:" . $opt ['seekTo'] . "][Length:" . $opt ['length'] . "]success! ", $opt ); + $object_list ['object_list'] ['part_' . $i] ['etag'] = $response->header ['Content-MD5']; + continue; + } else { + $this->log ( "Sub-object upload[" . $opt [self::OBJECT] . "][$i/$sliceNum] failed! ", $opt ); + return $response; + } + } + //将子文件分片的列表构造成 superfile + unset ( $opt ['fileUpload'] ); + unset ( $opt ['length'] ); + unset ( $opt ['seekTo'] ); + $opt ['content'] = self::array_to_json ( $object_list ); + $opt [self::QUERY_STRING] = array ( + "superfile" => 1 ); + $opt [self::OBJECT] = $object; + if (isset ( $opt ['filename'] )) { + self::set_header_into_opt ( "Content-Disposition", 'attachment; filename=' . $opt ['filename'], $opt ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Create object-superfile success!" : "Create object-superfile failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 将目录中的所有文件进行上传,每个文件为单独object,object命名方式下详: + * 如有 /home/worker/a/b/c.txt 需上传目录为$dir=/home/worker/a + * object命令方式为 + * 1. object默认命名方式为 “子目录名 +文件名”,如上述文件c.txt,默认为 '/b/c.txt' + * 2. 增强命名模式,在$opt中有可选参数进行配置 + * 举例说明 :prefix . has_sub_directory?"/b":"" . '/c.txt' + * @param string $bucket (Required) + * @param string $dir (Required) + * @param array $opt(Optional) + * string prefix 文件object前缀 + * boolean has_sub_directory(default=true) object命名中是否携带文件的子目录结构,若置为false,请确认待上传的目录和所有子目录中没有重名文件,否则会产生object覆盖问题 + * BaiduBCS::IMPORT_BCS_PRE_FILTER 用户可自定义上传文件前的操作函数 + * 1. 函数参数列表顺序需为 ($bucket,$object,$file,&$opt),注意$opt为upload_directory函数传入的$opt的拷贝,只对当前object生效 + * 2. 函数返回值必须为boolean,当true该文件进行上传,若false跳过上传 + * 3. 如果函数返回false,将不会进行post_filter的调用 + * BaiduBCS::IMPORT_BCS_POST_FILTER 用户可自定义上传文件后的操作函数 + * 1. 函数参数列表顺序需为 ($bucket,$object,$file,&$opt,$response),注意$opt为upload_directory函数传入的$opt的拷贝,只对当前object生效 + * 2. 函数返回值无要求 + * string seek_object 用户断点续传,需要为object名称,如果该object在目录中不存在,抛出异常,若存在则将该object和此后的object进行上传 + * string seek_object_id 作用同seek_object,只需要传入上传过程中日志中展示的[a/b]中object序号即可,注意object序号是以1开始计算的 + * @return array 数组形式的上传结果 + * 'success' => int 上传成功的文件数目 + * 'skipped' => int 被跳过的文件 + * 'failed' => array() 上传失败的文件 + * + */ + public function upload_directory($bucket, $dir, $opt = array()) { + $this->assertParameterArray ( $opt ); + if (! is_dir ( $dir )) { + throw new BCS_Exception ( "$dir is not a dir!", - 1 ); + } + $result = array ( + "success" => 0, + "failed" => array (), + "skipped" => 0 ); + $prefix = ""; + if (isset ( $opt ['prefix'] )) { + $prefix = $opt ['prefix']; + } + $has_sub_directory = true; + if (isset ( $opt ['has_sub_directory'] ) && is_bool ( $opt ['has_sub_directory'] )) { + $has_sub_directory = $opt ['has_sub_directory']; + } + //获取文件树和构造object名 + $file_tree = self::get_filetree ( $dir ); + $objects = array (); + foreach ( $file_tree as $file ) { + $object = $has_sub_directory == true ? substr ( $file, strlen ( $dir ) ) : "/" . basename ( $file ); + $objects [$prefix . $object] = $file; + } + $objectCount = count ( $objects ); + $before_upload_log = "Upload directory: bucket[$bucket] upload_dir[$dir] file_sum[$objectCount]"; + if (isset ( $opt ["seek_object_id"] )) { + $before_upload_log .= " seek_object_id[" . $opt ["seek_object_id"] . "/$objectCount]"; + } + if (isset ( $opt ["seek_object"] )) { + $before_upload_log .= " seek_object[" . $opt ["seek_object"] . "]"; + } + $this->log ( $before_upload_log, $opt ); + //查看是否需要查询断点,进行断点续传 + if (isset ( $opt ["seek_object_id"] ) && isset ( $opt ["seek_object"] )) { + throw new BCS_Exception ( "Can not set see_object_id and seek_object at the same time!", - 1 ); + } + + $num = 1; + if (isset ( $opt ["seek_object"] )) { + if (isset ( $objects [$opt ["seek_object"]] )) { + foreach ( $objects as $object => $file ) { + if ($object != $opt ["seek_object"]) { + //当非断点文件,该object已完成上传 + $this->log ( "Seeking[" . $opt ["seek_object"] . "]. Skip id[$num/$objectCount]object[$object]file[$file].", $opt ); + //$result ['skipped'] [] = "[$num/$objectCount] " . $file; + $result ['skipped'] ++; + unset ( $objects [$object] ); + } else { + //当找到断点文件,停止循环,从断点文件重新上传 + //当非断点文件,该object已完成上传 + $this->log ( "Found seek id[$num/$objectCount]object[$object]file[$file], begin from here.", $opt ); + break; + } + $num ++; + } + } else { + throw new BCS_Exception ( "Can not find you seek object, please check!", - 1 ); + } + } + if (isset ( $opt ["seek_object_id"] )) { + if (is_int ( $opt ["seek_object_id"] ) && $opt ["seek_object_id"] <= $objectCount) { + foreach ( $objects as $object => $file ) { + if ($num < $opt ["seek_object_id"]) { + $this->log ( "Seeking object of [" . $opt ["seek_object_id"] . "/$objectCount]. Skip id[$num/$objectCount]object[$object]file[$file].", $opt ); + //$result ['skipped'] [] = "[$num/$objectCount] " . $file; + $result ['skipped'] ++; + unset ( $objects [$object] ); + } else { + break; + } + $num ++; + } + } else { + throw new BCS_Exception ( "Param seek_object_id not valid, please check!", - 1 ); + } + } + //上传objects + $objectCount = count ( $objects ); + foreach ( $objects as $object => $file ) { + $tmp_opt = array_merge ( $opt ); + if (isset ( $opt [self::IMPORT_BCS_PRE_FILTER] ) && function_exists ( $opt [self::IMPORT_BCS_PRE_FILTER] )) { + $bolRes = $opt [self::IMPORT_BCS_PRE_FILTER] ( $bucket, $object, $file, $tmp_opt ); + if ($bolRes !== true) { + $this->log ( "User pre_filter_function return un-true. Skip id[$num/$objectCount]object[$object]file[$file].", $opt ); + //$result ['skipped'] [] = "id[$num/$objectCount]object[$object]file[$file]"; + $result ['skipped'] ++; + $num ++; + continue; + } + } + try { + $response = $this->create_object ( $bucket, $object, $file, $tmp_opt ); + } catch ( Exception $e ) { + $this->log ( $e->getMessage (), $opt ); + $this->log ( "Upload Failed id[$num/$objectCount]object[$object]file[$file].", $opt ); + $num ++; + continue; + } + if ($response->isOK ()) { + $result ["success"] ++; + $this->log ( "Upload Success id[$num/$objectCount]object[$object]file[$file].", $opt ); + } else { + $result ["failed"] [] = "id[$num/$objectCount]object[$object]file[$file]"; + $this->log ( "Upload Failed id[$num/$objectCount]object[$object]file[$file].", $opt ); + } + if (isset ( $opt [self::IMPORT_BCS_POST_FILTER] ) && function_exists ( $opt [self::IMPORT_BCS_POST_FILTER] )) { + $opt [self::IMPORT_BCS_POST_FILTER] ( $bucket, $object, $file, $tmp_opt, $response ); + } + $num ++; + } + //打印日志并返回结果数组 + $result_str = "\r\n\r\nUpload $dir to $bucket finished!\r\n"; + $result_str .= "**********************************************************\r\n"; + $result_str .= "**********************Result Summary**********************\r\n"; + $result_str .= "**********************************************************\r\n"; + $result_str .= "Upload directory : [$dir]\r\n"; + $result_str .= "File num : [$objectCount]\r\n"; + $result_str .= "Success: \r\n\tNum: " . $result ["success"] . "\r\n"; + $result_str .= "Skipped:\r\n\tNum:" . $result ["skipped"] . "\r\n"; + // foreach ( $result ["skipped"] as $skip ) { + // $result_str .= "\t$skip\r\n"; + // } + $result_str .= "Failed:\r\n\tNum:" . count ( $result ["failed"] ) . "\r\n"; + foreach ( $result ["failed"] as $fail ) { + $result_str .= "\t$fail\r\n"; + } + if (isset ( $opt [self::IMPORT_BCS_LOG_METHOD] )) { + $this->log ( $result_str, $opt ); + } else { + echo $result_str; + } + return $result; + } + + /** + * 通过此方法以拷贝的方式创建object,object来源为$source + * @param array $source (Required) object 来源 + * bucket(Required) + * object(Required) + * @param array $dest (Required) 待拷贝的目标object + * bucket(Required) + * object(Required) + * @param array $opt (Optional) + * source_tag 指定拷贝对象的版本号 + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function copy_object($source, $dest, $opt = array()) { + $this->assertParameterArray ( $opt ); + //valid source and dest + if (empty ( $source ) || ! is_array ( $source ) || ! isset ( $source [self::BUCKET] ) || ! isset ( $source [self::OBJECT] )) { + throw new BCS_Exception ( '$source invalid, please check!', - 1 ); + } + if (empty ( $dest ) || ! is_array ( $dest ) || ! isset ( $dest [self::BUCKET] ) || ! isset ( $dest [self::OBJECT] ) || ! self::validate_bucket ( $dest [self::BUCKET] ) || ! self::validate_object ( $dest [self::OBJECT] )) { + throw new BCS_Exception ( '$dest invalid, please check!', - 1 ); + } + $opt [self::BUCKET] = $dest [self::BUCKET]; + $opt [self::OBJECT] = $dest [self::OBJECT]; + $opt [self::METHOD] = 'PUT'; + self::set_header_into_opt ( 'x-bs-copy-source', 'bs://' . $source [self::BUCKET] . $source [self::OBJECT], $opt ); + if (isset ( $opt ['source_tag'] )) { + self::set_header_into_opt ( 'x-bs-copy-source-tag', $opt ['source_tag'], $opt ); + } + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Copy object success!" : "Copy object failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 设置object的meta信息 + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * 目前支持的meta信息如下: + * Content-Type + * Cache-Control + * Content-Disposition + * Content-Encoding + * Content-MD5 + * Expires + * @return BCS_ResponseCore + */ + public function set_object_meta($bucket, $object, $meta, $opt = array()) { + $this->assertParameterArray ( $opt ); + $this->assertParameterArray ( $meta ); + $opt [self::BUCKET] = $bucket; + $opt [self::OBJECT] = $object; + $opt [self::METHOD] = 'PUT'; + //利用copy_object接口来设置meta信息 + $source = "bs://$bucket$object"; + if (empty ( $meta )) { + throw new BCS_Exception ( '$meta can not be empty! And $meta must be array.', - 1 ); + } + foreach ( $meta as $header => $value ) { + self::set_header_into_opt ( $header, $value, $opt ); + } + $source = array ( + self::BUCKET => $bucket, + self::OBJECT => $object ); + $response = $this->copy_object ( $source, $source, $opt ); + $this->log ( $response->isOK () ? "Set object meta success!" : "Set object meta failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 获取object的acl + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function get_object_acl($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = $object; + $opt [self::QUERY_STRING] = array ( + self::ACL => 1 ); + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Get object acl success!" : "Get object acl failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 设置object的acl,有三种模式, + * (1).设置详细json格式的acl; + * a. $acl 为json的array + * b. $acl 为json的string + * (2).通过acl_type字段进行设置 + * a. $acl 为BaiduBCS::$ACL_ACTIONS中的字段 + * @param string $bucket (Required) + * @param string $object (Required) + * @param string|array $acl (Required) + * @param array $opt (Optional) + * @return BCS_ResponseCore + */ + public function set_object_acl($bucket, $object, $acl, $opt = array()) { + $this->assertParameterArray ( $opt ); + //analyze acl + $result = $this->analyze_user_acl ( $acl ); + $opt = array_merge ( $opt, $result ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'PUT'; + $opt [self::OBJECT] = $object; + $opt [self::QUERY_STRING] = array ( + self::ACL => 1 ); + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Set object acl success!" : "Set object acl failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 删除object + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function delete_object($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'DELETE'; + $opt [self::OBJECT] = $object; + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Delete object success!" : "Delete object failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 判断object是否存在 + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * @throws BCS_Exception + * @return boolean true|boolean false|BCS_ResponseCore + * true:object存在 + * false:不存在 + * BCS_ResponseCore其他错误 + */ + public function is_object_exist($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'HEAD'; + $opt [self::OBJECT] = $object; + $response = $this->get_object_info ( $bucket, $object, $opt ); + if ($response->isOK ()) { + return true; + } elseif ($response->status === 404) { + return false; + } + return $response; + } + + /** + * 获取文件信息,发送的为HTTP HEAD请求,文件信息都在http response的header中,不会提取文件的内容 + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * @throws BCS_Exception + * @return array BCS_ResponseCore + */ + public function get_object_info($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'HEAD'; + $opt [self::OBJECT] = $object; + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Get object info success!" : "Get object info failed! Response: [" . $response->body . "]", $opt ); + return $response; + } + + /** + * 下载object + * @param string $bucket (Required) + * @param string $object (Required) + * @param array $opt (Optional) + * fileWriteTo (Optional)直接将请求结果写入该文件,如果fileWriteTo文件存在,sdk进行重命名再存储 + * @throws BCS_Exception + * @return BCS_ResponseCore + */ + public function get_object($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + //若fileWriteTo待写入的文件已经存在,需要进行重命名 + if (isset ( $opt ["fileWriteTo"] ) && file_exists ( $opt ["fileWriteTo"] )) { + $original_file_write_to = $opt ["fileWriteTo"]; + $arr = explode ( DIRECTORY_SEPARATOR, $opt ["fileWriteTo"] ); + $file_name = $arr [count ( $arr ) - 1]; + $num = 1; + while ( file_exists ( $opt ["fileWriteTo"] ) ) { + $new_name_arr = explode ( ".", $file_name ); + if (count ( $new_name_arr ) > 1) { + $new_name_arr [count ( $new_name_arr ) - 2] .= " ($num)"; + } else { + $new_name_arr [0] .= " ($num)"; + } + $arr [count ( $arr ) - 1] = implode ( ".", $new_name_arr ); + $opt ["fileWriteTo"] = implode ( DIRECTORY_SEPARATOR, $arr ); + $num ++; + } + $this->log ( "[$original_file_write_to] already exist, rename it to [" . $opt ["fileWriteTo"] . "]", $opt ); + } + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = 'GET'; + $opt [self::OBJECT] = $object; + $response = $this->authenticate ( $opt ); + $this->log ( $response->isOK () ? "Get object success!" : "Get object failed! Response: [" . $response->body . "]", $opt ); + if (! $response->isOK () && isset ( $opt ["fileWriteTo"] )) { + unlink ( $opt ["fileWriteTo"] ); + } + return $response; + } + + /** + * 生成签名链接 + */ + private function generate_user_url($method, $bucket, $object, $opt = array()) { + $opt [self::AK] = $this->ak; + $opt [self::SK] = $this->sk; + $opt [self::BUCKET] = $bucket; + $opt [self::METHOD] = $method; + $opt [self::OBJECT] = $object; + $opt [self::QUERY_STRING] = array (); + if (isset ( $opt ["time"] )) { + $opt [self::QUERY_STRING] ["time"] = $opt ["time"]; + } + if (isset ( $opt ["size"] )) { + $opt [self::QUERY_STRING] ["size"] = $opt ["size"]; + } + return $this->format_url ( $opt ); + } + + /** + * 生成get_object的url + * @param string $bucket (Required) + * @param string $object (Required) + * return false| string url + */ + public function generate_get_object_url($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + return $this->generate_user_url ( "GET", $bucket, $object, $opt ); + } + + /** + * 生成put_object的url + * @param string $bucket (Required) + * @param string $object (Required) + * return false| string url + */ + public function generate_put_object_url($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + return $this->generate_user_url ( "PUT", $bucket, $object, $opt ); + } + + /** + * 生成post_object的url + * @param string $bucket (Required) + * @param string $object (Required) + * return false| string url + */ + public function generate_post_object_url($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + return $this->generate_user_url ( "POST", $bucket, $object, $opt ); + } + + /** + * 生成delete_object的url + * @param string $bucket (Required) + * @param string $object (Required) + * return false| string url + */ + public function generate_delete_object_url($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + return $this->generate_user_url ( "DELETE", $bucket, $object, $opt ); + } + + /** + * 生成head_object的url + * @param string $bucket (Required) + * @param string $object (Required) + * return false| string url + */ + public function generate_head_object_url($bucket, $object, $opt = array()) { + $this->assertParameterArray ( $opt ); + return $this->generate_user_url ( "HEAD", $bucket, $object, $opt ); + } + + /** + * @return the $use_ssl + */ + public function getUse_ssl() { + return $this->use_ssl; + } + + /** + * @param boolean $use_ssl + */ + public function setUse_ssl($use_ssl) { + $this->use_ssl = $use_ssl; + } + + /** + * 校验bucket是否合法,bucket规范 + * 1. 由小写字母,数字和横线'-'组成,长度为6~63位 + * 2. 不能以数字作为Bucket开头 + * 3. 不能以'-'作为Bucket的开头或者结尾 + * @param string $bucket + * @return boolean + */ + public static function validate_bucket($bucket) { + //bucket 正则 + $pattern1 = '/^[a-z][-a-z0-9]{4,61}[a-z0-9]$/'; + if (! preg_match ( $pattern1, $bucket )) { + return false; + } + return true; + } + + /** + * 校验object是否合法,object命名规范 + * 1. object必须以'/'开头 + * @param string $object + * @return boolean + */ + public static function validate_object($object) { + $pattern = '/^\//'; + if (empty ( $object ) || ! preg_match ( $pattern, $object )) { + return false; + } + return true; + } + + /** + * 将常用set http-header的动作抽离出来 + * @param string $header + * @param string $value + * @param array $opt + * @throws BCS_Exception + * @return void + */ + private static function set_header_into_opt($header, $value, &$opt) { + if (isset ( $opt [self::HEADERS] )) { + if (! is_array ( $opt [self::HEADERS] )) { + trigger_error ( 'Invalid $opt[\'headers\'], please check.' ); + throw new BCS_Exception ( 'Invalid $opt[\'headers\'], please check.', - 1 ); + } + } else { + $opt [self::HEADERS] = array (); + } + $opt [self::HEADERS] [$header] = $value; + } + + /** + * 使用特定function对数组中所有元素做处理 + * @param string &$array 要处理的字符串 + * @param string $function 要执行的函数 + * @param boolean $apply_to_keys_also 是否也应用到key上 + */ + private static function array_recursive(&$array, $function, $apply_to_keys_also = false) { + foreach ( $array as $key => $value ) { + if (is_array ( $value )) { + self::array_recursive ( $array [$key], $function, $apply_to_keys_also ); + } else { + $array [$key] = $function ( $value ); + } + + if ($apply_to_keys_also && is_string ( $key )) { + $new_key = $function ( $key ); + if ($new_key != $key) { + $array [$new_key] = $array [$key]; + unset ( $array [$key] ); + } + } + } + } + + /** + * 由数组构造json字符串,增加了一些特殊处理以支持特殊字符和不同编码的中文 + * @param array $array + */ + private static function array_to_json($array) { + if (! is_array ( $array )) { + throw new BCS_Exception ( "Param must be array in function array_to_json()", - 1 ); + } + self::array_recursive ( $array, 'addslashes', false ); + self::array_recursive ( $array, 'rawurlencode', false ); + return rawurldecode ( json_encode ( $array ) ); + } + + /** + * 根据用户传入的acl,进行相应的处理 + * (1).设置详细json格式的acl; + * a. $acl 为json的array + * b. $acl 为json的string + * (2).通过acl_type字段进行设置 + * @param string|array $acl + * @throws BCS_Exception + * @return array + */ + private function analyze_user_acl($acl) { + $result = array (); + if (is_array ( $acl )) { + //(1).a + $result ['content'] = $this->check_user_acl ( $acl ); + } else if (is_string ( $acl )) { + if (in_array ( $acl, self::$ACL_TYPES )) { + //(2).a + $result ["headers"] = array ( + "x-bs-acl" => $acl ); + } else { + //(1).b + $result ['content'] = $acl; + } + } else { + throw new BCS_Exception ( "Invalid acl.", - 1 ); + } + return $result; + } + + /** + * 生成签名 + * @param array $opt + * @return boolean|string + */ + private function format_signature($opt) { + $flags = ""; + $content = ''; + if (! isset ( $opt [self::AK] ) || ! isset ( $opt [self::SK] )) { + trigger_error ( 'ak or sk is not in the array when create factor!' ); + return false; + } + if (isset ( $opt [self::BUCKET] ) && isset ( $opt [self::METHOD] ) && isset ( $opt [self::OBJECT] )) { + $flags .= 'MBO'; + $content .= "Method=" . $opt [self::METHOD] . "\n"; //method + $content .= "Bucket=" . $opt [self::BUCKET] . "\n"; //bucket + $content .= "Object=" . self::trimUrl ( $opt [self::OBJECT] ) . "\n"; //object + } else { + trigger_error ( 'bucket、method and object cann`t be NULL!' ); + return false; + } + if (isset ( $opt ['ip'] )) { + $flags .= 'I'; + $content .= "Ip=" . $opt ['ip'] . "\n"; + } + if (isset ( $opt ['time'] )) { + $flags .= 'T'; + $content .= "Time=" . $opt ['time'] . "\n"; + } + if (isset ( $opt ['size'] )) { + $flags .= 'S'; + $content .= "Size=" . $opt ['size'] . "\n"; + } + $content = $flags . "\n" . $content; + $sign = base64_encode ( hash_hmac ( 'sha1', $content, $opt [self::SK], true ) ); + return 'sign=' . $flags . ':' . $opt [self::AK] . ':' . urlencode ( $sign ); + } + + /** + * 检查用户输入的acl array是否合法,并转为json + * @param array $acl + * @throws BCS_Exception + * @return string acl-json + */ + private function check_user_acl($acl) { + if (! is_array ( $acl )) { + throw new BCS_Exception ( "Invalid acl array" ); + } + foreach ( $acl ['statements'] as $key => $statement ) { + // user resource action effect must in statement + if (! isset ( $statement ['user'] ) || ! isset ( $statement ['resource'] ) || ! isset ( $statement ['action'] ) || ! isset ( $statement ['effect'] )) { + throw new BCS_Exception ( 'Param miss: format acl error, please check your param!' ); + } + if (! is_array ( $statement ['user'] ) || ! is_array ( $statement ['resource'] )) { + throw new BCS_Exception ( 'Param error: user or resource must be array, please check your param!' ); + } + if (! is_array ( $statement ['action'] ) || ! count ( array_diff ( $statement ['action'], self::$ACL_ACTIONS ) ) == 0) { + throw new BCS_Exception ( 'Param error: action, please check your param!' ); + } + if (! in_array ( $statement ['effect'], self::$ACL_EFFECTS )) { + throw new BCS_Exception ( 'Param error: effect, please check your param!' ); + } + if (isset ( $statement ['time'] )) { + if (! is_array ( $statement ['time'] )) { + throw new BCS_Exception ( 'Param error: time, please check your param!' ); + } + } + } + + return self::array_to_json ( $acl ); + } + + /** + * 构造url + * @param array $opt + * @return boolean|string + */ + private function format_url($opt) { + $sign = $this->format_signature ( $opt ); + if ($sign === false) { + trigger_error ( "Format signature failed, please check!" ); + return false; + } + $opt ['sign'] = $sign; + $url = ""; + $url .= $this->use_ssl ? 'https://' : 'http://'; + $url .= $this->hostname; + $url .= '/' . $opt [self::BUCKET]; + if (isset ( $opt [self::OBJECT] ) && '/' !== $opt [self::OBJECT]) { + $url .= "/" . rawurlencode ( $opt [self::OBJECT] ); + } + $url .= '?' . $sign; + if (isset ( $opt [self::QUERY_STRING] )) { + foreach ( $opt [self::QUERY_STRING] as $key => $value ) { + $url .= '&' . $key . '=' . $value; + } + } + return $url; + } + + /** + * 将url中 '//' 替换为 '/' + * @param $url + * @return string + */ + public static function trimUrl($url) { + $result = str_replace ( "//", "/", $url ); + while ( $result !== $url ) { + $url = $result; + $result = str_replace ( "//", "/", $url ); + } + return $result; + } + + /** + * 获取传入目录的文件列表 + * @param string $dir 文件目录 + * @return array 文件树 + */ + public static function get_filetree($dir, $file_prefix = "/*") { + $tree = array (); + foreach ( glob ( $dir . $file_prefix ) as $single ) { + if (is_dir ( $single )) { + $tree = array_merge ( $tree, self::get_filetree ( $single ) ); + } else { + $tree [] = $single; + } + } + return $tree; + } + + /** + * 内置的日志函数,可以根据用户传入的log函数,进行日志输出 + * @param string $log + * @param array $opt + */ + public function log($log, $opt) { + if (isset ( $opt [self::IMPORT_BCS_LOG_METHOD] ) && function_exists ( $opt [self::IMPORT_BCS_LOG_METHOD] )) { + $opt [self::IMPORT_BCS_LOG_METHOD] ( $log ); + } else { + trigger_error ( $log ); + } + } + + /** + * make sure $opt is an array + * @param $opt + */ + private function assertParameterArray($opt) { + if (! is_array ( $opt )) { + throw new BCS_Exception ( 'Parameter must be array, please check!', - 1 ); + } + } +} \ No newline at end of file diff --git a/ThinkPHP/Library/Think/Upload/Driver/Bcs/mimetypes.class.php b/ThinkPHP/Library/Think/Upload/Driver/Bcs/mimetypes.class.php new file mode 100644 index 0000000..61c06c0 --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Bcs/mimetypes.class.php @@ -0,0 +1,137 @@ + 'video/3gpp', 'ai' => 'application/postscript', + 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', + 'aiff' => 'audio/x-aiff', 'asc' => 'text/plain', + 'atom' => 'application/atom+xml', 'au' => 'audio/basic', + 'avi' => 'video/x-msvideo', 'bcpio' => 'application/x-bcpio', + 'bin' => 'application/octet-stream', 'bmp' => 'image/bmp', + 'cdf' => 'application/x-netcdf', 'cgm' => 'image/cgm', + 'class' => 'application/octet-stream', + 'cpio' => 'application/x-cpio', + 'cpt' => 'application/mac-compactpro', + 'csh' => 'application/x-csh', 'css' => 'text/css', + 'dcr' => 'application/x-director', 'dif' => 'video/x-dv', + 'dir' => 'application/x-director', 'djv' => 'image/vnd.djvu', + 'djvu' => 'image/vnd.djvu', + 'dll' => 'application/octet-stream', + 'dmg' => 'application/octet-stream', + 'dms' => 'application/octet-stream', + 'doc' => 'application/msword', 'dtd' => 'application/xml-dtd', + 'dv' => 'video/x-dv', 'dvi' => 'application/x-dvi', + 'dxr' => 'application/x-director', + 'eps' => 'application/postscript', 'etx' => 'text/x-setext', + 'exe' => 'application/octet-stream', + 'ez' => 'application/andrew-inset', 'flv' => 'video/x-flv', + 'gif' => 'image/gif', 'gram' => 'application/srgs', + 'grxml' => 'application/srgs+xml', + 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', + 'hdf' => 'application/x-hdf', + 'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', + 'html' => 'text/html', 'ice' => 'x-conference/x-cooltalk', + 'ico' => 'image/x-icon', 'ics' => 'text/calendar', + 'ief' => 'image/ief', 'ifb' => 'text/calendar', + 'iges' => 'model/iges', 'igs' => 'model/iges', + 'jnlp' => 'application/x-java-jnlp-file', 'jp2' => 'image/jp2', + 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', + 'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', + 'kar' => 'audio/midi', 'latex' => 'application/x-latex', + 'lha' => 'application/octet-stream', + 'lzh' => 'application/octet-stream', + 'm3u' => 'audio/x-mpegurl', 'm4a' => 'audio/mp4a-latm', + 'm4p' => 'audio/mp4a-latm', 'm4u' => 'video/vnd.mpegurl', + 'm4v' => 'video/x-m4v', 'mac' => 'image/x-macpaint', + 'man' => 'application/x-troff-man', + 'mathml' => 'application/mathml+xml', + 'me' => 'application/x-troff-me', 'mesh' => 'model/mesh', + 'mid' => 'audio/midi', 'midi' => 'audio/midi', + 'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime', + 'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg', + 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', + 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', + 'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', + 'ms' => 'application/x-troff-ms', 'msh' => 'model/mesh', + 'mxu' => 'video/vnd.mpegurl', 'nc' => 'application/x-netcdf', + 'oda' => 'application/oda', 'ogg' => 'application/ogg', + 'ogv' => 'video/ogv', 'pbm' => 'image/x-portable-bitmap', + 'pct' => 'image/pict', 'pdb' => 'chemical/x-pdb', + 'pdf' => 'application/pdf', + 'pgm' => 'image/x-portable-graymap', + 'pgn' => 'application/x-chess-pgn', 'pic' => 'image/pict', + 'pict' => 'image/pict', 'png' => 'image/png', + 'pnm' => 'image/x-portable-anymap', + 'pnt' => 'image/x-macpaint', 'pntg' => 'image/x-macpaint', + 'ppm' => 'image/x-portable-pixmap', + 'ppt' => 'application/vnd.ms-powerpoint', + 'ps' => 'application/postscript', 'qt' => 'video/quicktime', + 'qti' => 'image/x-quicktime', 'qtif' => 'image/x-quicktime', + 'ra' => 'audio/x-pn-realaudio', + 'ram' => 'audio/x-pn-realaudio', 'ras' => 'image/x-cmu-raster', + 'rdf' => 'application/rdf+xml', 'rgb' => 'image/x-rgb', + 'rm' => 'application/vnd.rn-realmedia', + 'roff' => 'application/x-troff', 'rtf' => 'text/rtf', + 'rtx' => 'text/richtext', 'sgm' => 'text/sgml', + 'sgml' => 'text/sgml', 'sh' => 'application/x-sh', + 'shar' => 'application/x-shar', 'silo' => 'model/mesh', + 'sit' => 'application/x-stuffit', + 'skd' => 'application/x-koan', 'skm' => 'application/x-koan', + 'skp' => 'application/x-koan', 'skt' => 'application/x-koan', + 'smi' => 'application/smil', 'smil' => 'application/smil', + 'snd' => 'audio/basic', 'so' => 'application/octet-stream', + 'spl' => 'application/x-futuresplash', + 'src' => 'application/x-wais-source', + 'sv4cpio' => 'application/x-sv4cpio', + 'sv4crc' => 'application/x-sv4crc', 'svg' => 'image/svg+xml', + 'swf' => 'application/x-shockwave-flash', + 't' => 'application/x-troff', 'tar' => 'application/x-tar', + 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', + 'texi' => 'application/x-texinfo', + 'texinfo' => 'application/x-texinfo', 'tif' => 'image/tiff', + 'tiff' => 'image/tiff', 'tr' => 'application/x-troff', + 'tsv' => 'text/tab-separated-values', 'txt' => 'text/plain', + 'ustar' => 'application/x-ustar', + 'vcd' => 'application/x-cdlink', 'vrml' => 'model/vrml', + 'vxml' => 'application/voicexml+xml', 'wav' => 'audio/x-wav', + 'wbmp' => 'image/vnd.wap.wbmp', + 'wbxml' => 'application/vnd.wap.wbxml', 'webm' => 'video/webm', + 'wml' => 'text/vnd.wap.wml', + 'wmlc' => 'application/vnd.wap.wmlc', + 'wmls' => 'text/vnd.wap.wmlscript', + 'wmlsc' => 'application/vnd.wap.wmlscriptc', + 'wmv' => 'video/x-ms-wmv', 'wrl' => 'model/vrml', + 'xbm' => 'image/x-xbitmap', 'xht' => 'application/xhtml+xml', + 'xhtml' => 'application/xhtml+xml', + 'xls' => 'application/vnd.ms-excel', + 'xml' => 'application/xml', 'xpm' => 'image/x-xpixmap', + 'xsl' => 'application/xml', 'xslt' => 'application/xslt+xml', + 'xul' => 'application/vnd.mozilla.xul+xml', + 'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', + 'zip' => 'application/zip', + //add by zhengkan 20110905 + "apk" => "application/vnd.android.package-archive", + "bin" => "application/octet-stream", + "cab" => "application/vnd.ms-cab-compressed", + "gb" => "application/chinese-gb", + "gba" => "application/octet-stream", + "gbc" => "application/octet-stream", + "jad" => "text/vnd.sun.j2me.app-descriptor", + "jar" => "application/java-archive", + "nes" => "application/octet-stream", + "rar" => "application/x-rar-compressed", + "sis" => "application/vnd.symbian.install", + "sisx" => "x-epoc/x-sisx-app", + "smc" => "application/octet-stream", + "smd" => "application/octet-stream", + "swf" => "application/x-shockwave-flash", + "zip" => "application/x-zip-compressed", + "wap" => "text/vnd.wap.wml wml", "mrp" => "application/mrp", + //add by zhengkan 20110914 + "wma" => "audio/x-ms-wma", + "lrc" => "application/lrc" ); + public static function get_mimetype($ext) { + $ext = strtolower ( $ext ); + return (isset ( self::$mime_types [$ext] ) ? self::$mime_types [$ext] : 'application/octet-stream'); + } +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Bcs/requestcore.class.php b/ThinkPHP/Library/Think/Upload/Driver/Bcs/requestcore.class.php new file mode 100644 index 0000000..283f23e --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Bcs/requestcore.class.php @@ -0,0 +1,837 @@ +). + */ + public $request_class = 'BCS_RequestCore'; + /** + * The default class to use for HTTP Responses (defaults to ). + */ + public $response_class = 'BCS_ResponseCore'; + /** + * Default useragent string to use. + */ + public $useragent = 'BCS_RequestCore/1.4.2'; + /** + * File to read from while streaming up. + */ + public $read_file = null; + /** + * The resource to read from while streaming up. + */ + public $read_stream = null; + /** + * The size of the stream to read from. + */ + public $read_stream_size = null; + /** + * The length already read from the stream. + */ + public $read_stream_read = 0; + /** + * File to write to while streaming down. + */ + public $write_file = null; + /** + * The resource to write to while streaming down. + */ + public $write_stream = null; + /** + * Stores the intended starting seek position. + */ + public $seek_position = null; + /** + * The user-defined callback function to call when a stream is read from. + */ + public $registered_streaming_read_callback = null; + /** + * The user-defined callback function to call when a stream is written to. + */ + public $registered_streaming_write_callback = null; + /*%******************************************************************************************%*/ + // CONSTANTS + /** + * GET HTTP Method + */ + const HTTP_GET = 'GET'; + /** + * POST HTTP Method + */ + const HTTP_POST = 'POST'; + /** + * PUT HTTP Method + */ + const HTTP_PUT = 'PUT'; + /** + * DELETE HTTP Method + */ + const HTTP_DELETE = 'DELETE'; + /** + * HEAD HTTP Method + */ + const HTTP_HEAD = 'HEAD'; + + /*%******************************************************************************************%*/ + // CONSTRUCTOR/DESTRUCTOR + /** + * Constructs a new instance of this class. + * + * @param string $url (Optional) The URL to request or service endpoint to query. + * @param string $proxy (Optional) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port` + * @param array $helpers (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class. + * @return $this A reference to the current instance. + */ + public function __construct($url = null, $proxy = null, $helpers = null) { + // Set some default values. + $this->request_url = $url; + $this->method = self::HTTP_GET; + $this->request_headers = array (); + $this->request_body = ''; + // Set a new Request class if one was set. + if (isset ( $helpers ['request'] ) && ! empty ( $helpers ['request'] )) { + $this->request_class = $helpers ['request']; + } + // Set a new Request class if one was set. + if (isset ( $helpers ['response'] ) && ! empty ( $helpers ['response'] )) { + $this->response_class = $helpers ['response']; + } + if ($proxy) { + $this->set_proxy ( $proxy ); + } + return $this; + } + + /** + * Destructs the instance. Closes opened file handles. + * + * @return $this A reference to the current instance. + */ + public function __destruct() { + if (isset ( $this->read_file ) && isset ( $this->read_stream )) { + fclose ( $this->read_stream ); + } + if (isset ( $this->write_file ) && isset ( $this->write_stream )) { + fclose ( $this->write_stream ); + } + return $this; + } + + /*%******************************************************************************************%*/ + // REQUEST METHODS + /** + * Sets the credentials to use for authentication. + * + * @param string $user (Required) The username to authenticate with. + * @param string $pass (Required) The password to authenticate with. + * @return $this A reference to the current instance. + */ + public function set_credentials($user, $pass) { + $this->username = $user; + $this->password = $pass; + return $this; + } + + /** + * Adds a custom HTTP header to the cURL request. + * + * @param string $key (Required) The custom HTTP header to set. + * @param mixed $value (Required) The value to assign to the custom HTTP header. + * @return $this A reference to the current instance. + */ + public function add_header($key, $value) { + $this->request_headers [$key] = $value; + return $this; + } + + /** + * Removes an HTTP header from the cURL request. + * + * @param string $key (Required) The custom HTTP header to set. + * @return $this A reference to the current instance. + */ + public function remove_header($key) { + if (isset ( $this->request_headers [$key] )) { + unset ( $this->request_headers [$key] ); + } + return $this; + } + + /** + * Set the method type for the request. + * + * @param string $method (Required) One of the following constants: , , , , . + * @return $this A reference to the current instance. + */ + public function set_method($method) { + $this->method = strtoupper ( $method ); + return $this; + } + + /** + * Sets a custom useragent string for the class. + * + * @param string $ua (Required) The useragent string to use. + * @return $this A reference to the current instance. + */ + public function set_useragent($ua) { + $this->useragent = $ua; + return $this; + } + + /** + * Set the body to send in the request. + * + * @param string $body (Required) The textual content to send along in the body of the request. + * @return $this A reference to the current instance. + */ + public function set_body($body) { + $this->request_body = $body; + return $this; + } + + /** + * Set the URL to make the request to. + * + * @param string $url (Required) The URL to make the request to. + * @return $this A reference to the current instance. + */ + public function set_request_url($url) { + $this->request_url = $url; + return $this; + } + + /** + * Set additional CURLOPT settings. These will merge with the default settings, and override if + * there is a duplicate. + * + * @param array $curlopts (Optional) A set of key-value pairs that set `CURLOPT` options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the `CURLOPT_*` constants, not strings. + * @return $this A reference to the current instance. + */ + public function set_curlopts($curlopts) { + $this->curlopts = $curlopts; + return $this; + } + + /** + * Sets the length in bytes to read from the stream while streaming up. + * + * @param integer $size (Required) The length in bytes to read from the stream. + * @return $this A reference to the current instance. + */ + public function set_read_stream_size($size) { + $this->read_stream_size = $size; + return $this; + } + + /** + * Sets the resource to read from while streaming up. Reads the stream from its current position until + * EOF or `$size` bytes have been read. If `$size` is not given it will be determined by and + * . + * + * @param resource $resource (Required) The readable resource to read from. + * @param integer $size (Optional) The size of the stream to read. + * @return $this A reference to the current instance. + */ + public function set_read_stream($resource, $size = null) { + if (! isset ( $size ) || $size < 0) { + $stats = fstat ( $resource ); + if ($stats && $stats ['size'] >= 0) { + $position = ftell ( $resource ); + if ($position !== false && $position >= 0) { + $size = $stats ['size'] - $position; + } + } + } + $this->read_stream = $resource; + return $this->set_read_stream_size ( $size ); + } + + /** + * Sets the file to read from while streaming up. + * + * @param string $location (Required) The readable location to read from. + * @return $this A reference to the current instance. + */ + public function set_read_file($location) { + $this->read_file = $location; + $read_file_handle = fopen ( $location, 'r' ); + return $this->set_read_stream ( $read_file_handle ); + } + + /** + * Sets the resource to write to while streaming down. + * + * @param resource $resource (Required) The writeable resource to write to. + * @return $this A reference to the current instance. + */ + public function set_write_stream($resource) { + $this->write_stream = $resource; + return $this; + } + + /** + * Sets the file to write to while streaming down. + * + * @param string $location (Required) The writeable location to write to. + * @return $this A reference to the current instance. + */ + public function set_write_file($location) { + $this->write_file = $location; + $write_file_handle = fopen ( $location, 'w' ); + return $this->set_write_stream ( $write_file_handle ); + } + + /** + * Set the proxy to use for making requests. + * + * @param string $proxy (Required) The faux-url to use for proxy settings. Takes the following format: `proxy://user:pass@hostname:port` + * @return $this A reference to the current instance. + */ + public function set_proxy($proxy) { + $proxy = parse_url ( $proxy ); + $proxy ['user'] = isset ( $proxy ['user'] ) ? $proxy ['user'] : null; + $proxy ['pass'] = isset ( $proxy ['pass'] ) ? $proxy ['pass'] : null; + $proxy ['port'] = isset ( $proxy ['port'] ) ? $proxy ['port'] : null; + $this->proxy = $proxy; + return $this; + } + + /** + * Set the intended starting seek position. + * + * @param integer $position (Required) The byte-position of the stream to begin reading from. + * @return $this A reference to the current instance. + */ + public function set_seek_position($position) { + $this->seek_position = isset ( $position ) ? ( integer ) $position : null; + return $this; + } + + /** + * Register a callback function to execute whenever a data stream is read from using + * . + * + * The user-defined callback function should accept three arguments: + * + *
    + *
  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • + *
  • $file_handle - resource - Required - The file handle resource that represents the file on the local file system.
  • + *
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
  • + *
+ * + * @param string|array|function $callback (Required) The callback function is called by , so you can pass the following values:
    + *
  • The name of a global function to execute, passed as a string.
  • + *
  • A method to execute, passed as array('ClassName', 'MethodName').
  • + *
  • An anonymous function (PHP 5.3+).
+ * @return $this A reference to the current instance. + */ + public function register_streaming_read_callback($callback) { + $this->registered_streaming_read_callback = $callback; + return $this; + } + + /** + * Register a callback function to execute whenever a data stream is written to using + * . + * + * The user-defined callback function should accept two arguments: + * + *
    + *
  • $curl_handle - resource - Required - The cURL handle resource that represents the in-progress transfer.
  • + *
  • $length - integer - Required - The length in kilobytes of the data chunk that was transferred.
  • + *
+ * + * @param string|array|function $callback (Required) The callback function is called by , so you can pass the following values:
    + *
  • The name of a global function to execute, passed as a string.
  • + *
  • A method to execute, passed as array('ClassName', 'MethodName').
  • + *
  • An anonymous function (PHP 5.3+).
+ * @return $this A reference to the current instance. + */ + public function register_streaming_write_callback($callback) { + $this->registered_streaming_write_callback = $callback; + return $this; + } + + /*%******************************************************************************************%*/ + // PREPARE, SEND, AND PROCESS REQUEST + /** + * A callback function that is invoked by cURL for streaming up. + * + * @param resource $curl_handle (Required) The cURL handle for the request. + * @param resource $file_handle (Required) The open file handle resource. + * @param integer $length (Required) The maximum number of bytes to read. + * @return binary Binary data from a stream. + */ + public function streaming_read_callback($curl_handle, $file_handle, $length) { + // Once we've sent as much as we're supposed to send... + if ($this->read_stream_read >= $this->read_stream_size) { + // Send EOF + return ''; + } + // If we're at the beginning of an upload and need to seek... + if ($this->read_stream_read == 0 && isset ( $this->seek_position ) && $this->seek_position !== ftell ( $this->read_stream )) { + if (fseek ( $this->read_stream, $this->seek_position ) !== 0) { + throw new BCS_RequestCore_Exception ( 'The stream does not support seeking and is either not at the requested position or the position is unknown.' ); + } + } + $read = fread ( $this->read_stream, min ( $this->read_stream_size - $this->read_stream_read, $length ) ); // Remaining upload data or cURL's requested chunk size + $this->read_stream_read += strlen ( $read ); + $out = $read === false ? '' : $read; + // Execute callback function + if ($this->registered_streaming_read_callback) { + call_user_func ( $this->registered_streaming_read_callback, $curl_handle, $file_handle, $out ); + } + return $out; + } + + /** + * A callback function that is invoked by cURL for streaming down. + * + * @param resource $curl_handle (Required) The cURL handle for the request. + * @param binary $data (Required) The data to write. + * @return integer The number of bytes written. + */ + public function streaming_write_callback($curl_handle, $data) { + $length = strlen ( $data ); + $written_total = 0; + $written_last = 0; + while ( $written_total < $length ) { + $written_last = fwrite ( $this->write_stream, substr ( $data, $written_total ) ); + if ($written_last === false) { + return $written_total; + } + $written_total += $written_last; + } + // Execute callback function + if ($this->registered_streaming_write_callback) { + call_user_func ( $this->registered_streaming_write_callback, $curl_handle, $written_total ); + } + return $written_total; + } + + /** + * Prepares and adds the details of the cURL request. This can be passed along to a + * function. + * + * @return resource The handle for the cURL object. + */ + public function prep_request() { + $curl_handle = curl_init (); + // Set default options. + curl_setopt ( $curl_handle, CURLOPT_URL, $this->request_url ); + curl_setopt ( $curl_handle, CURLOPT_FILETIME, true ); + curl_setopt ( $curl_handle, CURLOPT_FRESH_CONNECT, false ); + curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYPEER, false ); + curl_setopt ( $curl_handle, CURLOPT_SSL_VERIFYHOST, true ); + curl_setopt ( $curl_handle, CURLOPT_CLOSEPOLICY, CURLCLOSEPOLICY_LEAST_RECENTLY_USED ); + curl_setopt ( $curl_handle, CURLOPT_MAXREDIRS, 5 ); + curl_setopt ( $curl_handle, CURLOPT_HEADER, true ); + curl_setopt ( $curl_handle, CURLOPT_RETURNTRANSFER, true ); + curl_setopt ( $curl_handle, CURLOPT_TIMEOUT, 5184000 ); + curl_setopt ( $curl_handle, CURLOPT_CONNECTTIMEOUT, 120 ); + curl_setopt ( $curl_handle, CURLOPT_NOSIGNAL, true ); + curl_setopt ( $curl_handle, CURLOPT_REFERER, $this->request_url ); + curl_setopt ( $curl_handle, CURLOPT_USERAGENT, $this->useragent ); + curl_setopt ( $curl_handle, CURLOPT_READFUNCTION, array ( + $this, + 'streaming_read_callback' ) ); + if ($this->debug_mode) { + curl_setopt ( $curl_handle, CURLOPT_VERBOSE, true ); + } + //if (! ini_get ( 'safe_mode' )) { + //modify by zhengkan + //curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true); + //} + // Enable a proxy connection if requested. + if ($this->proxy) { + curl_setopt ( $curl_handle, CURLOPT_HTTPPROXYTUNNEL, true ); + $host = $this->proxy ['host']; + $host .= ($this->proxy ['port']) ? ':' . $this->proxy ['port'] : ''; + curl_setopt ( $curl_handle, CURLOPT_PROXY, $host ); + if (isset ( $this->proxy ['user'] ) && isset ( $this->proxy ['pass'] )) { + curl_setopt ( $curl_handle, CURLOPT_PROXYUSERPWD, $this->proxy ['user'] . ':' . $this->proxy ['pass'] ); + } + } + // Set credentials for HTTP Basic/Digest Authentication. + if ($this->username && $this->password) { + curl_setopt ( $curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY ); + curl_setopt ( $curl_handle, CURLOPT_USERPWD, $this->username . ':' . $this->password ); + } + // Handle the encoding if we can. + if (extension_loaded ( 'zlib' )) { + curl_setopt ( $curl_handle, CURLOPT_ENCODING, '' ); + } + // Process custom headers + if (isset ( $this->request_headers ) && count ( $this->request_headers )) { + $temp_headers = array (); + foreach ( $this->request_headers as $k => $v ) { + $temp_headers [] = $k . ': ' . $v; + } + curl_setopt ( $curl_handle, CURLOPT_HTTPHEADER, $temp_headers ); + } + switch ($this->method) { + case self::HTTP_PUT : + curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, 'PUT' ); + if (isset ( $this->read_stream )) { + if (! isset ( $this->read_stream_size ) || $this->read_stream_size < 0) { + throw new BCS_RequestCore_Exception ( 'The stream size for the streaming upload cannot be determined.' ); + } + curl_setopt ( $curl_handle, CURLOPT_INFILESIZE, $this->read_stream_size ); + curl_setopt ( $curl_handle, CURLOPT_UPLOAD, true ); + } else { + curl_setopt ( $curl_handle, CURLOPT_POSTFIELDS, $this->request_body ); + } + break; + case self::HTTP_POST : + curl_setopt ( $curl_handle, CURLOPT_POST, true ); + curl_setopt ( $curl_handle, CURLOPT_POSTFIELDS, $this->request_body ); + break; + case self::HTTP_HEAD : + curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, self::HTTP_HEAD ); + curl_setopt ( $curl_handle, CURLOPT_NOBODY, 1 ); + break; + default : // Assumed GET + curl_setopt ( $curl_handle, CURLOPT_CUSTOMREQUEST, $this->method ); + if (isset ( $this->write_stream )) { + curl_setopt ( $curl_handle, CURLOPT_WRITEFUNCTION, array ( + $this, + 'streaming_write_callback' ) ); + curl_setopt ( $curl_handle, CURLOPT_HEADER, false ); + } else { + curl_setopt ( $curl_handle, CURLOPT_POSTFIELDS, $this->request_body ); + } + break; + } + // Merge in the CURLOPTs + if (isset ( $this->curlopts ) && sizeof ( $this->curlopts ) > 0) { + foreach ( $this->curlopts as $k => $v ) { + curl_setopt ( $curl_handle, $k, $v ); + } + } + return $curl_handle; + } + + /** + * is the environment BAE? + * @return boolean the result of the answer + */ + private function isBaeEnv() { + if (isset ( $_SERVER ['HTTP_HOST'] )) { + $host = $_SERVER ['HTTP_HOST']; + $pos = strpos ( $host, '.' ); + if ($pos !== false) { + $substr = substr ( $host, $pos + 1 ); + if ($substr == 'duapp.com') { + return true; + } + } + } + if (isset ( $_SERVER ["HTTP_BAE_LOGID"] )) { + return true; + } + + return false; + } + + /** + * Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the + * data stored in the `curl_handle` and `response` properties unless replacement data is passed in via + * parameters. + * + * @param resource $curl_handle (Optional) The reference to the already executed cURL request. + * @param string $response (Optional) The actual response content itself that needs to be parsed. + * @return BCS_ResponseCore A object containing a parsed HTTP response. + */ + public function process_response($curl_handle = null, $response = null) { + // Accept a custom one if it's passed. + if ($curl_handle && $response) { + $this->curl_handle = $curl_handle; + $this->response = $response; + } + // As long as this came back as a valid resource... + if (is_resource ( $this->curl_handle )) { + // Determine what's what. + $header_size = curl_getinfo ( $this->curl_handle, CURLINFO_HEADER_SIZE ); + $this->response_headers = substr ( $this->response, 0, $header_size ); + $this->response_body = substr ( $this->response, $header_size ); + $this->response_code = curl_getinfo ( $this->curl_handle, CURLINFO_HTTP_CODE ); + $this->response_info = curl_getinfo ( $this->curl_handle ); + // Parse out the headers + $this->response_headers = explode ( "\r\n\r\n", trim ( $this->response_headers ) ); + $this->response_headers = array_pop ( $this->response_headers ); + $this->response_headers = explode ( "\r\n", $this->response_headers ); + array_shift ( $this->response_headers ); + // Loop through and split up the headers. + $header_assoc = array (); + foreach ( $this->response_headers as $header ) { + $kv = explode ( ': ', $header ); + //$header_assoc [strtolower ( $kv [0] )] = $kv [1]; + $header_assoc [$kv [0]] = $kv [1]; + } + // Reset the headers to the appropriate property. + $this->response_headers = $header_assoc; + $this->response_headers ['_info'] = $this->response_info; + $this->response_headers ['_info'] ['method'] = $this->method; + if ($curl_handle && $response) { + $class='\Think\Upload\Driver\Bcs\\'. $this->response_class; + return new $class ( $this->response_headers, $this->response_body, $this->response_code, $this->curl_handle ); + } + } + // Return false + return false; + } + + /** + * Sends the request, calling necessary utility functions to update built-in properties. + * + * @param boolean $parse (Optional) Whether to parse the response with BCS_ResponseCore or not. + * @return string The resulting unparsed data from the request. + */ + public function send_request($parse = false) { + if (false === $this->isBaeEnv ()) { + set_time_limit ( 0 ); + } + $curl_handle = $this->prep_request (); + $this->response = curl_exec ( $curl_handle ); + if ($this->response === false || + ($this->method === self::HTTP_GET && + curl_errno($curl_handle) === CURLE_PARTIAL_FILE)) { + throw new BCS_RequestCore_Exception ( 'cURL resource: ' . ( string ) $curl_handle . '; cURL error: ' . curl_error ( $curl_handle ) . ' (' . curl_errno ( $curl_handle ) . ')' ); + } + $parsed_response = $this->process_response ( $curl_handle, $this->response ); + curl_close ( $curl_handle ); + if ($parse) { + return $parsed_response; + } + return $this->response; + } + + /** + * Sends the request using , enabling parallel requests. Uses the "rolling" method. + * + * @param array $handles (Required) An indexed array of cURL handles to process simultaneously. + * @param array $opt (Optional) An associative array of parameters that can have the following keys:
    + *
  • callback - string|array - Optional - The string name of a function to pass the response data to. If this is a method, pass an array where the [0] index is the class and the [1] index is the method name.
  • + *
  • limit - integer - Optional - The number of simultaneous requests to make. This can be useful for scaling around slow server responses. Defaults to trusting cURLs judgement as to how many to use.
+ * @return array Post-processed cURL responses. + */ + public function send_multi_request($handles, $opt = null) { + if (false === $this->isBaeEnv ()) { + set_time_limit ( 0 ); + } + // Skip everything if there are no handles to process. + if (count ( $handles ) === 0) + return array (); + if (! $opt) + $opt = array (); + + // Initialize any missing options + $limit = isset ( $opt ['limit'] ) ? $opt ['limit'] : - 1; + // Initialize + $handle_list = $handles; + $http = new $this->request_class (); + $multi_handle = curl_multi_init (); + $handles_post = array (); + $added = count ( $handles ); + $last_handle = null; + $count = 0; + $i = 0; + // Loop through the cURL handles and add as many as it set by the limit parameter. + while ( $i < $added ) { + if ($limit > 0 && $i >= $limit) + break; + curl_multi_add_handle ( $multi_handle, array_shift ( $handles ) ); + $i ++; + } + do { + $active = false; + // Start executing and wait for a response. + while ( ($status = curl_multi_exec ( $multi_handle, $active )) === CURLM_CALL_MULTI_PERFORM ) { + // Start looking for possible responses immediately when we have to add more handles + if (count ( $handles ) > 0) + break; + } + // Figure out which requests finished. + $to_process = array (); + while ( $done = curl_multi_info_read ( $multi_handle ) ) { + // Since curl_errno() isn't reliable for handles that were in multirequests, we check the 'result' of the info read, which contains the curl error number, (listed here http://curl.haxx.se/libcurl/c/libcurl-errors.html ) + if ($done ['result'] > 0) { + throw new BCS_RequestCore_Exception ( 'cURL resource: ' . ( string ) $done ['handle'] . '; cURL error: ' . curl_error ( $done ['handle'] ) . ' (' . $done ['result'] . ')' ); + } // Because curl_multi_info_read() might return more than one message about a request, we check to see if this request is already in our array of completed requests +elseif (! isset ( $to_process [( int ) $done ['handle']] )) { + $to_process [( int ) $done ['handle']] = $done; + } + } + // Actually deal with the request + foreach ( $to_process as $pkey => $done ) { + $response = $http->process_response ( $done ['handle'], curl_multi_getcontent ( $done ['handle'] ) ); + $key = array_search ( $done ['handle'], $handle_list, true ); + $handles_post [$key] = $response; + if (count ( $handles ) > 0) { + curl_multi_add_handle ( $multi_handle, array_shift ( $handles ) ); + } + curl_multi_remove_handle ( $multi_handle, $done ['handle'] ); + curl_close ( $done ['handle'] ); + } + } while ( $active || count ( $handles_post ) < $added ); + curl_multi_close ( $multi_handle ); + ksort ( $handles_post, SORT_NUMERIC ); + return $handles_post; + } + + /*%******************************************************************************************%*/ + // RESPONSE METHODS + /** + * Get the HTTP response headers from the request. + * + * @param string $header (Optional) A specific header value to return. Defaults to all headers. + * @return string|array All or selected header values. + */ + public function get_response_header($header = null) { + if ($header) { + // return $this->response_headers [strtolower ( $header )]; + return $this->response_headers [$header]; + } + return $this->response_headers; + } + + /** + * Get the HTTP response body from the request. + * + * @return string The response body. + */ + public function get_response_body() { + return $this->response_body; + } + + /** + * Get the HTTP response code from the request. + * + * @return string The HTTP response code. + */ + public function get_response_code() { + return $this->response_code; + } +} +/** + * Container for all response-related methods. + */ +class BCS_ResponseCore { + /** + * Stores the HTTP header information. + */ + public $header; + /** + * Stores the SimpleXML response. + */ + public $body; + /** + * Stores the HTTP response code. + */ + public $status; + + /** + * Constructs a new instance of this class. + * + * @param array $header (Required) Associative array of HTTP headers (typically returned by ). + * @param string $body (Required) XML-formatted response from AWS. + * @param integer $status (Optional) HTTP response status code from the request. + * @return object Contains an `header` property (HTTP headers as an associative array), a or `body` property, and an `status` code. + */ + public function __construct($header, $body, $status = null) { + $this->header = $header; + $this->body = $body; + $this->status = $status; + return $this; + } + + /** + * Did we receive the status code we expected? + * + * @param integer|array $codes (Optional) The status code(s) to expect. Pass an for a single acceptable value, or an of integers for multiple acceptable values. + * @return boolean Whether we received the expected status code or not. + */ + public function isOK($codes = array(200, 201, 204, 206)) { + if (is_array ( $codes )) { + return in_array ( $this->status, $codes ); + } + return $this->status === $codes; + } +} +/** + * Default BCS_RequestCore Exception. + */ +class BCS_RequestCore_Exception extends \Exception { +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Ftp.class.php b/ThinkPHP/Library/Think/Upload/Driver/Ftp.class.php new file mode 100644 index 0000000..fccf9a6 --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Ftp.class.php @@ -0,0 +1,163 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Upload\Driver; +class Ftp { + /** + * 上传文件根目录 + * @var string + */ + private $rootPath; + + /** + * 本地上传错误信息 + * @var string + */ + private $error = ''; //上传错误信息 + + /** + * FTP连接 + * @var resource + */ + private $link; + + private $config = array( + 'host' => '', //服务器 + 'port' => 21, //端口 + 'timeout' => 90, //超时时间 + 'username' => '', //用户名 + 'password' => '', //密码 + ); + + /** + * 构造函数,用于设置上传根路径 + * @param array $config FTP配置 + */ + public function __construct($config){ + /* 默认FTP配置 */ + $this->config = array_merge($this->config, $config); + + /* 登录FTP服务器 */ + if(!$this->login()){ + E($this->error); + } + } + + /** + * 检测上传根目录 + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + /* 设置根目录 */ + $this->rootPath = ftp_pwd($this->link) . '/' . ltrim($rootpath, '/'); + + if(!@ftp_chdir($this->link, $this->rootPath)){ + $this->error = '上传根目录不存在!'; + return false; + } + return true; + } + + /** + * 检测上传目录 + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + /* 检测并创建目录 */ + if (!$this->mkdir($savepath)) { + return false; + } else { + //TODO:检测目录是否可写 + return true; + } + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save($file, $replace=true) { + $filename = $this->rootPath . $file['savepath'] . $file['savename']; + + /* 不覆盖同名文件 */ + // if (!$replace && is_file($filename)) { + // $this->error = '存在同名文件' . $file['savename']; + // return false; + // } + + /* 移动文件 */ + if (!ftp_put($this->link, $filename, $file['tmp_name'], FTP_BINARY)) { + $this->error = '文件上传保存错误!'; + return false; + } + return true; + } + + /** + * 创建目录 + * @param string $savepath 要创建的目录 + * @return boolean 创建状态,true-成功,false-失败 + */ + public function mkdir($savepath){ + $dir = $this->rootPath . $savepath; + if(ftp_chdir($this->link, $dir)){ + return true; + } + + if(ftp_mkdir($this->link, $dir)){ + return true; + } elseif($this->mkdir(dirname($savepath)) && ftp_mkdir($this->link, $dir)) { + return true; + } else { + $this->error = "目录 {$savepath} 创建失败!"; + return false; + } + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + + /** + * 登录到FTP服务器 + * @return boolean true-登录成功,false-登录失败 + */ + private function login(){ + extract($this->config); + $this->link = ftp_connect($host, $port, $timeout); + if($this->link) { + if (ftp_login($this->link, $username, $password)) { + return true; + } else { + $this->error = "无法登录到FTP服务器:username - {$username}"; + } + } else { + $this->error = "无法连接到FTP服务器:{$host}"; + } + return false; + } + + /** + * 析构方法,用于断开当前FTP连接 + */ + public function __destruct() { + ftp_close($this->link); + } + +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Local.class.php b/ThinkPHP/Library/Think/Upload/Driver/Local.class.php new file mode 100644 index 0000000..5988d5a --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Local.class.php @@ -0,0 +1,118 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Upload\Driver; +class Local{ + /** + * 上传文件根目录 + * @var string + */ + private $rootPath; + + /** + * 本地上传错误信息 + * @var string + */ + private $error = ''; //上传错误信息 + + /** + * 构造函数,用于设置上传根路径 + */ + public function __construct($config = null){ + + } + + /** + * 检测上传根目录 + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + if(!(is_dir($rootpath) && is_writable($rootpath))){ + $this->error = '上传根目录不存在!请尝试手动创建:'.$rootpath; + return false; + } + $this->rootPath = $rootpath; + return true; + } + + /** + * 检测上传目录 + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + /* 检测并创建目录 */ + if (!$this->mkdir($savepath)) { + return false; + } else { + /* 检测目录是否可写 */ + if (!is_writable($this->rootPath . $savepath)) { + $this->error = '上传目录 ' . $savepath . ' 不可写!'; + return false; + } else { + return true; + } + } + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save($file, $replace=true) { + $filename = $this->rootPath . $file['savepath'] . $file['savename']; + + /* 不覆盖同名文件 */ + if (!$replace && is_file($filename)) { + $this->error = '存在同名文件' . $file['savename']; + return false; + } + + /* 移动文件 */ + if (!move_uploaded_file($file['tmp_name'], $filename)) { + $this->error = '文件上传保存错误!'; + return false; + } + + return true; + } + + /** + * 创建目录 + * @param string $savepath 要创建的穆里 + * @return boolean 创建状态,true-成功,false-失败 + */ + public function mkdir($savepath){ + $dir = $this->rootPath . $savepath; + if(is_dir($dir)){ + return true; + } + + if(mkdir($dir, 0777, true)){ + return true; + } else { + $this->error = "目录 {$savepath} 创建失败!"; + return false; + } + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Qiniu.class.php b/ThinkPHP/Library/Think/Upload/Driver/Qiniu.class.php new file mode 100644 index 0000000..c745f9f --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Qiniu.class.php @@ -0,0 +1,102 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Upload\Driver; +use Think\Upload\Driver\Qiniu\QiniuStorage; + +class Qiniu{ + /** + * 上传文件根目录 + * @var string + */ + private $rootPath; + + /** + * 上传错误信息 + * @var string + */ + private $error = ''; + + private $config = array( + 'secretKey' => '', //七牛服务器 + 'accessKey' => '', //七牛用户 + 'domain' => '', //七牛密码 + 'bucket' => '', //空间名称 + 'timeout' => 300, //超时时间 + ); + + /** + * 构造函数,用于设置上传根路径 + * @param array $config FTP配置 + */ + public function __construct($config){ + $this->config = array_merge($this->config, $config); + /* 设置根目录 */ + $this->qiniu = new QiniuStorage($config); + } + + /** + * 检测上传根目录(七牛上传时支持自动创建目录,直接返回) + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + $this->rootPath = trim($rootpath, './') . '/'; + return true; + } + + /** + * 检测上传目录(七牛上传时支持自动创建目录,直接返回) + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + return true; + } + + /** + * 创建文件夹 (七牛上传时支持自动创建目录,直接返回) + * @param string $savepath 目录名称 + * @return boolean true-创建成功,false-创建失败 + */ + public function mkdir($savepath){ + return true; + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save(&$file,$replace=true) { + $file['name'] = $file['savepath'] . $file['savename']; + $key = str_replace('/', '_', $file['name']); + $upfile = array( + 'name'=>'file', + 'fileName'=>$key, + 'fileBody'=>file_get_contents($file['tmp_name']) + ); + $config = array(); + $result = $this->qiniu->upload($config, $upfile); + $url = $this->qiniu->downlink($key); + $file['url'] = $url; + return false ===$result ? false : true; + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->qiniu->errorStr; + } +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Qiniu/QiniuStorage.class.php b/ThinkPHP/Library/Think/Upload/Driver/Qiniu/QiniuStorage.class.php new file mode 100644 index 0000000..472e0b4 --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Qiniu/QiniuStorage.class.php @@ -0,0 +1,333 @@ +sk = $config['secretKey']; + $this->ak = $config['accessKey']; + $this->domain = $config['domain']; + $this->bucket = $config['bucket']; + $this->timeout = isset($config['timeout'])? $config['timeout'] : 3600; + } + + static function sign($sk, $ak, $data){ + $sign = hash_hmac('sha1', $data, $sk, true); + return $ak . ':' . self::Qiniu_Encode($sign); + } + + static function signWithData($sk, $ak, $data){ + $data = self::Qiniu_Encode($data); + return self::sign($sk, $ak, $data) . ':' . $data; + } + + public function accessToken($url, $body=''){ + $parsed_url = parse_url($url); + $path = $parsed_url['path']; + $access = $path; + if (isset($parsed_url['query'])) { + $access .= "?" . $parsed_url['query']; + } + $access .= "\n"; + + if($body){ + $access .= $body; + } + return self::sign($this->sk, $this->ak, $access); + } + + public function UploadToken($sk ,$ak ,$param){ + $param['deadline'] = $param['Expires'] == 0? 3600: $param['Expires']; + $param['deadline'] += time(); + $data = array('scope'=> $this->bucket, 'deadline'=>$param['deadline']); + if (!empty($param['CallbackUrl'])) { + $data['callbackUrl'] = $param['CallbackUrl']; + } + if (!empty($param['CallbackBody'])) { + $data['callbackBody'] = $param['CallbackBody']; + } + if (!empty($param['ReturnUrl'])) { + $data['returnUrl'] = $param['ReturnUrl']; + } + if (!empty($param['ReturnBody'])) { + $data['returnBody'] = $param['ReturnBody']; + } + if (!empty($param['AsyncOps'])) { + $data['asyncOps'] = $param['AsyncOps']; + } + if (!empty($param['EndUser'])) { + $data['endUser'] = $param['EndUser']; + } + $data = json_encode($data); + return self::SignWithData($sk, $ak, $data); + } + + public function upload($config, $file){ + $uploadToken = $this->UploadToken($this->sk, $this->ak, $config); + + $url = "{$this->QINIU_UP_HOST}"; + $mimeBoundary = md5(microtime()); + $header = array('Content-Type'=>'multipart/form-data;boundary='.$mimeBoundary); + $data = array(); + + $fields = array( + 'token' => $uploadToken, + 'key' => $config['saveName']? : $file['fileName'], + ); + + if(is_array($config['custom_fields']) && $config['custom_fields'] !== array()){ + $fields = array_merge($fields, $config['custom_fields']); + } + + foreach ($fields as $name => $val) { + array_push($data, '--' . $mimeBoundary); + array_push($data, "Content-Disposition: form-data; name=\"$name\""); + array_push($data, ''); + array_push($data, $val); + } + + //文件 + array_push($data, '--' . $mimeBoundary); + $name = $file['name']; + $fileName = $file['fileName']; + $fileBody = $file['fileBody']; + $fileName = self::Qiniu_escapeQuotes($fileName); + array_push($data, "Content-Disposition: form-data; name=\"$name\"; filename=\"$fileName\""); + array_push($data, 'Content-Type: application/octet-stream'); + array_push($data, ''); + array_push($data, $fileBody); + + array_push($data, '--' . $mimeBoundary . '--'); + array_push($data, ''); + + $body = implode("\r\n", $data); + $response = $this->request($url, 'POST', $header, $body); + return $response; + } + + public function dealWithType($key, $type){ + $param = $this->buildUrlParam(); + $url = ''; + + switch($type){ + case 'img': + $url = $this->downLink($key); + if($param['imageInfo']){ + $url .= '?imageInfo'; + }else if($param['exif']){ + $url .= '?exif'; + }else if($param['imageView']){ + $url .= '?imageView/'.$param['mode']; + if($param['w']) + $url .= "/w/{$param['w']}"; + if($param['h']) + $url .= "/h/{$param['h']}"; + if($param['q']) + $url .= "/q/{$param['q']}"; + if($param['format']) + $url .= "/format/{$param['format']}"; + } + break; + case 'video': //TODO 视频处理 + case 'doc': + $url = $this->downLink($key); + $url .= '?md2html'; + if(isset($param['mode'])) + $url .= '/'.(int)$param['mode']; + if($param['cssurl']) + $url .= '/'. self::Qiniu_Encode($param['cssurl']); + break; + + } + return $url; + } + + public function buildUrlParam(){ + return $_REQUEST; + } + + //获取某个路径下的文件列表 + public function getList($query = array(), $path = ''){ + $query = array_merge(array('bucket'=>$this->bucket), $query); + $url = "{$this->QINIU_RSF_HOST}/list?".http_build_query($query); + $accessToken = $this->accessToken($url); + $response = $this->request($url, 'POST', array('Authorization'=>"QBox $accessToken")); + return $response; + } + + //获取某个文件的信息 + public function info($key){ + $key = trim($key); + $url = "{$this->QINIU_RS_HOST}/stat/" . self::Qiniu_Encode("{$this->bucket}:{$key}"); + $accessToken = $this->accessToken($url); + $response = $this->request($url, 'POST', array( + 'Authorization' => "QBox $accessToken", + )); + return $response; + } + + //获取文件下载资源链接 + public function downLink($key){ + $key = urlencode($key); + $key = self::Qiniu_escapeQuotes($key); + $url = "http://{$this->domain}/{$key}"; + return $url; + } + + //重命名单个文件 + public function rename($file, $new_file){ + $key = trim($file); + $url = "{$this->QINIU_RS_HOST}/move/" . self::Qiniu_Encode("{$this->bucket}:{$key}") .'/'. self::Qiniu_Encode("{$this->bucket}:{$new_file}"); + trace($url); + $accessToken = $this->accessToken($url); + $response = $this->request($url, 'POST', array('Authorization'=>"QBox $accessToken")); + return $response; + } + + //删除单个文件 + public function del($file){ + $key = trim($file); + $url = "{$this->QINIU_RS_HOST}/delete/" . self::Qiniu_Encode("{$this->bucket}:{$key}"); + $accessToken = $this->accessToken($url); + $response = $this->request($url, 'POST', array('Authorization'=>"QBox $accessToken")); + return $response; + } + + //批量删除文件 + public function delBatch($files){ + $url = $this->QINIU_RS_HOST . '/batch'; + $ops = array(); + foreach ($files as $file) { + $ops[] = "/delete/". self::Qiniu_Encode("{$this->bucket}:{$file}"); + } + $params = 'op=' . implode('&op=', $ops); + $url .= '?'.$params; + trace($url); + $accessToken = $this->accessToken($url); + $response = $this->request($url, 'POST', array('Authorization'=>"QBox $accessToken")); + return $response; + } + + static function Qiniu_Encode($str) {// URLSafeBase64Encode + $find = array('+', '/'); + $replace = array('-', '_'); + return str_replace($find, $replace, base64_encode($str)); + } + + static function Qiniu_escapeQuotes($str){ + $find = array("\\", "\""); + $replace = array("\\\\", "\\\""); + return str_replace($find, $replace, $str); + } + + /** + * 请求云服务器 + * @param string $path 请求的PATH + * @param string $method 请求方法 + * @param array $headers 请求header + * @param resource $body 上传文件资源 + * @return boolean + */ + private function request($path, $method, $headers = null, $body = null){ + $ch = curl_init($path); + + $_headers = array('Expect:'); + if (!is_null($headers) && is_array($headers)){ + foreach($headers as $k => $v) { + array_push($_headers, "{$k}: {$v}"); + } + } + + $length = 0; + $date = gmdate('D, d M Y H:i:s \G\M\T'); + + if (!is_null($body)) { + if(is_resource($body)){ + fseek($body, 0, SEEK_END); + $length = ftell($body); + fseek($body, 0); + + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_INFILE, $body); + curl_setopt($ch, CURLOPT_INFILESIZE, $length); + } else { + $length = @strlen($body); + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + } else { + array_push($_headers, "Content-Length: {$length}"); + } + + // array_push($_headers, 'Authorization: ' . $this->sign($method, $uri, $date, $length)); + array_push($_headers, "Date: {$date}"); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + + if ($method == 'PUT' || $method == 'POST') { + curl_setopt($ch, CURLOPT_POST, 1); + } else { + curl_setopt($ch, CURLOPT_POST, 0); + } + + if ($method == 'HEAD') { + curl_setopt($ch, CURLOPT_NOBODY, true); + } + + $response = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + list($header, $body) = explode("\r\n\r\n", $response, 2); + if ($status == 200) { + if ($method == 'GET') { + return $body; + } else { + return $this->response($response); + } + } else { + $this->error($header , $body); + return false; + } + } + + /** + * 获取响应数据 + * @param string $text 响应头字符串 + * @return array 响应数据列表 + */ + private function response($text){ + $headers = explode(PHP_EOL, $text); + $items = array(); + foreach($headers as $header) { + $header = trim($header); + if(strpos($header, '{') !== False){ + $items = json_decode($header, 1); + break; + } + } + return $items; + } + + /** + * 获取请求错误信息 + * @param string $header 请求返回头信息 + */ + private function error($header, $body) { + list($status, $stash) = explode("\r\n", $header, 2); + list($v, $code, $message) = explode(" ", $status, 3); + $message = is_null($message) ? 'File Not Found' : "[{$status}]:{$message}]"; + $this->error = $message; + $this->errorStr = json_decode($body ,1); + $this->errorStr = $this->errorStr['error']; + } + } diff --git a/ThinkPHP/Library/Think/Upload/Driver/Sae.class.php b/ThinkPHP/Library/Think/Upload/Driver/Sae.class.php new file mode 100644 index 0000000..82c77d6 --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Sae.class.php @@ -0,0 +1,106 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Upload\Driver; +class Sae{ + /** + * Storage的Domain + * @var string + */ + private $domain = ''; + + private $rootPath = ''; + + /** + * 本地上传错误信息 + * @var string + */ + private $error = ''; + + /** + * 构造函数,设置storage的domain, 如果有传配置,则domain为配置项,如果没有传domain为第一个路径的目录名称。 + * @param mixed $config 上传配置 + */ + public function __construct($config = null){ + if(is_array($config) && !empty($config['domain'])){ + $this->domain = strtolower($config['domain']); + } + } + + /** + * 检测上传根目录 + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + $rootpath = trim($rootpath,'./'); + if(!$this->domain){ + $rootpath = explode('/', $rootpath); + $this->domain = strtolower(array_shift($rootpath)); + $rootpath = implode('/', $rootpath); + } + + $this->rootPath = $rootpath; + $st = new \SaeStorage(); + if(false===$st->getDomainCapacity($this->domain)){ + $this->error = '您好像没有建立Storage的domain['.$this->domain.']'; + return false; + } + return true; + } + + /** + * 检测上传目录 + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + return true; + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save(&$file, $replace=true) { + $filename = ltrim($this->rootPath .'/'. $file['savepath'] . $file['savename'],'/'); + $st = new \SaeStorage(); + /* 不覆盖同名文件 */ + if (!$replace && $st->fileExists($this->domain,$filename)) { + $this->error = '存在同名文件' . $file['savename']; + return false; + } + + /* 移动文件 */ + if (!$st->upload($this->domain,$filename,$file['tmp_name'])) { + $this->error = '文件上传保存错误!['.$st->errno().']:'.$st->errmsg(); + return false; + }else{ + $file['url'] = $st->getUrl($this->domain, $filename); + } + return true; + } + + public function mkdir(){ + return true; + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + +} diff --git a/ThinkPHP/Library/Think/Upload/Driver/Upyun.class.php b/ThinkPHP/Library/Think/Upload/Driver/Upyun.class.php new file mode 100644 index 0000000..c159526 --- /dev/null +++ b/ThinkPHP/Library/Think/Upload/Driver/Upyun.class.php @@ -0,0 +1,218 @@ + +// +---------------------------------------------------------------------- + +namespace Think\Upload\Driver; +class Upyun{ + /** + * 上传文件根目录 + * @var string + */ + private $rootPath; + + /** + * 上传错误信息 + * @var string + */ + private $error = ''; + + private $config = array( + 'host' => '', //又拍云服务器 + 'username' => '', //又拍云用户 + 'password' => '', //又拍云密码 + 'bucket' => '', //空间名称 + 'timeout' => 90, //超时时间 + ); + + /** + * 构造函数,用于设置上传根路径 + * @param array $config FTP配置 + */ + public function __construct($config){ + /* 默认FTP配置 */ + $this->config = array_merge($this->config, $config); + $this->config['password'] = md5($this->config['password']); + } + + /** + * 检测上传根目录(又拍云上传时支持自动创建目录,直接返回) + * @param string $rootpath 根目录 + * @return boolean true-检测通过,false-检测失败 + */ + public function checkRootPath($rootpath){ + /* 设置根目录 */ + $this->rootPath = trim($rootpath, './') . '/'; + return true; + } + + /** + * 检测上传目录(又拍云上传时支持自动创建目录,直接返回) + * @param string $savepath 上传目录 + * @return boolean 检测结果,true-通过,false-失败 + */ + public function checkSavePath($savepath){ + return true; + } + + /** + * 创建文件夹 (又拍云上传时支持自动创建目录,直接返回) + * @param string $savepath 目录名称 + * @return boolean true-创建成功,false-创建失败 + */ + public function mkdir($savepath){ + return true; + } + + /** + * 保存指定文件 + * @param array $file 保存的文件信息 + * @param boolean $replace 同名文件是否覆盖 + * @return boolean 保存状态,true-成功,false-失败 + */ + public function save($file, $replace = true) { + $header['Content-Type'] = $file['type']; + $header['Content-MD5'] = $file['md5']; + $header['Mkdir'] = 'true'; + $resource = fopen($file['tmp_name'], 'r'); + + $save = $this->rootPath . $file['savepath'] . $file['savename']; + $data = $this->request($save, 'PUT', $header, $resource); + return false === $data ? false : true; + } + + /** + * 获取最后一次上传错误信息 + * @return string 错误信息 + */ + public function getError(){ + return $this->error; + } + + /** + * 请求又拍云服务器 + * @param string $path 请求的PATH + * @param string $method 请求方法 + * @param array $headers 请求header + * @param resource $body 上传文件资源 + * @return boolean + */ + private function request($path, $method, $headers = null, $body = null){ + $uri = "/{$this->config['bucket']}/{$path}"; + $ch = curl_init($this->config['host'] . $uri); + + $_headers = array('Expect:'); + if (!is_null($headers) && is_array($headers)){ + foreach($headers as $k => $v) { + array_push($_headers, "{$k}: {$v}"); + } + } + + $length = 0; + $date = gmdate('D, d M Y H:i:s \G\M\T'); + + if (!is_null($body)) { + if(is_resource($body)){ + fseek($body, 0, SEEK_END); + $length = ftell($body); + fseek($body, 0); + + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_INFILE, $body); + curl_setopt($ch, CURLOPT_INFILESIZE, $length); + } else { + $length = @strlen($body); + array_push($_headers, "Content-Length: {$length}"); + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); + } + } else { + array_push($_headers, "Content-Length: {$length}"); + } + + array_push($_headers, 'Authorization: ' . $this->sign($method, $uri, $date, $length)); + array_push($_headers, "Date: {$date}"); + + curl_setopt($ch, CURLOPT_HTTPHEADER, $_headers); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->config['timeout']); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + + if ($method == 'PUT' || $method == 'POST') { + curl_setopt($ch, CURLOPT_POST, 1); + } else { + curl_setopt($ch, CURLOPT_POST, 0); + } + + if ($method == 'HEAD') { + curl_setopt($ch, CURLOPT_NOBODY, true); + } + + $response = curl_exec($ch); + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + list($header, $body) = explode("\r\n\r\n", $response, 2); + + if ($status == 200) { + if ($method == 'GET') { + return $body; + } else { + $data = $this->response($header); + return count($data) > 0 ? $data : true; + } + } else { + $this->error($header); + return false; + } + } + + /** + * 获取响应数据 + * @param string $text 响应头字符串 + * @return array 响应数据列表 + */ + private function response($text){ + $headers = explode("\r\n", $text); + $items = array(); + foreach($headers as $header) { + $header = trim($header); + if(strpos($header, 'x-upyun') !== False){ + list($k, $v) = explode(':', $header); + $items[trim($k)] = in_array(substr($k,8,5), array('width','heigh','frame')) ? intval($v) : trim($v); + } + } + return $items; + } + + /** + * 生成请求签名 + * @param string $method 请求方法 + * @param string $uri 请求URI + * @param string $date 请求时间 + * @param integer $length 请求内容大小 + * @return string 请求签名 + */ + private function sign($method, $uri, $date, $length){ + $sign = "{$method}&{$uri}&{$date}&{$length}&{$this->config['password']}"; + return 'UpYun ' . $this->config['username'] . ':' . md5($sign); + } + + /** + * 获取请求错误信息 + * @param string $header 请求返回头信息 + */ + private function error($header) { + list($status, $stash) = explode("\r\n", $header, 2); + list($v, $code, $message) = explode(" ", $status, 3); + $message = is_null($message) ? 'File Not Found' : "[{$status}]:{$message}"; + $this->error = $message; + } + +} diff --git a/ThinkPHP/Library/Think/Verify.class.php b/ThinkPHP/Library/Think/Verify.class.php new file mode 100644 index 0000000..6e5e38a --- /dev/null +++ b/ThinkPHP/Library/Think/Verify.class.php @@ -0,0 +1,293 @@ + +// +---------------------------------------------------------------------- + +namespace Think; + +class Verify { + protected $config = array( + 'seKey' => 'ThinkPHP.CN', // 验证码加密密钥 + 'codeSet' => '2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY', // 验证码字符集合 + 'expire' => 1800, // 验证码过期时间(s) + 'useZh' => false, // 使用中文验证码 + 'zhSet' => '们以我到他会作时要动国产的一是工就年阶义发成部民可出能方进在了不和有大这主中人上为来分生对于学下级地个用同行面说种过命度革而多子后自社加小机也经力线本电高量长党得实家定深法表着水理化争现所二起政三好十战无农使性前等反体合斗路图把结第里正新开论之物从当两些还天资事队批点育重其思与间内去因件日利相由压员气业代全组数果期导平各基或月毛然如应形想制心样干都向变关问比展那它最及外没看治提五解系林者米群头意只明四道马认次文通但条较克又公孔领军流入接席位情运器并飞原油放立题质指建区验活众很教决特此常石强极土少已根共直团统式转别造切九你取西持总料连任志观调七么山程百报更见必真保热委手改管处己将修支识病象几先老光专什六型具示复安带每东增则完风回南广劳轮科北打积车计给节做务被整联步类集号列温装即毫知轴研单色坚据速防史拉世设达尔场织历花受求传口断况采精金界品判参层止边清至万确究书术状厂须离再目海交权且儿青才证低越际八试规斯近注办布门铁需走议县兵固除般引齿千胜细影济白格效置推空配刀叶率述今选养德话查差半敌始片施响收华觉备名红续均药标记难存测士身紧液派准斤角降维板许破述技消底床田势端感往神便贺村构照容非搞亚磨族火段算适讲按值美态黄易彪服早班麦削信排台声该击素张密害侯草何树肥继右属市严径螺检左页抗苏显苦英快称坏移约巴材省黑武培著河帝仅针怎植京助升王眼她抓含苗副杂普谈围食射源例致酸旧却充足短划剂宣环落首尺波承粉践府鱼随考刻靠够满夫失包住促枝局菌杆周护岩师举曲春元超负砂封换太模贫减阳扬江析亩木言球朝医校古呢稻宋听唯输滑站另卫字鼓刚写刘微略范供阿块某功套友限项余倒卷创律雨让骨远帮初皮播优占死毒圈伟季训控激找叫云互跟裂粮粒母练塞钢顶策双留误础吸阻故寸盾晚丝女散焊功株亲院冷彻弹错散商视艺灭版烈零室轻血倍缺厘泵察绝富城冲喷壤简否柱李望盘磁雄似困巩益洲脱投送奴侧润盖挥距触星松送获兴独官混纪依未突架宽冬章湿偏纹吃执阀矿寨责熟稳夺硬价努翻奇甲预职评读背协损棉侵灰虽矛厚罗泥辟告卵箱掌氧恩爱停曾溶营终纲孟钱待尽俄缩沙退陈讨奋械载胞幼哪剥迫旋征槽倒握担仍呀鲜吧卡粗介钻逐弱脚怕盐末阴丰雾冠丙街莱贝辐肠付吉渗瑞惊顿挤秒悬姆烂森糖圣凹陶词迟蚕亿矩康遵牧遭幅园腔订香肉弟屋敏恢忘编印蜂急拿扩伤飞露核缘游振操央伍域甚迅辉异序免纸夜乡久隶缸夹念兰映沟乙吗儒杀汽磷艰晶插埃燃欢铁补咱芽永瓦倾阵碳演威附牙芽永瓦斜灌欧献顺猪洋腐请透司危括脉宜笑若尾束壮暴企菜穗楚汉愈绿拖牛份染既秋遍锻玉夏疗尖殖井费州访吹荣铜沿替滚客召旱悟刺脑措贯藏敢令隙炉壳硫煤迎铸粘探临薄旬善福纵择礼愿伏残雷延烟句纯渐耕跑泽慢栽鲁赤繁境潮横掉锥希池败船假亮谓托伙哲怀割摆贡呈劲财仪沉炼麻罪祖息车穿货销齐鼠抽画饲龙库守筑房歌寒喜哥洗蚀废纳腹乎录镜妇恶脂庄擦险赞钟摇典柄辩竹谷卖乱虚桥奥伯赶垂途额壁网截野遗静谋弄挂课镇妄盛耐援扎虑键归符庆聚绕摩忙舞遇索顾胶羊湖钉仁音迹碎伸灯避泛亡答勇频皇柳哈揭甘诺概宪浓岛袭谁洪谢炮浇斑讯懂灵蛋闭孩释乳巨徒私银伊景坦累匀霉杜乐勒隔弯绩招绍胡呼痛峰零柴簧午跳居尚丁秦稍追梁折耗碱殊岗挖氏刃剧堆赫荷胸衡勤膜篇登驻案刊秧缓凸役剪川雪链渔啦脸户洛孢勃盟买杨宗焦赛旗滤硅炭股坐蒸凝竟陷枪黎救冒暗洞犯筒您宋弧爆谬涂味津臂障褐陆啊健尊豆拔莫抵桑坡缝警挑污冰柬嘴啥饭塑寄赵喊垫丹渡耳刨虎笔稀昆浪萨茶滴浅拥穴覆伦娘吨浸袖珠雌妈紫戏塔锤震岁貌洁剖牢锋疑霸闪埔猛诉刷狠忽灾闹乔唐漏闻沈熔氯荒茎男凡抢像浆旁玻亦忠唱蒙予纷捕锁尤乘乌智淡允叛畜俘摸锈扫毕璃宝芯爷鉴秘净蒋钙肩腾枯抛轨堂拌爸循诱祝励肯酒绳穷塘燥泡袋朗喂铝软渠颗惯贸粪综墙趋彼届墨碍启逆卸航衣孙龄岭骗休借', // 中文验证码字符串 + 'useImgBg' => false, // 使用背景图片 + 'fontSize' => 25, // 验证码字体大小(px) + 'useCurve' => true, // 是否画混淆曲线 + 'useNoise' => true, // 是否添加杂点 + 'imageH' => 0, // 验证码图片高度 + 'imageW' => 0, // 验证码图片宽度 + 'length' => 5, // 验证码位数 + 'fontttf' => '', // 验证码字体,不设置随机获取 + 'bg' => array(243, 251, 254), // 背景颜色 + 'reset' => true, // 验证成功后是否重置 + ); + + private $_image = NULL; // 验证码图片实例 + private $_color = NULL; // 验证码字体颜色 + + /** + * 架构方法 设置参数 + * @access public + * @param array $config 配置参数 + */ + public function __construct($config=array()){ + $this->config = array_merge($this->config, $config); + } + + /** + * 使用 $this->name 获取配置 + * @access public + * @param string $name 配置名称 + * @return multitype 配置值 + */ + public function __get($name) { + return $this->config[$name]; + } + + /** + * 设置验证码配置 + * @access public + * @param string $name 配置名称 + * @param string $value 配置值 + * @return void + */ + public function __set($name,$value){ + if(isset($this->config[$name])) { + $this->config[$name] = $value; + } + } + + /** + * 检查配置 + * @access public + * @param string $name 配置名称 + * @return bool + */ + public function __isset($name){ + return isset($this->config[$name]); + } + + /** + * 验证验证码是否正确 + * @access public + * @param string $code 用户验证码 + * @param string $id 验证码标识 + * @return bool 用户验证码是否正确 + */ + public function check($code, $id = '') { + $key = $this->authcode($this->seKey).$id; + // 验证码不能为空 + $secode = session($key); + if(empty($code) || empty($secode)) { + return false; + } + // session 过期 + if(NOW_TIME - $secode['verify_time'] > $this->expire) { + session($key, null); + return false; + } + + if($this->authcode(strtoupper($code)) == $secode['verify_code']) { + $this->reset && session($key, null); + return true; + } + + return false; + } + + /** + * 输出验证码并把验证码的值保存的session中 + * 验证码保存到session的格式为: array('verify_code' => '验证码值', 'verify_time' => '验证码创建时间'); + * @access public + * @param string $id 要生成验证码的标识 + * @return void + */ + public function entry($id = '') { + // 图片宽(px) + $this->imageW || $this->imageW = $this->length*$this->fontSize*1.5 + $this->length*$this->fontSize/2; + // 图片高(px) + $this->imageH || $this->imageH = $this->fontSize * 2.5; + // 建立一幅 $this->imageW x $this->imageH 的图像 + $this->_image = imagecreate($this->imageW, $this->imageH); + // 设置背景 + imagecolorallocate($this->_image, $this->bg[0], $this->bg[1], $this->bg[2]); + + // 验证码字体随机颜色 + $this->_color = imagecolorallocate($this->_image, mt_rand(1,150), mt_rand(1,150), mt_rand(1,150)); + // 验证码使用随机字体 + $ttfPath = dirname(__FILE__) . '/Verify/' . ($this->useZh ? 'zhttfs' : 'ttfs') . '/'; + + if(empty($this->fontttf)){ + $dir = dir($ttfPath); + $ttfs = array(); + while (false !== ($file = $dir->read())) { + if($file[0] != '.' && substr($file, -4) == '.ttf') { + $ttfs[] = $file; + } + } + $dir->close(); + $this->fontttf = $ttfs[array_rand($ttfs)]; + } + $this->fontttf = $ttfPath . $this->fontttf; + + if($this->useImgBg) { + $this->_background(); + } + + if ($this->useNoise) { + // 绘杂点 + $this->_writeNoise(); + } + if ($this->useCurve) { + // 绘干扰线 + $this->_writeCurve(); + } + + // 绘验证码 + $code = array(); // 验证码 + $codeNX = 0; // 验证码第N个字符的左边距 + if($this->useZh){ // 中文验证码 + for ($i = 0; $i<$this->length; $i++) { + $code[$i] = iconv_substr($this->zhSet,floor(mt_rand(0,mb_strlen($this->zhSet,'utf-8')-1)),1,'utf-8'); + imagettftext($this->_image, $this->fontSize, mt_rand(-40, 40), $this->fontSize*($i+1)*1.5, $this->fontSize + mt_rand(10, 20), $this->_color, $this->fontttf, $code[$i]); + } + }else{ + for ($i = 0; $i<$this->length; $i++) { + $code[$i] = $this->codeSet[mt_rand(0, strlen($this->codeSet)-1)]; + $codeNX += mt_rand($this->fontSize*1.2, $this->fontSize*1.6); + imagettftext($this->_image, $this->fontSize, mt_rand(-40, 40), $codeNX, $this->fontSize*1.6, $this->_color, $this->fontttf, $code[$i]); + } + } + + // 保存验证码 + $key = $this->authcode($this->seKey); + $code = $this->authcode(strtoupper(implode('', $code))); + $secode = array(); + $secode['verify_code'] = $code; // 把校验码保存到session + $secode['verify_time'] = NOW_TIME; // 验证码创建时间 + session($key.$id, $secode); + + header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate'); + header('Cache-Control: post-check=0, pre-check=0', false); + header('Pragma: no-cache'); + header("content-type: image/png"); + + // 输出图像 + imagepng($this->_image); + imagedestroy($this->_image); + } + + /** + * 画一条由两条连在一起构成的随机正弦函数曲线作干扰线(你可以改成更帅的曲线函数) + * + * 高中的数学公式咋都忘了涅,写出来 + * 正弦型函数解析式:y=Asin(ωx+φ)+b + * 各常数值对函数图像的影响: + * A:决定峰值(即纵向拉伸压缩的倍数) + * b:表示波形在Y轴的位置关系或纵向移动距离(上加下减) + * φ:决定波形与X轴位置关系或横向移动距离(左加右减) + * ω:决定周期(最小正周期T=2π/∣ω∣) + * + */ + private function _writeCurve() { + $px = $py = 0; + + // 曲线前部分 + $A = mt_rand(1, $this->imageH/2); // 振幅 + $b = mt_rand(-$this->imageH/4, $this->imageH/4); // Y轴方向偏移量 + $f = mt_rand(-$this->imageH/4, $this->imageH/4); // X轴方向偏移量 + $T = mt_rand($this->imageH, $this->imageW*2); // 周期 + $w = (2* M_PI)/$T; + + $px1 = 0; // 曲线横坐标起始位置 + $px2 = mt_rand($this->imageW/2, $this->imageW * 0.8); // 曲线横坐标结束位置 + + for ($px=$px1; $px<=$px2; $px = $px + 1) { + if ($w!=0) { + $py = $A * sin($w*$px + $f)+ $b + $this->imageH/2; // y = Asin(ωx+φ) + b + $i = (int) ($this->fontSize/5); + while ($i > 0) { + imagesetpixel($this->_image, $px + $i , $py + $i, $this->_color); // 这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出(不用这while循环)性能要好很多 + $i--; + } + } + } + + // 曲线后部分 + $A = mt_rand(1, $this->imageH/2); // 振幅 + $f = mt_rand(-$this->imageH/4, $this->imageH/4); // X轴方向偏移量 + $T = mt_rand($this->imageH, $this->imageW*2); // 周期 + $w = (2* M_PI)/$T; + $b = $py - $A * sin($w*$px + $f) - $this->imageH/2; + $px1 = $px2; + $px2 = $this->imageW; + + for ($px=$px1; $px<=$px2; $px=$px+ 1) { + if ($w!=0) { + $py = $A * sin($w*$px + $f)+ $b + $this->imageH/2; // y = Asin(ωx+φ) + b + $i = (int) ($this->fontSize/5); + while ($i > 0) { + imagesetpixel($this->_image, $px + $i, $py + $i, $this->_color); + $i--; + } + } + } + } + + /** + * 画杂点 + * 往图片上写不同颜色的字母或数字 + */ + private function _writeNoise() { + $codeSet = '2345678abcdefhijkmnpqrstuvwxyz'; + for($i = 0; $i < 10; $i++){ + //杂点颜色 + $noiseColor = imagecolorallocate($this->_image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225)); + for($j = 0; $j < 5; $j++) { + // 绘杂点 + imagestring($this->_image, 5, mt_rand(-10, $this->imageW), mt_rand(-10, $this->imageH), $codeSet[mt_rand(0, 29)], $noiseColor); + } + } + } + + /** + * 绘制背景图片 + * 注:如果验证码输出图片比较大,将占用比较多的系统资源 + */ + private function _background() { + $path = dirname(__FILE__).'/Verify/bgs/'; + $dir = dir($path); + + $bgs = array(); + while (false !== ($file = $dir->read())) { + if($file[0] != '.' && substr($file, -4) == '.jpg') { + $bgs[] = $path . $file; + } + } + $dir->close(); + + $gb = $bgs[array_rand($bgs)]; + + list($width, $height) = @getimagesize($gb); + // Resample + $bgImage = @imagecreatefromjpeg($gb); + @imagecopyresampled($this->_image, $bgImage, 0, 0, 0, 0, $this->imageW, $this->imageH, $width, $height); + @imagedestroy($bgImage); + } + + /* 加密验证码 */ + private function authcode($str){ + $key = substr(md5($this->seKey), 5, 8); + $str = substr(md5($str), 8, 10); + return md5($key . $str); + } + +} diff --git a/ThinkPHP/Library/Think/Verify/bgs/1.jpg b/ThinkPHP/Library/Think/Verify/bgs/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d417136bb4613984dd88ac25590d2794344c990f GIT binary patch literal 30428 zcmeHwcU)7=((p+mw9rASgx*U60YdK*igcu^ln9}O7K+#a0R#OQ9wlj zu~1ct(k!5YfTE}%-$}6G^E~&ym+yP;Umwfw%$c2?nVp@TbJ!)>VfpFu2*74;N-zZ= zPzYozWGetHk1{HnM3Z&^fRz;>3jhE;fP`=WFc5=)KLCUuK+tdi@PY{Z!u=uAKX{-Z z4+a1sAP8Pz5G)Pn0`b%XBmn+Hwh+8`0yy6h0FYw)c{lJ0_9CKf{DLXL;eNp(Xd`

>%aJv{?GGXn!NI};-lJ2xvcGb=YQCnq;2CoelQt^ByHRQ?Jf zC?+Np3yO_}g^i1ag@ua>Sh!Y1*#8p+%gq2gJ)jSqgF!?AC_4nk4q1K%4x4eg1)>L9 ziGa`wXfUlV7!8(m2z>$K+N4MQua3 z;}~)7O2X})i181mQdxzG)yGqFM7A3N`7{ppGF3j2jOG<^v=XJ1*+fj|e56^TubeJg{v)s`+QNhZB<|B^^ZkoGy z;=&MsnA*j3qC0{`xbJ(FsZqYZbb&tW$!{4*8$H&HGg>)sRbNz3kq(`Aor5CH3^@pV<((}xO z7P;M`YdrFL9KMFX;u0x7+Qeltc8HpUuPAvNO;b-sAbFoL#jE{H^g$Px;$}_iAUkc*=h!;4)|9 zwQc(>pM8w@6jyq7+OXJwVM1$`B8-a??@MNs(#6qgw-e>8`Qdu9B#WTgj&gf*eoYuRcdT>s=mO zPWri76YJ&9r{#k}(*pT>O73vHx=wfFw$st@>c{(35dwz<$GwfC&)|f58N%bjUq0uk zt;>J;nPG3|umuS+)Umm7m|?LOL)o&eaL>C;!Dh{%?{@p$nT(9dGqYCw(?|A+8j3jC z_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dJ%a}$MG6}%Gm-Ao2yI?I?`pPOBd211e33aS}1}CT8+#dBHDW73<=U(AS8V}tRwCG zSFIiir=)2^u8pOTwx^xFv0A-HW@1Z&o-PBM;QZWApOh0sPilNH-`KY;i)ip7_q(L5n**13*^CS-@WLw?1M2| zZewB4(OC_rau+k)8+`DBrxvEVIBe_G)1ygPeb_ms$}hx`z&kLd_uT3WWkws9>N>oN z%zaI=%26h|9$2GHj!HsHU=#cF;CDVn0jn|wXZy3(5Q7CD^V5%|75(&WkTw8(i8nqc z=x}Ie4a;EEVn~AY1rA-6dkqehl8!*xVr!9ECAI)p{&Z_p!&rHyt-h?b=AMPJr*CaE z>&zE=iV?5+7fw3_Iu$j}jwZTFFkn6l``K3x4esuC4kIn7gJBec5ri-OCA<^KNzFf8P^ literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/bgs/2.jpg b/ThinkPHP/Library/Think/Verify/bgs/2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..56640bde4ed9a02c4e46b951f2108e5e4814b14a GIT binary patch literal 29677 zcmeHwc|4Tg_xLlr8T%Td#va*bY%{XY*h2QLRG1k{_A%Brq$08>5k<<$UoO`x=?z!iA+}q4^X6nIIFC?(s!rB6Y!C|m9 zur&}g^&FRJ9vkQfL3VbK3Isu15C$d$Apise{~(wogyO&uD^JU;20>W5fkpW@hc#1O-?;aRR z4~vO}h?<(Z`UIjrQ5R3p(kJTaYia@&5Mn=U#M@iI@o;f*VYzs)SRO%c9Jin-KMxPTsJO7OsIaiOAP=YfxJ-BcY+=0I+`N3e z0(^V|B7A&&BJ74wWLiYp zyC6WIAW>)x7Z%42!r^x!41yzm5(OX_5{7^y;V2B63x(j(0z^RsQbve?GIjJ3mW@ax zqD8VxPnyZei#lEL)zW4rbx<%0InHCx$7zu|Vr4a36sfr`bn~kRSh@>3UHcesPbFXL zit2x7p_Es?_4KaB?t%9Q&s@JdIN|0Oy)FMxZPUFMAM`BU{bRQ8uBdCi|MH_C1cw7_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O_I05jO;6;V^ z6)aRud{HyZCF7UxxqMqsQ^oNoyM_rVCCZWvp5(va=zeE)__Z6*u>Ix(IuFkzzm_g4 zO}l8dy55fn!-pdfb@utL(xx@`)epyFR5osiPd-~F^4xqF)3v+VnfYv2`0=f^H#ePv zX;OCyH1+H$svpT6my1aG>|27UA6}JV@A9PD;le&zyh|wYflbuX>#UEjeoOz%*G+d`e7JaQs|_ie zmcKtO*-89lWyNH=_$|cO-fOCw_^j2b~0^5`CmL$d|Cd+TS1kP?Hw7rFxs8p7uyd#I_AWb>#&o3ZIz0OI||3R~?Ms z`*1L^*j-6d=wOif`~5h}1@bw@Jf{Sn@6^n$$-NnUi`5Bp@aP(RtV6st(#LGvsGV7N z$yq*X`69E^lP_-boe%vrYK?N{Q*W(RY552gRc`jq6mGARQD|0`xE|)2O zuxrTrRq{&(2s-ldqnbqe*}mwIN~_7i?apMJH-Wm)IjO%xwVOvgf??RiiTFTeub8MbRI&WJ0%NPM4t=c}swfYmjL?3Stp zw?w5Un&A>#;9Nandjz}Ns~>$`Qo51Yl$MuHukBRP&Nourmayfc-x>o?jKu-*Jll`h zNMUMrmYtrl{@}yZy|#e~%~wNsgI_${o7i#!zUvT;rX;v*75Q3?>kzLuimM5qp=N#LPM3tvg_>S`j~rGj}}_2 zvRhY)OdXFQpXeHB#8ig%w+kyV)*fBSe=%AqhOek;tvcd%Q6Dbh|l zT$tee>`mJ`g|p~SpJ>)$owQ4~=2Ag+r=-WL=|q%LZM@HkHafSPB08_ZQ$p7#ObU;; rK5jelOsSzL!0ahTK)A8SLU8Bj!H(;}Woj$P-F1|lF;8*hsfYg$;V&%M literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/bgs/3.jpg b/ThinkPHP/Library/Think/Verify/bgs/3.jpg new file mode 100644 index 0000000000000000000000000000000000000000..83e5bd9026f9d46c96738a4209f1abb91f7e1e6f GIT binary patch literal 32109 zcmeIbcUTn5(l|Uz&PWuH93`_$&KX1`NX`n&0!vt6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Fo%=6mGUOXGJep=m)@c}HAKuc76M?jw1}ULkMb=d`n$%xGC- z4of|-hgoH&F`iLVfJ#Y3|`r;{u^{Y>!o+KYl zBh+hurkG$yu2J&Jn=lg|evnxprKu#lq+L&uE%D0Htm3;$)feD=51K;bM$6OEzhV*dRD7HN15K2g|wRDv2p9Co-cGMlIkkUC{Rz8=f~9U(7n22 zfsVe#kea$^K;t%JLCl`|k?9mmk~O>0^(o8y{gd!HlguS2`I+a>UtG$0Gji>kLNDhP zZP5)wN|RcbpcI~KLzDgVCtF@VWsb^Sbwp8D*o2RZ#lhpf#Vk>}IiK<#MzcqpxV)Bs ziIdiI;wTu(=eO?{c^m!$CBB;6P zQAV7fcoHn{S5}qP5cT#-U19ooqDH0tq5G|VW*r+*6V4uyBC#ot+zdCi=Q3oJsjguu z4~1E_+UD(F%62jdkTIbl(_wvUS+0H@&hIf-k^;VYjtPzBKN_LAY&xv# z}{7$8WJ0=ZuU$q$?Es=`Ij4#PsgLJTvMg)kGwFS@ltvYMf$Yo+D)`ebqIL1$#|yU za~vt+kvc8QGf;{~%g>u7>gKx0Ger0ub=H0xl&ho3?mQhqacbq*(*%m_m`4|ZuutdX z1f*$9>=>Il+{v`4y;%db6Md`wtXD@wZcsd%L8F=cZIFq~}g0Zw90&;L}$d^^zw<>N8dJg<^lb)P@Z^$)RRSqBx~GxBGu2D1qR-W znvIJHY30C`;?6J3S&gKmxmU7lh&Deta`+IF<}2bNVY9BA2CA2mb#CV99poi^+Rc=0 z6x#a?;e1HFojsAUud(o$fp>?(rMn^gmf*uhc5A+SWbkobO<&@N?v*lEXDqemGHc?s WW2Q1p-X6|ip1UGwC*Qp@{Qm&B(nP5M literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/bgs/4.jpg b/ThinkPHP/Library/Think/Verify/bgs/4.jpg new file mode 100644 index 0000000000000000000000000000000000000000..97a3721bc777a569c6665e38dec04a82df9176da GIT binary patch literal 29081 zcmeHwcU%+Q((ooB34~q+1P#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hu)uVZx(5+u#4KByO=Df`>{M1Uu(5D9~-EH8EaoXXU z#3cHmmLGBI>?BsY9Vf6{~@*G+M;!awop!ZHU%1H1& z%)ctX(}Uw~S$W=zlK4k{#>? zoEDR^ML5$m(@fjfv7X~Oel~Qs4L6VzoTt!v`y|7_o4)szpU>3-n?~f`7LAX!cT0&Y z2jKWk7Bk;o=97jYJ$KO$SS#|>ax~M~jlN1lrk!^TyTBAR8%;-#Z@JooJ z>Tw1&+alyOn}MKck*xJj1U%N}_&i0LNzsm1!4V>UF*v0lze0+=nnzv^r~H__IG~&{ zGW_-GgW=b^^4@ea&h3=iN~b)x*u3Z4jiZTEXGror=sV=TCE$Ydhgp96G#3R`kqu(i zio)3?hWh+3dZW85J>bsQ=%gOvuV>y+a9Lw7*#wc2Pe_zOY zMwz2Q_Ggo?*vvK>9+k0>D=l`O`*yQXv4#ZBvWAlSii>2dyfZuZA9u8pZSJyu-R^bl R;s=GvM3(ZxPL-v5{|~;{ne6}o literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/bgs/8.jpg b/ThinkPHP/Library/Think/Verify/bgs/8.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e10cf28115e47d1f5413e76efeccc39cd655b6cc GIT binary patch literal 30188 zcmeHwXIK+W*YGBR0HIfDLg+8L10 zP_ZEbf(5~fAV{--@@;|z@8^CB@B2PKzUyMV_UxI{=FFM1>+FV|Ssq*-0XQs8EldFj z6av`}*$x29FIebIqDejgU~LV^0|3AXFhIBf7>Gf@e*i=fpr_#g;0+P_h5JKff5<>V z8596QKo~s2AZQxS1L7G6NC4dr-4gJ8A5ilh0RS0}pJzh?*_(*8^&?Zr;eO;0B+dbi z+)4^2kfXu@w2F$l77DF}R!5>RS}IsA3CA*NU!b(6!OysL<#!KHsbDzIlvq|gArLdFRzXzl?HN`Cjk~(pFDBa0A%?C zz(%V9ggC0^@-VOuU}0orWMX7tVq)QBMlf^ova_(T^YU|Z^Kx_ZbF$FNkJC!!uMon@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MS`(*d`gM67B=QXM`ht58X7baR-&22LEPtfQT_S@?`c%ova o6k)@Cq-!FF=NmuCIQ2n*!YN;`*>;Q3?U*ky_mA_`doDlze*}E?jsO4v literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/ttfs/1.ttf b/ThinkPHP/Library/Think/Verify/ttfs/1.ttf new file mode 100644 index 0000000000000000000000000000000000000000..d4ee155870e0011906a24cf200a8f6a11d2daa0a GIT binary patch literal 57520 zcmeHw37j2OmG`+-Z|S%7{`z&l?j*0%Nt&#k^pYlPzt>qHkY>w5KtNiubj)fJ!X`pq zLONh@z!60U0YwxL9b_5x8+05O42(L$hv=Xv!{;zMe&g`PCI04#FZrwWf+;h)8_uO;OB}GIPG@ESt%Gs;h+VdCpe4gkhKgHd%F5A|>^X5h0 zJCEqeuM-6hUbc5n=ItLCzL6;SD4zFj+_`Dn{*JGnjqAH{UAt-PRU21d5XJkU0irLy zdtm*xD}#ssj1~&Ase<6PczW8D%;?EtxjqtR<8Mxkx>q!IK_FVZ=zUSja zUpqo%zqn%VfR`m!|+@85#=Gu!*O zZFuVAw_S$t?*Z>8cJA1{=UCUn`2IKVBeEKI?%J^P=RLpe0=&ONoSoQ{%ED1L^;P;; z6Qq#!NhfSkx%G$>wyD?pg%b`S4zMCykWRPHb;2PE*>@0Ql{ZdNhZWh@Jxad1Whc%o!EO2&Q z*_AnE?}lBwH}BY8KVb*0kwq@?m zw9lU1K7)^)Bck^9@7}OJgQWKiY{+cguxHPPU7NRW%3RKOH}2S#>EE>n=dJ4jK&F3B z=8PS?H|!k9EbHIBXP|#u=Jd^*1~RKI8`!a9>#WR*?U`*Gw(Zz;Rc6P=%<3K6ugWax z-`l^vf78H>%;xR8cW&O*zXzG<-ztgj+0cL4z=mD3GSop=QWs_D6xvH0Xcz6K&9sBI z<4!xx0@=@@sR(E29ds3rXClsK+Cu{f_fkJX8}J4{AKPzBrV{U51=8Ap)Gx!Aw&BhD zvA5$}vvHi^hC9cQCd05BX{|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66@97V)vGBG+b(AszRG?H@mV)*ISOdJqtn626b=7h g`z7bT_wnD!o!>#<248R3V5WrcM-kdj!+56tA1s{=qyPW_ literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/ttfs/2.ttf b/ThinkPHP/Library/Think/Verify/ttfs/2.ttf new file mode 100644 index 0000000000000000000000000000000000000000..3a452b68f3baa612539ad43cd427725e96f44100 GIT binary patch literal 28328 zcmdUY2YegHmG{hIv5VdtNss^tq7Wbnk{}6EB*CQ!l9EU@s&`Sv>Yb7$OD>Wu%d#v> z?!79mk>VyhF0rH7j_nkuJI%SX&xsw|Nt}9#&$fW?KZ`<8l5^kPcfb4nz6BT9T`YIr zym{}<|GjxLAe0bdB=tl=PEVZ?Yus;_+6dWj2d>VZ)-yP>@#$CkasD@)w=CZo&$53xPRIp6Aw+n6^~&KDKfmiID+$?H!=Aqy7sM09j`I~buUfrfWapVFe>yGC)md0 z`0eZ=QIZO3&K(OxN1JoUA{n8(3F9!^*weGel!)XjxnmB;FXxUGIQ~QKn8)$YbH_?z zq+IS;AOel$jzuz#cBADeug0?({n_Iz{n_Iz{n_Iz{n_Iz{n_Iz{n_Iz{n=xg{)Zdd z+FHHyhc~YD&fIk2#%(J%uJB$ok~@-CZyMP!yk>pf@=Y7O7hZT_-K>pUal^{3>;ie1 zG>|sDT8Wp;C&OeTS&5^WWD~g%$J=nWk*vU#i$MF>YZ6(FD71@sG4U?_s zz4N>m8|#`Iz4cA8#(1o;zP^DpqOfMXd!aT>B!;87{9cdqhK6{d{9Nh(e=!h(BvDec zqu2YGBGBs}UhVR)UYe@SXz8omN<|mxCC`#Ra**6XcA?_W(Ki;1`{EaL#DwQrbvmt9 zqfx6>DusgMD1{;%d4^^V^sY{Q(chCwzK=wo6a~CL&hxnKaY4X4=p!6~4%4Ry(0Vo5 zD%DesM$)2SmB3S8!7EWkp5qiMQKeR?1yNK9f~XQjK`nqVDrAZ2$`V5l)~Q}meXe?i zeH!pd>#&i!x*TBw(G(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ToqrsIO%=>sIdMR4281Xw`8Y$GfTAryt#cF^44Y6on&eW1GUf(Q8;*zUWv jM|<^NA9cOn4XUM5V-N;q&ulFQdE-~ACP=hZO(^{aR9Qcq literal 0 HcmV?d00001 diff --git a/ThinkPHP/Library/Think/Verify/ttfs/6.ttf b/ThinkPHP/Library/Think/Verify/ttfs/6.ttf new file mode 100644 index 0000000000000000000000000000000000000000..7f183e20820646f07ae833b64230629ce815fd36 GIT binary patch literal 28036 zcmcJ&2Y6h?)i-`;Zrk2_(-v)!R&`gqD_gQ`Yvm%jNwN(#nBs;_aKkoWOb^Y0BtWo9 zfe;dsfJs6i0TW0ggc1@`fRL9ELYxAaRPs^+*t`1w&fQ&EHt;_0_kGWQr8|4?%-oqX zr_Gsj=H3;UAP7d`Qb82DmMrbeUH9=GEJrJLjDs2+}$n(G8oUFP{=ih_6-@{Sdhz##OXD7~4E;Mi4ymQx8XD07PdwT?dzi`(2 z?ORg$)O~`m`iLON?`_(;cJ=C=7jy}N?h4e|wt4lgZS1?svpDzR{^*v~o7aE#{7v5# zgbnWqg80X6TX*bSxom8{Ae{9g>f9j^>^PphSKc7d_fQHhC6k_EWv<6 zj09I`i3i#Bf-ErpJ$?=HuB&~s$AlacsS$~i5BSX9v~vgAipKpl7$hC*14wTQGpRCL zR6kO}C~Fcj@)Ls0{!3^Bq{I9x!aCtbA;ZE#feuj-ay%&ng~LLT1%-a0B1~iBLX7(F3w`W$A;v$6{2n1E28HQ-FWP?#`_ro1Z4M zOrB%>%q)c2U8swL@FEt3b#wraF5pgJKL(C*5U%OqDdf3OA4eUJS~)u?>_)u}!25l4 z&bx%Hb`W0Z03L|O+V~0Q#~m8}3HMVD4fllq`oX)=4sZ`#tb5-o5 zKH&l3yTaqbZ-keGmxWh^w}lBd$dgS}|#knVA3Zu^{wXgF| zT`%l9fAPCLXH1S$ME0n|F;|%{rU&;;8cG8Kj6YzYg74f;@cAs{NHinA09rA z7YA$Dm`sZ}qr8PUMkaHoa^`%k>}V13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{(W&E38gaP>cJqLy!8G2&{TR?%u zT|+}aE9A1lBMRPMN7oHJD|nk7*(>WN{tjQ~ZJ@w$zD~p+$d?O8C#^|#24enn zEzDDU3aS)y;<*fZ167CiHY)acgebOsh_kc$^0Cg&7p|M)>kKg0H+_zdoBrhr|6u&4={TEQo4Bv(@qFA6NyC{egk7Dx3=EBO~vB zUzT1u_I+8imQB7cD~AUePZvYYBjw%I18ih>c?7S^V)sr$Mtg(1gdsdv`S_$fB31&I zD@=gK_sa|WQmd~^o%yHwH+%f7xlc3QydSZT)=xl_4``>9$LnI8rL?pD-L+`C*3L-% zduY>~r>pPG`%(4c`U#qW4$=JH!qw3E6zfGC0*}lg!bb0exi*|mx8Vq1{c$l93}(by zO7~g86aS5ec8`s79@Q&3X!x=gFKl>1YFdRnYK5a7AH;v)>#b{*{ITJV<5o=EdOOoR zfp5XOfjipFG#B8jAGA`c`vsw2Ud3wSyrCg@xRTZ1k*i4ax{Xv{9D-NumGX0)$1j}P zHel^pUpUodqdrcBqy+Yc3o-NEjhK0?;9_TJL36DP@jLcXt;`OorgMbWCh*SEd)Qv= zF;C&mkEF*wB4Ay6O#WF~{#ld{&Om+PDb%mW_7NjPzy~`t-3Xql6i6u6V*3#%V*9-9 zXmB4}e`>+~_qTzi*@y2B;H9H&Ol}Y`0me7jTXlb=1y2i5lp_i4Mq0P#wTH%{HI}Al zYrbzkou1;Z8$&dF$ULS}D$;O`R(HR=N6%@~v=)JKzv!aE7-s@`fwr zQ$nl$6a3b#!LQvBT5By^@qBm9KVF@8{q^iza!ywN#@3pesy~6vG3gvXi4

  • PHP-Script: ' . $_SERVER['PATH_TRANSLATED'] . '
  • Template: ' . $this->filename . '

  • '; + echo '
  • Template
  • '; + echo '
  • Compiled Template
  • '; + echo '
  • Data
  • '; + echo '

    '; + + // Print Template + echo '
    Template: [
    Hide Ouptut]
    '; + echo '
    ';
    +			echo $page;
    +			echo '
    '; + + // Print Compiled Template + if (@include_once ("class.smarttemplateparser.php")) + { + $parser = new SmartTemplateParser($this->filename); + $compiled = $parser->compile(); + echo '

    Compiled Template: [
    Hide Ouptut]
    '; + echo '
    ';
    +				highlight_string($compiled);
    +				echo '
    '; + } + else + { + exit( "SmartTemplate Error: Cannot find class.smarttemplateparser.php; check SmartTemplate installation"); + } + + // Print Data + echo '

    Data: [
    Hide Ouptut]
    '; + echo '
    ';
    +			echo $this->vardump($vars);
    +			echo '
    '; + } + + + /** + * Insert Hide/Show Layer Switch + * + * @param string $suffix Additional Text + * @desc Insert Hide/Show Layer Switch + */ + function toggleview ( $suffix = '') + { + global $spancnt; + + $spancnt++; + if ($suffix) + { + $suffix .= ':'; + } + $ret = '[' . $suffix . 'Hide Block]'; + return $ret; + } + + + /** + * Create Title Text + * + * @param string $value Content + * @desc Create Title Text + */ + function tip ( $value ) + { + if (empty($value)) + { + return "[NULL]"; + } + else + { + $ret = htmlentities(substr($value,0,200)); + return $ret; + } + } + + + /** + * Recursive Variable Display Output + * + * @param mixed $var Content + * @param int $depth Incremented Indent Counter for Recursive Calls + * @return string Variable Content + * @access private + * @desc Recursive Variable Display Output + */ + function vardump($var, $depth = 0) + { + if (is_array($var)) + { + $result = "Array (" . count($var) . ")
    "; + foreach(array_keys($var) as $key) + { + $result .= $this->tab[$depth] . "$key: " . $this->vardump($var[$key], $depth+1); + } + return $result; + } + else + { + $ret = htmlentities($var) . "
    "; + return $ret; + } + } + + + /** + * Splits Template-Style Variable Names into an Array-Name/Key-Name Components + * + * @param string $tag Variale Name used in Template + * @return array Array Name, Key Name + * @access private + * @desc Splits Template-Style Variable Names into an Array-Name/Key-Name Components + */ + function var_name($tag) + { + $parent_level = 0; + while (substr($tag, 0, 7) == 'parent.') + { + $tag = substr($tag, 7); + $parent_level++; + } + if (substr($tag, 0, 4) == 'top.') + { + $ret = array('_stack[0]', substr($tag,4)); + return $ret; + } + elseif ($parent_level) + { + $ret = array('_stack[$_stack_cnt-'.$parent_level.']', $tag); + return $ret; + } + else + { + $ret = array('_obj', $tag); + return $ret; + } + } + + + /** + * Highlight HTML Source + * + * @param string $code HTML Source + * @return string Hightlighte HTML Source + * @access private + * @desc Highlight HTML Source + */ + function highlight_html ( $code ) + { + $code = htmlentities($code); + $code = preg_replace('/([a-zA-Z_]+)=/', '$1=', $code); + $code = preg_replace('/(<[\/a-zA-Z0-9&;]+)/', '$1', $code); + $code = str_replace('<!--', '<!--', $code); + $code = str_replace('-->', '-->', $code); + $code = preg_replace('/[\r\n]+/', "\n", $code); + return $code; + } + } +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplateparser.php b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplateparser.php new file mode 100644 index 0000000..e16d2cf --- /dev/null +++ b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplateparser.php @@ -0,0 +1,365 @@ +template = fread($hd, filesize($template_filename)); + } + else + { + $this->template = "SmartTemplate Parser Error: File size is zero byte: '$template_filename'"; + } + fclose($hd); + // Extract the name of the template directory + $this->template_dir = dirname($template_filename); + } + else + { + $this->template = "SmartTemplate Parser Error: File not found: '$template_filename'"; + } + } + + /** + * Main Template Parser + * + * @param string $compiled_template_filename Compiled Template Filename + * @desc Creates Compiled PHP Template + */ + function compile( $compiled_template_filename = '' ) + { + if (empty($this->template)) + { + return; + } + /* Quick hack to allow subtemplates */ + if(eregi("/', $this->template, $tvar); + foreach($tvar[1] as $subfile) + { + if(file_exists($this->template_dir . "/$subfile")) + { + $subst = implode('',file($this->template_dir . "/$subfile")); + } + else + { + $subst = 'SmartTemplate Parser Error: Subtemplate not found: \''.$subfile.'\''; + } + $this->template = str_replace("", $subst, $this->template); + } + } + } + // END, ELSE Blocks + $page = preg_replace("//", "", $this->template); + $page = preg_replace("//", "", $page); + $page = str_replace("", "", $page); + + // 'BEGIN - END' Blocks + if (preg_match_all('//', $page, $var)) + { + foreach ($var[1] as $tag) + { + list($parent, $block) = $this->var_name($tag); + $code = "\$$parent"."['$block']));\n" + . "\$_tmp_arr_keys=array_keys(\$$parent"."['$block']);\n" + . "if (\$_tmp_arr_keys[0]!='0')\n" + . "\$$parent"."['$block']=array(0=>\$$parent"."['$block']);\n" + . "\$_stack[\$_stack_cnt++]=\$_obj;\n" + . "foreach (\$$parent"."['$block'] as \$rowcnt=>\$$block) {\n" + . "\$$block"."['ROWCNT']=\$rowcnt;\n" + . "\$$block"."['ALTROW']=\$rowcnt%2;\n" + . "\$$block"."['ROWBIT']=\$rowcnt%2;\n" + . "\$_obj=&\$$block;\n?>"; + $page = str_replace("", $code, $page); + } + } + + // 'IF nnn=mmm' Blocks + if (preg_match_all('//', $page, $var)) + { + foreach ($var[2] as $cnt => $tag) + { + list($parent, $block) = $this->var_name($tag); + $cmp = $var[3][$cnt]; + $val = $var[4][$cnt]; + $else = ($var[1][$cnt] == 'ELSE') ? '} else' : ''; + if ($cmp == '=') + { + $cmp = '=='; + } + + if (preg_match('/"([^"]*)"/',$val,$matches)) + { + $code = ""; + } + elseif (preg_match('/([^"]*)/',$val,$matches)) + { + list($parent_right, $block_right) = $this->var_name($matches[1]); + $code = ""; + } + + $page = str_replace($var[0][$cnt], $code, $page); + } + } + + // 'IF nnn' Blocks + if (preg_match_all('//', $page, $var)) + { + foreach ($var[2] as $cnt => $tag) + { + $else = ($var[1][$cnt] == 'ELSE') ? '} else' : ''; + list($parent, $block) = $this->var_name($tag); + $code = ""; + $page = str_replace($var[0][$cnt], $code, $page); + } + } + + // Replace Scalars + if (preg_match_all('/{([a-zA-Z0-9_. >]+)}/', $page, $var)) + { + foreach ($var[1] as $fulltag) + { + // Determin Command (echo / $obj[n]=) + list($cmd, $tag) = $this->cmd_name($fulltag); + + list($block, $skalar) = $this->var_name($tag); + $code = "\n"; + $page = str_replace('{'.$fulltag.'}', $code, $page); + } + } + + + // ROSI Special: Replace Translations + if (preg_match_all('/<"([a-zA-Z0-9_.]+)">/', $page, $var)) + { + foreach ($var[1] as $tag) + { + list($block, $skalar) = $this->var_name($tag); + $code = "\n"; + $page = str_replace('<"'.$tag.'">', $code, $page); + } + } + + + // Include Extensions + $header = ''; + if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $page, $var)) + { + foreach ($var[2] as $cnt => $tag) + { + // Determin Command (echo / $obj[n]=) + list($cmd, $tag) = $this->cmd_name($tag); + + $extension = $var[1][$cnt]; + if (!isset($this->extension_tagged[$extension])) + { + $header .= "include_once \"smarttemplate_extensions/smarttemplate_extension_$extension.php\";\n"; + $this->extension_tagged[$extension] = true; + } + if (!strlen($tag)) + { + $code = "\n"; + } + elseif (substr($tag, 0, 1) == '"') + { + $code = "\n"; + } + elseif (strpos($tag, ',')) + { + list($tag, $addparam) = explode(',', $tag, 2); + list($block, $skalar) = $this->var_name($tag); + if (preg_match('/^([a-zA-Z_]+)/', $addparam, $match)) + { + $nexttag = $match[1]; + list($nextblock, $nextskalar) = $this->var_name($nexttag); + $addparam = substr($addparam, strlen($nexttag)); + $code = "\n"; + } + else + { + $code = "\n"; + } + } + else + { + list($block, $skalar) = $this->var_name($tag); + $code = "\n"; + } + $page = str_replace($var[0][$cnt], $code, $page); + } + } + + // Add Include Header + if (isset($header) && !empty($header)) + { + $page = "$page"; + } + + // Store Code to Temp Dir + if (strlen($compiled_template_filename)) + { + if ($hd = fopen($compiled_template_filename, "w")) + { + fwrite($hd, $page); + fclose($hd); + return true; + } + else + { + $this->error = "Could not write compiled file."; + return false; + } + } + else + { + return $page; + } + } + + + /** + * Splits Template-Style Variable Names into an Array-Name/Key-Name Components + * {example} : array( "_obj", "example" ) -> $_obj['example'] + * {example.value} : array( "_obj['example']", "value" ) -> $_obj['example']['value'] + * {example.0.value} : array( "_obj['example'][0]", "value" ) -> $_obj['example'][0]['value'] + * {top.example} : array( "_stack[0]", "example" ) -> $_stack[0]['example'] + * {parent.example} : array( "_stack[$_stack_cnt-1]", "example" ) -> $_stack[$_stack_cnt-1]['example'] + * {parent.parent.example} : array( "_stack[$_stack_cnt-2]", "example" ) -> $_stack[$_stack_cnt-2]['example'] + * + * @param string $tag Variale Name used in Template + * @return array Array Name, Key Name + * @access private + * @desc Splits Template-Style Variable Names into an Array-Name/Key-Name Components + */ + function var_name($tag) + { + $parent_level = 0; + while (substr($tag, 0, 7) == 'parent.') + { + $tag = substr($tag, 7); + $parent_level++; + } + if (substr($tag, 0, 4) == 'top.') + { + $obj = '_stack[0]'; + $tag = substr($tag,4); + } + elseif ($parent_level) + { + $obj = '_stack[$_stack_cnt-'.$parent_level.']'; + } + else + { + $obj = '_obj'; + } + while (is_int(strpos($tag, '.'))) + { + list($parent, $tag) = explode('.', $tag, 2); + if (is_numeric($parent)) + { + $obj .= "[" . $parent . "]"; + } + else + { + $obj .= "['" . $parent . "']"; + } + } + $ret = array($obj, $tag); + return $ret; + } + + + /** + * Determine Template Command from Variable Name + * {variable} : array( "echo", "variable" ) -> echo $_obj['variable'] + * {variable > new_name} : array( "_obj['new_name']=", "variable" ) -> $_obj['new_name']= $_obj['variable'] + * + * @param string $tag Variale Name used in Template + * @return array Array Command, Variable + * @access private + * @desc Determine Template Command from Variable Name + */ + function cmd_name($tag) + { + if (preg_match('/^(.+) > ([a-zA-Z0-9_.]+)$/', $tag, $tagvar)) + { + $tag = $tagvar[1]; + list($newblock, $newskalar) = $this->var_name($tagvar[2]); + $cmd = "\$$newblock"."['$newskalar']="; + } + else + { + $cmd = "echo"; + } + $ret = array($cmd, $tag); + return $ret; + } + + /** + * @return int Number of subtemplate included + * @access private + * @desc Count number of subtemplates included in current template + */ + function count_subtemplates() + { + preg_match_all('//', $this->template, $tvar); + $count_subtemplates = count($tvar[1]); + $ret = intval($count_subtemplates); + return $ret; + } + } +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/Smarty.class.php b/ThinkPHP/Library/Vendor/Smarty/Smarty.class.php new file mode 100644 index 0000000..f2d3408 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/Smarty.class.php @@ -0,0 +1,1473 @@ + +* @author Uwe Tews +* @author Rodney Rehm +* @package Smarty +* @version 3.1.6 +*/ + +/** +* define shorthand directory separator constant +*/ +if (!defined('DS')) { + define('DS', DIRECTORY_SEPARATOR); +} + +/** +* set SMARTY_DIR to absolute path to Smarty library files. +* Sets SMARTY_DIR only if user application has not already defined it. +*/ +if (!defined('SMARTY_DIR')) { + define('SMARTY_DIR', dirname(__FILE__) . DS); +} + +/** +* set SMARTY_SYSPLUGINS_DIR to absolute path to Smarty internal plugins. +* Sets SMARTY_SYSPLUGINS_DIR only if user application has not already defined it. +*/ +if (!defined('SMARTY_SYSPLUGINS_DIR')) { + define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS); +} +if (!defined('SMARTY_PLUGINS_DIR')) { + define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS); +} +if (!defined('SMARTY_MBSTRING')) { + define('SMARTY_MBSTRING', function_exists('mb_strlen')); +} +if (!defined('SMARTY_RESOURCE_CHAR_SET')) { + // UTF-8 can only be done properly when mbstring is available! + define('SMARTY_RESOURCE_CHAR_SET', SMARTY_MBSTRING ? 'UTF-8' : 'ISO-8859-1'); +} +if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) { + define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y'); +} + +/** +* register the class autoloader +*/ +if (!defined('SMARTY_SPL_AUTOLOAD')) { + define('SMARTY_SPL_AUTOLOAD', 0); +} + +if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) { + $registeredAutoLoadFunctions = spl_autoload_functions(); + if (!isset($registeredAutoLoadFunctions['spl_autoload'])) { + spl_autoload_register(); + } +} else { + spl_autoload_register('smartyAutoload'); +} + +/** +* Load always needed external class files +*/ +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_data.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_templatebase.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_template.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_resource.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_resource_file.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_cacheresource.php'; +include_once SMARTY_SYSPLUGINS_DIR.'smarty_internal_cacheresource_file.php'; + +/** +* This is the main Smarty class +* @package Smarty +*/ +class Smarty extends Smarty_Internal_TemplateBase { + + /**#@+ + * constant definitions + */ + + /** + * smarty version + */ + const SMARTY_VERSION = 'Smarty-3.1.6'; + + /** + * define variable scopes + */ + const SCOPE_LOCAL = 0; + const SCOPE_PARENT = 1; + const SCOPE_ROOT = 2; + const SCOPE_GLOBAL = 3; + /** + * define caching modes + */ + const CACHING_OFF = 0; + const CACHING_LIFETIME_CURRENT = 1; + const CACHING_LIFETIME_SAVED = 2; + /** + * define compile check modes + */ + const COMPILECHECK_OFF = 0; + const COMPILECHECK_ON = 1; + const COMPILECHECK_CACHEMISS = 2; + /** + * modes for handling of "" tags in templates. + */ + const PHP_PASSTHRU = 0; //-> print tags as plain text + const PHP_QUOTE = 1; //-> escape tags as entities + const PHP_REMOVE = 2; //-> escape tags as entities + const PHP_ALLOW = 3; //-> escape tags as entities + /** + * filter types + */ + const FILTER_POST = 'post'; + const FILTER_PRE = 'pre'; + const FILTER_OUTPUT = 'output'; + const FILTER_VARIABLE = 'variable'; + /** + * plugin types + */ + const PLUGIN_FUNCTION = 'function'; + const PLUGIN_BLOCK = 'block'; + const PLUGIN_COMPILER = 'compiler'; + const PLUGIN_MODIFIER = 'modifier'; + const PLUGIN_MODIFIERCOMPILER = 'modifiercompiler'; + + /**#@-*/ + + /** + * assigned global tpl vars + */ + public static $global_tpl_vars = array(); + + /** + * error handler returned by set_error_hanlder() in Smarty::muteExpectedErrors() + */ + public static $_previous_error_handler = null; + /** + * contains directories outside of SMARTY_DIR that are to be muted by muteExpectedErrors() + */ + public static $_muted_directories = array(); + + /**#@+ + * variables + */ + + /** + * auto literal on delimiters with whitspace + * @var boolean + */ + public $auto_literal = true; + /** + * display error on not assigned variables + * @var boolean + */ + public $error_unassigned = false; + /** + * look up relative filepaths in include_path + * @var boolean + */ + public $use_include_path = false; + /** + * template directory + * @var array + */ + private $template_dir = array(); + /** + * joined template directory string used in cache keys + * @var string + */ + public $joined_template_dir = null; + /** + * joined config directory string used in cache keys + * @var string + */ + public $joined_config_dir = null; + /** + * default template handler + * @var callable + */ + public $default_template_handler_func = null; + /** + * default config handler + * @var callable + */ + public $default_config_handler_func = null; + /** + * default plugin handler + * @var callable + */ + public $default_plugin_handler_func = null; + /** + * compile directory + * @var string + */ + private $compile_dir = null; + /** + * plugins directory + * @var array + */ + private $plugins_dir = array(); + /** + * cache directory + * @var string + */ + private $cache_dir = null; + /** + * config directory + * @var array + */ + private $config_dir = array(); + /** + * force template compiling? + * @var boolean + */ + public $force_compile = false; + /** + * check template for modifications? + * @var boolean + */ + public $compile_check = true; + /** + * use sub dirs for compiled/cached files? + * @var boolean + */ + public $use_sub_dirs = false; + /** + * allow ambiguous resources (that are made unique by the resource handler) + * @var boolean + */ + public $allow_ambiguous_resources = false; + /** + * caching enabled + * @var boolean + */ + public $caching = false; + /** + * merge compiled includes + * @var boolean + */ + public $merge_compiled_includes = false; + /** + * cache lifetime in seconds + * @var integer + */ + public $cache_lifetime = 3600; + /** + * force cache file creation + * @var boolean + */ + public $force_cache = false; + /** + * Set this if you want different sets of cache files for the same + * templates. + * + * @var string + */ + public $cache_id = null; + /** + * Set this if you want different sets of compiled files for the same + * templates. + * + * @var string + */ + public $compile_id = null; + /** + * template left-delimiter + * @var string + */ + public $left_delimiter = "{"; + /** + * template right-delimiter + * @var string + */ + public $right_delimiter = "}"; + /**#@+ + * security + */ + /** + * class name + * + * This should be instance of Smarty_Security. + * + * @var string + * @see Smarty_Security + */ + public $security_class = 'Smarty_Security'; + /** + * implementation of security class + * + * @var Smarty_Security + */ + public $security_policy = null; + /** + * controls handling of PHP-blocks + * + * @var integer + */ + public $php_handling = self::PHP_PASSTHRU; + /** + * controls if the php template file resource is allowed + * + * @var bool + */ + public $allow_php_templates = false; + /** + * Should compiled-templates be prevented from being called directly? + * + * {@internal + * Currently used by Smarty_Internal_Template only. + * }} + * + * @var boolean + */ + public $direct_access_security = true; + /**#@-*/ + /** + * debug mode + * + * Setting this to true enables the debug-console. + * + * @var boolean + */ + public $debugging = false; + /** + * This determines if debugging is enable-able from the browser. + *
      + *
    • NONE => no debugging control allowed
    • + *
    • URL => enable debugging when SMARTY_DEBUG is found in the URL.
    • + *
    + * @var string + */ + public $debugging_ctrl = 'NONE'; + /** + * Name of debugging URL-param. + * + * Only used when $debugging_ctrl is set to 'URL'. + * The name of the URL-parameter that activates debugging. + * + * @var type + */ + public $smarty_debug_id = 'SMARTY_DEBUG'; + /** + * Path of debug template. + * @var string + */ + public $debug_tpl = null; + /** + * When set, smarty uses this value as error_reporting-level. + * @var int + */ + public $error_reporting = null; + /** + * Internal flag for getTags() + * @var boolean + */ + public $get_used_tags = false; + + /**#@+ + * config var settings + */ + + /** + * Controls whether variables with the same name overwrite each other. + * @var boolean + */ + public $config_overwrite = true; + /** + * Controls whether config values of on/true/yes and off/false/no get converted to boolean. + * @var boolean + */ + public $config_booleanize = true; + /** + * Controls whether hidden config sections/vars are read from the file. + * @var boolean + */ + public $config_read_hidden = false; + + /**#@-*/ + + /**#@+ + * resource locking + */ + + /** + * locking concurrent compiles + * @var boolean + */ + public $compile_locking = true; + /** + * Controls whether cache resources should emply locking mechanism + * @var boolean + */ + public $cache_locking = false; + /** + * seconds to wait for acquiring a lock before ignoring the write lock + * @var float + */ + public $locking_timeout = 10; + + /**#@-*/ + + /** + * global template functions + * @var array + */ + public $template_functions = array(); + /** + * resource type used if none given + * + * Must be an valid key of $registered_resources. + * @var string + */ + public $default_resource_type = 'file'; + /** + * caching type + * + * Must be an element of $cache_resource_types. + * + * @var string + */ + public $caching_type = 'file'; + /** + * internal config properties + * @var array + */ + public $properties = array(); + /** + * config type + * @var string + */ + public $default_config_type = 'file'; + /** + * cached template objects + * @var array + */ + public $template_objects = array(); + /** + * check If-Modified-Since headers + * @var boolean + */ + public $cache_modified_check = false; + /** + * registered plugins + * @var array + */ + public $registered_plugins = array(); + /** + * plugin search order + * @var array + */ + public $plugin_search_order = array('function', 'block', 'compiler', 'class'); + /** + * registered objects + * @var array + */ + public $registered_objects = array(); + /** + * registered classes + * @var array + */ + public $registered_classes = array(); + /** + * registered filters + * @var array + */ + public $registered_filters = array(); + /** + * registered resources + * @var array + */ + public $registered_resources = array(); + /** + * resource handler cache + * @var array + */ + public $_resource_handlers = array(); + /** + * registered cache resources + * @var array + */ + public $registered_cache_resources = array(); + /** + * cache resource handler cache + * @var array + */ + public $_cacheresource_handlers = array(); + /** + * autoload filter + * @var array + */ + public $autoload_filters = array(); + /** + * default modifier + * @var array + */ + public $default_modifiers = array(); + /** + * autoescape variable output + * @var boolean + */ + public $escape_html = false; + /** + * global internal smarty vars + * @var array + */ + public static $_smarty_vars = array(); + /** + * start time for execution time calculation + * @var int + */ + public $start_time = 0; + /** + * default file permissions + * @var int + */ + public $_file_perms = 0644; + /** + * default dir permissions + * @var int + */ + public $_dir_perms = 0771; + /** + * block tag hierarchy + * @var array + */ + public $_tag_stack = array(); + /** + * self pointer to Smarty object + * @var Smarty + */ + public $smarty; + /** + * required by the compiler for BC + * @var string + */ + public $_current_file = null; + /** + * internal flag to enable parser debugging + * @var bool + */ + public $_parserdebug = false; + /** + * Saved parameter of merged templates during compilation + * + * @var array + */ + public $merged_templates_func = array(); + /**#@-*/ + + /** + * Initialize new Smarty object + * + */ + public function __construct() + { + // selfpointer needed by some other class methods + $this->smarty = $this; + if (is_callable('mb_internal_encoding')) { + mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET); + } + $this->start_time = microtime(true); + // set default dirs + $this->setTemplateDir('.' . DS . 'templates' . DS) + ->setCompileDir('.' . DS . 'templates_c' . DS) + ->setPluginsDir(SMARTY_PLUGINS_DIR) + ->setCacheDir('.' . DS . 'cache' . DS) + ->setConfigDir('.' . DS . 'configs' . DS); + + $this->debug_tpl = 'file:' . dirname(__FILE__) . '/debug.tpl'; + if (isset($_SERVER['SCRIPT_NAME'])) { + $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']); + } + } + + + /** + * Class destructor + */ + public function __destruct() + { + // intentionally left blank + } + + /** + * <> set selfpointer on cloned object + */ + public function __clone() + { + $this->smarty = $this; + } + + + /** + * <> Generic getter. + * + * Calls the appropriate getter function. + * Issues an E_USER_NOTICE if no valid getter is found. + * + * @param string $name property name + * @return mixed + */ + public function __get($name) + { + $allowed = array( + 'template_dir' => 'getTemplateDir', + 'config_dir' => 'getConfigDir', + 'plugins_dir' => 'getPluginsDir', + 'compile_dir' => 'getCompileDir', + 'cache_dir' => 'getCacheDir', + ); + + if (isset($allowed[$name])) { + return $this->{$allowed[$name]}(); + } else { + trigger_error('Undefined property: '. get_class($this) .'::$'. $name, E_USER_NOTICE); + } + } + + /** + * <> Generic setter. + * + * Calls the appropriate setter function. + * Issues an E_USER_NOTICE if no valid setter is found. + * + * @param string $name property name + * @param mixed $value parameter passed to setter + */ + public function __set($name, $value) + { + $allowed = array( + 'template_dir' => 'setTemplateDir', + 'config_dir' => 'setConfigDir', + 'plugins_dir' => 'setPluginsDir', + 'compile_dir' => 'setCompileDir', + 'cache_dir' => 'setCacheDir', + ); + + if (isset($allowed[$name])) { + $this->{$allowed[$name]}($value); + } else { + trigger_error('Undefined property: ' . get_class($this) . '::$' . $name, E_USER_NOTICE); + } + } + + /** + * Check if a template resource exists + * + * @param string $resource_name template name + * @return boolean status + */ + public function templateExists($resource_name) + { + // create template object + $save = $this->template_objects; + $tpl = new $this->template_class($resource_name, $this); + // check if it does exists + $result = $tpl->source->exists; + $this->template_objects = $save; + return $result; + } + + /** + * Returns a single or all global variables + * + * @param object $smarty + * @param string $varname variable name or null + * @return string variable value or or array of variables + */ + public function getGlobal($varname = null) + { + if (isset($varname)) { + if (isset(self::$global_tpl_vars[$varname])) { + return self::$global_tpl_vars[$varname]->value; + } else { + return ''; + } + } else { + $_result = array(); + foreach (self::$global_tpl_vars AS $key => $var) { + $_result[$key] = $var->value; + } + return $_result; + } + } + + /** + * Empty cache folder + * + * @param integer $exp_time expiration time + * @param string $type resource type + * @return integer number of cache files deleted + */ + function clearAllCache($exp_time = null, $type = null) + { + // load cache resource and call clearAll + $_cache_resource = Smarty_CacheResource::load($this, $type); + Smarty_CacheResource::invalidLoadedCache($this); + return $_cache_resource->clearAll($this, $exp_time); + } + + /** + * Empty cache for a specific template + * + * @param string $template_name template name + * @param string $cache_id cache id + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @param string $type resource type + * @return integer number of cache files deleted + */ + public function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null) + { + // load cache resource and call clear + $_cache_resource = Smarty_CacheResource::load($this, $type); + Smarty_CacheResource::invalidLoadedCache($this); + return $_cache_resource->clear($this, $template_name, $cache_id, $compile_id, $exp_time); + } + + /** + * Loads security class and enables security + * + * @param string|Smarty_Security $security_class if a string is used, it must be class-name + * @return Smarty current Smarty instance for chaining + * @throws SmartyException when an invalid class name is provided + */ + public function enableSecurity($security_class = null) + { + if ($security_class instanceof Smarty_Security) { + $this->security_policy = $security_class; + return $this; + } elseif (is_object($security_class)) { + throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security."); + } + if ($security_class == null) { + $security_class = $this->security_class; + } + if (!class_exists($security_class)) { + throw new SmartyException("Security class '$security_class' is not defined"); + } elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) { + throw new SmartyException("Class '$security_class' must extend Smarty_Security."); + } else { + $this->security_policy = new $security_class($this); + } + + return $this; + } + + /** + * Disable security + * @return Smarty current Smarty instance for chaining + */ + public function disableSecurity() + { + $this->security_policy = null; + + return $this; + } + + /** + * Set template directory + * + * @param string|array $template_dir directory(s) of template sources + * @return Smarty current Smarty instance for chaining + */ + public function setTemplateDir($template_dir) + { + $this->template_dir = array(); + foreach ((array) $template_dir as $k => $v) { + $this->template_dir[$k] = rtrim($v, '/\\') . DS; + } + + $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); + return $this; + } + + /** + * Add template directory(s) + * + * @param string|array $template_dir directory(s) of template sources + * @param string $key of the array element to assign the template dir to + * @return Smarty current Smarty instance for chaining + * @throws SmartyException when the given template directory is not valid + */ + public function addTemplateDir($template_dir, $key=null) + { + // make sure we're dealing with an array + $this->template_dir = (array) $this->template_dir; + + if (is_array($template_dir)) { + foreach ($template_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->template_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->template_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } elseif ($key !== null) { + // override directory at specified index + $this->template_dir[$key] = rtrim($template_dir, '/\\') . DS; + } else { + // append new directory + $this->template_dir[] = rtrim($template_dir, '/\\') . DS; + } + $this->joined_template_dir = join(DIRECTORY_SEPARATOR, $this->template_dir); + return $this; + } + + /** + * Get template directories + * + * @param mixed index of directory to get, null to get all + * @return array|string list of template directories, or directory of $index + */ + public function getTemplateDir($index=null) + { + if ($index !== null) { + return isset($this->template_dir[$index]) ? $this->template_dir[$index] : null; + } + + return (array)$this->template_dir; + } + + /** + * Set config directory + * + * @param string|array $template_dir directory(s) of configuration sources + * @return Smarty current Smarty instance for chaining + */ + public function setConfigDir($config_dir) + { + $this->config_dir = array(); + foreach ((array) $config_dir as $k => $v) { + $this->config_dir[$k] = rtrim($v, '/\\') . DS; + } + + $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); + return $this; + } + + /** + * Add config directory(s) + * + * @param string|array $config_dir directory(s) of config sources + * @param string key of the array element to assign the config dir to + * @return Smarty current Smarty instance for chaining + */ + public function addConfigDir($config_dir, $key=null) + { + // make sure we're dealing with an array + $this->config_dir = (array) $this->config_dir; + + if (is_array($config_dir)) { + foreach ($config_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->config_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->config_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } elseif( $key !== null ) { + // override directory at specified index + $this->config_dir[$key] = rtrim($config_dir, '/\\') . DS; + } else { + // append new directory + $this->config_dir[] = rtrim($config_dir, '/\\') . DS; + } + + $this->joined_config_dir = join(DIRECTORY_SEPARATOR, $this->config_dir); + return $this; + } + + /** + * Get config directory + * + * @param mixed index of directory to get, null to get all + * @return array|string configuration directory + */ + public function getConfigDir($index=null) + { + if ($index !== null) { + return isset($this->config_dir[$index]) ? $this->config_dir[$index] : null; + } + + return (array)$this->config_dir; + } + + /** + * Set plugins directory + * + * @param string|array $plugins_dir directory(s) of plugins + * @return Smarty current Smarty instance for chaining + */ + public function setPluginsDir($plugins_dir) + { + $this->plugins_dir = array(); + foreach ((array)$plugins_dir as $k => $v) { + $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; + } + + return $this; + } + + /** + * Adds directory of plugin files + * + * @param object $smarty + * @param string $ |array $ plugins folder + * @return Smarty current Smarty instance for chaining + */ + public function addPluginsDir($plugins_dir) + { + // make sure we're dealing with an array + $this->plugins_dir = (array) $this->plugins_dir; + + if (is_array($plugins_dir)) { + foreach ($plugins_dir as $k => $v) { + if (is_int($k)) { + // indexes are not merged but appended + $this->plugins_dir[] = rtrim($v, '/\\') . DS; + } else { + // string indexes are overridden + $this->plugins_dir[$k] = rtrim($v, '/\\') . DS; + } + } + } else { + // append new directory + $this->plugins_dir[] = rtrim($plugins_dir, '/\\') . DS; + } + + $this->plugins_dir = array_unique($this->plugins_dir); + return $this; + } + + /** + * Get plugin directories + * + * @return array list of plugin directories + */ + public function getPluginsDir() + { + return (array)$this->plugins_dir; + } + + /** + * Set compile directory + * + * @param string $compile_dir directory to store compiled templates in + * @return Smarty current Smarty instance for chaining + */ + public function setCompileDir($compile_dir) + { + $this->compile_dir = rtrim($compile_dir, '/\\') . DS; + if (!isset(Smarty::$_muted_directories[$this->compile_dir])) { + Smarty::$_muted_directories[$this->compile_dir] = null; + } + return $this; + } + + /** + * Get compiled directory + * + * @return string path to compiled templates + */ + public function getCompileDir() + { + return $this->compile_dir; + } + + /** + * Set cache directory + * + * @param string $cache_dir directory to store cached templates in + * @return Smarty current Smarty instance for chaining + */ + public function setCacheDir($cache_dir) + { + $this->cache_dir = rtrim($cache_dir, '/\\') . DS; + if (!isset(Smarty::$_muted_directories[$this->cache_dir])) { + Smarty::$_muted_directories[$this->cache_dir] = null; + } + return $this; + } + + /** + * Get cache directory + * + * @return string path of cache directory + */ + public function getCacheDir() + { + return $this->cache_dir; + } + + /** + * Set default modifiers + * + * @param array|string $modifiers modifier or list of modifiers to set + * @return Smarty current Smarty instance for chaining + */ + public function setDefaultModifiers($modifiers) + { + $this->default_modifiers = (array) $modifiers; + return $this; + } + + /** + * Add default modifiers + * + * @param array|string $modifiers modifier or list of modifiers to add + * @return Smarty current Smarty instance for chaining + */ + public function addDefaultModifiers($modifiers) + { + if (is_array($modifiers)) { + $this->default_modifiers = array_merge($this->default_modifiers, $modifiers); + } else { + $this->default_modifiers[] = $modifiers; + } + + return $this; + } + + /** + * Get default modifiers + * + * @return array list of default modifiers + */ + public function getDefaultModifiers() + { + return $this->default_modifiers; + } + + + /** + * Set autoload filters + * + * @param array $filters filters to load automatically + * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types + * @return Smarty current Smarty instance for chaining + */ + public function setAutoloadFilters($filters, $type=null) + { + if ($type !== null) { + $this->autoload_filters[$type] = (array) $filters; + } else { + $this->autoload_filters = (array) $filters; + } + + return $this; + } + + /** + * Add autoload filters + * + * @param array $filters filters to load automatically + * @param string $type "pre", "output", … specify the filter type to set. Defaults to none treating $filters' keys as the appropriate types + * @return Smarty current Smarty instance for chaining + */ + public function addAutoloadFilters($filters, $type=null) + { + if ($type !== null) { + if (!empty($this->autoload_filters[$type])) { + $this->autoload_filters[$type] = array_merge($this->autoload_filters[$type], (array) $filters); + } else { + $this->autoload_filters[$type] = (array) $filters; + } + } else { + foreach ((array) $filters as $key => $value) { + if (!empty($this->autoload_filters[$key])) { + $this->autoload_filters[$key] = array_merge($this->autoload_filters[$key], (array) $value); + } else { + $this->autoload_filters[$key] = (array) $value; + } + } + } + + return $this; + } + + /** + * Get autoload filters + * + * @param string $type type of filter to get autoloads for. Defaults to all autoload filters + * @return array array( 'type1' => array( 'filter1', 'filter2', … ) ) or array( 'filter1', 'filter2', …) if $type was specified + */ + public function getAutoloadFilters($type=null) + { + if ($type !== null) { + return isset($this->autoload_filters[$type]) ? $this->autoload_filters[$type] : array(); + } + + return $this->autoload_filters; + } + + /** + * return name of debugging template + * + * @return string + */ + public function getDebugTemplate() + { + return $this->debug_tpl; + } + + /** + * set the debug template + * + * @param string $tpl_name + * @return Smarty current Smarty instance for chaining + * @throws SmartyException if file is not readable + */ + public function setDebugTemplate($tpl_name) + { + if (!is_readable($tpl_name)) { + throw new SmartyException("Unknown file '{$tpl_name}'"); + } + $this->debug_tpl = $tpl_name; + + return $this; + } + + /** + * creates a template object + * + * @param string $template the resource handle of the template file + * @param mixed $cache_id cache id to be used with this template + * @param mixed $compile_id compile id to be used with this template + * @param object $parent next higher level of Smarty variables + * @param boolean $do_clone flag is Smarty object shall be cloned + * @return object template object + */ + public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true) + { + if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) { + $parent = $cache_id; + $cache_id = null; + } + if (!empty($parent) && is_array($parent)) { + $data = $parent; + $parent = null; + } else { + $data = null; + } + // default to cache_id and compile_id of Smarty object + $cache_id = $cache_id === null ? $this->cache_id : $cache_id; + $compile_id = $compile_id === null ? $this->compile_id : $compile_id; + // already in template cache? + if ($this->allow_ambiguous_resources) { + $_templateId = Smarty_Resource::getUniqueTemplateName($this, $template) . $cache_id . $compile_id; + } else { + $_templateId = $this->joined_template_dir . '#' . $template . $cache_id . $compile_id; + } + if (isset($_templateId[150])) { + $_templateId = sha1($_templateId); + } + if ($do_clone) { + if (isset($this->template_objects[$_templateId])) { + // return cached template object + $tpl = clone $this->template_objects[$_templateId]; + $tpl->smarty = clone $tpl->smarty; + $tpl->parent = $parent; + $tpl->tpl_vars = array(); + $tpl->config_vars = array(); + } else { + $tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id); + } + } else { + if (isset($this->template_objects[$_templateId])) { + // return cached template object + $tpl = $this->template_objects[$_templateId]; + $tpl->parent = $parent; + $tpl->tpl_vars = array(); + $tpl->config_vars = array(); + } else { + $tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id); + } + } + // fill data if present + if (!empty($data) && is_array($data)) { + // set up variable values + foreach ($data as $_key => $_val) { + $tpl->tpl_vars[$_key] = new Smarty_variable($_val); + } + } + return $tpl; + } + + + /** + * Takes unknown classes and loads plugin files for them + * class name format: Smarty_PluginType_PluginName + * plugin filename format: plugintype.pluginname.php + * + * @param string $plugin_name class plugin name to load + * @param bool $check check if already loaded + * @return string |boolean filepath of loaded file or false + */ + public function loadPlugin($plugin_name, $check = true) + { + // if function or class exists, exit silently (already loaded) + if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false))) { + return true; + } + // Plugin name is expected to be: Smarty_[Type]_[Name] + $_name_parts = explode('_', $plugin_name, 3); + // class name must have three parts to be valid plugin + // count($_name_parts) < 3 === !isset($_name_parts[2]) + if (!isset($_name_parts[2]) || strtolower($_name_parts[0]) !== 'smarty') { + throw new SmartyException("plugin {$plugin_name} is not a valid name format"); + return false; + } + // if type is "internal", get plugin from sysplugins + if (strtolower($_name_parts[1]) == 'internal') { + $file = SMARTY_SYSPLUGINS_DIR . strtolower($plugin_name) . '.php'; + if (file_exists($file)) { + require_once($file); + return $file; + } else { + return false; + } + } + // plugin filename is expected to be: [type].[name].php + $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php"; + + // loop through plugin dirs and find the plugin + foreach($this->getPluginsDir() as $_plugin_dir) { + $names = array( + $_plugin_dir . $_plugin_filename, + $_plugin_dir . strtolower($_plugin_filename), + ); + foreach ($names as $file) { + if (file_exists($file)) { + require_once($file); + return $file; + } + if ($this->use_include_path && !preg_match('/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/', $_plugin_dir)) { + // try PHP include_path + if (($file = Smarty_Internal_Get_Include_Path::getIncludePath($file)) !== false) { + require_once($file); + return $file; + } + } + } + } + // no plugin loaded + return false; + } + + /** + * Compile all template files + * + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * @return integer number of template files recompiled + */ + public function compileAllTemplates($extention = '.tpl', $force_compile = false, $time_limit = 0, $max_errors = null) + { + return Smarty_Internal_Utility::compileAllTemplates($extention, $force_compile, $time_limit, $max_errors, $this); + } + + /** + * Compile all config files + * + * @param string $extension file extension + * @param bool $force_compile force all to recompile + * @param int $time_limit + * @param int $max_errors + * @return integer number of template files recompiled + */ + public function compileAllConfig($extention = '.conf', $force_compile = false, $time_limit = 0, $max_errors = null) + { + return Smarty_Internal_Utility::compileAllConfig($extention, $force_compile, $time_limit, $max_errors, $this); + } + + /** + * Delete compiled template file + * + * @param string $resource_name template name + * @param string $compile_id compile id + * @param integer $exp_time expiration time + * @return integer number of template files deleted + */ + public function clearCompiledTemplate($resource_name = null, $compile_id = null, $exp_time = null) + { + return Smarty_Internal_Utility::clearCompiledTemplate($resource_name, $compile_id, $exp_time, $this); + } + + + /** + * Return array of tag/attributes of all tags used by an template + * + * @param object $templae template object + * @return array of tag/attributes + */ + public function getTags(Smarty_Internal_Template $template) + { + return Smarty_Internal_Utility::getTags($template); + } + + /** + * Run installation test + * + * @param array $errors Array to write errors into, rather than outputting them + * @return boolean true if setup is fine, false if something is wrong + */ + public function testInstall(&$errors=null) + { + return Smarty_Internal_Utility::testInstall($this, $errors); + } + + /** + * Error Handler to mute expected messages + * + * @link http://php.net/set_error_handler + * @param integer $errno Error level + * @return boolean + */ + public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) + { + $_is_muted_directory = false; + + // add the SMARTY_DIR to the list of muted directories + if (!isset(Smarty::$_muted_directories[SMARTY_DIR])) { + $smarty_dir = realpath(SMARTY_DIR); + Smarty::$_muted_directories[SMARTY_DIR] = array( + 'file' => $smarty_dir, + 'length' => strlen($smarty_dir), + ); + } + + // walk the muted directories and test against $errfile + foreach (Smarty::$_muted_directories as $key => &$dir) { + if (!$dir) { + // resolve directory and length for speedy comparisons + $file = realpath($key); + $dir = array( + 'file' => $file, + 'length' => strlen($file), + ); + } + if (!strncmp($errfile, $dir['file'], $dir['length'])) { + $_is_muted_directory = true; + break; + } + } + + // pass to next error handler if this error did not occur inside SMARTY_DIR + // or the error was within smarty but masked to be ignored + if (!$_is_muted_directory || ($errno && $errno & error_reporting())) { + if (Smarty::$_previous_error_handler) { + return call_user_func(Smarty::$_previous_error_handler, $errno, $errstr, $errfile, $errline, $errcontext); + } else { + return false; + } + } + } + + /** + * Enable error handler to mute expected messages + * + * @return void + */ + public static function muteExpectedErrors() + { + /* + error muting is done because some people implemented custom error_handlers using + http://php.net/set_error_handler and for some reason did not understand the following paragraph: + + It is important to remember that the standard PHP error handler is completely bypassed for the + error types specified by error_types unless the callback function returns FALSE. + error_reporting() settings will have no effect and your error handler will be called regardless - + however you are still able to read the current value of error_reporting and act appropriately. + Of particular note is that this value will be 0 if the statement that caused the error was + prepended by the @ error-control operator. + + Smarty deliberately uses @filemtime() over file_exists() and filemtime() in some places. Reasons include + - @filemtime() is almost twice as fast as using an additional file_exists() + - between file_exists() and filemtime() a possible race condition is opened, + which does not exist using the simple @filemtime() approach. + */ + $error_handler = array('Smarty', 'mutingErrorHandler'); + $previous = set_error_handler($error_handler); + + // avoid dead loops + if ($previous !== $error_handler) { + Smarty::$_previous_error_handler = $previous; + } + } + + /** + * Disable error handler muting expected messages + * + * @return void + */ + public static function unmuteExpectedErrors() + { + restore_error_handler(); + } +} + +/** +* Smarty exception class +* @package Smarty +*/ +class SmartyException extends Exception { +} + +/** +* Smarty compiler exception class +* @package Smarty +*/ +class SmartyCompilerException extends SmartyException { +} + +/** +* Autoloader +*/ +function smartyAutoload($class) +{ + $_class = strtolower($class); + $_classes = array( + 'smarty_config_source' => true, + 'smarty_config_compiled' => true, + 'smarty_security' => true, + 'smarty_cacheresource' => true, + 'smarty_cacheresource_custom' => true, + 'smarty_cacheresource_keyvaluestore' => true, + 'smarty_resource' => true, + 'smarty_resource_custom' => true, + 'smarty_resource_uncompiled' => true, + 'smarty_resource_recompiled' => true, + ); + + if (!strncmp($_class, 'smarty_internal_', 16) || isset($_classes[$_class])) { + include SMARTY_SYSPLUGINS_DIR . $_class . '.php'; + } +} + +?> diff --git a/ThinkPHP/Library/Vendor/Smarty/SmartyBC.class.php b/ThinkPHP/Library/Vendor/Smarty/SmartyBC.class.php new file mode 100644 index 0000000..c060a25 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/SmartyBC.class.php @@ -0,0 +1,460 @@ + + * @author Uwe Tews + * @author Rodney Rehm + * @package Smarty + */ +/** + * @ignore + */ +require(dirname(__FILE__) . '/Smarty.class.php'); + +/** + * Smarty Backward Compatability Wrapper Class + * + * @package Smarty + */ +class SmartyBC extends Smarty { + + /** + * Smarty 2 BC + * @var string + */ + public $_version = self::SMARTY_VERSION; + + /** + * Initialize new SmartyBC object + * + * @param array $options options to set during initialization, e.g. array( 'forceCompile' => false ) + */ + public function __construct(array $options=array()) + { + parent::__construct($options); + // register {php} tag + $this->registerPlugin('block', 'php', 'smarty_php_tag'); + } + + /** + * wrapper for assign_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to assign + */ + public function assign_by_ref($tpl_var, &$value) + { + $this->assignByRef($tpl_var, $value); + } + + /** + * wrapper for append_by_ref + * + * @param string $tpl_var the template variable name + * @param mixed &$value the referenced value to append + * @param boolean $merge flag if array elements shall be merged + */ + public function append_by_ref($tpl_var, &$value, $merge = false) + { + $this->appendByRef($tpl_var, $value, $merge); + } + + /** + * clear the given assigned template variable. + * + * @param string $tpl_var the template variable to clear + */ + public function clear_assign($tpl_var) + { + $this->clearAssign($tpl_var); + } + + /** + * Registers custom function to be used in templates + * + * @param string $function the name of the template function + * @param string $function_impl the name of the PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_function($function, $function_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('function', $function, $function_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters custom function + * + * @param string $function name of template function + */ + public function unregister_function($function) + { + $this->unregisterPlugin('function', $function); + } + + /** + * Registers object to be used in templates + * + * @param string $object name of template object + * @param object $object_impl the referenced PHP object to register + * @param array $allowed list of allowed methods (empty = all) + * @param boolean $smarty_args smarty argument format, else traditional + * @param array $block_functs list of methods that are block format + */ + public function register_object($object, $object_impl, $allowed = array(), $smarty_args = true, $block_methods = array()) + { + settype($allowed, 'array'); + settype($smarty_args, 'boolean'); + $this->registerObject($object, $object_impl, $allowed, $smarty_args, $block_methods); + } + + /** + * Unregisters object + * + * @param string $object name of template object + */ + public function unregister_object($object) + { + $this->unregisterObject($object); + } + + /** + * Registers block function to be used in templates + * + * @param string $block name of template block + * @param string $block_impl PHP function to register + * @param bool $cacheable + * @param mixed $cache_attrs + */ + public function register_block($block, $block_impl, $cacheable=true, $cache_attrs=null) + { + $this->registerPlugin('block', $block, $block_impl, $cacheable, $cache_attrs); + } + + /** + * Unregisters block function + * + * @param string $block name of template function + */ + public function unregister_block($block) + { + $this->unregisterPlugin('block', $block); + } + + /** + * Registers compiler function + * + * @param string $function name of template function + * @param string $function_impl name of PHP function to register + * @param bool $cacheable + */ + public function register_compiler_function($function, $function_impl, $cacheable=true) + { + $this->registerPlugin('compiler', $function, $function_impl, $cacheable); + } + + /** + * Unregisters compiler function + * + * @param string $function name of template function + */ + public function unregister_compiler_function($function) + { + $this->unregisterPlugin('compiler', $function); + } + + /** + * Registers modifier to be used in templates + * + * @param string $modifier name of template modifier + * @param string $modifier_impl name of PHP function to register + */ + public function register_modifier($modifier, $modifier_impl) + { + $this->registerPlugin('modifier', $modifier, $modifier_impl); + } + + /** + * Unregisters modifier + * + * @param string $modifier name of template modifier + */ + public function unregister_modifier($modifier) + { + $this->unregisterPlugin('modifier', $modifier); + } + + /** + * Registers a resource to fetch a template + * + * @param string $type name of resource + * @param array $functions array of functions to handle resource + */ + public function register_resource($type, $functions) + { + $this->registerResource($type, $functions); + } + + /** + * Unregisters a resource + * + * @param string $type name of resource + */ + public function unregister_resource($type) + { + $this->unregisterResource($type); + } + + /** + * Registers a prefilter function to apply + * to a template before compiling + * + * @param callable $function + */ + public function register_prefilter($function) + { + $this->registerFilter('pre', $function); + } + + /** + * Unregisters a prefilter function + * + * @param callable $function + */ + public function unregister_prefilter($function) + { + $this->unregisterFilter('pre', $function); + } + + /** + * Registers a postfilter function to apply + * to a compiled template after compilation + * + * @param callable $function + */ + public function register_postfilter($function) + { + $this->registerFilter('post', $function); + } + + /** + * Unregisters a postfilter function + * + * @param callable $function + */ + public function unregister_postfilter($function) + { + $this->unregisterFilter('post', $function); + } + + /** + * Registers an output filter function to apply + * to a template output + * + * @param callable $function + */ + public function register_outputfilter($function) + { + $this->registerFilter('output', $function); + } + + /** + * Unregisters an outputfilter function + * + * @param callable $function + */ + public function unregister_outputfilter($function) + { + $this->unregisterFilter('output', $function); + } + + /** + * load a filter of specified type and name + * + * @param string $type filter type + * @param string $name filter name + */ + public function load_filter($type, $name) + { + $this->loadFilter($type, $name); + } + + /** + * clear cached content for the given template and cache id + * + * @param string $tpl_file name of template file + * @param string $cache_id name of cache_id + * @param string $compile_id name of compile_id + * @param string $exp_time expiration time + * @return boolean + */ + public function clear_cache($tpl_file = null, $cache_id = null, $compile_id = null, $exp_time = null) + { + return $this->clearCache($tpl_file, $cache_id, $compile_id, $exp_time); + } + + /** + * clear the entire contents of cache (all templates) + * + * @param string $exp_time expire time + * @return boolean + */ + public function clear_all_cache($exp_time = null) + { + return $this->clearCache(null, null, null, $exp_time); + } + + /** + * test to see if valid cache exists for this template + * + * @param string $tpl_file name of template file + * @param string $cache_id + * @param string $compile_id + * @return boolean + */ + public function is_cached($tpl_file, $cache_id = null, $compile_id = null) + { + return $this->isCached($tpl_file, $cache_id, $compile_id); + } + + /** + * clear all the assigned template variables. + */ + public function clear_all_assign() + { + $this->clearAllAssign(); + } + + /** + * clears compiled version of specified template resource, + * or all compiled template files if one is not specified. + * This function is for advanced use only, not normally needed. + * + * @param string $tpl_file + * @param string $compile_id + * @param string $exp_time + * @return boolean results of {@link smarty_core_rm_auto()} + */ + public function clear_compiled_tpl($tpl_file = null, $compile_id = null, $exp_time = null) + { + return $this->clearCompiledTemplate($tpl_file, $compile_id, $exp_time); + } + + /** + * Checks whether requested template exists. + * + * @param string $tpl_file + * @return boolean + */ + public function template_exists($tpl_file) + { + return $this->templateExists($tpl_file); + } + + /** + * Returns an array containing template variables + * + * @param string $name + * @return array + */ + public function get_template_vars($name=null) + { + return $this->getTemplateVars($name); + } + + /** + * Returns an array containing config variables + * + * @param string $name + * @return array + */ + public function get_config_vars($name=null) + { + return $this->getConfigVars($name); + } + + /** + * load configuration values + * + * @param string $file + * @param string $section + * @param string $scope + */ + public function config_load($file, $section = null, $scope = 'global') + { + $this->ConfigLoad($file, $section, $scope); + } + + /** + * return a reference to a registered object + * + * @param string $name + * @return object + */ + public function get_registered_object($name) + { + return $this->getRegisteredObject($name); + } + + /** + * clear configuration values + * + * @param string $var + */ + public function clear_config($var = null) + { + $this->clearConfig($var); + } + + /** + * trigger Smarty error + * + * @param string $error_msg + * @param integer $error_type + */ + public function trigger_error($error_msg, $error_type = E_USER_WARNING) + { + trigger_error("Smarty error: $error_msg", $error_type); + } + +} + +/** + * Smarty {php}{/php} block function + * + * @param array $params parameter list + * @param string $content contents of the block + * @param object $template template object + * @param boolean &$repeat repeat flag + * @return string content re-formatted + */ +function smarty_php_tag($params, $content, $template, &$repeat) +{ + eval($content); + return ''; +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/debug.tpl b/ThinkPHP/Library/Vendor/Smarty/debug.tpl new file mode 100644 index 0000000..12eef0f --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/debug.tpl @@ -0,0 +1,133 @@ +{capture name='_smarty_debug' assign=debug_output} + + + + Smarty Debug Console + + + + +

    Smarty Debug Console - {if isset($template_name)}{$template_name|debug_print_var nofilter}{else}Total Time {$execution_time|string_format:"%.5f"}{/if}

    + +{if !empty($template_data)} +

    included templates & config files (load time in seconds)

    + +
    +{foreach $template_data as $template} + {$template.name} + + (compile {$template['compile_time']|string_format:"%.5f"}) (render {$template['render_time']|string_format:"%.5f"}) (cache {$template['cache_time']|string_format:"%.5f"}) + +
    +{/foreach} +
    +{/if} + +

    assigned template variables

    + + + {foreach $assigned_vars as $vars} + + + + {/foreach} +
    ${$vars@key|escape:'html'}{$vars|debug_print_var nofilter}
    + +

    assigned config file variables (outer template scope)

    + + + {foreach $config_vars as $vars} + + + + {/foreach} + +
    {$vars@key|escape:'html'}{$vars|debug_print_var nofilter}
    + + +{/capture} + diff --git a/ThinkPHP/Library/Vendor/Smarty/plugins/block.textformat.php b/ThinkPHP/Library/Vendor/Smarty/plugins/block.textformat.php new file mode 100644 index 0000000..bdd8067 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/plugins/block.textformat.php @@ -0,0 +1,113 @@ + + * Name: textformat
    + * Purpose: format text a certain way with preset styles + * or custom wrap/indent settings
    + * Params: + *
    + * - style         - string (email)
    + * - indent        - integer (0)
    + * - wrap          - integer (80)
    + * - wrap_char     - string ("\n")
    + * - indent_char   - string (" ")
    + * - wrap_boundary - boolean (true)
    + * 
    + * + * @link http://www.smarty.net/manual/en/language.function.textformat.php {textformat} + * (Smarty online manual) + * @param array $params parameters + * @param string $content contents of the block + * @param Smarty_Internal_Template $template template object + * @param boolean &$repeat repeat flag + * @return string content re-formatted + * @author Monte Ohrt + */ +function smarty_block_textformat($params, $content, $template, &$repeat) +{ + if (is_null($content)) { + return; + } + + $style = null; + $indent = 0; + $indent_first = 0; + $indent_char = ' '; + $wrap = 80; + $wrap_char = "\n"; + $wrap_cut = false; + $assign = null; + + foreach ($params as $_key => $_val) { + switch ($_key) { + case 'style': + case 'indent_char': + case 'wrap_char': + case 'assign': + $$_key = (string)$_val; + break; + + case 'indent': + case 'indent_first': + case 'wrap': + $$_key = (int)$_val; + break; + + case 'wrap_cut': + $$_key = (bool)$_val; + break; + + default: + trigger_error("textformat: unknown attribute '$_key'"); + } + } + + if ($style == 'email') { + $wrap = 72; + } + // split into paragraphs + $_paragraphs = preg_split('![\r\n]{2}!', $content); + $_output = ''; + + + foreach ($_paragraphs as &$_paragraph) { + if (!$_paragraph) { + continue; + } + // convert mult. spaces & special chars to single space + $_paragraph = preg_replace(array('!\s+!u', '!(^\s+)|(\s+$)!u'), array(' ', ''), $_paragraph); + // indent first line + if ($indent_first > 0) { + $_paragraph = str_repeat($indent_char, $indent_first) . $_paragraph; + } + // wordwrap sentences + if (SMARTY_MBSTRING /* ^phpunit */&&empty($_SERVER['SMARTY_PHPUNIT_DISABLE_MBSTRING'])/* phpunit$ */) { + require_once(SMARTY_PLUGINS_DIR . 'shared.mb_wordwrap.php'); + $_paragraph = smarty_mb_wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); + } else { + $_paragraph = wordwrap($_paragraph, $wrap - $indent, $wrap_char, $wrap_cut); + } + // indent lines + if ($indent > 0) { + $_paragraph = preg_replace('!^!m', str_repeat($indent_char, $indent), $_paragraph); + } + } + $_output = implode($wrap_char . $wrap_char, $_paragraphs); + + if ($assign) { + $template->assign($assign, $_output); + } else { + return $_output; + } +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/plugins/function.counter.php b/ThinkPHP/Library/Vendor/Smarty/plugins/function.counter.php new file mode 100644 index 0000000..3906bad --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/plugins/function.counter.php @@ -0,0 +1,78 @@ + + * Name: counter
    + * Purpose: print out a counter value + * + * @author Monte Ohrt + * @link http://www.smarty.net/manual/en/language.function.counter.php {counter} + * (Smarty online manual) + * @param array $params parameters + * @param Smarty_Internal_Template $template template object + * @return string|null + */ +function smarty_function_counter($params, $template) +{ + static $counters = array(); + + $name = (isset($params['name'])) ? $params['name'] : 'default'; + if (!isset($counters[$name])) { + $counters[$name] = array( + 'start'=>1, + 'skip'=>1, + 'direction'=>'up', + 'count'=>1 + ); + } + $counter =& $counters[$name]; + + if (isset($params['start'])) { + $counter['start'] = $counter['count'] = (int)$params['start']; + } + + if (!empty($params['assign'])) { + $counter['assign'] = $params['assign']; + } + + if (isset($counter['assign'])) { + $template->assign($counter['assign'], $counter['count']); + } + + if (isset($params['print'])) { + $print = (bool)$params['print']; + } else { + $print = empty($counter['assign']); + } + + if ($print) { + $retval = $counter['count']; + } else { + $retval = null; + } + + if (isset($params['skip'])) { + $counter['skip'] = $params['skip']; + } + + if (isset($params['direction'])) { + $counter['direction'] = $params['direction']; + } + + if ($counter['direction'] == "down") + $counter['count'] -= $counter['skip']; + else + $counter['count'] += $counter['skip']; + + return $retval; + +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/plugins/function.cycle.php b/ThinkPHP/Library/Vendor/Smarty/plugins/function.cycle.php new file mode 100644 index 0000000..1778ffb --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/plugins/function.cycle.php @@ -0,0 +1,106 @@ + + * Name: cycle
    + * Date: May 3, 2002
    + * Purpose: cycle through given values
    + * Params: + *
    + * - name      - name of cycle (optional)
    + * - values    - comma separated list of values to cycle, or an array of values to cycle
    + *               (this can be left out for subsequent calls)
    + * - reset     - boolean - resets given var to true
    + * - print     - boolean - print var or not. default is true
    + * - advance   - boolean - whether or not to advance the cycle
    + * - delimiter - the value delimiter, default is ","
    + * - assign    - boolean, assigns to template var instead of printed.
    + * 
    + * Examples:
    + *
    + * {cycle values="#eeeeee,#d0d0d0d"}
    + * {cycle name=row values="one,two,three" reset=true}
    + * {cycle name=row}
    + * 
    + * + * @link http://www.smarty.net/manual/en/language.function.cycle.php {cycle} + * (Smarty online manual) + * @author Monte Ohrt + * @author credit to Mark Priatel + * @author credit to Gerard + * @author credit to Jason Sweat + * @version 1.3 + * @param array $params parameters + * @param Smarty_Internal_Template $template template object + * @return string|null + */ + +function smarty_function_cycle($params, $template) +{ + static $cycle_vars; + + $name = (empty($params['name'])) ? 'default' : $params['name']; + $print = (isset($params['print'])) ? (bool)$params['print'] : true; + $advance = (isset($params['advance'])) ? (bool)$params['advance'] : true; + $reset = (isset($params['reset'])) ? (bool)$params['reset'] : false; + + if (!isset($params['values'])) { + if(!isset($cycle_vars[$name]['values'])) { + trigger_error("cycle: missing 'values' parameter"); + return; + } + } else { + if(isset($cycle_vars[$name]['values']) + && $cycle_vars[$name]['values'] != $params['values'] ) { + $cycle_vars[$name]['index'] = 0; + } + $cycle_vars[$name]['values'] = $params['values']; + } + + if (isset($params['delimiter'])) { + $cycle_vars[$name]['delimiter'] = $params['delimiter']; + } elseif (!isset($cycle_vars[$name]['delimiter'])) { + $cycle_vars[$name]['delimiter'] = ','; + } + + if(is_array($cycle_vars[$name]['values'])) { + $cycle_array = $cycle_vars[$name]['values']; + } else { + $cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']); + } + + if(!isset($cycle_vars[$name]['index']) || $reset ) { + $cycle_vars[$name]['index'] = 0; + } + + if (isset($params['assign'])) { + $print = false; + $template->assign($params['assign'], $cycle_array[$cycle_vars[$name]['index']]); + } + + if($print) { + $retval = $cycle_array[$cycle_vars[$name]['index']]; + } else { + $retval = null; + } + + if($advance) { + if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) { + $cycle_vars[$name]['index'] = 0; + } else { + $cycle_vars[$name]['index']++; + } + } + + return $retval; +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/plugins/function.fetch.php b/ThinkPHP/Library/Vendor/Smarty/plugins/function.fetch.php new file mode 100644 index 0000000..cde98d2 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/plugins/function.fetch.php @@ -0,0 +1,216 @@ + + * Name: fetch
    + * Purpose: fetch file, web or ftp data and display results + * + * @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch} + * (Smarty online manual) + * @author Monte Ohrt + * @param array $params parameters + * @param Smarty_Internal_Template $template template object + * @return string|null if the assign parameter is passed, Smarty assigns the result to a template variable + */ +function smarty_function_fetch($params, $template) +{ + if (empty($params['file'])) { + trigger_error("[plugin] fetch parameter 'file' cannot be empty",E_USER_NOTICE); + return; + } + + $content = ''; + if (isset($template->smarty->security_policy) && !preg_match('!^(http|ftp)://!i', $params['file'])) { + if(!$template->smarty->security_policy->isTrustedResourceDir($params['file'])) { + return; + } + + // fetch the file + if($fp = @fopen($params['file'],'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'',E_USER_NOTICE); + return; + } + } else { + // not a local file + if(preg_match('!^http://!i',$params['file'])) { + // http fetch + if($uri_parts = parse_url($params['file'])) { + // set defaults + $host = $server_name = $uri_parts['host']; + $timeout = 30; + $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; + $agent = "Smarty Template Engine ". Smarty::SMARTY_VERSION; + $referer = ""; + $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; + $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; + $_is_proxy = false; + if(empty($uri_parts['port'])) { + $port = 80; + } else { + $port = $uri_parts['port']; + } + if(!empty($uri_parts['user'])) { + $user = $uri_parts['user']; + } + if(!empty($uri_parts['pass'])) { + $pass = $uri_parts['pass']; + } + // loop through parameters, setup headers + foreach($params as $param_key => $param_value) { + switch($param_key) { + case "file": + case "assign": + case "assign_headers": + break; + case "user": + if(!empty($param_value)) { + $user = $param_value; + } + break; + case "pass": + if(!empty($param_value)) { + $pass = $param_value; + } + break; + case "accept": + if(!empty($param_value)) { + $accept = $param_value; + } + break; + case "header": + if(!empty($param_value)) { + if(!preg_match('![\w\d-]+: .+!',$param_value)) { + trigger_error("[plugin] invalid header format '".$param_value."'",E_USER_NOTICE); + return; + } else { + $extra_headers[] = $param_value; + } + } + break; + case "proxy_host": + if(!empty($param_value)) { + $proxy_host = $param_value; + } + break; + case "proxy_port": + if(!preg_match('!\D!', $param_value)) { + $proxy_port = (int) $param_value; + } else { + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); + return; + } + break; + case "agent": + if(!empty($param_value)) { + $agent = $param_value; + } + break; + case "referer": + if(!empty($param_value)) { + $referer = $param_value; + } + break; + case "timeout": + if(!preg_match('!\D!', $param_value)) { + $timeout = (int) $param_value; + } else { + trigger_error("[plugin] invalid value for attribute '".$param_key."'",E_USER_NOTICE); + return; + } + break; + default: + trigger_error("[plugin] unrecognized attribute '".$param_key."'",E_USER_NOTICE); + return; + } + } + if(!empty($proxy_host) && !empty($proxy_port)) { + $_is_proxy = true; + $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout); + } else { + $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout); + } + + if(!$fp) { + trigger_error("[plugin] unable to fetch: $errstr ($errno)",E_USER_NOTICE); + return; + } else { + if($_is_proxy) { + fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); + } else { + fputs($fp, "GET $uri HTTP/1.0\r\n"); + } + if(!empty($host)) { + fputs($fp, "Host: $host\r\n"); + } + if(!empty($accept)) { + fputs($fp, "Accept: $accept\r\n"); + } + if(!empty($agent)) { + fputs($fp, "User-Agent: $agent\r\n"); + } + if(!empty($referer)) { + fputs($fp, "Referer: $referer\r\n"); + } + if(isset($extra_headers) && is_array($extra_headers)) { + foreach($extra_headers as $curr_header) { + fputs($fp, $curr_header."\r\n"); + } + } + if(!empty($user) && !empty($pass)) { + fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n"); + } + + fputs($fp, "\r\n"); + while(!feof($fp)) { + $content .= fgets($fp,4096); + } + fclose($fp); + $csplit = preg_split("!\r\n\r\n!",$content,2); + + $content = $csplit[1]; + + if(!empty($params['assign_headers'])) { + $template->assign($params['assign_headers'],preg_split("!\r\n!",$csplit[0])); + } + } + } else { + trigger_error("[plugin fetch] unable to parse URL, check syntax",E_USER_NOTICE); + return; + } + } else { + // ftp fetch + if($fp = @fopen($params['file'],'r')) { + while(!feof($fp)) { + $content .= fgets ($fp,4096); + } + fclose($fp); + } else { + trigger_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'',E_USER_NOTICE); + return; + } + } + + } + + + if (!empty($params['assign'])) { + $template->assign($params['assign'],$content); + } else { + return $content; + } +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Smarty/plugins/function.html_checkboxes.php b/ThinkPHP/Library/Vendor/Smarty/plugins/function.html_checkboxes.php new file mode 100644 index 0000000..4251369 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Smarty/plugins/function.html_checkboxes.php @@ -0,0 +1,216 @@ + + * Type: function
    + * Name: html_checkboxes
    + * Date: 24.Feb.2003
    + * Purpose: Prints out a list of checkbox input types
    + * Examples: + *
    + * {html_checkboxes values=$ids output=$names}
    + * {html_checkboxes values=$ids name='box' separator='
    ' output=$names} + * {html_checkboxes values=$ids checked=$checked separator='
    ' output=$names} + *
    + * Params: + *
    + * - name       (optional) - string default "checkbox"
    + * - values     (required) - array
    + * - options    (optional) - associative array
    + * - checked    (optional) - array default not set
    + * - separator  (optional) - ie 
    or   + * - output (optional) - the output next to each checkbox + * - assign (optional) - assign the output as an array to this variable + * - escape (optional) - escape the content (not value), defaults to true + *
    + * + * @link http://www.smarty.net/manual/en/language.function.html.checkboxes.php {html_checkboxes} + * (Smarty online manual) + * @author Christopher Kvarme + * @author credits to Monte Ohrt + * @version 1.0 + * @param array $params parameters + * @param object $template template object + * @return string + * @uses smarty_function_escape_special_chars() + */ +function smarty_function_html_checkboxes($params, $template) +{ + require_once(SMARTY_PLUGINS_DIR . 'shared.escape_special_chars.php'); + + $name = 'checkbox'; + $values = null; + $options = null; + $selected = array(); + $separator = ''; + $escape = true; + $labels = true; + $label_ids = false; + $output = null; + + $extra = ''; + + foreach($params as $_key => $_val) { + switch($_key) { + case 'name': + case 'separator': + $$_key = (string) $_val; + break; + + case 'escape': + case 'labels': + case 'label_ids': + $$_key = (bool) $_val; + break; + + case 'options': + $$_key = (array) $_val; + break; + + case 'values': + case 'output': + $$_key = array_values((array) $_val); + break; + + case 'checked': + case 'selected': + if (is_array($_val)) { + $selected = array(); + foreach ($_val as $_sel) { + if (is_object($_sel)) { + if (method_exists($_sel, "__toString")) { + $_sel = smarty_function_escape_special_chars((string) $_sel->__toString()); + } else { + trigger_error("html_checkboxes: selected attribute contains an object of class '". get_class($_sel) ."' without __toString() method", E_USER_NOTICE); + continue; + } + } else { + $_sel = smarty_function_escape_special_chars((string) $_sel); + } + $selected[$_sel] = true; + } + } elseif (is_object($_val)) { + if (method_exists($_val, "__toString")) { + $selected = smarty_function_escape_special_chars((string) $_val->__toString()); + } else { + trigger_error("html_checkboxes: selected attribute is an object of class '". get_class($_val) ."' without __toString() method", E_USER_NOTICE); + } + } else { + $selected = smarty_function_escape_special_chars((string) $_val); + } + break; + + case 'checkboxes': + trigger_error('html_checkboxes: the use of the "checkboxes" attribute is deprecated, use "options" instead', E_USER_WARNING); + $options = (array) $_val; + break; + + case 'assign': + break; + + default: + if(!is_array($_val)) { + $extra .= ' '.$_key.'="'.smarty_function_escape_special_chars($_val).'"'; + } else { + trigger_error("html_checkboxes: extra attribute '$_key' cannot be an array", E_USER_NOTICE); + } + break; + } + } + + if (!isset($options) && !isset($values)) + return ''; /* raise error here? */ + + $_html_result = array(); + + if (isset($options)) { + foreach ($options as $_key=>$_val) { + $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); + } + } else { + foreach ($values as $_i=>$_key) { + $_val = isset($output[$_i]) ? $output[$_i] : ''; + $_html_result[] = smarty_function_html_checkboxes_output($name, $_key, $_val, $selected, $extra, $separator, $labels, $label_ids, $escape); + } + } + + if(!empty($params['assign'])) { + $template->assign($params['assign'], $_html_result); + } else { + return implode("\n", $_html_result); + } + +} + +function smarty_function_html_checkboxes_output($name, $value, $output, $selected, $extra, $separator, $labels, $label_ids, $escape=true) { + $_output = ''; + + if (is_object($value)) { + if (method_exists($value, "__toString")) { + $value = (string) $value->__toString(); + } else { + trigger_error("html_options: value is an object of class '". get_class($value) ."' without __toString() method", E_USER_NOTICE); + return ''; + } + } else { + $value = (string) $value; + } + + if (is_object($output)) { + if (method_exists($output, "__toString")) { + $output = (string) $output->__toString(); + } else { + trigger_error("html_options: output is an object of class '". get_class($output) ."' without __toString() method", E_USER_NOTICE); + return ''; + } + } else { + $output = (string) $output; + } + + if ($labels) { + if ($label_ids) { + $_id = smarty_function_escape_special_chars(preg_replace('![^\w\-\.]!u', '_', $name . '_' . $value)); + $_output .= '

    NiFR; z@9a_5d;0C}4zCuU<0N;&%XPV%l(~kiP0AS151BZoZbPoR>hjo-Ba$8FM9k<5HQ8}~ zuDr1{OqS@^9Nz-Ku6rizs5c(UI-0dduyPeIdm{1 z;?-eO3>EN{YtmFbon5zMAfThQ{>$rKcp+oQ-M%^<={B=}& zV5L%;!4n9#6x1Y~l@G&5{1#kYjs?>NWBe0l3F?&AzRm9_(Ax zTZs(H*VY|alcZ?ff&9L=KRAB{vX9oM{-VfG@Q&Ci`Jinhe+PlnXdiZ8BY)-8`k;3s ze<$?|t}0FJIwodC`%$pspjFrhMXhN23AWsLVYblMYWXYc z`P$k`YaeSbYX6~H{p0gjJU=y`+OO5${^*o^t^Hd5$|sQz3lw{Ycw&-w?V9hup&L;~ z`$fnvi6~rYY81{(&d8%tIGB0lYDt6F@!HP9Rj}#cbzzHJyDcq&JMS#5H~mwK$W^zM z%coxj)kbT4I%=jJf^x=QuCM&q=;mPy^JS}!;-<3-3p17HGt5Dn5HCinzP9?=XEhww z){n$bSU&v~6g>34 z*dO_C+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nhlsd97!ZAl_9|gAP8k$qI&t9xmYUd15-^Mu?RA#E@i$W{b zv9&tVlsdA2t*`Zb?Am8*u*PJPz7A*Yyas3Oyas3Oyas3Oyas3Oyas3OyawmEuwK}J z71kzUHP$_gkgmn|R$(*p*I_-p8ne$_TyMcoOKe5W?Z~0u&RCB#%x0v4aX_a5%R7;~ z1^1tc)@pa1gIdStQ(MSgx^w-OwP$XM&fR*>_UPKJo41{_bN%+{8C$pP+z~yuyQ3?* zKiAdO9i6{=`_@hCq6@cf+=Ak-MCaGeX06`3sRMT*XXDPD+opGRZeG86&HC*-I_d?T z)DqoN`wVZ{vF*(5>(@osoFCn}aeZ{t)(u;uThEA=H?H2YW&NgTPc*Z9LCg614d-lH zy?xQ@wcEFDUcc_l)qrlx&aE4^uimy1P4#qicjTi}0so(C_H^cQ_#u$`4K&c>P;nGR zQ6P;_z741$Bob=Rs3Uy`&d=45+=VlmZo2T-jq~{$$+iO7>u|LY^)~|j+TBqY0w|xF zHw(3?Zb!YZs8(kq`rC z6z!akbf?BFQS?mgvlTg8(M}YqbR*i|qCrgTf=Lj@$8xBgmj5Rptl703-@8K7@2h@c1cMuj>%EHDJABf=||hRe%lt8wdPvF2wFVunT>NqXrNy z3t@*jMRJ>AO{HK(WdM3BY@Rk)FtATF0ALYdXa&rLC7Q>8=swIkGw|CJWq8EqK(^+A zP{X9LL9RulL81M|pv$1OfQ}RJ9>Ep(VHf&kn^pMTmMdZFe**8ExE?n3O~P&Xg`h9t zmwomNci~rpj{eHc{dl+F1H$)(AK<+dKNcPp9>cHw{8sqA@JHcK!k_WJ!I$xCLSGlY zAv}rS0lFK6S_^{x3}pL>@KfQJc&_Q^!Y_o^K&EGfUkOj+_j5Mj?H0clo&(ALCj0~b z(=+i4I-5b#Eg +// +---------------------------------------------------------------------- +namespace Think; +/** + * ThinkPHP 视图类 + */ +class View { + /** + * 模板输出变量 + * @var tVar + * @access protected + */ + protected $tVar = array(); + + /** + * 模板主题 + * @var theme + * @access protected + */ + protected $theme = ''; + + /** + * 模板变量赋值 + * @access public + * @param mixed $name + * @param mixed $value + */ + public function assign($name,$value=''){ + if(is_array($name)) { + $this->tVar = array_merge($this->tVar,$name); + }else { + $this->tVar[$name] = $value; + } + } + + /** + * 取得模板变量的值 + * @access public + * @param string $name + * @return mixed + */ + public function get($name=''){ + if('' === $name) { + return $this->tVar; + } + return isset($this->tVar[$name])?$this->tVar[$name]:false; + } + + /** + * 加载模板和页面输出 可以返回输出内容 + * @access public + * @param string $templateFile 模板文件名 + * @param string $charset 模板输出字符集 + * @param string $contentType 输出类型 + * @param string $content 模板输出内容 + * @param string $prefix 模板缓存前缀 + * @return mixed + */ + public function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') { + G('viewStartTime'); + // 视图开始标签 + Hook::listen('view_begin',$templateFile); + // 解析并获取模板内容 + $content = $this->fetch($templateFile,$content,$prefix); + // 输出模板内容 + $this->render($content,$charset,$contentType); + // 视图结束标签 + Hook::listen('view_end'); + } + + /** + * 输出内容文本可以包括Html + * @access private + * @param string $content 输出内容 + * @param string $charset 模板输出字符集 + * @param string $contentType 输出类型 + * @return mixed + */ + private function render($content,$charset='',$contentType=''){ + if(empty($charset)) $charset = C('DEFAULT_CHARSET'); + if(empty($contentType)) $contentType = C('TMPL_CONTENT_TYPE'); + // 网页字符编码 + header('Content-Type:'.$contentType.'; charset='.$charset); + header('Cache-control: '.C('HTTP_CACHE_CONTROL')); // 页面缓存控制 + header('X-Powered-By:ThinkPHP'); + // 输出模板文件 + echo $content; + } + + /** + * 解析和获取模板内容 用于输出 + * @access public + * @param string $templateFile 模板文件名 + * @param string $content 模板输出内容 + * @param string $prefix 模板缓存前缀 + * @return string + */ + public function fetch($templateFile='',$content='',$prefix='') { + if(empty($content)) { + $templateFile = $this->parseTemplate($templateFile); + // 模板文件不存在直接返回 + if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_').':'.$templateFile); + }else{ + defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath()); + } + // 页面缓存 + ob_start(); + ob_implicit_flush(0); + if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { // 使用PHP原生模板 + $_content = $content; + // 模板阵列变量分解成为独立变量 + extract($this->tVar, EXTR_OVERWRITE); + // 直接载入PHP模板 + empty($_content)?include $templateFile:eval('?>'.$_content); + }else{ + // 视图解析标签 + $params = array('var'=>$this->tVar,'file'=>$templateFile,'content'=>$content,'prefix'=>$prefix); + Hook::listen('view_parse',$params); + } + // 获取并清空缓存 + $content = ob_get_clean(); + // 内容过滤标签 + Hook::listen('view_filter',$content); + // 输出模板文件 + return $content; + } + + /** + * 自动定位模板文件 + * @access protected + * @param string $template 模板文件规则 + * @return string + */ + public function parseTemplate($template='') { + if(is_file($template)) { + return $template; + } + $depr = C('TMPL_FILE_DEPR'); + $template = str_replace(':', $depr, $template); + + // 获取当前模块 + $module = MODULE_NAME; + if(strpos($template,'@')){ // 跨模块调用模版文件 + list($module,$template) = explode('@',$template); + } + // 获取当前主题的模版路径 + defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath($module)); + + // 分析模板文件规则 + if('' == $template) { + // 如果模板文件名为空 按照默认规则定位 + $template = CONTROLLER_NAME . $depr . ACTION_NAME; + }elseif(false === strpos($template, $depr)){ + $template = CONTROLLER_NAME . $depr . $template; + } + $file = THEME_PATH.$template.C('TMPL_TEMPLATE_SUFFIX'); + if(C('TMPL_LOAD_DEFAULTTHEME') && THEME_NAME != C('DEFAULT_THEME') && !is_file($file)){ + // 找不到当前主题模板的时候定位默认主题中的模板 + $file = dirname(THEME_PATH).'/'.C('DEFAULT_THEME').'/'.$template.C('TMPL_TEMPLATE_SUFFIX'); + } + return $file; + } + + /** + * 获取当前的模板路径 + * @access protected + * @param string $module 模块名 + * @return string + */ + protected function getThemePath($module=MODULE_NAME){ + // 获取当前主题名称 + $theme = $this->getTemplateTheme(); + // 获取当前主题的模版路径 + $tmplPath = C('VIEW_PATH'); // 模块设置独立的视图目录 + if(!$tmplPath){ + // 定义TMPL_PATH 则改变全局的视图目录到模块之外 + $tmplPath = defined('TMPL_PATH')? TMPL_PATH.$module.'/' : APP_PATH.$module.'/'.C('DEFAULT_V_LAYER').'/'; + } + return $tmplPath.$theme; + } + + /** + * 设置当前输出的模板主题 + * @access public + * @param mixed $theme 主题名称 + * @return View + */ + public function theme($theme){ + $this->theme = $theme; + return $this; + } + + /** + * 获取当前的模板主题 + * @access private + * @return string + */ + private function getTemplateTheme() { + if($this->theme) { // 指定模板主题 + $theme = $this->theme; + }else{ + /* 获取模板主题名称 */ + $theme = C('DEFAULT_THEME'); + if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题 + $t = C('VAR_TEMPLATE'); + if (isset($_GET[$t])){ + $theme = $_GET[$t]; + }elseif(cookie('think_template')){ + $theme = cookie('think_template'); + } + if(!in_array($theme,explode(',',C('THEME_LIST')))){ + $theme = C('DEFAULT_THEME'); + } + cookie('think_template',$theme,864000); + } + } + defined('THEME_NAME') || define('THEME_NAME', $theme); // 当前模板主题名称 + return $theme?$theme . '/':''; + } + +} \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Boris/Boris.php b/ThinkPHP/Library/Vendor/Boris/Boris.php new file mode 100644 index 0000000..e2319cd --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/Boris.php @@ -0,0 +1,174 @@ + ', $historyFile = null) { + $this->setPrompt($prompt); + $this->_historyFile = $historyFile + ? $historyFile + : sprintf('%s/.boris_history', getenv('HOME')) + ; + $this->_inspector = new ColoredInspector(); + } + + /** + * Add a new hook to run in the context of the REPL when it starts. + * + * @param mixed $hook + * + * The hook is either a string of PHP code to eval(), or a Closure accepting + * the EvalWorker object as its first argument and the array of defined + * local variables in the second argument. + * + * If the hook is a callback and needs to set any local variables in the + * REPL's scope, it should invoke $worker->setLocal($var_name, $value) to + * do so. + * + * Hooks are guaranteed to run in the order they were added and the state + * set by each hook is available to the next hook (either through global + * resources, such as classes and interfaces, or through the 2nd parameter + * of the callback, if any local variables were set. + * + * @example Contrived example where one hook sets the date and another + * prints it in the REPL. + * + * $boris->onStart(function($worker, $vars){ + * $worker->setLocal('date', date('Y-m-d')); + * }); + * + * $boris->onStart('echo "The date is $date\n";'); + */ + public function onStart($hook) { + $this->_startHooks[] = $hook; + } + + /** + * Add a new hook to run in the context of the REPL when a fatal error occurs. + * + * @param mixed $hook + * + * The hook is either a string of PHP code to eval(), or a Closure accepting + * the EvalWorker object as its first argument and the array of defined + * local variables in the second argument. + * + * If the hook is a callback and needs to set any local variables in the + * REPL's scope, it should invoke $worker->setLocal($var_name, $value) to + * do so. + * + * Hooks are guaranteed to run in the order they were added and the state + * set by each hook is available to the next hook (either through global + * resources, such as classes and interfaces, or through the 2nd parameter + * of the callback, if any local variables were set. + * + * @example An example if your project requires some database connection cleanup: + * + * $boris->onFailure(function($worker, $vars){ + * DB::reset(); + * }); + */ + public function onFailure($hook){ + $this->_failureHooks[] = $hook; + } + + /** + * Set a local variable, or many local variables. + * + * @example Setting a single variable + * $boris->setLocal('user', $bob); + * + * @example Setting many variables at once + * $boris->setLocal(array('user' => $bob, 'appContext' => $appContext)); + * + * This method can safely be invoked repeatedly. + * + * @param array|string $local + * @param mixed $value, optional + */ + public function setLocal($local, $value = null) { + if (!is_array($local)) { + $local = array($local => $value); + } + + $this->_exports = array_merge($this->_exports, $local); + } + + /** + * Sets the Boris prompt text + * + * @param string $prompt + */ + public function setPrompt($prompt) { + $this->_prompt = $prompt; + } + + /** + * Set an Inspector object for Boris to output return values with. + * + * @param object $inspector any object the responds to inspect($v) + */ + public function setInspector($inspector) { + $this->_inspector = $inspector; + } + + /** + * Start the REPL (display the readline prompt). + * + * This method never returns. + */ + public function start() { + declare(ticks = 1); + pcntl_signal(SIGINT, SIG_IGN, true); + + if (!$pipes = stream_socket_pair( + STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP)) { + throw new \RuntimeException('Failed to create socket pair'); + } + + $pid = pcntl_fork(); + + if ($pid > 0) { + if (function_exists('setproctitle')) { + setproctitle('boris (master)'); + } + + fclose($pipes[0]); + $client = new ReadlineClient($pipes[1]); + $client->start($this->_prompt, $this->_historyFile); + } elseif ($pid < 0) { + throw new \RuntimeException('Failed to fork child process'); + } else { + if (function_exists('setproctitle')) { + setproctitle('boris (worker)'); + } + + fclose($pipes[1]); + $worker = new EvalWorker($pipes[0]); + $worker->setLocal($this->_exports); + $worker->setStartHooks($this->_startHooks); + $worker->setFailureHooks($this->_failureHooks); + $worker->setInspector($this->_inspector); + $worker->start(); + } + } +} diff --git a/ThinkPHP/Library/Vendor/Boris/CLIOptionsHandler.php b/ThinkPHP/Library/Vendor/Boris/CLIOptionsHandler.php new file mode 100644 index 0000000..2aa3ab3 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/CLIOptionsHandler.php @@ -0,0 +1,85 @@ + $value) { + switch ($option) { + /* + * Sets files to load at startup, may be used multiple times, + * i.e: boris -r test.php,foo/bar.php -r ba/foo.php --require hey.php + */ + case 'r': + case 'require': + $this->_handleRequire($boris, $value); + break; + + /* + * Show Usage info + */ + case 'h': + case 'help': + $this->_handleUsageInfo(); + break; + + /* + * Show version + */ + case 'v': + case 'version': + $this->_handleVersion(); + break; + } + } + } + + // -- Private Methods + + private function _handleRequire($boris, $paths) { + $require = array_reduce( + (array) $paths, + function($acc, $v) { return array_merge($acc, explode(',', $v)); }, + array() + ); + + $boris->onStart(function($worker, $scope) use($require) { + foreach($require as $path) { + require $path; + } + + $worker->setLocal(get_defined_vars()); + }); + } + + private function _handleUsageInfo() { + echo << + * @author Chris Corbyn + * + * Copyright © 2013-2014 Rob Morris. + */ + +namespace Boris; + +/** + * Identifies data types in data structures and syntax highlights them. + */ +class ColoredInspector implements Inspector { + static $TERM_COLORS = array( + 'black' => "\033[0;30m", + 'white' => "\033[1;37m", + 'none' => "\033[1;30m", + 'dark_grey' => "\033[1;30m", + 'light_grey' => "\033[0;37m", + 'dark_red' => "\033[0;31m", + 'light_red' => "\033[1;31m", + 'dark_green' => "\033[0;32m", + 'light_green' => "\033[1;32m", + 'dark_yellow' => "\033[0;33m", + 'light_yellow' => "\033[1;33m", + 'dark_blue' => "\033[0;34m", + 'light_blue' => "\033[1;34m", + 'dark_purple' => "\033[0;35m", + 'light_purple' => "\033[1;35m", + 'dark_cyan' => "\033[0;36m", + 'light_cyan' => "\033[1;36m", + ); + + private $_fallback; + private $_colorMap = array(); + + /** + * Initialize a new ColoredInspector, using $colorMap. + * + * The colors should be an associative array with the keys: + * + * - 'integer' + * - 'float' + * - 'keyword' + * - 'string' + * - 'boolean' + * - 'default' + * + * And the values, one of the following colors: + * + * - 'none' + * - 'black' + * - 'white' + * - 'dark_grey' + * - 'light_grey' + * - 'dark_red' + * - 'light_red' + * - 'dark_green' + * - 'light_green' + * - 'dark_yellow' + * - 'light_yellow' + * - 'dark_blue' + * - 'light_blue' + * - 'dark_purple' + * - 'light_purple' + * - 'dark_cyan' + * - 'light_cyan' + * + * An empty $colorMap array effectively means 'none' for all types. + * + * @param array $colorMap + */ + public function __construct($colorMap = null) { + $this->_fallback = new DumpInspector(); + + if (isset($colorMap)) { + $this->_colorMap = $colorMap; + } else { + $this->_colorMap = $this->_defaultColorMap(); + } + } + + public function inspect($variable) { + return preg_replace( + '/^/m', + $this->_colorize('comment', '// '), + $this->_dump($variable) + ); + } + + /** + * Returns an associative array of an object's properties. + * + * This method is public so that subclasses may override it. + * + * @param object $value + * @return array + * */ + public function objectVars($value) { + return get_object_vars($value); + } + + // -- Private Methods + + public function _dump($value) { + $tests = array( + 'is_null' => '_dumpNull', + 'is_string' => '_dumpString', + 'is_bool' => '_dumpBoolean', + 'is_integer' => '_dumpInteger', + 'is_float' => '_dumpFloat', + 'is_array' => '_dumpArray', + 'is_object' => '_dumpObject' + ); + + foreach ($tests as $predicate => $outputMethod) { + if (call_user_func($predicate, $value)) + return call_user_func(array($this, $outputMethod), $value); + } + + return $this->_fallback->inspect($value); + } + + private function _dumpNull($value) { + return $this->_colorize('keyword', 'NULL'); + } + + private function _dumpString($value) { + return $this->_colorize('string', var_export($value, true)); + } + + private function _dumpBoolean($value) { + return $this->_colorize('bool', var_export($value, true)); + } + + private function _dumpInteger($value) { + return $this->_colorize('integer', var_export($value, true)); + } + + private function _dumpFloat($value) { + return $this->_colorize('float', var_export($value, true)); + } + + private function _dumpArray($value) { + return $this->_dumpStructure('array', $value); + } + + private function _dumpObject($value) { + return $this->_dumpStructure( + sprintf('object(%s)', get_class($value)), + $this->objectVars($value) + ); + } + + private function _dumpStructure($type, $value) { + return $this->_astToString($this->_buildAst($type, $value)); + } + + public function _buildAst($type, $value, $seen = array()) { + // FIXME: Improve this AST so it doesn't require access to dump() or colorize() + if ($this->_isSeen($value, $seen)) { + return $this->_colorize('default', '*** RECURSION ***'); + } else { + $nextSeen = array_merge($seen, array($value)); + } + + if (is_object($value)) { + $vars = $this->objectVars($value); + } else { + $vars = $value; + } + + $self = $this; + + return array( + 'name' => $this->_colorize('keyword', $type), + 'children' => empty($vars) ? array() : array_combine( + array_map(array($this, '_dump'), array_keys($vars)), + array_map( + function($v) use($self, $nextSeen) { + if (is_object($v)) { + return $self->_buildAst( + sprintf('object(%s)', get_class($v)), + $v, + $nextSeen + ); + } elseif (is_array($v)) { + return $self->_buildAst('array', $v, $nextSeen); + } else { + return $self->_dump($v); + } + }, + array_values($vars) + ) + ) + ); + } + + public function _astToString($node, $indent = 0) { + $children = $node['children']; + $self = $this; + + return implode( + "\n", + array( + sprintf('%s(', $node['name']), + implode( + ",\n", + array_map( + function($k) use($self, $children, $indent) { + if (is_array($children[$k])) { + return sprintf( + '%s%s => %s', + str_repeat(' ', ($indent + 1) * 2), + $k, + $self->_astToString($children[$k], $indent + 1) + ); + } else { + return sprintf( + '%s%s => %s', + str_repeat(' ', ($indent + 1) * 2), + $k, + $children[$k] + ); + } + }, + array_keys($children) + ) + ), + sprintf('%s)', str_repeat(' ', $indent * 2)) + ) + ); + } + + private function _defaultColorMap() { + return array( + 'integer' => 'light_green', + 'float' => 'light_yellow', + 'string' => 'light_red', + 'bool' => 'light_purple', + 'keyword' => 'light_cyan', + 'comment' => 'dark_grey', + 'default' => 'none' + ); + } + + private function _colorize($type, $value) { + if (!empty($this->_colorMap[$type])) { + $colorName = $this->_colorMap[$type]; + } else { + $colorName = $this->_colorMap['default']; + } + + return sprintf( + "%s%s\033[0m", + static::$TERM_COLORS[$colorName], + $value + ); + } + + private function _isSeen($value, $seen) { + foreach ($seen as $v) { + if ($v === $value) + return true; + } + + return false; + } +} diff --git a/ThinkPHP/Library/Vendor/Boris/Config.php b/ThinkPHP/Library/Vendor/Boris/Config.php new file mode 100644 index 0000000..f03d3b7 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/Config.php @@ -0,0 +1,85 @@ +_cascade = $cascade; + $this->_searchPaths = $searchPaths; + } + + /** + * Searches for configuration files in the available + * search paths, and applies them to the provided + * boris instance. + * + * Returns true if any configuration files were found. + * + * @param Boris\Boris $boris + * @return bool + */ + public function apply(Boris $boris) { + $applied = false; + + foreach($this->_searchPaths as $path) { + if (is_readable($path)) { + $this->_loadInIsolation($path, $boris); + + $applied = true; + $this->_files[] = $path; + + if (!$this->_cascade) { + break; + } + } + } + + return $applied; + } + + /** + * Returns an array of files that were loaded + * for this Config + * + * @return array + */ + public function loadedFiles() { + return $this->_files; + } + + // -- Private Methods + + private function _loadInIsolation($path, $boris) { + require $path; + } +} diff --git a/ThinkPHP/Library/Vendor/Boris/DumpInspector.php b/ThinkPHP/Library/Vendor/Boris/DumpInspector.php new file mode 100644 index 0000000..96ab38a --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/DumpInspector.php @@ -0,0 +1,16 @@ +_socket = $socket; + $this->_inspector = new DumpInspector(); + stream_set_blocking($socket, 0); + } + + /** + * Set local variables to be placed in the workers's scope. + * + * @param array|string $local + * @param mixed $value, if $local is a string + */ + public function setLocal($local, $value = null) { + if (!is_array($local)) { + $local = array($local => $value); + } + + $this->_exports = array_merge($this->_exports, $local); + } + + /** + * Set hooks to run inside the worker before it starts looping. + * + * @param array $hooks + */ + public function setStartHooks($hooks) { + $this->_startHooks = $hooks; + } + + /** + * Set hooks to run inside the worker after a fatal error is caught. + * + * @param array $hooks + */ + public function setFailureHooks($hooks) { + $this->_failureHooks = $hooks; + } + + /** + * Set an Inspector object for Boris to output return values with. + * + * @param object $inspector any object the responds to inspect($v) + */ + public function setInspector($inspector) { + $this->_inspector = $inspector; + } + + /** + * Start the worker. + * + * This method never returns. + */ + public function start() { + $__scope = $this->_runHooks($this->_startHooks); + extract($__scope); + + $this->_write($this->_socket, self::READY); + + /* Note the naming of the local variables due to shared scope with the user here */ + for (;;) { + declare(ticks = 1); + // don't exit on ctrl-c + pcntl_signal(SIGINT, SIG_IGN, true); + + $this->_cancelled = false; + + $__input = $this->_transform($this->_read($this->_socket)); + + if ($__input === null) { + continue; + } + + $__response = self::DONE; + + $this->_ppid = posix_getpid(); + $this->_pid = pcntl_fork(); + + if ($this->_pid < 0) { + throw new \RuntimeException('Failed to fork child labourer'); + } elseif ($this->_pid > 0) { + // kill the child on ctrl-c + pcntl_signal(SIGINT, array($this, 'cancelOperation'), true); + pcntl_waitpid($this->_pid, $__status); + + if (!$this->_cancelled && $__status != (self::ABNORMAL_EXIT << 8)) { + $__response = self::EXITED; + } else { + $this->_runHooks($this->_failureHooks); + $__response = self::FAILED; + } + } else { + // user exception handlers normally cause a clean exit, so Boris will exit too + if (!$this->_exceptionHandler = + set_exception_handler(array($this, 'delegateExceptionHandler'))) { + restore_exception_handler(); + } + + // undo ctrl-c signal handling ready for user code execution + pcntl_signal(SIGINT, SIG_DFL, true); + $__pid = posix_getpid(); + + $__result = eval($__input); + + if (posix_getpid() != $__pid) { + // whatever the user entered caused a forked child + // (totally valid, but we don't want that child to loop and wait for input) + exit(0); + } + + if (preg_match('/\s*return\b/i', $__input)) { + fwrite(STDOUT, sprintf("%s\n", $this->_inspector->inspect($__result))); + } + $this->_expungeOldWorker(); + } + + $this->_write($this->_socket, $__response); + + if ($__response == self::EXITED) { + exit(0); + } + } + } + + /** + * While a child process is running, terminate it immediately. + */ + public function cancelOperation() { + printf("Cancelling...\n"); + $this->_cancelled = true; + posix_kill($this->_pid, SIGKILL); + pcntl_signal_dispatch(); + } + + /** + * If any user-defined exception handler is present, call it, but be sure to exit correctly. + */ + public function delegateExceptionHandler($ex) { + call_user_func($this->_exceptionHandler, $ex); + exit(self::ABNORMAL_EXIT); + } + + // -- Private Methods + + private function _runHooks($hooks) { + extract($this->_exports); + + foreach ($hooks as $__hook) { + if (is_string($__hook)) { + eval($__hook); + } elseif (is_callable($__hook)) { + call_user_func($__hook, $this, get_defined_vars()); + } else { + throw new \RuntimeException( + sprintf( + 'Hooks must be closures or strings of PHP code. Got [%s].', + gettype($__hook) + ) + ); + } + + // hooks may set locals + extract($this->_exports); + } + + return get_defined_vars(); + } + + private function _expungeOldWorker() { + posix_kill($this->_ppid, SIGTERM); + pcntl_signal_dispatch(); + } + + private function _write($socket, $data) { + if (!fwrite($socket, $data)) { + throw new \RuntimeException('Socket error: failed to write data'); + } + } + + private function _read($socket) + { + $read = array($socket); + $except = array($socket); + + if ($this->_select($read, $except) > 0) { + if ($read) { + return stream_get_contents($read[0]); + } else if ($except) { + throw new \UnexpectedValueException("Socket error: closed"); + } + } + } + + private function _select(&$read, &$except) { + $write = null; + set_error_handler(function(){return true;}, E_WARNING); + $result = stream_select($read, $write, $except, 10); + restore_error_handler(); + return $result; + } + + private function _transform($input) { + if ($input === null) { + return null; + } + + $transforms = array( + 'exit' => 'exit(0)' + ); + + foreach ($transforms as $from => $to) { + $input = preg_replace('/^\s*' . preg_quote($from, '/') . '\s*;?\s*$/', $to . ';', $input); + } + + return $input; + } +} diff --git a/ThinkPHP/Library/Vendor/Boris/ExportInspector.php b/ThinkPHP/Library/Vendor/Boris/ExportInspector.php new file mode 100644 index 0000000..2ac226b --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/ExportInspector.php @@ -0,0 +1,14 @@ +_socket = $socket; + } + + /** + * Start the client with an prompt and readline history path. + * + * This method never returns. + * + * @param string $prompt + * @param string $historyFile + */ + public function start($prompt, $historyFile) { + readline_read_history($historyFile); + + declare(ticks = 1); + pcntl_signal(SIGCHLD, SIG_IGN); + pcntl_signal(SIGINT, array($this, 'clear'), true); + + // wait for the worker to finish executing hooks + if (fread($this->_socket, 1) != EvalWorker::READY) { + throw new \RuntimeException('EvalWorker failed to start'); + } + + $parser = new ShallowParser(); + $buf = ''; + $lineno = 1; + + for (;;) { + $this->_clear = false; + $line = readline( + sprintf( + '[%d] %s', + $lineno, + ($buf == '' + ? $prompt + : str_pad('*> ', strlen($prompt), ' ', STR_PAD_LEFT)) + ) + ); + + if ($this->_clear) { + $buf = ''; + continue; + } + + if (false === $line) { + $buf = 'exit(0);'; // ctrl-d acts like exit + } + + if (strlen($line) > 0) { + readline_add_history($line); + } + + $buf .= sprintf("%s\n", $line); + + if ($statements = $parser->statements($buf)) { + ++$lineno; + + $buf = ''; + foreach ($statements as $stmt) { + if (false === $written = fwrite($this->_socket, $stmt)) { + throw new \RuntimeException('Socket error: failed to write data'); + } + + if ($written > 0) { + $status = fread($this->_socket, 1); + if ($status == EvalWorker::EXITED) { + readline_write_history($historyFile); + echo "\n"; + exit(0); + } elseif ($status == EvalWorker::FAILED) { + break; + } + } + } + } + } + } + + /** + * Clear the input buffer. + */ + public function clear() { + // FIXME: I'd love to have this send \r to readline so it puts the user on a blank line + $this->_clear = true; + } +} diff --git a/ThinkPHP/Library/Vendor/Boris/ShallowParser.php b/ThinkPHP/Library/Vendor/Boris/ShallowParser.php new file mode 100644 index 0000000..624724b --- /dev/null +++ b/ThinkPHP/Library/Vendor/Boris/ShallowParser.php @@ -0,0 +1,233 @@ + ')', + '{' => '}', + '[' => ']', + '"' => '"', + "'" => "'", + '//' => "\n", + '#' => "\n", + '/*' => '*/', + '<<<' => '_heredoc_special_case_' + ); + + private $_initials; + + public function __construct() { + $this->_initials = '/^(' . implode('|', array_map(array($this, 'quote'), array_keys($this->_pairs))) . ')/'; + } + + /** + * Break the $buffer into chunks, with one for each highest-level construct possible. + * + * If the buffer is incomplete, returns an empty array. + * + * @param string $buffer + * + * @return array + */ + public function statements($buffer) { + $result = $this->_createResult($buffer); + + while (strlen($result->buffer) > 0) { + $this->_resetResult($result); + + if ($result->state == '<<<') { + if (!$this->_initializeHeredoc($result)) { + continue; + } + } + + $rules = array('_scanEscapedChar', '_scanRegion', '_scanStateEntrant', '_scanWsp', '_scanChar'); + + foreach ($rules as $method) { + if ($this->$method($result)) { + break; + } + } + + if ($result->stop) { + break; + } + } + + if (!empty($result->statements) && trim($result->stmt) === '' && strlen($result->buffer) == 0) { + $this->_combineStatements($result); + $this->_prepareForDebug($result); + return $result->statements; + } + } + + public function quote($token) { + return preg_quote($token, '/'); + } + + // -- Private Methods + + private function _createResult($buffer) { + $result = new \stdClass(); + $result->buffer = $buffer; + $result->stmt = ''; + $result->state = null; + $result->states = array(); + $result->statements = array(); + $result->stop = false; + + return $result; + } + + private function _resetResult($result) { + $result->stop = false; + $result->state = end($result->states); + $result->terminator = $result->state + ? '/^(.*?' . preg_quote($this->_pairs[$result->state], '/') . ')/s' + : null + ; + } + + private function _combineStatements($result) { + $combined = array(); + + foreach ($result->statements as $scope) { + if (trim($scope) == ';' || substr(trim($scope), -1) != ';') { + $combined[] = ((string) array_pop($combined)) . $scope; + } else { + $combined[] = $scope; + } + } + + $result->statements = $combined; + } + + private function _prepareForDebug($result) { + $result->statements []= $this->_prepareDebugStmt(array_pop($result->statements)); + } + + private function _initializeHeredoc($result) { + if (preg_match('/^([\'"]?)([a-z_][a-z0-9_]*)\\1/i', $result->buffer, $match)) { + $docId = $match[2]; + $result->stmt .= $match[0]; + $result->buffer = substr($result->buffer, strlen($match[0])); + + $result->terminator = '/^(.*?\n' . $docId . ');?\n/s'; + + return true; + } else { + return false; + } + } + + private function _scanWsp($result) { + if (preg_match('/^\s+/', $result->buffer, $match)) { + if (!empty($result->statements) && $result->stmt === '') { + $result->statements[] = array_pop($result->statements) . $match[0]; + } else { + $result->stmt .= $match[0]; + } + $result->buffer = substr($result->buffer, strlen($match[0])); + + return true; + } else { + return false; + } + } + + private function _scanEscapedChar($result) { + if (($result->state == '"' || $result->state == "'") + && preg_match('/^[^' . $result->state . ']*?\\\\./s', $result->buffer, $match)) { + + $result->stmt .= $match[0]; + $result->buffer = substr($result->buffer, strlen($match[0])); + + return true; + } else { + return false; + } + } + + private function _scanRegion($result) { + if (in_array($result->state, array('"', "'", '<<<', '//', '#', '/*'))) { + if (preg_match($result->terminator, $result->buffer, $match)) { + $result->stmt .= $match[1]; + $result->buffer = substr($result->buffer, strlen($match[1])); + array_pop($result->states); + } else { + $result->stop = true; + } + + return true; + } else { + return false; + } + } + + private function _scanStateEntrant($result) { + if (preg_match($this->_initials, $result->buffer, $match)) { + $result->stmt .= $match[0]; + $result->buffer = substr($result->buffer, strlen($match[0])); + $result->states[] = $match[0]; + + return true; + } else { + return false; + } + } + + private function _scanChar($result) { + $chr = substr($result->buffer, 0, 1); + $result->stmt .= $chr; + $result->buffer = substr($result->buffer, 1); + if ($result->state && $chr == $this->_pairs[$result->state]) { + array_pop($result->states); + } + + if (empty($result->states) && ($chr == ';' || $chr == '}')) { + if (!$this->_isLambda($result->stmt) || $chr == ';') { + $result->statements[] = $result->stmt; + $result->stmt = ''; + } + } + + return true; + } + + private function _isLambda($input) { + return preg_match( + '/^([^=]*?=\s*)?function\s*\([^\)]*\)\s*(use\s*\([^\)]*\)\s*)?\s*\{.*\}\s*;?$/is', + trim($input) + ); + } + + private function _isReturnable($input) { + $input = trim($input); + if (substr($input, -1) == ';' && substr($input, 0, 1) != '{') { + return $this->_isLambda($input) || !preg_match( + '/^(' . + 'echo|print|exit|die|goto|global|include|include_once|require|require_once|list|' . + 'return|do|for|foreach|while|if|function|namespace|class|interface|abstract|switch|' . + 'declare|throw|try|unset' . + ')\b/i', + $input + ); + } else { + return false; + } + } + + private function _prepareDebugStmt($input) { + if ($this->_isReturnable($input) && !preg_match('/^\s*return/i', $input)) { + $input = sprintf('return %s', $input); + } + + return $input; + } +} diff --git a/ThinkPHP/Library/Vendor/EaseTemplate/template.core.php b/ThinkPHP/Library/Vendor/EaseTemplate/template.core.php new file mode 100644 index 0000000..630c38d --- /dev/null +++ b/ThinkPHP/Library/Vendor/EaseTemplate/template.core.php @@ -0,0 +1,970 @@ +Power by Ease Template!');}"; + var $Compile = array(); + var $Analysis = array(); + var $Emc = array(); + + /** + * 声明模板用法 + */ + function ETCoreStart( + $set = array( + 'ID' =>'1', //缓存ID + 'TplType' =>'htm', //模板格式 + 'CacheDir' =>'cache', //缓存目录 + 'TemplateDir'=>'template' , //模板存放目录 + 'AutoImage' =>'on' , //自动解析图片目录开关 on表示开放 off表示关闭 + 'LangDir' =>'language' , //语言文件存放的目录 + 'Language' =>'default' , //语言的默认文件 + 'Copyright' =>'off' , //版权保护 + 'MemCache' =>'' , //Memcache服务器地址例如:127.0.0.1:11211 + ) + ){ + + $this->TplID = (defined('TemplateID')?TemplateID:( ((int)@$set['ID']<=1)?1:(int)$set['ID']) ).'_'; + + $this->CacheDir = (defined('NewCache')?NewCache:( (trim($set['CacheDir']) != '')?$set['CacheDir']:'cache') ).'/'; + + $this->TemplateDir = (defined('NewTemplate')?NewTemplate:( (trim($set['TemplateDir']) != '')?$set['TemplateDir']:'template') ).'/'; + + $this->Ext = (@$set['TplType'] != '')?$set['TplType']:'htm'; + + $this->AutoImage = (@$set['AutoImage']=='off')?0:1; + + $this->Copyright = (@$set['Copyright']=='off')?0:1; + + $this->Server = (is_array($GLOBALS['_SERVER']))?$GLOBALS['_SERVER']:$_SERVER; + $this->version = (trim($_GET['EaseTemplateVer']))?die('Ease Templae E3!'):''; + + //载入语言文件 + $this->LangDir = (defined('LangDir')?LangDir:( ((@$set['LangDir']!='language' && @$set['LangDir'])?$set['LangDir']:'language') )).'/'; + if(is_dir($this->LangDir)){ + $this->Language = (defined('Language')?Language:( (($set['Language']!='default' && $set['Language'])?$set['Language']:'default') )); + if(@is_file($this->LangDir.$this->Language.'.php')){ + $lang = array(); + @include_once $this->LangDir.$this->Language.'.php'; + $this->LangData = $lang; + } + }else{ + $this->Language = 'default'; + } + + + //缓存目录检测以及运行模式 + if(@ereg(':',$set['MemCache'])){ + $this->RunType = 'MemCache'; + $memset = explode(":",$set['MemCache']); + $this->Emc = memcache_connect($memset[0], $memset[1]) OR die("Could not connect!"); + }else{ + $this->RunType = (@substr(@sprintf('%o', @fileperms($this->CacheDir)), -3)==777 && is_dir($this->CacheDir))?'Cache':'Replace'; + } + + $CompileBasic = array( + '/(\{\s*|)/eis', + + '//is', + '//is', + '//is', + '//is', + '//is', + '//', + '//is', + + '/(\{\s*|)/eis', + '/(\{\s*|)/eis', + '/(\{\s*|)/eis', + '/(\{\s*|)/eis', + '/(\{\s*|)\s*(.+?)\s*(\{|)/is', + '/(\{\s*|)/is', + '/\{([a-zA-Z0-9_\'\"\[\]\$]{1,100})\}/', + ); + $this->Compile = (is_array($this->Compile))?array_merge($this->Compile,$CompileBasic):$CompileBasic; + + $AnalysisBasic = array( + '$this->inc_php("\\2")', + + '";if($ET_Del==true){echo"', + '";if(\\2){echo"', + '";}elseif(\\2){echo"', + '";}else{echo"', + '";}echo"', + '";\$_i=0;foreach((array)\\1 AS \\3){\$_i++;echo"', + '";\$_i=0;while(\\1){\$_i++;echo"', + + '$this->lang("\\2")', + '$this->Row("\\2")', + '$this->Color("\\2")', + '$this->Dirs("\\2")', + '";\\3;echo"', + '";\\2;echo"', + '";echo \$\\1;echo"', + ); + $this->Analysis = (is_array($this->Analysis))?array_merge($this->Analysis,$AnalysisBasic):$AnalysisBasic; + + } + + + /** + * 设置数值 + * set_var(变量名或是数组,设置数值[数组不设置此值]); + */ + function set_var( + $name, + $value = '' + ){ + if (is_array($name)){ + $this->ThisValue = @array_merge($this->ThisValue,$name); + }else{ + $this->ThisValue[$name] = $value; + } + } + + + /** + * 设置模板文件 + * set_file(文件名,设置目录); + */ + function set_file( + $FileName, + $NewDir = '' + ){ + //当前模板名 + $this->ThisFile = $FileName.'.'.$this->Ext; + + //目录地址检测 + $this->FileDir[$this->ThisFile] = (trim($NewDir) != '')?$NewDir.'/':$this->TemplateDir; + + $this->IncFile[$FileName] = $this->FileDir[$this->ThisFile].$this->ThisFile; + + if(!is_file($this->IncFile[$FileName]) && $this->Copyright==1){ + die('Sorry, The file '.$this->IncFile[$FileName].' does not exist.'); + } + + + //bug 系统 + $this->IncList[] = $this->ThisFile; + } + + //解析替换程序 + function ParseCode( + $FileList = '', + $CacheFile = '' + ){ + //模板数据 + $ShowTPL = ''; + //解析续载 + if (@is_array($FileList) && $FileList!='include_page'){ + foreach ($FileList AS $K=>$V) { + $ShowTPL .= $this->reader($V.$K); + } + }else{ + + + //如果指定文件地址则载入 + $SourceFile = ($FileList!='')?$FileList:$this->FileDir[$this->ThisFile].$this->ThisFile; + + if(!is_file($SourceFile) && $this->Copyright==1){ + die('Sorry, The file '.$SourceFile.' does not exist.'); + } + + $ShowTPL = $this->reader($SourceFile); + } + + //引用模板处理 + $ShowTPL = $this->inc_preg($ShowTPL); + + //检测run方法 + $run = 0; + if (eregi("run:",$ShowTPL)){ + $run = 1; + //Fix = + $ShowTPL = preg_replace('/(\{|)\s*=/','{run:}echo ',$ShowTPL); + $ShowTPL = preg_replace('/(\{|)\s*(.+?)\s*(\{|)/is', '(T_T)\\3;(T_T!)',$ShowTPL); + } + + //Fix XML + if (eregi("/is', '\\1', $ShowTPL); + } + + //修复代码中\n换行错误 + $ShowTPL = str_replace('\\','\\\\',$ShowTPL); + //修复双引号问题 + $ShowTPL = str_replace('"','\"',$ShowTPL); + + //编译运算 + $ShowTPL = @preg_replace($this->Compile, $this->Analysis, $ShowTPL); + + //分析图片地址 + $ShowTPL = $this->ImgCheck($ShowTPL); + + //Fix 模板中金钱符号 + $ShowTPL = str_replace('$','\$',$ShowTPL); + + //修复php运行错误 + $ShowTPL = @preg_replace("/\";(.+?)echo\"/e", '$this->FixPHP(\'\\1\')', $ShowTPL); + + //Fix Run 2 + if ($run==1){ + $ShowTPL = preg_replace("/\(T_T\)(.+?)\(T_T!\)/ise", '$this->FixPHP(\'\\1\')', $ShowTPL); + } + + //还原xml + $ShowTPL = (strrpos($ShowTPL,''))?@preg_replace('/ET>(.+?)<\/ET/is', '?\\1?', $ShowTPL):$ShowTPL; + + //修复"问题 + $ShowTPL = str_replace('echo ""','echo "\"',$ShowTPL); + + + //从数组中将变量导入到当前的符号表 + @extract($this->Value()); + ob_start(); + ob_implicit_flush(0); + @eval('echo "'.$ShowTPL.'";'); + $contents = ob_get_contents(); + ob_end_clean(); + + //Cache htm + if($this->HtmID){ + $this->writer($this->HtmDir.$this->HtmID,$this->Hacker."?>".$contents); + } + + + //编译模板 + if ($this->RunType=='Cache'){ + $this->CompilePHP($ShowTPL,$CacheFile); + } + + + //错误检查 + if(strlen($contents)<=0){ + //echo $ShowTPL; + die('
    Sorry, Error or complicated syntax error exists in '.$SourceFile.' file.'); + } + + return $contents; + } + + + /** + * 多语言 + */ + function lang( + $str = '' + ){ + if (is_dir($this->LangDir)){ + + //采用MD5效验 + $id = md5($str); + + //不存在数据则写入 + if($this->LangData[$id]=='' && $this->Language=='default'){ + + //语言包文件 + if (@is_file($this->LangDir.$this->Language.'.php')){ + unset($lang); + @include($this->LangDir.$this->Language.'.php'); + } + + + //如果检测到有数据则输出 + if ($lang[$id]){ + $out = str_replace('\\','\\\\',$lang[$id]); + return str_replace('"','\"',$out); + } + + + //修复'多\问题 + $str = str_replace("\\'","'",$str); + + + //语言文件过大时采取建立新文件 + if(strlen($docs)>400){ + $this->writer($this->LangDir.$this->Language.'.'.$id.'.php',''); + $docs= substr($str,0,40); //简要说明 + $docs = str_replace('\"','"',$docs); + $docs = str_replace('\\\\','\\',$docs); + $str = 'o(O_O)o.ET Lang.o(*_*)o'; //语言新文件 + }else{ + $docs = str_replace('\"','"',$str); + $docs = str_replace('\\\\','\\',$docs); + } + + //文件安全处理 + $data = (!is_file($this->LangDir.'default.php'))?"Language."\n*/\n\n\n":''; + + + if (trim($str)){ + //写入数据 + $data .= "/**".date("Y.m.d",time())."\n"; + $data.= $docs."\n"; + $data.= "*/\n"; + $data.= '$lang["'.$id.'"] = "'.$str.'";'."\n\n"; + $this->writer($this->LangDir.'default.php',$data,'a+'); + } + } + + //单独语言文件包 + if($this->LangData[$id]=='o(O_O)o.ET Lang.o(*_*)o'){ + unset($etl); + include($this->LangDir.$this->Language.".".$id.".php"); + $this->LangData[$id] = $etl; + } + + $out = ($this->LangData[$id])?$this->LangData[$id]:$str; + + //输出部分要做处理 + if(($this->RunType=='Replace' || $this->RunType!='Replace') && $data==''){ + $out = str_replace('\\','\\\\',$out); + $out = str_replace('"','\"',$out); + } + + return $out; + }else{ + return $str; + } + } + + /** + * inc引用函数 + */ + function inc_preg( + $content + ){ + return preg_replace('/<\!--\s*\#include\s*file\s*=(\"|\')([a-zA-Z0-9_\.\|]{1,100})(\"|\')\s*-->/eis', '$this->inc("\\2")', preg_replace('/(\{\s*|)/eis', '$this->inc("\\2")', $content)); + } + + + /** + * 引用函数运算 + */ + function inc( + $Files = '' + ){ + if($Files){ + if (!strrpos($Files,$this->Ext)){ + $Files = $Files.".".$this->Ext; + } + $FileLs = $this->TemplateDir.$Files; + $contents =$this->ParseCode($FileLs,$Files); + + if($this->RunType=='Cache'){ + //引用模板 + $this->IncList[] = $Files; + $cache_file = $this->CacheDir.$this->TplID.$Files.".".$this->Language.".php"; + return " +{inc_php:".$cache_file."} +{run:@eval('echo \"'.\$EaseTemplate3_Cache.'\";')} +"; + }elseif($this->RunType=='MemCache'){ + //cache date + memcache_set($this->Emc,$Files.'_date', time()) OR die("Failed to save data at the server."); + memcache_set($this->Emc,$Files, $contents) OR die("Failed to save data at the server"); + return "".$contents; + }else{ + //引用模板 + $this->IncList[] = $Files; + return $contents; + } + } + } + + + /** + * 编译解析处理 + */ + function CompilePHP( + $content='', + $cachename = '' + ){ + if ($content){ + //如果没有安全文件则自动创建 + if($this->RunType=='Cache' && !is_file($this->CacheDir.'index.htm')){ + $Ease_name = 'Ease Template!'; + $Ease_base = "$Ease_name
    $Ease_name"; + $this->writer($this->CacheDir.'index.htm',$Ease_base); + $this->writer($this->CacheDir.'index.html',$Ease_base); + $this->writer($this->CacheDir.'default.htm',$Ease_base); + } + + + //编译记录 + $content = str_replace("\\","\\\\",$content); + $content = str_replace("'","\'",$content); + $content = str_replace('echo"";',"",$content); //替换多余数据 + + $wfile = ($cachename)?$cachename:$this->ThisFile; + $this->writer($this->FileName($wfile,$this->TplID) ,$this->Hacker.'$EaseTemplate3_Cache = \''.$content.'\';'); + } + } + + + //修复PHP执行时产生的错误 + function FixPHP( + $content='' + ){ + $content = str_replace('\\\\','\\',$content); + return '";'.str_replace('\\"','"',str_replace('\$','$',$content)).'echo"'; + } + + + /** + * 检测缓存是否要更新 + * filename 缓存文件名 + * settime 指定事件则提供更新,只用于memcache + */ + function FileUpdate($filname,$settime=0){ + + //检测设置模板文件 + if (is_array($this->IncFile)){ + unset($k,$v); + $update = 0; + $settime = ($settime>0)?$settime:@filemtime($filname); + foreach ($this->IncFile AS $k=>$v) { + if (@filemtime($v)>$settime){$update = 1;} + } + //更新缓存 + if($update==1){ + return false; + }else { + return $filname; + } + + }else{ + return $filname; + } + } + + + /** + * 输出运算 + * Filename 连载编译输出文件名 + */ + function output( + $Filename = '' + ){ + switch($this->RunType){ + + //Mem编译模式 + case'MemCache': + if ($Filename=='include_page'){ + //直接输出文件 + return $this->reader($this->FileDir[$this->ThisFile].$this->ThisFile); + }else{ + + $FileNames = ($Filename)?$Filename:$this->ThisFile; + $CacheFile = $this->FileName($FileNames,$this->TplID); + + //检测记录时间 + $updateT = memcache_get($this->Emc,$CacheFile.'_date'); + $update = $this->FileUpdate($CacheFile,$updateT); + + $CacheData = memcache_get($this->Emc,$CacheFile); + + if(trim($CacheData) && $update){ + //获得列表文件 + unset($ks,$vs); + preg_match_all('/<\!-- ET\_inc\_cache\[(.+?)\] -->/',$CacheData, $IncFile); + if (is_array($IncFile[1])){ + foreach ($IncFile[1] AS $ks=>$vs) { + $this->IncList[] = $vs; + $listDate = memcache_get($this->Emc,$vs.'_date'); + + echo @filemtime($this->TemplateDir.$vs).' - '.$listDate.'
    '; + + //更新inc缓存 + if (@filemtime($this->TemplateDir.$vs)>$listDate){ + $update = 1; + $this->inc($vs); + } + } + + //更新数据 + if ($update == 1){ + $CacheData = $this->ParseCode($this->FileList,$Filename); + //cache date + @memcache_set($this->Emc,$CacheFile.'_date', time()) OR die("Failed to save data at the server."); + @memcache_set($this->Emc,$CacheFile, $CacheData) OR die("Failed to save data at the server."); + } + } + //Close + memcache_close($this->Emc); + return $CacheData; + }else{ + if ($Filename){ + $CacheData = $this->ParseCode($this->FileList,$Filename); + //cache date + @memcache_set($this->Emc,$CacheFile.'_date', time()) OR die("Failed to save data at the server."); + @memcache_set($this->Emc,$CacheFile, $CacheData) OR die("Failed to save data at the server."); + //Close + memcache_close($this->Emc); + return $CacheData; + }else{ + $CacheData = $this->ParseCode(); + //cache date + @memcache_set($this->Emc,$CacheFile.'_date', time()) OR die("Failed to save data at the server."); + @memcache_set($this->Emc,$CacheFile, $CacheData) OR die("Failed to save data at the server2"); + //Close + memcache_close($this->Emc); + return $CacheData; + } + } + } + break; + + + //编译模式 + case'Cache': + if ($Filename=='include_page'){ + //直接输出文件 + return $this->reader($this->FileDir[$this->ThisFile].$this->ThisFile); + }else{ + + $FileNames = ($Filename)?$Filename:$this->ThisFile; + $CacheFile = $this->FileName($FileNames,$this->TplID); + + $CacheFile = $this->FileUpdate($CacheFile); + + if (@is_file($CacheFile)){ + @extract($this->Value()); + ob_start(); + ob_implicit_flush(0); + include $CacheFile; + + //获得列表文件 + if($EaseTemplate3_Cache!=''){ + unset($ks,$vs); + preg_match_all('/<\!-- ET\_inc\_cache\[(.+?)\] -->/',$EaseTemplate3_Cache, $IncFile); + + if (is_array($IncFile[1])){ + foreach ($IncFile[1] AS $ks=>$vs) { + $this->IncList[] = $vs; + //更新inc缓存 + if (@filemtime($this->TemplateDir.$vs)>@filemtime($this->CacheDir.$this->TplID.$vs.'.'.$this->Language.'.php')){ + $this->inc($vs); + } + } + } + + @eval('echo "'.$EaseTemplate3_Cache.'";'); + $contents = ob_get_contents(); + ob_end_clean(); + return $contents; + } + }else{ + if ($Filename){ + return $this->ParseCode($this->FileList,$Filename); + }else{ + return $this->ParseCode(); + } + } + } + break; + + + //替换引擎 + default: + if($Filename){ + if ($Filename=='include_page'){ + //直接输出文件 + return $this->reader($this->FileDir[$this->ThisFile].$this->ThisFile); + }else { + return $this->ParseCode($this->FileList); + } + }else{ + return $this->ParseCode(); + } + } + } + + + /** + * 连载函数 + */ + function n(){ + //连载模板 + $this->FileList[$this->ThisFile] = $this->FileDir[$this->ThisFile]; + } + + + /** + * 输出模板内容 + * Filename 连载编译输出文件名 + */ + function r( + $Filename = '' + ){ + return $this->output($Filename); + } + + + /** + * 打印模板内容 + * Filename 连载编译输出文件名 + */ + function p( + $Filename = '' + ){ + echo $this->output($Filename); + } + + + /** + * 分析图片地址 + */ + function ImgCheck( + $content + ){ + //Check Image Dir + if($this->AutoImage==1){ + $NewFileDir = $this->FileDir[$this->ThisFile]; + + //FIX img + if(is_array($this->ImgDir)){ + foreach($this->ImgDir AS $rep){ + $rep = trim($rep); + //检测是否执行替换 + if(strrpos($content,$rep."/")){ + if(substr($rep,-1)=='/'){ + $rep = substr($rep,0,strlen($rep)-1); + } + $content = str_replace($rep.'/',$NewFileDir.$rep.'/',$content); + } + } + } + + //FIX Dir + $NewFileDirs = $NewFileDir.$NewFileDir; + if(strrpos($content,$NewFileDirs)){ + $content = str_replace($NewFileDirs,$NewFileDir,$content); + } + } + return $content; + } + + + /** + * 获得所有设置与公共变量 + */ + function Value(){ + return (is_array($this->ThisValue))?array_merge($this->ThisValue,$GLOBALS):$GLOBALS; + } + + + /** + * 清除设置 + */ + function clear(){ + $this->RunType = 'Replace'; + } + + + /** + * 静态文件写入 + */ + function htm_w( + $w_dir = '', + $w_filename = '', + $w_content = '' + ){ + + $dvs = ''; + if($w_dir && $w_filename && $w_content){ + //目录检测数量 + $w_dir_ex = explode('/',$w_dir); + $w_new_dir = ''; //处理后的写入目录 + unset($dvs,$fdk,$fdv,$w_dir_len); + foreach((array)$w_dir_ex AS $dvs){ + if(trim($dvs) && $dvs!='..'){ + $w_dir_len .= '../'; + $w_new_dir .= $dvs.'/'; + if (!@is_dir($w_new_dir)) @mkdir($w_new_dir, 0777); + } + } + + + //获得需要更改的目录数 + foreach((array)$this->FileDir AS $fdk=>$fdv){ + $w_content = str_replace($fdv,$w_dir_len.str_replace('../','',$fdv),$w_content); + } + + $this->writer($w_dir.$w_filename,$w_content); + } + } + + + /** + * 改变静态刷新时间 + */ + function htm_time($times=0){ + if((int)$times>0){ + $this->HtmTime = (int)$times; + } + } + + + /** + * 静态文件存放的绝对目录 + */ + function htm_dir($Name = ''){ + if(trim($Name)){ + $this->HtmDir = trim($Name).'/'; + } + } + + + /** + * 产生静态文件输出 + */ + function HtmCheck( + $Name = '' + ){ + $this->HtmID = md5(trim($Name)? trim($Name).'.php' : $this->Server['REQUEST_URI'].'.php' ); + //检测时间 + if(is_file($this->HtmDir.$this->HtmID) && (time() - @filemtime($this->HtmDir.$this->HtmID)<=$this->HtmTime)){ + ob_start(); + ob_implicit_flush(0); + include $this->HtmDir.$this->HtmID; + $HtmContent = ob_get_contents(); + ob_end_clean(); + return $HtmContent; + } + } + + + /** + * 打印静态内容 + */ + function htm_p( + $Name = '' + ){ + $output = $this->HtmCheck($Name); + if ($output){ + die($this->HtmCheck($Name)); + } + } + + + /** + * 输出静态内容 + */ + function htm_r( + $Name = '' + ){ + return $this->HtmCheck($Name); + } + + + + + + /** + * 解析文件 + */ + function FileName( + $name, + $id = '1' + ){ + $extdir = explode("/",$name); + $dircnt = @count($extdir) - 1; + $extdir[$dircnt] = $id.$extdir[$dircnt]; + + return $this->CacheDir.implode("_",$extdir).".".$this->Language.'.php'; + } + + + /** + * 检测引入文件 + */ + function inc_php( + $url = '' + ){ + $parse = parse_url($url); + unset($vals,$code_array); + foreach((array)explode('&',$parse['query']) AS $vals){ + $code_array .= preg_replace('/(.+)=(.+)/',"\$_GET['\\1']= \$\\1 ='\\2';",$vals); + } + return '";'.$code_array.' @include(\''.$parse['path'].'\');echo"'; + } + + + /** + * 换行函数 + * Row(换行数,换行颜色); + * Row("5,#ffffff:#e1e1e1"); + */ + function Row( + $Num = '' + ){ + $Num = trim($Num); + if($Num != ''){ + $Nums = explode(",",$Num); + $Numr = ((int)$Nums[0]>0)?(int)$Nums[0]:2; + $input = (trim($Nums[1]) == '')?'':$Nums[1]; + + if(trim($Nums[1]) != ''){ + $Co = explode(":",$Nums[1]); + $OutStr = "if(\$_i%$Numr===0){\$row_count++;echo(\$row_count%2===0)?'':'';}"; + }else{ + $OutStr = "if(\$_i%$Numr===0){echo '$input';}"; + } + return '";'.$OutStr.'echo "'; + } + } + + + /** + * 间隔变色 + * Color(两组颜色代码); + * Color('#FFFFFF,#DCDCDC'); + */ + function Color( + $color = '' + ){ + if($color != ''){ + $OutStr = preg_replace("/(.+),(.+)/","_i%2===0)?'\\1':'\\2';",$color); + if(strrpos($OutStr,"%2")){ + return '";echo(\$'.$OutStr.'echo "'; + } + } + } + + + /** + * 映射图片地址 + */ + function Dirs( + $adds = '' + ){ + $adds_ary = explode(",",$adds); + if(is_array($adds_ary)){ + $this->ImgDir = (is_array($this->ImgDir))?@array_merge($adds_ary, $this->ImgDir):$adds_ary; + } + } + + + /** + * 读取函数 + * reader(文件名); + */ + function reader( + $filename + ){ + $get_fun = @get_defined_functions(); + return (in_array('file_get_contents',$get_fun['internal']))?@file_get_contents($filename):@implode("", @file($filename)); + } + + + /** + * 写入函数 + * writer(文件名,写入数据, 写入数据方式); + */ + function writer( + $filename, + $data = '', + $mode='w' + ){ + if(trim($filename)){ + $file = @fopen($filename, $mode); + $filedata = @fwrite($file, $data); + @fclose($file); + } + if(!is_file($filename)){ + die('Sorry,'.$filename.' file write in failed!'); + } + } + + + /** + * 引入模板系统 + * 察看当前使用的模板以及调试信息 + */ + function inc_list(){ + if(is_array($this->IncList)){ + $EXTS = explode("/",$this->Server['REQUEST_URI']); + $Last = count($EXTS) -1; + //处理清除工作 START + if(strrpos($EXTS[$Last],'Ease_Templatepage=Clear') && trim($EXTS[$Last]) != ''){ + $dir_name = $this->CacheDir; + if(file_exists($dir_name)){ + $handle=@opendir($dir_name); + while($tmp_file=@readdir($handle)){ + if(@file_exists($dir_name.$tmp_file)){ + @unlink($dir_name.$tmp_file); + } + } + @closedir($handle); + } + $GoURL = urldecode(preg_replace("/.+?REFERER=(.+?)!!!/","\\1",$EXTS[$Last])); + + die(''); + } + //处理清除工作 END + + $list_file = array(); + $file_nums = count($this->IncList); + $AllSize = 0; + foreach($this->IncList AS $Ks=>$Vs){ + $FSize[$Ks] = @filesize($this->TemplateDir.$Vs); + $AllSize += $FSize[$Ks]; + } + + foreach($this->IncList AS $K=>$V){ + $File_Size = @round($FSize[$K] / 1024 * 100) / 100 . 'KB'; + $Fwidth = @floor(100*$FSize[$K]/$AllSize); + $list_file[] = "".$this->TemplateDir.$V." + ".$File_Size." +
    "; + } + + //连接地址 + $BackURL = preg_replace("/.+\//","\\1",$this->Server['REQUEST_URI']); + $NowPAGE = 'http://'.$this->Server['HTTP_HOST'].$this->Server['SCRIPT_NAME']; + $clear_link = $NowPAGE."?Ease_Templatepage=Clear&REFERER=".urlencode($BackURL)."!!!"; + $sf13 = ' style="font-size:13px;color:#666666"'; + echo '
    + +'.implode("",$list_file)."
    Include Templates (Num:'.count($this-> IncList).')'; + +if($this->RunType=='Cache'){ + echo '[Clear Cache]'; +} + +echo '
    +Cache File ID: '.substr($this->TplID,0,-1).' +Index: '.((count($this->FileList)==0)?'False':'True').' +Format: '.$this->Ext.' +Cache: '.($this->RunType=='MemCache'?'Memcache Engine':($this->RunType == 'Replace'?'Replace Engine':$this->CacheDir)).' +Template: '.$this->TemplateDir.' +
    "; + } + } + +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/EaseTemplate/template.ease.php b/ThinkPHP/Library/Vendor/EaseTemplate/template.ease.php new file mode 100644 index 0000000..9366b29 --- /dev/null +++ b/ThinkPHP/Library/Vendor/EaseTemplate/template.ease.php @@ -0,0 +1,42 @@ +'1', //缓存ID + 'TplType' =>'htm', //模板格式 + 'CacheDir' =>'cache', //缓存目录 + 'TemplateDir'=>'template' , //模板存放目录 + 'AutoImage' =>'on' , //自动解析图片目录开关 on表示开放 off表示关闭 + 'LangDir' =>'language' , //语言文件存放的目录 + 'Language' =>'default' , //语言的默认文件 + 'Copyright' =>'off' , //版权保护 + 'MemCache' =>'' , //Memcache服务器地址例如:127.0.0.1:11211 + ) + ){ + + parent::ETCoreStart($set); + } + +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php b/ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php new file mode 100644 index 0000000..aabea87 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseClassManager.php @@ -0,0 +1,53 @@ + * + * * +\**********************************************************/ + +class HproseClassManager { + private static $classCache1 = array(); + private static $classCache2 = array(); + public static function register($class, $alias) { + self::$classCache1[$alias] = $class; + self::$classCache2[$class] = $alias; + } + public static function getClassAlias($class) { + if (array_key_exists($class, self::$classCache2)) { + return self::$classCache2[$class]; + } + $alias = str_replace('\\', '_', $class); + self::register($class, $alias); + return $alias; + } + public static function getClass($alias) { + if (array_key_exists($alias, self::$classCache1)) { + return self::$classCache1[$alias]; + } + if (!class_exists($alias)) { + $class = str_replace('_', '\\', $alias); + if (class_exists($class)) { + self::register($class, $alias); + return $class; + } + eval("class " . $alias . " { }"); + } + return $alias; + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseClient.php b/ThinkPHP/Library/Vendor/Hprose/HproseClient.php new file mode 100644 index 0000000..53c01ec --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseClient.php @@ -0,0 +1,134 @@ + * + * * +\**********************************************************/ + +require_once('HproseCommon.php'); +require_once('HproseIO.php'); + +abstract class HproseClient { + protected $url; + private $filter; + private $simple; + protected abstract function send($request); + public function __construct($url = '') { + $this->useService($url); + $this->filter = NULL; + $this->simple = false; + } + public function useService($url = '', $namespace = '') { + if ($url) { + $this->url = $url; + } + return new HproseProxy($this, $namespace); + } + public function invoke($functionName, &$arguments = array(), $byRef = false, $resultMode = HproseResultMode::Normal, $simple = NULL) { + if ($simple === NULL) $simple = $this->simple; + $stream = new HproseStringStream(HproseTags::TagCall); + $hproseWriter = ($simple ? new HproseSimpleWriter($stream) : new HproseWriter($stream)); + $hproseWriter->writeString($functionName); + if (count($arguments) > 0 || $byRef) { + $hproseWriter->reset(); + $hproseWriter->writeList($arguments); + if ($byRef) { + $hproseWriter->writeBoolean(true); + } + } + $stream->write(HproseTags::TagEnd); + $request = $stream->toString(); + if ($this->filter) $request = $this->filter->outputFilter($request); + $stream->close(); + $response = $this->send($request); + if ($this->filter) $response = $this->filter->inputFilter($response); + if ($resultMode == HproseResultMode::RawWithEndTag) { + return $response; + } + if ($resultMode == HproseResultMode::Raw) { + return substr($response, 0, -1); + } + $stream = new HproseStringStream($response); + $hproseReader = new HproseReader($stream); + $result = NULL; + while (($tag = $hproseReader->checkTags( + array(HproseTags::TagResult, + HproseTags::TagArgument, + HproseTags::TagError, + HproseTags::TagEnd))) !== HproseTags::TagEnd) { + switch ($tag) { + case HproseTags::TagResult: + if ($resultMode == HproseResultMode::Serialized) { + $result = $hproseReader->readRaw()->toString(); + } + else { + $hproseReader->reset(); + $result = &$hproseReader->unserialize(); + } + break; + case HproseTags::TagArgument: + $hproseReader->reset(); + $args = &$hproseReader->readList(true); + for ($i = 0; $i < count($arguments); $i++) { + $arguments[$i] = &$args[$i]; + } + break; + case HproseTags::TagError: + $hproseReader->reset(); + throw new HproseException($hproseReader->readString(true)); + break; + } + } + return $result; + } + public function getFilter() { + return $this->filter; + } + public function setFilter($filter) { + $this->filter = $filter; + } + public function getSimpleMode() { + return $this->simple; + } + public function setSimpleMode($simple = true) { + $this->simple = $simple; + } + public function __call($function, $arguments) { + return $this->invoke($function, $arguments); + } + public function __get($name) { + return new HproseProxy($this, $name . '_'); + } +} + +class HproseProxy { + private $client; + private $namespace; + public function __construct($client, $namespace = '') { + $this->client = $client; + $this->namespace = $namespace; + } + public function __call($function, $arguments) { + $function = $this->namespace . $function; + return $this->client->invoke($function, $arguments); + } + public function __get($name) { + return new HproseProxy($this->client, $this->namespace . $name . '_'); + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseCommon.php b/ThinkPHP/Library/Vendor/Hprose/HproseCommon.php new file mode 100644 index 0000000..33d102c --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseCommon.php @@ -0,0 +1,816 @@ + * + * * +\**********************************************************/ + +class HproseResultMode { + const Normal = 0; + const Serialized = 1; + const Raw = 2; + const RawWithEndTag = 3; +} + +class HproseException extends Exception {} + +interface HproseFilter { + function inputFilter($data); + function outputFilter($data); +} + +class HproseDate { + public $year; + public $month; + public $day; + public $utc = false; + public function __construct() { + $args_num = func_num_args(); + $args = func_get_args(); + switch ($args_num) { + case 0: + $time = getdate(); + $this->year = $time['year']; + $this->month = $time['mon']; + $this->day = $time['mday']; + break; + case 1: + $time = false; + if (is_int($args[0])) { + $time = getdate($args[0]); + } + elseif (is_string($args[0])) { + $time = getdate(strtotime($args[0])); + } + if (is_array($time)) { + $this->year = $time['year']; + $this->month = $time['mon']; + $this->day = $time['mday']; + } + elseif ($args[0] instanceof HproseDate) { + $this->year = $args[0]->year; + $this->month = $args[0]->month; + $this->day = $args[0]->day; + } + else { + throw new HproseException('Unexpected arguments'); + } + break; + case 4: + $this->utc = $args[3]; + case 3: + if (!self::isValidDate($args[0], $args[1], $args[2])) { + throw new HproseException('Unexpected arguments'); + } + $this->year = $args[0]; + $this->month = $args[1]; + $this->day = $args[2]; + break; + default: + throw new HproseException('Unexpected arguments'); + } + } + public function addDays($days) { + if (!is_int($days)) return false; + $year = $this->year; + if ($days == 0) return true; + if ($days >= 146097 || $days <= -146097) { + $remainder = $days % 146097; + if ($remainder < 0) { + $remainder += 146097; + } + $years = 400 * (int)(($days - $remainder) / 146097); + $year += $years; + if ($year < 1 || $year > 9999) return false; + $days = $remainder; + } + if ($days >= 36524 || $days <= -36524) { + $remainder = $days % 36524; + if ($remainder < 0) { + $remainder += 36524; + } + $years = 100 * (int)(($days - $remainder) / 36524); + $year += $years; + if ($year < 1 || $year > 9999) return false; + $days = $remainder; + } + if ($days >= 1461 || $days <= -1461) { + $remainder = $days % 1461; + if ($remainder < 0) { + $remainder += 1461; + } + $years = 4 * (int)(($days - $remainder) / 1461); + $year += $years; + if ($year < 1 || $year > 9999) return false; + $days = $remainder; + } + $month = $this->month; + while ($days >= 365) { + if ($year >= 9999) return false; + if ($month <= 2) { + if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) { + $days -= 366; + } + else { + $days -= 365; + } + $year++; + } + else { + $year++; + if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) { + $days -= 366; + } + else { + $days -= 365; + } + } + } + while ($days < 0) { + if ($year <= 1) return false; + if ($month <= 2) { + $year--; + if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) { + $days += 366; + } + else { + $days += 365; + } + } + else { + if ((($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false) { + $days += 366; + } + else { + $days += 365; + } + $year--; + } + } + $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); + $day = $this->day; + while ($day + $days > $daysInMonth) { + $days -= $daysInMonth - $day + 1; + $month++; + if ($month > 12) { + if ($year >= 9999) return false; + $year++; + $month = 1; + } + $day = 1; + $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); + } + $day += $days; + $this->year = $year; + $this->month = $month; + $this->day = $day; + return true; + } + public function addMonths($months) { + if (!is_int($months)) return false; + if ($months == 0) return true; + $month = $this->month + $months; + $months = ($month - 1) % 12 + 1; + if ($months < 1) { + $months += 12; + } + $years = (int)(($month - $months) / 12); + if ($this->addYears($years)) { + $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $months, $this->year); + if ($this->day > $daysInMonth) { + $months++; + $this->day -= $daysInMonth; + } + $this->month = (int)$months; + return true; + } + else { + return false; + } + } + public function addYears($years) { + if (!is_int($years)) return false; + if ($years == 0) return true; + $year = $this->year + $years; + if ($year < 1 || $year > 9999) return false; + $this->year = $year; + return true; + } + public function timestamp() { + if ($this->utc) { + return gmmktime(0, 0, 0, $this->month, $this->day, $this->year); + } + else { + return mktime(0, 0, 0, $this->month, $this->day, $this->year); + } + } + public function toString($fullformat = true) { + $format = ($fullformat ? '%04d-%02d-%02d': '%04d%02d%02d'); + $str = sprintf($format, $this->year, $this->month, $this->day); + if ($this->utc) { + $str .= 'Z'; + } + return $str; + } + public function __toString() { + return $this->toString(); + } + + public static function isLeapYear($year) { + return (($year % 4) == 0) ? (($year % 100) == 0) ? (($year % 400) == 0) : true : false; + } + public static function daysInMonth($year, $month) { + if (($month < 1) || ($month > 12)) { + return false; + } + return cal_days_in_month(CAL_GREGORIAN, $month, $year); + } + public static function isValidDate($year, $month, $day) { + if (($year >= 1) && ($year <= 9999)) { + return checkdate($month, $day, $year); + } + return false; + } + + public function dayOfWeek() { + $num = func_num_args(); + if ($num == 3) { + $args = func_get_args(); + $y = $args[0]; + $m = $args[1]; + $d = $args[2]; + } + else { + $y = $this->year; + $m = $this->month; + $d = $this->day; + } + $d += $m < 3 ? $y-- : $y - 2; + return ((int)(23 * $m / 9) + $d + 4 + (int)($y / 4) - (int)($y / 100) + (int)($y / 400)) % 7; + } + public function dayOfYear() { + static $daysToMonth365 = array(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365); + static $daysToMonth366 = array(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366); + $num = func_num_args(); + if ($num == 3) { + $args = func_get_args(); + $y = $args[0]; + $m = $args[1]; + $d = $args[2]; + } + else { + $y = $this->year; + $m = $this->month; + $d = $this->day; + } + $days = self::isLeapYear($y) ? $daysToMonth365 : $daysToMonth366; + return $days[$m - 1] + $d; + } +} + +class HproseTime { + public $hour; + public $minute; + public $second; + public $microsecond = 0; + public $utc = false; + public function __construct() { + $args_num = func_num_args(); + $args = func_get_args(); + switch ($args_num) { + case 0: + $time = getdate(); + $timeofday = gettimeofday(); + $this->hour = $time['hours']; + $this->minute = $time['minutes']; + $this->second = $time['seconds']; + $this->microsecond = $timeofday['usec']; + break; + case 1: + $time = false; + if (is_int($args[0])) { + $time = getdate($args[0]); + } + elseif (is_string($args[0])) { + $time = getdate(strtotime($args[0])); + } + if (is_array($time)) { + $this->hour = $time['hours']; + $this->minute = $time['minutes']; + $this->second = $time['seconds']; + } + elseif ($args[0] instanceof HproseTime) { + $this->hour = $args[0]->hour; + $this->minute = $args[0]->minute; + $this->second = $args[0]->second; + $this->microsecond = $args[0]->microsecond; + } + else { + throw new HproseException('Unexpected arguments'); + } + break; + case 5: + $this->utc = $args[4]; + case 4: + if (($args[3] < 0) || ($args[3] > 999999)) { + throw new HproseException('Unexpected arguments'); + } + $this->microsecond = $args[3]; + case 3: + if (!self::isValidTime($args[0], $args[1], $args[2])) { + throw new HproseException('Unexpected arguments'); + } + $this->hour = $args[0]; + $this->minute = $args[1]; + $this->second = $args[2]; + break; + default: + throw new HproseException('Unexpected arguments'); + } + } + public function timestamp() { + if ($this->utc) { + return gmmktime($this->hour, $this->minute, $this->second) + + ($this->microsecond / 1000000); + } + else { + return mktime($this->hour, $this->minute, $this->second) + + ($this->microsecond / 1000000); + } + } + public function toString($fullformat = true) { + if ($this->microsecond == 0) { + $format = ($fullformat ? '%02d:%02d:%02d': '%02d%02d%02d'); + $str = sprintf($format, $this->hour, $this->minute, $this->second); + } + if ($this->microsecond % 1000 == 0) { + $format = ($fullformat ? '%02d:%02d:%02d.%03d': '%02d%02d%02d.%03d'); + $str = sprintf($format, $this->hour, $this->minute, $this->second, (int)($this->microsecond / 1000)); + } + else { + $format = ($fullformat ? '%02d:%02d:%02d.%06d': '%02d%02d%02d.%06d'); + $str = sprintf($format, $this->hour, $this->minute, $this->second, $this->microsecond); + } + if ($this->utc) { + $str .= 'Z'; + } + return $str; + } + public function __toString() { + return $this->toString(); + } + public static function isValidTime($hour, $minute, $second, $microsecond = 0) { + return !(($hour < 0) || ($hour > 23) || + ($minute < 0) || ($minute > 59) || + ($second < 0) || ($second > 59) || + ($microsecond < 0) || ($microsecond > 999999)); + } +} + +class HproseDateTime extends HproseDate { + public $hour; + public $minute; + public $second; + public $microsecond = 0; + public function __construct() { + $args_num = func_num_args(); + $args = func_get_args(); + switch ($args_num) { + case 0: + $time = getdate(); + $timeofday = gettimeofday(); + $this->year = $time['year']; + $this->month = $time['mon']; + $this->day = $time['mday']; + $this->hour = $time['hours']; + $this->minute = $time['minutes']; + $this->second = $time['seconds']; + $this->microsecond = $timeofday['usec']; + break; + case 1: + $time = false; + if (is_int($args[0])) { + $time = getdate($args[0]); + } + elseif (is_string($args[0])) { + $time = getdate(strtotime($args[0])); + } + if (is_array($time)) { + $this->year = $time['year']; + $this->month = $time['mon']; + $this->day = $time['mday']; + $this->hour = $time['hours']; + $this->minute = $time['minutes']; + $this->second = $time['seconds']; + } + elseif ($args[0] instanceof HproseDate) { + $this->year = $args[0]->year; + $this->month = $args[0]->month; + $this->day = $args[0]->day; + $this->hour = 0; + $this->minute = 0; + $this->second = 0; + } + elseif ($args[0] instanceof HproseTime) { + $this->year = 1970; + $this->month = 1; + $this->day = 1; + $this->hour = $args[0]->hour; + $this->minute = $args[0]->minute; + $this->second = $args[0]->second; + $this->microsecond = $args[0]->microsecond; + } + elseif ($args[0] instanceof HproseDateTime) { + $this->year = $args[0]->year; + $this->month = $args[0]->month; + $this->day = $args[0]->day; + $this->hour = $args[0]->hour; + $this->minute = $args[0]->minute; + $this->second = $args[0]->second; + $this->microsecond = $args[0]->microsecond; + } + else { + throw new HproseException('Unexpected arguments'); + } + break; + case 2: + if (($args[0] instanceof HproseDate) && ($args[1] instanceof HproseTime)) { + $this->year = $args[0]->year; + $this->month = $args[0]->month; + $this->day = $args[0]->day; + $this->hour = $args[1]->hour; + $this->minute = $args[1]->minute; + $this->second = $args[1]->second; + $this->microsecond = $args[1]->microsecond; + } + else { + throw new HproseException('Unexpected arguments'); + } + break; + case 3: + if (!self::isValidDate($args[0], $args[1], $args[2])) { + throw new HproseException('Unexpected arguments'); + } + $this->year = $args[0]; + $this->month = $args[1]; + $this->day = $args[2]; + $this->hour = 0; + $this->minute = 0; + $this->second = 0; + break; + case 8: + $this->utc = $args[7]; + case 7: + if (($args[6] < 0) || ($args[6] > 999999)) { + throw new HproseException('Unexpected arguments'); + } + $this->microsecond = $args[6]; + case 6: + if (!self::isValidDate($args[0], $args[1], $args[2])) { + throw new HproseException('Unexpected arguments'); + } + if (!self::isValidTime($args[3], $args[4], $args[5])) { + throw new HproseException('Unexpected arguments'); + } + $this->year = $args[0]; + $this->month = $args[1]; + $this->day = $args[2]; + $this->hour = $args[3]; + $this->minute = $args[4]; + $this->second = $args[5]; + break; + default: + throw new HproseException('Unexpected arguments'); + } + } + + public function addMicroseconds($microseconds) { + if (!is_int($microseconds)) return false; + if ($microseconds == 0) return true; + $microsecond = $this->microsecond + $microseconds; + $microseconds = $microsecond % 1000000; + if ($microseconds < 0) { + $microseconds += 1000000; + } + $seconds = (int)(($microsecond - $microseconds) / 1000000); + if ($this->addSeconds($seconds)) { + $this->microsecond = (int)$microseconds; + return true; + } + else { + return false; + } + } + + public function addSeconds($seconds) { + if (!is_int($seconds)) return false; + if ($seconds == 0) return true; + $second = $this->second + $seconds; + $seconds = $second % 60; + if ($seconds < 0) { + $seconds += 60; + } + $minutes = (int)(($second - $seconds) / 60); + if ($this->addMinutes($minutes)) { + $this->second = (int)$seconds; + return true; + } + else { + return false; + } + } + public function addMinutes($minutes) { + if (!is_int($minutes)) return false; + if ($minutes == 0) return true; + $minute = $this->minute + $minutes; + $minutes = $minute % 60; + if ($minutes < 0) { + $minutes += 60; + } + $hours = (int)(($minute - $minutes) / 60); + if ($this->addHours($hours)) { + $this->minute = (int)$minutes; + return true; + } + else { + return false; + } + } + public function addHours($hours) { + if (!is_int($hours)) return false; + if ($hours == 0) return true; + $hour = $this->hour + $hours; + $hours = $hour % 24; + if ($hours < 0) { + $hours += 24; + } + $days = (int)(($hour - $hours) / 24); + if ($this->addDays($days)) { + $this->hour = (int)$hours; + return true; + } + else { + return false; + } + } + public function after($when) { + if (!($when instanceof HproseDateTime)) { + $when = new HproseDateTime($when); + } + if ($this->utc != $when->utc) return ($this->timestamp() > $when->timestamp()); + if ($this->year < $when->year) return false; + if ($this->year > $when->year) return true; + if ($this->month < $when->month) return false; + if ($this->month > $when->month) return true; + if ($this->day < $when->day) return false; + if ($this->day > $when->day) return true; + if ($this->hour < $when->hour) return false; + if ($this->hour > $when->hour) return true; + if ($this->minute < $when->minute) return false; + if ($this->minute > $when->minute) return true; + if ($this->second < $when->second) return false; + if ($this->second > $when->second) return true; + if ($this->microsecond < $when->microsecond) return false; + if ($this->microsecond > $when->microsecond) return true; + return false; + } + public function before($when) { + if (!($when instanceof HproseDateTime)) { + $when = new HproseDateTime($when); + } + if ($this->utc != $when->utc) return ($this->timestamp() < $when->timestamp()); + if ($this->year < $when->year) return true; + if ($this->year > $when->year) return false; + if ($this->month < $when->month) return true; + if ($this->month > $when->month) return false; + if ($this->day < $when->day) return true; + if ($this->day > $when->day) return false; + if ($this->hour < $when->hour) return true; + if ($this->hour > $when->hour) return false; + if ($this->minute < $when->minute) return true; + if ($this->minute > $when->minute) return false; + if ($this->second < $when->second) return true; + if ($this->second > $when->second) return false; + if ($this->microsecond < $when->microsecond) return true; + if ($this->microsecond > $when->microsecond) return false; + return false; + } + public function equals($when) { + if (!($when instanceof HproseDateTime)) { + $when = new HproseDateTime($when); + } + if ($this->utc != $when->utc) return ($this->timestamp() == $when->timestamp()); + return (($this->year == $when->year) && + ($this->month == $when->month) && + ($this->day == $when->day) && + ($this->hour == $when->hour) && + ($this->minute == $when->minute) && + ($this->second == $when->second) && + ($this->microsecond == $when->microsecond)); + } + public function timestamp() { + if ($this->utc) { + return gmmktime($this->hour, + $this->minute, + $this->second, + $this->month, + $this->day, + $this->year) + + ($this->microsecond / 1000000); + } + else { + return mktime($this->hour, + $this->minute, + $this->second, + $this->month, + $this->day, + $this->year) + + ($this->microsecond / 1000000); + } + } + public function toString($fullformat = true) { + if ($this->microsecond == 0) { + $format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d' + : '%04d%02d%02dT%02d%02d%02d'); + $str = sprintf($format, + $this->year, $this->month, $this->day, + $this->hour, $this->minute, $this->second); + } + if ($this->microsecond % 1000 == 0) { + $format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d.%03d' + : '%04d%02d%02dT%02d%02d%02d.%03d'); + $str = sprintf($format, + $this->year, $this->month, $this->day, + $this->hour, $this->minute, $this->second, + (int)($this->microsecond / 1000)); + } + else { + $format = ($fullformat ? '%04d-%02d-%02dT%02d:%02d:%02d.%06d' + : '%04d%02d%02dT%02d%02d%02d.%06d'); + $str = sprintf($format, + $this->year, $this->month, $this->day, + $this->hour, $this->minute, $this->second, + $this->microsecond); + } + if ($this->utc) { + $str .= 'Z'; + } + return $str; + } + public function __toString() { + return $this->toString(); + } + public static function isValidTime($hour, $minute, $second, $microsecond = 0) { + return HproseTime::isValidTime($hour, $minute, $second, $microsecond); + } +} + +/* + integer is_utf8(string $s) + if $s is UTF-8 String, return 1 else 0 + */ +if (function_exists('mb_detect_encoding')) { + function is_utf8($s) { + return mb_detect_encoding($s, 'UTF-8', true) === 'UTF-8'; + } +} +elseif (function_exists('iconv')) { + function is_utf8($s) { + return iconv('UTF-8', 'UTF-8//IGNORE', $s) === $s; + } +} +else { + function is_utf8($s) { + $len = strlen($s); + for($i = 0; $i < $len; ++$i){ + $c = ord($s{$i}); + switch ($c >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: + break; + case 12: + case 13: + if ((ord($s{++$i}) >> 6) != 0x2) return false; + break; + case 14: + if ((ord($s{++$i}) >> 6) != 0x2) return false; + if ((ord($s{++$i}) >> 6) != 0x2) return false; + break; + case 15: + $b = $s{++$i}; + if ((ord($b) >> 6) != 0x2) return false; + if ((ord($s{++$i}) >> 6) != 0x2) return false; + if ((ord($s{++$i}) >> 6) != 0x2) return false; + if (((($c & 0xf) << 2) | (($b >> 4) & 0x3)) > 0x10) return false; + break; + default: + return false; + } + } + return true; + } +} + +/* + integer ustrlen(string $s) + $s must be a UTF-8 String, return the Unicode code unit (not code point) length + */ +if (function_exists('iconv')) { + function ustrlen($s) { + return strlen(iconv('UTF-8', 'UTF-16LE', $s)) >> 1; + } +} +elseif (function_exists('mb_convert_encoding')) { + function ustrlen($s) { + return strlen(mb_convert_encoding($s, "UTF-16LE", "UTF-8")) >> 1; + } +} +else { + function ustrlen($s) { + $pos = 0; + $length = strlen($s); + $len = $length; + while ($pos < $length) { + $a = ord($s{$pos++}); + if ($a < 0x80) { + continue; + } + elseif (($a & 0xE0) == 0xC0) { + ++$pos; + --$len; + } + elseif (($a & 0xF0) == 0xE0) { + $pos += 2; + $len -= 2; + } + elseif (($a & 0xF8) == 0xF0) { + $pos += 3; + $len -= 2; + } + } + return $len; + } +} + +/* + bool is_list(array $a) + if $a is list, return true else false + */ +function is_list(array $a) { + $count = count($a); + if ($count === 0) return true; + return !array_diff_key($a, array_fill(0, $count, NULL)); +} + +/* + mixed array_ref_search(mixed &$value, array $array) + if $value ref in $array, return the index else false +*/ +function array_ref_search(&$value, &$array) { + if (!is_array($value)) return array_search($value, $array, true); + $temp = $value; + foreach ($array as $i => &$ref) { + if (($ref === ($value = 1)) && ($ref === ($value = 0))) { + $value = $temp; + return $i; + } + } + $value = $temp; + return false; +} + +/* + string spl_object_hash(object $obj) + This function returns a unique identifier for the object. + This id can be used as a hash key for storing objects or for identifying an object. +*/ +if (!function_exists('spl_object_hash')) { + function spl_object_hash($object) { + ob_start(); + var_dump($object); + preg_match('[#(\d+)]', ob_get_clean(), $match); + return $match[1]; + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php b/ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php new file mode 100644 index 0000000..b72fe4b --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseFormatter.php @@ -0,0 +1,40 @@ + * + * * +\**********************************************************/ + +require_once('HproseIOStream.php'); +require_once('HproseReader.php'); +require_once('HproseWriter.php'); + +class HproseFormatter { + public static function serialize(&$var, $simple = false) { + $stream = new HproseStringStream(); + $hproseWriter = ($simple ? new HproseSimpleWriter($stream) : new HproseWriter($stream)); + $hproseWriter->serialize($var); + return $stream->toString(); + } + public static function &unserialize($data, $simple = false) { + $stream = new HproseStringStream($data); + $hproseReader = ($simple ? new HproseSimpleReader($stream) : new HproseReader($stream)); + return $hproseReader->unserialize(); + } +} +?> diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php b/ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php new file mode 100644 index 0000000..3472454 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseHttpClient.php @@ -0,0 +1,314 @@ + * + * * +\**********************************************************/ + +require_once('HproseCommon.php'); +require_once('HproseIO.php'); +require_once('HproseClient.php'); + +abstract class HproseBaseHttpClient extends HproseClient { + protected $host; + protected $path; + protected $secure; + protected $proxy; + protected $header; + protected $timeout; + protected $keepAlive; + protected $keepAliveTimeout; + protected static $cookieManager = array(); + static function hproseKeepCookieInSession() { + $_SESSION['HPROSE_COOKIE_MANAGER'] = self::$cookieManager; + } + public static function keepSession() { + if (array_key_exists('HPROSE_COOKIE_MANAGER', $_SESSION)) { + self::$cookieManager = $_SESSION['HPROSE_COOKIE_MANAGER']; + } + register_shutdown_function(array('HproseBaseHttpClient', 'hproseKeepCookieInSession')); + } + protected function setCookie($headers) { + foreach ($headers as $header) { + @list($name, $value) = explode(':', $header, 2); + if (strtolower($name) == 'set-cookie' || + strtolower($name) == 'set-cookie2') { + $cookies = explode(';', trim($value)); + $cookie = array(); + list($name, $value) = explode('=', trim($cookies[0]), 2); + $cookie['name'] = $name; + $cookie['value'] = $value; + for ($i = 1; $i < count($cookies); $i++) { + list($name, $value) = explode('=', trim($cookies[$i]), 2); + $cookie[strtoupper($name)] = $value; + } + // Tomcat can return SetCookie2 with path wrapped in " + if (array_key_exists('PATH', $cookie)) { + $cookie['PATH'] = trim($cookie['PATH'], '"'); + } + else { + $cookie['PATH'] = '/'; + } + if (array_key_exists('EXPIRES', $cookie)) { + $cookie['EXPIRES'] = strtotime($cookie['EXPIRES']); + } + if (array_key_exists('DOMAIN', $cookie)) { + $cookie['DOMAIN'] = strtolower($cookie['DOMAIN']); + } + else { + $cookie['DOMAIN'] = $this->host; + } + $cookie['SECURE'] = array_key_exists('SECURE', $cookie); + if (!array_key_exists($cookie['DOMAIN'], self::$cookieManager)) { + self::$cookieManager[$cookie['DOMAIN']] = array(); + } + self::$cookieManager[$cookie['DOMAIN']][$cookie['name']] = $cookie; + } + } + } + protected abstract function formatCookie($cookies); + protected function getCookie() { + $cookies = array(); + foreach (self::$cookieManager as $domain => $cookieList) { + if (strpos($this->host, $domain) !== false) { + $names = array(); + foreach ($cookieList as $cookie) { + if (array_key_exists('EXPIRES', $cookie) && (time() > $cookie['EXPIRES'])) { + $names[] = $cookie['name']; + } + elseif (strpos($this->path, $cookie['PATH']) === 0) { + if ((($this->secure && $cookie['SECURE']) || + !$cookie['SECURE']) && !is_null($cookie['value'])) { + $cookies[] = $cookie['name'] . '=' . $cookie['value']; + } + } + } + foreach ($names as $name) { + unset(self::$cookieManager[$domain][$name]); + } + } + } + return $this->formatCookie($cookies); + } + public function __construct($url = '') { + parent::__construct($url); + $this->header = array('Content-type' => 'application/hprose'); + } + public function useService($url = '', $namespace = '') { + $serviceProxy = parent::useService($url, $namespace); + if ($url) { + $url = parse_url($url); + $this->secure = (strtolower($url['scheme']) == 'https'); + $this->host = strtolower($url['host']); + $this->path = $url['path']; + $this->timeout = 30000; + $this->keepAlive = false; + $this->keepAliveTimeout = 300; + } + return $serviceProxy; + } + public function setHeader($name, $value) { + $lname = strtolower($name); + if ($lname != 'content-type' && + $lname != 'content-length' && + $lname != 'host') { + if ($value) { + $this->header[$name] = $value; + } + else { + unset($this->header[$name]); + } + } + } + public function setProxy($proxy = NULL) { + $this->proxy = $proxy; + } + public function setTimeout($timeout) { + $this->timeout = $timeout; + } + public function getTimeout() { + return $this->timeout; + } + public function setKeepAlive($keepAlive = true) { + $this->keepAlive = $keepAlive; + } + public function getKeepAlive() { + return $this->keeepAlive; + } + public function setKeepAliveTimeout($timeout) { + $this->keepAliveTimeout = $timeout; + } + public function getKeepAliveTimeout() { + return $this->keepAliveTimeout; + } +} + +if (class_exists('SaeFetchurl')) { + class HproseHttpClient extends HproseBaseHttpClient { + protected function formatCookie($cookies) { + if (count($cookies) > 0) { + return implode('; ', $cookies); + } + return ''; + } + protected function send($request) { + $f = new SaeFetchurl(); + $cookie = $this->getCookie(); + if ($cookie != '') { + $f->setHeader("Cookie", $cookie); + } + if ($this->keepAlive) { + $f->setHeader("Connection", "keep-alive"); + $f->setHeader("Keep-Alive", $this->keepAliveTimeout); + } + else { + $f->setHeader("Connection", "close"); + } + foreach ($this->header as $name => $value) { + $f->setHeader($name, $value); + } + $f->setMethod("post"); + $f->setPostData($request); + $f->setConnectTimeout($this->timeout); + $f->setSendTimeout($this->timeout); + $f->setReadTimeout($this->timeout); + $response = $f->fetch($this->url); + if ($f->errno()) { + throw new HproseException($f->errno() . ": " . $f->errmsg()); + } + $http_response_header = $f->responseHeaders(false); + $this->setCookie($http_response_header); + return $response; + } + } +} +elseif (function_exists('curl_init')) { + class HproseHttpClient extends HproseBaseHttpClient { + private $curl; + protected function formatCookie($cookies) { + if (count($cookies) > 0) { + return "Cookie: " . implode('; ', $cookies); + } + return ''; + } + public function __construct($url = '') { + parent::__construct($url); + $this->curl = curl_init(); + } + protected function send($request) { + curl_setopt($this->curl, CURLOPT_URL, $this->url); + curl_setopt($this->curl, CURLOPT_HEADER, TRUE); + curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE); + curl_setopt($this->curl, CURLOPT_POST, TRUE); + curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request); + $headers_array = array($this->getCookie(), + "Content-Length: " . strlen($request)); + if ($this->keepAlive) { + $headers_array[] = "Connection: keep-alive"; + $headers_array[] = "Keep-Alive: " . $this->keepAliveTimeout; + } + else { + $headers_array[] = "Connection: close"; + } + foreach ($this->header as $name => $value) { + $headers_array[] = $name . ": " . $value; + } + curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers_array); + if ($this->proxy) { + curl_setopt($this->curl, CURLOPT_PROXY, $this->proxy); + } + if (defined(CURLOPT_TIMEOUT_MS)) { + curl_setopt($this->curl, CURLOPT_TIMEOUT_MS, $this->timeout); + } + else { + curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout / 1000); + } + $response = curl_exec($this->curl); + $errno = curl_errno($this->curl); + if ($errno) { + throw new HproseException($errno . ": " . curl_error($this->curl)); + } + do { + list($response_headers, $response) = explode("\r\n\r\n", $response, 2); + $http_response_header = explode("\r\n", $response_headers); + $http_response_firstline = array_shift($http_response_header); + if (preg_match('@^HTTP/[0-9]\.[0-9]\s([0-9]{3})\s(.*)@', + $http_response_firstline, $matches)) { + $response_code = $matches[1]; + $response_status = trim($matches[2]); + } + else { + $response_code = "500"; + $response_status = "Unknown Error."; + } + } while (substr($response_code, 0, 1) == "1"); + if ($response_code != '200') { + throw new HproseException($response_code . ": " . $response_status); + } + $this->setCookie($http_response_header); + return $response; + } + public function __destruct() { + curl_close($this->curl); + } + } +} +else { + class HproseHttpClient extends HproseBaseHttpClient { + protected function formatCookie($cookies) { + if (count($cookies) > 0) { + return "Cookie: " . implode('; ', $cookies) . "\r\n"; + } + return ''; + } + public function __errorHandler($errno, $errstr, $errfile, $errline) { + throw new Exception($errstr, $errno); + } + protected function send($request) { + $opts = array ( + 'http' => array ( + 'method' => 'POST', + 'header'=> $this->getCookie() . + "Content-Length: " . strlen($request) . "\r\n" . + ($this->keepAlive ? + "Connection: keep-alive\r\n" . + "Keep-Alive: " . $this->keepAliveTimeout . "\r\n" : + "Connection: close\r\n"), + 'content' => $request, + 'timeout' => $this->timeout / 1000.0, + ), + ); + foreach ($this->header as $name => $value) { + $opts['http']['header'] .= "$name: $value\r\n"; + } + if ($this->proxy) { + $opts['http']['proxy'] = $this->proxy; + $opts['http']['request_fulluri'] = true; + } + $context = stream_context_create($opts); + set_error_handler(array(&$this, '__errorHandler')); + $response = file_get_contents($this->url, false, $context); + restore_error_handler(); + $this->setCookie($http_response_header); + return $response; + } + } +} + +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php b/ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php new file mode 100644 index 0000000..86443ee --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseHttpServer.php @@ -0,0 +1,483 @@ + * + * * +\**********************************************************/ + +require_once('HproseCommon.php'); +require_once('HproseIO.php'); + +class HproseHttpServer { + private $errorTable = array(E_ERROR => 'Error', + E_WARNING => 'Warning', + E_PARSE => 'Parse Error', + E_NOTICE => 'Notice', + E_CORE_ERROR => 'Core Error', + E_CORE_WARNING => 'Core Warning', + E_COMPILE_ERROR => 'Compile Error', + E_COMPILE_WARNING => 'Compile Warning', + E_USER_ERROR => 'User Error', + E_USER_WARNING => 'User Warning', + E_USER_NOTICE => 'User Notice', + E_STRICT => 'Run-time Notice', + E_RECOVERABLE_ERROR => 'Error'); + private $functions; + private $funcNames; + private $resultModes; + private $simpleModes; + private $debug; + private $crossDomain; + private $P3P; + private $get; + private $input; + private $output; + private $error; + private $filter; + private $simple; + public $onBeforeInvoke; + public $onAfterInvoke; + public $onSendHeader; + public $onSendError; + public function __construct() { + $this->functions = array(); + $this->funcNames = array(); + $this->resultModes = array(); + $this->simpleModes = array(); + $this->debug = false; + $this->crossDomain = false; + $this->P3P = false; + $this->get = true; + $this->filter = NULL; + $this->simple = false; + $this->error_types = E_ALL & ~E_NOTICE; + $this->onBeforeInvoke = NULL; + $this->onAfterInvoke = NULL; + $this->onSendHeader = NULL; + $this->onSendError = NULL; + } + /* + __filterHandler & __errorHandler must be public, + however we should never call them directly. + */ + public function __filterHandler($data) { + if (preg_match('/.*? error<\/b>:(.*?)
    debug) { + $error = preg_replace('/<.*?>/', '', $match[1]); + } + else { + $error = preg_replace('/ in .*<\/b>$/', '', $match[1]); + } + $data = HproseTags::TagError . + HproseFormatter::serialize(trim($error), true) . + HproseTags::TagEnd; + } + if ($this->filter) $data = $this->filter->outputFilter($data); + return $data; + } + public function __errorHandler($errno, $errstr, $errfile, $errline) { + if ($this->debug) { + $errstr .= " in $errfile on line $errline"; + } + $this->error = $this->errorTable[$errno] . ": " . $errstr; + $this->sendError(); + return true; + } + private function sendHeader() { + if ($this->onSendHeader) { + call_user_func($this->onSendHeader); + } + header("Content-Type: text/plain"); + if ($this->P3P) { + header('P3P: CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi ' . + 'CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL ' . + 'UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"'); + } + if ($this->crossDomain) { + if (array_key_exists('HTTP_ORIGIN', $_SERVER) && $_SERVER['HTTP_ORIGIN'] != "null") { + header("Access-Control-Allow-Origin: " . $_SERVER['HTTP_ORIGIN']); + header("Access-Control-Allow-Credentials: true"); + } + else { + header('Access-Control-Allow-Origin: *'); + } + } + } + private function sendError() { + if ($this->onSendError) { + call_user_func($this->onSendError, $this->error); + } + ob_clean(); + $this->output->write(HproseTags::TagError); + $writer = new HproseSimpleWriter($this->output); + $writer->writeString($this->error); + $this->output->write(HproseTags::TagEnd); + ob_end_flush(); + } + private function doInvoke() { + $simpleReader = new HproseSimpleReader($this->input); + do { + $functionName = $simpleReader->readString(true); + $aliasName = strtolower($functionName); + $resultMode = HproseResultMode::Normal; + if (array_key_exists($aliasName, $this->functions)) { + $function = $this->functions[$aliasName]; + $resultMode = $this->resultModes[$aliasName]; + $simple = $this->simpleModes[$aliasName]; + } + elseif (array_key_exists('*', $this->functions)) { + $function = $this->functions['*']; + $resultMode = $this->resultModes['*']; + $simple = $this->resultModes['*']; + } + else { + throw new HproseException("Can't find this function " . $functionName . "()."); + } + if ($simple === NULL) $simple = $this->simple; + $writer = ($simple ? new HproseSimpleWriter($this->output) : new HproseWriter($this->output)); + $args = array(); + $byref = false; + $tag = $simpleReader->checkTags(array(HproseTags::TagList, + HproseTags::TagEnd, + HproseTags::TagCall)); + if ($tag == HproseTags::TagList) { + $reader = new HproseReader($this->input); + $args = &$reader->readList(); + $tag = $reader->checkTags(array(HproseTags::TagTrue, + HproseTags::TagEnd, + HproseTags::TagCall)); + if ($tag == HproseTags::TagTrue) { + $byref = true; + $tag = $reader->checkTags(array(HproseTags::TagEnd, + HproseTags::TagCall)); + } + } + if ($this->onBeforeInvoke) { + call_user_func($this->onBeforeInvoke, $functionName, $args, $byref); + } + if (array_key_exists('*', $this->functions) && ($function === $this->functions['*'])) { + $arguments = array($functionName, &$args); + } + elseif ($byref) { + $arguments = array(); + for ($i = 0; $i < count($args); $i++) { + $arguments[$i] = &$args[$i]; + } + } + else { + $arguments = $args; + } + $result = call_user_func_array($function, $arguments); + if ($this->onAfterInvoke) { + call_user_func($this->onAfterInvoke, $functionName, $args, $byref, $result); + } + // some service functions/methods may echo content, we need clean it + ob_clean(); + if ($resultMode == HproseResultMode::RawWithEndTag) { + $this->output->write($result); + return; + } + elseif ($resultMode == HproseResultMode::Raw) { + $this->output->write($result); + } + else { + $this->output->write(HproseTags::TagResult); + if ($resultMode == HproseResultMode::Serialized) { + $this->output->write($result); + } + else { + $writer->reset(); + $writer->serialize($result); + } + if ($byref) { + $this->output->write(HproseTags::TagArgument); + $writer->reset(); + $writer->writeList($args); + } + } + } while ($tag == HproseTags::TagCall); + $this->output->write(HproseTags::TagEnd); + ob_end_flush(); + } + private function doFunctionList() { + $functions = array_values($this->funcNames); + $writer = new HproseSimpleWriter($this->output); + $this->output->write(HproseTags::TagFunctions); + $writer->writeList($functions); + $this->output->write(HproseTags::TagEnd); + ob_end_flush(); + } + private function getDeclaredOnlyMethods($class) { + $all = get_class_methods($class); + if ($parent_class = get_parent_class($class)) { + $inherit = get_class_methods($parent_class); + $result = array_diff($all, $inherit); + } + else { + $result = $all; + } + return $result; + } + public function addMissingFunction($function, $resultMode = HproseResultMode::Normal, $simple = NULL) { + $this->addFunction($function, '*', $resultMode, $simple); + } + public function addFunction($function, $alias = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + if (is_callable($function)) { + if ($alias === NULL) { + if (is_string($function)) { + $alias = $function; + } + else { + $alias = $function[1]; + } + } + if (is_string($alias)) { + $aliasName = strtolower($alias); + $this->functions[$aliasName] = $function; + $this->funcNames[$aliasName] = $alias; + $this->resultModes[$aliasName] = $resultMode; + $this->simpleModes[$aliasName] = $simple; + } + else { + throw new HproseException('Argument alias is not a string'); + } + } + else { + throw new HproseException('Argument function is not a callable variable'); + } + } + public function addFunctions($functions, $aliases = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + $aliases_is_null = ($aliases === NULL); + $count = count($functions); + if (!$aliases_is_null && $count != count($aliases)) { + throw new HproseException('The count of functions is not matched with aliases'); + } + for ($i = 0; $i < $count; $i++) { + $function = $functions[$i]; + if ($aliases_is_null) { + $this->addFunction($function, NULL, $resultMode, $simple); + } + else { + $this->addFunction($function, $aliases[$i], $resultMode, $simple); + } + } + } + public function addMethod($methodname, $belongto, $alias = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + if ($alias === NULL) { + $alias = $methodname; + } + if (is_string($belongto)) { + $this->addFunction(array($belongto, $methodname), $alias, $resultMode, $simple); + } + else { + $this->addFunction(array(&$belongto, $methodname), $alias, $resultMode, $simple); + } + } + public function addMethods($methods, $belongto, $aliases = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + $aliases_is_null = ($aliases === NULL); + $count = count($methods); + if (is_string($aliases)) { + $aliasPrefix = $aliases; + $aliases = array(); + foreach ($methods as $name) { + $aliases[] = $aliasPrefix . '_' . $name; + } + } + if (!$aliases_is_null && $count != count($aliases)) { + throw new HproseException('The count of methods is not matched with aliases'); + } + for ($i = 0; $i < $count; $i++) { + $method = $methods[$i]; + if (is_string($belongto)) { + $function = array($belongto, $method); + } + else { + $function = array(&$belongto, $method); + } + if ($aliases_is_null) { + $this->addFunction($function, $method, $resultMode, $simple); + } + else { + $this->addFunction($function, $aliases[$i], $resultMode, $simple); + } + } + } + public function addInstanceMethods($object, $class = NULL, $aliasPrefix = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + if ($class === NULL) $class = get_class($object); + $this->addMethods($this->getDeclaredOnlyMethods($class), $object, $aliasPrefix, $resultMode, $simple); + } + public function addClassMethods($class, $execclass = NULL, $aliasPrefix = NULL, $resultMode = HproseResultMode::Normal, $simple = NULL) { + if ($execclass === NULL) $execclass = $class; + $this->addMethods($this->getDeclaredOnlyMethods($class), $execclass, $aliasPrefix, $resultMode, $simple); + } + public function add() { + $args_num = func_num_args(); + $args = func_get_args(); + switch ($args_num) { + case 1: { + if (is_callable($args[0])) { + return $this->addFunction($args[0]); + } + elseif (is_array($args[0])) { + return $this->addFunctions($args[0]); + } + elseif (is_object($args[0])) { + return $this->addInstanceMethods($args[0]); + } + elseif (is_string($args[0])) { + return $this->addClassMethods($args[0]); + } + break; + } + case 2: { + if (is_callable($args[0]) && is_string($args[1])) { + return $this->addFunction($args[0], $args[1]); + } + elseif (is_string($args[0])) { + if (is_string($args[1]) && !is_callable(array($args[1], $args[0]))) { + if (class_exists($args[1])) { + return $this->addClassMethods($args[0], $args[1]); + } + else { + return $this->addClassMethods($args[0], NULL, $args[1]); + } + } + return $this->addMethod($args[0], $args[1]); + } + elseif (is_array($args[0])) { + if (is_array($args[1])) { + return $this->addFunctions($args[0], $args[1]); + } + else { + return $this->addMethods($args[0], $args[1]); + } + } + elseif (is_object($args[0])) { + return $this->addInstanceMethods($args[0], $args[1]); + } + break; + } + case 3: { + if (is_callable($args[0]) && is_null($args[1]) && is_string($args[2])) { + return $this->addFunction($args[0], $args[2]); + } + elseif (is_string($args[0]) && is_string($args[2])) { + if (is_string($args[1]) && !is_callable(array($args[0], $args[1]))) { + return $this->addClassMethods($args[0], $args[1], $args[2]); + } + else { + return $this->addMethod($args[0], $args[1], $args[2]); + } + } + elseif (is_array($args[0])) { + if (is_null($args[1]) && is_array($args[2])) { + return $this->addFunctions($args[0], $args[2]); + } + else { + return $this->addMethods($args[0], $args[1], $args[2]); + } + } + elseif (is_object($args[0])) { + return $this->addInstanceMethods($args[0], $args[1], $args[2]); + } + break; + } + throw new HproseException('Wrong arguments'); + } + } + public function isDebugEnabled() { + return $this->debug; + } + public function setDebugEnabled($enable = true) { + $this->debug = $enable; + } + public function isCrossDomainEnabled() { + return $this->crossDomain; + } + public function setCrossDomainEnabled($enable = true) { + $this->crossDomain = $enable; + } + public function isP3PEnabled() { + return $this->P3P; + } + public function setP3PEnabled($enable = true) { + $this->P3P = $enable; + } + public function isGetEnabled() { + return $this->get; + } + public function setGetEnabled($enable = true) { + $this->get = $enable; + } + public function getFilter() { + return $this->filter; + } + public function setFilter($filter) { + $this->filter = $filter; + } + public function getSimpleMode() { + return $this->simple; + } + public function setSimpleMode($simple = true) { + $this->simple = $simple; + } + public function getErrorTypes() { + return $this->error_types; + } + public function setErrorTypes($error_types) { + $this->error_types = $error_types; + } + public function handle() { + if (!isset($HTTP_RAW_POST_DATA)) $HTTP_RAW_POST_DATA = file_get_contents("php://input"); + if ($this->filter) $HTTP_RAW_POST_DATA = $this->filter->inputFilter($HTTP_RAW_POST_DATA); + $this->input = new HproseStringStream($HTTP_RAW_POST_DATA); + $this->output = new HproseFileStream(fopen('php://output', 'wb')); + set_error_handler(array(&$this, '__errorHandler'), $this->error_types); + ob_start(array(&$this, "__filterHandler")); + ob_implicit_flush(0); + ob_clean(); + $this->sendHeader(); + if (($_SERVER['REQUEST_METHOD'] == 'GET') and $this->get) { + return $this->doFunctionList(); + } + elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { + try { + switch ($this->input->getc()) { + case HproseTags::TagCall: return $this->doInvoke(); + case HproseTags::TagEnd: return $this->doFunctionList(); + default: throw new HproseException("Wrong Request: \r\n" . $HTTP_RAW_POST_DATA); + } + } + catch (Exception $e) { + $this->error = $e->getMessage(); + if ($this->debug) { + $this->error .= "\nfile: " . $e->getFile() . + "\nline: " . $e->getLine() . + "\ntrace: " . $e->getTraceAsString(); + } + $this->sendError(); + } + } + $this->input->close(); + $this->output->close(); + } + public function start() { + $this->handle(); + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseIO.php b/ThinkPHP/Library/Vendor/Hprose/HproseIO.php new file mode 100644 index 0000000..cadbba7 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseIO.php @@ -0,0 +1,29 @@ + * + * * +\**********************************************************/ + +require_once('HproseTags.php'); +require_once('HproseClassManager.php'); +require_once('HproseReader.php'); +require_once('HproseWriter.php'); +require_once('HproseFormatter.php'); + +?> diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php b/ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php new file mode 100644 index 0000000..72c0fb5 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseIOStream.php @@ -0,0 +1,349 @@ + * + * * +\**********************************************************/ + +abstract class HproseAbstractStream { + public abstract function close(); + public abstract function getc(); + public abstract function read($length); + public abstract function readuntil($char); + public abstract function seek($offset, $whence = SEEK_SET); + public abstract function mark(); + public abstract function unmark(); + public abstract function reset(); + public abstract function skip($n); + public abstract function eof(); + public abstract function write($string, $length = -1); +} + +class HproseStringStream extends HproseAbstractStream { + protected $buffer; + protected $pos; + protected $mark; + protected $length; + public function __construct($string = '') { + $this->buffer = $string; + $this->pos = 0; + $this->mark = -1; + $this->length = strlen($string); + } + public function close() { + $this->buffer = NULL; + $this->pos = 0; + $this->mark = -1; + $this->length = 0; + } + public function length() { + return $this->length; + } + public function getc() { + return $this->buffer{$this->pos++}; + } + public function read($length) { + $s = substr($this->buffer, $this->pos, $length); + $this->skip($length); + return $s; + } + public function readuntil($tag) { + $pos = strpos($this->buffer, $tag, $this->pos); + if ($pos !== false) { + $s = substr($this->buffer, $this->pos, $pos - $this->pos); + $this->pos = $pos + strlen($tag); + } + else { + $s = substr($this->buffer, $this->pos); + $this->pos = $this->length; + } + return $s; + } + public function seek($offset, $whence = SEEK_SET) { + switch ($whence) { + case SEEK_SET: + $this->pos = $offset; + break; + case SEEK_CUR: + $this->pos += $offset; + break; + case SEEK_END: + $this->pos = $this->length + $offset; + break; + } + $this->mark = -1; + return 0; + } + public function mark() { + $this->mark = $this->pos; + } + public function unmark() { + $this->mark = -1; + } + public function reset() { + if ($this->mark != -1) { + $this->pos = $this->mark; + } + } + public function skip($n) { + $this->pos += $n; + } + public function eof() { + return ($this->pos >= $this->length); + } + public function write($string, $length = -1) { + if ($length == -1) { + $this->buffer .= $string; + $length = strlen($string); + } + else { + $this->buffer .= substr($string, 0, $length); + } + $this->length += $length; + } + public function toString() { + return $this->buffer; + } +} + +class HproseFileStream extends HproseAbstractStream { + protected $fp; + protected $buf; + protected $unmark; + protected $pos; + protected $length; + public function __construct($fp) { + $this->fp = $fp; + $this->buf = ""; + $this->unmark = true; + $this->pos = -1; + $this->length = 0; + } + public function close() { + return fclose($this->fp); + } + public function getc() { + if ($this->pos == -1) { + return fgetc($this->fp); + } + elseif ($this->pos < $this->length) { + return $this->buf{$this->pos++}; + } + elseif ($this->unmark) { + $this->buf = ""; + $this->pos = -1; + $this->length = 0; + return fgetc($this->fp); + } + elseif (($c = fgetc($this->fp)) !== false) { + $this->buf .= $c; + $this->pos++; + $this->length++; + } + return $c; + } + public function read($length) { + if ($this->pos == -1) { + return fread($this->fp, $length); + } + elseif ($this->pos < $this->length) { + $len = $this->length - $this->pos; + if ($len < $length) { + $s = fread($this->fp, $length - $len); + $this->buf .= $s; + $this->length += strlen($s); + } + $s = substr($this->buf, $this->pos, $length); + $this->pos += strlen($s); + } + elseif ($this->unmark) { + $this->buf = ""; + $this->pos = -1; + $this->length = 0; + return fread($this->fp, $length); + } + elseif (($s = fread($this->fp, $length)) !== "") { + $this->buf .= $s; + $len = strlen($s); + $this->pos += $len; + $this->length += $len; + } + return $s; + } + public function readuntil($char) { + $s = ''; + while ((($c = $this->getc()) != $char) && $c !== false) $s .= $c; + return $s; + } + public function seek($offset, $whence = SEEK_SET) { + if (fseek($this->fp, $offset, $whence) == 0) { + $this->buf = ""; + $this->unmark = true; + $this->pos = -1; + $this->length = 0; + return 0; + } + return -1; + } + public function mark() { + $this->unmark = false; + if ($this->pos == -1) { + $this->buf = ""; + $this->pos = 0; + $this->length = 0; + } + elseif ($this->pos > 0) { + $this->buf = substr($this->buf, $this->pos); + $this->length -= $this->pos; + $this->pos = 0; + } + } + public function unmark() { + $this->unmark = true; + } + public function reset() { + $this->pos = 0; + } + public function skip($n) { + $this->read($n); + } + public function eof() { + if (($this->pos != -1) && ($this->pos < $this->length)) return false; + return feof($this->fp); + } + public function write($string, $length = -1) { + if ($length == -1) $length = strlen($string); + return fwrite($this->fp, $string, $length); + } +} + +class HproseProcStream extends HproseAbstractStream { + protected $process; + protected $pipes; + protected $buf; + protected $unmark; + protected $pos; + protected $length; + public function __construct($process, $pipes) { + $this->process = $process; + $this->pipes = $pipes; + $this->buf = ""; + $this->unmark = true; + $this->pos = -1; + $this->length = 0; + } + public function close() { + fclose($this->pipes[0]); + fclose($this->pipes[1]); + proc_close($this->process); + } + public function getc() { + if ($this->pos == -1) { + return fgetc($this->pipes[1]); + } + elseif ($this->pos < $this->length) { + return $this->buf{$this->pos++}; + } + elseif ($this->unmark) { + $this->buf = ""; + $this->pos = -1; + $this->length = 0; + return fgetc($this->pipes[1]); + } + elseif (($c = fgetc($this->pipes[1])) !== false) { + $this->buf .= $c; + $this->pos++; + $this->length++; + } + return $c; + } + public function read($length) { + if ($this->pos == -1) { + return fread($this->pipes[1], $length); + } + elseif ($this->pos < $this->length) { + $len = $this->length - $this->pos; + if ($len < $length) { + $s = fread($this->pipes[1], $length - $len); + $this->buf .= $s; + $this->length += strlen($s); + } + $s = substr($this->buf, $this->pos, $length); + $this->pos += strlen($s); + } + elseif ($this->unmark) { + $this->buf = ""; + $this->pos = -1; + $this->length = 0; + return fread($this->pipes[1], $length); + } + elseif (($s = fread($this->pipes[1], $length)) !== "") { + $this->buf .= $s; + $len = strlen($s); + $this->pos += $len; + $this->length += $len; + } + return $s; + } + public function readuntil($char) { + $s = ''; + while ((($c = $this->getc()) != $char) && $c !== false) $s .= $c; + return $s; + } + public function seek($offset, $whence = SEEK_SET) { + if (fseek($this->pipes[1], $offset, $whence) == 0) { + $this->buf = ""; + $this->unmark = true; + $this->pos = -1; + $this->length = 0; + return 0; + } + return -1; + } + public function mark() { + $this->unmark = false; + if ($this->pos == -1) { + $this->buf = ""; + $this->pos = 0; + $this->length = 0; + } + elseif ($this->pos > 0) { + $this->buf = substr($this->buf, $this->pos); + $this->length -= $this->pos; + $this->pos = 0; + } + } + public function unmark() { + $this->unmark = true; + } + public function reset() { + $this->pos = 0; + } + public function skip($n) { + $this->read($n); + } + public function eof() { + if (($this->pos != -1) && ($this->pos < $this->length)) return false; + return feof($this->pipes[1]); + } + public function write($string, $length = -1) { + if ($length == -1) $length = strlen($string); + return fwrite($this->pipes[0], $string, $length); + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseReader.php b/ThinkPHP/Library/Vendor/Hprose/HproseReader.php new file mode 100644 index 0000000..da223a8 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseReader.php @@ -0,0 +1,672 @@ + * + * * +\**********************************************************/ + +require_once('HproseCommon.php'); +require_once('HproseTags.php'); +require_once('HproseClassManager.php'); + +class HproseRawReader { + public $stream; + function __construct(&$stream) { + $this->stream = &$stream; + } + public function readRaw($ostream = NULL, $tag = NULL) { + if (is_null($ostream)) { + $ostream = new HproseStringStream(); + } + if (is_null($tag)) { + $tag = $this->stream->getc(); + } + switch ($tag) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + case HproseTags::TagNull: + case HproseTags::TagEmpty: + case HproseTags::TagTrue: + case HproseTags::TagFalse: + case HproseTags::TagNaN: + $ostream->write($tag); + break; + case HproseTags::TagInfinity: + $ostream->write($tag); + $ostream->write($this->stream->getc()); + break; + case HproseTags::TagInteger: + case HproseTags::TagLong: + case HproseTags::TagDouble: + case HproseTags::TagRef: + $this->readNumberRaw($ostream, $tag); + break; + case HproseTags::TagDate: + case HproseTags::TagTime: + $this->readDateTimeRaw($ostream, $tag); + break; + case HproseTags::TagUTF8Char: + $this->readUTF8CharRaw($ostream, $tag); + break; + case HproseTags::TagBytes: + $this->readBytesRaw($ostream, $tag); + break; + case HproseTags::TagString: + $this->readStringRaw($ostream, $tag); + break; + case HproseTags::TagGuid: + $this->readGuidRaw($ostream, $tag); + break; + case HproseTags::TagList: + case HproseTags::TagMap: + case HproseTags::TagObject: + $this->readComplexRaw($ostream, $tag); + break; + case HproseTags::TagClass: + $this->readComplexRaw($ostream, $tag); + $this->readRaw($ostream); + break; + case HproseTags::TagError: + $ostream->write($tag); + $this->readRaw($ostream); + break; + case false: + throw new HproseException("No byte found in stream"); + default: + throw new HproseException("Unexpected serialize tag '" + $tag + "' in stream"); + } + return $ostream; + } + + private function readNumberRaw($ostream, $tag) { + $s = $tag . + $this->stream->readuntil(HproseTags::TagSemicolon) . + HproseTags::TagSemicolon; + $ostream->write($s); + } + + private function readDateTimeRaw($ostream, $tag) { + $s = $tag; + do { + $tag = $this->stream->getc(); + $s .= $tag; + } while ($tag != HproseTags::TagSemicolon && + $tag != HproseTags::TagUTC); + $ostream->write($s); + } + + private function readUTF8CharRaw($ostream, $tag) { + $s = $tag; + $tag = $this->stream->getc(); + $s .= $tag; + $a = ord($tag); + if (($a & 0xE0) == 0xC0) { + $s .= $this->stream->getc(); + } + elseif (($a & 0xF0) == 0xE0) { + $s .= $this->stream->read(2); + } + elseif ($a > 0x7F) { + throw new HproseException("bad utf-8 encoding"); + } + $ostream->write($s); + } + + private function readBytesRaw($ostream, $tag) { + $len = $this->stream->readuntil(HproseTags::TagQuote); + $s = $tag . $len . HproseTags::TagQuote . $this->stream->read((int)$len) . HproseTags::TagQuote; + $this->stream->skip(1); + $ostream->write($s); + } + + private function readStringRaw($ostream, $tag) { + $len = $this->stream->readuntil(HproseTags::TagQuote); + $s = $tag . $len . HproseTags::TagQuote; + $len = (int)$len; + $this->stream->mark(); + $utf8len = 0; + for ($i = 0; $i < $len; ++$i) { + switch (ord($this->stream->getc()) >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: { + // 0xxx xxxx + $utf8len++; + break; + } + case 12: + case 13: { + // 110x xxxx 10xx xxxx + $this->stream->skip(1); + $utf8len += 2; + break; + } + case 14: { + // 1110 xxxx 10xx xxxx 10xx xxxx + $this->stream->skip(2); + $utf8len += 3; + break; + } + case 15: { + // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + $this->stream->skip(3); + $utf8len += 4; + ++$i; + break; + } + default: { + throw new HproseException('bad utf-8 encoding'); + } + } + } + $this->stream->reset(); + $this->stream->unmark(); + $s .= $this->stream->read($utf8len) . HproseTags::TagQuote; + $this->stream->skip(1); + $ostream->write($s); + } + + private function readGuidRaw($ostream, $tag) { + $s = $tag . $this->stream->read(38); + $ostream->write($s); + } + + private function readComplexRaw($ostream, $tag) { + $s = $tag . + $this->stream->readuntil(HproseTags::TagOpenbrace) . + HproseTags::TagOpenbrace; + $ostream->write($s); + while (($tag = $this->stream->getc()) != HproseTags::TagClosebrace) { + $this->readRaw($ostream, $tag); + } + $ostream->write($tag); + } +} + +class HproseSimpleReader extends HproseRawReader { + private $classref; + function __construct(&$stream) { + parent::__construct($stream); + $this->classref = array(); + } + public function &unserialize($tag = NULL) { + if (is_null($tag)) { + $tag = $this->stream->getc(); + } + $result = NULL; + switch ($tag) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + $result = (int)$tag; break; + case HproseTags::TagInteger: $result = $this->readInteger(); break; + case HproseTags::TagLong: $result = $this->readLong(); break; + case HproseTags::TagDouble: $result = $this->readDouble(); break; + case HproseTags::TagNull: break; + case HproseTags::TagEmpty: $result = ''; break; + case HproseTags::TagTrue: $result = true; break; + case HproseTags::TagFalse: $result = false; break; + case HproseTags::TagNaN: $result = log(-1); break; + case HproseTags::TagInfinity: $result = $this->readInfinity(); break; + case HproseTags::TagDate: $result = $this->readDate(); break; + case HproseTags::TagTime: $result = $this->readTime(); break; + case HproseTags::TagBytes: $result = $this->readBytes(); break; + case HproseTags::TagUTF8Char: $result = $this->readUTF8Char(); break; + case HproseTags::TagString: $result = $this->readString(); break; + case HproseTags::TagGuid: $result = $this->readGuid(); break; + case HproseTags::TagList: $result = &$this->readList(); break; + case HproseTags::TagMap: $result = &$this->readMap(); break; + case HproseTags::TagClass: $this->readClass(); $result = &$this->unserialize(); break; + case HproseTags::TagObject: $result = $this->readObject(); break; + case HproseTags::TagError: throw new HproseException($this->readString(true)); + case false: throw new HproseException('No byte found in stream'); + default: throw new HproseException("Unexpected serialize tag '$tag' in stream"); + } + return $result; + } + public function checkTag($expectTag, $tag = NULL) { + if (is_null($tag)) $tag = $this->stream->getc(); + if ($tag != $expectTag) { + throw new HproseException("Tag '$expectTag' expected, but '$tag' found in stream"); + } + } + public function checkTags($expectTags, $tag = NULL) { + if (is_null($tag)) $tag = $this->stream->getc(); + if (!in_array($tag, $expectTags)) { + $expectTags = implode('', $expectTags); + throw new HproseException("Tag '$expectTags' expected, but '$tag' found in stream"); + } + return $tag; + } + public function readInteger($includeTag = false) { + if ($includeTag) { + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + return (int)$tag; + } + $this->checkTag(HproseTags::TagInteger, $tag); + } + return (int)($this->stream->readuntil(HproseTags::TagSemicolon)); + } + public function readLong($includeTag = false) { + if ($includeTag) { + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + return $tag; + } + $this->checkTag(HproseTags::TagLong, $tag); + } + return $this->stream->readuntil(HproseTags::TagSemicolon); + } + public function readDouble($includeTag = false) { + if ($includeTag) { + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + return (double)$tag; + } + $this->checkTag(HproseTags::TagDouble, $tag); + } + return (double)($this->stream->readuntil(HproseTags::TagSemicolon)); + } + public function readNaN() { + $this->checkTag(HproseTags::TagNaN); + return log(-1); + } + public function readInfinity($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagInfinity); + return (($this->stream->getc() == HproseTags::TagNeg) ? log(0) : -log(0)); + } + public function readNull() { + $this->checkTag(HproseTags::TagNull); + return NULL; + } + public function readEmpty() { + $this->checkTag(HproseTags::TagEmpty); + return ''; + } + public function readBoolean() { + $tag = $this->checkTags(array(HproseTags::TagTrue, HproseTags::TagFalse)); + return ($tag == HproseTags::TagTrue); + } + public function readDate($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagDate); + $year = (int)($this->stream->read(4)); + $month = (int)($this->stream->read(2)); + $day = (int)($this->stream->read(2)); + $tag = $this->stream->getc(); + if ($tag == HproseTags::TagTime) { + $hour = (int)($this->stream->read(2)); + $minute = (int)($this->stream->read(2)); + $second = (int)($this->stream->read(2)); + $microsecond = 0; + $tag = $this->stream->getc(); + if ($tag == HproseTags::TagPoint) { + $microsecond = (int)($this->stream->read(3)) * 1000; + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + $microsecond += (int)($tag) * 100 + (int)($this->stream->read(2)); + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + $this->stream->skip(2); + $tag = $this->stream->getc(); + } + } + } + if ($tag == HproseTags::TagUTC) { + $date = new HproseDateTime($year, $month, $day, + $hour, $minute, $second, + $microsecond, true); + } + else { + $date = new HproseDateTime($year, $month, $day, + $hour, $minute, $second, + $microsecond); + } + } + elseif ($tag == HproseTags::TagUTC) { + $date = new HproseDate($year, $month, $day, true); + } + else { + $date = new HproseDate($year, $month, $day); + } + return $date; + } + public function readTime($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagTime); + $hour = (int)($this->stream->read(2)); + $minute = (int)($this->stream->read(2)); + $second = (int)($this->stream->read(2)); + $microsecond = 0; + $tag = $this->stream->getc(); + if ($tag == HproseTags::TagPoint) { + $microsecond = (int)($this->stream->read(3)) * 1000; + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + $microsecond += (int)($tag) * 100 + (int)($this->stream->read(2)); + $tag = $this->stream->getc(); + if (($tag >= '0') && ($tag <= '9')) { + $this->stream->skip(2); + $tag = $this->stream->getc(); + } + } + } + if ($tag == HproseTags::TagUTC) { + $time = new HproseTime($hour, $minute, $second, $microsecond, true); + } + else { + $time = new HproseTime($hour, $minute, $second, $microsecond); + } + return $time; + } + public function readBytes($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagBytes); + $count = (int)($this->stream->readuntil(HproseTags::TagQuote)); + $bytes = $this->stream->read($count); + $this->stream->skip(1); + return $bytes; + } + public function readUTF8Char($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagUTF8Char); + $c = $this->stream->getc(); + $s = $c; + $a = ord($c); + if (($a & 0xE0) == 0xC0) { + $s .= $this->stream->getc(); + } + elseif (($a & 0xF0) == 0xE0) { + $s .= $this->stream->read(2); + } + elseif ($a > 0x7F) { + throw new HproseException("bad utf-8 encoding"); + } + return $s; + } + public function readString($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagString); + $len = (int)$this->stream->readuntil(HproseTags::TagQuote); + $this->stream->mark(); + $utf8len = 0; + for ($i = 0; $i < $len; ++$i) { + switch (ord($this->stream->getc()) >> 4) { + case 0: + case 1: + case 2: + case 3: + case 4: + case 5: + case 6: + case 7: { + // 0xxx xxxx + $utf8len++; + break; + } + case 12: + case 13: { + // 110x xxxx 10xx xxxx + $this->stream->skip(1); + $utf8len += 2; + break; + } + case 14: { + // 1110 xxxx 10xx xxxx 10xx xxxx + $this->stream->skip(2); + $utf8len += 3; + break; + } + case 15: { + // 1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + $this->stream->skip(3); + $utf8len += 4; + ++$i; + break; + } + default: { + throw new HproseException('bad utf-8 encoding'); + } + } + } + $this->stream->reset(); + $this->stream->unmark(); + $s = $this->stream->read($utf8len); + $this->stream->skip(1); + return $s; + } + public function readGuid($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagGuid); + $this->stream->skip(1); + $s = $this->stream->read(36); + $this->stream->skip(1); + return $s; + } + protected function &readListBegin() { + $list = array(); + return $list; + } + protected function &readListEnd(&$list) { + $count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace); + for ($i = 0; $i < $count; ++$i) { + $list[] = &$this->unserialize(); + } + $this->stream->skip(1); + return $list; + } + public function &readList($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagList); + $list = &$this->readListBegin(); + return $this->readListEnd($list); + } + protected function &readMapBegin() { + $map = array(); + return $map; + } + protected function &readMapEnd(&$map) { + $count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace); + for ($i = 0; $i < $count; ++$i) { + $key = &$this->unserialize(); + $map[$key] = &$this->unserialize(); + } + $this->stream->skip(1); + return $map; + } + public function &readMap($includeTag = false) { + if ($includeTag) $this->checkTag(HproseTags::TagMap); + $map = &$this->readMapBegin(); + return $this->readMapEnd($map); + } + protected function readObjectBegin() { + list($classname, $fields) = $this->classref[(int)$this->stream->readuntil(HproseTags::TagOpenbrace)]; + $object = new $classname; + return array($object, $fields); + } + protected function readObjectEnd($object, $fields) { + $count = count($fields); + if (class_exists('ReflectionClass')) { + $reflector = new ReflectionClass($object); + for ($i = 0; $i < $count; ++$i) { + $field = $fields[$i]; + if ($reflector->hasProperty($field)) { + $property = $reflector->getProperty($field); + $property->setAccessible(true); + $property->setValue($object, $this->unserialize()); + } + else { + $object->$field = &$this->unserialize(); + } + } + } + else { + for ($i = 0; $i < $count; ++$i) { + $object->$fields[$i] = &$this->unserialize(); + } + } + $this->stream->skip(1); + return $object; + } + public function readObject($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagClass, HproseTags::TagObject)); + if ($tag == HproseTags::TagClass) { + $this->readClass(); + return $this->readObject(true); + } + } + list($object, $fields) = $this->readObjectBegin(); + return $this->readObjectEnd($object, $fields); + } + protected function readClass() { + $classname = HproseClassManager::getClass(self::readString()); + $count = (int)$this->stream->readuntil(HproseTags::TagOpenbrace); + $fields = array(); + for ($i = 0; $i < $count; ++$i) { + $fields[] = $this->readString(true); + } + $this->stream->skip(1); + $this->classref[] = array($classname, $fields); + } + public function reset() { + $this->classref = array(); + } +} + +class HproseReader extends HproseSimpleReader { + private $ref; + function __construct(&$stream) { + parent::__construct($stream); + $this->ref = array(); + } + public function &unserialize($tag = NULL) { + if (is_null($tag)) { + $tag = $this->stream->getc(); + } + if ($tag == HproseTags::TagRef) { + return $this->readRef(); + } + return parent::unserialize($tag); + } + public function readDate($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagDate, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $date = parent::readDate(); + $this->ref[] = $date; + return $date; + } + public function readTime($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagTime, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $time = parent::readTime(); + $this->ref[] = $time; + return $time; + } + public function readBytes($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagBytes, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $bytes = parent::readBytes(); + $this->ref[] = $bytes; + return $bytes; + } + public function readString($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagString, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $str = parent::readString(); + $this->ref[] = $str; + return $str; + } + public function readGuid($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagGuid, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $guid = parent::readGuid(); + $this->ref[] = $guid; + return $guid; + } + public function &readList($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagList, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $list = &$this->readListBegin(); + $this->ref[] = &$list; + return $this->readListEnd($list); + } + public function &readMap($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagMap, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + } + $map = &$this->readMapBegin(); + $this->ref[] = &$map; + return $this->readMapEnd($map); + } + public function readObject($includeTag = false) { + if ($includeTag) { + $tag = $this->checkTags(array(HproseTags::TagClass, HproseTags::TagObject, HproseTags::TagRef)); + if ($tag == HproseTags::TagRef) return $this->readRef(); + if ($tag == HproseTags::TagClass) { + $this->readClass(); + return $this->readObject(true); + } + } + list($object, $fields) = $this->readObjectBegin(); + $this->ref[] = $object; + return $this->readObjectEnd($object, $fields); + } + private function &readRef() { + $ref = &$this->ref[(int)$this->stream->readuntil(HproseTags::TagSemicolon)]; + if (gettype($ref) == 'array') { + $result = &$ref; + } + else { + $result = $ref; + } + return $result; + } + public function reset() { + parent::reset(); + $this->ref = array(); + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseTags.php b/ThinkPHP/Library/Vendor/Hprose/HproseTags.php new file mode 100644 index 0000000..c1d6430 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseTags.php @@ -0,0 +1,62 @@ + * + * * +\**********************************************************/ + +class HproseTags { + /* Serialize Tags */ + const TagInteger = 'i'; + const TagLong = 'l'; + const TagDouble = 'd'; + const TagNull = 'n'; + const TagEmpty = 'e'; + const TagTrue = 't'; + const TagFalse = 'f'; + const TagNaN = 'N'; + const TagInfinity = 'I'; + const TagDate = 'D'; + const TagTime = 'T'; + const TagUTC = 'Z'; + const TagBytes = 'b'; + const TagUTF8Char = 'u'; + const TagString = 's'; + const TagGuid = 'g'; + const TagList = 'a'; + const TagMap = 'm'; + const TagClass = 'c'; + const TagObject = 'o'; + const TagRef = 'r'; + /* Serialize Marks */ + const TagPos = '+'; + const TagNeg = '-'; + const TagSemicolon = ';'; + const TagOpenbrace = '{'; + const TagClosebrace = '}'; + const TagQuote = '"'; + const TagPoint = '.'; + /* Protocol Tags */ + const TagFunctions = 'F'; + const TagCall = 'C'; + const TagResult = 'R'; + const TagArgument = 'A'; + const TagError = 'E'; + const TagEnd = 'z'; +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/Hprose/HproseWriter.php b/ThinkPHP/Library/Vendor/Hprose/HproseWriter.php new file mode 100644 index 0000000..6ec9d79 --- /dev/null +++ b/ThinkPHP/Library/Vendor/Hprose/HproseWriter.php @@ -0,0 +1,301 @@ + * + * * +\**********************************************************/ + +require_once('HproseCommon.php'); +require_once('HproseTags.php'); +require_once('HproseClassManager.php'); + +class HproseSimpleWriter { + public $stream; + private $classref; + private $fieldsref; + function __construct(&$stream) { + $this->stream = &$stream; + $this->classref = array(); + $this->fieldsref = array(); + } + public function serialize(&$var) { + if ((!isset($var)) || ($var === NULL)) { + $this->writeNull(); + } + elseif (is_scalar($var)) { + if (is_int($var)) { + $this->writeInteger($var); + } + elseif (is_bool($var)) { + $this->writeBoolean($var); + } + elseif (is_float($var)) { + $this->writeDouble($var); + } + elseif (is_string($var)) { + if ($var === '') { + $this->writeEmpty(); + } + elseif ((strlen($var) < 4) && is_utf8($var) && (ustrlen($var) == 1)) { + $this->writeUTF8Char($var); + } + elseif (is_utf8($var)) { + $this->writeString($var, true); + } + else { + $this->writeBytes($var, true); + } + } + } + elseif (is_array($var)) { + if (is_list($var)) { + $this->writeList($var, true); + } + else { + $this->writeMap($var, true); + } + } + elseif (is_object($var)) { + if ($var instanceof stdClass) { + $this->writeStdObject($var, true); + } + elseif (($var instanceof HproseDate) || ($var instanceof HproseDateTime)) { + $this->writeDate($var, true); + } + elseif ($var instanceof HproseTime) { + $this->writeTime($var, true); + } + else { + $this->writeObject($var, true); + } + } + else { + throw new HproseException('Not support to serialize this data'); + } + } + public function writeInteger($integer) { + if ($integer >= 0 && $integer <= 9) { + $this->stream->write((string)$integer); + } + else { + $this->stream->write(HproseTags::TagInteger . $integer . HproseTags::TagSemicolon); + } + } + public function writeLong($long) { + if ($long >= '0' && $long <= '9') { + $this->stream->write($long); + } + else { + $this->stream->write(HproseTags::TagLong . $long . HproseTags::TagSemicolon); + } + } + public function writeDouble($double) { + if (is_nan($double)) { + $this->writeNaN(); + } + elseif (is_infinite($double)) { + $this->writeInfinity($double > 0); + } + else { + $this->stream->write(HproseTags::TagDouble . $double . HproseTags::TagSemicolon); + } + } + public function writeNaN() { + $this->stream->write(HproseTags::TagNaN); + } + public function writeInfinity($positive = true) { + $this->stream->write(HproseTags::TagInfinity . ($positive ? HproseTags::TagPos : HproseTags::TagNeg)); + } + public function writeNull() { + $this->stream->write(HproseTags::TagNull); + } + public function writeEmpty() { + $this->stream->write(HproseTags::TagEmpty); + } + public function writeBoolean($bool) { + $this->stream->write($bool ? HproseTags::TagTrue : HproseTags::TagFalse); + } + public function writeDate($date, $checkRef = false) { + if ($date->utc) { + $this->stream->write(HproseTags::TagDate . $date->toString(false)); + } + else { + $this->stream->write(HproseTags::TagDate . $date->toString(false) . HproseTags::TagSemicolon); + } + } + public function writeTime($time, $checkRef = false) { + if ($time->utc) { + $this->stream->write(HproseTags::TagTime . $time->toString(false)); + } + else { + $this->stream->write(HproseTags::TagTime . $time->toString(false) . HproseTags::TagSemicolon); + } + } + public function writeBytes($bytes, $checkRef = false) { + $len = strlen($bytes); + $this->stream->write(HproseTags::TagBytes); + if ($len > 0) $this->stream->write((string)$len); + $this->stream->write(HproseTags::TagQuote . $bytes . HproseTags::TagQuote); + } + public function writeUTF8Char($char) { + $this->stream->write(HproseTags::TagUTF8Char . $char); + } + public function writeString($str, $checkRef = false) { + $len = ustrlen($str); + $this->stream->write(HproseTags::TagString); + if ($len > 0) $this->stream->write((string)$len); + $this->stream->write(HproseTags::TagQuote . $str . HproseTags::TagQuote); + } + public function writeList(&$list, $checkRef = false) { + $count = count($list); + $this->stream->write(HproseTags::TagList); + if ($count > 0) $this->stream->write((string)$count); + $this->stream->write(HproseTags::TagOpenbrace); + for ($i = 0; $i < $count; ++$i) { + $this->serialize($list[$i]); + } + $this->stream->write(HproseTags::TagClosebrace); + } + public function writeMap(&$map, $checkRef = false) { + $count = count($map); + $this->stream->write(HproseTags::TagMap); + if ($count > 0) $this->stream->write((string)$count); + $this->stream->write(HproseTags::TagOpenbrace); + foreach ($map as $key => &$value) { + $this->serialize($key); + $this->serialize($value); + } + $this->stream->write(HproseTags::TagClosebrace); + } + public function writeStdObject($obj, $checkRef = false) { + $map = (array)$obj; + self::writeMap($map); + } + protected function writeObjectBegin($obj) { + $class = get_class($obj); + $alias = HproseClassManager::getClassAlias($class); + $fields = array_keys((array)$obj); + if (array_key_exists($alias, $this->classref)) { + $index = $this->classref[$alias]; + } + else { + $index = $this->writeClass($alias, $fields); + } + return $index; + } + protected function writeObjectEnd($obj, $index) { + $fields = $this->fieldsref[$index]; + $count = count($fields); + $this->stream->write(HproseTags::TagObject . $index . HproseTags::TagOpenbrace); + $array = (array)$obj; + for ($i = 0; $i < $count; ++$i) { + $this->serialize($array[$fields[$i]]); + } + $this->stream->write(HproseTags::TagClosebrace); + } + public function writeObject($obj, $checkRef = false) { + $this->writeObjectEnd($obj, $this->writeObjectBegin($obj)); + } + protected function writeClass($alias, $fields) { + $len = ustrlen($alias); + $this->stream->write(HproseTags::TagClass . $len . + HproseTags::TagQuote . $alias . HproseTags::TagQuote); + $count = count($fields); + if ($count > 0) $this->stream->write((string)$count); + $this->stream->write(HproseTags::TagOpenbrace); + for ($i = 0; $i < $count; ++$i) { + $field = $fields[$i]; + if ($field{0} === "\0") { + $field = substr($field, strpos($field, "\0", 1) + 1); + } + $this->writeString($field); + } + $this->stream->write(HproseTags::TagClosebrace); + $index = count($this->fieldsref); + $this->classref[$alias] = $index; + $this->fieldsref[$index] = $fields; + return $index; + } + public function reset() { + $this->classref = array(); + $this->fieldsref = array(); + } +} +class HproseWriter extends HproseSimpleWriter { + private $ref; + private $arrayref; + function __construct(&$stream) { + parent::__construct($stream); + $this->ref = array(); + $this->arrayref = array(); + } + private function writeRef(&$obj, $checkRef, $writeBegin, $writeEnd) { + if (is_string($obj)) { + $key = 's_' . $obj; + } + elseif (is_array($obj)) { + if (($i = array_ref_search($obj, $this->arrayref)) === false) { + $i = count($this->arrayref); + $this->arrayref[$i] = &$obj; + } + $key = 'a_' . $i; + } + else { + $key = 'o_' . spl_object_hash($obj); + } + if ($checkRef && array_key_exists($key, $this->ref)) { + $this->stream->write(HproseTags::TagRef . $this->ref[$key] . HproseTags::TagSemicolon); + } + else { + $result = $writeBegin ? call_user_func_array($writeBegin, array(&$obj)) : false; + $index = count($this->ref); + $this->ref[$key] = $index; + call_user_func_array($writeEnd, array(&$obj, $result)); + } + } + public function writeDate($date, $checkRef = false) { + $this->writeRef($date, $checkRef, NULL, array(&$this, 'parent::writeDate')); + } + public function writeTime($time, $checkRef = false) { + $this->writeRef($time, $checkRef, NULL, array(&$this, 'parent::writeTime')); + } + public function writeBytes($bytes, $checkRef = false) { + $this->writeRef($bytes, $checkRef, NULL, array(&$this, 'parent::writeBytes')); + } + public function writeString($str, $checkRef = false) { + $this->writeRef($str, $checkRef, NULL, array(&$this, 'parent::writeString')); + } + public function writeList(&$list, $checkRef = false) { + $this->writeRef($list, $checkRef, NULL, array(&$this, 'parent::writeList')); + } + public function writeMap(&$map, $checkRef = false) { + $this->writeRef($map, $checkRef, NULL, array(&$this, 'parent::writeMap')); + } + public function writeStdObject($obj, $checkRef = false) { + $this->writeRef($obj, $checkRef, NULL, array(&$this, 'parent::writeStdObject')); + } + public function writeObject($obj, $checkRef = false) { + $this->writeRef($obj, $checkRef, array(&$this, 'writeObjectBegin'), array(&$this, 'writeObjectEnd')); + } + public function reset() { + parent::reset(); + $this->ref = array(); + $this->arrayref = array(); + } +} +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/README.txt b/ThinkPHP/Library/Vendor/README.txt new file mode 100644 index 0000000..88cafc0 --- /dev/null +++ b/ThinkPHP/Library/Vendor/README.txt @@ -0,0 +1 @@ +第三方类库包目录 \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplate.php b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplate.php new file mode 100644 index 0000000..e245e38 --- /dev/null +++ b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplate.php @@ -0,0 +1,392 @@ +assign( 'TITLE', 'TemplateDemo - Userlist' ); + * $page->assign( 'user', DB_read_all( 'select * from ris_user' ) ); + * $page->output(); + * + * Usage Example II: + * + * $data = array( + * 'TITLE' => 'TemplateDemo - Userlist', + * 'user' => DB_read_all( 'select * from ris_user' ) + * ); + * $page = new SmartTemplate( "template.html" ); + * $page->output( $data ); + * + * + * @author Philipp v. Criegern philipp@criegern.com + * @author Manuel 'EndelWar' Dalla Lana endelwar@aregar.it + * @version 1.2.1 03.07.2006 + * + * CVS ID: $Id: class.smarttemplate.php 2504 2011-12-28 07:35:29Z liu21st $ + */ + class SmartTemplate + { + /** + * Whether to store compiled php code or not (for debug purpose) + * + * @access public + */ + var $reuse_code = true; + + /** + * Directory where all templates are stored + * Can be overwritten by global configuration array $_CONFIG['template_dir'] + * + * @access public + */ + var $template_dir = 'templates/'; + + /** + * Where to store compiled templates + * Can be overwritten by global configuration array $_CONFIG['smarttemplate_compiled'] + * + * @access public + */ + var $temp_dir = 'templates_c/'; + + /** + * Temporary folder for output cache storage + * Can be overwritten by global configuration array $_CONFIG['smarttemplate_cache'] + * + * @access public + */ + var $cache_dir = 'templates_c/'; + + /** + * Default Output Cache Lifetime in Seconds + * Can be overwritten by global configuration array $_CONFIG['cache_lifetime'] + * + * @access public + */ + var $cache_lifetime = 600; + + /** + * Temporary file for output cache storage + * + * @access private + */ + var $cache_filename; + + /** + * The template filename + * + * @access private + */ + var $tpl_file; + + /** + * The compiled template filename + * + * @access private + */ + var $cpl_file; + + /** + * Template content array + * + * @access private + */ + var $data = array(); + + /** + * Parser Class + * + * @access private + */ + var $parser; + + /** + * Debugger Class + * + * @access private + */ + var $debugger; + + /** + * SmartTemplate Constructor + * + * @access public + * @param string $template_filename Template Filename + */ + function SmartTemplate ( $template_filename = '' ) + { + global $_CONFIG; + + if (!empty($_CONFIG['smarttemplate_compiled'])) + { + $this->temp_dir = $_CONFIG['smarttemplate_compiled']; + } + if (!empty($_CONFIG['smarttemplate_cache'])) + { + $this->cache_dir = $_CONFIG['smarttemplate_cache']; + } + if (is_numeric($_CONFIG['cache_lifetime'])) + { + $this->cache_lifetime = $_CONFIG['cache_lifetime']; + } + if (!empty($_CONFIG['template_dir']) && is_file($_CONFIG['template_dir'] . '/' . $template_filename)) + { + $this->template_dir = $_CONFIG['template_dir']; + } + $this->tpl_file = $template_filename; + } + + // DEPRECATED METHODS + // Methods used in older parser versions, soon will be removed + function set_templatefile ($template_filename) { $this->tpl_file = $template_filename; } + function add_value ($name, $value ) { $this->assign($name, $value); } + function add_array ($name, $value ) { $this->append($name, $value); } + + + /** + * Assign Template Content + * + * Usage Example: + * $page->assign( 'TITLE', 'My Document Title' ); + * $page->assign( 'userlist', array( + * array( 'ID' => 123, 'NAME' => 'John Doe' ), + * array( 'ID' => 124, 'NAME' => 'Jack Doe' ), + * ); + * + * @access public + * @param string $name Parameter Name + * @param mixed $value Parameter Value + * @desc Assign Template Content + */ + function assign ( $name, $value = '' ) + { + if (is_array($name)) + { + foreach ($name as $k => $v) + { + $this->data[$k] = $v; + } + } + else + { + $this->data[$name] = $value; + } + } + + + /** + * Assign Template Content + * + * Usage Example: + * $page->append( 'userlist', array( 'ID' => 123, 'NAME' => 'John Doe' ) ); + * $page->append( 'userlist', array( 'ID' => 124, 'NAME' => 'Jack Doe' ) ); + * + * @access public + * @param string $name Parameter Name + * @param mixed $value Parameter Value + * @desc Assign Template Content + */ + function append ( $name, $value ) + { + if (is_array($value)) + { + $this->data[$name][] = $value; + } + elseif (!is_array($this->data[$name])) + { + $this->data[$name] .= $value; + } + } + + + /** + * Parser Wrapper + * Returns Template Output as a String + * + * @access public + * @param array $_top Content Array + * @return string Parsed Template + * @desc Output Buffer Parser Wrapper + */ + function result ( $_top = '' ) + { + ob_start(); + $this->output( $_top ); + $result = ob_get_contents(); + ob_end_clean(); + return $result; + } + + + /** + * Execute parsed Template + * Prints Parsing Results to Standard Output + * + * @access public + * @param array $_top Content Array + * @desc Execute parsed Template + */ + function output ( $_top = '' ) + { + global $_top; + + // Make sure that folder names have a trailing '/' + if (strlen($this->template_dir) && substr($this->template_dir, -1) != '/') + { + $this->template_dir .= '/'; + } + if (strlen($this->temp_dir) && substr($this->temp_dir, -1) != '/') + { + $this->temp_dir .= '/'; + } + // Prepare Template Content + if (!is_array($_top)) + { + if (strlen($_top)) + { + $this->tpl_file = $_top; + } + $_top = $this->data; + } + $_obj = &$_top; + $_stack_cnt = 0; + $_stack[$_stack_cnt++] = $_obj; + + // Check if template is already compiled + $cpl_file_name = preg_replace('/[:\/.\\\\]/', '_', $this->tpl_file); + if (strlen($cpl_file_name) > 0) + { + $this->cpl_file = $this->temp_dir . $cpl_file_name . '.php'; + $compile_template = true; + if ($this->reuse_code) + { + if (is_file($this->cpl_file)) + { + if ($this->mtime($this->cpl_file) > $this->mtime($this->template_dir . $this->tpl_file)) + { + $compile_template = false; + } + } + } + if ($compile_template) + { + if (@include_once("class.smarttemplateparser.php")) + { + $this->parser = new SmartTemplateParser($this->template_dir . $this->tpl_file); + if (!$this->parser->compile($this->cpl_file)) + { + exit( "SmartTemplate Parser Error: " . $this->parser->error ); + } + } + else + { + exit( "SmartTemplate Error: Cannot find class.smarttemplateparser.php; check SmartTemplate installation"); + } + } + // Execute Compiled Template + include($this->cpl_file); + } + else + { + exit( "SmartTemplate Error: You must set a template file name"); + } + // Delete Global Content Array in order to allow multiple use of SmartTemplate class in one script + unset ($_top); + } + + + /** + * Debug Template + * + * @access public + * @param array $_top Content Array + * @desc Debug Template + */ + function debug ( $_top = '' ) + { + // Prepare Template Content + if (!$_top) + { + $_top = $this->data; + } + if (@include_once("class.smarttemplatedebugger.php")) + { + $this->debugger = new SmartTemplateDebugger($this->template_dir . $this->tpl_file); + $this->debugger->start($_top); + } + else + { + exit( "SmartTemplate Error: Cannot find class.smarttemplatedebugger.php; check SmartTemplate installation"); + } + } + + + /** + * Start Ouput Content Buffering + * + * Usage Example: + * $page = new SmartTemplate('template.html'); + * $page->use_cache(); + * ... + * + * @access public + * @desc Output Cache + */ + function use_cache ( $key = '' ) + { + if (empty($_POST)) + { + $this->cache_filename = $this->cache_dir . 'cache_' . md5($_SERVER['REQUEST_URI'] . serialize($key)) . '.ser'; + if (($_SERVER['HTTP_CACHE_CONTROL'] != 'no-cache') && ($_SERVER['HTTP_PRAGMA'] != 'no-cache') && @is_file($this->cache_filename)) + { + if ((time() - filemtime($this->cache_filename)) < $this->cache_lifetime) + { + readfile($this->cache_filename); + exit; + } + } + ob_start( array( &$this, 'cache_callback' ) ); + } + } + + + /** + * Output Buffer Callback Function + * + * @access private + * @param string $output + * @return string $output + */ + function cache_callback ( $output ) + { + if ($hd = @fopen($this->cache_filename, 'w')) + { + fputs($hd, $output); + fclose($hd); + } + return $output; + } + + + /** + * Determine Last Filechange Date (if File exists) + * + * @access private + * @param string $filename + * @return mixed + * @desc Determine Last Filechange Date + */ + function mtime ( $filename ) + { + if (@is_file($filename)) + { + $ret = filemtime($filename); + return $ret; + } + } + } +?> \ No newline at end of file diff --git a/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php new file mode 100644 index 0000000..8a2ebf4 --- /dev/null +++ b/ThinkPHP/Library/Vendor/SmartTemplate/class.smarttemplatedebugger.php @@ -0,0 +1,456 @@ +filename = $template_filename; + + // Load Template + if ($hd = @fopen($template_filename, "r")) + { + $this->template = fread($hd, filesize($template_filename)); + fclose($hd); + } + else + { + $this->template = "SmartTemplate Debugger Error: File not found: '$template_filename'"; + } + $this->tab[0] = ''; + for ($i=1; $i < 10; $i++) { + $this->tab[$i] = str_repeat(' ', $i); + } + } + + + /** + * Main Template Parser + * + * @param string $compiled_template_filename Compiled Template Filename + * @desc Creates Compiled PHP Template + */ + function start ( $vars ) + { + $page = $this->template; + + $page = preg_replace("/()/", "\n$1\n", $page); + $page = preg_replace("/()/", "\n$1\n", $page); + $page = preg_replace("/()/", "\n$1\n", $page); + $page = preg_replace("/()/", "\n$1\n", $page); + $page = preg_replace("/()/", "\n$1\n", $page); + + $page = $this->highlight_html($page); + + $rows = explode("\n", $page); + $page_arr = array(); + $level = 0; + $blocklvl = 0; + $rowcnt = 0; + $spancnt = 0; + $offset = 22; + $lvl_block = array(); + $lvl_row = array(); + $lvl_typ = array(); + foreach ($rows as $row) + { + if ($row = trim($row)) + { + $closespan = false; + if (substr($row, $offset, 12) == '<!-- END ') + { + if ($level < 1) + { + $level++; + $error[$rowcnt] = "END Without BEGIN"; + } + elseif ($lvl_typ[$level] != 'BEGIN') + { + $error[$lvl_row[$level]] = "IF without ENDIF"; + $error[$rowcnt] = "END Without BEGIN"; + } + $blocklvl--; + $level--; + $closespan = true; + } + if (substr($row, $offset, 14) == '<!-- ENDIF ') + { + if ($level < 1) + { + $level++; + $error[$rowcnt] = "ENDIF Without IF"; + } + elseif ($lvl_typ[$level] != 'IF') + { + $error[$lvl_row[$level]] = "BEGIN without END"; + $error[$rowcnt] = "ENDIF Without IF"; + } + $closespan = true; + $level--; + } + if ($closespan) + { + $page_arr[$rowcnt-1] .= ''; + } + $this_row = $this->tab[$level] . $row; + if (substr($row, $offset, 12) == '<!-- ELSE') + { + if ($level < 1) + { + $error[$rowcnt] = "ELSE Without IF"; + } + elseif ($lvl_typ[$level] != 'IF') + { + $error[$rowcnt] = "ELSE Without IF"; + } + else + { + $this_row = $this->tab[$level-1] . $row; + } + } + if (substr($row, $offset, 14) == '<!-- BEGIN ') + { + if ($blocklvl == 0) + { + if ($lp = strpos($row, '-->')) + { + if ($blockname = trim(substr($row, $offset + 14, $lp -$offset -14))) + { + if ($nr = count($vars[$blockname])) + { + $this_row .= $this->toggleview("$nr Entries"); + } + else + { + $this_row .= $this->toggleview("Emtpy"); + } + } + } + } + else + { + $this_row .= $this->toggleview('['); + } + $blocklvl++; + $level++; + $lvl_row[$level] = $rowcnt; + $lvl_typ[$level] = 'BEGIN'; + } + elseif (substr($row, $offset, 11) == '<!-- IF ') + { + $level++; + $lvl_row[$level] = $rowcnt; + $lvl_typ[$level] = 'IF'; + $this_row .= $this->toggleview(); + } + $page_arr[] = $this_row; + $lvl_block[$rowcnt] = $blocklvl; + $rowcnt++; + } + } + if ($level > 0) + { + $error[$lvl_row[$level]] = "Block not closed"; + } + + $page = join("\n", $page_arr); + $rows = explode("\n", $page); + $cnt = count($rows); + + for ($i = 0; $i < $cnt; $i++) + { + // Add Errortext + if (isset($error)) + { + if ($err = $error[$i]) + { + $rows[$i] = '' . $rows[$i] . ' ERROR: ' . $err . '!'; + } + } + + // Replace Scalars + if (preg_match_all('/{([a-zA-Z0-9_. &;]+)}/', $rows[$i], $var)) + { + foreach ($var[1] as $tag) + { + $fulltag = $tag; + if ($delim = strpos($tag, ' > ')) + { + $tag = substr($tag, 0, $delim); + } + if (substr($tag, 0, 4) == 'top.') + { + $title = $this->tip($vars[substr($tag, 4)]); + } + elseif ($lvl_block[$i] == 0) + { + $title = $this->tip($vars[$tag]); + } + else + { + $title = '[BLOCK?]'; + } + $code = '{' . $fulltag . '}'; + $rows[$i] = str_replace('{'.$fulltag.'}', $code, $rows[$i]); + } + } + + // Replace Extensions + if (preg_match_all('/{([a-zA-Z0-9_]+):([^}]*)}/', $rows[$i], $var)) + { + foreach ($var[2] as $tmpcnt => $tag) + { + $fulltag = $tag; + if ($delim = strpos($tag, ' > ')) + { + $tag = substr($tag, 0, $delim); + } + if (strpos($tag, ',')) + { + list($tag, $addparam) = explode(',', $tag, 2); + } + $extension = $var[1][$tmpcnt]; + + if (substr($tag, 0, 4) == 'top.') + { + $title = $this->tip($vars[substr($tag, 4)]); + } + elseif ($lvl_block[$i] == 0) + { + $title = $this->tip($vars[$tag]); + } + else + { + $title = '[BLOCK?]'; + } + $code = '{' . $extension . ':' . $fulltag . '}'; + $rows[$i] = str_replace('{'.$extension . ':' . $fulltag .'}', $code, $rows[$i]); + } + } + + // 'IF nnn' Blocks + if (preg_match_all('/<!-- IF ([a-zA-Z0-9_.]+) -->/', $rows[$i], $var)) + { + foreach ($var[1] as $tag) + { + if (substr($tag, 0, 4) == 'top.') + { + $title = $this->tip($vars[substr($tag, 4)]); + } + elseif ($lvl_block[$i] == 0) + { + $title = $this->tip($vars[$tag]); + } + else + { + $title = '[BLOCK?]'; + } + $code = '<!-- IF ' . $tag . ' -->'; + $rows[$i] = str_replace("<!-- IF $tag -->", $code, $rows[$i]); + if ($title == '[NULL]') + { + $rows[$i] = str_replace('Hide', 'Show', $rows[$i]); + $rows[$i] = str_replace('block', 'none', $rows[$i]); + } + } + } + } + $page = join("
    ", $rows); + + // Print Header + echo ''; + + // Print Index + echo ''; + echo 'SmartTemplate Debugger
    '; + echo '