Completed
Push — master ( caf222...deba87 )
by Jeroen
72:32 queued 44:47
created

actions/avatar/crop.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * Avatar crop action
4
 */
5
6
$guid = get_input('guid');
7
$owner = get_user($guid);
0 ignored issues
show
It seems like $guid can also be of type string; however, parameter $guid of get_user() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

7
$owner = get_user(/** @scrutinizer ignore-type */ $guid);
Loading history...
8
9
if (!$owner || !$owner->canEdit()) {
10
	return elgg_error_response(elgg_echo('avatar:crop:fail'));
11
}
12
13
// ensuring the avatar image exists in the first place
14
if (!$owner->hasIcon('master')) {
15
	return elgg_error_response(elgg_echo('avatar:crop:fail'));
16
}
17
18
$coords = [
19
	'x1' => (int) get_input('x1', 0),
20
	'y1' => (int) get_input('y1', 0),
21
	'x2' => (int) get_input('x2', 0),
22
	'y2' => (int) get_input('y2', 0),
23
];
24
25
if (!$owner->saveIconFromElggFile($owner->getIcon('master'), 'icon', $coords)) {
26
	return elgg_error_response(elgg_echo('avatar:crop:fail'));
27
}
28
29
// River
30
$view = 'river/user/default/profileiconupdate';
31
32
// remove old river items
33
elgg_delete_river([
34
	'subject_guid' => $owner->guid,
35
	'view' => $view,
36
	'limit' => false,
37
]);
38
// create new river entry
39
elgg_create_river_item([
40
	'view' => $view,
41
	'action_type' => 'update',
42
	'subject_guid' => $owner->guid,
43
	'object_guid' => $owner->guid,
44
]);
45
46
return elgg_ok_response('', elgg_echo('avatar:crop:success'));
47