extras.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. <script type="text/javascript" src="js/modules/extras.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) Copyright (C) 2008 - 2013 The OGP Development Team
  7. *
  8. * http://www.opengamepanel.org/
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version 2
  13. * of the License, or any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  23. *
  24. */
  25. require('modules/update/unzip.php');
  26. require('modules/modulemanager/module_handling.php');
  27. function rmdir_recurse($path) {
  28. $path = rtrim($path, '/').'/';
  29. $handle = opendir($path);
  30. while(false !== ($file = readdir($handle))) {
  31. if($file != '.' and $file != '..' ) {
  32. $fullpath = $path.$file;
  33. if(is_dir($fullpath)) rmdir_recurse($fullpath); else unlink($fullpath);
  34. }
  35. }
  36. closedir($handle);
  37. rmdir($path);
  38. }
  39. function getMyFile($url,$destination)
  40. {
  41. $result = file_get_contents($url);
  42. if(!$result)
  43. return $result;
  44. return file_put_contents($destination, $result);
  45. }
  46. function installUpdate($info, $base_dir, $current_blacklist = array())
  47. {
  48. $tmp = get_temp_dir(dirname(__FILE__));
  49. $temp_dwl = $tmp . DIRECTORY_SEPARATOR . $info['file'];
  50. $_SESSION['link'] = $info['link'];
  51. if(!getMyFile($info['link'],$temp_dwl))
  52. {
  53. echo get_lang_f('unable_download',$info['title'])."\n";
  54. return;
  55. }
  56. // Set default values for file checkings before installing
  57. $not_writable = can_not_update_non_writable_files ." :\n";
  58. $filename = "";
  59. $overwritten = 0;
  60. $not_overwritten = 0;
  61. $new = 0;
  62. $all_writable = TRUE;
  63. $filelist = "";
  64. $overwritten_files = "";
  65. $not_overwritten_files = "";
  66. $new_files = "";
  67. $temp_dir = $tmp . DIRECTORY_SEPARATOR . "OGP_Extras";
  68. if( !file_exists($temp_dir) )
  69. mkdir($temp_dir, 0775);
  70. $result = extractZip( $temp_dwl, $temp_dir . DIRECTORY_SEPARATOR, $info['remove_path'] );
  71. if ( is_array($result['extracted_files']) and count($result['extracted_files']) > 0 )
  72. {
  73. $nfo_file = DATA_PATH . str_replace(' ','_',$info['title']) . ".nfo";
  74. $install_nfo = $info['timestamp']."\n$nfo_file\n";
  75. // Check file by file if already exists, if it matches, compares both files
  76. // looking for changes determining if the file needs to be updated.
  77. // Also determines if the file is writable
  78. $filelist = array();
  79. $i = 0;
  80. foreach( $result['extracted_files'] as $file )
  81. {
  82. if( DIRECTORY_SEPARATOR == '\\')
  83. $filename = str_replace('/', '\\', $file['filename']);
  84. else
  85. $filename = $file['filename'];
  86. $filename = preg_replace( "/".preg_quote($info['remove_path'])."/", "", $filename);
  87. $install_nfo .= realpath($base_dir) . $filename . "\n";
  88. $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $filename;
  89. $web_file = $base_dir . $filename;
  90. if( file_exists( $web_file ) )
  91. {
  92. echo $filename . "\n";
  93. if(!in_array($filename, $current_blacklist)){
  94. $temp = file_get_contents($temp_file);
  95. $web = file_get_contents($web_file);
  96. if( $temp != $web )
  97. {
  98. if( !is_writable( $web_file ) )
  99. {
  100. if ( ! @chmod( $web_file, 0644 ) )
  101. {
  102. $all_writable = FALSE;
  103. $not_writable .= $web_file."\n";
  104. }
  105. else
  106. {
  107. $filelist[$i] = $file['filename'];
  108. $i++;
  109. $overwritten_files .= $filename . "\n";
  110. $overwritten++;
  111. }
  112. }
  113. else
  114. {
  115. $filelist[$i] = $file['filename'];
  116. $i++;
  117. $overwritten_files .= $filename . "\n";
  118. $overwritten++;
  119. }
  120. }
  121. }else{
  122. $not_overwritten_files .= $filename . "\n";
  123. $not_overwritten++;
  124. }
  125. }
  126. else
  127. {
  128. $filelist[$i] = $file['filename'];
  129. $i++;
  130. $new_files .= $filename . "\n";
  131. $new++;
  132. }
  133. }
  134. }
  135. else
  136. {
  137. echo $result;
  138. // Remove the downloaded package
  139. if( file_exists( $temp_dwl ) )
  140. unlink( $temp_dwl );
  141. return FALSE;
  142. }
  143. // Once checkings are done the temp folder is removed
  144. if( file_exists( $temp_dir ) )
  145. {
  146. rmdir_recurse( $temp_dir );
  147. }
  148. if( $all_writable )
  149. {
  150. // Extract the files that are set in $filelist, to the folder at $base_dir.
  151. $result = extractZip( $temp_dwl, $base_dir, $info['remove_path'], '', $filelist );
  152. if( is_array( $result['extracted_files'] ) )
  153. {
  154. // Updated files
  155. if ( $overwritten > 0 )
  156. {
  157. echo get_lang_f('files_overwritten',$overwritten).":\n".$overwritten_files;
  158. }
  159. if ( $new > 0 )
  160. {
  161. echo get_lang_f('new_files',$new).":\n".$new_files;
  162. }
  163. if ( $not_overwritten > 0 )
  164. {
  165. echo get_lang_f('files_not_overwritten',$not_overwritten).":\n".$not_overwritten_files;
  166. }
  167. // Add install.nfo file to the module/theme directory so we can remove the installed files later and check the installed files timestamp.
  168. file_put_contents($nfo_file, $install_nfo);
  169. // Remove the downloaded package
  170. if( file_exists( $temp_dwl ) )
  171. unlink( $temp_dwl );
  172. return TRUE;
  173. }
  174. else
  175. {
  176. // Remove the downloaded package
  177. if( file_exists( $temp_dwl ) )
  178. unlink( $temp_dwl );
  179. return FALSE;
  180. }
  181. }
  182. else
  183. {
  184. echo $info['title'].":\n$not_writable";
  185. // Remove the downloaded package
  186. if( file_exists( $temp_dwl ) )
  187. unlink( $temp_dwl );
  188. return FALSE;
  189. }
  190. }
  191. function rglob($pattern, $flags = 0) {
  192. $files = glob($pattern, $flags);
  193. foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
  194. $files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
  195. }
  196. return $files;
  197. }
  198. function deeperPathFirst($a, $b)
  199. {
  200. $al = count(explode(DIRECTORY_SEPARATOR,$a));
  201. $bl = count(explode(DIRECTORY_SEPARATOR,$b));
  202. if ($al == $bl) {
  203. return strcmp($a,$b);
  204. }
  205. return ($al > $bl) ? -1 : +1;
  206. }
  207. function exec_ogp_module()
  208. {
  209. global $db, $settings;
  210. // Get blacklisted files
  211. $current_blacklist = array();
  212. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  213. if($blacklisted_files !== FALSE)
  214. {
  215. $current_blacklist = array();
  216. foreach($blacklisted_files as $blacklisted_file)
  217. {
  218. $current_blacklist[] = $blacklisted_file['file_path'];
  219. }
  220. }
  221. // GitHub URL
  222. $gitHubURL = $settings["custom_github_update_URL"];
  223. $gitHubURL = getOGPGitHubURL($gitHubURL);
  224. $gitHubOrganization = getGitHubOrganization($gitHubURL);
  225. if($gitHubOrganization == "OpenGamePanel"){
  226. $gitAPICont = "orgs";
  227. }else{
  228. $gitAPICont = "users";
  229. }
  230. set_time_limit(0);
  231. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  232. define('DATA_PATH', realpath('modules/'.$_GET['m'].'/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR);
  233. if(!file_exists(DATA_PATH))
  234. {
  235. if(!mkdir(DATA_PATH))
  236. {
  237. print_failure("Need create folder: " . DATA_PATH . ' <br>But ' . dirname(DATA_PATH) . ' is not writable.<br>The command: <pre>chmod -R ' . dirname(DATA_PATH) . '</pre> would fix it.');
  238. return;
  239. }
  240. $back_compatibility = [ 'Util',
  241. 'RCON',
  242. 'DSi',
  243. 'Cron',
  244. 'LGSL_with_Img_Mod',
  245. 'Simple-billing',
  246. 'Support',
  247. 'TeamSpeak3',
  248. 'DarkNature',
  249. 'expand-soft',
  250. 'Katiuska',
  251. 'mobile',
  252. 'Light',
  253. 'Silver',
  254. 'Soft',
  255. 'Uprise' ];
  256. $installed = rglob('*/*/install.nfo');
  257. foreach($installed as $nfo)
  258. {
  259. $nfo_new = preg_replace('#^([m|t]{1})(odule|heme){1}s/([^?/]+)/install.nfo#','\3',$nfo);
  260. #echo $nfo_new.'<br>';
  261. $matches = preg_grep('#'.preg_quote($nfo_new).'#i',$back_compatibility);
  262. sort($matches);
  263. if($nfo_new == 'fastdl')
  264. $matches[0] = 'Fast_Download';
  265. if(isset($matches[0]))
  266. {
  267. #echo DATA_PATH.$matches[0].'.nfo<br>';
  268. file_put_contents(DATA_PATH.$matches[0].'.nfo', file_get_contents($nfo));
  269. }
  270. unlink($nfo);
  271. }
  272. }
  273. #return;
  274. define('REPO_FILE', DATA_PATH . "repos");
  275. define('URL', 'https://api.github.com/' . $gitAPICont . '/' . $gitHubOrganization . '/repos'); // Returns detailed information of all repositories, and urls for more detailed informations about. Nice API GitHub! :)
  276. if(!file_exists(REPO_FILE) or isset($_GET['searchForUpdates']) or isset($_POST['update']) or filesize(REPO_FILE) == 0 or filesize(REPO_FILE) == 1)
  277. {
  278. # Without this $context the file_get_contents function was returning HTTP/1.0 403 Forbidden
  279. # Thanks: https://github.com/philsturgeon/codeigniter-oauth2/issues/57#issuecomment-29306192
  280. $options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
  281. $context = stream_context_create($options);
  282. $response = file_get_contents(URL, false, $context);
  283. file_put_contents(REPO_FILE,$response);
  284. }
  285. else
  286. {
  287. $response = file_get_contents(REPO_FILE);
  288. }
  289. # Converting json string to array
  290. # http://php.net/manual/es/function.json-decode.php mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
  291. # *options - Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
  292. $repos_info_array = json_decode($response, true);
  293. # Checking for contents while debbuging
  294. /* echo "<xmp>";
  295. print_r($repos_info_array);
  296. echo "</xmp>"; */
  297. if(isset($_POST['remove']))
  298. {
  299. $remove = $_POST['remove'];
  300. $folderToDelete = str_replace(' ','_',$_POST['folder']);
  301. if(isset($folderToDelete) && !empty($folderToDelete)){
  302. // Delete nfo file if it exists
  303. $install_nfo = DATA_PATH . $folderToDelete . ".nfo";
  304. if(file_exists($install_nfo)){
  305. unlink($install_nfo);
  306. // Delete directory if it exists
  307. // We won't run this operation if the nfo file doesn't exist because it could be abused...
  308. $dirToDelete = $remove . "/" . strtolower($folderToDelete);
  309. if(file_exists($dirToDelete) && is_dir($dirToDelete)){
  310. recursiveDelete($dirToDelete);
  311. }
  312. // In case we are using case sensitive names... which happens for themes
  313. $dirToDelete = $remove . "/" . $folderToDelete;
  314. if(file_exists($dirToDelete) && is_dir($dirToDelete)){
  315. recursiveDelete($dirToDelete);
  316. }
  317. // Delete lang files too
  318. $langDirs = array_filter(glob('lang/*'), 'is_dir');
  319. foreach($langDirs as $langDir){
  320. if($langDir != ".." && $langDir != "."){
  321. $langDirPath = "lang/" . $langDir . "/modules/" . strtolower($folderToDelete) . ".php";
  322. if(file_exists($langDirPath)){
  323. recursiveDelete($langDirPath);
  324. }
  325. }
  326. }
  327. // Delete js files for module too
  328. $js = "js/modules/" . strtolower($folderToDelete) . ".js";
  329. if(file_exists($js)){
  330. recursiveDelete($js);
  331. }
  332. // Delete possible image too
  333. $modImage = "modules/administration/images/" . strtolower($folderToDelete) . ".png";
  334. if(file_exists($modImage)){
  335. recursiveDelete($modImage);
  336. }
  337. }
  338. }
  339. return;
  340. }
  341. $modules = array();
  342. $themes = array();
  343. $moduleErrors = array();
  344. $m = 0;
  345. $t = 0;
  346. foreach($repos_info_array as $key => $repository)
  347. {
  348. if(preg_match('/^(OGP-Website|OGP-Agent-Linux|OGP-Agent-Windows)$/',$repository['name']))
  349. continue;
  350. $REMOTE_REPO_FILE = $gitHubURL . $repository['name'] . '/commits/master.atom';
  351. $LOCAL_REPO_FILE = DATA_PATH . $repository['name'] . '.atom';
  352. if(!file_exists($LOCAL_REPO_FILE) OR (isset($_GET['searchForUpdates']) and $_GET['searchForUpdates'] == $repository['name']) OR isset($_POST['update']))
  353. {
  354. $used_file = $REMOTE_REPO_FILE;
  355. $contents = file_get_contents($used_file);
  356. if(file_put_contents($LOCAL_REPO_FILE, $contents))
  357. touch($LOCAL_REPO_FILE);
  358. }
  359. else
  360. {
  361. $used_file = $LOCAL_REPO_FILE;
  362. $contents = file_get_contents($used_file);
  363. if(!isset($contents) || empty($contents) || filesize($used_file) == 0 || filesize($used_file) == 1){
  364. $used_file = $REMOTE_REPO_FILE;
  365. $contents = file_get_contents($used_file);
  366. if(file_put_contents($LOCAL_REPO_FILE, $contents))
  367. touch($LOCAL_REPO_FILE);
  368. }
  369. }
  370. if( ! $contents && !isset($_GET["type"]) )
  371. {
  372. print_failure('Unable to get contents from : ' . $used_file);
  373. continue;
  374. }
  375. try {
  376. $feedXml = new SimpleXMLElement($contents, LIBXML_NOCDATA);
  377. $seed = basename( (string) $feedXml->entry[0]->link['href'] );
  378. /* echo "<xmp>";
  379. print_r($feedXml);
  380. echo "</xmp>"; */
  381. if($seed)
  382. {
  383. if(preg_match("/^Module-/",$repository['name']))
  384. {
  385. $module_title = preg_replace(array("/^Module-/i","/_/"),array(""," "),$repository['name']);
  386. $modules[$m]['title'] = $module_title;
  387. $modules[$m]['reponame'] = $repository['name'];
  388. $modules[$m]['file'] = $seed.'.zip';
  389. $modules[$m]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
  390. $modules[$m]['date'] = (string) $feedXml->entry[0]->updated;
  391. $modules[$m]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
  392. $modules[$m]['remove_path'] = $repository['name']."-".$seed;
  393. $m++;
  394. }
  395. if(preg_match("/^Theme-/",$repository['name']))
  396. {
  397. $theme_title = preg_replace("/Theme-/i","",$repository['name']);
  398. $themes[$t]['title'] = $theme_title;
  399. $themes[$t]['reponame'] = $repository['name'];
  400. $themes[$t]['file'] = $seed.'.zip';
  401. $themes[$t]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
  402. $themes[$t]['date'] = (string) $feedXml->entry[0]->updated;
  403. $themes[$t]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
  404. $themes[$t]['remove_path'] = $repository['name']."-".$seed;
  405. $t++;
  406. }
  407. }
  408. } catch (Exception $e) {
  409. if (preg_match("/^Module-/", $repository['name'])) {
  410. $moduleErrors['modules'][] = preg_replace(array("/^Module-/i","/_/"),array(""," "),$repository['name']);
  411. }
  412. if(preg_match("/^Theme-/", $repository['name']) && !empty($repository['name'])) {
  413. $moduleErrors['themes'][] = preg_replace("/Theme-/i","",$repository['name']);
  414. }
  415. }
  416. }
  417. $installed_modules = $db->getInstalledModules();
  418. if(isset($_POST['update']))
  419. {
  420. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  421. $uMF = array();
  422. $tmpdir = get_temp_dir(dirname(__FILE__));
  423. if( !is_writable( $tmpdir ) )
  424. {
  425. echo get_lang_f('temp_folder_not_writable', $tmpdir);
  426. return;
  427. }
  428. foreach($_POST as $key => $value)
  429. {
  430. if($key == 'update')continue;
  431. if($key == 'module')
  432. {
  433. foreach($value as $m)
  434. {
  435. if(installUpdate($modules[$m], $baseDir, $current_blacklist))
  436. {
  437. $install_nfo = DATA_PATH . str_replace(' ','_',$modules[$m]['title']) . ".nfo";
  438. $nfo = file_get_contents($install_nfo);
  439. $modules_dir_preg = preg_quote(realpath('modules') . DIRECTORY_SEPARATOR);
  440. $modulephp_preg = preg_quote(DIRECTORY_SEPARATOR . 'module.php');
  441. $preg = '#'.$modules_dir_preg.'(.*)'.$modulephp_preg.'#';
  442. if(preg_match($preg, $nfo, $matches))
  443. $uMF[] = $matches[1];
  444. }
  445. }
  446. }
  447. if($key == 'theme')
  448. {
  449. foreach($value as $t)
  450. installUpdate($themes[$t], $baseDir, $current_blacklist);
  451. }
  452. }
  453. if(isset($_POST['module']))
  454. {
  455. foreach ( $installed_modules as $installed_module )
  456. {
  457. if(in_array($installed_module['folder'],$uMF))
  458. {
  459. update_module($db,$installed_module['id'],$installed_module['folder']);
  460. echo "\n";
  461. }
  462. }
  463. }
  464. return;
  465. }
  466. echo "<h2>".extras."</h2>";
  467. echo "<table style=\"width:100%;\">";
  468. echo "<tr><td style=\"width:50%;\">";
  469. # MODULES
  470. echo "<div class=\"dragbox bloc rounded\" style=\"margin:1%;\">".
  471. "<h4>".extra_modules."</h4>".
  472. "<div class=\"dragbox-content\" >";
  473. if (!empty($moduleErrors['modules'])) {
  474. foreach($moduleErrors['modules'] as $module) {
  475. echo '<input type="checkbox" disabled><b>',$module,'</b> - <b style="color:red;">Unable to retrieve XML data.</b><br>';
  476. }
  477. }
  478. foreach ( $installed_modules as $installed_module )
  479. {
  480. $folder = $installed_module['folder'];
  481. $installed_modules_by_folder[$folder] = $installed_module['id'];
  482. }
  483. foreach($modules as $key => $module)
  484. {
  485. $local_repo_file = DATA_PATH . $module['reponame'] . '.atom';
  486. $install_nfo = DATA_PATH . str_replace(' ','_',$module['title']) . ".nfo";
  487. $on_disk = file_exists($install_nfo);
  488. $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time());
  489. //echo $install_nfo;
  490. $folder = str_replace(' ','_',strtolower($module['title']));
  491. $installed = array_key_exists($folder,$installed_modules_by_folder);
  492. $installed_str = $on_disk ? $installed ? "<a class='uninstall' style='color:blue;' data-module-folder='$folder' data-module-id='".
  493. $installed_modules_by_folder[$folder]."' href='#uninstall_$folder' >".uninstall."</a>" :
  494. "<a class='install' style='color:blue;' data-module-folder='$folder' href='#install_$folder' >".install."</a> - ".
  495. "<a class='remove' style='color:red;' data-module-folder='$module[title]' data-remove-mode='modules' href='#remove_$folder' >".remove."</a>" :
  496. "<b style='color:red;' >".not_installed."</b>";
  497. $uptodate = FALSE;
  498. if($on_disk)
  499. {
  500. $install_nfo = file_get_contents($install_nfo);
  501. list($timestamp, $files) = explode("\n", $install_nfo);
  502. $uptodate = ($timestamp == $module['timestamp']) ? TRUE : FALSE;
  503. }
  504. $updated_str = $on_disk ?
  505. $uptodate ?
  506. $is_old ? " - <a class='search' style='color:brown;' href='?m=".$_GET['m']."&searchForUpdates=".$module['reponame']."' >".search_for_updates."</a>" :
  507. " - <b style='color:green;' >".uptodate."</b>" :
  508. " - <b style='color:orange;' >".update_available."</b> (".$module['date'].")" :
  509. "";
  510. $disabled = $uptodate ? "disabled=disabled" : "";
  511. echo '<input type="checkbox" name="module" value="'.$key."\" $disabled>";
  512. echo '<b>'.$module['title']."</b> - $installed_str$updated_str <span id='loading' class='$folder' ></span><br>";
  513. }
  514. echo "</div></td><td></div>";
  515. # THEMES
  516. echo "<div class=\"dragbox bloc rounded\" style=\"margin:1%;\">".
  517. "<h4>".extra_themes."</h4>".
  518. "<div class=\"dragbox-content\" >";
  519. if (!empty($moduleErrors['themes'])) {
  520. foreach($moduleErrors['themes'] as $theme) {
  521. echo '<input type="checkbox" disabled><b>',$theme,'</b> - <b style="color:red;">Unable to retrieve XML data.</b><br>';
  522. }
  523. }
  524. foreach($themes as $key => $theme)
  525. {
  526. $local_repo_file = DATA_PATH . $theme['reponame'] . '.atom';
  527. $install_nfo = DATA_PATH . str_replace(' ','_',$theme['title']) . ".nfo";
  528. $on_disk = file_exists($install_nfo);
  529. $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time());
  530. $installed_str = $on_disk ? "<b style='color:green;' >".installed."</b> - ".
  531. "<a class='remove' style='color:red;' data-module-folder='$theme[title]' data-remove-mode='themes' href='#remove_$folder' >".remove."</a>":
  532. "<b style='color:red;' >".not_installed."</b>";
  533. $uptodate = FALSE;
  534. if($on_disk)
  535. {
  536. $install_nfo = file_get_contents($install_nfo);
  537. list($timestamp, $files) = explode("\n", $install_nfo);
  538. $uptodate = ($timestamp == $theme['timestamp']) ? TRUE : FALSE;
  539. }
  540. $updated_str = $on_disk ?
  541. $uptodate ?
  542. $is_old ? " - <a class='search' style='color:brown;' href='?m=".$_GET['m']."&searchForUpdates=".$theme['reponame']."' >".search_for_updates."</a>" :
  543. " - <b style='color:green;' >".uptodate."</b>" :
  544. " - <b style='color:orange;' >".update_available."</b> (".$theme['date'].")" :
  545. "";
  546. $disabled = $uptodate ? "disabled=disabled" : "";
  547. echo '<input type="checkbox" name="theme" value="'.$key."\" $disabled>";
  548. echo '<b>'.$theme['title']."</b> - $installed_str$updated_str<br>";
  549. }
  550. echo "</div></div></td></tr>".
  551. "<tr><td colspan=2 ><span id=updateButton ><button name=update >".download_update."</button></span></td></tr></table><div id=resp ></div>";
  552. echo "<div id='dialog".
  553. "' data-uninstalling_module_dataloss='".uninstalling_module_dataloss.
  554. "' data-are_you_sure='".are_you_sure.
  555. "' data-remove_files_for='".remove_files_for.
  556. "' data-confirm='".confirm.
  557. "' data-cancel='".cancel.
  558. "' ></div>";
  559. }
  560. ?>