一.效果图如下:
二.实现步骤:
1.phpcms/modules/block/templates/block_list.tpl.php模板文件被修改为:
<?php
defined('IN_ADMIN') or exit('No permission resources.');
include $this->admin_tpl('header', 'admin');
?>
<div class="pad_10">
<div class="table-list">
<table width="100%" cellspacing="0">
<thead>
<tr>
<th><?php echo L('name')?></th>
<th width="80"><?php echo L('type')?></th>
<th><?php echo L('display_position')?></th>
<th width="200"><?php echo L('operations_manage')?></th>
</tr>
</thead>
<tbody>
<?php
if(is_array($list)):
foreach($list as $v):
?>
<tr>
<td align="center"><?php echo $v['name']?></td>
<td align="center"><?php if($v['type']==1) {echo L('code');} else {echo L('table_style');}?></td>
<td align="center"><?php echo $v['pos']?></td>
<td align="center"><a href="javascript:block_update(<?php echo $v['id']?>, '<?php echo $v['name']?>')"><?php echo L('updates')?></a> | <a href="javascript:edit(<?php echo $v['id']?>, '<?php echo $v['name']?>')"><?php echo L('edit')?></a> | <a href="javascript:void(0)" οnclick="copy_spider(<?php echo $v['id']?>)">复制</a> | <a href="?m=block&c=block_admin&a=del&id=<?php echo $v['id']?>" οnclick="return confirm('<?php echo L('confirm', array('message'=>$v['name']))?>')"><?php echo L('delete')?></a></td>
</tr>
<?php
endforeach;
endif;
?>
<!--新添加-->
<script type="text/javascript">
function copy_spider(id) {
window.top.art.dialog({id:'test'}).close();
window.top.art.dialog({title:'复制碎片',id:'test',iframe:'?m=block&c=block_admin&a=copy&id='+id,width:'420',height:'250'}, function(){var d = window.top.art.dialog({id:'test'}).data.iframe;var form = d.document.getElementById('dosubmit');form.click();return false;}, function(){window.top.art.dialog({id:'test'}).close()});
}
</script>
</tbody>
</table>
</div>
</div>
<div id="pages"><?php echo $pages?></div>
<div id="closeParentTime" style="display:none"></div>
<script type="text/javascript">
<!--
if(window.top.$("#current_pos").data('clicknum')==1 || window.top.$("#current_pos").data('clicknum')==null) {
parent.document.getElementById('display_center_id').style.display='';
parent.document.getElementById('center_frame').src = '?m=content&c=content&a=public_categorys&type=add&from=block&pc_hash=<?php echo $_SESSION['pc_hash'];?>';
window.top.$("#current_pos").data('clicknum',0);
}
function block_update(id, name) {
window.top.art.dialog({id:'edit'}).close();
window.top.art.dialog({title:'<?php echo L('edit')?>《'+name+'》',id:'edit',iframe:'?m=block&c=block_admin&a=block_update&id='+id,width:'700',height:'500'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe;d.document.getElementById('dosubmit').click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()});
}
function edit(id, name) {
window.top.art.dialog({id:'edit'}).close();
window.top.art.dialog({title:'<?php echo L('edit')?>《'+name+'》',id:'edit',iframe:'?m=block&c=block_admin&a=edit&id='+id,width:'700',height:'500'}, function(){var d = window.top.art.dialog({id:'edit'}).data.iframe;d.document.getElementById('dosubmit').click();return false;}, function(){window.top.art.dialog({id:'edit'}).close()});
}
//-->
</script>
</body>
</html>
2.phpcms/modules/block/block_admin.php控制器文件中添加copy()方法:
//复制碎片: wyh添加
public function copy() {
//碎片id
$id = isset($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);//提示非法参数
//查询当前碎片信息
if ($data = $this->db->get_one(array('id'=>$id))) {
//是否确定复制当前碎片信息
if (isset($_POST['dosubmit'])) {
//销毁当前碎片id
unset($data['id']);
//新碎片名称
$name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
//新碎片位置
$pos = isset($_POST['pos']) && trim($_POST['pos']) ? trim($_POST['pos']) : showmessage(L('illegal_parameters'), HTTP_REFERER);
//查询数据库中是否已存在该新碎片名称
if ($this->db->get_one(array('pos'=>$pos), 'id')) {
showmessage(L('该碎片').L('exists'), HTTP_REFERER);
}
//新碎片名称
$data['name'] = $name;
//新碎片位置,即:pos字段的值
$data['pos'] = $pos;
//在特殊字符前加反斜线
$data = new_addslashes($data);
//插入新碎片名称到数据库
if ($this->db->insert($data)) {
//插入成功
showmessage(L('operation_success'), '', '', 'test');
} else {
showmessage(L('operation_failure'));
}
} else {
$show_validator = $show_header = true;
include $this->admin_tpl('suipian_copy');//添加采集节点页面
}
} else {
showmessage(L('notfound'));
}
}
3.添加phpcms/modules/block/templates/suipian_copy.tpl.php模板文件
<?php defined('IN_ADMIN') or exit('No permission resources.');?>
<?php include $this->admin_tpl('header', 'admin');?>
<div class="pad-10">
<form name="myform" action="?m=block&c=block_admin&a=copy&id=<?php if(isset($id)) echo $id?>" method="post" id="myform">
<div class="common-form">
<table width="100%" class="table_form">
<tr>
<td width="120">原碎片名称:</td>
<td>
<?php if(isset($data['name'])) echo $data['name']?>
</td>
</tr>
<tr>
<td width="120">原碎片位置:</td>
<td>
<?php if(isset($data['pos'])) echo $data['pos']?>
</td>
</tr>
<tr>
<td width="120">新碎片名称:</td>
<td>
<input type="text" name="name" id="name" class="input-text" value="" />
</td>
</tr>
<tr>
<td width="120">新碎片位置:</td>
<td>
<input type="text" name="pos" id="pos" class="input-text" value="" />
</td>
</tr>
<tr>
<td width="120" ><font color="red">如果当前复制的是专题碎片,碎片位置应遵守规则:任意前缀_专题id_任意非重复标识(如:special_1_2)</font></td>
<td width="120" ><font color="red">如果当前复制的是非专题碎片,碎片位置应遵守规则:任意前缀_任意非重复标识(如:index_1)</font></td>
</tr>
</table>
<input name="dosubmit" type="submit" id="dosubmit" value="<?php echo L('submit')?>" class="dialog">
</div>
</div>
</form>
</body>
</html>