示例#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());
            }
        }
    }
}
示例#2
0
<?php

$user = elgg_get_page_owner_entity();
$plugin = elgg_extract("entity", $vars);
// for yes/no dropdowns
$yesno_options_values = array("no" => elgg_echo("option:no"), "yes" => elgg_echo("option:yes"));
echo "<div>";
echo "<div class='socialink_usersettings_network_icon' id='socialink_usersettings_linkedin_icon'></div>";
echo "<div class='socialink_usersettings_network_config'>";
if (socialink_linkedin_is_connected($user->getGUID())) {
    $linkedin_remove_link = elgg_add_action_tokens_to_url("action/socialink/remove?service=linkedin");
    $link_begin = "<a href='" . $linkedin_remove_link . "'>";
    $link_end = "</a>";
    echo "<div>" . elgg_echo("socialink:usersettings:linkedin:remove", array($link_begin, $link_end)) . "</div>";
    // configure profile synchronisation
    if ($fields = socialink_get_configured_network_fields("linkedin")) {
        $network_name = elgg_echo("socialink:network:linkedin");
        echo "<br />";
        echo "<div>";
        echo elgg_echo("socialink:usersettings:profile_sync", array($network_name));
        echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[linkedin_sync_allow]", "options_values" => array_reverse($yesno_options_values), "value" => $plugin->getUserSetting("linkedin_sync_allow"), "onchange" => "socialink_toggle_network_configure(this, 'linkedin');"));
        echo "&nbsp;<span id='socialink_linkedin_sync_configure' ";
        if ($plugin->getUserSetting("linkedin_sync_allow") != "no") {
            echo "class='socialink_network_sync_allow'";
        }
        echo ">";
        echo elgg_view("output/url", array("text" => elgg_echo("socialink:configure"), "href" => "#socialink_linkedin_sync_fields", "rel" => "toggle"));
        echo "</span>";
        echo "</div>";
        echo "<table id='socialink_linkedin_sync_fields' class='elgg-table'>";
        echo "<tr>";
示例#3
0
$user = elgg_get_page_owner_entity();
$plugin = elgg_extract("entity", $vars);
// for yes/no dropdowns
$yesno_options_values = array("no" => elgg_echo("option:no"), "yes" => elgg_echo("option:yes"));
echo "<div>";
echo "<div class='socialink_usersettings_network_icon' id='socialink_usersettings_facebook_icon'></div>";
echo "<div class='socialink_usersettings_network_config'>";
// is the user conntected
if (socialink_facebook_is_connected($user->getGUID())) {
    $facebook_remove_link = elgg_add_action_tokens_to_url("action/socialink/remove?service=facebook");
    $link_begin = "<a href='" . $facebook_remove_link . "'>";
    $link_end = "</a>";
    echo "<div>" . elgg_echo("socialink:usersettings:facebook:remove", array($link_begin, $link_end)) . "</div>";
    // configure profile synchronisation
    if ($fields = socialink_get_configured_network_fields("facebook")) {
        $network_name = elgg_echo("socialink:network:facebook");
        echo "<br />";
        echo "<div>";
        echo elgg_echo("socialink:usersettings:profile_sync", array($network_name));
        echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[facebook_sync_allow]", "options_values" => array_reverse($yesno_options_values), "value" => $plugin->getUserSetting("facebook_sync_allow"), "js" => "onchange='socialink_toggle_network_configure(this, \"facebook\");'"));
        echo "&nbsp;<span id='socialink_facebook_sync_configure' ";
        if ($plugin->getUserSetting("facebook_sync_allow") != "no") {
            echo "class='socialink_network_sync_allow'";
        }
        echo "><a href='javascript:void(0);' onclick='\$(\"#socialink_facebook_sync_fields\").toggle();'>" . elgg_echo("socialink:configure") . "</a></span>";
        echo "</div>";
        echo "<table id='socialink_facebook_sync_fields' class='elgg-table'>";
        echo "<tr>";
        echo "<th>" . elgg_echo("socialink:usersettings:profile_field", array($network_name)) . "</th>";
        echo "<th>" . elgg_echo("socialink:usersettings:profile_sync:allow") . "</th>";
示例#4
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());
    }
}
示例#5
0
$user = elgg_get_page_owner_entity();
$plugin = elgg_extract("entity", $vars);
// for yes/no dropdowns
$noyes_options_values = array("no" => elgg_echo("option:no"), "yes" => elgg_echo("option:yes"));
echo "<div>";
echo "<div class='socialink_usersettings_network_icon' id='socialink_usersettings_twitter_icon'></div>";
echo "<div class='socialink_usersettings_network_config'>";
// is the user conntected
if (socialink_twitter_is_connected($user->getGUID())) {
    $twitter_remove_link = elgg_add_action_tokens_to_url("action/socialink/remove?service=twitter");
    $twitter_screen_name = $plugin->getUserSetting("twitter_screen_name");
    $link_begin = "<a href='" . $twitter_remove_link . "'>";
    $link_end = "</a>";
    echo "<div>" . elgg_echo("socialink:usersettings:twitter:remove", array($twitter_screen_name, $link_begin, $link_end)) . "</div>";
    // configure profile synchronisation
    if ($fields = socialink_get_configured_network_fields("twitter")) {
        $network_name = elgg_echo("socialink:network:twitter");
        echo "<br />";
        echo "<div>";
        echo elgg_echo("socialink:usersettings:profile_sync", array($network_name));
        echo "&nbsp;" . elgg_view("input/dropdown", array("name" => "params[twitter_sync_allow]", "options_values" => array_reverse($noyes_options_values), "value" => $plugin->getUserSetting("twitter_sync_allow"), "onchange" => "socialink_toggle_network_configure(this, 'twitter');"));
        echo "&nbsp;<span id='socialink_twitter_sync_configure' ";
        if ($plugin->getUserSetting("twitter_sync_allow") != "no") {
            echo "class='socialink_network_sync_allow'";
        }
        echo ">";
        echo elgg_view("output/url", array("text" => elgg_echo("socialink:configure"), "href" => "#socialink_twitter_sync_fields", "rel" => "toggle"));
        echo "</span>";
        echo "</div>";
        echo "<table id='socialink_twitter_sync_fields' class='elgg-table'>";
        echo "<tr>";