/** * Save the wire_tools preferences for the user * * @param string $hook the name of the hook * @param stirng $type the type of the hook * @param array $return_value the current return value * @param array $params supplied values * * @return void */ public static function saveUserNotificationsSettings($hook, $type, $return_value, $params) { $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods(); if (empty($NOTIFICATION_HANDLERS) || !is_array($NOTIFICATION_HANDLERS)) { return; } $user_guid = (int) get_input('guid'); if (empty($user_guid)) { return; } $user = get_user($user_guid); if (empty($user) || !$user->canEdit()) { return; } $methods = []; foreach ($NOTIFICATION_HANDLERS as $method) { $setting = get_input("thewire_tools_{$method}"); if (!empty($setting)) { $methods[] = $method; } } if (!empty($methods)) { elgg_set_plugin_user_setting('notification_settings', implode(',', $methods), $user->getGUID(), 'thewire_tools'); } else { elgg_unset_plugin_user_setting('notification_settings', $user->getGUID(), 'thewire_tools'); } // set flag for correct fallback behaviour elgg_set_plugin_user_setting('notification_settings_saved', '1', $user->getGUID(), 'thewire_tools'); }
/** * Listen to the leave site event * * @param string $event the name of the event * @param string $type the type of the event * @param mixed $object supplied object * * @return void */ function theme_haarlem_intranet_site_leave_event($event, $type, $object) { if (empty($object) || !$object instanceof ElggRelationship) { return; } // disable mentions notifications for the leaving user $user_guid = (int) $object->guid_one; elgg_set_plugin_user_setting('notify', '0', $user_guid, 'mentions'); }
/** * Save the authenticaion attributes provided by the Service Provider (SP) for later use. * * @param ElggUser $user the user to store the attributes for * @param string $saml_source the name of the Service Provider which provided the attributes * @param array|false $attributes the attributes to save, false to remove all attributes * * @return void */ function simplesaml_save_authentication_attributes(ElggUser $user, $saml_source, $attributes = false) { if (!$user instanceof ElggUser || empty($saml_source) || !simplesaml_is_enabled_source($saml_source)) { return; } // remove the current attributes elgg_unset_plugin_user_setting("{$saml_source}_attributes", $user->getGUID(), 'simplesaml'); if (empty($attributes)) { // no new attributes to save return; } // are we allowed to save the attributes if (elgg_get_plugin_setting("{$saml_source}_save_attributes", 'simplesaml')) { // filter some keys out of the attributes unset($attributes["elgg:firstname"]); unset($attributes["elgg:lastname"]); unset($attributes["elgg:email"]); unset($attributes["elgg:external_id"]); unset($attributes["elgg:username"]); unset($attributes["elgg:auto_link"]); // save attributes elgg_set_plugin_user_setting("{$saml_source}_attributes", json_encode($attributes), $user->getGUID(), 'simplesaml'); } }
$useremail = $user_profile->email; $user = new ElggUser(); $user->username = $userlogin; $user->name = $username; $user->access_id = ACCESS_PUBLIC; $user->email = $user_profile->email; $user->salt = generate_random_cleartext_password(); $user->password = generate_user_password($user, $password); $user->owner_guid = 0; $user->container_guid = 0; if (!$user->save()) { register_error(elgg_echo('registerbad')); } // register user && provider elgg_set_plugin_user_setting('uid', $user_uid, $user->guid, 'elgg_social_login'); elgg_set_plugin_user_setting('provider', $provider, $user->guid, 'elgg_social_login'); // notice && login if (elgg_get_plugin_setting("social_login_notify", "social_login") == "yes") { if (strtolower($provider) == "facebook" || strtolower($provider) == "linkedin") { if (empty($user->last_login)) { $message = elgg_echo('social:register:joined'); $adapter->setUserStatus($message); } } } system_message(elgg_echo('A new user account has been created from your ' . $provider . ' account.')); login($user); # {{{ update user profile // access_id 1 => Logged in users // 1. About me create_metadata($user->guid, "description", html_entity_decode($user_profile->description, ENT_COMPAT, 'UTF-8'), "text", $user->guid, 1);
/** * Save the content subscriptions preferences for the user * * @param string $hook the name of the hook * @param stirng $type the type of the hook * @param array $return_value the current return value * @param array $params supplied values * * @return void */ function content_subscriptions_notifications_settings_save_hook($hook, $type, $return_value, $params) { $NOTIFICATION_HANDLERS = _elgg_services()->notifications->getMethods(); if (empty($NOTIFICATION_HANDLERS) || !is_array($NOTIFICATION_HANDLERS)) { return; } $user_guid = (int) get_input("guid"); if (empty($user_guid)) { return; } $user = get_user($user_guid); if (empty($user) || !$user->canEdit()) { return; } $methods = array(); foreach ($NOTIFICATION_HANDLERS as $method) { $setting = get_input("content_subscriptions_" . $method); if (!empty($setting)) { $methods[] = $method; } } if (!empty($methods)) { elgg_set_plugin_user_setting("notification_settings", implode(",", $methods), $user->getGUID(), "content_subscriptions"); } else { elgg_unset_plugin_user_setting("notification_settings", $user->getGUID(), "content_subscriptions"); } // set flag for correct fallback behaviour elgg_set_plugin_user_setting("notification_settings_saved", "1", $user->getGUID(), "content_subscriptions"); }
if ($photo_url) { $icon_sizes = elgg_get_config('icon_sizes'); $filehandler = new ElggFile(); $filehandler->owner_guid = $new_user->guid; foreach ($icon_sizes as $size => $dimensions) { $image = get_resized_image_from_existing_file($photo_url, $dimensions[0], $dimensions[1], $dimensions[2]); $image = get_resized_image_from_existing_file($photo_url, $dimensions['w'], $dimensions['h'], $dimensions['square'], 0, 0, 0, 0, $dimensions['upscale']); $filehandler->setFilename("profile/{$new_user->guid}{$size}.jpg"); $filehandler->open('write'); $filehandler->write($image); $filehandler->close(); } $new_user->icontime = time(); } if ($provider && $provider_uid) { elgg_set_plugin_user_setting("{$provider}:uid", $provider_uid, $new_user->guid, 'elgg_hybridauth'); elgg_trigger_plugin_hook('hybridauth:authenticate', $provider, array('entity' => $new_user)); } $params = array_merge($params, $metadata); // @todo should registration be allowed no matter what the plugins return? if (!elgg_trigger_plugin_hook('register', 'user', $params, TRUE)) { $ia = elgg_set_ignore_access(true); $new_user->delete(); elgg_set_ignore_access($ia); // @todo this is a generic messages. We could have plugins // throw a RegistrationException, but that is very odd // for the plugin hooks system. throw new RegistrationException(elgg_echo('registerbad')); } $subject = elgg_echo('useradd:subject'); $body = elgg_echo('useradd:body', array($name, elgg_get_site_entity()->name, elgg_get_site_entity()->url, $username, $password));
/** * User-initiated Twitter authorization * * Callback action from Twitter registration. Registers a single Elgg user with * the authorization tokens. Will revoke access from previous users when a * conflict exists. * * Depends upon {@link twitter_api_get_authorize_url} being called previously * to establish session request tokens. */ function twitter_api_authorize() { $token = twitter_api_get_access_token(get_input('oauth_verifier')); if (!isset($token['oauth_token']) || !isset($token['oauth_token_secret'])) { register_error(elgg_echo('twitter_api:authorize:error')); forward('settings/plugins', 'twitter_api'); } // make sure no other users are registered to this twitter account. $options = array('type' => 'user', 'plugin_id' => 'twitter_api', 'plugin_user_setting_name_value_pairs' => array('access_key' => $token['oauth_token'], 'access_secret' => $token['oauth_token_secret']), 'limit' => 0); $users = elgg_get_entities_from_plugin_user_settings($options); /* @var ElggUser[] $users */ if ($users) { foreach ($users as $user) { // revoke access elgg_unset_plugin_user_setting('twitter_name', $user->getGUID(), 'twitter_api'); elgg_unset_plugin_user_setting('access_key', $user->getGUID(), 'twitter_api'); elgg_unset_plugin_user_setting('access_secret', $user->getGUID(), 'twitter_api'); } } // register user's access tokens elgg_set_plugin_user_setting('twitter_name', $token['screen_name'], 0, 'twitter_api'); elgg_set_plugin_user_setting('access_key', $token['oauth_token'], 0, 'twitter_api'); elgg_set_plugin_user_setting('access_secret', $token['oauth_token_secret'], 0, 'twitter_api'); // trigger authorization hook elgg_trigger_plugin_hook('authorize', 'twitter_api', array('token' => $token)); system_message(elgg_echo('twitter_api:authorize:success')); forward('settings/plugins', 'twitter_api'); }
/** * Prevents users from joining a subgroup if they're not a member of the parent * * @param type $event * @param type $type * @param ElggRelationship $object * @return boolean */ function au_subgroups_join_group($event, $type, $object) { if ($object instanceof ElggRelationship) { $user = get_entity($object->guid_one); $group = get_entity($object->guid_two); $parent = au_subgroups_get_parent_group($group); // use temp global config to decide if we should prevent joining // prevent joining if not a member of the parent group // except during a subgroup move invitation $au_subgroups_ignore_join = elgg_get_config('au_subgroups_ignore_join'); if ($parent && !$au_subgroups_ignore_join) { // cover the case of moved subgroups // user will have been invited, and have a plugin setting saying which other groups to join $invited = check_entity_relationship($group->guid, 'invited', $user->guid); $children_to_join = elgg_get_plugin_user_setting('invitation_' . $group->guid, $user->guid, 'au_subgroups'); if (!empty($children_to_join)) { $children_to_join = unserialize($children_to_join); } if ($invited) { elgg_set_config('au_subgroups_ignore_join', true); // we have been invited in through the back door by a subgroup move // join this user to all parent groups fo this group if (au_subgroups_join_parents_recursive($group, $user)) { // we're in, now lets rejoin the children if (is_array($children_to_join)) { $children_guids = au_subgroups_get_all_children_guids($group); foreach ($children_to_join as $child) { if (in_array($child, $children_guids)) { $child_group = get_entity($child); $child_group->join($user); } } } // delete plugin setting elgg_set_plugin_user_setting('invitation_' . $group->guid, '', $user->guid, 'au_subgroups'); } else { // something went wrong with joining the groups // lets stop everything now return false; } } elseif (!$parent->isMember($user)) { register_error(elgg_echo('au_subgroups:error:notparentmember')); return false; } } } }
/** * Adds auth records that signify that user is connected to the provider * * @param \Elgg\HybridAuth\Provider $provider Provider * @param mixed $profile Profile object or id * @return bool */ public function addAuthRecord(Provider $provider, $profile) { if ($this->handle == Session::DEFAULT_HANDLE) { elgg_trigger_plugin_hook('hybridauth:authenticate', $provider->getName(), array('provider' => $provider, 'entity' => $this->user, 'profile' => $profile)); } else { elgg_trigger_plugin_hook('hybridauth:authenticate:session', $provider->getName(), array('profile' => $profile, 'provider' => $provider, 'session' => $this)); } $uid = is_object($profile) ? $profile->identifier : $profile; return elgg_set_plugin_user_setting($this->getAuthRecordName($provider), $uid, $this->user->guid, 'elgg_hybridauth'); }
} else { elgg_unset_plugin_user_setting('background_fixed', $user->guid, 'deyan'); } elgg_set_plugin_user_setting('background', $background, $user->guid, 'deyan'); $custom = get_input('background_custom'); if ($custom) { elgg_set_plugin_user_setting('background_custom', 1, $user->guid, 'deyan'); } else { elgg_unset_plugin_user_setting('background_custom', $user->guid, 'deyan'); } /* Use windows scroll */ $scroll = get_input('window_scroll'); if ($scroll) { elgg_set_plugin_user_setting('window_scroll', 1, $user->guid, 'deyan'); } else { elgg_unset_plugin_user_setting('window_scroll', $user->guid, 'deyan'); } /****************************** UPGRADE SIMPLECACHE ******************************/ elgg_regenerate_simplecache();
/** * User-initiated facebook authorization * * Callback action from facebook registration. Registers a single Elgg user with * the authorization tokens. Will revoke access from previous users when a * conflict exists. * */ function facebook_connect_authorize() { $facebook = facebookservice_api(); $access_token = $facebook->getAccessToken(); if (!($userID = $facebook->getUser())) { register_error(elgg_echo('facebook_connect:authorize:error')); forward('settings/plugins', 'facebook_connect'); } // make sure no other users are registered to this facebook account. $options = array('type' => 'user', 'plugin_user_setting_name_value_pairs' => array('uid' => $userID, 'access_token' => $access_token), 'plugin_user_setting_name_value_pairs_operator' => 'OR', 'limit' => 0); $users = elgg_get_entities_from_plugin_user_settings($options); if ($users) { foreach ($users as $user) { // revoke access elgg_unset_plugin_user_setting('uid', $user->getGUID()); elgg_unset_plugin_user_setting('access_token', $user->getGUID()); } } // register user's access tokens elgg_set_plugin_user_setting('uid', $userID); elgg_set_plugin_user_setting('access_token', $access_token); system_message(elgg_echo('facebook_connect:authorize:success')); forward('settings/plugins', 'facebook_connect'); }
function social_connect_user($user_uid, $user, $user_profile, $provider) { // register user && provider elgg_set_plugin_user_setting("{$provider}/uid", $user_uid, $user->guid, 'social_connect'); login($user); # {{{ user image if ($user_profile->photoURL) { $sizes = array('topbar' => array(16, 16, TRUE), 'tiny' => array(25, 25, TRUE), 'small' => array(40, 40, TRUE), 'medium' => array(100, 100, TRUE), 'large' => array(200, 200, FALSE), 'master' => array(550, 550, FALSE)); $filehandler = new ElggFile(); $filehandler->owner_guid = $user->guid; foreach ($sizes as $size => $dimensions) { $image = get_resized_image_from_existing_file($user_profile->photoURL, $dimensions[0], $dimensions[1], $dimensions[2]); $filehandler->setFilename("profile/{$user->guid}{$size}.jpg"); if (!$filehandler->exists()) { $filehandler->open('write'); $filehandler->write($image); $filehandler->close(); } } $user->icontime = time(); } # }}} user image }
/** * Create a user based on Facebook information * * @param string $token Facebook access token * * @return bool|ElggUser */ function socialink_facebook_create_user($token) { if (empty($token)) { return false; } if (!socialink_facebook_available()) { return false; } $session = new Facebook\FacebookSession($token); if (empty($session)) { return false; } $request = new FaceBook\FacebookRequest($session, "GET", "/me"); // set correct proxy settings (if needed) $curl_http_client = socialink_facebook_get_curl_http_client(); $request->setHttpClientHandler($curl_http_client); try { $api_result = $request->execute()->getGraphObject(Facebook\GraphUser::className()); } catch (Exception $e) { } if (empty($api_result)) { return false; } // get user information $name = $api_result->getName(); $email = $api_result->getEmail(); if (get_user_by_email($email)) { register_error(elgg_echo("socialink:networks:create_user:error:email")); return false; } $pwd = generate_random_cleartext_password(); $username = socialink_create_username_from_email($email); try { $user_guid = register_user($username, $pwd, $name, $email); if (empty($user_guid)) { return false; } // show hidden entities $access = access_get_show_hidden_status(); access_show_hidden_entities(true); $user = get_user($user_guid); if (empty($user)) { access_show_hidden_entities($access); return false; } // register user's access tokens elgg_set_plugin_user_setting("facebook_access_token", $token, $user_guid, "socialink"); elgg_set_plugin_user_setting("facebook_user_id", $api_result->getId(), $user_guid, "socialink"); // no need for uservalidationbyemail elgg_unregister_plugin_hook_handler("register", "user", "uservalidationbyemail_disable_new_user"); // sync user data socialink_facebook_sync_profile_metadata($user->getGUID()); // trigger hook for registration $params = array("user" => $user, "password" => $pwd, "friend_guid" => 0, "invitecode" => ""); if (elgg_trigger_plugin_hook("register", "user", $params, true) !== false) { access_show_hidden_entities($access); // return the user return $user; } // restore hidden entities access_show_hidden_entities($access); } catch (Exception $e) { } return false; }
<?php set_time_limit(0); $options = array('type' => 'user', 'plugin_id' => 'elgg_social_login', 'plugin_user_setting_names' => array('uid'), 'limit' => 0); $users = new ElggBatch('elgg_get_entities_from_plugin_user_settings', $options); foreach ($users as $user) { $setting = elgg_get_plugin_user_setting('uid', $user->guid, 'elgg_social_login'); list($provider, $uid) = explode('_', $setting); // Check to see if another record has been created with elgg_hybridauth $elgg_hybridauth_options = array('type' => 'user', 'plugin_id' => 'elgg_hybridauth', 'plugin_user_setting_name_value_pairs' => array("{$provider}:uid" => $uid), 'limit' => 0); $elgg_hybridauth_users = elgg_get_entities_from_plugin_user_settings($elgg_hybridauth_options); if ($elgg_hybridauth_users) { $elgg_hybridauth_user = $elgg_hybridauth_users[0]; if ($user->time_created < $elgg_hybridauth_user->time_created) { // elgg_social_login user was created earlier, so give that user the ability to login in with this provider uid elgg_unset_plugin_user_setting("{$provider}:uid", $elgg_hybridauth_user->guid, 'elgg_hybridauth'); } } else { elgg_set_plugin_user_setting("{$provider}:uid", $uid, $user->guid, 'elgg_hybridauth'); } // keep a backup record elgg_unset_plugin_user_setting('uid', $user->guid, 'elgg_social_login'); elgg_set_plugin_user_setting('elgg_social_login_uid', "{$provider}_{$uid}", 'elgg_hybridauth'); $i++; } system_message(elgg_echo('hybridauth:admin:elgg_social_login:action', array($i))); forward(REFERER);
$thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } /** * Set file folder guids as plugin setting */ $folders = new ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjfilefolder', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjwall'), 'limit' => false)); foreach ($folders as $folder) { elgg_set_plugin_user_setting('wall_collection', $folder->guid, $folder->owner_guid, PLUGIN_ID); } /** * Convert 'hjfilefolder' to 'wall_collection' */ $subtypeIdFrom = add_subtype('object', 'hjfilefolder'); $subtypeIdTo = add_subtype('object', 'wallcollection'); $dbprefix = elgg_get_config('dbprefix'); $query = "\tUPDATE {$dbprefix}entities e\r\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = e.guid\r\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\r\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\r\n\t\t\t\tSET e.subtype = {$subtypeIdTo}\r\n\t\t\t\tWHERE e.subtype = {$subtypeIdFrom} AND msn.string = 'handler' AND msv.string = 'hjwall' "; elgg_set_ignore_access($ia);
<?php $user = elgg_get_logged_in_user_entity(); if (empty($user)) { return; } if (theme_haarlem_intranet_sidebar_collapsed()) { elgg_unset_plugin_user_setting('sidebar_collapsed', $user->guid, 'theme_haarlem_intranet'); } else { elgg_set_plugin_user_setting('sidebar_collapsed', true, $user->guid, 'theme_haarlem_intranet'); }
<?php $user_guid = (int) get_input('user_guid'); $user = get_user($user_guid); if (empty($user)) { register_error(elgg_echo('error:missing_data')); forward(REFERER); } if ($user->isAdmin()) { register_error(elgg_echo('site_announcements:action:toggle_editor:error:is_admin', array($user->name))); forward(REFERER); } if (site_announcements_is_editor($user)) { elgg_unset_plugin_user_setting('editor', $user->getGUID(), 'site_announcements'); system_message(elgg_echo('site_announcements:action:toggle_editor:unmake', array($user->name))); } else { elgg_set_plugin_user_setting('editor', time(), $user->getGUID(), 'site_announcements'); system_message(elgg_echo('site_announcements:action:toggle_editor:make', array($user->name))); } forward(REFERER);
/** * Save mentions-specific info from the notification form * * @param type $hook * @param type $type * @param type $value * @param type $params */ function mentions_save_settings($hook, $type, $value, $params) { $notify = (bool) get_input('mentions_notify'); $user = get_entity(get_input('guid')); if (!elgg_set_plugin_user_setting('notify', $notify, $user->getGUID(), 'mentions')) { register_error(elgg_echo('mentions:settings:failed')); } return; }
<?php $tags = get_input("tags"); $user_guid = (int) get_input("user_guid"); if (empty($user_guid)) { register_error(elgg_echo("error:missing_data")); forward(REFERER); } $user = get_user($user_guid); if (empty($user) || !elgg_instanceof($user, "user")) { register_error(elgg_echo("error:missing_data")); forward(REFERER); } if (!$user->canEdit()) { register_error(elgg_echo("noaccess")); forward(REFERER); } if (empty($tags)) { elgg_unset_plugin_user_setting("notifications", $user->getGUID(), "tags_tools"); } else { elgg_set_plugin_user_setting("notifications", json_encode($tags), $user->getGUID(), "tag_tools"); } system_message(elgg_echo("save:success")); forward(REFERER);
/** * The socialink page handler * * @param array $page page elements * * @return bool */ function socialink_page_handler($page) { $result = false; switch ($page[0]) { case "authorize": elgg_gatekeeper(); $user = elgg_get_logged_in_user_entity(); switch ($page[1]) { case "twitter": case "linkedin": case "facebook": case "wordpress": if (call_user_func("socialink_" . $page[1] . "_authorize")) { system_message(elgg_echo("socialink:authorize:success", array(elgg_echo("socialink:network:" . $page[1])))); } else { register_error(elgg_echo("socialink:authorize:failed", array(elgg_echo("socialink:network:" . $page[1])))); } break; } if (!empty($page[1]) && socialink_is_available_network($page[1])) { elgg_trigger_plugin_hook("socialink:sync", "user", array("user" => $user, "network" => $page[1])); } forward("settings/plugins/" . $user->username . "/socialink"); break; case "login": if (elgg_is_logged_in() || !isset($page[1])) { // invalid input forward(); } $network = $page[1]; $network_name = elgg_echo("socialink:network:" . $network); $error_msg_no_user = elgg_echo("socialink:login:error:no_user", array($network_name, $network_name)); if (!socialink_is_available_network($network)) { // unavailable network forward(); } // find hidden users (just created) $access_status = access_get_show_hidden_status(); access_show_hidden_entities(true); switch ($network) { case "twitter": $token = socialink_twitter_get_access_token(get_input("oauth_verifier")); if (!isset($token["oauth_token"]) || !isset($token["oauth_token_secret"])) { register_error($error_msg_no_user); break; } $params = array("type" => "user", "limit" => 1, "site_guids" => false, "plugin_id" => "socialink", "plugin_user_setting_name_value_pairs" => array("twitter_oauth_token" => $token["oauth_token"], "twitter_oauth_secret" => $token["oauth_token_secret"])); $users = elgg_get_entities_from_plugin_user_settings($params); if (!empty($users)) { $user = $users[0]; } else { $_SESSION["socialink_token"] = $token; forward("socialink/no_linked_account/twitter"); } break; case "linkedin": $token = socialink_linkedin_get_access_token(get_input("oauth_verifier")); if (!isset($token["oauth_token"]) || !isset($token["oauth_token_secret"])) { register_error($error_msg_no_user); break; } $params = array("type" => "user", "limit" => 1, "site_guids" => false, "plugin_id" => "socialink", "plugin_user_setting_name_value_pairs" => array("linkedin_oauth_token" => $token["oauth_token"], "linkedin_oauth_secret" => $token["oauth_token_secret"])); $users = elgg_get_entities_from_plugin_user_settings($params); if (!empty($users)) { $user = $users[0]; } else { $_SESSION["socialink_token"] = $token; forward("socialink/no_linked_account/linkedin"); } break; case "facebook": $token = socialink_facebook_get_access_token(); if (empty($token)) { register_error($error_msg_no_user); break; } $user_id = socialink_facebook_get_user_id_from_access_token($token); if (empty($user_id)) { register_error($error_msg_no_user); break; } $params = array("type" => "user", "limit" => 1, "site_guids" => false, "plugin_id" => "socialink", "plugin_user_setting_name_value_pairs" => array("facebook_user_id" => $user_id)); $users = elgg_get_entities_from_plugin_user_settings($params); if (!empty($users)) { $user = $users[0]; } else { $_SESSION["socialink_token"] = $token; forward("socialink/no_linked_account/facebook"); } break; case "wordpress": $token = socialink_wordpress_get_access_token(get_input("oauth_token")); if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) { if ($userdata = socialink_wordpress_get_user_data_from_token($token)) { $params = array("type" => "user", "limit" => 1, "site_guids" => false, "plugin_id" => "socialink", "plugin_user_setting_name_value_pairs" => array("wordpress_userid" => $userdata->ID)); if ($users = elgg_get_entities_from_plugin_user_settings($params)) { $user = $users[0]; socialink_wordpress_update_connection($token, $user->getGUID()); } else { $_SESSION["socialink_token"] = $token; forward("socialink/no_linked_account/wordpress"); } } } else { register_error($error_msg_no_user); } break; } if (!empty($user) && elgg_instanceof($user, "user")) { try { // permanent login login($user, true); // log last network elgg_set_plugin_user_setting("last_login_network", $network, $user->getGUID(), "socialink"); // sync network data elgg_trigger_plugin_hook("socialink:sync", "user", array("user" => $user, "network" => $network)); // set message and forward to correct page system_message(elgg_echo("loginok")); if (isset($_SESSION["last_forward_from"]) && $_SESSION["last_forward_from"]) { $forward_url = $_SESSION["last_forward_from"]; unset($_SESSION["last_forward_from"]); forward($forward_url); } elseif (get_input("returntoreferer")) { forward(REFERER); } else { forward(); } } catch (LoginException $e) { // validation mechanisme should report that you are not authenticated. Currently uservalidation by email doesn't do that //register_error($e->getMessage()); forward(); } } // restore hidden status access_show_hidden_entities($access_status); forward(); break; case "no_linked_account": if (elgg_is_logged_in()) { forward(); } switch ($page[1]) { case "linkedin": case "facebook": case "twitter": case "wordpress": $result = true; set_input("network", $page[1]); include dirname(dirname(__FILE__)) . "/pages/no_linked_account.php"; break; } break; case "share": elgg_gatekeeper(); $result = true; include dirname(dirname(__FILE__)) . "/pages/share.php"; break; case "forward": if (!isset($page[1]) && !isset($page[2])) { // invalid input break; } $network = $page[1]; $action = $page[2]; $allowed_actions = array("login", "authorize"); if (!socialink_is_available_network($network) || !in_array($action, $allowed_actions)) { // unavailable network or unsupported action break; } if ($action == "login") { socialink_prepare_login(); } $callback_url = elgg_get_site_url() . "socialink/" . $action . "/" . $network; $forward_url = ""; switch ($network) { case "linkedin": $forward_url = socialink_linkedin_get_authorize_url($callback_url); break; case "facebook": $forward_url = socialink_facebook_get_authorize_url($callback_url); break; case "twitter": $forward_url = socialink_twitter_get_authorize_url($callback_url); break; case "wordpress": $forward_url = socialink_wordpress_get_authorize_url($callback_url); break; } forward($forward_url); break; } return $result; }
<?php /** * Ssend a message action * * @package ElggMessages */ $limit = get_input('limit'); $excerpt = get_input('excerpt'); $user_guid = elgg_get_logged_in_user_guid(); if (!elgg_set_plugin_user_setting('limit', $limit, $user_guid, 'messages')) { register_error(elgg_echo("messages:settings:failed")); forward(REFERER); } if ($excerpt == 1) { if (!elgg_set_plugin_user_setting('excerpt', 1, $user_guid, 'messages')) { register_error(elgg_echo("messages:settings:failed")); forward(REFERER); } } else { elgg_set_plugin_user_setting('excerpt', 0, $user_guid, 'messages'); } system_message(elgg_echo('messages:settings:saved')); forward(REFERER);
/** * Save the authenticaion attributes provided by the Service Provider (SP) for later use. * * @param ElggUser $user the user to store the attributes for * @param string $saml_source the name of the Service Provider which provided the attributes * @param array|false $attributes the attributes to save, false to remove all attributes * * @return void */ function simplesaml_save_authentication_attributes(ElggUser $user, $saml_source, $attributes = false) { if (!empty($user) && elgg_instanceof($user, "user") && !empty($saml_source) && simplesaml_is_enabled_source($saml_source)) { // remove the current attrributes elgg_unset_plugin_user_setting($saml_source . "_attributes", $user->getGUID(), "simplesaml"); // are we allowed to save the attributes if (elgg_get_plugin_setting($saml_source . "_save_attributes", "simplesaml")) { // save settings if (!empty($attributes) && is_array($attributes)) { // filter some keys out of the attributes unset($attributes["elgg:firstname"]); unset($attributes["elgg:lastname"]); unset($attributes["elgg:email"]); unset($attributes["elgg:external_id"]); unset($attributes["elgg:username"]); unset($attributes["elgg:auto_link"]); elgg_set_plugin_user_setting($saml_source . "_attributes", json_encode($attributes), $user->getGUID(), "simplesaml"); } } } }
/** * Used to create user with facebook data * * @access public * @param array $fbData facebook data of user * @return void */ function facebook_connect_create_update_user($fbData) { elgg_load_library('facebook'); // need facebook account credentials // backward compatibility for stalled-development FBConnect plugin $user = FALSE; $facebook_users = elgg_get_entities_from_metadata(array('type' => 'user', 'metadata_name_value_pairs' => array('name' => 'facebook_uid', 'value' => $fbData['user_profile']['id']))); if (is_array($facebook_users) && count($facebook_users) == 1) { // convert existing account $user = $facebook_users[0]; // remove unused metadata remove_metadata($user->getGUID(), 'facebook_uid'); remove_metadata($user->getGUID(), 'facebook_controlled_profile'); } // create new user if (!$user) { // check new registration allowed if (!facebook_connect_allow_new_users_with_facebook()) { register_error(elgg_echo('registerdisabled')); forward(); } $email = $fbData['user_profile']['email']; $users = get_user_by_email($email); if (!$users) { // Elgg-ify facebook credentials if (!empty($fbData['user_profile']['username'])) { $username = $fbData['user_profile']['username']; } else { $username = str_replace(' ', '', strtolower($fbData['user_profile']['name'])); } $usernameTmp = $username; while (get_user_by_username($username)) { $username = $usernameTmp . '_' . rand(1000, 9999); } $password = generate_random_cleartext_password(); $name = $fbData['user_profile']['name']; $user = new ElggUser(); $user->username = $username; $user->name = $name; $user->email = $email; $user->access_id = ACCESS_PUBLIC; $user->salt = generate_random_cleartext_password(); $user->password = generate_user_password($user, $password); $user->owner_guid = 0; $user->container_guid = 0; $user->last_action = date("Y-m-d"); $user->last_login = date("Y-m-d"); $user->validated = 1; $user->validated_method = 'facebook'; $user->language = 'en'; if (!$user->save()) { register_error(elgg_echo('registerbad')); forward(); } else { // send mail to user send_user_password_mail($email, $name, $username, $password); // post status on facebook if (facebook_connect_allow_post_on_facebook()) { facebook_connect_post_status($fbData); } // pull in facebook icon $url = 'https://graph.facebook.com/' . $fbData['user_profile']['id'] . '/picture?type=large'; facebook_connect_update_user_avatar($user, $url); } } else { $user = $users[0]; } } // set facebook services tokens elgg_set_plugin_user_setting('uid', $fbData['user_profile']['id'], $user->guid); elgg_set_plugin_user_setting('access_token', $fbData['user_profile']['accessToken'], $user->guid); return $user; }
<?php /** * Provides links and notifications for using @username mentions * * @package Mentions * @author Curverider Ltd <*****@*****.**> * @copyright Curverider Ltd 2008-2010 * @link http://elgg.com/ */ $user = elgg_get_logged_in_user_entity(); if (FALSE === elgg_get_plugin_user_setting('notify', $user->getGUID(), 'mentions')) { elgg_set_plugin_user_setting('notify', TRUE, $user->getGUID(), 'mentions'); } $notify_label = elgg_echo('mentions:settings:send_notification'); $notify_field = elgg_view('input/dropdown', array('name' => 'params[notify]', 'options_values' => array(1 => elgg_echo('option:yes'), 0 => elgg_echo('option:no')), 'value' => elgg_get_plugin_user_setting('notify', $user->getGUID(), 'mentions'))); echo <<<___END <p> \t<label>{$notify_label}: {$notify_field}</label> </p> ___END ;
/** * Create a user based on LinkedIn information * * @param string $token LinkedIn access token * * @return bool|ElggUser */ function socialink_linkedin_create_user($token) { if (empty($token) || !is_array($token)) { return false; } $keys = socialink_linkedin_available(); if (empty($keys)) { return false; } $keys["oauth_token"] = $token["oauth_token"]; $keys["oauth_secret"] = $token["oauth_token_secret"]; $api = socialink_linkedin_get_api_object($keys); if (empty($api)) { return false; } try { // get user data $response = $api->profile("~:(first-name,last-name,email-address)"); } catch (Exception $e) { } $api_result = socialink_linkedin_verify_response($response); if (empty($api_result)) { return false; } $api_result = json_decode($api_result); // build user information $name = $api_result->firstName . " " . $api_result->lastName; $email = $api_result->emailAddress; $pwd = generate_random_cleartext_password(); $username = socialink_create_username_from_email($email); // check email address if (get_user_by_email($email)) { register_error(elgg_echo("socialink:networks:create_user:error:email")); return false; } try { // register user $user_guid = register_user($username, $pwd, $name, $email); if (empty($user_guid)) { return false; } // show hidden entities $access = access_get_show_hidden_status(); access_show_hidden_entities(true); $user = get_user($user_guid); if (empty($user)) { access_show_hidden_entities($access); return false; } // save user tokens elgg_set_plugin_user_setting("linkedin_oauth_token", $token["oauth_token"], $user_guid, "socialink"); elgg_set_plugin_user_setting("linkedin_oauth_secret", $token["oauth_token_secret"], $user_guid, "socialink"); // no need for uservalidationbyemail elgg_unregister_plugin_hook_handler("register", "user", "uservalidationbyemail_disable_new_user"); // sync user data socialink_linkedin_sync_profile_metadata($user->getGUID()); // trigger hook for registration $params = array("user" => $user, "password" => $pwd, "friend_guid" => 0, "invitecode" => ""); if (elgg_trigger_plugin_hook("register", "user", $params, true) !== false) { // return the user access_show_hidden_entities($access); return $user; } // restore hidden entities access_show_hidden_entities($access); } catch (Exception $e) { } return false; }
*/ $user_guid = (int) get_input('user_guid'); if (empty($user_guid) || $user_guid != elgg_get_logged_in_user_guid()) { register_error(elgg_echo('actionunauthorized')); forward(REFERER); } $user = get_user($user_guid); if (empty($user)) { forward(REFERER); } if (!admin_tools_is_admin_user($user)) { register_error(elgg_echo('actionunauthorized')); forward(REFERER); } if ($user->isAdmin()) { // make the user a normal user $secret = admin_tools_make_switch_admin_secret($user); if (!empty($secret)) { $user->removeAdmin(); elgg_set_plugin_user_setting('switched_admin', $secret, $user->getGUID(), 'admin_tools'); system_message(elgg_echo('admin_tools:action:toggle_admin:success:user')); } else { register_error(elgg_echo('save:fail')); } } else { // make the user an admin $user->makeAdmin(); elgg_unset_plugin_user_setting('switched_admin', $user->getGUID(), 'admin_tools'); system_message(elgg_echo('admin_tools:action:toggle_admin:success:admin')); } forward(REFERER);
/** * Updates the fixed widgets for a given context and user * * @param string $context context of the widgets * @param int $user_guid owner of the new widgets * * @return void */ function widget_manager_update_fixed_widgets($context, $user_guid) { // need to be able to access everything $old_ia = elgg_set_ignore_access(true); elgg_push_context('create_default_widgets'); $options = ['type' => 'object', 'subtype' => 'widget', 'owner_guid' => elgg_get_site_entity()->guid, 'private_setting_name_value_pairs' => ['context' => $context, 'fixed' => 1.0], 'limit' => false]; // see if there are configured fixed widgets $configured_fixed_widgets = elgg_get_entities_from_private_settings($options); widget_manager_sort_widgets_guid($configured_fixed_widgets); // fetch all currently configured widgets fixed AND not fixed $options['private_setting_name_value_pairs'] = ['context' => $context]; $options['owner_guid'] = $user_guid; $user_widgets = elgg_get_entities_from_private_settings($options); widget_manager_sort_widgets_guid($user_widgets); $default_widget_guids = []; // update current widgets if ($user_widgets) { foreach ($user_widgets as $guid => $widget) { $widget_fixed = $widget->fixed; $default_widget_guid = $widget->fixed_parent_guid; $default_widget_guids[] = $default_widget_guid; if (empty($default_widget_guid)) { continue; } if ($widget_fixed && !array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // remove fixed status $widget->fixed = false; } elseif (!$widget_fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // add fixed status $widget->fixed = true; } // need to recheck the fixed status as it could have been changed if ($widget->fixed && array_key_exists($default_widget_guid, $configured_fixed_widgets)) { // update settings for currently configured widgets // pull in settings $settings = get_all_private_settings($configured_fixed_widgets[$default_widget_guid]->guid); foreach ($settings as $name => $value) { $widget->{$name} = $value; } // access is no setting, but could also be controlled from the default widget $widget->access = $configured_fixed_widgets[$default_widget_guid]->access; // save the widget (needed for access update) $widget->save(); } } } // add new fixed widgets if ($configured_fixed_widgets) { foreach ($configured_fixed_widgets as $guid => $widget) { if (in_array($guid, $default_widget_guids)) { continue; } // if no widget is found which is already linked to this default widget, clone the widget to the user $new_widget = clone $widget; $new_widget->container_guid = $user_guid; $new_widget->owner_guid = $user_guid; // pull in settings $settings = get_all_private_settings($guid); foreach ($settings as $name => $value) { $new_widget->{$name} = $value; } $new_widget->save(); } } // fixing order on all columns for this context, fixed widgets should always stay on top of other 'free' widgets foreach ([1, 2, 3] as $column) { // reuse previous declared options with a minor adjustment $options['private_setting_name_value_pairs'] = ['context' => $context, 'column' => $column]; $column_widgets = elgg_get_entities_from_private_settings($options); $free_widgets = []; $max_fixed_order = 0; if ($column_widgets) { foreach ($column_widgets as $widget) { if ($widget->fixed) { if ($widget->order > $max_fixed_order) { $max_fixed_order = $widget->order; } } else { $free_widgets[] = $widget; } } if (!empty($max_fixed_order) && !empty($free_widgets)) { foreach ($free_widgets as $widget) { $widget->order += $max_fixed_order; } } } } // revert access elgg_set_ignore_access($old_ia); elgg_pop_context(); // set the user timestamp elgg_set_plugin_user_setting($context . '_fixed_ts', time(), $user_guid, 'widget_manager'); }
/** * called during pagesetup * * @return void */ function theme_eersel_pagesetup() { if (!elgg_is_logged_in()) { return; } $user = elgg_get_logged_in_user_entity(); // store last page view in session for further use if (!isset($_SESSION['theme_eersel_activity_last_action'])) { $plugin_setting = (int) elgg_get_plugin_user_setting('river_last_view', $user->getGUID(), 'theme_eersel'); if (!empty($plugin_setting)) { $_SESSION['theme_eersel_activity_last_action'] = $plugin_setting; } } elgg_set_plugin_user_setting('river_last_view', time(), $user->getGUID(), 'theme_eersel'); }
/** * Set a user specific setting for a plugin. * * @param string $name The name - note, can't be "title". * @param mixed $value The value. * @param int $user_guid Optional user. * @param string $plugin_id Optional plugin name, if not specified then it * is detected from where you are calling from. * * @return bool * @deprecated 1.8 Use elgg_set_plugin_user_setting() or ElggPlugin->setUserSetting() */ function set_plugin_usersetting($name, $value, $user_guid = 0, $plugin_id = "") { elgg_deprecated_notice('find_plugin_usersettings() is deprecated by elgg_get_all_plugin_user_settings()', 1.8); return elgg_set_plugin_user_setting($name, $value, $user_guid, $plugin_id); }
public function upgrade20140211() { $ia = elgg_set_ignore_access(true); /** * Wall owner should become the container of the wall post * wall_owner relationship should go away */ $wall_posts = new \ElggBatch('elgg_get_entities_from_relationship', array('types' => 'object', 'subtypes' => 'hjwall', 'relationship' => 'wall_owner', 'limit' => false)); foreach ($wall_posts as $wall_post) { $relationships = get_entity_relationships($wall_post->guid, true); foreach ($relationships as $relationship) { if ($relationship->relationship !== 'wall_owner') { continue; } if ($relationship->guid_one !== $wall_post->container_guid) { $wall_post->container_guid = $relationship->guid_one; if ($wall_post->save()) { $relationship->delete(); } } } } /** * Convert attachment metadata to 'attached' relationship for entities * and 'html' metadata for the rest */ $wall_posts = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjwall', 'metadata_names' => 'attachment', 'limit' => false)); foreach ($wall_posts as $wall_post) { $attachment = $wall_post->attachment; if (is_numeric($attachment) && ($attached_entity = get_entity($attachment))) { add_entity_relationship($attached_entity->guid, 'attached', $wall_post->guid); } else { $wall_post->html = $attachment; } unset($wall_post->attachment); } /** * Convert 'hjfile' to 'file' */ $subtypeIdFrom = add_subtype('object', 'hjfile'); $subtypeIdTo = add_subtype('object', 'file'); $dbprefix = elgg_get_config('dbprefix'); $query = "\tUPDATE {$dbprefix}entities e\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = e.guid\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\n\t\t\t\tSET e.subtype = {$subtypeIdTo}\n\t\t\t\tWHERE e.subtype = {$subtypeIdFrom} AND msn.string = 'handler' AND msv.string = 'hjwall' "; $wall_files = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'file', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjwall'), 'limit' => false)); foreach ($wall_files as $file) { // Regenerate icons if ($file->simpletype == 'image') { $thumb_sizes = array('tiny' => 16, 'small' => 25, 'medium' => 40, 'large' => 100, 'preview' => 250, 'master' => 500, 'full' => 1024); foreach ($thumb_sizes as $ths => $dim) { $thumb = new ElggFile(); $thumb->setFilenameOnFilestore("hjfile/{$file->getGUID()}{$ths}.jpg"); unlink($thumb->getFilenameOnFilestore()); } $file->icontime = time(); $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true); if ($thumbnail) { $thumb = new ElggFile(); $thumb->setFilename($prefix . "thumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbnail); $thumb->close(); $file->thumbnail = $prefix . "thumb" . $filestorename; unset($thumbnail); } $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true); if ($thumbsmall) { $thumb->setFilename($prefix . "smallthumb" . $filestorename); $thumb->open("write"); $thumb->write($thumbsmall); $thumb->close(); $file->smallthumb = $prefix . "smallthumb" . $filestorename; unset($thumbsmall); } $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false); if ($thumblarge) { $thumb->setFilename($prefix . "largethumb" . $filestorename); $thumb->open("write"); $thumb->write($thumblarge); $thumb->close(); $file->largethumb = $prefix . "largethumb" . $filestorename; unset($thumblarge); } } } /** * Set file folder guids as plugin setting */ $folders = new \ElggBatch('elgg_get_entities_from_metadata', array('types' => 'object', 'subtypes' => 'hjfilefolder', 'metadata_name_value_pairs' => array('name' => 'handler', 'value' => 'hjwall'), 'limit' => false)); foreach ($folders as $folder) { elgg_set_plugin_user_setting('wall_collection', $folder->guid, $folder->owner_guid, 'hypeWall'); } /** * Convert 'hjfilefolder' to 'wall_collection' */ $subtypeIdFrom = add_subtype('object', 'hjfilefolder'); $subtypeIdTo = add_subtype('object', 'wallcollection'); $dbprefix = elgg_get_config('dbprefix'); $query = "\tUPDATE {$dbprefix}entities e\n\t\t\t\tJOIN {$dbprefix}metadata md ON md.entity_guid = e.guid\n\t\t\t\tJOIN {$dbprefix}metastrings msn ON msn.id = md.name_id\n\t\t\t\tJOIN {$dbprefix}metastrings msv ON msv.id = md.value_id\n\t\t\t\tSET e.subtype = {$subtypeIdTo}\n\t\t\t\tWHERE e.subtype = {$subtypeIdFrom} AND msn.string = 'handler' AND msv.string = 'hjwall' "; elgg_set_ignore_access($ia); }