├── .gitignore ├── Src ├── img │ ├── bnt_bg.png │ └── gear_disable.png ├── css │ ├── zh-cn-system.css │ ├── reset.css │ └── table_form.css ├── index.php └── tree.class.php ├── .gitattributes ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | /.idea 2 | /.vscode 3 | /.image 4 | /Src/runtime/ 5 | /install.lock 6 | -------------------------------------------------------------------------------- /Src/img/bnt_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengcao/phpcms-tree/master/Src/img/bnt_bg.png -------------------------------------------------------------------------------- /Src/img/gear_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dengcao/phpcms-tree/master/Src/img/gear_disable.png -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=php 2 | *.css linguist-language=php 3 | *.html linguist-language=php 4 | *.php linguist-language=php -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phpcms-tree 无限级别分类 2 | 3 | phpcms-tree,是一个从PHPCMS v9最新版中提取出来的无限级别分类的源码,可以整合到任何项目中。 4 | 5 | ### 使用方法 6 | 7 | 参考Src/index.php里的实例。 8 | 9 | ### 赞助支持: 10 | 11 | 支持本程序,请到Gitee和GitHub给我们点Star! 12 | 13 | Gitee:https://gitee.com/dengzhenhua/phpcms-tree 14 | 15 | GitHub:https://github.com/dengcao/phpcms-tree 16 | 17 | 18 | ### 关于 19 | 20 | 开发:[邓草博客 blog.5300.cn](http://blog.5300.cn) 21 | 22 | 赞助:[品络互联 www.pinluo.com](http://www.pinluo.com)   [AI工具箱 5300.cn](http://5300.cn)   [汉语言文学网 hyywx.com](http://hyywx.com)   [雄马 xiongma.cn](http://xiongma.cn)   [优惠券 tm.gs](http://tm.gs) 23 | 24 | 25 | ### 图片预览 26 | 27 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0528/163033_ae7d7b47_7397417.png "1.png") 28 | ![输入图片说明](https://images.gitee.com/uploads/images/2020/0528/163042_0708d171_7397417.png "2.png") 29 | 30 | 31 | -------------------------------------------------------------------------------- /Src/css/zh-cn-system.css: -------------------------------------------------------------------------------- 1 | body{color:#444; height:100%;} 2 | a{text-decoration:none; color:#444} 3 | 4 | 5 | /*栏目菜单*/ 6 | .cat-menu{ width:180px; margin:10px 8px 0 0; } 7 | .cat-menu div.content{padding-left:8px} 8 | 9 | /*内容菜单*/ 10 | .content-menu{ padding:0 0 6px} 11 | .content-menu a:hover{text-decoration: none} 12 | .content-menu a em{display:inline-block;display:-moz-inline-stack;zoom:1;*display:inline;} 13 | .content-menu a.add,.content-menu a.add em, 14 | .content-menu a.on,.content-menu a.on em{background: url(../img/bnt_bg.png) no-repeat;height:28px; line-height:28px;*line-height:28px} 15 | .content-menu span{color:#ddd; padding:0 8px} 16 | .content-menu a{cursor:pointer;} 17 | .content-menu a.add{ padding:0 0 0 5px;} 18 | .content-menu a.add em{ padding:0 10px 0 5px;color:#fff;background-position: right top} 19 | .content-menu a.on{background-position: left -40px;*background-position: left -41px;_background-position: left -39px; color:#fff; padding:0 0 0 5px;} 20 | .content-menu a.on em{background-position: right -40px;*background-position: right -41px;_background-position: right -39px; padding:0 10px 0 5px} 21 | -------------------------------------------------------------------------------- /Src/css/reset.css: -------------------------------------------------------------------------------- 1 | body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;word-wrap:break-word} 2 | body,html,input{font:12px/1.5 tahoma,arial,\5b8b\4f53,sans-serif;} 3 | table{border-collapse:collapse;border-spacing:0;}img{border:none} 4 | pre {white-space: pre-wrap; /* css-3 */white-space: -moz-pre-wrap; /* Mozilla, since 1999 */white-space: -pre-wrap; /* Opera 4-6 */white-space: -o-pre-wrap; /* Opera 7 */ word-wrap: break-word; /* Internet Explorer 5.5+ */} 5 | h1,h2,h3,h4,h5,h6{font-size:100%;}input.dialog{height:0; height:0; font-size:0; line-height:0; border:none} 6 | h1{font-size:34px;}h2{font-size:26px;}h3{font-size:18px; }h4{font-size:16px;}h5{font-size:14px;}h6{font-size:12px;} 7 | input,label,img,th{vertical-align:middle;}.font-fixh{font-family: Georgia,Arial; color: #f00; font-size: 16px; font-weight: 700;}address,cite,dfn,em,var{font-style:normal;} 8 | code,kbd,pre,samp{font-family:courier new,courier,monospace;} 9 | input.button ,input.btn{padding:0.25em;width: auto;_width:0;overflow:visible !ie;} 10 | ul,ol,li{list-style:none;} 11 | a{text-decoration:none;} 12 | a:hover{text-decoration:underline;} 13 | .white,.white a{color:#fff}.blue,.blue a{color:#004499}.gray4,a.gray4{color:#999} 14 | .red, .red a, a.red{color:red;}.green{color:#0E774A} 15 | select optgroup{color:#CAC8BB;} 16 | header{ display:block} 17 | /*通用样式*/ 18 | .hidden{display:none;}.invisible{visibility:hidden;} 19 | .ib,.ib-a a{display:inline-block;zoom:1;*display:inline;} 20 | .clear:after,.main:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.clear,.main{display:inline-block;}/* Hides from IE-mac \*/* html .clear,* html .main{height:1%;}.clear,.main{display:block;} 21 | 22 | .f12{font-size: 12px}.f14{font-size: 14px}.f16{font-size: 16px}.f18{font-size:18px}.f20{font-size:20px} 23 | .lh20{line-height: 20px}.lh22{line-height: 22px}.lh24{line-height: 24px}.lh26{line-height: 26px}.lh28{line-height: 28px} 24 | .fb{ font-weight:bold}.fn{ font-weight:normal} 25 | .bk,.bk3,.bk6,.bk8,.bk10,.bk15,.bk20,.bk30{clear: both;font-size: 1px;height: 0;line-height: 1px} 26 | .bk3{height: 3px;}.bk6{height: 6px}.bk8{height: 8px}.bk10{height: 10px}.bk15{height: 15px}.bk20{height: 20px}.bk30{height: 30px} 27 | .row-2 li{ float:left; width:50%}.row-3 li{ float:left; width:33%}.row-4 li{ float:left; width:25%}.row-5 li{ float:left; width:20%} 28 | .cu,.cu-li li,.cu-span span {cursor: hand;!important;cursor: pointer} 29 | .text-c{text-align: center}.text-l{text-align: left}.text-r{text-align: right} 30 | .lf{float: left}.rt{float: right}.pr{ position:relative}.pa{ position:absolute} 31 | .img-wrap{border:1px solid #eee;text-align:center;overflow:hidden} 32 | .img-wrap a{display:table-cell;vertical-align:middle;*display:block; overflow:hidden; background-color:#fff} 33 | .img-wrap a:hover{ background-color:#e8eff6} 34 | .col-left{float:left} 35 | .col-auto{overflow:hidden;_zoom:1;_float:left;} 36 | .col-right{float:right} -------------------------------------------------------------------------------- /Src/css/table_form.css: -------------------------------------------------------------------------------- 1 | body fieldset{border:1px solid #D8D8D8; padding:10px;} 2 | body fieldset legend{padding:3px 8px;font-weight:700;border:1px solid #D8D8D8;background-color: #F9F9F9;} 3 | body fieldset.blue{border:1px solid #dce3ed} 4 | body fieldset.blue legend{padding:3px 8px;font-weight:700;color:#347add; background:none; border:none} 5 | .picBut {color:#FFF;float:left; text-align:center;font-weight:700;height:28px;line-height:26px;*line-height:30px;margin-right:10px;width:75px} 6 | .picBut a{color:#fff;text-decoration: none; width:75px; height:28px;display:inline-block;zoom:1;*display:inline;} 7 | 8 | .table-list td,.table-list th{padding-left:12px} 9 | .table-list thead th{ height:30px; background:#eef3f7; border-bottom:1px solid #d5dfe8; font-weight:normal} 10 | .table-list tbody td,.table-list .btn{border-bottom: #eee 1px solid; padding-top:5px; padding-bottom:5px} 11 | div.btn{background:#f6f6f6; padding:6px 12px 0 12px; height:30px;line-height:30px} 12 | .table-list tr:hover,.table-list table tbody tr:hover{ background:#fbffe4} 13 | .nHover tr:hover,.nHover tr:hover td{ background:none} 14 | .table-list .input-text-c{ padding:0; height:18px} 15 | .input-text-c{border:1px solid #A7A6AA;height:18px;padding:2px 0 0; text-align:center} 16 | .td-line{border:1px solid #eee} 17 | .td-line td,.td-line th{border:1px solid #eee} 18 | .button{background:#ddd;height:24px; border-top:0;border-left:0; border-bottom:1px solid #666; border-right:1px solid #666; padding:3px 6px; margin-right:5px} 19 | .table-list tr.on,.table-list tr.on td,.table-list tr.on th,.table-list td.on,.table-list th.on{background:#fdf9e5;} 20 | a.close-own{display:block; width:16px; height:16px;position: absolute;outline:none;right:7px; top:8px; text-indent:200px; overflow: hidden} 21 | a.close-own:hover{background-position: left -46px} 22 | /*通用表单*/ 23 | .common-form{} 24 | .common-form div.contentWrap{padding-right:20px} 25 | .common-form ul li{color:#444; clear:both; vertical-align:middle} 26 | .common-form ul li span.text{width:60px} 27 | .common-form .set{border:1px dashed #e0e7ed;zoom:1; background:#f2f7fb; padding:10px; font-size:12px; margin-bottom:10px} 28 | .common-form .set table td,.common-form .set table th{padding-left:12px} 29 | .common-form .set table th{font-weight:normal; text-align:left;padding:0 8px} 30 | .common-form .set table td{ padding:3px 0 3px 5px} 31 | .common-form .set table td input{ background-image:none; height:18px; font-size:12px} 32 | .input-text,.measure-input,textarea,input.date,input.endDate,.input-focus{border:1px solid #A7A6AA;height:18px;margin:0 5px 0 0;padding:2px 0 2px 5px;border: 1px solid #d0d0d0; font-family: Verdana, Geneva, sans-serif,"宋体";font-size:12px;} 33 | textarea,textarea.input-text,textarea.input-focus{font-size:12px;height:auto; padding:5px; margin:0;} 34 | select{ vertical-align:middle;background:none repeat scroll 0 0 #F9F9F9;border-color:#666666 #CCCCCC #CCCCCC #666666;border-style:solid;border-width:1px;color:#333;padding:2px;} 35 | .search-form{ margin-bottom:10px} 36 | /*表格表单*/ 37 | .table_form{font-size:12px} 38 | .table_form td{padding-left:12px} 39 | .table_form th{font-weight:normal; text-align:right;padding-right:10px; color:#777} 40 | .table_form td label{ vertical-align:middle} 41 | .table_form td,.table_form th{padding:4px 0 4px 8px} 42 | .table_form tbody td,.table_form tbody th{border-bottom:1px solid #eee; } 43 | .colorpanel tbody td,.colorpanel tbody th{ padding:0;border-bottom: none;} 44 | /*select美化*/ 45 | .js ul.newList {left:-9999px;} 46 | ul.newList * {margin:0; padding:0;} 47 | ul.newList {margin:0; padding:0; list-style:none; color:#000; background:#fff; position:absolute; border:1px solid #ccc; top:22px; left:0; overflow:auto; z-index:9999;} 48 | .newListSelected span {display:block;} 49 | ul.newList li a {padding:3px 8px;display:block;text-decoration: none;} 50 | .selectedTxt {overflow:hidden; height:16px; padding:0 23px 0 0;} 51 | .hiLite {background:#e0ebf4!important; color:#444!important;} 52 | .newListHover {background:#f2f7fb!important; color:#000!important; cursor:default;} 53 | .newListSelHover, .newListSelFocus {background-position:right -26px; cursor:default;} 54 | .newListOptionTitle {font-weight:bold;} 55 | .newListOptionTitle ul {margin:3px 0 0;} 56 | .newListOptionTitle li {font-weight:normal; border-left:1px solid #ccc;} 57 | -------------------------------------------------------------------------------- /Src/index.php: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 15 | 16 | PHPCMS 无限级别分类 - 后台管理中心 17 | 18 | 19 | 20 | 21 | 22 | 26 |
29 |
30 |
31 | 温馨提示:请在添加、修改栏目全部完成后,更新栏目缓存 32 |
33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | icon = array('   │ ','   ├─ ','   └─ '); 53 | $tree->nbsp = '   '; 54 | $categorys = array(); 55 | //读取缓存 56 | $result = include_once("category_content_1.cache.php"); 57 | $show_detail = count($result) < 500 ? 1 : 0; 58 | $parentid = $_GET['parentid'] ? intval($_GET['parentid']) : 0; 59 | $html_root = "/"; 60 | $types = array(0 => "内部栏目",1 => "单网页",2 => "外部链接"); 61 | if(!empty($result)) { 62 | foreach ($result as $r) { 63 | $r['modelname'] = "文章模型"; 64 | $r['str_manage'] = ''; 65 | if (!$show_detail) { 66 | if ($r['parentid'] != $parentid) continue; 67 | $r['parentid'] = 0; 68 | $r['str_manage'] .= '管理子栏目 | '; 69 | } 70 | $r['str_manage'] .= '添加子栏目 | '; 71 | 72 | $r['str_manage'] .= '修改 | 删除 | 批量移动'; 73 | $r['typename'] = $types[$r['type']]; 74 | $r['display_icon'] = $r['ismenu'] ? '' : ' '; 75 | if ($r['type'] || $r['child']) { 76 | $r['items'] = ''; 77 | } else { 78 | $r['items'] = $category_items[$r['modelid']][$r['catid']]; 79 | } 80 | $r['help'] = ''; 81 | $r['url'] = "访问"; 82 | $categorys[$r['catid']] = $r; 83 | } 84 | } 85 | 86 | $str = " 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | "; 97 | $tree->init($categorys); 98 | $categorys = $tree->get_tree(0, $str); 99 | //get_tree(父ID,格式化字符窜,默认选中哪个分类,修饰前缀,父级分类样式) 前面两个必填,后面三个可选 100 | ?> 101 | 102 | 103 |
排序catid栏目名称栏目类型所属模型数据量访问域名绑定须知管理操作
\$id\$spacer\$catname\$display_icon\$typename\$modelname\$items\$url\$help\$str_manage
104 | 105 |
106 | 107 |
108 |
109 | 110 |
111 | 112 |

