Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

mod/file/views/default/object/file.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * File renderer.
4
 *
5
 * @package ElggFile
6
 */
7
8
$full = elgg_extract('full_view', $vars, false);
9
$file = elgg_extract('entity', $vars, false);
10
11
if (!$file) {
12
	return true;
13
}
14
15
$owner = $file->getOwnerEntity();
16
$categories = elgg_view('output/categories', $vars);
17
18
$by_line = elgg_view('object/elements/imprint', $vars);
19
20
$comments_count = $file->countComments();
21
//only display if there are commments
22 View Code Duplication
if ($comments_count != 0) {
23
	$text = elgg_echo("comments") . " ($comments_count)";
24
	$comments_link = elgg_view('output/url', [
25
		'href' => $file->getURL() . '#comments',
26
		'text' => $text,
27
		'is_trusted' => true,
28
	]);
29
} else {
30
	$comments_link = '';
31
}
32
33
$subtitle = "$by_line $comments_link $categories";
34
35
$metadata = '';
36 View Code Duplication
if (!elgg_in_context('widgets') && !elgg_in_context('gallery')) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
	// only show entity menu outside of widgets and gallery view
38
	$metadata = elgg_view_menu('entity', [
39
		'entity' => $vars['entity'],
40
		'handler' => 'file',
41
		'sort_by' => 'priority',
42
		'class' => 'elgg-menu-hz',
43
	]);
44
}
45
46
if ($full && !elgg_in_context('gallery')) {
47
	$mime = $file->getMimeType();
48
	$base_type = substr($mime, 0, strpos($mime, '/'));
49
50
	$extra = '';
51
	if (elgg_view_exists("file/specialcontent/$mime")) {
52
		$extra = elgg_view("file/specialcontent/$mime", $vars);
53
	} else if (elgg_view_exists("file/specialcontent/$base_type/default")) {
54
		$extra = elgg_view("file/specialcontent/$base_type/default", $vars);
55
	}
56
57
	$params = [
58
		'entity' => $file,
59
		'title' => false,
60
		'metadata' => $metadata,
61
		'subtitle' => $subtitle,
62
	];
63
	$params = $params + $vars;
64
	$summary = elgg_view('object/elements/summary', $params);
65
66
	$body = elgg_view('output/longtext', ['value' => $file->description]);
67
68
	$owner_icon = elgg_view_entity_icon($owner, 'small');
69
70
	$responses = '';
71
	if (elgg_extract('show_responses', $vars, false)) {
72
		$responses = elgg_view_comments($file);
73
	}
74
75
	echo elgg_view('object/elements/full', [
76
		'entity' => $file,
77
		'icon' => $owner_icon,
78
		'summary' => $summary,
79
		'body' => $body,
80
		'attachments' => $extra,
81
		'responses' => $responses,
82
		'show_navigation' => true,
83
	]);
84
} elseif (elgg_in_context('gallery')) {
85
	echo '<div class="file-gallery-item">';
86
	echo "<h3>" . $file->title . "</h3>";
87
	echo elgg_view_entity_icon($file, 'medium');
88
	echo "<p class='subtitle'>$owner_link $date</p>";
89
	echo '</div>';
90
} else {
91
	// brief view
92
	$excerpt = elgg_get_excerpt($file->description);
93
94
	$file_icon = elgg_view_entity_icon($file, 'small');
95
96
	$params = [
97
		'entity' => $file,
98
		'metadata' => $metadata,
99
		'subtitle' => $subtitle,
100
		'content' => $excerpt,
101
		'icon' => $file_icon,
102
	];
103
	$params = $params + $vars;
104
	echo elgg_view('object/elements/summary', $params);
105
}
106