/* Arbitrary request */ /*********************/ $t->diag('Arbitrary request'); $t->like($b->call($dump_headers_url, 'MICHEL')->getResponseText(), '/\\[REQUEST_METHOD\\] => MICHEL/', 'call() supports any HTTP methods'); /****************************/ /* Response formats methods */ /****************************/ $t->diag('Response formats methods'); $b = new sfWebBrowser(array(), $adapter); $b->get($example_site_url); $t->like($b->getResponseText(), '/<body .*>/', 'getResponseText() returns the response text'); $t->unlike($b->getResponseBody(), '/<body>/', 'getResponseBody() returns the response body'); $t->isa_ok($b->getResponseDom(), 'DOMDocument', 'getResponseDom() returns the response Dom'); $t->isa_ok($b->getResponseDomCssSelector(), 'sfDomCssSelector', 'getResponseDomCssSelector() returns a CSS selector on the response Dom'); $b->get('http://rss.cnn.com/rss/cnn_topstories.rss'); $t->isa_ok($b->getResponseXml(), 'SimpleXMLElement', 'getResponseXml() returns the response as a SimpleXML Element'); $b->get('http://www.w3.org/StyleSheets/home.css'); try { $b->getResponseXml(); $t->fail('Incorrect XML throws an exception'); } catch (Exception $e) { $t->pass('Incorrect XML throws an exception'); } try { /******************************/ /* Absolute and relative URls */ /******************************/ $t->diag('Absolute and relative URls'); $b = new sfWebBrowser(array(), $adapter); $t->like($b->get($askeet_params['url'])->getResponseText(), '/<h1>featured questions<\\/h1>/', 'get() understands absolute urls'); $t->like($b->get($askeet_params['url'] . '/index/1')->getResponseText(), '/<h1>popular questions<\\/h1>/', 'get() understands absolute urls');
/** * Uses Google Maps API to parse flat address */ static function parse($str, $returnAccuracy = false) { //CLEANUP $str = preg_replace('/[\\n\\r]/', ' ', $str); $key = sfConfig::get('sf_google_maps_key'); $url = 'http://maps.google.com/maps/geo?q=' . urlencode($str) . '&output=xml&key=' . $key; //echo $url . "\n"; $c = new sfWebBrowser(); try { if (!$c->get($url)->responseIsError()) { $c->setResponseText(iconv('ISO-8859-1', 'UTF-8', $c->getResponseText())); $xml = $c->getResponseXml(); //var_dump($xml); $structured = $xml->Response->Placemark->AddressDetails; $accuracy = (int) $structured['Accuracy']; } else { return null; } } catch (Exception $e) { // Adapter error (eg. Host not found) throw $e; } //accuracy of 4+ means we have at least a town (UNLESS THE TOWN DOESN'T "OFFICIALLY" EXIST) if ($accuracy > 3) { $address = new Address(); //COUNTRY (USA only for now) $address->country_id = 1; //STATE (for some reason trickery needs to be done to get state to work right) $stateName = null; if (isset($structured->Country->AdministrativeArea->AdministrativeAreaName)) { $stateName = (array) $structured->Country->AdministrativeArea->AdministrativeAreaName; $stateName = isset($stateName[0]) ? $stateName[0] : $stateName; } else { $possible_state = $structured->Country->CountryNameCode; if ($possible_state != 'US') { $stateName = $possible_state; } } if (!$stateName) { return null; } if (!($state = AddressStateTable::retrieveByText($stateName))) { return null; } $address->state_id = $state->id; //COUNTY (this may not exist) $countyName = $structured->Country->AdministrativeArea->SubAdministrativeArea->SubAdministrativeAreaName; $address->county = LsString::emptyToNull((string) $countyName); if ($countyName) { $cityName = $structured->Country->AdministrativeArea->SubAdministrativeArea->Locality->LocalityName; } else { $cityName = $structured->Country->AdministrativeArea->Locality->LocalityName; } //CITY (this may not exist!) $address->city = (string) $cityName; //accuracy of 5+ means we have postal code if ($accuracy > 4) { if ($cityName && $countyName) { $base = $structured->Country->AdministrativeArea->SubAdministrativeArea->Locality; if (isset($base->DependentLocality)) { $base = $base->DependentLocality; } } else { if ($cityName && !$countyName) { $base = $structured->Country->AdministrativeArea->Locality; } else { if (!$cityName && $countyName) { $base = $structured->Country->AdministrativeArea->SubAdministrativeArea; } else { $base = $structured->Country->AdministrativeArea; } } } //POSTAL CODE (for some reason trickery needs to be done to get postal code to work right) if ($postalCode = (array) $base->PostalCode->PostalCodeNumber) { $postalCode = $postalCode[0]; $address->postal = (string) $postalCode; } //accuracy of 8 means we have exact match //echo $accuracy . "\n"; if ($accuracy > 5) { //STREET (unit info is lost) //echo "street1 info found \n"; $street1 = $base->Thoroughfare->ThoroughfareName; $address->street1 = (string) $street1; } } //COORDINATES // Parse the coordinate string $coords = $c->getResponseXml()->Response->Placemark->Point->coordinates; list($lon, $lat, $alt) = explode(",", $coords); $address->longitude = $lon; $address->latitude = $lat; if ($returnAccuracy) { return array('address' => $address, 'accuracy' => $accuracy); } else { return $address; } } else { return null; } }
$item->addChild('original_outing_id', $id); $item->addChild('url', "http://www.camptocamp.org/outings/{$id}/{$lang}/" . make_slug(htmlspecialchars($object->get('name')))); } if (!$n) { exit; // it's better to keep the script mute if not necessary, thus avoiding cron to send useless mails } // debug info : //echo "XML created : \n" . $xml->asXML() . " \n"; $b = new sfWebBrowser(); try { if (!$b->get($meta_url)->responseIsError()) { // Successful response (eg. 200, 201, etc) //echo "Pushing $n outing(s) ... \n"; $b->post($meta_url . 'outings/push', array('metaengine_user_id' => $user_id, 'metaengine_user_key' => $user_key, 'metaengine_xml' => urlencode($xml->asXML()))); $response = $b->getResponseXml(); if ($response->status == 1) { //echo "Push succeeded. \n"; } else { // now, what append ??? // try to get more info on what could make it fail //var_dump($xml->asXML()); //var_dump($response); foreach ($response->errors->error as $error) { if (!isset($complaint)) { echo "Push failed for outings:\n"; $complaint = 1; } echo "- {$error->outing_id} : {$error->error_message}\n"; } }