PHPCMS V9关联链接的作用不再阐述,具体功能位置为后台-扩展-关联链接;
本身不具备批量导出和导入功能,现在增加:
首先增加2个菜单,分别为批量导出和批量导入:
后台-扩展-菜单管理,找到关联链接,增加2子菜单:
对应的中文语言名称:批量导出 和 批量导入
菜单英文名称:keylink_export 和 keylink_import
模块名:admin
文件名:keylink
方法名:export 和 import
添加完之后关联链接里就有2个菜单,如图:
然后是功能实现代码:
涉及修改的文件路径为:/phpcms/modules/admin/keylink.php
打开这个文件,在合适的位置比如:
的上方增加:
/** * 导出关联链接为文本 一行一条记录 */ function export() { $result = $s = ''; $result = $this->db->select($where = '', $data = '*', $limit = '', $order = 'keylinkid DESC', $group = ''); if(!is_array($result) || empty($result)){ showmessage('暂无关联链接设置,正在返回!','?m=admin&c=keylink'); } foreach($result as $s){ extract($s); $str .= $word.','.$url."\n"; } $filename = L('keylink').'.txt'; header('Content-Type: text/x-sql'); header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: attachment; filename="' . $filename . '"'); $is_ie = 'IE'; if ($is_ie == 'IE') { header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); } else { header('Pragma: no-cache'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); } echo $str; exit(); }
/** * 从文本中导入关联链接, 一行一条记录 */ function import(){ if(isset($_POST['dosubmit'])){ $arr = $s = $str = ''; $s = trim($_POST['info']); if(empty($s)) showmessage(L('not_information'),'?m=admin&c=keylink&a=import'); $arr = explode("\n",$s); if(!is_array($arr) || empty($arr)) return false; foreach($arr as $s){ $str = explode(",",$s); $sql_str = array(); $sql_str['word'] = $str[0]; $sql_str['url'] = $str[1]; if(empty($sql_str['word'])){ continue; }else{ $check_word = $this->db->get_one(array('word'=>$sql_str['word']), $data = '*', $order = '', $group = ''); if($check_word){ continue; } $this->db->insert($sql_str); } unset($sql_str,$check_word); } showmessage(L('operation_success'),'?m=admin&c=keylink'); }else{ include $this->admin_tpl('keylink_import'); } }
然后新建一个模板文件,文件路径为:phpcms/modules/admin/templates/keylink_import.tpl.php
代码为:
<?php defined('IN_ADMIN') or exit('No permission resources.'); include $this->admin_tpl('header');?> <div class="pad_10"> <table cellpadding="2" cellspacing="1" class="table_form" width="100%"> <form action="?m=admin&c=keylink&a=import" method="post" name="myform"> <tr> <th width="10%">导入关联链接</th> <td width="200"><textarea name="info" cols="50" rows="6" require="true" datatype="limit" ></textarea> </td> </tr> <tr> <th>说明: </th> <td> 1.文件要求每行一个关联链接;<br> 2.请使用英文标点,参数之间用英文","隔开,如:关键词,链接。<br> </td> </tr> <tr> <th></th> <td> <input type="hidden" name="forward" value="?m=admin&c=keylink&a=import"> <input type="submit" name="dosubmit" value=" <?php echo L('submit')?> " class="button"> <input type="reset" name="reset" value=" <?php echo L('clear')?> " class="button"> </td> </tr> </form> </table> </div> </body> </html>
经过如上修改,就为phpcms v9关联链接增加了批量导入和导出功能了