theme-functions.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. if ($GLOBALS['installedThemes'] !== '') {
  18. $installedThemes = explode('|', $GLOBALS['installedThemes']);
  19. foreach ($installedThemes as $k => $v) {
  20. $themes = explode(':', $v);
  21. $installedThemesList[$themes[0]] = $themes[1];
  22. }
  23. if (isset($installedThemesList[$name])) {
  24. $installedThemesList[$name] = $version;
  25. $installedThemesNew = '';
  26. foreach ($installedThemesList as $k => $v) {
  27. if ($installedThemesNew == '') {
  28. $installedThemesNew .= $k . ':' . $v;
  29. } else {
  30. $installedThemesNew .= '|' . $k . ':' . $v;
  31. }
  32. }
  33. } else {
  34. $installedThemesNew = $GLOBALS['installedThemes'] . '|' . $name . ':' . $version;
  35. }
  36. } else {
  37. $installedThemesNew = $name . ':' . $version;
  38. }
  39. updateConfig(array('installedThemes' => $installedThemesNew));
  40. return 'Success!@!' . $installedThemesNew;
  41. }
  42. function removeTheme($theme)
  43. {
  44. $name = $theme['data']['theme']['name'];
  45. $version = $theme['data']['theme']['version'];
  46. foreach ($theme['data']['theme']['downloadList'] as $k => $v) {
  47. $file = array(
  48. 'from' => $v['githubPath'],
  49. 'to' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'] . $v['fileName']),
  50. 'path' => str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $GLOBALS['root'] . $v['path'])
  51. );
  52. if (!rrmdir($file['to'])) {
  53. writeLog('error', 'Theme Function - Remove File Failed for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
  54. return false;
  55. }
  56. }
  57. if ($GLOBALS['themeInstalled'] !== '') {
  58. $installedTheme = $GLOBALS['themeInstalled'];
  59. if ($installedTheme == $name) {
  60. updateConfig(
  61. array(
  62. 'themeInstalled' => '',
  63. 'themeVersion' => '',
  64. )
  65. );
  66. }
  67. }
  68. return true;
  69. }