예제 #1
0
파일: home.php 프로젝트: eva-bi/coupon
 public function action_search()
 {
     $coupons = "";
     try {
         $coupons = unserialize(Cache::get('cache_coupons'));
     } catch (\CacheNotFoundException $e) {
         $curl = Request::forge('http://allcoupon.jp/api-v1/coupon', 'curl');
         $curl->set_params(array('output' => 'json', 'apikey' => '9EBgSyRbAPmutrWE'));
         // this is going to be an HTTP POST
         $curl->set_method('get');
         $curl->set_auto_format(true);
         $result = $curl->execute()->response();
         $coupons = json_decode($result->body);
         Cache::set('cache_coupons', serialize($coupons), 300);
     }
     if ($area = Input::get('area')) {
         $coupons = array_filter($coupons, function ($v, $k) {
             return $v->coupon_area == Input::get('area');
         }, ARRAY_FILTER_USE_BOTH);
     }
     if ($category = Input::get('category')) {
         $coupons = array_filter($coupons, function ($v, $k) {
             return $v->category_name == Input::get('category');
         }, ARRAY_FILTER_USE_BOTH);
     }
     $view = Presenter::forge('home/search');
     $view->set('title', $area, false);
     $view->set('area', $area, false);
     $view->set('category', $category, false);
     $view->set('coupons', $coupons, false);
     $this->template->content = $view;
 }
예제 #2
0
 /**
  * Will attempt to find an item based on the current URL, and route it through a controller before returning a 404 error
  * 
  * @access  public
  * @return  Response
  */
 public function action_catchall()
 {
     // Will try to find the model based on the URL
     $model = $this->model = \CMF::currentModel();
     \CMF::$routed = true;
     // Return the normal 404 error if not found
     if (is_null($model)) {
         $action = trim(\Input::uri(), '/');
         if (!empty($action)) {
             return \Request::forge('base/' . $action, false)->execute()->response();
         }
         return $this->show404();
     }
     // So the model was found - check if it has a controller to route to
     $template = \CMF::$template;
     $action = \CMF::$action;
     if (\CMF::hasController($template)) {
         $module = \CMF::$module;
         $path = \CMF::$path;
         $route = (empty($module) ? '' : $module . '/') . $path . (empty($action) ? '' : '/' . $action);
         return \Request::forge($route, false)->execute()->response();
     } else {
         if (!empty($action)) {
             return $this->show404();
         } else {
             if (\CMF::$root) {
                 return \Request::forge('base/' . $action, false)->execute()->response();
             }
         }
     }
 }
예제 #3
0
 /**
  * Gets data from Google calculator
  *
  * @return	bool	success boolean
  */
 protected function _execute()
 {
     $currency_from = strtoupper($this->currency_from);
     $currency_to = strtoupper($this->currency_to);
     $amount = $this->amount;
     $url = sprintf($this->url, $amount, $currency_from, $currency_to);
     try {
         $request = \Request::forge($url, 'curl')->execute();
     } catch (\Exception $e) {
         throw new \FuelException('_execute() error in driver : ' . $this->config['driver'] . '. Error message returned: ' . $e->getMessage());
     }
     if ($request and $request->response()->status === 200 and $request->response()->body()) {
         $response = $request->response()->body();
         $search = array('lhs', 'rhs', 'error', 'icc');
         $replace = array('"lhs"', '"rhs"', '"error"', '"icc"');
         $response = str_replace($search, $replace, $response);
         $return = json_decode($response);
         if (empty($return->error)) {
             $result = (double) $return->rhs;
             return $result;
         }
     } else {
         throw new \FuelException('Got invalid status/body from ' . $this->config['driver']);
     }
     return false;
 }
예제 #4
0
 /**
  * Create Request object
  * @param  string $url     Resource URL
  * @param  array  $options Array of options (must include driver)
  * @return $this           Returns this for method chaining
  */
 protected function request($url, array $options = array())
 {
     empty($options['driver']) && ($options['driver'] = 'curl');
     $this->request = \Request::forge($url, $options);
     $this->get_config('auto_format', true) === false and $this->request->set_auto_format(false);
     return $this;
 }
