Permalink
Browse files

close #662

  • Loading branch information...
joyqi committed Nov 12, 2017
1 parent 4a5f1ae commit abcecb124dd01da086c48e692aa5b92c0502f463
Showing with 28 additions and 22 deletions.
  1. +28 −22 var/Widget/Ajax.php
View
@@ -43,29 +43,35 @@ public function checkVersion()
$client = Typecho_Http_Client::get();
if ($client) {
$client->setHeader('User-Agent', $this->options->generator)
->setTimeout(10)
->send('http://typecho.org/version.json');
/** 匹配内容体 */
$response = $client->getResponseBody();
$json = json_decode($response, true);
if (!empty($json)) {
list($soft, $version) = explode(' ', $this->options->generator);
$current = explode('/', $version);
if (isset($json['release']) && isset($json['version'])
&& preg_match("/^[0-9\.]+$/", $json['release'])
&& preg_match("/^[0-9\.]+$/", $json['version'])
&& version_compare($json['release'], $current[0], '>=')
&& version_compare($json['version'], $current[1], '>')) {
$result = array(
'available' => 1,
'latest' => $json['release'] . '-' . $json['version'],
'current' => $current[0] . '-' . $current[1],
'link' => 'http://typecho.org/download'
);
->setTimeout(10);
$result = array('available' => 0);
try {
$client->send('http://typecho.org/version.json');
/** 匹配内容体 */
$response = $client->getResponseBody();
$json = json_decode($response, true);
if (!empty($json)) {
list($soft, $version) = explode(' ', $this->options->generator);
$current = explode('/', $version);
if (isset($json['release']) && isset($json['version'])
&& preg_match("/^[0-9\.]+$/", $json['release'])
&& preg_match("/^[0-9\.]+$/", $json['version'])
&& version_compare($json['release'], $current[0], '>=')
&& version_compare($json['version'], $current[1], '>')) {
$result = array(
'available' => 1,
'latest' => $json['release'] . '-' . $json['version'],
'current' => $current[0] . '-' . $current[1],
'link' => 'http://typecho.org/download'
);
}
}
} catch (Exception $e) {
// do nothing
}
$this->response->throwJson($result);

0 comments on commit abcecb1

Please sign in to comment.