Example #1
0
/**
 * Update the Elgg profile with LinkedIn data
 *
 * @param int $user_guid the user_guid of the profile to update
 *
 * @return void
 */
function socialink_linkedin_sync_profile_metadata($user_guid = 0)
{
    global $CONFIG;
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    // can we get a user
    if (($user = get_user($user_guid)) && socialink_linkedin_is_connected($user_guid)) {
        // does the user allow sync
        if (elgg_get_plugin_user_setting("linkedin_sync_allow", $user->getGUID(), "socialink") != "no") {
            // get configured fields and network fields
            if (($configured_fields = socialink_get_configured_network_fields("linkedin")) && ($network_fields = socialink_get_network_fields("linkedin"))) {
                // ask the api for all fields
                if ($api_result = socialink_linkedin_get_profile_information($user->getGUID())) {
                    $api_result = json_decode($api_result);
                    // check settings for each field
                    foreach ($configured_fields as $setting_name => $profile_field) {
                        $setting = "linkedin_sync_" . $setting_name;
                        if (elgg_get_plugin_user_setting($setting, $user->getGUID(), "socialink") != "no") {
                            $api_setting = $network_fields[$setting_name];
                            // get the correct value from api result
                            if (stristr($api_setting, "->")) {
                                $temp_fields = explode("->", $api_setting);
                                $temp_result = $api_result;
                                for ($i = 0; $i < count($temp_fields); $i++) {
                                    $temp_result = $temp_result->{$temp_fields}[$i];
                                }
                            } else {
                                $temp_result = $api_result->{$api_setting};
                            }
                            // are we dealing with a tags profile field type
                            if (!empty($CONFIG->profile) && is_array($CONFIG->profile)) {
                                if (array_key_exists($profile_field, $CONFIG->profile) && $CONFIG->profile[$profile_field] == "tags") {
                                    $temp_result = string_to_tag_array($temp_result);
                                }
                            }
                            // check if the user has this metadata field, to get access id
                            $params = array("guid" => $user->getGUID(), "metadata_name" => $profile_field, "limit" => false);
                            if ($metadata = elgg_get_metadata($params)) {
                                if (is_array($metadata)) {
                                    $access_id = $metadata[0]->access_id;
                                } else {
                                    $access_id = $metadata->access_id;
                                }
                            } else {
                                $access_id = get_default_access($user);
                            }
                            // remove metadata to set new values
                            elgg_delete_metadata($params);
                            // make new metadata field
                            if (!empty($temp_result)) {
                                if (is_array($temp_result)) {
                                    foreach ($temp_result as $index => $temp_value) {
                                        if ($index > 0) {
                                            $multiple = true;
                                        } else {
                                            $multiple = false;
                                        }
                                        create_metadata($user->getGUID(), $profile_field, $temp_value, 'text', $user->getGUID(), $access_id, $multiple);
                                    }
                                } else {
                                    create_metadata($user->getGUID(), $profile_field, $temp_result, 'text', $user->getGUID(), $access_id);
                                }
                            }
                        }
                    }
                }
            }
            // sync profile icon, only if the user has no icon
            if (empty($user->icontime)) {
                socialink_linkedin_sync_profile_icon($user->getGUID());
            }
        }
    }
}
Example #2
0
			<div><?php 
echo elgg_echo("socialink:settings:linkedin:allow_create");
?>
</div>
			<?php 
echo elgg_view("input/dropdown", array("name" => "params[linkedin_allow_create]", "value" => $plugin->linkedin_allow_create, "options_values" => $yesno_options));
?>
			
			<br /><br />
			
			<div><?php 
echo elgg_echo("socialink:settings:linkedin:sync_profile_fields");
?>
</div>
			<?php 
