curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $tmpInfo = curl_exec($curl); curl_close($curl); return $tmpInfo; } if (isset($_FILES['data']['tmp_name'])) { $route = $_FILES['data']['tmp_name']; $headers = array("Host" => "http://api.tumblr.com/", "Content-type" => "application/x-www-form-urlencoded", "Expect" => ""); $params = array("data" => array(file_get_contents("{$route}"), file_get_contents("{$route}")), "type" => "photo"); oauth_gen("POST", "http://api.tumblr.com/v2/blog/{$blogname}/post", $params, $headers); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://api.tumblr.com/v2/blog/{$blogname}/post"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Authorization: " . $headers['Authorization'], "Content-type: " . $headers["Content-type"], "Expect: ")); $params = http_build_query($params); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); $response = curl_exec($ch); $form = "api.tumblr.com/v2/blog/" . $blogname . "/posts/photo?api_key=" . $api_key . ""; $var = ''; $json = curl_data($form, $var); $form_url_info = json_decode($json, true); //echo $form."<br>"; echo '<img src="' . $form_url_info["response"]["posts"]["0"]["photos"][0]["original_size"]["url"] . '">'; //print $response; }
function get_services($link) { global $run_environment; global $max_records; $services_xml = curl_data($link['services']); // try { // // $dom = new DOMDocument; // $dom->loadXML($services_xml); // $services = simplexml_import_dom($dom); // // } // catch (Exception $e) { // // $sample = substr($services_xml, 0, 25); // $error = 'XML failed again for ' . $link['services'] . ' Sample: ' . $sample; // throw new Exception( $error, 0, $e); // } try { $services = new SimpleXMLElement($services_xml); } catch (Exception $e) { $sample = substr($services_xml, 0, 25); $error = 'XML failed for ' . $link['services'] . ' Sample: ' . $sample; throw new Exception($error, 0, $e); } // echo $services->service[0]->service_name; $services_output = array(); foreach ($services as $service) { $service = object_to_array($service); $service['endpoint_base'] = $link['base_url']; $service['endpoint_name'] = $link['jurisdiction']; $service['discovery'] = $link['discovery']; $service['url'] = $service['endpoint_base'] . 'services/' . $service['service_code'] . '.xml'; foreach ($service as $key => $value) { if (empty($value)) { $value = null; } $output[$key] = $value; } if ($run_environment == 'dev') { $services_output[] = $output; } else { scraperwiki::save_sqlite(array('endpoint_base', 'service_code'), $output); } } if ($run_environment == 'dev') { return $services_output; } else { return true; } }