Elgg  Version 2.3
edit.php
Go to the documentation of this file.
1 <?php
7 elgg_make_sticky_form('profile:edit');
8 
9 $guid = get_input('guid');
11 
12 if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) {
13  register_error(elgg_echo('profile:noaccess'));
15 }
16 
17 // grab the defined profile field names and their load the values from POST.
18 // each field can have its own access, so sort that too.
19 $input = array();
20 $accesslevel = get_input('accesslevel');
21 
22 if (!is_array($accesslevel)) {
23  $accesslevel = array();
24 }
25 
26 $profile_fields = elgg_get_config('profile_fields');
27 foreach ($profile_fields as $shortname => $valuetype) {
28  $value = get_input($shortname);
29 
30  if ($value === null) {
31  // only submitted profile fields should be updated
32  continue;
33  }
34 
35  // the decoding is a stop gap to prevent &amp;&amp; showing up in profile fields
36  // because it is escaped on both input (get_input()) and output (view:output/text). see #561 and #1405.
37  // must decode in utf8 or string corruption occurs. see #1567.
38  if (is_array($value)) {
39  array_walk_recursive($value, function(&$v) {
40  $v = elgg_html_decode($v);
41  });
42  } else {
44  }
45 
46  // convert tags fields to array values
47  if ($valuetype == 'tags') {
49  }
50 
51  if ($value && $valuetype == 'url' && !preg_match('~^https?\://~i', $value)) {
52  $value = "http://$value";
53  }
54 
55  if ($valuetype == 'email' && !empty($value) && !is_email_address($value)) {
56  register_error(elgg_echo('profile:invalid_email', array(
57  elgg_echo("profile:{$shortname}")
58  )));
60  }
61 
62  $input[$shortname] = $value;
63 }
64 
65 // display name is handled separately
66 $name = strip_tags(get_input('name'));
67 if ($name) {
68  if (elgg_strlen($name) > 50) {
69  register_error(elgg_echo('user:name:fail'));
70  } elseif ($owner->name != $name) {
71  $owner->name = $name;
72  $owner->save();
73  }
74 }
75 
76 // go through custom fields
77 if (sizeof($input) > 0) {
78 
79  // fetch default access level for the user for use in fallback cases
81 
82  foreach ($input as $shortname => $value) {
83  $options = array(
84  'guid' => $owner->guid,
85  'metadata_name' => $shortname,
86  'limit' => false
87  );
89 
90  if (!is_null($value) && ($value !== '')) {
91  // only create metadata for non empty values (0 is allowed) to prevent metadata records
92  // with empty string values #4858
93 
94  if (isset($accesslevel[$shortname])) {
95  $access_id = (int) $accesslevel[$shortname];
96  } else {
97  // this should never be executed since the access level should always be set
98  $access_id = $user_default_access;
99  }
100  if (is_array($value)) {
101  $i = 0;
102  foreach ($value as $interval) {
103  $i++;
104  $multiple = ($i > 1) ? TRUE : FALSE;
105  create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
106  }
107  } else {
108  create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id);
109  }
110  }
111  }
112 
113  $owner->save();
114 
115  // Notify of profile update
116  elgg_trigger_event('profileupdate', $owner->type, $owner);
117 
118  elgg_clear_sticky_form('profile:edit');
119  system_message(elgg_echo("profile:saved"));
120 }
121 
122 forward($owner->getUrl());
$owner
Definition: edit.php:10
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=null, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:66
elgg_html_decode($string)
Decode HTML markup into a raw text string.
Definition: output.php:514
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $input
Definition: edit.php:19
string_to_tag_array($string)
Takes in a comma-separated string and returns an array of tags which have been trimmed.
Definition: tags.php:18
$value
Definition: longtext.php:42
$accesslevel
Definition: edit.php:20
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:425
$options
Elgg admin footer.
Definition: footer.php:6
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:72
is_email_address($address)
Validates an email address.
Definition: input.php:88
get_default_access(ElggUser $user=null, array $input_params=array())
Gets the default access permission.
Definition: access.php:118
if(!is_array($accesslevel)) $profile_fields
Definition: edit.php:26
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
const REFERER
Definition: elgglib.php:2123
elgg_make_sticky_form($form_name)
Save form submission data (all GET and POST vars) into a session cache.
Definition: input.php:103
$guid
Definition: edit.php:9
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:390
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:179
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:399
$user_default_access
elgg_trigger_event($event, $object_type, $object=null)
Definition: elgglib.php:614
elgg_clear_sticky_form($form_name)
Remove form submission data from the session.
Definition: input.php:119
foreach($profile_fields as $shortname=> $valuetype) $name
Definition: edit.php:66
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:204