plugin-functions.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. function installPlugin($plugin)
  3. {
  4. $name = $plugin['data']['plugin']['name'];
  5. $version = $plugin['data']['plugin']['version'];
  6. foreach ($plugin['data']['plugin']['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', 'Plugin Function - Downloaded File Failed for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
  14. return false;
  15. }
  16. }
  17. if ($GLOBALS['installedPlugins'] !== '') {
  18. $installedPlugins = explode('|', $GLOBALS['installedPlugins']);
  19. foreach ($installedPlugins as $k => $v) {
  20. $plugins = explode(':', $v);
  21. $installedPluginsList[$plugins[0]] = $plugins[1];
  22. }
  23. if (isset($installedPluginsList[$name])) {
  24. $installedPluginsList[$name] = $version;
  25. $installedPluginsNew = '';
  26. foreach ($installedPluginsList as $k => $v) {
  27. if ($installedPluginsNew == '') {
  28. $installedPluginsNew .= $k . ':' . $v;
  29. } else {
  30. $installedPluginsNew .= '|' . $k . ':' . $v;
  31. }
  32. }
  33. } else {
  34. $installedPluginsNew = $GLOBALS['installedPlugins'] . '|' . $name . ':' . $version;
  35. }
  36. } else {
  37. $installedPluginsNew = $name . ':' . $version;
  38. }
  39. updateConfig(array('installedPlugins' => $installedPluginsNew));
  40. return 'Success!@!' . $installedPluginsNew;
  41. }
  42. function removePlugin($plugin)
  43. {
  44. $name = $plugin['data']['plugin']['name'];
  45. $version = $plugin['data']['plugin']['version'];
  46. foreach ($plugin['data']['plugin']['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', 'Plugin Function - Remove File Failed for: ' . $v['githubPath'], $GLOBALS['organizrUser']['username']);
  54. return false;
  55. }
  56. }
  57. if ($GLOBALS['installedPlugins'] !== '') {
  58. $installedPlugins = explode('|', $GLOBALS['installedPlugins']);
  59. foreach ($installedPlugins as $k => $v) {
  60. $plugins = explode(':', $v);
  61. $installedPluginsList[$plugins[0]] = $plugins[1];
  62. }
  63. if (isset($installedPluginsList[$name])) {
  64. $installedPluginsNew = '';
  65. foreach ($installedPluginsList as $k => $v) {
  66. if ($k !== $name) {
  67. if ($installedPluginsNew == '') {
  68. $installedPluginsNew .= $k . ':' . $v;
  69. } else {
  70. $installedPluginsNew .= '|' . $k . ':' . $v;
  71. }
  72. }
  73. }
  74. }
  75. } else {
  76. $installedPluginsNew = '';
  77. }
  78. updateConfig(array('installedPlugins' => $installedPluginsNew));
  79. return 'Success!@!' . $installedPluginsNew;
  80. }