首页 > CMS > PhpCMS > 正文

【phpcms-v9】phpcms-v9中的碎片复制功能

2024-09-10 07:15:57
字体:
来源:转载
供稿:网友

一.效果图如下:

二.实现步骤:

1.phpcms/modules/block/templates/block_list.tpl.php模板文件被修改为:

  1. <?php   
  2. defined('IN_ADMIN'or exit('No permission resources.');   
  3. include $this->admin_tpl('header''admin');   
  4. ?>   
  5.    
  6. <div class="pad_10">   
  7. <div class="table-list">   
  8.     <table width="100%" cellspacing="0">   
  9.         <thead>   
  10.         <tr>   
  11.         <th><?php echo L('name')?></th>   
  12.         <th width="80"><?php echo L('type')?></th>   
  13.         <th><?php echo L('display_position')?></th>   
  14.         <th width="200"><?php echo L('operations_manage')?></th>   
  15.         </tr>   
  16.         </thead>   
  17.         <tbody>   
  18. <?php    
  19. if(is_array($list)):   
  20.     foreach($list as $v):   
  21. ?>   
  22. <tr>   
  23. <td align="center"><?php echo $v['name']?></td>   
  24. <td align="center"><?php if($v['type']==1) {echo L('code');} else {echo L('table_style');}?></td>   
  25. <td align="center"><?php echo $v['pos']?></td>   
  26. <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)" onclick="copy_spider(<?php echo $v['id']?>)">复制</a> | <a href="?m=block&c=block_admin&a=del&id=<?php echo $v['id']?>" onclick="return confirm('<?php echo L('confirm', array('message'=>$v['name']))?>')"><?php echo L('delete')?></a></td>   
  27. </tr>   
  28. <?php    
  29.     endforeach;   
  30. endif;   
  31. ?>   
  32.  
  33. <!--新添加-->   
  34. <script type="text/javascript">   
  35. function copy_spider(id) {   
  36.     window.top.art.dialog({id:'test'}).close();   
  37.     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()});   
  38. }    
  39. </script>   
  40. </tbody>   
  41. </table>   
  42. </div>   
  43. </div>   
  44. <div id="pages"><?php echo $pages?></div>   
  45. <div id="closeParentTime" style="display:none"></div>   
  46. <script type="text/javascript">   
  47. <!--   
  48. if(window.top.$("#current_pos").data('clicknum')==1 || window.top.$("#current_pos").data('clicknum')==null) {   
  49.     parent.document.getElementById('display_center_id').style.display='';   
  50.     parent.document.getElementById('center_frame').src = '?m=content&c=content&a=public_categorys&type=add&from=block&pc_hash=<?php echo $_SESSION['pc_hash'];?>';   
  51.     window.top.$("#current_pos").data('clicknum',0);   
  52. }   
  53.    
  54. function block_update(id, name) {   
  55.     window.top.art.dialog({id:'edit'}).close();   
  56.     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()});   
  57. }   
  58.    
  59. function edit(id, name) {   
  60.     window.top.art.dialog({id:'edit'}).close();   
  61.     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()});   
  62. }   
  63. //-->   
  64. </script>   
  65. </body>   
  66. </html>   

2.phpcms/modules/block/block_admin.php控制器文件中添加copy()方法:

  1. //复制碎片:wyh添加   
  2.     public function copy() {   
  3.         //碎片id   
  4.         $id = isset($_GET['id']) ? intval($_GET['id']) : showmessage(L('illegal_parameters'), HTTP_REFERER);//提示非法参数   
  5.         //查询当前碎片信息   
  6.         if ($data = $this->db->get_one(array('id'=>$id))) {   
  7.             //是否确定复制当前碎片信息   
  8.             if (isset($_POST['dosubmit'])) {   
  9.                 //销毁当前碎片id   
  10.                 unset($data['id']);   
  11.                 //新碎片名称   
  12.                 $name = isset($_POST['name']) && trim($_POST['name']) ? trim($_POST['name']) : showmessage(L('illegal_parameters'), HTTP_REFERER);   
  13.                 //新碎片位置   
  14.                 $pos = isset($_POST['pos']) && trim($_POST['pos']) ? trim($_POST['pos']) : showmessage(L('illegal_parameters'), HTTP_REFERER);   
  15.                 //查询数据库中是否已存在该新碎片名称   
  16.                 if ($this->db->get_one(array('pos'=>$pos), 'id')) {   
  17.                     showmessage(L('该碎片').L('exists'), HTTP_REFERER);   
  18.                 }   
  19.                 //新碎片名称   
  20.                 $data['name'] = $name;   
  21.                 //新碎片位置,即:pos字段的值   
  22.                 $data['pos'] = $pos;   
  23.                 //在特殊字符前加反斜线   
  24.                 $data = new_addslashes($data);   
  25.                 //插入新碎片名称到数据库   
  26.                 if ($this->db->insert($data)) {   
  27.                     //插入成功   
  28.                     showmessage(L('operation_success'), '''''test');   
  29.                 } else {   
  30.                     showmessage(L('operation_failure'));   
  31.                 }  //开源代码Vevb.com 
  32.             } else {   
  33.                 $show_validator = $show_header = true;   
  34.                 include $this->admin_tpl('suipian_copy');//添加采集节点页面  
  35.             }   
  36.         } else {   
  37.             showmessage(L('notfound'));   
  38.         }   
  39.     } 

3.添加phpcms/modules/block/templates/suipian_copy.tpl.php模板文件:

  1. <?php defined('IN_ADMIN'or exit('No permission resources.');?>   
  2. <?php include $this->admin_tpl('header''admin');?>   
  3. <div class="pad-10">   
  4. <form name="myform" action="?m=block&c=block_admin&a=copy&id=<?php if(isset($id)) echo $id?>" method="post" id="myform">   
  5. <div class="common-form">   
  6.     <table width="100%" class="table_form">   
  7.         <tr>   
  8.             <td width="120">原碎片名称:</td>    
  9.             <td>   
  10.             <?php if(isset($data['name'])) echo $data['name']?>   
  11.             </td>   
  12.         </tr>   
  13.         <tr>   
  14.             <td width="120">原碎片位置:</td>    
  15.             <td>   
  16.             <?php if(isset($data['pos'])) echo $data['pos']?>   
  17.             </td>   
  18.         </tr>   
  19.         <tr>   
  20.             <td width="120">新碎片名称:</td>    
  21.             <td>   
  22.             <input type="text" name="name" id="name"  class="input-text" value="" />   
  23.             </td>   
  24.         </tr>   
  25.         <tr>   
  26.             <td width="120">新碎片位置:</td>    
  27.             <td>   
  28.             <input type="text" name="pos" id="pos"  class="input-text" value="" />   
  29.             </td>   
  30.         </tr>   
  31.         <tr>   
  32.             <td width="120" ><font color="red">如果当前复制的是专题碎片,碎片位置应遵守规则:任意前缀_专题id_任意非重复标识(如:special_1_2)</font></td>   
  33.             <td width="120" ><font color="red">如果当前复制的是非专题碎片,碎片位置应遵守规则:任意前缀_任意非重复标识(如:index_1)</font></td>   //开源代码Vevb.com 
  34.         </tr>   
  35.     </table>   
  36.     <input name="dosubmit" type="submit" id="dosubmit" value="<?php echo L('submit')?>" class="dialog">   
  37. </div>   
  38. </div>   
  39. </form>   
  40.    
  41. </body>   
  42. </html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表