destoon7.0后台栏目分类一键获取所有栏目拼音目录
近期研究DT,从DT4.0一直研究到DT7.0,总算也有些心得。最近重新开发设计了一个信息资讯站点:http://www.xuetong365.com/
废话不多说,上教程
用于DESTOON7.0系统
到admin 目录替换 category.inc.php
刷新后台,然后每个模块的栏目分类后面会多一个菜单-批量拼音目录,点这个就菜单就可以了
代码修改不陈述,直接上全部代码
以下为category.inc.php代码
<?php defined('DT_ADMIN') or exit('Access Denied');
$mid or $mid = 4;
$CATEGORY = cache_read('category-'.$mid.'.php');
$MOD = cache_read('module-'.$mid.'.php');
$NUM = count($CATEGORY);
$catid = isset($catid) ? intval($catid) : 0;
$do = new category($mid, $catid);
$parentid = isset($parentid) ? intval($parentid) : 0;
$table = $DT_PRE.'category';
$menus = array (
array('添加分类', '?file='.$file.'&action=add&mid='.$mid.'&parentid='.$parentid),
array('管理分类', '?file='.$file.'&mid='.$mid),
array('分类复制', '?file='.$file.'&action=copy&mid='.$mid),
array('更新缓存', '?file='.$file.'&action=caches&mid='.$mid),
array('更新地址', '?file='.$file.'&action=url&mid='.$mid),
array('更新统计', '?file='.$file.'&action=count&mid='.$mid),
array('批量索引', '?file='.$file.'&action=letters&mid='.$mid),
array('批量拼音目录', '?file='.$file.'&action=allletter&mid='.$mid),
);
if(strpos($forward, 'category') === false) $forward = '?file='.$file.'&mid='.$mid.'&parentid='.$parentid.'&kw='.urlencode($kw);
switch($action) {
case 'add':
if($submit) {
if(!$category['catname']) msg('分类名不能为空');
$category['catname'] = trim($category['catname']);
$childs = '';
$catids = array();
if(strpos($category['catname'], "\n") === false) {
$category['catdir'] = $do->get_catdir($category['catdir']);
$do->add($category);
$childs .= ','.$do->catid;
$catids[] = $do->catid;
} else {
$catnames = explode("\n", $category['catname']);
foreach($catnames as $catname) {
$catname = trim($catname);
if(!$catname) continue;
$category['catname'] = $catname;
$category['catdir'] = '';
$category['letter'] = '';
$category['seo_title'] = '';
$category['seo_keywords'] = '';
$category['seo_description'] = '';
$do->add($category);
$childs .= ','.$do->catid;
$catids[] = $do->catid;
}
}
if($category['parentid']) {
$parents = array();
$cid = $category['parentid'];
$parents[] = $cid;
while(1) {
if($CATEGORY[$cid]['parentid']) {
$parents[] = $cid = $CATEGORY[$cid]['parentid'];
} else {
break;
}
}
foreach($parents as $catid) {
$arrchildid = $CATEGORY[$catid]['child'] ? $CATEGORY[$catid]['arrchildid'].$childs : $catid.$childs;
$db->query("UPDATe {$table} SET child=1,arrchildid='$arrchildid' WHERe catid=$catid");
}
}
foreach($catids as $catid) {
$CATEGORY[$catid] = $db->get_one("SELECT * FROM {$table} WHERe catid=$catid");
update_category($CATEGORY[$catid]);
}
$NUM > 500 ? $do->cache() : $do->repair();
dmsg('添加成功', '?file='.$file.'&mid='.$mid.'&parentid='.$category['parentid']);
} else {
include tpl('category_add');
}
break;
case 'edit':
$catid or msg();
if($submit) {
if(!$category['catname']) msg('分类名不能为空');
if($category['parentid'] == $catid) msg('上级分类不能与当前分类相同');
$do->edit($category);
$category['catid'] = $catid;
update_category($category);
$NUM > 500 ? $do->cache() : $do->repair();
dmsg('修改成功', '?file='.$file.'&mid='.$mid.'&parentid='.$category['parentid']);
} else {
extract($db->get_one("SELECT * FROM {$table} WHERe catid=$catid"));
include tpl('category_edit');
}
break;
case 'copy':
if($submit) {
if(!$fromid) msg('源模块ID不能为空');
if(!$save) $db->query("DELETe FROM {$table} WHERe moduleid=$mid");
$result = $db->query("SELECt * FROM {$table} WHERe moduleid=$fromid ORDER BY catid");
$O = $R = array();
while($r = $db->fetch_array($result)) {
$O[$r['catid']] = $r['catname'];
$sqlk = $sqlv = '';
$catid = $r['catid'];
unset($r['catid']);
$r['moduleid'] = $mid;
$r['item'] = $r['property'] = 0;
$r = daddslashes($r);
foreach($r as $k=>$v) {
$sqlk .= ','.$k; $sqlv .= ",'$v'";
}
$sqlk = substr($sqlk, 1);
$sqlv = substr($sqlv, 1);
$db->query("INSERT INTO {$table} ($sqlk) VALUES ($sqlv)");
$R[$catid] = $db->insert_id();
}
$result = $db->query("SELECt * FROM {$table} WHERe moduleid='$mid' ORDER BY catid");
while($r = $db->fetch_array($result)) {
$catid = $r['catid'];
$v = $r['parentid'];
$parentid = isset($R[$v]) ? $R[$v] : $v;
$arrparentid = explode(',', $r['arrparentid']);
foreach($arrparentid as $k=>$v) {
if(isset($R[$v])) $arrparentid[$k] = $R[$v];
}
$arrparentid = implode(',', $arrparentid);
$arrchildid = explode(',', $r['arrchildid']);
foreach($arrchildid as $k=>$v) {
if(isset($R[$v])) $arrchildid[$k] = $R[$v];
}
$arrchildid = implode(',', $arrchildid);
$db->query("UPDATe {$table} SET parentid='$parentid',arrparentid='$arrparentid',arrchildid='$arrchildid' WHERe catid=$catid");
}
$do->repair();
msg('分类复制成功', '?file='.$file.'&action=url&&mid='.$mid.'&forward='.urlencode('?file='.$file.'&mid='.$mid));
} else {
include tpl('category_copy');
}
break;
case 'caches':
msg('开始更新统计', "?file=$file&mid=$mid&action=count");
break;
case 'count':
require DT_ROOT.'/include/module.func.php';
$tb = get_table($mid);
if($MODULE[$mid]['module'] == 'club') $tb = $DT_PRE.'club_group_'.$mid;
if(!isset($num)) {
$num = 50;
}
if(!isset($fid)) {
$r = $db->get_one("SELECT MIN(catid) AS fid FROM {$table} WHERe moduleid=$mid");
$fid = $r['fid'] ? $r['fid'] : 0;
}
isset($sid) or $sid = $fid;
if(!isset($tid)) {
$r = $db->get_one("SELECt MAX(catid) AS tid FROM {$table} WHERe moduleid=$mid");
$tid = $r['tid'] ? $r['tid'] : 0;
}
if($fid <= $tid) {
$result = $db->query("SELECt catid FROM {$table} WHERe moduleid=$mid AND catid>=$fid ORDER BY catid LIMIT 0,$num");
if($db->affected_rows($result)) {
while($r = $db->fetch_array($result)) {
$catid = $r['catid'];
if($mid == 4) {
$condition = "groupid>5 and catids like '%,".$catid.",%'";
} else {
$condition = 'status=3';
$condition .= $CATEGORY[$catid]['child'] ? " AND catid IN (".$CATEGORY[$catid]['arrchildid'].")" : " AND catid=$catid";
}
$item = $db->count($tb, $condition);
$db->query("UPDATe {$table} SET item=$item WHERe catid=$catid");
}
$catid += 1;
} else {
$catid = $fid + $num;
}
} else {
msg('统计更新成功', "?file=$file&mid=$mid&action=url");
}
msg('ID从'.$fid.'至'.($catid-1).'更新成功'.progress($sid, $fid, $tid), "?file=$file&mid=$mid&action=$action&sid=$sid&fid=$catid&tid=$tid&num=$num");
break;
case 'url':
foreach($CATEGORY as $c) {
update_category($c);
}
msg('地址更新成功', "?file=$file&mid=$mid&action=letters");
break;
case 'letters':
$update = false;
foreach($CATEGORY as $k=>$v) {
if(strlen($v['letter']) != 1) {
$letter = $do->get_letter($v['catname'], false);
if($letter) {
$update = true;
$letter = substr($letter, 0, 1);
$db->query("UPDATE {$table} SET letter='$letter' WHERe catid='$v[catid]'");
}
}
}
msg('索引修复成功', "?file=$file&mid=$mid&action=cache");
break;
case 'cache':
$do->repair();
dmsg('缓存更新成功', '?file='.$file.'&mid='.$mid);
break;
case 'delete':
if($catid) $catids = $catid;
$catids or msg('请选择分类');
$do->delete($catids);
$NUM > 500 ? $do->cache() : $do->repair();
dmsg('删除成功', $forward);
break;
case 'update':
if(!$category || !is_array($category)) msg();
$do->update($category);
foreach($category as $catid=>$v) {
$CATEGORY[$catid] = $db->get_one("SELECT * FROM {$table} WHERe catid=$catid");
update_category($CATEGORY[$catid]);
}
$NUM > 500 ? $do->cache() : $do->repair();
dmsg('更新成功', '?file='.$file.'&mid='.$mid.'&parentid='.$parentid);
break;
case 'letter':
isset($catname) or $catname = '';
if(!$catname || strpos($catname, "\n") !== false) exit('');
exit($do->get_letter($catname, false));
break;
case 'ckdir':
if($do->get_catdir($catdir)) {
dialog('目录名可以使用');
} else {
dialog('目录名不合法或者已经被使用');
}
break;
//20180603 S
case 'allletter':
$q=$db->query("select * from {$table} where moduleid='$mid'");
while($rs=$db->fetch_array($q)){
$lets = $do->get_letter($rs['catname'],false);
DB::query("UPDATe {$table} SET catdir='$lets' WHERe catid='$rs[catid]'");
}
dmsg('拼音目录修复成功', $forward);
break;
//20180603 E
default:
$total = 0;
$DTCAT = array();
$condition = "moduleid=$mid";
$condition .= $keyword ? " AND catname LIKE '%$keyword%'" : " AND parentid=$parentid";
$result = $db->query("SELECT * FROM {$table} WHERe $condition ORDER BY listorder,catid");
while($r = $db->fetch_array($result)) {
$r['childs'] = substr_count($r['arrchildid'], ',');
$total += $r['item'];
$DTCAT[$r['catid']] = $r;
}
if(!$DTCAT && !$parentid && !$keyword) msg('暂无分类,请先添加', '?file='.$file.'&mid='.$mid.'&action=add&parentid='.$parentid);
include tpl('category');
break;
} class category {
var $moduleid;
var $catid;
var $category = array();
var $table; function __construct($moduleid = 1, $catid = 0) {
global $CATEGORY;
$this->moduleid = $moduleid;
$this->catid = $catid;
if(!isset($CATEGORY)) $CATEGORY = cache_read('category-'.$this->moduleid.'.php');
$this->category = $CATEGORY;
$this->table = DT_PRE.'category';
} function category($moduleid = 1, $catid = 0) {
$this->__construct($moduleid, $catid);
} function add($category) {
$category['moduleid'] = $this->moduleid;
$category['letter'] = preg_match("/^[a-z]{1}+$/i", $category['letter']) ? strtolower($category['letter']) : '';
foreach(array('group_list', 'group_show', 'group_add') as $v) {
$category[$v] = isset($category[$v]) ? implode(',', $category[$v]) : '';
}
$sqlk = $sqlv = '';
foreach($category as $k=>$v) {
$sqlk .= ','.$k; $sqlv .= ",'$v'";
}
$sqlk = substr($sqlk, 1);
$sqlv = substr($sqlv, 1);
DB::query("INSERT INTO {$this->table} ($sqlk) VALUES ($sqlv)");
$this->catid = DB::insert_id();
if($category['parentid']) {
$category['catid'] = $this->catid;
$this->category[$this->catid] = $category;
$arrparentid = $this->get_arrparentid($this->catid, $this->category);
} else {
$arrparentid = 0;
}
$catdir = $category['catdir'] ? $category['catdir'] : $this->catid;
DB::query("UPDATe {$this->table} SET listorder=$this->catid,catdir='$catdir',arrparentid='$arrparentid' WHERe catid=$this->catid");
return true;
} function edit($category) {
$category['letter'] = preg_match("/^[a-z]{1}+$/i", $category['letter']) ? strtolower($category['letter']) : '';
if($category['parentid']) {
$category['catid'] = $this->catid;
$this->category[$this->catid] = $category;
$category['arrparentid'] = $this->get_arrparentid($this->catid, $this->category);
} else {
$category['arrparentid'] = 0;
}
foreach(array('group_list', 'group_show', 'group_add') as $v) {
$category[$v] = isset($category[$v]) ? implode(',', $category[$v]) : '';
}
$category['linkurl'] = '';
$sql = '';
foreach($category as $k=>$v) {
$sql .= ",$k='$v'";
}
$sql = substr($sql, 1);
DB::query("UPDATE {$this->table} SET $sql WHERe catid=$this->catid");
return true;
} function delete($catids) {
if(is_array($catids)) {
foreach($catids as $catid) {
if(isset($this->category[$catid])) $this->delete($catid);
}
} else {
$catid = $catids;
if(isset($this->category[$catid])) {
DB::query("DELETE FROM {$this->table} WHERe catid=$catid");
$arrchildid = $this->category[$catid]['arrchildid'] ? $this->category[$catid]['arrchildid'] : $catid;
DB::query("DELETe FROM {$this->table} WHERe catid IN ($arrchildid)");
if($this->moduleid > 4) DB::query("UPDATe ".get_table($this->moduleid)." SET status=0 WHERe catid IN (".$arrchildid.")");
}
}
return true;
} function update($category) {
if(!is_array($category)) return false;
foreach($category as $k=>$v) {
if(!$v['catname']) continue;
$v['parentid'] = intval($v['parentid']);
if($k == $v['parentid']) continue;
if($v['parentid'] > 0 && !isset($this->category[$v['parentid']])) continue;
$v['listorder'] = intval($v['listorder']);
$v['level'] = intval($v['level']);
$v['letter'] = preg_match("/^[a-z0-9]{1}+$/i", $v['letter']) ? strtolower($v['letter']) : '';
$v['catdir'] = $this->get_catdir($v['catdir'], $k);
if(!$v['catdir']) $v['catdir'] = $k;
DB::query("UPDATE {$this->table} SET catname='$v[catname]',parentid='$v[parentid]',listorder='$v[listorder]',style='$v[style]',level='$v[level]',letter='$v[letter]',catdir='$v[catdir]' WHERe catid=$k ");
}
return true;
} function repair() {
$query = DB::query("SELECT * FROM {$this->table} WHERe moduleid='$this->moduleid' ORDER BY listorder,catid");
$CATEGORY = array();
while($r = DB::fetch_array($query)) {
$CATEGORY[$r['catid']] = $r;
}
$childs = array();
foreach($CATEGORY as $catid => $category) {
$CATEGORY[$catid]['arrparentid'] = $arrparentid = $this->get_arrparentid($catid, $CATEGORY);
$CATEGORY[$catid]['catdir'] = $catdir = preg_match("/^[0-9a-z_\-\/]+$/i", $category['catdir']) ? $category['catdir'] : $catid;
$sql = "catdir='$catdir',arrparentid='$arrparentid'";
if(!$category['linkurl']) {
$CATEGORY[$catid]['linkurl'] = listurl($category);
$sql .= ",linkurl='$category[linkurl]'";
}
DB::query("UPDATe {$this->table} SET $sql WHERe catid=$catid");
if($arrparentid) {
$arr = explode(',', $arrparentid);
foreach($arr as $a) {
if($a == 0) continue;
isset($childs[$a]) or $childs[$a] = '';
$childs[$a] .= ','.$catid;
}
}
}
foreach($CATEGORY as $catid => $category) {
if(isset($childs[$catid])) {
$CATEGORY[$catid]['arrchildid'] = $arrchildid = $catid.$childs[$catid];
$CATEGORY[$catid]['child'] = 1;
DB::query("UPDATE {$this->table} SET arrchildid='$arrchildid',child=1 WHERe catid='$catid'");
} else {
$CATEGORY[$catid]['arrchildid'] = $catid;
$CATEGORY[$catid]['child'] = 0;
DB::query("UPDATE {$this->table} SET arrchildid='$catid',child=0 WHERe catid='$catid'");
}
}
$this->cache($CATEGORY);
return true;
} function get_arrparentid($catid, $CATEGORY) {
if($CATEGORY[$catid]['parentid'] && $CATEGORY[$catid]['parentid'] != $catid) {
$parents = array();
$cid = $catid;
while($catid) {
if($CATEGORY[$cid]['parentid']) {
$parents[] = $cid = $CATEGORY[$cid]['parentid'];
} else {
break;
}
}
$parents[] = 0;
return implode(',', array_reverse($parents));
} else {
return '0';
}
} function get_arrchildid($catid, $CATEGORY) {
$arrchildid = '';
foreach($CATEGORY as $category) {
if(strpos(','.$category['arrparentid'].',', ','.$catid.',') !== false) $arrchildid .= ','.$category['catid'];
}
return $arrchildid ? $catid.$arrchildid : $catid;
} function get_catdir($catdir, $catid = 0) {
if(preg_match("/^[0-9a-z_\-\/]+$/i", $catdir)) {
$condition = "catdir='$catdir' AND moduleid='$this->moduleid'";
if($catid) $condition .= " AND catid!=$catid";
$r = DB::get_one("SELECT catid FROM {$this->table} WHERe $condition");
if($r) {
return '';
} else {
return $catdir;
}
} else {
return '';
}
} function get_letter($catname, $letter = true) {
return $letter ? strtolower(substr(gb2py($catname), 0, 1)) : str_replace(' ', '', gb2py($catname));
} function cache($data = array()) {
cache_category($this->moduleid, $data);
}
}
?>
顺便在分享下自己做的 文学故事网:http://wenxue.xuetong365.com/
destoon7.0后台栏目分类一键获取所有栏目拼音目录的更多相关文章
- php+mysql网站无限级栏目分类-递归获取树形结构函数
如果网站采用了无限级栏目结构,我们可以将网站所有栏目获取出来组成一个树形结构.数据库结构: 函数代码: //获得指定文章分类的子分类组成的树形结构 function cateTree($pid=0,$ ...
- 5UCMS判断当前栏目高亮(用于当前所在栏目加背景图片或颜色)
5UCMS判断当前栏目高亮标签 比较简单的是频道页(channel.html): 大类代码: <!--menu:{ $row=10 $table=channel }--> <li { ...
- WordPress后台edit-tags.php里无限栏目分类实现
在 WordPress 里 http://localhost/wordpress3.6.1/wp-admin/edit-tags.php?taxonomy=category 这个链接可以显示 WP 里 ...
- 夺命雷公狗ThinkPHP项目之----企业网站24之网站前台获取当前栏目和顶级栏目
我们现在要实现的是取出网站当前栏目名称和顶级分类名称,如下所示: 列表页的和单页的不能总是写死的吧?? 我能就要想办法去让他变活的才可以解决问题噢,我们已经有了他的cate_id ,然后我们就可以通过 ...
- MVC4做网站后台:栏目管理2、修改栏目
接上节添加栏目. 修改栏目与添加栏目非常相似,主要区别在于先向视图传递要修改栏目的model.另外在保存时比添加栏目验证要更多一些. 1.要验证父栏目不能是其本身: 2.父栏目不能是其子栏目: 3.父 ...
- MVC4做网站后台:栏目管理1、添加栏目
把栏目添加删除跟前台混在一起结构清晰,现在有了后台管理的区域就把后台管理相关的代码分开. 要实现功能: 1.添加栏目 2.删除栏目 3.修改栏目信息 -- 一.开始 1.添加 接口InterfaceC ...
- DTCMS自定义标签,获取所有栏目文章列表TOP,以及文章通用URL
网站最近更新等地方,发现DTCMS没有获取所有栏目文章列表的标签,只能自己写 思路:获取所有栏目文章列表不难,难点在于linkurl的写法 1.制作获取所有文章列表标签 DTcms.Web.UI\La ...
- PHP 实现无限极栏目分类
首先,创建一个DB CREATE TABLE IF NOT EXISTS `class` ( `id` mediumint(6) NOT NULL AUTO_INCREMENT, `title` va ...
- [C#]Winform后台提交数据且获取远程接口返回的XML数据,转换成DataSet
#region 接口返回的Xml转换成DataSet /// <summary> /// 返回的Xml转换成DataSet /// </summary> /// <par ...
随机推荐
- 用vue实现列表分页和按钮操作
为中华之崛起而读书 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...
- Jackson 动态Bean
为了解决json字符串有很多属性, 但是不必每个属性都映射到pojo的属性. @JsonProperty : 标记一个方法是一个属性的getter或setter方法, 也即把java属性和json域关 ...
- 酷!微软发布新终端工具,Win 10 将自带 Linux 内核
原创:技术最前线(id:TopITNews) 北京时间 5 月 7 日,2019 年微软 Build 开发者大会在雷德蒙德召开.今年大会上亮点很多,本文汇总一些和开发者相关的内容. 1. Window ...
- 常用Tables控件介绍(一)
1.DataTables Datatables是一款jquery表格插件.它是一个高度灵活的工具,可以将任何HTML表格添加高级的交互功能. 分页,即时搜索和排序 几乎支持任何数据源:DOM, jav ...
- const指针和指向常量的指针
先看下面六种写法: . const int p; . const int *p; . int const* p; . int * const p; . const int * const p; . i ...
- Java 总结篇2
第02章:数据类型和运算符 一.概述: 1.数据类型:int.float.char.boolean 2.运算符:算术运算符.赋值运算符.关系运算符.逻辑运算符.位运算符(了解即可).条件运算符 3.基 ...
- 【转】webpack4安装过程遇到的问题及处理方法
随便百度一下,安装使用webpack的教程铺天盖地,安装一步步来,最后的最后打包没反应......,浪费了不少的时间. 这里我要提醒一下,如果安装webpack1,2,3按照百度上的教程应该不会有问题 ...
- c#Queue队列的使用
消息队列 队列(System.Collections.Queue)代表了一个先进先出的对象集合.当您需要对各项进行先进先出的访问时,则使用队列.当您在列表中添加一项,称为入队,当您从列表中移除一项时, ...
- java之hibernate之多对多双向关联映射
1.比如在权限管理中,角色和权限之间的关系就是多对多的关系,表结构为: 2.类结构 Role.java public class Role implements Serializable{ priva ...
- js 简单的滑动4
js 简单的滑动教程(四) 作者:Lellansin 转载请标明出处,谢谢 在大概的了解滑动的基本原理和怎么去实现之后,现在我们将更深入的去讨论js的滑动. 相信细心的朋友应该已经发现了,在本教程 ...