-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.php
More file actions
331 lines (276 loc) · 8.21 KB
/
start.php
File metadata and controls
331 lines (276 loc) · 8.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/*
* Check In
*
* @author Per Jensen
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License v2
* @copyright Copyright (c) 2019, Per Jensen
*
*/
return function() {
elgg_register_event_handler('init', 'system', 'checkin_init');
};
function checkin_init() {
elgg_set_entity_class('object', 'checkin', ElggCheckinCover::class);
// plugin specific CSS
elgg_extend_view('elgg.css', 'checkin/checkin.css');
elgg_register_plugin_hook_handler('view_vars', 'page/default', 'checkin_context_vars');
// Register for notifications
elgg_register_notification_event('object', 'checkin', ['create']);
elgg_register_plugin_hook_handler('prepare', 'notification:create:object:checkin', 'checkin_prepare_notification');
// custom icon sizes
elgg_register_plugin_hook_handler('entity:icon:sizes', 'object', 'checkin_custom_icon_sizes');
elgg_register_plugin_hook_handler('entity:icon:file', 'object', 'checkin_set_icon_file');
// cleanup thumbnails on delete. high priority because we want to try to make sure the
// deletion will actually occur before we go through with this.
elgg_register_event_handler('delete', 'object', 'checkin_handle_object_delete', 999);
// add the group checkin tool option
elgg()->group_tools->register('checkin');
// add a check-in link to owner blocks
elgg_register_plugin_hook_handler('register', 'menu:owner_block', 'checkin_owner_block_menu');
// allow to be liked
elgg_register_plugin_hook_handler('likes:is_likable', 'object:checkin', 'Elgg\Values::getTrue');
// hack to load google libraries with async defer (checkin/google-api)
elgg_extend_view('page/elements/foot', 'checkin/google-api');
elgg_register_ajax_view('checkin/infowindow');
// menus
elgg_register_menu_item('site', [
'name' => 'checkin',
'icon' => 'map-marker',
'text' => elgg_echo('checkin:menu:item'),
'href' => elgg_generate_url('default:object:checkin'),
]);
// add map tab to filter:checkin
elgg_register_menu_item('filter:checkin', [
'name' => 'checkin_map',
'text' => elgg_view_icon('map-marker'),
'href' => elgg_generate_url('collection:object:checkin:map'),
'title' => elgg_echo("checkin:map"),
'priority' => 1200,
]);
}
/**
* Set body tag for checkin context
*
* @param string $hook 'view_vars'
* @param string $type 'page/default'
* @param array $vars return value
* @param array $params supplied params
*
* @return void|array
*/
function checkin_context_vars($hook, $type, $vars, $params) {
$body_vars = elgg_extract('body_attrs', $vars);
if (elgg_in_context('checkin')) {
$vars['body_attrs'] = array('class' => 'elgg-page-checkin');
}
return $vars;
}
/**
* Adds a toggle to filter menu for switching between list and gallery views
*
* @return void
*/
function checkin_register_toggle() {
if (get_input('list_type', 'list') == 'list') {
$list_type = 'gallery';
$icon = elgg_view_icon('grid');
} else {
$list_type = 'list';
$icon = elgg_view_icon('list');
}
$url = elgg_http_add_url_query_elements(current_page_url(), ['list_type' => $list_type]);
elgg_register_menu_item('filter:checkin', [
'name' => 'checkin_list',
'text' => $icon,
'href' => $url,
'title' => elgg_echo("checkin:list:$list_type"),
'priority' => 1000,
]);
}
/**
* Prepare a notification message about a new checkin
*
* @param string $hook Hook name
* @param string $type Hook type
* @param Elgg\Notifications\Notification $notification The notification to prepare
* @param array $params Hook parameters
* @return Elgg\Notifications\Notification
*/
function checkin_prepare_notification($hook, $type, $notification, $params) {
$entity = $params['event']->getObject();
$owner = $params['event']->getActor();
$language = $params['language'];
$descr = $entity->description;
$title = $entity->getDisplayName();
$notification->subject = elgg_echo('checkin:notify:subject', [$title], $language);
$notification->body = elgg_echo('checkin:notify:body', [
$owner->getDisplayName(),
$title,
$descr,
$entity->getURL()
], $language);
$notification->summary = elgg_echo('checkin:notify:summary', [$title], $language);
$notification->url = $entity->getURL();
return $notification;
}
/**
* Add a menu item to the user ownerblock
*
* @param string $hook 'register'
* @param string $type 'menu:owner_block'
* @param ElggMenuItem[] $return current return value
* @param array $params supplied params
*
* @return ElggMenuItem[]
*/
function checkin_owner_block_menu($hook, $type, $return, $params) {
$entity = elgg_extract('entity', $params);
if ($entity instanceof ElggUser) {
$url = elgg_generate_url('collection:object:checkin:owner', ['username' => $entity->username]);
$item = new ElggMenuItem('checkin', elgg_echo('collection:object:checkin'), $url);
$return[] = $item;
} elseif ($entity instanceof ElggGroup) {
if ($entity->isToolEnabled('checkin')) {
$url = elgg_generate_url('collection:object:checkin:group', ['guid' => $entity->guid]);
$item = new ElggMenuItem('checkin', elgg_echo('collection:object:checkin:group'), $url);
$return[] = $item;
}
}
return $return;
}
/**
* Set custom icon sizes for checkin objects
*
* @param string $hook "entity:icon:url"
* @param string $type "object"
* @param array $return Sizes
* @param array $params Hook params
* @return array
*/
function checkin_custom_icon_sizes($hook, $type, $return, $params) {
$entity_subtype = elgg_extract('entity_subtype', $params);
if ($entity_subtype !== 'checkin') {
return;
}
$return['checkin_cover'] = [
'w' => 1920,
'h' => 1080,
'square' => false,
'upscale' => false,
];
$return['checkin_cover_small'] = [
'w' => 384,
'h' => 216,
'square' => false,
'upscale' => false,
];
$return['medium'] = [
'w' => 480,
'h' => 480,
'square' => true,
'upscale' => true,
];
$return['small'] = [
'w' => 60,
'h' => 60,
'square' => true,
'upscale' => true,
];
return $return;
}
/**
* Set custom file thumbnail location
*
* @param string $hook "entity:icon:file"
* @param string $type "object"
* @param \ElggIcon $icon Icon file
* @param array $params Hook params
* @return \ElggIcon
*/
function checkin_set_icon_file($hook, $type, $icon, $params) {
$entity = elgg_extract('entity', $params);
$size = elgg_extract('size', $params);
if (!($entity instanceof ElggCheckinCover)) {
return;
}
switch ($size) {
case 'small' :
$name = 'small';
break;
case 'medium' :
$name = 'medium';
break;
case 'checkin_cover' :
$name = 'cover';
break;
case 'checkin_cover_small' :
$name = 'cover_small';
break;
default :
$name = "{$size}";
break;
}
$icon->owner_guid = $entity->owner_guid;
$prefix = $entity->guid . '_';
$filename = pathinfo($entity->getFilenameOnFilestore(), PATHINFO_FILENAME);
$filename = "checkin/{$prefix}{$name}.jpg";
$icon->setFilename($filename);
return $icon;
}
/**
* Handle an object being deleted
*
* @param string $event Event name
* @param string $type Event type
* @param ElggObject $file The object deleted
* @return void
*/
function checkin_handle_object_delete($event, $type, ElggObject $file) {
if (!$file instanceof ElggCheckinCover) {
return;
}
if (!$file->guid) {
// this is an ElggFile used as temporary API
return;
}
$file->deleteIcon();
}
/**
* Prepare the upload/edit form variables
*
* @param ElggCheckinCover $file the file to edit
*
* @return array
*/
function checkin_prepare_form_vars($checkin = null) {
// input names => defaults
$values = [
'title' => '',
'location' => '',
'collection_tagged' => '',
'latitude' => '',
'longitude' => '',
'description' => '',
'access_id' => ACCESS_DEFAULT,
'tags' => '',
'container_guid' => elgg_get_page_owner_guid(),
'guid' => null,
'entity' => $checkin,
];
if ($checkin) {
foreach (array_keys($values) as $field) {
if (isset($checkin->$field)) {
$values[$field] = $checkin->$field;
}
}
}
if (elgg_is_sticky_form('checkin')) {
$sticky_values = elgg_get_sticky_values('checkin');
foreach ($sticky_values as $key => $value) {
$values[$key] = $value;
}
}
elgg_clear_sticky_form('checkin');
return $values;
}