function flickr_api($url, $params, $response_tag = "", $method = "GET") { # Automatically sign the request, process it, and return it # Build query and sign it $url .= "?" . flickr_sign($params); # Run query $opts = array('http' => array('method' => $method)); $context = stream_context_create($opts); $xml = file_get_contents($url, false, $context); global $last_xml; $last_xml = $xml; if ($response_tag == "") { return true; } else { return flickr_get_response_tag($xml, $response_tag); } }
$flickr_frob = sql_value("select flickr_frob value from user where ref='{$userref}'", ""); $valid_frob = false; if ($flickr_frob != "") { #echo "check existing frob $flickr_frob<br>"; $flickr_token = flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.auth.getToken", "frob" => $flickr_frob), "token"); if ($flickr_token !== false) { $valid_frob = true; $validtoken = true; sql_query("update user set flickr_token='" . escape_check($flickr_token) . "' where ref='{$userref}'"); } } if (!$valid_frob) { $flickr_frob = flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.auth.getFrob"), "frob"); sql_query("update user set flickr_frob='" . escape_check($flickr_frob) . "' where ref='{$userref}'"); # Authenticate frob $auth_url = "http://flickr.com/services/auth/?" . flickr_sign(array("api_key" => $flickr_api_key, "perms" => "write", "frob" => $flickr_frob)); ?> <p>> <a target=_blank href="<?php echo $auth_url; ?> "><?php echo $lang["flickrnotloggedin"]; ?> </a></p> <p><?php echo $lang["flickronceloggedinreload"]; ?> </p> <form method="post" action="sync.php?theme=<?php echo $theme; ?>
function flickr_check_frob($userref) { global $flickr_api_key, $flickr_frob, $lang, $auth_url, $theme; $flickr_frob = sql_value("select flickr_frob value from user where ref='{$userref}'", ""); $valid_frob = false; $validtoken = false; if ($flickr_frob != "") { #echo "check existing frob $flickr_frob<br>"; $flickr_token = flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.auth.getToken", "frob" => $flickr_frob), "token"); if ($flickr_token !== false) { $valid_frob = true; $validtoken = true; sql_query("update user set flickr_token='" . escape_check($flickr_token) . "' where ref='{$userref}'"); } } if (!$valid_frob) { $flickr_frob = flickr_api("http://flickr.com/services/rest/", array("api_key" => $flickr_api_key, "method" => "flickr.auth.getFrob"), "frob"); sql_query("update user set flickr_frob='" . escape_check($flickr_frob) . "' where ref='{$userref}'"); # Authenticate frob $auth_url = "http://flickr.com/services/auth/?" . flickr_sign(array("api_key" => $flickr_api_key, "perms" => "write", "frob" => $flickr_frob)); ?> <p>> <a target=_blank href="<?php echo $auth_url; ?> "><?php echo $lang["flickrnotloggedin"]; ?> </a></p> <p><?php echo $lang["flickronceloggedinreload"]; ?> </p> <form method="post" action="sync.php?theme=<?php echo $theme; ?> "><input type="submit" name="reload" value="<?php echo $lang["reload"]; ?> "></form> <?php } return $validtoken; }