/** * * Posta sulla timeline di Facebook (se possibile) * @param array $reviewDescription * @param PCModelWebsite $onSite * @param PCModelUserOauth $user * @return boolean */ public static function postReviewToFacebook($reviewDescription, $onSite, $user){ PCAutoloader::importLibrary('facebook'); $oauth = $user->getOauthStore(); if($oauth == null){ return FALSE; } $domain = $onSite->getDomain(); $usa = $reviewDescription['usability']; $rel = $reviewDescription['reliability']; $cont = $reviewDescription['contents']; $vote = sprintf("%.1f",(($usa+$rel+$cont)/3.0)); $text = "I've just reviewed $domain (Vote: $vote) using http://websherpa.me : ".$reviewDescription['comment']; $facebook = new Facebook(array( "appId" => FB_APP_ID, "secret" => FB_APP_SECRET, "cookie" => true )); $facebook->setAccessToken($oauth['oauth_token']); try { $result = $facebook->api("/me/feed", 'post', array( 'message' => $text, 'name' => 'WebSherpa', 'link' => "http://websherpa.me/sites/site?id=".$onSite->getIdentifier(), 'picture' => 'http://websherpa.me/public/fresh/img/logo_footer.png', )); return isset($result['id']); } catch (FacebookApiException $exc) { c_dump($exc); return FALSE; } return FALSE; }
/** * @param PCRequest $request */ public function twitterLoginAction($request){ PCAutoloader::importLibrary("twitter"); unset($_SESSION['reg_username']); $connection = new TwitterOAuth(TW_CONSUMER_KEY, TW_CONSUMER_SECRET); $connection->host = "https://api.twitter.com/1.1/"; /* Get temporary credentials. */ $request_token = $connection->getRequestToken(TW_OAUTH_CALLBACK); /* Save temporary credentials to session. */ $_SESSION['oauth_token'] = $token = $request_token['oauth_token']; $_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret']; /* If last connection failed don't display authorization link. */ switch ($connection->http_code) { case 200: /* Build authorize URL and redirect user to Twitter. */ $url = $connection->getAuthorizeURL($token); throw new PCExceptionRedirection($url); break; default: /* Show notification if something went wrong. */ echo 'Could not connect to Twitter. Refresh the page or try again later. code: '.$connection->http_code; } }
/** * Posta sulla timeline di twitter * @param array $reviewDescription * @param PCModelWebsite $onSite * @param PCModelUserOauth $user * @return boolean */ public static function postReviewToTwitter($reviewDescription, $onSite ,$user){ PCAutoloader::importLibrary('twitter'); $oauth = $user->getOauthStore(); if($oauth == null) return FALSE; $connection = new TwitterOAuth(TW_CONSUMER_KEY, TW_CONSUMER_SECRET, $oauth['oauth_token'], $oauth['oauth_secret']); $domain = $onSite->getDomain(); $usa = $reviewDescription['usability']; $rel = $reviewDescription['reliability']; $cont = $reviewDescription['contents']; $vote = sprintf("$.1f",(($usa+$rel+$cont)/3.0));; $text = "I've just reviewed http://$domain (Vote: $vote) using @WebSherpa_me http://websherpa.me/sites/site?id=".$onSite->getIdentifier(); $status = $connection->post('statuses/update', array('status' => $text)); if(isset($status->errors)) return FALSE; return TRUE; }