Browse Source

Version 1 trouvée

alpha
commit
54c24457e9

+ 192
- 0
addrelease.php View File

@@ -0,0 +1,192 @@
1
+<?php
2
+set_time_limit('240');
3
+function addRelease($input) {
4
+	$debug = false;
5
+	// D�finition des variables de travail
6
+	$lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
7
+	$lastVersions_e_backup = $lastVersions_e;
8
+	if ($input == 'r') {
9
+		$lastVersions_e[1] = 'UP';
10
+	} else {
11
+		$lastVersions_e[3] = 'UP';
12
+	}
13
+	// Enregistrement des donn�es d'ajout
14
+	$lastVersions_e[0] = time();
15
+	$lastVersions_txt = fopen('lastVersions.txt', 'w');
16
+	fwrite($lastVersions_txt, implode('|', $lastVersions_e));
17
+	fclose($lastVersions_txt);
18
+	if ($input == 'r') {
19
+		$type = 'r';
20
+		$url = 'http://s3.amazonaws.com/MinecraftDownload/minecraft.jar';
21
+	} else {
22
+		$type = 'apr';
23
+		$url = 'http://assets.minecraft.net/'.$input.'/minecraft.zip';
24
+	}
25
+	
26
+	// Chargement du XML
27
+	$data = new DomDocument();
28
+	$data->load('data.xml');
29
+	$dataNode = $data->getElementsByTagName('data')->item(0);
30
+	$mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
31
+	$id = $mcupdatesNode->getAttribute('total')+1;
32
+	$releaseS = $mcupdatesNode->getElementsByTagName('release');
33
+	$release = $releaseS->item($releaseS->length-1);
34
+	
35
+	// Creation du noeud XML
36
+	$releaseNode = $data->createElement('release');
37
+	$mcupdatesNode->appendChild($releaseNode);
38
+	$infosNode = $data->createElement('infos');
39
+	$releaseNode->appendChild($infosNode);
40
+	$files = $data->createElement('files');
41
+	$releaseNode->appendChild($files);
42
+	
43
+	// Extraction et copie de minecraft.jar
44
+	$directory = $id.' - '.$lastVersions_e[0].' ('.rand(1, 1000).')';
45
+	if (!mkdir($directory) OR !copy($url, $directory.'/minecraft.jar')) { return 'ERREUR Impossible de copier le fichier ou de cr�er un nouveau dossier.';}
46
+	if ($type == 'r') {
47
+            $zip = new ZipArchive;
48
+            if ($zip->open($directory.'/minecraft.jar') AND mkdir($directory.'/content')) {
49
+                $zip->extractTo($directory.'/content');
50
+                $zip->close();
51
+            }
52
+        } else {
53
+            $zip = new ZipArchive;
54
+            if ($zip->open($directory.'/minecraft.jar') AND mkdir($directory.'/extract')) {
55
+		$zip->extractTo($directory.'/extract');
56
+		$zip->close();
57
+		$zip2 = new ZipArchive;
58
+		if ($zip2->open($directory.'/extract/bin/minecraft.jar') AND mkdir($directory.'/content')) {
59
+			$zip2->extractTo($directory.'/content');
60
+			$zip2->close();
61
+		} else {
62
+			return 'ERREUR Impossible d\'extraire le fichier ou de cr�er un nouveau dossier².';
63
+		}
64
+            } else {
65
+            	return 'ERREUR Impossible d\'extraire le fichier ou de cr�er un nouveau dossier.';
66
+            }
67
+        }
68
+	$md5 = md5_file($directory.'/minecraft.jar');
69
+	directoryConstruct($directory.'/content', $files, $data, directoryOld($release));
70
+	
71
+	// Detection de $givenName
72
+	// Code par @EphysPatato
73
+	$minecraft_class = file_get_contents($directory.'/content/net/minecraft/client/Minecraft.class');
74
+	$givenName = 'false';
75
+	if (preg_match('/Minecraft Minecraft (.+)Minecraft main/', $minecraft_class, $matches)) {
76
+		$givenName = '';
77
+		$givenName_w = $matches[count($matches)-1];
78
+		for( $i = 0 ; $i < strlen($givenName_w) ; $i++ )
79
+		{
80
+			$givenName_cw = substr($givenName_w, $i, 1);
81
+			if(($givenName_cw >= 'a' && $givenName_cw <= 'z') || ($givenName_cw >= 'A' && $givenName_cw <= 'Z') || ($givenName_cw >= '0' && $givenName_cw <= '9') || $givenName_cw == '|' || $givenName_cw == '.' || $givenName_cw == '_' || $givenName_cw == '-')
82
+				$givenName .= $givenName_cw;
83
+		}
84
+	}
85
+	// Sp�cifications selon le type de release
86
+	if ($type == 'r') {
87
+		$name = $givenName;
88
+		$lastVersions_e[1] = $name;
89
+		$lastVersions_e[2] = $md5;
90
+		$infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history#'.$name);	
91
+	} else {
92
+		$name = $input;
93
+		$lastVersions_e[3] = $name;
94
+		$lastVersions_e[4] = $md5;
95
+		$infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history/Development_versions#'.$name);
96
+	}
97
+	
98
+	// Mise des infos dans le XML
99
+	$releaseNode->setAttribute('id', $id);
100
+	$releaseNode->setAttribute('name', $name);	
101
+	$releaseNode->setAttribute('type', $type);
102
+	$infosNode->setAttribute('givenName', $givenName);
103
+	$infosNode->setAttribute('directory', $directory);
104
+	$infosNode->setAttribute('link', $url);
105
+	$infosNode->setAttribute('size', filesize($directory.'/minecraft.jar'));
106
+	$infosNode->setAttribute('md5', $md5);
107
+	$infosNode->setAttribute('sha1', sha1_file($directory.'/minecraft.jar'));
108
+	$infosNode->setAttribute('date', $lastVersions_e[0]);
109
+	$infosNode->setAttribute('shortDescription', 'false');
110
+	$mcupdatesNode->setAttribute('total', $id);
111
+	
112
+	// Sauvegarde finale
113
+	$lastVersions_e[0] = time();
114
+	$lastVersions_e[5] = $id;
115
+	$lastVersions_e[6] = $name;
116
+	$lastVersions_e[7] = $type;
117
+	$id = $mcupdatesNode->setAttribute('total', $id);
118
+	$lastVersions_f = fopen('lastVersions.txt', 'w');
119
+	$lastError = error_get_last();
120
+	if ($debug) { echo substr($lastError['file'], -14); }
121
+	if ($lastError /*AND $lastError['type']!= 2 */AND substr($lastError['file'], -14) == 'addrelease.php') {
122
+		fwrite($lastVersions_f, implode('|', $lastVersions_e_backup));
123
+		rrmdir($directory);
124
+		return 'ERREUR "'.$lastError['message'].'" (type : '.$lastError['type'].') dans '.$lastError['file'].' ligne '.$lastError['line'].'.';
125
+	} else {
126
+		$data->save('data.xml');
127
+		fwrite($lastVersions_f, implode('|', $lastVersions_e));
128
+		fclose($lastVersions_f);
129
+		return implode('|', $lastVersions_e);
130
+	}
131
+}
132
+function directoryConstruct($directoryName, $XML, $data, $array) {
133
+	$directory = opendir($directoryName); 
134
+	while($file = readdir($directory)) {
135
+		if ($file != '.' AND $file != '..') {
136
+			if (is_dir($directoryName.'/'.$file)) {
137
+				$newDirectory = $data->createElement('dir');
138
+				$XML->appendChild($newDirectory);
139
+				$newDirectory->setAttribute('name', $file);
140
+				if (isset($array[$file])) {
141
+					$newDirectory->setAttribute('comparaison', 'same');
142
+					directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, $array[$file]);
143
+				} else {
144
+					$newDirectory->setAttribute('comparaison', 'added');
145
+					directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, array());
146
+				}
147
+			} else {
148
+				$fileXML = $data->createElement('file');
149
+				$XML->appendChild($fileXML);
150
+				$fileXML->setAttribute('name', $file);
151
+				$fileXML->setAttribute('md5', md5_file($directoryName.'/'.$file));
152
+				if (isset($array[$file])) {
153
+					if ($array[$file] == md5_file($directoryName.'/'.$file)) {
154
+						$fileXML->setAttribute('comparaison', 'same');
155
+					} else {
156
+						$fileXML->setAttribute('comparaison', 'change');
157
+					}
158
+				} else {
159
+					$fileXML->setAttribute('comparaison', 'added');
160
+				}
161
+				// TODO Verifier si un fichier a �t� supprim�	
162
+			}
163
+		}
164
+	}
165
+}
166
+function directoryOld($XML) {
167
+$array = array();
168
+	$dirS = $XML->getElementsByTagName('dir');
169
+	for ($c = $dirS->length, $i = 0; $i < $c; $i++) {
170
+		$dir = $dirS->item($i);
171
+		$array[$dir->getAttribute('name')]= directoryOld($dir);
172
+	}
173
+	$fileS = $XML->getElementsByTagName('file');
174
+	for ($c = $fileS->length, $i = 0; $i < $c; $i++) {
175
+		$file = $fileS->item($i);
176
+		$array[$file->getAttribute('name')] = $file->getAttribute('md5');
177
+	}
178
+	return $array;
179
+}
180
+function rrmdir($dir) { // Par holger1@NOSPAMzentralplan.de
181
+   if (is_dir($dir)) { 
182
+     $objects = scandir($dir); 
183
+     foreach ($objects as $object) { 
184
+       if ($object != "." && $object != "..") { 
185
+         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
186
+       } 
187
+     } 
188
+     reset($objects); 
189
+     rmdir($dir); 
190
+   } 
191
+ } 
192
+?>

