phpcms文章列表增加一键推送到百度功能
(1)打开phpcms\modules\content\content.php 在最下边增加推送方法
/** * 一键推送百度 */ public function push_bd() { $ids = $_POST['ids']; $ids = implode(',', $ids);//合并子栏目id if(!$ids) showmessage(L('you_do_not_check')); $catid = intval($_GET['catid']); if(!$catid) showmessage(L('missing_part_parameters')); $modelid = $this->categorys[$catid]['modelid']; $siteid = $this->categorys[$catid]['siteid']; $data = $urls = array(); $this->db = pc_base::load_model('content_model');//引入content模型 $this->db->set_model($modelid); $sql = "status=99 AND id IN ($ids)"; $order = "listorder desc, id desc"; $data = $this->db->select($sql, '*', '', $order, '', 'id'); foreach($data as $v){ $urls[] = $v['url']; }; /*获取appid和appsecret*/ $this->site = pc_base::load_model('site_model'); $siteinfo = $this->site->get_one(array('siteid'=>$siteid)); $setting = json_decode($siteinfo['setting'], true); $bdtoken = $setting['bdtoken'];//站长token $token = $setting['xtoken'];//熊掌token $appid = $setting['appid']; $domain = parse_url($siteinfo['domain']); $siteurl = $domain['host']; $res1 = $res2 = ''; if(!empty($bdtoken)){ $bdapi = 'http://data.zz.baidu.com/urls?site='.$siteurl.'&token='.$bdtoken; $res1 = json_decode(self::baidu_push($bdapi, $urls), true); } if(!empty($token) && !empty($appid)){ $api = 'http://data.zz.baidu.com/urls?appid='.$appid.'&token='.$token.'&type=realtime'; $res2 = json_decode(self::baidu_push($api, $urls), true); } if($res1 || $res2){ $text = ''; if($res1['success']){ $text .= '站长推送成功,成功数量'.$res1['success']; }else{ $text .= '站长推送失败,失败数量'.$res1['success']; } if($res2['success']){ $text .= '------熊掌推送成功,成功数量'.$res2['success_realtime']; }else{ if($res2['remain_realtime']){ $text .= '------熊掌推送失败,失败数量'.$res2['success_realtime']; }else{ $text .= '------<font color="red">今日熊掌推送次数已用完</font>'; } } showmessage($text,HTTP_REFERER,8000); }else { showmessage(L('operation_failure')); } } /* ** 百度推送处理函数 */ public function baidu_push($api, $urls){ $ch = curl_init(); $options = array( CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => implode("\n", $urls), CURLOPT_HTTPHEADER => array('Content-Type: text/plain'), ); curl_setopt_array($ch, $options); $result = curl_exec($ch); return $result; }
(2)phpcms\modules\content\templates\content_list.tpl.php 找到大概141行代码:
<input type="button" class="button" value="<?php echo L('remove');?>" onclick="myform.action='?m=content&c=content&a=remove&catid=<?php echo $catid;?>';myform.submit();"/>
在下边增加代码:
<input type="button" class="button" value="一键推送百度" onclick="myform.action='?m=content&c=content&a=push_bd&catid=<?php echo $catid;?>';myform.submit();"/>
(3)phpcms\modules\admin\templates\site_add.tpl.php 找到大概135代码:
<tr> <th width="130" valign="top"><?php echo L('site_att_allow_ext')?></th> <td class="y-bg"><input type="text" class="input-text" name="setting[upload_allowext]" id="upload_allowext" size="50" value="<?php echo $setting['upload_allowext']?>"/></td> </tr>
在下边新增代码:
<tr> <th width="130" valign="top">百度推送Token</th> <td class="y-bg"><input type="text" class="input-text" name="setting[bdtoken]" id="bdtoken" size="50" value="<?php echo $setting['bdtoken']?>"/></td> </tr> <tr> <th width="130" valign="top">百度熊掌号设置</th> <td class="y-bg">Appid:<input type="text" class="input-text" name="setting[appid]" id="appid" size="20" value="<?php echo $setting['appid']?>"/> Toekn:<input type="text" class="input-text" name="setting[xtoken]" id="xtoken" size="20" value="<?php echo $setting['xtoken']?>"/> </td> </tr>
(4)phpcms\modules\admin\templates\site_edit.tpl.php找到125行之后增加如上代码:
<tr> <th width="130" valign="top">百度推送Token</th> <td class="y-bg"><input type="text" class="input-text" name="setting[bdtoken]" id="bdtoken" size="50" value="<?php echo $setting['bdtoken']?>"/></td> </tr> <tr> <th width="130" valign="top">百度熊掌号设置</th> <td class="y-bg">Appid:<input type="text" class="input-text" name="setting[appid]" id="appid" size="20" value="<?php echo $setting['appid']?>"/> Toekn:<input type="text" class="input-text" name="setting[xtoken]" id="xtoken" size="20" value="<?php echo $setting['xtoken']?>"/> </td> </tr>
最后保存,更新后台缓存,即可实现对百度的手动推送
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
相关文章
phpcms-v9中将一个站点下的文章内容完美的推送到另一个站点下2024-09-24
phpcms loop循环判断是否为最后一条的代码2024-06-18
Phpcms V9 文章或图片模型增加相关下载功能2022-12-30
phpcms 标题SEO栏目不同的代码2022-11-14
PHPCMS替换内容的两种方法:str_replace和preg_replace2022-10-25
phpcms 搜索结果第一页比设定的多一条数据的解决办法2021-01-05
phpcms v9 字段多行文本不换行的解决办法2020-09-22
phpcms 栏目和文章页面“您没有访问该信息的权限”跳转登陆页面2020-09-17
phpcms 模板header包含action="lists"导致搜索结果错误的解决方案2020-04-26
phpcms转向链接过滤#的问题解决2020-04-23