theme-functions.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. function installTheme($theme)
  3. {
  4. $name = $theme['data']['theme']['name'];
  5. $version = $theme['data']['theme']['version'];
  6. foreach ($theme['data']['theme']['downloadList'] as $k => $v) {
  7. $file = array(
  8. 'from' => $v['githubPath'],
  9. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'] . $v['fileName']),
  10. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'])
  11. );
  12. if (!downloadFileToPath($file['from'], $file['to'], $file['path'])) {
  13. writeLog('error', 'Theme Function - Downloaded File Failed for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
  14. return false;
  15. }
  16. }
  17. updateConfig(
  18. array(
  19. 'themeInstalled' => $name,
  20. 'themeVersion' => $version,
  21. )
  22. );
  23. return true;
  24. }
  25. function removeTheme($theme)
  26. {
  27. $name = $theme['data']['theme']['name'];
  28. $version = $theme['data']['theme']['version'];
  29. foreach ($theme['data']['theme']['downloadList'] as $k => $v) {
  30. $file = array(
  31. 'from' => $v['githubPath'],
  32. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'] . $v['fileName']),
  33. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'])
  34. );
  35. if (!rrmdir($file['to'])) {
  36. writeLog('error', 'Theme Function - Remove File Failed for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
  37. return false;
  38. }
  39. }
  40. if ($GLOBALS['themeInstalled'] !== '') {
  41. $installedTheme = $GLOBALS['themeInstalled'];
  42. if ($installedTheme == $name) {
  43. updateConfig(
  44. array(
  45. 'themeInstalled' => '',
  46. 'themeVersion' => '',
  47. )
  48. );
  49. }
  50. }
  51. return true;
  52. }