forked from turanct/jnet-version-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_version.php
137 lines (106 loc) · 2.96 KB
/
get_version.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
//***********************************************************
// Get Latest version info from Project Sites
//***********************************************************
class FOSSVersions {
// Variables ----------------------------
public $version;
// Methods ------------------------------
// Constructor
public function __construct($project) {
// Typecast
$project = ucfirst(strtolower((string) $project));
// Check if the method exists
if (method_exists($this, $project)) {
$this->version = $this->$project();
}
}
// Method to get latest Wordpress version
private function Wordpress() {
// Method vars
$url = 'https://wordpress.org/download/';
$match = '/<strong>Download WordPress ([\d\.]*)<\/strong>/i';
// Return
return $this->version($url, $match);
}
// Method to get latest Joomla version
private function Joomla() {
// Method vars
$url = 'http://www.joomla.org/download.html';
$match = '/<td width="265">([\d\.]*)\sFull\sPackage<\/td>/i';
// Return
return $this->version($url, $match);
}
// Method to get latest Gallery version
private function Gallery() {
// Method vars
$url = 'http://gallery.menalto.com/';
$match = '/<a\sclass=\"db_g\d\"\shref\=\".*?\">Gallery\s([\d\.]*)<\/a>/i';
// Return
return $this->version($url, $match);
}
// Method to get latest Drupal version
private function Drupal() {
// Method vars
$url = 'https://drupal.org/project/drupal';
$match = '/<tr.*?release\-update\-status\-0.*?>[\s\t\n]*?<td.*?views\-field\-version.*?>[\s\t\n]*?<a.*?>([\d\.]*)<\/a>/i';
// Return
return $this->version($url, $match);
}
// Method to get latest phpBB version
private function Phpbb() {
// Method vars
$url = 'http://www.phpbb.com/';
$match = '/<span\sclass\=\"version\">([\d\.]*)<\/span>/i';
// Return
return $this->version($url, $match);
}
// Helper Methods -----------------------
// Method to get the version number array or false
private function version($url, $match) {
// Match
$match = $this->match($match, @file_get_contents($url));
// Did we find a match?
if ($match !== false) {
// Return version
return $match[1];
}
else {
// Return false
return false;
}
}
// Method to simplify preg_match and preg_match_all
private function match($pattern, $subject) {
// Run The Match
$match = preg_match_all($pattern, $subject, $matches);
// Check Matches
if ($match != 0 && $match !== false && isset($matches) && is_array($matches)) {
// Return Matches
return $matches;
}
else {
// Return
return false;
}
}
}
// Run the class if we're not included
if (basename(__FILE__) == basename($_SERVER['PHP_SELF'])) {
if (isset($argv)) {
// Get argv
$a = $argv;
// Options (nr. 1 = keyword)
$keyword = $a[1];
}
else {
// Get GET data
$keyword = $_GET['s'];
}
// Create new FOSSVersions instance
$versions = new FOSSVersions($keyword);
// Print
echo implode("\n", (array) $versions->version);
echo "\n";
}
?>