aboutsummaryrefslogtreecommitdiff
path: root/actions/avatar/remove.php
blob: cd38e456a541578ad9362150327106f8e919b56a (plain)
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
<?php
/**
 * Avatar remove action
 */

$guid = get_input('guid');
$user = get_entity($guid);
if ($user) {
	// Delete all icons from diskspace
	$icon_sizes = elgg_get_config('icon_sizes');
	foreach ($icon_sizes as $name => $size_info) {
		$file = new ElggFile();
		$file->owner_guid = $guid;
		$file->setFilename("profile/{$guid}{$name}.jpg");
		$filepath = $file->getFilenameOnFilestore();
		if (!$file->delete()) {
			elgg_log("Avatar file remove failed. Remove $filepath manually, please.", 'WARNING');
		}
	}
	
	// Remove crop coords
	unset($user->x1);
	unset($user->x2);
	unset($user->y1);
	unset($user->y2);
	
	// Remove icon
	unset($user->icontime);
	system_message(elgg_echo('avatar:remove:success'));
} else {
	register_error(elgg_echo('avatar:remove:fail'));
}

forward(REFERER);