+ 27
- 0
data.xml
File diff suppressed because it is too large
View File


+ 179
- 0
design.css View File

@@ -0,0 +1,179 @@
1
+* {
2
+	margin: 0px;
3
+	padding: 0px;
4
+}
5
+
6
+body {
7
+	font-family: "Trebuchet MS";
8
+	background-image: url('images/background_pattern.png');
9
+	text-shadow : 0px 2px 23px white;
10
+}
11
+
12
+h1 {
13
+	color: #2D4C6B;
14
+	text-align: center;
15
+	margin: 15px;
16
+}
17
+
18
+h3 {
19
+	margin: 18px 18px 0px 18px;
20
+}
21
+
22
+.more, .releaseFilesButton {
23
+	padding: 0px 5px;
24
+}
25
+
26
+p {
27
+	margin: 0px 0px 10px 0px;
28
+}
29
+
30
+li {
31
+	margin-left: 25px;
32
+	line-height: 25px;
33
+}
34
+
35
+#body {
36
+	-webkit-border-radius: 3px;
37
+	-moz-border-radius: 3px;
38
+	border-radius: 3px;
39
+	background-color: white;
40
+	margin: 25px;
41
+	padding: 10px;
42
+	box-shadow: 0px 3px 10px #222323;
43
+	-webkit-box-shadow : 0px 3px 10px #222323;
44
+	-moz-box-shadow : 0px 3px 10px #222323;
45
+	background-image: url('images/body_pattern.png');
46
+}
47
+
48
+#allreleases {
49
+	margin: 10px;
50
+}
51
+
52
+#copyright {
53
+	float: right;
54
+}
55
+
56
+footer {
57
+	-webkit-border-radius: 3px;
58
+	-moz-border-radius: 3px;
59
+	border-radius: 3px;
60
+	background-color: white;
61
+	margin: 25px;
62
+	padding: 10px;
63
+	box-shadow: 0px 3px 10px #222323;
64
+	-webkit-box-shadow : 0px 3px 10px #222323;
65
+	-moz-box-shadow : 0px 3px 10px #222323;
66
+	background-image: url('images/body_pattern.png');
67
+	overflow: hidden;
68
+}
69
+
70
+a {
71
+	color: #0f7eff;
72
+	text-decoration: none;
73
+	font-weight: bold;
74
+	text-shadow : 0px 2px 15px white;
75
+}
76
+.release {
77
+	border: #3d3d3d 2px solid;
78
+	padding: 10px;
79
+	background-color: white;
80
+	color: black;
81
+	background-image: url('images/release_pattern.png');
82
+	margin: 0px 15px 15px 15px;
83
+	-webkit-border-radius: 6px;
84
+	-moz-border-radius: 6px;
85
+	border-radius: 6px;
86
+}
87
+
88
+.download , .changelog, .files{
89
+	border: 1px solid black;
90
+	-webkit-border-radius: 6px;
91
+	-moz-border-radius: 6px;
92
+	border-radius: 6px;
93
+	margin: 5px;
94
+	padding: 5px;
95
+}
96
+
97
+.wiki, .releaseFilesContainer {
98
+	background-color: white;
99
+	margin: 25px;
100
+	padding: 10px;
101
+	-webkit-border-radius: 6px;
102
+	-moz-border-radius: 6px;
103
+	border-radius: 6px;
104
+	box-shadow: 0px 1px 10px #222323;
105
+	-webkit-box-shadow : 0px 1px 10px #222323;
106
+	-moz-box-shadow : 0px 1px 10px #222323;
107
+}
108
+
109
+.shortDescription {
110
+	font-style: italic;
111
+}
112
+
113
+.releaseFiles {
114
+	margin-top: 10px;
115
+}
116
+
117
+.releaseFiles p {
118
+	margin-left: 15px;
119
+}
120
+
121
+.RL_search {
122
+	background-color: white;
123
+	padding: 10px;
124
+	margin: 10px;
125
+	-webkit-border-radius: 6px;
126
+	-moz-border-radius: 6px;
127
+	border-radius: 6px;
128
+}
129
+
130
+.minecraftDotJar {
131
+	background-repeat: no-repeat;
132
+	padding-left: 20px;
133
+	background-image: url("images/icons/bookshelf.png");
134
+}
135
+
136
+.dir , .file  {
137
+	color: black;
138
+	text-decoration: underline;
139
+	width: 16px;
140
+	height: 16px;
141
+	background: none;
142
+	border: none;
143
+	background-repeat: no-repeat;
144
+	padding-left: 20px;
145
+}
146
+
147
+li {
148
+	list-style: none;
149
+}
150
+
151
+.dir.closed{
152
+	background-image: url("images/icons/bookMore.png");
153
+}
154
+
155
+.dir.opened{
156
+	background-image: url("images/icons/bookLess.png");
157
+}
158
+
159
+.file {
160
+	background-image: url("images/icons/paper.png");
161
+}
162
+
163
+/*.file  a {
164
+	color: #0f7eff;
165
+}*/
166
+
167
+.file.image {
168
+	background-image: url("images/icons/painting.png");
169
+	
170
+}
171
+
172
+.file.technic {
173
+	background-image: url("images/icons/map.png");
174
+}
175
+
176
+.file.txt {
177
+	background-image: url("images/icons/sign.png");
178
+
179
+}

BIN
images/background_pattern.png View File


BIN
images/body_pattern.png View File


BIN
images/icons/book.png View File


BIN
images/icons/bookLess.png View File


BIN
images/icons/bookMore.png View File


BIN
images/icons/bookshelf.png View File


BIN
images/icons/bookshelfMore.png View File


BIN
images/icons/map.png View File


BIN
images/icons/painting.png View File


BIN
images/icons/paper.png View File


BIN
images/icons/redstoneTorchOff.png View File


BIN
images/icons/redstoneTorchOn.png View File


BIN
images/icons/sign.png View File


BIN
images/release_pattern.png View File


+ 236
- 0
index.php View File

