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

mod/pages/views/default/object/page_top.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
 * View for page object
4
 *
5
 * @package ElggPages
6
 *
7
 * @uses $vars['entity']    The page object
8
 * @uses $vars['full_view'] Whether to display the full view
9
 * @uses $vars['revision']  This parameter not supported by elgg_view_entity()
10
 */
11
12
13
$full = elgg_extract('full_view', $vars, false);
14
$page = elgg_extract('entity', $vars, false);
15
$revision = elgg_extract('revision', $vars, false);
16
17
if (!$page) {
18
	return true;
19
}
20
21
// pages used to use Public for write access
22
if ($page->write_access_id == ACCESS_PUBLIC) {
23
	// this works because this metadata is public
24
	$page->write_access_id = ACCESS_LOGGED_IN;
25
}
26
27
28
if ($revision) {
29
	$annotation = $revision;
30
} else {
31
	$annotation = $page->getAnnotations([
32
		'annotation_name' => 'page',
33
		'limit' => 1,
34
		'reverse_order_by' => true,
35
	]);
36
	if ($annotation) {
37
		$annotation = $annotation[0];
38
	} else {
39
		elgg_log("Failed to access annotation for page with GUID {$page->guid}", 'WARNING');
40
		return;
41
	}
42
}
43
44
$page_icon = elgg_view('pages/icon', ['annotation' => $annotation, 'size' => 'small']);
45
46
$editor_text = elgg_view('object/elements/imprint', $vars);
47
$categories = elgg_view('output/categories', $vars);
48
49
$comments_count = $page->countComments();
50
//only display if there are commments
51 View Code Duplication
if ($comments_count != 0 && !$revision) {
52
	$text = elgg_echo("comments") . " ($comments_count)";
53
	$comments_link = elgg_view('output/url', [
54
		'href' => $page->getURL() . '#comments',
55
		'text' => $text,
56
		'is_trusted' => true,
57
	]);
58
} else {
59
	$comments_link = '';
60
}
61
62
$subtitle = "$editor_text $comments_link $categories";
63
64
$metadata = '';
65
// do not show the metadata and controls in widget view
66
if (!elgg_in_context('widgets')) {
67
	// If we're looking at a revision, display annotation menu
68
	if ($revision) {
69
		$metadata = elgg_view_menu('annotation', [
70
			'annotation' => $annotation,
71
			'sort_by' => 'priority',
72
			'class' => 'elgg-menu-hz float-alt',
73
		]);
74 View Code Duplication
	} else {
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...
75
		// Regular entity menu
76
		$metadata = elgg_view_menu('entity', [
77
			'entity' => $vars['entity'],
78
			'handler' => 'pages',
79
			'sort_by' => 'priority',
80
			'class' => 'elgg-menu-hz',
81
		]);
82
	}
83
}
84
85
if ($full) {
86
	$body = elgg_view('output/longtext', ['value' => $annotation->value]);
87
88
	$params = [
89
		'entity' => $page,
90
		'metadata' => $metadata,
91
		'title' => false,
92
		'subtitle' => $subtitle,
93
	];
94
95
	$params = $params + $vars;
96
	$summary = elgg_view('object/elements/summary', $params);
97
98
	$responses = '';
99
	if (elgg_extract('show_responses', $vars, false)) {
100
		$responses = elgg_view_comments($page);
101
	}
102
103
	echo elgg_view('object/elements/full', [
104
		'entity' => $page,
105
		'icon' => $page_icon,
106
		'summary' => $summary,
107
		'body' => $body,
108
		'responses' => $responses,
109
	]);
110 View Code Duplication
} else {
111
	// brief view
112
113
	$excerpt = elgg_get_excerpt($page->description);
114
115
	$params = [
116
		'entity' => $page,
117
		'metadata' => $metadata,
118
		'subtitle' => $subtitle,
119
		'content' => $excerpt,
120
		'icon' => $page_icon,
121
	];
122
	$params = $params + $vars;
123
	echo elgg_view('object/elements/summary', $params);
124
}
125