예제 #5
0
	public function get_user_info(Consumer $consumer, Token $token)
	{		
		// Create a new GET request with the required parameters
		$request = Request::forge('resource', 'GET', 'http://api.twitter.com/1/users/lookup.json', array(
			'oauth_consumer_key' => $consumer->key,
			'oauth_token' => $token->access_token,
			'user_id' => $token->uid,
		));

		// Sign the request using the consumer and token
		$request->sign($this->signature, $consumer, $token);

		$user = current(json_decode($request->execute()));
		
		// Create a response from the request
		return array(
			'uid' => $token->uid,
			'nickname' => $user->screen_name,
			'name' => $user->name ?: $user->screen_name,
			'location' => $user->location,
			'image' => $user->profile_image_url,
			'description' => $user->description,
			'urls' => array(
			  'Website' => $user->url,
			  'Twitter' => 'http://twitter.com/'.$user->screen_name,
			),
		);
	}
예제 #6
0
	public function get_user_info(Consumer $consumer, Token $token)
	{
		// Create a new GET request with the required parameters
		$url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)';
		$request = Request::forge('resource', 'GET', $url, array(
			'oauth_consumer_key' => $consumer->key,
			'oauth_token' => $token->access_token,
		));

		// Sign the request using the consumer and token
		$request->sign($this->signature, $consumer, $token);
		
		$user = \Format::forge($request->execute(), 'xml')->to_array();
		
		// Create a response from the request
		return array(
			'uid' => $user['id'],
			'name' => $user['first-name'].' '.$user['last-name'],
			'nickname' => end(explode('/', $user['public-profile-url'])),
			'description' => $user['headline'],
			'location' => \Arr::get($user, 'location.name'),
			'urls' => array(
			  'Linked In' => $user['public-profile-url'],
			),
		);
	}
예제 #7
0
 /**
  * Sends the email using the Amazon SES email delivery system
  * 
  * @return boolean	True if successful, false if not.
  */
 protected function _send()
 {
     $params = array('Action' => 'SendEmail', 'Source' => static::format_addresses(array($this->config['from'])), 'Message.Subject.Data' => $this->subject, 'Message.Body.Text.Data' => $this->alt_body, 'Message.Body.Html.Data' => $this->body);
     $i = 0;
     foreach ($this->to as $value) {
         $params['Destination.ToAddresses.member.' . ($i + 1)] = static::format_addresses(array($value));
         ++$i;
     }
     $i = 0;
     foreach ($this->cc as $value) {
         $params['Destination.CcAddresses.member.' . ($i + 1)] = static::format_addresses(array($value));
         ++$i;
     }
     $i = 0;
     foreach ($this->bcc as $value) {
         $params['Destination.BccAddresses.member.' . ($i + 1)] = static::format_addresses(array($value));
         ++$i;
     }
     $i = 0;
     foreach ($this->reply_to as $value) {
         $params['ReplyToAddresses.member.' . ($i + 1)] = static::format_addresses(array($value));
         ++$i;
     }
     $date = date(DATE_RSS);
     $signature = $this->_sign_signature($date);
     $curl = \Request::forge('https://email.' . $this->region . '.amazonaws.com/', array('driver' => 'curl', 'method' => 'post'))->set_header('Content-Type', 'application/x-www-form-urlencoded')->set_header('X-Amzn-Authorization', 'AWS3-HTTPS AWSAccessKeyId=' . \Config::get('ses.access_key') . ', Algorithm=HmacSHA256, Signature=' . $signature)->set_header('Date', $date);
     $response = $curl->execute($params);
     if (intval($response->response()->status / 100) != 2) {
         return false;
     }
     return true;
 }
