/** * * 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; }
/** * 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; }