/**
  *
  * @see Ai1ec_Connector_Plugin::render_tab_content()
  *
  */
 public function render_tab_content()
 {
     global $ai1ec_view_helper;
     $this->render_opening_div_of_tab();
     $file_input = Ai1ec_Helper_Factory::create_input_instance();
     $file_input->set_type('file');
     $file_input->set_id(self::NAME_OF_FILE_INPUT);
     $file_input->set_name(self::NAME_OF_FILE_INPUT);
     $submit = Ai1ec_Helper_Factory::create_input_instance();
     $submit->set_type('submit');
     $submit->add_class('button-primary');
     $submit->set_name(self::NAME_OF_SUBMIT);
     $submit->set_id(self::NAME_OF_SUBMIT);
     $submit->set_value(__('Submit Events', AI1EC_PLUGIN_NAME));
     $textarea = Ai1ec_Helper_Factory::create_generic_html_tag('textarea');
     $textarea->set_attribute('name', self::NAME_OF_TEXTAREA);
     $textarea->set_attribute('rows', 6);
     $textarea->set_id(self::NAME_OF_TEXTAREA);
     $facebook_tab = Ai1ec_Facebook_Factory::get_facebook_tab_instance();
     $category_select = $facebook_tab->create_select_category('ai1ec_file_upload_feed_category');
     $message = false;
     if (isset($this->count)) {
         $text = __('No events were found', AI1EC_PLUGIN_NAME);
         if ($this->count > 0) {
             $text = sprintf(_n('Imported %s event', 'Imported %s events', $this->count, AI1EC_PLUGIN_NAME), $this->count);
         }
         $message = Ai1ec_Helper_Factory::create_bootstrap_message_instance($text);
     }
     $args = array("category_select" => $category_select, "submit" => $submit, "file_input" => $file_input, "textarea" => $textarea);
     if (false !== $message) {
         $args['message'] = $message;
     }
     $ai1ec_view_helper->display_admin('plugins/file_upload/file_upload.php', $args);
     $this->render_closing_div_of_tab();
 }
 /**
  * Deletes the rows from the user_events table which are associated to the current object.
  * 
  * @return number
  */
 public function delete_events_from_user_event_table()
 {
     global $wpdb;
     $user_event_table = Ai1ec_Facebook_Factory::get_user_events_table();
     $query = $wpdb->prepare("DELETE FROM {$user_event_table} WHERE user_id = %s", $this->_id);
     $num_rows_deleted = $wpdb->query($query);
     return $num_rows_deleted;
 }
 /**
  * Loads data about subscription, tag and category in the object.
  */
 private function check_if_user_is_subscribed()
 {
     global $wpdb;
     $table_name = Ai1ec_Facebook_Factory::get_plugin_table();
     $query = $wpdb->prepare("SELECT subscribed, category, tag FROM {$table_name} WHERE user_id = %s", $this->_id);
     $user = $wpdb->get_row($query, ARRAY_A);
     $this->_subscribed = (int) $user['subscribed'] === 1 ? TRUE : FALSE;
     $this->_tag = $user['tag'];
     $this->_category = $user['category'];
 }
 /**
  * Gets the subscribers data from the db
  *
  * @param string $type the type to get
  *
  * @param $current_id The id of the currently logged on user which must be excluded from subscribers and multiselects
  *
  * @return array the results
  */
 private function get_data_for_subscribed_items($type, $current_id)
 {
     global $wpdb;
     $table_name = Ai1ec_Facebook_Factory::get_plugin_table();
     $data = $wpdb->get_results($wpdb->prepare("\n\t\t\t\tSELECT\n\t\t\t\t\tuser_id,\n\t\t\t\t\tuser_name,\n\t\t\t\t\tuser_pic,\n\t\t\t\t\tcategory,\n\t\t\t\t\ttag,\n\t\t\t\t\tcomments_enabled,\n\t\t\t\t\tmap_display_enabled\n\t\t\t\tFROM\n\t\t\t\t\t{$table_name}\n\t\t\t\tWHERE\n\t\t\t\t\tsubscribed = 1 AND\n\t\t\t\t\ttype = %s AND\n\t\t\t\t\tuser_id != %s\n\t\t\t\tORDER BY\n\t\t\t\t\tuser_name ASC\n\t\t\t\t", $type, $current_id), ARRAY_A);
     return $data;
 }
 /**
  * Get the wordpress post id for this facebook event
  *
  * @return int the wordpress post id
  */
 public function get_wordpress_post_id_from_facebook_event_id()
 {
     global $wpdb;
     $ai1ec_event_Table = Ai1ec_Facebook_Factory::get_events_table();
     $query = $wpdb->prepare("SELECT post_id FROM {$ai1ec_event_Table} where facebook_eid = %s", $this->id);
     $post_id = $wpdb->get_var($query);
     return $post_id;
 }
 /**
  * This function is called when the user deletes a calendar event and we must delete the linked facebook event
  *
  * @param Ai1ec_Event $event
  */
 public function handle_delete_event(Ai1ec_Event $event)
 {
     if (isset($event->facebook_eid) && (int) $event->facebook_eid !== 0 && $event->facebook_status !== self::FB_IMPORTED_EVENT) {
         if ($this->check_if_we_have_a_valid_access_token()) {
             $facebook_event = Ai1ec_Facebook_Factory::get_facebook_event_instance();
             $facebook_event->set_id($event->facebook_eid);
             $facebook = $this->facebook_instance_factory();
             $facebook_event->delete_from_facebook($facebook);
         } else {
             $message = array("label" => __('All-in-One Event Calendar Facebook Import Error', AI1EC_PLUGIN_NAME), "message" => __("We couldn't delete data from Facebook as we don't have a valid access token. Try to log out of Facebook from the <strong>Events</strong> &gt; <strong>Calendar Feeds</strong> screen, then log in again.", AI1EC_PLUGIN_NAME), "message_type" => "error");
             update_option(Ai1ecFacebookConnectorPlugin::FB_OPTION_CRON_NOTICE, $message);
         }
     }
 }
 /**
  * Get the post id from the event id
  *
  * @param int $eid the event id
  *
  * @return int|NULL the post id or NULL if nothing is found.
  */
 private function get_post_id_from_eid($eid)
 {
     global $wpdb;
     $table_name = Ai1ec_Facebook_Factory::get_events_table();
     $query = $wpdb->prepare("SELECT post_id FROM {$table_name} WHERE facebook_eid = %s", $eid);
     return $wpdb->get_var($query);
 }
 /**
  * Execute the custom bulk action "Export to Facebook".
  *
  */
 public function facebook_custom_bulk_action()
 {
     // if our custom action is selected and something has been posted
     if ((isset($_GET['action']) && $_GET['action'] === 'export-facebook' || isset($_GET['action2']) && $_GET['action2'] === 'export-facebook') && isset($_GET['post'])) {
         // Check if we have a valid access token
         if ($this->facebook_plugin->check_if_we_have_a_valid_access_token()) {
             // Iterate on the posts
             foreach ($_GET['post'] as $post_id) {
                 $ai1ec_event = new Ai1ec_Event($post_id);
                 // MAke an extra check that the post can be exported
                 if ($ai1ec_event->facebook_status === '') {
                     // Get a facebook event instance
                     $facebook_event = Ai1ec_Facebook_Factory::get_facebook_event_instance();
                     // Prepare the event
                     $facebook_event->populate_event_from_ai1ec_event($ai1ec_event);
                     $facebook = $this->facebook_plugin->facebook_instance_factory();
                     // Save the event to facebook
                     $result = $facebook_event->save_to_facebook($facebook);
                     // If everything went as expected, update the calendar event
                     if (is_array($result) && !empty($result)) {
                         $ai1ec_event->facebook_eid = $result['id'];
                         $ai1ec_event->facebook_status = Ai1ecFacebookConnectorPlugin::FB_EXPORTED_EVENT;
                         $ai1ec_event->save(TRUE);
                     }
                 }
                 // Wait one second to avoid overloading Facebook
                 sleep(1);
             }
         } else {
             $message = array("label" => __('All-in-One Event Calendar Facebook Export Error', AI1EC_PLUGIN_NAME), "message" => __("We couldn't export data to Facebook as we don't have a valid access token. Try to log out of Facebook from the <strong>Events</strong> &gt; <strong>Calendar Feeds</strong> screen, then log in again.", AI1EC_PLUGIN_NAME), "message_type" => "error");
             update_option(Ai1ecFacebookConnectorPlugin::FB_OPTION_CRON_NOTICE, $message);
         }
     }
 }