예제 #8
0
 /**
  * @return	bool	long url String
  */
 protected function _expand($url)
 {
     $curl = \Request::forge('http://api.bitly.com/v3/expand', array('driver' => 'curl', 'method' => 'get', 'params' => array('format' => 'json', 'apikey' => \Config::get('urlshortener.accounts.bitly.api_key'), 'login' => \Config::get('urlshortener.accounts.bitly.login'), 'shorturl' => $url)));
     $response = $curl->execute()->response();
     if (intval($response->status / 100) != 2) {
         throw new \Fuel_Exception('There was a problem expanding the url (' . $response->status . ')');
     }
     $data = json_decode($response->body);
     switch ($data->status_code) {
         case 200:
         case 201:
             $expanded = current($data->data->expand);
             if (isset($expanded->error)) {
                 if ($expanded->error == 'NOT_FOUND') {
                     throw new NotFoundException('The short url could not be expanded because it doesn\'t exist');
                 }
                 throw new \Fuel_Exception('There was a problem expanding the url (' . $expanded->error . ')');
             } else {
                 return $expanded->long_url;
             }
             break;
         case 500:
         case 401:
             throw new \Fuel_Exception('Please set your bit.ly API key and login name in the config (' . $data->status_code . ')');
             break;
         default:
             throw new \Fuel_Exception('There was a problem expanding the url (' . $data->status_code . ')');
     }
     return false;
 }
예제 #9
0
파일: fieldset.php 프로젝트: wushian/MDD
 public static function tearDownAfterClass()
 {
     // reset Request::$main
     $request = \Request::forge();
     $rp = new \ReflectionProperty($request, 'main');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
 }
예제 #10
0
 public function action_post($add = null, $id = null)
 {
     if ($id) {
         $view = \Request::forge('blog/backend/post/add/' . $id, false)->execute()->response()->body();
         $this->template->content = $view;
     }
     $view = \Request::forge('blog/backend/post/add', false)->execute()->response()->body();
     $this->template->content = $view;
 }
예제 #11
0
 public function get_user_info(Consumer $consumer, Token $token)
 {
     // Create a new GET request with the required parameters
     $request = Request::forge('resource', 'GET', 'https://api.dropbox.com/0/account/info', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     $user = json_decode($request->execute());
     // Create a response from the request
     return array('uid' => $token->uid, 'name' => $user->display_name, 'location' => $user->country);
 }
예제 #12
0
 public function action_index($ng_view = 'register')
 {
     $data = array();
     $data['facebook_login'] = View::forge('user/facebook');
     $data['form_create'] = Request::forge('user/auth/create', false)->execute()->response()->body();
     $data['form_login'] = Request::forge('user/auth/login', false)->execute()->response()->body();
     $data['form_recover'] = Request::forge('user/password/recover', false)->execute()->response()->body();
     $authentication_forms = View::forge('user/service/index')->set('content', $data)->set('ng_view', $ng_view);
     $this->template->content = View::forge('user/page')->set('header', $this->_header)->set('content', $authentication_forms);
 }
예제 #13
0
 public function get_user_info(Consumer $consumer, Token $token)
 {
     // Create a new GET request with the required parameters
     $request = Request::forge('resource', 'GET', 'http://api.flickr.com/services/rest', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'nojsoncallback' => 1, 'format' => 'json', 'method' => 'flickr.test.login'));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     $response = json_decode($request->execute(), true);
     // Create a response from the request
     return array('uid' => \Arr::get($response, 'user.id'), 'name' => \Arr::get($response, 'user.username._content'), 'nickname' => \Arr::get($response, 'user.username._content'));
 }
예제 #14
0
 /**
  * Call API
  *
  * @param  string $method
  * @param  string $uri
  * @param  array $params
  * @return \Fuel\Core\Response
  */
 protected static function call($method, $uri, array $params = array())
 {
     $curl = \Request::forge(static::$endpoint . $uri, 'curl');
     $curl->set_mime_type('json')->set_method($method)->set_params($params)->set_header('X-ChatWorkToken', \Config::get('chatwork.api_token'));
     try {
         $curl->execute();
     } catch (\Exception $e) {
         // do nothing.
     }
     return $curl->response();
 }