@@ -0,0 +1,236 @@
1
+<?php
2
+$data = new DomDocument();
3
+$data->load('data.xml');
4
+$dataNode = $data->getElementsByTagName('data')->item(0);
5
+$mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
6
+$releaseS = $mcupdatesNode->getElementsByTagName('release');
7
+$text = '';
8
+for ($i = $releaseS->length; $i > 1; $i--) {
9
+	$release = $releaseS->item($i-1);
10
+	$releaseInfos = $release->getElementsByTagName('infos')->item(0);
11
+	$text .= '<h3>Minecraft '.$release->getAttribute('name').' ';
12
+	if (isset($prevRelease)) {
13
+		if ($release->getAttribute('name') == $prevRelease->getAttribute('name')) {
14
+			$text .= '(version enterrée) ';
15
+		}
16
+	}
17
+	$shortDescription = $releaseInfos->getAttribute('shortDescription');
18
+	if ($shortDescription == 'false') {
19
+		$shortDescription = 'Pas de description.';
20
+	}
21
+	$text .= '</h3><div class="release" id="R'.$release->getAttribute('id').'"><div class="shortDescription">'.$shortDescription.' <input type="button" value="+" class="more" /></div><div class="content"></div></div>';
22
+	$prevRelease = $release;
23
+}
24
+?>
25
+<!DOCTYPE html>
26
+<html lang="fr">
27
+<head>
28
+<title>Minecraft Checker</title>
29
+<meta charset="utf-8">
30
+<link rel="stylesheet" media="screen" type="text/css" title="design" href="design.css">
31
+<script type="text/javascript">
32
+var checkIntervalForm;
33
+var checkState;
34
+var checkTimeout;
35
+var addXhr;
36
+var allReleases;
37
+var checkXhr;
38
+var lastId = <?php echo $mcupdatesNode->getAttribute('total'); ?>;
39
+
40
+window.onload = function () {
41
+checkIntervalForm = document.getElementById('checkActivate');
42
+checkState = document.getElementById('checkState');
43
+checkIntervalForm.addEventListener('change', function(e) {
44
+	if (e.target.checked) {
45
+		checkState.innerHTML = 'activé';
46
+		checkTimeout = true;
47
+		check();
48
+		console.log('Checking activated');
49
+	} else {
50
+		checkState.innerHTML = 'désactivé';
51
+		clearTimeout(checkTimeout); // TODO Annulation de checkXhr
52
+		checkTimeout = false;
53
+		checkXhr.abort();
54
+		console.log('Checking stopped');
55
+	}
56
+}, false);
57
+
58
+allReleases = document.getElementById('allreleases');
59
+allReleaseS = allReleases.getElementsByClassName('more');
60
+for (var allReleaseI = 0; allReleaseI < allReleaseS.length; allReleaseI++) {
61
+	allReleaseS[allReleaseI].addEventListener('click', releaseOpen, false);
62
+}
63
+console.log('System initialised');
64
+}
65
+function releaseOpen(e) {
66
+e.target.value = '...';
67
+var releaseXhr = new XMLHttpRequest();
68
+releaseXhr.onreadystatechange = function() {
69
+	if (releaseXhr.readyState == 4 && (releaseXhr.status == 200 || releaseXhr.status == 0)) {
70
+		e.target.removeEventListener('click', releaseOpen, false);
71
+		console.log('	Infos recevied');
72
+		var content = e.target.parentNode.parentNode.getElementsByClassName('content')[0];
73
+		content.innerHTML = releaseXhr.responseText;
74
+		if (content.getElementsByClassName('releaseFiles')[0]) {
75
+		content.getElementsByClassName('releaseFilesButton')[0].addEventListener('click', releaseFilesOpen, false);
76
+		filesDirExpandS = content.getElementsByClassName('dir');
77
+			for (var filesDirExpandI = 0; filesDirExpandI < filesDirExpandS.length; filesDirExpandI++) {
78
+				filesDirExpandS[filesDirExpandI].addEventListener('click', releaseFilesDirOpen, false);
79
+			}
80
+			var releaseFilesSelectionS = content.getElementsByClassName('releaseFiles')[0].getElementsByTagName('input');
81
+			for (var releaseFilesSelectionI = 0; releaseFilesSelectionI < releaseFilesSelectionS.length; releaseFilesSelectionI++) {
82
+				if (releaseFilesSelectionS[releaseFilesSelectionI].name == 'filesSelectionChangement' || releaseFilesSelectionS[releaseFilesSelectionI].name == 'filesSelectionClass') {
83
+					releaseFilesSelectionS[releaseFilesSelectionI].addEventListener('click', releaseFilesOrderEvent, false);
84
+				}
85
+			}
86
+		}
87
+		e.target.value = '-';
88
+		e.target.addEventListener('click', releaseClose, false);
89
+	}
90
+};
91
+var releaseId = e.target.parentNode.parentNode.id.split('R')[1];
92
+console.log('Searching details for release ID = '+releaseId+'.');
93
+releaseXhr.open('GET', 'moreinfos.php?i='+releaseId, true);
94
+releaseXhr.send(null);
95
+}
96
+function releaseFilesDirOpen(e) {
97
+	e.target.parentNode.getElementsByClassName('dirUl')[0].style.display = '';
98
+	e.target.className = 'dir opened';
99
+	e.target.removeEventListener('click', releaseFilesDirOpen, false);
100
+	e.target.addEventListener('click', releaseFilesDirClose, false);
101
+}
102
+function releaseFilesDirClose(e) {
103
+	e.target.parentNode.getElementsByClassName('dirUl')[0].style.display = 'none';
104
+	e.target.className = 'dir closed';
105
+	e.target.removeEventListener('click', releaseFilesDirClose, false);
106
+	e.target.addEventListener('click', releaseFilesDirOpen, false);
107
+}
108
+function releaseClose(e) {
109
+	e.target.value = '...';
110
+	e.target.parentNode.parentNode.getElementsByClassName('content')[0].innerHTML = '';
111
+	e.target.removeEventListener('click', releaseClose, false);
112
+	e.target.addEventListener('click', releaseOpen, false);
113
+	e.target.value = '+';
114
+}
115
+function releaseFilesOpen(e) {
116
+	e.target.value = '...';
117
+	var releaseFiles = e.target.parentNode.parentNode.getElementsByClassName('releaseFiles')[0];
118
+	releaseFiles.style.display = '';
119
+	releaseFilesOrder(releaseFiles);
120
+	e.target.removeEventListener('click', releaseFilesOpen, false);
121
+	e.target.addEventListener('click', releaseFilesClose, false);
122
+	e.target.value = '-';
123
+}
124
+function releaseFilesOrder(releaseFiles) {
125
+	var releaseFilesFileS = releaseFiles.getElementsByClassName('file');
126
+	var releaseFilesSelectionClassAll = releaseFiles.getElementsByClassName('fileSelectionClassAll')[0].checked;
127
+	var releaseFilesSelectionClassNonTechnic = releaseFiles.getElementsByClassName('fileSelectionClassNontechnic')[0].checked;
128
+	var releaseFilesSelectionClassNone = releaseFiles.getElementsByClassName('fileSelectionClassNone')[0].checked;
129
+	var releaseFilesSelectionChangementAll = releaseFiles.getElementsByClassName('fileSelectionChangementAll')[0].checked;
130
+	var releaseFilesSelectionChangementChanged = releaseFiles.getElementsByClassName('fileSelectionChangementChanged')[0].checked;
131
+	var releaseFilesSelectionChangementAdded = releaseFiles.getElementsByClassName('fileSelectionChangementAdded')[0].checked;
132
+	for (var releaseFilesFileI = 0; releaseFilesFileI < releaseFilesFileS.length; releaseFilesFileI++) {
133
+		var releaseFilesFileClassE = releaseFilesFileS[releaseFilesFileI].className.split(' ');
134
+		var releaseFilesFileTechnic = in_array('technic', releaseFilesFileClassE);
135
+		var releaseFilesFileClass = in_array('class', releaseFilesFileClassE);
136
+		var releaseFilesFileChanged = in_array('change', releaseFilesFileClassE);
137
+		var releaseFilesFileAdded = in_array('added', releaseFilesFileClassE);
138
+		if ((releaseFilesSelectionClassAll || (releaseFilesSelectionClassNonTechnic && (!releaseFilesFileTechnic)) || (releaseFilesSelectionClassNone && (!releaseFilesFileClass))) && (releaseFilesSelectionChangementAll || (releaseFilesSelectionChangementChanged && (releaseFilesFileChanged || releaseFilesFileAdded)) || (releaseFilesSelectionChangementAdded && releaseFilesFileAdded))) {
139
+			releaseFilesFileS[releaseFilesFileI].parentNode.style.display = '';
140
+		} else  {
141
+			releaseFilesFileS[releaseFilesFileI].parentNode.style.display = 'none';
142
+		}
143
+	}
144
+}
145
+function releaseFilesOrderEvent(e) {
146
+	releaseFilesOrder(e.target.parentNode.parentNode);
147
+}
148
+function releaseFilesClose(e) {
149
+	e.target.value = '+';
150
+	e.target.parentNode.parentNode.getElementsByClassName('releaseFiles')[0].style.display = 'none';
151
+	e.target.removeEventListener('click', releaseFilesClose, false);
152
+	e.target.addEventListener('click', releaseFilesOpen, false);
153
+}
154
+function check() {
155
+checkXhr = new XMLHttpRequest();
156
+checkXhr.onreadystatechange = function() {
157
+	if (checkXhr.readyState == 4 && (checkXhr.status == 200 || checkXhr.status == 0)) {
158
+		console.log('Check finished, with information : '+checkXhr.responseText);
159
+		var newReleaseE = checkXhr.responseText.split('|');
160
+		if (newReleaseE.length == 8 && checkTimeout) {
161
+			if (newReleaseE[5] == lastId) {
162
+				console.log('	Information analysed : no new release (date: '+newReleaseE[0]+').');
163
+				checkState.innerHTML = 'attente';
164
+			} else if (newReleaseE[5] > lastId) {
165
+				console.log('	Information analysed : new release.');
166
+				checkState.innerHTML = 'nouvelle version';
167
+				// TODO Vérifier si (newReleaseE[5] == lastId+1)
168
+				lastRelease = newReleaseE[6];
169
+				if (newReleaseE[7] == 'r' && newReleaseE[5] == lastId+1) {
170
+					var newReleaseAlertType = 'La release complète';
171
+				} else if (newReleaseE[7] == 'apr' && newReleaseE[5] == lastId+1) {
172
+					var newReleaseAlertType = 'La pre-release automatique';
173
+				} else if (newReleaseE[7] == 'pr' && newReleaseE[5] == lastId+1) {
174
+					var newReleaseAlertType = 'La pre-release';				
175
+				} else {
176
+					console.error('	Bad informations on the new release. Reloading page.');
177
+					checkState.innerHTML = 'erreur';
178
+					location.reload();
179
+					return false;
180
+				}
181
+				lastId = newReleaseE[5];
182
+				console.info('New release: name: '+lastRelease+' id:'+newReleaseE[5]+' type: '+newReleaseE[7]+'.');
183
+				checkState.innerHTML = 'nouvelle version';
184
+				document.title='Version '+lastRelease+' sortie !';
185
+				alert(newReleaseAlertType+' '+lastRelease+' est sortie !');
186
+				location.reload();
187
+			} else {
188
+				console.error('Database upset. Reloading page.');
189
+				checkState.innerHTML = 'erreur';
190
+				location.reload();
191
+			}
192
+			checkTimeout = setTimeout('check()', 5000);
193
+		} else if (!checkTimeout) {
194
+			return false;
195
+		} else {
196
+			console.error('Error comited server-side.');
197
+			checkState.innerHTML = 'erreur';
198
+		}
199
+	}
200
+};
201
+checkXhr.open('GET', 'test.php', true);
202
+checkState.innerHTML = 'recherche';
203
+checkXhr.send(null);
204
+}
205
+
206
+function in_array(needle, haystack) {
207
+	for (key in haystack) {
208
+		if (haystack[key] == needle) {
209
+			return true;
210
+		}
211
+	}
212
+	return false;
213
+}
214
+</script>
215
+</head>
216
+<body>
217
+<h1>Minecraft Checker</h1>
218
+<div id="body">
219
+	<h2>Rechercher des versions</h2>
220
+	<p class="RL_search"><input type="checkbox" id="checkActivate" name="checkActivate"/><label for="checkActivate"> Rechercher les nouvelles releases (<span id="checkState">désactivé</span>)</label></p>
221
+
222
+	<h2>Versions référencées</h2>
223
+	<div id="allreleases">
224
+		<?php echo $text; ?>
225
+	</div>
226
+</div>
227
+<footer>
228
+<p id="copyright">Copyright &copy; <a href="https://twitter.com/#!/WebFrogeye">WebFrogeye</a> 2012</p>
229
+<p>Créé par <a href="https://twitter.com/#!/WebFrogeye">@WebFrogeye</a>.<br/>
230
+Avec l'aide d'<a href="https://twitter.com/#!/EphysPotato">@EphysPotato</a>.<br/>
231
+Sur un design de <a href="http://dlp.host56.com/">DLProduction</a>.<br/>
232
+D'après un script de <a href="https://twitter.com/#!/shellgratuit">@shellgratuit</a>.</p>
233
+</footer>
234
+<div id="cache" style="display: none;"></div>
235
+</body>
236
+</html>

