From 8c6eeb8b42ee158a8186aaade9747a911ebd736f Mon Sep 17 00:00:00 2001 From: joyqi Date: Tue, 10 Dec 2013 12:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E5=90=8E=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- var/Widget/Ajax.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/var/Widget/Ajax.php b/var/Widget/Ajax.php index e5cfb4d4..4ebffdea 100644 --- a/var/Widget/Ajax.php +++ b/var/Widget/Ajax.php @@ -43,11 +43,11 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do $client = Typecho_Http_Client::get(); if ($client) { $client->setHeader('User-Agent', $this->options->generator) - ->send('http://code.google.com/feeds/p/typecho/downloads/basic'); + ->send('https://github.com/typecho/typecho/releases.atom'); /** 匹配内容体 */ $response = $client->getResponseBody(); - preg_match_all("/]*href=\"([^>]*)\"\s*\/>\s*([^>]*)<\/title>/is", $response, $matches); + preg_match_all("/<link rel=\"alternate\"[^>]+href=\"([^>]*)\"\s*\/>/is", $response, $matches); $result = array('available' => 0); list($soft, $version) = explode(' ', $this->options->generator); @@ -55,12 +55,16 @@ class Widget_Ajax extends Widget_Abstract_Options implements Widget_Interface_Do if ($matches) { foreach ($matches[0] as $key => $val) { - $title = trim($matches[2][$key]); - if (preg_match("/([0-9\.]+)\(([0-9\.]+)\)\-release/is", $title, $out)) { + $title = trim($matches[1][$key]); + if (preg_match("/v([0-9\.]+)\-([0-9\.]+)\-release$/is", $title, $out)) { if (version_compare($out[1], $current[0], '>=') && version_compare($out[2], $current[1], '>')) { - $result = array('available' => 1, 'latest' => $out[1] . '-' . $out[2], - 'current' => $current[0] . '-' . $current[1], 'link' => $matches[1][$key]); + $result = array( + 'available' => 1, + 'latest' => $out[1] . '-' . $out[2], + 'current' => $current[0] . '-' . $current[1], + 'link' => 'https://github.com' . $matches[1][$key] + ); break; } }