Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
phpgao committed Jan 25, 2015
1 parent b9eac68 commit e11a57a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
52 changes: 32 additions & 20 deletions Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public function baidusitemap()
}

$method = strval($_GET['m']);
if(in_array($method,array('indexall','indexinc'))){
#if (method_exists($this, $method)) {
call_user_func_array(array($this, $method),$_REQUEST);
if (in_array($method, array('indexall', 'indexinc'))) {
#if (method_exists($this, $method)) {
call_user_func_array(array($this, $method), $_REQUEST);
BaidusubmitSetting::logger('外部', '请求', 'sitemap', '成功', $_SERVER['HTTP_USER_AGENT']);
}else{
} else {
BaidusubmitSetting::logger($_SERVER['HTTP_USER_AGENT'], '请求', 'sitemap', 'failed', "Wrong param {$method}");
}
}
Expand All @@ -58,9 +58,9 @@ protected function indexall()
# 默认取设置的个数
$max_num = BaidusubmitSetting::get_plugin_config()->max;

if($max_num == 0){
if ($max_num == 0) {
$ids = BaidusubmitSitemap::get_post_id_by_range(1);
}else{
} else {
$ids = BaidusubmitSitemap::get_post_id_by_max($max_num);
}

Expand Down Expand Up @@ -88,44 +88,56 @@ protected function print_xml_footer()
echo '</urlset>';
}