+ 236
- 0
indexold.php View File

@@ -0,0 +1,236 @@
1
+<?php
2
+$data = new DomDocument();
3
+$data->load('data.xml');
4
+$dataNode = $data->getElementsByTagName('data')->item(0);
5
+$mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
6
+$releaseS = $mcupdatesNode->getElementsByTagName('release');
7
+$text = '';
8
+for ($i = $releaseS->length; $i > 1; $i--) {
9
+	$release = $releaseS->item($i-1);
10
+	$releaseInfos = $release->getElementsByTagName('infos')->item(0);
11
+	$text .= '<h3>Minecraft '.$release->getAttribute('name').' ';
12
+	if (isset($prevRelease)) {
13
+		if ($release->getAttribute('name') == $prevRelease->getAttribute('name')) {
14
+			$text .= '(version enterrée) ';
15
+		}
16
+	}
17
+	$shortDescription = $releaseInfos->getAttribute('shortDescription');
18
+	if ($shortDescription == 'false') {
19
+		$shortDescription = 'Pas de description.';
20
+	}
21
+	$text .= '</h3><div class="release" id="R'.$release->getAttribute('id').'"><div class="shortDescription">'.$shortDescription.' <input type="button" value="+" class="more" /></div><div class="content"></div></div>';
22
+	$prevRelease = $release;
23
+}
24
+?>
25
+<!DOCTYPE html>
26
+<html lang="fr">
27
+<head>
28
+<title>Minecraft Checker</title>
29
+<meta charset="utf-8">
30
+<link rel="stylesheet" media="screen" type="text/css" title="design" href="design.css">
31
+<script type="text/javascript">
32
+var checkIntervalForm;
33
+var checkState;
34
+var checkTimeout;
35
+var addXhr;
36
+var allReleases;
37
+var checkXhr;
38
+var lastId = <?php echo $mcupdatesNode->getAttribute('total'); ?>;
39
+
40
+window.onload = function () {
41
+checkIntervalForm = document.getElementById('checkActivate');
42
+checkState = document.getElementById('checkState');
43
+checkIntervalForm.addEventListener('change', function(e) {
44
+	if (e.target.checked) {
45
+		checkState.innerHTML = 'activé';
46
+		checkTimeout = true;
47
+		check();
48
+		console.log('Checking activated');
49
+	} else {
50
+		checkState.innerHTML = 'désactivé';
51
+		clearTimeout(checkTimeout); // TODO Annulation de checkXhr
52
+		checkTimeout = false;
53
+		checkXhr.abort();
54
+		console.log('Checking stopped');
55
+	}
56
+}, false);
57
+
58
+allReleases = document.getElementById('allreleases');
59
+allReleaseS = allReleases.getElementsByClassName('more');
60
+for (var allReleaseI = 0; allReleaseI < allReleaseS.length; allReleaseI++) {
61
+	allReleaseS[allReleaseI].addEventListener('click', releaseOpen, false);
62
+}
63
+console.log('System initialised');
64
+}
65
+function releaseOpen(e) {
66
+e.target.value = '...';
67
+var releaseXhr = new XMLHttpRequest();
68
+releaseXhr.onreadystatechange = function() {
69
+	if (releaseXhr.readyState == 4 && (releaseXhr.status == 200 || releaseXhr.status == 0)) {
70
+		e.target.removeEventListener('click', releaseOpen, false);
71
+		console.log('	Infos recevied');
72
+		var content = e.target.parentNode.parentNode.getElementsByClassName('content')[0];
73
+		content.innerHTML = releaseXhr.responseText;
74
+		if (content.getElementsByClassName('releaseFiles')[0]) {
75
+		content.getElementsByClassName('releaseFilesButton')[0].addEventListener('click', releaseFilesOpen, false);
76
+		filesDirExpandS = content.getElementsByClassName('dir');
77
+			for (var filesDirExpandI = 0; filesDirExpandI < filesDirExpandS.length; filesDirExpandI++) {
78
+				filesDirExpandS[filesDirExpandI].addEventListener('click', releaseFilesDirOpen, false);
79
+			}
80
+			var releaseFilesSelectionS = content.getElementsByClassName('releaseFiles')[0].getElementsByTagName('input');
81
+			for (var releaseFilesSelectionI = 0; releaseFilesSelectionI < releaseFilesSelectionS.length; releaseFilesSelectionI++) {
82
+				if (releaseFilesSelectionS[releaseFilesSelectionI].name == 'filesSelectionChangement' || releaseFilesSelectionS[releaseFilesSelectionI].name == 'filesSelectionClass') {
83
+					releaseFilesSelectionS[releaseFilesSelectionI].addEventListener('click', releaseFilesOrderEvent, false);
84
+				}
85
+			}
86
+		}
87
+		e.target.value = '-';
88
+		e.target.addEventListener('click', releaseClose, false);
89
+	}
90
+};
91
+var releaseId = e.target.parentNode.parentNode.id.split('R')[1];
92
+console.log('Searching details for release ID = '+releaseId+'.');
93
+releaseXhr.open('GET', 'moreinfos.php?i='+releaseId, true);
94
+releaseXhr.send(null);
95
+}
96
+function releaseFilesDirOpen(e) {
97
+	e.target.parentNode.getElementsByClassName('dirUl')[0].style.display = '';
98
+	e.target.className = 'dir opened';
99
+	e.target.removeEventListener('click', releaseFilesDirOpen, false);
100
+	e.target.addEventListener('click', releaseFilesDirClose, false);
101
+}
102
+function releaseFilesDirClose(e) {
103
+	e.target.parentNode.getElementsByClassName('dirUl')[0].style.display = 'none';
104
+	e.target.className = 'dir closed';
105
+	e.target.removeEventListener('click', releaseFilesDirClose, false);
106
+	e.target.addEventListener('click', releaseFilesDirOpen, false);
107
+}
108
+function releaseClose(e) {
109
+	e.target.value = '...';
110
+	e.target.parentNode.parentNode.getElementsByClassName('content')[0].innerHTML = '';
111
+	e.target.removeEventListener('click', releaseClose, false);
112
+	e.target.addEventListener('click', releaseOpen, false);
113
+	e.target.value = '+';
114
+}
115
+function releaseFilesOpen(e) {
116
+	e.target.value = '...';
117
+	var releaseFiles = e.target.parentNode.parentNode.getElementsByClassName('releaseFiles')[0];
118
+	releaseFiles.style.display = '';
119
+	releaseFilesOrder(releaseFiles);
120
+	e.target.removeEventListener('click', releaseFilesOpen, false);
121
+	e.target.addEventListener('click', releaseFilesClose, false);
122
+	e.target.value = '-';
123
+}
124
+function releaseFilesOrder(releaseFiles) {
125
+	var releaseFilesFileS = releaseFiles.getElementsByClassName('file');
126
+	var releaseFilesSelectionClassAll = releaseFiles.getElementsByClassName('fileSelectionClassAll')[0].checked;
127
+	var releaseFilesSelectionClassNonTechnic = releaseFiles.getElementsByClassName('fileSelectionClassNontechnic')[0].checked;
128
+	var releaseFilesSelectionClassNone = releaseFiles.getElementsByClassName('fileSelectionClassNone')[0].checked;
129
+	var releaseFilesSelectionChangementAll = releaseFiles.getElementsByClassName('fileSelectionChangementAll')[0].checked;
130
+	var releaseFilesSelectionChangementChanged = releaseFiles.getElementsByClassName('fileSelectionChangementChanged')[0].checked;
131
+	var releaseFilesSelectionChangementAdded = releaseFiles.getElementsByClassName('fileSelectionChangementAdded')[0].checked;
132
+	for (var releaseFilesFileI = 0; releaseFilesFileI < releaseFilesFileS.length; releaseFilesFileI++) {
133
+		var releaseFilesFileClassE = releaseFilesFileS[releaseFilesFileI].className.split(' ');
134
+		var releaseFilesFileTechnic = in_array('technic', releaseFilesFileClassE);
135
+		var releaseFilesFileClass = in_array('class', releaseFilesFileClassE);
136
+		var releaseFilesFileChanged = in_array('change', releaseFilesFileClassE);
137
+		var releaseFilesFileAdded = in_array('added', releaseFilesFileClassE);
138
+		if ((releaseFilesSelectionClassAll || (releaseFilesSelectionClassNonTechnic && (!releaseFilesFileTechnic)) || (releaseFilesSelectionClassNone && (!releaseFilesFileClass))) && (releaseFilesSelectionChangementAll || (releaseFilesSelectionChangementChanged && (releaseFilesFileChanged || releaseFilesFileAdded)) || (releaseFilesSelectionChangementAdded && releaseFilesFileAdded))) {
139
+			releaseFilesFileS[releaseFilesFileI].parentNode.style.display = '';
140
+		} else  {
141
+			releaseFilesFileS[releaseFilesFileI].parentNode.style.display = 'none';
142
+		}
143
+	}
144
+}
145
+function releaseFilesOrderEvent(e) {
146
+	releaseFilesOrder(e.target.parentNode.parentNode);
147
+}
148
+function releaseFilesClose(e) {
149
+	e.target.value = '+';
150
+	e.target.parentNode.parentNode.getElementsByClassName('releaseFiles')[0].style.display = 'none';
151
+	e.target.removeEventListener('click', releaseFilesClose, false);
152
+	e.target.addEventListener('click', releaseFilesOpen, false);
153
+}
154
+function check() {
155
+checkXhr = new XMLHttpRequest();
156
+checkXhr.onreadystatechange = function() {
157
+	if (checkXhr.readyState == 4 && (checkXhr.status == 200 || checkXhr.status == 0)) {
158
+		console.log('Check finished, with information : '+checkXhr.responseText);
159
+		var newReleaseE = checkXhr.responseText.split('|');
160
+		if (newReleaseE.length == 8 && checkTimeout) {
161
+			if (newReleaseE[5] == lastId) {
162
+				console.log('	Information analysed : no new release (date: '+newReleaseE[0]+').');
163
+				checkState.innerHTML = 'attente';
164
+			} else if (newReleaseE[5] > lastId) {
165
+				console.log('	Information analysed : new release.');
166
+				checkState.innerHTML = 'nouvelle version';
167
+				// TODO Vérifier si (newReleaseE[5] == lastId+1)
168
+				lastRelease = newReleaseE[6];
169
+				if (newReleaseE[7] == 'r' && newReleaseE[5] == lastId+1) {
170
+					var newReleaseAlertType = 'La release complète';
171
+				} else if (newReleaseE[7] == 'apr' && newReleaseE[5] == lastId+1) {
172
+					var newReleaseAlertType = 'La pre-release automatique';
173
+				} else if (newReleaseE[7] == 'pr' && newReleaseE[5] == lastId+1) {
174
+					var newReleaseAlertType = 'La pre-release';				
175
+				} else {
176
+					console.error('	Bad informations on the new release. Reloading page.');
177
+					checkState.innerHTML = 'erreur';
178
+					location.reload();
179
+					return false;
180
+				}
181
+				lastId = newReleaseE[5];
182
+				console.info('New release: name: '+lastRelease+' id:'+newReleaseE[5]+' type: '+newReleaseE[7]+'.');
183
+				checkState.innerHTML = 'nouvelle version';
184
+				document.title='Version '+lastRelease+' sortie !';
185
+				alert(newReleaseAlertType+' '+lastRelease+' est sortie !');
186
+				location.reload();
187
+			} else {
188
+				console.error('Database upset. Reloading page.');
189
+				checkState.innerHTML = 'erreur';
190
+				location.reload();
191
+			}
192
+			checkTimeout = setTimeout('check()', 5000);
193
+		} else if (!checkTimeout) {
194
+			return false;
195
+		} else {
196
+			console.error('Error comited server-side.');
197
+			checkState.innerHTML = 'erreur';
198
+		}
199
+	}
200
+};
201
+checkXhr.open('GET', 'test.php', true);
202
+checkState.innerHTML = 'recherche';
203
+checkXhr.send(null);
204
+}
205
+
206
+function in_array(needle, haystack) {
207
+	for (key in haystack) {
208
+		if (haystack[key] == needle) {
209
+			return true;
210
+		}
211
+	}
212
+	return false;
213
+}
214
+</script>
215
+</head>
216
+<body>
217
+<h1>Minecraft Checker</h1>
218
+<div id="body">
219
+	<h2>Rechercher des versions</h2>
220
+	<p class="RL_search"><input type="checkbox" id="checkActivate" name="checkActivate"/><label for="checkActivate"> Rechercher les nouvelles releases (<span id="checkState">désactivé</span>)</label></p>
221
+
222
+	<h2>Versions référencées</h2>
223
+	<div id="allreleases">
224
+		<?php echo $text; ?>
225
+	</div>
226
+</div>
227
+<footer>
228
+<p id="copyright">Copyright &copy; <a href="https://twitter.com/#!/WebFrogeye">WebFrogeye</a> 2012</p>
229
+<p>Créé par <a href="https://twitter.com/#!/WebFrogeye">@WebFrogeye</a>.<br/>
230
+Avec l'aide d'<a href="https://twitter.com/#!/EphysPotato">@EphysPotato</a>.<br/>
231
+Sur un design de <a href="http://dlp.host56.com/">DLProduction</a>.<br/>
232
+D'après un script de <a href="https://twitter.com/#!/shellgratuit">@shellgratuit</a>.</p>
233
+</footer>
234
+<div id="cache" style="display: none;"></div>
235
+</body>
236
+</html>

