1 | <?php |
||
2 | /** |
||
3 | * Avatar crop action |
||
4 | */ |
||
5 | |||
6 | $guid = (int) get_input('guid'); |
||
7 | $owner = get_user($guid); |
||
8 | |||
9 | if (!$owner || !$owner->canEdit()) { |
||
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
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 |