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

mod/pages/views/default/object/page.php (1 issue)

1
<?php
2
/**
3
 * View for page object
4
 *
5
 * @uses $vars['entity']    The page object
6
 * @uses $vars['full_view'] Whether to display the full view
7
 * @uses $vars['revision']  This parameter not supported by elgg_view_entity()
8
 */
9
10
$full = elgg_extract('full_view', $vars, false);
11
$page = elgg_extract('entity', $vars, false);
12
$revision = elgg_extract('revision', $vars, false);
13
14
if (!$page instanceof ElggPage) {
15
	return;
16
}
17
18
// pages used to use Public for write access
19
if ($page->write_access_id == ACCESS_PUBLIC) {
20
	// this works because this metadata is public
21
	$page->write_access_id = ACCESS_LOGGED_IN;
22
}
23
24
if ($revision) {
25
	$annotation = $revision;
26
} else {
27
	$annotation = $page->getAnnotations([
28
		'annotation_name' => 'page',
29
		'limit' => 1,
30
		'order_by' => 'n_table.time_created desc, n_table.id desc',
31
	]);
32
	if ($annotation) {
0 ignored issues
show
Bug Best Practice introduced by Jerôme Bakker
The expression $annotation 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...
33
		$annotation = $annotation[0];
34
	} else {
35
		elgg_log("Failed to access annotation for page with GUID {$page->guid}", 'WARNING');
36
		return;
37
	}
38
}
39
40
$owner = $annotation->getOwnerEntity();
41
$owner_icon = elgg_view_entity_icon($owner, 'small');
42
43
$metadata = null;
44
// If we're looking at a revision, display annotation menu
45
if ($revision) {
46
	$metadata = elgg_view_menu('annotation', [
47
		'annotation' => $annotation,
48
		'sort_by' => 'priority',
49
		'class' => 'elgg-menu-hz float-alt',
50
	]);
51
}
52
53
if ($full) {
54
	$body = elgg_view('output/longtext', ['value' => $annotation->value]);
55
56
	$params = [
57
		'entity' => $page,
58
		'metadata' => $metadata,
59
		'handler' => 'pages',
60
		'title' => false,
61
	];
62
63
	$params = $params + $vars;
64
	$summary = elgg_view('object/elements/summary', $params);
65
66
	echo elgg_view('object/elements/full', [
67
		'entity' => $page,
68
		'icon' => $owner_icon,
69
		'summary' => $summary,
70
		'body' => $body,
71
		'show_responses' => elgg_extract('show_responses', $vars, false),
72
	]);
73
} else {
74
	// brief view
75
	$params = [
76
		'entity' => $page,
77
		'metadata' => $metadata,
78
		'handler' => 'pages',
79
		'content' => elgg_get_excerpt($page->description),
80
		'icon' => $owner_icon,
81
	];
82
	$params = $params + $vars;
83
	echo elgg_view('object/elements/summary', $params);
84
}
85