public function getCik() { if (!$this->ticker) { return; } $url = 'http://finance.yahoo.com/q/sec?s=' . urlencode($this->ticker) . '+SEC+Filings'; $cik = null; $sic = null; $browser = new sfWebBrowser(); if (!$browser->get($url)->responseIsError()) { $text = $browser->getResponseText(); //get CIK document codes preg_match('/cik\\=(\\d+)>/', $text, $matches); if ($matches) { $this->sec_cik = $matches[1]; $this->save(); return true; } } $url2 = 'http://www.sec.gov/cgi-bin/browse-edgar?company=&match=&CIK=' . urlencode($this->ticker) . '&filenum=&State=&Country=&SIC=&owner=exclude&Find=Find+Companies&action=getcompany'; if (!$browser->get($url2)->responseIsError()) { $text = $browser->getResponseText(); preg_match('/CIK\\=(\\d+)[^\\d]/', $text, $matches); if ($matches) { $this->sec_cik = $matches[1]; $this->save(); return true; } } return false; }
/** * /robokassa/init * Инициализация транзакции и возврат json-обекта * * @param sfWebRequest $request */ public function executeInit(sfWebRequest $request) { $userId = $this->getUser()->getUserRecord()->getId(); // В качестве параметра ожидаем ID услуги (POST параметр service) $serviceId = (int) $request->getParameter("service", 0); $term = (int) $request->getParameter("term", 1); // Получаем стоимость услуги $service = Doctrine::getTable('Service')->find($serviceId); $this->forward404Unless($service); $price = $service->getPrice(); // Инициализация транзакции $transaction = new BillingTransaction(); $transaction->setUserId($userId); $transaction->setPaysystem('robokassa'); $transaction->setServiceId($serviceId); $transaction->setPrice($price); $transaction->setTerm($term); $total = round($term * $price, 2); $transaction->setTotal($total); $transaction->save(); $url = Robokassa::getScriptURL($transaction); $b = new sfWebBrowser(); $b->get($url); $text = $b->getResponseText(); $matches = array(); preg_match_all("/^(.*)document.write\\(\\'(.*)\\'\\)/isu", $text, $matches); $return = array("result" => array("script" => html_entity_decode(trim($matches[1][0])), "html" => html_entity_decode(trim($matches[2][0])))); $this->getResponse()->setHttpHeader('Content-Type', 'application/json'); return $this->renderText(json_encode($return)); }
public function executeDocumentation($request) { $browser = new sfWebBrowser(); $this->prefix = $request->getUriPrefix(); if ($extraPrefix = $request->getParameter('prefix')) { $this->prefix .= $extraPrefix; } if (!($apiKey = sfConfig::get('app_documentation_admin_key'))) { return $this->renderText("Something's broken! Can't display API documentation."); } $orgId = 1; $personId = 1164; $relationshipId = 23; $listId = 23; $this->uris = array('entity_basic' => $this->prefix . '/entity/' . $orgId . '.xml', 'entity_details' => $this->prefix . '/entity/' . $orgId . '/details.xml', 'entity_batch' => $this->prefix . '/batch/entities.xml?ids=1,2,3,1201,28219,35306&details=1', 'entity_aliases' => $this->prefix . '/entity/' . $orgId . '/aliases.xml', 'entity_relationships' => $this->prefix . '/entity/' . $orgId . '/relationships.xml?cat_ids=1,7', 'entity_related' => $this->prefix . '/entity/' . $orgId . '/related.xml?cat_ids=1&order=2&is_current=1', 'entity_leadership' => $this->prefix . '/entity/' . $orgId . '/leadership.xml?is_current=1', 'entity_orgs' => $this->prefix . '/entity/' . $personId . '/orgs.xml', 'entity_degree2' => $this->prefix . '/entity/' . $orgId . '/related/degree2.xml?cat1_ids=1&cat2_ids=1&order1=2&order2=1', 'entity_lists' => $this->prefix . '/entity/' . $orgId . '/lists.xml', 'entity_childorgs' => $this->prefix . '/entity/' . $orgId . '/child-orgs.xml', 'entity_images' => $this->prefix . '/entity/' . $orgId . '/images.xml', 'entity_references' => $this->prefix . '/entity/' . $orgId . '/references.xml', 'entity_rel_references' => $this->prefix . '/entity/' . $orgId . '/relationships/references.xml?cat_ids=1,7', 'relationship_basic' => $this->prefix . '/relationship/' . $relationshipId . '.xml', 'relationship_details' => $this->prefix . '/relationship/' . $relationshipId . '/details.xml', 'relationship_batch' => $this->prefix . '/batch/relationships.xml?ids=' . implode(',', range(74, 95)) . '&details=1', 'relationship_references' => $this->prefix . '/relationship/' . $relationshipId . '/references.xml', 'list_basic' => $this->prefix . '/list/' . $listId . '.xml', 'list_entities' => $this->prefix . '/list/' . $listId . '/entities.xml?type_ids=29', 'entity_search' => $this->prefix . '/entities.xml?q=treasury&type_ids=35', 'entity_lookup' => $this->prefix . '/entities/bioguide_id/O000167.xml', 'entity_chains' => $this->prefix . '/entities/chains/1;2.xml', 'relationship_search' => $this->prefix . '/relationships/1026;1.xml?cat_ids=1', 'list_search' => $this->prefix . '/lists.xml?q=forbes'); $this->responses = array(); foreach ($this->uris as $key => $uri) { $uri = $this->addKeyToUri($uri, $apiKey); if ($browser->get($uri)->responseIsError()) { throw new Exception("Couldn't get example URI: " . $uri); } $text = $browser->getResponseText(); $this->responses[$key] = LsDataFormat::formatXmlString($text); } }
public static function test() { $url = 'http://www.nytimes.com/2010/11/02/us/politics/02campaign.html?hp'; $browser = new sfWebBrowser(); $text = $browser->get($url)->getResponseText(); $ret = self::getEntityNames($text, array('Person', 'Org')); //var_dump($ret); }
public function executeIndex(sfWebRequest $request) { if ($this->getUser()->isAuthenticated() && $this->getUser()->getGuardUser()->account_type != 'Trial') { $this->getUser()->setFlash('notice', 'You are already registered and signed in!'); $this->redirect('/project'); } if ($this->getUser()->isAuthenticated()) { $user = $this->getUser()->getGuardUser(); $user->email_address = ''; $user->account_type = 'Free'; $this->form = new sfGuardRegisterForm($user); } else { $this->form = new sfGuardRegisterForm(); if ($this->getUser()->getAttribute('google_token')) { $google_token = json_decode($this->getUser()->getAttribute('google_token')); $browser = new sfWebBrowser(array(), null, array('ssl_verify_host' => false, 'ssl_verify' => false)); $result = $browser->get('https://www.googleapis.com/oauth2/v1/userinfo?access_token=' . $google_token->access_token); if ($result->getResponseCode() == 200) { $response_text = json_decode($result->getResponseText()); if (property_exists($response_text, 'email')) { $user_exists = sfGuardUserTable::getInstance()->createQuery('u')->where('email_address = ?', $response_text->email)->fetchOne(); if (is_object($user_exists)) { $this->getUser()->setAttribute('google_token', null); if ($user_exists->is_active) { $this->getUser()->signIn($user_exists); $this->redirect('/project'); } else { $this->getUser()->setFlash('notice', 'Check your e-mail! You should verify your email address.'); $this->redirect('@sf_guard_signin'); } } $this->getUser()->setAttribute('google_token_info', array($response_text->email => array('given_name' => $response_text->given_name, 'family_name' => $response_text->family_name))); $this->form->setDefault('email_address', $response_text->email); // $this->form->getWidget('email_address')->setAttribute('readonly', 'readonly'); } } } } if ($request->isMethod('post')) { $this->form->bind($request->getParameter($this->form->getName())); if ($this->form->isValid()) { $user = $this->form->save(); $google_token_info = $this->getUser()->getAttribute('google_token_info'); $this->getUser()->setAttribute('google_token', null); $this->getUser()->setAttribute('google_token_info', null); if (is_array($google_token_info) && array_key_exists($user->email_address, $google_token_info)) { $user->first_name = $google_token_info[$user->email_address]['given_name']; $user->last_name = $google_token_info[$user->email_address]['family_name']; $user->is_active = true; @$user->save(); $this->getUser()->signIn($user); $this->redirect('/project'); } else { $this->sendConfirmationEmail($user); } } } }
/** * 会員が存在するかチェック */ private function memberExist() { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_check_registration_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId)); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { return false; } return true; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_get_reserved_driver_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId)); $options = array('complexType' => 'array', 'parseAttributes' => TRUE); $Unserializer = new XML_Unserializer($options); //$Unserializer->setOption('parseAttributes', TRUE); $status = $Unserializer->unserialize($b->getResponseText()); $this->list = $Unserializer->getUnserializedData(); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $b = new sfWebBrowser(); $b->get(sfConfig::get('sf_takutomo_get_attend_event_url'), array('guid' => 'DEBUG,sample_member_001')); //xmlを連想配列に変換 $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); //if ($status === true) { $this->get_attend_event_list = $Unserializer->getUnserializedData(); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { //$mixi_persistence = $persistence->entry->{'mixi.jp:'.MixiAppMobileApi::$ownerId}; $b = new sfWebBrowser(); $b->get(sfConfig::get('sf_takutomo_get_attend_event_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId)); //xmlを連想配列に変換 $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); //if ($status === true) { $this->get_attend_event_list = $Unserializer->getUnserializedData(); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_get_profile_url'), array('id' => $this->getRequestParameter('id'))); if ((int) $xml->status->code >= 1000) { $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description)); } else { //xmlを連想配列に変換 $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); $this->member = $Unserializer->getUnserializedData(); } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new AddEventCommentForm(); if ($request->isMethod('get')) { $this->form->setDefault('event_id', $request->getParameter('event_id')); } elseif ($request->isMethod('post')) { $this->form->bind($request->getParameterHolder()->getAll()); if ($this->form->isValid()) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_add_event_comment_url'), array('event_id' => $this->getRequestParameter('event_id'), 'comment' => $this->getRequestParameter('comment'))); print $b->getResponseText(); } } }
/** * 相乗りリストを返す * errorの場合 null */ private function getAttendEventList() { $b = new sfWebBrowser(); $b->get(sfConfig::get('sf_takutomo_get_attend_event_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId)); //xmlを連想配列に変換 $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); if ($status === true) { return $Unserializer->getUnserializedData(); } else { return null; } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new ForgotPasswordForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameterHolder()->getAll()); if ($this->form->isValid()) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_forgot_password_url'), array('email' => $this->getRequestParameter('email'))); $xml = new SimpleXMLElement($b->getResponseText()); $this->display_description = (string) $xml->status->description; $this->setTemplate('submit'); } } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { if ($request->isMethod('post')) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_delete_user_url'), array('guid' => 'DEBUG,sample_member_001')); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { $this->display_description = (string) $xml->status->description; } else { $this->display_description = (string) $xml->status->description; $this->setTemplate('submit'); } } }
private function getProFileMySelf() { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_get_profile_myself_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId)); $xml = new SimpleXMLElement($b->getResponseText()); $this->profileForm = new sfForm(); if ((int) $xml->status->code >= 1000) { $this->profileForm->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description)); } else { $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); $this->profile = $Unserializer->getUnserializedData(); } }
private function addEventComment(sfWebRequest $request) { $b = new sfWebBrowser(); $this->form = new AddEventCommentForm(); $this->form->bind($request->getParameterHolder()->getAll()); if ($this->form->isValid()) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_add_event_comment_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId, 'event_id' => $this->getRequestParameter('event_id'), 'comments' => $this->getRequestParameter('comment'))); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description)); } else { $this->display_description = (string) $xml->status->description; $this->setTemplate('submit'); } } }
/** * タクトモ会員登録 * return boolean */ private function memberRegister() { $mixi = new MixiAppMobileApi(); $person = $mixi->get(sfConfig::get('sf_opensocial_person_api') . '?fields=birthday,gender'); $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_register_by_guid_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId, 'name' => $person->entry->nickname, 'age' => $this->convertAge($person->entry->birthday), 'gender' => $this->convertGender($person->entry->gender), 'introduction' => '')); $xml = new SimpleXMLElement($b->getResponseText()); $moduleArr = array('index', 'member_register', 'forgot_password'); if ((int) $xml->status->code >= 1000) { /*if(array_search(sfContext::getInstance()->getModuleName(),$moduleArr) === false){ header("Location:".sfConfig::get('sf_mixi_index_url')); exit; }*/ return false; } return true; }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new LoginForm(); if ($request->isMethod('post')) { $this->form->bind($request->getParameterHolder()->getAll()); if ($this->form->isValid()) { $b = new sfWebBrowser(); $b->post('http://api.takutomo.com/v3/member/get_profile_myself.php?api_key=pontuyo', array('email' => $this->getRequestParameter('email'), 'password' => $this->getRequestParameter('password'))); print $b->getResponseText(); $xml = new SimpleXMLElement($b->getResponseText()); //var_dump(MemberForm::$sexs[$this->getRequestParameter('gender')]); //$this->display_form = MemberForm::$sexs[$this->getRequestParameter('gender')]; //$this->form->freeze(); // $this->setTemplate('confirm'); } } }
function writeTmpFile($source, $debug = false, $localdir = false) { $defaultHeaders = array('User-Agent' => 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061205 Iceweasel/2.0.0.1 (Debian-2.0.0.1+dfsg-2)'); $b = new sfWebBrowser($defaultHeaders, 'sfCurlAdapter', array('cookies' => true)); if ($b->get($source)->responseIsError()) { return false; } $fileData = $b->getResponseText(); unset($b); $filePath = $this->getLocalPath($source, $localdir); $localFile = fopen($filePath, 'w+b'); fwrite($localFile, $fileData); if ($debug) { print "SAVED LOCAL: " . $source . " [" . sha1($source) . "] [" . strlen($fileData) . "]\n"; } if (!fclose($localFile)) { throw new Exception("Couldn't close file: " . $filePath); } }
/** * @param sfWebRequest $request * @throws sfStopException */ public function executeAuth(sfWebRequest $request) { $client_id = sfConfig::get('app_google_api_client_id'); $redirect_uri = $this->generateUrl('sf_guard_auth', array('auth_method' => 'google'), true); if ($request->hasParameter('code')) { $client_secret = sfConfig::get('app_google_api_client_secret'); $this->redirect = false; $params = array('client_id' => $client_id, 'client_secret' => $client_secret, 'grant_type' => 'authorization_code', 'code' => $request->getParameter('code'), 'redirect_uri' => $redirect_uri); $browser = new sfWebBrowser(array(), null, array('ssl_verify_host' => false, 'ssl_verify' => false)); $result = $browser->post('https://accounts.google.com/o/oauth2/token', $params); if ($result->getResponseCode() == 200) { $this->redirect = true; $this->getUser()->setAttribute('google_token', $result->getResponseText()); } } else { $scope = 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'; $this->redirect('https://accounts.google.com/o/oauth2/auth?client_id=' . $client_id . '&redirect_uri=' . urlencode($redirect_uri) . '&scope=' . $scope . '&response_type=code&access_type=offline'); } }
function getEval($id) { $result = null; $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_get_profile_url'), array('id' => $id)); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { return null; } else { //xmlを連想配列に変換 $options = array('complexType' => 'array'); $Unserializer = new XML_Unserializer($options); $status = $Unserializer->unserialize($b->getResponseText()); if ($status) { $member = $Unserializer->getUnserializedData(); return createStars(calculateEvaluate($member)); } return null; } }
/** * Returns response as XML * * If reponse is not a valid XML it is being created from * a DOM document which is being created from a text response * (this is the case for not valid HTML documents). * * @return SimpleXMLElement */ public function getResponseXML() { try { $this->responseXml = parent::getResponseXML(); } catch (Exception $exception) { $doc = new DOMDocument(); $doc->loadHTML($this->getResponseText()); $this->responseXml = simplexml_import_dom($doc); } return $this->responseXml; }
public function executeOnePercentSearch($request) { $this->search_form = new OnePercentSearchForm(); if ($request->isMethod('post')) { $searchParams = $request->getParameter('onepercent'); $url = $searchParams['url']; $text = $searchParams['text']; $this->search_form->bind($searchParams); if (!$this->search_form->isValid()) { return; } if ($url) { $browser = new sfWebBrowser(); if (!$browser->get($url)->responseIsError()) { $text = $browser->getResponseText(); } } if ($text) { $html = stripos($text, "<html"); $entity_types = 'people'; $names = array(); if ($html !== false) { $names = LsTextAnalysis::getHtmlEntityNames($text, $entity_types); } else { $names = LsTextAnalysis::getTextEntityNames($text, $entity_types); } $this->matches = array(); foreach ($names as $name) { $name_terms = $name; $name_parts = preg_split('/\\s+/', $name); if (count($name_parts) > 1) { $name_terms = PersonTable::nameSearch($name); } $pager = EntityTable::getSphinxPager($terms, $page = 1, $num = 20, $listIds = null, $aliases = true, $primary_ext = "Person"); $match['name'] = $name; $match['search_results'] = $pager->execute(); $this->matches[] = $match; } } } }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $this->form = new LoginForm(); $agent = $this->getContext()->getRequest()->getAttribute('userAgent'); //print($agent->isDoCoMo()); // APIのURLなどの詳細は以下を参照。 // http://developer.mixi.co.jp/appli/appli_mobile/lets_enjoy_making_mixiappmobile/for_partners $personApi = 'http://api.mixi-platform.com/os/0.8/people/@me/@self'; $persistenceApi = 'http://****************************************'; $mixi = new MixiAppMobileApi(); // owner(viewer) データ取得 //print_r($mixi->get($personApi)); $person = $mixi->get($personApi); if ($request->isMethod('post')) { $this->form->bind($request->getParameterHolder()->getAll()); if ($this->getRequestParameter('login') != '' && $this->form->isValid()) { $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_get_profile_myself_url'), array('guid' => 'DEBUG,sample_member_001', 'email' => $this->getRequestParameter('email'), 'password' => $this->getRequestParameter('password'))); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description)); } else { $this->getUser()->setName((string) $xml->profile->name); $this->getUser()->setEmail((string) $xml->profile->email); $this->getUser()->setPassword((string) $xml->profile->password); $this->getUser()->setAuthenticated(true); //$this->redirect("member", "index"); //print('index'); $this->forward('member', 'index'); $this->redirect('http://pontuyo.net/takutomo/web/member'); if ($agent->isDoCoMo()) { $this->redirect('member/index?sid=' + SID); } else { $this->redirect('member/index'); } } $this->display_description = (string) $xml->status->description; //$this->display_response = (string)$b->getResponseText(); } } }
public function execute($request) { if (!$this->context->user->hasCredential('administrator') || !sfConfig::get('app_check_for_updates')) { return sfView::NONE; } $this->currentVersion = qubitConfiguration::VERSION; $this->updateCheckUrl = 'http://updatecheck.qubit-toolkit.org/check/'; $this->cookiePath = sfContext::getInstance()->request->getRelativeUrlRoot(); if (1 > strlen($this->cookiePath)) { $this->cookiePath = '/'; } $this->updateCheckData = array(); $this->updateCheckData['address'] = $request->getUriPrefix() . $request->getScriptName() . $request->getPathInfo(); $this->updateCheckData['version'] = qubitConfiguration::VERSION . ' - ' . sfConfig::get('app_version'); if (null === ($this->updateCheckData['distribution'] = $this->context->user->getAttribute('distribution'))) { $packageXmlPath = sfConfig::get('sf_config_dir') . '/package.xml'; if (file_exists($packageXmlPath)) { require_once sfConfig::get('sf_root_dir') . '/vendor/FluentDOM/FluentDOM.php'; $fd = FluentDOM($packageXmlPath)->namespaces(array('p' => 'http://pear.php.net/dtd/package-2.0')); $this->context->user->setAttribute('distribution', $this->updateCheckData['distribution'] = $fd->find('/*/p:name')->item(0)->textContent); } } $this->updateCheckData['site_description'] = sfConfig::get('app_siteDescription'); $this->updateCheckData['site_title'] = sfConfig::get('app_siteTitle'); if (!$request->getCookie('has_js')) { if (null === ($this->lastVersion = $this->context->user->getAttribute('last_version'))) { try { $browser = new sfWebBrowser(); $this->lastVersion = $browser->post($this->updateCheckUrl, $this->updateCheckData)->getResponseText(); } catch (Exception $e) { $this->lastVersion = 0; } $this->context->user->setAttribute('last_version', $this->lastVersion); } if (0 == $this->lastVersion || 1 > version_compare($this->lastVersion, qubitConfiguration::VERSION)) { return sfView::NONE; } } }
public function executeSubmit(sfWebRequest $request) { $requestIdKey = null; $requestIdValue = null; if ($this->getRequestParameter('request_id') != "") { $requestIdKey = 'request_id'; $requestIdValue = $this->getRequestParameter('request_id'); } else { if ($this->getRequestParameter('event_id') != "") { $requestIdKey = 'event_id'; $requestIdValue = $this->getRequestParameter('event_id'); } } $b = new sfWebBrowser(); $b->post(sfConfig::get('sf_takutomo_eval_user_url'), array('guid' => 'mixi,' . MixiAppMobileApi::$ownerId, 'id' => $this->getRequestParameter('id'), 'eval' => $this->getRequestParameter('eval'), 'eval_comment' => $this->getRequestParameter('eval_comment'), $requestIdKey => $requestIdValue)); $this->form = new sfForm(); $xml = new SimpleXMLElement($b->getResponseText()); if ((int) $xml->status->code >= 1000) { $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description)); $this->setTemplate('index'); } $this->display_description = (string) $xml->status->description; }
protected function execute($arguments = array(), $options = array()) { $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); $web = new sfWebBrowser(); $latest = Doctrine::getTable('Position')->createQuery('p')->limit(1)->orderBy('p.timestamp DESC')->fetchOne(); $this->logSection($this->namespace, 'Getting latest instamapper positions'); $instamapper = $web->get('http://www.instamapper.com/api?action=getPositions&key=' . sfConfig::get('app_instamapper_api_key') . '&num=1000' . ($latest instanceof Position ? '&from_ts=' . $latest->getTimestamp() : '') . '&format=json'); try { if (!$instamapper->responseIsError()) { $json = json_decode($instamapper->getResponseText()); foreach ($json->positions as $gps) { if (!$latest instanceof Position || $gps->timestamp >= $latest->getTimestamp()) { $position = new Position(); $position->setDeviceKey($gps->device_key); $position->setDeviceLabel($gps->device_label); $position->setTimestamp($gps->timestamp); $position->setLatitude($gps->latitude); $position->setLongitude($gps->longitude); $position->setAltitude($gps->altitude); $position->setSpeed($gps->speed); $position->setHeading($gps->heading); $position->save(); echo '.'; $this->new++; } } } else { // Error response (eg. 404, 500, etc) } } catch (Exception $e) { // Adapter error (eg. Host not found) } echo "\n"; $this->logSection($this->namespace, 'Done: ' . $this->new . ' added.'); }
/** * Returns response as XML * * If reponse is not a valid XML it is being created from * a DOM document which is being created from a text response * (this is the case for not valid HTML documents). * * @return SimpleXMLElement */ public function getResponseXML() { try { $this->responseXml = parent::getResponseXML(); } catch (Exception $exception) { $doc = new DOMDocument(); $resp_str = $this->getResponseText(); // suppress error output libxml_use_internal_errors(true); $doc->loadHTML($resp_str); $this->responseXml = simplexml_import_dom($doc); // send errors to logger $errors = libxml_get_errors(); foreach ($errors as $error) { sfLogger::getInstance()->warning('{zWebBrowser::getResponseXML} ' . $this->displayXMLError($error)); } libxml_clear_errors(); } return $this->responseXml; }
/** * Retrieve a new sfFeed implementation instance, populated from a web feed. * The class of the returned instance depends on the nature of the web feed. * This method uses the sfWebBrowser plugin. * * @param string A web feed URI * * @return sfFeed A sfFeed implementation instance */ public static function createFromWeb($uri, $options = array()) { if (isset($options['adapter'])) { $browser = new sfWebBrowser(array(), $options['adapter'], isset($options['adapter_options']) ? $options['adapter_options'] : array()); } else { $browser = new sfWebBrowser(); } $browser->setUserAgent(isset($options['userAgent']) ? $options['userAgent'] : 'sfFeedReader/0.9'); if ($browser->get($uri)->responseIsError()) { $error = 'The given URL (%s) returns an error (%s: %s)'; $error = sprintf($error, $uri, $browser->getResponseCode(), $browser->getResponseMessage()); throw new Exception($error); } $feedString = $browser->getResponseText(); return self::createFromXml($feedString, $uri); }
/** * Loads an image from a file or URL and creates an internal thumbnail out of it * * @param string filename (with absolute path) of the image to load. If the filename is a http(s) URL, then an attempt to download the file will be made. * * @return boolean True if the image was properly loaded * @throws Exception If the image cannot be loaded, or if its mime type is not supported */ public function loadFile($image) { if (preg_match('/http(s)?:\\//i', $image)) { if (class_exists('sfWebBrowser')) { if (!is_null($this->tempFile)) { unlink($this->tempFile); } $this->tempFile = tempnam('/tmp', 'sfThumbnailPlugin'); $b = new sfWebBrowser(); try { $b->get($image); if ($b->getResponseCode() != 200) { throw new Exception(sprintf('%s returned error code %s', $image, $b->getResponseCode())); } file_put_contents($this->tempFile, $b->getResponseText()); if (!filesize($this->tempFile)) { throw new Exception('downloaded file is empty'); } else { $image = $this->tempFile; } } catch (Exception $e) { throw new Exception("Source image is a URL but it cannot be used because " . $e->getMessage()); } } else { throw new Exception("Source image is a URL but sfWebBrowserPlugin is not installed"); } } else { if (!is_readable($image)) { throw new Exception(sprintf('The file "%s" is not readable.', $image)); } } $this->adapter->loadFile($this, $image); }