/**
  * get_instance function
  *
  * Return singleton instance
  *
  * @return Ai1ec_Importer_Helper
  **/
 static function get_instance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Tries to import data treating it either as csv or as ics.
  *
  * @param string $data
  * @return int the number of imported objetcs
  */
 private function import_from_string($data)
 {
     $ai1ec_importer_helper = Ai1ec_Importer_Helper::get_instance();
     $count = 0;
     $id = __('textarea_import', AI1EC_PLUGIN_NAME) . '-' . date('Y-m-d-H:i:s');
     $feed = $this->create_feed_instance($id);
     $comments = isset($_POST['ai1ec_file_upload_comments_enabled']) ? 'open' : 'closed';
     $show_map = isset($_POST['ai1ec_file_upload_map_display_enabled']) ? 1 : 0;
     $iCalcnv = new iCalcnv();
     $iCalcnv->setConfig(array('outputobj' => true, 'string_to_parse' => $data));
     $v = $iCalcnv->csv2iCal();
     $count = $ai1ec_importer_helper->add_vcalendar_events_to_db($v, $feed, $comments, $show_map);
     if (0 === $count) {
         // create new instance
         $v = new vcalendar();
         $v->parse($data);
         $count = $ai1ec_importer_helper->add_vcalendar_events_to_db($v, $feed, $comments, $show_map);
     }
     return $count;
 }
if (isset($_POST['ai1ec_save_settings'])) {
    $ai1ec_settings->event_platform = isset($_POST['event_platform']);
    $ai1ec_settings->event_platform_strict = isset($_POST['event_platform_strict']);
}
// Set up the Routing Factory
Ai1ec_Routing_Factory::set_ai1ec_settings($ai1ec_settings);
// ================================
// = Initialize and setup HELPERS =
// ================================
global $ai1ec_view_helper, $ai1ec_settings_helper, $ai1ec_calendar_helper, $ai1ec_app_helper, $ai1ec_events_helper, $ai1ec_importer_helper, $ai1ec_exporter_helper, $ai1ec_platform_helper, $ai1ec_localization_helper, $ai1ec_importer_plugin_helper, $ai1ec_events_list_helper;
$ai1ec_view_helper = Ai1ec_View_Helper::get_instance();
$ai1ec_settings_helper = Ai1ec_Settings_Helper::get_instance();
$ai1ec_calendar_helper = Ai1ec_Calendar_Helper::get_instance();
$ai1ec_app_helper = Ai1ec_App_Helper::get_instance();
$ai1ec_events_helper = Ai1ec_Events_Helper::get_instance();
$ai1ec_importer_helper = Ai1ec_Importer_Helper::get_instance();
$ai1ec_exporter_helper = Ai1ec_Exporter_Helper::get_instance();
$ai1ec_platform_helper = Ai1ec_Platform_Helper::get_instance();
$ai1ec_localization_helper = Ai1ec_Localization_Helper::get_instance();
$ai1ec_importer_plugin_helper = Ai1ec_Importer_Plugin_Helper::get_instance();
$ai1ec_events_list_helper = Ai1ec_Events_List_Helper::get_instance();
if ('admin-ajax.php' === basename($_SERVER['SCRIPT_NAME']) && isset($_REQUEST['lang'])) {
    $ai1ec_localization_helper->set_language($_REQUEST['lang']);
}
// ====================================
// = Initialize and setup CONTROLLERS =
// ====================================
global $ai1ec_app_controller, $ai1ec_settings_controller, $ai1ec_events_controller, $ai1ec_calendar_controller, $ai1ec_importer_controller, $ai1ec_exporter_controller, $ai1ec_platform_controller, $ai1ec_duplicate_controller, $ai1ec_oauth_controller, $ai1ec_logging_controller;
$ai1ec_settings_controller = Ai1ec_Settings_Controller::get_instance();
$ai1ec_events_controller = Ai1ec_Events_Controller::get_instance();
$ai1ec_calendar_controller = Ai1ec_Calendar_Controller::get_instance();