+ 1
- 0
lastVersions.txt View File

@@ -0,0 +1 @@
1
+1336223378|1.2.5|8e8778078a175a33603a585257f28563|12w18a|37d778548796dd95c4d0ea49a015be06|27|12w18a|apr

+ 143
- 0
moreinfos.php View File

@@ -0,0 +1,143 @@
1
+<?php
2
+date_default_timezone_set('Europe/Paris');
3
+if (isset($_GET['i']))
4
+{
5
+	$data = new DomDocument();
6
+	$data->load('data.xml');
7
+	$dataNode = $data->getElementsByTagName('data')->item(0);
8
+	$mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
9
+	$releaseS = $mcupdatesNode->getElementsByTagName('release');
10
+	// $lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
11
+	$prevRelease = false;
12
+	for ($c = $releaseS->length, $i = 0; $i < $c; $i++) {
13
+		$release = $releaseS->item($i);
14
+		if ($_GET['i'] == $release->getAttribute('id')) {
15
+			$releaseInfos = $release->getElementsByTagName('infos')->item(0);
16
+			$releaseDateE = explode('/', $releaseInfos->getAttribute('date'));
17
+			$date = $releaseInfos->getAttribute('date');
18
+			echo 'Sortie le '.date('d', $date).'/'.date('m', $date).'/'.date('Y', $date);
19
+			/*if (date('G', $date) != 0 OR date('i', $date) != 0) { 
20
+				echo ' à '.date('G', $date).':'.date('i', $date).' (environ)'; 
21
+			}*/
22
+			echo '.<br/>';
23
+			if ($release->getAttribute('name') != $releaseInfos->getAttribute('givenName')) {
24
+				echo 'Le nom de la version donné dans le jeu est '.$releaseInfos->getAttribute('givenName').' mais le nom réel est '.$release->getAttribute('name').'.<br/>';
25
+			}
26
+			// Téléchargement
27
+			echo '<div class="download"><h4>Téléchargement</h4>
28
+Nom : <strong>minecraft.jar</strong>
29
+Taille : <strong>'.$releaseInfos->getAttribute('size').' octets</strong><br/>
30
+MD5 : <strong>'.$releaseInfos->getAttribute('md5').'</strong><br/>
31
+SHA-1 : <strong>'.$releaseInfos->getAttribute('sha1').'</strong><br/>';
32
+			if (is_dir($releaseInfos->getAttribute('directory'))) {
33
+				$downloadLocal = $releaseInfos->getAttribute('directory').'/minecraft.jar'; }
34
+			if (@fopen($releaseInfos->getAttribute('link'), 'r') AND ($release->getAttribute('type') != 'r' OR $i+1 == $c)) {
35
+				$downloadServer = $releaseInfos->getAttribute('link');
36
+			} else {
37
+				// TODO AR? Prévoir ça (variable $changes par exemple)
38
+			}
39
+			// TODO AR $downloadWiki
40
+			if (isset($downloadLocal) OR isset($downloadServer) OR isset($downloadWiki)) {
41
+				if (isset($downloadLocal)) {
42
+				echo '<a href="'.$downloadLocal.'">Depuis ce serveur</a><br/>'; }
43
+				if (isset($downloadServer)) {
44
+				echo '<a href="'.$downloadServer.'">Depuis minecraft.net</a><br/> '; }
45
+				if (isset($downloadWiki)) {
46
+				echo '<a href="'.$downloadWiki.'">Depuis Minecaft Wiki</a><br/> '; }	
47
+			} else {
48
+				echo 'Aucun lien de téléchargement n\'est disponible.';
49
+			}
50
+			echo '</div>';
51
+			echo '<div class="changelog">
52
+<h4>Changelog</h4>
53
+Langue : Français<br/>
54
+<a class="wikiLink" href="'.$releaseInfos->getAttribute('wiki').'">Lien vers le wiki</a><br/>
55
+</div>';
56
+			$text = '<ul>';
57
+			if ($release->getElementsByTagName('files')->item(0)) {
58
+				echo '<div class="files">
59
+<h4>Fichiers du .jar</h4>';
60
+				$directory = $releaseInfos->getAttribute('directory');
61
+				$haveLink = (is_dir($directory) AND is_dir($directory.'/content'));
62
+				$elementS = $release->getElementsByTagName('files')->item(0)->childNodes;
63
+				$filesModificationsStat = array(0, 0, 0, 0);
64
+				$directoryXML = directoryXML($elementS, $releaseInfos->getAttribute('directory').'/content');
65
+				if ($prevRelease)
66
+					echo 'Comparaison par rapport à la version : '.$prevRelease->getAttribute('name').'.<br/>';
67
+				echo '<span class="changeStats">'.$filesModificationsStat[3].' fichiers au total, '.$filesModificationsStat[2].' inchangés, '.$filesModificationsStat[1].' ajoutés et '.$filesModificationsStat[0].' modifiés (dont fichiers obstrués). <input class="releaseFilesButton" type="button" value="+" /></span><br/>';
68
+				// TODO Supprimer (s) (conditions)
69
+				echo '<div class="releaseFiles" style="display: none;"><p>Tri selon les fichiers modifiés : <input type="radio" name="filesSelectionChangement" class="fileSelectionChangementAll" title="Pas de filtre pour les modifications de fichier" checked /><input type="radio" name="filesSelectionChangement" class="fileSelectionChangementChanged" title="Filtrer les fichiers restés inchangés" /><input type="radio" name="filesSelectionChangement" class="fileSelectionChangementAdded" title="Filtrer les fichiers uniquement modifiés (ne garder que les fichiers ajoutés)"/></p><p>
70
+Tri selon le type de fichier : <input type="radio" name="filesSelectionClass" class="fileSelectionClassAll" title="Pas de filtre pour les types de fichiers"/><input type="radio" name="filesSelectionClass" checked class="fileSelectionClassNontechnic" title="Filtrer les fichiers obstrués"/><input type="radio" name="filesSelectionClass" class="fileSelectionClassNone" title="Filtrer les fichiers .class"/></p><div class="releaseFilesContainer">
71
+<strong class="minecraftDotJar">Minecraft.jar</strong><br/><ul>'.$directoryXML.'</ul></div></div>';
72
+				echo '</div>';
73
+			}
74
+			exit();
75
+		}
76
+		else {
77
+			$prevRelease = $release;
78
+		}
79
+	}
80
+	echo 'ERREUR L\'information demmandée n\'a pas été trouvée.<br/>
81
+Si il s\'agit d\'une sortie récente, attendez un peu et réésayez.';
82
+} else {
83
+	echo 'ERREUR Les informations demmandées ne sont pas correctes.';
84
+}
85
+function directoryXML($XML, $path) {
86
+	global $filesModificationsStat;
87
+	global $haveLink;
88
+	$text = '';
89
+	for ($c = $XML->length, $i = 0; $i < $c; $i++) {
90
+		$element = $XML->item($i);
91
+		if ($element->tagName == 'dir') {
92
+			if ($directoryXML = directoryXML($element->childNodes, $path.'/'.$element->getAttribute('name'))) {
93
+				$text .= '<li><span class="dir closed">'.$element->getAttribute('name').'</span><ul class="dirUl" style="display: none;">'.$directoryXML.'</ul></li>';
94
+			}
95
+		} elseif ($element->tagName == 'file') {
96
+		/*
97
+		if ((isset($_GET['allowClass']) OR strlen(@$exploded[0]) > 3 OR @$exploded[1] != 'class' OR $element->getAttribute('comparaison')== 'addded') AND (isset($_GET['allowSame']) OR $element->getAttribute('comparaison')!= 'same')) { */
98
+				$className = 'file';
99
+				switch ($element->getAttribute('comparaison')) {
100
+					case 'change':
101
+					$comparaison = '≠';
102
+					$className .= ' change';
103
+					$filesModificationsStat[0]++;
104
+					break;
105
+					case 'added':
106
+					$comparaison = '+';
107
+					$className .= ' added';
108
+					$filesModificationsStat[1]++;
109
+					break;
110
+					case 'same';
111
+					$comparaison = '=';
112
+					$className .= ' same';
113
+					$filesModificationsStat[2]++;
114
+					break;
115
+					default:
116
+					$comparaison = '?';
117
+					break;
118
+				}
119
+				$exploded = explode('.', $element->getAttribute('name'));
120
+				if (@$exploded[1] == 'class') {
121
+					$className .= ' class';
122
+				}
123
+				if (strlen($exploded[0]) < 4 AND @$exploded[1] == 'class') {
124
+					$className .= ' technic';
125
+				}
126
+				if (@$exploded[1] == 'png') {
127
+					$className .= ' image';
128
+				}
129
+				if (@$exploded[1] == 'txt') {
130
+					$className .= ' txt';
131
+				}
132
+				$filesModificationsStat[3]++;
133
+				$text .= '<li><span class="'.$className.'">';
134
+				if ($haveLink) { $text.= '<a href="'.$path.'/'.$element->getAttribute('name').'">'; }
135
+				$text .= $element->getAttribute('name');
136
+				if ($haveLink) { $text .= '</a>'; }
137
+				$text .= '</span>('.$comparaison.')</li>';  
138
+		}
139
+	}
140
+return $text;
141
+}
142
+
143
+?>

