1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Avatar crop action |
4
|
|
|
* |
5
|
|
|
*/ |
6
|
|
|
|
7
|
|
|
$guid = get_input('guid'); |
8
|
|
|
$owner = get_entity($guid); |
9
|
|
|
|
10
|
|
|
if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) { |
11
|
|
|
register_error(elgg_echo('avatar:crop:fail')); |
12
|
|
|
forward(REFERER); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
$x1 = (int) get_input('x1', 0); |
16
|
|
|
$y1 = (int) get_input('y1', 0); |
17
|
|
|
$x2 = (int) get_input('x2', 0); |
18
|
|
|
$y2 = (int) get_input('y2', 0); |
19
|
|
|
|
20
|
|
|
$filehandler = new ElggFile(); |
21
|
|
|
$filehandler->owner_guid = $owner->getGUID(); |
22
|
|
|
$filehandler->setFilename("profile/" . $owner->guid . "master" . ".jpg"); |
23
|
|
|
$filename = $filehandler->getFilenameOnFilestore(); |
24
|
|
|
|
25
|
|
|
// ensuring the avatar image exists in the first place |
26
|
|
|
if (!file_exists($filename)) { |
27
|
|
|
register_error(elgg_echo('avatar:crop:fail')); |
28
|
|
|
forward(REFERER); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
$icon_sizes = elgg_get_config('icon_sizes'); |
32
|
|
|
unset($icon_sizes['master']); |
33
|
|
|
|
34
|
|
|
// get the images and save their file handlers into an array |
35
|
|
|
// so we can do clean up if one fails. |
36
|
|
|
$files = array(); |
37
|
|
View Code Duplication |
foreach ($icon_sizes as $name => $size_info) { |
38
|
|
|
$resized = get_resized_image_from_existing_file($filename, $size_info['w'], $size_info['h'], $size_info['square'], $x1, $y1, $x2, $y2, $size_info['upscale']); |
39
|
|
|
|
40
|
|
|
if ($resized) { |
|
|
|
|
41
|
|
|
//@todo Make these actual entities. See exts #348. |
42
|
|
|
$file = new ElggFile(); |
43
|
|
|
$file->owner_guid = $guid; |
44
|
|
|
$file->setFilename("profile/{$guid}{$name}.jpg"); |
45
|
|
|
$file->open('write'); |
46
|
|
|
$file->write($resized); |
47
|
|
|
$file->close(); |
48
|
|
|
$files[] = $file; |
49
|
|
|
} else { |
50
|
|
|
// cleanup on fail |
51
|
|
|
foreach ($files as $file) { |
52
|
|
|
$file->delete(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
register_error(elgg_echo('avatar:resize:fail')); |
56
|
|
|
forward(REFERER); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$owner->icontime = time(); |
61
|
|
|
|
62
|
|
|
$owner->x1 = $x1; |
63
|
|
|
$owner->x2 = $x2; |
64
|
|
|
$owner->y1 = $y1; |
65
|
|
|
$owner->y2 = $y2; |
66
|
|
|
|
67
|
|
|
system_message(elgg_echo('avatar:crop:success')); |
68
|
|
|
$view = 'river/user/default/profileiconupdate'; |
69
|
|
|
elgg_delete_river(array('subject_guid' => $owner->guid, 'view' => $view)); |
70
|
|
|
elgg_create_river_item(array( |
71
|
|
|
'view' => $view, |
72
|
|
|
'action_type' => 'update', |
73
|
|
|
'subject_guid' => $owner->guid, |
74
|
|
|
'object_guid' => $owner->guid, |
75
|
|
|
)); |
76
|
|
|
|
77
|
|
|
|
78
|
|
|
forward(REFERER); |
79
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: