destoon7.0后台栏目分类一键获取所有栏目拼音目录的修改

  2020-02-21    阅读:150
 用于DESTOON7.0系统
        
       到admin 目录替换 category.inc.php 


刷新后台,然后每个模块的栏目分类后面会多一个菜单-批量拼音目录,点这个就菜单就可以了

代码修改不陈述,直接上全部代码

以下为category.inc.php代码

  1. <?php
  2.  
  3. defined('DT_ADMIN') or exit('Access Denied');
  4. $mid or $mid = 4;
  5. $CATEGORY = cache_read('category-'.$mid.'.php');
  6. $MOD = cache_read('module-'.$mid.'.php');
  7. $NUM = count($CATEGORY);
  8. $catid = isset($catid) ? intval($catid) : 0;
  9. $do = new category($mid, $catid);
  10. $parentid = isset($parentid) ? intval($parentid) : 0;
  11. $table = $DT_PRE.'category';
  12. $menus = array (
  13. array('添加分类', '?file='.$file.'&action=add&mid='.$mid.'&parentid='.$parentid),
  14. array('管理分类', '?file='.$file.'&mid='.$mid),
  15. array('分类复制', '?file='.$file.'&action=copy&mid='.$mid),
  16. array('更新缓存', '?file='.$file.'&action=caches&mid='.$mid),
  17. array('更新地址', '?file='.$file.'&action=url&mid='.$mid),
  18. array('更新统计', '?file='.$file.'&action=count&mid='.$mid),
  19. array('批量索引', '?file='.$file.'&action=letters&mid='.$mid),
  20. array('批量拼音目录', '?file='.$file.'&action=allletter&mid='.$mid),
  21. );
  22. if(strpos($forward, 'category') === false) $forward = '?file='.$file.'&mid='.$mid.'&parentid='.$parentid.'&kw='.urlencode($kw);
  23. switch($action) {
  24. case 'add':
  25. if($submit) {
  26. if(!$category['catname']) msg('分类名不能为空');
  27. $category['catname'] = trim($category['catname']);
  28. $childs = '';
  29. $catids = array();
  30. if(strpos($category['catname'], "\n") === false) {
  31. $category['catdir'] = $do->get_catdir($category['catdir']);
  32. $do->add($category);
  33. $childs .= ','.$do->catid;
  34. $catids[] = $do->catid;
  35. } else {
  36. $catnames = explode("\n", $category['catname']);
  37. foreach($catnames as $catname) {
  38. $catname = trim($catname);
  39. if(!$catname) continue;
  40. $category['catname'] = $catname;
  41. $category['catdir'] = '';
  42. $category['letter'] = '';
  43. $category['seo_title'] = '';
  44. $category['seo_keywords'] = '';
  45. $category['seo_description'] = '';
  46. $do->add($category);
  47. $childs .= ','.$do->catid;
  48. $catids[] = $do->catid;
  49. }
  50. }
  51. if($category['parentid']) {
  52. $parents = array();
  53. $cid = $category['parentid'];
  54. $parents[] = $cid;
  55. while(1) {
  56. if($CATEGORY[$cid]['parentid']) {
  57. $parents[] = $cid = $CATEGORY[$cid]['parentid'];
  58. } else {
  59. break;
  60. }
  61. }
  62. foreach($parents as $catid) {
  63. $arrchildid = $CATEGORY[$catid]['child'] ? $CATEGORY[$catid]['arrchildid'].$childs : $catid.$childs;
  64. $db->query("UPDATe {$table} SET child=1,arrchildid='$arrchildid' WHERe catid=$catid");
  65. }
  66. }
  67. foreach($catids as $catid) {
  68. $CATEGORY[$catid] = $db->get_one("SELECt * FROM {$table} WHERe catid=$catid");
  69. update_category($CATEGORY[$catid]);
  70. }
  71. $NUM > 500 ? $do->cache() : $do->repair();
  72. dmsg('添加成功', '?file='.$file.'&mid='.$mid.'&parentid='.$category['parentid']);
  73. } else {
  74. include tpl('category_add');
  75. }
  76. break;
  77. case 'edit':
  78. $catid or msg();
  79. if($submit) {
  80. if(!$category['catname']) msg('分类名不能为空');
  81. if($category['parentid'] == $catid) msg('上级分类不能与当前分类相同');
  82. $do->edit($category);
  83. $category['catid'] = $catid;
  84. update_category($category);
  85. $NUM > 500 ? $do->cache() : $do->repair();
  86. dmsg('修改成功', '?file='.$file.'&mid='.$mid.'&parentid='.$category['parentid']);
  87. } else {
  88. extract($db->get_one("SELECT * FROM {$table} WHERe catid=$catid"));
  89. include tpl('category_edit');
  90. }
  91. break;
  92. case 'copy':
  93. if($submit) {
  94. if(!$fromid) msg('源模块ID不能为空');
  95. if(!$save) $db->query("DELETe FROM {$table} WHERe moduleid=$mid");
  96. $result = $db->query("SELECt * FROM {$table} WHERe moduleid=$fromid ORDER BY catid");
  97. $O = $R = array();
  98. while($r = $db->fetch_array($result)) {
  99. $O[$r['catid']] = $r['catname'];
  100. $sqlk = $sqlv = '';
  101. $catid = $r['catid'];
  102. unset($r['catid']);
  103. $r['moduleid'] = $mid;
  104. $r['item'] = $r['property'] = 0;
  105. $r = daddslashes($r);
  106. foreach($r as $k=>$v) {
  107. $sqlk .= ','.$k; $sqlv .= ",'$v'";
  108. }
  109. $sqlk = substr($sqlk, 1);
  110. $sqlv = substr($sqlv, 1);
  111. $db->query("INSERT INTO {$table} ($sqlk) VALUES ($sqlv)");
  112. $R[$catid] = $db->insert_id();
  113. }
  114. $result = $db->query("SELECt * FROM {$table} WHERe moduleid='$mid' ORDER BY catid");
  115. while($r = $db->fetch_array($result)) {
  116. $catid = $r['catid'];
  117. $v = $r['parentid'];
  118. $parentid = isset($R[$v]) ? $R[$v] : $v;
  119. $arrparentid = explode(',', $r['arrparentid']);
  120. foreach($arrparentid as $k=>$v) {
  121. if(isset($R[$v])) $arrparentid[$k] = $R[$v];
  122. }
  123. $arrparentid = implode(',', $arrparentid);
  124. $arrchildid = explode(',', $r['arrchildid']);
  125. foreach($arrchildid as $k=>$v) {
  126. if(isset($R[$v])) $arrchildid[$k] = $R[$v];
  127. }
  128. $arrchildid = implode(',', $arrchildid);
  129. $db->query("UPDATe {$table} SET parentid='$parentid',arrparentid='$arrparentid',arrchildid='$arrchildid' WHERe catid=$catid");
  130. }
  131. $do->repair();
  132. msg('分类复制成功', '?file='.$file.'&action=url&&mid='.$mid.'&forward='.urlencode('?file='.$file.'&mid='.$mid));
  133. } else {
  134. include tpl('category_copy');
  135. }
  136. break;
  137. case 'caches':
  138. msg('开始更新统计', "?file=$file&mid=$mid&action=count");
  139. break;
  140. case 'count':
  141. require DT_ROOT.'/include/module.func.php';
  142. $tb = get_table($mid);
  143. if($MODULE[$mid]['module'] == 'club') $tb = $DT_PRE.'club_group_'.$mid;
  144. if(!isset($num)) {
  145. $num = 50;
  146. }
  147. if(!isset($fid)) {
  148. $r = $db->get_one("SELECt MIN(catid) AS fid FROM {$table} WHERe moduleid=$mid");
  149. $fid = $r['fid'] ? $r['fid'] : 0;
  150. }
  151. isset($sid) or $sid = $fid;
  152. if(!isset($tid)) {
  153. $r = $db->get_one("SELECt MAX(catid) AS tid FROM {$table} WHERe moduleid=$mid");
  154. $tid = $r['tid'] ? $r['tid'] : 0;
  155. }
  156. if($fid <= $tid) {
  157. $result = $db->query("SELECt catid FROM {$table} WHERe moduleid=$mid AND catid>=$fid ORDER BY catid LIMIT 0,$num");
  158. if($db->affected_rows($result)) {
  159. while($r = $db->fetch_array($result)) {
  160. $catid = $r['catid'];
  161. if($mid == 4) {
  162. $condition = "groupid>5 and catids like '%,".$catid.",%'";
  163. } else {
  164. $condition = 'status=3';
  165. $condition .= $CATEGORY[$catid]['child'] ? " AND catid IN (".$CATEGORY[$catid]['arrchildid'].")" : " AND catid=$catid";
  166. }
  167. $item = $db->count($tb, $condition);
  168. $db->query("UPDATe {$table} SET item=$item WHERe catid=$catid");
  169. }
  170. $catid += 1;
  171. } else {
  172. $catid = $fid + $num;
  173. }
  174. } else {
  175. msg('统计更新成功', "?file=$file&mid=$mid&action=url");
  176. }
  177. msg('ID从'.$fid.'至'.($catid-1).'更新成功'.progress($sid, $fid, $tid), "?file=$file&mid=$mid&action=$action&sid=$sid&fid=$catid&tid=$tid&num=$num");
  178. break;
  179. case 'url':
  180. foreach($CATEGORY as $c) {
  181. update_category($c);
  182. }
  183. msg('地址更新成功', "?file=$file&mid=$mid&action=letters");
  184. break;
  185. case 'letters':
  186. $update = false;
  187. foreach($CATEGORY as $k=>$v) {
  188. if(strlen($v['letter']) != 1) {
  189. $letter = $do->get_letter($v['catname'], false);
  190. if($letter) {
  191. $update = true;
  192. $letter = substr($letter, 0, 1);
  193. $db->query("UPDATE {$table} SET letter='$letter' WHERe catid='$v[catid]'");
  194. }
  195. }
  196. }
  197. msg('索引修复成功', "?file=$file&mid=$mid&action=cache");
  198. break;
  199. case 'cache':
  200. $do->repair();
  201. dmsg('缓存更新成功', '?file='.$file.'&mid='.$mid);
  202. break;
  203. case 'delete':
  204. if($catid) $catids = $catid;
  205. $catids or msg('请选择分类');
  206. $do->delete($catids);
  207. $NUM > 500 ? $do->cache() : $do->repair();
  208. dmsg('删除成功', $forward);
  209. break;
  210. case 'update':
  211. if(!$category || !is_array($category)) msg();
  212. $do->update($category);
  213. foreach($category as $catid=>$v) {
  214. $CATEGORY[$catid] = $db->get_one("SELECT * FROM {$table} WHERe catid=$catid");
  215. update_category($CATEGORY[$catid]);
  216. }
  217. $NUM > 500 ? $do->cache() : $do->repair();
  218. dmsg('更新成功', '?file='.$file.'&mid='.$mid.'&parentid='.$parentid);
  219. break;
  220. case 'letter':
  221. isset($catname) or $catname = '';
  222. if(!$catname || strpos($catname, "\n") !== false) exit('');
  223. exit($do->get_letter($catname, false));
  224. break;
  225. case 'ckdir':
  226. if($do->get_catdir($catdir)) {
  227. dialog('目录名可以使用');
  228. } else {
  229. dialog('目录名不合法或者已经被使用');
  230. }
  231. break;
  232. //20180603 S
  233. case 'allletter':
  234. $q=$db->query("select * from {$table} where moduleid='$mid'");
  235. while($rs=$db->fetch_array($q)){
  236. $lets = $do->get_letter($rs['catname'],false);
  237. DB::query("UPDATe {$table} SET catdir='$lets' WHERe catid='$rs[catid]'");
  238. }
  239. dmsg('拼音目录修复成功', $forward);
  240. break;
  241. //20180603 E
  242. default:
  243. $total = 0;
  244. $DTCAT = array();
  245. $condition = "moduleid=$mid";
  246. $condition .= $keyword ? " AND catname LIKE '%$keyword%'" : " AND parentid=$parentid";
  247. $result = $db->query("SELECt * FROM {$table} WHERe $condition ORDER BY listorder,catid");
  248. while($r = $db->fetch_array($result)) {
  249. $r['childs'] = substr_count($r['arrchildid'], ',');
  250. $total += $r['item'];
  251. $DTCAT[$r['catid']] = $r;
  252. }
  253. if(!$DTCAT && !$parentid && !$keyword) msg('暂无分类,请先添加', '?file='.$file.'&mid='.$mid.'&action=add&parentid='.$parentid);
  254. include tpl('category');
  255. break;
  256. }
  257.  
  258. class category {
  259. var $moduleid;
  260. var $catid;
  261. var $category = array();
  262. var $table;
  263.  
  264. function __construct($moduleid = 1, $catid = 0) {
  265. global $CATEGORY;
  266. $this->moduleid = $moduleid;
  267. $this->catid = $catid;
  268. if(!isset($CATEGORY)) $CATEGORY = cache_read('category-'.$this->moduleid.'.php');
  269. $this->category = $CATEGORY;
  270. $this->table = DT_PRE.'category';
  271. }
  272.  
  273. function category($moduleid = 1, $catid = 0) {
  274. $this->__construct($moduleid, $catid);
  275. }
  276.  
  277. function add($category) {
  278. $category['moduleid'] = $this->moduleid;
  279. $category['letter'] = preg_match("/^[a-z]{1}+$/i", $category['letter']) ? strtolower($category['letter']) : '';
  280. foreach(array('group_list', 'group_show', 'group_add') as $v) {
  281. $category[$v] = isset($category[$v]) ? implode(',', $category[$v]) : '';
  282. }
  283. $sqlk = $sqlv = '';
  284. foreach($category as $k=>$v) {
  285. $sqlk .= ','.$k; $sqlv .= ",'$v'";
  286. }
  287. $sqlk = substr($sqlk, 1);
  288. $sqlv = substr($sqlv, 1);
  289. DB::query("INSERT INTO {$this->table} ($sqlk) VALUES ($sqlv)");
  290. $this->catid = DB::insert_id();
  291. if($category['parentid']) {
  292. $category['catid'] = $this->catid;
  293. $this->category[$this->catid] = $category;
  294. $arrparentid = $this->get_arrparentid($this->catid, $this->category);
  295. } else {
  296. $arrparentid = 0;
  297. }
  298. $catdir = $category['catdir'] ? $category['catdir'] : $this->catid;
  299. DB::query("UPDATe {$this->table} SET listorder=$this->catid,catdir='$catdir',arrparentid='$arrparentid' WHERe catid=$this->catid");
  300. return true;
  301. }
  302.  
  303. function edit($category) {
  304. $category['letter'] = preg_match("/^[a-z]{1}+$/i", $category['letter']) ? strtolower($category['letter']) : '';
  305. if($category['parentid']) {
  306. $category['catid'] = $this->catid;
  307. $this->category[$this->catid] = $category;
  308. $category['arrparentid'] = $this->get_arrparentid($this->catid, $this->category);
  309. } else {
  310. $category['arrparentid'] = 0;
  311. }
  312. foreach(array('group_list', 'group_show', 'group_add') as $v) {
  313. $category[$v] = isset($category[$v]) ? implode(',', $category[$v]) : '';
  314. }
  315. $category['linkurl'] = '';
  316. $sql = '';
  317. foreach($category as $k=>$v) {
  318. $sql .= ",$k='$v'";
  319. }
  320. $sql = substr($sql, 1);
  321. DB::query("UPDATe {$this->table} SET $sql WHERe catid=$this->catid");
  322. return true;
  323. }
  324.  
  325. function delete($catids) {
  326. if(is_array($catids)) {
  327. foreach($catids as $catid) {
  328. if(isset($this->category[$catid])) $this->delete($catid);
  329. }
  330. } else {
  331. $catid = $catids;
  332. if(isset($this->category[$catid])) {
  333. DB::query("DELETE FROM {$this->table} WHERe catid=$catid");
  334. $arrchildid = $this->category[$catid]['arrchildid'] ? $this->category[$catid]['arrchildid'] : $catid;
  335. DB::query("DELETe FROM {$this->table} WHERe catid IN ($arrchildid)");
  336. if($this->moduleid > 4) DB::query("UPDATe ".get_table($this->moduleid)." SET status=0 WHERe catid IN (".$arrchildid.")");
  337. }
  338. }
  339. return true;
  340. }
  341.  
  342. function update($category) {
  343. if(!is_array($category)) return false;
  344. foreach($category as $k=>$v) {
  345. if(!$v['catname']) continue;
  346. $v['parentid'] = intval($v['parentid']);
  347. if($k == $v['parentid']) continue;
  348. if($v['parentid'] > 0 && !isset($this->category[$v['parentid']])) continue;
  349. $v['listorder'] = intval($v['listorder']);
  350. $v['level'] = intval($v['level']);
  351. $v['letter'] = preg_match("/^[a-z0-9]{1}+$/i", $v['letter']) ? strtolower($v['letter']) : '';
  352. $v['catdir'] = $this->get_catdir($v['catdir'], $k);
  353. if(!$v['catdir']) $v['catdir'] = $k;
  354. 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 ");
  355. }
  356. return true;
  357. }
  358.  
  359. function repair() {
  360. $query = DB::query("SELECT * FROM {$this->table} WHERe moduleid='$this->moduleid' ORDER BY listorder,catid");
  361. $CATEGORY = array();
  362. while($r = DB::fetch_array($query)) {
  363. $CATEGORY[$r['catid']] = $r;
  364. }
  365. $childs = array();
  366. foreach($CATEGORY as $catid => $category) {
  367. $CATEGORY[$catid]['arrparentid'] = $arrparentid = $this->get_arrparentid($catid, $CATEGORY);
  368. $CATEGORY[$catid]['catdir'] = $catdir = preg_match("/^[0-9a-z_\-\/]+$/i", $category['catdir']) ? $category['catdir'] : $catid;
  369. $sql = "catdir='$catdir',arrparentid='$arrparentid'";
  370. if(!$category['linkurl']) {
  371. $CATEGORY[$catid]['linkurl'] = listurl($category);
  372. $sql .= ",linkurl='$category[linkurl]'";
  373. }
  374. DB::query("UPDATe {$this->table} SET $sql WHERe catid=$catid");
  375. if($arrparentid) {
  376. $arr = explode(',', $arrparentid);
  377. foreach($arr as $a) {
  378. if($a == 0) continue;
  379. isset($childs[$a]) or $childs[$a] = '';
  380. $childs[$a] .= ','.$catid;
  381. }
  382. }
  383. }
  384. foreach($CATEGORY as $catid => $category) {
  385. if(isset($childs[$catid])) {
  386. $CATEGORY[$catid]['arrchildid'] = $arrchildid = $catid.$childs[$catid];
  387. $CATEGORY[$catid]['child'] = 1;
  388. DB::query("UPDATe {$this->table} SET arrchildid='$arrchildid',child=1 WHERe catid='$catid'");
  389. } else {
  390. $CATEGORY[$catid]['arrchildid'] = $catid;
  391. $CATEGORY[$catid]['child'] = 0;
  392. DB::query("UPDATE {$this->table} SET arrchildid='$catid',child=0 WHERe catid='$catid'");
  393. }
  394. }
  395. $this->cache($CATEGORY);
  396. return true;
  397. }
  398.  
  399. function get_arrparentid($catid, $CATEGORY) {
  400. if($CATEGORY[$catid]['parentid'] && $CATEGORY[$catid]['parentid'] != $catid) {
  401. $parents = array();
  402. $cid = $catid;
  403. while($catid) {
  404. if($CATEGORY[$cid]['parentid']) {
  405. $parents[] = $cid = $CATEGORY[$cid]['parentid'];
  406. } else {
  407. break;
  408. }
  409. }
  410. $parents[] = 0;
  411. return implode(',', array_reverse($parents));
  412. } else {
  413. return '0';
  414. }
  415. }
  416.  
  417. function get_arrchildid($catid, $CATEGORY) {
  418. $arrchildid = '';
  419. foreach($CATEGORY as $category) {
  420. if(strpos(','.$category['arrparentid'].',', ','.$catid.',') !== false) $arrchildid .= ','.$category['catid'];
  421. }
  422. return $arrchildid ? $catid.$arrchildid : $catid;
  423. }
  424.  
  425. function get_catdir($catdir, $catid = 0) {
  426. if(preg_match("/^[0-9a-z_\-\/]+$/i", $catdir)) {
  427. $condition = "catdir='$catdir' AND moduleid='$this->moduleid'";
  428. if($catid) $condition .= " AND catid!=$catid";
  429. $r = DB::get_one("SELECT catid FROM {$this->table} WHERe $condition");
  430. if($r) {
  431. return '';
  432. } else {
  433. return $catdir;
  434. }
  435. } else {
  436. return '';
  437. }
  438. }
  439.  
  440. function get_letter($catname, $letter = true) {
  441. return $letter ? strtolower(substr(gb2py($catname), 0, 1)) : str_replace(' ', '', gb2py($catname));
  442. }
  443.  
  444. function cache($data = array()) {
  445. cache_category($this->moduleid, $data);
  446. }
  447. }
  448. ?>

免责声明:
本站部份内容系网友自发上传与转载,不代表本网赞同其观点;
如涉及内容、版权等问题,请在30日内联系,我们将在第一时间删除内容!

相关Destoon技术

(c)2012-2023 www.qiyeyunshang.com All Rights Reserved.
慧一科技destoon模板   辽ICP备2021002520号-1
  QQ咨询

购买模板 售前咨询

  咨询QQ

3292628658
(早8:30-晚10:00)

  微信咨询

咨询微信
客服微信

  返回顶部