implicit conversion of array to boolean.
1 | <?php |
||
2 | /** |
||
3 | * Blog sidebar menu showing revisions |
||
4 | * |
||
5 | * @package Blog |
||
6 | */ |
||
7 | |||
8 | //If editing a post, show the previous revisions and drafts. |
||
9 | $blog = elgg_extract('entity', $vars, false); |
||
10 | |||
11 | if (!$blog instanceof ElggBlog) { |
||
12 | return; |
||
13 | } |
||
14 | |||
15 | if (!$blog->canEdit()) { |
||
16 | return; |
||
17 | } |
||
18 | |||
19 | $owner = $blog->getOwnerEntity(); |
||
20 | $revisions = []; |
||
21 | |||
22 | $auto_save_annotations = $blog->getAnnotations([ |
||
23 | 'annotation_name' => 'blog_auto_save', |
||
24 | 'limit' => 1, |
||
25 | ]); |
||
26 | if ($auto_save_annotations) { |
||
0 ignored issues
–
show
|
|||
27 | $revisions[] = $auto_save_annotations[0]; |
||
28 | } |
||
29 | |||
30 | $saved_revisions = $blog->getAnnotations([ |
||
31 | 'annotation_name' => 'blog_revision', |
||
32 | 'order_by' => 'n_table.time_created desc, n_table.id desc', |
||
33 | 'limit' => false |
||
34 | ]); |
||
35 | |||
36 | $revisions = array_merge($revisions, $saved_revisions); |
||
37 | /* @var ElggAnnotation[] $revisions */ |
||
38 | |||
39 | if (empty($revisions)) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | $load_base_url = elgg_generate_url('edit:object:blog', [ |
||
44 | 'guid' => $blog->guid, |
||
45 | ]); |
||
46 | |||
47 | // show the "published revision" |
||
48 | $published_item = ''; |
||
49 | if ($blog->status == 'published') { |
||
50 | $load = elgg_view('output/url', [ |
||
51 | 'href' => $load_base_url, |
||
52 | 'text' => elgg_echo('status:published'), |
||
53 | 'is_trusted' => true, |
||
54 | ]); |
||
55 | |||
56 | $time = elgg_format_element('span', ['class' => 'elgg-subtext'], elgg_view_friendly_time($blog->time_created)); |
||
57 | $published_item = elgg_format_element('li', [], "$load: $time"); |
||
58 | } |
||
59 | |||
60 | $n = count($revisions); |
||
61 | $revisions_list = ''; |
||
62 | foreach ($revisions as $revision) { |
||
63 | $time = elgg_format_element('span', ['class' => 'elgg-subtext'], elgg_view_friendly_time($revision->time_created)); |
||
64 | |||
65 | if ($revision->name == 'blog_auto_save') { |
||
66 | $revision_lang = elgg_echo('blog:auto_saved_revision'); |
||
67 | } else { |
||
68 | $revision_lang = elgg_echo('blog:revision') . " $n"; |
||
69 | } |
||
70 | |||
71 | $load = elgg_view('output/url', [ |
||
72 | 'href' => "$load_base_url/$revision->id", |
||
73 | 'text' => $revision_lang, |
||
74 | 'is_trusted' => true, |
||
75 | ]); |
||
76 | |||
77 | $revisions_list .= elgg_format_element('li', ['class' => 'auto-saved'], "$load: $time"); |
||
78 | |||
79 | $n--; |
||
80 | } |
||
81 | |||
82 | $body = elgg_format_element('ul', ['class' => 'blog-revisions'], $published_item . $revisions_list); |
||
83 | |||
84 | echo elgg_view_module('aside', elgg_echo('blog:revisions'), $body); |
||
85 |
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.