Elgg  Version 1.11
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 
29 function profile_array_decoder(&$v) {
30  $v = _elgg_html_decode($v);
31 }
32 
33 $profile_fields = elgg_get_config('profile_fields');
34 foreach ($profile_fields as $shortname => $valuetype) {
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  $value = get_input($shortname);
39  if (is_array($value)) {
40  array_walk_recursive($value, 'profile_array_decoder');
41  } else {
43  }
44 
45  // limit to reasonable sizes
46  // @todo - throwing away changes due to this is dumb!
47  // ^^ This is a sticky form so changes aren't lost...?
48  if (!is_array($value) && $valuetype != 'longtext' && elgg_strlen($value) > 250) {
49  $error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}")));
52  }
53 
54  if ($value && $valuetype == 'url' && !preg_match('~^https?\://~i', $value)) {
55  $value = "http://$value";
56  }
57 
58  if ($valuetype == 'tags') {
60  }
61 
62  if ($valuetype == 'email' && !empty($value) && !is_email_address($value)) {
63  register_error(elgg_echo('profile:invalid_email', array(
64  elgg_echo("profile:{$shortname}")
65  )));
67  }
68 
69  $input[$shortname] = $value;
70 }
71 
72 // display name is handled separately
73 $name = strip_tags(get_input('name'));
74 if ($name) {
75  if (elgg_strlen($name) > 50) {
76  register_error(elgg_echo('user:name:fail'));
77  } elseif ($owner->name != $name) {
78  $owner->name = $name;
79  $owner->save();
80  }
81 }
82 
83 // go through custom fields
84 if (sizeof($input) > 0) {
85  foreach ($input as $shortname => $value) {
86  $options = array(
87  'guid' => $owner->guid,
88  'metadata_name' => $shortname,
89  'limit' => false
90  );
92 
93  if (!is_null($value) && ($value !== '')) {
94  // only create metadata for non empty values (0 is allowed) to prevent metadata records
95  // with empty string values #4858
96 
97  if (isset($accesslevel[$shortname])) {
98  $access_id = (int) $accesslevel[$shortname];
99  } else {
100  // this should never be executed since the access level should always be set
101  $access_id = ACCESS_DEFAULT;
102  }
103  if (is_array($value)) {
104  $i = 0;
105  foreach ($value as $interval) {
106  $i++;
107  $multiple = ($i > 1) ? TRUE : FALSE;
108  create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
109  }
110  } else {
111  create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id);
112  }
113  }
114  }
115 
116  $owner->save();
117 
118  // Notify of profile update
119  elgg_trigger_event('profileupdate', $owner->type, $owner);
120 
121  elgg_clear_sticky_form('profile:edit');
122  system_message(elgg_echo("profile:saved"));
123 }
124 
125 forward($owner->getUrl());
$owner
Definition: edit.php:10
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
if(!$owner||!($owner instanceof ElggUser)||!$owner->canEdit()) $error
Definition: upload.php:14
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_clear_sticky_form($form_name)
Clear the sticky form cache.
Definition: input.php:119
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:26
$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:419
elgg_strlen()
Wrapper function for mb_strlen().
Definition: mb_wrapper.php:72
$options
Definition: index.php:14
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
const REFERER
Definition: elgglib.php:1995
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:65
_elgg_html_decode($string)
Apply html_entity_decode() to a string while re-entitising HTML special char entities to prevent them...
Definition: output.php:536
$guid
Definition: edit.php:9
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg_delete_metadata(array $options)
Deletes metadata based on $options.
Definition: metadata.php:158
if(!is_array($accesslevel)) profile_array_decoder(&$v)
wrapper for recursive array walk decoding
Definition: edit.php:29
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
$profile_fields
Definition: edit.php:33
elgg_make_sticky_form($form_name)
Load all the GET and POST variables into the sticky form cache.
Definition: input.php:103
const ACCESS_DEFAULT
Definition: elgglib.php:1953
elgg_trigger_event($event, $object_type, $object=null)
Definition: elgglib.php:570
is_email_address($address)
Validates an email address.
Definition: input.php:88
foreach($profile_fields as $shortname=> $valuetype) $name
Definition: edit.php:73
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382