/**
  * Creates the output of the RSS feed.
  * 
  * @param boolean $comment ( ignored )
  */
 public function create_feed_output($comment)
 {
     global $ai1ec_calendar_helper, $ai1ec_view_helper, $ai1ec_events_helper, $ai1ec_settings;
     $number_of_posts = Ai1ec_Meta::get_option('posts_per_rss');
     // Get the request parser
     $request = new Ai1ec_Arguments_Parser(NULL, 'ai1ec_' . $ai1ec_settings->default_calendar_view);
     $request->parse();
     // Create the filter
     $filter = array('cat_ids' => $request->get('cat_ids'), 'tag_ids' => $request->get('tag_ids'), 'post_ids' => $request->get('post_ids'));
     $event_results = $ai1ec_calendar_helper->get_events_relative_to($ai1ec_events_helper->gmt_to_local(Ai1ec_Time_Utility::current_time()), $number_of_posts, 0, $filter, 0);
     require_once AI1EC_VIEW_PATH . '/event-feed-rss2.php';
 }
 /**
  * Handles all the required steps to install / update the schema
  */
 private function install_schema()
 {
     // If existing DB version is not consistent with current plugin's version,
     // or does not exist, then create/update table structure using dbDelta().
     if (Ai1ec_Meta::get_option(self::ICS_OPTION_DB_VERSION) != self::ICS_DB_VERSION) {
         global $wpdb;
         // ======================
         // = Create table feeds =
         // ======================
         $table_name = $wpdb->prefix . 'ai1ec_event_feeds';
         $sql = "CREATE TABLE {$table_name} (\r\n\t\t\t\tfeed_id bigint(20) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\tfeed_url varchar(255) CHARACTER SET ascii COLLATE ascii_general_ci NOT NULL,\r\n\t\t\t\tfeed_category bigint(20) NOT NULL,\r\n\t\t\t\tfeed_tags varchar(255) NOT NULL,\r\n\t\t\t\tcomments_enabled tinyint(1) NOT NULL DEFAULT '1',\r\n\t\t\t\tmap_display_enabled tinyint(1) NOT NULL DEFAULT '0',\r\n\t\t\t\tPRIMARY KEY  (feed_id),\r\n\t\t\t\tUNIQUE KEY feed (feed_url)\r\n\t\t\t) CHARACTER SET utf8;";
         if (Ai1ec_Database::instance()->apply_delta($sql)) {
             update_option(self::ICS_OPTION_DB_VERSION, self::ICS_DB_VERSION);
         } else {
             trigger_error('Failed to upgrade ICS DB schema', E_USER_WARNING);
         }
     }
 }
	<sy:updatePeriod><?php 
echo apply_filters('rss_update_period', 'hourly');
?>
</sy:updatePeriod>
	<sy:updateFrequency><?php 
