aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--actions/profile/edit.php (renamed from mod/profile/actions/edit.php)47
-rw-r--r--engine/lib/users.php83
-rw-r--r--languages/en.php3
-rw-r--r--mod/profile/start.php5
-rw-r--r--pages/avatar/edit.php2
-rw-r--r--pages/profile/edit.php32
-rw-r--r--views/default/forms/profile/edit.php64
7 files changed, 211 insertions, 25 deletions
diff --git a/mod/profile/actions/edit.php b/actions/profile/edit.php
index da7553b6e..219474f2c 100644
--- a/mod/profile/actions/edit.php
+++ b/actions/profile/edit.php
@@ -1,17 +1,14 @@
<?php
/**
- * Elgg profile plugin edit action
+ * Elgg profile edit action
*
- * @package ElggProfile
*/
-global $CONFIG;
+$guid = get_input('guid');
+$owner = get_entity($guid);
-$profile_username = get_input('username');
-$profile_owner = get_user_by_username($profile_username);
-
-if (!$profile_owner || !$profile_owner->canEdit()) {
- system_message(elgg_echo("profile:noaccess"));
+if (!$owner || !($owner instanceof ElggUser) || !$owner->canEdit()) {
+ register_error(elgg_echo('profile:edit:fail'));
forward(REFERER);
}
@@ -31,8 +28,8 @@ function profile_array_decoder(&$v) {
$v = html_entity_decode($v, ENT_COMPAT, 'UTF-8');
}
-
-foreach($CONFIG->profile as $shortname => $valuetype) {
+$profile_fields = elgg_get_config('profile');
+foreach ($profile_fields as $shortname => $valuetype) {
// the decoding is a stop gag to prevent &amp;&amp; showing up in profile fields
// because it is escaped on both input (get_input()) and output (view:output/text). see #561 and #1405.
// must decode in utf8 or string corruption occurs. see #1567.
@@ -43,7 +40,8 @@ foreach($CONFIG->profile as $shortname => $valuetype) {
$value = html_entity_decode($value, ENT_COMPAT, 'UTF-8');
}
- // limit to reasonable sizes.
+ // limit to reasonable sizes
+ // @todo - throwing away changes due to this is dumb!
if (!is_array($value) && $valuetype != 'longtext' && elgg_strlen($value) > 250) {
$error = elgg_echo('profile:field_too_long', array(elgg_echo("profile:{$shortname}")));
register_error($error);
@@ -58,13 +56,14 @@ foreach($CONFIG->profile as $shortname => $valuetype) {
}
// display name is handled separately
-if ($name = strip_tags(get_input('name'))) {
+$name = strip_tags(get_input('name'));
+if ($name) {
if (elgg_strlen($name) > 50) {
register_error(elgg_echo('user:name:fail'));
- } elseif ($profile_owner->name != $name) {
- $profile_owner->name = $name;
+ } elseif ($owner->name != $name) {
+ $owner->name = $name;
// @todo this is weird...giving two notifications?
- if ($profile_owner->save()) {
+ if ($owner->save()) {
system_message(elgg_echo('user:name:success'));
} else {
register_error(elgg_echo('user:name:fail'));
@@ -74,8 +73,8 @@ if ($name = strip_tags(get_input('name'))) {
// go through custom fields
if (sizeof($input) > 0) {
- foreach($input as $shortname => $value) {
- remove_metadata($profile_owner->guid, $shortname);
+ foreach ($input as $shortname => $value) {
+ remove_metadata($owner->guid, $shortname);
if (isset($accesslevel[$shortname])) {
$access_id = (int) $accesslevel[$shortname];
} else {
@@ -84,27 +83,27 @@ if (sizeof($input) > 0) {
}
if (is_array($value)) {
$i = 0;
- foreach($value as $interval) {
+ foreach ($value as $interval) {
$i++;
$multiple = ($i > 1) ? TRUE : FALSE;
- create_metadata($profile_owner->guid, $shortname, $interval, 'text', $profile_owner->guid, $access_id, $multiple);
+ create_metadata($owner->guid, $shortname, $interval, 'text', $owner->guid, $access_id, $multiple);
}
} else {
- create_metadata($profile_owner->getGUID(), $shortname, $value, 'text', $profile_owner->getGUID(), $access_id);
+ create_metadata($owner->getGUID(), $shortname, $value, 'text', $owner->getGUID(), $access_id);
}
}
- $profile_owner->save();
+ $owner->save();
// Notify of profile update
- elgg_trigger_event('profileupdate',$user->type,$user);
+ elgg_trigger_event('profileupdate', $user->type, $user);
//add to river if edited by self
if (get_loggedin_userid() == $user->guid) {
- add_to_river('river/user/default/profileupdate','update',get_loggedin_userid(),get_loggedin_userid(),get_default_access(get_loggedin_user()));
+ add_to_river('river/user/default/profileupdate', 'update', get_loggedin_userid(), get_loggedin_userid(), get_default_access(get_loggedin_user()));
}
system_message(elgg_echo("profile:saved"));
}
-forward($profile_owner->getUrl() . "/details");
+forward($owner->getUrl());
diff --git a/engine/lib/users.php b/engine/lib/users.php
index ee3814fd2..0482fd034 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -1478,6 +1478,61 @@ function user_avatar_hook($hook, $entity_type, $returnvalue, $params){
}
/**
+ * This function loads a set of default fields into the profile, then triggers a hook letting other plugins to edit
+ * add and delete fields.
+ *
+ * Note: This is a secondary system:init call and is run at a super low priority to guarantee that it is called after all
+ * other plugins have initialised.
+ */
+function elgg_profile_fields_setup() {
+ global $CONFIG;
+
+ $profile_defaults = array (
+ 'description' => 'longtext',
+ 'briefdescription' => 'text',
+ 'location' => 'tags',
+ 'interests' => 'tags',
+ 'skills' => 'tags',
+ 'contactemail' => 'email',
+ 'phone' => 'text',
+ 'mobile' => 'text',
+ 'website' => 'url',
+ 'twitter' => 'text'
+ );
+
+ $loaded_default = array();
+ if ($fieldlist = get_plugin_setting('user_defined_fields','profile')) {
+ if (!empty($fieldlist)) {
+ $fieldlistarray = explode(',',$fieldlist);
+ $loaded_defaults = array();
+ foreach($fieldlistarray as $listitem) {
+ if ($translation = get_plugin_setting("admin_defined_profile_{$listitem}", 'profile')) {
+ $type = get_plugin_setting("admin_defined_profile_type_{$listitem}", 'profile');
+ $loaded_defaults["admin_defined_profile_{$listitem}"] = $type;
+ add_translation(get_current_language(), array("profile:admin_defined_profile_{$listitem}" => $translation));
+ }
+ }
+ }
+ }
+
+ if (count($loaded_defaults)) {
+ $CONFIG->profile_using_custom = true;
+ $profile_defaults = $loaded_defaults;
+ }
+
+ $CONFIG->profile = elgg_trigger_plugin_hook('profile:fields', 'profile', NULL, $profile_defaults);
+
+ // register any tag metadata names
+ foreach ($CONFIG->profile as $name => $type) {
+ if ($type == 'tags') {
+ elgg_register_tag_metadata_name($name);
+ // register a tag name translation
+ add_translation(get_current_language(), array("tag_names:$name" => elgg_echo("profile:$name")));
+ }
+ }
+}
+
+/**
* Avatar page handler
*
* @param array $page
@@ -1496,6 +1551,22 @@ function elgg_avatar_page_handler($page) {
}
/**
+ * Profile page handler
+ *
+ * @param array $page
+ */
+function elgg_profile_page_handler($page) {
+ global $CONFIG;
+
+ $user = get_user_by_username($page[0]);
+ elgg_set_page_owner_guid($user->guid);
+
+ if ($page[1] == 'edit') {
+ require_once("{$CONFIG->path}pages/profile/edit.php");
+ }
+}
+
+/**
* Members page handler
*
* @param array $page url segments
@@ -1560,6 +1631,7 @@ function users_init() {
register_page_handler('login', 'elgg_user_login_page_handler');
register_page_handler('members', 'elgg_members_page_handler');
register_page_handler('avatar', 'elgg_avatar_page_handler');
+ register_page_handler('profile', 'elgg_profile_page_handler');
//register_page_handler('collections', 'collections_page_handler');
@@ -1572,7 +1644,14 @@ function users_init() {
'name' => 'edit_avatar',
'url' => "pg/avatar/edit/{$user->username}",
'title' => elgg_echo('avatar:edit'),
- 'contexts' => array('avatar'),
+ 'contexts' => array('profile_edit'),
+ );
+ elgg_register_menu_item('page', $params);
+ $params = array(
+ 'name' => 'edit_profile',
+ 'url' => "pg/profile/{$user->username}/edit",
+ 'title' => elgg_echo('profile:edit'),
+ 'contexts' => array('profile_edit'),
);
elgg_register_menu_item('page', $params);
}
@@ -1583,6 +1662,7 @@ function users_init() {
elgg_register_action("friends/remove");
elgg_register_action('avatar/upload');
elgg_register_action('avatar/crop');
+ elgg_register_action('profile/edit');
//elgg_register_action('friends/addcollection');
//elgg_register_action('friends/deletecollection');
@@ -1683,5 +1763,6 @@ function users_test($hook, $type, $value, $params) {
}
elgg_register_event_handler('init', 'system', 'users_init', 0);
+elgg_register_event_handler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins
elgg_register_event_handler('pagesetup', 'system', 'users_pagesetup', 0);
elgg_register_plugin_hook_handler('unit_test', 'system', 'users_test'); \ No newline at end of file
diff --git a/languages/en.php b/languages/en.php
index 9cde25c18..85c3861d7 100644
--- a/languages/en.php
+++ b/languages/en.php
@@ -379,6 +379,9 @@ $english = array(
'avatar:crop:success' => 'Cropping the avatar succeeded',
'avatar:crop:fail' => 'Avatar cropping failed',
+ 'profile:edit' => 'Edit profile',
+
+
/**
* Feeds
*/
diff --git a/mod/profile/start.php b/mod/profile/start.php
index 4c24c2b50..8ae16cfb5 100644
--- a/mod/profile/start.php
+++ b/mod/profile/start.php
@@ -135,6 +135,9 @@ function profile_page_handler($page) {
switch ($action) {
case 'edit':
+ require $CONFIG->path . 'pages/profile/edit.php';
+ return;
+ /*
$layout = 'one_column_with_sidebar';
if (!$user || !$user->canEdit()) {
@@ -144,6 +147,8 @@ function profile_page_handler($page) {
$content = profile_get_user_edit_content($user, $page);
$content = elgg_view_layout($layout, array('content' => $content));
+ *
+ */
break;
default:
diff --git a/pages/avatar/edit.php b/pages/avatar/edit.php
index a577170a0..5e44eb4b0 100644
--- a/pages/avatar/edit.php
+++ b/pages/avatar/edit.php
@@ -6,6 +6,8 @@
// Only logged in users
gatekeeper();
+elgg_set_context('profile_edit');
+
$title = elgg_echo('avatar:edit');
$content = elgg_view('core/avatar/upload', array('entity' => elgg_get_page_owner()));
diff --git a/pages/profile/edit.php b/pages/profile/edit.php
new file mode 100644
index 000000000..64ffd7dc5
--- /dev/null
+++ b/pages/profile/edit.php
@@ -0,0 +1,32 @@
+<?php
+/**
+ * Edit profile page
+ */
+
+gatekeeper();
+
+$user = elgg_get_page_owner();
+if (!$user) {
+ register_error(elgg_echo("profile:notfound"));
+ forward();
+}
+
+// check if logged in user can edit this profile
+if (!$user->canEdit()) {
+ register_error(elgg_echo("profile:noaccess"));
+ forward();
+}
+
+elgg_set_context('profile_edit');
+
+$title = elgg_echo('profile:edit');
+
+$content = elgg_view_form('profile/edit', array(), array('entity' => $user));
+
+$params = array(
+ 'content' => $content,
+ 'title' => $title,
+);
+$body = elgg_view_layout('one_sidebar', $params);
+
+echo elgg_view_page($title, $body);
diff --git a/views/default/forms/profile/edit.php b/views/default/forms/profile/edit.php
new file mode 100644
index 000000000..c9117c8e7
--- /dev/null
+++ b/views/default/forms/profile/edit.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Edit profile form
+ *
+ * @uses vars['entity']
+ */
+
+?>
+
+<p>
+ <label><?php echo elgg_echo('user:name:label'); ?></label>
+ <?php echo elgg_view('input/text',array('internalname' => 'name', 'value' => $vars['entity']->name)); ?>
+</p>
+<?php
+
+$profile_fields = elgg_get_config('profile');
+if (is_array($profile_fields) && count($profile_fields) > 0) {
+ foreach ($profile_fields as $shortname => $valtype) {
+ $metadata = get_metadata_byname($vars['entity']->guid, $shortname);
+ if ($metadata) {
+ if (is_array($metadata)) {
+ $value = '';
+ foreach ($metadata as $md) {
+ if (!empty($value)) {
+ $value .= ', ';
+ }
+ $value .= $md->value;
+ $access_id = $md->access_id;
+ }
+ } else {
+ $value = $metadata->value;
+ $access_id = $metadata->access_id;
+ }
+ } else {
+ $value = '';
+ $access_id = ACCESS_DEFAULT;
+ }
+
+?>
+<p>
+ <label><?php echo elgg_echo("profile:{$shortname}") ?></label>
+ <?php
+ $params = array(
+ 'internalname' => $shortname,
+ 'value' => $value,
+ );
+ echo elgg_view("input/{$valtype}", $params);
+ $params = array(
+ 'internalname' => "accesslevel[$shortname]",
+ 'value' => $access_id,
+ );
+ echo elgg_view('input/access', $params);
+ ?>
+</p>
+<?php
+ }
+}
+?>
+<p>
+<?php
+ echo elgg_view('input/hidden', array('internalname' => 'guid', 'value' => $vars['entity']->guid));
+ echo elgg_view('input/submit', array('value' => elgg_echo('save')));
+?>
+</p>