Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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();
     }
 }
Exemplo n.º 3
0
 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);
     }
 }
Exemplo n.º 4
0
 /**
  * /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));
 }
Exemplo n.º 5
0
 /**
  * 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');
         }
     }
 }
Exemplo n.º 6
0
 /**
  * 会員が存在するかチェック 
  */
 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;
 }
Exemplo n.º 7
0
 /**
  * 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();
 }
Exemplo n.º 8
0
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;
    }
}
Exemplo n.º 9
0
 /**
  * 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();
 }
Exemplo n.º 10
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     //xmlを連想配列に変換
     $options = array('complexType' => 'array');
     $Unserializer = new XML_Unserializer($options);
     $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 {
         $status = $Unserializer->unserialize($b->getResponseText());
         $this->member = $Unserializer->getUnserializedData();
     }
     $b->post(sfConfig::get('sf_takutomo_get_eval_comments_url'), array('id' => $this->getRequestParameter('m_id')));
     if ((int) $xml->status->code >= 1000) {
         $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description));
     } else {
         $status = $Unserializer->unserialize($b->getResponseText());
         $this->comments = $Unserializer->getUnserializedData();
     }
 }
Exemplo n.º 11
0
 /**
  * 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();
 }
Exemplo n.º 12
0
 /**
  * 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');
         }
     }
 }
Exemplo n.º 13
0
 /**
  * 相乗りリストを返す 
  * 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;
     }
 }
Exemplo n.º 14
0
 /**
  * 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();
         }
     }
 }
Exemplo n.º 15
0
 /**
  * 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');
         }
     }
 }
Exemplo n.º 16
0
 /**
  * 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);
 }
 /**
  * タクトモ会員登録
  * 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;
 }
Exemplo n.º 18
0
 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');
         }
     }
 }
 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);
     }
 }
Exemplo n.º 20
0
 /**
  * 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();
         }
     }
 }
Exemplo n.º 21
0
 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;
             }
         }
     }
 }
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 static function createFiles($filePath, $originalFilename = '')
 {
     //generate filename
     $filename = self::generateFilename($originalFilename);
     $originalFilePath = $filePath;
     //if remote path, create temporary local copy
     if (preg_match('#http(s)?://#i', $filePath)) {
         $url = $filePath;
         $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($url)->responseIsError()) {
             return false;
         }
         $fileData = $b->getResponseText();
         unset($b);
         $filePath = sfConfig::get('sf_temp_dir') . DIRECTORY_SEPARATOR . $filename;
         $localImage = fopen($filePath, 'wb');
         fwrite($localImage, $fileData);
         if (!fclose($localImage)) {
             throw new Exception("Couldn't close file: " . $filePath);
         }
         if (strtolower(substr($originalFilePath, -3, 3)) == "svg") {
             if (self::imageMagickInstalled()) {
                 $svgFilepath = sfConfig::get('sf_temp_dir') . DIRECTORY_SEPARATOR . substr($filename, 0 - 3) . ".svg";
                 $origFilepath = sfConfig::get('sf_temp_dir') . DIRECTORY_SEPARATOR . $filename;
                 rename($origFilepath, $svgFilepath);
                 exec("{$convert} {$svgFilepath} {$origFilepath}");
             }
         }
     }
     //create full size file up to 1024x1024
     if (!self::createFile($filename, $filePath, 'large', 1024, 1024)) {
         return false;
     }
     //create profile size
     if (!self::createFile($filename, $filePath, 'profile', 200, 200)) {
         unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'large' . DIRECTORY_SEPARATOR . $filename);
         return false;
     }
     //create small size
     if (!self::createFile($filename, $filePath, 'small', null, 50)) {
         unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'large' . DIRECTORY_SEPARATOR . $filename);
         unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'profile' . DIRECTORY_SEPARATOR . $filename);
         return false;
     }
     /*
     if (!self::createSquareFile($filename, $filePath, 'square', 300))
     {
       unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'large' . DIRECTORY_SEPARATOR . $filename);
       unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'profile' . DIRECTORY_SEPARATOR . $filename);
       unlink(sfConfig::get('sf_image_dir') . DIRECTORY_SEPARATOR . 'small' . DIRECTORY_SEPARATOR . $filename);
       return false;    
     }
     */
     //remove temporary file
     if (isset($url)) {
         unlink($filePath);
     }
     return $filename;
 }
