extras.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. <script type="text/javascript" src="js/modules/extras.js"></script>
  2. <?php
  3. /*
  4. *
  5. * OGP - Open Game Panel
  6. * Copyright (C) 2008 - 2018 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. $overwritten_files = "";
  64. $not_overwritten_files = "";
  65. $new_files = "";
  66. $temp_dir = $tmp . DIRECTORY_SEPARATOR . "OGP_Extras";
  67. if( !file_exists($temp_dir) )
  68. mkdir($temp_dir, 0775);
  69. $result = extractZipGitUpdateFile($temp_dwl, $temp_dir);
  70. $newResult = array('ignored_files' => array(), 'extracted_files' => array());
  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. $i = 0;
  79. $i2 = 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. $fullFilename = $filename;
  87. $filename = preg_replace( "/".preg_quote($info['remove_path'])."/", "", $filename);
  88. $install_nfo .= realpath($base_dir) . $filename . "\n";
  89. $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $fullFilename;
  90. $web_file = $base_dir . $filename;
  91. if(file_exists($temp_file)){
  92. if(file_exists($web_file))
  93. {
  94. if(!in_array($filename, $current_blacklist)){
  95. $temp = file_get_contents($temp_file);
  96. $web = file_get_contents($web_file);
  97. if( $temp != $web )
  98. {
  99. if( !is_writable( $web_file ) )
  100. {
  101. if ( ! @chmod( $web_file, 0644 ) )
  102. {
  103. $all_writable = FALSE;
  104. $not_writable .= $web_file."\n";
  105. }
  106. else
  107. {
  108. $newResult["extracted_files"][$i]["filename"] = $filename;
  109. copy($temp_file, $web_file);
  110. $i++;
  111. $overwritten_files .= $filename . "\n";
  112. $overwritten++;
  113. }
  114. }
  115. else
  116. {
  117. $newResult["extracted_files"][$i]["filename"] = $filename;
  118. copy($temp_file, $web_file);
  119. $i++;
  120. $overwritten_files .= $filename . "\n";
  121. $overwritten++;
  122. }
  123. }
  124. }else{
  125. $newResult["ignored_files"][$i2] = $filename;
  126. $i2++;
  127. $not_overwritten_files .= $filename . "\n";
  128. $not_overwritten++;
  129. }
  130. }
  131. else
  132. {
  133. $newResult["extracted_files"][$i]["filename"] = $filename;
  134. $webDir = dirname($web_file);
  135. @mkdir($webDir, 0775, true);
  136. copy($temp_file, $web_file);
  137. $i++;
  138. $new_files .= $filename . "\n";
  139. $new++;
  140. }
  141. }
  142. }
  143. }
  144. else
  145. {
  146. echo $result;
  147. // Remove the downloaded package
  148. if( file_exists( $temp_dwl ) )
  149. unlink( $temp_dwl );
  150. return FALSE;
  151. }
  152. // Once checkings are done the temp folder is removed
  153. if( file_exists( $temp_dir ) )
  154. {
  155. rmdir_recurse( $temp_dir );
  156. }
  157. if( $all_writable )
  158. {
  159. if( is_array( $newResult['extracted_files'] ) )
  160. {
  161. // Updated files
  162. if ( $overwritten > 0 )
  163. {
  164. echo get_lang_f('files_overwritten',$overwritten).":\n\n".$overwritten_files;
  165. echo "\n\n";
  166. }
  167. if ( $new > 0 )
  168. {
  169. echo get_lang_f('new_files',$new).":\n\n".$new_files;
  170. echo "\n\n";
  171. }
  172. if ( $not_overwritten > 0 )
  173. {
  174. echo get_lang_f('files_not_overwritten',$not_overwritten).":\n\n".$not_overwritten_files;
  175. echo "\n\n";
  176. }
  177. // Add install.nfo file to the module/theme directory so we can remove the installed files later and check the installed files timestamp.
  178. file_put_contents($nfo_file, $install_nfo);
  179. // Remove the downloaded package
  180. if( file_exists( $temp_dwl ) )
  181. unlink( $temp_dwl );
  182. return TRUE;
  183. }
  184. else
  185. {
  186. // Remove the downloaded package
  187. if( file_exists( $temp_dwl ) )
  188. unlink( $temp_dwl );
  189. return FALSE;
  190. }
  191. }
  192. else
  193. {
  194. echo $info['title'].":\n$not_writable";
  195. // Remove the downloaded package
  196. if( file_exists( $temp_dwl ) )
  197. unlink( $temp_dwl );
  198. return FALSE;
  199. }
  200. }
  201. function rglob($pattern, $flags = 0) {
  202. $files = glob($pattern, $flags);
  203. foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
  204. $files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
  205. }
  206. return $files;
  207. }
  208. function deeperPathFirst($a, $b)
  209. {
  210. $al = count(explode(DIRECTORY_SEPARATOR,$a));
  211. $bl = count(explode(DIRECTORY_SEPARATOR,$b));
  212. if ($al == $bl) {
  213. return strcmp($a,$b);
  214. }
  215. return ($al > $bl) ? -1 : +1;
  216. }
  217. function exec_ogp_module()
  218. {
  219. global $db, $settings;
  220. // Get blacklisted files
  221. $current_blacklist = array();
  222. $blacklisted_files = $db->resultQuery('SELECT file_path FROM `OGP_DB_PREFIXupdate_blacklist`;');
  223. if($blacklisted_files !== FALSE)
  224. {
  225. $current_blacklist = array();
  226. foreach($blacklisted_files as $blacklisted_file)
  227. {
  228. $current_blacklist[] = $blacklisted_file['file_path'];
  229. }
  230. }
  231. // GitHub URL
  232. if(function_exists("getOGPGitHubURLUnstrict") && function_exists("getGitHubOrganization")){
  233. $gitHubUsername = $settings["custom_github_update_username"];
  234. $gitHubURL = getOGPGitHubURLUnstrict($gitHubUsername);
  235. $gitHubOrganization = getGitHubOrganization($gitHubURL);
  236. }else{
  237. $gitHubURL = "https://github.com/OpenGamePanel/";
  238. $gitHubOrganization = "OpenGamePanel";
  239. }
  240. if($gitHubOrganization == "OpenGamePanel"){
  241. $gitAPICont = "orgs";
  242. }else{
  243. $gitAPICont = "users";
  244. }
  245. set_time_limit(0);
  246. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  247. define('DATA_PATH', realpath('modules/'.$_GET['m'].'/') . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR);
  248. if(!file_exists(DATA_PATH))
  249. {
  250. if(!mkdir(DATA_PATH))
  251. {
  252. 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.');
  253. return;
  254. }
  255. $back_compatibility = array ( 'Util',
  256. 'RCON',
  257. 'DSi',
  258. 'Cron',
  259. 'LGSL_with_Img_Mod',
  260. 'Simple-billing',
  261. 'Support',
  262. 'TeamSpeak3',
  263. 'DarkNature',
  264. 'expand-soft',
  265. 'Katiuska',
  266. 'mobile',
  267. 'Light',
  268. 'Silver',
  269. 'Soft',
  270. 'Uprise' );
  271. $installed = rglob('*/*/install.nfo');
  272. foreach($installed as $nfo)
  273. {
  274. $nfo_new = preg_replace('#^([m|t]{1})(odule|heme){1}s/([^?/]+)/install.nfo#','\3',$nfo);
  275. #echo $nfo_new.'<br>';
  276. $matches = preg_grep('#'.preg_quote($nfo_new).'#i',$back_compatibility);
  277. sort($matches);
  278. if($nfo_new == 'fastdl')
  279. $matches[0] = 'Fast_Download';
  280. if(isset($matches[0]))
  281. {
  282. #echo DATA_PATH.$matches[0].'.nfo<br>';
  283. file_put_contents(DATA_PATH.$matches[0].'.nfo', file_get_contents($nfo));
  284. }
  285. unlink($nfo);
  286. }
  287. }
  288. #return;
  289. define('REPO_FILE', DATA_PATH . "repos" . "_" . strtolower($gitHubOrganization));
  290. define('URL', 'https://api.github.com/' . $gitAPICont . '/' . $gitHubOrganization . '/repos?per_page=100'); // Returns detailed information of all repositories, and urls for more detailed informations about. Nice API GitHub! :)
  291. if(!file_exists(REPO_FILE) || isset($_GET['searchForUpdates']) || isset($_POST['update']) || filesize(REPO_FILE) == 0 || filesize(REPO_FILE) == 1 || (time() - filemtime(REPO_FILE)) >= 86400)
  292. {
  293. # Without this $context the file_get_contents function was returning HTTP/1.0 403 Forbidden
  294. # Thanks: https://github.com/philsturgeon/codeigniter-oauth2/issues/57#issuecomment-29306192
  295. $options = array('http' => array('user_agent'=> $_SERVER['HTTP_USER_AGENT']));
  296. $context = stream_context_create($options);
  297. $response = file_get_contents(URL, false, $context);
  298. file_put_contents(REPO_FILE,$response);
  299. }
  300. else
  301. {
  302. $response = file_get_contents(REPO_FILE);
  303. }
  304. # Converting json string to array
  305. # http://php.net/manual/es/function.json-decode.php mixed json_decode ( string $json [, bool $assoc = false [, int $depth = 512 [, int $options = 0 ]]] )
  306. # *options - Bitmask of JSON decode options. Currently only JSON_BIGINT_AS_STRING is supported (default is to cast large integers as floats)
  307. $repos_info_array = json_decode($response, true);
  308. # Checking for contents while debbuging
  309. /* echo "<xmp>";
  310. print_r($repos_info_array);
  311. echo "</xmp>"; */
  312. if(isset($_POST['remove']))
  313. {
  314. $remove = $_POST['remove'];
  315. $folderToDelete = str_replace(' ','_',$_POST['folder']);
  316. if(isset($folderToDelete) && !empty($folderToDelete)){
  317. // Delete nfo file if it exists
  318. $install_nfo = DATA_PATH . $folderToDelete . ".nfo";
  319. if(file_exists($install_nfo)){
  320. unlink($install_nfo);
  321. // Delete directory if it exists
  322. // We won't run this operation if the nfo file doesn't exist because it could be abused...
  323. $dirToDelete = $remove . "/" . strtolower($folderToDelete);
  324. if(file_exists($dirToDelete) && is_dir($dirToDelete)){
  325. recursiveDelete($dirToDelete);
  326. }
  327. // In case we are using case sensitive names... which happens for themes
  328. $dirToDelete = $remove . "/" . $folderToDelete;
  329. if(file_exists($dirToDelete) && is_dir($dirToDelete)){
  330. recursiveDelete($dirToDelete);
  331. }
  332. // Delete lang files too
  333. $langDirs = array_filter(glob('lang/*'), 'is_dir');
  334. foreach($langDirs as $langDir){
  335. if($langDir != ".." && $langDir != "."){
  336. $langDirPath = $langDir . "/modules/" . strtolower($folderToDelete) . ".php";
  337. if(file_exists($langDirPath)){
  338. recursiveDelete($langDirPath);
  339. }
  340. }
  341. }
  342. // Delete js files for module too
  343. $js = "js/modules/" . strtolower($folderToDelete) . ".js";
  344. if(file_exists($js)){
  345. recursiveDelete($js);
  346. }
  347. // Delete possible image too
  348. $modImage = "modules/administration/images/" . strtolower($folderToDelete) . ".png";
  349. if(file_exists($modImage)){
  350. recursiveDelete($modImage);
  351. }
  352. }
  353. }
  354. return;
  355. }
  356. $modules = array();
  357. $themes = array();
  358. $moduleErrors = array();
  359. $m = 0;
  360. $t = 0;
  361. foreach($repos_info_array as $key => $repository)
  362. {
  363. $isTheme = false;
  364. $isModule = false;
  365. if(preg_match('/^(OGP-Website|OGP-Agent-Linux|OGP-Agent-Windows)$/',$repository['name']))
  366. continue;
  367. if(!preg_match('/^(Module-|Theme-).*$/',$repository['name']))
  368. continue;
  369. if(preg_match('/^(Module-).*$/',$repository['name'])){
  370. $isModule = true;
  371. }else if(preg_match('/^(Theme-).*$/',$repository['name'])){
  372. $isTheme = true;
  373. }
  374. $gitHubBranchName = (!empty($settings['custom_github_update_branch_name']) ? $settings['custom_github_update_branch_name'] : 'master');
  375. $REMOTE_REPO_FILE = $gitHubURL . $repository['name'] . '/commits/' . $gitHubBranchName . '.atom';
  376. $LOCAL_REPO_FILE = DATA_PATH . $repository['name'] . '.atom';
  377. if(!file_exists($LOCAL_REPO_FILE)
  378. OR (isset($_GET['searchForUpdates']) and $_GET['searchForUpdates'] == $repository['name'])
  379. OR ( isset($_POST['update']) && ( (in_array($m, $_POST["module"]) && $isModule) || (in_array($t, $_POST["theme"]) && $isTheme) ) ) )
  380. {
  381. $used_file = $REMOTE_REPO_FILE;
  382. $contents = file_get_contents($used_file);
  383. if(file_put_contents($LOCAL_REPO_FILE, $contents))
  384. touch($LOCAL_REPO_FILE);
  385. }
  386. else
  387. {
  388. $used_file = $LOCAL_REPO_FILE;
  389. $contents = file_get_contents($used_file);
  390. if(!isset($contents) || empty($contents) || filesize($used_file) == 0 || filesize($used_file) == 1){
  391. $used_file = $REMOTE_REPO_FILE;
  392. $contents = file_get_contents($used_file);
  393. if(file_put_contents($LOCAL_REPO_FILE, $contents))
  394. touch($LOCAL_REPO_FILE);
  395. }
  396. }
  397. if( ! $contents && !isset($_GET["type"]) )
  398. {
  399. print_failure('Unable to get contents from: ' . $used_file);
  400. continue;
  401. }
  402. try {
  403. $feedXml = new SimpleXMLElement($contents, LIBXML_NOCDATA);
  404. $seed = basename( (string) $feedXml->entry[0]->link['href'] );
  405. /* echo "<xmp>";
  406. print_r($feedXml);
  407. echo "</xmp>"; */
  408. if($seed)
  409. {
  410. if(preg_match("/^Module-/",$repository['name']))
  411. {
  412. $module_title = preg_replace(array("/^Module-/i","/_/"),array(""," "),$repository['name']);
  413. $modules[$m]['title'] = $module_title;
  414. $modules[$m]['reponame'] = $repository['name'];
  415. $modules[$m]['file'] = $seed.'.zip';
  416. $modules[$m]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
  417. $modules[$m]['date'] = (string) $feedXml->entry[0]->updated;
  418. $modules[$m]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
  419. $modules[$m]['remove_path'] = $repository['name']."-".$seed;
  420. $m++;
  421. }
  422. if(preg_match("/^Theme-/",$repository['name']))
  423. {
  424. $theme_title = preg_replace("/Theme-/i","",$repository['name']);
  425. $themes[$t]['title'] = $theme_title;
  426. $themes[$t]['reponame'] = $repository['name'];
  427. $themes[$t]['file'] = $seed.'.zip';
  428. $themes[$t]['link'] = $gitHubURL . $repository['name'] . '/archive/'.$seed.'.zip';
  429. $themes[$t]['date'] = (string) $feedXml->entry[0]->updated;
  430. $themes[$t]['timestamp'] = strtotime((string) $feedXml->entry[0]->updated);
  431. $themes[$t]['remove_path'] = $repository['name']."-".$seed;
  432. $t++;
  433. }
  434. }
  435. } catch (Exception $e) {
  436. if (preg_match("/^Module-/", $repository['name'])) {
  437. $moduleErrors['modules'][] = preg_replace(array("/^Module-/i","/_/"),array(""," "),$repository['name']);
  438. }
  439. if(preg_match("/^Theme-/", $repository['name']) && !empty($repository['name'])) {
  440. $moduleErrors['themes'][] = preg_replace("/Theme-/i","",$repository['name']);
  441. }
  442. }
  443. }
  444. $installed_modules = $db->getInstalledModules();
  445. if(isset($_POST['update']))
  446. {
  447. $baseDir = str_replace( "modules" . DIRECTORY_SEPARATOR . $_GET['m'],"",dirname(__FILE__) );
  448. $uMF = array();
  449. $tmpdir = get_temp_dir(dirname(__FILE__));
  450. if( !is_writable( $tmpdir ) )
  451. {
  452. echo get_lang_f('temp_folder_not_writable', $tmpdir);
  453. return;
  454. }
  455. foreach($_POST as $key => $value)
  456. {
  457. if($key == 'update')continue;
  458. if($key == 'module')
  459. {
  460. foreach($value as $m)
  461. {
  462. if(installUpdate($modules[$m], $baseDir, $current_blacklist))
  463. {
  464. $install_nfo = DATA_PATH . str_replace(' ','_',$modules[$m]['title']) . ".nfo";
  465. $nfo = file_get_contents($install_nfo);
  466. $modules_dir_preg = preg_quote(realpath('modules') . DIRECTORY_SEPARATOR);
  467. $modulephp_preg = preg_quote(DIRECTORY_SEPARATOR . 'module.php');
  468. $preg = '#'.$modules_dir_preg.'(.*)'.$modulephp_preg.'#';
  469. if(preg_match($preg, $nfo, $matches))
  470. $uMF[] = $matches[1];
  471. }
  472. }
  473. }
  474. if($key == 'theme')
  475. {
  476. foreach($value as $t)
  477. installUpdate($themes[$t], $baseDir, $current_blacklist);
  478. }
  479. }
  480. if(isset($_POST['module']))
  481. {
  482. foreach ( $installed_modules as $installed_module )
  483. {
  484. if(in_array($installed_module['folder'],$uMF))
  485. {
  486. update_module($db,$installed_module['id'],$installed_module['folder']);
  487. echo "\n";
  488. }
  489. }
  490. }
  491. return;
  492. }
  493. echo "<h2>".get_lang("extras")."</h2>";
  494. echo "<table style=\"width:100%;\">";
  495. echo "<tr><td style=\"width:50%; vertical-align:top;\">";
  496. # MODULES
  497. echo "<div class=\"dragbox bloc rounded\" style=\"margin:1%;\">".
  498. "<h4>".get_lang("extra_modules")."</h4>".
  499. "<div class=\"dragbox-content\" >";
  500. if (!empty($moduleErrors['modules'])) {
  501. foreach($moduleErrors['modules'] as $module) {
  502. echo '<input type="checkbox" disabled><b>',$module,'</b> - <b style="color:red;">Unable to retrieve XML data.</b><br>';
  503. }
  504. }
  505. foreach ( $installed_modules as $installed_module )
  506. {
  507. $folder = $installed_module['folder'];
  508. $installed_modules_by_folder[$folder] = $installed_module['id'];
  509. }
  510. foreach($modules as $key => $module)
  511. {
  512. $local_repo_file = DATA_PATH . $module['reponame'] . '.atom';
  513. $install_nfo = DATA_PATH . str_replace(' ','_',$module['title']) . ".nfo";
  514. $on_disk = file_exists($install_nfo);
  515. $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time());
  516. //echo $install_nfo;
  517. $folder = str_replace(' ','_',strtolower($module['title']));
  518. $installed = array_key_exists($folder,$installed_modules_by_folder);
  519. $installed_str = $on_disk ? $installed ? "<a class='uninstall' style='color:blue;' data-module-folder='$folder' data-module-id='".
  520. $installed_modules_by_folder[$folder]."' href='#uninstall_$folder' >".get_lang("uninstall")."</a>" :
  521. "<a class='install' style='color:blue;' data-module-folder='$folder' href='#install_$folder' >".get_lang("install")."</a> - ".
  522. "<a class='remove' style='color:red;' data-module-folder='$module[title]' data-remove-mode='modules' href='#remove_$folder' >".get_lang("remove")."</a>" :
  523. "<b style='color:red;' >".get_lang("not_installed")."</b>";
  524. $uptodate = FALSE;
  525. if($on_disk)
  526. {
  527. $install_nfo = file_get_contents($install_nfo);
  528. list($timestamp, $files) = explode("\n", $install_nfo);
  529. $uptodate = ($timestamp == $module['timestamp']) ? TRUE : FALSE;
  530. }
  531. $updated_str = $on_disk ?
  532. $uptodate ?
  533. $is_old ? " - <a class='search' style='color:brown;' href='?m=".$_GET['m']."&searchForUpdates=".$module['reponame']."' >".get_lang("search_for_updates")."</a>" :
  534. " - <b style='color:green;' >".get_lang("uptodate")."</b>" :
  535. " - <b style='color:orange;' >".get_lang("update_available")."</b> (".$module['date'].")" :
  536. "";
  537. $disabled = $uptodate ? "disabled=disabled" : "";
  538. echo '<input type="checkbox" name="module" value="'.$key."\" $disabled>";
  539. echo '<b>'.$module['title']."</b> - $installed_str$updated_str <span id='loading' class='$folder' ></span><br>";
  540. }
  541. echo "</div></div></td><td style=\"width:50%; vertical-align:top;\">";
  542. # THEMES
  543. echo "<div class=\"dragbox bloc rounded\" style=\"margin:1%;\">".
  544. "<h4>".get_lang("extra_themes")."</h4>".
  545. "<div class=\"dragbox-content\" >";
  546. if (!empty($moduleErrors['themes'])) {
  547. foreach($moduleErrors['themes'] as $theme) {
  548. echo '<input type="checkbox" disabled><b>',$theme,'</b> - <b style="color:red;">Unable to retrieve XML data.</b><br>';
  549. }
  550. }
  551. foreach($themes as $key => $theme)
  552. {
  553. $local_repo_file = DATA_PATH . $theme['reponame'] . '.atom';
  554. $install_nfo = DATA_PATH . str_replace(' ','_',$theme['title']) . ".nfo";
  555. $on_disk = file_exists($install_nfo);
  556. $is_old = $on_disk && (strtotime('+1 hour', filemtime($local_repo_file)) <= time());
  557. $installed_str = $on_disk ? "<b style='color:green;' >".get_lang("installed")."</b> - ".
  558. "<a class='remove' style='color:red;' data-module-folder='$theme[title]' data-remove-mode='themes' href='#remove_$folder' >".get_lang("remove")."</a>":
  559. "<b style='color:red;' >".get_lang("not_installed")."</b>";
  560. $uptodate = FALSE;
  561. if($on_disk)
  562. {
  563. $install_nfo = file_get_contents($install_nfo);
  564. list($timestamp, $files) = explode("\n", $install_nfo);
  565. $uptodate = ($timestamp == $theme['timestamp']) ? TRUE : FALSE;
  566. }
  567. $updated_str = $on_disk ?
  568. $uptodate ?
  569. $is_old ? " - <a class='search' style='color:brown;' href='?m=".$_GET['m']."&searchForUpdates=".$theme['reponame']."' >".get_lang("search_for_updates")."</a>" :
  570. " - <b style='color:green;' >".get_lang("uptodate")."</b>" :
  571. " - <b style='color:orange;' >".get_lang("update_available")."</b> (".$theme['date'].")" :
  572. "";
  573. $disabled = $uptodate ? "disabled=disabled" : "";
  574. echo '<input type="checkbox" name="theme" value="'.$key."\" $disabled>";
  575. echo '<b>'.$theme['title']."</b> - $installed_str$updated_str<br>";
  576. }
  577. echo "</div></div></td></tr>".
  578. "<tr><td colspan=2 ><span id=updateButton ><button name=update >".get_lang("download_update")."</button></span></td></tr></table><div id=resp ></div>";
  579. echo "<div id='dialog".
  580. "' data-uninstalling_module_dataloss='".get_lang("uninstalling_module_dataloss").
  581. "' data-are_you_sure='".get_lang("are_you_sure").
  582. "' data-remove_files_for='".get_lang("remove_files_for").
  583. "' data-confirm='".get_lang("confirm").
  584. "' data-cancel='".get_lang("cancel").
  585. "' ></div>";
  586. }
  587. ?>