+ 178
- 0
preRelease.php View File

@@ -0,0 +1,178 @@
1
+<?php
2
+set_time_limit('240');
3
+addRelease('1_2_5');
4
+function addRelease($input) {
5
+	$debug = false;
6
+	// Définition des variables de travail
7
+	$lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
8
+	$lastVersions_e_backup = $lastVersions_e;
9
+	if ($input == 'r') {
10
+		$lastVersions_e[1] = 'UP';
11
+	} else {
12
+		$lastVersions_e[3] = 'UP';
13
+	}
14
+	// Enregistrement des données d'ajout
15
+	$lastVersions_e[0] = time();
16
+	$lastVersions_txt = fopen('lastVersions.txt', 'w');
17
+	fwrite($lastVersions_txt, implode('|', $lastVersions_e));
18
+	fclose($lastVersions_txt);
19
+	if ($input == 'r') {
20
+		$type = 'r';
21
+		$url = 'http://s3.amazonaws.com/MinecraftDownload/minecraft.jar';
22
+	} else {
23
+		$type = 'pr';
24
+		$url = 'http://assets.minecraft.net/'.$input.'/minecraft.jar';
25
+	}
26
+	
27
+	// Chargement du XML
28
+	$data = new DomDocument();
29
+	$data->load('data.xml');
30
+	$dataNode = $data->getElementsByTagName('data')->item(0);
31
+	$mcupdatesNode = $dataNode->getElementsByTagName('mcupdates')->item(0);
32
+	$id = $mcupdatesNode->getAttribute('total')+1;
33
+	$releaseS = $mcupdatesNode->getElementsByTagName('release');
34
+	$release = $releaseS->item($releaseS->length-1);
35
+	
36
+	// Creation du noeud XML
37
+	$releaseNode = $data->createElement('release');
38
+	$mcupdatesNode->appendChild($releaseNode);
39
+	$infosNode = $data->createElement('infos');
40
+	$releaseNode->appendChild($infosNode);
41
+	$files = $data->createElement('files');
42
+	$releaseNode->appendChild($files);
43
+	
44
+	// Extraction et copie de minecraft.jar
45
+	$directory = $id.' - '.$lastVersions_e[0].' ('.rand(1, 1000).')';
46
+	if (!mkdir($directory) OR !copy($url, $directory.'/minecraft.jar')) { return 'ERREUR Impossible de copier le fichier ou de créer un nouveau dossier.';}
47
+	$zip = new ZipArchive;
48
+	if ($zip->open($directory.'/minecraft.jar') AND mkdir($directory.'/content')) {
49
+		$zip->extractTo($directory.'/content');
50
+		$zip->close();
51
+	} else {
52
+		return 'ERREUR Impossible d\'extraire le fichier ou de créer un nouveau dossier.';
53
+	}
54
+	$md5 = md5_file($directory.'/minecraft.jar');
55
+	directoryConstruct($directory.'/content', $files, $data, directoryOld($release));
56
+	
57
+	// Detection de $givenName
58
+	// Code par @EphysPatato
59
+	$minecraft_class = file_get_contents($directory.'/content/net/minecraft/client/Minecraft.class');
60
+	$givenName = 'false';
61
+	if (preg_match('/Minecraft Minecraft (.+)Minecraft main/', $minecraft_class, $matches)) {
62
+		$givenName = '';
63
+		$givenName_w = $matches[count($matches)-1];
64
+		for( $i = 0 ; $i < strlen($givenName_w) ; $i++ )
65
+		{
66
+			$givenName_cw = substr($givenName_w, $i, 1);
67
+			if(($givenName_cw >= 'a' && $givenName_cw <= 'z') || ($givenName_cw >= 'A' && $givenName_cw <= 'Z') || ($givenName_cw >= '0' && $givenName_cw <= '9') || $givenName_cw == '|' || $givenName_cw == '.' || $givenName_cw == '_' || $givenName_cw == '-')
68
+				$givenName .= $givenName_cw;
69
+		}
70
+	}
71
+	// Spécifications selon le type de release
72
+	if ($type == 'r') {
73
+		$name = $givenName;
74
+		$lastVersions_e[1] = $name;
75
+		$lastVersions_e[2] = $md5;
76
+		$infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history#'.$name);	
77
+	} else {
78
+		$name = $input;
79
+		$lastVersions_e[3] = $name;
80
+		$lastVersions_e[4] = $md5;
81
+		$infosNode->setAttribute('wiki', 'http://www.minecraftwiki.net/wiki/Version_history/Development_versions#'.$name);
82
+	}
83
+	
84
+	// Mise des infos dans le XML
85
+	$releaseNode->setAttribute('id', $id);
86
+	$releaseNode->setAttribute('name', $name);	
87
+	$releaseNode->setAttribute('type', $type);
88
+	$infosNode->setAttribute('givenName', $givenName);
89
+	$infosNode->setAttribute('directory', $directory);
90
+	$infosNode->setAttribute('link', $url);
91
+	$infosNode->setAttribute('size', filesize($directory.'/minecraft.jar'));
92
+	$infosNode->setAttribute('md5', $md5);
93
+	$infosNode->setAttribute('sha1', sha1_file($directory.'/minecraft.jar'));
94
+	$infosNode->setAttribute('date', $lastVersions_e[0]);
95
+	$infosNode->setAttribute('shortDescription', 'false');
96
+	$mcupdatesNode->setAttribute('total', $id);
97
+	
98
+	// Sauvegarde finale
99
+	$lastVersions_e[0] = time();
100
+	$lastVersions_e[5] = $id;
101
+	$lastVersions_e[6] = $name;
102
+	$lastVersions_e[7] = $type;
103
+	$id = $mcupdatesNode->setAttribute('total', $id);
104
+	$lastVersions_f = fopen('lastVersions.txt', 'w');
105
+	$lastError = error_get_last();
106
+	if ($debug) { echo substr($lastError['file'], -14); }
107
+	if ($lastError /*AND $lastError['type']!= 2 */AND substr($lastError['file'], -14) == 'addrelease.php') {
108
+		fwrite($lastVersions_f, implode('|', $lastVersions_e_backup));
109
+		rrmdir($directory);
110
+		return 'ERREUR "'.$lastError['message'].'" (type : '.$lastError['type'].') dans '.$lastError['file'].' ligne '.$lastError['line'].'.';
111
+	} else {
112
+		$data->save('data.xml');
113
+		fwrite($lastVersions_f, implode('|', $lastVersions_e));
114
+		fclose($lastVersions_f);
115
+		return implode('|', $lastVersions_e);
116
+	}
117
+}
118
+function directoryConstruct($directoryName, $XML, $data, $array) {
119
+	$directory = opendir($directoryName); 
120
+	while($file = readdir($directory)) {
121
+		if ($file != '.' AND $file != '..') {
122
+			if (is_dir($directoryName.'/'.$file)) {
123
+				$newDirectory = $data->createElement('dir');
124
+				$XML->appendChild($newDirectory);
125
+				$newDirectory->setAttribute('name', $file);
126
+				if (isset($array[$file])) {
127
+					$newDirectory->setAttribute('comparaison', 'same');
128
+					directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, $array[$file]);
129
+				} else {
130
+					$newDirectory->setAttribute('comparaison', 'added');
131
+					directoryConstruct($directoryName.'/'.$file, $newDirectory, $data, array());
132
+				}
133
+			} else {
134
+				$fileXML = $data->createElement('file');
135
+				$XML->appendChild($fileXML);
136
+				$fileXML->setAttribute('name', $file);
137
+				$fileXML->setAttribute('md5', md5_file($directoryName.'/'.$file));
138
+				if (isset($array[$file])) {
139
+					if ($array[$file] == md5_file($directoryName.'/'.$file)) {
140
+						$fileXML->setAttribute('comparaison', 'same');
141
+					} else {
142
+						$fileXML->setAttribute('comparaison', 'change');
143
+					}
144
+				} else {
145
+					$fileXML->setAttribute('comparaison', 'added');
146
+				}
147
+				// TODO Verifier si un fichier a été supprimé	
148
+			}
149
+		}
150
+	}
151
+}
152
+function directoryOld($XML) {
153
+$array = array();
154
+	$dirS = $XML->getElementsByTagName('dir');
155
+	for ($c = $dirS->length, $i = 0; $i < $c; $i++) {
156
+		$dir = $dirS->item($i);
157
+		$array[$dir->getAttribute('name')]= directoryOld($dir);
158
+	}
159
+	$fileS = $XML->getElementsByTagName('file');
160
+	for ($c = $fileS->length, $i = 0; $i < $c; $i++) {
161
+		$file = $fileS->item($i);
162
+		$array[$file->getAttribute('name')] = $file->getAttribute('md5');
163
+	}
164
+	return $array;
165
+}
166
+function rrmdir($dir) { // Par holger1@NOSPAMzentralplan.de
167
+   if (is_dir($dir)) { 
168
+     $objects = scandir($dir); 
169
+     foreach ($objects as $object) { 
170
+       if ($object != "." && $object != "..") { 
171
+         if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object); 
172
+       } 
173
+     } 
174
+     reset($objects); 
175
+     rmdir($dir); 
176
+   } 
177
+ } 
178
+?>

