1 | <?php |
||||||||
2 | /** |
||||||||
3 | * Blogs |
||||||||
4 | * |
||||||||
5 | * @package Blog |
||||||||
6 | */ |
||||||||
7 | |||||||||
8 | /** |
||||||||
9 | * Init blog plugin |
||||||||
10 | * |
||||||||
11 | * @return void |
||||||||
12 | */ |
||||||||
13 | function blog_init() { |
||||||||
14 | |||||||||
15 | 31 | elgg_register_library('elgg:blog', __DIR__ . '/lib/blog.php'); |
|||||||
16 | |||||||||
17 | // add a site navigation item |
||||||||
18 | 31 | elgg_register_menu_item('site', [ |
|||||||
19 | 31 | 'name' => 'blog', |
|||||||
20 | 31 | 'text' => elgg_echo('blog:blogs'), |
|||||||
21 | 31 | 'href' => elgg_generate_url('collection:object:blog:all'), |
|||||||
22 | ]); |
||||||||
23 | |||||||||
24 | 31 | elgg_extend_view('object/elements/imprint/contents', 'blog/imprint/status'); |
|||||||
25 | |||||||||
26 | // notifications |
||||||||
27 | 31 | elgg_register_notification_event('object', 'blog', ['publish']); |
|||||||
28 | elgg_register_plugin_hook_handler('prepare', 'notification:publish:object:blog', 'blog_prepare_notification'); |
||||||||
29 | |||||||||
30 | 31 | // add blog link to owner block |
|||||||
31 | 31 | elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'blog_owner_block_menu'); |
|||||||
32 | |||||||||
33 | // Add group option |
||||||||
34 | 31 | add_group_tool_option('blog', elgg_echo('blog:enableblog'), true); |
|||||||
35 | elgg_extend_view('groups/tool_latest', 'blog/group_module'); |
||||||||
36 | |||||||||
37 | 31 | // archive menu |
|||||||
38 | 31 | elgg_register_plugin_hook_handler('register', 'menu:blog_archive', 'blog_archive_menu_setup'); |
|||||||
39 | |||||||||
40 | // ecml |
||||||||
41 | 31 | elgg_register_plugin_hook_handler('get_views', 'ecml', 'blog_ecml_views_hook'); |
|||||||
42 | |||||||||
43 | // allow to be liked |
||||||||
44 | 31 | elgg_register_plugin_hook_handler('likes:is_likable', 'object:blog', 'Elgg\Values::getTrue'); |
|||||||
45 | |||||||||
46 | // register database seed |
||||||||
47 | 31 | elgg_register_plugin_hook_handler('seeds', 'database', 'blog_register_db_seeds'); |
|||||||
48 | } |
||||||||
49 | |||||||||
50 | 31 | /** |
|||||||
51 | 31 | * Add a menu item to an ownerblock |
|||||||
52 | * |
||||||||
53 | * @param string $hook 'register' |
||||||||
54 | * @param string $type 'menu:owner_block' |
||||||||
55 | * @param ElggMenuItem[] $return current return value |
||||||||
56 | * @param array $params supplied params |
||||||||
57 | * |
||||||||
58 | * @return ElggMenuItem[] |
||||||||
59 | */ |
||||||||
60 | function blog_owner_block_menu($hook, $type, $return, $params) { |
||||||||
2 ignored issues
–
show
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||||
61 | $entity = elgg_extract('entity', $params); |
||||||||
62 | if ($entity instanceof ElggUser) { |
||||||||
63 | $return[] = ElggMenuItem::factory([ |
||||||||
64 | 3 | 'name' => 'blog', |
|||||||
65 | 3 | 'text' => elgg_echo('blog'), |
|||||||
66 | 3 | 'href' => elgg_generate_url('collection:object:blog:owner', [ |
|||||||
67 | 'username' => $entity->username, |
||||||||
68 | ]), |
||||||||
69 | ]); |
||||||||
70 | } elseif ($entity instanceof ElggGroup) { |
||||||||
71 | if ($entity->isToolEnabled('blog')) { |
||||||||
72 | $return[] = ElggMenuItem::factory([ |
||||||||
73 | 'name' => 'blog', |
||||||||
74 | 'text' => elgg_echo('blog:group'), |
||||||||
75 | 'href' => elgg_generate_url('collection:object:blog:group', [ |
||||||||
76 | 'group_guid' => $entity->guid, |
||||||||
77 | 'subpage' => 'all', |
||||||||
78 | ]), |
||||||||
79 | ]); |
||||||||
80 | } |
||||||||
81 | } |
||||||||
82 | |||||||||
83 | return $return; |
||||||||
84 | } |
||||||||
85 | |||||||||
86 | /** |
||||||||
87 | * Add menu items to the archive menu |
||||||||
88 | * |
||||||||
89 | * @param string $hook 'register' |
||||||||
90 | * @param string $type 'menu:blog_archive' |
||||||||
91 | * @param ElggMenuItem[] $return current return value |
||||||||
92 | * @param array $params supplied params |
||||||||
93 | * |
||||||||
94 | * @return void|ElggMenuItem[] |
||||||||
95 | */ |
||||||||
96 | function blog_archive_menu_setup($hook, $type, $return, $params) { |
||||||||
3 ignored issues
–
show
The parameter
$params is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$hook is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||||
97 | |||||||||
98 | $page_owner = elgg_get_page_owner_entity(); |
||||||||
99 | if (empty($page_owner)) { |
||||||||
100 | return; |
||||||||
101 | } |
||||||||
102 | |||||||||
103 | $dates = get_entity_dates('object', 'blog', $page_owner->getGUID()); |
||||||||
104 | if (!$dates) { |
||||||||
105 | return; |
||||||||
106 | } |
||||||||
107 | |||||||||
108 | $dates = array_reverse($dates); |
||||||||
109 | |||||||||
110 | $generate_url = function($lower = null, $upper = null) use ($page_owner) { |
||||||||
111 | if ($page_owner instanceof ElggUser) { |
||||||||
112 | $url_segment = elgg_generate_url('collection:object:blog:archive', [ |
||||||||
113 | 'username' => $page_owner->username, |
||||||||
114 | 'lower' => $lower, |
||||||||
115 | 'upper' => $upper, |
||||||||
116 | ]); |
||||||||
117 | } else { |
||||||||
118 | $url_segment = elgg_generate_url('collection:object:blog:group', [ |
||||||||
119 | 'group_guid' => $page_owner->guid, |
||||||||
120 | 'subpage' => 'archive', |
||||||||
121 | 'lower' => $lower, |
||||||||
122 | 'upper' => $upper, |
||||||||
123 | ]); |
||||||||
124 | } |
||||||||
125 | |||||||||
126 | return $url_segment; |
||||||||
127 | }; |
||||||||
128 | |||||||||
129 | $years = []; |
||||||||
130 | foreach ($dates as $date) { |
||||||||
131 | $timestamplow = mktime(0, 0, 0, substr($date, 4, 2), 1, substr($date, 0, 4)); |
||||||||
132 | $timestamphigh = mktime(0, 0, 0, ((int) substr($date, 4, 2)) + 1, 1, substr($date, 0, 4)); |
||||||||
133 | |||||||||
134 | $year = substr($date, 0, 4); |
||||||||
135 | if (!in_array($year, $years)) { |
||||||||
136 | $return[] = ElggMenuItem::factory([ |
||||||||
137 | 'name' => $year, |
||||||||
138 | 'text' => $year, |
||||||||
139 | 'href' => '#', |
||||||||
140 | 'child_menu' => [ |
||||||||
141 | 'display' => 'toggle', |
||||||||
142 | ] |
||||||||
143 | ]); |
||||||||
144 | } |
||||||||
145 | |||||||||
146 | $month = trim(elgg_echo('date:month:' . substr($date, 4, 2), [''])); |
||||||||
147 | |||||||||
148 | $return[] = ElggMenuItem::factory([ |
||||||||
149 | 'name' => $date, |
||||||||
150 | 'text' => $month, |
||||||||
151 | 'href' => $generate_url($timestamplow, $timestamphigh), |
||||||||
152 | 'parent_name' => $year, |
||||||||
153 | ]); |
||||||||
154 | } |
||||||||
155 | |||||||||
156 | return $return; |
||||||||
157 | } |
||||||||
158 | |||||||||
159 | /** |
||||||||
160 | * Prepare a notification message about a published blog |
||||||||
161 | * |
||||||||
162 | * @param string $hook Hook name |
||||||||
163 | * @param string $type Hook type |
||||||||
164 | * @param Elgg\Notifications\Notification $notification The notification to prepare |
||||||||
165 | * @param array $params Hook parameters |
||||||||
166 | * @return Elgg\Notifications\Notification |
||||||||
167 | */ |
||||||||
168 | function blog_prepare_notification($hook, $type, $notification, $params) { |
||||||||
2 ignored issues
–
show
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$hook is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||||
169 | $entity = $params['event']->getObject(); |
||||||||
170 | $owner = $params['event']->getActor(); |
||||||||
171 | $recipient = $params['recipient']; |
||||||||
172 | $language = $params['language']; |
||||||||
173 | $method = $params['method']; |
||||||||
174 | |||||||||
175 | $notification->subject = elgg_echo('blog:notify:subject', [$entity->title], $language); |
||||||||
176 | $notification->body = elgg_echo('blog:notify:body', [ |
||||||||
177 | $owner->name, |
||||||||
178 | $entity->title, |
||||||||
179 | $entity->getExcerpt(), |
||||||||
180 | $entity->getURL() |
||||||||
181 | ], $language); |
||||||||
182 | $notification->summary = elgg_echo('blog:notify:summary', [$entity->title], $language); |
||||||||
183 | $notification->url = $entity->getURL(); |
||||||||
184 | |||||||||
185 | return $notification; |
||||||||
186 | } |
||||||||
187 | |||||||||
188 | /** |
||||||||
189 | * Register blogs with ECML |
||||||||
190 | * |
||||||||
191 | * @param string $hook 'get_views' |
||||||||
192 | * @param string $type 'ecml' |
||||||||
193 | * @param array $return_value current return value |
||||||||
194 | * @param array $params supplied params |
||||||||
195 | * |
||||||||
196 | * @return array |
||||||||
197 | */ |
||||||||
198 | function blog_ecml_views_hook($hook, $type, $return_value, $params) { |
||||||||
3 ignored issues
–
show
The parameter
$hook is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$params is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
The parameter
$type is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.
Loading history...
|
|||||||||
199 | $return_value['object/blog'] = elgg_echo('blog:blogs'); |
||||||||
200 | |||||||||
201 | return $return_value; |
||||||||
202 | } |
||||||||
203 | |||||||||
204 | /** |
||||||||
205 | * Register database seed |
||||||||
206 | * |
||||||||
207 | * @elgg_plugin_hook seeds database |
||||||||
208 | * |
||||||||
209 | * @param \Elgg\Hook $hook Hook |
||||||||
210 | * @return array |
||||||||
211 | */ |
||||||||
212 | function blog_register_db_seeds(\Elgg\Hook $hook) { |
||||||||
213 | |||||||||
214 | $seeds = $hook->getValue(); |
||||||||
215 | |||||||||
216 | $seeds[] = \Elgg\Blog\Seeder::class; |
||||||||
217 | |||||||||
218 | return $seeds; |
||||||||
219 | } |
||||||||
220 | |||||||||
221 | return function() { |
||||||||
222 | elgg_register_event_handler('init', 'system', 'blog_init'); |
||||||||
223 | }; |
||||||||
224 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.