Exemplo n.º 24
0
    $t->diag('Soap requests');
    $url = 'http://www.abundanttech.com/WebServices/Population/population.asmx';
    $headers = array('Soapaction' => 'http://www.abundanttech.com/WebServices/Population/getWorldPopulation', 'Content-Type' => 'text/xml');
    $requestBody = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <getWorldPopulation xmlns="http://www.abundanttech.com/WebServices/Population" />
  </soap:Body>
</soap:Envelope>
EOT;
    $b = new sfWebBrowser(array(), $adapter);
    $b->post($url, $requestBody, $headers);
    $t->like($b->getResponseText(), '/<Country>World<\\/Country>/', 'sfWebBrowser can make a low-level SOAP call without parameter');
    $url = 'http://www.abundanttech.com/WebServices/Population/population.asmx';
    $headers = array('Soapaction' => 'http://www.abundanttech.com/WebServices/Population/getPopulation', 'Content-Type' => 'text/xml');
    $requestBody = <<<EOT
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pop="http://www.abundanttech.com/WebServices/Population">
  <soapenv:Header/>
  <soapenv:Body>
    <pop:getPopulation>
      <pop:strCountry>Comoros</pop:strCountry>
    </pop:getPopulation>
  </soapenv:Body>
</soapenv:Envelope>
EOT;
    $b = new sfWebBrowser(array(), $adapter);
    $b->post($url, $requestBody, $headers);
    $t->like($b->getResponseText(), '/<Country>Comoros<\\/Country>/', 'sfWebBrowser can make a low-level SOAP call with parameter');
    $t->diag('');
}
$client = new IXR_Client($project_baseurl . "/sfWebRPCPluginDemo/RPC2");
// query remote neoip-casti to pull cast_mdata
$succeed = $client->query('add', 3, 7);
$t->is($client->query('add', 3, 7), true, 'call to sfWebRPCPluginDemo::add succeed');
// if it failed, notify the error
//if(! $succeed )	throw new Exception("Error doing xmlrpc to casti_srv_uri due to ".$client->getErrorMessage());
$t->is($client->getResponse(), 10, 'add 3+7 is 10');
$t->is($client->query('fctnamej_which_doesnt_exist'), false, 'call to unexisting function fails as expected');
/************************************************************************/
/*		Test handler JSON					*/
/************************************************************************/
$t->diag('sfWebRPCPlugin JSON');
$b->get($project_baseurl . "/sfWebRPCPluginDemo/JSON?method=add&arg0=3&arg1=2");
$t->is($b->getResponseCode(), 200, 'http code 200 on "add" JSON handler');
$t->is($b->getResponseHeader("Content-Type"), "application/json", "mimetype is application/json on json call");
$t->is($b->getResponseText(), 5, "response is 5 (as expected for add(3,2))");
$b->get($project_baseurl . "/sfWebRPCPluginDemo/JSON?method=add&arg0=3");
$t->isnt($b->getResponseCode(), 200, 'http code NOT 200 "add" when wrong number of parameters');
/************************************************************************/
/*		Test handler JSONP					*/
/************************************************************************/
$t->diag('sfWebRPCPlugin JSONP');
$b->get($project_baseurl . "/sfWebRPCPluginDemo/JSON?callback=cbsample&method=add&arg0=3&arg1=2");
$t->is($b->getResponseCode(), 200, 'http code 200 on "add" JSON handler');
$t->like($b->getResponseHeader("Content-Type"), "/text\\/javascript/", "mimetype is text/javascript on JSONP call");
$t->is($b->getResponseText(), 'cbsample("5")', 'response is cbsample("5")');
/************************************************************************/
/*		Test handler XDOMRPC					*/
/************************************************************************/
$t->diag('sfWebRPCPlugin XDOMRPC');
$b->get($project_baseurl . "/sfWebRPCPluginDemo/XDOMRPC?obj_id=4242&method=add&arg0=3&arg1=2");
Exemplo n.º 26
0
 static function parseV3($str)
 {
     $str = preg_replace('/[\\n\\r]/', ' ', $str);
     $url = 'http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=' . urlencode($str);
     $c = new sfWebBrowser();
     try {
         if (!$c->get($url)->responseIsError()) {
             $c->setResponseText(iconv('ISO-8859-1', 'UTF-8', $c->getResponseText()));
             $json = $c->getResponseText();
             $result = json_decode($json, true);
         } else {
             return null;
         }
     } catch (Exception $e) {
         // Adapter error (eg. Host not found)
         throw $e;
     }
     if ($result['status'] == 'OK') {
         $address = self::parseGeoArray($result);
         return $address;
     } else {
         return false;
     }
 }
 /**
  * Populate a digital object from a resource pointed to by a URI
  * This is for, eg. importing encoded digital objects from XML
  *
  * @param string  $uri  URI pointing to the resource
  * @return boolean  success or failure
  */
 public function importFromURI($uri, $options = array())
 {
     // Parse URL into components and get file/base name
     $uriComponents = parse_url($uri);
     // Initialize web browser
     $browser = new sfWebBrowser(array(), null, array('Timeout' => 10));
     // Add asset to digital object assets array
     if (true !== $browser->get($uri)->responseIsError() && 0 < strlen($filename = basename($uriComponents['path']))) {
         $asset = new QubitAsset($uri, $browser->getResponseText());
         $this->assets[] = $asset;
     } else {
         throw new sfException('Encountered error fetching external resource.');
     }
     // Set digital object as external URI
     $this->usageId = QubitTerm::EXTERNAL_URI_ID;
     // Save filestream temporary, because sfImageMagickAdapter does not support load data from streams
     $this->localPath = Qubit::saveTemporaryFile($filename, $asset->getContents());
     $this->name = $filename;
     $this->path = $uri;
     $this->checksum = $asset->getChecksum();
     $this->checksumType = $asset->getChecksumAlgorithm();
     $this->byteSize = strlen($browser->getResponseText());
     $this->setMimeAndMediaType();
 }