예제 #15
0
 public function action_featured($id = false)
 {
     $gallery = \Model_Gallery::query()->where('post_id', $id)->get_one();
     if (!$gallery) {
         return \Response::forge(\View::forge('frontend/post/show/image'));
     }
     $data['url'] = $gallery->asset->uri . '' . $gallery->asset->name;
     $data['extension'] = $gallery->asset->type;
     $this->data['image_url'] = \Request::forge('image/encoder/encodeBase64')->execute($data)->response()->body();
     return \Response::forge(\View::forge('frontend/post/show/image')->set($this->data, null, false));
 }
예제 #16
0
 /**
  * Check that both Controller_Index and Controller\Index with
  * subdirs will both be found.
  *
  * @dataProvider provider_test_classnames
  */
 public function test_classnames($url, $controller, $action, $check_class, $get_prefix)
 {
     // Mock check_class to avoid class_exists and autoloader.
     Test_Router_Mock::$check_class = $check_class;
     // Mock get_prefix to avoid Config and test both
     // Controller\\ and Controller_ prefixes.
     Test_Router_Mock::$get_prefix = $get_prefix;
     $match = Test_Router_Mock::process(\Request::forge($url));
     $this->assertEquals($controller, $match->controller);
     $this->assertEquals($action, $match->action);
     $this->assertEquals(array(), $match->method_params);
 }
예제 #17
0
파일: pagination.php 프로젝트: wushian/MDD
 public function tearDown()
 {
     // reset Request::$main
     $request = \Request::forge();
     $rp = new \ReflectionProperty($request, 'main');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
     // reset Request::$active
     $rp = new \ReflectionProperty($request, 'active');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
 }
예제 #18
0
파일: themer.php 프로젝트: sajans/cms
 public static function header($content)
 {
     $rendered_content = "";
     if (is_array($content)) {
         foreach ($content as $item) {
             $rendered_content .= Request::forge($item)->execute()->response();
         }
     } else {
         $rendered_content = Request::forge($content, false)->execute()->response();
     }
     return $rendered_content;
 }
