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 blog objects |
||
4 | * |
||
5 | * @package Blog |
||
6 | */ |
||
7 | |||
8 | $full = elgg_extract('full_view', $vars, false); |
||
9 | $blog = elgg_extract('entity', $vars, false); |
||
10 | |||
11 | if (!$blog) { |
||
12 | return true; |
||
13 | } |
||
14 | |||
15 | $owner = $blog->getOwnerEntity(); |
||
16 | $categories = elgg_view('output/categories', $vars); |
||
17 | $excerpt = $blog->excerpt; |
||
18 | if (!$excerpt) { |
||
19 | $excerpt = elgg_get_excerpt($blog->description); |
||
20 | } |
||
21 | |||
22 | $owner_icon = elgg_view_entity_icon($owner, 'tiny'); |
||
23 | |||
24 | $by_line = elgg_view('object/elements/imprint', $vars); |
||
25 | |||
26 | // The "on" status changes for comments, so best to check for !Off |
||
27 | if ($blog->comments_on != 'Off') { |
||
28 | $comments_count = $blog->countComments(); |
||
29 | //only display if there are commments |
||
30 | View Code Duplication | if ($comments_count != 0) { |
|
31 | $text = elgg_echo("comments") . " ($comments_count)"; |
||
32 | $comments_link = elgg_view('output/url', [ |
||
33 | 'href' => $blog->getURL() . '#comments', |
||
34 | 'text' => $text, |
||
35 | 'is_trusted' => true, |
||
36 | ]); |
||
37 | } else { |
||
38 | $comments_link = ''; |
||
39 | } |
||
40 | } else { |
||
41 | $comments_link = ''; |
||
42 | } |
||
43 | |||
44 | $subtitle = "$by_line $comments_link $categories"; |
||
45 | |||
46 | $metadata = ''; |
||
47 | View Code Duplication | if (!elgg_in_context('widgets')) { |
|
1 ignored issue
–
show
|
|||
48 | // only show entity menu outside of widgets |
||
49 | $metadata = elgg_view_menu('entity', [ |
||
50 | 'entity' => $vars['entity'], |
||
51 | 'handler' => 'blog', |
||
52 | 'sort_by' => 'priority', |
||
53 | 'class' => 'elgg-menu-hz', |
||
54 | ]); |
||
55 | } |
||
56 | |||
57 | if ($full) { |
||
58 | $body = elgg_view('output/longtext', [ |
||
59 | 'value' => $blog->description, |
||
60 | 'class' => 'blog-post', |
||
61 | ]); |
||
62 | |||
63 | $params = [ |
||
64 | 'entity' => $blog, |
||
65 | 'title' => false, |
||
66 | 'metadata' => $metadata, |
||
67 | 'subtitle' => $subtitle, |
||
68 | ]; |
||
69 | $params = $params + $vars; |
||
70 | $summary = elgg_view('object/elements/summary', $params); |
||
71 | |||
72 | $responses = ''; |
||
73 | if (elgg_extract('show_responses', $vars, false)) { |
||
74 | // check to see if we should allow comments |
||
75 | if ($blog->comments_on != 'Off' && $blog->status == 'published') { |
||
76 | $responses = elgg_view_comments($blog); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | echo elgg_view('object/elements/full', [ |
||
81 | 'entity' => $blog, |
||
82 | 'summary' => $summary, |
||
83 | 'icon' => $owner_icon, |
||
84 | 'body' => $body, |
||
85 | 'responses' => $responses, |
||
86 | 'show_navigation' => true, |
||
87 | ]); |
||
88 | } else { |
||
89 | // brief view |
||
90 | |||
91 | $params = [ |
||
92 | 'entity' => $blog, |
||
93 | 'metadata' => $metadata, |
||
94 | 'subtitle' => $subtitle, |
||
95 | 'content' => $excerpt, |
||
96 | 'icon' => $owner_icon, |
||
97 | ]; |
||
98 | $params = $params + $vars; |
||
99 | echo elgg_view('object/elements/summary', $params); |
||
100 | } |
||
101 |
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.