From 37ee11d541d6902d26883d8a1f464fcffb574db6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:16:50 +0000 Subject: [PATCH 01/23] Bump dompurify from 2.4.7 to 2.5.4 Bumps [dompurify](https://github.com/cure53/DOMPurify) from 2.4.7 to 2.5.4. - [Release notes](https://github.com/cure53/DOMPurify/releases) - [Commits](https://github.com/cure53/DOMPurify/compare/2.4.7...2.5.4) --- updated-dependencies: - dependency-name: dompurify dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- package.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb501540..a854bb7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "3.3.1", "license": "GPL-2.0-or-later", "dependencies": { - "dompurify": "^2.4.1" + "dompurify": "^2.5.4" }, "devDependencies": { "@babel/core": "^7.16.12", @@ -4819,9 +4819,9 @@ } }, "node_modules/dompurify": { - "version": "2.4.7", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.7.tgz", - "integrity": "sha512-kxxKlPEDa6Nc5WJi+qRgPbOAbgTpSULL+vI3NUXsZMlkJxTqYI9wg5ZTay2sFrdZRWHPWNi+EdAhcJf81WtoMQ==" + "version": "2.5.4", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.5.4.tgz", + "integrity": "sha512-l5NNozANzaLPPe0XaAwvg3uZcHtDBnziX/HjsY1UcDj1MxTK8Dd0Kv096jyPK5HRzs/XM5IMj20dW8Fk+HnbUA==" }, "node_modules/electron-to-chromium": { "version": "1.4.640", @@ -12778,9 +12778,9 @@ "dev": true }, "dompurify": { - "version": "2.4.7", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.4.7.tgz", - "integrity": "sha512-kxxKlPEDa6Nc5WJi+qRgPbOAbgTpSULL+vI3NUXsZMlkJxTqYI9wg5ZTay2sFrdZRWHPWNi+EdAhcJf81WtoMQ==" + "version": "2.5.4", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.5.4.tgz", + "integrity": "sha512-l5NNozANzaLPPe0XaAwvg3uZcHtDBnziX/HjsY1UcDj1MxTK8Dd0Kv096jyPK5HRzs/XM5IMj20dW8Fk+HnbUA==" }, "electron-to-chromium": { "version": "1.4.640", diff --git a/package.json b/package.json index ffb7dd84..4a9276d9 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,6 @@ "makepot": "wp i18n make-pot . ./languages/publishpress.pot --domain=publishpress" }, "dependencies": { - "dompurify": "^2.4.1" + "dompurify": "^2.5.4" } } From 2f2132b1da19d1c7721f8812422b03a25508598b Mon Sep 17 00:00:00 2001 From: olatechpro Date: Mon, 30 Sep 2024 23:15:25 +0100 Subject: [PATCH 02/23] Optimize file size --- .../icons/content-icon.svg | 0 common/php/class-module.php | 77 +- modules/calendar/calendar.php | 3344 +---------------- modules/calendar/library/calendar-methods.php | 1569 ++++++++ .../calendar/library/calendar-utilities.php | 1012 +++++ modules/content-board/content-board.php | 1265 +------ .../content-board/lib/content-board-icon.svg | 1 - .../library/content-board-utilities.php | 1255 +++++++ modules/content-overview/content-overview.php | 1263 +------ .../lib/content-overview-icon.svg | 1 - .../library/content-overview-utilities.php | 1252 ++++++ .../editorial-metadata/editorial-metadata.php | 917 +---- .../library/editorial-metadata-list-table.php | 167 + .../library/editorial-metadata-utilities.php | 748 ++++ 14 files changed, 6304 insertions(+), 6567 deletions(-) rename modules/calendar/lib/content-calendar-icon.svg => common/icons/content-icon.svg (100%) create mode 100644 modules/calendar/library/calendar-methods.php create mode 100644 modules/calendar/library/calendar-utilities.php delete mode 100644 modules/content-board/lib/content-board-icon.svg create mode 100644 modules/content-board/library/content-board-utilities.php delete mode 100644 modules/content-overview/lib/content-overview-icon.svg create mode 100644 modules/content-overview/library/content-overview-utilities.php create mode 100644 modules/editorial-metadata/library/editorial-metadata-list-table.php create mode 100644 modules/editorial-metadata/library/editorial-metadata-utilities.php diff --git a/modules/calendar/lib/content-calendar-icon.svg b/common/icons/content-icon.svg similarity index 100% rename from modules/calendar/lib/content-calendar-icon.svg rename to common/icons/content-icon.svg diff --git a/common/php/class-module.php b/common/php/class-module.php index 6ab27d5e..9259922d 100644 --- a/common/php/class-module.php +++ b/common/php/class-module.php @@ -196,7 +196,7 @@ public function get_post_statuses() return $publishpress->getPostStatuses(); } - + /** * Returns the CSS class name and color for the given custom status. @@ -503,11 +503,11 @@ public function print_ajax_response($status, $message = '', $data = null) protected function is_whitelisted_functional_view($module_name = null) { $whitelisted_pages = ['pp-calendar', 'pp-content-overview', 'pp-content-board', 'pp-notif-log', 'pp-modules-settings']; - + if (isset($_GET['page']) && in_array($_GET['page'], $whitelisted_pages)) { return true; } - + return false; } @@ -911,22 +911,22 @@ public function getPostStatusOptions() /** * Retrieve wordpress registered taxonomy - * + * * Private taxonomy are excluded * * @since 3.7.0 */ public function get_all_taxonomies() { - + //category and post tag are not included in public taxonomy $category = get_taxonomies(['name' => 'category'], 'objects'); $post_tag = get_taxonomies(['name' => 'post_tag'], 'objects'); - + $public = get_taxonomies(['_builtin' => false, 'public' => true], 'objects'); - + $taxonomies = array_merge($category, $post_tag, $public); - + return $taxonomies; } @@ -949,13 +949,13 @@ public function filter_get_param($param, $request_filter = false) } elseif (empty($request_filter[$param])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended return ''; } - + return sanitize_key($request_filter[$param]); // phpcs:ignore WordPress.Security.NonceVerification.Recommended } - + /** * This function is an alternative to filter_get_param() that's stripping out date characters - * + * * @param string $param The parameter to look for in $_GET * * @return mixed null if the parameter is not set in $_GET, empty string if the parameter is empty in $_GET, @@ -975,7 +975,7 @@ public function filter_get_param_text($param, $request_filter = false) } elseif (empty($request_filter[$param])) { return ''; } - + return sanitize_text_field($request_filter[$param]); } @@ -985,41 +985,46 @@ public function meta_query_operator_label($operator = false) { 'not_equals' => 'Does not equal (!=)', 'greater_than' => 'Greater than (>)', 'greater_than_or_equals' => 'Greater than or equals (>=)', - 'less_than' => 'Less than (<)', - 'less_than_or_equals' => 'Less than or equals (<=)', + 'less_than' => 'Less than (<)', + 'less_than_or_equals' => 'Less than or equals (<=)', 'like' => 'Like/Contains', 'not_like' => 'Not Like', 'not_exists' => 'Not Exists/Empty', ]; - + if ($operator) { $return = array_key_exists($operator, $operators) ? $operators[$operator] : $operator; } else { $return = $operators; } - + return $return; } - + public function meta_query_operator_symbol($operator = false) { + + return self::meta_query_operator_symbol($operator = false); + } + + public static function static_meta_query_operator_symbol($operator = false) { $operators = [ 'equals' => '=', 'not_equals' => '!=', 'greater_than' => '>', 'greater_than_or_equals' => '>=', - 'less_than' => '<', - 'less_than_or_equals' => '<=', + 'less_than' => '<', + 'less_than_or_equals' => '<=', 'like' => 'LIKE', 'not_like' => 'NOT LIKE', 'not_exists' => 'NOT EXISTS', ]; - + if ($operator) { $return = array_key_exists($operator, $operators) ? $operators[$operator] : $operator; } else { $return = $operators; } - + return $return; } @@ -1029,7 +1034,7 @@ public function localize_post_data($localized_post_data, $post, $can_edit_post) // add taxonomies $taxonomies = get_object_taxonomies($post->post_type, 'object'); foreach ($taxonomies as $taxonomy => $tax_object ) { - if (!empty($tax_object->public) + if (!empty($tax_object->public) && !in_array($taxonomy, ['author', 'post_format', 'post_status', 'post_status_core_wp_pp', 'post_visibility_pp'])) { $terms = get_the_terms($post->ID, $taxonomy); //add post content to localized data @@ -1172,7 +1177,7 @@ public function get_author_markup($post, $can_edit_post) { $post_author = get_userdata($post->post_author); $author_name = is_object($post_author) ? $post_author->display_name : ''; $author_name = apply_filters('the_author', $author_name); - + $author_name = apply_filters('publishpress_content_overview_author_column', $author_name, $post); return $author_name; } @@ -1193,25 +1198,25 @@ public function get_publish_date_markup() { public function touch_time( $tab_index = 0, $multi = 0 ) { global $wp_locale; - + $tab_index_attribute = ''; if ( (int) $tab_index > 0 ) { $tab_index_attribute = " tabindex=\"$tab_index\""; } - + $jj = current_time( 'd' ); $mm = current_time( 'm' ); $aa = current_time( 'Y' ); $hh = current_time( 'H' ); $mn = current_time( 'i' ); $ss = current_time( 's' ); - + $cur_jj = current_time( 'd' ); $cur_mm = current_time( 'm' ); $cur_aa = current_time( 'Y' ); $cur_hh = current_time( 'H' ); $cur_mn = current_time( 'i' ); - + $month = ''; - + $day = ''; - + echo '
'; /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */ printf( __( '%1$s %2$s, %3$s at %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); - + echo '
'; - + if ( $multi ) { return; } - + echo "\n\n"; - + $map = array( 'mm' => array( $mm, $cur_mm ), 'jj' => array( $jj, $cur_jj ), @@ -1261,10 +1266,10 @@ public function touch_time( $tab_index = 0, $multi = 0 ) { 'hh' => array( $hh, $cur_hh ), 'mn' => array( $mn, $cur_mn ), ); - + foreach ( $map as $timeunit => $value ) { list( $unit, $curr ) = $value; - + echo '' . "\n"; $cur_timeunit = 'cur_' . $timeunit; echo '' . "\n"; @@ -1272,7 +1277,7 @@ public function touch_time( $tab_index = 0, $multi = 0 ) { ?> dateUtil = new \PublishPress\Utility\Date(); $this->module = PublishPress()->register_module('calendar', $args); + + // Load utilities files. + $this->load_utilities_files(); + + $this->content_calendar_methods = new PP_Calendar_Methods([ + 'module' => $this->module, + 'module_url' => $this->module_url + ]); } /** @@ -275,6 +290,7 @@ public function __construct() */ public function init() { + add_action('template_include', [$this, 'handle_public_calendar_feed']); if (is_admin()) { @@ -301,25 +317,25 @@ public function init() require_once PUBLISHPRESS_BASE_PATH . '/common/php/' . 'screen-options.php'; - add_action('admin_init', [$this, 'register_settings']); - add_action('admin_print_styles', [$this, 'add_admin_styles']); + add_action('admin_init', [$this->content_calendar_methods, 'register_settings']); + add_action('admin_print_styles', [$this->content_calendar_methods, 'add_admin_styles']); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']); // Ajax insert post placeholder for a specific date add_action('wp_ajax_pp_insert_post', [$this, 'handle_ajax_insert_post']); - add_action('wp_ajax_publishpress_calendar_search_authors', [$this, 'searchAuthors']); - add_action('wp_ajax_publishpress_calendar_search_terms', [$this, 'searchTerms']); + add_action('wp_ajax_publishpress_calendar_search_authors', ['PP_Calendar_Utilities', 'searchAuthors']); + add_action('wp_ajax_publishpress_calendar_search_terms', ['PP_Calendar_Utilities', 'searchTerms']); add_action('wp_ajax_publishpress_calendar_get_data', [$this, 'fetchCalendarDataJson']); - add_action('wp_ajax_publishpress_calendar_move_item', [$this, 'moveCalendarItemToNewDate']); + add_action('wp_ajax_publishpress_calendar_move_item', [$this->content_calendar_methods, 'moveCalendarItemToNewDate']); add_action('wp_ajax_publishpress_calendar_get_post_data', [$this, 'getPostData']); add_action('wp_ajax_publishpress_calendar_get_post_type_fields', [$this, 'getPostTypeFields']); add_action('wp_ajax_publishpress_calendar_create_item', [$this, 'createItem']); // Action to regenerate the calendar feed secret - add_action('admin_init', [$this, 'handle_regenerate_calendar_feed_secret']); + add_action('admin_init', [$this->content_calendar_methods, 'handle_regenerate_calendar_feed_secret']); - add_filter('post_date_column_status', [$this, 'filter_post_date_column_status'], 12, 4); + add_filter('post_date_column_status', [$this->content_calendar_methods, 'filter_post_date_column_status'], 12, 4); add_filter('pp_calendar_after_form_submission_sanitize_title', [$this, 'sanitize_text_input'], 10, 1); add_filter('pp_calendar_after_form_submission_sanitize_content', [$this, 'sanitize_text_input'], 10, 1); @@ -365,72 +381,17 @@ public function handle_public_calendar_feed($original_template) return $original_template; } - add_filter('pp_calendar_total_weeks', [$this, 'filter_calendar_total_weeks_public_feed'], 10, 3); + add_filter('pp_calendar_total_weeks', [$this->content_calendar_methods, 'filter_calendar_total_weeks_public_feed'], 10, 3); add_filter( 'pp_calendar_ics_subscription_start_date', - [$this, 'filter_calendar_start_date_public_feed'], + [$this->content_calendar_methods, 'filter_calendar_start_date_public_feed'], 10 ); $this->handle_ics_subscription(); - remove_filter('pp_calendar_total_weeks', [$this, 'filter_calendar_total_weeks_public_feed']); - remove_filter('pp_calendar_ics_subscription_start_date', [$this, 'filter_calendar_start_date_public_feed']); - } - - /** - * @param $weeks - * @param $startDate - * @param $context - * - * @return float|int - */ - public function filter_calendar_total_weeks_public_feed($weeks, $startDate, $context) - { - if (! isset($_GET['end'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - $end = 'm2'; - } else { - $end = preg_replace('/[^wm0-9]/', '', sanitize_text_field($_GET['end'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended - } - - if (preg_match('/m[0-9]*/', $end)) { - $weeks = (int)str_replace('m', '', $end) * 4; - } else { - $weeks = (int)str_replace('w', '', $end); - } - - // Calculate the diff in weeks from start date until now - $today = date('Y-m-d'); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date - - $first = DateTime::createFromFormat('Y-m-d', $startDate); - $second = DateTime::createFromFormat('Y-m-d', $today); - - $diff = floor($first->diff($second)->days / 7); - - $weeks += $diff; - - return $weeks; - } - - /** - * @param $startDate - * - * @return false|string - */ - public function filter_calendar_start_date_public_feed($startDate) - { - if (! isset($_GET['start'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - // Current week - $start = 0; - } else { - $start = (int)$_GET['start']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - } - - if ($start > 0) { - $startDate = date('Y-m-d', strtotime('-' . $start . ' months', strtotime($startDate))); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date - } - - return $startDate; + remove_filter('pp_calendar_total_weeks', [$this->content_calendar_methods, 'filter_calendar_total_weeks_public_feed']); + remove_filter('pp_calendar_ics_subscription_start_date', [$this->content_calendar_methods, 'filter_calendar_start_date_public_feed']); } /** @@ -531,57 +492,6 @@ public function upgrade($previous_version) } } - /** - * Add any necessary CSS to the WordPress admin - * - * @uses wp_enqueue_style() - */ - public function add_admin_styles() - { - global $pagenow; - - // Only load calendar styles on the calendar page - if ('admin.php' === $pagenow && isset($_GET['page']) && $_GET['page'] === 'pp-calendar') { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - wp_enqueue_style( - 'publishpress-calendar-css', - $this->module_url . 'lib/calendar.css', - ['publishpress-select2'], - PUBLISHPRESS_VERSION - ); - - wp_enqueue_style( - 'publishpress-async-calendar-theme-light-css', - $this->module_url . 'lib/async-calendar/styles/themes/theme-light.css', - [], - PUBLISHPRESS_VERSION - ); - - wp_enqueue_style( - 'publishpress-async-calendar-css', - $this->module_url . 'lib/async-calendar/styles/async-calendar.css', - ['publishpress-async-calendar-theme-light-css'], - PUBLISHPRESS_VERSION - ); - - if (isset($this->module->options->show_calendar_posts_full_title) && 'on' === $this->module->options->show_calendar_posts_full_title) { - $inline_style = '.publishpress-calendar .publishpress-calendar-item { - height: auto; - max-height: max-content; - white-space: break-spaces; - }'; - wp_add_inline_style('publishpress-async-calendar-css', $inline_style); - } - - wp_enqueue_style( - 'publishpress-select2', - PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/css/select2.min.css', - false, - PUBLISHPRESS_VERSION, - 'screen' - ); - } - } - /** * Check whether the user should have the ability to view the calendar. * Returns true if the user can view. @@ -604,248 +514,20 @@ public function enqueue_admin_scripts() if ($this->is_whitelisted_functional_view()) { $this->enqueue_datepicker_resources(); - $js_libraries = [ - 'jquery', - 'jquery-ui-core', - 'jquery-ui-sortable', - 'jquery-ui-draggable', - 'jquery-ui-droppable', - 'clipboard-js', - 'publishpress-select2' - ]; - foreach ($js_libraries as $js_library) { - wp_enqueue_script($js_library); - } - wp_enqueue_script( - 'clipboard-js', - $this->module_url . 'lib/clipboard.min.js', - ['jquery'], - PUBLISHPRESS_VERSION, - true - ); - - wp_enqueue_script( - 'publishpress-admin', - PUBLISHPRESS_URL . 'common/js/publishpress-admin.js', - ['jquery'], - PUBLISHPRESS_VERSION - ); - - wp_enqueue_script( - 'publishpress-calendar-js', - $this->module_url . 'lib/calendar.js', - $js_libraries, - PUBLISHPRESS_VERSION, - true - ); - - wp_enqueue_script( - 'publishpress-select2', - PUBLISHPRESS_URL . 'common/libs/select2-v4.0.13.1/js/select2.min.js', - ['jquery'], - PUBLISHPRESS_VERSION - ); - - if (is_admin() && isset($_GET['page']) && $_GET['page'] === 'pp-calendar' && ! isset($_GET['stop-the-calendar'])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended - global $wp_scripts; - - if (! isset($wp_scripts->queue['react'])) { - wp_enqueue_script( - 'react', - PUBLISHPRESS_URL . 'common/js/react.min.js', - [], - PUBLISHPRESS_VERSION, - true - ); - wp_enqueue_script( - 'react-dom', - PUBLISHPRESS_URL . 'common/js/react-dom.min.js', - ['react'], - PUBLISHPRESS_VERSION, - true - ); - } - - wp_enqueue_script( - 'jquery-inputmask', - PUBLISHPRESS_URL . 'common/js/jquery.inputmask.min.js', - [ - 'jquery', - ], - PUBLISHPRESS_VERSION, - true - ); - - wp_enqueue_script( - 'date_i18n', - PUBLISHPRESS_URL . 'common/js/date-i18n.js', - [], - PUBLISHPRESS_VERSION, - true - ); - - // TODO: Replace react and react-dom with the wp.element dependency - wp_enqueue_script( - 'publishpress-async-calendar-js', - $this->module_url . 'lib/async-calendar/js/index.min.js', - [ - 'react', - 'react-dom', - 'jquery', - 'jquery-ui-core', - 'jquery-ui-sortable', - 'jquery-ui-draggable', - 'jquery-ui-droppable', - 'jquery-inputmask', - 'wp-i18n', - 'wp-element', - 'date_i18n', - ], - PUBLISHPRESS_VERSION, - true - ); - - /* - * Filters - */ - $userFilters = $this->get_filters(); - $calendar_request_args = $userFilters; - $calendar_request_filter = $userFilters; - - $maxVisibleItemsOption = isset($this->module->options->max_visible_posts_per_date) && ! empty($this->default_max_visible_posts_per_date) ? - (int)$this->module->options->max_visible_posts_per_date : $this->default_max_visible_posts_per_date; - - $postStatuses = $this->getPostStatusOptions(); - - $postTypes = []; - $postTypesUserCanCreate = []; - foreach ($this->get_selected_post_types() as $postTypeName) { - $postType = get_post_type_object($postTypeName); - - $postTypes[] = [ - 'value' => esc_attr($postTypeName), - 'text' => esc_html($postType->label) - ]; - - if (current_user_can($postType->cap->edit_posts)) { - $postTypesUserCanCreate[] = [ - 'value' => esc_attr($postTypeName), - 'text' => esc_html($postType->labels->singular_name) - ]; - } - } - - $numberOfWeeksToDisplay = isset($calendar_request_filter['weeks']) ? // phpcs:ignore WordPress.Security.NonceVerification.Recommended - (int)$calendar_request_filter['weeks'] : self::DEFAULT_NUM_WEEKS; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - - $firstDateToDisplay = (isset($calendar_request_filter['start_date']) ? // phpcs:ignore WordPress.Security.NonceVerification.Recommended - sanitize_text_field($calendar_request_filter['start_date']) : date('Y-m-d')) . ' 00:00:00'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.DateTime.RestrictedFunctions.date_date - $firstDateToDisplay = $this->get_beginning_of_week($firstDateToDisplay); - $endDate = $this->get_ending_of_week( - $firstDateToDisplay, - 'Y-m-d', - $numberOfWeeksToDisplay - ); - - $params = [ - 'requestFilter' => $calendar_request_filter, - 'numberOfWeeksToDisplay' => $numberOfWeeksToDisplay, - 'firstDateToDisplay' => esc_js($firstDateToDisplay), - 'theme' => 'light', - 'weekStartsOnSunday' => (int)get_option('start_of_week') === 0, - 'todayDate' => esc_js(date('Y-m-d 00:00:00')), // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date - 'dateFormat' => esc_js(get_option('date_format', 'Y-m-d H:i:s')), - 'timeFormat' => esc_js($this->getCalendarTimeFormat()), - 'maxVisibleItems' => $maxVisibleItemsOption, - 'statuses' => $postStatuses, - 'postTypes' => $postTypes, - 'postTypesCanCreate' => $postTypesUserCanCreate, - 'ajaxUrl' => esc_url(admin_url('admin-ajax.php')), - 'nonce' => wp_create_nonce('publishpress-calendar-get-data'), - 'userCanAddPosts' => count($postTypesUserCanCreate) > 0, - 'items' => $this->getCalendarData($firstDateToDisplay, $endDate, $calendar_request_args), - 'allowAddingMultipleAuthors' => (bool)apply_filters( - 'publishpress_calendar_allow_multiple_authors', - false - ), - 'proActive' => Util::isPlannersProActive(), - 'strings' => [ - 'loading' => esc_js(__('Loading...', 'publishpress')), - 'loadingItem' => esc_js(__('Loading item...', 'publishpress')), - 'clickToAdd' => esc_js(__('Click to add', 'publishpress')), - 'movingTheItem' => esc_js(__('Moving the item...', 'publishpress')), - 'hideItems' => esc_js(__('Hide the %s last items', 'publishpress')), - 'showMore' => esc_js(__('Show %s more', 'publishpress')), - 'untitled' => esc_js(__('Untitled', 'publishpress')), - 'close' => esc_js(__('Close', 'publishpress')), - 'save' => esc_js(__('Save', 'publishpress')), - 'saving' => esc_js(__('Saving...', 'publishpress')), - 'saveAndEdit' => esc_js(__('Save and edit', 'publishpress')), - 'addContentFor' => esc_js(__('Add content for %s', 'publishpress')), - 'postTypeNotFound' => esc_js(__('Post type not found', 'publishpress')), - 'postType' => esc_js(__('Post type:', 'publishpress')), - 'pleaseWaitLoadingFormFields' => esc_js(__('Please, wait! Loading the form fields...', 'publishpress')), - 'weekDaySun' => esc_js(__('Sun', 'publishpress')), - 'weekDayMon' => esc_js(__('Mon', 'publishpress')), - 'weekDayTue' => esc_js(__('Tue', 'publishpress')), - 'weekDayWed' => esc_js(__('Wed', 'publishpress')), - 'weekDayThu' => esc_js(__('Thu', 'publishpress')), - 'weekDayFri' => esc_js(__('Fri', 'publishpress')), - 'weekDaySat' => esc_js(__('Sat', 'publishpress')), - 'monthJan' => esc_js(__('Jan', 'publishpress')), - 'monthFeb' => esc_js(__('Feb', 'publishpress')), - 'monthMar' => esc_js(__('Mar', 'publishpress')), - 'monthApr' => esc_js(__('Apr', 'publishpress')), - 'monthMay' => esc_js(__('May', 'publishpress')), - 'monthJun' => esc_js(__('Jun', 'publishpress')), - 'monthJul' => esc_js(__('Jul', 'publishpress')), - 'monthAug' => esc_js(__('Aug', 'publishpress')), - 'monthSep' => esc_js(__('Sep', 'publishpress')), - 'monthOct' => esc_js(__('Oct', 'publishpress')), - 'monthNov' => esc_js(__('Nov', 'publishpress')), - 'monthDec' => esc_js(__('Dec', 'publishpress')), - 'allStatuses' => esc_js(__('All statuses', 'publishpress')), - 'allCategories' => esc_js(__('All categories', 'publishpress')), - 'allTags' => esc_js(__('All tags', 'publishpress')), - 'allAuthors' => esc_js(__('All authors', 'publishpress')), - 'allTypes' => esc_js(__('All types', 'publishpress')), - 'xWeek' => esc_js(__('%d week', 'publishpress')), - 'xWeeks' => esc_js(__('%d weeks', 'publishpress')), - 'today' => esc_js(__('Today', 'publishpress')), - 'noTerms' => esc_js(__('No terms', 'publishpress')), - 'post_date_label' => esc_html__('Post Date', 'publishpress'), - 'edit_label' => esc_html__('Edit', 'publishpress'), - 'delete_label' => esc_html__('Trash', 'publishpress'), - 'preview_label' => esc_html__('Preview', 'publishpress'), - 'view_label' => esc_html__('View', 'publishpress'), - 'prev_label' => esc_html__('Previous Post', 'publishpress'), - 'next_label' => esc_html__('Next Post', 'publishpress'), - 'post_status_label' => esc_html__('Post Status', 'publishpress'), - 'update_label' => esc_html__('Save Changes', 'publishpress'), - 'empty_term' => esc_html__('Taxonomy not set.', 'publishpress'), - 'post_author' => esc_html__('Author', 'publishpress'), - 'date_format' => pp_convert_date_format_to_jqueryui_datepicker(get_option('date_format')), - 'week_first_day' => esc_js(get_option('start_of_week')), - ] - ]; - wp_localize_script('publishpress-async-calendar-js', 'publishpressCalendarParams', $params); - - global $wp_locale; - $monthNames = array_map([&$wp_locale, 'get_month'], range(1, 12)); - $monthNamesShort = array_map([&$wp_locale, 'get_month_abbrev'], $monthNames); - $dayNames = array_map([&$wp_locale, 'get_weekday'], range(0, 6)); - $dayNamesShort = array_map([&$wp_locale, 'get_weekday_abbrev'], $dayNames); - wp_localize_script( - "date_i18n", - "DATE_I18N", - array( - "month_names" => $monthNames, - "month_names_short" => $monthNamesShort, - "day_names" => $dayNames, - "day_names_short" => $dayNamesShort - ) - ); - } + $method_args = []; + $method_args['content_calendar_datas'] = $this->get_content_calendar_datas(); + $method_args['userFilters'] = $this->get_filters(); + $method_args['postStatuses'] = $this->getPostStatusOptions(); + $method_args['selectedPostTypes'] = $this->get_selected_post_types(); + $method_args['timeFormat'] = $this->getCalendarTimeFormat(); + $method_args['proActive'] = Util::isPlannersProActive(); + $method_args['operator_labels'] = $this->meta_query_operator_label(); + $method_args['post_statuses'] = $this->get_post_statuses(); + $method_args['terms_options'] = $this->terms_options; + $method_args['form_filters'] = $this->form_filters; + $method_args['form_filter_list'] = $this->form_filter_list; + $method_args['all_filters'] = $this->filters; + $this->content_calendar_methods->enqueue_admin_scripts($method_args); } } @@ -871,135 +553,6 @@ private function getTimezoneString() return $timezoneString; } - /** - * Returns a VTIMEZONE component for a Olson timezone identifier - * with daylight transitions covering the given date range. - * - * @param \Sabre\VObject\Component\VCalendar - * @param string $tzid Timezone ID as used in PHP's Date functions - * @param int $from Unix timestamp with first date/time in this timezone - * @param int $to Unix timestap with last date/time in this timezone - * - * @return mixed A Sabre\VObject\Component object representing a VTIMEZONE definition - * or false if no timezone information is available - */ - private function generateVTimeZone(&$calendar, $tzid, $from = 0, $to = 0) - { - if (! $from) { - $from = time(); - } - if (! $to) { - $to = $from; - } - - try { - $tz = new DateTimeZone($tzid); - } catch (Exception $e) { - return false; - } - - // get all transitions for one year back/ahead - $year = 86400 * 360; - $transitions = $tz->getTransitions($from - $year, $to + $year); - - $vTimeZone = $calendar->add( - 'VTIMEZONE', - [ - 'TZID' => $tz->getName(), - ] - ); - - $standard = null; - $daylight = null; - $t_std = null; - $t_dst = null; - $tzfrom = 0; - if (is_array($transitions) || is_object($transitions)) { - foreach ($transitions as $i => $trans) { - if ($i == 0) { - $tzfrom = $trans['offset'] / 3600; - continue; - } - - // daylight saving time definition - if ($trans['isdst']) { - $t_dst = $trans['ts']; - $dt = new DateTime($trans['time']); - $offset = $trans['offset'] / 3600; - - $daylight = $vTimeZone->add( - 'DAYLIGHT', - [ - 'DTSTART' => $dt->format('Ymd\THis'), - 'TZOFFSETFROM' => sprintf( - '%s%02d%02d', - $tzfrom >= 0 ? '+' : '', - floor($tzfrom), - ($tzfrom - floor($tzfrom)) * 60 - ), - 'TZOFFSETTO' => sprintf( - '%s%02d%02d', - $offset >= 0 ? '+' : '', - floor($offset), - ($offset - floor($offset)) * 60 - ), - ] - ); - - // add abbreviated timezone name if available - if (! empty($trans['abbr'])) { - $daylight->add('TZNAME', [$trans['abbr']]); - } - - $tzfrom = $offset; - } else { - $t_std = $trans['ts']; - $dt = new DateTime($trans['time']); - $offset = $trans['offset'] / 3600; - - $standard = $vTimeZone->add( - 'STANDARD', - [ - 'DTSTART' => $dt->format('Ymd\THis'), - 'TZOFFSETFROM' => sprintf( - '%s%02d%02d', - $tzfrom >= 0 ? '+' : '', - floor($tzfrom), - ($tzfrom - floor($tzfrom)) * 60 - ), - 'TZOFFSETTO' => sprintf( - '%s%02d%02d', - $offset >= 0 ? '+' : '', - floor($offset), - ($offset - floor($offset)) * 60 - ), - ] - ); - - // add abbreviated timezone name if available - if (! empty($trans['abbr'])) { - $standard->add('TZNAME', [$trans['abbr']]); - } - - $tzfrom = $offset; - } - - // we covered the entire date range - if ($standard && $daylight && min($t_std, $t_dst) < $from && max($t_std, $t_dst) > $to) { - break; - } - } - } - - // add X-MICROSOFT-CDO-TZID if available - $microsoftExchangeMap = array_flip(Sabre\VObject\TimeZoneUtil::$microsoftExchangeMap); - if (array_key_exists($tz->getName(), $microsoftExchangeMap)) { - $vTimeZone->add('X-MICROSOFT-CDO-TZID', $microsoftExchangeMap[$tz->getName()]); - } - - return $vTimeZone; - } - /** * After checking that the request is valid, do an .ics file * @@ -1029,7 +582,7 @@ public function handle_ics_subscription() // Set up the post data to be printed $post_query_args = []; - $calendar_filters = $this->calendar_filters(); + $calendar_filters = PP_Calendar_Utilities::calendar_filters(); foreach ($calendar_filters as $filter) { if (isset($_GET[$filter]) && false !== ($value = $this->sanitize_filter( $filter, @@ -1045,7 +598,7 @@ public function handle_ics_subscription() $this->start_date = sanitize_text_field( apply_filters( 'pp_calendar_ics_subscription_start_date', - $this->get_beginning_of_week(date('Y-m-d', current_time('timestamp'))) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date + PP_Calendar_Utilities::get_beginning_of_week(date('Y-m-d', current_time('timestamp'))) // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date ) ); @@ -1066,7 +619,7 @@ public function handle_ics_subscription() $timezoneString = $this->dateUtil->getTimezoneString(); - $this->generateVtimezone( + PP_Calendar_Utilities::generateVtimezone( $vCalendar, $timezoneString, strtotime($this->start_date), @@ -1120,7 +673,7 @@ public function handle_ics_subscription() 'VEVENT', [ 'UID' => $post->guid, - 'SUMMARY' => $this->do_ics_escaping(apply_filters('the_title', $post->post_title)) + 'SUMMARY' => PP_Calendar_Utilities::do_ics_escaping(apply_filters('the_title', $post->post_title)) . ' - ' . $this->get_post_status_friendly_name(get_post_status($post->ID)), 'DTSTART' => $start_date, 'DTEND' => $end_date, @@ -1142,63 +695,6 @@ public function handle_ics_subscription() // phpcs:enable } - /** - * Perform the encoding necessary for ICS feed text. - * - * @param string $text The string that needs to be escaped - * - * @return string The string after escaping for ICS. - * @since 0.8 - * */ - - public function do_ics_escaping($text) - { - $text = str_replace(',', '\,', $text); - $text = str_replace(';', '\:', $text); - $text = str_replace('\\', '\\\\', $text); - - return $text; - } - - /** - * Handle a request to regenerate the calendar feed secret - * - * @since 0.8 - */ - public function handle_regenerate_calendar_feed_secret() - { - if (! isset($_GET['action']) || 'pp_calendar_regenerate_calendar_feed_secret' != $_GET['action']) { - return; - } - - if (! current_user_can('manage_options')) { - wp_die($this->module->messages['invalid-permissions']); - } - - if (! isset($_GET['_wpnonce']) - || ! wp_verify_nonce(sanitize_text_field($_GET['_wpnonce']), 'pp-regenerate-ics-key') - ) { - wp_die($this->module->messages['nonce-failed']); - } - - PublishPress()->update_module_option($this->module->name, 'ics_secret_key', wp_generate_password()); - - $args = [ - 'page' => PP_Modules_Settings::SETTINGS_SLUG, - 'settings_module' => $this->module->settings_slug, - ]; - - wp_safe_redirect( - add_query_arg( - 'message', - 'key-regenerated', - add_query_arg($args, admin_url('admin.php')) - ) - ); - - exit; - } - /** * Get the user's filters for calendar, either with $_GET or from saved * @@ -1326,7 +822,7 @@ public function update_user_filters($request_filter = []) } // Set the start date as the beginning of the week, according to blog settings - $user_filters['start_date'] = $this->get_beginning_of_week($user_filters['start_date']); + $user_filters['start_date'] = PP_Calendar_Utilities::get_beginning_of_week($user_filters['start_date']); if (!empty($user_filters['me_mode'])) { $user_filters['author'] = $current_user->ID; @@ -1400,408 +896,14 @@ public function content_calendar_filters() return apply_filters('PP_Content_Calendar_filter_names', $select_filter_names); } - public function content_calendar_filter_options($select_id, $select_name, $filters) - { - - if (array_key_exists($select_id, $this->terms_options)) { - $select_id = 'metadata_key'; - } - - if (array_key_exists($select_id, $this->content_calendar_datas['taxonomies']) && taxonomy_exists($select_id)) { - $select_id = 'taxonomy'; - } - - $filter_label = ''; - $selected_value = ''; - - ob_start(); - - switch ($select_id) { - case 'post_status': - $post_statuses = $this->get_post_statuses(); - $filter_label = esc_html__('Post Status', 'publishpress'); - ?> - - label); - ?> - - - - - - - - terms_options[$select_name]; - - $metadata_type = $metadata_term['type']; - $selected_value = $metadata_value; - $filter_label = $metadata_term['name']; - - ?> -