Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

views/default/object/plugin/full.php (1 issue)

loose comparison of strings.

Best Practice Bug Major
1
<?php
2
/**
3
 * Displays a plugin on the admin screen.
4
 *
5
 * This file renders a plugin for the admin screen, including active/deactive,
6
 * manifest details & display plugin settings.
7
 *
8
 * @uses $vars['entity']
9
 * @uses $vars['display_reordering'] Do we display the priority reordering links?
10
 *
11
 * @package Elgg.Core
12
 * @subpackage Plugins
13
 */
14
/* @var ElggPlugin $plugin */
15
$plugin = elgg_extract('entity', $vars);
16
$reordering = elgg_extract('display_reordering', $vars, false);
17
$priority = $plugin->getPriority();
18
$active = $plugin->isActive();
19
$plugin_id = $plugin->getID();
20
21
$actions_base = '/action/admin/plugins/';
22
23
// build reordering links
24
$links = '';
25
$classes = ['elgg-plugin'];
26
27
if ($reordering) {
28
	$max_priority = _elgg_get_max_plugin_priority();
29
	
30
	if ($active) {
31
		$can_activate = false;
32
		$can_deactivate = $plugin->canDeactivate();
33
	} else {
34
		$can_deactivate = false;
35
		$can_activate = $plugin->canActivate();
36
	}
37
38
	$classes[] = 'elgg-state-draggable';
39
40
	// top and up link only if not at top
41
	if ($priority > 1) {
42
		$top_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', [
43
			'plugin_guid' => $plugin->guid,
44
			'priority' => 'first',
45
			'is_action' => true
46
		]);
47
48
		$links .= "<li>" . elgg_view('output/url', [
49
			'href' => $top_url,
50
			'text' => elgg_echo('top'),
51
			'is_action' => true,
52
			'is_trusted' => true,
53
		]) . "</li>";
54
55
		$up_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', [
56
			'plugin_guid' => $plugin->guid,
57
			'priority' => '-1',
58
			'is_action' => true
59
		]);
60
61
		$links .= "<li>" . elgg_view('output/url', [
62
			'href' => $up_url,
63
			'text' => elgg_echo('up'),
64
			'is_action' => true,
65
			'is_trusted' => true,
66
		]) . "</li>";
67
	}
68
69
	// down and bottom links only if not at bottom
70
	if ($priority < $max_priority) {
71
		$down_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', [
72
			'plugin_guid' => $plugin->guid,
73
			'priority' => '+1',
74
			'is_action' => true
75
		]);
76
77
		$links .= "<li>" . elgg_view('output/url', [
78
			'href' => $down_url,
79
			'text' => elgg_echo('down'),
80
			'is_action' => true,
81
			'is_trusted' => true,
82
		]) . "</li>";
83
84
		$bottom_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', [
85
			'plugin_guid' => $plugin->guid,
86
			'priority' => 'last',
87
			'is_action' => true
88
		]);
89
90
		$links .= "<li>" . elgg_view('output/url', [
91
			'href' => $bottom_url,
92
			'text' => elgg_echo('bottom'),
93
			'is_action' => true,
94
			'is_trusted' => true,
95
		]) . "</li>";
96
	}
97
98
	if ($links) {
99
		$links = '<ul class="elgg-menu elgg-plugin-list-reordering">' . $links . '</ul>';
100
	}
101
} else {
102
	$classes[] = 'elgg-state-undraggable';
103
}
104
105
// activate / deactivate links
106
// always let them deactivate
107
$options = [
108
	'is_action' => true,
109
	'is_trusted' => true,
110
];
111
$action = false;
112
if ($active) {
113
	$classes[] = 'elgg-state-active';
114
	$options['title'] = elgg_echo('admin:plugins:deactivate');
115
	$options['text'] = elgg_echo('admin:plugins:deactivate');
116
	if ($can_deactivate) {
117
		$action = 'deactivate';
118
		$options['class'] = 'elgg-button elgg-button-cancel elgg-plugin-state-change';
119
	} else {
120
		$classes[] = 'elgg-state-cannot-deactivate';
121
		$options['title'] = elgg_echo('admin:plugins:cannot_deactivate');
122
		$options['class'] = 'elgg-button elgg-button-cancel elgg-state-disabled';
123
		$options['disabled'] = 'disabled';
124
	}
125
} else if ($can_activate) {
126
	$classes[] = 'elgg-state-inactive';
127
	$action = 'activate';
128
	$options['title'] = elgg_echo('admin:plugins:activate');
129
	$options['class'] = 'elgg-button elgg-button-submit elgg-plugin-state-change';
130
	$options['text'] = elgg_echo('admin:plugins:activate');
131
} else {
132
	$classes[] = 'elgg-state-inactive elgg-state-cannot-activate';
133
	$options['title'] = elgg_echo('admin:plugins:cannot_activate');
134
	$options['class'] = 'elgg-button elgg-button-submit elgg-state-disabled';
135
	$options['text'] = elgg_echo('admin:plugins:activate');
136
	$options['disabled'] = 'disabled';
137
}
138
139
if ($action) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $action of type false|string is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== false instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
140
	$options['href'] = elgg_http_add_url_query_elements($actions_base . $action, [
141
		'plugin_guids[]' => $plugin->guid
142
	]);
143
}
144
145
$action_button = elgg_view('output/url', $options);
146
147
$action_button = elgg_trigger_plugin_hook("action_button", "plugin", ["entity" => $plugin], $action_button);
148
149
// Display categories and make category classes
150
$categories = $plugin->getManifest()->getCategories();
151
152
$categories[] = 'all';
153
$categories[] = $active ? 'active' : 'inactive';
154
155
if (!in_array('bundled', $categories)) {
156
	$categories[] = 'nonbundled';
157
}
158
159
foreach ($categories as $category) {
160
	$css_class = preg_replace('/[^a-z0-9-]/i', '-', $category);
161
	$classes[] = "elgg-plugin-category-$css_class";
162
}
163
164
$body = elgg_view('output/url', [
165
	'href' => "ajax/view/object/plugin/details?guid={$plugin->getGUID()}",
166
	'text' => $plugin->getDisplayName(),
167
	'class' => 'elgg-lightbox elgg-plugin-title',
168
]);
169
170
if (elgg_view_exists("plugins/{$plugin_id}/settings")) {
171
	$body .= elgg_view('output/url', [
172
		'href' => "admin/plugin_settings/{$plugin_id}",
173
		'title' => elgg_echo('settings'),
174
		'text' => elgg_view_icon('settings-alt'),
175
		'class' => 'elgg-plugin-settings',
176
	]);
177
}
178
179
$description = elgg_view('output/longtext', ['value' => $plugin->getManifest()->getDescription()]);
180
$body .= elgg_format_element('span', [
181
	'class' => 'elgg-plugin-list-description',
182
], $description);
183
	
184
$error = $plugin->getError();
185
if ($error) {
186
	$message = elgg_format_element('p', [
187
		'class' => $active ? 'elgg-text-help' : 'elgg-text-help elgg-state-error',
188
	], $error);
189
	
190
	$body .= "<div>$message</div>";
191
}
192
193
$result = elgg_view_image_block($action_button, $links . $body);
194
echo elgg_format_element('div', [
195
	'class' => $classes,
196
	'id' => preg_replace('/[^a-z0-9-]/i', '-', $plugin_id),
197
	'data-guid' => $plugin->guid,
198
], $result);
199