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

views/default/object/plugin/details.php (4 issues)

1
<?php
2
3
$guid = (int) get_input("guid");
4
5
if (empty($guid)) {
6
	return;
7
}
8
9
$plugin = get_entity($guid);
10
if (!$plugin instanceof ElggPlugin) {
11
	return;
12
}
13
14
$show_dependencies = false;
15
$package = $plugin->getPackage();
16
if ($package && !$package->checkDependencies()) {
17
	$show_dependencies = true;
18
}
19
20
$screenshots_menu = '';
21
$screenshots_body = '';
22
$screenshots = $plugin->getManifest()->getScreenshots();
23
if ($screenshots) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $screenshots of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
24
	foreach ($screenshots as $key => $screenshot) {
25
		$state = "";
26
		$rel = "elgg-plugin-details-screenshot-" . $key;
27
		if ($key == 0) {
28
			$state = " elgg-state-selected";
29
		}
30
		
31
		$desc = elgg_echo($screenshot['description']);
32
		$alt = htmlentities($desc, ENT_QUOTES, 'UTF-8');
33
		
34
		$thumbnail = elgg_view('output/img', [
35
			'src' => "mod/{$plugin->getID()}/{$screenshot['path']}",
36
			'alt' => $alt
37
		]);
38
		$attr = [
39
			'rel' => $rel,
40
			'class' => "elgg-plugin-screenshot pas $state",
41
			'title' => $alt
42
		];
43
		$screenshots_menu .= elgg_format_element('li', $attr, $thumbnail);
44
		
45
		$screenshots_body .= elgg_view('output/img', [
46
			'src' => "mod/{$plugin->getID()}/{$screenshot['path']}",
47
			'alt' => $alt,
48
			'title' => $alt,
49
			'class' => "hidden $state",
50
			'rel' => $rel
51
		]);
52
	}
53
	
54
	$screenshots_menu = elgg_format_element('ul', [], $screenshots_menu);
55
	$screenshots_body = elgg_format_element('div', [], $screenshots_body);
56
}
57
58
// table contents
59
$info = [];
60
61
$info[elgg_echo('admin:plugins:label:version')] = htmlspecialchars($plugin->getManifest()->getVersion());
62
63
$info[elgg_echo('admin:plugins:label:id')] = elgg_view('output/text', [
64
	'value' => $plugin->getID(),
65
]);
66
67
$info[elgg_echo('admin:plugins:label:author')] = elgg_view('output/text', [
68
	'value' => $plugin->getManifest()->getAuthor(),
69
]);
70
71
$url = $plugin->getManifest()->getWebsite();
72
if ($url) {
73
	$info[elgg_echo('admin:plugins:label:website')] = elgg_view('output/url', [
74
		'href' => $plugin->getManifest()->getWebsite(),
75
		'text' => $plugin->getManifest()->getWebsite(),
76
		'is_trusted' => true,
77
	]);
78
}
79
80
$info[elgg_echo('admin:plugins:label:copyright')] = elgg_view('output/text', [
81
	'value' => $plugin->getManifest()->getCopyright(),
82
]);
83
84
$info[elgg_echo('admin:plugins:label:licence')] = elgg_view('output/text', [
85
	'value' => $plugin->getManifest()->getLicense(),
86
]);
87
88
$site_path = elgg_get_root_path();
89
$path = $plugin->getPath();
90
if (0 === strpos($path, $site_path)) {
91
	$path = substr($path, strlen($site_path));
92
}
93
$info[elgg_echo('admin:plugins:label:location')] = htmlspecialchars($path);
94
95
$categories = (array) $plugin->getManifest()->getCategories();
96
array_walk($categories, function(&$value) {
97
	$value = htmlspecialchars(ElggPluginManifest::getFriendlyCategory($value));
98
});
99
100
$info[elgg_echo('admin:plugins:label:categories')] = implode(', ', $categories);
101
102
// assemble table
103
$rows = '';
104
foreach ($info as $name => $value) {
105
	if (trim($value) === '') {
106
		continue;
107
	}
108
	$rows .= "<tr><th>$name</th><td>$value</td></tr>";
109
}
110
111
$info_html = elgg_format_element('table', ['class' => 'elgg-table'], $rows);
112
113
$extra_info = elgg_echo("admin:plugins:info:" . $plugin->getID());
114
if ($extra_info !== ("admin:plugins:info:" . $plugin->getID())) {
115
	$info_html .= "<div class='mtm'>" . $extra_info . "</div>";
116
}
117
118
$resources = [
119
	'repository' => $plugin->getManifest()->getRepositoryURL(),
120
	'bugtracker' => $plugin->getManifest()->getBugTrackerURL(),
121
	'donate' => $plugin->getManifest()->getDonationsPageURL(),
122
];
123
124
$resources_html = '';
125
foreach ($resources as $id => $href) {
126
	if ($href) {
127
		$resources_html .= "<li>";
128
		$resources_html .= elgg_view('output/url', [
129
				'href' => $href,
130
				'text' => elgg_echo("admin:plugins:label:$id"),
131
				'is_trusted' => true,
132
		]);
133
		$resources_html .= "</li>";
134
	}
135
}
136
137
if (!empty($resources_html)) {
138
	$resources_html = elgg_format_element('ul', [], $resources_html);
139
}
140
141
// show links to text files
142
$files = $plugin->getAvailableTextFiles();
143
144
$files_html = '';
145
if ($files) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $files of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
146
	$files_html = '<ul>';