Exemplo n.º 28
0
 /**
  * Validate the IPN notification
  *
  * PayPal expects to receive a response to an IPN message within 30 seconds.
  * Your listener should not perform time-consuming operations, such as
  * creating a process, before responding to the IPN message.
  *
  * @param none
  * @return boolean
  */
 protected function handlePaypalData($parameters = array(), $is_ipn = false)
 {
     $this->debug('Parameters posted from Paypal ...');
     foreach ($parameters as $key => $value) {
         $this->debug("{$key}={$value}");
     }
     //--------------------------------------------------------------------------
     // store IPN data in object
     //--------------------------------------------------------------------------
     $this->ipnData = $parameters;
     $this->rewind();
     $this->relatedEntity = null;
     //--------------------------------------------------------------------------
     // post validation request; prepend cmd, leave order intact
     //--------------------------------------------------------------------------
     if ($is_ipn) {
         $this->debug('Sending IPN validation response');
         $browser = new sfWebBrowser(array("Content-type: application/x-www-form-urlencoded\r\n", "Connection: close\r\n\r\n"), null, array('ssl_verify' => false));
         $url = $this->testMode ? self::$ppSandboxUrl : self::$ppProductionUrl;
         $browser->post($url, array('cmd' => '_notify-validate') + $this->ipnData);
     }
     $dispatcher = sfContext::getInstance()->getEventDispatcher();
     //--------------------------------------------------------------------------
     // After PayPal verifies the message, there are additional checks that
     // your listener or back-end or administrative software must take
     //--------------------------------------------------------------------------
     try {
         //------------------------------------------------------------------------
         // make sure response == 'VERIFIED'
         //------------------------------------------------------------------------
         if ($is_ipn) {
             $this->checkVerified($browser->getResponseText());
         }
         //------------------------------------------------------------------------
         // make sure the IPN message is in relation to the business account
         //------------------------------------------------------------------------
         $this->checkReceiver();
         //------------------------------------------------------------------------
         // make sure this response has not been handled before
         //------------------------------------------------------------------------
         $this->checkDuplicateTxn();
         //------------------------------------------------------------------------
         // save the transaction
         //------------------------------------------------------------------------
         $transaction = $this->saveTransaction();
         //------------------------------------------------------------------------
         // make sure IPN data matches an existing entity
         //------------------------------------------------------------------------
         $this->checkEntity();
         //------------------------------------------------------------------------
         // call application specific method to handle payment status
         //------------------------------------------------------------------------
         $this->handlePaymentStatus($this['payment_status'], $this['pending_reason']);
         $dispatcher->notify(new sfEvent($transaction, 'paypal.ipn_success', array('ipn_data' => $this->ipnData)));
         $this->debug('******* SUCCESS ********');
     } catch (sfException $e) {
         $this->lastError = $e->getMessage();
         $dispatcher->notify(new sfEvent($this->lastError, 'paypal.ipn_error', array('ipn_data' => $this->ipnData)));
         $this->debug($this->lastError, 'alert');
         $this->debug('******* FAILED ********');
     }
     return isset($transaction) ? $transaction : false;
 }
