[ARCHIVE 2012] Récupère des informations sur les nouvelles versions de Minecraft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

indexold.php 10KB

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