+ 84
- 0
test.php View File

@@ -0,0 +1,84 @@
1
+<?php
2
+date_default_timezone_set('Europe/Paris');
3
+$lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
4
+// set_time_limit('240');
5
+function debug($a){return 0;}
6
+// V�rification d'une update en cours
7
+	debug('test.php started');
8
+if ($lastVersions_e[1] == 'UP') {
9
+	debug('R Up');
10
+	for ($i = 0; $i <= 200; $i++) {
11
+		sleep(1);
12
+		$lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
13
+		if ($lastVersions_e[1] != 'UP') {
14
+			echo implode('|', $lastVersions_e);
15
+			exit();
16
+		}
17
+	}
18
+	echo 'ERREUR La release n\'a pas �t� correctement trait�e. Le syst�me d\'ajout de release est suspendu pour le moment.';
19
+	exit();
20
+}
21
+if ($lastVersions_e[3] == 'UP') {
22
+	debug('APR Up');
23
+	for ($i = 0; $i <= 200; $i++) {
24
+		sleep(1);
25
+		$lastVersions_e = explode('|', file_get_contents('lastVersions.txt'));
26
+		if ($lastVersions_e[3] != 'UP') {
27
+			echo implode('|', $lastVersions_e);
28
+			exit();
29
+		}
30
+	}
31
+	echo 'ERREUR La release n\'a pas �t� correctement trait�e. Le syst�me d\'ajout de release est suspendu pour le moment.';
32
+	exit();
33
+}
34
+if (time()-$lastVersions_e[0] < 5) {
35
+	echo implode('|', $lastVersions_e);
36
+	exit();
37
+}
38
+// TODO Commande serveur
39
+// D�finition de la prochaine APR
40
+if (substr($lastVersions_e[3], 0, 2) == substr(date('Y'), 2, 2) AND substr($lastVersions_e[3], 3, 2) == date('W')) {
41
+	$alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
42
+	$nextAPR = substr(date('Y'), 2, 2).'w'.date('W').$alphabet[array_search(substr($lastVersions_e[3], 2), $alphabet)+1];
43
+	$nextAPR_firstOfWeek = false;
44
+} else {
45
+	$nextAPR = substr(date('Y'), 2, 2).'w'.date('W').'a';
46
+	$nextAPR_firstOfWeek = true;
47
+}
48
+	debug('$nextAPR='.$nextAPR);
49
+// Check de l'APR
50
+if (true) {
51
+// if (((date('D') == 'Thu') AND $nextAPR_firstOfWeek AND time()-$lastVersions_e[0] >= 5) OR time()-$lastVersions_e[0] >= 10) {
52
+	debug('nextAPR check 1');
53
+	if (@fopen('http://assets.minecraft.net/'.$nextAPR.'/minecraft.zip', 'r')) {
54
+		include_once('addrelease.php');
55
+		echo addRelease($nextAPR);
56
+		exit();
57
+	}
58
+}
59
+// Check de la R
60
+if (true) {
61
+// if (time()-$lastVersions_e[0] >= 30){
62
+	if (@md5_file('http://s3.amazonaws.com/MinecraftDownload/minecraft.jar') != $lastVersions_e[2]) {
63
+	debug('nextR check');
64
+		include_once('addrelease.php');
65
+		echo addRelease('r');
66
+		exit();
67
+	}
68
+}
69
+// Re-check de la derni�re APR
70
+if (true) {
71
+//if ((time()-$lastVersions_e[0] <= 20 AND !$nextAPR_firstOfWeek) OR (time()-$lastVersions_e[0] >= 60)) {
72
+	debug('lastAPR re-check');
73
+	if (@md5_file('http://assets.minecraft.net/'.$lastVersions_e[3].'/minecraft.zip') != $lastVersions_e[4]) {
74
+		include_once('addrelease.php');
75
+		echo addRelease($lastVersions_e[3]);
76
+		exit();
77
+	}
78
+}
79
+$lastVersions_e[0] = time();
80
+$lastVersions_f = fopen('lastVersions.txt', 'w');
81
+fwrite($lastVersions_f, implode('|', $lastVersions_e));
82
+fclose($lastVersions_f);
83
+echo implode('|', $lastVersions_e);
84
+?>

