<?php $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 " " . 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 " <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>";
/** * Save settings from the settings page * * @param string $hook the name of the hook * @param string $type the type of the hook * @param mixed $returnvalue current return value * @param array $params supplied params * * @return void */ function socialink_twitter_usersettings_save($hook, $type, $returnvalue, $params) { if (!empty($params) && is_array($params)) { if (array_key_exists("user", $params) && array_key_exists("plugin", $params) && array_key_exists("name", $params) && array_key_exists("value", $params)) { $user = $params["user"]; $plugin = $params["plugin"]; $name = $params["name"]; $value = $params["value"]; if ($plugin == "socialink" && ($name = "twitter_in") && $value == "yes") { $prev = elgg_get_plugin_user_setting("twitter_in", $user->getGUID(), "socialink"); if ($prev != "yes") { if ($keys = socialink_twitter_is_connected($user->getGUID())) { if ($api = socialink_twitter_get_api_object($keys)) { try { $url = "statuses/user_timeline"; $params = array("include_rts" => true, "count" => 1); $response = $api->get($url, $params); if (!empty($response) && empty($response->error)) { foreach ($response as $tweet) { elgg_set_plugin_user_setting("twitter_in_since_id", $tweet->id_str, $user->getGUID(), "socialink"); break; } } } catch (Exception $e) { } } } } } } } }