Elgg  Version 1.9
crop.php
Go to the documentation of this file.
1 <?php
7 $guid = get_input('guid');
9 
10 if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) {
11  register_error(elgg_echo('avatar:crop:fail'));
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 
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'));
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 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'));
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));
71  'view' => $view,
72  'action_type' => 'update',
73  'subject_guid' => $owner->guid,
74  'object_guid' => $owner->guid,
75 ));
76 
77 
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$view
Definition: crop.php:68
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
$files
Definition: crop.php:36
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $x1
Definition: crop.php:15
get_resized_image_from_existing_file($input_name, $maxwidth, $maxheight, $square=false, $x1=0, $y1=0, $x2=0, $y2=0, $upscale=false)
Gets the jpeg contents of the resized version of an already uploaded image (Returns false if the file...
Definition: filestore.php:107
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
elgg_create_river_item(array $options=array())
Adds an item to the river.
Definition: river.php:37
$owner
Definition: crop.php:8
$filehandler
Definition: crop.php:20
$guid
Avatar crop action.
Definition: crop.php:7
const REFERER
Definition: elgglib.php:2162
if(!file_exists($filename)) $icon_sizes
Definition: crop.php:31
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
$y1
Definition: crop.php:16
elgg_delete_river(array $options=array())
Delete river items.
Definition: river.php:168
$filename
Definition: crop.php:23
$x2
Definition: crop.php:17
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604
$y2
Definition: crop.php:18