/** * Send an e-mail to the admin and another to the user if form passes * validation. */ public function add_ics_feed_frontend() { global $wpdb; $table_name = $wpdb->prefix . 'ai1ec_event_feeds'; $check = $this->validate_form(); $check['nonce'] = wp_nonce_field('ai1ec_submit_ics_form', AI1EC_POST_TYPE, true, false); if (true === $check['success']) { $ai1ec_settings = Ai1ec_Settings::get_instance(); // Strip slashes if ridiculous PHP setting magic_quotes_gpc is enabled. if (get_magic_quotes_gpc()) { foreach ($_POST as &$param) { $param = stripslashes($param); } } $translations = $this->get_translations(); $notification_for_admin = Ai1ec_Notification_Factory::create_notification_instance(array(get_option('admin_email')), $ai1ec_settings->admin_mail_body, Ai1ec_Notification_Factory::EMAIL_NOTIFICATION, $ai1ec_settings->admin_mail_subject); $notification_for_user = Ai1ec_Notification_Factory::create_notification_instance(array($_POST['ai1ec_submitter_email']), $ai1ec_settings->user_mail_body, Ai1ec_Notification_Factory::EMAIL_NOTIFICATION, $ai1ec_settings->user_mail_subject); $notification_for_admin->set_translations($translations); $notification_for_admin->send(); $notification_for_user->set_translations($translations); $notification_for_user->send(); } echo json_encode($check); exit; }
/** * Check if a cookie is set for the current page * * @return Ai1ec_Cookie_Present_Dto */ public static function is_cookie_set_for_current_page() { $cookie_dto = Ai1ec_Dto_Factory::create_cookie_present_dto_instance(); $ai1ec_settings = Ai1ec_Settings::get_instance(); $calendar_url = get_page_link($ai1ec_settings->calendar_page_id); $requested_page_url = Ai1ec_Wp_Uri_Helper::get_current_url(true); $cookie_set = isset($_COOKIE['ai1ec_saved_filter']); if (false !== $cookie_set) { $cookie = json_decode(stripslashes($_COOKIE['ai1ec_saved_filter']), true); if ($calendar_url === $requested_page_url && isset($cookie['calendar_page']) && $cookie['calendar_page'] !== $calendar_url) { $cookie_dto->set_calendar_cookie($cookie['calendar_page']); $cookie_dto->set_is_cookie_set_for_calendar_page(true); $cookie_dto->set_is_a_cookie_set_for_this_page(true); } else { if (isset($cookie[$requested_page_url])) { $cookie_dto->set_shortcode_cookie($cookie[$requested_page_url]); $cookie_dto->set_is_cookie_set_for_shortcode(true); $cookie_dto->set_is_a_cookie_set_for_this_page(true); } else { if (strpos($requested_page_url, $calendar_url) === 0 && isset($cookie['calendar_page']) && is_page($ai1ec_settings->calendar_page_id)) { // This is the case after a redirect from the calendar page $cookie_dto->set_is_a_cookie_set_for_this_page(true); $cookie_dto->set_calendar_cookie($cookie['calendar_page']); } } } } return $cookie_dto; }
/** * Returns singletonian instance of this object * * @return Ai1ec_Oauth_Controller Singletonian instance of self */ public static function get_instance() { if (!self::$_instance instanceof self) { global $wpdb; self::$_instance = new self($wpdb, Ai1ec_Settings::get_instance()); } return self::$_instance; }
/** * Constructor * * Initiate local values - settings object and initialize * Twitter library. * * @return void Constructor does not return */ public function __construct(Ai1ec_Settings $settings = NULL) { if (NULL === $settings) { $settings = Ai1ec_Settings::get_instance(); } $this->_settings = $settings; if (NULL === $this->_reinit_connector()) { throw new Ai1ec_Oauth_Exception('Twitter provider not configured'); } $this->_state = new Ai1ec_Session_Model(); }
/** * Check if client accepts gzip and we should compress content * * Plugin settings, client preferences and server capabilities are * checked to make sure we should use gzip for output compression. * * @uses Ai1ec_Settings::get_instance To early instantiate object * * @return bool True when gzip should be used */ public static function client_use_gzip() { if (Ai1ec_Settings::get_instance()->disable_gzip_compression || isset($_SERVER['HTTP_ACCEPT_ENCODING']) && 'identity' === $_SERVER['HTTP_ACCEPT_ENCODING'] || !extension_loaded('zlib')) { return false; } $zlib_output_handler = ini_get('zlib.output_handler'); if (in_array('ob_gzhandler', ob_list_handlers()) || in_array(strtolower(ini_get('zlib.output_compression')), array('1', 'on')) || !empty($zlib_output_handler)) { return false; } return true; }
/** * Create the array needed for translation and passing other settings to JS. * * @return $data array the dynamic data array */ private function get_translation_data() { global $ai1ec_importer_plugin_helper; $force_ssl_admin = force_ssl_admin(); if ($force_ssl_admin && !is_ssl()) { force_ssl_admin(false); } $ajax_url = admin_url('admin-ajax.php'); force_ssl_admin($force_ssl_admin); $data = array('select_one_option' => __('Select at least one user/group/page to subscribe to.', AI1EC_PLUGIN_NAME), 'is_calendar_page' => isset($_GET[self::IS_CALENDAR_PAGE]) && $_GET[self::IS_CALENDAR_PAGE] === self::TRUE_PARAM, 'error_no_response' => __('An unexpected error occurred. Try reloading the page.', AI1EC_PLUGIN_NAME), 'no_more_subscription' => __('No subscriptions yet!', AI1EC_PLUGIN_NAME), 'no_more_than_ten' => __('Please select no more than ten users/groups/pages at a time to avoid overloading Facebook requests.', AI1EC_PLUGIN_NAME), 'duplicate_feed_message' => esc_html__('This feed is already being imported.', AI1EC_PLUGIN_NAME), 'invalid_url_message' => esc_html__('Please enter a valid iCalendar URL.', AI1EC_PLUGIN_NAME), 'invalid_email_message' => esc_html__('Please enter a valid e-mail address.', AI1EC_PLUGIN_NAME), 'now' => $this->events_helper->gmt_to_local(Ai1ec_Time_Utility::current_time()), 'date_format' => $this->settings->input_date_format, 'month_names' => $this->ai1ec_locale->get_localized_month_names(), 'day_names' => $this->ai1ec_locale->get_localized_week_names(), 'week_start_day' => $this->settings->week_start_day, 'twentyfour_hour' => $this->settings->input_24h_time, 'region' => $this->settings->geo_region_biasing ? $this->events_helper->get_region() : '', 'disable_autocompletion' => $this->settings->disable_autocompletion, 'error_message_not_valid_lat' => __('Please enter a valid latitude. A valid latitude is comprised between +90 and -90.', AI1EC_PLUGIN_NAME), 'error_message_not_valid_long' => __('Please enter a valid longitude. A valid longitude is comprised between +180 and -180.', AI1EC_PLUGIN_NAME), 'error_message_not_entered_lat' => __('When the "Input coordinates" checkbox is checked, "Latitude" is a required field.', AI1EC_PLUGIN_NAME), 'error_message_not_entered_long' => __('When the "Input coordinates" checkbox is checked, "Longitude" is a required field.', AI1EC_PLUGIN_NAME), 'language' => $this->events_helper->get_lang(), 'page' => '', 'page_on_front_description' => __('This setting cannot be changed in Event Platform mode.', AI1EC_PLUGIN_NAME), 'strict_mode' => $this->settings->event_platform_strict, 'platform_active' => $this->settings->event_platform_active, 'facebook_logged_in' => $ai1ec_importer_plugin_helper->check_if_we_have_a_valid_facebook_access_token(), 'app_id_and_secret_are_required' => __('You must specify both an app ID and app secret to connect to Facebook.', AI1EC_PLUGIN_NAME), 'file_upload_required' => __('You must specify a valid file to upload or paste your data into the text field.', AI1EC_PLUGIN_NAME), 'file_upload_not_permitted' => __('Only .ics and .csv files are supported.', AI1EC_PLUGIN_NAME), 'ajax_url' => $ajax_url, 'url_not_valid' => __('The URL you have entered seems to be invalid. Please remember that URLs must start with either "http://" or "https://".', AI1EC_PLUGIN_NAME), 'mail_url_required' => __('Both the <em>calendar URL</em> and <em>e-mail address</em> fields are required.', AI1EC_PLUGIN_NAME), 'confirm_reset_theme' => __('Are you sure you want to reset your theme options to their default values?', AI1EC_PLUGIN_NAME), 'license_key' => $this->settings->get_license_key(), 'reset_saved_filter_text' => __('Save this filter as default', AI1EC_PLUGIN_NAME), 'clear_saved_filter_text' => __('Remove default filter', AI1EC_PLUGIN_NAME), 'save_filter_text_ok' => __('The active filter has been saved as your default for this calendar.', AI1EC_PLUGIN_NAME), 'remove_filter_text_ok' => __('Your default calendar filter has been removed.', AI1EC_PLUGIN_NAME), 'size_less_variable_not_ok' => __('The value you have entered is not a valid CSS length.', AI1EC_PLUGIN_NAME), 'week_view_starts_at' => $this->settings->week_view_starts_at, 'week_view_ends_at' => $this->settings->week_view_ends_at, 'end_must_be_after_start' => __('The end date can\'t be earlier than the start date.', AI1EC_PLUGIN_NAME), 'show_at_least_six_hours' => __('For week and day view, you must select an interval of at least 6 hours.', AI1EC_PLUGIN_NAME), 'label_buy_tickets_url' => __('Buy tickets URL (optional)', AI1EC_PLUGIN_NAME), 'label_rsvp_url' => __('Registration URL (optional)', AI1EC_PLUGIN_NAME), 'label_a_buy_tickets_url' => __('Buy Tickets URL:', AI1EC_PLUGIN_NAME), 'label_a_rsvp_url' => __('Registration URL:', AI1EC_PLUGIN_NAME), 'event_price_not_entered' => __('Please enter an event cost, or mark the event as free.', AI1EC_PLUGIN_NAME), 'blog_timezone' => Ai1ec_Meta::get_option('gmt_offset'), 'use_select2' => $this->settings->use_select2_widgets, 'require_desclaimer' => __('If you choose to require a disclaimer on the front-end event creation form, you must provide the disclaimer text (HTML allowed) in the appropriate field.', AI1EC_PLUGIN_NAME)); return $data; }
/** * Returns whether provider is properly configured or not. * * @return bool */ public function is_configured() { if (null !== $this->_is_configured) { return $this->_is_configured; } $this->_is_configured = true; foreach ($this->get_settings() as $key => $setting) { $value = $this->_settings->get($key); if (empty($value)) { $this->_is_configured = false; break; } } return $this->_is_configured; }
/** * Add the link to render the javascript * * @param string $page * @param boolean $backend * * @return void */ public function add_link_to_render_js($page, $backend) { $load_backend_script = 'false'; if (true === $backend) { $load_backend_script = self::TRUE_PARAM; } $is_calendar_page = false; if (true === is_page($this->_settings->get('calendar_page_id'))) { $is_calendar_page = self::TRUE_PARAM; } $url = add_query_arg(array(self::LOAD_JS_PARAMETER => $page, self::IS_BACKEND_PARAMETER => $load_backend_script, self::IS_CALENDAR_PAGE => $is_calendar_page), trailingslashit(ai1ec_get_site_url())); if (true === $backend) { $this->_scripts_helper->enqueue_script(self::JS_HANDLE, $url, array('postbox'), true); } else { $this->_scripts_helper->enqueue_script(self::JS_HANDLE, $url, array(), true); } }
/** * Add the link to render the javascript * * @param string $page * @param boolean $backend * * @return void */ public function add_link_to_render_js($page, $backend) { $load_backend_script = 'false'; if (true === $backend) { $load_backend_script = self::TRUE_PARAM; } $is_calendar_page = false; if (true === is_page($this->_settings->get('calendar_page_id')) || self::CALENDAR_PAGE_JS === $page) { $is_calendar_page = self::TRUE_PARAM; } $url = add_query_arg(array(self::LOAD_JS_PARAMETER => $page, self::IS_BACKEND_PARAMETER => $load_backend_script, self::IS_CALENDAR_PAGE => $is_calendar_page), trailingslashit(ai1ec_get_site_url())); if ($this->_settings->get('cache_dynamic_js') && $is_calendar_page && '1' === $this->_registry->get('model.option')->get('calendarjsupdated') && $this->_registry->get('filesystem.checker')->check_file_exists(AI1EC_PATH . self::CALENDAR_JS_CACHE_FILE, true)) { $url = plugin_dir_url('all-in-one-event-calendar/public/js_cache/.') . $page; } if (true === $backend) { $this->_scripts_helper->enqueue_script(self::JS_HANDLE, $url, array('postbox'), true); } else { $this->_scripts_helper->enqueue_script(self::JS_HANDLE, $url, array(), false); } }
/** * Check if at least one filter is set in the request * * @param array $view_args * @return boolean */ public static function is_at_least_one_filter_set_in_request(array $view_args) { if (null === self::$at_least_one_filter_set_in_request) { $filter_set = false; $ai1ec_settings = Ai1ec_Settings::get_instance(); // check if something in the filters is set foreach (Ai1ec_Cookie_Utility::$types as $type) { if (!empty($view_args[$type])) { $filter_set = true; break; } } // check if the default view is set if ($ai1ec_settings->default_calendar_view !== $view_args['action']) { $filter_set = true; } self::$at_least_one_filter_set_in_request = $filter_set; } return self::$at_least_one_filter_set_in_request; }
/** * Allow the upgrade notice only on certain pages. * * @param string|bool $real_value Value from options table or false if none * * @return string|bool Given value {$real_value} or false */ public function limit_update_notice($real_value) { // In CRON `get_current_screen()` is not present // and we wish to have notice on all "our" pages if (isset($_GET['page']) && 0 === strncasecmp($_GET['page'], AI1EC_PLUGIN_NAME, strlen(AI1EC_PLUGIN_NAME)) || !function_exists('get_current_screen')) { return $real_value; } $ai1ec_settings = Ai1ec_Settings::get_instance(); $screen = get_current_screen(); $allow_on = array('plugins', 'update-core', $ai1ec_settings->settings_page); if (is_object($screen) && isset($screen->id) && in_array($screen->id, $allow_on)) { return $real_value; } return false; }
/** * get_instance function * * Return singleton instance * * @return Ai1ec_Settings **/ static function get_instance($refresh = false) { if (self::$_instance === NULL || $refresh) { // if W3TC is enabled, we have to empty the cache // before requesting it if (defined('W3TC') || defined('WP_CACHE')) { wp_cache_delete('alloptions', 'options'); } // get the settings from the database self::$_instance = Ai1ec_Meta::get_option('ai1ec_settings'); // if there are no settings in the database // save default values for the settings if (!self::$_instance) { self::$_instance = new self(); delete_option('ai1ec_settings'); add_option('ai1ec_settings', self::$_instance); } else { self::$_instance->set_defaults(); // set default settings } self::$_instance = apply_filters('ai1ec_settings_initiated', self::$_instance); } return self::$_instance; }
/** * Handle AJAX request for submission of front-end create event form. * * @return null */ public function submit_front_end_create_event_form() { global $ai1ec_view_helper, $ai1ec_calendar_helper, $ai1ec_events_helper; $ai1ec_settings = Ai1ec_Settings::get_instance(); $error = false; $html = ''; $default_error_msg = __('There was an error creating your event.', AI1EC_PLUGIN_NAME) . ' ' . __('Please try again or contact the site administrator for help.', AI1EC_PLUGIN_NAME); $valid = $this->validate_front_end_create_event_form($message); // If valid submission, proceed with event creation. if ($valid) { // Determine post publish status. if (current_user_can('publish_ai1ec_events')) { $post_status = 'publish'; } else { if (current_user_can('edit_ai1ec_events')) { $post_status = 'pending'; } else { if ($ai1ec_settings->allow_anonymous_submissions) { $post_status = 'pending'; } } } // Strip slashes if ridiculous PHP setting magic_quotes_gpc is enabled. foreach ($_POST as $param_name => $param) { if ('ai1ec' === substr($param_name, 0, 5) && is_scalar($param)) { $_POST[$param_name] = stripslashes($param); } } // Build post array from submitted data. $post = array('post_type' => AI1EC_POST_TYPE, 'post_author' => get_current_user_id(), 'post_title' => $_POST['post_title'], 'post_content' => $_POST['post_content'], 'post_status' => $post_status); // Copy posted event data to new empty event object. $event = new Ai1ec_Event(); $event->post = $post; $event->categories = isset($_POST['ai1ec_categories']) ? implode(',', $_POST['ai1ec_categories']) : ''; $event->tags = isset($_POST['ai1ec_tags']) ? $_POST['ai1ec_tags'] : ''; $event->allday = isset($_POST['ai1ec_all_day_event']) ? (bool) $_POST['ai1ec_all_day_event'] : 0; $event->instant_event = isset($_POST['ai1ec_instant_event']) ? (bool) $_POST['ai1ec_instant_event'] : 0; $event->start = isset($_POST['ai1ec_start_time']) ? $_POST['ai1ec_start_time'] : ''; if ($event->instant_event) { $event->end = $event->start + 1800; } else { $event->end = isset($_POST['ai1ec_end_time']) ? $_POST['ai1ec_end_time'] : ''; } $event->address = isset($_POST['ai1ec_address']) ? $_POST['ai1ec_address'] : ''; $event->show_map = isset($_POST['ai1ec_google_map']) ? (bool) $_POST['ai1ec_google_map'] : 0; $scalar_field_list = array('ai1ec_venue' => FILTER_SANITIZE_STRING, 'ai1ec_cost' => FILTER_SANITIZE_STRING, 'ai1ec_is_free' => FILTER_SANITIZE_NUMBER_INT, 'ai1ec_ticket_url' => FILTER_VALIDATE_URL, 'ai1ec_contact_name' => FILTER_SANITIZE_STRING, 'ai1ec_contact_phone' => FILTER_SANITIZE_STRING, 'ai1ec_contact_email' => FILTER_VALIDATE_EMAIL, 'ai1ec_contact_url' => FILTER_VALIDATE_URL); foreach ($scalar_field_list as $scalar_field => $field_filter) { $scalar_value = filter_input(INPUT_POST, $scalar_field, $field_filter); if (!empty($scalar_value)) { $use_name = substr($scalar_field, 6); $event->{$use_name} = $scalar_value; } } // Save the event to the database. try { $event->save(); $ai1ec_events_helper->cache_event($event); // Check if uploads are enabled and there is an uploaded file. if ((is_user_logged_in() || $ai1ec_settings->allow_anonymous_submissions && $ai1ec_settings->allow_anonymous_uploads) && !empty($_FILES['ai1ec_image']['name'])) { require_once ABSPATH . 'wp-admin/includes/image.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; require_once ABSPATH . 'wp-admin/includes/media.php'; $attach_id = media_handle_upload('ai1ec_image', $event->post_id); if (is_int($attach_id)) { update_post_meta($event->post_id, '_thumbnail_id', $attach_id); } } // Send the mail $admin_notification = Ai1ec_Notification_Factory::create_notification_instance(array(get_option('admin_email')), $ai1ec_settings->admin_add_new_event_mail_body, Ai1ec_Notification_Factory::EMAIL_NOTIFICATION, $ai1ec_settings->admin_add_new_event_mail_subject); $edit_url = 'post.php?post=' . $event->post_id . '&action=edit'; $translations = array('[event_title]' => $_POST['post_title'], '[site_title]' => get_bloginfo('name'), '[site_url]' => site_url(), '[event_admin_url]' => admin_url($edit_url)); $admin_notification->set_translations($translations); $sent = $admin_notification->send(); if (current_user_can('publish_ai1ec_events')) { $message = sprintf(__('Thank you for your submission. Your event <em>%s</em> was published successfully.', AI1EC_PLUGIN_NAME), $post['post_title']); $link_text = __('View Your Event', AI1EC_PLUGIN_NAME); $link_url = get_permalink($event->post_id); } else { $message = sprintf(__('Thank you for your submission. Your event <em>%s</em> will be reviewed and published once approved.', AI1EC_PLUGIN_NAME), $post['post_title']); $link_text = __('Back to Calendar', AI1EC_PLUGIN_NAME); $link_url = $ai1ec_calendar_helper->get_calendar_url(); } } catch (Exception $e) { trigger_error(sprintf(__('There was an error during event creation: %s', AI1EC_PLUGIN_NAME), $e->getMessage()), E_USER_WARNING); $error = true; $message = $default_error_msg; } $args = array('message_type' => $error ? 'error' : 'success', 'message' => $message, 'link_text' => $link_text, 'link_url' => $link_url); $html = $ai1ec_view_helper->get_theme_view('create-event-message.php', $args); } else { $error = true; } $response = array('error' => $error, 'message' => $message, 'html' => $html); $ai1ec_view_helper->xml_response($response); }
/** * Adds extension settings * * @param Ai1ec_Settings $settings */ protected function _add_settings(Ai1ec_Settings $settings) { foreach ($this->_settings as $name => $params) { $renderer = null; if (isset($params['renderer'])) { $renderer = $params['renderer']; } $settings->register($name, $params['value'], $params['type'], $renderer, $this->get_version()); } }
} // Not a plugin update request. $plugins = unserialize($r['body']['plugins']); unset($plugins->plugins[plugin_basename(__FILE__)]); unset($plugins->active[array_search(plugin_basename(__FILE__), $plugins->active)]); $r['body']['plugins'] = serialize($plugins); return $r; } add_filter('http_request_args', 'ai1ec_disable_updates', 5, 2); // Instantiate scheduling utility early, to get all schedules set-up Ai1ec_Scheduling_Utility::instance(); // =============================== // = Initialize and setup MODELS = // =============================== global $ai1ec_settings; $ai1ec_settings = Ai1ec_Settings::get_instance(); // If GZIP is causing JavaScript failure following query // parameter disable compression, until reversing change // is made. Causative issue: AIOEC-1192. if (isset($_REQUEST['ai1ec_disable_gzip_compression'])) { $ai1ec_settings->disable_gzip_compression = true; $ai1ec_settings->save(); } // This is a fix for AIOEC-73. I need to set those values as soon as possible so that // the platofrom controller has the fresh data and can act accordingly // I do not trigger the save action at this point because there are too many things going on // there and i might break things if (isset($_POST['ai1ec_save_settings'])) { $ai1ec_settings->event_platform = isset($_POST['event_platform']); $ai1ec_settings->event_platform_strict = isset($_POST['event_platform_strict']); }