|
楼主 |
发表于 2010-9-14 10:58:03
|
显示全部楼层
附上本人修改后的完整代码(因为没有附件上传权限,所以只能帖代码,大家复制替换即可)
<?php
require_once(dirname(__FILE__).\'/../config.inc.php\');
require_once(dirname(__FILE__).\'/inc/common.php\');
aPurview(301);
if(empty($do)) $do= \'\';
if($do==\\\"savedata\\\"){
$id = empty($id) ? \'\' :intval($id);
//如果是修改则不用判断目录是否存在!
if($id!=\'\'){
$sql=\\\"select * from {$cfg[\'tb_pre\']}channel where c_id!=$id and c_name=\'$name\'\\\";
}else{
if($channeldir!=\'\'){
if(is_dir(FR_ROOT.\\\"/$channeldir\\\")){showmsg(\\\"目录已经存在!\\\",\\\"-1\\\",0,2000);exit;}
}
if($channeltype==2){
//如果添加外部频道只检查频道名称是否存在
$sql=\\\"select * from {$cfg[\'tb_pre\']}channel where c_name=\'$name\'\\\";
}else{
// $channeldir = preg_replace(\\\"/[^a-zA-Z\\.-]/i\\\",\'\',cleartags($channeldir));
if($channeldir==\'\'){showmsg(\\\"频道目录名必须为英文字符!\\\",\\\"-1\\\",0,2000);exit;}
$sql=\\\"select * from {$cfg[\'tb_pre\']}channel where c_name=\'$name\' or c_channeldir=\'$channeldir\'\\\";
}
}
$rs = $db->get_one($sql);
if($rs){
if($channeltype==2){
showmsg(\\\"对不起该频道已经存在!\\\",\\\"-1\\\",0,2000);exit;
}else{
showmsg(\\\"对不起该频道或目录已经存在!\\\",\\\"-1\\\",0,2000);exit;
}
}
$rs = $db->get_one(\\\"select max(c_order) as m from {$cfg[\'tb_pre\']}channel\\\");
$max=$rs?$rs[\'m\']+1:0;
if($name==\'\'){showmsg(\\\"频道名称不能为!\\\",\\\"-1\\\",0,2000);exit;}
if($channeltype!=2){
$sqlstr=Array(\'c_name\',\'c_shortname\',\'c_itemunit\',\'c_readme\',\'c_keywords\',\'c_description\',\'c_opentype\',\'c_channeltype\',\'c_linkurl\',\'c_channeldir\',\'c_moduletype\',\'c_disabled\',\'c_shownav\',\'c_createhtml\',\'c_fileext\',\'c_listfiletype\',\'c_structuretype\',\'c_filenametype\');
}else{
$sqlstr=Array(\'c_name\',\'c_readme\',\'c_keywords\',\'c_description\',\'c_opentype\',\'c_channeltype\',\'c_linkurl\',\'c_disabled\',\'c_shownav\');
}
if($id!=\'\'){
$sqls=\'\';
foreach($sqlstr as $v){
$s=str_replace(\'c_\',\'\',$v);
if(isset($$s)){
$sqls.=\\\"$v=\'\\\".$$s.\\\"\',\\\";
}
}
$sqls=substr($sqls,0,-1);
$db ->query(\\\"update {$cfg[\'tb_pre\']}channel set $sqls where c_id=\'$id\'\\\");
}else{
$sqls=$sqlss=\'\';
foreach($sqlstr as $v){
$s=str_replace(\'c_\',\'\',$v);
if(isset($$s)){
$sqls.=\\\"$v,\\\";
if($s==\'readme\'||$s==\'keywords\'||$s==\'description\'){$sqlss.=\\\"\'\\\".replace_strbox($$s).\\\"\',\\\";}else{$sqlss.=\\\"\'\\\".cleartags($$s).\\\"\',\\\";}
}
}
$sqls.=\\\"c_order,\\\";$sqlss.=\\\"$max,\\\";
$sqls=substr($sqls,0,-1);$sqlss=substr($sqlss,0,-1);
$db ->query(\\\"INSERT INTO {$cfg[\'tb_pre\']}channel ($sqls) VALUES($sqlss)\\\");
$cid=$db ->insert_id();
//复制文件
//避免根目录文件被覆盖
if($channeldir!=\'\'){
$loadfile=file_get(FR_ROOT.\\\"/article/index.php\\\");
$loadfile=str_replace(\'$cid=10;\',\'$cid=\'.$cid.\';\',$loadfile);
$loadfile=str_replace(\'\\\'article\\\');\',\'\\\'\'.$channeldir.\'\\\');\',$loadfile);
file_put(FR_ROOT.\\\"/$channeldir/index.php\\\",$loadfile);
$loadfile=file_get(FR_ROOT.\\\"/article/list.php\\\");
$loadfile=str_replace(\'$cid=10;\',\'$cid=\'.$cid.\';\',$loadfile);
$loadfile=str_replace(\'\\\'article\\\');\',\'\\\'\'.$channeldir.\'\\\');\',$loadfile);
file_put(FR_ROOT.\\\"/$channeldir/list.php\\\",$loadfile);
$loadfile=file_get(FR_ROOT.\\\"/article/article.php\\\");
$loadfile=str_replace(\'$cid=10;\',\'$cid=\'.$cid.\';\',$loadfile);
$loadfile=str_replace(\'\\\'article\\\');\',\'\\\'\'.$channeldir.\'\\\');\',$loadfile);
file_put(FR_ROOT.\\\"/$channeldir/article.php\\\",$loadfile);
//复制模版
dir_copy(FR_ROOT.\'/templates/\'.$cfg[\'template\'].\'/article\',FR_ROOT.\'/templates/\'.$cfg[\'template\'].\'/\'.$channeldir.\'\');
}
}
showmsg(\\\"操作成功!\\\",\\\"websys_channel.php\\\");exit;
}elseif($do==\\\"stop\\\"){
$id = empty($id) ? \'\' :intval($id);
$id;;$db ->query(\\\"update {$cfg[\'tb_pre\']}channel set c_disabled=1 where c_id=\'$id\'\\\");
showmsg(\\\"操作成功!\\\",\\\"websys_channel.php\\\");exit;
}elseif($do==\\\"start\\\"){
$id = empty($id) ? \'\' :intval($id);
$id;;$db ->query(\\\"update {$cfg[\'tb_pre\']}channel set c_disabled=0 where c_id=\'$id\'\\\");
showmsg(\\\"操作成功!\\\",\\\"websys_channel.php\\\");exit;
}elseif($do==\\\"del\\\"){
$id = empty($id) ? \'\' :intval($id);
if($id!=\'\'){
$rs = $db->get_one(\\\"select c_channeldir,c_channeltype from {$cfg[\'tb_pre\']}channel where c_channeltype!=0 and c_id=\'$id\'\\\");
if($rs){
if($rs[\'c_channeltype\']==1){
dir_delete(FR_ROOT.\\\"/$rs[c_channeldir]\\\");
dir_delete(FR_ROOT.\'/templates/\'.$cfg[\'template\'].\'/\'.$rs[\'c_channeldir\']);
}
$db ->query(\\\"delete from {$cfg[\'tb_pre\']}channel where c_id =\'$id\'\\\");
}
}
showmsg(\\\"操作成功!\\\",\\\"websys_channel.php\\\");exit;
}elseif($do==\\\"add\\\"){
$sqlstr=Array(\'c_id\',\'c_name\',\'c_shortname\',\'c_itemunit\',\'c_readme\',\'c_keywords\',\'c_description\',\'c_order\',\'c_opentype\',\'c_channeltype\',\'c_linkurl\',\'c_channeldir\',\'c_moduletype\',\'c_disabled\',\'c_shownav\',\'c_createhtml\',\'c_fileext\',\'c_listfiletype\',\'c_structuretype\',\'c_filenametype\');
$sqls=\'\';
$id = empty($id) ? \'\' :intval($id);
if($id!=\'\'){
foreach($sqlstr as $v) $sqls.=\\\"$v,\\\";
$sqls=substr($sqls,0,-1);
$rs = $db->get_one(\\\"select $sqls from {$cfg[\'tb_pre\']}channel where c_id=$id limit 0,1\\\");
if($rs){
foreach($sqlstr as $v){
$s=str_replace(\'c_\',\'\',$v);
$$s=$rs[$v];
}
}else{
foreach($sqlstr as $v){
$s=str_replace(\'c_\',\'\',$v);
$$s=\'\';
}
$channeltype=2;
}
}else{
foreach($sqlstr as $v){
$s=str_replace(\'c_\',\'\',$v);
$$s=\'\';
}
$channeltype=2;
}
$cid=$num=$pass=\\\"\\\";
$validnum=0;
$enddate=dtime(0,3);
}elseif($do==\\\"saveorder\\\"){
$id = empty($id) ? array() : $id;
$s_count=count($id);
if ($s_count>0){
for($s=0;$s<$s_count;$s++){
if (!is_numeric($order[$s])) {showmsg(\'排序只能为数字!\',\'-1\');exit();}
$orders=$order[$s]?intval($order[$s]):0;
$rs=$db ->query(\\\"update {$cfg[\'tb_pre\']}channel set c_order=\'$order[$s]\' where c_id=$id[$s]\\\");
}
}
if($rs){
showmsg(\\\"操作成功!\\\",\\\"websys_channel.php\\\");exit;
}else{
showmsg(\'操作失败!原因:\'.$db ->error(),\\\"javascript:;\\\");exit;
}
}else{
$rsdb=array();
$sqladd=\'\';
$sql=\\\"select * from {$cfg[\'tb_pre\']}channel order by c_order\\\";
$query=$db->query($sql);
while($row=$db->fetch_array($query)){
$rsdb[]=$row;
}
}
include(\'templets/websys_channel.htm\');
?> |
|