plugin-functions.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 true;
  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. return true;
  58. }