+ 48
- 0
todo.txt View File

@@ -0,0 +1,48 @@
1
+TODO
2
+Before release
3
+- Correction de bugs
4
+Before or after
5
+- Autoriser le chargement depuis Minecraft.net pour les R quand dernière R
6
+- Bot (minimaliste, avec gestion de processus à incrémentation)
7
+- Ajouter quelques icônes
8
+- Faire en sorte que les dossiers vides n'apparaissent pas (get Childs)
9
+- nextVersions.txt
10
+After release
11
+- Checker les tweets de @jeb_
12
+- Tweeter les infos sur la release
13
+- Recodage entier en Programmation Orientée Objet (serveur et client) avec jQuery & SQL
14
+	Corrections à faire lors de ce recodage :
15
+	- Nom du fichier
16
+	- Administration
17
+	- Analyser les fichiers / dossiers quand on ouvre Miecraft.jar, pas à l'arrivée de la release
18
+	- Pouvoir actualiser le nom et la description de chaque release
19
+	- data.xml
20
+		- Descriptions multi-langage
21
+		- Pas de lien Wiki
22
+	- Suggestions de description
23
+	- Widget
24
+
25
+
26
+/*var wikiXhr = new XMLHttpRequest();
27
+		wikiXhr.onreadystatechange = function() {
28
+			if (wikiXhr.readyState == 4 && (wikiXhr.status == 200 || wikiXhr.status == 0)) {
29
+				console.debug(wikiXhr.responseHTML);
30
+				// content.getElementsByClassName('wiki')[0].innerHTML = wikiXhr.responseHTML.innerHTML;
31
+			}
32
+		}
33
+		wikiXhr.open('GET', 'wikiAccess.php?u='+content.getElementsByClassName('wikiLink')[0].href, true);
34
+		wikiXhr.send(null);
35
+		$("#cache").load('wikiAccess.php?u='+content.getElementsByClassName('wikiLink')[0].href, function() {
36
+			console.debug('LOOOOOOOOOOOOOOOOOOL');
37
+			data = $(".wikitable tbody tr td").children("span");
38
+			for(i = 0; i<data.length; i++)
39
+			{
40
+				if($(data[i]).attr("id") == MCVersion)
41
+				{
42
+					$("#cache").html('');
43
+				content.getElementsByClassName('wiki')[0].innerHTML = $(data[i]).parent();
44
+				}
45
+			}
46
+			content.getElementsByClassName('wiki')[0].innerHTML = 'Pas d\'informations sur le Wiki';
47
+		});
48
+		*/