分享

【phpcms支持团队】【二次开发】下载模型批量添加软件

 昵称9234923 2012-03-21
功能类似phpcms2007的批量添加软件.先说下局限性,只是用phpcms2008gbk版本,utf8下无法使用,一块心病……
有改好了utf8下能用的烦请发布一下.

第一步:
admin\templates\content_manage.tpl.php
这个文件里加一段代码:
  1. <?php
  2. if($modelid==3)
  3. echo "<a href='?mod=phpcms&file=content&action=add_batch_local&catid=$catid'>批量添加下载</a>";
  4. ?>
复制代码

这个的目的是加一个链接,点击后就可以批量添加软件;

第二步:add_batch_local.tpl.php
把压缩包里的这个文件放到 admin\templates

第三步:admin/content.inc.php
添加以下代码:

  1. case 'add_batch_local':
  2. function bytes2x($size)
  3. {
  4. $result = '';
  5. if($size < 1024)
  6. {
  7.   $result = round($size, 2).' B';
  8. }
  9. elseif($size < 1024*1024)
  10. {
  11.   $result = round($size/1024, 2).' KB';
  12. }
  13. elseif($size < 1024*1024*1024)
  14. {
  15.   $result = round($size/1024/1024, 2).' MB';
  16. }
  17. elseif($size < 1024*1024*1024*1024)
  18. {
  19.   $result = round($size/1024/1024/1024, 2).' GB';
  20. }
  21. else
  22. {
  23.   $result = round($size/1024/1024/1024/1024, 2).' TB';
  24. }
  25. return $result;
  26. }
  27.   if(!$priv_role->check('catid', $catid, 'add') && !$allow_manage) showmessage('无发布权限!');
  28.   if($dosubmit)
  29.   {
  30. if(substr($batch['dir'],-1) != '/') $batch['dir'] = $batch['dir'].'/';
  31. $dir = $dirtype ? $batch['dir'] : PHPCMS_ROOT.'/'.$batch['dir'];
  32. is_dir($dir) or showmessage('目录不正确或者不存在', '?mod=phpcms&file=content&action=manage&catid='.$catid);
  33. $files = glob($dir."*.*");
  34. !empty($files) or showmessage('发布失败!请确认文件夹下有文件可以添加', '?mod=phpcms&file=content&action=manage&catid='.$catid);
  35. foreach($files as $file)
  36. {
  37.   if(strpos($file, ".") === false) continue;
  38.   if($batch['ext'] && !preg_match("/^(".$batch['ext'].")$/i", fileext($file))) continue;
  39.   $info = array();
  40.   if(preg_match("/^([\s\S]*?)([\x81-\xfe][\x40-\xfe])([\s\S]*?)/", $file))
  41.   {
  42.    $file = str_replace(array("%5C", "%2F", "%3A"), array("\\", "/", ":"), urlencode($file));
  43.   }
  44.   $info['title'] = urldecode(str_replace('.'.fileext($file), '', basename($file)));
  45.   $r = $db->get_one("select contentid from ".DB_PRE."content where title='$info[title]'");
  46.   if($r['contentid'])
  47.   {
  48.   showmessage('此文件夹下的文件已经添加过了!', '?mod=phpcms&file=content&action=manage&catid='.$catid);
  49.   continue;
  50.   }
  51. $info['status'] = ($status == 2 || $status == 3) ? $status : ($allow_manage ? 99 : 3);
  52.    $info['catid'] = $catid;
  53.    $file = $dirtype ? $file : str_replace(PHPCMS_ROOT.'/', '', $file);
  54.    $info['filesize'] = bytes2x(filesize(urldecode($file)));
  55.       $info['downurls'] = $info['title'].'|'.$file;
  56.    $info['content'] = $info['title'];
  57.    $contentid = $c->add($info,$cat_selected);
  58. }   
  59.           if($contentid) showmessage('发布成功!', '?mod=phpcms&file=content&action=manage&catid='.$catid);
  60.    }
  61.   else
  62.   {
  63.    $data['catid'] = $catid;
  64.    $data['template'] = isset($template_show) ? $template_show :$MODEL[$modelid]['template_show'];
  65.    require CACHE_MODEL_PATH.'content_form.class.php';
  66.    $content_form = new content_form($modelid);
  67.    $forminfos = $content_form->get($data);
  68.             require_once 'tree.class.php';
  69.             foreach($CATEGORY as $cid=>$c)
  70.             {
  71.     if($c['module'] != $mod || $c['type'] > 0) continue;
  72.     $checkbox = $c['child'] ? '' : '<input type="checkbox" name="cat_selected[]" value="'.$cid.'">';
  73.     $cats[$cid] = array('id'=>$cid, 'parentid'=>$c['parentid'], 'name'=>$c['catname'], 'checkbox'=>$checkbox);
  74.             }
  75.    $str = "<tr><td style='height:22px;padding:0 0 0 10px;'>\$spacer\$name</td><td>\$checkbox</td></tr>";
  76.    $tree = new tree($cats);
  77.    $categorys = $tree->get_tree(0, $str);
  78.             $pagetitle = $CATEGORY[$catid]['catname'].'-发布';
  79.    include admin_tpl('add_batch_local');
  80.   }
  81.   break;
复制代码

这步是为了往数据库里写数据以及是否添加过进行对比.

效果图如下:
QQ截图未命名.jpg

2.jpg
2009-4-21 22:28:28 上传
下载附件 (91.88 KB)


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多