예제 #19
0
 public function get_user_info(Consumer $consumer, Token $token)
 {
     // Create a new GET request with the required parameters
     $request = Request::forge('resource', 'GET', 'http://vimeo.com/api/rest/v2/', array('method' => 'vimeo.people.getInfo', 'oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'format' => 'json'));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     $response = json_decode($request->execute());
     $user = $response->person;
     $profile_image = end($user->portraits->portrait);
     $url = current($user->url);
     // Create a response from the request
     return array('uid' => $user->id, 'nickname' => $user->username, 'name' => $user->display_name ?: $user->username, 'location' => $user->location, 'image' => $profile_image->_content, 'description' => $user->bio, 'urls' => array('Website' => $url, 'Vimeo' => $user->profileurl));
 }
예제 #20
0
 public function get_user_info(Consumer $consumer, Token $token)
 {
     // Create a new GET request with the required parameters
     $request = Request::forge('resource', 'GET', 'http://api.tumblr.com/v2/user/info', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     $response = json_decode($request->execute());
     $status = current($response);
     $response = next($response);
     $user = $response->user;
     // Create a response from the request
     return array('uid' => $user->name, 'name' => $user->name, 'likes' => $user->likes, 'following' => $user->following, 'default_post_format' => $user->default_post_format);
 }
예제 #21
0
파일: Google.php 프로젝트: jaksmid/website
 public function get_user_info(OAuth_Consumer $consumer, OAuth_Token $token)
 {
     // Create a new GET request with the required parameters
     $request = Request::forge('resource', 'GET', 'https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     $response = json_decode($request->execute(), true);
     // Fetch data parts
     $email = \Arr::get($response, 'feed.id.$t');
     $name = \Arr::get($response, 'feed.author.0.name.$t');
     $name == '(unknown)' and $name = $email;
     return array('uid' => $email, 'nickname' => \Inflector::friendly_title($name), 'name' => $name, 'email' => $email, 'location' => null, 'image' => null, 'description' => null, 'urls' => array());
 }
 public function response()
 {
     $error_code = $this->getMessage();
     $error_list = Lang::load('error/user', $error_code);
     if (!isset($error_list[$error_code])) {
         $error_code = \Model_Error::ER00001;
     }
     $error_message = $error_list[$error_code];
     $params = array('error_code' => $error_code, 'error_message' => $error_message, 'line' => $this->getLine(), 'file' => $this->getFile(), 'url' => Uri::main(), 'input' => print_r(Input::all(), true), 'real_ip' => Input::real_ip(), 'user_agent' => Input::user_agent(), 'user_id' => Auth::get_user_id(), 'occurred_at' => date('Y/m/d H:i:s'));
     $email = new Model_Email();
     $email->sendMailByParams('error', $params);
     $response = \Request::forge('errors/index', false)->execute($params)->response();
     return $response;
 }
예제 #23
0
 /**
  * Logging wrapper for off site requests (Allows for desired log formatting)
  * 
  * @param string $uri		The URL to execute
  * @param string $options	The type of request
  * @param string $method	The HTTP method to use for the request
  */
 public static function forge($uri = NULL, $options = true, $method = NULL)
 {
     /*
      * If someone uses this for internal calls, we'll still allow it to function, but we don't log it since it
      * isn't a remote request.
      */
     if (is_string($options)) {
         // We only grab the URL and method, not params or headers since the latter two could contain sensitive data.
         $tokens = array('url' => $uri, 'method' => $method);
         // Log the request
         \Log::logger('INFO', 'REMOTE:' . $options, 'Started execution of an off-site request', __METHOD__, $tokens);
     }
     return parent::forge($uri, $options, $method);
 }
예제 #24
0
 public function get_user_info(Consumer $consumer, Token $token)
 {
     // Create a new GET request with the required parameters
     $url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)?format=json';
     $request = Request::forge('resource', 'GET', $url, array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token));
     // Sign the request using the consumer and token
     $request->sign($this->signature, $consumer, $token);
     // Gets the JSON object from the response
     $user = json_decode($request->execute()->body, true);
     // Split the profile url to get the user's nickname
     $split_url = explode('/', $user['publicProfileUrl']);
     // Create a response from the request
     return array('uid' => $user['id'], 'name' => $user['firstName'] . ' ' . $user['lastName'], 'image' => $user['pictureUrl'], 'nickname' => end($split_url), 'description' => $user['headline'], 'location' => \Arr::get($user, 'location.name'), 'urls' => array('Linked In' => $user['publicProfileUrl']));
 }
예제 #25
0
 public function tearDown()
 {
     // remove the fake uri
     if (property_exists($this, 'pathinfo')) {
         $_SERVER['PATH_INFO'] = $this->pathinfo;
     } else {
         unset($_SERVER['PATH_INFO']);
     }
     // reset Request::$main
     $request = \Request::forge();
     $rp = new \ReflectionProperty($request, 'main');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
 }
예제 #26
0
 private function exportLanguageCanonical()
 {
     $base_url = \CMF\Model\DevSettings::instance()->parent_site;
     if (!empty($base_url)) {
         $url = $base_url . "/api/_lang-canonicals_";
         $curl = \Request::forge($url, 'curl');
         if (!empty($api_key)) {
             $curl->set_header('Authorization', 'bearer ' . \CMF\Model\DevSettings::instance()->parent_site_api_key);
         }
         $curl->set_method('post');
         $curl->set_header('Content-Type', 'application/json');
         $curl->set_header('Content-Language', \Config::get('language'), true);
         $curl->set_params(json_encode($this->jsonObject));
         $curl->execute();
     }
 }
예제 #27
0
 /**
  * Gets data from Openxchangerates site
  *
  * @return	bool	success boolean
  */
 protected function _execute()
 {
     //http://openexchangerates.org/api/latest.json?app_id=XXXXXXXXXXXX
     $app_id = $this->get_config('drivers.openexchangerates.app_id');
     if (!$app_id) {
         throw new \FuelException('_execute() error in driver : ' . $this->config['driver'] . '. app_id not set.');
     }
     $cache_found = false;
     $response = null;
     // try to retrieve the cache
     try {
         $response = \Cache::get('currency_openexchangerates');
         $cache_found = true;
     } catch (\CacheNotFoundException $e) {
         try {
             $url = $this->url . '?app_id=' . $app_id;
             $request = \Request::forge($url, 'curl')->execute();
         } catch (\Exception $e) {
             throw new \FuelException('_execute() error in driver : ' . $this->config['driver'] . '. Error message returned: ' . $e->getMessage());
         }
     }
     if ($response or $request) {
         if (!$cache_found) {
             if ($request->response()->status === 200 and $request->response()->body()) {
                 $response = $request->response()->body();
                 \Cache::set('currency_openexchangerates', $response, $this->get_config('currency.cache', 1800));
             } else {
                 throw new \FuelException('Got invalid status/body from ' . $this->config['driver']);
             }
         }
         $return = json_decode($response);
         $currency_from = strtoupper($this->currency_from);
         $currency_to = strtoupper($this->currency_to);
         $amount = $this->amount;
         if (isset($return->rates->{$currency_to}) and isset($return->rates->{$currency_from})) {
             $part1 = bcdiv($amount, $return->rates->{$currency_from}, 6);
             return bcmul($part1, $return->rates->{$currency_to}, 6);
         } else {
             throw new \FuelException('Driver: ' . $this->config['driver'] . ' does not support $currency_to ' . $currency_to . ' and $currency_from: ' . $currency_from);
         }
     }
     return false;
 }
예제 #28
0
 /**
  * Gets data from JSON source
  *
  * @return	bool	success boolean
  */
 protected function _execute()
 {
     $currency_from = strtolower($this->currency_from);
     $currency_to = strtolower($this->currency_to);
     $amount = $this->amount;
     $url = $this->url;
     try {
         $request = \Request::forge($url, 'curl')->execute();
     } catch (\Exception $e) {
         throw new \FuelException('_execute() error in driver : ' . $this->config['driver'] . '. Error message returned: ' . $e->getMessage());
     }
     if ($request and $request->response()->status === 200 and $request->response()->body()) {
         $jsondata = json_decode($request->response()->body());
         return $this->_convert($amount, $currency_from, $currency_to, $jsondata);
     } else {
         throw new \FuelException('Got invalid status/body from ' . $this->config['driver']);
     }
     return false;
 }
예제 #29
0
 /**
  * Triggers an event.
  *
  * @param string       $name   The name of the event to trigger.
  * @param Model_Seller $seller The seller for which to trigger the event.
  * @param array        $data   Optional data to send to the event callback.
  *
  * @return bool
  */
 public static function trigger($name, Model_Seller $seller, array $data = array())
 {
     $callback = Service_Seller_Callback::find_one(array('seller' => $seller, 'event' => $name));
     if (!$callback) {
         return false;
     }
     // Event name should always be included in the post data.
     $data['event'] = $name;
     $request = Request::forge($callback->url, 'curl');
     $request->set_method('post');
     $request->set_params($data);
     try {
         $request->execute();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     return true;
 }
예제 #30
0
 public function tearDown()
 {
     // remove the fake uri
     if (property_exists($this, 'pathinfo')) {
         $_SERVER['PATH_INFO'] = $this->pathinfo;
     } else {
         unset($_SERVER['PATH_INFO']);
     }
     // reset Request::$main
     $request = \Request::forge();
     $rp = new \ReflectionProperty($request, 'main');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
     // reset Request::$active
     $rp = new \ReflectionProperty($request, 'active');
     $rp->setAccessible(true);
     $rp->setValue($request, false);
     // ensure base_url is reset even if an exception occurs
     Config::set('base_url', $this->old_base_url);
 }