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

mod/bookmarks/views/default/object/bookmarks.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
 * Elgg bookmark view
4
 *
5
 * @package ElggBookmarks
6
 */
7
8
$full = elgg_extract('full_view', $vars, false);
9
$bookmark = elgg_extract('entity', $vars, false);
10
11
if (!$bookmark) {
12
	return;
13
}
14
15
$owner = $bookmark->getOwnerEntity();
16
$owner_icon = elgg_view_entity_icon($owner, 'tiny');
17
$categories = elgg_view('output/categories', $vars);
18
19
$link = elgg_view('output/url', ['href' => $bookmark->address]);
20
$description = elgg_view('output/longtext', ['value' => $bookmark->description, 'class' => 'pbl']);
21
22
$by_line = elgg_view('object/elements/imprint', $vars);
23
24
$comments_count = $bookmark->countComments();
25
//only display if there are commments
26 View Code Duplication
if ($comments_count != 0) {
27
	$text = elgg_echo("comments") . " ($comments_count)";
28
	$comments_link = elgg_view('output/url', [
29
		'href' => $bookmark->getURL() . '#comments',
30
		'text' => $text,
31
		'is_trusted' => true,
32
	]);
33
} else {
34
	$comments_link = '';
35
}
36
37
$subtitle = "$by_line $comments_link $categories";
38
39
$metadata = '';
40 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...
41
	// only show entity menu outside of widgets and gallery view
42
	$metadata = elgg_view_menu('entity', [
43
		'entity' => $vars['entity'],
44
		'handler' => 'bookmarks',
45
		'sort_by' => 'priority',
46
		'class' => 'elgg-menu-hz',
47
	]);
48
}
49
50
if ($full && !elgg_in_context('gallery')) {
51
	$params = [
52
		'entity' => $bookmark,
53
		'title' => false,
54
		'metadata' => $metadata,
55
		'subtitle' => $subtitle,
56
	];
57
	$params = $params + $vars;
58
	$summary = elgg_view('object/elements/summary', $params);
59
60
	$bookmark_icon = elgg_view_icon('push-pin-alt');
61
	$body = <<<HTML
62
<div class="bookmark elgg-content mts">
63
	$bookmark_icon<span class="elgg-heading-basic mbs">$link</span>
64
	$description
65
</div>
66
HTML;
67
68
	$responses = '';
69
	if (elgg_extract('show_responses', $vars, false)) {
70
		$responses = elgg_view_comments($bookmark);
71
	}
72
	echo elgg_view('object/elements/full', [
73
		'entity' => $bookmark,
74
		'icon' => $owner_icon,
75
		'summary' => $summary,
76
		'body' => $body,
77
		'responses' => $responses,
78
		'show_navigation' => true,
79
	]);
80
} elseif (elgg_in_context('gallery')) {
81
	echo <<<HTML
82
<div class="bookmarks-gallery-item">
83
	<h3>$bookmark->title</h3>
84
	<p class='subtitle'>$owner_link $date</p>
85
</div>
86
HTML;
87
} else {
88
	// brief view
89
	$url = $bookmark->address;
90
	$display_text = $url;
91
	$excerpt = elgg_get_excerpt($bookmark->description);
92
	if ($excerpt) {
93
		$excerpt = " - $excerpt";
94
	}
95
96
	if (strlen($url) > 25) {
97
		$bits = parse_url($url);
98
		if (isset($bits['host'])) {
99
			$display_text = $bits['host'];
100
		} else {
101
			$display_text = elgg_get_excerpt($url, 100);
102
		}
103
	}
104
105
	$link = elgg_view('output/url', [
106
		'href' => $bookmark->address,
107
		'text' => $display_text,
108
	]);
109
110
	$content = elgg_view_icon('push-pin-alt') . "$link{$excerpt}";
111
112
	$params = [
113
		'entity' => $bookmark,
114
		'metadata' => $metadata,
115
		'subtitle' => $subtitle,
116
		'content' => $content,
117
		'icon' => $owner_icon,
118
	];
119
	$params = $params + $vars;
120
	echo elgg_view('object/elements/summary', $params);
121
}
122