public function send_add_xml($a,$b){
public function send_add_xml($a, $b)
{

require '.' . __TYPECHO_PLUGIN_DIR__ . '/BaiduSubmit/inc/' . 'sitemap.php';
require '.' . __TYPECHO_PLUGIN_DIR__ . '/BaiduSubmit/inc/' . 'setting.php';

$plugin_option = BaidusubmitSetting::get_plugin_config();

if(0 == $plugin_option->realtime){
return 1;
}
$post = $b->next();
if($post['status'] != 'publish' || $post['created']>time()) {
if ($post['status'] != 'publish' || $post['created'] > time()) {
BaidusubmitSetting::logger('', '提交删除', '百度服务器', 'failed', '条件错误');
return false;
}
$id = $post['cid'];
if($id){
if ($id) {
$schemas = BaidusubmitSitemap::gen_elenment_by_cid($id);
$base_xml = $schemas[0]->toXml();
$content = BaidusubmitSitemap::genPostXml($base_xml);
$r = BaidusubmitSitemap::sendXml($content, 1);
if(false !== $r){
BaidusubmitSetting::logger('','提交更新','百度服务器','success',"文章ID->{$id}" . $r);
}else{
BaidusubmitSetting::logger('','提交更新','百度服务器','failed',"文章ID->{$id}" . $r);
if (false !== $r) {
BaidusubmitSetting::logger('', '提交更新', '百度服务器', 'success', "文章ID->{$id}" . $r);
} else {
BaidusubmitSetting::logger('', '提交更新', '百度服务器', 'failed', "文章ID->{$id}" . $r);
}
}
}

public function send_del_xml($id,$b){
public function send_del_xml($id, $b)
{

require_once '.' . __TYPECHO_PLUGIN_DIR__ . '/BaiduSubmit/inc/' . 'sitemap.php';
require_once '.' . __TYPECHO_PLUGIN_DIR__ . '/BaiduSubmit/inc/' . 'setting.php';
$plugin_option = BaidusubmitSetting::get_plugin_config();

if(0 == $plugin_option->realtime){
return 1;
}

if($id){
debug_print_backtrace();
if ($id) {
$schemas = BaidusubmitSitemap::gen_elenment_by_cid($id);
$base_xml = $schemas[0]->toXml();
$content = BaidusubmitSitemap::genDeleteXml($base_xml);
$r = BaidusubmitSitemap::sendXml($content, 2);
if(false !== $r){
BaidusubmitSetting::logger('','提交删除','百度服务器','success',"文章ID->{$id}" . $r);
}else{
BaidusubmitSetting::logger('','提交删除','百度服务器','failed',"文章ID->{$id}" . $r);
if (false !== $r) {
BaidusubmitSetting::logger('', '提交删除', '百度服务器', 'success', "文章ID->{$id}" . $r);
} else {
BaidusubmitSetting::logger('', '提交删除', '百度服务器', 'failed', "文章ID->{$id}" . $r);
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public static function config(Typecho_Widget_Helper_Form $form)
$passwd = new Typecho_Widget_Helper_Form_Element_Hidden('passwd', NULL, NULL, _t('passwd'));
$form->addInput($passwd);

$max = new Typecho_Widget_Helper_Form_Element_Text('max', null, 5000, _t('一个sitemap文件中包含主题数'),'0表示所有文章(慎用)');
$max = new Typecho_Widget_Helper_Form_Element_Text('max', null, 5000, _t('一个sitemap文件中包含主题数'), '0表示所有文章(慎用)');
$form->addInput($max);

$renew = new Typecho_Widget_Helper_Form_Element_Radio('delete', array(0 => '不删除', 1 => '删除'), 0, _t('卸载是否删除数据表'));
$form->addInput($renew);

$real_time = new Typecho_Widget_Helper_Form_Element_Radio('realtime', array(0 => '非即时', 1 => '即时'), 0, _t('是否即时推送信息'), '即时的意思是发布和删除文章的同时向百度服务器提交');
$form->addInput($real_time);

}

Expand Down Expand Up @@ -121,7 +123,7 @@ public static function configHandle($config, $is_init)

if (isset($data->status) && '0' != $data->status) {
BaidusubmitSetting::logger('', '获取checksign', '百度站长', 'failed', array($config_from_file, $result));
}else{
} else {
BaidusubmitSetting::logger('', '获取checksign', '百度站长', 'success', $result);

}
Expand All @@ -138,7 +140,7 @@ public static function configHandle($config, $is_init)
$output = json_decode($authData);

if (isset($output->status) && '0' == $output->status) {
#if (1) {
#if (1) {
$token = $output->token;
$config['token'] = $token;

Expand Down Expand Up @@ -259,9 +261,9 @@ public static function remove_table()
//删除表
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
try{
try {
$db->query("DROP TABLE `" . $prefix . "baidusubmit`", Typecho_Db::WRITE);
}catch (Typecho_Exception $e){
} catch (Typecho_Exception $e) {

}
}
Expand Down
8 changes: 3 additions & 5 deletions inc/sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ static function httpSend($url, $limit = 0, $post = '', $cookie = '', $timeout =
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$data = curl_exec($ch);
file_put_contents('/tmp/baidusitemap.log',$data,FILE_APPEND);
$status = curl_getinfo($ch);
$errno = curl_errno($ch);
curl_close($ch);
Expand Down Expand Up @@ -625,7 +624,6 @@ static function httpSend($url, $limit = 0, $post = '', $cookie = '', $timeout =
}
}
@fclose($fp);
file_put_contents('/tmp/baidusitemap.log',$return,FILE_APPEND);

return $return;
}
Expand All @@ -647,13 +645,13 @@ static function headerStatus($status)
*/
public static function get_post_id_by_max($max)
{
if($max < 1 ){
if ($max < 1) {
throw new Typecho_Exception('max取值错误');
}
$db = Typecho_Db::get();

$ids = $db->fetchAll($db->select('cid')->from('table.contents')->order('cid',Typecho_Db::SORT_DESC)->limit($max));
if(false != $ids){
$ids = $db->fetchAll($db->select('cid')->from('table.contents')->order('cid', Typecho_Db::SORT_DESC)->limit($max));
if (false != $ids) {
$last_id = array_pop($ids);
}
return self::get_post_id_by_range($last_id['cid']);
Expand Down

0 comments on commit e11a57a

Please sign in to comment.