extras.php 20 KB

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