1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Mage Scan |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category MageScan |
8
|
|
|
* @package MageScan |
9
|
|
|
* @author Dardo Guidobono <[email protected]> |
10
|
|
|
* @copyright 2016 Dardo Guidobono |
11
|
|
|
* @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 |
12
|
|
|
* @link https://github.com/steverobbins/magescan |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace MageScan\Check\Version; |
16
|
|
|
|
17
|
|
|
use GuzzleHttp\Psr7\Response; |
18
|
|
|
use MageScan\Check\AbstractCheck; |
19
|
|
|
use MageScan\Check\Version; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Scan for Magento edition and version via doc block style comment |
23
|
|
|
* |
24
|
|
|
* @category MageScan |
25
|
|
|
* @package MageScan |
26
|
|
|
* @author Dardo Guidobono <[email protected]> |
27
|
|
|
* @copyright 2016 Dardo Guidobono |
28
|
|
|
* @license http://creativecommons.org/licenses/by/4.0/ CC BY 4.0 |
29
|
|
|
* @link https://github.com/steverobbins/magescan |
30
|
|
|
*/ |
31
|
|
|
class DownloaderComment extends AbstractCheck |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Guess magento edition and version |
35
|
|
|
* |
36
|
|
|
* @return array|boolean |
37
|
|
|
*/ |
38
|
|
|
public function getInfo() |
39
|
|
|
{ |
40
|
|
|
$response = $this->getRequest()->get('downloader'); |
41
|
|
|
$year = $this->getMagentoYear($response); |
42
|
|
|
if ($year) { |
|
|
|
|
43
|
|
|
$version = $this->getMagentoVersion($response); |
44
|
|
|
$edition = $this->getMagentoEditionByYearAndVersion($year, $version); |
|
|
|
|
45
|
|
|
return [$edition, $version]; |
46
|
|
|
} |
47
|
|
|
return false; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Guess Magento year from downloader url |
52
|
|
|
* |
53
|
|
|
* @param Response $response |
54
|
|
|
* |
55
|
|
|
* @return string|boolean |
56
|
|
|
*/ |
57
|
|
|
public function getMagentoYear(Response $response) |
58
|
|
|
{ |
59
|
|
|
|
60
|
|
View Code Duplication |
if ($response->getStatusCode() == 200) { |
61
|
|
|
preg_match('/([0-9]{4}).*Magento/', $response->getBody(), $match); |
62
|
|
|
if (isset($match[1])) { |
63
|
|
|
return $match[1]; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Guess Magento version from downloader body |
71
|
|
|
* |
72
|
|
|
* @param Response $response |
73
|
|
|
* |
74
|
|
|
* @return string|boolean |
75
|
|
|
*/ |
76
|
|
|
public function getMagentoVersion(Response $response) |
77
|
|
|
{ |
78
|
|
View Code Duplication |
if ($response->getStatusCode() == 200 ) { |
79
|
|
|
if ( preg_match('/([0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}(\.[0-9]{1,2})?)/', $response->getBody(), $match) ){ |
80
|
|
|
return $match[1]; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Guess Magento edition from copyright year and version |
88
|
|
|
* |
89
|
|
|
* @param string $year |
90
|
|
|
* @param string $version |
91
|
|
|
* |
92
|
|
|
* @return string |
93
|
|
|
*/ |
94
|
|
|
protected function getMagentoEditionByYearAndVersion($year, $version) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
return 'Unknown'; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: