Elgg  Version master
full.php
Go to the documentation of this file.
1 <?php
11  return;
12 }
13 
14 $plugin = elgg_extract('entity', $vars);
15 if (!$plugin instanceof \ElggPlugin) {
16  return;
17 }
18 
19 $reordering = elgg_extract('display_reordering', $vars, false);
20 $active = $plugin->isActive();
21 
22 $classes = ['elgg-plugin'];
23 $classes[] = $reordering ? 'elgg-state-draggable' : 'elgg-state-undraggable';
24 
25 $error = '';
26 if ($active) {
27  $can_activate = false;
28  try {
29  $plugin->assertCanDeactivate();
30  $can_deactivate = true;
31  } catch (\Elgg\Exceptions\PluginException $e) {
32  $error = $e->getMessage();
33  $can_deactivate = false;
34  }
35 } else {
36  $can_deactivate = false;
37  try {
38  $plugin->assertCanActivate();
39  $can_activate = true;
40  } catch (\Elgg\Exceptions\PluginException $e) {
41  $error = $e->getMessage();
42  $can_activate = false;
43  }
44 }
45 
46 // activate / deactivate button
48  'href' => false,
49 ];
50 
51 if ($active) {
52  $classes[] = 'elgg-state-active';
53 
54  $options['title'] = elgg_echo('admin:plugins:deactivate');
55  $options['text'] = elgg_echo('admin:plugins:deactivate');
56  if ($can_deactivate) {
57  $options['href'] = elgg_generate_action_url('admin/plugins/deactivate', ['plugin_guids[]' => $plugin->guid]);
58  $options['class'] = 'elgg-button elgg-button-cancel elgg-plugin-state-change';
59  } else {
60  $classes[] = 'elgg-state-cannot-deactivate';
61 
62  $options['title'] = elgg_echo('admin:plugins:cannot_deactivate');
63  $options['class'] = 'elgg-button elgg-button-cancel elgg-state-disabled';
64  }
65 } else if ($can_activate) {
66  $classes[] = 'elgg-state-inactive';
67 
68  $options['href'] = elgg_generate_action_url('admin/plugins/activate', ['plugin_guids[]' => $plugin->guid]);
69  $options['title'] = elgg_echo('admin:plugins:activate');
70  $options['class'] = 'elgg-button elgg-button-submit elgg-plugin-state-change';
71  $options['text'] = elgg_echo('admin:plugins:activate');
72 } else {
73  $classes[] = 'elgg-state-inactive';
74  $classes[] = 'elgg-state-cannot-activate';
75 
76  $options['title'] = elgg_echo('admin:plugins:cannot_activate');
77  $options['class'] = 'elgg-button elgg-button-submit elgg-state-disabled';
78  $options['text'] = elgg_echo('admin:plugins:activate');
79 }
80 
81 $action_button = elgg_trigger_event_results('action_button', 'plugin', ['entity' => $plugin], elgg_view('output/url', $options));
82 
83 // Display categories and make category classes
84 $categories = array_keys($plugin->getCategories());
85 
86 $categories[] = 'all';
87 $categories[] = $active ? 'active' : 'inactive';
88 
89 if (!in_array('bundled', $categories)) {
90  $categories[] = 'nonbundled';
91 }
92 
93 $categories = array_map('strtolower', $categories);
94 
95 $style = null;
96 if (!in_array(elgg_extract('active_filter', $vars), $categories)) {
97  $style = 'display: none;';
98 }
99 
100 foreach ($categories as $category) {
101  $css_class = preg_replace('/[^a-z0-9-]/i', '-', $category);
102  $classes[] = "elgg-plugin-category-{$css_class}";
103 }
104 
105 $title = elgg_view('output/url', [
106  'href' => "ajax/view/object/plugin/details?guid={$plugin->guid}",
107  'text' => $plugin->getDisplayName(),
108  'class' => 'elgg-lightbox',
109 ]);
110 
111 $content = '';
112 
113 if ($error) {
114  $type = $active ? 'notice' : 'error';
115 
116  $content .= elgg_view_message($type, $error, ['title' => false, 'class' => 'elgg-subtext']);
117 }
118 
119 echo elgg_view('object/elements/summary', [
120  'entity' => $plugin,
121  'class' => $classes,
122  'image_block_vars' => [
123  'style' => $style,
124  'id' => preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID()),
125  ],
126  'data-guid' => $plugin->guid,
127  'icon' => $action_button,
128  'title' => $title,
129  'subtitle' => elgg_view('output/longtext', [
130  'value' => $plugin->getDescription(),
131  ]),
132  'content' => $content,
133  'display_reordering' => $reordering,
134 ]);
$action_button
Definition: full.php:81
elgg_generate_action_url(string $action, array $query=[], bool $add_csrf_tokens=true)
Generate an action URL.
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:52
Plugin class containing helper functions for plugin activation/deactivation, dependency checking capa...
Definition: ElggPlugin.php:17
$categories
Definition: full.php:84
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!$plugin instanceof\ElggPlugin) $reordering
Definition: full.php:19
$type
Definition: delete.php:21
elgg_trigger_event_results(string $event, string $type, array $params=[], $returnvalue=null)
Triggers an event where it is expected that the mixed return value could be manipulated by event call...
Definition: events.php:117
$can_activate
Definition: full.php:39
if(!elgg_is_admin_logged_in()) $plugin
Displays a plugin.
Definition: full.php:14
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:254
elgg_view(string $view, array $vars=[], string $viewtype= '')
Return a parsed view.
Definition: views.php:156
if(!in_array(elgg_extract('active_filter', $vars), $categories)) foreach($categories as $category) $title
Definition: full.php:105
$content
Definition: full.php:25
$active
Definition: full.php:20
$classes
Definition: full.php:22
$error
Definition: full.php:25
$vars
Definition: theme.php:5
elgg_view_message(string $type, string $body, array $vars=[])
Wrapper function for the message display pattern.
Definition: views.php:940
$style
Definition: full.php:95
catch(\Elgg\Exceptions\PluginException $e) $options
Definition: full.php:47