147
	foreach ($files as $file => $path) {
148
		$url = 'admin_plugin_text_file/' . $plugin->getID() . "/$file";
149
		$link = elgg_view('output/url', [
150
				'text' => $file,
151
				'href' => $url,
152
				'is_trusted' => true,
153
		]);
154
		$files_html .= "<li>$link</li>";
155
	}
156
	$files_html .= '</ul>';
157
}
158
159
$body = "<div class='elgg-plugin'>";
160
161
$body .= "<div class='elgg-plugin-details-container pvm'>";
162
163
$body .= elgg_view('output/longtext', ['value' => $plugin->getManifest()->getDescription()]);
164
165
// tabs
166
$tabs = [];
167
168
$tabs[] = [
169
	'text' => elgg_echo("admin:plugins:label:info"),
170
	'rel' => 'elgg-plugin-details-info',
171
	'selected' => !$show_dependencies,
172
];
173
174
if ($resources_html) {
175
	$tabs[] = [
176
		'text' => elgg_echo("admin:plugins:label:resources"),
177
		'rel' => 'elgg-plugin-details-resources'
178
	];
179
}
180
181
if ($files_html) {
182
	$tabs[] = [
183
		'text' => elgg_echo("admin:plugins:label:files"),
184
		'rel' => 'elgg-plugin-details-files'
185
	];
186
}
187
188
if ($screenshots) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $screenshots of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
189
	$tabs[] = [
190
		'text' => elgg_echo("admin:plugins:label:screenshots"),
191
		'rel' => 'elgg-plugin-details-screenshots'
192
	];
193
}
194
195
$tabs[] = [
196
	'text' => elgg_echo("admin:plugins:label:dependencies"),
197
	'rel' => 'elgg-plugin-details-dependencies',
198
	'selected' => $show_dependencies,
199
];
200
201
$body .= elgg_view('navigation/tabs', [
202
	'tabs' => $tabs,
203
	'class' => 'mtl',
204
]);
205
206
$body .= "<div>";
207
208
// info
209
if (!$show_dependencies) {
210
	$body .= "<div class='elgg-plugin-details-info'>";
211
} else {
212
	$body .= "<div class='elgg-plugin-details-info hidden'>";
213
}
214
$body .= $info_html;
215
$body .= "</div>";
216
217
// resources
218
if ($resources_html) {
219
	$body .= "<div class='elgg-plugin-details-resources hidden'>";
220
	$body .= $resources_html;
221
	$body .= "</div>";
222
}
223
224
// files
225
if ($files_html) {
226
	$body .= "<div class='elgg-plugin-details-files hidden'>";
227
	$body .= $files_html;
228
	$body .= "</div>";
229
}
230
231
// screenshots
232
if ($screenshots) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $screenshots of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
233
	$body .= "<div class='elgg-plugin-details-screenshots hidden'>";
234
	$body .= $screenshots_menu;
235
	$body .= $screenshots_body;
236
	$body .= "</div>";
237
}
238
239
// dependencies
240
if (!$show_dependencies) {
241
	$body .= "<div class='elgg-plugin-details-dependencies hidden'>";
242
} else {
243
	$body .= "<div class='elgg-plugin-details-dependencies'>";
244
}
245
$body .= elgg_view('object/plugin/elements/dependencies', ['plugin' => $plugin]);
246
$body .= "</div>";
247
248
$body .= "</div>";
249
250
$body .= "</div>";
251
252
$body .= "</div>";
253
254
echo elgg_view_module("plugin-details", $plugin->getDisplayName(), $body);
255