Ejemplo n.º 1
0
 /**
  * Handles the requests to the proxy.
  *
  * @param  Social_Service_Account|int  $account
  * @param  string                      $api
  * @param  array                       $args
  * @param  string                      $method
  * @return Social_Response|bool
  */
 public function request($account, $api, array $args = array(), $method = 'GET')
 {
     if (!is_object($account)) {
         $account = $this->account($account);
     }
     if ($account !== false) {
         $proxy = apply_filters('social_api_proxy', Social::$api_url . $this->_key, $this->_key);
         $api = apply_filters('social_api_endpoint', $api, $this->_key);
         $method = apply_filters('social_api_endpoint_method', $method, $this->_key);
         $args = apply_filters('social_api_endpoint_args', $args, $this->_key);
         $request = wp_remote_post($proxy, array('sslverify' => false, 'body' => array('api' => $api, 'method' => $method, 'public_key' => $account->public_key(), 'hash' => sha1($account->public_key() . $account->private_key()), 'params' => json_encode($args))));
         if (!is_wp_error($request)) {
             $request['body'] = apply_filters('social_response_body', $request['body'], $this->_key);
             if (is_string($request['body'])) {
                 // slashes are normalized (always added) by WordPress
                 $request['body'] = json_decode(stripslashes_deep($request['body']));
             }
             return Social_Response::factory($this, $request, $account);
         } else {
             Social::log('Service::request() error: ' . $request->get_error_message());
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Create tweet when Social does a broadcast
  *
  * @param Social_Response $response 
  * @param string $key
  * @param stdClass $post
  * @return void
  */
 static function social_broadcast_response($response, $key, $post)
 {
     // get tweet
     $data = $response->body();
     $tweet = $data->response;
     // check if it's one of our enabled accounts
     self::get_social_accounts();
     foreach (self::$accounts as $account) {
         if ($account->option('enabled') && $account->social_acct->id() == $tweet->user->id) {
             // populate AKTT_Tweet object, save
             $t = new AKTT_Tweet($tweet);
             $t->add();
             break;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Sets the raw data for the broadcasted post.
  *
  * @wp-filter social_broadcast_response
  * @static
  * @param  array                   $data
  * @param  Social_Service_Account  $account
  * @param  string                  $service_key
  * @param  int                     $post_id
  * @param  Social_Response         $response
  * @return array
  */
 public static function social_save_broadcasted_ids_data(array $data, Social_Service_Account $account, $service_key, $post_id, Social_Response $response = null)
 {
     if ($service_key == 'twitter') {
         if (!empty($response)) {
             $data['message'] = base64_encode(json_encode($response->body()->response));
         }
         $data['account'] = (object) array('user' => $account->as_object()->user);
     }
     return $data;
 }