/** * Subscribe the passed users and fetches from Facebook their events. The events and the users are tagged with the relative category and tag. * * @param array $users the users to subscribe to * * @param string $type the type of the users array (user / page / group) * * @param int $category the category * * @param string $tag the tags * * @param bool $enable_comments whereas comments shall be enabled * * @param bool $display_map whereas map shall be displayed */ private function subscribe_users(array $users, $type, $category, $tag, $enable_comments = false, $display_map = false) { // Get a collection object $fgoc = Ai1ec_Facebook_Factory::get_facebook_graph_object_collection($users); // Set the category (needed to attach to the users, not to the events) $fgoc->set_category($category); // Set the tags (needed to attach to the users, not to the events) $fgoc->set_tag($tag); // Set the comments enablement (needed to attach to the users, not to the events) $fgoc->set_enable_comments($enable_comments); // Set the map display (needed to attach to the users, not to the events) $fgoc->set_display_map($display_map); // Set the an instance of the Facebook class $facebook = $this->facebook_instance_factory(); $fgoc->set_facebook($facebook); // Set the currently active user. $fgoc->set_facebook_user($this->get_current_facebook_user_from_cache()); // Set the type of the collection. $fgoc->set_type($type); try { // Update the subscription status. $fgoc->update_subscription_status(TRUE, $category, $tag); $this->_information_message[] = $fgoc->refresh_events(); } catch (Ai1ec_Facebook_Db_Exception $e) { $this->_error_messages = array_merge($this->_error_messages, $e->get_error_messages()); } catch (WP_FacebookApiException $e) { if ($e->getCode() === self::FB_OAUTH_EXC_CODE) { $message = __("Something went wrong with Facebook authentication. Try to log out and then log in again.", AI1EC_PLUGIN_NAME); $this->_error_messages = array_merge($this->_error_messages, array($message)); $facebook->destroySession(); } else { $message = __("Something went wrong when retrieving data from Facebook. Try subscribing to fewer calendars.", AI1EC_PLUGIN_NAME); $this->_error_messages = array_merge($this->_error_messages, array($message)); } } }