activate.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Activate a plugin or plugins.
  4. *
  5. * Plugins to be activated are passed via $_REQUEST['plugin_guids'] as GUIDs.
  6. * After activating the plugin(s), the views cache and simplecache are invalidated.
  7. *
  8. * @uses mixed $_GET['plugin_guids'] The GUIDs of the plugin to activate. Can be an array.
  9. *
  10. * @package Elgg.Core
  11. * @subpackage Administration.Plugins
  12. */
  13. $plugin_guids = get_input('plugin_guids');
  14. if (!is_array($plugin_guids)) {
  15. $plugin_guids = array($plugin_guids);
  16. }
  17. $activated_guids = array();
  18. foreach ($plugin_guids as $guid) {
  19. $plugin = get_entity($guid);
  20. if (!($plugin instanceof ElggPlugin)) {
  21. register_error(elgg_echo('admin:plugins:activate:no', array($guid)));
  22. continue;
  23. }
  24. if ($plugin->activate()) {
  25. $activated_guids[] = $guid;
  26. $ids = array(
  27. 'cannot_start' . $plugin->getID(),
  28. 'invalid_and_deactivated_' . $plugin->getID()
  29. );
  30. foreach ($ids as $id) {
  31. elgg_delete_admin_notice($id);
  32. }
  33. } else {
  34. $msg = $plugin->getError();
  35. $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no';
  36. register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError())));
  37. }
  38. }
  39. // don't regenerate the simplecache because the plugin won't be
  40. // loaded until next run. Just invalidate and let it regenerate as needed
  41. elgg_flush_caches();
  42. if (count($activated_guids) === 1) {
  43. $url = 'admin/plugins';
  44. $query = (string)parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY);
  45. if ($query) {
  46. $url .= "?$query";
  47. }
  48. $plugin = get_entity($plugin_guids[0]);
  49. $id = $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID());
  50. forward("$url#$id");
  51. } else {
  52. // forward to top of page with a failure so remove any #foo
  53. $url = $_SERVER['HTTP_REFERER'];
  54. if (strpos($url, '#')) {
  55. $url = substr(0, strpos($url, '#'));
  56. }
  57. forward($url);
  58. }