功能类似phpcms2007的批量添加软件.先说下局限性,只是用phpcms2008gbk版本,utf8下无法使用,一块心病…… 有改好了utf8下能用的烦请发布一下.
第一步: admin\templates\content_manage.tpl.php 这个文件里加一段代码:
- <?php
- if($modelid==3)
- echo "<a href='?mod=phpcms&file=content&action=add_batch_local&catid=$catid'>批量添加下载</a>";
- ?>
复制代码 这个的目的是加一个链接,点击后就可以批量添加软件;
第二步:add_batch_local.tpl.php 把压缩包里的这个文件放到 admin\templates
第三步:admin/content.inc.php 添加以下代码:
- case 'add_batch_local':
- function bytes2x($size)
- {
- $result = '';
- if($size < 1024)
- {
- $result = round($size, 2).' B';
- }
- elseif($size < 1024*1024)
- {
- $result = round($size/1024, 2).' KB';
- }
- elseif($size < 1024*1024*1024)
- {
- $result = round($size/1024/1024, 2).' MB';
- }
- elseif($size < 1024*1024*1024*1024)
- {
- $result = round($size/1024/1024/1024, 2).' GB';
- }
- else
- {
- $result = round($size/1024/1024/1024/1024, 2).' TB';
- }
- return $result;
- }
- if(!$priv_role->check('catid', $catid, 'add') && !$allow_manage) showmessage('无发布权限!');
- if($dosubmit)
- {
- if(substr($batch['dir'],-1) != '/') $batch['dir'] = $batch['dir'].'/';
- $dir = $dirtype ? $batch['dir'] : PHPCMS_ROOT.'/'.$batch['dir'];
- is_dir($dir) or showmessage('目录不正确或者不存在', '?mod=phpcms&file=content&action=manage&catid='.$catid);
- $files = glob($dir."*.*");
- !empty($files) or showmessage('发布失败!请确认文件夹下有文件可以添加', '?mod=phpcms&file=content&action=manage&catid='.$catid);
- foreach($files as $file)
- {
- if(strpos($file, ".") === false) continue;
- if($batch['ext'] && !preg_match("/^(".$batch['ext'].")$/i", fileext($file))) continue;
- $info = array();
- if(preg_match("/^([\s\S]*?)([\x81-\xfe][\x40-\xfe])([\s\S]*?)/", $file))
- {
- $file = str_replace(array("%5C", "%2F", "%3A"), array("\\", "/", ":"), urlencode($file));
- }
- $info['title'] = urldecode(str_replace('.'.fileext($file), '', basename($file)));
- $r = $db->get_one("select contentid from ".DB_PRE."content where title='$info[title]'");
- if($r['contentid'])
- {
- showmessage('此文件夹下的文件已经添加过了!', '?mod=phpcms&file=content&action=manage&catid='.$catid);
- continue;
- }
- $info['status'] = ($status == 2 || $status == 3) ? $status : ($allow_manage ? 99 : 3);
- $info['catid'] = $catid;
- $file = $dirtype ? $file : str_replace(PHPCMS_ROOT.'/', '', $file);
- $info['filesize'] = bytes2x(filesize(urldecode($file)));
- $info['downurls'] = $info['title'].'|'.$file;
- $info['content'] = $info['title'];
- $contentid = $c->add($info,$cat_selected);
- }
- if($contentid) showmessage('发布成功!', '?mod=phpcms&file=content&action=manage&catid='.$catid);
- }
- else
- {
- $data['catid'] = $catid;
- $data['template'] = isset($template_show) ? $template_show :$MODEL[$modelid]['template_show'];
- require CACHE_MODEL_PATH.'content_form.class.php';
- $content_form = new content_form($modelid);
- $forminfos = $content_form->get($data);
- require_once 'tree.class.php';
- foreach($CATEGORY as $cid=>$c)
- {
- if($c['module'] != $mod || $c['type'] > 0) continue;
- $checkbox = $c['child'] ? '' : '<input type="checkbox" name="cat_selected[]" value="'.$cid.'">';
- $cats[$cid] = array('id'=>$cid, 'parentid'=>$c['parentid'], 'name'=>$c['catname'], 'checkbox'=>$checkbox);
- }
- $str = "<tr><td style='height:22px;padding:0 0 0 10px;'>\$spacer\$name</td><td>\$checkbox</td></tr>";
- $tree = new tree($cats);
- $categorys = $tree->get_tree(0, $str);
- $pagetitle = $CATEGORY[$catid]['catname'].'-发布';
- include admin_tpl('add_batch_local');
- }
- break;
复制代码 这步是为了往数据库里写数据以及是否添加过进行对比.
效果图如下:
|