113 |
114 | 多选框: 115 | icon = array('  │ ','  ├─ ','  └─ '); 121 | $tree->nbsp = '  '; 122 | foreach($result as $cid=>$r) { 123 | $r['disabled'] = $r['child'] ? 'disabled' : ''; 124 | $r['selected'] = $cid == $catid ? 'selected' : ''; 125 | $categorys[$cid] = $r; 126 | } 127 | $str = ""; 128 | $tree->init($categorys); 129 | $string .= $tree->get_tree(0, $str); 130 | echo ""; 133 | ?> 134 |
135 | 136 |
137 | 单选框: 138 | \$spacer \$catname"; 140 | $source_string = ''; 141 | $tree->init($categorys); 142 | $source_string .= $tree->get_tree(0, $str); 143 | echo ""; 146 | ?> 147 |
148 | 149 | 150 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 木兰宽松许可证, 第2版 2 | 3 | 木兰宽松许可证, 第2版 4 | 2020年1月 http://license.coscl.org.cn/MulanPSL2 5 | 6 | 7 | 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: 8 | 9 | 0. 定义 10 | 11 | “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 12 | 13 | “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 14 | 15 | “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 16 | 17 | “法人实体”是指提交贡献的机构及其“关联实体”。 18 | 19 | “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 20 | 21 | 1. 授予版权许可 22 | 23 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 24 | 25 | 2. 授予专利许可 26 | 27 | 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 28 | 29 | 3. 无商标许可 30 | 31 | “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 32 | 33 | 4. 分发限制 34 | 35 | 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 36 | 37 | 5. 免责声明与责任限制 38 | 39 | “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 40 | 41 | 6. 语言 42 | “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 43 | 44 | 条款结束 45 | 46 | 如何将木兰宽松许可证,第2版,应用到您的软件 47 | 48 | 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: 49 | 50 | 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; 51 | 52 | 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; 53 | 54 | 3, 请将如下声明文本放入每个源文件的头部注释中。 55 | 56 | Copyright (c) [Year] [name of copyright holder] 57 | [Software Name] is licensed under Mulan PSL v2. 58 | You can use this software according to the terms and conditions of the Mulan PSL v2. 59 | You may obtain a copy of Mulan PSL v2 at: 60 | http://license.coscl.org.cn/MulanPSL2 61 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 62 | See the Mulan PSL v2 for more details. 63 | 64 | 65 | Mulan Permissive Software License,Version 2 66 | 67 | Mulan Permissive Software License,Version 2 (Mulan PSL v2) 68 | January 2020 http://license.coscl.org.cn/MulanPSL2 69 | 70 | Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: 71 | 72 | 0. Definition 73 | 74 | Software means the program and related documents which are licensed under this License and comprise all Contribution(s). 75 | 76 | Contribution means the copyrightable work licensed by a particular Contributor under this License. 77 | 78 | Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. 79 | 80 | Legal Entity means the entity making a Contribution and all its Affiliates. 81 | 82 | Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. 83 | 84 | 1. Grant of Copyright License 85 | 86 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. 87 | 88 | 2. Grant of Patent License 89 | 90 | Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. 91 | 92 | 3. No Trademark License 93 | 94 | No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. 95 | 96 | 4. Distribution Restriction 97 | 98 | You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. 99 | 100 | 5. Disclaimer of Warranty and Limitation of Liability 101 | 102 | THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 103 | 104 | 6. Language 105 | 106 | THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. 107 | 108 | END OF THE TERMS AND CONDITIONS 109 | 110 | How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software 111 | 112 | To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: 113 | 114 | i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; 115 | 116 | ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; 117 | 118 | iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. 119 | 120 | 121 | Copyright (c) [Year] [name of copyright holder] 122 | [Software Name] is licensed under Mulan PSL v2. 123 | You can use this software according to the terms and conditions of the Mulan PSL v2. 124 | You may obtain a copy of Mulan PSL v2 at: 125 | http://license.coscl.org.cn/MulanPSL2 126 | THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 127 | See the Mulan PSL v2 for more details. 128 | -------------------------------------------------------------------------------- /Src/tree.class.php: -------------------------------------------------------------------------------- 1 | array('id'=>'1','parentid'=>0,'name'=>'一级栏目一'), 33 | * 2 => array('id'=>'2','parentid'=>0,'name'=>'一级栏目二'), 34 | * 3 => array('id'=>'3','parentid'=>1,'name'=>'二级栏目一'), 35 | * 4 => array('id'=>'4','parentid'=>1,'name'=>'二级栏目二'), 36 | * 5 => array('id'=>'5','parentid'=>2,'name'=>'二级栏目三'), 37 | * 6 => array('id'=>'6','parentid'=>3,'name'=>'三级栏目一'), 38 | * 7 => array('id'=>'7','parentid'=>3,'name'=>'三级栏目二') 39 | * ) 40 | */ 41 | public function init($arr=array()){ 42 | $this->arr = $arr; 43 | $this->ret = ''; 44 | return is_array($arr); 45 | } 46 | 47 | /** 48 | * 得到父级数组 49 | * @param int 50 | * @return array 51 | */ 52 | public function get_parent($myid){ 53 | $newarr = array(); 54 | if(!isset($this->arr[$myid])) return false; 55 | $pid = $this->arr[$myid]['parentid']; 56 | $pid = $this->arr[$pid]['parentid']; 57 | if(is_array($this->arr)){ 58 | foreach($this->arr as $id => $a){ 59 | if($a['parentid'] == $pid) $newarr[$id] = $a; 60 | } 61 | } 62 | return $newarr; 63 | } 64 | 65 | /** 66 | * 得到子级数组 67 | * @param int 68 | * @return array 69 | */ 70 | public function get_child($myid){ 71 | $a = $newarr = array(); 72 | if(is_array($this->arr)){ 73 | foreach($this->arr as $id => $a){ 74 | if($a['parentid'] == $myid) $newarr[$id] = $a; 75 | } 76 | } 77 | return $newarr ? $newarr : false; 78 | } 79 | 80 | /** 81 | * 得到当前位置数组 82 | * @param int 83 | * @return array 84 | */ 85 | public function get_pos($myid,&$newarr){ 86 | $a = array(); 87 | if(!isset($this->arr[$myid])) return false; 88 | $newarr[] = $this->arr[$myid]; 89 | $pid = $this->arr[$myid]['parentid']; 90 | if(isset($this->arr[$pid])){ 91 | $this->get_pos($pid,$newarr); 92 | } 93 | if(is_array($newarr)){ 94 | krsort($newarr); 95 | foreach($newarr as $v){ 96 | $a[$v['id']] = $v; 97 | } 98 | } 99 | return $a; 100 | } 101 | 102 | /** 103 | * 得到树型结构 104 | * @param int ID,表示获得这个ID下的所有子级 105 | * @param string 生成树型结构的基本代码,例如:"" 106 | * @param int 被选中的ID,比如在做树型下拉框的时候需要用到 107 | * @return string 108 | */ 109 | public function get_tree($myid, $str, $sid = 0, $adds = '', $str_group = ''){ 110 | $number=1; 111 | $child = $this->get_child($myid); 112 | if(is_array($child)){ 113 | $total = count($child); 114 | foreach($child as $id=>$value){ 115 | $j=$k=''; 116 | if($number==$total){ 117 | $j .= $this->icon[2]; 118 | }else{ 119 | $j .= $this->icon[1]; 120 | $k = $adds ? $this->icon[0] : ''; 121 | } 122 | $spacer = $adds ? $adds.$j : ''; 123 | $selected = $id==$sid ? 'selected' : ''; 124 | @extract($value); 125 | $parentid == 0 && $str_group ? eval("\$nstr = \"$str_group\";") : eval("\$nstr = \"$str\";"); 126 | $this->ret .= $nstr; 127 | $nbsp = $this->nbsp; 128 | $this->get_tree($id, $str, $sid, $adds.$k.$nbsp,$str_group); 129 | $number++; 130 | } 131 | } 132 | return $this->ret; 133 | } 134 | /** 135 | * 同上一方法类似,但允许多选 136 | */ 137 | public function get_tree_multi($myid, $str, $sid = 0, $adds = ''){ 138 | $number=1; 139 | $child = $this->get_child($myid); 140 | if(is_array($child)){ 141 | $total = count($child); 142 | foreach($child as $id=>$a){ 143 | $j=$k=''; 144 | if($number==$total){ 145 | $j .= $this->icon[2]; 146 | }else{ 147 | $j .= $this->icon[1]; 148 | $k = $adds ? $this->icon[0] : ''; 149 | } 150 | $spacer = $adds ? $adds.$j : ''; 151 | 152 | $selected = $this->have($sid,$id) ? 'selected' : ''; 153 | @extract($a); 154 | eval("\$nstr = \"$str\";"); 155 | $this->ret .= $nstr; 156 | $this->get_tree_multi($id, $str, $sid, $adds.$k.' '); 157 | $number++; 158 | } 159 | } 160 | return $this->ret; 161 | } 162 | /** 163 | * @param integer $myid 要查询的ID 164 | * @param string $str 第一种HTML代码方式 165 | * @param string $str2 第二种HTML代码方式 166 | * @param integer $sid 默认选中 167 | * @param integer $adds 前缀 168 | */ 169 | public function get_tree_category($myid, $str, $str2, $sid = 0, $adds = ''){ 170 | $number=1; 171 | $child = $this->get_child($myid); 172 | if(is_array($child)){ 173 | $total = count($child); 174 | foreach($child as $id=>$a){ 175 | $j=$k=''; 176 | if($number==$total){ 177 | $j .= $this->icon[2]; 178 | }else{ 179 | $j .= $this->icon[1]; 180 | $k = $adds ? $this->icon[0] : ''; 181 | } 182 | $spacer = $adds ? $adds.$j : ''; 183 | 184 | $selected = $this->have($sid,$id) ? 'selected' : ''; 185 | @extract($a); 186 | if (empty($html_disabled)) { 187 | eval("\$nstr = \"$str\";"); 188 | } else { 189 | eval("\$nstr = \"$str2\";"); 190 | } 191 | $this->ret .= $nstr; 192 | $this->get_tree_category($id, $str, $str2, $sid, $adds.$k.' '); 193 | $number++; 194 | } 195 | } 196 | return $this->ret; 197 | } 198 | 199 | /** 200 | * 同上一类方法,jquery treeview 风格,可伸缩样式(需要treeview插件支持) 201 | * @param $myid 表示获得这个ID下的所有子级 202 | * @param $effected_id 需要生成treeview目录数的id 203 | * @param $str 末级样式 204 | * @param $str2 目录级别样式 205 | * @param $showlevel 直接显示层级数,其余为异步显示,0为全部限制 206 | * @param $style 目录样式 默认 filetree 可增加其他样式如'filetree treeview-famfamfam' 207 | * @param $currentlevel 计算当前层级,递归使用 适用改函数时不需要用该参数 208 | * @param $recursion 递归使用 外部调用时为FALSE 209 | */ 210 | function get_treeview($myid,$effected_id='example',$str="\$name", $str2="\$name" ,$showlevel = 0 ,$style='filetree ' , $currentlevel = 1,$recursion=FALSE) { 211 | $child = $this->get_child($myid); 212 | if(!defined('EFFECTED_INIT')){ 213 | $effected = ' id="'.$effected_id.'"'; 214 | define('EFFECTED_INIT', 1); 215 | } else { 216 | $effected = ''; 217 | } 218 | $placeholder = ''; 219 | if(!$recursion) $this->str .=''; 220 | foreach($child as $id=>$a) { 221 | 222 | @extract($a); 223 | if($showlevel > 0 && $showlevel == $currentlevel && $this->get_child($id)) $folder = 'hasChildren'; //如设置显示层级模式@2011.07.01 224 | $floder_status = isset($folder) ? ' class="'.$folder.'"' : ''; 225 | $this->str .= $recursion ? '': ''; 240 | } 241 | if(!$recursion) $this->str .=''; 242 | return $this->str; 243 | } 244 | 245 | /** 246 | * 获取子栏目json 247 | * Enter description here ... 248 | * @param unknown_type $myid 249 | */ 250 | public function creat_sub_json($myid, $str='') { 251 | $sub_cats = $this->get_child($myid); 252 | $n = 0; 253 | if(is_array($sub_cats)) foreach($sub_cats as $c) { 254 | $data[$n]['id'] = iconv(CHARSET,'utf-8',$c['catid']); 255 | if($this->get_child($c['catid'])) { 256 | $data[$n]['liclass'] = 'hasChildren'; 257 | $data[$n]['children'] = array(array('text'=>' ','classes'=>'placeholder')); 258 | $data[$n]['classes'] = 'folder'; 259 | $data[$n]['text'] = iconv(CHARSET,'utf-8',$c['catname']); 260 | } else { 261 | if($str) { 262 | @extract(array_iconv($c,CHARSET,'utf-8')); 263 | eval("\$data[$n]['text'] = \"$str\";"); 264 | } else { 265 | $data[$n]['text'] = iconv(CHARSET,'utf-8',$c['catname']); 266 | } 267 | } 268 | $n++; 269 | } 270 | return json_encode($data); 271 | } 272 | private function have($list,$item){ 273 | return(strpos(',,'.$list.',',','.$item.',')); 274 | } 275 | } 276 | ?> --------------------------------------------------------------------------------