Exemplo n.º 29
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->form = new ReserveDriverForm();
     $b = new sfWebBrowser();
     $now = strtotime('+15 minute');
     $depart_date = array('year' => date('Y', $now), 'month' => date('n', $now), 'day' => date('j', $now));
     $depart_time = array('hour' => date('G', $now), 'minute' => (int) date('i', $now));
     $b->post(sfConfig::get('sf_takutomo_get_profile_url'), array('id' => $this->getRequestParameter('driver_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();
     }
     if ($request->isMethod('get')) {
         $mixi = new MixiAppMobileApi();
         $persistence = $mixi->get(sfConfig::get('sf_opensocial_persistence_api'));
         $mixi_persistence = $persistence->entry->{'mixi.jp:' . MixiAppMobileApi::$ownerId};
         $this->form->setDefault('to_address', $mixi_persistence->to_address);
         $this->form->setDefault('to_lon', $mixi_persistence->to_lon);
         $this->form->setDefault('to_lat', $mixi_persistence->to_lat);
         $this->form->setDefault('from_address', $mixi_persistence->from_address);
         $this->form->setDefault('from_lon', $mixi_persistence->from_lon);
         $this->form->setDefault('from_lat', $mixi_persistence->from_lat);
         $this->form->setDefault('depart_date', $depart_date['year'] . sprintf('%02d', $depart_date['month']) . $depart_date['day']);
         $this->form->setDefault('depart_time', $depart_time['hour'] . sprintf('%02d', $depart_time['minute']));
         $this->form->setDefault('driver_m_id', $request->getParameter('driver_id'));
         $this->form->setDefault('phone', $request->getParameter('phone'));
         $request->setParameter('from_address', $mixi_persistence->from_address);
         $request->setParameter('to_address', $mixi_persistence->to_address);
         $request->setParameter('depart_date', $depart_date['year'] . sprintf('%02d', $depart_date['month']) . $depart_date['day']);
         $request->setParameter('depart_time', $depart_time['hour'] . sprintf('%02d', $depart_time['minute']));
     } else {
         if ($request->isMethod('post')) {
             $this->form->bind($request->getParameterHolder()->getAll());
             if ($this->form->isValid()) {
                 $b->post(sfConfig::get('sf_takutomo_reserve_driver_url'), array('guid' => 'DEBUG,sample_member_001', 'email' => $this->getUser()->getEmail(), 'password' => $this->getUser()->getPassword(), 'from_address' => $this->getRequestParameter('from_address'), 'from_lat' => $this->getRequestParameter('from_lat'), 'from_lon' => $this->getRequestParameter('from_lon'), 'to_address' => $this->getRequestParameter('to_address'), 'to_lat' => $this->getRequestParameter('to_lat'), 'to_lon' => $this->getRequestParameter('to_lon'), 'depart_date' => $this->getRequestParameter('depart_date'), 'depart_hour' => substr($this->getRequestParameter('depart_time'), 0, 2), 'depart_min' => substr($this->getRequestParameter('depart_time'), 2, 2), 'driver_m_id' => $request->getParameter('driver_m_id'), 'phone' => $request->getParameter('phone')));
                 $xml = new SimpleXMLElement($b->getResponseText());
                 //print $b->getResponseText();
                 //print((string)$xml->status->code);
                 if ((int) $xml->status->code >= 1000) {
                     $this->form->getErrorSchema()->addError(new sfValidatorError(new sfValidatorPass(), (string) $xml->status->description));
                 } else {
                     //検索条件をsessionに格納
                     $this->getUser()->setToAddress($this->getRequestParameter('to_address'));
                     $this->getUser()->setToLon($this->getRequestParameter('to_lon'));
                     $this->getUser()->setToLat($this->getRequestParameter('to_lat'));
                     $this->getUser()->setFromAddress($this->getRequestParameter('from_address'));
                     $this->getUser()->setFromLon($this->getRequestParameter('from_lon'));
                     $this->getUser()->setFromLat($this->getRequestParameter('from_lat'));
                     $this->setTemplate('submit');
                 }
                 $this->display_description = (string) $xml->status->description;
                 $this->display_phone = (string) $xml->taxi_data->phone;
             }
         }
     }
 }
Exemplo n.º 30
-1
 /**
  * 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);
 }