/** * * @param Ai1ec_Facebook_Proxy $facebook an instance of the facebook class * * @param array $events the events to check * * @throws WP_FacebookApiException if something goes wrong in the facebook call * * @return array the events with the page_ids converted into venues */ protected function update_events_with_page_id_as_venues(Ai1ec_Facebook_Proxy $facebook, array $events) { // This array holds the fql queries $fql = array(); // This array will hold the Venues $venues = array(); // This array keeps track of what events need a venue so that we save cycles afterwards $indexes = array(); $index = 0; foreach ($events as $event) { // If the venues is a id if (isset($event['venue']['id'])) { $pid = $event['venue']['id']; // Save the index of this event $indexes[$event['eid']] = $index; // Create the query. $fql[$event['eid']] = "SELECT location FROM page WHERE page_id = {$pid}"; } $index++; } if (!empty($fql)) { try { $venues = $facebook->api(array('method' => 'fql.multiquery', 'queries' => $fql)); // Merge the results if no exception is thrown. $events = $this->merge_events_and_venues($events, $venues, $indexes); } catch (WP_FacebookApiException $e) { throw $e; } } return $events; }
public function get_users_from_facebook(Ai1ec_Facebook_Proxy $facebook) { $fql = "SELECT name, id, pic FROM profile WHERE id = me() OR id IN (SELECT uid2 FROM friend WHERE uid1 = me() )"; try { $items = $facebook->api(array('method' => 'fql.query', 'query' => $fql)); } catch (WP_FacebookApiException $e) { throw $e; } return $this->convert_user_data_for_saving($items); }
/** * (non-PHPdoc) * @see Sync_Objects_From_Facebook_Strategy_Interface::get_users_from_facebook() */ public function get_users_from_facebook(Ai1ec_Facebook_Proxy $facebook) { $user = $facebook->getUser(); try { $items = $facebook->api("/{$user}/groups/"); $items = $items['data']; $items = $this->get_images($facebook, $items); } catch (WP_FacebookApiException $e) { throw $e; } return $this->convert_group_data_for_saving($items); }
/** * (non-PHPdoc) * @see Query_Events_Strategy_Interface::query_events() */ public function query_events(Ai1ec_Facebook_Proxy $facebook, array $users, $timestamp) { $events = array(); // Create the fql query. $fql = $this->generate_fql_multiquery_to_get_events_details($users, $timestamp); try { $events = $facebook->api(array('method' => 'fql.multiquery', 'queries' => $fql)); } catch (WP_FacebookApiException $e) { throw $e; } // Normalize the events $events = $this->convert_multi_query_resultset($events); // When an event has a page as venue, we must get the data from the page. $events = $this->update_events_with_page_id_as_venues($facebook, $events); return $events; }
/** * Fetches data for the object to get missing icons. * * @param Ai1ec_Facebook_Proxy $facebook * * @param array $items * * @throws WP_FacebookApiException * * @return array the Facebook Graph Objects with the corrected icons */ protected function get_images(Ai1ec_Facebook_Proxy $facebook, array $items) { $idx = 0; foreach ($items as $item) { $id = $item['id']; try { $details = $facebook->api("/{$id}/"); // Applications have an icon url if (isset($details['icon_url']) && !isset($details['icon'])) { $details['icon'] = $details['icon_url']; } //Since things change fast in Facebook, i add this extra check to avoid notices if (!isset($details['icon'])) { $details['icon'] = ''; } $items[$idx]['user_pic'] = isset($details['picture']) ? $details['picture'] : $details['icon']; $idx++; } catch (WP_FacebookApiException $e) { throw $e; } } return $items; }
/** * When a user deletes an event from ai1ec and that event was exported to facebook, we try do delete the event from FB. * * @param Ai1ec_Facebook_Proxy $facebook */ public function delete_from_facebook(Ai1ec_Facebook_Proxy $facebook) { $id = $this->id; try { $result = $facebook->api("/{$id}", "DELETE"); } catch (WP_FacebookApiException $e) { // Usually if the event has already been canceled on Facebook those are the messages, if we get one of them // we do nothing as our intention was deleting the event if (!in_array($e->getMessage(), array(self::EX_UNSUPPORTED_POST_REQ, self::EX_PERMISSION_ERROR, self::EX_INVALID_EID))) { $message = array("label" => __('All-in-One Event Calendar Facebook Event Deletion Error', AI1EC_PLUGIN_NAME), "message" => __("Something went wrong while deleting the event from Facebook.", AI1EC_PLUGIN_NAME), "message_type" => "error"); $message['message'] .= '<br />' . __("This is the error message: {$e->getMessage()}", AI1EC_PLUGIN_NAME); update_option(Ai1ecFacebookConnectorPlugin::FB_OPTION_CRON_NOTICE, $message); } } }
/** * Get tokens from Facebook and updates the variable * * @param Ai1ec_Facebook_Proxy $facebook * @return array */ public function set_token_for_pages(Ai1ec_Facebook_Proxy $facebook) { $result = $facebook->api("/me/accounts"); $tokens = array(); foreach ($result['data'] as $app) { if (self::APP_CATEGORY !== $app['category']) { $tokens[] = $app; } } $this->save_plugin_variable(self::PAGE_TOKENS, $tokens); return $tokens; }
/** * Gets the details for the events for the groups so that they can be saved. * * @param Ai1ec_Facebook_Proxy $facebook a Facebook instance * * @param array $grouped_eids array where the keys are the id of the groups and the values are an array of events id * * @param int $timestamp the timestamp that needs to be passed for checking only events that start after it * * @throws WP_FacebookApiException * * @return array the result of the FQL query */ private function get_events_from_facebook_from_eids(Ai1ec_Facebook_Proxy $facebook, array $grouped_eids, $timestamp) { $fql = $this->generate_multi_query_for_event_details($grouped_eids, $timestamp); try { $events = $facebook->api(array('method' => 'fql.multiquery', 'queries' => $fql)); } catch (WP_FacebookApiException $e) { throw $e; } return $events; }