/**
     * Creates the HTML to display on the "Add new event" page so that the user can choose to export the event to Facebook.
     *
     * @return string an empty string or the html to show
     */
    public function render_export_box()
    {
        global $post;
        // We only want this for events.
        if ($post->post_type !== AI1EC_POST_TYPE) {
            return;
        }
        try {
            $event = new Ai1ec_Event($post->ID);
        } catch (Ai1ec_Event_Not_Found $e) {
            // Post exists, but event data hasn't been saved yet. Create new event
            // object.
            $event = NULL;
        }
        // If we have an event end the event was imported from facebook, return, we can't export it.
        if ($event !== NULL && $event->facebook_status === Ai1ecFacebookConnectorPlugin::FB_IMPORTED_EVENT) {
            return;
        }
        // Let's check if we have a user in session
        if ($this->get_current_facebook_user_from_cache() === NULL) {
            // No user in session, let's see if we have a token and the user can login.
            $facebook = $this->facebook_instance_factory();
            $current_user = Ai1ec_Facebook_Factory::get_facebook_user_instance($facebook);
            $logged_in = $current_user->do_login();
            // If the user couldn't login, do not print anything but return an hidden inpsave_current_facebook_user_in_sessionut, in this way the
            // plugin save post handler simply returns.
            if ($logged_in === FALSE) {
                $hidden_input_name = self::FB_HIDDEN_INPUT_NO_ACTIVE_TOKEN;
                echo "<input type='hidden' name='{$hidden_input_name}' value='1' />";
                return;
            }
            // Save it in session.
            $this->save_facebook_user_in_cache($current_user);
        }
        $checked = '';
        if ($event !== NULL && $event->facebook_status === Ai1ecFacebookConnectorPlugin::FB_EXPORTED_EVENT) {
            $checked = 'checked';
        }
        $link = '';
        $modal_html = '';
        if (isset($event->facebook_eid) && (int) $event->facebook_eid !== 0) {
            $link_label = __("Linked Facebook event", AI1EC_PLUGIN_NAME);
            $link = "<div id='ai1ec-facebook-linked-event'><a href='https://www.facebook.com/events/{$event->facebook_eid}'>{$link_label}</a></div>";
            // We include the modal only when the event has been exported to facebook
            $twitter_bootstrap_modal = new Ai1ec_Bootstrap_Modal(__("Would you like to delete the linked Facebook event or keep it? If you choose to keep it and later you export this event again, a new one will be created.", AI1EC_PLUGIN_NAME));
            $twitter_bootstrap_modal->set_header_text(__("Unpublish Facebook event?", AI1EC_PLUGIN_NAME));
            $twitter_bootstrap_modal->set_id("ai1ec-facebook-export-modal");
            $twitter_bootstrap_modal->set_delete_button_text(__("Delete event", AI1EC_PLUGIN_NAME));
            $twitter_bootstrap_modal->set_keep_button_text(__("Keep event", AI1EC_PLUGIN_NAME));
            $modal_html = $twitter_bootstrap_modal->render_modal_and_return_html();
        }
        $label = __('Export event to Facebook?', AI1EC_PLUGIN_NAME);
        $name = self::FB_EXPORT_CHKBX_NAME;
        $html = <<<HTML
<div id="ai1ec-facebook-publish" class="misc-pub-section">
\t<div id="ai1ec-facebook-small-logo"></div>
\t<label for="{$name}">
\t\t{$label}
\t</label>
\t<input type="checkbox" {$checked} name="{$name}" id="{$name}" value="1" />
\t{$link}
</div>
<div class="timely">
{$modal_html}
</div>
HTML;
        echo $html;
    }
    /**
     * Renders the Facebook Graph Object that user has subscribed to.
     *
     * @param array $types the Type of Facebook Graph Objects to render
     *
     * @param $current_id The id of the currently logged on user which must be excluded from subscribers and multiselects
     *
     * @return string the HTML
     */
    private function render_subscribers(array $types, $current_id)
    {
        $subscribers = $this->render_all_elements($types, FALSE, $current_id);
        $html = '';
        foreach ($types as $type) {
            $text = Ai1ec_Facebook_Graph_Object_Collection::get_type_printable_text($type);
            $html .= <<<HTML
<div class="ai1ec-facebook-items" data-type="{$type}">
\t<h2 class="ai1ec-facebook-header">{$text}</h2>
\t{$subscribers[$type]}
</div>
HTML;
        }
        $keep_events = __("Keep Events", AI1EC_PLUGIN_NAME);
        $remove_events = __("Remove Events", AI1EC_PLUGIN_NAME);
        $body = __("Would you like to remove these events from your calendar, or preserve them?", AI1EC_PLUGIN_NAME);
        $removing = __("Removing the following subscription: ", AI1EC_PLUGIN_NAME);
        $header_text = $removing . '<span id="ai1ec-facebook-user-modal"></span>';
        // Attach the modal for when you unsubscribe.
        $twitter_bootstrap_modal = new Ai1ec_Bootstrap_Modal($body);
        $twitter_bootstrap_modal->set_id('ai1ec-facebook-modal');
        $twitter_bootstrap_modal->set_delete_button_text($remove_events);
        $twitter_bootstrap_modal->set_keep_button_text($keep_events);
        $twitter_bootstrap_modal->set_header_text($header_text);
        $modal = <<<HTML
<div class="modal hide" id="ai1ec-facebook-modal">
\t<div class="modal-header">
\t\t<button class="close" data-dismiss="modal">×</button>
\t\t<h1><small>{$removing} <span id="ai1ec-facebook-user-modal"></span></small></h1>
\t</div>
\t<div class="modal-body">
\t\t<p>{$body}</p>
\t</div>
\t<div class="modal-footer">
\t\t<a href="#" class="btn remove btn-danger">{$remove_events}</a>
\t\t<a href="#" class="btn keep btn-primary">{$keep_events}</a>
\t</div>
</div>
HTML;
        $html .= $twitter_bootstrap_modal->render_modal_and_return_html();
        return $html;
    }