echo apply_filters('rss_update_frequency', '1');
?>
</sy:updateFrequency>
<?php 
foreach ($event_results['events'] as $event) {
    $title = htmlspecialchars(apply_filters('the_title', $event->post->post_title, $event->post_id));
    $permalink = htmlspecialchars(get_permalink($event->post_id));
    $date = date('d M Y H:i:s', $event->start);
    $user_info = get_userdata($event->post->post_author);
    $location = str_replace("\n", ', ', rtrim($event->get_location()));
    $use_excerpt = Ai1ec_Meta::get_option('rss_use_excerpt');
    $description = apply_filters('the_content', $event->post->post_content);
    if ($use_excerpt) {
        $description = Ai1ec_String_Utility::truncate_string_if_longer_than_x_words($description, 50, " <a href='{$permalink}' >" . __('Read more...', AI1EC_PLUGIN_NAME) . "</a>");
    }
    $args = array('timespan' => $event->get_timespan_html(), 'location' => $location, 'permalink' => $permalink, 'description' => wpautop($description));
    // Load the RSS specific template
    ob_start();
    $ai1ec_view_helper->display_theme('event-feed-description.php', $args);
    $content = ob_get_contents();
    ob_end_clean();
    $user = $user_info->user_login;
    $guid = htmlspecialchars(get_the_guid($event->post_id));
    $comments = esc_url(get_post_comments_feed_link($event->post_id, 'rss2'));
    $comments_number = get_comments_number($event->post_id);
    echo <<<FEED
 /**
  * Constructor
  *
  * Read configured hooks and frequencies from database
  *
  * @return void Constructor does not return
  */
 protected function __construct()
 {
     $defaults = array('hooks' => array(), 'freqs' => array(), 'version' => '1.11');
     $this->_updated = false;
     $this->_configuration = Ai1ec_Meta::get_option(self::OPTION_NAME, $defaults);
     $this->_configuration = array_merge($defaults, $this->_configuration);
     $this->install_default_schedules();
     Ai1ec_Shutdown_Utility::instance()->register(array($this, 'shutdown'));
     add_filter('ai1ec_settings_initiated', array($this, 'settings_initiated_hook'));
 }
 /**
  * Return the embedded day view of the calendar, optionally filtered by
  * event categories and tags.
  *
  * @param array $args     associative array with any of these elements:
  *   int oneday_offset  => specifies which day to display relative to the
  *                        current day
  *   array cat_ids     => restrict events returned to the given set of
  *                        event category slugs
  *   array tag_ids     => restrict events returned to the given set of
  *                        event tag names
  *   array post_ids    => restrict events returned to the given set of
  *                        post IDs
  *
  * @return string	        returns string of view output
  */
 function get_oneday_view($args)
 {
     global $ai1ec_view_helper, $ai1ec_events_helper, $ai1ec_calendar_helper, $ai1ec_settings;
     $defaults = array('oneday_offset' => 0, 'cat_ids' => array(), 'tag_ids' => array(), 'post_ids' => array(), 'exact_date' => Ai1ec_Time_Utility::current_time());
     $args = wp_parse_args($args, $defaults);
     // Localize requested date and get components.
     $local_date = Ai1ec_Time_Utility::gmt_to_local($args['exact_date']);
     $bits = Ai1ec_Time_Utility::gmgetdate($local_date);
     // Apply day offset.
     $day_shift = 0 + $args['oneday_offset'];
     // Now align date to start of day (midnight).
     $local_date = gmmktime(0, 0, 0, $bits['mon'], $bits['mday'] + $day_shift, $bits['year']);
     $cell_array = $ai1ec_calendar_helper->get_oneday_cell_array($local_date, array('cat_ids' => $args['cat_ids'], 'tag_ids' => $args['tag_ids'], 'post_ids' => $args['post_ids']));
     // Create pagination links.
     $pagination_links = $ai1ec_calendar_helper->get_oneday_pagination_links($args);
     $pagination_links = $ai1ec_view_helper->get_theme_view('pagination.php', array('links' => $pagination_links, 'data_type' => $args['data_type']));
     $date_format = Ai1ec_Meta::get_option('date_format', 'l, M j, Y');
     $title = Ai1ec_Time_Utility::date_i18n($date_format, $local_date, true);
     $time_format = Ai1ec_Meta::get_option('time_format', 'g a');
     // Calculate today marker's position.
     $now = Ai1ec_Time_Utility::current_time();
     $now = Ai1ec_Time_Utility::gmt_to_local($now);
     $now_text = $ai1ec_events_helper->get_short_time($now, false);
     $now = Ai1ec_Time_Utility::gmgetdate($now);
     $now = $now['hours'] * 60 + $now['minutes'];
     $view_args = array('title' => $title, 'type' => 'oneday', 'cell_array' => $cell_array, 'show_location_in_title' => $ai1ec_settings->show_location_in_title, 'now_top' => $now, 'now_text' => $now_text, 'pagination_links' => $pagination_links, 'post_ids' => join(',', $args['post_ids']), 'time_format' => $time_format, 'done_allday_label' => false, 'done_grid' => false, 'data_type' => $args['data_type'], 'data_type_events' => '');
     if ($ai1ec_settings->ajaxify_events_in_web_widget) {
         $view_args['data_type_events'] = $args['data_type'];
     }
     // Add navigation if requested.
     $view_args['navigation'] = $args['no_navigation'] ? '' : $ai1ec_view_helper->get_theme_view('navigation.php', $view_args);
     return apply_filters('ai1ec_get_oneday_view', $ai1ec_view_helper->get_theme_view('oneday.php', $view_args), $view_args);
 }
 /**
  * admin_notices function
  *
  * Notify the user about anything special.
  *
  * @return void
  **/
 function admin_notices()
 {
     global $ai1ec_view_helper, $ai1ec_settings, $plugin_page, $ai1ec_themes_controller, $ai1ec_importer_plugin_helper;
     if ('invalid' == $ai1ec_settings->license_warning) {
         $args = array('label' => __('All-in-One Event Calendar Warning', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Our records indicate that your license for the Pro Calendar has expired.</strong> Without a valid license you will not be able to access Premium Support services or receive software updates.</p><p>Please log into your <a href="%s" target="_blank">Timely Account</a> to renew your Pro license.</p>', AI1EC_PLUGIN_NAME), AI1EC_TIMELY_ACCOUNT_URL), 'button' => (object) array('class' => 'ai1ec-dismiss-license-warning', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME)), 'message_type' => 'error');
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     // Display introductory video notice if not disabled.
     if ($ai1ec_settings->show_intro_video) {
         $args = array('label' => __('Welcome to the All-in-One Event Calendar, by Timely', AI1EC_PLUGIN_NAME), 'msg' => sprintf('<div class="timely"><a href="#ai1ec-video-modal" data-toggle="modal" ' . 'class="button-primary pull-left">%s</a>' . '<div class="pull-left">&nbsp;</div></div>', __('Watch the introductory video »', AI1EC_PLUGIN_NAME)), 'button' => (object) array('class' => 'ai1ec-dismiss-intro-video', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME)));
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
         // Find out if CSS for Bootstrap modals has been attached. If not, embed
         // it inline.
         if (!wp_style_is('timely-bootstrap')) {
             $ai1ec_view_helper->display_admin_css('bootstrap.min.css');
         }
         $args = array('title' => __('Introducing the All-in-One Event Calendar, by Timely', AI1EC_PLUGIN_NAME), 'youtube_id' => 'XJ-KHOqBKuQ');
         $ai1ec_view_helper->display_admin('video_modal.php', $args);
     }
     // No themes available notice.
     if (!$ai1ec_themes_controller->are_themes_available()) {
         $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Core Calendar Themes are not installed.</strong></p>' . '<p>Our automated install couldn\'t install the core Calendar Themes automatically. ' . 'You will need to install calendar themes manually by following these steps:</p>' . '<ol><li>Gain access to your WordPress files. Either direct filesystem access or FTP access is fine.</li>' . '<li>Navigate to the <strong>%s</strong> folder.</li>' . '<li>Copy the <strong>%s</strong> folder and all of its contents into the <strong>%s</strong> folder.</li>' . '<li>You should now have a folder named <strong>%s</strong> containing all the same files and sub-folders as <strong>%s</strong> does.</li>' . '<li>Refresh this page and if this notice is gone, the core Calendar Themes are installed.</li></ol>', AI1EC_PLUGIN_NAME), AI1EC_PATH, AI1EC_THEMES_FOLDER, WP_CONTENT_DIR, WP_CONTENT_DIR . '/' . AI1EC_THEMES_FOLDER, AI1EC_PATH . '/' . AI1EC_THEMES_FOLDER));
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     // Outdated themes notice (on all pages except update themes page).
     if ($plugin_page != AI1EC_PLUGIN_NAME . '-update-themes' && $ai1ec_themes_controller->are_themes_outdated()) {
         $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p><strong>Core Calendar Themes are out of date.</strong> ' . 'We have found updates for some of your core Calendar Theme files and you should update them now to ensure proper functioning of your calendar.</p>' . '<p><strong>Warning:</strong> If you have previously modified any <strong>core</strong> Calendar Theme files, ' . 'your changes will be lost during update. Please make a backup of all modifications to core themes before proceeding.</p>' . '<p>Once you are ready, please <a href="%s">update your core Calendar Themes</a>.</p>', AI1EC_PLUGIN_NAME), admin_url(AI1EC_UPDATE_THEMES_BASE_URL)));
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     if ($ai1ec_settings->show_data_notification) {
         $args = array('label' => __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME), 'msg' => sprintf(__('<p>We collect some basic information about how your calendar works in order to deliver a better ' . 'and faster calendar system and one that will help you promote your events even more.</p>' . '<p>You can find more detailed information on our privacy policy by <a href="%s" target="_blank">clicking here</a>.</p>', AI1EC_PLUGIN_NAME), 'http://time.ly/event-search-calendar', admin_url(AI1EC_SETTINGS_BASE_URL)), 'button' => (object) array('class' => 'ai1ec-dismiss-notification', 'value' => __('Dismiss', AI1EC_PLUGIN_NAME)));
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     // If calendar page or time zone has not been set, this is a fresh install.
     // Additionally, if we're not already updating the settings, alert user
     // appropriately that the calendar is not properly set up.
     if ((!$ai1ec_settings->calendar_page_id || !Ai1ec_Meta::get_option('timezone_string')) && !isset($_REQUEST['ai1ec_save_settings'])) {
         $args = array();
         $messages = array();
         // Display messages for blog admin.
         if (current_user_can('manage_ai1ec_options')) {
             // If on the settings page, instruct user as to what to do.
             if ($plugin_page == AI1EC_PLUGIN_NAME . '-settings') {
                 if (!$ai1ec_settings->calendar_page_id) {
                     $messages[] = __('Select an option in the <strong>Calendar page</strong> dropdown list.', AI1EC_PLUGIN_NAME);
                 }
                 if (!Ai1ec_Meta::get_option('timezone_string')) {
                     $messages[] = __('Select an option in the <strong>Timezone</strong> dropdown list.', AI1EC_PLUGIN_NAME);
                 }
                 $messages[] = __('Click <strong>Update Settings</strong>.', AI1EC_PLUGIN_NAME);
             } else {
                 $msg = sprintf(__('The plugin is installed, but has not been configured. <a href="%s">Click here to set it up now &raquo;</a>', AI1EC_PLUGIN_NAME), admin_url(AI1EC_SETTINGS_BASE_URL));
                 $messages[] = $msg;
             }
         } else {
             $messages[] = __('The plugin is installed, but has not been configured. Please log in as an Administrator to set it up.', AI1EC_PLUGIN_NAME);
         }
         // Format notice message.
         if (count($messages) > 1) {
             $args['msg'] = __('<p>To set up the plugin:</p>', AI1EC_PLUGIN_NAME);
             $args['msg'] .= '<ol><li>';
             $args['msg'] .= implode('</li><li>', $messages);
             $args['msg'] .= '</li></ol>';
         } else {
             $args['msg'] = "<p>{$messages['0']}</p>";
         }
         $args['label'] = __('All-in-One Event Calendar Notice', AI1EC_PLUGIN_NAME);
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     // Premium plugin update available notice.
     $meta = Ai1ec_Meta::instance('Option');
     if ($meta->get('ai1ec_update_available', NULL, false) && current_user_can('update_plugins')) {
         $args = array('label' => __('All-in-One Event Calendar Update', AI1EC_PLUGIN_NAME));
         $update_url = AI1EC_UPGRADE_PLUGIN_BASE_URL;
         $args['msg'] = '<p>' . $meta->get('ai1ec_update_message', NULL, '') . '</p>';
         $args['msg'] .= '<p><a class="button" href="' . admin_url($update_url) . '">';
         $args['msg'] .= __('Upgrade now', AI1EC_PLUGIN_NAME);
         $args['msg'] .= '</a></p>';
         $ai1ec_view_helper->display_admin('admin_notices.php', $args);
     }
     // Let the plugin display their notice.
     $ai1ec_importer_plugin_helper->display_admin_notices();
 }
 /**
  * Custom "Right Now" dashboard widget for Calendar Administrators.
  *
  * @return  void
  */
 function dashboard_right_now()
 {
     global $wp_registered_sidebars;
     $num_comm = wp_count_comments();
     echo "\n\t" . '<div class="table table_content">';
     echo "\n\t" . '<p class="sub">' . __('Content') . '</p>' . "\n\t" . '<table>';
     echo "\n\t" . '<tr class="first">';
     do_action('right_now_content_table_end');
     echo "\n\t</table>\n\t</div>";
     echo "\n\t" . '<div class="table table_discussion">';
     echo "\n\t" . '<p class="sub">' . __('Discussion') . '</p>' . "\n\t" . '<table>';
     echo "\n\t" . '<tr class="first">';
     // Total Comments
     $num = '<span class="total-count">' . number_format_i18n($num_comm->total_comments) . '</span>';
     $text = _n('Comment', 'Comments', $num_comm->total_comments);
     if (current_user_can('moderate_comments')) {
         $num = '<a href="edit-comments.php">' . $num . '</a>';
         $text = '<a href="edit-comments.php">' . $text . '</a>';
     }
     echo '<td class="b b-comments">' . $num . '</td>';
     echo '<td class="last t comments">' . $text . '</td>';
     echo '</tr><tr>';
     // Approved Comments
     $num = '<span class="approved-count">' . number_format_i18n($num_comm->approved) . '</span>';
     $text = _nx('Approved', 'Approved', $num_comm->approved, 'Right Now');
     if (current_user_can('moderate_comments')) {
         $num = "<a href='edit-comments.php?comment_status=approved'>{$num}</a>";
         $text = "<a class='approved' href='edit-comments.php?comment_status=approved'>{$text}</a>";
     }
     echo '<td class="b b_approved">' . $num . '</td>';
     echo '<td class="last t">' . $text . '</td>';
     echo "</tr>\n\t<tr>";
     // Pending Comments
     $num = '<span class="pending-count">' . number_format_i18n($num_comm->moderated) . '</span>';
     $text = _n('Pending', 'Pending', $num_comm->moderated);
     if (current_user_can('moderate_comments')) {
         $num = "<a href='edit-comments.php?comment_status=moderated'>{$num}</a>";
         $text = "<a class='waiting' href='edit-comments.php?comment_status=moderated'>{$text}</a>";
     }
     echo '<td class="b b-waiting">' . $num . '</td>';
     echo '<td class="last t">' . $text . '</td>';
     echo "</tr>\n\t<tr>";
     // Spam Comments
     $num = number_format_i18n($num_comm->spam);
     $text = _nx('Spam', 'Spam', $num_comm->spam, 'comment');
     if (current_user_can('moderate_comments')) {
         $num = "<a href='edit-comments.php?comment_status=spam'><span class='spam-count'>{$num}</span></a>";
         $text = "<a class='spam' href='edit-comments.php?comment_status=spam'>{$text}</a>";
     }
     echo '<td class="b b-spam">' . $num . '</td>';
     echo '<td class="last t">' . $text . '</td>';
     echo "</tr>";
     do_action('right_now_table_end');
     do_action('right_now_discussion_table_end');
     echo "\n\t</table>\n\t</div>";
     echo "\n\t" . '<div class="versions">';
     // Check if search engines are blocked.
     if (!is_network_admin() && !is_user_admin() && current_user_can('manage_options') && '1' != Ai1ec_Meta::get_option('blog_public')) {
         $title = apply_filters('privacy_on_link_title', __('Your site is asking search engines not to index its content'));
         $content = apply_filters('privacy_on_link_text', __('Search Engines Blocked'));
         echo "<p><a href='options-privacy.php' title='{$title}'>{$content}</a></p>";
     }
     $msg = sprintf(__('You are using <span class="b">All-in-One Event Calendar %s</span>.'), AI1EC_VERSION);
     echo "<span id='wp-version-message'>{$msg}</span>";
     echo "\n\t" . '<br class="clear" /></div>';
     do_action('ai1ec_rightnow_end');
     do_action('activity_box_end');
 }
 /**
  * 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;
 }
 /**
  * upgrade function
  *
  * @return void
  **/
 function upgrade()
 {
     // continue only if user can update plugins
     if (!current_user_can('update_plugins')) {
         wp_die(__('You do not have sufficient permissions to update plugins for this site.'));
     }
     $package_url = Ai1ec_Meta::get_option('ai1ec_package_url');
     $plugin_name = Ai1ec_Meta::get_option('ai1ec_plugin_name');
     if (empty($package_url) || empty($plugin_name)) {
         wp_die(__('Download package is needed and was not supplied. Visit <a href="http://time.ly/" target="_blank">time.ly</a> to download the newest version of the plugin.'));
     }
     // use our custom class
     $upgrader = new Ai1ec_Updater();
     // update the plugin
     $upgrader->upgrade($plugin_name, $package_url);
     // clear update notification
     update_option('ai1ec_update_available', 0);
     update_option('ai1ec_update_message', '');
     update_option('ai1ec_package_url', '');
     update_option('ai1ec_plugin_name', '');
 }
 /**
  * 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);
 }
    /**
     * _create_table method
     *
     * Method check current DB version, and updates table, if necessary.
     *
     * @return bool Success / validity
     */
    protected function _create_table()
    {
        $success = true;
        $option = 'ai1ec_log_db_ver';
        if (Ai1ec_Meta::get_option($option) != self::DB_VERSION) {
            $sql_query = '
				CREATE TABLE ' . $this->_table() . ' (
					id          BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
					remote_addr VARCHAR(39),
					the_time    INT(10) UNSIGNED NOT NULL,
					http_method VARCHAR(10) NOT NULL,
					srv_host    VARCHAR(200) NOT NULL,
					request_uri VARCHAR(255) NOT NULL,
					logger      VARCHAR(255) NOT NULL,
					err_level   VARCHAR(32) NOT NULL,
					message     VARCHAR(4000) NOT NULL,
					thread      INT(10) UNSIGNED NOT NULL,
					last_file   VARCHAR(255) NOT NULL,
					last_line   SMALLINT(5) UNSIGNED NOT NULL,
					PRIMARY KEY (id)
				) ENGINE=InnoDB CHARACTER SET utf8;
			';
            if (Ai1ec_Database::instance()->apply_delta($sql_query)) {
                update_option($option, self::DB_VERSION);
            } else {
                trigger_error('Failed to upgrade/install Logger database', E_USER_WARNING);
                $success = false;
            }
        }
        return $success;
    }
 /**
  * Display notices available to super-admin only
  *
  * Term super-admin identifies network admin in network
  * installation, or admin otherwise
  *
  * @return void Method does not return
  */
 public function network_admin_notices()
 {
     // Premium plugin update available notice.
     $meta = Ai1ec_Meta::instance('Option');
     if (!$meta->is_visible_update()) {
         return NULL;
     }
     global $ai1ec_view_helper;
     $args = array('label' => __('All-in-One Event Calendar Update', AI1EC_PLUGIN_NAME));
     $update_url = AI1EC_UPGRADE_PLUGIN_BASE_URL;
     $args['msg'] = '<p>' . $meta->get('ai1ec_update_message', NULL, '') . '</p>';
     $args['msg'] .= '<p><a class="button" href="' . admin_url($update_url) . '">';
     $args['msg'] .= __('Upgrade now', AI1EC_PLUGIN_NAME);
     $args['msg'] .= '</a></p>';
     $ai1ec_view_helper->display_admin('admin_notices.php', $args);
 }
 /**
  * theme_enqueue_style function
  *
  * @return void
  **/
 function theme_enqueue_style($name, $file, $deps = array())
 {
     global $ai1ec_themes_controller;
     if (!$file || empty($file)) {
         throw new Ai1ec_File_Not_Provided("You need to specify a style file.");
     }
     // template path
     $active_template_path = $ai1ec_themes_controller->active_template_path();
     // template url
     $active_template_url = $ai1ec_themes_controller->active_template_url();
     // look for the file in the active theme
     $themes_root = array((object) array('path' => $active_template_path . '/' . AI1EC_CSS_FOLDER, 'url' => $active_template_url . '/' . AI1EC_CSS_FOLDER), (object) array('path' => $active_template_path, 'url' => $active_template_url), (object) array('path' => AI1EC_DEFAULT_THEME_PATH . '/' . AI1EC_CSS_FOLDER, 'url' => AI1EC_DEFAULT_THEME_URL . '/' . AI1EC_CSS_FOLDER), (object) array('path' => AI1EC_DEFAULT_THEME_PATH, 'url' => AI1EC_DEFAULT_THEME_URL));
     $file_found = false;
     // look for the file in each theme
     foreach ($themes_root as $theme_root) {
         // $_file is a local var to hold the value of
         // the file we are looking for
         $_file = $theme_root->path . '/' . $file;
         if (file_exists($_file)) {
             // file is found
             $file_found = true;
             // assign the found file
             $file = $theme_root->url . '/' . $file;
             // exit the loop;
             break;
         }
     }
     if ($file_found === false) {
         throw new Ai1ec_File_Not_Found("The specified file '" . $file . "' doesn't exist.");
     } else {
         // Append core themes version to version string to make sure recently
         // updated files are used.
         wp_enqueue_style($name, $file, $deps, AI1EC_VERSION . '-' . Ai1ec_Meta::get_option('ai1ec_themes_version', 1));
     }
 }
 /**
  * install_schedule method
  *
  * Update/install, if necessary CRON.
  * Return name of CRON action (hook) executed.
  *
  * @return string Name of CRON action
  */
 public function install_schedule()
 {
     $cron_key = 'ai1ec_logging_cron';
     $optn_key = $cron_key . '_version';
     if (Ai1ec_Meta::get_option($optn_key) != self::CRON_VERSION) {
         wp_clear_scheduled_hook($cron_key);
         wp_schedule_event(Ai1ec_Time_Utility::current_time(), 'daily', $cron_key);
         update_option($optn_key, self::CRON_VERSION);
     }
     return $cron_key;
 }
 /**
  * set_defaults function
  *
  * Set default values for settings.
  *
  * @return void
  **/
 function set_defaults()
 {
     $defaults = array('calendar_page_id' => 0, 'default_calendar_view' => 'posterboard', 'default_categories' => array(), 'default_tags' => array(), 'view_posterboard_enabled' => TRUE, 'view_month_enabled' => TRUE, 'view_week_enabled' => TRUE, 'view_oneday_enabled' => TRUE, 'view_agenda_enabled' => TRUE, 'calendar_css_selector' => '', 'week_start_day' => Ai1ec_Meta::get_option('start_of_week'), 'exact_date' => '', 'posterboard_events_per_page' => 30, 'posterboard_tile_min_width' => 240, 'agenda_events_per_page' => Ai1ec_Meta::get_option('posts_per_page'), 'agenda_include_entire_last_day' => FALSE, 'agenda_events_expanded' => FALSE, 'include_events_in_rss' => FALSE, 'allow_publish_to_facebook' => FALSE, 'facebook_credentials' => NULL, 'user_role_can_create_event' => NULL, 'show_publish_button' => FALSE, 'hide_maps_until_clicked' => FALSE, 'exclude_from_search' => FALSE, 'show_create_event_button' => FALSE, 'turn_off_subscription_buttons' => FALSE, 'inject_categories' => FALSE, 'input_date_format' => 'def', 'input_24h_time' => FALSE, 'cron_freq' => 'daily', 'timezone' => Ai1ec_Meta::get_option('timezone_string'), 'geo_region_biasing' => FALSE, 'show_data_notification' => TRUE, 'show_intro_video' => TRUE, 'allow_statistics' => TRUE, 'event_platform' => FALSE, 'event_platform_strict' => FALSE, 'plugins_options' => array(), 'disable_autocompletion' => FALSE, 'show_location_in_title' => TRUE, 'show_year_in_agenda_dates' => FALSE, 'skip_in_the_loop_check' => false);
     foreach ($defaults as $key => $default) {
         if (!isset($this->{$key})) {
             $this->{$key} = $default;
         }
     }
     // Force enable data collection setting.
     $this->allow_statistics = $defaults['allow_statistics'];
 }
 /**
  * Checks and sends message to Twitter
  *
  * Upon successfully sending message - updates meta to reflect status change
  *
  * @return bool Success
  *
  * @throws Ai1ec_Oauth_Exception In case of some error
  */
 protected function _send_twitter_message($event)
 {
     $format = '[title], [date] @ [venue], [link] [hashtags]';
     $oauth = Ai1ec_Oauth_Controller::get_instance();
     $status = Ai1ec_Meta::instance('Post')->get($event->post_id, '_ai1ec_post_twitter', array('not_requested'));
     if (is_array($status)) {
         $status = (string) current($status);
     }
     if ('pending' !== $status) {
         return false;
     }
     $terms = array_merge(wp_get_post_terms($event->post_id, 'events_categories'), wp_get_post_terms($event->post_id, 'events_tags'));
     $hashtags = array();
     foreach ($terms as $term) {
         $hashtags[] = '#' . implode('_', explode(' ', $term->name));
     }
     $hashtags = implode(' ', array_unique($hashtags));
     $link = get_permalink($event->post) . $event->instance_id;
     $message = str_replace(array('[title]', '[date]', '@ [venue]', '[link]', '[hashtags]'), array($event->post->post_title, $event->get_short_start_date(), $event->venue, $link, $hashtags), $format);
     $message = trim(preg_replace('/ ,/', ',', preg_replace('/\\s+/', ' ', $message)));
     $length = strlen($message);
     $link_length = strlen($link);
     if ($link_length > 20) {
         $length += 20 - $link_length;
     }
     if ($length > 140) {
         $message = substr($message, 0, strrpos($message, ' ', 140 - $length));
     }
     $status = $oauth->get_provider('twitter')->send_message($oauth->get_token($event->post->post_author, 'twitter'), $message);
     if (!$status) {
         return false;
     }
     return update_post_meta($event->post_id, '_ai1ec_post_twitter', array('status' => 'sent', 'twitter_status_id' => $status));
 }
 /**
  * Retrieve current theme display name.
  *
  * If the 'current_theme' option has already been set, then it will be returned
  * instead. If it is not set, then each theme will be iterated over until both
  * the current stylesheet and current template name.
  *
  * @since 1.5.0
  *
  * @return string
  */
 static function get_current_ai1ec_theme()
 {
     if ($theme = Ai1ec_Meta::get_option('ai1ec_current_theme')) {
         return $theme;
     }
     $self_instance = new Ai1ec_Themes_List_Table();
     $themes = $self_instance->get_themes();
     $current_theme = 'Vortex';
     if ($themes) {
         $theme_names = array_keys($themes);
         $current_template = Ai1ec_Meta::get_option('ai1ec_template');
         $current_stylesheet = Ai1ec_Meta::get_option('ai1ec_stylesheet');
         foreach ((array) $theme_names as $theme_name) {
             if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet && $themes[$theme_name]['Template'] == $current_template) {
                 $current_theme = $themes[$theme_name]['Name'];
                 break;
             }
         }
     }
     update_option('ai1ec_current_theme', $current_theme);
     return $current_theme;
 }
 /**
  * set_defaults function
  *
  * Set default values for settings.
  *
  * @return void
  **/
 function set_defaults()
 {
     $admin_mail_subject = __("[[site_title]] New iCalendar (.ics) feed submitted for review", AI1EC_PLUGIN_NAME);
     $admin_mail_body = __("A visitor has submitted their calendar feed for review:\n\niCalendar feed URL: [feed_url]\nCategories: [categories]\n\nTo add this feed to your calendar, visit your Calendar Feeds admin screen and add it as an ICS feed:\n[feeds_url]\n\nPlease respond to this user by e-mail ([user_email]) to let them know whether or not their feed is approved.\n\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $user_mail_subject = __("[[site_title]] Thanks for your calendar submission", AI1EC_PLUGIN_NAME);
     $user_mail_body = __("We have received your calendar submission. We will review it shortly and let you know if it is approved.\n\nThere is a small chance that your submission was lost in a spam trap. If you don't hear from us soon, please resubmit.\n\nThanks,\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $defaults = array('calendar_page_id' => 0, 'default_calendar_view' => 'posterboard', 'default_categories' => array(), 'default_tags' => array(), 'view_posterboard_enabled' => TRUE, 'view_stream_enabled' => TRUE, 'view_month_enabled' => TRUE, 'view_week_enabled' => TRUE, 'view_oneday_enabled' => TRUE, 'view_agenda_enabled' => TRUE, 'calendar_css_selector' => '', 'week_start_day' => Ai1ec_Meta::get_option('start_of_week'), 'exact_date' => '', 'posterboard_events_per_page' => 30, 'posterboard_tile_min_width' => 240, 'stream_events_per_page' => 30, 'agenda_events_per_page' => Ai1ec_Meta::get_option('posts_per_page'), 'agenda_include_entire_last_day' => FALSE, 'agenda_events_expanded' => FALSE, 'include_events_in_rss' => FALSE, 'allow_publish_to_facebook' => FALSE, 'facebook_credentials' => NULL, 'user_role_can_create_event' => NULL, 'show_publish_button' => FALSE, 'hide_maps_until_clicked' => FALSE, 'exclude_from_search' => FALSE, 'show_create_event_button' => FALSE, 'show_front_end_create_form' => FALSE, 'allow_anonymous_submissions' => FALSE, 'allow_anonymous_uploads' => FALSE, 'show_add_calendar_button' => FALSE, 'recaptcha_public_key' => '', 'recaptcha_private_key' => '', 'turn_off_subscription_buttons' => FALSE, 'inject_categories' => FALSE, 'input_date_format' => 'def', 'input_24h_time' => FALSE, 'cron_freq' => 'daily', 'timezone' => Ai1ec_Meta::get_option('timezone_string'), 'geo_region_biasing' => FALSE, 'show_data_notification' => TRUE, 'show_intro_video' => TRUE, 'license_warning' => 'valid', 'allow_statistics' => TRUE, 'event_platform' => FALSE, 'event_platform_strict' => FALSE, 'plugins_options' => array(), 'disable_autocompletion' => FALSE, 'show_location_in_title' => TRUE, 'show_year_in_agenda_dates' => FALSE, 'ajaxify_events_in_web_widget' => false, 'admin_mail_subject' => $admin_mail_subject, 'admin_mail_body' => $admin_mail_body, 'user_mail_subject' => $user_mail_subject, 'user_mail_body' => $user_mail_body);
     foreach ($defaults as $key => $default) {
         if (!isset($this->{$key})) {
             $this->{$key} = $default;
         }
     }
     // Force enable data collection setting.
     $this->allow_statistics = $defaults['allow_statistics'];
 }
 /**
  * Convert an event from a feed into a new Ai1ec_Event object and add it to
  * the calendar.
  *
  * @param Ai1ec_Event $event    Event object
  * @param vcalendar   $calendar Calendar object
  * @param bool        $export   States whether events are created for export
  *
  * @return void
  */
 function insert_event_in_calendar(Ai1ec_Event $event, vcalendar &$calendar, $export = false)
 {
     global $ai1ec_events_helper;
     $tz = Ai1ec_Meta::get_option('timezone_string');
     $e =& $calendar->newComponent('vevent');
     $uid = '';
     if ($event->ical_uid) {
         $uid = addcslashes($event->ical_uid, "\\;,\n");
     } else {
         $uid = sprintf($this->get_uid_format(), $event->post->ID);
     }
     $e->setProperty('uid', $this->_sanitize_value($uid));
     $e->setProperty('url', get_permalink($event->post_id));
     // =========================
     // = Summary & description =
     // =========================
     $e->setProperty('summary', $this->_sanitize_value(html_entity_decode(apply_filters('the_title', $event->post->post_title), ENT_QUOTES, 'UTF-8')));
     $content = apply_filters('the_content', $event->post->post_content);
     $content = str_replace(']]>', ']]&gt;', $content);
     $content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
     // Prepend featured image if available.
     $size = null;
     if ($img_url = $event->get_post_thumbnail_url($size)) {
         $content = '<div class="ai1ec-event-avatar alignleft timely"><img src="' . esc_attr($img_url) . '" width="' . $size[0] . '" height="' . $size[1] . '" /></div>' . $content;
     }
     $e->setProperty('description', $this->_sanitize_value($content));
     // =====================
     // = Start & end times =
     // =====================
     $dtstartstring = '';
     $dtstart = $dtend = array();
     if ($event->allday) {
         $dtstart["VALUE"] = $dtend["VALUE"] = 'DATE';
         // For exporting all day events, don't set a timezone
         if ($tz && !$export) {
             $dtstart["TZID"] = $dtend["TZID"] = $tz;
         }
         // For exportin' all day events, only set the date not the time
         if ($export) {
             $e->setProperty('dtstart', $this->_sanitize_value(gmdate("Ymd", $ai1ec_events_helper->gmt_to_local($event->start))), $dtstart);
             $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend);
         } else {
             $e->setProperty('dtstart', $this->_sanitize_value(gmdate("Ymd\\T", $ai1ec_events_helper->gmt_to_local($event->start))), $dtstart);
             $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd\\T", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend);
         }
     } else {
         if ($tz) {
             $dtstart["TZID"] = $dtend["TZID"] = $tz;
         }
         // This is used later.
         $dtstartstring = gmdate("Ymd\\THis", $ai1ec_events_helper->gmt_to_local($event->start));
         $e->setProperty('dtstart', $this->_sanitize_value($dtstartstring), $dtstart);
         $e->setProperty('dtend', $this->_sanitize_value(gmdate("Ymd\\THis", $ai1ec_events_helper->gmt_to_local($event->end))), $dtend);
     }
     // ========================
     // = Latitude & longitude =
     // ========================
     if (floatval($event->latitude) || floatval($event->longitude)) {
         $e->setProperty('geo', $event->latitude, $event->longitude);
     }
     // ===================
     // = Venue & address =
     // ===================
     if ($event->venue || $event->address) {
         $location = array($event->venue, $event->address);
         $location = array_filter($location);
         $location = implode(' @ ', $location);
         $e->setProperty('location', $this->_sanitize_value($location));
     }
     $categories = array();
     $language = get_bloginfo('language');
     foreach (wp_get_post_terms($event->post_id, 'events_categories') as $cat) {
         $categories[] = $cat->name;
     }
     $e->setProperty('categories', implode(',', $categories), array("LANGUAGE" => $language));
     $tags = array();
     foreach (wp_get_post_terms($event->post_id, 'events_tags') as $tag) {
         $tags[] = $tag->name;
     }
     if (!empty($tags)) {
         $e->setProperty('X-TAGS', implode(',', $tags), array("LANGUAGE" => $language));
     }
     // ==================
     // = Cost & tickets =
     // ==================
     if ($event->cost) {
         $e->setProperty('X-COST', $this->_sanitize_value($event->cost));
     }
     if ($event->ticket_url) {
         $e->setProperty('X-TICKETS-URL', $this->_sanitize_value($event->ticket_url));
     }
     // ====================================
     // = Contact name, phone, e-mail, URL =
     // ====================================
     $contact = array($event->contact_name, $event->contact_phone, $event->contact_email, $event->contact_url);
     $contact = array_filter($contact);
     $contact = implode('; ', $contact);
     $e->setProperty('contact', $this->_sanitize_value($contact));
     // ====================
     // = Recurrence rules =
     // ====================
     $rrule = array();
     if (!empty($event->recurrence_rules)) {
         $rules = array();
         foreach (explode(';', $event->recurrence_rules) as $v) {
             if (strpos($v, '=') === false) {
                 continue;
             }
             list($k, $v) = explode('=', $v);
             $k = strtoupper($k);
             // If $v is a comma-separated list, turn it into array for iCalcreator
             switch ($k) {
                 case 'BYSECOND':
                 case 'BYMINUTE':
                 case 'BYHOUR':
                 case 'BYDAY':
                 case 'BYMONTHDAY':
                 case 'BYYEARDAY':
                 case 'BYWEEKNO':
                 case 'BYMONTH':
                 case 'BYSETPOS':
                     $exploded = explode(',', $v);
                     break;
                 default:
                     $exploded = $v;
                     break;
             }
             // iCalcreator requires a more complex array structure for BYDAY...
             if ($k == 'BYDAY') {
                 $v = array();
                 foreach ($exploded as $day) {
                     $v[] = array('DAY' => $day);
                 }
             } else {
                 $v = $exploded;
             }
             $rrule[$k] = $v;
         }
     }
     // ===================
     // = Exception rules =
     // ===================
     $exrule = array();
     if (!empty($event->exception_rules)) {
         $rules = array();
         foreach (explode(';', $event->exception_rules) as $v) {
             if (strpos($v, '=') === false) {
                 continue;
             }
             list($k, $v) = explode('=', $v);
             $k = strtoupper($k);
             // If $v is a comma-separated list, turn it into array for iCalcreator
             switch ($k) {
                 case 'BYSECOND':
                 case 'BYMINUTE':
                 case 'BYHOUR':
                 case 'BYDAY':
                 case 'BYMONTHDAY':
                 case 'BYYEARDAY':
                 case 'BYWEEKNO':
                 case 'BYMONTH':
                 case 'BYSETPOS':
                     $exploded = explode(',', $v);
                     break;
                 default:
                     $exploded = $v;
                     break;
             }
             // iCalcreator requires a more complex array structure for BYDAY...
             if ($k == 'BYDAY') {
                 $v = array();
                 foreach ($exploded as $day) {
                     $v[] = array('DAY' => $day);
                 }
             } else {
                 $v = $exploded;
             }
             $exrule[$k] = $v;
         }
     }
     // add rrule to exported calendar
     if (!empty($rrule)) {
         $e->setProperty('rrule', $this->_sanitize_value($rrule));
     }
     // add exrule to exported calendar
     if (!empty($exrule)) {
         $e->setProperty('exrule', $this->_sanitize_value($exrule));
     }
     // ===================
     // = Exception dates =
     // ===================
     // For all day events that use a date as DTSTART, date must be supplied
     // For other other events which use DATETIME, we must use that as well
     // We must also match the exact starting time
     if (!empty($event->exception_dates)) {
         foreach (explode(',', $event->exception_dates) as $exdate) {
             if ($event->allday) {
                 // the local date will be always something like 20121122T000000Z
                 // we just need the date
                 $exdate = substr($ai1ec_events_helper->exception_dates_to_local($exdate), 0, 8);
                 $e->setProperty('exdate', array($exdate), array('VALUE' => 'DATE'));
             } else {
                 $params = array();
                 if ($tz) {
                     $params["TZID"] = $tz;
                 }
                 $exdate = $ai1ec_events_helper->exception_dates_to_local($exdate);
                 // get only the date + T
                 $exdate = substr($exdate, 0, 9);
                 // Take the time from
                 $exdate .= substr($dtstartstring, 9);
                 $e->setProperty('exdate', array($exdate), $params);
             }
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see Ai1ec_Connector_Plugin::display_admin_notices()
  */
 public function display_admin_notices()
 {
     // Let's check if the cron has set a message.
     $message = Ai1ec_Meta::get_option(self::FB_OPTION_CRON_NOTICE, false);
     if ($message === false) {
         return;
     }
     global $ai1ec_view_helper;
     $args = array('label' => $message['label'], 'msg' => $message['message'], 'button' => (object) array('class' => 'ai1ec-facebook-cron-dismiss-notification', 'value' => 'Dismiss'), 'message_type' => $message['message_type']);
     $ai1ec_view_helper->display_admin('admin_notices.php', $args);
 }
 /**
  * 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);
 }
 /**
  * are_themes_outdated method
  *
  * Performs multiple checks to find out if theme files need to be updated.
  *
  * If theme files do not exist - they need to be updated, thus this method
  * returns *true*.
  *
  * Else:
  *     -] If theme files version does match shipped version - update version
  *        number in database, as there is nothing to update, and return false;
  *     -] If theme files version does NOT match shipped version - they need to
  *        be updated, thus return *true*.
  *
  * Else themes are in sync, and method returns *false*.
  *
  * @return bool True, if themes are out of sync
  */
 public function are_themes_outdated()
 {
     if (NULL === $this->_are_themes_outdated) {
         if (!$this->are_themes_available()) {
             $this->_are_themes_outdated = true;
         } else {
             $ai1ec_themes_version = Ai1ec_Meta::get_option('ai1ec_themes_version', -1);
             if ((string) $ai1ec_themes_version !== (string) AI1EC_THEMES_VERSION) {
                 try {
                     $modified = $this->list_modified_files();
                     if (0 === count($modified)) {
                         update_option('ai1ec_themes_version', AI1EC_THEMES_VERSION);
                         return false;
                     }
                 } catch (Ai1ec_File_Not_Found $exception) {
                     // silently discard - themes are more than *outdated*
                 }
                 $this->_are_themes_outdated = true;
             } else {
                 $this->_are_themes_outdated = false;
             }
         }
     }
     return $this->_are_themes_outdated;
 }
 /**
  * set_defaults function
  *
  * Set default values for settings.
  *
  * @return void
  **/
 function set_defaults()
 {
     $admin_mail_subject = __("[[site_title]] New iCalendar (.ics) feed submitted for review", AI1EC_PLUGIN_NAME);
     $admin_mail_body = __("A visitor has submitted their calendar feed for review:\n\niCalendar feed URL: [feed_url]\nCategories: [categories]\n\nTo add this feed to your calendar, visit your Calendar Feeds admin screen and add it as an ICS feed:\n[feeds_url]\n\nPlease respond to this user by e-mail ([user_email]) to let them know whether or not their feed is approved.\n\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $user_mail_subject = __("[[site_title]] Thanks for your calendar submission", AI1EC_PLUGIN_NAME);
     $user_mail_body = __("We have received your calendar submission. We will review it shortly and let you know if it is approved.\n\nThere is a small chance that your submission was lost in a spam trap. If you don't hear from us soon, please resubmit.\n\nThanks,\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $admin_add_new_event_subject = __("[[site_title]] New event submission", AI1EC_PLUGIN_NAME);
     $admin_add_new_event_body = __("A new event has been submitted to the site.\n\nEvent title: [event_title]\nModify the event here: [event_admin_url].\n\nThanks,\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $user_upcoming_event_subject = __('[[site_title]] Event reminder: [event_title]', AI1EC_PLUGIN_NAME);
     $user_upcoming_event_body = __("An event you have indicated interest in is about to start:\n\nEvent title: [event_title]\nStarting at: [event_start]\n\nView the event’s details here: [event_url]\n\n(You have received this alert because you asked to receive an email notification for this event.)\n\nRegards,\n[site_title]\n[site_url]", AI1EC_PLUGIN_NAME);
     $license_key = $this->get_license_key();
     $defaults = array('calendar_page_id' => 0, 'default_calendar_view' => 'posterboard', 'default_categories' => array(), 'default_tags' => array(), 'view_posterboard_enabled' => TRUE, 'view_stream_enabled' => TRUE, 'view_month_enabled' => TRUE, 'view_week_enabled' => TRUE, 'view_oneday_enabled' => TRUE, 'view_agenda_enabled' => TRUE, 'calendar_css_selector' => '', 'week_start_day' => Ai1ec_Meta::get_option('start_of_week'), 'exact_date' => '', 'posterboard_events_per_page' => 30, 'disable_standard_filter_menu' => false, 'posterboard_tile_min_width' => 240, 'stream_events_per_page' => 30, 'week_view_starts_at' => self::WEEK_VIEW_STARTS_AT, 'week_view_ends_at' => self::WEEK_VIEW_ENDS_AT, 'agenda_events_per_page' => Ai1ec_Meta::get_option('posts_per_page'), 'agenda_include_entire_last_day' => FALSE, 'agenda_events_expanded' => FALSE, 'include_events_in_rss' => FALSE, 'allow_publish_to_facebook' => FALSE, 'facebook_credentials' => NULL, 'user_role_can_create_event' => NULL, 'show_publish_button' => FALSE, 'hide_maps_until_clicked' => FALSE, 'exclude_from_search' => FALSE, 'show_create_event_button' => FALSE, 'show_front_end_create_form' => FALSE, 'allow_anonymous_submissions' => FALSE, 'allow_anonymous_uploads' => FALSE, 'show_add_calendar_button' => FALSE, 'recaptcha_public_key' => '', 'recaptcha_private_key' => '', 'turn_off_subscription_buttons' => FALSE, 'inject_categories' => FALSE, 'input_date_format' => 'def', 'input_24h_time' => FALSE, 'cron_freq' => 'daily', 'timezone' => Ai1ec_Meta::get_option('timezone_string'), 'geo_region_biasing' => FALSE, 'show_data_notification' => TRUE, 'show_intro_video' => TRUE, 'license_warning' => 'valid', 'allow_statistics' => TRUE, 'event_platform' => FALSE, 'event_platform_strict' => FALSE, 'require_disclaimer' => FALSE, 'disclaimer' => '', 'plugins_options' => array(), 'disable_autocompletion' => FALSE, 'show_location_in_title' => TRUE, 'show_year_in_agenda_dates' => FALSE, 'views_enabled_ticket_button' => array(), 'skip_in_the_loop_check' => false, 'ajaxify_events_in_web_widget' => false, 'admin_mail_subject' => $admin_mail_subject, 'admin_mail_body' => $admin_mail_body, 'user_mail_subject' => $user_mail_subject, 'user_mail_body' => $user_mail_body, 'admin_add_new_event_mail_body' => $admin_add_new_event_body, 'admin_add_new_event_mail_subject' => $admin_add_new_event_subject, 'user_upcoming_event_mail_body' => $user_upcoming_event_body, 'user_upcoming_event_mail_subject' => $user_upcoming_event_subject, 'license_key' => $license_key, 'calendar_base_url_for_permalinks' => false, 'view_cache_refresh_interval' => NULL, 'enable_user_event_notifications' => true, 'oauth_twitter_id' => '', 'oauth_twitter_pass' => '', 'use_select2_widgets' => false, 'twitter_notice_interval' => '8h', 'use_authors_filter' => false, 'disable_gzip_compression' => false);
     $ai1ec_purge_events_cache = Ai1ec_Scheduling_Utility::instance()->get_details('ai1ec_purge_events_cache');
     $defaults['view_cache_refresh_interval'] = $ai1ec_purge_events_cache['freq'];
     unset($ai1ec_purge_events_cache);
     foreach ($defaults as $key => $default) {
         if (!isset($this->{$key})) {
             $this->{$key} = $default;
         }
     }
     // Force enable data collection setting.
     $this->allow_statistics = $defaults['allow_statistics'];
 }
 /**
  * Add Event Details meta box to the Add/Edit Event screen in the dashboard.
  *
  * @return void
  */
 public function meta_box_view()
 {
     global $ai1ec_view_helper, $ai1ec_events_helper, $post, $wpdb, $ai1ec_settings, $ai1ec_importer_plugin_helper;
     $empty_event = new Ai1ec_Event();
     // ==================
     // = Default values =
     // ==================
     // ATTENTION - When adding new fields to the event remember that you must
     // also set up the duplicate-controller.
     // TODO: Fix this duplication.
     $all_day_event = '';
     $instant_event = '';
     $start_timestamp = '';
     $end_timestamp = '';
     $show_map = false;
     $google_map = '';
     $venue = '';
     $country = '';
     $address = '';
     $city = '';
     $province = '';
     $postal_code = '';
     $contact_name = '';
     $contact_phone = '';
     $contact_email = '';
     $contact_url = '';
     $cost = '';
     $is_free = 'checked="checked"';
     $rrule = '';
     $rrule_text = '';
     $repeating_event = false;
     $exrule = '';
     $exrule_text = '';
     $exclude_event = false;
     $exdate = '';
     $show_coordinates = false;
     $longitude = '';
     $latitude = '';
     $coordinates = '';
     $ticket_url = '';
     $instance_id = false;
     if (isset($_REQUEST['instance'])) {
         $instance_id = absint($_REQUEST['instance']);
     }
     $parent_event_id = $ai1ec_events_helper->event_parent($post->ID);
     if ($instance_id) {
         add_filter('print_scripts_array', array($ai1ec_view_helper, 'disable_autosave'));
     }
     try {
         // on some php version, nested try catch blocks fail and the exception would never be caught.
         // this is why we use this approach.
         $excpt = NULL;
         try {
             $event = new Ai1ec_Event($post->ID, $instance_id);
         } catch (Ai1ec_Event_Not_Found $excpt) {
             global $ai1ec_localization_helper;
             $translatable_id = $ai1ec_localization_helper->get_translatable_id();
             if (false !== $translatable_id) {
                 $event = new Ai1ec_Event($translatable_id, $instance_id);
             }
         }
         if (NULL !== $excpt) {
             throw $excpt;
         }
         // Existing event was found. Initialize form values with values from
         // event object.
         $all_day_event = $event->allday ? 'checked' : '';
         $instant_event = $event->instant_event ? 'checked' : '';
         $start_timestamp = $ai1ec_events_helper->gmt_to_local($event->start);
         $end_timestamp = $ai1ec_events_helper->gmt_to_local($event->end);
         $multi_day = $event->get_multiday();
         $show_map = $event->show_map;
         $google_map = $show_map ? 'checked="checked"' : '';
         $show_coordinates = $event->show_coordinates;
         $coordinates = $show_coordinates ? 'checked="checked"' : '';
         $longitude = $event->longitude !== NULL ? floatval($event->longitude) : '';
         $latitude = $event->latitude !== NULL ? floatval($event->latitude) : '';
         // There is a known bug in Wordpress (https://core.trac.wordpress.org/ticket/15158) that saves 0 to the DB instead of null.
         // We handle a special case here to avoid having the fields with a value of 0 when the user never inputted any coordinates
         if (!$show_coordinates) {
             $longitude = '';
             $latitude = '';
         }
         $venue = $event->venue;
         $country = $event->country;
         $address = $event->address;
         $city = $event->city;
         $province = $event->province;
         $postal_code = $event->postal_code;
         $contact_name = $event->contact_name;
         $contact_phone = $event->contact_phone;
         $contact_email = $event->contact_email;
         $contact_url = $event->contact_url;
         $cost = $event->cost;
         $ticket_url = $event->ticket_url;
         $rrule = empty($event->recurrence_rules) ? '' : $ai1ec_events_helper->ics_rule_to_local($event->recurrence_rules);
         $exrule = empty($event->exception_rules) ? '' : $ai1ec_events_helper->ics_rule_to_local($event->exception_rules);
         $exdate = empty($event->exception_dates) ? '' : $ai1ec_events_helper->exception_dates_to_local($event->exception_dates);
         $repeating_event = empty($rrule) ? false : true;
         $exclude_event = empty($exrule) ? false : true;
         $facebook_status = $event->facebook_status;
         $is_free = '';
         if (!empty($event->is_free)) {
             $is_free = 'checked="checked" ';
             $cost = '';
         }
         if ($repeating_event) {
             $rrule_text = ucfirst($ai1ec_events_helper->rrule_to_text($rrule));
         }
         if ($exclude_event) {
             $exrule_text = ucfirst($ai1ec_events_helper->rrule_to_text($exrule));
         }
     } catch (Ai1ec_Event_Not_Found $e) {
         // Event does not exist.
         // Leave form fields undefined (= zero-length strings)
         $event = null;
     }
     // Time zone; display if set.
     $timezone = '';
     $timezone_string = Ai1ec_Meta::get_option('timezone_string');
     if ($timezone_string) {
         $timezone = Ai1ec_Time_Utility::get_gmt_offset_expr();
     }
     // This will store each of the accordion tabs' markup, and passed as an
     // argument to the final view.
     $boxes = array();
     // ===============================
     // = Display event time and date =
     // ===============================
     $args = array('all_day_event' => $all_day_event, 'instant_event' => $instant_event, 'start_timestamp' => $start_timestamp, 'end_timestamp' => $end_timestamp, 'repeating_event' => $repeating_event, 'rrule' => $rrule, 'rrule_text' => $rrule_text, 'exclude_event' => $exclude_event, 'exrule' => $exrule, 'exrule_text' => $exrule_text, 'timezone' => $timezone, 'timezone_string' => $timezone_string, 'exdate' => $exdate, 'parent_event_id' => $parent_event_id, 'instance_id' => $instance_id);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_time_and_date.php', $args);
     // =================================================
     // = Display event location details and Google map =
     // =================================================
     $args = array('venue' => $venue, 'country' => $country, 'address' => $address, 'city' => $city, 'province' => $province, 'postal_code' => $postal_code, 'google_map' => $google_map, 'show_map' => $show_map, 'show_coordinates' => $show_coordinates, 'longitude' => $longitude, 'latitude' => $latitude, 'coordinates' => $coordinates);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_location.php', $args);
     // ======================
     // = Display event cost =
     // ======================
     $args = array('cost' => $cost, 'is_free' => $is_free, 'ticket_url' => $ticket_url, 'event' => $empty_event);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_cost.php', $args);
     // =========================================
     // = Display organizer contact information =
     // =========================================
     $args = array('contact_name' => $contact_name, 'contact_phone' => $contact_phone, 'contact_email' => $contact_email, 'contact_url' => $contact_url, 'event' => $empty_event);
     $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_contact.php', $args);
     /*
     	TODO Display Eventbrite ticketing
     	$ai1ec_view_helper->display( 'box_eventbrite.php' );
     */
     // ==================
     // = Publish button =
     // ==================
     $publish_button = '';
     if ($ai1ec_settings->show_publish_button) {
         $args = array();
         $post_type = $post->post_type;
         $post_type_object = get_post_type_object($post_type);
         if (current_user_can($post_type_object->cap->publish_posts)) {
             $args['button_value'] = is_null($event) ? __('Publish', AI1EC_PLUGIN_NAME) : __('Update', AI1EC_PLUGIN_NAME);
         } else {
             $args['button_value'] = __('Submit for Review', AI1EC_PLUGIN_NAME);
         }
         $publish_button = $ai1ec_view_helper->get_admin_view('box_publish_button.php', $args);
     }
     // ==========================
     // = Parent/Child relations =
     // ==========================
     if ($event) {
         $parent = $ai1ec_events_helper->get_parent_event($event->post_id);
         if ($parent) {
             try {
                 $parent = new Ai1ec_Event($parent);
             } catch (Ai1ec_Event_Not_Found $exception) {
                 // ignore
                 $parent = NULL;
             }
         }
         $children = $ai1ec_events_helper->get_child_event_objects($event->post_id);
         $args = compact('parent', 'children');
         $boxes[] = $ai1ec_view_helper->get_admin_view('box_event_children.php', $args);
     }
     // Display the final view of the meta box.
     $args = array('boxes' => $boxes, 'publish_button' => $publish_button);
     $ai1ec_view_helper->display_admin('add_new_event_meta_box.php', $args);
 }
 /**
  * _ending_sentence function
  *
  * Ends rrule to text sentence
  *
  * @internal
  *
  * @return void
  **/
 function _ending_sentence(&$txt, &$rc)
 {
     if ($until = $rc->getUntil()) {
         if (!is_int($until)) {
             $until = strtotime($until);
         }
         $txt .= ' ' . sprintf(__('until %s', AI1EC_PLUGIN_NAME), Ai1ec_Time_Utility::date_i18n(Ai1ec_Meta::get_option('date_format'), $until, true));
     } else {
         if ($count = $rc->getCount()) {
             $txt .= ' ' . sprintf(__('for %d occurrences', AI1EC_PLUGIN_NAME), $count);
         } else {
             $txt .= ', ' . __('forever', AI1EC_PLUGIN_NAME);
         }
     }
 }
 public function update_tax_meta($term_id, $key, $value)
 {
     $m = Ai1ec_Meta::get_option('tax_meta_' . $term_id);
     $m[$key] = $value;
     update_option('tax_meta_' . $term_id, $m);
 }
 /**
  * export_events function
  *
  * Export events
  *
  * @return void
  **/
 function export_events()
 {
     global $ai1ec_events_helper, $ai1ec_exporter_helper, $ai1ec_localization_helper;
     $ai1ec_cat_ids = !empty($_REQUEST['ai1ec_cat_ids']) ? $_REQUEST['ai1ec_cat_ids'] : false;
     $ai1ec_tag_ids = !empty($_REQUEST['ai1ec_tag_ids']) ? $_REQUEST['ai1ec_tag_ids'] : false;
     $ai1ec_post_ids = !empty($_REQUEST['ai1ec_post_ids']) ? $_REQUEST['ai1ec_post_ids'] : false;
     if (!empty($_REQUEST['lang'])) {
         $ai1ec_localization_helper->set_language($_REQUEST['lang']);
     }
     $filter = array();
     if ($ai1ec_cat_ids) {
         $filter['cat_ids'] = explode(',', $ai1ec_cat_ids);
     }
     if ($ai1ec_tag_ids) {
         $filter['tag_ids'] = explode(',', $ai1ec_tag_ids);
     }
     if ($ai1ec_post_ids) {
         $filter['post_ids'] = explode(',', $ai1ec_post_ids);
     }
     // when exporting events by post_id, do not look up the event's start/end date/time
     $start = $ai1ec_post_ids !== false ? false : Ai1ec_Time_Utility::current_time(true) - 24 * 60 * 60;
     // Include any events ending today
     $end = false;
     $c = new vcalendar();
     $c->setProperty('calscale', 'GREGORIAN');
     $c->setProperty('method', 'PUBLISH');
     $c->setProperty('X-WR-CALNAME', get_bloginfo('name'));
     $c->setProperty('X-WR-CALDESC', get_bloginfo('description'));
     $c->setProperty('X-FROM-URL', home_url());
     // Timezone setup
     $tz = Ai1ec_Meta::get_option('timezone_string');
     if ($tz) {
         $c->setProperty('X-WR-TIMEZONE', $tz);
         $tz_xprops = array('X-LIC-LOCATION' => $tz);
         iCalUtilityFunctions::createTimezone($c, $tz, $tz_xprops);
     }
     $events = $ai1ec_events_helper->get_matching_events($start, $end, $filter);
     foreach ($events as $event) {
         $ai1ec_exporter_helper->insert_event_in_calendar($event, $c, $export = true);
     }
     $str = ltrim($c->createCalendar());
     header('Content-type: text/calendar; charset=utf-8');
     echo $str;
     exit;
 }
 /**
  *
  * @param $key string
  *
  * @see Ai1ec_Db_Adapter::get_data_from_config()
  *
  */
 public function get_data_from_config($key)
 {
     return Ai1ec_Meta::get_option($key);
 }
 /**
  * Get original post .
  *
  * @param int $id Optional. Post ID.
  * @param string $output Optional, default is Object. Either OBJECT, ARRAY_A, or ARRAY_N.
  * @return mixed Post data
  */
 function duplicate_post_get_original($id = 0, $output = OBJECT)
 {
     if (!($post =& get_post($id))) {
         return;
     }
     $original_ID = Ai1ec_Meta::instance('Post')->get($post->ID, '_dp_original', '', true);
     if (empty($original_ID)) {
         return NULL;
     }
     $original_post =& get_post($original_ID[0], $output);
     return $original_post;
 }
 /**
  * Return checkbox `checked` status for given event and provider
  *
  * @param Ai1ec_Event $event    Instance of Ai1ec_Event concerned
  * @param string      $provider Name of provider to check
  *
  * @return string Value for `checked` part of checkbox
  */
 protected function _selected_for_posting(Ai1ec_Event $event = NULL, $provider)
 {
     if (NULL === $event || !isset($event->post_id) || empty($event->post_id)) {
         return '';
     }
     $meta = '_ai1ec_post_' . $provider;
     $status = Ai1ec_Meta::instance('Post')->get($event->post_id, $meta, false);
     if (false === $status) {
         return '';
     }
     return 'checked="checked"';
 }