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 | |||
14 | $plugin_guids = get_input('plugin_guids'); |
||
15 | |||
16 | if (!is_array($plugin_guids)) { |
||
17 | $plugin_guids = array($plugin_guids); |
||
18 | } |
||
19 | |||
20 | $activated_guids = array(); |
||
21 | foreach ($plugin_guids as $guid) { |
||
22 | $plugin = get_entity($guid); |
||
23 | |||
24 | if (!($plugin instanceof ElggPlugin)) { |
||
25 | register_error(elgg_echo('admin:plugins:activate:no', array($guid))); |
||
26 | continue; |
||
27 | } |
||
28 | |||
29 | if ($plugin->activate()) { |
||
30 | $activated_guids[] = $guid; |
||
31 | $ids = array( |
||
32 | 'cannot_start' . $plugin->getID(), |
||
33 | 'invalid_and_deactivated_' . $plugin->getID() |
||
34 | ); |
||
35 | |||
36 | foreach ($ids as $id) { |
||
37 | elgg_delete_admin_notice($id); |
||
38 | } |
||
39 | |||
40 | } else { |
||
41 | $msg = $plugin->getError(); |
||
42 | $string = ($msg) ? 'admin:plugins:activate:no_with_msg' : 'admin:plugins:activate:no'; |
||
43 | register_error(elgg_echo($string, array($plugin->getFriendlyName(), $plugin->getError()))); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // don't regenerate the simplecache because the plugin won't be |
||
48 | // loaded until next run. Just invalidate and let it regenerate as needed |
||
49 | elgg_flush_caches(); |
||
50 | |||
51 | if (count($activated_guids) === 1) { |
||
52 | $url = 'admin/plugins'; |
||
53 | $query = (string)parse_url($_SERVER['HTTP_REFERER'], PHP_URL_QUERY); |
||
54 | if ($query) { |
||
55 | $url .= "?$query"; |
||
56 | } |
||
57 | $plugin = get_entity($plugin_guids[0]); |
||
58 | $id = $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()); |
||
59 | $url = "$url#id"; |
||
60 | return elgg_ok_response('', '', $url); |
||
61 | } else { |
||
62 | // forward to top of page with a failure so remove any #foo |
||
63 | $url = $_SERVER['HTTP_REFERER']; |
||
64 | if (strpos($url, '#')) { |
||
65 | $url = substr(0, strpos($url, '#')); |
||
66 | } |
||
67 | forward(elgg_normalize_site_url($url)); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
68 | } |
||
69 |