-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdbplugins.php
203 lines (176 loc) · 8.69 KB
/
dbplugins.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
include("config.php");
include("lib/functions.php");
require_once 'lib/steam-condenser/lib/steam-condenser.php';
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($table) or die(mysql_error());
if(isset($_SERVER['argc'])) $args = getopt("u");
//$args = $args[ 'u' ];
if (!$args) { $start = head(); }
function dbpage() {
error_reporting(E_ALL);
//error_reporting(E_ERROR);
ini_set("display_errors", 1);
$result = mysql_query( "SELECT * from plugindb,mods where mods.t != 'NULL' and mods.threadid=plugindb.threadid and mods.author != 'AlliedModders LLC'" ) or die(mysql_error());
while( $row = mysql_fetch_array( $result ) ) {
foreach ($row as $key => $value) {
$$key = $value;
}
echo "$pluginid - \n";
echo "$author\n";
echo "$version\n";
echo "$description\n<br/>";
}
}
function openplugins() {
$list = mysql_query( "SELECT modid,filename,title from mods where threadid is not NULL order by filename" ) or die(mysql_error());
while ( $list2 = mysql_fetch_array( $list ) ) {
// $selects .= "<option value=\"" . $list2['modid'] . " - " . $list2['filename'] . " - " . $list2['title'] . "\" </option>";
$selects .= "<option value=\"" . $list2['modid'] . "\">" . $list2['filename'] . "</option>\n";
}
//$list = mysql_query( "SELECT * from mods where threadid != NULL" ) or die(mysql_error());
$result = mysql_query( "SELECT * from mods where threadid is NULL and author != 'AlliedModders LLC'" ) or die(mysql_error());
if (mysql_num_rows($result)) {
echo '<fieldset><legend>Plugins without TreadID, fill in \'0\' to stop checking, or before you continue try the <a href="dbplugins.php?action=matches">Automatic matcher</a> in case you filled in threadid\'s before.</legend>';
while( $row2 = mysql_fetch_array( $result ) ) {
foreach ($row2 as $key => $value) {
$$key = $value;
}
echo "<fieldset><legend>$filename</legend>";
echo "<form method=get action=''>";
echo "Title : $title<br/>\n";
echo "Author : $author<br/>\n";
echo "Version : $version<br/>\n";
echo "URL : <a href=\"$url\">$url</a></br>\n";
echo "<input name=\"action\" type=\"hidden\" value=\"modthreadid\"><br/>";
echo "<input name=\"modid\" type=\"hidden\" value=\"$modid\"><br/>";
echo "<input name=\"threadid\" size=\"6\"> <input type=\"submit\" value=\"<- Threadid |OR| Select to which plugin it belongs ->\">";
echo "<select name=\"pluginmatch\">\n<option value=\"Select\">Select</option>\n";
echo $selects;
echo "</select>";
echo "</form>";
echo "</fieldset>";
}
echo '</fieldset>';
} else {
echo '<br/><b>All plugins are accounted for. All have either a threadid or the check disabled for it.</b><br/>';
}
}
function dbcompare() {
$settings = getsettings();
$result = mysql_query("select plugindb.description as dbdescr, plugindb.version as dbvers, mods.version as modvers, mods.filename, plugindb.threadid, plugindb.send from plugindb, mods where mods.threadid = plugindb.threadid and mods.version != plugindb.version and plugindb.threadid != '0'") or die (mysql_error());
if (mysql_num_rows($result)) {
echo "<table class=\"listtable\" align=\"left\"><tr class=\"headers\"><td></td><td>Plugin</td><td>Version</td><td>Current Version</td></tr>";
while( $row2 = mysql_fetch_array( $result ) ) {
foreach ($row2 as $key => $value) {
$$key = $value;
}
if (version_compare($modvers,$dbvers,'<')) {
echo "
<tr class=\"elements\"><td><img src=images/new.png></td><td><a href=\"http://forums.alliedmods.net/showthread.php?t=$threadid\">$filename</a></td><td>$dbvers</td><td>$modvers</td></tr>";
if ( $send == 'no' ) {
$subject = "Plugin $filename has a newer version on alliedmodders";
$message = "A update for $filename ($dbdescr) seems to be out, $dbvers is the latest. We have $modvers running....\nhttp://forums.alliedmods.net/showthread.php?t=$threadid";
mail($settings['emailalert']['config'], $subject, $message, null);
mysql_query("UPDATE plugindb SET send = 'yes' where threadid = '$threadid'") or die (mysql_error());
}
} else { mysql_query("UPDATE plugindb SET send = 'no' where threadid = '$threadid'") or die (mysql_error()); }
}
echo "</table><br/><br/><br /><br /><br/>";
} else { echo '<br/><b>-- No plugins are outdated, your a champ!</b><br/>'; }
}
function doplugin($threadid,$filename,$args) {
$html = file_get_contents("http://forums.alliedmods.net/showthread.php?t=$threadid&postcount=1");
$url = array();
preg_match("/Plugin ID.*?<div.*?>(.*?)<\/div>.*?Plugin Version.*?<div.*?>(.*?)<\/div>.*?Plugin Description:.*?<div.*?>(.*?)<\/div>.*?(\d{2}-\d{2}-\d{4}).*?/si", $html, $url);
array_shift($url);
print_r($url);
//if ($json == "NOTFOUND") { echo "MISS -> Threadid not found, make sure you use THREADID, not POSTID\n"; return; }
//$data = json_decode($json);
//$changefiles = str_replace(".sp",".smx", $data->files);
//$uniqfiles = array_unique($changefiles);
//foreach($uniqfiles as $allfiles) {
// if (preg_match( '/\.smx/i', $allfiles)) {
// $alles[] = $allfiles;
// }
// }
echo "Plugin information:\n";
// if (!empty($alles)) {
// $comma = implode(",", $alles);
// } else {
// echo ' ^ No files found : ';
// }
// $lastupdate = date("Y-m-d H:i:s",intval($data->last_updated));
$description = mysql_escape_string($url[2]);
if ($url) {
echo "HIT -> $url[2]\n";
}
echo "$url";
$result = mysql_query( "INSERT INTO plugindb (pluginid,threadid,filename,description,version) VALUES('$url[0]','$threadid','$filename','$description','$url[1]') ON DUPLICATE KEY UPDATE description='$description',version='$url[1]'") or die(mysql_error());
}
function threadmatch() {
$settings = getsettings();
$result = mysql_query("select threadid,filename from plugindb") or die (mysql_error());
while($dbres = mysql_fetch_assoc($result)){
$filepieces = explode(",", $dbres['filename']);
$threadarray[] = array(threadid=> $dbres['threadid'],files => $filepieces);
}
$result = mysql_query("select modid,filename from mods where threadid = ''") or die (mysql_error());
while( $row = mysql_fetch_array( $result ) ) {
foreach($threadarray as $thread) {
//print_r($thread);
foreach($thread['files'] as $files) {
if ($row['filename'] == "$files") {
echo "matched " . $row['filename'] . " with threaid " . $thread['threadid'] . "<br/>\n";
mysql_query( "UPDATE mods set threadid = " . $thread['threadid'] . " where modid = " . $row['modid'] ) or die(mysql_error());
}
}
}
}
echo "<pre>";
//print_r($threadarray);
echo "</pre>";
}
if( isset( $args[ 'u' ] ) ) {
$result = mysql_query( "select distinct threadid from mods where threadid != 'NULL' and threadid != '0'" ) or die(mysql_error());
while( $row = mysql_fetch_array( $result ) ) {
echo "Updating " . $row['threadid'] . "... ";
doplugin($row['threadid'],$row['filename'],$args);
}
dbcompare();
}
if (!$args) {
if ($_GET['action']) {
if ($_GET['action'] == "modthreadid") {
if ($_GET['pluginmatch'] == "Select") {
$result = mysql_query( "UPDATE mods set threadid = '" . $_GET['threadid'] . "' WHERE modid = " . $_GET['modid'] ) or die(mysql_error());
echo "<b> ModID " . $_GET['modid'] . " Updated Correctly with threadid : " . $_GET['threadid'] . "</b><br/>";
} else {
// this is the matched plugin select
$getinfo = mysql_query( "SELECT threadid, filename,modid from mods where modid = '" . $_GET['pluginmatch'] . "' or modid = '" . $_GET['modid'] ."'");
while( $check = mysql_fetch_array( $getinfo ) ) {
if ($check['modid'] == $_GET['modid']) {
$newfilenames = $check['filename'];
$newthreadid = $check['threadid'];
} else {
$oldfilenames = $check['filename'];
$oldthreadid = $check['threadid'];
}
}
$result = mysql_query( "UPDATE mods set threadid = '" . $newthreadid . "' where modid = '" . $_GET['modid'] . "'" ) or die(mysql_error());
// also update the filenames..
$totalfile = $oldfilenames . "," . $newfilenames;
$result = mysql_query( "UPDATE mods set filename = '" . $totalfile . "' where modid = '" . $_GET['pluginmatch'] . "'" ) or die(mysql_error());
}
}
if ($_GET['action'] == "matches") {
threadmatch();
}
}
//dbpage();
dbcompare();
openplugins();
bottom( $start );
}
mysql_close();
?>