if ($fields = socialink_get_network_fields("linkedin")) {
    ?>
					<table class="elgg-table">
						<tr>
							<th><?php 
    echo elgg_echo("socialink:settings:linkedin:linkedin_field");
    ?>
</th>
							<th><?php 
    echo elgg_echo("socialink:settings:profile_field");
    ?>
</th>
						</tr>
						<?php 
    foreach ($fields as $settings_name => $network_name) {
        $setting = "linkedin_profile_" . $settings_name;
Example #3
0
/**
 * Update the Elgg profile with Facebook data
 *
 * @param int $user_guid the user_guid of the profile to update
 *
 * @return void
 */
function socialink_facebook_sync_profile_metadata($user_guid = 0)
{
    $user_guid = sanitise_int($user_guid, false);
    if (empty($user_guid)) {
        $user_guid = elgg_get_logged_in_user_guid();
    }
    if (empty($user_guid)) {
        return;
    }
    $user = get_user($user_guid);
    if (empty($user) || !socialink_facebook_is_connected($user_guid)) {
        return;
    }
    // does the user allow sync
    if (elgg_get_plugin_user_setting("facebook_sync_allow", $user->getGUID(), "socialink") === "no") {
        return;
    }
    // get configured fields and network fields
    $profile_fields = elgg_get_config("profile_fields");
    $configured_fields = socialink_get_configured_network_fields("facebook");
    $network_fields = socialink_get_network_fields("facebook");
    if (empty($profile_fields) || empty($configured_fields) || empty($network_fields)) {
        return;
    }
    // ask the api for all fields
    $api_result = socialink_facebook_get_profile_information($user->getGUID());
    if (!empty($api_result)) {
        // check settings for each field
        foreach ($configured_fields as $setting_name => $profile_field) {
            $setting = "facebook_sync_" . $setting_name;
            if (elgg_get_plugin_user_setting($setting, $user->getGUID(), "socialink") === "no") {
                continue;
            }
            $api_setting = $network_fields[$setting_name];
            $temp_result = call_user_func(array($api_result, $api_setting));
            // are we dealing with a tags profile field type
            $field_type = elgg_extract($profile_field, $profile_fields);
            if ($field_type === "tags") {
                $temp_result = string_to_tag_array($temp_result);
            }
            // check if the user has this metadata field, to get access id
            $params = array("guid" => $user->getGUID(), "metadata_name" => $profile_field, "limit" => false);
            if ($metadata = elgg_get_metadata($params)) {
                if (is_array($metadata)) {
                    $access_id = $metadata[0]->access_id;
                } else {
                    $access_id = $metadata->access_id;
                }
            } else {
                $access_id = get_default_access($user);
            }
            // remove metadata to set new values
            elgg_delete_metadata($params);
            // make new metadata field
            if (empty($temp_result)) {
                continue;
            }
            if (is_array($temp_result)) {
                foreach ($temp_result as $index => $temp_value) {
                    if ($index > 0) {
                        $multiple = true;
                    } else {
                        $multiple = false;
                    }
                    create_metadata($user->getGUID(), $profile_field, $temp_value, 'text', $user->getGUID(), $access_id, $multiple);
                }
            } else {
                create_metadata($user->getGUID(), $profile_field, $temp_result, 'text', $user->getGUID(), $access_id);
            }
        }
    }
    // sync profile icon, only if the user has no icon
    if (empty($user->icontime)) {
        socialink_facebook_sync_profile_icon($user->getGUID());
    }
}
Example #4
0
/**
 * Get the profile field configuration for a social network
 *
 * @param string $network the name of the social network
 *
 * @return bool|array
 */
function socialink_get_configured_network_fields($network)
{
    $result = false;
    if (!empty($network) && socialink_is_available_network($network)) {
        if (($fields = socialink_get_network_fields($network)) && !empty($fields)) {
            $temp = array();
            foreach ($fields as $setting_name => $network_name) {
                if (($profile_field = elgg_get_plugin_setting($network . "_profile_" . $setting_name, "socialink")) && !empty($profile_field)) {
                    $result[$setting_name] = $profile_field;
                }
            }
            if (!empty($temp)) {
                $result = $temp;
            }
        }
    }
    return $result;
}