/**
  * Create the html element used as the UI control for the datepicker button.
  * The href must keep only active filters.
  *
  * @param array           $args         Populated args for the view
  * @param int|string|null $initial_date The datepicker's initially set date
  * @return Ai1ec_Generic_Html_Tag
  */
 public static function create_datepicker_link(array $args, $initial_date = null)
 {
     global $ai1ec_settings, $ai1ec_view_helper;
     $link = Ai1ec_Helper_Factory::create_generic_html_tag('a');
     $date_format_pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($ai1ec_settings->input_date_format);
     if ($initial_date == null) {
         // If exact_date argument was provided, use its value to initialize
         // datepicker.
         if (isset($args['exact_date']) && $args['exact_date'] !== false && $args['exact_date'] !== null) {
             $initial_date = $args['exact_date'];
         } else {
             $initial_date = Ai1ec_Time_Utility::gmt_to_local(Ai1ec_Time_Utility::current_time());
         }
     }
     // Convert initial date to formatted date if required.
     if (Ai1ec_Validation_Utility::is_valid_time_stamp($initial_date)) {
         $initial_date = Ai1ec_Time_Utility::format_date(Ai1ec_Time_Utility::gmt_to_local($initial_date), $ai1ec_settings->input_date_format);
     }
     $link->add_class('ai1ec-minical-trigger btn');
     $link->set_attribute('data-date', $initial_date);
     $link->set_attribute('data-date-format', $date_format_pattern);
     $link->set_attribute('data-date-weekstart', $ai1ec_settings->week_start_day);
     $link->set_attribute_expr($args['data_type']);
     $text = '<img src="' . esc_attr($ai1ec_view_helper->get_theme_img_url('date-icon.png')) . '" class="ai1ec-icon-datepicker" />';
     $link->set_text($text);
     $href_args = array('action' => $args['action'], 'cat_ids' => $args['cat_ids'], 'tag_ids' => $args['tag_ids'], 'exact_date' => "__DATE__");
     $data_href = self::create_href_helper_instance($href_args);
     $link->set_attribute('data-href', $data_href->generate_href());
     $link->set_attribute('href', '#');
     return $link;
 }
 /**
  * Check if the date supplied is valid. It validates date in the format given
  * by $pattern, which matches one of the supported date patterns.
  * @see  Ai1ec_Time_Utility::get_date_patterns()
  *
  * @param  string  $date    Date string to parse
  * @param  string  $pattern Key of date pattern (@see
  *                          Ai1ec_Time_Utility::get_date_patterns()) to
  *                          match date string against
  * @return array|boolean		An array with the parsed date or false if the date
  *                          is not valid
  */
 public static function validate_date_and_return_parsed_date($date, $pattern = 'def')
 {
     // Convert pattern to regex.
     $pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($pattern);
     $pattern = preg_quote($pattern, '/');
     $pattern = str_replace(array('dd', 'd', 'mm', 'm', 'yyyy', 'yy'), array('(?P<d>\\d{2})', '(?P<d>\\d{1,2})', '(?P<m>\\d{2})', '(?P<m>\\d{1,2})', '(?P<y>\\d{4})', '(?P<y>\\d{2})'), $pattern);
     // Accept hyphens and dots in place of forward slashes (for URLs).
     $pattern = str_replace('\\/', '[\\/\\-\\.]', $pattern);
     $pattern = "/^{$pattern}\$/";
     if (preg_match($pattern, $date, $matches)) {
         if (checkdate($matches['m'], $matches['d'], $matches['y'])) {
             return array("month" => $matches['m'], "day" => $matches['d'], "year" => $matches['y']);
         }
     }
     return false;
 }
 /**
  * Displays the General Settings meta box.
  *
  * @return void
  */
 public function general_settings_meta_box($object, $box)
 {
     global $ai1ec_view_helper, $ai1ec_settings;
     $calendar_page = $this->wp_pages_dropdown('calendar_page_id', $ai1ec_settings->calendar_page_id, __('Calendar', AI1EC_PLUGIN_NAME));
     $week_start_day_val = Ai1ec_Meta::get_option('start_of_week');
     $week_start_day = $this->get_week_dropdown($week_start_day_val);
     $exact_date = $ai1ec_settings->exact_date;
     $posterboard_events_per_page = $ai1ec_settings->posterboard_events_per_page;
     $posterboard_tile_min_width = $ai1ec_settings->posterboard_tile_min_width;
     $stream_events_per_page = $ai1ec_settings->stream_events_per_page;
     $agenda_events_per_page = $ai1ec_settings->agenda_events_per_page;
     $agenda_include_entire_last_day = $ai1ec_settings->agenda_include_entire_last_day ? 'checked="checked"' : '';
     $include_events_in_rss = '<input type="checkbox" name="include_events_in_rss"' . ' id="include_events_in_rss" value="1"' . ($ai1ec_settings->include_events_in_rss ? ' checked="checked"' : '') . '/>';
     $exclude_from_search = $ai1ec_settings->exclude_from_search ? 'checked="checked"' : '';
     $show_publish_button = $ai1ec_settings->show_publish_button ? 'checked="checked"' : '';
     $hide_maps_until_clicked = $ai1ec_settings->hide_maps_until_clicked ? 'checked="checked"' : '';
     $agenda_events_expanded = $ai1ec_settings->agenda_events_expanded ? 'checked="checked"' : '';
     $turn_off_subscription_buttons = $ai1ec_settings->turn_off_subscription_buttons ? 'checked="checked"' : '';
     $show_create_event_button = $ai1ec_settings->show_create_event_button ? 'checked="checked"' : '';
     $show_front_end_create_form = $ai1ec_settings->show_front_end_create_form ? 'checked="checked"' : '';
     $allow_anonymous_submissions = $ai1ec_settings->allow_anonymous_submissions ? 'checked="checked"' : '';
     $allow_anonymous_uploads = $ai1ec_settings->allow_anonymous_uploads ? 'checked="checked"' : '';
     $show_add_calendar_button = $ai1ec_settings->show_add_calendar_button ? 'checked="checked"' : '';
     $recaptcha_public_key = $ai1ec_settings->recaptcha_public_key;
     $recaptcha_private_key = $ai1ec_settings->recaptcha_private_key;
     $inject_categories = $ai1ec_settings->inject_categories ? 'checked="checked"' : '';
     $geo_region_biasing = $ai1ec_settings->geo_region_biasing ? 'checked="checked"' : '';
     $input_date_format = $this->get_date_format_dropdown($ai1ec_settings->input_date_format);
     $input_24h_time = $ai1ec_settings->input_24h_time ? 'checked="checked"' : '';
     $default_calendar_view = $this->get_view_options($ai1ec_settings->default_calendar_view);
     $timezone_control = $this->get_timezone_dropdown($ai1ec_settings->timezone);
     $disable_autocompletion = $ai1ec_settings->disable_autocompletion ? 'checked="checked"' : '';
     $show_location_in_title = $ai1ec_settings->show_location_in_title ? 'checked="checked"' : '';
     $show_year_in_agenda_dates = $ai1ec_settings->show_year_in_agenda_dates ? 'checked="checked"' : '';
     $tax_options = array('type' => 'categories', 'selected' => $ai1ec_settings->default_categories);
     $default_categories = $this->taxonomy_selector($tax_options);
     $tax_options = array('type' => 'tags', 'selected' => $ai1ec_settings->default_tags);
     $default_tags = $this->taxonomy_selector($tax_options);
     $show_timezone = $ai1ec_settings->is_timezone_open_for_change();
     $date_format_pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($ai1ec_settings->input_date_format);
     $ajaxify_events_in_web_widget = $ai1ec_settings->ajaxify_events_in_web_widget ? 'checked="checked"' : '';
     $event_platform = $ai1ec_settings->event_platform_active ? 'checked="checked"' : '';
     $event_platform_disabled = AI1EC_EVENT_PLATFORM ? 'disabled="disabled"' : '';
     $event_platform_strict = $ai1ec_settings->event_platform_strict ? 'checked="checked"' : '';
     $args = array('calendar_page' => $calendar_page, 'default_calendar_view' => $default_calendar_view, 'week_start_day_val' => $week_start_day_val, 'week_start_day' => $week_start_day, 'default_categories' => $default_categories, 'default_tags' => $default_tags, 'exact_date' => $exact_date, 'posterboard_events_per_page' => $posterboard_events_per_page, 'posterboard_tile_min_width' => $posterboard_tile_min_width, 'stream_events_per_page' => $stream_events_per_page, 'agenda_events_per_page' => $agenda_events_per_page, 'agenda_include_entire_last_day' => $agenda_include_entire_last_day, 'exclude_from_search' => $exclude_from_search, 'show_publish_button' => $show_publish_button, 'hide_maps_until_clicked' => $hide_maps_until_clicked, 'agenda_events_expanded' => $agenda_events_expanded, 'turn_off_subscription_buttons' => $turn_off_subscription_buttons, 'show_create_event_button' => $show_create_event_button, 'show_front_end_create_form' => $show_front_end_create_form, 'allow_anonymous_submissions' => $allow_anonymous_submissions, 'allow_anonymous_uploads' => $allow_anonymous_uploads, 'show_add_calendar_button' => $show_add_calendar_button, 'recaptcha_public_key' => $recaptcha_public_key, 'recaptcha_private_key' => $recaptcha_private_key, 'inject_categories' => $inject_categories, 'input_date_format' => $input_date_format, 'input_24h_time' => $input_24h_time, 'show_timezone' => $show_timezone, 'timezone_control' => $timezone_control, 'geo_region_biasing' => $geo_region_biasing, 'disable_autocompletion' => $disable_autocompletion, 'show_location_in_title' => $show_location_in_title, 'show_year_in_agenda_dates' => $show_year_in_agenda_dates, 'date_format_pattern' => $date_format_pattern, 'calendar_css_selector' => $ai1ec_settings->calendar_css_selector, 'ajaxify_events_in_web_widget' => $ajaxify_events_in_web_widget, 'event_platform' => $event_platform, 'event_platform_disabled' => $event_platform_disabled, 'event_platform_strict' => $event_platform_strict, 'display_event_platform' => is_super_admin(), 'user_mail_subject' => $ai1ec_settings->user_mail_subject, 'user_mail_body' => $ai1ec_settings->user_mail_body, 'admin_mail_subject' => $ai1ec_settings->admin_mail_subject, 'admin_mail_body' => $ai1ec_settings->admin_mail_body);
     $ai1ec_view_helper->display_admin('box_general_settings.php', $args);
 }
 /**
  * Handle AJAX request to display front-end create event form content.
  *
  * @return null
  */
 public function get_front_end_create_event_form()
 {
     global $ai1ec_view_helper, $ai1ec_settings;
     $date_format_pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($ai1ec_settings->input_date_format);
     $week_start_day = get_option('start_of_week');
     $input_24h_time = $ai1ec_settings->input_24h_time;
     $cat_select = $this->get_html_for_category_selector();
     $tag_select = $this->get_html_for_tag_selector();
     $form_action = admin_url('admin-ajax.php?action=ai1ec_front_end_submit_event');
     $default_image = $ai1ec_view_helper->get_theme_img_url('default-event-avatar.png');
     if (!is_user_logged_in() && $ai1ec_settings->allow_anonymous_submissions && $ai1ec_settings->recaptcha_key !== '') {
         $recaptcha_key = $ai1ec_settings->recaptcha_public_key;
     } else {
         $recaptcha_key = false;
     }
     $allow_uploads = is_user_logged_in() || $ai1ec_settings->allow_anonymous_submissions && $ai1ec_settings->allow_anonymous_uploads;
     $args = array('date_format_pattern' => $date_format_pattern, 'week_start_day' => $week_start_day, 'input_24h_time' => $input_24h_time, 'cat_select' => $cat_select, 'tag_select' => $tag_select, 'form_action' => $form_action, 'interactive_gmaps' => !$ai1ec_settings->disable_autocompletion, 'default_image' => $default_image, 'recaptcha_key' => $recaptcha_key, 'allow_uploads' => $allow_uploads);
     $ai1ec_view_helper->display_theme('create-event-form.php', $args);
     exit;
 }
 /**
  * Displays the General Settings meta box.
  *
  * @return void
  */
 public function general_settings_meta_box($object, $box)
 {
     global $ai1ec_view_helper, $ai1ec_settings;
     $calendar_page = $this->wp_pages_dropdown('calendar_page_id', $ai1ec_settings->calendar_page_id, __('Calendar', AI1EC_PLUGIN_NAME));
     $week_start_day_val = Ai1ec_Meta::get_option('start_of_week');
     $week_start_day = $this->get_week_dropdown($week_start_day_val);
     $exact_date = $ai1ec_settings->exact_date;
     $posterboard_events_per_page = $ai1ec_settings->posterboard_events_per_page;
     $posterboard_tile_min_width = $ai1ec_settings->posterboard_tile_min_width;
     $stream_events_per_page = $ai1ec_settings->stream_events_per_page;
     $agenda_events_per_page = $ai1ec_settings->agenda_events_per_page;
     $disable_standard_filter_menu = $ai1ec_settings->disable_standard_filter_menu ? 'checked="checked"' : '';
     $use_authors_filter = $ai1ec_settings->use_authors_filter ? 'checked="checked"' : '';
     $disable_gzip_compression = $ai1ec_settings->disable_gzip_compression ? 'checked="checked"' : '';
     $agenda_include_entire_last_day = $ai1ec_settings->agenda_include_entire_last_day ? 'checked="checked"' : '';
     $include_events_in_rss = '<input type="checkbox" name="include_events_in_rss"' . ' id="include_events_in_rss" value="1"' . ($ai1ec_settings->include_events_in_rss ? ' checked="checked"' : '') . '/>';
     $exclude_from_search = $ai1ec_settings->exclude_from_search ? 'checked="checked"' : '';
     $show_publish_button = $ai1ec_settings->show_publish_button ? 'checked="checked"' : '';
     $hide_maps_until_clicked = $ai1ec_settings->hide_maps_until_clicked ? 'checked="checked"' : '';
     $agenda_events_expanded = $ai1ec_settings->agenda_events_expanded ? 'checked="checked"' : '';
     $turn_off_subscription_buttons = $ai1ec_settings->turn_off_subscription_buttons ? 'checked="checked"' : '';
     $show_create_event_button = $ai1ec_settings->show_create_event_button ? 'checked="checked"' : '';
     $show_front_end_create_form = $ai1ec_settings->show_front_end_create_form ? 'checked="checked"' : '';
     $allow_anonymous_submissions = $ai1ec_settings->allow_anonymous_submissions ? 'checked="checked"' : '';
     $allow_anonymous_uploads = $ai1ec_settings->allow_anonymous_uploads ? 'checked="checked"' : '';
     $show_add_calendar_button = $ai1ec_settings->show_add_calendar_button ? 'checked="checked"' : '';
     $recaptcha_public_key = $ai1ec_settings->recaptcha_public_key;
     $recaptcha_private_key = $ai1ec_settings->recaptcha_private_key;
     $inject_categories = $ai1ec_settings->inject_categories ? 'checked="checked"' : '';
     $geo_region_biasing = $ai1ec_settings->geo_region_biasing ? 'checked="checked"' : '';
     $input_date_format = $this->get_date_format_dropdown($ai1ec_settings->input_date_format);
     $input_24h_time = $ai1ec_settings->input_24h_time ? 'checked="checked"' : '';
     $default_calendar_view = $this->get_view_options($ai1ec_settings->default_calendar_view);
     $timezone_control = $this->get_timezone_dropdown($ai1ec_settings->timezone);
     $disable_autocompletion = $ai1ec_settings->disable_autocompletion ? 'checked="checked"' : '';
     $show_location_in_title = $ai1ec_settings->show_location_in_title ? 'checked="checked"' : '';
     $show_year_in_agenda_dates = $ai1ec_settings->show_year_in_agenda_dates ? 'checked="checked"' : '';
     $enable_user_event_notifications = $ai1ec_settings->enable_user_event_notifications ? 'checked="checked"' : '';
     $oauth_twitter_id = $ai1ec_settings->oauth_twitter_id;
     $oauth_twitter_pass = $ai1ec_settings->oauth_twitter_pass;
     $twitter_notice_interval = $ai1ec_settings->twitter_notice_interval;
     $calendar_base_url_for_permalinks = $ai1ec_settings->calendar_base_url_for_permalinks ? 'checked="checked"' : '';
     $use_select2_widgets = $ai1ec_settings->use_select2_widgets ? 'checked="checked"' : '';
     $require_disclaimer = $ai1ec_settings->require_disclaimer ? 'checked="checked"' : '';
     $disclaimer = $ai1ec_settings->disclaimer;
     $tax_options = array('type' => 'categories', 'selected' => $ai1ec_settings->default_categories);
     $default_categories = $this->taxonomy_selector($tax_options);
     $tax_options = array('type' => 'tags', 'selected' => $ai1ec_settings->default_tags);
     $default_tags = $this->taxonomy_selector($tax_options);
     $show_timezone = $ai1ec_settings->is_timezone_open_for_change();
     $date_format_pattern = Ai1ec_Time_Utility::get_date_pattern_by_key($ai1ec_settings->input_date_format);
     $checkboxes_to_check = array('skip_in_the_loop_check', 'ajaxify_events_in_web_widget', 'event_platform', 'event_platform_strict');
     foreach ($checkboxes_to_check as $field) {
         ${$field} = '';
         if ($ai1ec_settings->{$field}) {
             ${$field} = 'checked="checked"';
         }
     }
     $event_platform_disabled = AI1EC_EVENT_PLATFORM ? 'disabled="disabled"' : '';
     $args = array('calendar_page' => $calendar_page, 'default_calendar_view' => $default_calendar_view, 'week_start_day_val' => $week_start_day_val, 'week_start_day' => $week_start_day, 'default_categories' => $default_categories, 'default_tags' => $default_tags, 'exact_date' => $exact_date, 'posterboard_events_per_page' => $posterboard_events_per_page, 'posterboard_tile_min_width' => $posterboard_tile_min_width, 'stream_events_per_page' => $stream_events_per_page, 'agenda_events_per_page' => $agenda_events_per_page, 'disable_standard_filter_menu' => $disable_standard_filter_menu, 'agenda_include_entire_last_day' => $agenda_include_entire_last_day, 'week_view_starts_at' => $ai1ec_settings->week_view_starts_at, 'week_view_ends_at' => $ai1ec_settings->week_view_ends_at, 'exclude_from_search' => $exclude_from_search, 'show_publish_button' => $show_publish_button, 'hide_maps_until_clicked' => $hide_maps_until_clicked, 'agenda_events_expanded' => $agenda_events_expanded, 'turn_off_subscription_buttons' => $turn_off_subscription_buttons, 'show_create_event_button' => $show_create_event_button, 'show_front_end_create_form' => $show_front_end_create_form, 'allow_anonymous_submissions' => $allow_anonymous_submissions, 'allow_anonymous_uploads' => $allow_anonymous_uploads, 'show_add_calendar_button' => $show_add_calendar_button, 'recaptcha_public_key' => $recaptcha_public_key, 'recaptcha_private_key' => $recaptcha_private_key, 'inject_categories' => $inject_categories, 'input_date_format' => $input_date_format, 'input_24h_time' => $input_24h_time, 'show_timezone' => $show_timezone, 'timezone_control' => $timezone_control, 'geo_region_biasing' => $geo_region_biasing, 'disable_autocompletion' => $disable_autocompletion, 'show_location_in_title' => $show_location_in_title, 'show_year_in_agenda_dates' => $show_year_in_agenda_dates, 'date_format_pattern' => $date_format_pattern, 'calendar_css_selector' => $ai1ec_settings->calendar_css_selector, 'skip_in_the_loop_check' => $skip_in_the_loop_check, 'calendar_base_url_for_permalinks' => $calendar_base_url_for_permalinks, 'ajaxify_events_in_web_widget' => $ajaxify_events_in_web_widget, 'event_platform' => $event_platform, 'event_platform_disabled' => $event_platform_disabled, 'event_platform_strict' => $event_platform_strict, 'require_disclaimer' => $require_disclaimer, 'disclaimer' => $disclaimer, 'display_event_platform' => is_super_admin(), 'user_mail_subject' => $ai1ec_settings->user_mail_subject, 'user_mail_body' => $ai1ec_settings->user_mail_body, 'admin_mail_subject' => $ai1ec_settings->admin_mail_subject, 'admin_mail_body' => $ai1ec_settings->admin_mail_body, 'view_cache_refresh_interval' => $ai1ec_settings->view_cache_refresh_interval, 'admin_add_new_event_mail_body' => $ai1ec_settings->admin_add_new_event_mail_body, 'admin_add_new_event_mail_subject' => $ai1ec_settings->admin_add_new_event_mail_subject, 'user_upcoming_event_mail_body' => $ai1ec_settings->user_upcoming_event_mail_body, 'user_upcoming_event_mail_subject' => $ai1ec_settings->user_upcoming_event_mail_subject, 'license_key' => $ai1ec_settings->license_key, 'enable_user_event_notifications' => $enable_user_event_notifications, 'oauth_twitter_id' => $oauth_twitter_id, 'oauth_twitter_pass' => $oauth_twitter_pass, 'use_select2_widgets' => $use_select2_widgets, 'twitter_notice_interval' => $twitter_notice_interval, 'use_authors_filter' => $use_authors_filter, 'disable_gzip_compression' => $disable_gzip_compression);
     $ai1ec_view_helper->display_admin('box_general_settings.php', $args);
 }